-
Notifications
You must be signed in to change notification settings - Fork 2
FEA-2017: Relationships #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
92fa8d3
spike implementation of relationships
matthewnitschke-wk 4e8b0bf
fmt
matthewnitschke-wk 1a8a182
spiked implementation for method relationships
matthewnitschke-wk ee5d762
regen snaps
matthewnitschke-wk a2640da
added example
matthewnitschke-wk da55b6b
cleaned up implementation to be specific to classes
matthewnitschke-wk 019346e
removed unused import
matthewnitschke-wk 073dcf3
fixed versions used in CI
matthewnitschke-wk 358bbd1
removed unused file
matthewnitschke-wk 98535d8
updated readme
matthewnitschke-wk 3628812
added entity to symbols indexed for relationships
matthewnitschke-wk 13b2278
fmt
matthewnitschke-wk 780d455
Merge branch 'master' of github.com:Workiva/scip-dart into relationships
bender-wk c34589a
removed unused import
matthewnitschke-wk 0ef2de7
Merge branch 'relationships' of github.com:Workiva/scip-dart into rel…
matthewnitschke-wk 71e70f5
resolved confliucts
matthewnitschke-wk cdafd9c
resolved conflicts
matthewnitschke-wk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:analyzer/dart/element/element.dart'; | ||
import 'package:scip_dart/src/gen/scip.pbserver.dart'; | ||
import 'package:scip_dart/src/symbol_generator.dart'; | ||
|
||
List<Relationship>? relationshipsFor( | ||
Declaration node, | ||
Element element, | ||
SymbolGenerator symbolGenerator, | ||
) { | ||
// Only classes have relationships. Mixins and enums do not support | ||
// inheritance themselves and therefore do not have any relationships | ||
// to define. | ||
if (element is ClassElement) { | ||
// All things inherit from Object, if they have one supertype | ||
// there are no relationships | ||
if (element.allSupertypes.length <= 1) return null; | ||
|
||
return element.allSupertypes | ||
.where((type) => !type.isDartCoreObject) | ||
.map((type) => Relationship( | ||
symbol: symbolGenerator.symbolFor(type.element), | ||
isImplementation: true, | ||
)) | ||
.toList(); | ||
} | ||
|
||
// Since mixins do not support inheritance, we only care about | ||
// methods that exist on classes | ||
if (node is MethodDeclaration && node.parent is ClassDeclaration) { | ||
final parentNode = node.parent as ClassDeclaration; | ||
final parentElement = parentNode.declaredElement as ClassElement; | ||
|
||
// 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]) | ||
.expand((type) => type) | ||
.where((type) => type.name == node.name.toString()); | ||
|
||
if (referencingElements.isNotEmpty) { | ||
return referencingElements | ||
.map((type) => Relationship( | ||
symbol: symbolGenerator.symbolFor(type), | ||
isImplementation: true, | ||
isReference: true)) | ||
.toList(); | ||
} | ||
} | ||
|
||
return null; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
abstract class Mammal { | ||
String get hierarchy; | ||
} | ||
|
||
abstract class Animal extends Mammal { | ||
String sound() => 'NOISE!'; | ||
} | ||
|
||
mixin SwimAction { | ||
void execute() => print('swimming...'); | ||
} | ||
|
||
class Dog extends Animal with SwimAction { | ||
@override | ||
String sound() => 'woof'; | ||
|
||
@override | ||
String get hierarchy => 'dog.animal.mammal'; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
abstract class Mammal { | ||
// definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/ | ||
// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/Mammal# | ||
// documentation ```dart | ||
String get hierarchy; | ||
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# | ||
// ^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/Mammal#hierarchy. | ||
// documentation ```dart | ||
} | ||
|
||
abstract class Animal extends Mammal { | ||
// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/Animal# | ||
// documentation ```dart | ||
// relationship scip-dart pub dart_test 1.0.0 lib/relationships.dart/Mammal# implementation | ||
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/relationships.dart/Mammal# | ||
String sound() => 'NOISE!'; | ||
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# | ||
// ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/Animal#sound(). | ||
// documentation ```dart | ||
} | ||
|
||
mixin SwimAction { | ||
// ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/SwimAction# | ||
// documentation ```dart | ||
void execute() => print('swimming...'); | ||
// ^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/SwimAction#execute(). | ||
// documentation ```dart | ||
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print(). | ||
} | ||
|
||
class Dog extends Animal with SwimAction { | ||
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/Dog# | ||
// documentation ```dart | ||
// relationship scip-dart pub dart_test 1.0.0 lib/relationships.dart/Animal# implementation | ||
// relationship scip-dart pub dart_test 1.0.0 lib/relationships.dart/Mammal# implementation | ||
// relationship scip-dart pub dart_test 1.0.0 lib/relationships.dart/SwimAction# implementation | ||
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/relationships.dart/Animal# | ||
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/relationships.dart/SwimAction# | ||
@override | ||
// ^^^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/annotations.dart/override. | ||
String sound() => 'woof'; | ||
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# | ||
// ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/Dog#sound(). | ||
// documentation ```dart | ||
// relationship scip-dart pub dart_test 1.0.0 lib/relationships.dart/Animal#sound(). implementation reference | ||
|
||
@override | ||
// ^^^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/annotations.dart/override. | ||
String get hierarchy => 'dog.animal.mammal'; | ||
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# | ||
// ^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/relationships.dart/Dog#hierarchy. | ||
// documentation ```dart | ||
// relationship scip-dart pub dart_test 1.0.0 lib/relationships.dart/Mammal#hierarchy. implementation reference | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a class has any supertypes, all of those supertypes (
allSupertypes
refers to every super type, including super types of super types) are relationships