Skip to content

Commit

Permalink
fixed constructor declarations in prefixed identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewnitschke-wk committed Dec 19, 2024
1 parent 169275a commit d29d685
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 27 deletions.
13 changes: 13 additions & 0 deletions lib/src/symbol_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ class SymbolGenerator {
// as the element to annotate instead of the reference to the Class
final parentConstructor = node.thisOrAncestorOfType<ConstructorName>();
if (parentConstructor != null) {
// ConstructorNames can also include a PrefixIdentifier: `math.Rectangle()`
// both 'math' and 'Rectangle' are simple identifiers. We only want
// the constructor element fo 'Rectangle' in this case
final parentPrefixIdentifier = node.thisOrAncestorOfType<PrefixedIdentifier>();
if (parentPrefixIdentifier != null) {
if (parentPrefixIdentifier.identifier == node) {
return parentConstructor.staticElement;
}
return element;
}

// Otherwise, element is just `Rectangle()`, so simply return the
// constructor's element
return parentConstructor.staticElement;
}

Expand Down
13 changes: 9 additions & 4 deletions snapshots/input/basic-project/lib/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Animal with SleepMixin {
}
}

factory Animal.cat() => Animal('Timmy', type: AnimalType.cat);

void makeSound() {
soundMaker?.call();
}
Expand All @@ -54,16 +56,19 @@ void main() {
List<int> numbers = [1, 2, 3, 4, 5];
int sum = calculateSum(numbers);

Animal cat = Animal('Kitty', type: AnimalType.cat);
Animal bird = Animal('Kitty', type: AnimalType.bird);
Animal dog = Animal('Buddy', type: AnimalType.dog);
Animal cat = Animal.cat();

cat.makeSound();
cat.sleep();
bird.makeSound();
bird.sleep();

dog.makeSound();
dog.sleep();

print(cat);
cat.makeSound();

print(bird);
print(dog);
print('The sum of $numbers is $sum');

Expand Down
2 changes: 1 addition & 1 deletion snapshots/input/basic-project/lib/relationships.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class Dog extends Animal with SwimAction {
String get someGetter => 'value';

@override
set someSetter(String v) {};
set someSetter(String v) => print(v);
}
58 changes: 37 additions & 21 deletions snapshots/output/basic-project/lib/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
}
}

factory Animal.cat() => Animal('Timmy', type: AnimalType.cat);
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#cat().
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().(type)
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#cat.

void makeSound() {
// ^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound().
soundMaker?.call();
Expand Down Expand Up @@ -121,27 +128,32 @@
// ^^^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/calculateSum().
// ^^^^^^^ reference local 3

Animal cat = Animal('Kitty', type: AnimalType.cat);
Animal bird = Animal('Kitty', type: AnimalType.bird);
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#
// ^^^ definition local 5
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().(type)
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#cat.
// ^^^^ definition local 5
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().(type)
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#bird.
Animal dog = Animal('Buddy', type: AnimalType.dog);
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#
// ^^^ definition local 6
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().(type)
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#dog.
Animal cat = Animal.cat();
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#
// ^^^ definition local 7
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#cat().
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#cat().

cat.makeSound();
// ^^^ reference local 5
// ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound().
cat.sleep();
// ^^^ reference local 5
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/SleepMixin#sleep().
bird.makeSound();
// ^^^^ reference local 5
// ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound().
bird.sleep();
// ^^^^ reference local 5
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/SleepMixin#sleep().

dog.makeSound();
// ^^^ reference local 6
Expand All @@ -150,9 +162,13 @@
// ^^^ reference local 6
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/SleepMixin#sleep().

print(cat);
cat.makeSound();
// ^^^ reference local 7
// ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound().

print(bird);
// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print().
// ^^^ reference local 5
// ^^^^ reference local 5
print(dog);
// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print().
// ^^^ reference local 6
Expand All @@ -163,24 +179,24 @@

print(math.Rectangle(1,2,3,4));
// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print().
// ^^^^ reference scip-dart pub dart:math 2.19.0 dart:math/`rectangle.dart`/Rectangle#`<constructor>`().
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/math.
// ^^^^^^^^^ reference scip-dart pub dart:math 2.19.0 dart:math/`rectangle.dart`/Rectangle#`<constructor>`().

[1,2].reduce((a, b) => a + b);
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`iterable.dart`/Iterable#reduce().
// ^ definition local 7
// ^ definition local 8
// ^ reference local 7
// ^ reference local 8
// ^ definition local 8
// ^ definition local 9
// ^ reference local 8
// ^ reference local 9
}

void test(String Function(int) p) {}
// ^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/test().
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String#
// ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int#
// ^ definition local 9
// ^ definition local 10
void deepTest(String Function(void Function(String test)) p) {}
// ^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/deepTest().
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String#
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String#
// ^ definition local 10
// ^ definition local 11
4 changes: 3 additions & 1 deletion snapshots/output/basic-project/lib/relationships.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@

@override
// ^^^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`annotations.dart`/override.
set someSetter(String v) {};
set someSetter(String v) => print(v);
// ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Dog#`<set>someSetter`.
// relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#`<set>someSetter`. implementation reference
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String#
// ^ definition local 1
// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print().
// ^ reference local 1
}

0 comments on commit d29d685

Please sign in to comment.