diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 97fa118..a35074f 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -55,6 +55,19 @@ class SymbolGenerator { // as the element to annotate instead of the reference to the Class final parentConstructor = node.thisOrAncestorOfType(); 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(); + 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; } diff --git a/snapshots/input/basic-project/lib/more.dart b/snapshots/input/basic-project/lib/more.dart index ae1ccf4..678db4f 100644 --- a/snapshots/input/basic-project/lib/more.dart +++ b/snapshots/input/basic-project/lib/more.dart @@ -36,6 +36,8 @@ class Animal with SleepMixin { } } + factory Animal.cat() => Animal('Timmy', type: AnimalType.cat); + void makeSound() { soundMaker?.call(); } @@ -54,16 +56,19 @@ void main() { List 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'); diff --git a/snapshots/input/basic-project/lib/relationships.dart b/snapshots/input/basic-project/lib/relationships.dart index 1ad9923..9218058 100644 --- a/snapshots/input/basic-project/lib/relationships.dart +++ b/snapshots/input/basic-project/lib/relationships.dart @@ -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); } \ No newline at end of file diff --git a/snapshots/output/basic-project/lib/more.dart b/snapshots/output/basic-project/lib/more.dart index 79aed98..56d7e5f 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -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#``(). +// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#``().(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(); @@ -121,13 +128,13 @@ // ^^^^^^^^^^^^ 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#``(). -// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#``().(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#``(). +// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#``().(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 @@ -135,13 +142,18 @@ // ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#``().(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 @@ -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 @@ -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#``(). +// ^^^^ 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#``(). [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 diff --git a/snapshots/output/basic-project/lib/relationships.dart b/snapshots/output/basic-project/lib/relationships.dart index dc6a8d9..11b0e1f 100755 --- a/snapshots/output/basic-project/lib/relationships.dart +++ b/snapshots/output/basic-project/lib/relationships.dart @@ -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#`someSetter`. // relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#`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 }