-
Notifications
You must be signed in to change notification settings - Fork 125
Deemphasize reexported symbols [#1158] #1319
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
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'package:analyzer/dart/element/element.dart'; | ||
|
||
/// Node in the directed export graph. | ||
/// | ||
/// It wraps a library element, and also contains links to the nodes/libs, which export this lib, | ||
/// and nodes/libs, which are exported by this lib. | ||
class _ExportGraphNode { | ||
final LibraryElement libraryElement; | ||
Set<_ExportGraphNode> exportedBy = new Set(); | ||
Set<_ExportGraphNode> exports = new Set(); | ||
|
||
_ExportGraphNode(this.libraryElement); | ||
|
||
/// It returns a "canonical" library element | ||
/// | ||
/// That's one of the passed in the arguments, which is the closest if we go up the graph. | ||
_ExportGraphNode canonicalLibraryElement(Iterable<LibraryElement> libraryElements) { | ||
if (libraryElements.contains(libraryElement)) { | ||
return this; | ||
} else { | ||
return exportedBy.toList().firstWhere((l) => l.canonicalLibraryElement(libraryElements) != null); | ||
} | ||
} | ||
} | ||
|
||
/// Recursively builds the export graph, and also populates the index [map]. It takes | ||
/// the library element from the arguments, adds it to the index, then goes through all | ||
/// the libraries this library element exports, adds them to the index too and also connects | ||
/// them to build a graph. | ||
void _buildSubGraph(Map<String, _ExportGraphNode> map, LibraryElement libraryElement) { | ||
if (!map.containsKey(libraryElement.source.fullName)) { | ||
map[libraryElement.source.fullName] = new _ExportGraphNode(libraryElement); | ||
} | ||
final node = map[libraryElement.source.fullName]; | ||
libraryElement.exports.forEach((ExportElement export) { | ||
final exportedLibraryElement = export.exportedLibrary; | ||
if (!map.containsKey(exportedLibraryElement.source.fullName)) { | ||
map[exportedLibraryElement.source.fullName] = new _ExportGraphNode(exportedLibraryElement); | ||
} | ||
final childNode = map[exportedLibraryElement.source.fullName]; | ||
childNode.exportedBy.add(node); | ||
node.exports.add(childNode); | ||
_buildSubGraph(map, exportedLibraryElement); | ||
}); | ||
} | ||
|
||
/// Directed graph, which allows to track what libs export and being exported by what libs | ||
/// (where libs are the documentable package libraries). | ||
/// | ||
/// Also, allows to find the "canonical" library element for the provided element, i.e. the | ||
/// one, which should contain documentation of the provided element. | ||
class ExportGraph { | ||
final Map<String, _ExportGraphNode> map = {}; | ||
final Iterable<LibraryElement> packageLibraryElements; | ||
|
||
ExportGraph(this.packageLibraryElements) { | ||
packageLibraryElements.forEach((LibraryElement libraryElement) { | ||
_buildSubGraph(map, libraryElement); | ||
}); | ||
} | ||
|
||
LibraryElement canonicalLibraryElement(Element element) { | ||
if (map.containsKey(element.library.source.fullName)) { | ||
final node = map[element.library.source.fullName]; | ||
return node.canonicalLibraryElement(packageLibraryElements)?.libraryElement; | ||
} else { | ||
return element.library; | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.
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.
Please add comments to methods to explain functionality.