Skip to content

Commit

Permalink
fixed relationships for setters
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewnitschke-wk committed Sep 27, 2024
1 parent ee367f4 commit 55a838d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,8 @@ jobs:
checks:
uses: Workiva/gha-dart-oss/.github/workflows/[email protected]

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/[email protected]

snapshots:
runs-on: ubuntu-latest
Expand Down
44 changes: 23 additions & 21 deletions lib/src/relationship_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,31 @@ List<Relationship>? 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<Element> 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;
Expand Down
7 changes: 2 additions & 5 deletions snapshots/output/basic-project/lib/relationships.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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#`<get>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#`<get>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#`<set>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#`<set>someSetter`. implementation reference
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String#
// ^ definition local 1
}

0 comments on commit 55a838d

Please sign in to comment.