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

Unified Diff: pkg/analyzer/lib/src/task/strong_mode.dart

Issue 1320923003: Implement a task to compute the dependencies between static variables (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 4 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/task/dart.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/strong_mode.dart
diff --git a/pkg/analyzer/lib/src/task/strong_mode.dart b/pkg/analyzer/lib/src/task/strong_mode.dart
index 823319893f36c3e1831fe4786ed144c8a8f823e0..afa5261b0f5a958b545bb76007e255a1cb4190ac 100644
--- a/pkg/analyzer/lib/src/task/strong_mode.dart
+++ b/pkg/analyzer/lib/src/task/strong_mode.dart
@@ -8,10 +8,17 @@ import 'dart:collection';
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/resolver.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
/**
+ * A function that returns `true` if the given [variable] passes the filter.
+ */
+typedef bool VariableFilter(VariableElement element);
+
+/**
* An object used to find static variables whose types should be inferred and
* classes whose members should have types inferred. Clients are expected to
* visit a [CompilationUnit].
@@ -79,7 +86,10 @@ class InferrenceFinder extends SimpleAstVisitor {
void _addVariables(NodeList<VariableDeclaration> variables) {
for (VariableDeclaration variable in variables) {
if (variable.initializer != null) {
- staticVariables.add(variable.element);
+ VariableElement element = variable.element;
+ if (element.hasImplicitType) {
+ staticVariables.add(element);
+ }
}
}
}
@@ -529,6 +539,43 @@ class InstanceMemberInferrer {
}
/**
+ * A visitor that will gather all of the variables referenced within a given
+ * AST structure. The collection can be restricted to contain only those
+ * variables that pass a specified filter.
+ */
+class VariableGatherer extends RecursiveAstVisitor {
+ /**
+ * The filter used to limit which variables are gathered, or `null` if no
+ * filtering is to be performed.
+ */
+ final VariableFilter filter;
+
+ /**
+ * The variables that were found.
+ */
+ final Set<VariableElement> results = new HashSet<VariableElement>();
+
+ /**
+ * Initialize a newly created gatherer to gather all of the variables that
+ * pass the given [filter] (or all variables if no filter is provided).
+ */
+ VariableGatherer([this.filter = null]);
+
+ @override
+ void visitSimpleIdentifier(SimpleIdentifier node) {
+ if (!node.inDeclarationContext()) {
+ Element element = node.staticElement;
+ if (element is PropertyAccessorElement && element.isSynthetic) {
+ element = (element as PropertyAccessorElement).variable;
+ }
+ if (element is VariableElement && (filter == null || filter(element))) {
+ results.add(element);
+ }
+ }
+ }
+}
+
+/**
* A class of exception that is not used anywhere else.
*/
class _CycleException implements Exception {}
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698