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

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

Issue 1289283004: Initial steps toward adding strong mode to the new task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: 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
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
new file mode 100644
index 0000000000000000000000000000000000000000..f92da0b2c4c11e76e8be9e66cb6b80f91b1ec124
--- /dev/null
+++ b/pkg/analyzer/lib/src/task/strong_mode.dart
@@ -0,0 +1,82 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library analyzer.src.task.strong_mode;
+
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/element.dart';
+
+/**
+ * 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].
+ */
+class InferrenceFinder extends SimpleAstVisitor {
+ /**
+ * The static variables that should have types inferred for them.
+ */
+ final List<VariableElement> staticVariables = <VariableElement>[];
+
+ /**
+ * The classes defined in the unit.
+ *
+ * TODO(brianwilkerson) We don't currently remove classes whose members do not
+ * need to be processed, but we potentially could.
+ */
+ final List<ClassElement> classes = <ClassElement>[];
+
+ /**
+ * Initialize a newly created finder.
+ */
+ InferrenceFinder();
+
+ @override
+ void visitClassDeclaration(ClassDeclaration node) {
+ classes.add(node.element);
+ for (ClassMember member in node.members) {
+ member.accept(this);
+ }
+ }
+
+ @override
+ void visitClassTypeAlias(ClassTypeAlias node) {
+ classes.add(node.element);
+ }
+
+ @override
+ void visitCompilationUnit(CompilationUnit node) {
+ for (CompilationUnitMember declaration in node.declarations) {
+ declaration.accept(this);
+ }
+ }
+
+ @override
+ void visitFieldDeclaration(FieldDeclaration node) {
+ if (node.isStatic && node.fields.type == null) {
+ _addVariables(node.fields.variables);
+ }
+ }
+
+ @override
+ void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
+ if (node.variables.type == null) {
+ _addVariables(node.variables.variables);
+ }
+ }
+
+ /**
+ * Add all of the [variables] with initializers to the list of variables whose
+ * type can be inferred. Technically, we only infer the types of variables
+ * that do not have a static type, but all variables with initializers
+ * potentially need to be re-resolved after inference because they might
+ * refer to fields whose type was inferred.
+ */
+ void _addVariables(NodeList<VariableDeclaration> variables) {
+ for (VariableDeclaration variable in variables) {
+ if (variable.initializer != null) {
+ staticVariables.add(variable.element);
+ }
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698