| 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 {}
|
|
|