AstVisitingSuggestor<R> mixin
Mixin that implements the Suggestor interface and makes it easier to write
suggestors that operate as an AstVisitor
.
With the AstVisitor
pattern, you can override the applicable visit
methods to find what you're looking for and generate patches at specific
locations in the source using the offsets provided by the AstNode
s and
tokens therein.
Note that this mixin provides an implementation of generatePatches
that
should not need to be overridden except for performance optimization reasons
like avoiding analysis on certain files.
By default, this operates on the unresolved AST. Subclasses that need a fully resolved AST (e.g. for static typing info) should override shouldResolveAst to return true.
The easiest way to understand this pattern is to see an example. Consider the following suggestor that aims to remove all deprecated declarations:
import 'package:analyzer/analyzer.dart';
import 'package:codemod/codemod.dart';
class DeprecatedRemover extends GeneralizingAstVisitor
with AstVisitingSuggestor {
static bool isDeprecated(AnnotatedNode node) =>
node.metadata.any((m) => m.name.name.toLowerCase() == 'deprecated');
@override
visitDeclaration(Declaration node) {
if (isDeprecated(node)) {
// Remove the node by replacing the span from its start offset to its end
// offset with an empty string.
yieldPatch('', node.offset, node.end);
}
}
}
Properties
- context → FileContext
-
The context helper for the file currently being visited.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
call(
FileContext context) → Stream< Patch> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shouldResolveAst(
FileContext context) → bool -
Whether the AST should be resolved for the file represented by
context
. -
shouldSkip(
FileContext context) → bool -
Whether the file represented by
context
should be parsed and visited. -
toString(
) → String -
A string representation of this object.
inherited
-
visitAdjacentStrings(
AdjacentStrings node) → R? -
inherited
-
visitAnnotation(
Annotation node) → R? -
inherited
-
visitArgumentList(
ArgumentList node) → R? -
inherited
-
visitAsExpression(
AsExpression node) → R? -
inherited
-
visitAssertInitializer(
AssertInitializer node) → R? -
inherited
-
visitAssertStatement(
AssertStatement assertStatement) → R? -
inherited
-
visitAssignedVariablePattern(
AssignedVariablePattern node) → R? -
inherited
-
visitAssignmentExpression(
AssignmentExpression node) → R? -
inherited
-
visitAugmentationImportDirective(
AugmentationImportDirective node) → R? -
inherited
-
visitAwaitExpression(
AwaitExpression node) → R? -
inherited
-
visitBinaryExpression(
BinaryExpression node) → R? -
inherited
-
visitBlock(
Block node) → R? -
inherited
-
visitBlockFunctionBody(
BlockFunctionBody node) → R? -
inherited
-
visitBooleanLiteral(
BooleanLiteral node) → R? -
inherited
-
visitBreakStatement(
BreakStatement node) → R? -
inherited
-
visitCascadeExpression(
CascadeExpression node) → R? -
inherited
-
visitCaseClause(
CaseClause node) → R? -
inherited
-
visitCastPattern(
CastPattern node) → R? -
inherited
-
visitCatchClause(
CatchClause node) → R? -
inherited
-
visitCatchClauseParameter(
CatchClauseParameter node) → R? -
inherited
-
visitClassDeclaration(
ClassDeclaration node) → R? -
inherited
-
visitClassTypeAlias(
ClassTypeAlias node) → R? -
inherited
-
visitComment(
Comment node) → R? -
inherited
-
visitCommentReference(
CommentReference node) → R? -
inherited
-
visitCompilationUnit(
CompilationUnit node) → R? -
inherited
-
visitConditionalExpression(
ConditionalExpression node) → R? -
inherited
-
visitConfiguration(
Configuration node) → R? -
inherited
-
visitConstantPattern(
ConstantPattern node) → R? -
inherited
-
visitConstructorDeclaration(
ConstructorDeclaration node) → R? -
inherited
-
visitConstructorFieldInitializer(
ConstructorFieldInitializer node) → R? -
inherited
-
visitConstructorName(
ConstructorName node) → R? -
inherited
-
visitConstructorReference(
ConstructorReference node) → R? -
inherited
-
visitConstructorSelector(
ConstructorSelector node) → R? -
inherited
-
visitContinueStatement(
ContinueStatement node) → R? -
inherited
-
visitDeclaredIdentifier(
DeclaredIdentifier node) → R? -
inherited
-
visitDeclaredVariablePattern(
DeclaredVariablePattern node) → R? -
inherited
-
visitDefaultFormalParameter(
DefaultFormalParameter node) → R? -
inherited
-
visitDoStatement(
DoStatement node) → R? -
inherited
-
visitDottedName(
DottedName node) → R? -
inherited
-
visitDoubleLiteral(
DoubleLiteral node) → R? -
inherited
-
visitEmptyFunctionBody(
EmptyFunctionBody node) → R? -
inherited
-
visitEmptyStatement(
EmptyStatement node) → R? -
inherited
-
visitEnumConstantArguments(
EnumConstantArguments node) → R? -
inherited
-
visitEnumConstantDeclaration(
EnumConstantDeclaration node) → R? -
inherited
-
visitEnumDeclaration(
EnumDeclaration node) → R? -
inherited
-
visitExportDirective(
ExportDirective node) → R? -
inherited
-
visitExpressionFunctionBody(
ExpressionFunctionBody node) → R? -
inherited
-
visitExpressionStatement(
ExpressionStatement node) → R? -
inherited
-
visitExtendsClause(
ExtendsClause node) → R? -
inherited
-
visitExtensionDeclaration(
ExtensionDeclaration node) → R? -
inherited
-
visitExtensionOverride(
ExtensionOverride node) → R? -
inherited
-
visitExtensionTypeDeclaration(
ExtensionTypeDeclaration node) → R? -
inherited
-
visitFieldDeclaration(
FieldDeclaration node) → R? -
inherited
-
visitFieldFormalParameter(
FieldFormalParameter node) → R? -
inherited
-
visitForEachPartsWithDeclaration(
ForEachPartsWithDeclaration node) → R? -
inherited
-
visitForEachPartsWithIdentifier(
ForEachPartsWithIdentifier node) → R? -
inherited
-
visitForEachPartsWithPattern(
ForEachPartsWithPattern node) → R? -
inherited
-
visitForElement(
ForElement node) → R? -
inherited
-
visitFormalParameterList(
FormalParameterList node) → R? -
inherited
-
visitForPartsWithDeclarations(
ForPartsWithDeclarations node) → R? -
inherited
-
visitForPartsWithExpression(
ForPartsWithExpression node) → R? -
inherited
-
visitForPartsWithPattern(
ForPartsWithPattern node) → R? -
inherited
-
visitForStatement(
ForStatement node) → R? -
inherited
-
visitFunctionDeclaration(
FunctionDeclaration node) → R? -
inherited
-
visitFunctionDeclarationStatement(
FunctionDeclarationStatement node) → R? -
inherited
-
visitFunctionExpression(
FunctionExpression node) → R? -
inherited
-
visitFunctionExpressionInvocation(
FunctionExpressionInvocation node) → R? -
inherited
-
visitFunctionReference(
FunctionReference node) → R? -
inherited
-
visitFunctionTypeAlias(
FunctionTypeAlias functionTypeAlias) → R? -
inherited
-
visitFunctionTypedFormalParameter(
FunctionTypedFormalParameter node) → R? -
inherited
-
visitGenericFunctionType(
GenericFunctionType node) → R? -
inherited
-
visitGenericTypeAlias(
GenericTypeAlias node) → R? -
inherited
-
visitGuardedPattern(
GuardedPattern node) → R? -
inherited
-
visitHideCombinator(
HideCombinator node) → R? -
inherited
-
visitIfElement(
IfElement node) → R? -
inherited
-
visitIfStatement(
IfStatement node) → R? -
inherited
-
visitImplementsClause(
ImplementsClause node) → R? -
inherited
-
visitImplicitCallReference(
ImplicitCallReference node) → R? -
inherited
-
visitImportDirective(
ImportDirective node) → R? -
inherited
-
visitImportPrefixReference(
ImportPrefixReference node) → R? -
inherited
-
visitIndexExpression(
IndexExpression node) → R? -
inherited
-
visitInstanceCreationExpression(
InstanceCreationExpression node) → R? -
inherited
-
visitIntegerLiteral(
IntegerLiteral node) → R? -
inherited
-
visitInterpolationExpression(
InterpolationExpression node) → R? -
inherited
-
visitInterpolationString(
InterpolationString node) → R? -
inherited
-
visitIsExpression(
IsExpression node) → R? -
inherited
-
visitLabel(
Label node) → R? -
inherited
-
visitLabeledStatement(
LabeledStatement node) → R? -
inherited
-
visitLibraryAugmentationDirective(
LibraryAugmentationDirective node) → R? -
inherited
-
visitLibraryDirective(
LibraryDirective node) → R? -
inherited
-
visitLibraryIdentifier(
LibraryIdentifier node) → R? -
inherited
-
visitListLiteral(
ListLiteral node) → R? -
inherited
-
visitListPattern(
ListPattern node) → R? -
inherited
-
visitLogicalAndPattern(
LogicalAndPattern node) → R? -
inherited
-
visitLogicalOrPattern(
LogicalOrPattern node) → R? -
inherited
-
visitMapLiteralEntry(
MapLiteralEntry node) → R? -
inherited
-
visitMapPattern(
MapPattern node) → R? -
inherited
-
visitMapPatternEntry(
MapPatternEntry node) → R? -
inherited
-
visitMethodDeclaration(
MethodDeclaration node) → R? -
inherited
-
visitMethodInvocation(
MethodInvocation node) → R? -
inherited
-
visitMixinDeclaration(
MixinDeclaration node) → R? -
inherited
-
visitNamedExpression(
NamedExpression node) → R? -
inherited
-
visitNamedType(
NamedType node) → R? -
inherited
-
visitNativeClause(
NativeClause node) → R? -
inherited
-
visitNativeFunctionBody(
NativeFunctionBody node) → R? -
inherited
-
visitNullAssertPattern(
NullAssertPattern node) → R? -
inherited
-
visitNullCheckPattern(
NullCheckPattern node) → R? -
inherited
-
visitNullLiteral(
NullLiteral node) → R? -
inherited
-
visitObjectPattern(
ObjectPattern node) → R? -
inherited
-
visitOnClause(
OnClause node) → R? -
inherited
-
visitParenthesizedExpression(
ParenthesizedExpression node) → R? -
inherited
-
visitParenthesizedPattern(
ParenthesizedPattern node) → R? -
inherited
-
visitPartDirective(
PartDirective node) → R? -
inherited
-
visitPartOfDirective(
PartOfDirective node) → R? -
inherited
-
visitPatternAssignment(
PatternAssignment node) → R? -
inherited
-
visitPatternField(
PatternField node) → R? -
inherited
-
visitPatternFieldName(
PatternFieldName node) → R? -
inherited
-
visitPatternVariableDeclaration(
PatternVariableDeclaration node) → R? -
inherited
-
visitPatternVariableDeclarationStatement(
PatternVariableDeclarationStatement node) → R? -
inherited
-
visitPostfixExpression(
PostfixExpression node) → R? -
inherited
-
visitPrefixedIdentifier(
PrefixedIdentifier node) → R? -
inherited
-
visitPrefixExpression(
PrefixExpression node) → R? -
inherited
-
visitPropertyAccess(
PropertyAccess node) → R? -
inherited
-
visitRecordLiteral(
RecordLiteral node) → R? -
inherited
-
visitRecordPattern(
RecordPattern node) → R? -
inherited
-
visitRecordTypeAnnotation(
RecordTypeAnnotation node) → R? -
inherited
-
visitRecordTypeAnnotationNamedField(
RecordTypeAnnotationNamedField node) → R? -
inherited
-
visitRecordTypeAnnotationNamedFields(
RecordTypeAnnotationNamedFields node) → R? -
inherited
-
visitRecordTypeAnnotationPositionalField(
RecordTypeAnnotationPositionalField node) → R? -
inherited
-
visitRedirectingConstructorInvocation(
RedirectingConstructorInvocation node) → R? -
inherited
-
visitRelationalPattern(
RelationalPattern node) → R? -
inherited
-
visitRepresentationConstructorName(
RepresentationConstructorName node) → R? -
inherited
-
visitRepresentationDeclaration(
RepresentationDeclaration node) → R? -
inherited
-
visitRestPatternElement(
RestPatternElement node) → R? -
inherited
-
visitRethrowExpression(
RethrowExpression node) → R? -
inherited
-
visitReturnStatement(
ReturnStatement node) → R? -
inherited
-
visitScriptTag(
ScriptTag node) → R? -
inherited
-
visitSetOrMapLiteral(
SetOrMapLiteral node) → R? -
inherited
-
visitShowCombinator(
ShowCombinator node) → R? -
inherited
-
visitSimpleFormalParameter(
SimpleFormalParameter node) → R? -
inherited
-
visitSimpleIdentifier(
SimpleIdentifier node) → R? -
inherited
-
visitSimpleStringLiteral(
SimpleStringLiteral node) → R? -
inherited
-
visitSpreadElement(
SpreadElement node) → R? -
inherited
-
visitStringInterpolation(
StringInterpolation node) → R? -
inherited
-
visitSuperConstructorInvocation(
SuperConstructorInvocation node) → R? -
inherited
-
visitSuperExpression(
SuperExpression node) → R? -
inherited
-
visitSuperFormalParameter(
SuperFormalParameter node) → R? -
inherited
-
visitSwitchCase(
SwitchCase node) → R? -
inherited
-
visitSwitchDefault(
SwitchDefault node) → R? -
inherited
-
visitSwitchExpression(
SwitchExpression node) → R? -
inherited
-
visitSwitchExpressionCase(
SwitchExpressionCase node) → R? -
inherited
-
visitSwitchPatternCase(
SwitchPatternCase node) → R? -
inherited
-
visitSwitchStatement(
SwitchStatement node) → R? -
inherited
-
visitSymbolLiteral(
SymbolLiteral node) → R? -
inherited
-
visitThisExpression(
ThisExpression node) → R? -
inherited
-
visitThrowExpression(
ThrowExpression node) → R? -
inherited
-
visitTopLevelVariableDeclaration(
TopLevelVariableDeclaration node) → R? -
inherited
-
visitTryStatement(
TryStatement node) → R? -
inherited
-
visitTypeArgumentList(
TypeArgumentList node) → R? -
inherited
-
visitTypeLiteral(
TypeLiteral node) → R? -
inherited
-
visitTypeParameter(
TypeParameter node) → R? -
inherited
-
visitTypeParameterList(
TypeParameterList node) → R? -
inherited
-
visitVariableDeclaration(
VariableDeclaration node) → R? -
inherited
-
visitVariableDeclarationList(
VariableDeclarationList node) → R? -
inherited
-
visitVariableDeclarationStatement(
VariableDeclarationStatement node) → R? -
inherited
-
visitWhenClause(
WhenClause node) → R? -
inherited
-
visitWhileStatement(
WhileStatement node) → R? -
inherited
-
visitWildcardPattern(
WildcardPattern node) → R? -
inherited
-
visitWithClause(
WithClause node) → R? -
inherited
-
visitYieldStatement(
YieldStatement node) → R? -
inherited
-
yieldPatch(
String updatedText, int startOffset, [int? endOffset]) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited