mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Deprecate 'name' in AST, use 'name2' token instead.
Change-Id: I867f009dca12208f835199297d2ea85c203c8556 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252566 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Jake Macdonald <jakemac@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
023c6df3b4
commit
01173e2aa2
|
@ -330,7 +330,7 @@ class DartCallHierarchyComputer {
|
|||
}
|
||||
}
|
||||
} else if (node is ConstructorDeclaration) {
|
||||
final name = node.name;
|
||||
final name = node.name2;
|
||||
if (name != null && offset < name.offset) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -682,6 +682,14 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
computer._addRegion_token(
|
||||
node.factoryKeyword, HighlightRegionType.BUILT_IN);
|
||||
computer._addRegion_token(node.constKeyword, HighlightRegionType.KEYWORD);
|
||||
computer._addRegion_token(
|
||||
node.name2,
|
||||
HighlightRegionType.CONSTRUCTOR,
|
||||
semanticTokenType: SemanticTokenTypes.method,
|
||||
semanticTokenModifiers: {
|
||||
CustomSemanticTokenModifiers.constructor,
|
||||
},
|
||||
);
|
||||
super.visitConstructorDeclaration(node);
|
||||
}
|
||||
|
||||
|
@ -743,8 +751,8 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitEnumConstantDeclaration(EnumConstantDeclaration node) {
|
||||
computer._addRegion_node(
|
||||
node.name,
|
||||
computer._addRegion_token(
|
||||
node.name2,
|
||||
HighlightRegionType.ENUM_CONSTANT,
|
||||
);
|
||||
node.visitChildren(this);
|
||||
|
@ -803,8 +811,8 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
if (element is FieldFormalParameterElement) {
|
||||
var field = element.field;
|
||||
if (field != null) {
|
||||
computer._addRegion_node(
|
||||
node.identifier,
|
||||
computer._addRegion_token(
|
||||
node.name,
|
||||
HighlightRegionType.INSTANCE_FIELD_REFERENCE,
|
||||
);
|
||||
}
|
||||
|
@ -1109,6 +1117,12 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
final parent = node.parent;
|
||||
// ignore: deprecated_member_use
|
||||
if (parent is ConstructorDeclaration && parent.name == node) {
|
||||
return;
|
||||
}
|
||||
|
||||
computer._addIdentifierRegion(node);
|
||||
super.visitSimpleIdentifier(node);
|
||||
}
|
||||
|
@ -1135,8 +1149,8 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
HighlightRegionType.KEYWORD,
|
||||
);
|
||||
|
||||
computer._addRegion_node(
|
||||
node.identifier,
|
||||
computer._addRegion_token(
|
||||
node.name,
|
||||
HighlightRegionType.PARAMETER_DECLARATION,
|
||||
);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:analysis_server/src/collections.dart';
|
|||
import 'package:analysis_server/src/utilities/flutter.dart';
|
||||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart' as engine;
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
||||
|
@ -90,9 +91,13 @@ class DartUnitOutlineComputer {
|
|||
endLine: endLine, endColumn: endColumn);
|
||||
}
|
||||
|
||||
Location _getLocationToken(Token token) {
|
||||
return _getLocationOffsetLength(token.offset, token.length);
|
||||
}
|
||||
|
||||
Outline _newClassOutline(ClassDeclaration node, List<Outline> classContents) {
|
||||
var nameNode = node.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = node.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var element = Element(
|
||||
ElementKind.CLASS,
|
||||
name,
|
||||
|
@ -100,14 +105,14 @@ class DartUnitOutlineComputer {
|
|||
isPrivate: Identifier.isPrivateName(name),
|
||||
isDeprecated: _isDeprecated(node),
|
||||
isAbstract: node.abstractKeyword != null),
|
||||
location: _getLocationNode(nameNode),
|
||||
location: _getLocationToken(nameToken),
|
||||
typeParameters: _getTypeParametersStr(node.typeParameters));
|
||||
return _nodeOutline(node, element, classContents);
|
||||
}
|
||||
|
||||
Outline _newClassTypeAlias(ClassTypeAlias node) {
|
||||
var nameNode = node.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = node.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var element = Element(
|
||||
ElementKind.CLASS_TYPE_ALIAS,
|
||||
name,
|
||||
|
@ -115,7 +120,7 @@ class DartUnitOutlineComputer {
|
|||
isPrivate: Identifier.isPrivateName(name),
|
||||
isDeprecated: _isDeprecated(node),
|
||||
isAbstract: node.abstractKeyword != null),
|
||||
location: _getLocationNode(nameNode),
|
||||
location: _getLocationToken(nameToken),
|
||||
typeParameters: _getTypeParametersStr(node.typeParameters));
|
||||
return _nodeOutline(node, element);
|
||||
}
|
||||
|
@ -125,14 +130,14 @@ class DartUnitOutlineComputer {
|
|||
var name = returnType.name;
|
||||
var offset = returnType.offset;
|
||||
var length = returnType.length;
|
||||
var constructorNameNode = constructor.name;
|
||||
var constructorNameToken = constructor.name2;
|
||||
var isPrivate = false;
|
||||
if (constructorNameNode != null) {
|
||||
var constructorName = constructorNameNode.name;
|
||||
if (constructorNameToken != null) {
|
||||
var constructorName = constructorNameToken.lexeme;
|
||||
isPrivate = Identifier.isPrivateName(constructorName);
|
||||
name += '.$constructorName';
|
||||
offset = constructorNameNode.offset;
|
||||
length = constructorNameNode.length;
|
||||
offset = constructorNameToken.offset;
|
||||
length = constructorNameToken.length;
|
||||
}
|
||||
var parameters = constructor.parameters;
|
||||
var parametersStr = _safeToSource(parameters);
|
||||
|
@ -148,50 +153,52 @@ class DartUnitOutlineComputer {
|
|||
}
|
||||
|
||||
Outline _newEnumConstant(EnumConstantDeclaration node) {
|
||||
var nameNode = node.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = node.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var element = Element(
|
||||
ElementKind.ENUM_CONSTANT,
|
||||
name,
|
||||
Element.makeFlags(
|
||||
isPrivate: Identifier.isPrivateName(name),
|
||||
isDeprecated: _isDeprecated(node)),
|
||||
location: _getLocationNode(nameNode));
|
||||
location: _getLocationToken(nameToken));
|
||||
return _nodeOutline(node, element);
|
||||
}
|
||||
|
||||
Outline _newEnumOutline(EnumDeclaration node, List<Outline> children) {
|
||||
var nameNode = node.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = node.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var element = Element(
|
||||
ElementKind.ENUM,
|
||||
name,
|
||||
Element.makeFlags(
|
||||
isPrivate: Identifier.isPrivateName(name),
|
||||
isDeprecated: _isDeprecated(node)),
|
||||
location: _getLocationNode(nameNode));
|
||||
location: _getLocationToken(nameToken));
|
||||
return _nodeOutline(node, element, children);
|
||||
}
|
||||
|
||||
Outline _newExtensionOutline(
|
||||
ExtensionDeclaration node, List<Outline> extensionContents) {
|
||||
var nameNode = node.name;
|
||||
var name = nameNode?.name ?? '';
|
||||
var nameToken = node.name2;
|
||||
var name = nameToken?.lexeme ?? '';
|
||||
var element = Element(
|
||||
ElementKind.EXTENSION,
|
||||
name,
|
||||
Element.makeFlags(
|
||||
isPrivate: Identifier.isPrivateName(name),
|
||||
isDeprecated: _isDeprecated(node)),
|
||||
location: _getLocationNode(nameNode ?? node.extendedType),
|
||||
location: nameToken != null
|
||||
? _getLocationToken(nameToken)
|
||||
: _getLocationNode(node.extendedType),
|
||||
typeParameters: _getTypeParametersStr(node.typeParameters));
|
||||
return _nodeOutline(node, element, extensionContents);
|
||||
}
|
||||
|
||||
Outline _newFunctionOutline(FunctionDeclaration function, bool isStatic) {
|
||||
var returnType = function.returnType;
|
||||
var nameNode = function.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = function.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var functionExpression = function.functionExpression;
|
||||
var parameters = functionExpression.parameters;
|
||||
ElementKind kind;
|
||||
|
@ -211,7 +218,7 @@ class DartUnitOutlineComputer {
|
|||
isPrivate: Identifier.isPrivateName(name),
|
||||
isDeprecated: _isDeprecated(function),
|
||||
isStatic: isStatic),
|
||||
location: _getLocationNode(nameNode),
|
||||
location: _getLocationToken(nameToken),
|
||||
parameters: parametersStr,
|
||||
returnType: returnTypeStr,
|
||||
typeParameters:
|
||||
|
@ -222,8 +229,8 @@ class DartUnitOutlineComputer {
|
|||
|
||||
Outline _newFunctionTypeAliasOutline(FunctionTypeAlias node) {
|
||||
var returnType = node.returnType;
|
||||
var nameNode = node.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = node.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var parameters = node.parameters;
|
||||
var parametersStr = _safeToSource(parameters);
|
||||
var returnTypeStr = _safeToSource(returnType);
|
||||
|
@ -233,7 +240,7 @@ class DartUnitOutlineComputer {
|
|||
Element.makeFlags(
|
||||
isPrivate: Identifier.isPrivateName(name),
|
||||
isDeprecated: _isDeprecated(node)),
|
||||
location: _getLocationNode(nameNode),
|
||||
location: _getLocationToken(nameToken),
|
||||
parameters: parametersStr,
|
||||
returnType: returnTypeStr,
|
||||
typeParameters: _getTypeParametersStr(node.typeParameters));
|
||||
|
@ -241,8 +248,8 @@ class DartUnitOutlineComputer {
|
|||
}
|
||||
|
||||
Outline _newGenericTypeAliasOutline(GenericTypeAlias node) {
|
||||
var nameNode = node.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = node.name2;
|
||||
var name = nameToken.lexeme;
|
||||
|
||||
var aliasedType = node.type;
|
||||
var aliasedFunctionType =
|
||||
|
@ -258,7 +265,7 @@ class DartUnitOutlineComputer {
|
|||
isDeprecated: _isDeprecated(node),
|
||||
),
|
||||
aliasedType: _safeToSource(aliasedType),
|
||||
location: _getLocationNode(nameNode),
|
||||
location: _getLocationToken(nameToken),
|
||||
parameters: aliasedFunctionType != null
|
||||
? _safeToSource(aliasedFunctionType.parameters)
|
||||
: null,
|
||||
|
@ -273,8 +280,8 @@ class DartUnitOutlineComputer {
|
|||
|
||||
Outline _newMethodOutline(MethodDeclaration method) {
|
||||
var returnType = method.returnType;
|
||||
var nameNode = method.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = method.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var parameters = method.parameters;
|
||||
ElementKind kind;
|
||||
if (method.isGetter) {
|
||||
|
@ -294,7 +301,7 @@ class DartUnitOutlineComputer {
|
|||
isDeprecated: _isDeprecated(method),
|
||||
isAbstract: method.isAbstract,
|
||||
isStatic: method.isStatic),
|
||||
location: _getLocationNode(nameNode),
|
||||
location: _getLocationToken(nameToken),
|
||||
parameters: parametersStr,
|
||||
returnType: returnTypeStr,
|
||||
typeParameters: _getTypeParametersStr(method.typeParameters));
|
||||
|
@ -304,15 +311,15 @@ class DartUnitOutlineComputer {
|
|||
|
||||
Outline _newMixinOutline(MixinDeclaration node, List<Outline> mixinContents) {
|
||||
node.firstTokenAfterCommentAndMetadata;
|
||||
var nameNode = node.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = node.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var element = Element(
|
||||
ElementKind.MIXIN,
|
||||
name,
|
||||
Element.makeFlags(
|
||||
isPrivate: Identifier.isPrivateName(name),
|
||||
isDeprecated: _isDeprecated(node)),
|
||||
location: _getLocationNode(nameNode),
|
||||
location: _getLocationToken(nameToken),
|
||||
typeParameters: _getTypeParametersStr(node.typeParameters));
|
||||
return _nodeOutline(node, element, mixinContents);
|
||||
}
|
||||
|
@ -327,8 +334,8 @@ class DartUnitOutlineComputer {
|
|||
|
||||
Outline _newVariableOutline(String typeName, ElementKind kind,
|
||||
VariableDeclaration variable, bool isStatic) {
|
||||
var nameNode = variable.name;
|
||||
var name = nameNode.name;
|
||||
var nameToken = variable.name2;
|
||||
var name = nameToken.lexeme;
|
||||
var element = Element(
|
||||
kind,
|
||||
name,
|
||||
|
@ -338,7 +345,7 @@ class DartUnitOutlineComputer {
|
|||
isStatic: isStatic,
|
||||
isConst: variable.isConst,
|
||||
isFinal: variable.isFinal),
|
||||
location: _getLocationNode(nameNode),
|
||||
location: _getLocationToken(nameToken),
|
||||
returnType: typeName);
|
||||
return _nodeOutline(variable, element);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:analysis_server/src/collections.dart';
|
|||
import 'package:analysis_server/src/protocol_server.dart' as proto;
|
||||
import 'package:analysis_server/src/utilities/extensions/ast.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
|
||||
/// Return the elements that the given [element] overrides.
|
||||
|
@ -35,9 +36,8 @@ class DartUnitOverridesComputer {
|
|||
return _overrides;
|
||||
}
|
||||
|
||||
/// Add a new [Override] for the declaration with the given name [node].
|
||||
void _addOverride(SimpleIdentifier node) {
|
||||
var element = node.staticElement;
|
||||
/// Add a new [Override] for the declaration with the given name [token].
|
||||
void _addOverride(Token token, Element? element) {
|
||||
if (element != null) {
|
||||
var overridesResult = _OverriddenElementsFinder(element).find();
|
||||
var superElements = overridesResult.superElements;
|
||||
|
@ -53,7 +53,7 @@ class DartUnitOverridesComputer {
|
|||
member.nonSynthetic,
|
||||
withNullability: _unit.isNonNullableByDefault))
|
||||
.toList();
|
||||
_overrides.add(proto.Override(node.offset, node.length,
|
||||
_overrides.add(proto.Override(token.offset, token.length,
|
||||
superclassMember: superMember,
|
||||
interfaceMembers: nullIfEmpty(interfaceMembers)));
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class DartUnitOverridesComputer {
|
|||
if (classMember.isStatic) {
|
||||
continue;
|
||||
}
|
||||
_addOverride(classMember.name);
|
||||
_addOverride(classMember.name2, classMember.declaredElement);
|
||||
}
|
||||
if (classMember is FieldDeclaration) {
|
||||
if (classMember.isStatic) {
|
||||
|
@ -74,7 +74,7 @@ class DartUnitOverridesComputer {
|
|||
}
|
||||
List<VariableDeclaration> fields = classMember.fields.variables;
|
||||
for (var field in fields) {
|
||||
_addOverride(field.name);
|
||||
_addOverride(field.name2, field.declaredElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,13 @@ void addDartOccurrences(OccurrencesCollector collector, CompilationUnit unit) {
|
|||
class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
|
||||
final Map<Element, List<int>> elementsOffsets = <Element, List<int>>{};
|
||||
|
||||
@override
|
||||
void visitEnumConstantDeclaration(EnumConstantDeclaration node) {
|
||||
_addOccurrence(node.declaredElement!, node.name2.offset);
|
||||
|
||||
super.visitEnumConstantDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
var element = node.writeOrReadElement;
|
||||
|
|
|
@ -478,17 +478,26 @@ class DartCompletionRequest {
|
|||
}
|
||||
}
|
||||
|
||||
/// TODO(scheglov) Can we make it better?
|
||||
String fromToken(Token token) {
|
||||
final lexeme = token.lexeme;
|
||||
if (offset >= token.offset && offset < token.end) {
|
||||
return lexeme.substring(0, offset - token.offset);
|
||||
} else if (offset == token.end) {
|
||||
return lexeme;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
while (entity is AstNode) {
|
||||
if (entity is SimpleIdentifier) {
|
||||
var identifier = entity.name;
|
||||
if (offset >= entity.offset && offset < entity.end) {
|
||||
return identifier.substring(0, offset - entity.offset);
|
||||
} else if (offset == entity.end) {
|
||||
return identifier;
|
||||
}
|
||||
return fromToken(entity.token);
|
||||
}
|
||||
var children = entity.childEntities;
|
||||
entity = children.isEmpty ? null : children.first;
|
||||
if (entity is Token) {
|
||||
return fromToken(entity);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
|
|
@ -979,7 +979,7 @@ parent3: ${node.parent?.parent?.parent}
|
|||
var parent = node.parent;
|
||||
if (parent is VariableDeclarationList) {
|
||||
return parent.type?.type ??
|
||||
_impliedDartTypeWithName(typeProvider, node.name.name);
|
||||
_impliedDartTypeWithName(typeProvider, node.name2.lexeme);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -992,7 +992,7 @@ parent3: ${node.parent?.parent?.parent}
|
|||
var equals = varDecl.equals;
|
||||
if (equals != null && equals.end <= offset) {
|
||||
return node.type?.type ??
|
||||
_impliedDartTypeWithName(typeProvider, varDecl.name.name);
|
||||
_impliedDartTypeWithName(typeProvider, varDecl.name2.lexeme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,9 @@ class FieldFormalContributor extends DartCompletionContributor {
|
|||
param = param.parameter;
|
||||
}
|
||||
if (param is FieldFormalParameter) {
|
||||
var fieldId = param.identifier;
|
||||
var fieldId = param.name;
|
||||
if (fieldId != request.target.entity) {
|
||||
var fieldName = fieldId.name;
|
||||
var fieldName = fieldId.lexeme;
|
||||
if (fieldName.isNotEmpty) {
|
||||
referencedFields.add(fieldName);
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor<void> {
|
|||
void visitClassDeclaration(ClassDeclaration node) {
|
||||
final entity = this.entity;
|
||||
// Don't suggest class name
|
||||
if (entity == node.name) {
|
||||
if (entity == node.name2) {
|
||||
return;
|
||||
}
|
||||
if (entity == node.rightBracket) {
|
||||
|
@ -266,7 +266,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (entity == node.name) {
|
||||
if (entity == node.name2) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -298,7 +298,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor<void> {
|
|||
@override
|
||||
void visitExtensionDeclaration(ExtensionDeclaration node) {
|
||||
// Don't suggest extension name
|
||||
if (entity == node.name) {
|
||||
if (entity == node.name2) {
|
||||
return;
|
||||
}
|
||||
if (entity == node.rightBracket) {
|
||||
|
@ -407,15 +407,13 @@ class _KeywordVisitor extends GeneralizingAstVisitor<void> {
|
|||
bool hasCovariant() {
|
||||
var last = lastParameter();
|
||||
return last != null &&
|
||||
(last.covariantKeyword != null ||
|
||||
last.identifier?.name == 'covariant');
|
||||
(last.covariantKeyword != null || last.name?.lexeme == 'covariant');
|
||||
}
|
||||
|
||||
bool hasRequired() {
|
||||
var last = lastParameter();
|
||||
return last != null &&
|
||||
(last.requiredKeyword != null ||
|
||||
last.identifier?.name == 'required');
|
||||
(last.requiredKeyword != null || last.name?.lexeme == 'required');
|
||||
}
|
||||
|
||||
var tokenType = entity.type;
|
||||
|
@ -494,7 +492,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor<void> {
|
|||
void visitFunctionDeclaration(FunctionDeclaration node) {
|
||||
// If the cursor is at the beginning of the declaration, include the
|
||||
// compilation unit keywords. See dartbug.com/41039.
|
||||
if (entity == node.returnType || entity == node.name) {
|
||||
if (entity == node.returnType || entity == node.name2) {
|
||||
_addSuggestion(Keyword.DYNAMIC);
|
||||
_addSuggestion(Keyword.VOID);
|
||||
}
|
||||
|
@ -617,7 +615,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor<void> {
|
|||
_addSuggestion2(SYNC_STAR);
|
||||
}
|
||||
}
|
||||
} else if (entity == node.returnType || entity == node.name) {
|
||||
} else if (entity == node.returnType || entity == node.name2) {
|
||||
// If the cursor is at the beginning of the declaration, include the class
|
||||
// body keywords. See dartbug.com/41039.
|
||||
_addClassBodyKeywords();
|
||||
|
@ -645,7 +643,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor<void> {
|
|||
void visitMixinDeclaration(MixinDeclaration node) {
|
||||
final entity = this.entity;
|
||||
// Don't suggest mixin name
|
||||
if (entity == node.name) {
|
||||
if (entity == node.name2) {
|
||||
return;
|
||||
}
|
||||
if (entity == node.rightBracket) {
|
||||
|
|
|
@ -241,7 +241,7 @@ class _LocalVisitor extends LocalDeclarationVisitor {
|
|||
if (declaredElement != null &&
|
||||
visibilityTracker._isVisible(declaredElement) &&
|
||||
opType.includeReturnValueSuggestions &&
|
||||
declaration.name != null) {
|
||||
declaration.name2 != null) {
|
||||
builder.suggestExtension(declaredElement, kind: _defaultKind);
|
||||
}
|
||||
}
|
||||
|
@ -316,10 +316,14 @@ class _LocalVisitor extends LocalDeclarationVisitor {
|
|||
}
|
||||
|
||||
@override
|
||||
void declaredLocalVar(SimpleIdentifier name, TypeAnnotation? type) {
|
||||
if (visibilityTracker._isVisible(name.staticElement) &&
|
||||
void declaredLocalVar(
|
||||
Token name,
|
||||
TypeAnnotation? type,
|
||||
LocalVariableElement declaredElement,
|
||||
) {
|
||||
if (visibilityTracker._isVisible(declaredElement) &&
|
||||
opType.includeReturnValueSuggestions) {
|
||||
builder.suggestLocalVariable(name.staticElement as LocalVariableElement);
|
||||
builder.suggestLocalVariable(declaredElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
|
||||
import 'package:analyzer_plugin/src/utilities/completion/completion_target.dart';
|
||||
|
||||
|
@ -14,11 +15,12 @@ class OverrideContributor extends DartCompletionContributor {
|
|||
|
||||
@override
|
||||
Future<void> computeSuggestions() async {
|
||||
var targetId = _getTargetId(request.target);
|
||||
if (targetId == null) {
|
||||
final target = _getTargetId(request.target);
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
var classDecl = targetId.thisOrAncestorOfType<ClassOrMixinDeclaration>();
|
||||
var classDecl =
|
||||
target.enclosingNode.thisOrAncestorOfType<ClassOrMixinDeclaration>();
|
||||
if (classDecl == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -41,14 +43,14 @@ class OverrideContributor extends DartCompletionContributor {
|
|||
// Gracefully degrade if the overridden element has not been resolved.
|
||||
if (element != null) {
|
||||
var invokeSuper = interface.isSuperImplemented(name);
|
||||
await builder.suggestOverride(targetId, element, invokeSuper);
|
||||
await builder.suggestOverride(target.id, element, invokeSuper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If the target looks like a partial identifier inside a class declaration
|
||||
/// then return that identifier, otherwise return `null`.
|
||||
SimpleIdentifier? _getTargetId(CompletionTarget target) {
|
||||
_Target? _getTargetId(CompletionTarget target) {
|
||||
var node = target.containingNode;
|
||||
if (node is ClassOrMixinDeclaration) {
|
||||
var entity = target.entity;
|
||||
|
@ -64,23 +66,23 @@ class OverrideContributor extends DartCompletionContributor {
|
|||
return null;
|
||||
}
|
||||
|
||||
SimpleIdentifier? _getTargetIdFromVarList(VariableDeclarationList fields) {
|
||||
_Target? _getTargetIdFromVarList(VariableDeclarationList fields) {
|
||||
var variables = fields.variables;
|
||||
var type = fields.type;
|
||||
if (variables.length == 1) {
|
||||
var variable = variables[0];
|
||||
var targetId = variable.name;
|
||||
if (targetId.name.isEmpty) {
|
||||
var targetId = variable.name2;
|
||||
if (targetId.lexeme.isEmpty) {
|
||||
// analyzer parser
|
||||
// Actual: class C { foo^ }
|
||||
// Parsed: class C { foo^ _s_ }
|
||||
// where _s_ is a synthetic id inserted by the analyzer parser
|
||||
return targetId;
|
||||
return _Target(fields, targetId);
|
||||
} else if (fields.keyword == null &&
|
||||
type == null &&
|
||||
variable.initializer == null) {
|
||||
// fasta parser does not insert a synthetic identifier
|
||||
return targetId;
|
||||
return _Target(fields, targetId);
|
||||
} else if (fields.keyword == null &&
|
||||
type is NamedType &&
|
||||
type.typeArguments == null &&
|
||||
|
@ -93,7 +95,7 @@ class OverrideContributor extends DartCompletionContributor {
|
|||
// Parses as a variable list where `m` is the type and `String` is a
|
||||
// variable.
|
||||
var name = type.name;
|
||||
return name is SimpleIdentifier ? name : null;
|
||||
return name is SimpleIdentifier ? _Target(fields, name.token) : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -113,3 +115,10 @@ class OverrideContributor extends DartCompletionContributor {
|
|||
return namesToOverride;
|
||||
}
|
||||
}
|
||||
|
||||
class _Target {
|
||||
final AstNode enclosingNode;
|
||||
final Token id;
|
||||
|
||||
_Target(this.enclosingNode, this.id);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import 'package:analysis_server/src/utilities/extensions/element.dart';
|
|||
import 'package:analysis_server/src/utilities/flutter.dart';
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
|
@ -222,7 +223,7 @@ class SuggestionBuilder {
|
|||
var containingMethod = request.target.containingNode
|
||||
.thisOrAncestorOfType<MethodDeclaration>();
|
||||
if (containingMethod != null) {
|
||||
_cachedContainingMemberName = containingMethod.name.name;
|
||||
_cachedContainingMemberName = containingMethod.name2.lexeme;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -831,12 +832,12 @@ class SuggestionBuilder {
|
|||
/// Add a suggestion to replace the [targetId] with an override of the given
|
||||
/// [element]. If [invokeSuper] is `true`, then the override will contain an
|
||||
/// invocation of an overridden member.
|
||||
Future<void> suggestOverride(SimpleIdentifier targetId,
|
||||
ExecutableElement element, bool invokeSuper) async {
|
||||
Future<void> suggestOverride(
|
||||
Token targetId, ExecutableElement element, bool invokeSuper) async {
|
||||
var displayTextBuffer = StringBuffer();
|
||||
var builder = ChangeBuilder(session: request.analysisSession);
|
||||
await builder.addDartFileEdit(request.path, (builder) {
|
||||
builder.addReplacement(range.node(targetId), (builder) {
|
||||
builder.addReplacement(range.token(targetId), (builder) {
|
||||
builder.writeOverride(
|
||||
element,
|
||||
displayTextBuffer: displayTextBuffer,
|
||||
|
|
|
@ -110,7 +110,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
|
|||
|
||||
@override
|
||||
void declaredClass(ClassDeclaration declaration) {
|
||||
if (declaration.name.name == targetName) {
|
||||
if (declaration.name2.lexeme == targetName) {
|
||||
// no type
|
||||
finished();
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
|
|||
|
||||
@override
|
||||
void declaredClassTypeAlias(ClassTypeAlias declaration) {
|
||||
if (declaration.name.name == targetName) {
|
||||
if (declaration.name2.lexeme == targetName) {
|
||||
// no type
|
||||
finished();
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
|
|||
|
||||
@override
|
||||
void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
|
||||
if (varDecl.name.name == targetName) {
|
||||
if (varDecl.name2.lexeme == targetName) {
|
||||
// Type provided by the element in computeFull above
|
||||
finished();
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
|
|||
|
||||
@override
|
||||
void declaredFunction(FunctionDeclaration declaration) {
|
||||
if (declaration.name.name == targetName) {
|
||||
if (declaration.name2.lexeme == targetName) {
|
||||
var returnType = declaration.returnType;
|
||||
if (returnType != null) {
|
||||
var type = returnType.type;
|
||||
|
@ -148,7 +148,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
|
|||
|
||||
@override
|
||||
void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {
|
||||
if (declaration.name.name == targetName) {
|
||||
if (declaration.name2.lexeme == targetName) {
|
||||
var returnType = declaration.returnType;
|
||||
if (returnType != null) {
|
||||
var type = returnType.type;
|
||||
|
@ -162,7 +162,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
|
|||
|
||||
@override
|
||||
void declaredGenericTypeAlias(GenericTypeAlias declaration) {
|
||||
if (declaration.name.name == targetName) {
|
||||
if (declaration.name2.lexeme == targetName) {
|
||||
var returnType = declaration.functionType?.returnType;
|
||||
if (returnType != null) {
|
||||
var type = returnType.type;
|
||||
|
@ -183,17 +183,20 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
|
|||
}
|
||||
|
||||
@override
|
||||
void declaredLocalVar(SimpleIdentifier name, TypeAnnotation? type) {
|
||||
if (name.name == targetName) {
|
||||
var element = name.staticElement as VariableElement;
|
||||
typeFound = element.type;
|
||||
void declaredLocalVar(
|
||||
Token name,
|
||||
TypeAnnotation? type,
|
||||
LocalVariableElement declaredElement,
|
||||
) {
|
||||
if (name.lexeme == targetName) {
|
||||
typeFound = declaredElement.type;
|
||||
finished();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void declaredMethod(MethodDeclaration declaration) {
|
||||
if (declaration.name.name == targetName) {
|
||||
if (declaration.name2.lexeme == targetName) {
|
||||
var returnType = declaration.returnType;
|
||||
if (returnType != null) {
|
||||
var type = returnType.type;
|
||||
|
@ -216,7 +219,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
|
|||
@override
|
||||
void declaredTopLevelVar(
|
||||
VariableDeclarationList varList, VariableDeclaration varDecl) {
|
||||
if (varDecl.name.name == targetName) {
|
||||
if (varDecl.name2.lexeme == targetName) {
|
||||
// Type provided by the element in computeFull above.
|
||||
finished();
|
||||
}
|
||||
|
|
|
@ -37,8 +37,12 @@ class VariableNameContributor extends DartCompletionContributor {
|
|||
strName = _getStringName(expression);
|
||||
}
|
||||
} else if (node is SimpleFormalParameter) {
|
||||
var identifier = _formalParameterTypeIdentifier(node);
|
||||
strName = _getStringName(identifier);
|
||||
var identifier = _formalParameterTypeIdentifier2(node);
|
||||
if (identifier != null) {
|
||||
strName = _getStringName(identifier);
|
||||
} else {
|
||||
strName = node.name?.lexeme;
|
||||
}
|
||||
} else if (node is VariableDeclarationList) {
|
||||
var identifier = _typeAnnotationIdentifier(node.type);
|
||||
strName = _getStringName(identifier);
|
||||
|
@ -57,7 +61,7 @@ class VariableNameContributor extends DartCompletionContributor {
|
|||
var varDeclarations = varDeclarationList.variables;
|
||||
if (varDeclarations.length == 1) {
|
||||
var declaration = varDeclarations.first;
|
||||
strName = _getStringName(declaration.name);
|
||||
strName = declaration.name2.lexeme;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,13 +104,12 @@ class VariableNameContributor extends DartCompletionContributor {
|
|||
return id.name;
|
||||
}
|
||||
|
||||
static Identifier? _formalParameterTypeIdentifier(FormalParameter node) {
|
||||
static Identifier? _formalParameterTypeIdentifier2(FormalParameter node) {
|
||||
if (node is SimpleFormalParameter) {
|
||||
var type = node.type;
|
||||
if (type != null) {
|
||||
return _typeAnnotationIdentifier(type);
|
||||
}
|
||||
return node.identifier;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -238,6 +238,8 @@ class CorrectionProducerContext {
|
|||
|
||||
final AstNode node;
|
||||
|
||||
final Token token;
|
||||
|
||||
CorrectionProducerContext._({
|
||||
required this.resolvedResult,
|
||||
required this.workspace,
|
||||
|
@ -245,6 +247,7 @@ class CorrectionProducerContext {
|
|||
this.dartFixContext,
|
||||
this.diagnostic,
|
||||
required this.node,
|
||||
required this.token,
|
||||
this.overrideSet,
|
||||
this.selectionOffset = -1,
|
||||
this.selectionLength = 0,
|
||||
|
@ -271,10 +274,13 @@ class CorrectionProducerContext {
|
|||
var node = locator.searchWithin(resolvedResult.unit);
|
||||
node ??= resolvedResult.unit;
|
||||
|
||||
final token = _tokenAt(node, selectionOffset) ?? node.beginToken;
|
||||
|
||||
return CorrectionProducerContext._(
|
||||
resolvedResult: resolvedResult,
|
||||
workspace: workspace,
|
||||
node: node,
|
||||
token: token,
|
||||
applyingBulkFixes: applyingBulkFixes,
|
||||
dartFixContext: dartFixContext,
|
||||
diagnostic: diagnostic,
|
||||
|
@ -283,6 +289,21 @@ class CorrectionProducerContext {
|
|||
selectionLength: selectionLength,
|
||||
);
|
||||
}
|
||||
|
||||
static Token? _tokenAt(AstNode node, int offset) {
|
||||
for (final entity in node.childEntities) {
|
||||
if (entity is AstNode) {
|
||||
if (entity.offset <= offset && offset <= entity.end) {
|
||||
return _tokenAt(entity, offset);
|
||||
}
|
||||
} else if (entity is Token) {
|
||||
if (entity.offset <= offset && offset <= entity.end) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class CorrectionProducerWithDiagnostic extends CorrectionProducer {
|
||||
|
@ -437,6 +458,8 @@ abstract class _AbstractCorrectionProducer {
|
|||
|
||||
AnalysisSessionHelper get sessionHelper => _context.sessionHelper;
|
||||
|
||||
Token get token => _context.token;
|
||||
|
||||
TypeProvider get typeProvider => _context.typeProvider;
|
||||
|
||||
/// Return the type system appropriate to the library in which the correction
|
||||
|
|
|
@ -48,7 +48,7 @@ class AddCallSuper extends CorrectionProducer {
|
|||
var parameters = methodDeclaration.parameters?.parameters;
|
||||
var argumentList = parameters
|
||||
?.map((p) {
|
||||
var name = p.identifier?.name;
|
||||
var name = p.name?.lexeme;
|
||||
if (overriddenParameters.contains(name)) {
|
||||
return p.isNamed ? '$name: $name' : name;
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
|
|||
|
||||
final debugFillProperties = classDeclaration.members
|
||||
.whereType<MethodDeclaration>()
|
||||
.where((e) => e.name.name == 'debugFillProperties')
|
||||
.where((e) => e.name2.lexeme == 'debugFillProperties')
|
||||
.singleOrNull;
|
||||
if (debugFillProperties == null) {
|
||||
var location = utils.prepareNewMethodLocation(classDeclaration);
|
||||
|
@ -167,10 +167,10 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
|
|||
for (var parameter in parameterList.parameters) {
|
||||
if (parameter is SimpleFormalParameter) {
|
||||
final type = parameter.type;
|
||||
final identifier = parameter.identifier;
|
||||
final identifier = parameter.name;
|
||||
if (type is NamedType && identifier != null) {
|
||||
if (type.name.name == 'DiagnosticPropertiesBuilder') {
|
||||
propertiesBuilderName = identifier.name;
|
||||
propertiesBuilderName = identifier.lexeme;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class AddEnumConstant extends CorrectionProducer {
|
|||
var length = constructors.length;
|
||||
if (length > 1) return;
|
||||
|
||||
var name = length == 1 ? constructors.first.name?.name : null;
|
||||
var name = length == 1 ? constructors.first.name2?.lexeme : null;
|
||||
|
||||
var offset = targetNode.constants.last.end;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:analysis_server/src/services/correction/assist.dart';
|
|||
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/syntactic_entity.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/dart/element/type_system.dart';
|
||||
|
@ -33,27 +33,28 @@ class AddReturnType extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
SyntacticEntity? insertBeforeEntity;
|
||||
Token? insertBeforeEntity;
|
||||
FunctionBody? body;
|
||||
if (node is SimpleIdentifier) {
|
||||
var executable = node.parent;
|
||||
if (executable is MethodDeclaration && executable.name == node) {
|
||||
if (executable is MethodDeclaration && executable.name2 == token) {
|
||||
if (executable.returnType != null) {
|
||||
return;
|
||||
}
|
||||
if (executable.isSetter) {
|
||||
return;
|
||||
}
|
||||
insertBeforeEntity = executable.propertyKeyword ?? executable.name;
|
||||
insertBeforeEntity = executable.propertyKeyword ?? executable.name2;
|
||||
body = executable.body;
|
||||
} else if (executable is FunctionDeclaration && executable.name == node) {
|
||||
} else if (executable is FunctionDeclaration &&
|
||||
executable.name2 == token) {
|
||||
if (executable.returnType != null) {
|
||||
return;
|
||||
}
|
||||
if (executable.isSetter) {
|
||||
return;
|
||||
}
|
||||
insertBeforeEntity = executable.propertyKeyword ?? executable.name;
|
||||
insertBeforeEntity = executable.propertyKeyword ?? executable.name2;
|
||||
body = executable.functionExpression.body;
|
||||
} else {
|
||||
return;
|
||||
|
|
|
@ -120,7 +120,7 @@ class AddTypeAnnotation extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
await _applyChange(builder, declaredIdentifier.keyword,
|
||||
declaredIdentifier.identifier.offset, type);
|
||||
declaredIdentifier.name.offset, type);
|
||||
}
|
||||
|
||||
Future<void> _forSimpleFormalParameter(ChangeBuilder builder,
|
||||
|
@ -150,7 +150,7 @@ class AddTypeAnnotation extends CorrectionProducer {
|
|||
final variables = declarationList.variables;
|
||||
final variable = variables[0];
|
||||
// Ensure that the selection is not after the name of the variable.
|
||||
if (selectionOffset > variable.name.end) {
|
||||
if (selectionOffset > variable.name2.end) {
|
||||
return;
|
||||
}
|
||||
// Ensure that there is an initializer to get the type from.
|
||||
|
|
|
@ -8,6 +8,8 @@ import 'package:analysis_server/src/services/correction/levenshtein.dart';
|
|||
import 'package:analysis_server/src/services/correction/util.dart';
|
||||
import 'package:analysis_server/src/services/search/hierarchy.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/syntactic_entity.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
|
@ -82,7 +84,7 @@ class ChangeTo extends CorrectionProducer {
|
|||
return element.parameters.where((superParam) =>
|
||||
superParam.isNamed &&
|
||||
!formalParameters
|
||||
.any((param) => superParam.name == param.identifier?.name));
|
||||
.any((param) => superParam.name == param.name?.lexeme));
|
||||
}
|
||||
|
||||
Future<void> _proposeAnnotation(ChangeBuilder builder) async {
|
||||
|
@ -130,17 +132,14 @@ class ChangeTo extends CorrectionProducer {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _proposeClassOrMixinMember(
|
||||
ChangeBuilder builder,
|
||||
SimpleIdentifier node,
|
||||
Expression? target,
|
||||
_ElementPredicate predicate) async {
|
||||
Future<void> _proposeClassOrMixinMember(ChangeBuilder builder, Token node,
|
||||
Expression? target, _ElementPredicate predicate) async {
|
||||
var targetIdentifierElement =
|
||||
target is Identifier ? target.staticElement : null;
|
||||
var finder = _ClosestElementFinder(node.name, predicate);
|
||||
var finder = _ClosestElementFinder(node.lexeme, predicate);
|
||||
// unqualified invocation
|
||||
if (target == null) {
|
||||
var clazz = node.thisOrAncestorOfType<ClassDeclaration>();
|
||||
var clazz = this.node.thisOrAncestorOfType<ClassDeclaration>();
|
||||
if (clazz != null) {
|
||||
var classElement = clazz.declaredElement!;
|
||||
_updateFinderWithClassMembers(finder, classElement);
|
||||
|
@ -177,7 +176,7 @@ class ChangeTo extends CorrectionProducer {
|
|||
var formalParameterList = node.thisOrAncestorOfType<FormalParameterList>();
|
||||
if (formalParameterList != null) {
|
||||
for (var parameter in formalParameterList.parameters) {
|
||||
var name = parameter.identifier?.name;
|
||||
var name = parameter.name?.lexeme;
|
||||
if (name != null) {
|
||||
exclusions.add(name);
|
||||
}
|
||||
|
@ -185,7 +184,7 @@ class ChangeTo extends CorrectionProducer {
|
|||
}
|
||||
|
||||
var type = node.type?.type;
|
||||
await _proposeClassOrMixinMember(builder, node.identifier, null,
|
||||
await _proposeClassOrMixinMember(builder, node.name, null,
|
||||
(Element element) {
|
||||
return element is FieldElement &&
|
||||
!exclusions.contains(element.name) &&
|
||||
|
@ -245,7 +244,7 @@ class ChangeTo extends CorrectionProducer {
|
|||
// find getter or setter
|
||||
var wantGetter = node.inGetterContext();
|
||||
var wantSetter = node.inSetterContext();
|
||||
await _proposeClassOrMixinMember(builder, node, target,
|
||||
await _proposeClassOrMixinMember(builder, node.token, target,
|
||||
(Element element) {
|
||||
if (element is PropertyAccessorElement) {
|
||||
return wantGetter && element.isGetter ||
|
||||
|
@ -263,7 +262,7 @@ class ChangeTo extends CorrectionProducer {
|
|||
final node = this.node;
|
||||
var parent = node.parent;
|
||||
if (parent is MethodInvocation && node is SimpleIdentifier) {
|
||||
await _proposeClassOrMixinMember(builder, node, parent.realTarget,
|
||||
await _proposeClassOrMixinMember(builder, node.token, parent.realTarget,
|
||||
(Element element) => element is MethodElement && !element.isOperator);
|
||||
}
|
||||
}
|
||||
|
@ -279,8 +278,7 @@ class ChangeTo extends CorrectionProducer {
|
|||
var formalParameters = constructorDeclaration.parameters.parameters
|
||||
.whereType<DefaultFormalParameter>();
|
||||
|
||||
var finder =
|
||||
_ClosestElementFinder(parent.identifier.name, (Element e) => true);
|
||||
var finder = _ClosestElementFinder(parent.name.lexeme, (Element e) => true);
|
||||
|
||||
var superInvocation = constructorDeclaration.initializers.lastOrNull;
|
||||
|
||||
|
@ -312,11 +310,11 @@ class ChangeTo extends CorrectionProducer {
|
|||
}
|
||||
|
||||
Future<void> _suggest(
|
||||
ChangeBuilder builder, AstNode node, String? name) async {
|
||||
ChangeBuilder builder, SyntacticEntity node, String? name) async {
|
||||
if (name != null) {
|
||||
_proposedName = name;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(range.node(node), _proposedName);
|
||||
builder.addSimpleReplacement(range.entity(node), _proposedName);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,12 +51,8 @@ class ConvertClassToEnum extends CorrectionProducer {
|
|||
// the class.
|
||||
return;
|
||||
}
|
||||
var node = this.node;
|
||||
if (node is! SimpleIdentifier) {
|
||||
return;
|
||||
}
|
||||
var parent = node.parent;
|
||||
if (parent is ClassDeclaration && parent.name == node) {
|
||||
if (parent is ClassDeclaration && parent.name2 == token) {
|
||||
var description = _EnumDescription.fromClass(parent);
|
||||
if (description != null) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
|
@ -309,7 +305,7 @@ class _EnumDescription {
|
|||
return null;
|
||||
}
|
||||
var constructor = constructors[0];
|
||||
var name = constructor.name?.name;
|
||||
var name = constructor.name2?.lexeme;
|
||||
if (name != null && name != 'new') {
|
||||
return null;
|
||||
}
|
||||
|
@ -634,7 +630,8 @@ class _EnumDescription {
|
|||
static bool _validateMethods(ClassDeclaration classDeclaration) {
|
||||
for (var member in classDeclaration.members) {
|
||||
if (member is MethodDeclaration) {
|
||||
if (member.name.name == '==' || member.name.name == 'hashCode') {
|
||||
final name = member.name2.lexeme;
|
||||
if (name == '==' || name == 'hashCode') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -700,7 +697,7 @@ class _Field {
|
|||
this.fieldDeclaration);
|
||||
|
||||
/// Return the name of the field.
|
||||
String get name => declaration.name.name;
|
||||
String get name => declaration.name2.lexeme;
|
||||
}
|
||||
|
||||
/// A representation of all the fields of interest in the class being converted.
|
||||
|
|
|
@ -22,7 +22,7 @@ class ConvertClassToMixin extends CorrectionProducer {
|
|||
if (classDeclaration == null) {
|
||||
return;
|
||||
}
|
||||
if (selectionOffset > classDeclaration.name.end ||
|
||||
if (selectionOffset > classDeclaration.name2.end ||
|
||||
selectionEnd < classDeclaration.classKeyword.offset) {
|
||||
return;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class ConvertClassToMixin extends CorrectionProducer {
|
|||
classDeclaration.abstractKeyword ?? classDeclaration.classKeyword,
|
||||
classDeclaration.leftBracket), (builder) {
|
||||
builder.write('mixin ');
|
||||
builder.write(classDeclaration.name.name);
|
||||
builder.write(classDeclaration.name2.lexeme);
|
||||
builder.writeTypeParameters(classElement.typeParameters);
|
||||
builder.writeTypes(superclassConstraints, prefix: ' on ');
|
||||
builder.writeTypes(interfaces, prefix: ' implements ');
|
||||
|
|
|
@ -46,7 +46,7 @@ class ConvertForEachToForLoop extends CorrectionProducer {
|
|||
if (parameter is! NormalFormalParameter) {
|
||||
return;
|
||||
}
|
||||
var loopVariableName = parameter.identifier?.name;
|
||||
var loopVariableName = parameter.name?.lexeme;
|
||||
if (loopVariableName == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ class ConvertIntoFinalField extends CorrectionProducer {
|
|||
if (returnType != null) {
|
||||
code += ' ${utils.getNodeText(returnType)}';
|
||||
}
|
||||
code += ' ${utils.getNodeText(getter.name)}';
|
||||
code += ' ${getter.name2.lexeme}';
|
||||
if (expression is! NullLiteral) {
|
||||
code += ' = ${utils.getNodeText(expression)}';
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ class ConvertIntoGetter extends CorrectionProducer {
|
|||
code += '${utils.getNodeText(typeAnnotation)} ';
|
||||
}
|
||||
code += 'get';
|
||||
code += ' ${utils.getNodeText(field.name)}';
|
||||
code += ' ${field.name2.lexeme}';
|
||||
code += ' => ${utils.getNodeText(initializer)}';
|
||||
code += ';';
|
||||
var replacementRange = range.startEnd(finalKeyword, fieldDeclaration);
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:analysis_server/src/services/correction/assist.dart';
|
|||
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer_plugin/utilities/assist/assist.dart';
|
||||
|
@ -67,9 +68,9 @@ class ConvertMapFromIterableToForLiteral extends CorrectionProducer {
|
|||
// necessary.
|
||||
//
|
||||
var keyParameter = keyClosure.parameter;
|
||||
var keyParameterName = keyClosure.parameterIdentifier.name;
|
||||
var keyParameterName = keyClosure.parameterIdentifier.lexeme;
|
||||
var valueParameter = valueClosure.parameter;
|
||||
var valueParameterName = valueClosure.parameterIdentifier.name;
|
||||
var valueParameterName = valueClosure.parameterIdentifier.lexeme;
|
||||
var keyExpressionText = utils.getNodeText(keyClosure.body);
|
||||
var valueExpressionText = utils.getNodeText(valueClosure.body);
|
||||
|
||||
|
@ -172,7 +173,7 @@ class ConvertMapFromIterableToForLiteral extends CorrectionProducer {
|
|||
var parameter = parameters[0];
|
||||
if (parameter is SimpleFormalParameter &&
|
||||
parameter.isRequiredPositional) {
|
||||
var parameterIdentifier = parameter.identifier;
|
||||
var parameterIdentifier = parameter.name;
|
||||
if (parameterIdentifier != null) {
|
||||
var body = _extractBody(expression);
|
||||
if (body != null) {
|
||||
|
@ -190,7 +191,7 @@ class ConvertMapFromIterableToForLiteral extends CorrectionProducer {
|
|||
|
||||
class _Closure {
|
||||
final SimpleFormalParameter parameter;
|
||||
final SimpleIdentifier parameterIdentifier;
|
||||
final Token parameterIdentifier;
|
||||
final Expression body;
|
||||
|
||||
_Closure(this.parameter, this.parameterIdentifier, this.body);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analysis_server/src/services/correction/assist.dart';
|
||||
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer_plugin/utilities/assist/assist.dart';
|
||||
|
@ -24,7 +25,7 @@ class ConvertToFieldParameter extends CorrectionProducer {
|
|||
}
|
||||
|
||||
// analyze parameter
|
||||
var parameterName = context.identifier.name;
|
||||
var parameterName = context.identifier.lexeme;
|
||||
var parameterElement = context.parameter.declaredElement!;
|
||||
var initializers = context.constructor.initializers;
|
||||
|
||||
|
@ -88,7 +89,7 @@ class ConvertToFieldParameter extends CorrectionProducer {
|
|||
static _Context? _findParameter(AstNode node) {
|
||||
var parent = node.parent;
|
||||
if (parent is SimpleFormalParameter) {
|
||||
var identifier = parent.identifier;
|
||||
var identifier = parent.name;
|
||||
if (identifier == null) return null;
|
||||
|
||||
var formalParameterList = parent.parent;
|
||||
|
@ -111,8 +112,8 @@ class ConvertToFieldParameter extends CorrectionProducer {
|
|||
if (parent.expression == node) {
|
||||
for (var formalParameter in constructor.parameters.parameters) {
|
||||
if (formalParameter is SimpleFormalParameter) {
|
||||
var identifier = formalParameter.identifier;
|
||||
if (identifier != null && identifier.name == node.name) {
|
||||
var identifier = formalParameter.name;
|
||||
if (identifier != null && identifier.lexeme == node.name) {
|
||||
return _Context(
|
||||
parameter: formalParameter,
|
||||
identifier: identifier,
|
||||
|
@ -130,7 +131,7 @@ class ConvertToFieldParameter extends CorrectionProducer {
|
|||
|
||||
class _Context {
|
||||
final SimpleFormalParameter parameter;
|
||||
final SimpleIdentifier identifier;
|
||||
final Token identifier;
|
||||
final ConstructorDeclaration constructor;
|
||||
|
||||
_Context({
|
||||
|
|
|
@ -76,7 +76,7 @@ class ConvertToGenericFunctionSyntax extends CorrectionProducer {
|
|||
}
|
||||
|
||||
var functionName = utils.getRangeText(
|
||||
range.startEnd(node.name, node.typeParameters ?? node.name));
|
||||
range.startEnd(node.name2, node.typeParameters ?? node.name2));
|
||||
var parameters = utils.getNodeText(node.parameters);
|
||||
String replacement;
|
||||
if (returnType == null) {
|
||||
|
@ -102,8 +102,8 @@ class ConvertToGenericFunctionSyntax extends CorrectionProducer {
|
|||
var returnTypeNode = node.returnType;
|
||||
var returnType =
|
||||
returnTypeNode != null ? '${utils.getNodeText(returnTypeNode)} ' : '';
|
||||
var functionName = utils.getRangeText(range.startEnd(
|
||||
node.identifier, node.typeParameters ?? node.identifier));
|
||||
var functionName = utils.getRangeText(
|
||||
range.startEnd(node.name, node.typeParameters ?? node.name));
|
||||
var parameters = utils.getNodeText(node.parameters);
|
||||
var question = node.question != null ? '?' : '';
|
||||
var replacement =
|
||||
|
|
|
@ -39,7 +39,7 @@ class ConvertToInitializingFormal extends CorrectionProducer {
|
|||
if (parameter == null) {
|
||||
return;
|
||||
}
|
||||
var identifier = parameter.identifier;
|
||||
var identifier = parameter.name;
|
||||
if (identifier == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class ConvertToInitializingFormal extends CorrectionProducer {
|
|||
builder.addSimpleInsertion(identifier.offset, 'this.');
|
||||
} else {
|
||||
builder.addSimpleReplacement(
|
||||
range.node(parameter), 'this.${identifier.name}');
|
||||
range.node(parameter), 'this.${identifier.lexeme}');
|
||||
}
|
||||
|
||||
var statements = block.statements;
|
||||
|
@ -68,7 +68,7 @@ class ConvertToInitializingFormal extends CorrectionProducer {
|
|||
if (parameter == null) {
|
||||
return;
|
||||
}
|
||||
var identifier = parameter.identifier;
|
||||
var identifier = parameter.name;
|
||||
if (identifier == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ class ConvertToInitializingFormal extends CorrectionProducer {
|
|||
builder.addSimpleInsertion(identifier.offset, 'this.');
|
||||
} else {
|
||||
builder.addSimpleReplacement(
|
||||
range.node(parameter), 'this.${identifier.name}');
|
||||
range.node(parameter), 'this.${identifier.lexeme}');
|
||||
}
|
||||
|
||||
var initializers = constructor.initializers;
|
||||
|
|
|
@ -241,7 +241,7 @@ class ConvertToSuperParameters extends CorrectionProducer {
|
|||
}
|
||||
|
||||
var parameterNode = parameter.parameter;
|
||||
var identifier = parameterNode.identifier;
|
||||
var identifier = parameterNode.name;
|
||||
if (identifier == null) {
|
||||
// This condition should never occur, but the test is here to promote the
|
||||
// type.
|
||||
|
@ -272,7 +272,7 @@ class ConvertToSuperParameters extends CorrectionProducer {
|
|||
var superDefault = superParameter.computeConstantValue();
|
||||
var thisDefault = thisParameter.computeConstantValue();
|
||||
if (superDefault != null && superDefault == thisDefault) {
|
||||
return range.endEnd(parameter.identifier!, defaultValue);
|
||||
return range.endEnd(parameter.name!, defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -410,14 +410,13 @@ class ConvertToSuperParameters extends CorrectionProducer {
|
|||
var typeAnnotation = parameter.type;
|
||||
if (typeAnnotation != null) {
|
||||
return _TypeData(
|
||||
primaryRange:
|
||||
range.startStart(typeAnnotation, parameter.identifier!));
|
||||
primaryRange: range.startStart(typeAnnotation, parameter.name!));
|
||||
}
|
||||
} else if (parameter is FunctionTypedFormalParameter) {
|
||||
var returnType = parameter.returnType;
|
||||
return _TypeData(
|
||||
primaryRange: returnType != null
|
||||
? range.startStart(returnType, parameter.identifier)
|
||||
? range.startStart(returnType, parameter.name)
|
||||
: null,
|
||||
parameterRange: range.node(parameter.parameters));
|
||||
}
|
||||
|
@ -452,7 +451,7 @@ class _ParameterData {
|
|||
final _TypeData? typeToDelete;
|
||||
|
||||
/// The name.
|
||||
final Identifier name;
|
||||
final Token name;
|
||||
|
||||
/// Whether to add a default initializer with `null` value or not.
|
||||
final bool nullInitializer;
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:analysis_server/src/services/correction/dart/abstract_producer.d
|
|||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analysis_server/src/services/correction/util.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
|
@ -36,22 +37,23 @@ class CreateConstructor extends CorrectionProducer {
|
|||
if (node is SimpleIdentifier) {
|
||||
var parent = node.parent;
|
||||
if (parent is ConstructorName) {
|
||||
await _proposeFromConstructorName(builder, node, parent);
|
||||
await _proposeFromConstructorName(builder, node.token, parent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
var parent = node.thisOrAncestorOfType<EnumConstantDeclaration>();
|
||||
if (parent != null) {
|
||||
await _proposeFromEnumConstantDeclaration(builder, parent.name, parent);
|
||||
await _proposeFromEnumConstantDeclaration(
|
||||
builder, parent.name2, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _proposeFromConstructorName(ChangeBuilder builder,
|
||||
SimpleIdentifier name, ConstructorName constructorName) async {
|
||||
Future<void> _proposeFromConstructorName(ChangeBuilder builder, Token name,
|
||||
ConstructorName constructorName) async {
|
||||
InstanceCreationExpression? instanceCreation;
|
||||
_constructorName = constructorName.toSource();
|
||||
if (constructorName.name == name) {
|
||||
if (constructorName.name?.token == name) {
|
||||
var grandParent = constructorName.parent;
|
||||
// Type.name
|
||||
if (grandParent is InstanceCreationExpression) {
|
||||
|
@ -101,8 +103,8 @@ class CreateConstructor extends CorrectionProducer {
|
|||
constructorName: name, argumentList: instanceCreation.argumentList);
|
||||
}
|
||||
|
||||
Future<void> _proposeFromEnumConstantDeclaration(ChangeBuilder builder,
|
||||
SimpleIdentifier name, EnumConstantDeclaration parent) async {
|
||||
Future<void> _proposeFromEnumConstantDeclaration(
|
||||
ChangeBuilder builder, Token name, EnumConstantDeclaration parent) async {
|
||||
var grandParent = parent.parent;
|
||||
if (grandParent is! EnumDeclaration) {
|
||||
return;
|
||||
|
@ -137,7 +139,7 @@ class CreateConstructor extends CorrectionProducer {
|
|||
|
||||
var arguments = parent.arguments;
|
||||
_constructorName =
|
||||
'${targetNode.name}${arguments?.constructorSelector ?? ''}';
|
||||
'${targetNode.name2.lexeme}${arguments?.constructorSelector ?? ''}';
|
||||
|
||||
await _write(
|
||||
builder,
|
||||
|
@ -145,7 +147,7 @@ class CreateConstructor extends CorrectionProducer {
|
|||
targetElement,
|
||||
targetLocation,
|
||||
isConst: true,
|
||||
constructorName: arguments?.constructorSelector?.name,
|
||||
constructorName: arguments?.constructorSelector?.name.token,
|
||||
argumentList: arguments?.argumentList,
|
||||
);
|
||||
}
|
||||
|
@ -199,10 +201,10 @@ class CreateConstructor extends CorrectionProducer {
|
|||
|
||||
Future<void> _write(
|
||||
ChangeBuilder builder,
|
||||
SimpleIdentifier name,
|
||||
Token name,
|
||||
ClassElement targetElement,
|
||||
InsertionLocation targetLocation, {
|
||||
SimpleIdentifier? constructorName,
|
||||
Token? constructorName,
|
||||
bool isConst = false,
|
||||
ArgumentList? argumentList,
|
||||
}) async {
|
||||
|
@ -213,12 +215,12 @@ class CreateConstructor extends CorrectionProducer {
|
|||
builder.writeConstructorDeclaration(targetElement.name,
|
||||
isConst: isConst,
|
||||
argumentList: argumentList,
|
||||
constructorName: constructorName,
|
||||
constructorName: constructorName?.lexeme,
|
||||
constructorNameGroupName: 'NAME');
|
||||
builder.write(targetLocation.suffix);
|
||||
});
|
||||
if (targetFile == file) {
|
||||
builder.addLinkedPosition(range.node(name), 'NAME');
|
||||
builder.addLinkedPosition(range.token(name), 'NAME');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class CreateConstructorForFinalFields extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
|
||||
var className = classDeclaration.name.name;
|
||||
var className = classDeclaration.name2.lexeme;
|
||||
var superType = classDeclaration.declaredElement?.supertype;
|
||||
if (superType == null) {
|
||||
return;
|
||||
|
@ -70,7 +70,7 @@ class CreateConstructorForFinalFields extends CorrectionProducer {
|
|||
for (var variableList in variableLists) {
|
||||
fieldNames.addAll(variableList.variables
|
||||
.where((v) => v.initializer == null)
|
||||
.map((v) => v.name.name));
|
||||
.map((v) => v.name2.lexeme));
|
||||
}
|
||||
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
|
@ -143,7 +143,7 @@ class CreateConstructorForFinalFields extends CorrectionProducer {
|
|||
for (var variableList in variableLists) {
|
||||
var fieldNames = variableList.variables
|
||||
.where((v) => v.initializer == null)
|
||||
.map((v) => v.name.name);
|
||||
.map((v) => v.name2.lexeme);
|
||||
|
||||
for (var fieldName in fieldNames) {
|
||||
if (fieldName == 'child' || fieldName == 'children') {
|
||||
|
|
|
@ -37,8 +37,7 @@ class CreateField extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
|
||||
var nameNode = parameter.identifier;
|
||||
_fieldName = nameNode.name;
|
||||
_fieldName = parameter.name.lexeme;
|
||||
|
||||
var targetLocation = utils.prepareNewFieldLocation(targetClassNode);
|
||||
if (targetLocation == null) {
|
||||
|
|
|
@ -68,7 +68,7 @@ class CreateMethod extends CorrectionProducer {
|
|||
final classElement = classDecl.declaredElement!;
|
||||
|
||||
var missingEquals = memberDecl is FieldDeclaration ||
|
||||
(memberDecl as MethodDeclaration).name.name == 'hashCode';
|
||||
(memberDecl as MethodDeclaration).name2.lexeme == 'hashCode';
|
||||
ExecutableElement? element;
|
||||
if (missingEquals) {
|
||||
_memberName = '==';
|
||||
|
|
|
@ -34,7 +34,7 @@ class DataDriven extends MultiCorrectionProducer {
|
|||
importedUris.add(uri.relativeUri);
|
||||
}
|
||||
}
|
||||
var matchers = ElementMatcher.matchersForNode(node);
|
||||
var matchers = ElementMatcher.matchersForNode(node, token);
|
||||
if (matchers.isEmpty) {
|
||||
// The node doesn't represent any element that can be transformed.
|
||||
return;
|
||||
|
|
|
@ -40,15 +40,15 @@ class EncapsulateField extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
var field = fields.first;
|
||||
var nameNode = field.name;
|
||||
var nameToken = field.name2;
|
||||
var fieldElement = field.declaredElement as FieldElement;
|
||||
// should have a public name
|
||||
var name = nameNode.name;
|
||||
var name = nameToken.lexeme;
|
||||
if (Identifier.isPrivateName(name)) {
|
||||
return;
|
||||
}
|
||||
// should be on the name
|
||||
if (nameNode != node) {
|
||||
if (nameToken != token) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -60,17 +60,17 @@ class EncapsulateField extends CorrectionProducer {
|
|||
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
// rename field
|
||||
builder.addSimpleReplacement(range.node(nameNode), '_$name');
|
||||
builder.addSimpleReplacement(range.token(nameToken), '_$name');
|
||||
// update references in constructors
|
||||
for (var member in classDeclaration.members) {
|
||||
if (member is ConstructorDeclaration) {
|
||||
for (var parameter in member.parameters.parameters) {
|
||||
var identifier = parameter.identifier;
|
||||
var identifier = parameter.name;
|
||||
var parameterElement = parameter.declaredElement;
|
||||
if (identifier != null &&
|
||||
parameterElement is FieldFormalParameterElement &&
|
||||
parameterElement.field == fieldElement) {
|
||||
builder.addSimpleReplacement(range.node(identifier), '_$name');
|
||||
builder.addSimpleReplacement(range.token(identifier), '_$name');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class ExtendClassForMixin extends CorrectionProducer {
|
|||
_typeName = message.substring(startIndex, endIndex);
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleInsertion(
|
||||
declaration.typeParameters?.end ?? declaration.name.end,
|
||||
declaration.typeParameters?.end ?? declaration.name2.end,
|
||||
' extends $_typeName');
|
||||
});
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ class FlutterConvertToStatefulWidget extends CorrectionProducer {
|
|||
builder.writeln(' @override');
|
||||
builder.write(' ');
|
||||
builder.writeReference(stateClass);
|
||||
builder.write('<${widgetClass.name}$typeParams>');
|
||||
builder.write('<${widgetClass.name2.lexeme}$typeParams>');
|
||||
builder.writeln(' createState() => $stateName$typeParams();');
|
||||
if (hasEmptyLineAfterCreateState) {
|
||||
builder.writeln();
|
||||
|
@ -205,7 +205,7 @@ class FlutterConvertToStatefulWidget extends CorrectionProducer {
|
|||
builder.writeReference(stateClass);
|
||||
|
||||
// Write just param names (and not bounds, metadata and docs).
|
||||
builder.write('<${widgetClass.name}');
|
||||
builder.write('<${widgetClass.name2.lexeme}');
|
||||
if (typeParameters != null) {
|
||||
builder.write('<');
|
||||
var first = true;
|
||||
|
@ -214,7 +214,7 @@ class FlutterConvertToStatefulWidget extends CorrectionProducer {
|
|||
builder.write(', ');
|
||||
first = false;
|
||||
}
|
||||
builder.write(param.name.name);
|
||||
builder.write(param.name2.lexeme);
|
||||
}
|
||||
builder.write('>');
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ class FlutterConvertToStatefulWidget extends CorrectionProducer {
|
|||
|
||||
MethodDeclaration? _findBuildMethod(ClassDeclaration widgetClass) {
|
||||
for (var member in widgetClass.members) {
|
||||
if (member is MethodDeclaration && member.name.name == 'build') {
|
||||
if (member is MethodDeclaration && member.name2.lexeme == 'build') {
|
||||
var parameters = member.parameters;
|
||||
if (parameters != null && parameters.parameters.length == 1) {
|
||||
return member;
|
||||
|
|
|
@ -48,7 +48,7 @@ class FlutterConvertToStatelessWidget extends CorrectionProducer {
|
|||
var stateClassElement = stateClass?.declaredElement;
|
||||
if (stateClass == null ||
|
||||
stateClassElement == null ||
|
||||
!Identifier.isPrivateName(stateClass.name.name) ||
|
||||
!Identifier.isPrivateName(stateClass.name2.lexeme) ||
|
||||
!_isSameTypeParameters(widgetClass, stateClass)) {
|
||||
return;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ class FlutterConvertToStatelessWidget extends CorrectionProducer {
|
|||
|
||||
MethodDeclaration? _findCreateStateMethod(ClassDeclaration widgetClass) {
|
||||
for (var member in widgetClass.members) {
|
||||
if (member is MethodDeclaration && member.name.name == 'createState') {
|
||||
if (member is MethodDeclaration && member.name2.lexeme == 'createState') {
|
||||
var parameters = member.parameters;
|
||||
if (parameters?.parameters.isEmpty ?? false) {
|
||||
return member;
|
||||
|
@ -214,7 +214,7 @@ class FlutterConvertToStatelessWidget extends CorrectionProducer {
|
|||
outer:
|
||||
for (var stateParam in stateParams) {
|
||||
for (var widgetParam in widgetParams) {
|
||||
if (stateParam.name.name == widgetParam.name.name &&
|
||||
if (stateParam.name2.lexeme == widgetParam.name2.lexeme &&
|
||||
stateParam.bound?.type == widgetParam.bound?.type) {
|
||||
continue outer;
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ class FlutterConvertToStatelessWidget extends CorrectionProducer {
|
|||
}
|
||||
if (expression is MethodInvocation &&
|
||||
expression.target is SuperExpression &&
|
||||
methodDeclaration!.name.name == expression.methodName.name) {
|
||||
methodDeclaration!.name2.lexeme == expression.methodName.name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ class _StateUsageVisitor extends RecursiveAstVisitor<void> {
|
|||
var classDeclaration =
|
||||
methodDeclaration?.thisOrAncestorOfType<ClassDeclaration>();
|
||||
|
||||
if (methodDeclaration?.name.name != 'createState' ||
|
||||
if (methodDeclaration?.name2.lexeme != 'createState' ||
|
||||
classDeclaration?.declaredElement != widgetClassElement) {
|
||||
used = true;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class InlineTypedef extends CorrectionProducer {
|
|||
List<FormalParameter> parameters;
|
||||
if (parent is FunctionTypeAlias) {
|
||||
returnType = parent.returnType;
|
||||
_name = parent.name.name;
|
||||
_name = parent.name2.lexeme;
|
||||
typeParameters = parent.typeParameters;
|
||||
parameters = parent.parameters.parameters;
|
||||
} else if (parent is GenericTypeAlias) {
|
||||
|
@ -56,7 +56,7 @@ class InlineTypedef extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
returnType = functionType.returnType;
|
||||
_name = parent.name.name;
|
||||
_name = parent.name2.lexeme;
|
||||
typeParameters = functionType.typeParameters;
|
||||
parameters = functionType.parameters.parameters;
|
||||
} else {
|
||||
|
@ -128,10 +128,10 @@ class InlineTypedef extends CorrectionProducer {
|
|||
builder.write(utils.getNodeText(typeAnnotation));
|
||||
}
|
||||
if (parameter.isNamed) {
|
||||
var identifier = parameter.identifier;
|
||||
var identifier = parameter.name;
|
||||
if (identifier != null) {
|
||||
builder.write(' ');
|
||||
builder.write(identifier.name);
|
||||
builder.write(identifier.lexeme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ class JoinVariableDeclaration extends CorrectionProducer {
|
|||
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(
|
||||
range.endStart(declaredVariable.name, assignment.operator),
|
||||
range.endStart(declaredVariable.name2, assignment.operator),
|
||||
' ',
|
||||
);
|
||||
});
|
||||
|
|
|
@ -23,7 +23,7 @@ class MakeClassAbstract extends CorrectionProducer {
|
|||
if (enclosingClass == null) {
|
||||
return;
|
||||
}
|
||||
_className = enclosingClass.name.name;
|
||||
_className = enclosingClass.name2.lexeme;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleInsertion(
|
||||
enclosingClass.classKeyword.offset, 'abstract ');
|
||||
|
|
|
@ -28,7 +28,9 @@ class MakeFieldPublic extends CorrectionProducer {
|
|||
var getterName = node.name;
|
||||
_fieldName = '_$getterName';
|
||||
var parent = node.parent;
|
||||
if (parent is MethodDeclaration && parent.name == node && parent.isGetter) {
|
||||
if (parent is MethodDeclaration &&
|
||||
parent.name2 == token &&
|
||||
parent.isGetter) {
|
||||
var container = parent.parent;
|
||||
if (container is ClassOrMixinDeclaration) {
|
||||
var members = container.members;
|
||||
|
@ -36,12 +38,12 @@ class MakeFieldPublic extends CorrectionProducer {
|
|||
VariableDeclaration? field;
|
||||
for (var member in members) {
|
||||
if (member is MethodDeclaration &&
|
||||
member.name.name == getterName &&
|
||||
member.name2.lexeme == getterName &&
|
||||
member.isSetter) {
|
||||
setter = member;
|
||||
} else if (member is FieldDeclaration) {
|
||||
for (var variable in member.fields.variables) {
|
||||
if (variable.name.name == _fieldName) {
|
||||
if (variable.name2.lexeme == _fieldName) {
|
||||
field = variable;
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +53,7 @@ class MakeFieldPublic extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(range.node(field!.name), getterName);
|
||||
builder.addSimpleReplacement(range.token(field!.name2), getterName);
|
||||
builder.removeMember(members, parent);
|
||||
builder.removeMember(members, setter!);
|
||||
});
|
||||
|
|
|
@ -62,7 +62,7 @@ class MakeFinal extends CorrectionProducer {
|
|||
builder.addSimpleInsertion(type.offset, 'final ');
|
||||
return;
|
||||
}
|
||||
final identifier = simpleNode.identifier;
|
||||
final identifier = simpleNode.name;
|
||||
if (identifier != null) {
|
||||
builder.addSimpleInsertion(identifier.offset, 'final ');
|
||||
} else {
|
||||
|
|
|
@ -118,7 +118,7 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
if (parameter.question != null) {
|
||||
return;
|
||||
}
|
||||
_variableName = parameter.identifier.name;
|
||||
_variableName = parameter.name.lexeme;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
// Add '?' after `)`.
|
||||
builder.addSimpleInsertion(parameter.endToken.end, '?');
|
||||
|
@ -128,7 +128,7 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
if (type == null || !_typeCanBeMadeNullable(type)) {
|
||||
return;
|
||||
}
|
||||
_variableName = parameter.identifier.name;
|
||||
_variableName = parameter.name.lexeme;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleInsertion(type.end, '?');
|
||||
});
|
||||
|
@ -141,7 +141,7 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
if (parameter.question != null) {
|
||||
return;
|
||||
}
|
||||
_variableName = parameter.identifier.name;
|
||||
_variableName = parameter.name.lexeme;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
// Add '?' after `)`.
|
||||
builder.addSimpleInsertion(parameter.endToken.end, '?');
|
||||
|
@ -155,12 +155,12 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
|
||||
var identifier = parameter.identifier;
|
||||
var identifier = parameter.name;
|
||||
if (identifier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
_variableName = identifier.name;
|
||||
_variableName = identifier.lexeme;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleInsertion(type.end, '?');
|
||||
});
|
||||
|
@ -174,7 +174,7 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
if (parameter.question != null) {
|
||||
return;
|
||||
}
|
||||
_variableName = parameter.identifier.name;
|
||||
_variableName = parameter.name.lexeme;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
// Add '?' after `)`.
|
||||
builder.addSimpleInsertion(parameter.endToken.end, '?');
|
||||
|
@ -184,7 +184,7 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
if (type == null || !_typeCanBeMadeNullable(type)) {
|
||||
return;
|
||||
}
|
||||
_variableName = parameter.identifier.name;
|
||||
_variableName = parameter.name.lexeme;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleInsertion(type.end, '?');
|
||||
});
|
||||
|
@ -226,7 +226,7 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
Future<void> _updateVariableType(ChangeBuilder builder,
|
||||
VariableDeclarationList declarationList, DartType newType) async {
|
||||
var variable = declarationList.variables[0];
|
||||
_variableName = variable.name.name;
|
||||
_variableName = variable.name2.lexeme;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
var keyword = declarationList.keyword;
|
||||
if (keyword != null && keyword.type == Keyword.VAR) {
|
||||
|
|
|
@ -38,7 +38,7 @@ class RemoveInitializer extends CorrectionProducer {
|
|||
var parameter = node.thisOrAncestorOfType<DefaultFormalParameter>();
|
||||
if (parameter != null) {
|
||||
// Handle formal parameters with default values.
|
||||
var identifier = parameter.identifier;
|
||||
var identifier = parameter.name;
|
||||
var defaultValue = parameter.defaultValue;
|
||||
if (identifier != null && defaultValue != null) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
|
@ -54,7 +54,7 @@ class RemoveInitializer extends CorrectionProducer {
|
|||
if (variable != null && initializer != null) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addDeletion(
|
||||
range.endEnd(variable.name, initializer),
|
||||
range.endEnd(variable.name2, initializer),
|
||||
);
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -20,7 +20,7 @@ class RemoveParametersInGetterDeclaration extends CorrectionProducer {
|
|||
final node = this.node;
|
||||
if (node is MethodDeclaration) {
|
||||
// Support for the analyzer error.
|
||||
var name = node.name;
|
||||
var name = node.name2;
|
||||
var body = node.body;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(range.endStart(name, body), ' ');
|
||||
|
|
|
@ -55,12 +55,12 @@ class RemoveTypeAnnotation extends CorrectionProducer {
|
|||
}
|
||||
// ignore if an incomplete variable declaration
|
||||
if (declarationList.variables.length == 1 &&
|
||||
declarationList.variables[0].name.isSynthetic) {
|
||||
declarationList.variables[0].name2.isSynthetic) {
|
||||
return;
|
||||
}
|
||||
// must be not after the name of the variable
|
||||
var firstVariable = declarationList.variables[0];
|
||||
if (selectionOffset > firstVariable.name.end) {
|
||||
if (selectionOffset > firstVariable.name2.end) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ class RemoveTypeAnnotation extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
var keyword = declaration.keyword;
|
||||
var variableName = declaration.identifier;
|
||||
var variableName = declaration.name;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
var typeRange = range.startStart(typeNode, variableName);
|
||||
if (keyword != null && keyword.lexeme != 'var') {
|
||||
|
|
|
@ -27,7 +27,7 @@ class RemoveUnusedLocalVariable extends CorrectionProducer {
|
|||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final declaration = node.parent;
|
||||
if (!(declaration is VariableDeclaration && declaration.name == node)) {
|
||||
if (!(declaration is VariableDeclaration && declaration.name2 == token)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class RenameMethodParameter extends CorrectionProducer {
|
|||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final parameter = node.parent;
|
||||
if (parameter is! FormalParameter) return;
|
||||
var paramIdentifier = parameter.identifier;
|
||||
var paramIdentifier = parameter.name;
|
||||
if (paramIdentifier == null) return;
|
||||
|
||||
var method = parameter.thisOrAncestorOfType<MethodDeclaration>();
|
||||
|
@ -38,12 +38,12 @@ class RenameMethodParameter extends CorrectionProducer {
|
|||
if (classElement is! ClassElement) return;
|
||||
|
||||
var parentMethod = classElement.lookUpInheritedMethod(
|
||||
method.name.name, classElement.library);
|
||||
method.name2.lexeme, classElement.library);
|
||||
if (parentMethod == null) return;
|
||||
|
||||
var parameters = methodParameters.parameters;
|
||||
var parentParameters = parentMethod.parameters;
|
||||
var oldName = paramIdentifier.name;
|
||||
var oldName = paramIdentifier.lexeme;
|
||||
|
||||
var i = parameters.indexOf(parameter);
|
||||
if (0 <= i && i < parentParameters.length) {
|
||||
|
|
|
@ -114,17 +114,17 @@ class ReplaceConditionalWithIfElse extends CorrectionProducer {
|
|||
builder.writeType(type);
|
||||
});
|
||||
} else {
|
||||
builder.addInsertion(variable.name.offset, (builder) {
|
||||
builder.addInsertion(variable.name2.offset, (builder) {
|
||||
builder.writeType(type);
|
||||
builder.write(' ');
|
||||
});
|
||||
}
|
||||
}
|
||||
builder.addDeletion(range.endEnd(variable.name, conditional));
|
||||
builder.addDeletion(range.endEnd(variable.name2, conditional));
|
||||
var conditionSrc = utils.getNodeText(conditional.condition);
|
||||
var thenSrc = utils.getNodeText(conditional.thenExpression);
|
||||
var elseSrc = utils.getNodeText(conditional.elseExpression);
|
||||
var name = variable.name.name;
|
||||
var name = variable.name2.lexeme;
|
||||
var src = eol;
|
||||
src += '${prefix}if ($conditionSrc) {$eol';
|
||||
src += '$prefix$indent$name = $thenSrc;$eol';
|
||||
|
|
|
@ -28,8 +28,8 @@ class ReplaceWithIdentifier extends CorrectionProducer {
|
|||
node.thisOrAncestorOfType<FunctionTypedFormalParameter>();
|
||||
if (functionTyped != null) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(range.node(functionTyped),
|
||||
utils.getNodeText(functionTyped.identifier));
|
||||
builder.addSimpleReplacement(
|
||||
range.node(functionTyped), functionTyped.name.lexeme);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ class ReplaceWithVar extends CorrectionProducer {
|
|||
}
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
if (parent.isConst || parent.isFinal) {
|
||||
builder.addDeletion(range.startStart(type, parent.identifier));
|
||||
builder.addDeletion(range.startStart(type, parent.name));
|
||||
} else {
|
||||
builder.addSimpleReplacement(range.node(type), 'var');
|
||||
}
|
||||
|
|
|
@ -32,11 +32,11 @@ class SortUnnamedConstructorFirst extends CorrectionProducer {
|
|||
.firstWhereOrNull((child) => child is ConstructorDeclaration)
|
||||
as ConstructorDeclaration?;
|
||||
if (firstConstructor == null ||
|
||||
firstConstructor.name == null ||
|
||||
firstConstructor.name?.name == 'new') return;
|
||||
firstConstructor.name2 == null ||
|
||||
firstConstructor.name2?.lexeme == 'new') return;
|
||||
|
||||
final unnamedConstructor = clazz.childEntities.firstWhereOrNull(
|
||||
(child) => child is ConstructorDeclaration && child.name == null)
|
||||
(child) => child is ConstructorDeclaration && child.name2 == null)
|
||||
as ConstructorDeclaration?;
|
||||
if (unnamedConstructor == null) return;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class SplitVariableDeclaration extends CorrectionProducer {
|
|||
|
||||
// The caret must be between the type and the variable name.
|
||||
var variable = variables[0];
|
||||
if (!range.startEnd(statement, variable.name).contains(selectionOffset)) {
|
||||
if (!range.startEnd(statement, variable.name2).contains(selectionOffset)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -64,8 +64,8 @@ class SplitVariableDeclaration extends CorrectionProducer {
|
|||
}
|
||||
|
||||
var indent = utils.getNodePrefix(statement);
|
||||
var name = variable.name.name;
|
||||
builder.addSimpleInsertion(variable.name.end, ';$eol$indent$name');
|
||||
var name = variable.name2.lexeme;
|
||||
builder.addSimpleInsertion(variable.name2.end, ';$eol$indent$name');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ class AddTypeParameter extends Change<_Data> {
|
|||
if (_isInvalidIndex(typeParameters?.typeParameters)) {
|
||||
return null;
|
||||
}
|
||||
return _TypeParameterData(typeParameters, parent.name.end);
|
||||
return _TypeParameterData(typeParameters, parent.name2.end);
|
||||
} else if (node is TypeArgumentList && parent is ExtensionOverride) {
|
||||
// wrong_number_of_type_arguments_extension
|
||||
if (!argumentValue.validate(context)) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analysis_server/src/services/correction/fix/data_driven/element_descriptor.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/element_kind.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/element.dart'
|
||||
show ClassElement, ExtensionElement, PrefixElement;
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
|
@ -97,7 +98,7 @@ class ElementMatcher {
|
|||
/// Return a list of element matchers that will match the element that is, or
|
||||
/// should be, associated with the given [node]. The list will be empty if
|
||||
/// there are no appropriate matchers for the [node].
|
||||
static List<ElementMatcher> matchersForNode(AstNode? node) {
|
||||
static List<ElementMatcher> matchersForNode(AstNode? node, Token? nameToken) {
|
||||
if (node == null) {
|
||||
return const <ElementMatcher>[];
|
||||
}
|
||||
|
@ -106,7 +107,7 @@ class ElementMatcher {
|
|||
return const <ElementMatcher>[];
|
||||
}
|
||||
var builder = _MatcherBuilder(importedUris);
|
||||
builder.buildMatchersForNode(node);
|
||||
builder.buildMatchersForNode(node, nameToken);
|
||||
return builder.matchers.toList();
|
||||
}
|
||||
|
||||
|
@ -143,7 +144,7 @@ class _MatcherBuilder {
|
|||
|
||||
_MatcherBuilder(this.importedUris);
|
||||
|
||||
void buildMatchersForNode(AstNode? node) {
|
||||
void buildMatchersForNode(AstNode? node, Token? nameToken) {
|
||||
if (node is ArgumentList) {
|
||||
_buildFromArgumentList(node);
|
||||
} else if (node is BinaryExpression) {
|
||||
|
@ -159,8 +160,8 @@ class _MatcherBuilder {
|
|||
_buildFromNamedType(node);
|
||||
} else if (node is PrefixedIdentifier) {
|
||||
_buildFromPrefixedIdentifier(node);
|
||||
} else if (node is SimpleIdentifier) {
|
||||
_buildFromSimpleIdentifier(node);
|
||||
} else if (node is SimpleIdentifier && nameToken != null) {
|
||||
_buildFromSimpleIdentifier(node, nameToken);
|
||||
} else if (node is TypeArgumentList) {
|
||||
_buildFromTypeArgumentList(node);
|
||||
}
|
||||
|
@ -257,7 +258,7 @@ class _MatcherBuilder {
|
|||
/// Build a matcher for the method being declared.
|
||||
void _buildFromMethodDeclaration(MethodDeclaration node) {
|
||||
_addMatcher(
|
||||
components: [node.name.name],
|
||||
components: [node.name2.lexeme],
|
||||
kinds: [ElementKind.methodKind],
|
||||
);
|
||||
}
|
||||
|
@ -447,7 +448,7 @@ class _MatcherBuilder {
|
|||
}
|
||||
|
||||
/// Build a matcher for the element referenced by the identifier.
|
||||
void _buildFromSimpleIdentifier(SimpleIdentifier node) {
|
||||
void _buildFromSimpleIdentifier(SimpleIdentifier node, Token nameToken) {
|
||||
// TODO(brianwilkerson) Use the static element, if there is one, in order to
|
||||
// get a more exact matcher.
|
||||
var parent = node.parent;
|
||||
|
@ -458,7 +459,7 @@ class _MatcherBuilder {
|
|||
_buildFromArgumentList(parent.parent!.parent as ArgumentList);
|
||||
} else if (parent is NamedType) {
|
||||
_buildFromNamedType(parent);
|
||||
} else if (parent is MethodDeclaration && node == parent.name) {
|
||||
} else if (parent is MethodDeclaration && nameToken == parent.name2) {
|
||||
_buildFromMethodDeclaration(parent);
|
||||
} else if (parent is MethodInvocation &&
|
||||
node == parent.methodName &&
|
||||
|
|
|
@ -38,9 +38,9 @@ class RenameParameter extends Change<_Data> {
|
|||
if (overriddenParameter == null) {
|
||||
// If the overridden parameter has already been removed, then just
|
||||
// rename the old parameter to have the new name.
|
||||
var identifier = parameter.identifier;
|
||||
var identifier = parameter.name;
|
||||
if (identifier != null) {
|
||||
builder.addSimpleReplacement(range.node(identifier), newName);
|
||||
builder.addSimpleReplacement(range.token(identifier), newName);
|
||||
}
|
||||
} else {
|
||||
// If the overridden parameter still exists, then mark it as
|
||||
|
|
|
@ -34,7 +34,7 @@ List<String> getVariableNameSuggestionsForExpression(DartType? expectedType,
|
|||
// If we're in a build() method, use 'build' as the name prefix.
|
||||
var method = assignedExpression?.thisOrAncestorOfType<MethodDeclaration>();
|
||||
if (method != null) {
|
||||
var enclosingName = method.name.name;
|
||||
var enclosingName = method.name2.lexeme;
|
||||
if (enclosingName.startsWith('build')) {
|
||||
prefix = 'build';
|
||||
}
|
||||
|
|
|
@ -112,19 +112,14 @@ class MemberSorter {
|
|||
String name;
|
||||
if (member is ConstructorDeclaration) {
|
||||
kind = _MemberKind.CLASS_CONSTRUCTOR;
|
||||
var nameNode = member.name;
|
||||
if (nameNode == null) {
|
||||
name = '';
|
||||
} else {
|
||||
name = nameNode.name;
|
||||
}
|
||||
name = member.name2?.lexeme ?? '';
|
||||
} else if (member is FieldDeclaration) {
|
||||
var fieldDeclaration = member;
|
||||
List<VariableDeclaration> fields = fieldDeclaration.fields.variables;
|
||||
if (fields.isNotEmpty) {
|
||||
kind = _MemberKind.CLASS_FIELD;
|
||||
isStatic = fieldDeclaration.isStatic;
|
||||
name = fields[0].name.name;
|
||||
name = fields[0].name2.lexeme;
|
||||
} else {
|
||||
// Don't sort members if there are errors in the code.
|
||||
return;
|
||||
|
@ -132,7 +127,7 @@ class MemberSorter {
|
|||
} else if (member is MethodDeclaration) {
|
||||
var method = member;
|
||||
isStatic = method.isStatic;
|
||||
name = method.name.name;
|
||||
name = method.name2.lexeme;
|
||||
if (method.isGetter) {
|
||||
kind = _MemberKind.CLASS_ACCESSOR;
|
||||
name += ' getter';
|
||||
|
@ -172,23 +167,22 @@ class MemberSorter {
|
|||
String name;
|
||||
if (member is ClassOrMixinDeclaration) {
|
||||
kind = _MemberKind.UNIT_CLASS;
|
||||
name = member.name.name;
|
||||
name = member.name2.lexeme;
|
||||
} else if (member is ClassTypeAlias) {
|
||||
kind = _MemberKind.UNIT_CLASS;
|
||||
name = member.name.name;
|
||||
name = member.name2.lexeme;
|
||||
} else if (member is EnumDeclaration) {
|
||||
kind = _MemberKind.UNIT_CLASS;
|
||||
name = member.name.name;
|
||||
name = member.name2.lexeme;
|
||||
} else if (member is ExtensionDeclaration) {
|
||||
kind = _MemberKind.UNIT_EXTENSION;
|
||||
name = member.name?.name ?? '';
|
||||
name = member.name2?.lexeme ?? '';
|
||||
} else if (member is FunctionDeclaration) {
|
||||
var function = member;
|
||||
name = function.name.name;
|
||||
if (function.isGetter) {
|
||||
name = member.name2.lexeme;
|
||||
if (member.isGetter) {
|
||||
kind = _MemberKind.UNIT_ACCESSOR;
|
||||
name += ' getter';
|
||||
} else if (function.isSetter) {
|
||||
} else if (member.isSetter) {
|
||||
kind = _MemberKind.UNIT_ACCESSOR;
|
||||
name += ' setter';
|
||||
} else {
|
||||
|
@ -200,10 +194,10 @@ class MemberSorter {
|
|||
}
|
||||
} else if (member is FunctionTypeAlias) {
|
||||
kind = _MemberKind.UNIT_FUNCTION_TYPE;
|
||||
name = member.name.name;
|
||||
name = member.name2.lexeme;
|
||||
} else if (member is GenericTypeAlias) {
|
||||
kind = _MemberKind.UNIT_GENERIC_TYPE_ALIAS;
|
||||
name = member.name.name;
|
||||
name = member.name2.lexeme;
|
||||
} else if (member is TopLevelVariableDeclaration) {
|
||||
var variableDeclaration = member;
|
||||
List<VariableDeclaration> variables =
|
||||
|
@ -214,7 +208,7 @@ class MemberSorter {
|
|||
} else {
|
||||
kind = _MemberKind.UNIT_VARIABLE;
|
||||
}
|
||||
name = variables[0].name.name;
|
||||
name = variables[0].name2.lexeme;
|
||||
} else {
|
||||
// Don't sort members if there are errors in the code.
|
||||
return;
|
||||
|
|
|
@ -476,7 +476,7 @@ bool isLeftHandOfAssignment(SimpleIdentifier node) {
|
|||
return true;
|
||||
}
|
||||
return node.parent is VariableDeclaration &&
|
||||
(node.parent as VariableDeclaration).name == node;
|
||||
(node.parent as VariableDeclaration).name2 == node.token;
|
||||
}
|
||||
|
||||
/// Return `true` if the given [node] is the name of a [NamedExpression].
|
||||
|
|
|
@ -288,7 +288,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
|
||||
// anchor- defines/binding
|
||||
addAnchorEdgesContainingEdge(
|
||||
syntacticEntity: node.name,
|
||||
syntacticEntity: node.name2,
|
||||
edges: [
|
||||
schema.DEFINES_BINDING_EDGE,
|
||||
],
|
||||
|
@ -355,7 +355,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
|
||||
// anchor
|
||||
addAnchorEdgesContainingEdge(
|
||||
syntacticEntity: node.name,
|
||||
syntacticEntity: node.name2,
|
||||
edges: [
|
||||
schema.DEFINES_BINDING_EDGE,
|
||||
],
|
||||
|
@ -471,9 +471,9 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
// anchor
|
||||
var start = node.returnType.offset;
|
||||
var end = node.returnType.end;
|
||||
var nameNode = node.name;
|
||||
if (nameNode != null) {
|
||||
end = nameNode.end;
|
||||
var nameToken = node.name2;
|
||||
if (nameToken != null) {
|
||||
end = nameToken.end;
|
||||
}
|
||||
addAnchorEdgesContainingEdge(
|
||||
start: start,
|
||||
|
@ -503,7 +503,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
@override
|
||||
void visitDeclaredIdentifier(DeclaredIdentifier node) {
|
||||
var declaredElement = node.declaredElement!;
|
||||
_handleVariableDeclaration(declaredElement, node.identifier,
|
||||
_handleVariableDeclaration(declaredElement, node.name,
|
||||
subKind: schema.LOCAL_SUBKIND, type: declaredElement.type);
|
||||
|
||||
// no children
|
||||
|
@ -517,7 +517,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
|
||||
// anchor- defines/binding, defines
|
||||
addAnchorEdgesContainingEdge(
|
||||
syntacticEntity: node.name,
|
||||
syntacticEntity: node.name2,
|
||||
edges: [
|
||||
schema.DEFINES_BINDING_EDGE,
|
||||
schema.DEFINES_EDGE,
|
||||
|
@ -539,7 +539,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
|
||||
// anchor- defines/binding
|
||||
addAnchorEdgesContainingEdge(
|
||||
syntacticEntity: node.name,
|
||||
syntacticEntity: node.name2,
|
||||
edges: [
|
||||
schema.DEFINES_BINDING_EDGE,
|
||||
],
|
||||
|
@ -578,7 +578,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
_handleRefEdge(
|
||||
element,
|
||||
const <String>[schema.REF_EDGE],
|
||||
syntacticEntity: node.identifier,
|
||||
syntacticEntity: node.name,
|
||||
);
|
||||
|
||||
// visit children
|
||||
|
@ -599,7 +599,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
|
||||
// anchor- defines/binding
|
||||
addAnchorEdgesContainingEdge(
|
||||
syntacticEntity: node.name,
|
||||
syntacticEntity: node.name2,
|
||||
edges: [
|
||||
schema.DEFINES_BINDING_EDGE,
|
||||
],
|
||||
|
@ -665,7 +665,6 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
// visit children
|
||||
_safelyVisit(node.documentationComment);
|
||||
_safelyVisitList(node.metadata);
|
||||
_safelyVisit(node.identifier);
|
||||
_safelyVisit(node.typeParameters);
|
||||
_safelyVisit(node.parameters);
|
||||
}
|
||||
|
@ -752,7 +751,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
|
||||
// anchor- defines/binding
|
||||
addAnchorEdgesContainingEdge(
|
||||
syntacticEntity: node.name,
|
||||
syntacticEntity: node.name2,
|
||||
edges: [
|
||||
schema.DEFINES_BINDING_EDGE,
|
||||
],
|
||||
|
@ -824,7 +823,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
// node.identifier can be null in cases with the new generic function type
|
||||
// syntax
|
||||
// TODO(jwren) add test cases for this situation
|
||||
var identifier = node.identifier;
|
||||
var identifier = node.name;
|
||||
if (identifier != null) {
|
||||
// The anchor and anchor edges generation are broken into two cases, the
|
||||
// first case is "method(parameter_name) ...", where the parameter
|
||||
|
@ -920,7 +919,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
|
||||
// variable
|
||||
var declaredElement = node.declaredElement!;
|
||||
_handleVariableDeclaration(declaredElement, node.name,
|
||||
_handleVariableDeclaration(declaredElement, node.name2,
|
||||
subKind: isLocal ? schema.LOCAL_SUBKIND : schema.FIELD_SUBKIND,
|
||||
type: declaredElement.type);
|
||||
|
||||
|
|
|
@ -523,6 +523,7 @@ class _OccurrencesVisitor extends GeneralizingAstVisitor<void> {
|
|||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
var parent = node.parent;
|
||||
// ignore: deprecated_member_use
|
||||
if (parent is VariableDeclaration && parent.name == node ||
|
||||
parent is AssignmentExpression && parent.leftHandSide == node) {
|
||||
return;
|
||||
|
|
|
@ -310,8 +310,8 @@ class ExtractWidgetRefactoringImpl extends RefactoringImpl
|
|||
parameter = parameter.parameter;
|
||||
}
|
||||
if (parameter is NormalFormalParameter) {
|
||||
_parameters.add(_Parameter(
|
||||
parameter.identifier!.name, parameter.declaredElement!.type,
|
||||
final element = parameter.declaredElement!;
|
||||
_parameters.add(_Parameter(element.name, element.type,
|
||||
isMethodParameter: true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,36 +144,36 @@ class AstWriter extends UnifyingAstVisitor with TreeWriter {
|
|||
/// declaration.
|
||||
String? _getName(AstNode node) {
|
||||
if (node is ClassTypeAlias) {
|
||||
return node.name.name;
|
||||
return node.name2.lexeme;
|
||||
} else if (node is ClassDeclaration) {
|
||||
return node.name.name;
|
||||
return node.name2.lexeme;
|
||||
} else if (node is ConstructorDeclaration) {
|
||||
var name = node.name;
|
||||
var name = node.name2;
|
||||
if (name == null) {
|
||||
return node.returnType.name;
|
||||
} else {
|
||||
return '${node.returnType.name}.${name.name}';
|
||||
return '${node.returnType.name}.${name.lexeme}';
|
||||
}
|
||||
} else if (node is ConstructorName) {
|
||||
return node.toSource();
|
||||
} else if (node is FieldDeclaration) {
|
||||
return _getNames(node.fields);
|
||||
} else if (node is FunctionDeclaration) {
|
||||
return node.name.name;
|
||||
return node.name2.lexeme;
|
||||
} else if (node is FunctionTypeAlias) {
|
||||
return node.name.name;
|
||||
return node.name2.lexeme;
|
||||
} else if (node is Identifier) {
|
||||
return node.name;
|
||||
} else if (node is MethodDeclaration) {
|
||||
return node.name.name;
|
||||
return node.name2.lexeme;
|
||||
} else if (node is TopLevelVariableDeclaration) {
|
||||
return _getNames(node.variables);
|
||||
} else if (node is TypeAnnotation) {
|
||||
return node.toSource();
|
||||
} else if (node is TypeParameter) {
|
||||
return node.name.name;
|
||||
return node.name2.lexeme;
|
||||
} else if (node is VariableDeclaration) {
|
||||
return node.name.name;
|
||||
return node.name2.lexeme;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ class AstWriter extends UnifyingAstVisitor with TreeWriter {
|
|||
} else {
|
||||
buffer.write(', ');
|
||||
}
|
||||
buffer.write(variable.name.name);
|
||||
buffer.write(variable.name2.lexeme);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
|
|
@ -503,7 +503,6 @@ void f() {
|
|||
assertHasRegion(HighlightRegionType.CONSTRUCTOR, 'AAA<int>.name(');
|
||||
assertHasRegion(HighlightRegionType.CLASS, 'int>(');
|
||||
assertHasRegion(HighlightRegionType.CLASS, 'int>.name(');
|
||||
assertHasRegion(HighlightRegionType.CONSTRUCTOR, 'name(p)');
|
||||
assertHasRegion(HighlightRegionType.CONSTRUCTOR, 'name(42)');
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ void main() {
|
|||
throw Exception(parseResult.errors);
|
||||
}
|
||||
|
||||
var lintNamesClass = parseResult.unit.declarations
|
||||
.firstWhere((m) => m is ClassDeclaration && m.name.name == 'LintNames');
|
||||
var lintNamesClass = parseResult.unit.declarations.firstWhere(
|
||||
(m) => m is ClassDeclaration && m.name2.lexeme == 'LintNames');
|
||||
|
||||
var collector = _FixCollector();
|
||||
lintNamesClass.accept(collector);
|
||||
|
@ -65,7 +65,7 @@ class _FixCollector extends GeneralizingAstVisitor<void> {
|
|||
@override
|
||||
void visitFieldDeclaration(FieldDeclaration node) {
|
||||
for (var v in node.fields.variables) {
|
||||
lintNames.add(v.name.name);
|
||||
lintNames.add(v.name2.lexeme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:analysis_server/src/services/correction/namespace.dart';
|
|||
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/ast/extensions.dart';
|
||||
import 'package:analyzer/src/dart/ast/element_locator.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart' hide Element;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
|
@ -41,7 +41,7 @@ class RenameRefactoringTest extends RefactoringTest {
|
|||
/// the [SimpleIdentifier] at the given [search] pattern.
|
||||
void createRenameRefactoringAtString(String search) {
|
||||
var identifier = findNode.simple(search);
|
||||
var element = identifier.writeOrReadElement;
|
||||
var element = ElementLocator.locate(identifier);
|
||||
if (element is PrefixElement) {
|
||||
element = getImportElement(identifier);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ abstract class AbstractElementMatcherTest extends DataDrivenFixProcessorTest {
|
|||
List<ElementKind>? expectedKinds,
|
||||
List<String>? expectedUris}) {
|
||||
var node = findNode.any(search);
|
||||
var matchers = ElementMatcher.matchersForNode(node);
|
||||
var matchers = ElementMatcher.matchersForNode(node, node.beginToken);
|
||||
expect(matchers, hasLength(1));
|
||||
var matcher = matchers[0];
|
||||
if (expectedUris != null) {
|
||||
|
|
|
@ -544,7 +544,7 @@ Text createEmptyText() => new Text('');
|
|||
for (var topDeclaration in unit.declarations) {
|
||||
if (topDeclaration is TopLevelVariableDeclaration) {
|
||||
for (var variable in topDeclaration.variables.variables) {
|
||||
if (variable.name.name == name) {
|
||||
if (variable.name2.lexeme == name) {
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,10 @@ class BulkFixDetails {
|
|||
if (classElement != null &&
|
||||
classElement.allSupertypes.any(
|
||||
(element) => element.element.name == 'CorrectionProducer')) {
|
||||
var correctionName = classDecl.name.name;
|
||||
var correctionName = classDecl.name2.lexeme;
|
||||
|
||||
for (var method in classDecl.members.whereType<MethodDeclaration>()) {
|
||||
if (method.name.name == 'canBeAppliedInBulk') {
|
||||
if (method.name2.lexeme == 'canBeAppliedInBulk') {
|
||||
var hasComment =
|
||||
method.returnType?.beginToken.precedingComments != null;
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
'documentationComment': node.documentationComment,
|
||||
'metadata': node.metadata,
|
||||
'abstractKeyword': node.abstractKeyword,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'typeParameters': node.typeParameters,
|
||||
'extendsClause': node.extendsClause,
|
||||
'withClause': node.withClause,
|
||||
|
@ -324,7 +324,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
'documentationComment': node.documentationComment,
|
||||
'metadata': node.metadata,
|
||||
'abstractKeyword': node.abstractKeyword,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'typeParameters': node.typeParameters,
|
||||
'superclass': node.superclass,
|
||||
'withClause': node.withClause,
|
||||
|
@ -387,7 +387,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
'constKeyword': node.constKeyword,
|
||||
'factoryKeyword': node.factoryKeyword,
|
||||
'returnType': node.returnType,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'parameters': node.parameters,
|
||||
'initializers': node.initializers,
|
||||
'redirectedConstructor': node.redirectedConstructor,
|
||||
|
@ -428,7 +428,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
_visitChildren(node, {
|
||||
'keyword': node.keyword,
|
||||
'type': node.type,
|
||||
'identifier': node.identifier,
|
||||
'name': node.name,
|
||||
});
|
||||
super.visitDeclaredIdentifier(node);
|
||||
}
|
||||
|
@ -482,7 +482,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
_visitChildren(node, {
|
||||
'documentationComment': node.documentationComment,
|
||||
'metadata': node.metadata,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
});
|
||||
super.visitEnumConstantDeclaration(node);
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
_visitChildren(node, {
|
||||
'documentationComment': node.documentationComment,
|
||||
'metadata': node.metadata,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'constants': node.constants,
|
||||
});
|
||||
super.visitEnumDeclaration(node);
|
||||
|
@ -539,7 +539,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitExtensionDeclaration(ExtensionDeclaration node) {
|
||||
_visitChildren(node, {
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'typeParameters': node.typeParameters,
|
||||
'extendedType': node.extendedType,
|
||||
'member': node.members,
|
||||
|
@ -579,7 +579,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
'keyword': node.keyword,
|
||||
'type': node.type,
|
||||
'thisKeyword': node.thisKeyword,
|
||||
'identifier': node.identifier,
|
||||
'name': node.name,
|
||||
'typeParameters': node.typeParameters,
|
||||
'parameters': node.parameters,
|
||||
'question': node.question,
|
||||
|
@ -660,7 +660,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
'metadata': node.metadata,
|
||||
'externalKeyword': node.externalKeyword,
|
||||
'propertyKeyword': node.propertyKeyword,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'functionExpression': node.functionExpression,
|
||||
'returnType': node.returnType,
|
||||
});
|
||||
|
@ -701,7 +701,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
'documentationComment': node.documentationComment,
|
||||
'metadata': node.metadata,
|
||||
'returnType': node.returnType,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'typeParameters': node.typeParameters,
|
||||
'parameters': node.parameters,
|
||||
});
|
||||
|
@ -713,7 +713,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
_visitChildren(node, {
|
||||
'covariantKeyword': node.covariantKeyword,
|
||||
'returnType': node.returnType,
|
||||
'identifier': node.identifier,
|
||||
'name': node.name,
|
||||
'typeParameters': node.typeParameters,
|
||||
'parameters': node.parameters,
|
||||
'question': node.question,
|
||||
|
@ -737,7 +737,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
_visitChildren(node, {
|
||||
'documentationComment': node.documentationComment,
|
||||
'metadata': node.metadata,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'typeParameters': node.typeParameters,
|
||||
'functionType': node.functionType,
|
||||
});
|
||||
|
@ -910,7 +910,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
'externalKeyword': node.externalKeyword,
|
||||
'modifierKeyword': node.modifierKeyword,
|
||||
'returnType': node.returnType,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'operatorKeyword': node.operatorKeyword,
|
||||
'typeParameters': node.typeParameters,
|
||||
'parameters': node.parameters,
|
||||
|
@ -935,7 +935,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
_visitChildren(node, {
|
||||
'documentationComment': node.documentationComment,
|
||||
'metadata': node.metadata,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'typeParameters': node.typeParameters,
|
||||
'onClause': node.onClause,
|
||||
'implementsClause': node.implementsClause,
|
||||
|
@ -1111,7 +1111,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
'covariantKeyword': node.covariantKeyword,
|
||||
'keyword': node.keyword,
|
||||
'type': node.type,
|
||||
'identifier': node.identifier,
|
||||
'name': node.name,
|
||||
});
|
||||
super.visitSimpleFormalParameter(node);
|
||||
}
|
||||
|
@ -1232,7 +1232,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitTypeParameter(TypeParameter node) {
|
||||
_visitChildren(node, {
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'bound': node.bound,
|
||||
});
|
||||
super.visitTypeParameter(node);
|
||||
|
@ -1249,7 +1249,7 @@ class CodeShapeDataCollector extends RecursiveAstVisitor<void> {
|
|||
_visitChildren(node, {
|
||||
'documentationComment': node.documentationComment,
|
||||
'metadata': node.metadata,
|
||||
'name': node.name,
|
||||
'name': node.name2,
|
||||
'initializer': node.initializer,
|
||||
});
|
||||
super.visitVariableDeclaration(node);
|
||||
|
|
|
@ -110,7 +110,7 @@ class ImpliedTypeCollector extends RecursiveAstVisitor<void> {
|
|||
if (rhsType != null && !rhsType.isDynamic) {
|
||||
// Record the name with the type.
|
||||
data.recordImpliedType(
|
||||
node.name.name,
|
||||
node.name2.lexeme,
|
||||
rhsType.getDisplayString(withNullability: false),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -993,7 +993,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
if (node.target is SuperExpression) {
|
||||
var enclosingMethod = node.thisOrAncestorOfType<MethodDeclaration>();
|
||||
if (enclosingMethod != null) {
|
||||
if (enclosingMethod.name.name == node.methodName.name) {
|
||||
if (enclosingMethod.name2.lexeme == node.methodName.name) {
|
||||
data.recordTypeMatch('super invocation member', 'same');
|
||||
} else {
|
||||
data.recordTypeMatch('super invocation member', 'different');
|
||||
|
@ -1120,7 +1120,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
if (node.target is SuperExpression) {
|
||||
var enclosingMethod = node.thisOrAncestorOfType<MethodDeclaration>();
|
||||
if (enclosingMethod != null) {
|
||||
if (enclosingMethod.name.name == node.propertyName.name) {
|
||||
if (enclosingMethod.name2.lexeme == node.propertyName.name) {
|
||||
data.recordTypeMatch('super property access member', 'same');
|
||||
} else {
|
||||
data.recordTypeMatch('super property access member', 'different');
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Deprecated `CatchClause.exceptionParameter` and `CatchClause.stackTraceParameter`.
|
||||
Use `exceptionParameter2` and `stackTraceParameter2` instead.
|
||||
* Added `FileResult.isAugmentation` and `isLibrary` to complement `isPart`.
|
||||
* Deprecated 'XyzDeclaration.name' in AST, use `name2` and `declaredElement` instead.
|
||||
|
||||
## 4.3.1
|
||||
* Fix `identifier` for `LibraryExportElement` and `LibraryImportElement`.
|
||||
|
|
|
@ -90,19 +90,19 @@ it might look something like this:
|
|||
void printMembers(CompilationUnit unit) {
|
||||
for (CompilationUnitMember unitMember in unit.declarations) {
|
||||
if (unitMember is ClassDeclaration) {
|
||||
print(unitMember.name.name);
|
||||
print(unitMember.name2.lexeme);
|
||||
for (ClassMember classMember in unitMember.members) {
|
||||
if (classMember is MethodDeclaration) {
|
||||
print(' ${classMember.name}');
|
||||
print(' ${classMember.name2.lexeme}');
|
||||
} else if (classMember is FieldDeclaration) {
|
||||
for (VariableDeclaration field in classMember.fields.variables) {
|
||||
print(' ${field.name.name}');
|
||||
print(' ${field.name2.lexeme}');
|
||||
}
|
||||
} else if (classMember is ConstructorDeclaration) {
|
||||
if (classMember.name == null) {
|
||||
print(' ${unitMember.name.name}');
|
||||
if (classMember.name2 == null) {
|
||||
print(' ${unitMember.name2.lexeme}');
|
||||
} else {
|
||||
print(' ${unitMember.name.name}.${classMember.name.name}');
|
||||
print(' ${unitMember.name2.lexeme}.${classMember.name2.lexeme}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -789,7 +789,7 @@ abstract class CascadeExpression
|
|||
/// | 'on' type catchPart? [Block]
|
||||
///
|
||||
/// catchPart ::=
|
||||
/// 'catch' '(' [SimpleIdentifier] (',' [SimpleIdentifier])? ')'
|
||||
/// 'catch' '(' [CatchClauseParameter] (',' [CatchClauseParameter])? ')'
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class CatchClause implements AstNode {
|
||||
|
@ -851,7 +851,7 @@ abstract class CatchClauseParameter extends AstNode {
|
|||
/// The declaration of a class augmentation.
|
||||
///
|
||||
/// classAugmentationDeclaration ::=
|
||||
/// 'augment' 'class' [SimpleIdentifier] [TypeParameterList]?
|
||||
/// 'augment' 'class' name [TypeParameterList]?
|
||||
/// [ExtendsClause]? [WithClause]? [ImplementsClause]?
|
||||
/// '{' [ClassMember]* '}'
|
||||
///
|
||||
|
@ -869,7 +869,7 @@ abstract class ClassAugmentationDeclaration
|
|||
/// The declaration of a class.
|
||||
///
|
||||
/// classDeclaration ::=
|
||||
/// 'abstract'? 'class' [SimpleIdentifier] [TypeParameterList]?
|
||||
/// 'abstract'? 'class' name [TypeParameterList]?
|
||||
/// [ExtendsClause]? [WithClause]? [ImplementsClause]?
|
||||
/// '{' [ClassMember]* '}'
|
||||
///
|
||||
|
@ -986,7 +986,7 @@ abstract class ClassOrMixinDeclaration implements NamedCompilationUnitMember {
|
|||
/// A class type alias.
|
||||
///
|
||||
/// classTypeAlias ::=
|
||||
/// [SimpleIdentifier] [TypeParameterList]? '=' 'abstract'? mixinApplication
|
||||
/// name [TypeParameterList]? '=' 'abstract'? mixinApplication
|
||||
///
|
||||
/// mixinApplication ::=
|
||||
/// [TypeName] [WithClause] [ImplementsClause]? ';'
|
||||
|
@ -1011,9 +1011,6 @@ abstract class ClassTypeAlias implements TypeAlias {
|
|||
@Deprecated('Use abstractKeyword instead')
|
||||
bool get isAbstract;
|
||||
|
||||
@override
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the name of the superclass of the class being declared.
|
||||
NamedType get superclass;
|
||||
|
||||
|
@ -1339,7 +1336,7 @@ abstract class Configuration implements AstNode {
|
|||
/// | 'external'? 'const' constructorName formalParameterList initializerList?
|
||||
///
|
||||
/// constructorName ::=
|
||||
/// [SimpleIdentifier] ('.' [SimpleIdentifier])?
|
||||
/// [SimpleIdentifier] ('.' name)?
|
||||
///
|
||||
/// factoryName ::=
|
||||
/// [Identifier] ('.' [SimpleIdentifier])?
|
||||
|
@ -1371,8 +1368,13 @@ abstract class ConstructorDeclaration implements ClassMember {
|
|||
|
||||
/// Return the name of the constructor, or `null` if the constructor being
|
||||
/// declared is unnamed.
|
||||
@Deprecated('Use name2 instead')
|
||||
SimpleIdentifier? get name;
|
||||
|
||||
/// Return the name of the constructor, or `null` if the constructor being
|
||||
/// declared is unnamed.
|
||||
Token? get name2;
|
||||
|
||||
/// Return the parameters associated with the constructor.
|
||||
FormalParameterList get parameters;
|
||||
|
||||
|
@ -1545,6 +1547,7 @@ abstract class DeclaredIdentifier implements Declaration {
|
|||
LocalVariableElement? get declaredElement;
|
||||
|
||||
/// Return the name of the variable being declared.
|
||||
@Deprecated('Use identifier2 instead')
|
||||
SimpleIdentifier get identifier;
|
||||
|
||||
/// Return `true` if this variable was declared with the 'const' modifier.
|
||||
|
@ -1559,6 +1562,9 @@ abstract class DeclaredIdentifier implements Declaration {
|
|||
/// keyword, or `null` if no keyword was used.
|
||||
Token? get keyword;
|
||||
|
||||
/// Return the name of the variable being declared.
|
||||
Token get name;
|
||||
|
||||
/// Return the name of the declared type of the parameter, or `null` if the
|
||||
/// parameter does not have a declared type.
|
||||
TypeAnnotation? get type;
|
||||
|
@ -1734,13 +1740,17 @@ abstract class EnumConstantDeclaration implements Declaration {
|
|||
ConstructorElement? get constructorElement;
|
||||
|
||||
/// Return the name of the constant.
|
||||
@Deprecated('Use name2 instead')
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the name of the constant.
|
||||
Token get name2;
|
||||
}
|
||||
|
||||
/// The declaration of an enumeration.
|
||||
///
|
||||
/// enumType ::=
|
||||
/// metadata 'enum' [SimpleIdentifier] [TypeParameterList]?
|
||||
/// metadata 'enum' name [TypeParameterList]?
|
||||
/// [WithClause]? [ImplementsClause]? '{' [SimpleIdentifier]
|
||||
/// (',' [SimpleIdentifier])* (';' [ClassMember]+)? '}'
|
||||
///
|
||||
|
@ -1765,9 +1775,6 @@ abstract class EnumDeclaration implements NamedCompilationUnitMember {
|
|||
/// Return the members declared by the enumeration.
|
||||
NodeList<ClassMember> get members;
|
||||
|
||||
@override
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the right curly bracket.
|
||||
Token get rightBracket;
|
||||
|
||||
|
@ -1946,8 +1953,13 @@ abstract class ExtensionDeclaration implements CompilationUnitMember {
|
|||
|
||||
/// Return the name of the extension, or `null` if the extension does not have
|
||||
/// a name.
|
||||
@Deprecated('Use name2 instead')
|
||||
SimpleIdentifier? get name;
|
||||
|
||||
/// Return the name of the extension, or `null` if the extension does not have
|
||||
/// a name.
|
||||
Token? get name2;
|
||||
|
||||
/// Return the token representing the 'on' keyword.
|
||||
Token get onKeyword;
|
||||
|
||||
|
@ -2061,10 +2073,11 @@ abstract class FieldDeclaration implements ClassMember {
|
|||
///
|
||||
/// fieldFormalParameter ::=
|
||||
/// ('final' [TypeAnnotation] | 'const' [TypeAnnotation] | 'var' | [TypeAnnotation])?
|
||||
/// 'this' '.' [SimpleIdentifier] ([TypeParameterList]? [FormalParameterList])?
|
||||
/// 'this' '.' name ([TypeParameterList]? [FormalParameterList])?
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class FieldFormalParameter implements NormalFormalParameter {
|
||||
@Deprecated('Use identifier2 instead')
|
||||
@override
|
||||
SimpleIdentifier get identifier;
|
||||
|
||||
|
@ -2072,6 +2085,9 @@ abstract class FieldFormalParameter implements NormalFormalParameter {
|
|||
/// keyword, or `null` if no keyword was used.
|
||||
Token? get keyword;
|
||||
|
||||
@override
|
||||
Token get name;
|
||||
|
||||
/// Return the parameters of the function-typed parameter, or `null` if this
|
||||
/// is not a function-typed field formal parameter.
|
||||
FormalParameterList? get parameters;
|
||||
|
@ -2190,6 +2206,7 @@ abstract class FormalParameter implements AstNode {
|
|||
/// Return the name of the parameter being declared, or `null` if the
|
||||
/// parameter doesn't have a name, such as when it's part of a generic
|
||||
/// function type.
|
||||
@Deprecated('Use identifier2 instead')
|
||||
SimpleIdentifier? get identifier;
|
||||
|
||||
/// Return `true` if this parameter was declared with the 'const' modifier.
|
||||
|
@ -2247,6 +2264,11 @@ abstract class FormalParameter implements AstNode {
|
|||
/// Return the annotations associated with this parameter.
|
||||
NodeList<Annotation> get metadata;
|
||||
|
||||
/// Return the name of the parameter being declared, or `null` if the
|
||||
/// parameter doesn't have a name, such as when it's part of a generic
|
||||
/// function type.
|
||||
Token? get name;
|
||||
|
||||
/// The 'required' keyword, or `null` if the keyword was not used.
|
||||
Token? get requiredKeyword;
|
||||
}
|
||||
|
@ -2448,7 +2470,7 @@ abstract class FunctionBody implements AstNode {
|
|||
/// | functionSignature [FunctionBody]
|
||||
///
|
||||
/// functionSignature ::=
|
||||
/// [Type]? ('get' | 'set')? [SimpleIdentifier] [FormalParameterList]
|
||||
/// [Type]? ('get' | 'set')? name [FormalParameterList]
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class FunctionDeclaration implements NamedCompilationUnitMember {
|
||||
|
@ -2468,9 +2490,6 @@ abstract class FunctionDeclaration implements NamedCompilationUnitMember {
|
|||
/// Return `true` if this function declares a setter.
|
||||
bool get isSetter;
|
||||
|
||||
@override
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the token representing the 'get' or 'set' keyword, or `null` if
|
||||
/// this is a function declaration rather than a property declaration.
|
||||
Token? get propertyKeyword;
|
||||
|
@ -2592,14 +2611,18 @@ abstract class FunctionTypeAlias implements TypeAlias {
|
|||
/// A function-typed formal parameter.
|
||||
///
|
||||
/// functionSignature ::=
|
||||
/// [TypeAnnotation]? [SimpleIdentifier] [TypeParameterList]?
|
||||
/// [TypeAnnotation]? name [TypeParameterList]?
|
||||
/// [FormalParameterList] '?'?
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class FunctionTypedFormalParameter implements NormalFormalParameter {
|
||||
@Deprecated('Use identifier2 instead')
|
||||
@override
|
||||
SimpleIdentifier get identifier;
|
||||
|
||||
@override
|
||||
Token get name;
|
||||
|
||||
/// Return the parameters of the function-typed parameter.
|
||||
FormalParameterList get parameters;
|
||||
|
||||
|
@ -2666,7 +2689,7 @@ abstract class GenericFunctionType implements TypeAnnotation {
|
|||
/// A generic type alias.
|
||||
///
|
||||
/// functionTypeAlias ::=
|
||||
/// metadata 'typedef' [SimpleIdentifier] [TypeParameterList]? = [FunctionType] ';'
|
||||
/// metadata 'typedef' name [TypeParameterList]? = [FunctionType] ';'
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class GenericTypeAlias implements TypeAlias {
|
||||
|
@ -3394,8 +3417,12 @@ abstract class MethodDeclaration implements ClassMember {
|
|||
Token? get modifierKeyword;
|
||||
|
||||
/// Return the name of the method.
|
||||
@Deprecated('Use name2 instead')
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the name of the method.
|
||||
Token get name2;
|
||||
|
||||
/// Return the token representing the 'operator' keyword, or `null` if this
|
||||
/// method does not declare an operator.
|
||||
Token? get operatorKeyword;
|
||||
|
@ -3480,7 +3507,7 @@ abstract class MethodReferenceExpression implements Expression {
|
|||
/// The declaration of a mixin.
|
||||
///
|
||||
/// mixinDeclaration ::=
|
||||
/// metadata? 'mixin' [SimpleIdentifier] [TypeParameterList]?
|
||||
/// metadata? 'mixin' name [TypeParameterList]?
|
||||
/// [OnClause]? [ImplementsClause]? '{' [ClassMember]* '}'
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
|
@ -3498,7 +3525,11 @@ abstract class MixinDeclaration implements ClassOrMixinDeclaration {
|
|||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class NamedCompilationUnitMember implements CompilationUnitMember {
|
||||
/// Return the name of the member being declared.
|
||||
@Deprecated('Use name2 instead')
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the name of the member being declared.
|
||||
Token get name2;
|
||||
}
|
||||
|
||||
/// An expression that has a name associated with it. They are used in method
|
||||
|
@ -4295,10 +4326,11 @@ abstract class SuperExpression implements Expression {
|
|||
///
|
||||
/// superFormalParameter ::=
|
||||
/// ('final' [TypeAnnotation] | 'const' [TypeAnnotation] | 'var' | [TypeAnnotation])?
|
||||
/// 'super' '.' [SimpleIdentifier] ([TypeParameterList]? [FormalParameterList])?
|
||||
/// 'super' '.' name ([TypeParameterList]? [FormalParameterList])?
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class SuperFormalParameter implements NormalFormalParameter {
|
||||
@Deprecated('Use identifier2 instead')
|
||||
@override
|
||||
SimpleIdentifier get identifier;
|
||||
|
||||
|
@ -4306,6 +4338,9 @@ abstract class SuperFormalParameter implements NormalFormalParameter {
|
|||
/// keyword, or `null` if no keyword was used.
|
||||
Token? get keyword;
|
||||
|
||||
@override
|
||||
Token get name;
|
||||
|
||||
/// Return the parameters of the function-typed parameter, or `null` if this
|
||||
/// is not a function-typed field formal parameter.
|
||||
FormalParameterList? get parameters;
|
||||
|
@ -4508,9 +4543,6 @@ abstract class TryStatement implements Statement {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class TypeAlias implements NamedCompilationUnitMember {
|
||||
@override
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the semicolon terminating the declaration.
|
||||
Token get semicolon;
|
||||
|
||||
|
@ -4594,7 +4626,7 @@ abstract class TypeLiteral implements Expression, CommentReferableExpression {
|
|||
/// A type parameter.
|
||||
///
|
||||
/// typeParameter ::=
|
||||
/// [SimpleIdentifier] ('extends' [TypeAnnotation])?
|
||||
/// name ('extends' [TypeAnnotation])?
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class TypeParameter implements Declaration {
|
||||
|
@ -4610,7 +4642,11 @@ abstract class TypeParameter implements Declaration {
|
|||
Token? get extendsKeyword;
|
||||
|
||||
/// Return the name of the type parameter.
|
||||
@Deprecated('Use name2 instead')
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the name of the type parameter.
|
||||
Token get name2;
|
||||
}
|
||||
|
||||
/// Type parameters within a declaration.
|
||||
|
@ -4669,7 +4705,7 @@ abstract class UriBasedDirective implements Directive {
|
|||
/// [VariableDeclarationList].
|
||||
///
|
||||
/// variableDeclaration ::=
|
||||
/// [SimpleIdentifier] ('=' [Expression])?
|
||||
/// name ('=' [Expression])?
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
// TODO(paulberry): the grammar does not allow metadata to be associated with a
|
||||
|
@ -4701,7 +4737,11 @@ abstract class VariableDeclaration implements Declaration {
|
|||
bool get isLate;
|
||||
|
||||
/// Return the name of the variable being declared.
|
||||
@Deprecated('Use name2 instead')
|
||||
SimpleIdentifier get name;
|
||||
|
||||
/// Return the name of the variable being declared.
|
||||
Token get name2;
|
||||
}
|
||||
|
||||
/// The declaration of one or more variables of the same type.
|
||||
|
|
|
@ -86,10 +86,10 @@ class ErrorReporter {
|
|||
// TODO(brianwilkerson) Consider extending this method to take any
|
||||
// declaration and compute the correct range for the name of that
|
||||
// declaration. This might make it easier to be consistent.
|
||||
if (constructor.name != null) {
|
||||
if (constructor.name2 != null) {
|
||||
var offset = constructor.returnType.offset;
|
||||
reportErrorForOffset(
|
||||
code, offset, constructor.name!.end - offset, arguments);
|
||||
code, offset, constructor.name2!.end - offset, arguments);
|
||||
} else {
|
||||
reportErrorForNode(code, constructor.returnType, arguments);
|
||||
}
|
||||
|
|
|
@ -3,37 +3,38 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
|
||||
/// Compute the [DefinedNames] for the given [unit].
|
||||
DefinedNames computeDefinedNames(CompilationUnit unit) {
|
||||
DefinedNames names = DefinedNames();
|
||||
|
||||
void appendName(Set<String> names, SimpleIdentifier? node) {
|
||||
var name = node?.name;
|
||||
if (name != null && name.isNotEmpty) {
|
||||
names.add(name);
|
||||
void appendName(Set<String> names, Token? token) {
|
||||
var lexeme = token?.lexeme;
|
||||
if (lexeme != null && lexeme.isNotEmpty) {
|
||||
names.add(lexeme);
|
||||
}
|
||||
}
|
||||
|
||||
void appendClassMemberName(ClassMember member) {
|
||||
if (member is MethodDeclaration) {
|
||||
appendName(names.classMemberNames, member.name);
|
||||
appendName(names.classMemberNames, member.name2);
|
||||
} else if (member is FieldDeclaration) {
|
||||
for (VariableDeclaration field in member.fields.variables) {
|
||||
appendName(names.classMemberNames, field.name);
|
||||
appendName(names.classMemberNames, field.name2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void appendTopLevelName(CompilationUnitMember member) {
|
||||
if (member is NamedCompilationUnitMember) {
|
||||
appendName(names.topLevelNames, member.name);
|
||||
appendName(names.topLevelNames, member.name2);
|
||||
if (member is ClassDeclaration) {
|
||||
member.members.forEach(appendClassMemberName);
|
||||
}
|
||||
if (member is EnumDeclaration) {
|
||||
for (var constant in member.constants) {
|
||||
appendName(names.classMemberNames, constant.name);
|
||||
appendName(names.classMemberNames, constant.name2);
|
||||
}
|
||||
member.members.forEach(appendClassMemberName);
|
||||
}
|
||||
|
@ -42,7 +43,7 @@ DefinedNames computeDefinedNames(CompilationUnit unit) {
|
|||
}
|
||||
} else if (member is TopLevelVariableDeclaration) {
|
||||
for (VariableDeclaration variable in member.variables.variables) {
|
||||
appendName(names.topLevelNames, variable.name);
|
||||
appendName(names.topLevelNames, variable.name2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -910,13 +910,13 @@ class FileState {
|
|||
if (declaration.macroKeyword != null) {
|
||||
var constructors = declaration.members
|
||||
.whereType<ConstructorDeclaration>()
|
||||
.map((e) => e.name?.name ?? '')
|
||||
.map((e) => e.name2?.lexeme ?? '')
|
||||
.where((e) => !e.startsWith('_'))
|
||||
.toList();
|
||||
if (constructors.isNotEmpty) {
|
||||
macroClasses.add(
|
||||
MacroClass(
|
||||
name: declaration.name.name,
|
||||
name: declaration.name2.lexeme,
|
||||
constructors: constructors,
|
||||
),
|
||||
);
|
||||
|
@ -940,21 +940,21 @@ class FileState {
|
|||
final topLevelDeclarations = <String>{};
|
||||
for (final declaration in unit.declarations) {
|
||||
if (declaration is ClassDeclaration) {
|
||||
topLevelDeclarations.add(declaration.name.name);
|
||||
topLevelDeclarations.add(declaration.name2.lexeme);
|
||||
} else if (declaration is EnumDeclaration) {
|
||||
topLevelDeclarations.add(declaration.name.name);
|
||||
topLevelDeclarations.add(declaration.name2.lexeme);
|
||||
} else if (declaration is ExtensionDeclaration) {
|
||||
var name = declaration.name;
|
||||
var name = declaration.name2;
|
||||
if (name != null) {
|
||||
topLevelDeclarations.add(name.name);
|
||||
topLevelDeclarations.add(name.lexeme);
|
||||
}
|
||||
} else if (declaration is FunctionDeclaration) {
|
||||
topLevelDeclarations.add(declaration.name.name);
|
||||
topLevelDeclarations.add(declaration.name2.lexeme);
|
||||
} else if (declaration is MixinDeclaration) {
|
||||
topLevelDeclarations.add(declaration.name.name);
|
||||
topLevelDeclarations.add(declaration.name2.lexeme);
|
||||
} else if (declaration is TopLevelVariableDeclaration) {
|
||||
for (var variable in declaration.variables.variables) {
|
||||
topLevelDeclarations.add(variable.name.name);
|
||||
topLevelDeclarations.add(variable.name2.lexeme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/syntactic_entity.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
|
@ -464,8 +465,8 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
/// of the given [node]. The flag [isQualified] is `true` if [node] has an
|
||||
/// explicit or implicit qualifier, so cannot be shadowed by a local
|
||||
/// declaration.
|
||||
void recordRelation(Element? element, IndexRelationKind kind, AstNode node,
|
||||
bool isQualified) {
|
||||
void recordRelation(Element? element, IndexRelationKind kind,
|
||||
SyntacticEntity node, bool isQualified) {
|
||||
if (element != null) {
|
||||
recordRelationOffset(
|
||||
element, kind, node.offset, node.length, isQualified);
|
||||
|
@ -564,7 +565,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
if (node.extendsClause == null) {
|
||||
ClassElement? objectElement = declaredElement.supertype?.element;
|
||||
recordRelationOffset(objectElement, IndexRelationKind.IS_EXTENDED_BY,
|
||||
node.name.offset, 0, true);
|
||||
node.name2.offset, 0, true);
|
||||
}
|
||||
recordIsAncestorOf(declaredElement);
|
||||
super.visitClassDeclaration(node);
|
||||
|
@ -654,7 +655,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
offset = constructorSelector.period.offset;
|
||||
length = constructorSelector.name.end - offset;
|
||||
} else {
|
||||
offset = node.name.end;
|
||||
offset = node.name2.end;
|
||||
length = 0;
|
||||
}
|
||||
recordRelationOffset(
|
||||
|
@ -674,7 +675,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
@override
|
||||
void visitEnumDeclaration(EnumDeclaration node) {
|
||||
_addSubtype(
|
||||
node.name.name,
|
||||
node.name2.lexeme,
|
||||
withClause: node.withClause,
|
||||
implementsClause: node.implementsClause,
|
||||
memberNodes: node.members,
|
||||
|
@ -713,8 +714,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
if (element is FieldFormalParameterElement) {
|
||||
var field = element.field;
|
||||
if (field != null) {
|
||||
recordRelation(
|
||||
field, IndexRelationKind.IS_WRITTEN_BY, node.identifier, true);
|
||||
recordRelation(field, IndexRelationKind.IS_WRITTEN_BY, node.name, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -861,11 +861,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
}
|
||||
// this.field parameter
|
||||
if (element is FieldFormalParameterElement) {
|
||||
AstNode parent = node.parent!;
|
||||
IndexRelationKind kind =
|
||||
parent is FieldFormalParameter && parent.identifier == node
|
||||
? IndexRelationKind.IS_WRITTEN_BY
|
||||
: IndexRelationKind.IS_REFERENCED_BY;
|
||||
IndexRelationKind kind = IndexRelationKind.IS_REFERENCED_BY;
|
||||
recordRelation(element.field, kind, node, true);
|
||||
return;
|
||||
}
|
||||
|
@ -901,7 +897,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
var superParameter = element.superConstructorParameter;
|
||||
if (superParameter != null) {
|
||||
recordRelation(superParameter, IndexRelationKind.IS_REFERENCED_BY,
|
||||
node.identifier, true);
|
||||
node.name, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -943,8 +939,8 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
onClause?.superclassConstraints.forEach(addSupertype);
|
||||
implementsClause?.interfaces.forEach(addSupertype);
|
||||
|
||||
void addMemberName(SimpleIdentifier identifier) {
|
||||
String name = identifier.name;
|
||||
void addMemberName(Token identifier) {
|
||||
String name = identifier.lexeme;
|
||||
if (name.isNotEmpty) {
|
||||
members.add(name);
|
||||
}
|
||||
|
@ -952,10 +948,10 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
|
||||
for (ClassMember member in memberNodes) {
|
||||
if (member is MethodDeclaration && !member.isStatic) {
|
||||
addMemberName(member.name);
|
||||
addMemberName(member.name2);
|
||||
} else if (member is FieldDeclaration && !member.isStatic) {
|
||||
for (var field in member.fields.variables) {
|
||||
addMemberName(field.name);
|
||||
addMemberName(field.name2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -968,7 +964,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
|
||||
/// Record the given class as a subclass of its direct superclasses.
|
||||
void _addSubtypeForClassDeclaration(ClassDeclaration node) {
|
||||
_addSubtype(node.name.name,
|
||||
_addSubtype(node.name2.lexeme,
|
||||
superclass: node.extendsClause?.superclass,
|
||||
withClause: node.withClause,
|
||||
implementsClause: node.implementsClause,
|
||||
|
@ -977,7 +973,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
|
||||
/// Record the given class as a subclass of its direct superclasses.
|
||||
void _addSubtypeForClassTypeAlis(ClassTypeAlias node) {
|
||||
_addSubtype(node.name.name,
|
||||
_addSubtype(node.name2.lexeme,
|
||||
superclass: node.superclass,
|
||||
withClause: node.withClause,
|
||||
implementsClause: node.implementsClause,
|
||||
|
@ -986,7 +982,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
|||
|
||||
/// Record the given mixin as a subclass of its direct superclasses.
|
||||
void _addSubtypeForMixinDeclaration(MixinDeclaration node) {
|
||||
_addSubtype(node.name.name,
|
||||
_addSubtype(node.name2.lexeme,
|
||||
onClause: node.onClause,
|
||||
implementsClause: node.implementsClause,
|
||||
memberNodes: node.members);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
|
||||
/// Compute the set of external names referenced in the [unit].
|
||||
|
@ -64,7 +65,7 @@ class _LocalNameScope {
|
|||
_LocalNameScope scope = _LocalNameScope(enclosing);
|
||||
for (Statement statement in node.statements) {
|
||||
if (statement is FunctionDeclarationStatement) {
|
||||
scope.add(statement.functionDeclaration.name);
|
||||
scope.add(statement.functionDeclaration.name2);
|
||||
} else if (statement is VariableDeclarationStatement) {
|
||||
scope.addVariableNames(statement.variables);
|
||||
}
|
||||
|
@ -80,7 +81,7 @@ class _LocalNameScope {
|
|||
if (member is FieldDeclaration) {
|
||||
scope.addVariableNames(member.fields);
|
||||
} else if (member is MethodDeclaration) {
|
||||
scope.add(member.name);
|
||||
scope.add(member.name2);
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
|
@ -127,7 +128,7 @@ class _LocalNameScope {
|
|||
_LocalNameScope scope = _LocalNameScope(null);
|
||||
for (CompilationUnitMember declaration in node.declarations) {
|
||||
if (declaration is NamedCompilationUnitMember) {
|
||||
scope.add(declaration.name);
|
||||
scope.add(declaration.name2);
|
||||
} else if (declaration is TopLevelVariableDeclaration) {
|
||||
scope.addVariableNames(declaration.variables);
|
||||
}
|
||||
|
@ -135,29 +136,29 @@ class _LocalNameScope {
|
|||
return scope;
|
||||
}
|
||||
|
||||
void add(SimpleIdentifier? identifier) {
|
||||
if (identifier != null) {
|
||||
(names ??= <String>{}).add(identifier.name);
|
||||
void add(Token? token) {
|
||||
if (token != null) {
|
||||
(names ??= <String>{}).add(token.lexeme);
|
||||
}
|
||||
}
|
||||
|
||||
void addFormalParameters(FormalParameterList? parameterList) {
|
||||
if (parameterList != null) {
|
||||
parameterList.parameters
|
||||
.map((p) => p is NormalFormalParameter ? p.identifier : null)
|
||||
.map((p) => p is NormalFormalParameter ? p.name : null)
|
||||
.forEach(add);
|
||||
}
|
||||
}
|
||||
|
||||
void addTypeParameters(TypeParameterList? typeParameterList) {
|
||||
if (typeParameterList != null) {
|
||||
typeParameterList.typeParameters.map((p) => p.name).forEach(add);
|
||||
typeParameterList.typeParameters.map((p) => p.name2).forEach(add);
|
||||
}
|
||||
}
|
||||
|
||||
void addVariableNames(VariableDeclarationList variableList) {
|
||||
for (VariableDeclaration variable in variableList.variables) {
|
||||
add(variable.name);
|
||||
add(variable.name2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/dart/analysis/session.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type_provider.dart';
|
||||
|
@ -343,22 +344,22 @@ class _DeclarationByElementLocator extends UnifyingAstVisitor<void> {
|
|||
|
||||
if (element is ClassElement) {
|
||||
if (node is ClassOrMixinDeclaration) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
} else if (node is ClassTypeAlias) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
} else if (node is EnumDeclaration) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
}
|
||||
} else if (element is ConstructorElement) {
|
||||
if (node is ConstructorDeclaration) {
|
||||
if (node.name != null) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (node.name2 != null) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
} else {
|
||||
|
@ -369,48 +370,48 @@ class _DeclarationByElementLocator extends UnifyingAstVisitor<void> {
|
|||
}
|
||||
} else if (element is ExtensionElement) {
|
||||
if (node is ExtensionDeclaration) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
}
|
||||
} else if (element is FieldElement) {
|
||||
if (node is EnumConstantDeclaration) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
} else if (node is VariableDeclaration) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
}
|
||||
} else if (element is FunctionElement) {
|
||||
if (node is FunctionDeclaration && _hasOffset(node.name)) {
|
||||
if (node is FunctionDeclaration && _hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
} else if (element is LocalVariableElement) {
|
||||
if (node is VariableDeclaration && _hasOffset(node.name)) {
|
||||
if (node is VariableDeclaration && _hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
} else if (element is MethodElement) {
|
||||
if (node is MethodDeclaration && _hasOffset(node.name)) {
|
||||
if (node is MethodDeclaration && _hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
} else if (element is ParameterElement) {
|
||||
if (node is FormalParameter && _hasOffset(node.identifier)) {
|
||||
if (node is FormalParameter && _hasOffset2(node.name)) {
|
||||
result = node;
|
||||
}
|
||||
} else if (element is PropertyAccessorElement) {
|
||||
if (node is FunctionDeclaration) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
} else if (node is MethodDeclaration) {
|
||||
if (_hasOffset(node.name)) {
|
||||
if (_hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
}
|
||||
} else if (element is TopLevelVariableElement) {
|
||||
if (node is VariableDeclaration && _hasOffset(node.name)) {
|
||||
if (node is VariableDeclaration && _hasOffset2(node.name2)) {
|
||||
result = node;
|
||||
}
|
||||
}
|
||||
|
@ -423,4 +424,8 @@ class _DeclarationByElementLocator extends UnifyingAstVisitor<void> {
|
|||
bool _hasOffset(AstNode? node) {
|
||||
return node?.offset == _nameOffset;
|
||||
}
|
||||
|
||||
bool _hasOffset2(Token? token) {
|
||||
return token?.offset == _nameOffset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class _UnitApiSignatureComputer {
|
|||
var functionExpression = declaration.functionExpression;
|
||||
_addTokens(
|
||||
declaration.beginToken,
|
||||
(functionExpression.parameters ?? declaration.name).endToken,
|
||||
functionExpression.parameters?.endToken ?? declaration.name2,
|
||||
);
|
||||
_addFunctionBodyModifiers(functionExpression.body);
|
||||
} else if (declaration is TopLevelVariableDeclaration) {
|
||||
|
@ -138,7 +138,7 @@ class _UnitApiSignatureComputer {
|
|||
signature.addInt(_kindMethodDeclaration);
|
||||
_addTokens(
|
||||
node.beginToken,
|
||||
(node.parameters ?? node.name).endToken,
|
||||
node.parameters?.endToken ?? node.name2,
|
||||
);
|
||||
signature.addBool(node.body is EmptyFunctionBody);
|
||||
_addFunctionBodyModifiers(node.body);
|
||||
|
@ -212,7 +212,7 @@ class _UnitApiSignatureComputer {
|
|||
signature.addInt(variables.length);
|
||||
|
||||
for (var variable in variables) {
|
||||
_addNode(variable.name);
|
||||
_addToken(variable.name2);
|
||||
signature.addBool(variable.initializer != null);
|
||||
if (includeInitializers) {
|
||||
_addNode(variable.initializer);
|
||||
|
|
|
@ -1678,6 +1678,9 @@ class ClassDeclarationImpl extends ClassOrMixinDeclarationImpl
|
|||
/// native clause.
|
||||
NativeClauseImpl? _nativeClause;
|
||||
|
||||
@override
|
||||
ClassElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created class declaration. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the class does not have the
|
||||
/// corresponding attribute. The [abstractKeyword] can be `null` if the class
|
||||
|
@ -1707,9 +1710,6 @@ class ClassDeclarationImpl extends ClassOrMixinDeclarationImpl
|
|||
_becomeParentOf(_withClause);
|
||||
}
|
||||
|
||||
@override
|
||||
ClassElement? get declaredElement => _name.staticElement as ClassElement?;
|
||||
|
||||
@override
|
||||
ExtendsClauseImpl? get extendsClause => _extendsClause;
|
||||
|
||||
|
@ -1746,7 +1746,7 @@ class ClassDeclarationImpl extends ClassOrMixinDeclarationImpl
|
|||
..addToken('macroKeyword', macroKeyword)
|
||||
..addToken('augmentKeyword', augmentKeyword)
|
||||
..addToken('classKeyword', classKeyword)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('typeParameters', typeParameters)
|
||||
..addNode('extendsClause', extendsClause)
|
||||
..addNode('withClause', withClause)
|
||||
|
@ -1782,7 +1782,8 @@ class ClassDeclarationImpl extends ClassOrMixinDeclarationImpl
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_extendsClause?.accept(visitor);
|
||||
_withClause?.accept(visitor);
|
||||
|
@ -1886,7 +1887,7 @@ abstract class ClassOrMixinDeclarationImpl
|
|||
ClassMember classMember = _members[i];
|
||||
if (classMember is MethodDeclaration) {
|
||||
MethodDeclaration method = classMember;
|
||||
if (name == method.name.name) {
|
||||
if (name == method.name2.lexeme) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
@ -1935,6 +1936,9 @@ class ClassTypeAliasImpl extends TypeAliasImpl implements ClassTypeAlias {
|
|||
/// clause.
|
||||
ImplementsClauseImpl? _implementsClause;
|
||||
|
||||
@override
|
||||
ClassElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created class type alias. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the class type alias does not
|
||||
/// have the corresponding attribute. The [typeParameters] can be `null` if
|
||||
|
@ -1962,9 +1966,6 @@ class ClassTypeAliasImpl extends TypeAliasImpl implements ClassTypeAlias {
|
|||
_becomeParentOf(_implementsClause);
|
||||
}
|
||||
|
||||
@override
|
||||
ClassElement? get declaredElement => _name.staticElement as ClassElement?;
|
||||
|
||||
@override
|
||||
Token get firstTokenAfterCommentAndMetadata {
|
||||
return abstractKeyword ?? macroKeyword ?? augmentKeyword ?? typedefKeyword;
|
||||
|
@ -2010,7 +2011,7 @@ class ClassTypeAliasImpl extends TypeAliasImpl implements ClassTypeAlias {
|
|||
@override
|
||||
ChildEntities get _childEntities => super._childEntities
|
||||
..addToken('typedefKeyword', typedefKeyword)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('typeParameters', typeParameters)
|
||||
..addToken('equals', equals)
|
||||
..addToken('abstractKeyword', abstractKeyword)
|
||||
|
@ -2027,7 +2028,8 @@ class ClassTypeAliasImpl extends TypeAliasImpl implements ClassTypeAlias {
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_superclass.accept(visitor);
|
||||
_withClause.accept(visitor);
|
||||
|
@ -2700,7 +2702,7 @@ class ConstructorDeclarationImpl extends ClassMemberImpl
|
|||
/// [comment] and [metadata] can be `null` if the constructor does not have
|
||||
/// the corresponding attribute. The [constKeyword] can be `null` if the
|
||||
/// constructor cannot be used to create a constant. The [factoryKeyword] can
|
||||
/// be `null` if the constructor is not a factory. The [period] and [name] can
|
||||
/// be `null` if the constructor is not a factory. The [period] and [name2] can
|
||||
/// both be `null` if the constructor is not a named constructor. The
|
||||
/// [separator] can be `null` if the constructor does not have any
|
||||
/// initializers and does not redirect to a different constructor. The list of
|
||||
|
@ -2752,13 +2754,20 @@ class ConstructorDeclarationImpl extends ClassMemberImpl
|
|||
@override
|
||||
NodeListImpl<ConstructorInitializer> get initializers => _initializers;
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl? get name => _name;
|
||||
|
||||
set name(SimpleIdentifier? identifier) {
|
||||
_name = _becomeParentOf(identifier as SimpleIdentifierImpl?);
|
||||
SimpleIdentifierImpl? get name {
|
||||
_name?.staticElement = declaredElement;
|
||||
return _name;
|
||||
}
|
||||
|
||||
set name(SimpleIdentifier? name) {
|
||||
_name = _becomeParentOf(name as SimpleIdentifierImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
Token? get name2 => _name?.token;
|
||||
|
||||
@override
|
||||
FormalParameterListImpl get parameters => _parameters;
|
||||
|
||||
|
@ -2788,7 +2797,7 @@ class ConstructorDeclarationImpl extends ClassMemberImpl
|
|||
..addToken('factoryKeyword', factoryKeyword)
|
||||
..addNode('returnType', returnType)
|
||||
..addToken('period', period)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('parameters', parameters)
|
||||
..addToken('separator', separator)
|
||||
..addNodeList('initializers', initializers)
|
||||
|
@ -3144,6 +3153,9 @@ class DeclaredIdentifierImpl extends DeclarationImpl
|
|||
/// The name of the variable being declared.
|
||||
SimpleIdentifierImpl _identifier;
|
||||
|
||||
@override
|
||||
LocalVariableElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created formal parameter. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the declaration does not have
|
||||
/// the corresponding attribute. The [keyword] can be `null` if a type name is
|
||||
|
@ -3154,11 +3166,6 @@ class DeclaredIdentifierImpl extends DeclarationImpl
|
|||
_becomeParentOf(_identifier);
|
||||
}
|
||||
|
||||
@override
|
||||
LocalVariableElement? get declaredElement {
|
||||
return _identifier.staticElement as LocalVariableElement;
|
||||
}
|
||||
|
||||
@override
|
||||
Token get endToken => _identifier.endToken;
|
||||
|
||||
|
@ -3167,8 +3174,12 @@ class DeclaredIdentifierImpl extends DeclarationImpl
|
|||
return keyword ?? _type?.beginToken ?? _identifier.beginToken;
|
||||
}
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get identifier => _identifier;
|
||||
SimpleIdentifierImpl get identifier {
|
||||
_identifier.staticElement = declaredElement;
|
||||
return _identifier;
|
||||
}
|
||||
|
||||
set identifier(SimpleIdentifier identifier) {
|
||||
_identifier = _becomeParentOf(identifier as SimpleIdentifierImpl);
|
||||
|
@ -3180,6 +3191,9 @@ class DeclaredIdentifierImpl extends DeclarationImpl
|
|||
@override
|
||||
bool get isFinal => keyword?.keyword == Keyword.FINAL;
|
||||
|
||||
@override
|
||||
Token get name => _identifier.token;
|
||||
|
||||
@override
|
||||
TypeAnnotationImpl? get type => _type;
|
||||
|
||||
|
@ -3191,7 +3205,7 @@ class DeclaredIdentifierImpl extends DeclarationImpl
|
|||
ChildEntities get _childEntities => super._childEntities
|
||||
..addToken('keyword', keyword)
|
||||
..addNode('type', type)
|
||||
..addNode('identifier', identifier);
|
||||
..addToken('name', name);
|
||||
|
||||
@override
|
||||
E? accept<E>(AstVisitor<E> visitor) => visitor.visitDeclaredIdentifier(this);
|
||||
|
@ -3200,7 +3214,8 @@ class DeclaredIdentifierImpl extends DeclarationImpl
|
|||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_type?.accept(visitor);
|
||||
_identifier.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
identifier.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3279,6 +3294,7 @@ class DefaultFormalParameterImpl extends FormalParameterImpl
|
|||
return _parameter.endToken;
|
||||
}
|
||||
|
||||
@Deprecated('Use identifier2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl? get identifier => _parameter.identifier;
|
||||
|
||||
|
@ -3294,6 +3310,9 @@ class DefaultFormalParameterImpl extends FormalParameterImpl
|
|||
@override
|
||||
NodeListImpl<Annotation> get metadata => _parameter.metadata;
|
||||
|
||||
@override
|
||||
Token? get name => _parameter.name;
|
||||
|
||||
@override
|
||||
NormalFormalParameterImpl get parameter => _parameter;
|
||||
|
||||
|
@ -3642,6 +3661,9 @@ class EnumConstantDeclarationImpl extends DeclarationImpl
|
|||
/// The name of the constant.
|
||||
SimpleIdentifierImpl _name;
|
||||
|
||||
@override
|
||||
FieldElement? declaredElement;
|
||||
|
||||
@override
|
||||
final EnumConstantArgumentsImpl? arguments;
|
||||
|
||||
|
@ -3662,25 +3684,29 @@ class EnumConstantDeclarationImpl extends DeclarationImpl
|
|||
_becomeParentOf(arguments);
|
||||
}
|
||||
|
||||
@override
|
||||
FieldElement get declaredElement => _name.staticElement as FieldElement;
|
||||
|
||||
@override
|
||||
Token get endToken => (arguments ?? _name).endToken;
|
||||
|
||||
@override
|
||||
Token get firstTokenAfterCommentAndMetadata => _name.beginToken;
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get name => _name;
|
||||
SimpleIdentifierImpl get name {
|
||||
_name.staticElement = declaredElement;
|
||||
return _name;
|
||||
}
|
||||
|
||||
set name(SimpleIdentifier name) {
|
||||
_name = _becomeParentOf(name as SimpleIdentifierImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
Token get name2 => _name.token;
|
||||
|
||||
@override
|
||||
ChildEntities get _childEntities => super._childEntities
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('arguments', arguments);
|
||||
|
||||
@override
|
||||
|
@ -3690,7 +3716,8 @@ class EnumConstantDeclarationImpl extends DeclarationImpl
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
arguments?.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
@ -3736,6 +3763,9 @@ class EnumDeclarationImpl extends NamedCompilationUnitMemberImpl
|
|||
@override
|
||||
Token rightBracket;
|
||||
|
||||
@override
|
||||
ClassElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created enumeration declaration. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the declaration does not have
|
||||
/// the corresponding attribute. The list of [constants] must contain at least
|
||||
|
@ -3764,9 +3794,6 @@ class EnumDeclarationImpl extends NamedCompilationUnitMemberImpl
|
|||
@override
|
||||
NodeListImpl<EnumConstantDeclaration> get constants => _constants;
|
||||
|
||||
@override
|
||||
ClassElement? get declaredElement => _name.staticElement as ClassElement?;
|
||||
|
||||
@override
|
||||
Token get endToken => rightBracket;
|
||||
|
||||
|
@ -3802,7 +3829,7 @@ class EnumDeclarationImpl extends NamedCompilationUnitMemberImpl
|
|||
// TODO(brianwilkerson) Add commas?
|
||||
ChildEntities get _childEntities => super._childEntities
|
||||
..addToken('enumKeyword', enumKeyword)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('typeParameters', typeParameters)
|
||||
..addNode('withClause', withClause)
|
||||
..addNode('implementsClause', implementsClause)
|
||||
|
@ -3818,7 +3845,8 @@ class EnumDeclarationImpl extends NamedCompilationUnitMemberImpl
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_withClause?.accept(visitor);
|
||||
_implementsClause?.accept(visitor);
|
||||
|
@ -4306,13 +4334,20 @@ class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
|
|||
@override
|
||||
NodeListImpl<ClassMember> get members => _members;
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl? get name => _name;
|
||||
SimpleIdentifierImpl? get name {
|
||||
_name?.staticElement = declaredElement;
|
||||
return _name;
|
||||
}
|
||||
|
||||
set name(SimpleIdentifier? identifier) {
|
||||
_name = _becomeParentOf(identifier as SimpleIdentifierImpl?);
|
||||
}
|
||||
|
||||
@override
|
||||
Token? get name2 => _name?.token;
|
||||
|
||||
@override
|
||||
ShowClauseImpl? get showClause => _showClause;
|
||||
|
||||
|
@ -4330,7 +4365,7 @@ class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
|
|||
@override
|
||||
ChildEntities get _childEntities => ChildEntities()
|
||||
..addToken('extensionKeyword', extensionKeyword)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('typeParameters', typeParameters)
|
||||
..addToken('onKeyword', onKeyword)
|
||||
..addNode('extendedType', extendedType)
|
||||
|
@ -4345,6 +4380,7 @@ class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name?.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_extendedType.accept(visitor);
|
||||
|
@ -4617,9 +4653,10 @@ class FieldFormalParameterImpl extends NormalFormalParameterImpl
|
|||
|
||||
@override
|
||||
Token get endToken {
|
||||
return question ?? _parameters?.endToken ?? identifier.endToken;
|
||||
return question ?? _parameters?.endToken ?? name;
|
||||
}
|
||||
|
||||
@Deprecated('Use identifier2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get identifier => super.identifier!;
|
||||
|
||||
|
@ -4632,6 +4669,9 @@ class FieldFormalParameterImpl extends NormalFormalParameterImpl
|
|||
@override
|
||||
bool get isFinal => keyword?.keyword == Keyword.FINAL;
|
||||
|
||||
@override
|
||||
Token get name => super.name!;
|
||||
|
||||
@override
|
||||
FormalParameterListImpl? get parameters => _parameters;
|
||||
|
||||
|
@ -4659,7 +4699,7 @@ class FieldFormalParameterImpl extends NormalFormalParameterImpl
|
|||
..addNode('type', type)
|
||||
..addToken('thisKeyword', thisKeyword)
|
||||
..addToken('period', period)
|
||||
..addNode('identifier', identifier)
|
||||
..addToken('name', name)
|
||||
..addNode('parameters', parameters);
|
||||
|
||||
@override
|
||||
|
@ -4670,6 +4710,7 @@ class FieldFormalParameterImpl extends NormalFormalParameterImpl
|
|||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_type?.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
identifier.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_parameters?.accept(visitor);
|
||||
|
@ -4873,17 +4914,24 @@ abstract class ForLoopPartsImpl extends AstNodeImpl implements ForLoopParts {}
|
|||
abstract class FormalParameterImpl extends AstNodeImpl
|
||||
implements FormalParameter {
|
||||
@override
|
||||
ParameterElement? get declaredElement {
|
||||
final identifier = this.identifier;
|
||||
if (identifier == null) {
|
||||
return null;
|
||||
}
|
||||
return identifier.staticElement as ParameterElement?;
|
||||
}
|
||||
ParameterElement? declaredElement;
|
||||
|
||||
@Deprecated('Use identifier2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl? get identifier;
|
||||
|
||||
/// TODO(scheglov) I was not able to update 'nnbd_migration' any better.
|
||||
SimpleIdentifier? get identifierForMigration {
|
||||
final token = name;
|
||||
if (token != null) {
|
||||
final result = SimpleIdentifierImpl(token);
|
||||
result.staticElement = declaredElement;
|
||||
_becomeParentOf(result);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isNamed => kind.isNamed;
|
||||
|
||||
|
@ -4910,19 +4958,6 @@ abstract class FormalParameterImpl extends AstNodeImpl
|
|||
|
||||
/// Return the kind of this parameter.
|
||||
ParameterKind get kind;
|
||||
|
||||
static void setDeclaredElement(
|
||||
FormalParameterImpl node,
|
||||
ParameterElement element,
|
||||
) {
|
||||
if (node is DefaultFormalParameterImpl) {
|
||||
setDeclaredElement(node.parameter, element);
|
||||
} else if (node is SimpleFormalParameterImpl) {
|
||||
node.declaredElement = element;
|
||||
} else {
|
||||
node.identifier!.staticElement = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The formal parameter list of a method declaration, function declaration, or
|
||||
|
@ -5331,6 +5366,9 @@ class FunctionDeclarationImpl extends NamedCompilationUnitMemberImpl
|
|||
/// The function expression being wrapped.
|
||||
FunctionExpressionImpl _functionExpression;
|
||||
|
||||
@override
|
||||
ExecutableElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created function declaration. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the function does not have the
|
||||
/// corresponding attribute. The [externalKeyword] can be `null` if the
|
||||
|
@ -5351,10 +5389,6 @@ class FunctionDeclarationImpl extends NamedCompilationUnitMemberImpl
|
|||
_becomeParentOf(_functionExpression);
|
||||
}
|
||||
|
||||
@override
|
||||
ExecutableElement? get declaredElement =>
|
||||
_name.staticElement as ExecutableElement?;
|
||||
|
||||
@override
|
||||
Token get endToken => _functionExpression.endToken;
|
||||
|
||||
|
@ -5394,7 +5428,7 @@ class FunctionDeclarationImpl extends NamedCompilationUnitMemberImpl
|
|||
..addToken('externalKeyword', externalKeyword)
|
||||
..addNode('returnType', returnType)
|
||||
..addToken('propertyKeyword', propertyKeyword)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('functionExpression', functionExpression);
|
||||
|
||||
@override
|
||||
|
@ -5404,7 +5438,8 @@ class FunctionDeclarationImpl extends NamedCompilationUnitMemberImpl
|
|||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_returnType?.accept(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_functionExpression.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
@ -5692,6 +5727,9 @@ class FunctionTypeAliasImpl extends TypeAliasImpl implements FunctionTypeAlias {
|
|||
/// The parameters associated with the function type.
|
||||
FormalParameterListImpl _parameters;
|
||||
|
||||
@override
|
||||
TypeAliasElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created function type alias. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the function does not have the
|
||||
/// corresponding attribute. The [returnType] can be `null` if no return type
|
||||
|
@ -5712,10 +5750,6 @@ class FunctionTypeAliasImpl extends TypeAliasImpl implements FunctionTypeAlias {
|
|||
_becomeParentOf(_parameters);
|
||||
}
|
||||
|
||||
@override
|
||||
TypeAliasElement? get declaredElement =>
|
||||
_name.staticElement as TypeAliasElement?;
|
||||
|
||||
@override
|
||||
FormalParameterListImpl get parameters => _parameters;
|
||||
|
||||
|
@ -5741,7 +5775,7 @@ class FunctionTypeAliasImpl extends TypeAliasImpl implements FunctionTypeAlias {
|
|||
ChildEntities get _childEntities => super._childEntities
|
||||
..addToken('typedefKeyword', typedefKeyword)
|
||||
..addNode('returnType', returnType)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('typeParameters', typeParameters)
|
||||
..addNode('parameters', parameters)
|
||||
..addToken('semicolon', semicolon);
|
||||
|
@ -5753,7 +5787,8 @@ class FunctionTypeAliasImpl extends TypeAliasImpl implements FunctionTypeAlias {
|
|||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_returnType?.accept(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_parameters.accept(visitor);
|
||||
}
|
||||
|
@ -5813,12 +5848,13 @@ class FunctionTypedFormalParameterImpl extends NormalFormalParameterImpl
|
|||
} else if (_returnType != null) {
|
||||
return _returnType!.beginToken;
|
||||
}
|
||||
return identifier.beginToken;
|
||||
return name;
|
||||
}
|
||||
|
||||
@override
|
||||
Token get endToken => question ?? _parameters.endToken;
|
||||
|
||||
@Deprecated('Use identifier2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get identifier => super.identifier!;
|
||||
|
||||
|
@ -5831,6 +5867,9 @@ class FunctionTypedFormalParameterImpl extends NormalFormalParameterImpl
|
|||
@override
|
||||
bool get isFinal => false;
|
||||
|
||||
@override
|
||||
Token get name => super.name!;
|
||||
|
||||
@override
|
||||
FormalParameterListImpl get parameters => _parameters;
|
||||
|
||||
|
@ -5855,7 +5894,7 @@ class FunctionTypedFormalParameterImpl extends NormalFormalParameterImpl
|
|||
@override
|
||||
ChildEntities get _childEntities => super._childEntities
|
||||
..addNode('returnType', returnType)
|
||||
..addNode('identifier', identifier)
|
||||
..addToken('name', name)
|
||||
..addNode('parameters', parameters);
|
||||
|
||||
@override
|
||||
|
@ -5866,6 +5905,7 @@ class FunctionTypedFormalParameterImpl extends NormalFormalParameterImpl
|
|||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_returnType?.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
identifier.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_parameters.accept(visitor);
|
||||
|
@ -6003,6 +6043,9 @@ class GenericTypeAliasImpl extends TypeAliasImpl implements GenericTypeAlias {
|
|||
@override
|
||||
Token equals;
|
||||
|
||||
@override
|
||||
Element? declaredElement;
|
||||
|
||||
/// Returns a newly created generic type alias. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the variable list does not have
|
||||
/// the corresponding attribute. The [typeParameters] can be `null` if there
|
||||
|
@ -6021,9 +6064,6 @@ class GenericTypeAliasImpl extends TypeAliasImpl implements GenericTypeAlias {
|
|||
_becomeParentOf(_type);
|
||||
}
|
||||
|
||||
@override
|
||||
Element? get declaredElement => name.staticElement;
|
||||
|
||||
/// The type of function being defined by the alias.
|
||||
///
|
||||
/// If the non-function type aliases feature is enabled, a type alias may have
|
||||
|
@ -6058,7 +6098,7 @@ class GenericTypeAliasImpl extends TypeAliasImpl implements GenericTypeAlias {
|
|||
ChildEntities get _childEntities => ChildEntities()
|
||||
..addNodeList('metadata', metadata)
|
||||
..addToken('typedefKeyword', typedefKeyword)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('typeParameters', typeParameters)
|
||||
..addToken('equals', equals)
|
||||
..addNode('type', type);
|
||||
|
@ -6071,6 +6111,7 @@ class GenericTypeAliasImpl extends TypeAliasImpl implements GenericTypeAlias {
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_type.accept(visitor);
|
||||
|
@ -7749,6 +7790,14 @@ class MethodDeclarationImpl extends ClassMemberImpl
|
|||
/// The body of the method.
|
||||
FunctionBodyImpl _body;
|
||||
|
||||
/// Return the element associated with this method, or `null` if the AST
|
||||
/// structure has not been resolved. The element can either be a
|
||||
/// [MethodElement], if this represents the declaration of a normal method, or
|
||||
/// a [PropertyAccessorElement] if this represents the declaration of either a
|
||||
/// getter or a setter.
|
||||
@override
|
||||
ExecutableElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created method declaration. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the declaration does not have
|
||||
/// the corresponding attribute. The [externalKeyword] can be `null` if the
|
||||
|
@ -7784,15 +7833,6 @@ class MethodDeclarationImpl extends ClassMemberImpl
|
|||
_body = _becomeParentOf(functionBody as FunctionBodyImpl);
|
||||
}
|
||||
|
||||
/// Return the element associated with this method, or `null` if the AST
|
||||
/// structure has not been resolved. The element can either be a
|
||||
/// [MethodElement], if this represents the declaration of a normal method, or
|
||||
/// a [PropertyAccessorElement] if this represents the declaration of either a
|
||||
/// getter or a setter.
|
||||
@override
|
||||
ExecutableElement? get declaredElement =>
|
||||
_name.staticElement as ExecutableElement?;
|
||||
|
||||
@override
|
||||
Token get endToken => _body.endToken;
|
||||
|
||||
|
@ -7823,13 +7863,20 @@ class MethodDeclarationImpl extends ClassMemberImpl
|
|||
@override
|
||||
bool get isStatic => modifierKeyword?.keyword == Keyword.STATIC;
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get name => _name;
|
||||
SimpleIdentifierImpl get name {
|
||||
_name.staticElement = declaredElement;
|
||||
return _name;
|
||||
}
|
||||
|
||||
set name(SimpleIdentifier identifier) {
|
||||
_name = _becomeParentOf(identifier as SimpleIdentifierImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
Token get name2 => _name.token;
|
||||
|
||||
@override
|
||||
FormalParameterListImpl? get parameters => _parameters;
|
||||
|
||||
|
@ -7858,7 +7905,7 @@ class MethodDeclarationImpl extends ClassMemberImpl
|
|||
..addNode('returnType', returnType)
|
||||
..addToken('propertyKeyword', propertyKeyword)
|
||||
..addToken('operatorKeyword', operatorKeyword)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('parameters', parameters)
|
||||
..addNode('body', body);
|
||||
|
||||
|
@ -7869,7 +7916,8 @@ class MethodDeclarationImpl extends ClassMemberImpl
|
|||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_returnType?.accept(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_parameters?.accept(visitor);
|
||||
_body.accept(visitor);
|
||||
|
@ -8048,6 +8096,9 @@ class MixinDeclarationImpl extends ClassOrMixinDeclarationImpl
|
|||
/// super-class constraints.
|
||||
OnClauseImpl? _onClause;
|
||||
|
||||
@override
|
||||
ClassElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created mixin declaration. Either or both of the
|
||||
/// [comment] and [metadata] can be `null` if the mixin does not have the
|
||||
/// corresponding attribute. The [typeParameters] can be `null` if the mixin
|
||||
|
@ -8072,9 +8123,6 @@ class MixinDeclarationImpl extends ClassOrMixinDeclarationImpl
|
|||
_becomeParentOf(_onClause);
|
||||
}
|
||||
|
||||
@override
|
||||
ClassElement? get declaredElement => _name.staticElement as ClassElement?;
|
||||
|
||||
@override
|
||||
Token get firstTokenAfterCommentAndMetadata {
|
||||
return mixinKeyword;
|
||||
|
@ -8099,7 +8147,7 @@ class MixinDeclarationImpl extends ClassOrMixinDeclarationImpl
|
|||
@override
|
||||
ChildEntities get _childEntities => super._childEntities
|
||||
..addToken('mixinKeyword', mixinKeyword)
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addNode('typeParameters', typeParameters)
|
||||
..addNode('onClause', onClause)
|
||||
..addNode('implementsClause', implementsClause)
|
||||
|
@ -8113,7 +8161,8 @@ class MixinDeclarationImpl extends ClassOrMixinDeclarationImpl
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_onClause?.accept(visitor);
|
||||
_implementsClause?.accept(visitor);
|
||||
|
@ -8127,19 +8176,26 @@ abstract class NamedCompilationUnitMemberImpl extends CompilationUnitMemberImpl
|
|||
/// The name of the member being declared.
|
||||
SimpleIdentifierImpl _name;
|
||||
|
||||
/// Initialize a newly created compilation unit member with the given [name].
|
||||
/// Initialize a newly created compilation unit member with the given [name2].
|
||||
/// Either or both of the [comment] and [metadata] can be `null` if the member
|
||||
/// does not have the corresponding attribute.
|
||||
NamedCompilationUnitMemberImpl(super.comment, super.metadata, this._name) {
|
||||
_becomeParentOf(_name);
|
||||
}
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get name => _name;
|
||||
SimpleIdentifierImpl get name {
|
||||
_name.staticElement = declaredElement;
|
||||
return _name;
|
||||
}
|
||||
|
||||
set name(SimpleIdentifier identifier) {
|
||||
_name = _becomeParentOf(identifier as SimpleIdentifierImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
Token get name2 => _name.token;
|
||||
}
|
||||
|
||||
/// An expression that has a name associated with it. They are used in method
|
||||
|
@ -8603,8 +8659,12 @@ abstract class NormalFormalParameterImpl extends FormalParameterImpl
|
|||
_comment = _becomeParentOf(comment as CommentImpl?);
|
||||
}
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl? get identifier => _identifier;
|
||||
SimpleIdentifierImpl? get identifier {
|
||||
_identifier?.staticElement = declaredElement;
|
||||
return _identifier;
|
||||
}
|
||||
|
||||
set identifier(SimpleIdentifier? identifier) {
|
||||
_identifier = _becomeParentOf(identifier as SimpleIdentifierImpl?);
|
||||
|
@ -8627,6 +8687,9 @@ abstract class NormalFormalParameterImpl extends FormalParameterImpl
|
|||
_metadata.addAll(metadata);
|
||||
}
|
||||
|
||||
@override
|
||||
Token? get name => _identifier?.token;
|
||||
|
||||
@override
|
||||
List<AstNode> get sortedCommentAndAnnotations {
|
||||
var comment = _comment;
|
||||
|
@ -9821,11 +9884,11 @@ class SimpleFormalParameterImpl extends NormalFormalParameterImpl
|
|||
} else if (_type != null) {
|
||||
return _type!.beginToken;
|
||||
}
|
||||
return identifier!.beginToken;
|
||||
return name!;
|
||||
}
|
||||
|
||||
@override
|
||||
Token get endToken => identifier?.endToken ?? type!.endToken;
|
||||
Token get endToken => name ?? type!.endToken;
|
||||
|
||||
@override
|
||||
bool get isConst => keyword?.keyword == Keyword.CONST;
|
||||
|
@ -9847,7 +9910,7 @@ class SimpleFormalParameterImpl extends NormalFormalParameterImpl
|
|||
ChildEntities get _childEntities => super._childEntities
|
||||
..addToken('keyword', keyword)
|
||||
..addNode('type', type)
|
||||
..addNode('identifier', identifier);
|
||||
..addToken('name', name);
|
||||
|
||||
@override
|
||||
E? accept<E>(AstVisitor<E> visitor) =>
|
||||
|
@ -9857,6 +9920,7 @@ class SimpleFormalParameterImpl extends NormalFormalParameterImpl
|
|||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_type?.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
identifier?.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
@ -10023,11 +10087,13 @@ class SimpleIdentifierImpl extends IdentifierImpl implements SimpleIdentifier {
|
|||
}
|
||||
}
|
||||
if (parent is FieldFormalParameter) {
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
if (identical(parent.identifier, target)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (parent is VariableDeclaration) {
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
if (identical(parent.name, target)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -10652,9 +10718,10 @@ class SuperFormalParameterImpl extends NormalFormalParameterImpl
|
|||
|
||||
@override
|
||||
Token get endToken {
|
||||
return question ?? _parameters?.endToken ?? identifier.endToken;
|
||||
return question ?? _parameters?.endToken ?? name;
|
||||
}
|
||||
|
||||
@Deprecated('Use identifier2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get identifier => super.identifier!;
|
||||
|
||||
|
@ -10667,6 +10734,9 @@ class SuperFormalParameterImpl extends NormalFormalParameterImpl
|
|||
@override
|
||||
bool get isFinal => keyword?.keyword == Keyword.FINAL;
|
||||
|
||||
@override
|
||||
Token get name => super.name!;
|
||||
|
||||
@override
|
||||
FormalParameterListImpl? get parameters => _parameters;
|
||||
|
||||
|
@ -10694,7 +10764,7 @@ class SuperFormalParameterImpl extends NormalFormalParameterImpl
|
|||
..addNode('type', type)
|
||||
..addToken('superKeyword', superKeyword)
|
||||
..addToken('period', period)
|
||||
..addNode('identifier', identifier)
|
||||
..addToken('name', name)
|
||||
..addNode('typeParameters', typeParameters)
|
||||
..addNode('parameters', parameters);
|
||||
|
||||
|
@ -10706,6 +10776,7 @@ class SuperFormalParameterImpl extends NormalFormalParameterImpl
|
|||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_type?.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
identifier.accept(visitor);
|
||||
_typeParameters?.accept(visitor);
|
||||
_parameters?.accept(visitor);
|
||||
|
@ -11402,6 +11473,9 @@ class TypeParameterImpl extends DeclarationImpl implements TypeParameter {
|
|||
/// explicit upper bound.
|
||||
TypeAnnotationImpl? _bound;
|
||||
|
||||
@override
|
||||
TypeParameterElement? declaredElement;
|
||||
|
||||
/// Initialize a newly created type parameter. Either or both of the [comment]
|
||||
/// and [metadata] can be `null` if the parameter does not have the
|
||||
/// corresponding attribute. The [extendsKeyword] and [bound] can be `null` if
|
||||
|
@ -11419,10 +11493,6 @@ class TypeParameterImpl extends DeclarationImpl implements TypeParameter {
|
|||
_bound = _becomeParentOf(type as TypeAnnotationImpl?);
|
||||
}
|
||||
|
||||
@override
|
||||
TypeParameterElement? get declaredElement =>
|
||||
_name.staticElement as TypeParameterElement?;
|
||||
|
||||
@override
|
||||
Token get endToken {
|
||||
if (_bound == null) {
|
||||
|
@ -11434,6 +11504,7 @@ class TypeParameterImpl extends DeclarationImpl implements TypeParameter {
|
|||
@override
|
||||
Token get firstTokenAfterCommentAndMetadata => _name.beginToken;
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get name => _name;
|
||||
|
||||
|
@ -11441,9 +11512,12 @@ class TypeParameterImpl extends DeclarationImpl implements TypeParameter {
|
|||
_name = _becomeParentOf(identifier as SimpleIdentifierImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
Token get name2 => _name.token;
|
||||
|
||||
@override
|
||||
ChildEntities get _childEntities => super._childEntities
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addToken('extendsKeyword', extendsKeyword)
|
||||
..addNode('bound', bound);
|
||||
|
||||
|
@ -11453,7 +11527,8 @@ class TypeParameterImpl extends DeclarationImpl implements TypeParameter {
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_bound?.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
@ -11606,6 +11681,9 @@ class VariableDeclarationImpl extends DeclarationImpl
|
|||
/// The name of the variable being declared.
|
||||
SimpleIdentifierImpl _name;
|
||||
|
||||
@override
|
||||
VariableElement? declaredElement;
|
||||
|
||||
/// The equal sign separating the variable name from the initial value, or
|
||||
/// `null` if the initial value was not specified.
|
||||
@override
|
||||
|
@ -11629,10 +11707,6 @@ class VariableDeclarationImpl extends DeclarationImpl
|
|||
_becomeParentOf(_initializer);
|
||||
}
|
||||
|
||||
@override
|
||||
VariableElement? get declaredElement =>
|
||||
_name.staticElement as VariableElement?;
|
||||
|
||||
/// This overridden implementation of [documentationComment] looks in the
|
||||
/// grandparent node for Dartdoc comments if no documentation is specifically
|
||||
/// available on the node.
|
||||
|
@ -11684,16 +11758,23 @@ class VariableDeclarationImpl extends DeclarationImpl
|
|||
return parent is VariableDeclarationList && parent.isLate;
|
||||
}
|
||||
|
||||
@Deprecated('Use name2 instead')
|
||||
@override
|
||||
SimpleIdentifierImpl get name => _name;
|
||||
SimpleIdentifierImpl get name {
|
||||
_name.staticElement = declaredElement;
|
||||
return _name;
|
||||
}
|
||||
|
||||
set name(SimpleIdentifier identifier) {
|
||||
_name = _becomeParentOf(identifier as SimpleIdentifierImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
Token get name2 => _name.token;
|
||||
|
||||
@override
|
||||
ChildEntities get _childEntities => super._childEntities
|
||||
..addNode('name', name)
|
||||
..addToken('name', name2)
|
||||
..addToken('equals', equals)
|
||||
..addNode('initializer', initializer);
|
||||
|
||||
|
@ -11703,7 +11784,8 @@ class VariableDeclarationImpl extends DeclarationImpl
|
|||
@override
|
||||
void visitChildren(AstVisitor visitor) {
|
||||
super.visitChildren(visitor);
|
||||
_name.accept(visitor);
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
name.accept(visitor);
|
||||
_initializer?.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,11 +68,26 @@ class _ElementMapper extends GeneralizingAstVisitor<Element> {
|
|||
return node.element2;
|
||||
}
|
||||
|
||||
@override
|
||||
Element? visitFormalParameter(FormalParameter node) {
|
||||
return node.declaredElement;
|
||||
}
|
||||
|
||||
@override
|
||||
Element? visitFunctionDeclaration(FunctionDeclaration node) {
|
||||
return node.declaredElement;
|
||||
}
|
||||
|
||||
@override
|
||||
Element? visitFunctionTypeAlias(FunctionTypeAlias node) {
|
||||
return node.declaredElement;
|
||||
}
|
||||
|
||||
@override
|
||||
Element? visitGenericTypeAlias(GenericTypeAlias node) {
|
||||
return node.declaredElement;
|
||||
}
|
||||
|
||||
@override
|
||||
Element? visitIdentifier(Identifier node) {
|
||||
var parent = node.parent;
|
||||
|
@ -86,14 +101,16 @@ class _ElementMapper extends GeneralizingAstVisitor<Element> {
|
|||
// Constructor Elements
|
||||
var returnType = parent.returnType;
|
||||
if (identical(returnType, node)) {
|
||||
var name = parent.name;
|
||||
var name = parent.name2;
|
||||
if (name != null) {
|
||||
return name.staticElement;
|
||||
return parent.declaredElement;
|
||||
}
|
||||
var element = node.staticElement;
|
||||
if (element is ClassElement) {
|
||||
return element.unnamedConstructor;
|
||||
}
|
||||
} else if (parent.name2 == node.endToken) {
|
||||
return parent.declaredElement;
|
||||
}
|
||||
} else if (parent is LibraryIdentifier) {
|
||||
var grandParent = parent.parent;
|
||||
|
@ -175,6 +192,11 @@ class _ElementMapper extends GeneralizingAstVisitor<Element> {
|
|||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Element? visitTypeParameter(TypeParameter node) {
|
||||
return node.declaredElement;
|
||||
}
|
||||
|
||||
@override
|
||||
Element? visitVariableDeclaration(VariableDeclaration node) {
|
||||
return node.declaredElement;
|
||||
|
|
|
@ -72,7 +72,7 @@ enum _Usage { writing, reading }
|
|||
extension MethodDeclarationExtension on MethodDeclaration {
|
||||
bool get invokesSuperSelf {
|
||||
var visitor = _SuperVisitor(
|
||||
name.name,
|
||||
name2.lexeme,
|
||||
isSetter ? _Usage.writing : _Usage.reading,
|
||||
);
|
||||
body.accept(visitor);
|
||||
|
|
|
@ -167,7 +167,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitToken(node.macroKeyword, suffix: ' ');
|
||||
_visitToken(node.augmentKeyword, suffix: ' ');
|
||||
sink.write('class ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.typeParameters);
|
||||
_visitNode(node.extendsClause, prefix: ' ');
|
||||
_visitNode(node.withClause, prefix: ' ');
|
||||
|
@ -186,7 +186,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitToken(node.macroKeyword, suffix: ' ');
|
||||
_visitToken(node.augmentKeyword, suffix: ' ');
|
||||
sink.write('class ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.typeParameters);
|
||||
sink.write(' = ');
|
||||
_visitNode(node.superclass);
|
||||
|
@ -237,7 +237,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitToken(node.constKeyword, suffix: ' ');
|
||||
_visitToken(node.factoryKeyword, suffix: ' ');
|
||||
_visitNode(node.returnType);
|
||||
_visitNode(node.name, prefix: '.');
|
||||
_visitToken(node.name2, prefix: '.');
|
||||
_visitNode(node.parameters);
|
||||
_visitNodeList(node.initializers, prefix: ' : ', separator: ', ');
|
||||
_visitNode(node.redirectedConstructor, prefix: ' = ');
|
||||
|
@ -281,7 +281,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
|
||||
_visitToken(node.keyword, suffix: ' ');
|
||||
_visitNode(node.type, suffix: ' ');
|
||||
_visitNode(node.identifier);
|
||||
_visitToken(node.name);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -336,7 +336,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
@override
|
||||
void visitEnumConstantDeclaration(EnumConstantDeclaration node) {
|
||||
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.arguments);
|
||||
}
|
||||
|
||||
|
@ -344,7 +344,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
void visitEnumDeclaration(EnumDeclaration node) {
|
||||
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
|
||||
sink.write('enum ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.typeParameters);
|
||||
_visitNode(node.withClause, prefix: ' ');
|
||||
_visitNode(node.implementsClause, prefix: ' ');
|
||||
|
@ -399,7 +399,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
|
||||
_visitToken(node.extensionKeyword, suffix: ' ');
|
||||
_visitToken(node.typeKeyword, suffix: ' ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.typeParameters);
|
||||
sink.write(' ');
|
||||
_visitToken(node.onKeyword);
|
||||
|
@ -437,7 +437,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitToken(node.keyword, suffix: ' ');
|
||||
_visitNode(node.type, suffix: ' ');
|
||||
sink.write('this.');
|
||||
_visitNode(node.identifier);
|
||||
_visitToken(node.name);
|
||||
_visitNode(node.typeParameters);
|
||||
_visitNode(node.parameters);
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitToken(node.externalKeyword, suffix: ' ');
|
||||
_visitNode(node.returnType, suffix: ' ');
|
||||
_visitToken(node.propertyKeyword, suffix: ' ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.functionExpression);
|
||||
}
|
||||
|
||||
|
@ -562,7 +562,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
|
||||
sink.write('typedef ');
|
||||
_visitNode(node.returnType, suffix: ' ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.typeParameters);
|
||||
_visitNode(node.parameters);
|
||||
sink.write(';');
|
||||
|
@ -574,7 +574,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitToken(node.requiredKeyword, suffix: ' ');
|
||||
_visitToken(node.covariantKeyword, suffix: ' ');
|
||||
_visitNode(node.returnType, suffix: ' ');
|
||||
_visitNode(node.identifier);
|
||||
_visitToken(node.name);
|
||||
_visitNode(node.typeParameters);
|
||||
_visitNode(node.parameters);
|
||||
if (node.question != null) {
|
||||
|
@ -597,7 +597,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
void visitGenericTypeAlias(GenericTypeAlias node) {
|
||||
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
|
||||
sink.write('typedef ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.typeParameters);
|
||||
sink.write(' = ');
|
||||
_visitNode(node.type);
|
||||
|
@ -771,7 +771,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitNode(node.returnType, suffix: ' ');
|
||||
_visitToken(node.propertyKeyword, suffix: ' ');
|
||||
_visitToken(node.operatorKeyword, suffix: ' ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
if (!node.isGetter) {
|
||||
_visitNode(node.typeParameters);
|
||||
_visitNode(node.parameters);
|
||||
|
@ -792,7 +792,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
void visitMixinDeclaration(MixinDeclaration node) {
|
||||
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
|
||||
sink.write('mixin ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.typeParameters);
|
||||
_visitNode(node.onClause, prefix: ' ');
|
||||
_visitNode(node.implementsClause, prefix: ' ');
|
||||
|
@ -958,10 +958,10 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitToken(node.covariantKeyword, suffix: ' ');
|
||||
_visitToken(node.keyword, suffix: ' ');
|
||||
_visitNode(node.type);
|
||||
if (node.type != null && node.identifier != null) {
|
||||
if (node.type != null && node.name != null) {
|
||||
sink.write(' ');
|
||||
}
|
||||
_visitNode(node.identifier);
|
||||
_visitToken(node.name);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1005,7 +1005,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
_visitToken(node.keyword, suffix: ' ');
|
||||
_visitNode(node.type, suffix: ' ');
|
||||
sink.write('super.');
|
||||
_visitNode(node.identifier);
|
||||
_visitToken(node.name);
|
||||
_visitNode(node.typeParameters);
|
||||
_visitNode(node.parameters);
|
||||
}
|
||||
|
@ -1093,7 +1093,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
if (varianceKeyword != null) {
|
||||
sink.write('${varianceKeyword.lexeme} ');
|
||||
}
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.bound, prefix: ' extends ');
|
||||
}
|
||||
|
||||
|
@ -1107,7 +1107,7 @@ class ToSourceVisitor implements AstVisitor<void> {
|
|||
@override
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
|
||||
_visitNode(node.name);
|
||||
_visitToken(node.name2);
|
||||
_visitNode(node.initializer, prefix: ' = ');
|
||||
}
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.abstractKeyword, other.abstractKeyword) &&
|
||||
isEqualTokens(node.classKeyword, other.classKeyword) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.typeParameters, other.typeParameters) &&
|
||||
isEqualNodes(node.extendsClause, other.extendsClause) &&
|
||||
isEqualNodes(node.withClause, other.withClause) &&
|
||||
|
@ -266,7 +266,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.typeParameters, other.typeParameters) &&
|
||||
isEqualTokens(node.equals, other.equals) &&
|
||||
isEqualTokens(node.abstractKeyword, other.abstractKeyword) &&
|
||||
|
@ -332,7 +332,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
isEqualTokens(node.factoryKeyword, other.factoryKeyword) &&
|
||||
isEqualNodes(node.returnType, other.returnType) &&
|
||||
isEqualTokens(node.period, other.period) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.parameters, other.parameters) &&
|
||||
isEqualTokens(node.separator, other.separator) &&
|
||||
_isEqualNodeLists(node.initializers, other.initializers) &&
|
||||
|
@ -387,7 +387,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.keyword, other.keyword) &&
|
||||
isEqualNodes(node.type, other.type) &&
|
||||
isEqualNodes(node.identifier, other.identifier);
|
||||
isEqualTokens(node.name, other.name);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -450,7 +450,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
return isEqualNodes(
|
||||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualNodes(node.name, other.name);
|
||||
isEqualTokens(node.name2, other.name2);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -460,7 +460,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.enumKeyword, other.enumKeyword) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualTokens(node.leftBracket, other.leftBracket) &&
|
||||
_isEqualNodeLists(node.constants, other.constants) &&
|
||||
isEqualTokens(node.rightBracket, other.rightBracket);
|
||||
|
@ -507,7 +507,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.extensionKeyword, other.extensionKeyword) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.typeParameters, other.typeParameters) &&
|
||||
isEqualTokens(node.onKeyword, other.onKeyword) &&
|
||||
isEqualNodes(node.extendedType, other.extendedType) &&
|
||||
|
@ -547,7 +547,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
isEqualNodes(node.type, other.type) &&
|
||||
isEqualTokens(node.thisKeyword, other.thisKeyword) &&
|
||||
isEqualTokens(node.period, other.period) &&
|
||||
isEqualNodes(node.identifier, other.identifier);
|
||||
isEqualTokens(node.name, other.name);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -627,7 +627,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
isEqualTokens(node.externalKeyword, other.externalKeyword) &&
|
||||
isEqualNodes(node.returnType, other.returnType) &&
|
||||
isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.functionExpression, other.functionExpression);
|
||||
}
|
||||
|
||||
|
@ -666,7 +666,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
|
||||
isEqualNodes(node.returnType, other.returnType) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.typeParameters, other.typeParameters) &&
|
||||
isEqualNodes(node.parameters, other.parameters) &&
|
||||
isEqualTokens(node.semicolon, other.semicolon);
|
||||
|
@ -679,7 +679,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualNodes(node.returnType, other.returnType) &&
|
||||
isEqualNodes(node.identifier, other.identifier) &&
|
||||
isEqualTokens(node.name, other.name) &&
|
||||
isEqualNodes(node.parameters, other.parameters);
|
||||
}
|
||||
|
||||
|
@ -700,7 +700,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.typedefKeyword, other.typedefKeyword) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.typeParameters, other.typeParameters) &&
|
||||
isEqualTokens(node.equals, other.equals) &&
|
||||
isEqualNodes(node.type, other.type);
|
||||
|
@ -894,7 +894,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
isEqualNodes(node.returnType, other.returnType) &&
|
||||
isEqualTokens(node.propertyKeyword, other.propertyKeyword) &&
|
||||
isEqualTokens(node.operatorKeyword, other.operatorKeyword) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.parameters, other.parameters) &&
|
||||
isEqualNodes(node.body, other.body);
|
||||
}
|
||||
|
@ -915,7 +915,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.mixinKeyword, other.mixinKeyword) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualNodes(node.typeParameters, other.typeParameters) &&
|
||||
isEqualNodes(node.onClause, other.onClause) &&
|
||||
isEqualNodes(node.implementsClause, other.implementsClause) &&
|
||||
|
@ -1099,7 +1099,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualTokens(node.keyword, other.keyword) &&
|
||||
isEqualNodes(node.type, other.type) &&
|
||||
isEqualNodes(node.identifier, other.identifier);
|
||||
isEqualTokens(node.name, other.name);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1153,7 +1153,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
isEqualNodes(node.type, other.type) &&
|
||||
isEqualTokens(node.superKeyword, other.superKeyword) &&
|
||||
isEqualTokens(node.period, other.period) &&
|
||||
isEqualNodes(node.identifier, other.identifier);
|
||||
isEqualTokens(node.name, other.name);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1250,7 +1250,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
return isEqualNodes(
|
||||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualTokens((node as TypeParameterImpl).varianceKeyword,
|
||||
(other as TypeParameterImpl).varianceKeyword) &&
|
||||
isEqualTokens(node.extendsKeyword, other.extendsKeyword) &&
|
||||
|
@ -1271,7 +1271,7 @@ class AstComparator implements AstVisitor<bool> {
|
|||
return isEqualNodes(
|
||||
node.documentationComment, other.documentationComment) &&
|
||||
_isEqualNodeLists(node.metadata, other.metadata) &&
|
||||
isEqualNodes(node.name, other.name) &&
|
||||
isEqualTokens(node.name2, other.name2) &&
|
||||
isEqualTokens(node.equals, other.equals) &&
|
||||
isEqualNodes(node.initializer, other.initializer);
|
||||
}
|
||||
|
@ -1805,10 +1805,7 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
|
||||
@override
|
||||
bool visitClassDeclaration(covariant ClassDeclarationImpl node) {
|
||||
if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.typeParameters, _oldNode)) {
|
||||
if (identical(node.typeParameters, _oldNode)) {
|
||||
node.typeParameters = _newNode as TypeParameterList;
|
||||
return true;
|
||||
} else if (identical(node.extendsClause, _oldNode)) {
|
||||
|
@ -1831,10 +1828,7 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
|
||||
@override
|
||||
bool visitClassTypeAlias(covariant ClassTypeAliasImpl node) {
|
||||
if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.typeParameters, _oldNode)) {
|
||||
if (identical(node.typeParameters, _oldNode)) {
|
||||
node.typeParameters = _newNode as TypeParameterList;
|
||||
return true;
|
||||
} else if (identical(node.superclass, _oldNode)) {
|
||||
|
@ -1915,9 +1909,6 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
if (identical(node.returnType, _oldNode)) {
|
||||
node.returnType = _newNode as Identifier;
|
||||
return true;
|
||||
} else if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.parameters, _oldNode)) {
|
||||
node.parameters = _newNode as FormalParameterList;
|
||||
return true;
|
||||
|
@ -1986,9 +1977,6 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
if (identical(node.type, _oldNode)) {
|
||||
node.type = _newNode as TypeAnnotation;
|
||||
return true;
|
||||
} else if (identical(node.identifier, _oldNode)) {
|
||||
node.identifier = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
}
|
||||
return visitAnnotatedNode(node);
|
||||
}
|
||||
|
@ -2048,19 +2036,12 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
@override
|
||||
bool visitEnumConstantDeclaration(
|
||||
covariant EnumConstantDeclarationImpl node) {
|
||||
if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
}
|
||||
return visitAnnotatedNode(node);
|
||||
}
|
||||
|
||||
@override
|
||||
bool visitEnumDeclaration(covariant EnumDeclarationImpl node) {
|
||||
if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.typeParameters, _oldNode)) {
|
||||
if (identical(node.typeParameters, _oldNode)) {
|
||||
node.typeParameters = _newNode as TypeParameterList;
|
||||
return true;
|
||||
} else if (identical(node.withClause, _oldNode)) {
|
||||
|
@ -2115,9 +2096,6 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
return true;
|
||||
} else if (_replaceInList(node.metadata)) {
|
||||
return true;
|
||||
} else if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.typeParameters, _oldNode)) {
|
||||
node.typeParameters = _newNode as TypeParameterList;
|
||||
return true;
|
||||
|
@ -2264,9 +2242,6 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
if (identical(node.returnType, _oldNode)) {
|
||||
node.returnType = _newNode as TypeAnnotation;
|
||||
return true;
|
||||
} else if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.functionExpression, _oldNode)) {
|
||||
node.functionExpression = _newNode as FunctionExpression;
|
||||
return true;
|
||||
|
@ -2332,9 +2307,6 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
if (identical(node.returnType, _oldNode)) {
|
||||
node.returnType = _newNode as TypeAnnotation;
|
||||
return true;
|
||||
} else if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.typeParameters, _oldNode)) {
|
||||
node.typeParameters = _newNode as TypeParameterList;
|
||||
return true;
|
||||
|
@ -2379,10 +2351,7 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
@override
|
||||
bool visitGenericTypeAlias(GenericTypeAlias node) {
|
||||
var nodeImpl = node as GenericTypeAliasImpl;
|
||||
if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.typeParameters, _oldNode)) {
|
||||
if (identical(node.typeParameters, _oldNode)) {
|
||||
nodeImpl.typeParameters = _newNode as TypeParameterList;
|
||||
return true;
|
||||
} else if (identical(node.type, _oldNode)) {
|
||||
|
@ -2591,9 +2560,6 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
if (identical(node.returnType, _oldNode)) {
|
||||
node.returnType = _newNode as TypeAnnotation;
|
||||
return true;
|
||||
} else if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.parameters, _oldNode)) {
|
||||
node.parameters = _newNode as FormalParameterList;
|
||||
return true;
|
||||
|
@ -2632,9 +2598,6 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
return true;
|
||||
} else if (_replaceInList(node.metadata)) {
|
||||
return true;
|
||||
} else if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.typeParameters, _oldNode)) {
|
||||
node.typeParameters = _newNode as TypeParameterList;
|
||||
return true;
|
||||
|
@ -2707,9 +2670,6 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
if (identical(node.documentationComment, _oldNode)) {
|
||||
node.documentationComment = _newNode as Comment;
|
||||
return true;
|
||||
} else if (identical(node.identifier, _oldNode)) {
|
||||
node.identifier = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (_replaceInList(node.metadata)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -3016,10 +2976,7 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
|
||||
@override
|
||||
bool visitTypeParameter(covariant TypeParameterImpl node) {
|
||||
if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.bound, _oldNode)) {
|
||||
if (identical(node.bound, _oldNode)) {
|
||||
node.bound = _newNode as TypeAnnotation;
|
||||
return true;
|
||||
}
|
||||
|
@ -3044,10 +3001,7 @@ class NodeReplacer implements AstVisitor<bool> {
|
|||
|
||||
@override
|
||||
bool visitVariableDeclaration(covariant VariableDeclarationImpl node) {
|
||||
if (identical(node.name, _oldNode)) {
|
||||
node.name = _newNode as SimpleIdentifier;
|
||||
return true;
|
||||
} else if (identical(node.initializer, _oldNode)) {
|
||||
if (identical(node.initializer, _oldNode)) {
|
||||
node.initializer = _newNode as Expression;
|
||||
return true;
|
||||
// TODO(srawlins) also replace node's declared element's
|
||||
|
@ -3173,8 +3127,8 @@ class ScopedNameFinder extends GeneralizingAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitCatchClause(CatchClause node) {
|
||||
_addToScope2(node.exceptionParameter2?.name);
|
||||
_addToScope2(node.stackTraceParameter2?.name);
|
||||
_addToScope(node.exceptionParameter2?.name);
|
||||
_addToScope(node.stackTraceParameter2?.name);
|
||||
super.visitCatchClause(node);
|
||||
}
|
||||
|
||||
|
@ -3193,7 +3147,7 @@ class ScopedNameFinder extends GeneralizingAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitForEachPartsWithDeclaration(ForEachPartsWithDeclaration node) {
|
||||
_addToScope(node.loopVariable.identifier);
|
||||
_addToScope(node.loopVariable.name);
|
||||
super.visitForEachPartsWithDeclaration(node);
|
||||
}
|
||||
|
||||
|
@ -3260,28 +3214,19 @@ class ScopedNameFinder extends GeneralizingAstVisitor<void> {
|
|||
|
||||
void _addParameters(NodeList<FormalParameter> vars) {
|
||||
for (FormalParameter var2 in vars) {
|
||||
_addToScope(var2.identifier);
|
||||
_addToScope(var2.name);
|
||||
}
|
||||
}
|
||||
|
||||
void _addToScope(SimpleIdentifier? identifier) {
|
||||
void _addToScope(Token? identifier) {
|
||||
if (identifier != null && _isInRange(identifier)) {
|
||||
_locals.add(identifier.name);
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO(scheglov) If we still have [_addToScope] after:
|
||||
/// https://dart-review.googlesource.com/c/sdk/+/252566,
|
||||
/// rename to `_addNodeToScope` and `_addTokenToScope`.
|
||||
void _addToScope2(Token? identifier) {
|
||||
if (identifier != null && _isInRange2(identifier)) {
|
||||
_locals.add(identifier.lexeme);
|
||||
}
|
||||
}
|
||||
|
||||
void _addVariables(NodeList<VariableDeclaration> variables) {
|
||||
for (VariableDeclaration variable in variables) {
|
||||
_addToScope(variable.name);
|
||||
_addToScope(variable.name2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3297,21 +3242,12 @@ class ScopedNameFinder extends GeneralizingAstVisitor<void> {
|
|||
_addVariables(statement.variables.variables);
|
||||
} else if (statement is FunctionDeclarationStatement &&
|
||||
!_referenceIsWithinLocalFunction) {
|
||||
_addToScope(statement.functionDeclaration.name);
|
||||
_addToScope(statement.functionDeclaration.name2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool _isInRange(AstNode node) {
|
||||
if (_position < 0) {
|
||||
// if source position is not set then all nodes are in range
|
||||
return true;
|
||||
// not reached
|
||||
}
|
||||
return node.end < _position;
|
||||
}
|
||||
|
||||
bool _isInRange2(Token token) {
|
||||
bool _isInRange(Token token) {
|
||||
if (_position < 0) {
|
||||
// if source position is not set then all nodes are in range
|
||||
return true;
|
||||
|
|
|
@ -576,7 +576,8 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
|
|||
if (member is FieldDeclaration && !member.isStatic) {
|
||||
for (VariableDeclaration variableDeclaration
|
||||
in member.fields.variables) {
|
||||
if (isEnumDeclaration && variableDeclaration.name.name == 'values') {
|
||||
if (isEnumDeclaration &&
|
||||
variableDeclaration.name2.lexeme == 'values') {
|
||||
continue;
|
||||
}
|
||||
var initializer = variableDeclaration.initializer;
|
||||
|
@ -597,7 +598,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
|
|||
CompileTimeErrorCode
|
||||
.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST,
|
||||
constKeyword,
|
||||
[variableDeclaration.name.name]);
|
||||
[variableDeclaration.name2.lexeme]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/element_locator.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:collection/src/iterable_extensions.dart';
|
||||
|
@ -15,6 +16,9 @@ Element? getElementOfNode(AstNode? node) {
|
|||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
if (node is DeclaredSimpleIdentifier) {
|
||||
node = node.parent;
|
||||
}
|
||||
if (node is SimpleIdentifier && node.parent is LibraryIdentifier) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
@ -280,7 +284,7 @@ class ReferencesCollector extends GeneralizingAstVisitor<void> {
|
|||
MatchInfo(e.nameOffset + e.nameLength, 0, MatchKind.DECLARATION));
|
||||
} else {
|
||||
var offset = node.period!.offset;
|
||||
var length = node.name!.end - offset;
|
||||
var length = node.name2!.end - offset;
|
||||
references.add(MatchInfo(offset, length, MatchKind.DECLARATION));
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +333,7 @@ class ReferencesCollector extends GeneralizingAstVisitor<void> {
|
|||
offset = constructorSelector.period.offset;
|
||||
length = constructorSelector.name.end - offset;
|
||||
} else {
|
||||
offset = node.name.end;
|
||||
offset = node.name2.end;
|
||||
length = 0;
|
||||
}
|
||||
var kind = node.arguments == null
|
||||
|
|
|
@ -26,7 +26,7 @@ Set<Object> _computeExplicitlyTypedParameterSet(
|
|||
int unnamedParameterIndex = 0;
|
||||
for (var formalParameter in parameters) {
|
||||
var key = formalParameter.isNamed
|
||||
? formalParameter.identifier?.name ?? ''
|
||||
? formalParameter.name?.lexeme ?? ''
|
||||
: unnamedParameterIndex++;
|
||||
if (formalParameter.isExplicitlyTyped) {
|
||||
result.add(key);
|
||||
|
|
|
@ -135,7 +135,7 @@ class PrefixedIdentifierResolver {
|
|||
return false;
|
||||
}
|
||||
if (parent is ConstructorDeclaration) {
|
||||
if (parent.name == node || parent.returnType == node) {
|
||||
if (parent.returnType == node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitClassDeclaration(covariant ClassDeclarationImpl node) {
|
||||
ClassElementImpl element = _elementWalker!.getClass();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
_namedTypeResolver.enclosingClass = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
@ -275,7 +275,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitClassTypeAlias(covariant ClassTypeAliasImpl node) {
|
||||
ClassElementImpl element = _elementWalker!.getClass();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
_namedTypeResolver.enclosingClass = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
@ -303,7 +303,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
void visitConstructorDeclaration(ConstructorDeclaration node) {
|
||||
ConstructorElementImpl element = _elementWalker!.getConstructor();
|
||||
(node as ConstructorDeclarationImpl).declaredElement = element;
|
||||
node.name?.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
||||
|
@ -330,10 +330,10 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitDeclaredIdentifier(covariant DeclaredIdentifierImpl node) {
|
||||
var nameNode = node.identifier;
|
||||
var element = LocalVariableElementImpl(nameNode.name, nameNode.offset);
|
||||
var nameToken = node.name;
|
||||
var element = LocalVariableElementImpl(nameToken.lexeme, nameToken.offset);
|
||||
_elementHolder.enclose(element);
|
||||
nameNode.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
||||
|
@ -354,14 +354,14 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitDefaultFormalParameter(covariant DefaultFormalParameterImpl node) {
|
||||
var normalParameter = node.parameter;
|
||||
var nameNode = normalParameter.identifier;
|
||||
var nameToken = normalParameter.name;
|
||||
|
||||
ParameterElementImpl element;
|
||||
if (_elementWalker != null) {
|
||||
element = _elementWalker!.getParameter();
|
||||
} else {
|
||||
var name = nameNode?.name ?? '';
|
||||
var nameOffset = nameNode?.offset ?? -1;
|
||||
var name = nameToken?.lexeme ?? '';
|
||||
var nameOffset = nameToken?.offset ?? -1;
|
||||
if (node.parameter is FieldFormalParameter) {
|
||||
// Only for recovery, this should not happen in valid code.
|
||||
element = DefaultFieldFormalParameterElementImpl(
|
||||
|
@ -389,10 +389,8 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
}
|
||||
|
||||
if (normalParameter is SimpleFormalParameterImpl) {
|
||||
normalParameter.declaredElement = element;
|
||||
}
|
||||
nameNode?.staticElement = element;
|
||||
normalParameter.declaredElement = element;
|
||||
node.declaredElement = element;
|
||||
|
||||
normalParameter.accept(this);
|
||||
|
||||
|
@ -409,8 +407,8 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitEnumConstantDeclaration(
|
||||
covariant EnumConstantDeclarationImpl node) {
|
||||
var element = _elementWalker!.getVariable();
|
||||
node.name.staticElement = element;
|
||||
var element = _elementWalker!.getVariable() as ConstFieldElementImpl;
|
||||
node.declaredElement = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
||||
|
@ -427,7 +425,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitEnumDeclaration(covariant EnumDeclarationImpl node) {
|
||||
EnumElementImpl element = _elementWalker!.getEnum();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
_namedTypeResolver.enclosingClass = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
@ -466,7 +464,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
void visitExtensionDeclaration(ExtensionDeclaration node) {
|
||||
var element = _elementWalker!.getExtension();
|
||||
(node as ExtensionDeclarationImpl).declaredElement = element;
|
||||
node.name?.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
||||
|
@ -489,15 +487,15 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
if (node.parent is DefaultFormalParameter) {
|
||||
element = node.declaredElement as FieldFormalParameterElementImpl;
|
||||
} else {
|
||||
var nameNode = node.identifier;
|
||||
var nameToken = node.name;
|
||||
if (_elementWalker != null) {
|
||||
element =
|
||||
_elementWalker!.getParameter() as FieldFormalParameterElementImpl;
|
||||
} else {
|
||||
// Only for recovery, this should not happen in valid code.
|
||||
element = FieldFormalParameterElementImpl(
|
||||
name: nameNode.name,
|
||||
nameOffset: nameNode.offset,
|
||||
name: nameToken.lexeme,
|
||||
nameOffset: nameToken.offset,
|
||||
parameterKind: node.kind,
|
||||
);
|
||||
_elementHolder.enclose(element);
|
||||
|
@ -506,7 +504,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
element.isFinal = node.isFinal;
|
||||
_setCodeRange(element, node);
|
||||
}
|
||||
nameNode.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
}
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
@ -548,7 +546,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
element = node.isGetter || node.isSetter
|
||||
? _elementWalker!.getAccessor()
|
||||
: _elementWalker!.getFunction();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
} else {
|
||||
element = node.declaredElement as ExecutableElementImpl;
|
||||
|
||||
|
@ -648,7 +646,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitFunctionTypeAlias(covariant FunctionTypeAliasImpl node) {
|
||||
var element = _elementWalker!.getTypedef();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
||||
|
@ -670,13 +668,13 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
if (node.parent is DefaultFormalParameter) {
|
||||
element = node.declaredElement as ParameterElementImpl;
|
||||
} else {
|
||||
var nameNode = node.identifier;
|
||||
var nameToken = node.name;
|
||||
if (_elementWalker != null) {
|
||||
element = _elementWalker!.getParameter();
|
||||
} else {
|
||||
element = ParameterElementImpl(
|
||||
name: nameNode.name,
|
||||
nameOffset: nameNode.offset,
|
||||
name: nameToken.lexeme,
|
||||
nameOffset: nameToken.offset,
|
||||
parameterKind: node.kind,
|
||||
);
|
||||
_elementHolder.addParameter(element);
|
||||
|
@ -685,7 +683,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
element.isFinal = node.isFinal;
|
||||
_setCodeRange(element, node);
|
||||
}
|
||||
nameNode.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
}
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
@ -762,7 +760,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitGenericTypeAlias(covariant GenericTypeAliasImpl node) {
|
||||
var element = _elementWalker!.getTypedef();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
||||
|
@ -864,7 +862,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
ExecutableElementImpl element = node.isGetter || node.isSetter
|
||||
? _elementWalker!.getAccessor()
|
||||
: _elementWalker!.getFunction();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
||||
|
@ -899,7 +897,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitMixinDeclaration(covariant MixinDeclarationImpl node) {
|
||||
var element = _elementWalker!.getMixin();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
||||
|
@ -975,14 +973,14 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
if (node.parent is DefaultFormalParameter) {
|
||||
element = node.declaredElement as ParameterElementImpl;
|
||||
} else {
|
||||
var nameNode = node.identifier;
|
||||
var nameToken = node.name;
|
||||
if (_elementWalker != null) {
|
||||
element = _elementWalker!.getParameter();
|
||||
} else {
|
||||
if (nameNode != null) {
|
||||
if (nameToken != null) {
|
||||
element = ParameterElementImpl(
|
||||
name: nameNode.name,
|
||||
nameOffset: nameNode.offset,
|
||||
name: nameToken.lexeme,
|
||||
nameOffset: nameToken.offset,
|
||||
parameterKind: node.kind,
|
||||
);
|
||||
} else {
|
||||
|
@ -1003,7 +1001,6 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
node.declaredElement = element;
|
||||
}
|
||||
nameNode?.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
}
|
||||
|
||||
|
@ -1021,15 +1018,15 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
if (node.parent is DefaultFormalParameter) {
|
||||
element = node.declaredElement as SuperFormalParameterElementImpl;
|
||||
} else {
|
||||
var nameNode = node.identifier;
|
||||
var nameToken = node.name;
|
||||
if (_elementWalker != null) {
|
||||
element =
|
||||
_elementWalker!.getParameter() as SuperFormalParameterElementImpl;
|
||||
} else {
|
||||
// Only for recovery, this should not happen in valid code.
|
||||
element = SuperFormalParameterElementImpl(
|
||||
name: nameNode.name,
|
||||
nameOffset: nameNode.offset,
|
||||
name: nameToken.lexeme,
|
||||
nameOffset: nameToken.offset,
|
||||
parameterKind: node.kind,
|
||||
);
|
||||
_elementHolder.enclose(element);
|
||||
|
@ -1038,7 +1035,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
element.isFinal = node.isFinal;
|
||||
_setCodeRange(element, node);
|
||||
}
|
||||
nameNode.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
}
|
||||
|
||||
_setOrCreateMetadataElements(element, node.metadata);
|
||||
|
@ -1112,7 +1109,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
VariableElementImpl element;
|
||||
if (_elementWalker != null) {
|
||||
element = _elementWalker!.getVariable();
|
||||
node.name.staticElement = element;
|
||||
node.declaredElement = element;
|
||||
} else {
|
||||
var localElement = node.declaredElement as LocalVariableElementImpl;
|
||||
element = localElement;
|
||||
|
@ -1196,9 +1193,9 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
void _buildLocalFunctionElement(
|
||||
covariant FunctionDeclarationStatementImpl statement) {
|
||||
var node = statement.functionDeclaration;
|
||||
var nameNode = node.name;
|
||||
var element = FunctionElementImpl(nameNode.name, nameNode.offset);
|
||||
nameNode.staticElement = element;
|
||||
var nameToken = node.name2;
|
||||
var element = FunctionElementImpl(nameToken.lexeme, nameToken.offset);
|
||||
node.declaredElement = element;
|
||||
_define(element);
|
||||
_elementHolder.enclose(element);
|
||||
}
|
||||
|
@ -1209,21 +1206,21 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
var isLate = variableList.isLate;
|
||||
for (var variable in variableList.variables) {
|
||||
variable as VariableDeclarationImpl;
|
||||
var variableName = variable.name;
|
||||
var nameToken = variable.name2;
|
||||
|
||||
LocalVariableElementImpl element;
|
||||
if (isConst && variable.initializer != null) {
|
||||
element = ConstLocalVariableElementImpl(
|
||||
variableName.name,
|
||||
variableName.offset,
|
||||
nameToken.lexeme,
|
||||
nameToken.offset,
|
||||
);
|
||||
} else {
|
||||
element = LocalVariableElementImpl(
|
||||
variableName.name,
|
||||
variableName.offset,
|
||||
nameToken.lexeme,
|
||||
nameToken.offset,
|
||||
);
|
||||
}
|
||||
variableName.staticElement = element;
|
||||
variable.declaredElement = element;
|
||||
_elementHolder.enclose(element);
|
||||
_define(element);
|
||||
|
||||
|
@ -1241,18 +1238,20 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
|
||||
for (var typeParameter in typeParameterList.typeParameters) {
|
||||
typeParameter as TypeParameterImpl;
|
||||
var name = typeParameter.name;
|
||||
var name = typeParameter.name2;
|
||||
|
||||
TypeParameterElementImpl element;
|
||||
if (_elementWalker != null) {
|
||||
element = _elementWalker!.getTypeParameter();
|
||||
} else {
|
||||
element = TypeParameterElementImpl(name.name, name.offset);
|
||||
element = TypeParameterElementImpl(name.lexeme, name.offset);
|
||||
_elementHolder.addTypeParameter(element);
|
||||
|
||||
_setCodeRange(element, typeParameter);
|
||||
}
|
||||
name.staticElement = element;
|
||||
typeParameter.declaredElement = element;
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
typeParameter.name.staticElement = element;
|
||||
_define(element);
|
||||
_setOrCreateMetadataElements(element, typeParameter.metadata);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ class SimpleIdentifierResolver with ScopeHelpers {
|
|||
return false;
|
||||
}
|
||||
if (parent is ConstructorDeclaration) {
|
||||
if (parent.name == node || parent.returnType == node) {
|
||||
if (parent.returnType == node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class VariableDeclarationResolver {
|
|||
_resolver.errorReporter.reportErrorForNode(
|
||||
HintCode.INFERENCE_FAILURE_ON_UNINITIALIZED_VARIABLE,
|
||||
node,
|
||||
[node.name.name],
|
||||
[node.name2.lexeme],
|
||||
);
|
||||
}
|
||||
return;
|
||||
|
@ -70,8 +70,13 @@ class VariableDeclarationResolver {
|
|||
element.constantInitializer = initializer;
|
||||
}
|
||||
|
||||
_resolver.checkForInvalidAssignment(node.name, initializer,
|
||||
whyNotPromoted: whyNotPromoted);
|
||||
_resolver.checkForAssignableExpressionAtType(
|
||||
initializer,
|
||||
initializer.typeOrThrow,
|
||||
element.type,
|
||||
CompileTimeErrorCode.INVALID_ASSIGNMENT,
|
||||
whyNotPromoted: whyNotPromoted,
|
||||
);
|
||||
}
|
||||
|
||||
void _setInferredType(VariableElement element, DartType initializerType) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/syntactic_entity.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/diagnostic/diagnostic.dart';
|
||||
|
@ -74,7 +75,7 @@ class DiagnosticFactory {
|
|||
AnalysisError invalidOverride(
|
||||
Source source,
|
||||
ErrorCode? errorCode,
|
||||
AstNode errorNode,
|
||||
SyntacticEntity errorNode,
|
||||
ExecutableElement member,
|
||||
ExecutableElement superMember) {
|
||||
errorCode ??= CompileTimeErrorCode.INVALID_OVERRIDE;
|
||||
|
|
|
@ -301,9 +301,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
if (undefinedParam != null) {
|
||||
String? name;
|
||||
if (parent is FunctionDeclaration) {
|
||||
name = parent.name.name;
|
||||
name = parent.name2.lexeme;
|
||||
} else if (parent is MethodDeclaration) {
|
||||
name = parent.name.name;
|
||||
name = parent.name2.lexeme;
|
||||
}
|
||||
if (name != null) {
|
||||
var paramName = undefinedParam is SimpleStringLiteral
|
||||
|
@ -494,9 +494,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
// Overridden members are always inside classes or mixins, which are
|
||||
// always named, so we can safely assume
|
||||
// `overriddenElement.enclosingElement2.name` is non-`null`.
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER, field.name, [
|
||||
field.name.name,
|
||||
_errorReporter.reportErrorForToken(
|
||||
HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER, field.name2, [
|
||||
field.name2.lexeme,
|
||||
overriddenElement.enclosingElement2.displayName
|
||||
]);
|
||||
}
|
||||
|
@ -534,7 +534,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
|
||||
// Return types are inferred only on non-recursive local functions.
|
||||
if (node.parent is CompilationUnit && !node.isSetter) {
|
||||
_checkStrictInferenceReturnType(node.returnType, node, node.name.name);
|
||||
_checkStrictInferenceReturnType(
|
||||
node.returnType, node, node.name2.lexeme);
|
||||
}
|
||||
_checkStrictInferenceInParameters(node.functionExpression.parameters,
|
||||
body: node.functionExpression.body);
|
||||
|
@ -571,15 +572,14 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitFunctionTypeAlias(FunctionTypeAlias node) {
|
||||
_checkStrictInferenceReturnType(node.returnType, node, node.name.name);
|
||||
_checkStrictInferenceReturnType(node.returnType, node, node.name2.lexeme);
|
||||
_checkStrictInferenceInParameters(node.parameters);
|
||||
super.visitFunctionTypeAlias(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
|
||||
_checkStrictInferenceReturnType(
|
||||
node.returnType, node, node.identifier.name);
|
||||
_checkStrictInferenceReturnType(node.returnType, node, node.name.lexeme);
|
||||
_checkStrictInferenceInParameters(node.parameters);
|
||||
super.visitFunctionTypedFormalParameter(node);
|
||||
}
|
||||
|
@ -598,7 +598,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
void visitGenericTypeAlias(GenericTypeAlias node) {
|
||||
if (node.functionType != null) {
|
||||
_checkStrictInferenceReturnType(
|
||||
node.functionType!.returnType, node, node.name.name);
|
||||
node.functionType!.returnType, node, node.name2.lexeme);
|
||||
}
|
||||
super.visitGenericTypeAlias(node);
|
||||
}
|
||||
|
@ -672,7 +672,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
: false;
|
||||
|
||||
if (!node.isSetter && !elementIsOverride) {
|
||||
_checkStrictInferenceReturnType(node.returnType, node, node.name.name);
|
||||
_checkStrictInferenceReturnType(
|
||||
node.returnType, node, node.name2.lexeme);
|
||||
}
|
||||
if (!elementIsOverride) {
|
||||
_checkStrictInferenceInParameters(node.parameters, body: node.body);
|
||||
|
@ -688,10 +689,11 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
// Overridden members are always inside classes or mixins, which are
|
||||
// always named, so we can safely assume
|
||||
// `overriddenElement.enclosingElement2.name` is non-`null`.
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER,
|
||||
node.name,
|
||||
[node.name.name, overriddenElement.enclosingElement2.displayName]);
|
||||
_errorReporter.reportErrorForToken(
|
||||
HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER, node.name2, [
|
||||
node.name2.lexeme,
|
||||
overriddenElement.enclosingElement2.displayName
|
||||
]);
|
||||
}
|
||||
|
||||
super.visitMethodDeclaration(node);
|
||||
|
@ -1051,8 +1053,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
definedOrInheritedNonFinalInstanceFields(
|
||||
element, HashSet<ClassElement>());
|
||||
if (nonFinalFields.isNotEmpty) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.MUST_BE_IMMUTABLE, node.name, [nonFinalFields.join(', ')]);
|
||||
_errorReporter.reportErrorForToken(HintCode.MUST_BE_IMMUTABLE,
|
||||
node.name2, [nonFinalFields.join(', ')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1124,8 +1126,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
// Note that null return types are expected to be flagged by other analyses.
|
||||
var returnType = decl.returnType?.type;
|
||||
if (returnType is VoidType) {
|
||||
_errorReporter.reportErrorForNode(HintCode.INVALID_FACTORY_METHOD_DECL,
|
||||
decl.name, [decl.name.toString()]);
|
||||
_errorReporter.reportErrorForToken(HintCode.INVALID_FACTORY_METHOD_DECL,
|
||||
decl.name2, [decl.name2.lexeme]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1153,8 +1155,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
}
|
||||
|
||||
_errorReporter.reportErrorForNode(HintCode.INVALID_FACTORY_METHOD_IMPL,
|
||||
decl.name, [decl.name.toString()]);
|
||||
_errorReporter.reportErrorForToken(
|
||||
HintCode.INVALID_FACTORY_METHOD_IMPL, decl.name2, [decl.name2.lexeme]);
|
||||
}
|
||||
|
||||
void _checkForInvalidSealedSuperclass(NamedCompilationUnitMember node) {
|
||||
|
@ -1314,18 +1316,25 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
var errorNode = functionNode;
|
||||
if (functionNode is FunctionDeclaration) {
|
||||
errorNode = functionNode.name;
|
||||
_errorReporter.reportErrorForToken(
|
||||
HintCode.MISSING_RETURN,
|
||||
functionNode.name2,
|
||||
[returnType],
|
||||
);
|
||||
} else if (functionNode is MethodDeclaration) {
|
||||
errorNode = functionNode.name;
|
||||
_errorReporter.reportErrorForToken(
|
||||
HintCode.MISSING_RETURN,
|
||||
functionNode.name2,
|
||||
[returnType],
|
||||
);
|
||||
} else {
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.MISSING_RETURN,
|
||||
functionNode,
|
||||
[returnType],
|
||||
);
|
||||
}
|
||||
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.MISSING_RETURN,
|
||||
errorNode,
|
||||
[returnType],
|
||||
);
|
||||
}
|
||||
|
||||
void _checkForNullableTypeInCatchClause(CatchClause node) {
|
||||
|
@ -1451,7 +1460,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
///
|
||||
/// Return `true` if and only if a hint code is generated on the passed node.
|
||||
bool _checkForUnnecessaryNoSuchMethod(MethodDeclaration node) {
|
||||
if (node.name.name != FunctionElement.NO_SUCH_METHOD_METHOD_NAME) {
|
||||
if (node.name2.lexeme != FunctionElement.NO_SUCH_METHOD_METHOD_NAME) {
|
||||
return false;
|
||||
}
|
||||
bool isNonObjectNoSuchMethodInvocation(Expression? invocation) {
|
||||
|
@ -1473,8 +1482,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
FunctionBody body = node.body;
|
||||
if (body is ExpressionFunctionBody) {
|
||||
if (isNonObjectNoSuchMethodInvocation(body.expression)) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.UNNECESSARY_NO_SUCH_METHOD, node.name);
|
||||
_errorReporter.reportErrorForToken(
|
||||
HintCode.UNNECESSARY_NO_SUCH_METHOD, node.name2);
|
||||
return true;
|
||||
}
|
||||
} else if (body is BlockFunctionBody) {
|
||||
|
@ -1483,8 +1492,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
Statement returnStatement = statements.first;
|
||||
if (returnStatement is ReturnStatement &&
|
||||
isNonObjectNoSuchMethodInvocation(returnStatement.expression)) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.UNNECESSARY_NO_SUCH_METHOD, node.name);
|
||||
_errorReporter.reportErrorForToken(
|
||||
HintCode.UNNECESSARY_NO_SUCH_METHOD, node.name2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1611,7 +1620,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
|
||||
for (var param in parameterList.parameters) {
|
||||
// Param is defined.
|
||||
if (param.identifier?.name == unlessParam) {
|
||||
if (param.name?.lexeme == unlessParam) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1804,8 +1813,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
|
||||
static String _formalParameterNameOrEmpty(FormalParameter node) {
|
||||
var identifier = node.identifier;
|
||||
return identifier?.name ?? '';
|
||||
return node.name?.lexeme ?? '';
|
||||
}
|
||||
|
||||
static bool _hasNonVirtualAnnotation(ExecutableElement element) {
|
||||
|
@ -1901,7 +1909,7 @@ class _InvalidAccessVerifier {
|
|||
|
||||
if (node.leftOperand is SuperExpression) {
|
||||
var methodDeclaration = node.thisOrAncestorOfType<MethodDeclaration>();
|
||||
if (methodDeclaration?.name.name == operator.lexeme) {
|
||||
if (methodDeclaration?.name2.lexeme == operator.lexeme) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -2032,7 +2040,7 @@ class _InvalidAccessVerifier {
|
|||
parent is PropertyAccess && parent.target is SuperExpression) {
|
||||
var methodDeclaration =
|
||||
grandparent?.thisOrAncestorOfType<MethodDeclaration>();
|
||||
if (methodDeclaration?.name.name == identifier.name) {
|
||||
if (methodDeclaration?.name2.lexeme == identifier.name) {
|
||||
validOverride = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,10 +234,10 @@ class ConstructorFieldsVerifier {
|
|||
_fieldMap[fieldElement] = _InitState.initInFieldFormal;
|
||||
} else if (state == _InitState.initInDeclaration) {
|
||||
if (fieldElement.isFinal || fieldElement.isConst) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
_errorReporter.reportErrorForToken(
|
||||
CompileTimeErrorCode
|
||||
.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR,
|
||||
parameter.identifier,
|
||||
parameter.name,
|
||||
[fieldElement.displayName],
|
||||
);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue