From 55a838dcba91a75542c5753f68cd5847cf787356 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 26 Sep 2024 22:49:35 -0600 Subject: [PATCH] fixed relationships for setters --- .github/workflows/ci.yaml | 13 +----- lib/src/relationship_generator.dart | 44 ++++++++++--------- .../basic-project/lib/relationships.dart | 7 +-- 3 files changed, 27 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f88a94d..f0e1c72 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,17 +15,8 @@ jobs: checks: uses: Workiva/gha-dart-oss/.github/workflows/checks.yaml@v0.1.6 - sbom: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dart-lang/setup-dart@v1 - with: - sdk: 2.19.6 - - uses: anchore/sbom-action@v0 - with: - path: ./ - format: cyclonedx-json + build: + uses: Workiva/gha-dart-oss/.github/workflows/build.yaml@v0.1.6 snapshots: runs-on: ubuntu-latest diff --git a/lib/src/relationship_generator.dart b/lib/src/relationship_generator.dart index 922f803..ec3364e 100644 --- a/lib/src/relationship_generator.dart +++ b/lib/src/relationship_generator.dart @@ -35,29 +35,31 @@ List? relationshipsFor( // null, just fail fast if (parentElement == null) return null; - late final String name; - if (element is PropertyAccessorElement) { - name = element.variable.name; - } else { - name = element.name.toString(); + late final Iterable referencingElements; + if (element is MethodElement) { + referencingElements = parentElement.allSupertypes + .expand((type) => type.methods) + .where((type) => type.name == element.name); + } else if (element is FieldElement) { + referencingElements = parentElement.allSupertypes + .expand((type) => type.accessors) + .map((acc) => acc.variable) + .where((variable) => variable.name == element.name) + .toSet(); // remove any duplicates caused from synthetic getters/setters + } if (element is PropertyAccessorElement) { + referencingElements = parentElement.allSupertypes + .expand((type) => type.accessors) + .where((acc) => acc.isSetter == element.isSetter) + .where((acc) => acc.isGetter == element.isGetter) + .where((acc) => acc.variable.name == element.variable.name); } - // retrieve all of the methods and accessors of every parent type that - // has the same name of [node]. These are the elements that this [node] - // are overriding - final referencingElements = parentElement.allSupertypes - .map((type) => [...type.methods, ...type.accessors.map((a) => a.variable)]) - .expand((type) => type) - .where((type) => type.name == name); - - if (referencingElements.isNotEmpty) { - return referencingElements - .map((type) => Relationship( - symbol: symbolGenerator.symbolFor(type), - isImplementation: true, - isReference: true)) - .toList(); - } + return referencingElements + .map((type) => Relationship( + symbol: symbolGenerator.symbolFor(type), + isImplementation: true, + isReference: true)) + .toList(); } return null; diff --git a/snapshots/output/basic-project/lib/relationships.dart b/snapshots/output/basic-project/lib/relationships.dart index ddc72fc..dc6a8d9 100755 --- a/snapshots/output/basic-project/lib/relationships.dart +++ b/snapshots/output/basic-project/lib/relationships.dart @@ -26,7 +26,6 @@ String field = 'asdf'; // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# // ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Animal#field. -// relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#field. implementation reference // relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#field. implementation reference } @@ -50,8 +49,6 @@ // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# // ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Dog#field. // relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Animal#field. implementation reference -// relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Animal#field. implementation reference -// relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#field. implementation reference // relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#field. implementation reference @override @@ -66,13 +63,13 @@ String get someGetter => 'value'; // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# // ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Dog#`someGetter`. -// relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#someGetter. implementation reference +// relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#`someGetter`. implementation reference @override // ^^^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`annotations.dart`/override. set someSetter(String 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 +// 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 }