diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index f080764..ce5fcbf 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -115,9 +115,12 @@ class ScipVisitor extends GeneralizingAstVisitor { // 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; + if (element == null) { + final assignmentExpr = + node.thisOrAncestorOfType(); + if (assignmentExpr == null) return; + + element = assignmentExpr.readElement ?? assignmentExpr.writeElement; } // When the identifier is a field, the analyzer creates synthetic getters/ diff --git a/snapshots/input/basic-project/lib/other.dart b/snapshots/input/basic-project/lib/other.dart index fb31e52..36a9d4c 100644 --- a/snapshots/input/basic-project/lib/other.dart +++ b/snapshots/input/basic-project/lib/other.dart @@ -2,6 +2,9 @@ import 'more.dart' deferred as more; class Foo { int _far; + bool value; + String value2; + double value3; Foo(this._far); } @@ -19,4 +22,12 @@ void main() { more.loadLibrary().then((_) => { Bar('a').someMethod.call() }); + + Foo()..value = false; + + final someStr = 'someStr'; + Foo() + ..value = true + ..value2 = someStr + ..value3 = 2.15 } \ No newline at end of file diff --git a/snapshots/output/basic-project/lib/other.dart b/snapshots/output/basic-project/lib/other.dart index d8eadfe..7d0b3d3 100755 --- a/snapshots/output/basic-project/lib/other.dart +++ b/snapshots/output/basic-project/lib/other.dart @@ -10,6 +10,18 @@ // ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int# // ^^^^ definition local 0 // documentation ```dart + bool value; +// ^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/bool.dart/bool# +// ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value. +// documentation ```dart + String value2; +// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# +// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value2. +// documentation ```dart + double value3; +// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/double.dart/double# +// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value3. +// documentation ```dart Foo(this._far); // ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#(). // documentation ```dart @@ -57,4 +69,21 @@ // ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Bar# // ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Bar#someMethod(). }); + + Foo()..value = false; +// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo# +// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value. + + final someStr = 'someStr'; +// ^^^^^^^ definition local 5 +// documentation ```dart + Foo() +// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo# + ..value = true +// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value. + ..value2 = someStr +// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value2. +// ^^^^^^^ reference local 5 + ..value3 = 2.15 +// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value3. }