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

Unified Diff: pkg/analyzer/lib/dart/ast/visitor.dart

Issue 2623453003: Add visitors that throw by default (Closed)
Patch Set: rework implementation Created 3 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
Index: pkg/analyzer/lib/dart/ast/visitor.dart
diff --git a/pkg/analyzer/lib/dart/ast/visitor.dart b/pkg/analyzer/lib/dart/ast/visitor.dart
index ad96bed8007a1dcd2b5838e37187dfb203b11ceb..ad00573c4ecb45053b5da678eb0d40f80fde2224 100644
--- a/pkg/analyzer/lib/dart/ast/visitor.dart
+++ b/pkg/analyzer/lib/dart/ast/visitor.dart
@@ -50,7 +50,7 @@ import 'package:analyzer/dart/ast/ast.dart';
*
* visitor.visitAllNodes(rootNode);
*
- * Clients may extend or implement this class.
+ * Clients may extend this class.
*/
class BreadthFirstVisitor<R> extends GeneralizingAstVisitor<R> {
/**
@@ -147,7 +147,7 @@ class DelegatingAstVisitor<T> extends UnifyingAstVisitor<T> {
* do so will cause the visit methods for superclasses of the node to not be
* invoked and will cause the children of the visited node to not be visited.
*
- * Clients may extend or implement this class.
+ * Clients may extend this class.
*/
class GeneralizingAstVisitor<R> implements AstVisitor<R> {
@override
@@ -576,7 +576,7 @@ class GeneralizingAstVisitor<R> implements AstVisitor<R> {
* Failure to do so will cause the children of the visited node to not be
* visited.
*
- * Clients may extend or implement this class.
+ * Clients may extend this class.
*/
class RecursiveAstVisitor<R> implements AstVisitor<R> {
@override
@@ -1241,7 +1241,7 @@ class RecursiveAstVisitor<R> implements AstVisitor<R> {
* dispatch mechanism (and hence don't need to recursively visit a whole
* structure) and that only need to visit a small number of node types.
*
- * Clients may extend or implement this class.
+ * Clients may extend this class.
*/
class SimpleAstVisitor<R> implements AstVisitor<R> {
@override
@@ -1579,7 +1579,360 @@ class SimpleAstVisitor<R> implements AstVisitor<R> {
}
/**
- * An AST Visitor that captures visit call timings.
+ * An AST visitor that will throw an exception if any of the visit methods that
+ * are invoked have not been overridden. It is intended to be a superclass for
+ * classes that implement the visitor pattern and need to override all of the
+ * visit methods.
Paul Berry 2017/01/09 17:36:51 It would also be useful for classes that implement
Brian Wilkerson 2017/01/09 18:08:07 Updated comment.
+ *
+ * Clients may extend this class.
+ */
+class ThrowingAstVisitor<R> implements AstVisitor<R> {
+ @override
+ R visitAdjacentStrings(AdjacentStrings node) => _throw(node);
+
+ @override
+ R visitAnnotation(Annotation node) => _throw(node);
+
+ @override
+ R visitArgumentList(ArgumentList node) => _throw(node);
+
+ @override
+ R visitAsExpression(AsExpression node) => _throw(node);
+
+ @override
+ R visitAssertInitializer(AssertInitializer node) => _throw(node);
+
+ @override
+ R visitAssertStatement(AssertStatement node) => _throw(node);
+
+ @override
+ R visitAssignmentExpression(AssignmentExpression node) => _throw(node);
+
+ @override
+ R visitAwaitExpression(AwaitExpression node) => _throw(node);
+
+ @override
+ R visitBinaryExpression(BinaryExpression node) => _throw(node);
+
+ @override
+ R visitBlock(Block node) => _throw(node);
+
+ @override
+ R visitBlockFunctionBody(BlockFunctionBody node) => _throw(node);
+
+ @override
+ R visitBooleanLiteral(BooleanLiteral node) => _throw(node);
+
+ @override
+ R visitBreakStatement(BreakStatement node) => _throw(node);
+
+ @override
+ R visitCascadeExpression(CascadeExpression node) => _throw(node);
+
+ @override
+ R visitCatchClause(CatchClause node) => _throw(node);
+
+ @override
+ R visitClassDeclaration(ClassDeclaration node) => _throw(node);
+
+ @override
+ R visitClassTypeAlias(ClassTypeAlias node) => _throw(node);
+
+ @override
+ R visitComment(Comment node) => _throw(node);
+
+ @override
+ R visitCommentReference(CommentReference node) => _throw(node);
+
+ @override
+ R visitCompilationUnit(CompilationUnit node) => _throw(node);
+
+ @override
+ R visitConditionalExpression(ConditionalExpression node) => _throw(node);
+
+ @override
+ R visitConfiguration(Configuration node) => _throw(node);
+
+ @override
+ R visitConstructorDeclaration(ConstructorDeclaration node) => _throw(node);
+
+ @override
+ R visitConstructorFieldInitializer(ConstructorFieldInitializer node) =>
+ _throw(node);
+
+ @override
+ R visitConstructorName(ConstructorName node) => _throw(node);
+
+ @override
+ R visitContinueStatement(ContinueStatement node) => _throw(node);
+
+ @override
+ R visitDeclaredIdentifier(DeclaredIdentifier node) => _throw(node);
+
+ @override
+ R visitDefaultFormalParameter(DefaultFormalParameter node) => _throw(node);
+
+ @override
+ R visitDoStatement(DoStatement node) => _throw(node);
+
+ @override
+ R visitDottedName(DottedName node) => _throw(node);
+
+ @override
+ R visitDoubleLiteral(DoubleLiteral node) => _throw(node);
+
+ @override
+ R visitEmptyFunctionBody(EmptyFunctionBody node) => _throw(node);
+
+ @override
+ R visitEmptyStatement(EmptyStatement node) => _throw(node);
+
+ @override
+ R visitEnumConstantDeclaration(EnumConstantDeclaration node) => _throw(node);
+
+ @override
+ R visitEnumDeclaration(EnumDeclaration node) => _throw(node);
+
+ @override
+ R visitExportDirective(ExportDirective node) => _throw(node);
+
+ @override
+ R visitExpressionFunctionBody(ExpressionFunctionBody node) => _throw(node);
+
+ @override
+ R visitExpressionStatement(ExpressionStatement node) => _throw(node);
+
+ @override
+ R visitExtendsClause(ExtendsClause node) => _throw(node);
+
+ @override
+ R visitFieldDeclaration(FieldDeclaration node) => _throw(node);
+
+ @override
+ R visitFieldFormalParameter(FieldFormalParameter node) => _throw(node);
+
+ @override
+ R visitForEachStatement(ForEachStatement node) => _throw(node);
+
+ @override
+ R visitFormalParameterList(FormalParameterList node) => _throw(node);
+
+ @override
+ R visitForStatement(ForStatement node) => _throw(node);
+
+ @override
+ R visitFunctionDeclaration(FunctionDeclaration node) => _throw(node);
+
+ @override
+ R visitFunctionDeclarationStatement(FunctionDeclarationStatement node) =>
+ _throw(node);
+
+ @override
+ R visitFunctionExpression(FunctionExpression node) => _throw(node);
+
+ @override
+ R visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
+ _throw(node);
+
+ @override
+ R visitFunctionTypeAlias(FunctionTypeAlias node) => _throw(node);
+
+ @override
+ R visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) =>
+ _throw(node);
+
+ @override
+ R visitHideCombinator(HideCombinator node) => _throw(node);
+
+ @override
+ R visitIfStatement(IfStatement node) => _throw(node);
+
+ @override
+ R visitImplementsClause(ImplementsClause node) => _throw(node);
+
+ @override
+ R visitImportDirective(ImportDirective node) => _throw(node);
+
+ @override
+ R visitIndexExpression(IndexExpression node) => _throw(node);
+
+ @override
+ R visitInstanceCreationExpression(InstanceCreationExpression node) =>
+ _throw(node);
+
+ @override
+ R visitIntegerLiteral(IntegerLiteral node) => _throw(node);
+
+ @override
+ R visitInterpolationExpression(InterpolationExpression node) => _throw(node);
+
+ @override
+ R visitInterpolationString(InterpolationString node) => _throw(node);
+
+ @override
+ R visitIsExpression(IsExpression node) => _throw(node);
+
+ @override
+ R visitLabel(Label node) => _throw(node);
+
+ @override
+ R visitLabeledStatement(LabeledStatement node) => _throw(node);
+
+ @override
+ R visitLibraryDirective(LibraryDirective node) => _throw(node);
+
+ @override
+ R visitLibraryIdentifier(LibraryIdentifier node) => _throw(node);
+
+ @override
+ R visitListLiteral(ListLiteral node) => _throw(node);
+
+ @override
+ R visitMapLiteral(MapLiteral node) => _throw(node);
+
+ @override
+ R visitMapLiteralEntry(MapLiteralEntry node) => _throw(node);
+
+ @override
+ R visitMethodDeclaration(MethodDeclaration node) => _throw(node);
+
+ @override
+ R visitMethodInvocation(MethodInvocation node) => _throw(node);
+
+ @override
+ R visitNamedExpression(NamedExpression node) => _throw(node);
+
+ @override
+ R visitNativeClause(NativeClause node) => _throw(node);
+
+ @override
+ R visitNativeFunctionBody(NativeFunctionBody node) => _throw(node);
+
+ @override
+ R visitNullLiteral(NullLiteral node) => _throw(node);
+
+ @override
+ R visitParenthesizedExpression(ParenthesizedExpression node) => _throw(node);
+
+ @override
+ R visitPartDirective(PartDirective node) => _throw(node);
+
+ @override
+ R visitPartOfDirective(PartOfDirective node) => _throw(node);
+
+ @override
+ R visitPostfixExpression(PostfixExpression node) => _throw(node);
+
+ @override
+ R visitPrefixedIdentifier(PrefixedIdentifier node) => _throw(node);
+
+ @override
+ R visitPrefixExpression(PrefixExpression node) => _throw(node);
+
+ @override
+ R visitPropertyAccess(PropertyAccess node) => _throw(node);
+
+ @override
+ R visitRedirectingConstructorInvocation(
+ RedirectingConstructorInvocation node) =>
+ _throw(node);
+
+ @override
+ R visitRethrowExpression(RethrowExpression node) => _throw(node);
+
+ @override
+ R visitReturnStatement(ReturnStatement node) => _throw(node);
+
+ @override
+ R visitScriptTag(ScriptTag node) => _throw(node);
+
+ @override
+ R visitShowCombinator(ShowCombinator node) => _throw(node);
+
+ @override
+ R visitSimpleFormalParameter(SimpleFormalParameter node) => _throw(node);
+
+ @override
+ R visitSimpleIdentifier(SimpleIdentifier node) => _throw(node);
+
+ @override
+ R visitSimpleStringLiteral(SimpleStringLiteral node) => _throw(node);
+
+ @override
+ R visitStringInterpolation(StringInterpolation node) => _throw(node);
+
+ @override
+ R visitSuperConstructorInvocation(SuperConstructorInvocation node) =>
+ _throw(node);
+
+ @override
+ R visitSuperExpression(SuperExpression node) => _throw(node);
+
+ @override
+ R visitSwitchCase(SwitchCase node) => _throw(node);
+
+ @override
+ R visitSwitchDefault(SwitchDefault node) => _throw(node);
+
+ @override
+ R visitSwitchStatement(SwitchStatement node) => _throw(node);
+
+ @override
+ R visitSymbolLiteral(SymbolLiteral node) => _throw(node);
+
+ @override
+ R visitThisExpression(ThisExpression node) => _throw(node);
+
+ @override
+ R visitThrowExpression(ThrowExpression node) => _throw(node);
+
+ @override
+ R visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) =>
+ _throw(node);
+
+ @override
+ R visitTryStatement(TryStatement node) => _throw(node);
+
+ @override
+ R visitTypeArgumentList(TypeArgumentList node) => _throw(node);
+
+ @override
+ R visitTypeName(TypeName node) => _throw(node);
+
+ @override
+ R visitTypeParameter(TypeParameter node) => _throw(node);
+
+ @override
+ R visitTypeParameterList(TypeParameterList node) => _throw(node);
+
+ @override
+ R visitVariableDeclaration(VariableDeclaration node) => _throw(node);
+
+ @override
+ R visitVariableDeclarationList(VariableDeclarationList node) => _throw(node);
+
+ @override
+ R visitVariableDeclarationStatement(VariableDeclarationStatement node) =>
+ _throw(node);
+
+ @override
+ R visitWhileStatement(WhileStatement node) => _throw(node);
+
+ @override
+ R visitWithClause(WithClause node) => _throw(node);
+
+ @override
+ R visitYieldStatement(YieldStatement node) => _throw(node);
+
+ R _throw(AstNode node) {
+ throw new Exception('Missing implementation of visit${node.runtimeType}');
+ }
+}
+
+/**
+ * An AST visitor that captures visit call timings.
+ *
+ * Clients may not extend, implement or mix-in this class.
*/
class TimedAstVisitor<T> implements AstVisitor<T> {
/**
@@ -2483,7 +2836,7 @@ class TimedAstVisitor<T> implements AstVisitor<T> {
* Failure to do so will cause the children of the visited node to not be
* visited.
*
- * Clients may extend or implement this class.
+ * Clients may extend this class.
*/
class UnifyingAstVisitor<R> implements AstVisitor<R> {
@override

Powered by Google App Engine
This is Rietveld 408576698