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

Unified Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 2330803002: Remove IncrementalScanner and IncrementalParser. (Closed)
Patch Set: Created 4 years, 3 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/generated/parser.dart
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index 21327613f0d5f99eed7583ac26797b31dca3b35e..8e7bbe183cd00f3c6b07718bf878abdd9f03d63c 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -9,10 +9,8 @@ import "dart:math" as math;
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
-import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/token.dart';
-import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/scanner/reader.dart';
import 'package:analyzer/src/dart/scanner/scanner.dart';
import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
@@ -22,7 +20,6 @@ import 'package:analyzer/src/generated/generated/shared_messages.dart'
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/source.dart';
-import 'package:analyzer/src/generated/utilities_collection.dart' show TokenMap;
import 'package:analyzer/src/generated/utilities_dart.dart';
export 'package:analyzer/src/dart/ast/utilities.dart' show ResolutionCopier;
@@ -534,1432 +531,6 @@ class FinalConstVarOrType {
}
/**
- * A dispatcher that will invoke the right parse method when re-parsing a
- * specified child of the visited node. All of the methods in this class assume
- * that the parser is positioned to parse the replacement for the node. All of
- * the methods will throw an [IncrementalParseException] if the node could not
- * be parsed for some reason.
- */
-@deprecated
-class IncrementalParseDispatcher implements AstVisitor<AstNode> {
- /**
- * The parser used to parse the replacement for the node.
- */
- final Parser _parser;
-
- /**
- * The node that is to be replaced.
- */
- final AstNode _oldNode;
-
- /**
- * Initialize a newly created dispatcher to parse a single node that will
- * use the [_parser] to replace the [_oldNode].
- */
- IncrementalParseDispatcher(this._parser, this._oldNode);
-
- @override
- AstNode visitAdjacentStrings(AdjacentStrings node) {
- if (node.strings.contains(_oldNode)) {
- return _parser.parseStringLiteral();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitAnnotation(Annotation node) {
- if (identical(_oldNode, node.name)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.constructorName)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.arguments)) {
- return _parser.parseArgumentList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitArgumentList(ArgumentList node) {
- if (node.arguments.contains(_oldNode)) {
- return _parser.parseArgument();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitAsExpression(AsExpression node) {
- if (identical(_oldNode, node.expression)) {
- return _parser.parseBitwiseOrExpression();
- } else if (identical(_oldNode, node.type)) {
- return _parser.parseTypeName();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitAssertStatement(AssertStatement node) {
- if (identical(_oldNode, node.condition)) {
- return _parser.parseExpression2();
- }
- if (identical(_oldNode, node.message)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitAssignmentExpression(AssignmentExpression node) {
- if (identical(_oldNode, node.leftHandSide)) {
- // TODO(brianwilkerson) If the assignment is part of a cascade section,
- // then we don't have a single parse method that will work.
- // Otherwise, we can parse a conditional expression, but need to ensure
- // that the resulting expression is assignable.
-// return parser.parseConditionalExpression();
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.rightHandSide)) {
- if (_isCascadeAllowedInAssignment(node)) {
- return _parser.parseExpression2();
- }
- return _parser.parseExpressionWithoutCascade();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitAwaitExpression(AwaitExpression node) {
- if (identical(_oldNode, node.expression)) {
- // TODO(brianwilkerson) Depending on precedence,
- // this might not be sufficient.
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitBinaryExpression(BinaryExpression node) {
- if (identical(_oldNode, node.leftOperand)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.rightOperand)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitBlock(Block node) {
- if (node.statements.contains(_oldNode)) {
- return _parser.parseStatement2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitBlockFunctionBody(BlockFunctionBody node) {
- if (identical(_oldNode, node.block)) {
- return _parser.parseBlock();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitBooleanLiteral(BooleanLiteral node) => _notAChild(node);
-
- @override
- AstNode visitBreakStatement(BreakStatement node) {
- if (identical(_oldNode, node.label)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitCascadeExpression(CascadeExpression node) {
- if (identical(_oldNode, node.target)) {
- return _parser.parseConditionalExpression();
- } else if (node.cascadeSections.contains(_oldNode)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitCatchClause(CatchClause node) {
- if (identical(_oldNode, node.exceptionType)) {
- return _parser.parseTypeName();
- } else if (identical(_oldNode, node.exceptionParameter)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.stackTraceParameter)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.body)) {
- return _parser.parseBlock();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitClassDeclaration(ClassDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.name)) {
- // Changing the class name changes whether a member is interpreted as a
- // constructor or not, so we'll just have to re-parse the entire class.
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.typeParameters)) {
- return _parser.parseTypeParameterList();
- } else if (identical(_oldNode, node.extendsClause)) {
- return _parser.parseExtendsClause();
- } else if (identical(_oldNode, node.withClause)) {
- return _parser.parseWithClause();
- } else if (identical(_oldNode, node.implementsClause)) {
- return _parser.parseImplementsClause();
- } else if (node.members.contains(_oldNode)) {
- ClassMember member = _parser.parseClassMember(node.name.name);
- if (member == null) {
- throw new InsufficientContextException();
- }
- return member;
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitClassTypeAlias(ClassTypeAlias node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.name)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.typeParameters)) {
- return _parser.parseTypeParameterList();
- } else if (identical(_oldNode, node.superclass)) {
- return _parser.parseTypeName();
- } else if (identical(_oldNode, node.withClause)) {
- return _parser.parseWithClause();
- } else if (identical(_oldNode, node.implementsClause)) {
- return _parser.parseImplementsClause();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitComment(Comment node) {
- throw new InsufficientContextException();
- }
-
- @override
- AstNode visitCommentReference(CommentReference node) {
- if (identical(_oldNode, node.identifier)) {
- return _parser.parsePrefixedIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitCompilationUnit(CompilationUnit node) {
- throw new InsufficientContextException();
- }
-
- @override
- AstNode visitConditionalExpression(ConditionalExpression node) {
- if (identical(_oldNode, node.condition)) {
- return _parser.parseIfNullExpression();
- } else if (identical(_oldNode, node.thenExpression)) {
- return _parser.parseExpressionWithoutCascade();
- } else if (identical(_oldNode, node.elseExpression)) {
- return _parser.parseExpressionWithoutCascade();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitConfiguration(Configuration node) {
- if (identical(_oldNode, node.name)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.value)) {
- return _parser.parseStringLiteral();
- } else if (identical(_oldNode, node.libraryUri)) {
- return _parser.parseStringLiteral();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitConstructorDeclaration(ConstructorDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.returnType)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.name)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.parameters)) {
- return _parser.parseFormalParameterList();
- } else if (identical(_oldNode, node.redirectedConstructor)) {
- throw new InsufficientContextException();
- } else if (node.initializers.contains(_oldNode)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.body)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
- if (identical(_oldNode, node.fieldName)) {
- return _parser.parseSimpleIdentifier();
- } else if (identical(_oldNode, node.expression)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitConstructorName(ConstructorName node) {
- if (identical(_oldNode, node.type)) {
- return _parser.parseTypeName();
- } else if (identical(_oldNode, node.name)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitContinueStatement(ContinueStatement node) {
- if (identical(_oldNode, node.label)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitDeclaredIdentifier(DeclaredIdentifier node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.type)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.identifier)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitDefaultFormalParameter(DefaultFormalParameter node) {
- if (identical(_oldNode, node.parameter)) {
- return _parser.parseNormalFormalParameter();
- } else if (identical(_oldNode, node.defaultValue)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitDoStatement(DoStatement node) {
- if (identical(_oldNode, node.body)) {
- return _parser.parseStatement2();
- } else if (identical(_oldNode, node.condition)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitDottedName(DottedName node) {
- if (node.components.contains(_oldNode)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitDoubleLiteral(DoubleLiteral node) => _notAChild(node);
-
- @override
- AstNode visitEmptyFunctionBody(EmptyFunctionBody node) => _notAChild(node);
-
- @override
- AstNode visitEmptyStatement(EmptyStatement node) => _notAChild(node);
-
- @override
- AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.name)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitEnumDeclaration(EnumDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.name)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (node.constants.contains(_oldNode)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitExportDirective(ExportDirective node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.uri)) {
- return _parser.parseStringLiteral();
- } else if (node.combinators.contains(_oldNode)) {
- throw new IncrementalParseException();
- //return parser.parseCombinator();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitExpressionFunctionBody(ExpressionFunctionBody node) {
- if (identical(_oldNode, node.expression)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitExpressionStatement(ExpressionStatement node) {
- if (identical(_oldNode, node.expression)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitExtendsClause(ExtendsClause node) {
- if (identical(_oldNode, node.superclass)) {
- return _parser.parseTypeName();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFieldDeclaration(FieldDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.fields)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFieldFormalParameter(FieldFormalParameter node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.type)) {
- return _parser.parseTypeName();
- } else if (identical(_oldNode, node.identifier)) {
- return _parser.parseSimpleIdentifier();
- } else if (identical(_oldNode, node.parameters)) {
- return _parser.parseFormalParameterList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitForEachStatement(ForEachStatement node) {
- if (identical(_oldNode, node.loopVariable)) {
- throw new InsufficientContextException();
- //return parser.parseDeclaredIdentifier();
- } else if (identical(_oldNode, node.identifier)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.body)) {
- return _parser.parseStatement2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFormalParameterList(FormalParameterList node) {
- // We don't know which kind of parameter to parse.
- throw new InsufficientContextException();
- }
-
- @override
- AstNode visitForStatement(ForStatement node) {
- if (identical(_oldNode, node.variables)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.initialization)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.condition)) {
- return _parser.parseExpression2();
- } else if (node.updaters.contains(_oldNode)) {
- return _parser.parseExpression2();
- } else if (identical(_oldNode, node.body)) {
- return _parser.parseStatement2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFunctionDeclaration(FunctionDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.returnType)) {
- return _parser.parseReturnType();
- } else if (identical(_oldNode, node.name)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.functionExpression)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
- if (identical(_oldNode, node.functionDeclaration)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFunctionExpression(FunctionExpression node) {
- if (identical(_oldNode, node.parameters)) {
- return _parser.parseFormalParameterList();
- } else if (identical(_oldNode, node.body)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
- if (identical(_oldNode, node.function)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.argumentList)) {
- return _parser.parseArgumentList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFunctionTypeAlias(FunctionTypeAlias node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.returnType)) {
- return _parser.parseReturnType();
- } else if (identical(_oldNode, node.name)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.typeParameters)) {
- return _parser.parseTypeParameterList();
- } else if (identical(_oldNode, node.parameters)) {
- return _parser.parseFormalParameterList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.returnType)) {
- return _parser.parseReturnType();
- } else if (identical(_oldNode, node.identifier)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.parameters)) {
- return _parser.parseFormalParameterList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitHideCombinator(HideCombinator node) {
- if (node.hiddenNames.contains(_oldNode)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitIfStatement(IfStatement node) {
- if (identical(_oldNode, node.condition)) {
- return _parser.parseExpression2();
- } else if (identical(_oldNode, node.thenStatement)) {
- return _parser.parseStatement2();
- } else if (identical(_oldNode, node.elseStatement)) {
- return _parser.parseStatement2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitImplementsClause(ImplementsClause node) {
- if (node.interfaces.contains(node)) {
- return _parser.parseTypeName();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitImportDirective(ImportDirective node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.uri)) {
- return _parser.parseStringLiteral();
- } else if (identical(_oldNode, node.prefix)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (node.combinators.contains(_oldNode)) {
- return _parser.parseCombinator();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitIndexExpression(IndexExpression node) {
- if (identical(_oldNode, node.target)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.index)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitInstanceCreationExpression(InstanceCreationExpression node) {
- if (identical(_oldNode, node.constructorName)) {
- return _parser.parseConstructorName();
- } else if (identical(_oldNode, node.argumentList)) {
- return _parser.parseArgumentList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitIntegerLiteral(IntegerLiteral node) => _notAChild(node);
-
- @override
- AstNode visitInterpolationExpression(InterpolationExpression node) {
- if (identical(_oldNode, node.expression)) {
- if (node.leftBracket == null) {
- throw new InsufficientContextException();
- //return parser.parseThisOrSimpleIdentifier();
- }
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitInterpolationString(InterpolationString node) {
- throw new InsufficientContextException();
- }
-
- @override
- AstNode visitIsExpression(IsExpression node) {
- if (identical(_oldNode, node.expression)) {
- return _parser.parseBitwiseOrExpression();
- } else if (identical(_oldNode, node.type)) {
- return _parser.parseTypeName();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitLabel(Label node) {
- if (identical(_oldNode, node.label)) {
- return _parser.parseSimpleIdentifier(
- isDeclaration: node.parent is LabeledStatement);
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitLabeledStatement(LabeledStatement node) {
- if (node.labels.contains(_oldNode)) {
- return _parser.parseLabel(isDeclaration: true);
- } else if (identical(_oldNode, node.statement)) {
- return _parser.parseStatement2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitLibraryDirective(LibraryDirective node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.name)) {
- return _parser.parseLibraryIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitLibraryIdentifier(LibraryIdentifier node) {
- if (node.components.contains(_oldNode)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitListLiteral(ListLiteral node) {
- if (identical(_oldNode, node.typeArguments)) {
- return _parser.parseTypeArgumentList();
- } else if (node.elements.contains(_oldNode)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitMapLiteral(MapLiteral node) {
- if (identical(_oldNode, node.typeArguments)) {
- return _parser.parseTypeArgumentList();
- } else if (node.entries.contains(_oldNode)) {
- return _parser.parseMapLiteralEntry();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitMapLiteralEntry(MapLiteralEntry node) {
- if (identical(_oldNode, node.key)) {
- return _parser.parseExpression2();
- } else if (identical(_oldNode, node.value)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitMethodDeclaration(MethodDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.returnType)) {
- throw new InsufficientContextException();
- //return parser.parseTypeName();
- //return parser.parseReturnType();
- } else if (identical(_oldNode, node.name)) {
- if (node.operatorKeyword != null) {
- throw new InsufficientContextException();
- }
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.body)) {
- //return parser.parseFunctionBody();
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.parameters)) {
- // TODO(paulberry): if we want errors to be correct, we'll need to also
- // call _validateFormalParameterList, and sometimes
- // _validateModifiersForGetterOrSetterOrMethod.
- return _parser.parseFormalParameterList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitMethodInvocation(MethodInvocation node) {
- if (identical(_oldNode, node.target)) {
- throw new IncrementalParseException();
- } else if (identical(_oldNode, node.methodName)) {
- return _parser.parseSimpleIdentifier();
- } else if (identical(_oldNode, node.argumentList)) {
- return _parser.parseArgumentList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitNamedExpression(NamedExpression node) {
- if (identical(_oldNode, node.name)) {
- return _parser.parseLabel();
- } else if (identical(_oldNode, node.expression)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitNativeClause(NativeClause node) {
- if (identical(_oldNode, node.name)) {
- return _parser.parseStringLiteral();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitNativeFunctionBody(NativeFunctionBody node) {
- if (identical(_oldNode, node.stringLiteral)) {
- return _parser.parseStringLiteral();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitNullLiteral(NullLiteral node) => _notAChild(node);
-
- @override
- AstNode visitParenthesizedExpression(ParenthesizedExpression node) {
- if (identical(_oldNode, node.expression)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitPartDirective(PartDirective node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.uri)) {
- return _parser.parseStringLiteral();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitPartOfDirective(PartOfDirective node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.libraryName)) {
- return _parser.parseLibraryIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitPostfixExpression(PostfixExpression node) {
- if (identical(_oldNode, node.operand)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitPrefixedIdentifier(PrefixedIdentifier node) {
- if (identical(_oldNode, node.prefix)) {
- return _parser.parseSimpleIdentifier();
- } else if (identical(_oldNode, node.identifier)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitPrefixExpression(PrefixExpression node) {
- if (identical(_oldNode, node.operand)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitPropertyAccess(PropertyAccess node) {
- if (identical(_oldNode, node.target)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.propertyName)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitRedirectingConstructorInvocation(
- RedirectingConstructorInvocation node) {
- if (identical(_oldNode, node.constructorName)) {
- return _parser.parseSimpleIdentifier();
- } else if (identical(_oldNode, node.argumentList)) {
- return _parser.parseArgumentList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitRethrowExpression(RethrowExpression node) => _notAChild(node);
-
- @override
- AstNode visitReturnStatement(ReturnStatement node) {
- if (identical(_oldNode, node.expression)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitScriptTag(ScriptTag node) => _notAChild(node);
-
- @override
- AstNode visitShowCombinator(ShowCombinator node) {
- if (node.shownNames.contains(_oldNode)) {
- return _parser.parseSimpleIdentifier();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitSimpleFormalParameter(SimpleFormalParameter node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.type)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.identifier)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitSimpleIdentifier(SimpleIdentifier node) => _notAChild(node);
-
- @override
- AstNode visitSimpleStringLiteral(SimpleStringLiteral node) =>
- _notAChild(node);
-
- @override
- AstNode visitStringInterpolation(StringInterpolation node) {
- if (node.elements.contains(_oldNode)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitSuperConstructorInvocation(SuperConstructorInvocation node) {
- if (identical(_oldNode, node.constructorName)) {
- return _parser.parseSimpleIdentifier();
- } else if (identical(_oldNode, node.argumentList)) {
- return _parser.parseArgumentList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitSuperExpression(SuperExpression node) => _notAChild(node);
-
- @override
- AstNode visitSwitchCase(SwitchCase node) {
- if (node.labels.contains(_oldNode)) {
- return _parser.parseLabel();
- } else if (identical(_oldNode, node.expression)) {
- return _parser.parseExpression2();
- } else if (node.statements.contains(_oldNode)) {
- return _parser.parseStatement2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitSwitchDefault(SwitchDefault node) {
- if (node.labels.contains(_oldNode)) {
- return _parser.parseLabel();
- } else if (node.statements.contains(_oldNode)) {
- return _parser.parseStatement2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitSwitchStatement(SwitchStatement node) {
- if (identical(_oldNode, node.expression)) {
- return _parser.parseExpression2();
- } else if (node.members.contains(_oldNode)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitSymbolLiteral(SymbolLiteral node) => _notAChild(node);
-
- @override
- AstNode visitThisExpression(ThisExpression node) => _notAChild(node);
-
- @override
- AstNode visitThrowExpression(ThrowExpression node) {
- if (identical(_oldNode, node.expression)) {
- if (_isCascadeAllowedInThrow(node)) {
- return _parser.parseExpression2();
- }
- return _parser.parseExpressionWithoutCascade();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.variables)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitTryStatement(TryStatement node) {
- if (identical(_oldNode, node.body)) {
- return _parser.parseBlock();
- } else if (node.catchClauses.contains(_oldNode)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.finallyBlock)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitTypeArgumentList(TypeArgumentList node) {
- if (node.arguments.contains(_oldNode)) {
- return _parser.parseTypeName();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitTypeName(TypeName node) {
- if (identical(_oldNode, node.name)) {
- return _parser.parsePrefixedIdentifier();
- } else if (identical(_oldNode, node.typeArguments)) {
- return _parser.parseTypeArgumentList();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitTypeParameter(TypeParameter node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.name)) {
- return _parser.parseSimpleIdentifier(isDeclaration: true);
- } else if (identical(_oldNode, node.bound)) {
- return _parser.parseTypeName();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitTypeParameterList(TypeParameterList node) {
- if (node.typeParameters.contains(node)) {
- return _parser.parseTypeParameter();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitVariableDeclaration(VariableDeclaration node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.name)) {
- throw new InsufficientContextException();
- } else if (identical(_oldNode, node.initializer)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitVariableDeclarationList(VariableDeclarationList node) {
- if (identical(_oldNode, node.documentationComment)) {
- throw new InsufficientContextException();
- } else if (node.metadata.contains(_oldNode)) {
- return _parser.parseAnnotation();
- } else if (identical(_oldNode, node.type)) {
- // There is not enough context to know whether we should reparse the type
- // using parseReturnType() (which allows 'void') or parseTypeName()
- // (which doesn't). Note that even though the language disallows
- // variables of type 'void', the parser sometimes accepts them in the
- // course of error recovery (e.g. "class C { void v; }"
- throw new InsufficientContextException();
- } else if (node.variables.contains(_oldNode)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitVariableDeclarationStatement(VariableDeclarationStatement node) {
- if (identical(_oldNode, node.variables)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitWhileStatement(WhileStatement node) {
- if (identical(_oldNode, node.condition)) {
- return _parser.parseExpression2();
- } else if (identical(_oldNode, node.body)) {
- return _parser.parseStatement2();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitWithClause(WithClause node) {
- if (node.mixinTypes.contains(node)) {
- return _parser.parseTypeName();
- }
- return _notAChild(node);
- }
-
- @override
- AstNode visitYieldStatement(YieldStatement node) {
- if (identical(_oldNode, node.expression)) {
- return _parser.parseExpression2();
- }
- return _notAChild(node);
- }
-
- /**
- * Return `true` if the given assignment [expression] can have a cascade
- * expression on the right-hand side.
- */
- bool _isCascadeAllowedInAssignment(AssignmentExpression expression) {
- // TODO(brianwilkerson) Implement this method.
- throw new InsufficientContextException();
- }
-
- /**
- * Return `true` if the given throw [expression] can have a cascade
- * expression.
- */
- bool _isCascadeAllowedInThrow(ThrowExpression expression) {
- // TODO(brianwilkerson) Implement this method.
- throw new InsufficientContextException();
- }
-
- /**
- * Throw an exception indicating that the visited [node] was not the parent of
- * the node to be replaced.
- */
- AstNode _notAChild(AstNode node) {
- throw new IncrementalParseException(
- "Internal error: the visited node (a ${node.runtimeType}) was not the parent of the node to be replaced (a ${_oldNode.runtimeType})");
- }
-}
-
-/**
- * An exception that occurred while attempting to parse a replacement for a
- * specified node in an existing AST structure.
- */
-@deprecated
-class IncrementalParseException {
- final String message;
- IncrementalParseException([this.message = '']);
- String toString() => '$runtimeType: $message';
-}
-
-/**
- * An object used to re-parse a single AST structure within a larger AST
- * structure.
- */
-@deprecated
-class IncrementalParser {
- /**
- * The source being parsed.
- */
- final Source _source;
-
- /**
- * A map from old tokens to new tokens used during the cloning process.
- */
- final TokenMap _tokenMap;
-
- /**
- * The error listener that will be informed of any errors that are found
- * during the parse.
- */
- final AnalysisErrorListener _errorListener;
-
- /**
- * The node in the AST structure that contains the revised content.
- */
- AstNode _updatedNode;
-
- /**
- * Initialize a newly created incremental parser to parse a portion of the
- * content of the given [_source]. The [_tokenMap] is a map from old tokens to
- * new tokens that is used during the cloning process. The [_errorListener]
- * will be informed of any errors that are found during the parse.
- */
- IncrementalParser(this._source, this._tokenMap, this._errorListener);
-
- /**
- * Return the node in the AST structure that contains the revised content.
- */
- AstNode get updatedNode => _updatedNode;
-
- /**
- * Given a range of tokens that were re-scanned, re-parse the minimum number
- * of tokens to produce a consistent AST structure. The range is represented
- * by the first and last tokens in the range.
- *
- * More specifically, the [leftToken] is the token in the new token stream
- * immediately to the left of the range of tokens that were inserted and the
- * [rightToken] is the token in the new token stream immediately to the right
- * of the range of tokens that were inserted. The [originalStart] and
- * [originalEnd] are the offsets in the original source of the first and last
- * characters that were modified.
- *
- * The tokens are assumed to be contained in the same token stream.
- */
- AstNode reparse(AstNode originalStructure, Token leftToken, Token rightToken,
- int originalStart, int originalEnd) {
- AstNode oldNode = null;
- AstNode newNode = null;
- //
- // Find the first token that needs to be re-parsed.
- //
- Token firstToken = leftToken.next;
- if (identical(firstToken, rightToken)) {
- // If there are no new tokens, then we need to include at least one copied
- // node in the range.
- firstToken = leftToken;
- }
- //
- // Find the smallest AST node that encompasses the range of re-scanned
- // tokens.
- //
- if (originalEnd < originalStart) {
- oldNode = new NodeLocator(originalStart).searchWithin(originalStructure);
- } else {
- oldNode = new NodeLocator(originalStart, originalEnd)
- .searchWithin(originalStructure);
- }
- //
- // Find the token at which parsing is to begin.
- //
- int originalOffset = oldNode.offset;
- Token parseToken = _findTokenAt(firstToken, originalOffset);
- if (parseToken == null) {
- return null;
- }
- //
- // Parse the appropriate AST structure starting at the appropriate place.
- //
- Parser parser = new Parser(_source, _errorListener);
- parser.currentToken = parseToken;
- while (newNode == null) {
- AstNode parent = oldNode.parent;
- if (parent == null) {
- parseToken = _findFirstToken(parseToken);
- parser.currentToken = parseToken;
- return parser.parseCompilationUnit2();
- }
- bool advanceToParent = false;
- try {
- IncrementalParseDispatcher dispatcher =
- new IncrementalParseDispatcher(parser, oldNode);
- IncrementalParseStateBuilder contextBuilder =
- new IncrementalParseStateBuilder(parser);
- contextBuilder.buildState(oldNode);
- newNode = parent.accept(dispatcher);
- //
- // Validate that the new node can replace the old node.
- //
- Token mappedToken = _tokenMap.get(oldNode.endToken.next);
- if (mappedToken == null ||
- newNode == null ||
- mappedToken.offset != newNode.endToken.next.offset ||
- newNode.offset != oldNode.offset) {
- advanceToParent = true;
- }
- } on InsufficientContextException {
- advanceToParent = true;
- } catch (exception) {
- return null;
- }
- if (advanceToParent) {
- newNode = null;
- oldNode = parent;
- originalOffset = oldNode.offset;
- parseToken = _findTokenAt(parseToken, originalOffset);
- parser.currentToken = parseToken;
- }
- }
- _updatedNode = newNode;
- //
- // Replace the old node with the new node in a copy of the original AST
- // structure.
- //
- if (identical(oldNode, originalStructure)) {
- // We ended up re-parsing the whole structure, so there's no need for a
- // copy.
- ResolutionCopier.copyResolutionData(oldNode, newNode);
- return newNode;
- }
- ResolutionCopier.copyResolutionData(oldNode, newNode);
- IncrementalAstCloner cloner =
- new IncrementalAstCloner(oldNode, newNode, _tokenMap);
- return originalStructure.accept(cloner);
- }
-
- /**
- * Return the first (non-EOF) token in the token stream containing the
- * [firstToken].
- */
- Token _findFirstToken(Token firstToken) {
- while (firstToken.type != TokenType.EOF) {
- firstToken = firstToken.previous;
- }
- return firstToken.next;
- }
-
- /**
- * Find the token at or before the [firstToken] with the given [offset], or
- * `null` if there is no such token.
- */
- Token _findTokenAt(Token firstToken, int offset) {
- while (firstToken.offset > offset && firstToken.type != TokenType.EOF) {
- firstToken = firstToken.previous;
- }
- return firstToken;
- }
-}
-
-/**
- * A visitor capable of inferring the correct parser state for incremental
- * parsing. This visitor visits each parent/child relationship in the chain of
- * ancestors of the node to be replaced (starting with the root of the parse
- * tree), updating the parser to the correct state for parsing the child of the
- * given parent. Once it has visited all of these relationships, the parser
- * will be in the correct state for reparsing the node to be replaced.
- */
-@deprecated
-class IncrementalParseStateBuilder extends SimpleAstVisitor {
- // TODO(paulberry): add support for other pieces of parser state (_inAsync,
- // _inGenerator, _inLoop, and _inSwitch). Note that _inLoop and _inSwitch
- // only affect error message generation.
-
- /**
- * The parser whose state should be built.
- */
- final Parser _parser;
-
- /**
- * The child node in the parent/child relationship currently being visited.
- * (The corresponding parent is the node passed to the visit...() function.)
- */
- AstNode _childNode;
-
- /**
- * Create an IncrementalParseStateBuilder which will build the correct state
- * for [_parser].
- */
- IncrementalParseStateBuilder(this._parser);
-
- /**
- * Build the correct parser state for parsing a replacement for [node].
- */
- void buildState(AstNode node) {
- List<AstNode> ancestors = <AstNode>[];
- while (node != null) {
- ancestors.add(node);
- node = node.parent;
- }
- _parser._inInitializer = false;
- for (int i = ancestors.length - 2; i >= 0; i--) {
- _childNode = ancestors[i];
- ancestors[i + 1].accept(this);
- }
- }
-
- @override
- void visitArgumentList(ArgumentList node) {
- _parser._inInitializer = false;
- }
-
- @override
- void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
- if (identical(_childNode, node.expression)) {
- _parser._inInitializer = true;
- }
- }
-
- @override
- void visitIndexExpression(IndexExpression node) {
- if (identical(_childNode, node.index)) {
- _parser._inInitializer = false;
- }
- }
-
- @override
- void visitInterpolationExpression(InterpolationExpression node) {
- if (identical(_childNode, node.expression)) {
- _parser._inInitializer = false;
- }
- }
-
- @override
- void visitListLiteral(ListLiteral node) {
- if (node.elements.contains(_childNode)) {
- _parser._inInitializer = false;
- }
- }
-
- @override
- void visitMapLiteral(MapLiteral node) {
- if (node.entries.contains(_childNode)) {
- _parser._inInitializer = false;
- }
- }
-
- @override
- void visitParenthesizedExpression(ParenthesizedExpression node) {
- if (identical(_childNode, node.expression)) {
- _parser._inInitializer = false;
- }
- }
-}
-
-/**
- * An exception indicating that an AST node cannot be re-parsed because there is
- * not enough context to know how to re-parse the node. Clients can attempt to
- * re-parse the parent of the node.
- */
-@deprecated
-class InsufficientContextException extends IncrementalParseException {
- InsufficientContextException([String message = '']) : super(message);
-}
-
-/**
* Wrapper around [Function] which should be called with "target" and
* "arguments".
*/
« no previous file with comments | « pkg/analyzer/lib/src/generated/incremental_scanner.dart ('k') | pkg/analyzer/test/generated/incremental_scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698