Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: pkg/analyzer/lib/src/summary/prelink.dart

Issue 1574053002: Move NameFilter to its own file so it can be conveniently reused. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/name_filter.dart ('k') | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/prelink.dart
diff --git a/pkg/analyzer/lib/src/summary/prelink.dart b/pkg/analyzer/lib/src/summary/prelink.dart
index 5a1cc93d8880a486143c16c5b628fa46ac174a5e..bfa20ca561ca292e9fad6bbda2d5a1172ba68219 100644
--- a/pkg/analyzer/lib/src/summary/prelink.dart
+++ b/pkg/analyzer/lib/src/summary/prelink.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/summary/format.dart';
+import 'package:analyzer/src/summary/name_filter.dart';
/**
* Create a [PrelinkedLibraryBuilder] corresponding to the given
@@ -40,95 +41,6 @@ typedef UnlinkedPublicNamespace GetImportCallback(String relativeUri);
typedef UnlinkedUnit GetPartCallback(String relativeUri);
/**
- * A [NameFilter] represents the set of filtering rules implied by zero or more
- * combinators in an `export` or `import` statement.
- */
-class NameFilter {
- /**
- * A [NameFilter] representing no filtering at all (i.e. no combinators).
- */
- static final NameFilter identity =
- new NameFilter._(hiddenNames: new Set<String>());
-
- /**
- * If this [NameFilter] accepts a finite number of names and hides all
- * others, the (possibly empty) set of names it accepts. Otherwise `null`.
- */
- final Set<String> shownNames;
-
- /**
- * If [shownNames] is `null`, the (possibly empty) set of names not accepted
- * by this filter (all other names are accepted). If [shownNames] is not
- * `null`, then [hiddenNames] will be `null`.
- */
- final Set<String> hiddenNames;
-
- /**
- * Create a [NameFilter] based on the given [combinator].
- */
- factory NameFilter.forCombinator(UnlinkedCombinator combinator) {
- if (combinator.shows.isNotEmpty) {
- return new NameFilter._(shownNames: combinator.shows.toSet());
- } else {
- return new NameFilter._(hiddenNames: combinator.hides.toSet());
- }
- }
-
- /**
- * Create a [NameFilter] based on the given (possibly empty) sequence of
- * [combinators].
- */
- factory NameFilter.forCombinators(List<UnlinkedCombinator> combinators) {
- NameFilter result = identity;
- for (UnlinkedCombinator combinator in combinators) {
- result = result.merge(new NameFilter.forCombinator(combinator));
- }
- return result;
- }
-
- const NameFilter._({this.shownNames, this.hiddenNames});
-
- /**
- * Determine if the given [name] is accepted by this [NameFilter].
- */
- bool accepts(String name) {
- if (name.endsWith('=')) {
- name = name.substring(0, name.length - 1);
- }
- if (shownNames != null) {
- return shownNames.contains(name);
- } else {
- return !hiddenNames.contains(name);
- }
- }
-
- /**
- * Produce a new [NameFilter] by combining this [NameFilter] with another
- * one. The new [NameFilter] will only accept names that would be accepted
- * by both input filters.
- */
- NameFilter merge(NameFilter other) {
- if (shownNames != null) {
- if (other.shownNames != null) {
- return new NameFilter._(
- shownNames: shownNames.intersection(other.shownNames));
- } else {
- return new NameFilter._(
- shownNames: shownNames.difference(other.hiddenNames));
- }
- } else {
- if (other.shownNames != null) {
- return new NameFilter._(
- shownNames: other.shownNames.difference(hiddenNames));
- } else {
- return new NameFilter._(
- hiddenNames: hiddenNames.union(other.hiddenNames));
- }
- }
- }
-}
-
-/**
* A [_Meaning] stores all the information necessary to find the declaration
* referred to by a name in a namespace.
*/
@@ -290,7 +202,8 @@ class _Prelinker {
}
});
chaseExports(
- filter.merge(new NameFilter.forCombinators(export.combinators)),
+ filter.merge(
+ new NameFilter.forUnlinkedCombinators(export.combinators)),
exportUri,
seenUris);
}
@@ -347,7 +260,7 @@ class _Prelinker {
void filterExportNamespace(String relativeUri,
List<UnlinkedCombinator> combinators, Map<String, _Meaning> result) {
Map<String, _Meaning> exportNamespace = computeExportNamespace(relativeUri);
- NameFilter filter = new NameFilter.forCombinators(combinators);
+ NameFilter filter = new NameFilter.forUnlinkedCombinators(combinators);
exportNamespace.forEach((String name, _Meaning meaning) {
if (filter.accepts(name) && !result.containsKey(name)) {
result[name] = meaning;
« no previous file with comments | « pkg/analyzer/lib/src/summary/name_filter.dart ('k') | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698