Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/src/scip_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,22 @@ class ScipVisitor extends GeneralizingAstVisitor {
}

void _visitSimpleIdentifier(SimpleIdentifier node) {
final element = node.staticElement;
var element = node.staticElement;

// [element] for assignment fields is null. If the parent node
// is a `CompoundAssignmentExpression`, we know this node is referring
// to an assignment line. In that case, use the read/write element attached
// to this node instead of the [node]'s element
if (node.parent is CompoundAssignmentExpression) {
final assignmentNode = node.parent as CompoundAssignmentExpression;
element = assignmentNode.readElement ?? assignmentNode.writeElement;
}

// When the identifier is a field, the analyzer creates synthetic getters/
// setters for it. We need to get the backing field.
if (element?.isSynthetic == true && element is PropertyAccessorElement) {
element = element.variable;
}
Comment on lines +96 to +100

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit should we go ahead and make this an else if to avoid the unnecessary second check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, its necessary to hit both

the CompoundAssignmentExpression is to get the correct ast node, it can assign the element to be PropertyAccessorElement

And if element is PropertyAccessorElement in any case, we want its variable, not it's element node

Its a bit strange, but we're bound to the criteria of the ast/static analysis by a lot of this stuff


// element is null if there's nothing really to do for this node. Example: `void`
// TODO: One weird issue found: named parameters of external symbols were element.source
Expand Down
10 changes: 10 additions & 0 deletions snapshots/input/basic-project/lib/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@ class Foo {
int _far;
Foo(this._far);
}

class Bar {
String _someValue;
Bar(this._someValue);

void someMethod() {
_someValue = 'asdf';
print(_someValue);
}
}
4 changes: 4 additions & 0 deletions snapshots/output/basic-project/lib/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,26 @@
// ^^^^^^^^^^ 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.
soundMaker = () => print('Meow!');
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#soundMaker.
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
break;
case AnimalType.dog:
// ^^^^^^^^^^ 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.
soundMaker = () => print('Woof!');
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#soundMaker.
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
break;
case AnimalType.bird:
// ^^^^^^^^^^ 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.
soundMaker = () => print('Chirp!');
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#soundMaker.
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
break;
default:
soundMaker = () => print('Unknown animal type');
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#soundMaker.
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
}
}
Expand Down
25 changes: 25 additions & 0 deletions snapshots/output/basic-project/lib/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,28 @@
// documentation ```dart
}

class Bar {
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Bar#
// documentation ```dart
String _someValue;
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String#
// ^^^^^^^^^^ definition local 2
// documentation ```dart
Bar(this._someValue);
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Bar#<constructor>().
// documentation ```dart
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Bar#
// ^^^^ reference local 2
// ^^^^^^^^^^ definition local 3
// documentation ```dart

void someMethod() {
// ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Bar#someMethod().
// documentation ```dart
_someValue = 'asdf';
// ^^^^^^^^^^ reference local 2
print(_someValue);
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
// ^^^^^^^^^^ reference local 2
}
}