Skip to content

Commit

Permalink
Merge pull request #84 from Workiva/fixed_cascade_references
Browse files Browse the repository at this point in the history
FEA-2496: Fixed Cascade Indexing
  • Loading branch information
rmconsole3-wf authored Sep 12, 2023
2 parents e6ec7a2 + d533b6b commit d8e02c4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/src/scip_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompoundAssignmentExpression>();
if (assignmentExpr == null) return;

element = assignmentExpr.readElement ?? assignmentExpr.writeElement;
}

// When the identifier is a field, the analyzer creates synthetic getters/
Expand Down
11 changes: 11 additions & 0 deletions snapshots/input/basic-project/lib/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import 'more.dart' deferred as more;

class Foo {
int _far;
bool value;
String value2;
double value3;
Foo(this._far);
}

Expand All @@ -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
}
29 changes: 29 additions & 0 deletions snapshots/output/basic-project/lib/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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#<constructor>().
// documentation ```dart
Expand Down Expand Up @@ -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.
}

0 comments on commit d8e02c4

Please sign in to comment.