mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:17:14 +00:00
Breaking changes for analyzer version 5.0.0
Change-Id: Id9f27b6c41829249f6b2e7b93ad396643193fc78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243164 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
5a59b00da5
commit
d8df88cbe4
|
@ -185,7 +185,7 @@ String? _getParametersString(engine.Element element,
|
|||
|
||||
String? _getTypeParametersString(engine.Element element) {
|
||||
List<engine.TypeParameterElement>? typeParameters;
|
||||
if (element is engine.ClassElement) {
|
||||
if (element is engine.InterfaceElement) {
|
||||
typeParameters = element.typeParameters;
|
||||
} else if (element is engine.TypeAliasElement) {
|
||||
typeParameters = element.typeParameters;
|
||||
|
@ -203,6 +203,9 @@ bool _isAbstract(engine.Element element) {
|
|||
if (element is engine.MethodElement) {
|
||||
return element.isAbstract;
|
||||
}
|
||||
if (element is engine.MixinElement) {
|
||||
return true;
|
||||
}
|
||||
if (element is engine.PropertyAccessorElement) {
|
||||
return element.isAbstract;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class CanRenameResponse {
|
|||
status = validateMethodName(name);
|
||||
} else if (element is TypeAliasElement) {
|
||||
status = validateTypeAliasName(name);
|
||||
} else if (element is ClassElement) {
|
||||
} else if (element is InterfaceElement) {
|
||||
status = validateClassName(name);
|
||||
} else if (element is ConstructorElement) {
|
||||
status = validateConstructorName(name);
|
||||
|
@ -297,12 +297,12 @@ class CheckNameResponse {
|
|||
|
||||
Future<CiderReplaceMatch?> _replaceSyntheticConstructor() async {
|
||||
var element = canRename.refactoringElement.element;
|
||||
var classElement = element.enclosingElement3;
|
||||
var interfaceElement = element.enclosingElement3;
|
||||
|
||||
var fileResolver = canRename._fileResolver;
|
||||
var libraryPath = classElement!.library!.source.fullName;
|
||||
var libraryPath = interfaceElement!.library!.source.fullName;
|
||||
var resolvedLibrary = await fileResolver.resolveLibrary2(path: libraryPath);
|
||||
var result = resolvedLibrary.getElementDeclaration(classElement);
|
||||
var result = resolvedLibrary.getElementDeclaration(interfaceElement);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ class CheckNameResponse {
|
|||
return null;
|
||||
}
|
||||
|
||||
var header = '${classElement.name}.$newName();';
|
||||
var header = '${interfaceElement.name}.$newName();';
|
||||
return CiderReplaceMatch(libraryPath, [
|
||||
ReplaceInfo(location.prefix + header + location.suffix,
|
||||
resolvedUnit.lineInfo.getLocation(location.offset), 0)
|
||||
|
@ -333,7 +333,7 @@ class CheckNameResponse {
|
|||
return null;
|
||||
}
|
||||
|
||||
var header = 'const ${classElement.name}.$newName();';
|
||||
var header = 'const ${interfaceElement.name}.$newName();';
|
||||
return CiderReplaceMatch(libraryPath, [
|
||||
ReplaceInfo(location.prefix + header + location.suffix,
|
||||
resolvedUnit.lineInfo.getLocation(location.offset), 0)
|
||||
|
@ -392,7 +392,7 @@ class CiderRenameComputer {
|
|||
if (element is LabelElement || element is LocalElement) {
|
||||
return true;
|
||||
}
|
||||
if (enclosingElement is ClassElement ||
|
||||
if (enclosingElement is InterfaceElement ||
|
||||
enclosingElement is ExtensionElement ||
|
||||
enclosingElement is CompilationUnitElement) {
|
||||
return true;
|
||||
|
|
|
@ -204,8 +204,8 @@ class DartCallHierarchyComputer {
|
|||
// `constructor`, because we need to locate them using an `offset`, which
|
||||
// implicit constructors do not have.
|
||||
// Here, we map them back to the synthetic constructor element.
|
||||
final isImplicitConstructor =
|
||||
element is ClassElement && target.kind == CallHierarchyKind.constructor;
|
||||
final isImplicitConstructor = element is InterfaceElement &&
|
||||
target.kind == CallHierarchyKind.constructor;
|
||||
if (isImplicitConstructor) {
|
||||
element = element.unnamedConstructor;
|
||||
}
|
||||
|
@ -311,7 +311,9 @@ class DartCallHierarchyComputer {
|
|||
/// Finds a target node for call hierarchy navigation at [offset].
|
||||
AstNode? _findTargetNode(int offset) {
|
||||
var node = NodeLocator(offset).searchWithin(_result.unit);
|
||||
if (node is SimpleIdentifier &&
|
||||
if (node is FormalParameterList) {
|
||||
node = node.parent;
|
||||
} else if (node is SimpleIdentifier &&
|
||||
node.parent != null &&
|
||||
node.parent is! VariableDeclaration &&
|
||||
node.parent is! AssignmentExpression) {
|
||||
|
|
|
@ -158,7 +158,7 @@ class DartUnitHighlightsComputer {
|
|||
|
||||
bool _addIdentifierRegion_class(SimpleIdentifier node) {
|
||||
var element = node.writeOrReadElement;
|
||||
if (element is! ClassElement) {
|
||||
if (element is! InterfaceElement) {
|
||||
return false;
|
||||
}
|
||||
// prepare type
|
||||
|
@ -662,9 +662,10 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitClassDeclaration(ClassDeclaration node) {
|
||||
computer._addRegion_token(node.classKeyword, HighlightRegionType.KEYWORD);
|
||||
computer._addRegion_token(
|
||||
node.abstractKeyword, HighlightRegionType.BUILT_IN);
|
||||
computer._addRegion_token(node.classKeyword, HighlightRegionType.KEYWORD);
|
||||
computer._addRegion_token(node.name2, HighlightRegionType.CLASS);
|
||||
super.visitClassDeclaration(node);
|
||||
}
|
||||
|
||||
|
@ -724,6 +725,12 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitDeclaredIdentifier(DeclaredIdentifier node) {
|
||||
computer._addRegion_token(node.keyword, HighlightRegionType.KEYWORD);
|
||||
|
||||
computer._addRegion_token(
|
||||
node.name,
|
||||
HighlightRegionType.LOCAL_VARIABLE_DECLARATION,
|
||||
);
|
||||
|
||||
super.visitDeclaredIdentifier(node);
|
||||
}
|
||||
|
||||
|
@ -761,6 +768,7 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitEnumDeclaration(EnumDeclaration node) {
|
||||
computer._addRegion_token(node.enumKeyword, HighlightRegionType.KEYWORD);
|
||||
computer._addRegion_token(node.name2, HighlightRegionType.ENUM);
|
||||
super.visitEnumDeclaration(node);
|
||||
}
|
||||
|
||||
|
@ -788,6 +796,7 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
void visitExtensionDeclaration(ExtensionDeclaration node) {
|
||||
computer._addRegion_token(
|
||||
node.extensionKeyword, HighlightRegionType.KEYWORD);
|
||||
computer._addRegion_token(node.name2, HighlightRegionType.EXTENSION);
|
||||
computer._addRegion_token(node.onKeyword, HighlightRegionType.BUILT_IN);
|
||||
super.visitExtensionDeclaration(node);
|
||||
}
|
||||
|
@ -799,13 +808,30 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
computer._addRegion_token(
|
||||
node.externalKeyword, HighlightRegionType.BUILT_IN);
|
||||
computer._addRegion_token(node.staticKeyword, HighlightRegionType.BUILT_IN);
|
||||
|
||||
for (final variable in node.fields.variables) {
|
||||
computer._addRegion_token(
|
||||
variable.name2,
|
||||
node.isStatic
|
||||
? HighlightRegionType.STATIC_FIELD_DECLARATION
|
||||
: HighlightRegionType.INSTANCE_FIELD_DECLARATION,
|
||||
);
|
||||
}
|
||||
|
||||
super.visitFieldDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitFieldFormalParameter(FieldFormalParameter node) {
|
||||
computer._addRegion_token(
|
||||
node.requiredKeyword, HighlightRegionType.KEYWORD);
|
||||
node.requiredKeyword,
|
||||
HighlightRegionType.KEYWORD,
|
||||
);
|
||||
|
||||
computer._addRegion_token(
|
||||
node.thisKeyword,
|
||||
HighlightRegionType.KEYWORD,
|
||||
);
|
||||
|
||||
var element = node.declaredElement;
|
||||
if (element is FieldFormalParameterElement) {
|
||||
|
@ -859,6 +885,19 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
node.externalKeyword, HighlightRegionType.BUILT_IN);
|
||||
computer._addRegion_token(
|
||||
node.propertyKeyword, HighlightRegionType.BUILT_IN);
|
||||
|
||||
final HighlightRegionType nameType;
|
||||
if (node.isGetter) {
|
||||
nameType = HighlightRegionType.TOP_LEVEL_GETTER_DECLARATION;
|
||||
} else if (node.isSetter) {
|
||||
nameType = HighlightRegionType.TOP_LEVEL_SETTER_DECLARATION;
|
||||
} else if (node.parent is CompilationUnit) {
|
||||
nameType = HighlightRegionType.TOP_LEVEL_FUNCTION_DECLARATION;
|
||||
} else {
|
||||
nameType = HighlightRegionType.LOCAL_FUNCTION_DECLARATION;
|
||||
}
|
||||
computer._addRegion_token(node.name2, nameType);
|
||||
|
||||
super.visitFunctionDeclaration(node);
|
||||
}
|
||||
|
||||
|
@ -866,6 +905,8 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
void visitFunctionTypeAlias(FunctionTypeAlias node) {
|
||||
computer._addRegion_token(
|
||||
node.typedefKeyword, HighlightRegionType.BUILT_IN);
|
||||
computer._addRegion_token(
|
||||
node.name2, HighlightRegionType.FUNCTION_TYPE_ALIAS);
|
||||
super.visitFunctionTypeAlias(node);
|
||||
}
|
||||
|
||||
|
@ -887,6 +928,15 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
void visitGenericTypeAlias(GenericTypeAlias node) {
|
||||
computer._addRegion_token(
|
||||
node.typedefKeyword, HighlightRegionType.BUILT_IN);
|
||||
|
||||
final HighlightRegionType nameType;
|
||||
if (node.functionType != null) {
|
||||
nameType = HighlightRegionType.FUNCTION_TYPE_ALIAS;
|
||||
} else {
|
||||
nameType = HighlightRegionType.TYPE_ALIAS;
|
||||
}
|
||||
computer._addRegion_token(node.name2, nameType);
|
||||
|
||||
super.visitGenericTypeAlias(node);
|
||||
}
|
||||
|
||||
|
@ -1014,6 +1064,23 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
node.operatorKeyword, HighlightRegionType.BUILT_IN);
|
||||
computer._addRegion_token(
|
||||
node.propertyKeyword, HighlightRegionType.BUILT_IN);
|
||||
|
||||
final HighlightRegionType nameType;
|
||||
if (node.isGetter) {
|
||||
nameType = node.isStatic
|
||||
? HighlightRegionType.STATIC_GETTER_DECLARATION
|
||||
: HighlightRegionType.INSTANCE_GETTER_DECLARATION;
|
||||
} else if (node.isSetter) {
|
||||
nameType = node.isStatic
|
||||
? HighlightRegionType.STATIC_SETTER_DECLARATION
|
||||
: HighlightRegionType.INSTANCE_SETTER_DECLARATION;
|
||||
} else {
|
||||
nameType = node.isStatic
|
||||
? HighlightRegionType.STATIC_METHOD_DECLARATION
|
||||
: HighlightRegionType.INSTANCE_METHOD_DECLARATION;
|
||||
}
|
||||
computer._addRegion_token(node.name2, nameType);
|
||||
|
||||
super.visitMethodDeclaration(node);
|
||||
}
|
||||
|
||||
|
@ -1112,17 +1179,19 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
void visitSimpleFormalParameter(SimpleFormalParameter node) {
|
||||
computer._addRegion_token(
|
||||
node.requiredKeyword, HighlightRegionType.KEYWORD);
|
||||
|
||||
computer._addRegion_token(
|
||||
node.name,
|
||||
node.declaredElement!.type is DynamicType
|
||||
? HighlightRegionType.DYNAMIC_PARAMETER_DECLARATION
|
||||
: HighlightRegionType.PARAMETER_DECLARATION,
|
||||
);
|
||||
|
||||
super.visitSimpleFormalParameter(node);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
@ -1202,6 +1271,14 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
|
||||
computer._addRegion_token(
|
||||
node.externalKeyword, HighlightRegionType.BUILT_IN);
|
||||
|
||||
for (final variable in node.variables.variables) {
|
||||
computer._addRegion_token(
|
||||
variable.name2,
|
||||
HighlightRegionType.TOP_LEVEL_VARIABLE_DECLARATION,
|
||||
);
|
||||
}
|
||||
|
||||
super.visitTopLevelVariableDeclaration(node);
|
||||
}
|
||||
|
||||
|
@ -1214,6 +1291,12 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
super.visitTryStatement(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitTypeParameter(TypeParameter node) {
|
||||
computer._addRegion_token(node.name2, HighlightRegionType.TYPE_PARAMETER);
|
||||
super.visitTypeParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclarationList(VariableDeclarationList node) {
|
||||
computer._addRegion_token(node.lateKeyword, HighlightRegionType.KEYWORD);
|
||||
|
@ -1221,6 +1304,21 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
super.visitVariableDeclarationList(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclarationStatement(VariableDeclarationStatement node) {
|
||||
for (final variable in node.variables.variables) {
|
||||
final element = variable.declaredElement2 as LocalVariableElement;
|
||||
computer._addRegion_token(
|
||||
variable.name2,
|
||||
element.type is DynamicType
|
||||
? HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_DECLARATION
|
||||
: HighlightRegionType.LOCAL_VARIABLE_DECLARATION,
|
||||
);
|
||||
}
|
||||
|
||||
super.visitVariableDeclarationStatement(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitWhileStatement(WhileStatement node) {
|
||||
computer._addRegion_token(node.whileKeyword, HighlightRegionType.KEYWORD,
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:analysis_server/protocol/protocol_generated.dart'
|
|||
import 'package:analysis_server/src/computer/computer_overrides.dart';
|
||||
import 'package:analysis_server/src/utilities/extensions/ast.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/syntactic_entity.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/ast/element_locator.dart';
|
||||
|
@ -29,6 +30,25 @@ class DartUnitHoverComputer {
|
|||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SyntacticEntity? locationEntity;
|
||||
if (node is NamedCompilationUnitMember) {
|
||||
locationEntity = node.name2;
|
||||
} else if (node is Expression) {
|
||||
locationEntity = node;
|
||||
} else if (node is ExtensionDeclaration) {
|
||||
locationEntity = node.name2;
|
||||
} else if (node is FormalParameter) {
|
||||
locationEntity = node.name;
|
||||
} else if (node is MethodDeclaration) {
|
||||
locationEntity = node.name2;
|
||||
} else if (node is VariableDeclaration) {
|
||||
locationEntity = node.name2;
|
||||
}
|
||||
if (locationEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var parent = node.parent;
|
||||
var grandParent = parent?.parent;
|
||||
if (parent is NamedType &&
|
||||
|
@ -39,19 +59,23 @@ class DartUnitHoverComputer {
|
|||
grandParent is InstanceCreationExpression) {
|
||||
node = grandParent;
|
||||
}
|
||||
if (node is Expression) {
|
||||
var expression = node;
|
||||
if (node != null &&
|
||||
(node is CompilationUnitMember ||
|
||||
node is Expression ||
|
||||
node is FormalParameter ||
|
||||
node is MethodDeclaration ||
|
||||
node is VariableDeclaration)) {
|
||||
// For constructor calls the whole expression is selected (above) but this
|
||||
// results in the range covering the whole call so narrow it to just the
|
||||
// ConstructorName.
|
||||
var hover = expression is InstanceCreationExpression
|
||||
var hover = node is InstanceCreationExpression
|
||||
? HoverInformation(
|
||||
expression.constructorName.offset,
|
||||
expression.constructorName.length,
|
||||
node.constructorName.offset,
|
||||
node.constructorName.length,
|
||||
)
|
||||
: HoverInformation(expression.offset, expression.length);
|
||||
: HoverInformation(locationEntity.offset, locationEntity.length);
|
||||
// element
|
||||
var element = ElementLocator.locate(expression);
|
||||
var element = ElementLocator.locate(node);
|
||||
if (element != null) {
|
||||
// variable, if synthetic accessor
|
||||
if (element is PropertyAccessorElement) {
|
||||
|
@ -73,7 +97,8 @@ class DartUnitHoverComputer {
|
|||
// not local element
|
||||
if (element.enclosingElement3 is! ExecutableElement) {
|
||||
// containing class
|
||||
var containingClass = element.thisOrAncestorOfType<ClassElement>();
|
||||
var containingClass =
|
||||
element.thisOrAncestorOfType<InterfaceElement>();
|
||||
if (containingClass != null && containingClass != element) {
|
||||
hover.containingClassDescription = containingClass.displayName;
|
||||
}
|
||||
|
@ -105,17 +130,24 @@ class DartUnitHoverComputer {
|
|||
hover.dartdoc = computeDocumentation(_dartdocInfo, element)?.full;
|
||||
}
|
||||
// parameter
|
||||
hover.parameter = _elementDisplayString(
|
||||
expression.staticParameterElement,
|
||||
);
|
||||
if (node is Expression) {
|
||||
hover.parameter = _elementDisplayString(
|
||||
node.staticParameterElement,
|
||||
);
|
||||
}
|
||||
// types
|
||||
{
|
||||
var parent = expression.parent;
|
||||
var parent = node.parent;
|
||||
DartType? staticType;
|
||||
if (element == null || element is VariableElement) {
|
||||
staticType = _getTypeOfDeclarationOrReference(node);
|
||||
if (element is VariableElement) {
|
||||
staticType = element.type;
|
||||
}
|
||||
if (parent is MethodInvocation && parent.methodName == expression) {
|
||||
if (node is Expression) {
|
||||
if (element == null || element is VariableElement) {
|
||||
staticType = _getTypeOfDeclarationOrReference(node);
|
||||
}
|
||||
}
|
||||
if (parent is MethodInvocation && parent.methodName == node) {
|
||||
staticType = parent.staticInvokeType;
|
||||
if (staticType != null && staticType.isDynamic) {
|
||||
staticType = null;
|
||||
|
|
|
@ -11,7 +11,7 @@ import 'package:analyzer/dart/element/element.dart';
|
|||
|
||||
/// Return the elements that the given [element] overrides.
|
||||
OverriddenElements findOverriddenElements(Element element) {
|
||||
if (element.enclosingElement3 is ClassElement) {
|
||||
if (element.enclosingElement3 is InterfaceElement) {
|
||||
return _OverriddenElementsFinder(element).find();
|
||||
}
|
||||
return OverriddenElements(element, <Element>[], <Element>[]);
|
||||
|
@ -102,7 +102,7 @@ class OverriddenElements {
|
|||
class _OverriddenElementsFinder {
|
||||
Element _seed;
|
||||
LibraryElement _library;
|
||||
ClassElement _class;
|
||||
InterfaceElement _class;
|
||||
String _name;
|
||||
List<ElementKind> _kinds;
|
||||
|
||||
|
@ -111,7 +111,7 @@ class _OverriddenElementsFinder {
|
|||
final Set<InterfaceElement> _visited = {};
|
||||
|
||||
factory _OverriddenElementsFinder(Element seed) {
|
||||
var class_ = seed.enclosingElement3 as ClassElement;
|
||||
var class_ = seed.enclosingElement3 as InterfaceElement;
|
||||
var library = class_.library;
|
||||
var name = seed.displayName;
|
||||
List<ElementKind> kinds;
|
||||
|
@ -164,9 +164,7 @@ class _OverriddenElementsFinder {
|
|||
_addInterfaceOverrides(interfaceType.element2, true);
|
||||
}
|
||||
// super
|
||||
if (class_ is ClassElement) {
|
||||
_addInterfaceOverrides(class_.supertype?.element2, checkType);
|
||||
}
|
||||
_addInterfaceOverrides(class_.supertype?.element2, checkType);
|
||||
}
|
||||
|
||||
void _addSuperOverrides(InterfaceElement? class_,
|
||||
|
@ -185,9 +183,7 @@ class _OverriddenElementsFinder {
|
|||
}
|
||||
}
|
||||
|
||||
if (class_ is ClassElement) {
|
||||
_addSuperOverrides(class_.supertype?.element2);
|
||||
}
|
||||
_addSuperOverrides(class_.supertype?.element2);
|
||||
for (var mixin_ in class_.mixins) {
|
||||
_addSuperOverrides(mixin_.element2);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,41 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
super.visitEnumConstantDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitFieldFormalParameter(FieldFormalParameter node) {
|
||||
final declaredElement = node.declaredElement;
|
||||
if (declaredElement is FieldFormalParameterElement) {
|
||||
final field = declaredElement.field;
|
||||
if (field != null) {
|
||||
_addOccurrence(field, node.name.offset);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitFieldFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitFunctionDeclaration(FunctionDeclaration node) {
|
||||
_addOccurrence(node.declaredElement2!, node.name2.offset);
|
||||
super.visitFunctionDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitMethodDeclaration(MethodDeclaration node) {
|
||||
_addOccurrence(node.declaredElement2!, node.name2.offset);
|
||||
super.visitMethodDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleFormalParameter(SimpleFormalParameter node) {
|
||||
final nameToken = node.name;
|
||||
if (nameToken != null) {
|
||||
_addOccurrence(node.declaredElement!, nameToken.offset);
|
||||
}
|
||||
|
||||
super.visitSimpleFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
var element = node.writeOrReadElement;
|
||||
|
@ -42,6 +77,18 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
|
|||
return super.visitSimpleIdentifier(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSuperFormalParameter(SuperFormalParameter node) {
|
||||
_addOccurrence(node.declaredElement!, node.name.offset);
|
||||
super.visitSuperFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
_addOccurrence(node.declaredElement2!, node.name2.offset);
|
||||
super.visitVariableDeclaration(node);
|
||||
}
|
||||
|
||||
void _addOccurrence(Element element, int offset) {
|
||||
var canonicalElement = _canonicalizeElement(element);
|
||||
if (canonicalElement == null || element == DynamicElementImpl.instance) {
|
||||
|
|
|
@ -63,7 +63,7 @@ class DocumentColorPresentationHandler
|
|||
Future<ColorPresentation> _createColorPresentation(
|
||||
ResolvedUnitResult unit,
|
||||
SourceRange editRange,
|
||||
ClassElement colorType,
|
||||
InterfaceElement colorType,
|
||||
String label,
|
||||
String invocationString,
|
||||
) async {
|
||||
|
|
|
@ -254,7 +254,7 @@ class RenameHandler extends MessageHandler<RenameParams, WorkspaceEdit?> {
|
|||
|
||||
bool _isClassRename(RenameRefactoring refactoring) =>
|
||||
refactoring is RenameUnitMemberRefactoringImpl &&
|
||||
refactoring.element is ClassElement;
|
||||
refactoring.element is InterfaceElement;
|
||||
|
||||
/// Asks the user whether they would like to rename the file along with the
|
||||
/// class.
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:analysis_server/lsp_protocol/protocol.dart';
|
|||
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
|
||||
import 'package:analysis_server/src/lsp/mapping.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/syntactic_entity.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/element.dart' as analyzer;
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
|
@ -69,7 +70,18 @@ class TypeDefinitionHandler extends MessageHandler<TypeDefinitionParams,
|
|||
return success(_emptyResult);
|
||||
}
|
||||
|
||||
final type = node is Expression ? _getType(node) : null;
|
||||
final SyntacticEntity originEntity;
|
||||
DartType? type;
|
||||
if (node is VariableDeclaration) {
|
||||
originEntity = node.name2;
|
||||
type = node.declaredElement2?.type;
|
||||
} else if (node is Expression) {
|
||||
originEntity = node;
|
||||
type = _getType(node);
|
||||
} else {
|
||||
return success(_emptyResult);
|
||||
}
|
||||
|
||||
analyzer.Element? element;
|
||||
if (type is InterfaceType) {
|
||||
element = type.element2;
|
||||
|
@ -96,8 +108,8 @@ class TypeDefinitionHandler extends MessageHandler<TypeDefinitionParams,
|
|||
|
||||
if (supportsLocationLink) {
|
||||
return success(TextDocumentTypeDefinitionResult.t2([
|
||||
_toLocationLink(
|
||||
result.lineInfo, targetLineInfo, node, element, location)
|
||||
_toLocationLink(result.lineInfo, targetLineInfo, originEntity,
|
||||
element, location)
|
||||
]));
|
||||
} else {
|
||||
return success(TextDocumentTypeDefinitionResult.t1(
|
||||
|
@ -118,12 +130,12 @@ class TypeDefinitionHandler extends MessageHandler<TypeDefinitionParams,
|
|||
|
||||
/// Creates an LSP [LocationLink] for the server [targetLocation].
|
||||
///
|
||||
/// Uses [originLineInfo] and [originNode] to compute `originSelectionRange`
|
||||
/// Uses [originLineInfo] and [originEntity] to compute `originSelectionRange`
|
||||
/// and [targetLineInfo] and [targetElement] for code ranges.
|
||||
LocationLink _toLocationLink(
|
||||
LineInfo originLineInfo,
|
||||
LineInfo targetLineInfo,
|
||||
AstNode originNode,
|
||||
SyntacticEntity originEntity,
|
||||
analyzer.ElementImpl targetElement,
|
||||
plugin.Location targetLocation,
|
||||
) {
|
||||
|
@ -138,7 +150,7 @@ class TypeDefinitionHandler extends MessageHandler<TypeDefinitionParams,
|
|||
|
||||
return LocationLink(
|
||||
originSelectionRange:
|
||||
toRange(originLineInfo, originNode.offset, originNode.length),
|
||||
toRange(originLineInfo, originEntity.offset, originEntity.length),
|
||||
targetUri: Uri.file(targetLocation.file).toString(),
|
||||
targetRange: codeRange,
|
||||
targetSelectionRange: nameRange,
|
||||
|
@ -150,7 +162,7 @@ class TypeDefinitionHandler extends MessageHandler<TypeDefinitionParams,
|
|||
static DartType? _getType(Expression node) {
|
||||
if (node is SimpleIdentifier) {
|
||||
final element = node.staticElement;
|
||||
if (element is ClassElement) {
|
||||
if (element is InterfaceElement) {
|
||||
return element.thisType;
|
||||
} else if (element is VariableElement) {
|
||||
if (node.inDeclarationContext()) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:analysis_server/src/services/search/search_engine.dart'
|
|||
import 'package:analysis_server/src/utilities/extensions/element.dart';
|
||||
import 'package:analyzer/dart/analysis/results.dart' as engine;
|
||||
import 'package:analyzer/dart/ast/ast.dart' as engine;
|
||||
import 'package:analyzer/dart/ast/token.dart' as engine;
|
||||
import 'package:analyzer/dart/element/element.dart' as engine;
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/diagnostic/diagnostic.dart' as engine;
|
||||
|
@ -205,6 +206,15 @@ Location newLocation_fromNode(engine.AstNode node) {
|
|||
return _locationForArgs(unitElement, range);
|
||||
}
|
||||
|
||||
/// Create a Location based on an [engine.AstNode].
|
||||
Location newLocation_fromToken({
|
||||
required engine.CompilationUnitElement unitElement,
|
||||
required engine.Token token,
|
||||
}) {
|
||||
var range = engine.SourceRange(token.offset, token.length);
|
||||
return _locationForArgs(unitElement, range);
|
||||
}
|
||||
|
||||
/// Create a Location based on an [engine.CompilationUnit].
|
||||
Location newLocation_fromUnit(
|
||||
engine.CompilationUnit unit, engine.SourceRange range) {
|
||||
|
|
|
@ -73,6 +73,6 @@ class ElementReferencesComputer {
|
|||
if (element is ConstructorElement) {
|
||||
return false;
|
||||
}
|
||||
return element.enclosingElement3 is ClassElement;
|
||||
return element.enclosingElement3 is InterfaceElement;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class TypeHierarchyComputer {
|
|||
final ElementKind _pivotKind;
|
||||
final String? _pivotName;
|
||||
late bool _pivotFieldFinal;
|
||||
ClassElement? _pivotClass;
|
||||
InterfaceElement? _pivotClass;
|
||||
|
||||
final List<TypeHierarchyItem> _items = <TypeHierarchyItem>[];
|
||||
final List<InterfaceElement> _itemClassElements = [];
|
||||
|
@ -40,7 +40,7 @@ class TypeHierarchyComputer {
|
|||
if (_pivotElement is ExecutableElement) {
|
||||
element = _pivotElement.enclosingElement3;
|
||||
}
|
||||
if (element is ClassElement) {
|
||||
if (element is InterfaceElement) {
|
||||
_pivotClass = element;
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class TypeHierarchyComputer {
|
|||
_itemClassElements.add(classElement);
|
||||
}
|
||||
// superclass
|
||||
if (classElement is ClassElement) {
|
||||
{
|
||||
var superType = classElement.supertype;
|
||||
if (superType != null) {
|
||||
item.superclass = _createSuperItem(
|
||||
|
|
|
@ -59,7 +59,7 @@ class ExtensionMemberContributor extends DartCompletionContributor {
|
|||
}
|
||||
if (expression is Identifier) {
|
||||
var elem = expression.staticElement;
|
||||
if (elem is ClassElement) {
|
||||
if (elem is InterfaceElement) {
|
||||
// Suggestions provided by StaticMemberContributor.
|
||||
return;
|
||||
} else if (elem is ExtensionElement) {
|
||||
|
|
|
@ -469,11 +469,8 @@ class FeatureComputer {
|
|||
} else if (!visited.add(subclass)) {
|
||||
return -1;
|
||||
}
|
||||
var minDepth = 0;
|
||||
if (subclass is ClassElement) {
|
||||
minDepth = _inheritanceDistance(
|
||||
subclass.supertype?.element2, superclass, visited);
|
||||
}
|
||||
var minDepth =
|
||||
_inheritanceDistance(subclass.supertype?.element2, superclass, visited);
|
||||
|
||||
void visitTypes(List<InterfaceType> types) {
|
||||
for (var type in types) {
|
||||
|
|
|
@ -52,7 +52,7 @@ class LibraryMemberContributor extends DartCompletionContributor {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (element is ClassElement ||
|
||||
if (element is InterfaceElement ||
|
||||
element is ExtensionElement ||
|
||||
element is TypeAliasElement) {
|
||||
builder.suggestElement(element,
|
||||
|
|
|
@ -46,27 +46,7 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor {
|
|||
|
||||
@override
|
||||
void visitClassElement(ClassElement element) {
|
||||
if (opType.includeTypeNameSuggestions) {
|
||||
builder.suggestInterface(element, prefix: prefix);
|
||||
}
|
||||
if (opType.includeConstructorSuggestions) {
|
||||
_addConstructorSuggestions(element);
|
||||
} else if (opType.includeAnnotationSuggestions) {
|
||||
_addConstructorSuggestions(element, onlyConst: true);
|
||||
}
|
||||
if (opType.includeReturnValueSuggestions) {
|
||||
final typeSystem = request.libraryElement.typeSystem;
|
||||
final contextType = request.contextType;
|
||||
if (contextType is InterfaceType) {
|
||||
// TODO(scheglov) This looks not ideal - we should suggest getters.
|
||||
for (final field in element.fields) {
|
||||
if (field.isStatic &&
|
||||
typeSystem.isSubtypeOf(field.type, contextType)) {
|
||||
builder.suggestStaticField(field, prefix: prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_visitInterfaceElement(element);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -79,6 +59,11 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor {
|
|||
// ignored
|
||||
}
|
||||
|
||||
@override
|
||||
visitEnumElement(EnumElement element) {
|
||||
_visitInterfaceElement(element);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitExtensionElement(ExtensionElement element) {
|
||||
if (opType.includeReturnValueSuggestions) {
|
||||
|
@ -114,12 +99,17 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
visitMixinElement(MixinElement element) {
|
||||
_visitInterfaceElement(element);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitPropertyAccessorElement(PropertyAccessorElement element) {
|
||||
if (opType.includeReturnValueSuggestions ||
|
||||
(opType.includeAnnotationSuggestions && element.variable.isConst)) {
|
||||
var parent = element.enclosingElement3;
|
||||
if (parent is ClassElement || parent is ExtensionElement) {
|
||||
if (parent is InterfaceElement || parent is ExtensionElement) {
|
||||
builder.suggestAccessor(element, inheritanceDistance: 0.0);
|
||||
} else {
|
||||
builder.suggestTopLevelPropertyAccessor(element, prefix: prefix);
|
||||
|
@ -165,6 +155,32 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor {
|
|||
builder.suggestConstructor(constructor, kind: kind, prefix: prefix);
|
||||
}
|
||||
}
|
||||
|
||||
void _visitInterfaceElement(InterfaceElement element) {
|
||||
if (opType.includeTypeNameSuggestions) {
|
||||
builder.suggestInterface(element, prefix: prefix);
|
||||
}
|
||||
if (element is ClassElement) {
|
||||
if (opType.includeConstructorSuggestions) {
|
||||
_addConstructorSuggestions(element);
|
||||
} else if (opType.includeAnnotationSuggestions) {
|
||||
_addConstructorSuggestions(element, onlyConst: true);
|
||||
}
|
||||
}
|
||||
if (opType.includeReturnValueSuggestions) {
|
||||
final typeSystem = request.libraryElement.typeSystem;
|
||||
final contextType = request.contextType;
|
||||
if (contextType is InterfaceType) {
|
||||
// TODO(scheglov) This looks not ideal - we should suggest getters.
|
||||
for (final field in element.fields) {
|
||||
if (field.isStatic &&
|
||||
typeSystem.isSubtypeOf(field.type, contextType)) {
|
||||
builder.suggestStaticField(field, prefix: prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A contributor that produces suggestions based on the top level members in
|
||||
|
|
|
@ -264,7 +264,7 @@ class _LocalVisitor extends LocalDeclarationVisitor {
|
|||
var enclosingElement = enclosingClass?.declaredElement2;
|
||||
if (enclosingElement != null) {
|
||||
var enclosingElement = field.enclosingElement3;
|
||||
if (enclosingElement is ClassElement) {
|
||||
if (enclosingElement is InterfaceElement) {
|
||||
inheritanceDistance = request.featureComputer
|
||||
.inheritanceDistanceFeature(enclosingElement, enclosingElement);
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ class _LocalVisitor extends LocalDeclarationVisitor {
|
|||
.thisOrAncestorOfType<ClassDeclaration>();
|
||||
if (enclosingClass != null) {
|
||||
var enclosingElement = element?.enclosingElement3;
|
||||
if (enclosingElement is ClassElement) {
|
||||
if (enclosingElement is InterfaceElement) {
|
||||
inheritanceDistance = request.featureComputer
|
||||
.inheritanceDistanceFeature(
|
||||
enclosingClass.declaredElement2!, enclosingElement);
|
||||
|
@ -428,9 +428,7 @@ class _LocalVisitor extends LocalDeclarationVisitor {
|
|||
!opType.includeConstructorSuggestions;
|
||||
if (!opType.isPrefixed &&
|
||||
includeConstructors &&
|
||||
element is ClassElement &&
|
||||
// TODO(scheglov) Remove when separated EnumElement from ClassElement
|
||||
element is! EnumElement) {
|
||||
element is ClassElement) {
|
||||
for (final constructor in element.constructors) {
|
||||
if (element.isAbstract && !constructor.isFactory) {
|
||||
continue;
|
||||
|
|
|
@ -435,7 +435,7 @@ class SuggestionBuilder {
|
|||
/// will be used as the kind for the suggestion.
|
||||
void suggestElement(Element element,
|
||||
{CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION}) {
|
||||
if (element is ClassElement) {
|
||||
if (element is InterfaceElement) {
|
||||
suggestInterface(element);
|
||||
} else if (element is ConstructorElement) {
|
||||
suggestConstructor(element, kind: kind);
|
||||
|
@ -1328,7 +1328,7 @@ class SuggestionBuilder {
|
|||
var enclosingElement = element.enclosingElement3;
|
||||
|
||||
String? declaringType;
|
||||
if (enclosingElement is ClassElement) {
|
||||
if (enclosingElement is InterfaceElement) {
|
||||
declaringType = enclosingElement.displayName;
|
||||
}
|
||||
|
||||
|
@ -1385,7 +1385,7 @@ class SuggestionBuilder {
|
|||
/// we either fail with assertion, or return `null`.
|
||||
String? _enclosingClassOrExtensionName(Element element) {
|
||||
var enclosing = element.enclosingElement3;
|
||||
if (enclosing is ClassElement) {
|
||||
if (enclosing is InterfaceElement) {
|
||||
return enclosing.name;
|
||||
} else if (enclosing is ExtensionElement) {
|
||||
return enclosing.name;
|
||||
|
|
|
@ -31,7 +31,7 @@ class TypeMemberContributor extends DartCompletionContributor {
|
|||
}
|
||||
if (expression is Identifier) {
|
||||
var elem = expression.staticElement;
|
||||
if (elem is ClassElement) {
|
||||
if (elem is InterfaceElement) {
|
||||
// Suggestions provided by StaticMemberContributor.
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -85,13 +85,13 @@ abstract class CorrectionProducer extends SingleCorrectionProducer {
|
|||
|
||||
/// Return the class element associated with the [target], or `null` if there
|
||||
/// is no such class element.
|
||||
InterfaceElement? getTargetClassElement(Expression target) {
|
||||
InterfaceElement? getTargetInterfaceElement(Expression target) {
|
||||
var type = target.staticType;
|
||||
if (type is InterfaceType) {
|
||||
return type.element2;
|
||||
} else if (target is Identifier) {
|
||||
var element = target.staticElement;
|
||||
if (element is ClassElement) {
|
||||
if (element is InterfaceElement) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,15 +36,15 @@ class AddAsync extends CorrectionProducer {
|
|||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
if (isForMissingReturn) {
|
||||
var parent = node.parent;
|
||||
final node = this.node;
|
||||
FunctionBody? body;
|
||||
DartType? returnType;
|
||||
if (parent is FunctionDeclaration) {
|
||||
body = parent.functionExpression.body;
|
||||
returnType = parent.declaredElement2!.returnType;
|
||||
} else if (parent is MethodDeclaration) {
|
||||
body = parent.body;
|
||||
returnType = parent.declaredElement2!.returnType;
|
||||
if (node is FunctionDeclaration) {
|
||||
body = node.functionExpression.body;
|
||||
returnType = node.declaredElement2!.returnType;
|
||||
} else if (node is MethodDeclaration) {
|
||||
body = node.body;
|
||||
returnType = node.declaredElement2!.returnType;
|
||||
}
|
||||
if (body == null || returnType == null) {
|
||||
return;
|
||||
|
|
|
@ -30,17 +30,16 @@ class AddCallSuper extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var node = this.node;
|
||||
if (node is! SimpleIdentifier) return;
|
||||
var methodDeclaration = node.thisOrAncestorOfType<MethodDeclaration>();
|
||||
if (methodDeclaration == null) return;
|
||||
final methodDeclaration = node;
|
||||
if (methodDeclaration is! MethodDeclaration) return;
|
||||
var classElement = methodDeclaration
|
||||
.thisOrAncestorOfType<ClassDeclaration>()
|
||||
?.declaredElement2;
|
||||
if (classElement == null) return;
|
||||
|
||||
var name = Name(classElement.library.source.uri, node.name);
|
||||
var overridden = InheritanceManager3().getInherited2(classElement, name);
|
||||
var name = methodDeclaration.name2.lexeme;
|
||||
var nameObj = Name(classElement.library.source.uri, name);
|
||||
var overridden = InheritanceManager3().getInherited2(classElement, nameObj);
|
||||
if (overridden == null) return;
|
||||
var overriddenParameters = overridden.parameters.map((p) => p.name);
|
||||
|
||||
|
@ -58,7 +57,7 @@ class AddCallSuper extends CorrectionProducer {
|
|||
.join(', ') ??
|
||||
'';
|
||||
|
||||
_addition = '${node.name}($argumentList)';
|
||||
_addition = '$name($argumentList)';
|
||||
|
||||
if (body is BlockFunctionBody) {
|
||||
await _block(builder, body);
|
||||
|
|
|
@ -34,7 +34,12 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
|
|||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final node = this.node;
|
||||
if (node is! SimpleIdentifier) {
|
||||
final String name;
|
||||
if (node is MethodDeclaration) {
|
||||
name = node.name2.lexeme;
|
||||
} else if (node is VariableDeclaration) {
|
||||
name = node.name2.lexeme;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -45,9 +50,7 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
|
||||
final parent = node.parent!;
|
||||
|
||||
var type = _getReturnType(parent);
|
||||
var type = _getReturnType(node);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -99,8 +102,8 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
|
|||
if (decl != null) {
|
||||
declType = decl.type;
|
||||
// getter
|
||||
} else if (parent is MethodDeclaration) {
|
||||
declType = parent.returnType;
|
||||
} else if (node is MethodDeclaration) {
|
||||
declType = node.returnType;
|
||||
}
|
||||
|
||||
if (declType != null) {
|
||||
|
@ -112,7 +115,7 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
|
|||
}
|
||||
}
|
||||
}
|
||||
builder.writeln("$constructorName('${node.name}', ${node.name}));");
|
||||
builder.writeln("$constructorName('$name', $name));");
|
||||
}
|
||||
|
||||
final debugFillProperties = classDeclaration.members
|
||||
|
|
|
@ -24,10 +24,10 @@ class AddKeyToConstructors extends CorrectionProducer {
|
|||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var node = this.node;
|
||||
var parent = node.parent;
|
||||
if (node is SimpleIdentifier && parent is ClassDeclaration) {
|
||||
if (node is ClassDeclaration) {
|
||||
// The lint is on the name of the class when there are no constructors.
|
||||
var targetLocation =
|
||||
utils.prepareNewConstructorLocation(resolvedResult.session, parent);
|
||||
utils.prepareNewConstructorLocation(resolvedResult.session, node);
|
||||
if (targetLocation == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ class AddKeyToConstructors extends CorrectionProducer {
|
|||
if (keyType == null) {
|
||||
return;
|
||||
}
|
||||
var className = node.name;
|
||||
var constructors = parent.declaredElement2?.supertype?.constructors;
|
||||
var className = node.name2.lexeme;
|
||||
var constructors = node.declaredElement2?.supertype?.constructors;
|
||||
if (constructors == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var canBeConst = _canBeConst(parent, constructors);
|
||||
var canBeConst = _canBeConst(node, constructors);
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addInsertion(targetLocation.offset, (builder) {
|
||||
builder.write(targetLocation.prefix);
|
||||
|
|
|
@ -22,11 +22,9 @@ class AddLate extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
final node = this.node;
|
||||
if (node is SimpleIdentifier) {
|
||||
var variable = node.parent;
|
||||
var variableList = variable?.parent;
|
||||
if (variable is VariableDeclaration &&
|
||||
variableList is VariableDeclarationList) {
|
||||
if (node is VariableDeclaration) {
|
||||
var variableList = node.parent;
|
||||
if (variableList is VariableDeclarationList) {
|
||||
if (!variableList.isLate) {
|
||||
if (variableList.type == null) {
|
||||
var keyword = variableList.keyword;
|
||||
|
@ -54,31 +52,31 @@ class AddLate extends CorrectionProducer {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var getter = node.writeOrReadElement;
|
||||
if (getter is PropertyAccessorElement &&
|
||||
getter.isGetter &&
|
||||
getter.isSynthetic &&
|
||||
!getter.variable.isSynthetic &&
|
||||
getter.variable.setter == null &&
|
||||
getter.enclosingElement3 is ClassElement) {
|
||||
var declarationResult =
|
||||
await sessionHelper.getElementDeclaration(getter.variable);
|
||||
if (declarationResult == null) {
|
||||
return;
|
||||
}
|
||||
var variable = declarationResult.node;
|
||||
var variableList = variable.parent;
|
||||
if (variable is VariableDeclaration &&
|
||||
variableList is VariableDeclarationList &&
|
||||
variableList.parent is FieldDeclaration) {
|
||||
var keywordToken = variableList.keyword;
|
||||
if (variableList.variables.length == 1 &&
|
||||
keywordToken != null &&
|
||||
keywordToken.keyword == Keyword.FINAL) {
|
||||
await _insertAt(builder, keywordToken.offset,
|
||||
source: declarationResult.element.source);
|
||||
}
|
||||
}
|
||||
} else if (node is SimpleIdentifier) {
|
||||
var getter = node.writeOrReadElement;
|
||||
if (getter is PropertyAccessorElement &&
|
||||
getter.isGetter &&
|
||||
getter.isSynthetic &&
|
||||
!getter.variable.isSynthetic &&
|
||||
getter.variable.setter == null &&
|
||||
getter.enclosingElement3 is InterfaceElement) {
|
||||
var declarationResult =
|
||||
await sessionHelper.getElementDeclaration(getter.variable);
|
||||
if (declarationResult == null) {
|
||||
return;
|
||||
}
|
||||
var variable = declarationResult.node;
|
||||
var variableList = variable.parent;
|
||||
if (variable is VariableDeclaration &&
|
||||
variableList is VariableDeclarationList &&
|
||||
variableList.parent is FieldDeclaration) {
|
||||
var keywordToken = variableList.keyword;
|
||||
if (variableList.variables.length == 1 &&
|
||||
keywordToken != null &&
|
||||
keywordToken.keyword == Keyword.FINAL) {
|
||||
await _insertAt(builder, keywordToken.offset,
|
||||
source: declarationResult.element.source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,7 @@ class AddNotNullAssert extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final identifier = node;
|
||||
if (identifier is! SimpleIdentifier) {
|
||||
return;
|
||||
}
|
||||
|
||||
var formalParameter = identifier.parent;
|
||||
final formalParameter = node;
|
||||
if (formalParameter is! FormalParameter) {
|
||||
return;
|
||||
}
|
||||
|
@ -48,7 +43,8 @@ class AddNotNullAssert extends CorrectionProducer {
|
|||
if (condition is BinaryExpression) {
|
||||
final leftOperand = condition.leftOperand;
|
||||
if (leftOperand is SimpleIdentifier) {
|
||||
if (leftOperand.staticElement == identifier.staticElement &&
|
||||
if (leftOperand.staticElement ==
|
||||
formalParameter.declaredElement &&
|
||||
condition.operator.type == TokenType.BANG_EQ &&
|
||||
condition.rightOperand is NullLiteral) {
|
||||
return;
|
||||
|
@ -60,7 +56,7 @@ class AddNotNullAssert extends CorrectionProducer {
|
|||
|
||||
final body_final = body;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
final id = identifier.name;
|
||||
final id = formalParameter.name!.lexeme;
|
||||
final prefix = utils.getNodePrefix(executable);
|
||||
final indent = utils.getIndent(1);
|
||||
// todo (pq): follow-ups:
|
||||
|
|
|
@ -25,25 +25,20 @@ class AddReturnNull extends CorrectionProducer {
|
|||
Future<void> compute(ChangeBuilder builder) async {
|
||||
Block block;
|
||||
|
||||
var coveringNode = coveredNode;
|
||||
if (coveringNode is Block) {
|
||||
block = coveringNode;
|
||||
} else if (coveringNode is SimpleIdentifier) {
|
||||
var declaration = coveringNode.parent;
|
||||
if (declaration is FunctionDeclaration) {
|
||||
var body = declaration.functionExpression.body;
|
||||
if (body is BlockFunctionBody) {
|
||||
block = body.block;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (declaration is MethodDeclaration) {
|
||||
var body = declaration.body;
|
||||
if (body is BlockFunctionBody) {
|
||||
block = body.block;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
final node = this.node;
|
||||
if (node is Block) {
|
||||
block = node;
|
||||
} else if (node is FunctionDeclaration) {
|
||||
var body = node.functionExpression.body;
|
||||
if (body is BlockFunctionBody) {
|
||||
block = body.block;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (node is MethodDeclaration) {
|
||||
var body = node.body;
|
||||
if (body is BlockFunctionBody) {
|
||||
block = body.block;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -35,33 +35,26 @@ class AddReturnType extends CorrectionProducer {
|
|||
Future<void> compute(ChangeBuilder builder) async {
|
||||
Token? insertBeforeEntity;
|
||||
FunctionBody? body;
|
||||
if (node is SimpleIdentifier) {
|
||||
var executable = node.parent;
|
||||
if (executable is MethodDeclaration && executable.name2 == token) {
|
||||
if (executable.returnType != null) {
|
||||
return;
|
||||
}
|
||||
if (executable.isSetter) {
|
||||
return;
|
||||
}
|
||||
insertBeforeEntity = executable.propertyKeyword ?? executable.name2;
|
||||
body = executable.body;
|
||||
} else if (executable is FunctionDeclaration &&
|
||||
executable.name2 == token) {
|
||||
if (executable.returnType != null) {
|
||||
return;
|
||||
}
|
||||
if (executable.isSetter) {
|
||||
return;
|
||||
}
|
||||
insertBeforeEntity = executable.propertyKeyword ?? executable.name2;
|
||||
body = executable.functionExpression.body;
|
||||
} else {
|
||||
final executable = node;
|
||||
if (executable is MethodDeclaration && executable.name2 == token) {
|
||||
if (executable.returnType != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (insertBeforeEntity == null || body == null) {
|
||||
if (executable.isSetter) {
|
||||
return;
|
||||
}
|
||||
insertBeforeEntity = executable.propertyKeyword ?? executable.name2;
|
||||
body = executable.body;
|
||||
} else if (executable is FunctionDeclaration && executable.name2 == token) {
|
||||
if (executable.returnType != null) {
|
||||
return;
|
||||
}
|
||||
if (executable.isSetter) {
|
||||
return;
|
||||
}
|
||||
insertBeforeEntity = executable.propertyKeyword ?? executable.name2;
|
||||
body = executable.functionExpression.body;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,12 +47,9 @@ class AddTypeAnnotation extends CorrectionProducer {
|
|||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final node = this.node;
|
||||
if (node is SimpleIdentifier) {
|
||||
var parent = node.parent;
|
||||
if (parent is SimpleFormalParameter) {
|
||||
await _forSimpleFormalParameter(builder, node, parent);
|
||||
return;
|
||||
}
|
||||
if (node is SimpleFormalParameter) {
|
||||
await _forSimpleFormalParameter(builder, node.name!, node);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var node in this.node.withParents) {
|
||||
|
@ -123,8 +120,8 @@ class AddTypeAnnotation extends CorrectionProducer {
|
|||
declaredIdentifier.name.offset, type);
|
||||
}
|
||||
|
||||
Future<void> _forSimpleFormalParameter(ChangeBuilder builder,
|
||||
SimpleIdentifier name, SimpleFormalParameter parameter) async {
|
||||
Future<void> _forSimpleFormalParameter(ChangeBuilder builder, Token name,
|
||||
SimpleFormalParameter parameter) async {
|
||||
// Ensure that there isn't already a type annotation.
|
||||
if (parameter.type != null) {
|
||||
return;
|
||||
|
|
|
@ -113,7 +113,7 @@ class ChangeTo extends CorrectionProducer {
|
|||
if (name != null) {
|
||||
// Prepare for selecting the closest element.
|
||||
var finder = _ClosestElementFinder(
|
||||
name, (Element element) => element is ClassElement);
|
||||
name, (Element element) => element is InterfaceElement);
|
||||
// Check elements of this library.
|
||||
if (prefixName == null) {
|
||||
for (var unit in resolvedResult.libraryElement.units) {
|
||||
|
@ -141,17 +141,17 @@ class ChangeTo extends CorrectionProducer {
|
|||
if (target == null) {
|
||||
var clazz = this.node.thisOrAncestorOfType<ClassDeclaration>();
|
||||
if (clazz != null) {
|
||||
var classElement = clazz.declaredElement2!;
|
||||
_updateFinderWithClassMembers(finder, classElement);
|
||||
var interfaceElement = clazz.declaredElement2!;
|
||||
_updateFinderWithClassMembers(finder, interfaceElement);
|
||||
}
|
||||
} else if (target is ExtensionOverride) {
|
||||
_updateFinderWithExtensionMembers(finder, target.staticElement);
|
||||
} else if (targetIdentifierElement is ExtensionElement) {
|
||||
_updateFinderWithExtensionMembers(finder, targetIdentifierElement);
|
||||
} else {
|
||||
var classElement = getTargetClassElement(target);
|
||||
if (classElement != null) {
|
||||
_updateFinderWithClassMembers(finder, classElement);
|
||||
var interfaceElement = getTargetInterfaceElement(target);
|
||||
if (interfaceElement != null) {
|
||||
_updateFinderWithClassMembers(finder, interfaceElement);
|
||||
}
|
||||
}
|
||||
// if we have close enough element, suggest to use it
|
||||
|
@ -268,17 +268,18 @@ class ChangeTo extends CorrectionProducer {
|
|||
}
|
||||
|
||||
Future<void> _proposeSuperFormalParameter(ChangeBuilder builder) async {
|
||||
var parent = node.parent;
|
||||
if (parent is! SuperFormalParameter) return;
|
||||
final superParameter = node;
|
||||
if (superParameter is! SuperFormalParameter) return;
|
||||
|
||||
var constructorDeclaration =
|
||||
parent.thisOrAncestorOfType<ConstructorDeclaration>();
|
||||
superParameter.thisOrAncestorOfType<ConstructorDeclaration>();
|
||||
if (constructorDeclaration == null) return;
|
||||
|
||||
var formalParameters = constructorDeclaration.parameters.parameters
|
||||
.whereType<DefaultFormalParameter>();
|
||||
|
||||
var finder = _ClosestElementFinder(parent.name.lexeme, (Element e) => true);
|
||||
var finder =
|
||||
_ClosestElementFinder(superParameter.name.lexeme, (Element e) => true);
|
||||
|
||||
var superInvocation = constructorDeclaration.initializers.lastOrNull;
|
||||
|
||||
|
@ -289,7 +290,8 @@ class ChangeTo extends CorrectionProducer {
|
|||
var list = _formalParameterSuggestions(staticElement, formalParameters);
|
||||
finder._updateList(list);
|
||||
} else {
|
||||
var targetClassNode = parent.thisOrAncestorOfType<ClassDeclaration>();
|
||||
var targetClassNode =
|
||||
superParameter.thisOrAncestorOfType<ClassDeclaration>();
|
||||
if (targetClassNode == null) return;
|
||||
|
||||
var targetClassElement = targetClassNode.declaredElement2!;
|
||||
|
@ -306,7 +308,7 @@ class ChangeTo extends CorrectionProducer {
|
|||
}
|
||||
|
||||
// If we have a close enough element, suggest to use it.
|
||||
await _suggest(builder, node, finder._element?.name);
|
||||
await _suggest(builder, superParameter.name, finder._element?.name);
|
||||
}
|
||||
|
||||
Future<void> _suggest(
|
||||
|
|
|
@ -45,7 +45,7 @@ class ChangeToStaticAccess extends CorrectionProducer {
|
|||
final target_final = target;
|
||||
var declaringElement = invokedElement.enclosingElement3;
|
||||
|
||||
if (declaringElement is ClassElement) {
|
||||
if (declaringElement is InterfaceElement) {
|
||||
_className = declaringElement.name;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addReplacement(range.node(target_final), (builder) {
|
||||
|
|
|
@ -51,9 +51,9 @@ class ConvertClassToEnum extends CorrectionProducer {
|
|||
// the class.
|
||||
return;
|
||||
}
|
||||
var parent = node.parent;
|
||||
if (parent is ClassDeclaration && parent.name2 == token) {
|
||||
var description = _EnumDescription.fromClass(parent);
|
||||
final declaration = node;
|
||||
if (declaration is ClassDeclaration && declaration.name2 == token) {
|
||||
var description = _EnumDescription.fromClass(declaration);
|
||||
if (description != null) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
description.applyChanges(builder, utils);
|
||||
|
|
|
@ -47,7 +47,7 @@ class ConvertIntoFinalField extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
var enclosing = element.enclosingElement3;
|
||||
if (enclosing is ClassElement) {
|
||||
if (enclosing is InterfaceElement) {
|
||||
if (enclosing.getSetter(element.name) != null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -88,18 +88,18 @@ class ConvertToFieldParameter extends CorrectionProducer {
|
|||
|
||||
static _Context? _findParameter(AstNode node) {
|
||||
var parent = node.parent;
|
||||
if (parent is SimpleFormalParameter) {
|
||||
var identifier = parent.name;
|
||||
if (node is SimpleFormalParameter) {
|
||||
var identifier = node.name;
|
||||
if (identifier == null) return null;
|
||||
|
||||
var formalParameterList = parent.parent;
|
||||
var formalParameterList = parent;
|
||||
if (formalParameterList is! FormalParameterList) return null;
|
||||
|
||||
var constructor = formalParameterList.parent;
|
||||
if (constructor is! ConstructorDeclaration) return null;
|
||||
|
||||
return _Context(
|
||||
parameter: parent,
|
||||
parameter: node,
|
||||
identifier: identifier,
|
||||
constructor: constructor,
|
||||
);
|
||||
|
|
|
@ -15,10 +15,7 @@ class ConvertToNormalParameter extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var identifier = node;
|
||||
if (identifier is! SimpleIdentifier) return;
|
||||
|
||||
var parameter = identifier.parent;
|
||||
var parameter = node;
|
||||
if (parameter is! FieldFormalParameter) return;
|
||||
|
||||
var parameterList = parameter.parent;
|
||||
|
@ -28,7 +25,7 @@ class ConvertToNormalParameter extends CorrectionProducer {
|
|||
if (constructor is! ConstructorDeclaration) return;
|
||||
|
||||
var parameterElement = parameter.declaredElement!;
|
||||
var name = identifier.name;
|
||||
var name = parameter.name.lexeme;
|
||||
var type = parameterElement.type;
|
||||
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
|
|
|
@ -19,14 +19,14 @@ class ConvertToOnType extends CorrectionProducer {
|
|||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var exceptionParameter = node;
|
||||
if (exceptionParameter is SimpleIdentifier) {
|
||||
var catchClause = exceptionParameter.parent?.parent;
|
||||
if (exceptionParameter is CatchClauseParameter) {
|
||||
var catchClause = exceptionParameter.parent;
|
||||
if (catchClause is CatchClause) {
|
||||
var catchKeyword = catchClause.catchKeyword;
|
||||
var rightParenthesis = catchClause.rightParenthesis;
|
||||
if (catchKeyword != null &&
|
||||
catchClause.exceptionType == null &&
|
||||
catchClause.exceptionParameter2?.name == exceptionParameter.token &&
|
||||
catchClause.exceptionParameter2 == exceptionParameter &&
|
||||
rightParenthesis != null) {
|
||||
var exceptionTypeName = exceptionParameter.name;
|
||||
fixArguments.add(exceptionTypeName);
|
||||
|
|
|
@ -298,6 +298,9 @@ class ConvertToSuperParameters extends CorrectionProducer {
|
|||
/// the name of a constructor.
|
||||
ConstructorDeclaration? _findConstructor() {
|
||||
final node = this.node;
|
||||
if (node is ConstructorDeclaration) {
|
||||
return node;
|
||||
}
|
||||
if (node is SimpleIdentifier) {
|
||||
var parent = node.parent;
|
||||
if (parent is ConstructorDeclaration) {
|
||||
|
|
|
@ -19,7 +19,7 @@ class CreateConstructorForFinalFields extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
if (node is! SimpleIdentifier || node.parent is! VariableDeclaration) {
|
||||
if (node is! VariableDeclaration) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class CreateField extends CorrectionProducer {
|
|||
var staticModifier = false;
|
||||
InterfaceElement? targetClassElement;
|
||||
if (target != null) {
|
||||
targetClassElement = getTargetClassElement(target);
|
||||
targetClassElement = getTargetInterfaceElement(target);
|
||||
// maybe static
|
||||
if (target is Identifier) {
|
||||
var targetIdentifier = target;
|
||||
|
|
|
@ -147,7 +147,7 @@ class CreateMethod extends CorrectionProducer {
|
|||
staticModifier = inStaticContext;
|
||||
}
|
||||
} else {
|
||||
var targetClassElement = getTargetClassElement(target);
|
||||
var targetClassElement = getTargetInterfaceElement(target);
|
||||
if (targetClassElement == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ class CreateMissingOverrides extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
if (node.parent is! ClassDeclaration) {
|
||||
final targetClass = node;
|
||||
if (targetClass is! ClassDeclaration) {
|
||||
return;
|
||||
}
|
||||
var targetClass = node.parent as ClassDeclaration;
|
||||
utils.targetClassElement = targetClass.declaredElement2;
|
||||
var signatures =
|
||||
InheritanceOverrideVerifier.missingOverrides(targetClass).toList();
|
||||
|
|
|
@ -14,10 +14,10 @@ class CreateNoSuchMethod extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
if (node.parent is! ClassDeclaration) {
|
||||
final targetClass = node;
|
||||
if (targetClass is! ClassDeclaration) {
|
||||
return;
|
||||
}
|
||||
var targetClass = node.parent as ClassDeclaration;
|
||||
// prepare environment
|
||||
var prefix = utils.getIndent(1);
|
||||
var insertOffset = targetClass.end - 1;
|
||||
|
|
|
@ -262,16 +262,20 @@ class _FieldFinder extends RecursiveAstVisitor<void> {
|
|||
Set<FieldElement> fieldsAssignedInConstructors = {};
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
if (node.parent is FieldFormalParameter) {
|
||||
var element = node.staticElement;
|
||||
if (element is FieldFormalParameterElement) {
|
||||
var field = element.field;
|
||||
if (field != null) {
|
||||
fieldsAssignedInConstructors.add(field);
|
||||
}
|
||||
void visitFieldFormalParameter(FieldFormalParameter node) {
|
||||
final element = node.declaredElement;
|
||||
if (element is FieldFormalParameterElement) {
|
||||
var field = element.field;
|
||||
if (field != null) {
|
||||
fieldsAssignedInConstructors.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitFieldFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
if (node.parent is ConstructorFieldInitializer) {
|
||||
var element = node.staticElement;
|
||||
if (element is FieldElement) {
|
||||
|
|
|
@ -31,10 +31,7 @@ class InlineTypedef extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var parent = node.parent;
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
final node = this.node;
|
||||
|
||||
//
|
||||
// Extract the information needed to build the edit.
|
||||
|
@ -42,21 +39,21 @@ class InlineTypedef extends CorrectionProducer {
|
|||
TypeAnnotation? returnType;
|
||||
TypeParameterList? typeParameters;
|
||||
List<FormalParameter> parameters;
|
||||
if (parent is FunctionTypeAlias) {
|
||||
returnType = parent.returnType;
|
||||
_name = parent.name2.lexeme;
|
||||
typeParameters = parent.typeParameters;
|
||||
parameters = parent.parameters.parameters;
|
||||
} else if (parent is GenericTypeAlias) {
|
||||
if (parent.typeParameters != null) {
|
||||
if (node is FunctionTypeAlias) {
|
||||
returnType = node.returnType;
|
||||
_name = node.name2.lexeme;
|
||||
typeParameters = node.typeParameters;
|
||||
parameters = node.parameters.parameters;
|
||||
} else if (node is GenericTypeAlias) {
|
||||
if (node.typeParameters != null) {
|
||||
return;
|
||||
}
|
||||
var functionType = parent.functionType;
|
||||
var functionType = node.functionType;
|
||||
if (functionType == null) {
|
||||
return;
|
||||
}
|
||||
returnType = functionType.returnType;
|
||||
_name = parent.name2.lexeme;
|
||||
_name = node.name2.lexeme;
|
||||
typeParameters = functionType.typeParameters;
|
||||
parameters = functionType.parameters.parameters;
|
||||
} else {
|
||||
|
@ -73,7 +70,7 @@ class InlineTypedef extends CorrectionProducer {
|
|||
// Build the edit.
|
||||
//
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addDeletion(utils.getLinesRange(range.node(parent)));
|
||||
builder.addDeletion(utils.getLinesRange(range.node(node)));
|
||||
builder.addReplacement(range.node(reference), (builder) {
|
||||
if (returnType != null) {
|
||||
builder.write(utils.getNodeText(returnType));
|
||||
|
|
|
@ -21,18 +21,15 @@ class MakeFieldPublic extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var node = this.node;
|
||||
if (node is! SimpleIdentifier) {
|
||||
final declaration = node;
|
||||
if (declaration is! MethodDeclaration) {
|
||||
return;
|
||||
}
|
||||
var getterName = node.name;
|
||||
var getterName = declaration.name2.lexeme;
|
||||
_fieldName = '_$getterName';
|
||||
var parent = node.parent;
|
||||
if (parent is MethodDeclaration &&
|
||||
parent.name2 == token &&
|
||||
parent.isGetter) {
|
||||
if (declaration.name2 == token && declaration.isGetter) {
|
||||
NodeList<ClassMember> members;
|
||||
var container = parent.parent;
|
||||
var container = declaration.parent;
|
||||
if (container is ClassDeclaration) {
|
||||
members = container.members;
|
||||
} else if (container is MixinDeclaration) {
|
||||
|
@ -61,7 +58,7 @@ class MakeFieldPublic extends CorrectionProducer {
|
|||
}
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(range.token(field!.name2), getterName);
|
||||
builder.removeMember(members, parent);
|
||||
builder.removeMember(members, declaration);
|
||||
builder.removeMember(members, setter!);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,18 +26,15 @@ class MakeFinal extends CorrectionProducer {
|
|||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final node = this.node;
|
||||
var parent = node.parent;
|
||||
var grandParent = parent?.parent;
|
||||
final parent = node.parent;
|
||||
|
||||
if (node is SimpleIdentifier &&
|
||||
parent is DeclaredIdentifier &&
|
||||
grandParent is ForEachPartsWithDeclaration) {
|
||||
if (node is DeclaredIdentifier && parent is ForEachPartsWithDeclaration) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
var keyword = parent.keyword;
|
||||
var keyword = node.keyword;
|
||||
if (keyword != null && keyword.keyword == Keyword.VAR) {
|
||||
builder.addSimpleReplacement(range.token(keyword), 'final');
|
||||
} else if (keyword == null) {
|
||||
builder.addSimpleInsertion(parent.offset, 'final ');
|
||||
builder.addSimpleInsertion(node.offset, 'final ');
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
@ -73,20 +70,15 @@ class MakeFinal extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
|
||||
if (node is SimpleIdentifier && parent is SimpleFormalParameter) {
|
||||
if (node is SimpleFormalParameter) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleInsertion(node.offset, 'final ');
|
||||
builder.addSimpleInsertion(node.name!.offset, 'final ');
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
VariableDeclarationList list;
|
||||
if (node is SimpleIdentifier &&
|
||||
parent is VariableDeclaration &&
|
||||
grandParent is VariableDeclarationList) {
|
||||
list = grandParent;
|
||||
} else if (node is VariableDeclaration &&
|
||||
parent is VariableDeclarationList) {
|
||||
if (node is VariableDeclaration && parent is VariableDeclarationList) {
|
||||
list = parent;
|
||||
} else if (node is VariableDeclarationList) {
|
||||
list = node;
|
||||
|
|
|
@ -33,8 +33,7 @@ class MakeVariableNotFinal extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
|
||||
var id = NodeLocator(variable.nameOffset).searchWithin(unit);
|
||||
var declaration = id?.parent;
|
||||
var declaration = NodeLocator(variable.nameOffset).searchWithin(unit);
|
||||
var declarationList = declaration?.parent;
|
||||
|
||||
if (declaration is VariableDeclaration &&
|
||||
|
|
|
@ -28,26 +28,24 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var node = coveredNode;
|
||||
var parent = node?.parent;
|
||||
final node = this.node;
|
||||
if (unit.featureSet.isEnabled(Feature.non_nullable)) {
|
||||
if (node is SimpleIdentifier && parent is SimpleFormalParameter) {
|
||||
await _forSimpleFormalParameter(builder, node, parent);
|
||||
} else if (node is SimpleIdentifier &&
|
||||
parent is FunctionTypedFormalParameter) {
|
||||
await _forFunctionTypedFormalParameter(builder, node, parent);
|
||||
} else if (node is SimpleIdentifier && parent is FieldFormalParameter) {
|
||||
await _forFieldFormalParameter(builder, node, parent);
|
||||
} else if (node is SimpleIdentifier && parent is SuperFormalParameter) {
|
||||
await _forSuperFormalParameter(builder, node, parent);
|
||||
} else if (node is Expression &&
|
||||
parent is AssignmentExpression &&
|
||||
parent.rightHandSide == node) {
|
||||
await _forAssignment(builder, node, parent);
|
||||
} else if (node is Expression &&
|
||||
parent is VariableDeclaration &&
|
||||
parent.initializer == node) {
|
||||
await _forVariableDeclaration(builder, node, parent);
|
||||
if (node is SimpleFormalParameter) {
|
||||
await _forSimpleFormalParameter(builder, node);
|
||||
} else if (node is FunctionTypedFormalParameter) {
|
||||
await _forFunctionTypedFormalParameter(builder, node);
|
||||
} else if (node is FieldFormalParameter) {
|
||||
await _forFieldFormalParameter(builder, node);
|
||||
} else if (node is SuperFormalParameter) {
|
||||
await _forSuperFormalParameter(builder, node);
|
||||
} else if (node is Expression) {
|
||||
final parent = node.parent;
|
||||
if (parent is AssignmentExpression && parent.rightHandSide == node) {
|
||||
await _forAssignment(builder, node, parent);
|
||||
} else if (parent is VariableDeclaration &&
|
||||
parent.initializer == node) {
|
||||
await _forVariableDeclaration(builder, node, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,8 +109,8 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
}
|
||||
|
||||
/// Makes [parameter] nullable if possible.
|
||||
Future<void> _forFieldFormalParameter(ChangeBuilder builder,
|
||||
SimpleIdentifier name, FieldFormalParameter parameter) async {
|
||||
Future<void> _forFieldFormalParameter(
|
||||
ChangeBuilder builder, FieldFormalParameter parameter) async {
|
||||
if (parameter.parameters != null) {
|
||||
// A function-typed field formal parameter.
|
||||
if (parameter.question != null) {
|
||||
|
@ -136,8 +134,8 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
}
|
||||
|
||||
/// Makes [parameter] nullable if possible.
|
||||
Future<void> _forFunctionTypedFormalParameter(ChangeBuilder builder,
|
||||
SimpleIdentifier name, FunctionTypedFormalParameter parameter) async {
|
||||
Future<void> _forFunctionTypedFormalParameter(
|
||||
ChangeBuilder builder, FunctionTypedFormalParameter parameter) async {
|
||||
if (parameter.question != null) {
|
||||
return;
|
||||
}
|
||||
|
@ -148,8 +146,8 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> _forSimpleFormalParameter(ChangeBuilder builder,
|
||||
SimpleIdentifier name, SimpleFormalParameter parameter) async {
|
||||
Future<void> _forSimpleFormalParameter(
|
||||
ChangeBuilder builder, SimpleFormalParameter parameter) async {
|
||||
var type = parameter.type;
|
||||
if (type == null || !_typeCanBeMadeNullable(type)) {
|
||||
return;
|
||||
|
@ -167,8 +165,8 @@ class MakeVariableNullable extends CorrectionProducer {
|
|||
}
|
||||
|
||||
/// Makes [parameter] nullable if possible.
|
||||
Future<void> _forSuperFormalParameter(ChangeBuilder builder,
|
||||
SimpleIdentifier name, SuperFormalParameter parameter) async {
|
||||
Future<void> _forSuperFormalParameter(
|
||||
ChangeBuilder builder, SuperFormalParameter parameter) async {
|
||||
if (parameter.parameters != null) {
|
||||
// A function-typed field formal parameter.
|
||||
if (parameter.question != null) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
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/element/element.dart';
|
||||
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
||||
import 'package:analyzer/source/source_range.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
|
@ -37,16 +38,24 @@ class RemoveAbstract extends CorrectionProducerWithDiagnostic {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var node = this.node;
|
||||
if (node is SimpleIdentifier) {
|
||||
await _compute(node, builder);
|
||||
final node = this.node;
|
||||
final parent = node.parent;
|
||||
final classDeclaration = node.thisOrAncestorOfType<ClassDeclaration>();
|
||||
if (node is VariableDeclaration) {
|
||||
await _compute(classDeclaration, node.declaredElement2, builder);
|
||||
} else if (node is SimpleIdentifier &&
|
||||
parent is ConstructorFieldInitializer) {
|
||||
await _compute(classDeclaration, node.staticElement, builder);
|
||||
} else if (node is CompilationUnitMember) {
|
||||
await _computeAbstractClassMember(builder);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _compute(SimpleIdentifier node, ChangeBuilder builder) async {
|
||||
var classDeclaration = node.thisOrAncestorOfType<ClassDeclaration>();
|
||||
Future<void> _compute(
|
||||
ClassDeclaration? classDeclaration,
|
||||
Element? fieldElement,
|
||||
ChangeBuilder builder,
|
||||
) async {
|
||||
if (classDeclaration == null) return;
|
||||
|
||||
for (var member in classDeclaration.members) {
|
||||
|
@ -59,7 +68,7 @@ class RemoveAbstract extends CorrectionProducerWithDiagnostic {
|
|||
continue;
|
||||
}
|
||||
for (var variable in variables) {
|
||||
if (variable.declaredElement2 == node.staticElement) {
|
||||
if (variable.declaredElement2 == fieldElement) {
|
||||
var abstractKeyword = member.abstractKeyword;
|
||||
if (abstractKeyword != null) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
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/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:analyzer_plugin/utilities/range_factory.dart';
|
||||
|
@ -55,15 +54,12 @@ class RemoveAnnotation extends CorrectionProducer {
|
|||
await addFix(findAnnotation(node.parameter.metadata, 'required'));
|
||||
} else if (node is NormalFormalParameter) {
|
||||
await addFix(findAnnotation(node.metadata, 'required'));
|
||||
} else if (node is DeclaredSimpleIdentifier) {
|
||||
var parent = node.parent;
|
||||
if (parent is MethodDeclaration) {
|
||||
await addFix(findAnnotation(parent.metadata, 'override'));
|
||||
} else if (parent is VariableDeclaration) {
|
||||
var fieldDeclaration = parent.thisOrAncestorOfType<FieldDeclaration>();
|
||||
if (fieldDeclaration != null) {
|
||||
await addFix(findAnnotation(fieldDeclaration.metadata, 'override'));
|
||||
}
|
||||
} else if (node is MethodDeclaration) {
|
||||
await addFix(findAnnotation(node.metadata, 'override'));
|
||||
} else if (node is VariableDeclaration) {
|
||||
var fieldDeclaration = node.thisOrAncestorOfType<FieldDeclaration>();
|
||||
if (fieldDeclaration != null) {
|
||||
await addFix(findAnnotation(fieldDeclaration.metadata, 'override'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,13 +24,17 @@ class RemoveConstructorName extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final identifier = node;
|
||||
if (identifier is! SimpleIdentifier) return;
|
||||
|
||||
// The '.' in ".new"
|
||||
var dotToken = identifier.token.previous!;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addDeletion(range.startStart(dotToken, identifier.token.next!));
|
||||
});
|
||||
final node = this.node;
|
||||
if (node is ConstructorDeclaration) {
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addDeletion(range.startStart(node.period!, node.name2!.next!));
|
||||
});
|
||||
} else if (node is SimpleIdentifier) {
|
||||
// The '.' in ".new"
|
||||
var dotToken = node.token.previous!;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addDeletion(range.startStart(dotToken, node.token.next!));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
|
@ -26,21 +27,35 @@ class RemoveLeadingUnderscore extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var identifier = node;
|
||||
if (identifier is! SimpleIdentifier) {
|
||||
final node = this.node;
|
||||
final Token? nameToken;
|
||||
final Element? element;
|
||||
if (node is SimpleIdentifier) {
|
||||
nameToken = node.token;
|
||||
element = node.staticElement;
|
||||
} else if (node is FormalParameter) {
|
||||
nameToken = node.name;
|
||||
element = node.declaredElement;
|
||||
} else if (node is VariableDeclaration) {
|
||||
nameToken = node.name2;
|
||||
element = node.declaredElement2;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
var name = identifier.name;
|
||||
if (name.length < 2) {
|
||||
if (nameToken == null || element == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var newName = name.substring(1);
|
||||
final oldName = nameToken.lexeme;
|
||||
if (oldName.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
var newName = oldName.substring(1);
|
||||
|
||||
// Find references to the identifier.
|
||||
List<SimpleIdentifier>? references;
|
||||
var element = identifier.staticElement;
|
||||
if (element is LocalVariableElement) {
|
||||
var root = node.thisOrAncestorOfType<Block>();
|
||||
if (root != null) {
|
||||
|
@ -68,10 +83,13 @@ class RemoveLeadingUnderscore extends CorrectionProducer {
|
|||
}
|
||||
|
||||
// Compute the change.
|
||||
var references_final = references;
|
||||
final sourceRanges = {
|
||||
range.token(nameToken),
|
||||
...references.map(range.node),
|
||||
};
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
for (var reference in references_final) {
|
||||
builder.addSimpleReplacement(range.node(reference), newName);
|
||||
for (var sourceRange in sourceRanges) {
|
||||
builder.addSimpleReplacement(sourceRange, newName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ class RemoveRequired extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var parent = node.parent;
|
||||
if (parent is! FormalParameter) return;
|
||||
final node = this.node;
|
||||
if (node is! FormalParameter) return;
|
||||
|
||||
var required = parent.requiredKeyword;
|
||||
var required = node.requiredKeyword;
|
||||
if (required == null) return;
|
||||
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
|
|
|
@ -24,7 +24,7 @@ class RemoveUnnecessaryLate extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final declaration = node.parent;
|
||||
final declaration = node;
|
||||
if (declaration is! VariableDeclaration) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -30,11 +30,7 @@ class RemoveUnusedElement extends _RemoveUnused {
|
|||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final sourceRanges = <SourceRange>[];
|
||||
|
||||
final referencedNode = node.parent;
|
||||
if (referencedNode == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final referencedNode = node;
|
||||
if (referencedNode is ClassDeclaration ||
|
||||
referencedNode is EnumDeclaration ||
|
||||
referencedNode is FunctionDeclaration ||
|
||||
|
@ -46,7 +42,7 @@ class RemoveUnusedElement extends _RemoveUnused {
|
|||
: (referencedNode as NamedCompilationUnitMember).declaredElement2!;
|
||||
final references = _findAllReferences(unit, element);
|
||||
// todo (pq): consider filtering for references that are limited to within the class.
|
||||
if (references.length == 1) {
|
||||
if (references.isEmpty) {
|
||||
var parent = referencedNode.parent;
|
||||
var grandParent = parent?.parent;
|
||||
SourceRange sourceRange;
|
||||
|
@ -87,7 +83,7 @@ class RemoveUnusedField extends _RemoveUnused {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final declaration = node.parent;
|
||||
final declaration = node;
|
||||
if (declaration is! VariableDeclaration) {
|
||||
return;
|
||||
}
|
||||
|
@ -98,7 +94,10 @@ class RemoveUnusedField extends _RemoveUnused {
|
|||
}
|
||||
|
||||
final sourceRanges = <SourceRange>[];
|
||||
final references = _findAllReferences(unit, element);
|
||||
final references = [
|
||||
node,
|
||||
..._findAllReferences(unit, element),
|
||||
];
|
||||
for (var reference in references) {
|
||||
// todo (pq): consider scoping this to parent or parent.parent.
|
||||
final referenceNode = reference.thisOrAncestorMatching((node) =>
|
||||
|
@ -217,10 +216,22 @@ class RemoveUnusedField extends _RemoveUnused {
|
|||
|
||||
class _ElementReferenceCollector extends RecursiveAstVisitor<void> {
|
||||
final Element element;
|
||||
final List<SimpleIdentifier> references = [];
|
||||
final List<AstNode> references = [];
|
||||
|
||||
_ElementReferenceCollector(this.element);
|
||||
|
||||
@override
|
||||
void visitFieldFormalParameter(FieldFormalParameter node) {
|
||||
final declaredElement = node.declaredElement;
|
||||
if (declaredElement is FieldFormalParameterElement) {
|
||||
if (declaredElement.field == element) {
|
||||
references.add(node);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitFieldFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
final staticElement = node.writeOrReadElement;
|
||||
|
@ -239,7 +250,7 @@ class _ElementReferenceCollector extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
|
||||
abstract class _RemoveUnused extends CorrectionProducer {
|
||||
List<SimpleIdentifier> _findAllReferences(AstNode root, Element element) {
|
||||
List<AstNode> _findAllReferences(AstNode root, Element element) {
|
||||
var collector = _ElementReferenceCollector(element);
|
||||
root.accept(collector);
|
||||
return collector.references;
|
||||
|
|
|
@ -24,7 +24,7 @@ class RemoveUnusedCatchClause extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final exceptionParameter = node.parent;
|
||||
final exceptionParameter = node;
|
||||
if (exceptionParameter is! CatchClauseParameter) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class RemoveUnusedCatchStack extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final stackTraceParameter = node.parent;
|
||||
final stackTraceParameter = node;
|
||||
if (stackTraceParameter is! CatchClauseParameter) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -26,24 +26,28 @@ class RemoveUnusedLocalVariable extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final declaration = node.parent;
|
||||
if (!(declaration is VariableDeclaration && declaration.name2 == token)) {
|
||||
final node = this.node;
|
||||
if (!(node is VariableDeclaration && node.name2 == token)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var element = declaration.declaredElement2;
|
||||
var element = node.declaredElement2;
|
||||
if (element is! LocalVariableElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
final sourceRanges = <SourceRange>[];
|
||||
|
||||
final functionBody = declaration.thisOrAncestorOfType<FunctionBody>();
|
||||
final functionBody = node.thisOrAncestorOfType<FunctionBody>();
|
||||
if (functionBody == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final references = findLocalElementReferences(functionBody, element);
|
||||
final references = [
|
||||
node,
|
||||
...findLocalElementReferences(functionBody, element),
|
||||
];
|
||||
|
||||
for (var reference in references) {
|
||||
final node = reference.thisOrAncestorMatching((node) =>
|
||||
node is VariableDeclaration || node is AssignmentExpression);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
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/change_builder/change_builder_core.dart';
|
||||
|
@ -23,7 +24,7 @@ class RenameMethodParameter extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
final parameter = node.parent;
|
||||
final parameter = node;
|
||||
if (parameter is! FormalParameter) return;
|
||||
var paramIdentifier = parameter.name;
|
||||
if (paramIdentifier == null) return;
|
||||
|
@ -35,7 +36,7 @@ class RenameMethodParameter extends CorrectionProducer {
|
|||
|
||||
var classDeclaration = method.parent as Declaration;
|
||||
var classElement = classDeclaration.declaredElement2;
|
||||
if (classElement is! ClassElement) return;
|
||||
if (classElement is! InterfaceElement) return;
|
||||
|
||||
var parentMethod = classElement.lookUpInheritedMethod(
|
||||
method.name2.lexeme, classElement.library);
|
||||
|
@ -57,8 +58,8 @@ class RenameMethodParameter extends CorrectionProducer {
|
|||
_newName = newName;
|
||||
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
for (var i in collector.oldIdentifiers) {
|
||||
builder.addSimpleReplacement(range.node(i), newName);
|
||||
for (var token in collector.oldTokens) {
|
||||
builder.addSimpleReplacement(range.token(token), newName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -67,23 +68,40 @@ class RenameMethodParameter extends CorrectionProducer {
|
|||
}
|
||||
|
||||
class _Collector extends RecursiveAstVisitor<void> {
|
||||
var error = false;
|
||||
bool error = false;
|
||||
final String newName;
|
||||
final ParameterElement target;
|
||||
|
||||
final oldIdentifiers = <SimpleIdentifier>[];
|
||||
final oldTokens = <Token>[];
|
||||
|
||||
_Collector(this.newName, this.target);
|
||||
|
||||
@override
|
||||
void visitSimpleFormalParameter(SimpleFormalParameter node) {
|
||||
_addNameToken(node.name, node.declaredElement);
|
||||
super.visitSimpleFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
_addNameToken(node.token, node.staticElement);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
_addNameToken(node.name2, node.declaredElement2);
|
||||
super.visitVariableDeclaration(node);
|
||||
}
|
||||
|
||||
void _addNameToken(Token? nameToken, Element? element) {
|
||||
if (error) return;
|
||||
|
||||
var nodeElement = node.staticElement;
|
||||
if (nodeElement == target) {
|
||||
oldIdentifiers.add(node);
|
||||
} else if (node.name == newName) {
|
||||
error = true;
|
||||
if (nameToken != null) {
|
||||
if (element == target) {
|
||||
oldTokens.add(nameToken);
|
||||
} else if (nameToken.lexeme == newName) {
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:analysis_server/src/services/correction/fix.dart';
|
|||
import 'package:analysis_server/src/services/correction/util.dart';
|
||||
import 'package:analysis_server/src/utilities/extensions/string.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_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
|
@ -33,13 +34,22 @@ class RenameToCamelCase extends CorrectionProducer {
|
|||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var identifier = node;
|
||||
if (identifier is! SimpleIdentifier) {
|
||||
Token? nameToken;
|
||||
Element? element;
|
||||
final node = this.node;
|
||||
if (node is SimpleFormalParameter) {
|
||||
nameToken = node.name;
|
||||
element = node.declaredElement;
|
||||
} else if (node is VariableDeclaration) {
|
||||
nameToken = node.name2;
|
||||
element = node.declaredElement2;
|
||||
}
|
||||
if (nameToken == null || element == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare the new name.
|
||||
var newName = identifier.name.toLowerCamelCase;
|
||||
var newName = nameToken.lexeme.toLowerCamelCase;
|
||||
if (newName == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -47,7 +57,6 @@ class RenameToCamelCase extends CorrectionProducer {
|
|||
|
||||
// Find references to the identifier.
|
||||
List<SimpleIdentifier>? references;
|
||||
var element = identifier.staticElement;
|
||||
if (element is LocalVariableElement) {
|
||||
var root = node.thisOrAncestorOfType<Block>();
|
||||
if (root != null) {
|
||||
|
@ -70,10 +79,13 @@ class RenameToCamelCase extends CorrectionProducer {
|
|||
}
|
||||
|
||||
// Compute the change.
|
||||
var references_final = references;
|
||||
final sourceRanges = {
|
||||
range.token(nameToken),
|
||||
...references.map(range.node),
|
||||
};
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
for (var reference in references_final) {
|
||||
builder.addSimpleReplacement(range.node(reference), _newName);
|
||||
for (var sourceRange in sourceRanges) {
|
||||
builder.addSimpleReplacement(sourceRange, _newName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class ShadowField extends CorrectionProducer {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!accessor.isGetter || accessor.enclosingElement3 is! ClassElement) {
|
||||
if (!accessor.isGetter || accessor.enclosingElement3 is! InterfaceElement) {
|
||||
// TODO(brianwilkerson) Should we also require that the getter be synthetic?
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -77,17 +77,17 @@ class AddTypeParameter extends Change<_Data> {
|
|||
return null;
|
||||
}
|
||||
return _TypeArgumentData(typeArguments, parent.argumentList.offset);
|
||||
} else if (parent is MethodDeclaration) {
|
||||
} else if (node is MethodDeclaration) {
|
||||
// invalid_override
|
||||
final extendedType = this.extendedType;
|
||||
if (extendedType != null && !extendedType.validate(context)) {
|
||||
return null;
|
||||
}
|
||||
var typeParameters = parent.typeParameters;
|
||||
var typeParameters = node.typeParameters;
|
||||
if (_isInvalidIndex(typeParameters?.typeParameters)) {
|
||||
return null;
|
||||
}
|
||||
return _TypeParameterData(typeParameters, parent.name2.end);
|
||||
return _TypeParameterData(typeParameters, node.name2.end);
|
||||
} else if (node is TypeArgumentList && parent is ExtensionOverride) {
|
||||
// wrong_number_of_type_arguments_extension
|
||||
if (!argumentValue.validate(context)) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/element_kind.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart' show ClassElement;
|
||||
import 'package:analyzer/dart/element/element.dart' show InterfaceElement;
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
|
||||
/// A description of an element.
|
||||
|
@ -143,8 +143,8 @@ class ElementDescriptor {
|
|||
var type = target.staticType;
|
||||
if (type == null && target is SimpleIdentifier) {
|
||||
var element = target.staticElement;
|
||||
// TODO(brianwilkerson) Handle more than `ClassElement`.
|
||||
if (element is ClassElement) {
|
||||
// TODO(brianwilkerson) Handle more than `InterfaceElement`.
|
||||
if (element is InterfaceElement) {
|
||||
type = element.thisType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'package:analysis_server/src/services/correction/fix/data_driven/element_
|
|||
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;
|
||||
show ExtensionElement, InterfaceElement, PrefixElement;
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
|
||||
/// An object that can be used to determine whether an element is appropriate
|
||||
|
@ -151,6 +151,8 @@ class _MatcherBuilder {
|
|||
_buildFromBinaryExpression(node);
|
||||
} else if (node is ConstructorName) {
|
||||
_buildFromConstructorName(node);
|
||||
} else if (node is FunctionDeclaration) {
|
||||
_addMatcher(components: [node.name2.lexeme], kinds: []);
|
||||
} else if (node is Literal) {
|
||||
var parent = node.parent;
|
||||
if (parent is ArgumentList) {
|
||||
|
@ -160,10 +162,14 @@ class _MatcherBuilder {
|
|||
_buildFromNamedType(node);
|
||||
} else if (node is PrefixedIdentifier) {
|
||||
_buildFromPrefixedIdentifier(node);
|
||||
} else if (node is MethodDeclaration) {
|
||||
_buildFromMethodDeclaration(node);
|
||||
} else if (node is SimpleIdentifier && nameToken != null) {
|
||||
_buildFromSimpleIdentifier(node, nameToken);
|
||||
} else if (node is TypeArgumentList) {
|
||||
_buildFromTypeArgumentList(node);
|
||||
} else if (node is VariableDeclaration) {
|
||||
_addMatcher(components: [node.name2.lexeme], kinds: []);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -395,7 +401,7 @@ class _MatcherBuilder {
|
|||
// It looks like we're accessing a member, but we don't know what kind of
|
||||
// member, so we include all of the member kinds.
|
||||
var container = node.prefix.staticElement;
|
||||
if (container is ClassElement) {
|
||||
if (container is InterfaceElement) {
|
||||
_addMatcher(
|
||||
components: [node.identifier.name, container.name],
|
||||
kinds: const [
|
||||
|
@ -504,7 +510,7 @@ class _MatcherBuilder {
|
|||
}
|
||||
if (element != null) {
|
||||
var enclosingElement = element.enclosingElement3;
|
||||
if (enclosingElement is ClassElement) {
|
||||
if (enclosingElement is InterfaceElement) {
|
||||
return [identifier.name, enclosingElement.name];
|
||||
} else if (enclosingElement is ExtensionElement) {
|
||||
var name = enclosingElement.name;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analysis_server/src/services/correction/dart/data_driven.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/change.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart';
|
||||
import 'package:analyzer_plugin/utilities/range_factory.dart';
|
||||
|
||||
|
@ -22,34 +23,35 @@ class Rename extends Change<_Data> {
|
|||
// the super-method and the class's super-class.
|
||||
// ignore: library_private_types_in_public_api
|
||||
void apply(DartFileEditBuilder builder, DataDrivenFix fix, _Data data) {
|
||||
var nameNode = data.nameNode;
|
||||
var nameToken = data.nameToken;
|
||||
if (fix.element.isConstructor) {
|
||||
var parent = nameNode?.parent;
|
||||
if (parent is ConstructorName) {
|
||||
if (nameNode != null && newName.isEmpty) {
|
||||
final node = data.node;
|
||||
final parent = node.parent;
|
||||
if (node is ConstructorName) {
|
||||
if (nameToken != null && newName.isEmpty) {
|
||||
// The constructor was renamed from a named constructor to an unnamed
|
||||
// constructor.
|
||||
builder.addDeletion(range.startEnd(parent.period!, parent));
|
||||
} else if (nameNode == null && newName.isNotEmpty) {
|
||||
builder.addDeletion(range.startEnd(node.period!, node));
|
||||
} else if (nameToken == null && newName.isNotEmpty) {
|
||||
// The constructor was renamed from an unnamed constructor to a named
|
||||
// constructor.
|
||||
builder.addSimpleInsertion(parent.end, '.$newName');
|
||||
} else if (nameNode != null) {
|
||||
builder.addSimpleInsertion(node.end, '.$newName');
|
||||
} else if (nameToken != null) {
|
||||
// The constructor was renamed from a named constructor to another
|
||||
// named constructor.
|
||||
builder.addSimpleReplacement(range.node(nameNode), newName);
|
||||
builder.addSimpleReplacement(range.token(nameToken), newName);
|
||||
}
|
||||
} else if (nameNode == null) {
|
||||
} else if (nameToken == null) {
|
||||
return;
|
||||
} else if (parent is MethodInvocation) {
|
||||
if (newName.isEmpty) {
|
||||
// The constructor was renamed from a named constructor to an unnamed
|
||||
// constructor.
|
||||
builder.addDeletion(range.startEnd(parent.operator!, nameNode));
|
||||
builder.addDeletion(range.startEnd(parent.operator!, nameToken));
|
||||
} else {
|
||||
// The constructor was renamed from a named constructor to another
|
||||
// named constructor.
|
||||
builder.addSimpleReplacement(range.node(nameNode), newName);
|
||||
builder.addSimpleReplacement(range.token(nameToken), newName);
|
||||
}
|
||||
} else if (parent is NamedType && parent.parent is ConstructorName) {
|
||||
// The constructor was renamed from an unnamed constructor to a named
|
||||
|
@ -62,11 +64,11 @@ class Rename extends Change<_Data> {
|
|||
} else {
|
||||
// The constructor was renamed from a named constructor to another named
|
||||
// constructor.
|
||||
builder.addSimpleReplacement(range.node(nameNode), newName);
|
||||
builder.addSimpleReplacement(range.token(nameToken), newName);
|
||||
}
|
||||
} else if (nameNode != null) {
|
||||
} else if (nameToken != null) {
|
||||
// The name is a simple identifier.
|
||||
builder.addSimpleReplacement(range.node(nameNode), newName);
|
||||
builder.addSimpleReplacement(range.token(nameToken), newName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +78,9 @@ class Rename extends Change<_Data> {
|
|||
// ignore: library_private_types_in_public_api
|
||||
_Data? validate(DataDrivenFix fix) {
|
||||
var node = fix.node;
|
||||
if (node is SimpleIdentifier) {
|
||||
if (node is MethodDeclaration) {
|
||||
return _Data(node, node.name2);
|
||||
} else if (node is SimpleIdentifier) {
|
||||
var parent = node.parent;
|
||||
var grandParent = parent?.parent;
|
||||
if (parent is Label && grandParent is NamedExpression) {
|
||||
|
@ -84,15 +88,15 @@ class Rename extends Change<_Data> {
|
|||
if (invocation is InstanceCreationExpression) {
|
||||
invocation.constructorName.name;
|
||||
} else if (invocation is MethodInvocation) {
|
||||
return _Data(invocation.methodName);
|
||||
return _Data(node, invocation.methodName.token);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return _Data(node);
|
||||
return _Data(node, node.token);
|
||||
} else if (node is ConstructorName) {
|
||||
return _Data(node.name);
|
||||
return _Data(node, node.name?.token);
|
||||
} else if (node is PrefixedIdentifier) {
|
||||
return _Data(node.identifier);
|
||||
return _Data(node.identifier, node.identifier.token);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -100,7 +104,8 @@ class Rename extends Change<_Data> {
|
|||
|
||||
/// The data renaming a declaration.
|
||||
class _Data {
|
||||
final SimpleIdentifier? nameNode;
|
||||
final AstNode node;
|
||||
final Token? nameToken;
|
||||
|
||||
_Data(this.nameNode);
|
||||
_Data(this.node, this.nameToken);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,9 @@ class RenameParameter extends Change<_Data> {
|
|||
// ignore: library_private_types_in_public_api
|
||||
_Data validate(DataDrivenFix fix) {
|
||||
var node = fix.node;
|
||||
if (node is SimpleIdentifier) {
|
||||
if (node is MethodDeclaration) {
|
||||
return _OverrideData(node);
|
||||
} else if (node is SimpleIdentifier) {
|
||||
var parent = node.parent;
|
||||
var grandParent = parent?.parent;
|
||||
if (node.name == oldName &&
|
||||
|
@ -80,8 +82,6 @@ class RenameParameter extends Change<_Data> {
|
|||
if (invocation != null && fix.element.matches(invocation)) {
|
||||
return _InvocationData(node);
|
||||
}
|
||||
} else if (parent is MethodDeclaration) {
|
||||
return _OverrideData(parent);
|
||||
}
|
||||
}
|
||||
return const _IgnoredData();
|
||||
|
@ -123,7 +123,7 @@ extension on MethodDeclaration {
|
|||
var element = declaredElement2;
|
||||
if (element != null) {
|
||||
var enclosingElement = element.enclosingElement3;
|
||||
if (enclosingElement is ClassElement) {
|
||||
if (enclosingElement is InterfaceElement) {
|
||||
var name = Name(enclosingElement.library.source.uri, element.name);
|
||||
return InheritanceManager3().getInherited2(enclosingElement, name);
|
||||
}
|
||||
|
|
|
@ -1466,6 +1466,12 @@ class _CollectReferencedUnprefixedNames extends RecursiveAstVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
visitVariableDeclaration(VariableDeclaration node) {
|
||||
names.add(node.name2.lexeme);
|
||||
return super.visitVariableDeclaration(node);
|
||||
}
|
||||
|
||||
static bool _isPrefixed(SimpleIdentifier node) {
|
||||
var parent = node.parent;
|
||||
return parent is ConstructorName && parent.name == node ||
|
||||
|
@ -1541,13 +1547,13 @@ class _LocalElementsCollector extends RecursiveAstVisitor<void> {
|
|||
final elements = <LocalElement>[];
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
if (node.inDeclarationContext()) {
|
||||
var element = node.staticElement;
|
||||
if (element is LocalElement) {
|
||||
elements.add(element);
|
||||
}
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
final element = node.declaredElement2;
|
||||
if (element is LocalVariableElement) {
|
||||
elements.add(element);
|
||||
}
|
||||
|
||||
super.visitVariableDeclaration(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,11 +108,15 @@ class PropertyDescription {
|
|||
|
||||
var builder = ChangeBuilder(session: resolvedUnit.session);
|
||||
|
||||
ClassElement? enumClassElement;
|
||||
InterfaceElement? enumElement;
|
||||
var enumValue = value.enumValue;
|
||||
if (enumValue != null) {
|
||||
var helper = AnalysisSessionHelper(resolvedUnit.session);
|
||||
enumClassElement = await helper.getClass(
|
||||
enumElement = await helper.getClass(
|
||||
enumValue.libraryUri,
|
||||
enumValue.className,
|
||||
);
|
||||
enumElement ??= await helper.getEnum(
|
||||
enumValue.libraryUri,
|
||||
enumValue.className,
|
||||
);
|
||||
|
@ -123,8 +127,8 @@ class PropertyDescription {
|
|||
var expression = value.expression;
|
||||
if (expression != null) {
|
||||
builder.write(expression);
|
||||
} else if (enumClassElement != null && enumValue != null) {
|
||||
builder.writeReference(enumClassElement);
|
||||
} else if (enumElement != null && enumValue != null) {
|
||||
builder.writeReference(enumElement);
|
||||
builder.write('.');
|
||||
builder.write(enumValue.name);
|
||||
} else {
|
||||
|
|
|
@ -520,13 +520,13 @@ class _WidgetDescriptionComputer {
|
|||
}
|
||||
|
||||
protocol.FlutterWidgetPropertyValueEnumItem _toEnumItem(FieldElement field) {
|
||||
var classElement = field.enclosingElement3 as ClassElement;
|
||||
var libraryUriStr = '${classElement.library.source.uri}';
|
||||
var interfaceElement = field.enclosingElement3 as InterfaceElement;
|
||||
var libraryUriStr = '${interfaceElement.library.source.uri}';
|
||||
var documentation = getFieldDocumentation(field);
|
||||
|
||||
return protocol.FlutterWidgetPropertyValueEnumItem(
|
||||
libraryUriStr,
|
||||
classElement.name,
|
||||
interfaceElement.name,
|
||||
field.name,
|
||||
documentation: documentation,
|
||||
);
|
||||
|
@ -546,7 +546,7 @@ class _WidgetDescriptionComputer {
|
|||
if (element is PropertyAccessorElement && element.isGetter) {
|
||||
var field = element.variable;
|
||||
if (field is FieldElement && field.isStatic) {
|
||||
var enclosingClass = field.enclosingElement3 as ClassElement;
|
||||
var enclosingClass = field.enclosingElement3 as InterfaceElement;
|
||||
if (field.isEnumConstant ||
|
||||
_flutter.isExactAlignment(enclosingClass) ||
|
||||
_flutter.isExactAlignmentDirectional(enclosingClass)) {
|
||||
|
|
|
@ -50,7 +50,7 @@ String? _getNodeKind(Element e) {
|
|||
return schema.VARIABLE_KIND;
|
||||
} else if (e is ExecutableElement) {
|
||||
return schema.FUNCTION_KIND;
|
||||
} else if (e is ClassElement || e is TypeParameterElement) {
|
||||
} else if (e is InterfaceElement || e is TypeParameterElement) {
|
||||
// TODO(jwren): this should be using absvar instead, see
|
||||
// https://kythe.io/docs/schema/#absvar
|
||||
return schema.RECORD_KIND;
|
||||
|
@ -169,7 +169,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
|
||||
late String _enclosingFilePath = '';
|
||||
Element? _enclosingElement;
|
||||
ClassElement? _enclosingClassElement;
|
||||
InterfaceElement? _enclosingClassElement;
|
||||
KytheVName? _enclosingVName;
|
||||
KytheVName? _enclosingFileVName;
|
||||
KytheVName? _enclosingClassVName;
|
||||
|
@ -1138,7 +1138,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
_enclosingElement = element;
|
||||
if (element is CompilationUnitElement) {
|
||||
_enclosingFileVName = _enclosingVName = _vNameFile();
|
||||
} else if (element is ClassElement) {
|
||||
} else if (element is InterfaceElement) {
|
||||
_enclosingClassElement = element;
|
||||
_enclosingClassVName = _enclosingVName =
|
||||
_vNameFromElement(_enclosingClassElement, schema.RECORD_KIND);
|
||||
|
|
|
@ -53,7 +53,7 @@ class ConvertGetterToMethodRefactoringImpl extends RefactoringImpl
|
|||
// method
|
||||
var field = element.variable;
|
||||
if (field is FieldElement &&
|
||||
(field.enclosingElement3 is ClassElement ||
|
||||
(field.enclosingElement3 is InterfaceElement ||
|
||||
field.enclosingElement3 is ExtensionElement)) {
|
||||
var elements = await getHierarchyMembers(searchEngine, field);
|
||||
await Future.forEach(elements, (ClassMemberElement member) async {
|
||||
|
|
|
@ -523,9 +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) {
|
||||
if (parent is AssignmentExpression && parent.leftHandSide == node) {
|
||||
return;
|
||||
}
|
||||
super.visitSimpleIdentifier(node);
|
||||
|
|
|
@ -19,6 +19,7 @@ import 'package:analysis_server/src/utilities/extensions/ast.dart';
|
|||
import 'package:analyzer/dart/analysis/features.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';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
|
@ -33,12 +34,16 @@ import 'package:analyzer_plugin/utilities/range_factory.dart';
|
|||
|
||||
const String _TOKEN_SEPARATOR = '\uFFFF';
|
||||
|
||||
Element? _getLocalElement(SimpleIdentifier node) {
|
||||
var element = node.writeOrReadElement;
|
||||
if (element is LocalVariableElement ||
|
||||
bool isLocalElement(Element? element) {
|
||||
return element is LocalVariableElement ||
|
||||
element is ParameterElement ||
|
||||
element is FunctionElement &&
|
||||
element.enclosingElement3 is! CompilationUnitElement) {
|
||||
element.enclosingElement3 is! CompilationUnitElement;
|
||||
}
|
||||
|
||||
Element? _getLocalElement(SimpleIdentifier node) {
|
||||
var element = node.writeOrReadElement;
|
||||
if (isLocalElement(element)) {
|
||||
return element;
|
||||
}
|
||||
return null;
|
||||
|
@ -1047,17 +1052,36 @@ class _GetSourcePatternVisitor extends GeneralizingAstVisitor<void> {
|
|||
|
||||
_GetSourcePatternVisitor(this.partRange, this.pattern, this.replaceEdits);
|
||||
|
||||
@override
|
||||
void visitNamedExpression(NamedExpression node) {
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
var nodeRange = range.node(node);
|
||||
if (partRange.covers(nodeRange)) {
|
||||
var element = _getLocalElement(node);
|
||||
if (element != null) {
|
||||
// name of a named expression
|
||||
if (isNamedExpressionName(node)) {
|
||||
return;
|
||||
}
|
||||
// continue
|
||||
_addPatterns(
|
||||
nameToken: node.token,
|
||||
element: node.staticElement,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
_addPatterns(
|
||||
nameToken: node.name2,
|
||||
element: node.declaredElement2,
|
||||
);
|
||||
|
||||
super.visitVariableDeclaration(node);
|
||||
}
|
||||
|
||||
void _addPatterns({
|
||||
required Token nameToken,
|
||||
required Element? element,
|
||||
}) {
|
||||
var nameRange = range.token(nameToken);
|
||||
if (partRange.covers(nameRange)) {
|
||||
if (element != null && isLocalElement(element)) {
|
||||
var originalName = element.displayName;
|
||||
var patternName = pattern.originalToPatternNames[originalName];
|
||||
if (patternName == null) {
|
||||
|
@ -1066,8 +1090,8 @@ class _GetSourcePatternVisitor extends GeneralizingAstVisitor<void> {
|
|||
patternName = '__refVar${pattern.originalToPatternNames.length}';
|
||||
pattern.originalToPatternNames[originalName] = patternName;
|
||||
}
|
||||
replaceEdits.add(SourceEdit(nodeRange.offset - partRange.offset,
|
||||
nodeRange.length, patternName));
|
||||
replaceEdits.add(SourceEdit(nameRange.offset - partRange.offset,
|
||||
nameRange.length, patternName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1292,6 +1316,34 @@ class _InitializeParametersVisitor extends GeneralizingAstVisitor {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
visitVariableDeclaration(VariableDeclaration node) {
|
||||
var nodeRange = range.node(node);
|
||||
if (ref.selectionRange.covers(nodeRange)) {
|
||||
final element = node.declaredElement2!;
|
||||
|
||||
// remember, if assigned and used after selection
|
||||
if (ref._isUsedAfterSelection(element)) {
|
||||
if (!assignedUsedVariables.contains(element)) {
|
||||
assignedUsedVariables.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
// remember information for conflicts checking
|
||||
if (element is LocalElement) {
|
||||
// declared local elements
|
||||
var range = ref._visibleRangeMap[element];
|
||||
if (range != null) {
|
||||
final name = node.name2.lexeme;
|
||||
var ranges = ref._localNames.putIfAbsent(name, () => <SourceRange>[]);
|
||||
ranges.add(range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.visitVariableDeclaration(node);
|
||||
}
|
||||
}
|
||||
|
||||
class _IsUsedAfterSelectionVisitor extends GeneralizingAstVisitor<void> {
|
||||
|
|
|
@ -610,7 +610,7 @@ class _Parameter {
|
|||
}
|
||||
|
||||
class _ParametersCollector extends RecursiveAstVisitor<void> {
|
||||
final ClassElement? enclosingClass;
|
||||
final InterfaceElement? enclosingClass;
|
||||
final SourceRange expressionRange;
|
||||
|
||||
final RefactoringStatus status = RefactoringStatus();
|
||||
|
|
|
@ -52,12 +52,14 @@ class InlineLocalRefactoringImpl extends RefactoringImpl
|
|||
@override
|
||||
Future<RefactoringStatus> checkInitialConditions() async {
|
||||
// prepare variable
|
||||
Element? element;
|
||||
var offsetNode = NodeLocator(offset).searchWithin(resolveResult.unit);
|
||||
if (offsetNode is! SimpleIdentifier) {
|
||||
return _noLocalVariableStatus();
|
||||
if (offsetNode is SimpleIdentifier) {
|
||||
element = offsetNode.staticElement;
|
||||
} else if (offsetNode is VariableDeclaration) {
|
||||
element = offsetNode.declaredElement2;
|
||||
}
|
||||
|
||||
var element = offsetNode.staticElement;
|
||||
if (element is! LocalVariableElement) {
|
||||
return _noLocalVariableStatus();
|
||||
}
|
||||
|
@ -171,12 +173,14 @@ class InlineLocalRefactoringImpl extends RefactoringImpl
|
|||
|
||||
/// Checks if [offset] is a variable that can be inlined.
|
||||
RefactoringStatus _checkOffset() {
|
||||
Element? element;
|
||||
var offsetNode = NodeLocator(offset).searchWithin(resolveResult.unit);
|
||||
if (offsetNode is! SimpleIdentifier) {
|
||||
return _noLocalVariableStatus();
|
||||
if (offsetNode is SimpleIdentifier) {
|
||||
element = offsetNode.staticElement;
|
||||
} else if (offsetNode is VariableDeclaration) {
|
||||
element = offsetNode.declaredElement2;
|
||||
}
|
||||
|
||||
var element = offsetNode.staticElement;
|
||||
if (element is! LocalVariableElement) {
|
||||
return _noLocalVariableStatus();
|
||||
}
|
||||
|
|
|
@ -160,14 +160,14 @@ Set<String> _getNamesConflictingAt(AstNode node) {
|
|||
}
|
||||
// fields
|
||||
{
|
||||
var enclosingClassElement = node.enclosingInterfaceElement;
|
||||
if (enclosingClassElement != null) {
|
||||
var enclosingInterfaceElement = node.enclosingInterfaceElement;
|
||||
if (enclosingInterfaceElement != null) {
|
||||
var elements = [
|
||||
...enclosingClassElement.allSupertypes.map((e) => e.element2),
|
||||
enclosingClassElement,
|
||||
...enclosingInterfaceElement.allSupertypes.map((e) => e.element2),
|
||||
enclosingInterfaceElement,
|
||||
];
|
||||
for (var classElement in elements) {
|
||||
var classMembers = getChildren(classElement);
|
||||
for (var interfaceElement in elements) {
|
||||
var classMembers = getChildren(interfaceElement);
|
||||
for (var classMemberElement in classMembers) {
|
||||
result.add(classMemberElement.displayName);
|
||||
}
|
||||
|
@ -213,9 +213,9 @@ class InlineMethodRefactoringImpl extends RefactoringImpl
|
|||
|
||||
@override
|
||||
String? get className {
|
||||
var classElement = _methodElement?.enclosingElement3;
|
||||
if (classElement is ClassElement) {
|
||||
return classElement.displayName;
|
||||
var interfaceElement = _methodElement?.enclosingElement3;
|
||||
if (interfaceElement is InterfaceElement) {
|
||||
return interfaceElement.displayName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -304,11 +304,19 @@ class InlineMethodRefactoringImpl extends RefactoringImpl
|
|||
var fatalStatus = RefactoringStatus.fatal(
|
||||
'Method declaration or reference must be selected to activate this refactoring.');
|
||||
|
||||
var identifier = NodeLocator(offset).searchWithin(resolveResult.unit);
|
||||
if (identifier is! SimpleIdentifier) {
|
||||
final selectedNode = NodeLocator(offset).searchWithin(resolveResult.unit);
|
||||
final Element? element;
|
||||
if (selectedNode is FunctionDeclaration) {
|
||||
element = selectedNode.declaredElement2;
|
||||
isDeclaration = true;
|
||||
} else if (selectedNode is MethodDeclaration) {
|
||||
element = selectedNode.declaredElement2;
|
||||
isDeclaration = true;
|
||||
} else if (selectedNode is SimpleIdentifier) {
|
||||
element = selectedNode.writeOrReadElement;
|
||||
} else {
|
||||
return fatalStatus;
|
||||
}
|
||||
var element = identifier.writeOrReadElement;
|
||||
if (element is! ExecutableElement) {
|
||||
return fatalStatus;
|
||||
}
|
||||
|
@ -347,13 +355,23 @@ class InlineMethodRefactoringImpl extends RefactoringImpl
|
|||
// prepare for failure
|
||||
var fatalStatus = RefactoringStatus.fatal(
|
||||
'Method declaration or reference must be selected to activate this refactoring.');
|
||||
|
||||
// prepare selected SimpleIdentifier
|
||||
var identifier = NodeLocator(offset).searchWithin(resolveResult.unit);
|
||||
if (identifier is! SimpleIdentifier) {
|
||||
final selectedNode = NodeLocator(offset).searchWithin(resolveResult.unit);
|
||||
final Element? element;
|
||||
if (selectedNode is FunctionDeclaration) {
|
||||
element = selectedNode.declaredElement2;
|
||||
isDeclaration = true;
|
||||
} else if (selectedNode is MethodDeclaration) {
|
||||
element = selectedNode.declaredElement2;
|
||||
isDeclaration = true;
|
||||
} else if (selectedNode is SimpleIdentifier) {
|
||||
element = selectedNode.writeOrReadElement;
|
||||
} else {
|
||||
return fatalStatus;
|
||||
}
|
||||
|
||||
// prepare selected ExecutableElement
|
||||
var element = identifier.writeOrReadElement;
|
||||
if (element is! ExecutableElement) {
|
||||
return fatalStatus;
|
||||
}
|
||||
|
@ -380,8 +398,6 @@ class InlineMethodRefactoringImpl extends RefactoringImpl
|
|||
return fatalStatus;
|
||||
}
|
||||
|
||||
isDeclaration = resolveResult.uri == element.source.uri &&
|
||||
identifier.offset == element.nameOffset;
|
||||
deleteSource = isDeclaration;
|
||||
inlineAll = deleteSource;
|
||||
return RefactoringStatus();
|
||||
|
@ -789,6 +805,19 @@ class _VariablesVisitor extends GeneralizingAstVisitor<void> {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
final nameRange = range.token(node.name2);
|
||||
if (bodyRange.covers(nameRange)) {
|
||||
final declaredElement = node.declaredElement2;
|
||||
if (declaredElement != null) {
|
||||
result.addVariable(declaredElement, nameRange);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitVariableDeclaration(node);
|
||||
}
|
||||
|
||||
void _addMemberQualifier(SimpleIdentifier node) {
|
||||
// should be unqualified
|
||||
var qualifier = getNodeQualifier(node);
|
||||
|
@ -806,7 +835,7 @@ class _VariablesVisitor extends GeneralizingAstVisitor<void> {
|
|||
} else {
|
||||
return;
|
||||
}
|
||||
if (element.enclosingElement3 is! ClassElement) {
|
||||
if (element.enclosingElement3 is! InterfaceElement) {
|
||||
return;
|
||||
}
|
||||
// record the implicit static or instance reference
|
||||
|
|
|
@ -23,6 +23,7 @@ import 'package:analysis_server/src/services/search/search_engine.dart';
|
|||
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/syntactic_entity.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
|
@ -425,7 +426,7 @@ abstract class RenameRefactoring implements Refactoring {
|
|||
if (element is LocalElement) {
|
||||
return RenameLocalRefactoringImpl(workspace, session, element);
|
||||
}
|
||||
if (enclosingElement is ClassElement) {
|
||||
if (enclosingElement is InterfaceElement) {
|
||||
return RenameClassMemberRefactoringImpl(
|
||||
workspace, session, enclosingElement, element);
|
||||
}
|
||||
|
@ -440,8 +441,36 @@ abstract class RenameRefactoring implements Refactoring {
|
|||
/// the class when on the `new` keyword).
|
||||
static RenameRefactoringElement? getElementToRename(
|
||||
AstNode node, Element? element) {
|
||||
var offset = node.offset;
|
||||
var length = node.length;
|
||||
// TODO(scheglov) This is bad code.
|
||||
SyntacticEntity? nameNode;
|
||||
if (node is ConstructorDeclaration) {
|
||||
nameNode = node;
|
||||
} else if (node is ConstructorSelector) {
|
||||
nameNode = node;
|
||||
} else if (node is FieldFormalParameter) {
|
||||
nameNode = node.name;
|
||||
} else if (node is ImportDirective) {
|
||||
nameNode = node;
|
||||
} else if (node is InstanceCreationExpression) {
|
||||
nameNode = node;
|
||||
} else if (node is LibraryDirective) {
|
||||
nameNode = node;
|
||||
} else if (node is MethodDeclaration) {
|
||||
nameNode = node.name2;
|
||||
} else if (node is NamedCompilationUnitMember) {
|
||||
nameNode = node.name2;
|
||||
} else if (node is SimpleFormalParameter) {
|
||||
nameNode = node.name;
|
||||
} else if (node is SimpleIdentifier) {
|
||||
nameNode = node.token;
|
||||
} else if (node is VariableDeclaration) {
|
||||
nameNode = node.name2;
|
||||
}
|
||||
if (nameNode == null) {
|
||||
return null;
|
||||
}
|
||||
var offset = nameNode.offset;
|
||||
var length = nameNode.length;
|
||||
|
||||
if (node is SimpleIdentifier && element is ParameterElement) {
|
||||
element = declaredParameterElement(node, element);
|
||||
|
|
|
@ -37,12 +37,12 @@ Future<RefactoringStatus> validateCreateMethod(
|
|||
/// A [Refactoring] for renaming class member [Element]s.
|
||||
class RenameClassMemberRefactoringImpl extends RenameRefactoringImpl {
|
||||
final AnalysisSessionHelper sessionHelper;
|
||||
final ClassElement classElement;
|
||||
final InterfaceElement interfaceElement;
|
||||
|
||||
late _RenameClassMemberValidator _validator;
|
||||
|
||||
RenameClassMemberRefactoringImpl(RefactoringWorkspace workspace,
|
||||
AnalysisSession session, this.classElement, Element element)
|
||||
AnalysisSession session, this.interfaceElement, Element element)
|
||||
: sessionHelper = AnalysisSessionHelper(session),
|
||||
super(workspace, element);
|
||||
|
||||
|
@ -60,7 +60,7 @@ class RenameClassMemberRefactoringImpl extends RenameRefactoringImpl {
|
|||
@override
|
||||
Future<RefactoringStatus> checkFinalConditions() {
|
||||
_validator = _RenameClassMemberValidator(
|
||||
searchEngine, sessionHelper, classElement, element, newName);
|
||||
searchEngine, sessionHelper, interfaceElement, element, newName);
|
||||
return _validator.validate();
|
||||
}
|
||||
|
||||
|
@ -240,11 +240,39 @@ class _LocalElementsCollector extends GeneralizingAstVisitor<void> {
|
|||
_LocalElementsCollector(this.name);
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
var element = node.staticElement;
|
||||
if (element is LocalElement && element.name == name) {
|
||||
elements.add(element);
|
||||
void visitFunctionDeclaration(FunctionDeclaration node) {
|
||||
if (node.name2.lexeme == name) {
|
||||
final element = node.declaredElement2;
|
||||
if (element is FunctionElement) {
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitFunctionDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleFormalParameter(SimpleFormalParameter node) {
|
||||
if (node.name?.lexeme == name) {
|
||||
final element = node.declaredElement;
|
||||
if (element != null) {
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitSimpleFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
if (node.name2.lexeme == name) {
|
||||
final element = node.declaredElement2;
|
||||
if (element is LocalVariableElement) {
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitVariableDeclaration(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,10 +293,10 @@ class _RenameClassMemberValidator extends _BaseClassMemberValidator {
|
|||
_RenameClassMemberValidator(
|
||||
SearchEngine searchEngine,
|
||||
AnalysisSessionHelper sessionHelper,
|
||||
ClassElement elementClass,
|
||||
InterfaceElement elementInterface,
|
||||
this.element,
|
||||
String name,
|
||||
) : super(searchEngine, sessionHelper, elementClass, element.kind, name);
|
||||
) : super(searchEngine, sessionHelper, elementInterface, element.kind, name);
|
||||
|
||||
Future<RefactoringStatus> validate() async {
|
||||
_checkClassAlreadyDeclares();
|
||||
|
@ -278,7 +306,8 @@ class _RenameClassMemberValidator extends _BaseClassMemberValidator {
|
|||
// check shadowing of class names
|
||||
for (var element in elements) {
|
||||
var enclosingElement = element.enclosingElement3;
|
||||
if (enclosingElement is ClassElement && enclosingElement.name == name) {
|
||||
if (enclosingElement is InterfaceElement &&
|
||||
enclosingElement.name == name) {
|
||||
result.addError(
|
||||
'Renamed ${elementKind.displayName} has the same name as the '
|
||||
"declaring ${enclosingElement.kind.displayName} '$name'.",
|
||||
|
|
|
@ -212,11 +212,39 @@ class _LocalElementsCollector extends GeneralizingAstVisitor<void> {
|
|||
_LocalElementsCollector(this.name);
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
var element = node.staticElement;
|
||||
if (element is LocalElement && element.name == name) {
|
||||
elements.add(element);
|
||||
void visitFunctionDeclaration(FunctionDeclaration node) {
|
||||
if (node.name2.lexeme == name) {
|
||||
final element = node.declaredElement2;
|
||||
if (element is FunctionElement) {
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitFunctionDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleFormalParameter(SimpleFormalParameter node) {
|
||||
if (node.name?.lexeme == name) {
|
||||
final element = node.declaredElement;
|
||||
if (element != null) {
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitSimpleFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
if (node.name2.lexeme == name) {
|
||||
final element = node.declaredElement2;
|
||||
if (element is LocalVariableElement) {
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitVariableDeclaration(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:analysis_server/src/services/refactoring/legacy/visible_ranges_c
|
|||
import 'package:analysis_server/src/services/search/hierarchy.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/src/dart/analysis/session_helper.dart';
|
||||
|
@ -124,18 +125,20 @@ class _ConflictValidatorVisitor extends RecursiveAstVisitor<void> {
|
|||
this.visibleRangeMap,
|
||||
);
|
||||
|
||||
@override
|
||||
void visitFunctionDeclaration(FunctionDeclaration node) {
|
||||
_checkDeclaration(
|
||||
declaredElement: node.declaredElement2!,
|
||||
nameToken: node.name2,
|
||||
);
|
||||
|
||||
super.visitFunctionDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
var nodeElement = node.staticElement;
|
||||
if (nodeElement != null && nodeElement.name == newName) {
|
||||
// Duplicate declaration.
|
||||
if (node.inDeclarationContext() && _isVisibleWithTarget(nodeElement)) {
|
||||
conflictingLocals.add(nodeElement);
|
||||
var nodeKind = nodeElement.kind.displayName;
|
||||
var message = "Duplicate $nodeKind '$newName'.";
|
||||
result.addError(message, newLocation_fromElement(nodeElement));
|
||||
return;
|
||||
}
|
||||
if (conflictingLocals.contains(nodeElement)) {
|
||||
return;
|
||||
}
|
||||
|
@ -157,6 +160,32 @@ class _ConflictValidatorVisitor extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariableDeclaration(VariableDeclaration node) {
|
||||
_checkDeclaration(
|
||||
declaredElement: node.declaredElement2!,
|
||||
nameToken: node.name2,
|
||||
);
|
||||
|
||||
super.visitVariableDeclaration(node);
|
||||
}
|
||||
|
||||
void _checkDeclaration({
|
||||
required Element? declaredElement,
|
||||
required Token nameToken,
|
||||
}) {
|
||||
if (declaredElement != null && nameToken.lexeme == newName) {
|
||||
// Duplicate declaration.
|
||||
if (_isVisibleWithTarget(declaredElement)) {
|
||||
conflictingLocals.add(declaredElement);
|
||||
var nodeKind = declaredElement.kind.displayName;
|
||||
var message = "Duplicate $nodeKind '$newName'.";
|
||||
result.addError(message, newLocation_fromElement(declaredElement));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SourceRange? _getVisibleRange(LocalElement element) {
|
||||
return visibleRangeMap[element];
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ class RenameUnitMemberRefactoringImpl extends RenameRefactoringImpl {
|
|||
if (element is TypeAliasElement) {
|
||||
result.addStatus(validateTypeAliasName(newName));
|
||||
}
|
||||
if (element is ClassElement) {
|
||||
if (element is InterfaceElement) {
|
||||
result.addStatus(validateClassName(newName));
|
||||
}
|
||||
return result;
|
||||
|
@ -214,7 +214,7 @@ class _BaseUnitMemberValidator {
|
|||
var declarations = await searchEngine.searchMemberDeclarations(name);
|
||||
for (var declaration in declarations) {
|
||||
var member = declaration.element;
|
||||
var declaringClass = member.enclosingElement3 as ClassElement;
|
||||
var declaringClass = member.enclosingElement3 as InterfaceElement;
|
||||
var memberReferences = await searchEngine.searchReferences(member);
|
||||
for (var memberReference in memberReferences) {
|
||||
var refElement = memberReference.element;
|
||||
|
@ -223,7 +223,7 @@ class _BaseUnitMemberValidator {
|
|||
continue;
|
||||
}
|
||||
// cannot be shadowed if declared in the same class as reference
|
||||
var refClass = refElement.thisOrAncestorOfType<ClassElement>();
|
||||
var refClass = refElement.thisOrAncestorOfType<InterfaceElement>();
|
||||
if (refClass == declaringClass) {
|
||||
continue;
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ class _RenameUnitMemberValidator extends _BaseUnitMemberValidator {
|
|||
void _validateWillBeShadowed() {
|
||||
for (var reference in references) {
|
||||
var refElement = reference.element;
|
||||
var refClass = refElement.thisOrAncestorOfType<ClassElement>();
|
||||
var refClass = refElement.thisOrAncestorOfType<InterfaceElement>();
|
||||
if (refClass != null) {
|
||||
visitChildren(refClass, (shadow) {
|
||||
if (hasDisplayName(shadow, name)) {
|
||||
|
|
|
@ -20,7 +20,7 @@ List<Element> getChildren(Element parent, [String? name]) {
|
|||
return children;
|
||||
}
|
||||
|
||||
/// Returns direct non-synthetic children of the given [ClassElement].
|
||||
/// Returns direct non-synthetic children of the given [InterfaceElement].
|
||||
///
|
||||
/// Includes: fields, accessors and methods.
|
||||
/// Excludes: constructors and synthetic elements.
|
||||
|
@ -48,10 +48,10 @@ List<Element> getClassMembers(InterfaceElement clazz, [String? name]) {
|
|||
}
|
||||
|
||||
/// Returns a [Set] with direct subclasses of [seed].
|
||||
Future<Set<ClassElement>> getDirectSubClasses(
|
||||
Future<Set<InterfaceElement>> getDirectSubClasses(
|
||||
SearchEngine searchEngine, InterfaceElement seed) async {
|
||||
var matches = await searchEngine.searchSubtypes(seed);
|
||||
return matches.map((match) => match.element).cast<ClassElement>().toSet();
|
||||
return matches.map((match) => match.element).cast<InterfaceElement>().toSet();
|
||||
}
|
||||
|
||||
/// Return the non-synthetic children of the given [extension]. This includes
|
||||
|
@ -93,7 +93,7 @@ Future<Set<ClassMemberElement>> getHierarchyMembers(
|
|||
return Future.value(result);
|
||||
}
|
||||
// method, field, etc
|
||||
if (enclosingElement is ClassElement) {
|
||||
if (enclosingElement is InterfaceElement) {
|
||||
var name = member.displayName;
|
||||
var searchClasses = [
|
||||
...enclosingElement.allSupertypes.map((e) => e.element2),
|
||||
|
@ -147,7 +147,7 @@ Future<List<ParameterElement>> getHierarchyNamedParameters(
|
|||
return [element];
|
||||
}
|
||||
|
||||
/// Returns non-synthetic members of the given [ClassElement] and its super
|
||||
/// Returns non-synthetic members of the given [InterfaceElement] and its super
|
||||
/// classes.
|
||||
///
|
||||
/// Includes: fields, accessors and methods.
|
||||
|
|
|
@ -22,7 +22,7 @@ class FlutterStatefulWidgetWithAnimationController
|
|||
@override
|
||||
late ClassElement? classKey;
|
||||
late ClassElement? classAnimationController;
|
||||
late ClassElement? classSingleTickerProviderStateMixin;
|
||||
late MixinElement? classSingleTickerProviderStateMixin;
|
||||
|
||||
FlutterStatefulWidgetWithAnimationController(super.request);
|
||||
|
||||
|
@ -132,7 +132,7 @@ class FlutterStatefulWidgetWithAnimationController
|
|||
(classAnimationController = await getClass('AnimationController')) ==
|
||||
null ||
|
||||
(classSingleTickerProviderStateMixin =
|
||||
await getClass('SingleTickerProviderStateMixin')) ==
|
||||
await getMixin('SingleTickerProviderStateMixin')) ==
|
||||
null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,11 @@ abstract class FlutterSnippetProducer extends DartSnippetProducer {
|
|||
Future<ClassElement?> getClass(String name) =>
|
||||
sessionHelper.getClass(flutter.widgetsUri, name);
|
||||
|
||||
Future<MixinElement?> getMixin(String name) =>
|
||||
sessionHelper.getMixin(flutter.widgetsUri, name);
|
||||
|
||||
DartType getType(
|
||||
ClassElement classElement, [
|
||||
InterfaceElement classElement, [
|
||||
NullabilitySuffix nullabilitySuffix = NullabilitySuffix.none,
|
||||
]) =>
|
||||
classElement.instantiate(
|
||||
|
|
|
@ -37,16 +37,17 @@ class ElementWriter extends GeneralizingElementVisitor with TreeWriter {
|
|||
|
||||
properties['metadata'] = element.metadata;
|
||||
properties['nameOffset'] = element.nameOffset;
|
||||
if (element is ClassElement) {
|
||||
properties['hasNonFinalField'] = element.hasNonFinalField;
|
||||
if (element is InterfaceElement) {
|
||||
properties['interfaces'] = element.interfaces;
|
||||
properties['isAbstract'] = element.isAbstract;
|
||||
properties['isEnum'] = element is EnumElement;
|
||||
properties['isMixinApplication'] = element.isMixinApplication;
|
||||
properties['isValidMixin'] = element.isValidMixin;
|
||||
properties['mixins'] = element.mixins;
|
||||
properties['superclassConstraints'] = element.superclassConstraints;
|
||||
properties['supertype'] = element.supertype;
|
||||
if (element is ClassElement) {
|
||||
properties['hasNonFinalField'] = element.hasNonFinalField;
|
||||
properties['isAbstract'] = element.isAbstract;
|
||||
properties['isMixinApplication'] = element.isMixinApplication;
|
||||
properties['isValidMixin'] = element.isValidMixin;
|
||||
}
|
||||
}
|
||||
if (element is ClassMemberElement) {
|
||||
properties['isStatic'] = element.isStatic;
|
||||
|
|
|
@ -31,7 +31,7 @@ extension ElementExtension on Element {
|
|||
return true;
|
||||
}
|
||||
var ancestor = enclosingElement3;
|
||||
if (ancestor is ClassElement) {
|
||||
if (ancestor is InterfaceElement) {
|
||||
if (ancestor.hasDeprecated) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -338,13 +338,13 @@ class Flutter {
|
|||
}
|
||||
|
||||
/// Return `true` if the [element] is the Flutter class `Alignment`.
|
||||
bool isExactAlignment(ClassElement element) {
|
||||
bool isExactAlignment(InterfaceElement element) {
|
||||
return _isExactWidget(element, 'Alignment', _uriAlignment);
|
||||
}
|
||||
|
||||
/// Return `true` if the [element] is the Flutter class
|
||||
/// `AlignmentDirectional`.
|
||||
bool isExactAlignmentDirectional(ClassElement element) {
|
||||
bool isExactAlignmentDirectional(InterfaceElement element) {
|
||||
return _isExactWidget(element, 'AlignmentDirectional', _uriAlignment);
|
||||
}
|
||||
|
||||
|
@ -538,7 +538,7 @@ class Flutter {
|
|||
/// Return `true` if the given [element] has a supertype with the
|
||||
/// [requiredName] defined in the file with the [requiredUri].
|
||||
bool _hasSupertype(
|
||||
ClassElement? element, Uri requiredUri, String requiredName) {
|
||||
InterfaceElement? element, Uri requiredUri, String requiredName) {
|
||||
if (element == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -451,6 +451,18 @@ AAA aaa;
|
|||
assertHasRegion(HighlightRegionType.CLASS, 'AAA aaa');
|
||||
}
|
||||
|
||||
Future<void> test_class_constructor_fieldFormalParameter() async {
|
||||
addTestFile('''
|
||||
class A {
|
||||
final int foo;
|
||||
A(this.foo);
|
||||
}
|
||||
''');
|
||||
await prepareHighlights();
|
||||
assertHasRegion(HighlightRegionType.KEYWORD, 'this.');
|
||||
assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'foo);');
|
||||
}
|
||||
|
||||
Future<void> test_CLASS_notDynamic() async {
|
||||
addTestFile('''
|
||||
dynamic f() {}
|
||||
|
@ -712,7 +724,7 @@ void f(E e) {
|
|||
await prepareHighlights();
|
||||
assertHasRegion(HighlightRegionType.CLASS, 'int ');
|
||||
assertHasRegion(HighlightRegionType.INSTANCE_FIELD_DECLARATION, 'a = 0');
|
||||
assertHasRegion(HighlightRegionType.PARAMETER_DECLARATION, 'a);');
|
||||
assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'a);');
|
||||
assertHasRegion(HighlightRegionType.INSTANCE_GETTER_REFERENCE, 'a;');
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class RefactoringLocationTest extends AbstractSingleUnitTest {
|
|||
void f() {
|
||||
}
|
||||
''');
|
||||
var node = findNode.simple('f');
|
||||
var node = findNode.functionDeclaration('f');
|
||||
// check
|
||||
var location = newLocation_fromNode(node);
|
||||
expect(location.file, testFile);
|
||||
|
|
|
@ -40,9 +40,9 @@ class RenameRefactoringTest extends RefactoringTest {
|
|||
/// Creates a new [RenameRefactoring] in [refactoring] for the [Element] of
|
||||
/// the [SimpleIdentifier] at the given [search] pattern.
|
||||
void createRenameRefactoringAtString(String search) {
|
||||
var identifier = findNode.simple(search);
|
||||
var identifier = findNode.any(search);
|
||||
var element = ElementLocator.locate(identifier);
|
||||
if (element is PrefixElement) {
|
||||
if (identifier is SimpleIdentifier && element is PrefixElement) {
|
||||
element = getImportElement(identifier);
|
||||
}
|
||||
createRenameRefactoringForElement(element);
|
||||
|
|
|
@ -98,7 +98,8 @@ void f() {
|
|||
// check conditions
|
||||
var status = await refactoring.checkAllConditions();
|
||||
assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL,
|
||||
expectedMessage: 'Cannot extract the name part of a declaration.');
|
||||
expectedMessage:
|
||||
'Expression must be selected to activate this refactoring.');
|
||||
}
|
||||
|
||||
Future<void>
|
||||
|
@ -112,7 +113,8 @@ void f() {
|
|||
// check conditions
|
||||
var status = await refactoring.checkAllConditions();
|
||||
assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL,
|
||||
expectedMessage: 'Cannot extract the name part of a declaration.');
|
||||
expectedMessage:
|
||||
'Expression must be selected to activate this refactoring.');
|
||||
}
|
||||
|
||||
Future<void> test_checkInitialConditions_noExpression() async {
|
||||
|
|
|
@ -423,7 +423,8 @@ void f() {
|
|||
''');
|
||||
_createRefactoringForString('f');
|
||||
return _assertConditionsFatal(
|
||||
'Cannot extract the name part of a declaration.');
|
||||
'The selection does not cover a set of statements or an expression. '
|
||||
'Extend selection to a valid range.');
|
||||
}
|
||||
|
||||
Future<void> test_bad_namePartOfDeclaration_variable() async {
|
||||
|
@ -434,7 +435,7 @@ void f() {
|
|||
''');
|
||||
_createRefactoringForString('vvv');
|
||||
return _assertConditionsFatal(
|
||||
'Cannot extract the name part of a declaration.');
|
||||
'Can only extract a single expression or a set of statements.');
|
||||
}
|
||||
|
||||
Future<void> test_bad_namePartOfQualified() async {
|
||||
|
|
|
@ -24,7 +24,6 @@ import 'package:analyzer/dart/ast/ast.dart';
|
|||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/element.dart'
|
||||
show
|
||||
ClassElement,
|
||||
ClassMemberElement,
|
||||
CompilationUnitElement,
|
||||
Element,
|
||||
|
@ -33,6 +32,7 @@ import 'package:analyzer/dart/element/element.dart'
|
|||
ExtensionElement,
|
||||
FieldElement,
|
||||
FunctionElement,
|
||||
InterfaceElement,
|
||||
LocalVariableElement,
|
||||
MixinElement,
|
||||
ParameterElement,
|
||||
|
@ -1702,14 +1702,14 @@ class CompletionResult {
|
|||
var element = _getElement(entity);
|
||||
if (element != null) {
|
||||
var parent = element.enclosingElement3;
|
||||
if (parent is ClassElement || parent is ExtensionElement) {
|
||||
if (parent is InterfaceElement || parent is ExtensionElement) {
|
||||
if (_isStatic(element)) {
|
||||
return CompletionGroup.staticMember;
|
||||
} else {
|
||||
return CompletionGroup.instanceMember;
|
||||
}
|
||||
} else if (parent is CompilationUnitElement &&
|
||||
element is! ClassElement &&
|
||||
element is! InterfaceElement &&
|
||||
element is! ExtensionElement) {
|
||||
return CompletionGroup.topLevelMember;
|
||||
}
|
||||
|
@ -1718,7 +1718,7 @@ class CompletionResult {
|
|||
return CompletionGroup.enumElement;
|
||||
} else if (element is MixinElement) {
|
||||
return CompletionGroup.mixinElement;
|
||||
} else if (element is ClassElement) {
|
||||
} else if (element is InterfaceElement) {
|
||||
if (entity is SimpleIdentifier &&
|
||||
entity.parent is NamedType &&
|
||||
entity.parent!.parent is ConstructorName &&
|
||||
|
|
|
@ -18,7 +18,6 @@ import 'package:analyzer/dart/ast/token.dart';
|
|||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart'
|
||||
show
|
||||
ClassElement,
|
||||
Element,
|
||||
ExecutableElement,
|
||||
ExtensionElement,
|
||||
|
@ -969,9 +968,9 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
data.recordPercentage(
|
||||
'Methods with type parameters', node.typeParameters != null);
|
||||
var element = node.declaredElement2!;
|
||||
if (!element.isStatic && element.enclosingElement3 is ClassElement) {
|
||||
if (!element.isStatic && element.enclosingElement3 is InterfaceElement) {
|
||||
var overriddenMembers = inheritanceManager.getOverridden2(
|
||||
element.enclosingElement3 as ClassElement,
|
||||
element.enclosingElement3 as InterfaceElement,
|
||||
Name(element.librarySource.uri, element.name));
|
||||
if (overriddenMembers != null) {
|
||||
// Consider limiting this to the most immediate override. If the
|
||||
|
@ -1460,7 +1459,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
if (element is ClassElement) {
|
||||
if (element is InterfaceElement) {
|
||||
var parent = node.parent;
|
||||
if (parent is Annotation && parent.arguments != null) {
|
||||
element = parent.element!;
|
||||
|
@ -1579,7 +1578,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
// TODO(brianwilkerson) It might be interesting to also know whether the
|
||||
// [element] was found in a class, interface, or mixin.
|
||||
var memberClass = member.thisOrAncestorOfType<ClassElement>();
|
||||
var memberClass = member.thisOrAncestorOfType<InterfaceElement>();
|
||||
if (memberClass != null) {
|
||||
/// Return the distance between the [targetClass] and the [memberClass]
|
||||
/// along the superclass chain. This includes all of the implicit
|
||||
|
@ -1598,11 +1597,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
}
|
||||
depth++;
|
||||
if (currentClass is ClassElement) {
|
||||
currentClass = currentClass.supertype?.element2;
|
||||
} else {
|
||||
currentClass = null;
|
||||
}
|
||||
currentClass = currentClass.supertype?.element2;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -1614,11 +1609,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
InterfaceElement? currentClass = targetClass;
|
||||
while (currentClass != null) {
|
||||
depth += currentClass.mixins.length + 1;
|
||||
if (currentClass is ClassElement) {
|
||||
currentClass = currentClass.supertype?.element2;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
currentClass = currentClass.supertype?.element2;
|
||||
}
|
||||
return depth;
|
||||
}
|
||||
|
@ -1792,7 +1783,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
var firstTokenType = identifier.staticType;
|
||||
if (firstTokenType == null) {
|
||||
var element = identifier.staticElement;
|
||||
if (element is ClassElement) {
|
||||
if (element is InterfaceElement) {
|
||||
// This is effectively treating a reference to a class name as having
|
||||
// the same type as an instance of the class, which isn't valid, but
|
||||
// on the other hand, the spec doesn't define the static type of a
|
||||
|
|
|
@ -16,7 +16,7 @@ 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'
|
||||
show ClassElement, Element, LibraryElement;
|
||||
show Element, InterfaceElement, LibraryElement;
|
||||
import 'package:analyzer/dart/element/type_provider.dart';
|
||||
import 'package:analyzer/dart/element/type_system.dart';
|
||||
import 'package:analyzer/diagnostic/diagnostic.dart';
|
||||
|
@ -1348,7 +1348,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
|
|||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
if (element is ClassElement) {
|
||||
if (element is InterfaceElement) {
|
||||
var parent = node.parent;
|
||||
if (parent is Annotation && parent.arguments != null) {
|
||||
element = parent.element!;
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
## 5.0.0 (Not yet released - breaking changes)
|
||||
* Removed deprecated methods from AST.
|
||||
* Removed deprecated `DiagnosticMessage.message`.
|
||||
* Removed deprecated `LibraryElement.getImportsWithPrefix()`.
|
||||
* Removed deprecated `ParameterElement.isNotOptional`.
|
||||
* Removed deprecated `DartType.displayName`.
|
||||
* Removed deprecated methods from `AnalysisDriver`.
|
||||
* Removed deprecated `ClassOrMixinDeclaration`.
|
||||
* Removed deprecated `Declaration.declaredElement`.
|
||||
* Removed deprecated `Element.enclosingElement` and `enclosingElement2`.
|
||||
* Removed deprecated `ExportElement`, `ImportElement`.
|
||||
|
||||
## 4.7.0-dev
|
||||
* Add missing `addXyz` to `NodeLintRegistry`.
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ 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/dart/element/type.dart';
|
||||
import 'package:analyzer/src/generated/source.dart' show LineInfo, Source;
|
||||
import 'package:analyzer/src/generated/source.dart' show LineInfo;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Two or more string literals that are implicitly concatenated because of
|
||||
|
@ -643,10 +643,6 @@ abstract class AugmentationImportDirective implements UriBasedDirective {
|
|||
/// The token representing the 'augment' keyword.
|
||||
Token get augmentKeyword;
|
||||
|
||||
@Deprecated('Use element2 instead')
|
||||
@override
|
||||
AugmentationImportElement? get element;
|
||||
|
||||
@override
|
||||
AugmentationImportElement? get element2;
|
||||
|
||||
|
@ -815,11 +811,6 @@ abstract class CatchClause implements AstNode {
|
|||
/// parameter, or `null` if there is no stack trace parameter.
|
||||
Token? get comma;
|
||||
|
||||
/// Return the parameter whose value will be the exception that was thrown, or
|
||||
/// `null` if there is no 'catch' keyword.
|
||||
@Deprecated('Use exceptionParameter2 instead')
|
||||
SimpleIdentifier? get exceptionParameter;
|
||||
|
||||
/// Return the parameter whose value will be the exception that was thrown, or
|
||||
/// `null` if there is no 'catch' keyword.
|
||||
CatchClauseParameter? get exceptionParameter2;
|
||||
|
@ -838,11 +829,6 @@ abstract class CatchClause implements AstNode {
|
|||
/// Return the right parenthesis, or `null` if there is no 'catch' keyword.
|
||||
Token? get rightParenthesis;
|
||||
|
||||
/// Return the parameter whose value will be the stack trace associated with
|
||||
/// the exception, or `null` if there is no stack trace parameter.
|
||||
@Deprecated('Use stackTraceParameter2 instead')
|
||||
SimpleIdentifier? get stackTraceParameter;
|
||||
|
||||
/// Return the parameter whose value will be the stack trace associated with
|
||||
/// the exception, or `null` if there is no stack trace parameter.
|
||||
CatchClauseParameter? get stackTraceParameter2;
|
||||
|
@ -885,18 +871,7 @@ abstract class ClassAugmentationDeclaration
|
|||
/// '{' [ClassMember]* '}'
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
//
|
||||
// TODO(scheglov) Add `ClassOrAugmentationElement get declaredElement`,
|
||||
// when [ClassOrMixinDeclaration] is gone.
|
||||
abstract class ClassDeclaration
|
||||
implements
|
||||
ClassOrAugmentationDeclaration,
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
ClassOrMixinDeclaration {
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
ClassElement? get declaredElement;
|
||||
|
||||
abstract class ClassDeclaration implements ClassOrAugmentationDeclaration {
|
||||
@override
|
||||
ClassElement? get declaredElement2;
|
||||
|
||||
|
@ -905,10 +880,6 @@ abstract class ClassDeclaration
|
|||
@override
|
||||
ImplementsClause? get implementsClause;
|
||||
|
||||
/// Return `true` if this class is declared to be an abstract class.
|
||||
@Deprecated('Use abstractKeyword instead')
|
||||
bool get isAbstract;
|
||||
|
||||
/// Returns the left curly bracket.
|
||||
@override
|
||||
Token get leftBracket;
|
||||
|
@ -929,14 +900,6 @@ abstract class ClassDeclaration
|
|||
/// class/mixin does not have any type parameters.
|
||||
@override
|
||||
TypeParameterList? get typeParameters;
|
||||
|
||||
/// Return the constructor declared in the class with the given [name], or
|
||||
/// `null` if there is no such constructor.
|
||||
///
|
||||
/// If the [name] is `null` then the default constructor will be searched
|
||||
/// for.
|
||||
@Deprecated('Filter members instead')
|
||||
ConstructorDeclaration? getConstructor(String? name);
|
||||
}
|
||||
|
||||
/// A node that declares a name within the scope of a class declarations.
|
||||
|
@ -993,48 +956,6 @@ abstract class ClassOrAugmentationDeclaration
|
|||
WithClause? get withClause;
|
||||
}
|
||||
|
||||
/// The declaration of a class or mixin.
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
@Deprecated('Use ClassDeclaration or MixinDeclaration directly')
|
||||
abstract class ClassOrMixinDeclaration implements NamedCompilationUnitMember {
|
||||
@Deprecated('Use ClassDeclaration or MixinDeclaration directly')
|
||||
@override
|
||||
ClassElement? get declaredElement;
|
||||
|
||||
/// Returns the implements clause for the class/mixin, or `null` if the
|
||||
/// class/mixin does not implement any interfaces.
|
||||
@Deprecated('Use ClassDeclaration or MixinDeclaration directly')
|
||||
ImplementsClause? get implementsClause;
|
||||
|
||||
/// Returns the left curly bracket.
|
||||
@Deprecated('Use ClassDeclaration or MixinDeclaration directly')
|
||||
Token get leftBracket;
|
||||
|
||||
/// Returns the members defined by the class/mixin.
|
||||
@Deprecated('Use ClassDeclaration or MixinDeclaration directly')
|
||||
NodeList<ClassMember> get members;
|
||||
|
||||
/// Returns the right curly bracket.
|
||||
@Deprecated('Use ClassDeclaration or MixinDeclaration directly')
|
||||
Token get rightBracket;
|
||||
|
||||
/// Returns the type parameters for the class/mixin, or `null` if the
|
||||
/// class/mixin does not have any type parameters.
|
||||
@Deprecated('Use ClassDeclaration or MixinDeclaration directly')
|
||||
TypeParameterList? get typeParameters;
|
||||
|
||||
/// Returns the field declared in the class/mixin with the given [name], or
|
||||
/// `null` if there is no such field.
|
||||
@Deprecated('Filter members instead')
|
||||
VariableDeclaration? getField(String name);
|
||||
|
||||
/// Returns the method declared in the class/mixin with the given [name], or
|
||||
/// `null` if there is no such method.
|
||||
@Deprecated('Filter members instead')
|
||||
MethodDeclaration? getMethod(String name);
|
||||
}
|
||||
|
||||
/// A class type alias.
|
||||
///
|
||||
/// classTypeAlias ::=
|
||||
|
@ -1049,10 +970,6 @@ abstract class ClassTypeAlias implements TypeAlias {
|
|||
/// defining an abstract class.
|
||||
Token? get abstractKeyword;
|
||||
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
ClassElement? get declaredElement;
|
||||
|
||||
@override
|
||||
ClassElement? get declaredElement2;
|
||||
|
||||
|
@ -1063,17 +980,9 @@ abstract class ClassTypeAlias implements TypeAlias {
|
|||
/// implements clause.
|
||||
ImplementsClause? get implementsClause;
|
||||
|
||||
/// Return `true` if this class is declared to be an abstract class.
|
||||
@Deprecated('Use abstractKeyword instead')
|
||||
bool get isAbstract;
|
||||
|
||||
/// Return the name of the superclass of the class being declared.
|
||||
NamedType get superclass;
|
||||
|
||||
/// Return the name of the superclass of the class being declared.
|
||||
@Deprecated('Use superclass instead')
|
||||
NamedType get superclass2;
|
||||
|
||||
/// Return the type parameters for the class, or `null` if the class does not
|
||||
/// have any type parameters.
|
||||
TypeParameterList? get typeParameters;
|
||||
|
@ -1167,10 +1076,6 @@ abstract class CommentReference implements AstNode {
|
|||
/// The comment-referable expression being referenced.
|
||||
CommentReferableExpression get expression;
|
||||
|
||||
/// Return the identifier being referenced.
|
||||
@Deprecated('Use expression instead')
|
||||
Identifier get identifier;
|
||||
|
||||
/// Return the token representing the 'new' keyword, or `null` if there was no
|
||||
/// 'new' keyword.
|
||||
Token? get newKeyword;
|
||||
|
@ -1371,10 +1276,6 @@ abstract class Configuration implements AstNode {
|
|||
/// is true.
|
||||
StringLiteral get uri;
|
||||
|
||||
/// Return the source to which the [uri] was resolved.
|
||||
@Deprecated('Use resolvedUri and check for DirectiveUriWithSource instead')
|
||||
Source? get uriSource;
|
||||
|
||||
/// Return the value to which the value of the declared variable will be
|
||||
/// compared, or `null` if the condition does not include an equality test.
|
||||
StringLiteral? get value;
|
||||
|
@ -1409,10 +1310,6 @@ abstract class ConstructorDeclaration implements ClassMember {
|
|||
/// not a const constructor.
|
||||
Token? get constKeyword;
|
||||
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
ConstructorElement? get declaredElement;
|
||||
|
||||
@override
|
||||
ConstructorElement? get declaredElement2;
|
||||
|
||||
|
@ -1426,11 +1323,6 @@ abstract class ConstructorDeclaration implements ClassMember {
|
|||
/// Return the initializers associated with the constructor.
|
||||
NodeList<ConstructorInitializer> get initializers;
|
||||
|
||||
/// 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;
|
||||
|
@ -1512,10 +1404,6 @@ abstract class ConstructorName implements AstNode, ConstructorReferenceNode {
|
|||
|
||||
/// Return the name of the type defining the constructor.
|
||||
NamedType get type;
|
||||
|
||||
/// Return the name of the type defining the constructor.
|
||||
@Deprecated('Use type instead')
|
||||
NamedType get type2;
|
||||
}
|
||||
|
||||
/// An expression representing a reference to a constructor, e.g. the expression
|
||||
|
@ -1590,12 +1478,6 @@ abstract class ContinueStatement implements Statement {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class Declaration implements AnnotatedNode {
|
||||
/// Return the element associated with this declaration, or `null` if either
|
||||
/// this node corresponds to a list of declarations or if the AST structure
|
||||
/// has not been resolved.
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
Element? get declaredElement;
|
||||
|
||||
/// Return the element associated with this declaration, or `null` if either
|
||||
/// this node corresponds to a list of declarations or if the AST structure
|
||||
/// has not been resolved.
|
||||
|
@ -1609,17 +1491,9 @@ abstract class Declaration implements AnnotatedNode {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class DeclaredIdentifier implements Declaration {
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
LocalVariableElement? get declaredElement;
|
||||
|
||||
@override
|
||||
LocalVariableElement? get declaredElement2;
|
||||
|
||||
/// Return the name of the variable being declared.
|
||||
@Deprecated('Use name instead')
|
||||
SimpleIdentifier get identifier;
|
||||
|
||||
/// Return `true` if this variable was declared with the 'const' modifier.
|
||||
bool get isConst;
|
||||
|
||||
|
@ -1676,20 +1550,9 @@ abstract class DefaultFormalParameter implements FormalParameter {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class Directive implements AnnotatedNode {
|
||||
/// Return the element associated with this directive, or `null` if the AST
|
||||
/// structure has not been resolved or if this directive could not be
|
||||
/// resolved.
|
||||
@Deprecated('Use element2 instead')
|
||||
Element? get element;
|
||||
|
||||
/// Return the element associated with this directive, or `null` if the AST
|
||||
/// structure has not been resolved.
|
||||
Element? get element2;
|
||||
|
||||
/// Return the token representing the keyword that introduces this directive
|
||||
/// ('import', 'export', 'library' or 'part').
|
||||
@Deprecated('Use specific xyzToken instead')
|
||||
Token get keyword;
|
||||
}
|
||||
|
||||
/// A do statement.
|
||||
|
@ -1809,10 +1672,6 @@ abstract class EnumConstantDeclaration implements Declaration {
|
|||
/// not be resolved.
|
||||
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;
|
||||
}
|
||||
|
@ -1829,10 +1688,6 @@ abstract class EnumDeclaration implements NamedCompilationUnitMember {
|
|||
/// Return the enumeration constants being declared.
|
||||
NodeList<EnumConstantDeclaration> get constants;
|
||||
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
ClassElement? get declaredElement;
|
||||
|
||||
@override
|
||||
EnumElement? get declaredElement2;
|
||||
|
||||
|
@ -1871,10 +1726,6 @@ abstract class EnumDeclaration implements NamedCompilationUnitMember {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class ExportDirective implements NamespaceDirective {
|
||||
@Deprecated('Use element2 instead')
|
||||
@override
|
||||
ExportElement? get element;
|
||||
|
||||
/// Return the element associated with this directive, or `null` if the AST
|
||||
/// structure has not been resolved.
|
||||
@override
|
||||
|
@ -1991,10 +1842,6 @@ abstract class ExtendsClause implements AstNode {
|
|||
|
||||
/// Return the name of the class that is being extended.
|
||||
NamedType get superclass;
|
||||
|
||||
/// Return the name of the class that is being extended.
|
||||
@Deprecated('Use superclass instead')
|
||||
NamedType get superclass2;
|
||||
}
|
||||
|
||||
/// The declaration of an extension of a type.
|
||||
|
@ -2006,10 +1853,6 @@ abstract class ExtendsClause implements AstNode {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class ExtensionDeclaration implements CompilationUnitMember {
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
ExtensionElement? get declaredElement;
|
||||
|
||||
@override
|
||||
ExtensionElement? get declaredElement2;
|
||||
|
||||
|
@ -2029,11 +1872,6 @@ abstract class ExtensionDeclaration implements CompilationUnitMember {
|
|||
/// Return the members being added to the extended class.
|
||||
NodeList<ClassMember> get members;
|
||||
|
||||
/// 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;
|
||||
|
@ -2155,10 +1993,6 @@ abstract class FieldDeclaration implements ClassMember {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class FieldFormalParameter implements NormalFormalParameter {
|
||||
@Deprecated('Use name instead')
|
||||
@override
|
||||
SimpleIdentifier get identifier;
|
||||
|
||||
/// Return the token representing either the 'final', 'const' or 'var'
|
||||
/// keyword, or `null` if no keyword was used.
|
||||
Token? get keyword;
|
||||
|
@ -2281,12 +2115,6 @@ abstract class FormalParameter implements AstNode {
|
|||
/// parameter has not been resolved.
|
||||
ParameterElement? get declaredElement;
|
||||
|
||||
/// 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 name instead')
|
||||
SimpleIdentifier? get identifier;
|
||||
|
||||
/// Return `true` if this parameter was declared with the 'const' modifier.
|
||||
bool get isConst;
|
||||
|
||||
|
@ -2552,10 +2380,6 @@ abstract class FunctionBody implements AstNode {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class FunctionDeclaration implements NamedCompilationUnitMember {
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
ExecutableElement? get declaredElement;
|
||||
|
||||
@override
|
||||
ExecutableElement? get declaredElement2;
|
||||
|
||||
|
@ -2675,10 +2499,6 @@ abstract class FunctionReference
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class FunctionTypeAlias implements TypeAlias {
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
TypeAliasElement? get declaredElement;
|
||||
|
||||
@override
|
||||
TypeAliasElement? get declaredElement2;
|
||||
|
||||
|
@ -2702,10 +2522,6 @@ abstract class FunctionTypeAlias implements TypeAlias {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class FunctionTypedFormalParameter implements NormalFormalParameter {
|
||||
@Deprecated('Use name instead')
|
||||
@override
|
||||
SimpleIdentifier get identifier;
|
||||
|
||||
@override
|
||||
Token get name;
|
||||
|
||||
|
@ -2923,10 +2739,6 @@ abstract class ImplementsClause implements AstNode {
|
|||
|
||||
/// Return the list of the interfaces that are being implemented.
|
||||
NodeList<NamedType> get interfaces;
|
||||
|
||||
/// Return the list of the interfaces that are being implemented.
|
||||
@Deprecated('Use interfaces instead')
|
||||
NodeList<NamedType> get interfaces2;
|
||||
}
|
||||
|
||||
/// An expression representing an implicit 'call' method reference.
|
||||
|
@ -2964,113 +2776,6 @@ abstract class ImplicitCallReference implements MethodReferenceExpression {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class ImportDirective implements NamespaceDirective {
|
||||
@Deprecated('This kind of syntactic equality is rarely useful')
|
||||
static Comparator<ImportDirective> COMPARATOR =
|
||||
(ImportDirective import1, ImportDirective import2) {
|
||||
//
|
||||
// uri
|
||||
//
|
||||
StringLiteral uri1 = import1.uri;
|
||||
StringLiteral uri2 = import2.uri;
|
||||
String? uriStr1 = uri1.stringValue;
|
||||
String? uriStr2 = uri2.stringValue;
|
||||
if (uriStr1 != null || uriStr2 != null) {
|
||||
if (uriStr1 == null) {
|
||||
return -1;
|
||||
} else if (uriStr2 == null) {
|
||||
return 1;
|
||||
} else {
|
||||
int compare = uriStr1.compareTo(uriStr2);
|
||||
if (compare != 0) {
|
||||
return compare;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// as
|
||||
//
|
||||
SimpleIdentifier? prefix1 = import1.prefix;
|
||||
SimpleIdentifier? prefix2 = import2.prefix;
|
||||
String? prefixStr1 = prefix1?.name;
|
||||
String? prefixStr2 = prefix2?.name;
|
||||
if (prefixStr1 != null || prefixStr2 != null) {
|
||||
if (prefixStr1 == null) {
|
||||
return -1;
|
||||
} else if (prefixStr2 == null) {
|
||||
return 1;
|
||||
} else {
|
||||
int compare = prefixStr1.compareTo(prefixStr2);
|
||||
if (compare != 0) {
|
||||
return compare;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// hides and shows
|
||||
//
|
||||
NodeList<Combinator> combinators1 = import1.combinators;
|
||||
List<String> allHides1 = <String>[];
|
||||
List<String> allShows1 = <String>[];
|
||||
int length1 = combinators1.length;
|
||||
for (int i = 0; i < length1; i++) {
|
||||
Combinator combinator = combinators1[i];
|
||||
if (combinator is HideCombinator) {
|
||||
NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
|
||||
int hideLength = hides.length;
|
||||
for (int j = 0; j < hideLength; j++) {
|
||||
SimpleIdentifier simpleIdentifier = hides[j];
|
||||
allHides1.add(simpleIdentifier.name);
|
||||
}
|
||||
} else {
|
||||
NodeList<SimpleIdentifier> shows =
|
||||
(combinator as ShowCombinator).shownNames;
|
||||
int showLength = shows.length;
|
||||
for (int j = 0; j < showLength; j++) {
|
||||
SimpleIdentifier simpleIdentifier = shows[j];
|
||||
allShows1.add(simpleIdentifier.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
NodeList<Combinator> combinators2 = import2.combinators;
|
||||
List<String> allHides2 = <String>[];
|
||||
List<String> allShows2 = <String>[];
|
||||
int length2 = combinators2.length;
|
||||
for (int i = 0; i < length2; i++) {
|
||||
Combinator combinator = combinators2[i];
|
||||
if (combinator is HideCombinator) {
|
||||
NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
|
||||
int hideLength = hides.length;
|
||||
for (int j = 0; j < hideLength; j++) {
|
||||
SimpleIdentifier simpleIdentifier = hides[j];
|
||||
allHides2.add(simpleIdentifier.name);
|
||||
}
|
||||
} else {
|
||||
NodeList<SimpleIdentifier> shows =
|
||||
(combinator as ShowCombinator).shownNames;
|
||||
int showLength = shows.length;
|
||||
for (int j = 0; j < showLength; j++) {
|
||||
SimpleIdentifier simpleIdentifier = shows[j];
|
||||
allShows2.add(simpleIdentifier.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
// test lengths of combinator lists first
|
||||
if (allHides1.length != allHides2.length) {
|
||||
return allHides1.length - allHides2.length;
|
||||
}
|
||||
if (allShows1.length != allShows2.length) {
|
||||
return allShows1.length - allShows2.length;
|
||||
}
|
||||
// next ensure that the lists are equivalent
|
||||
if (!allHides1.toSet().containsAll(allHides2)) {
|
||||
return -1;
|
||||
}
|
||||
if (!allShows1.toSet().containsAll(allShows2)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
/// Return the token representing the 'as' keyword, or `null` if the imported
|
||||
/// names are not prefixed.
|
||||
Token? get asKeyword;
|
||||
|
@ -3079,10 +2784,6 @@ abstract class ImportDirective implements NamespaceDirective {
|
|||
/// imported URI is not deferred.
|
||||
Token? get deferredKeyword;
|
||||
|
||||
@Deprecated('Use element2 instead')
|
||||
@override
|
||||
ImportElement? get element;
|
||||
|
||||
/// Return the element associated with this directive, or `null` if the AST
|
||||
/// structure has not been resolved.
|
||||
@override
|
||||
|
@ -3476,10 +3177,6 @@ abstract class MethodDeclaration implements ClassMember {
|
|||
/// Return the body of the method.
|
||||
FunctionBody get body;
|
||||
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
ExecutableElement? get declaredElement;
|
||||
|
||||
@override
|
||||
ExecutableElement? get declaredElement2;
|
||||
|
||||
|
@ -3506,10 +3203,6 @@ abstract class MethodDeclaration implements ClassMember {
|
|||
/// `null` if neither modifier was specified.
|
||||
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;
|
||||
|
||||
|
@ -3618,15 +3311,7 @@ abstract class MixinAugmentationDeclaration
|
|||
/// [OnClause]? [ImplementsClause]? '{' [ClassMember]* '}'
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class MixinDeclaration
|
||||
implements
|
||||
MixinOrAugmentationDeclaration,
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
ClassOrMixinDeclaration {
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
ClassElement? get declaredElement;
|
||||
|
||||
abstract class MixinDeclaration implements MixinOrAugmentationDeclaration {
|
||||
@override
|
||||
MixinElement? get declaredElement2;
|
||||
|
||||
|
@ -3692,10 +3377,6 @@ abstract class MixinOrAugmentationDeclaration
|
|||
///
|
||||
/// 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;
|
||||
}
|
||||
|
@ -3756,30 +3437,8 @@ abstract class NamespaceDirective implements UriBasedDirective {
|
|||
/// loaded at run-time.
|
||||
NodeList<Configuration> get configurations;
|
||||
|
||||
/// Return the source that was selected based on the declared variables.
|
||||
///
|
||||
/// This will be the source from the first configuration whose condition is
|
||||
/// true, or the `[uriSource]` if either there are no configurations or if
|
||||
/// there are no configurations whose condition is true.
|
||||
@Deprecated('Use element2.uri and check for DirectiveUriWithSource instead')
|
||||
Source? get selectedSource;
|
||||
|
||||
/// Return the content of the URI that was selected based on the declared
|
||||
/// variables.
|
||||
///
|
||||
/// This will be the URI from the first configuration whose condition is
|
||||
/// true, or the `[uriContent]` if either there are no configurations or if
|
||||
/// there are no configurations whose condition is true.
|
||||
@Deprecated(
|
||||
'Use element2.uri and check for DirectiveUriWithRelativeUriString instead')
|
||||
String? get selectedUriContent;
|
||||
|
||||
/// Return the semicolon terminating the directive.
|
||||
Token get semicolon;
|
||||
|
||||
@Deprecated('Use element2.uri and check for DirectiveUriWithLibrary instead')
|
||||
@override
|
||||
LibraryElement? get uriElement;
|
||||
}
|
||||
|
||||
/// The "native" clause in an class declaration.
|
||||
|
@ -3901,10 +3560,6 @@ abstract class OnClause implements AstNode {
|
|||
|
||||
/// Return the list of the classes are superclass constraints for the mixin.
|
||||
NodeList<NamedType> get superclassConstraints;
|
||||
|
||||
/// Return the list of the classes are superclass constraints for the mixin.
|
||||
@Deprecated('Use superclassConstraints instead')
|
||||
NodeList<NamedType> get superclassConstraints2;
|
||||
}
|
||||
|
||||
/// A parenthesized expression.
|
||||
|
@ -4606,10 +4261,6 @@ abstract class SuperExpression implements Expression {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class SuperFormalParameter implements NormalFormalParameter {
|
||||
@Deprecated('Use name instead')
|
||||
@override
|
||||
SimpleIdentifier get identifier;
|
||||
|
||||
/// Return the token representing either the 'final', 'const' or 'var'
|
||||
/// keyword, or `null` if no keyword was used.
|
||||
Token? get keyword;
|
||||
|
@ -4911,10 +4562,6 @@ abstract class TypeParameter implements Declaration {
|
|||
/// explicit upper bound.
|
||||
TypeAnnotation? get bound;
|
||||
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
TypeParameterElement? get declaredElement;
|
||||
|
||||
@override
|
||||
TypeParameterElement? get declaredElement2;
|
||||
|
||||
|
@ -4922,10 +4569,6 @@ abstract class TypeParameter implements Declaration {
|
|||
/// no explicit upper bound.
|
||||
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;
|
||||
}
|
||||
|
@ -4959,25 +4602,6 @@ abstract class TypeParameterList implements AstNode {
|
|||
abstract class UriBasedDirective implements Directive {
|
||||
/// Return the URI referenced by this directive.
|
||||
StringLiteral get uri;
|
||||
|
||||
/// Return the content of the [uri], or `null` if the AST structure has not
|
||||
/// been resolved, or if the [uri] has a string interpolation.
|
||||
@Deprecated(
|
||||
'Use element2.uri and check for DirectiveUriWithRelativeUriString instead')
|
||||
String? get uriContent;
|
||||
|
||||
/// Return the element associated with the [uri] of this directive, or `null`
|
||||
/// if the AST structure has not been resolved or if the URI could not be
|
||||
/// resolved.
|
||||
///
|
||||
/// Examples of the latter case include a directive that contains an invalid
|
||||
/// URL or a URL that does not exist.
|
||||
@Deprecated('Use element2.uri and check for DirectiveUriWithLibrary instead')
|
||||
Element? get uriElement;
|
||||
|
||||
/// Return the source to which the [uri] was resolved.
|
||||
@Deprecated('Use element2.uri and check for DirectiveUriWithSource instead')
|
||||
Source? get uriSource;
|
||||
}
|
||||
|
||||
/// An identifier that has an initial value associated with it.
|
||||
|
@ -4994,10 +4618,6 @@ abstract class UriBasedDirective implements Directive {
|
|||
// Consider changing the class hierarchy so that [VariableDeclaration] does not
|
||||
// extend [Declaration].
|
||||
abstract class VariableDeclaration implements Declaration {
|
||||
@Deprecated('Use declaredElement2 instead')
|
||||
@override
|
||||
VariableElement? get declaredElement;
|
||||
|
||||
@override
|
||||
VariableElement? get declaredElement2;
|
||||
|
||||
|
@ -5021,10 +4641,6 @@ abstract class VariableDeclaration implements Declaration {
|
|||
/// Return `true` if this variable was declared with the 'late' modifier.
|
||||
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;
|
||||
}
|
||||
|
@ -5123,10 +4739,6 @@ abstract class WithClause implements AstNode {
|
|||
/// Return the names of the mixins that were specified.
|
||||
NodeList<NamedType> get mixinTypes;
|
||||
|
||||
/// Return the names of the mixins that were specified.
|
||||
@Deprecated('Use mixinTypes instead')
|
||||
NodeList<NamedType> get mixinTypes2;
|
||||
|
||||
/// Return the token representing the 'with' keyword.
|
||||
Token get withKeyword;
|
||||
}
|
||||
|
|
|
@ -57,14 +57,6 @@ import 'package:pub_semver/pub_semver.dart';
|
|||
/// Clients may not extend, implement or mix-in this class.
|
||||
@experimental
|
||||
abstract class AugmentationImportElement implements _ExistingElement {
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
LibraryOrAugmentationElement get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
LibraryOrAugmentationElement get enclosingElement2;
|
||||
|
||||
@override
|
||||
LibraryOrAugmentationElement get enclosingElement3;
|
||||
|
||||
|
@ -185,12 +177,112 @@ abstract class ClassAugmentationElement implements ClassOrAugmentationElement {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class ClassElement
|
||||
implements
|
||||
ClassOrAugmentationElement,
|
||||
InterfaceElement,
|
||||
_TmpSharedClassElement {
|
||||
implements ClassOrAugmentationElement, InterfaceElement {
|
||||
/// Returns the result of applying augmentations to this class.
|
||||
AugmentedClassElement get augmented;
|
||||
|
||||
/// Return `true` if this class or its superclass declares a non-final
|
||||
/// instance field.
|
||||
bool get hasNonFinalField;
|
||||
|
||||
/// Return `true` if this class is abstract. A class is abstract if it has an
|
||||
/// explicit `abstract` modifier. Note, that this definition of
|
||||
/// <i>abstract</i> is different from <i>has unimplemented members</i>.
|
||||
bool get isAbstract;
|
||||
|
||||
/// Return `true` if this class represents the class 'Enum' defined in the
|
||||
/// dart:core library.
|
||||
bool get isDartCoreEnum;
|
||||
|
||||
/// Return `true` if this class represents the class 'Object' defined in the
|
||||
/// dart:core library.
|
||||
bool get isDartCoreObject;
|
||||
|
||||
/// Return `true` if this class is a mixin application. A class is a mixin
|
||||
/// application if it was declared using the syntax "class A = B with C;".
|
||||
bool get isMixinApplication;
|
||||
|
||||
/// Return `true` if this class can validly be used as a mixin when defining
|
||||
/// another class. For classes defined by a class declaration or a mixin
|
||||
/// application, the behavior of this method is defined by the Dart Language
|
||||
/// Specification in section 9:
|
||||
/// <blockquote>
|
||||
/// It is a compile-time error if a declared or derived mixin refers to super.
|
||||
/// It is a compile-time error if a declared or derived mixin explicitly
|
||||
/// declares a constructor. It is a compile-time error if a mixin is derived
|
||||
/// from a class whose superclass is not Object.
|
||||
/// </blockquote>
|
||||
bool get isValidMixin;
|
||||
|
||||
/// Return a list containing all of the superclass constraints defined for
|
||||
/// this class. The list will be empty if this class does not represent a
|
||||
/// mixin declaration. If this class _does_ represent a mixin declaration but
|
||||
/// the declaration does not have an `on` clause, then the list will contain
|
||||
/// the type for the class `Object`.
|
||||
///
|
||||
/// <b>Note:</b> Because the element model represents the state of the code,
|
||||
/// it is possible for it to be semantically invalid. In particular, it is not
|
||||
/// safe to assume that the inheritance structure of a class does not contain
|
||||
/// a cycle. Clients that traverse the inheritance structure must explicitly
|
||||
/// guard against infinite loops.
|
||||
@Deprecated('This getter is implemented only for MixinElement')
|
||||
List<InterfaceType> get superclassConstraints;
|
||||
|
||||
/// Return the element representing the getter that results from looking up
|
||||
/// the given [getterName] in the superclass of this class with respect to the
|
||||
/// given [library], ignoring abstract getters, or `null` if the look up
|
||||
/// fails. The behavior of this method is defined by the Dart Language
|
||||
/// Specification in section 16.15.2:
|
||||
/// <blockquote>
|
||||
/// The result of looking up getter (respectively setter) <i>m</i> in class
|
||||
/// <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
|
||||
/// instance getter (respectively setter) named <i>m</i> that is accessible to
|
||||
/// <i>L</i>, then that getter (respectively setter) is the result of the
|
||||
/// lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
|
||||
/// of the lookup is the result of looking up getter (respectively setter)
|
||||
/// <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
|
||||
/// lookup has failed.
|
||||
/// </blockquote>
|
||||
/// TODO(scheglov) Deprecate and remove it.
|
||||
PropertyAccessorElement? lookUpInheritedConcreteGetter(
|
||||
String getterName, LibraryElement library);
|
||||
|
||||
/// Return the element representing the method that results from looking up
|
||||
/// the given [methodName] in the superclass of this class with respect to the
|
||||
/// given [library], ignoring abstract methods, or `null` if the look up
|
||||
/// fails. The behavior of this method is defined by the Dart Language
|
||||
/// Specification in section 16.15.1:
|
||||
/// <blockquote>
|
||||
/// The result of looking up method <i>m</i> in class <i>C</i> with respect to
|
||||
/// library <i>L</i> is: If <i>C</i> declares an instance method named
|
||||
/// <i>m</i> that is accessible to <i>L</i>, then that method is the result of
|
||||
/// the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
|
||||
/// result of the lookup is the result of looking up method <i>m</i> in
|
||||
/// <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
|
||||
/// failed.
|
||||
/// </blockquote>
|
||||
/// TODO(scheglov) Deprecate and remove it.
|
||||
MethodElement? lookUpInheritedConcreteMethod(
|
||||
String methodName, LibraryElement library);
|
||||
|
||||
/// Return the element representing the setter that results from looking up
|
||||
/// the given [setterName] in the superclass of this class with respect to the
|
||||
/// given [library], ignoring abstract setters, or `null` if the look up
|
||||
/// fails. The behavior of this method is defined by the Dart Language
|
||||
/// Specification in section 16.15.2:
|
||||
/// <blockquote>
|
||||
/// The result of looking up getter (respectively setter) <i>m</i> in class
|
||||
/// <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
|
||||
/// instance getter (respectively setter) named <i>m</i> that is accessible to
|
||||
/// <i>L</i>, then that getter (respectively setter) is the result of the
|
||||
/// lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
|
||||
/// of the lookup is the result of looking up getter (respectively setter)
|
||||
/// <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
|
||||
/// lookup has failed.
|
||||
/// </blockquote>
|
||||
/// TODO(scheglov) Deprecate and remove it.
|
||||
PropertyAccessorElement? lookUpInheritedConcreteSetter(
|
||||
String setterName, LibraryElement library);
|
||||
}
|
||||
|
||||
/// An element that is contained within a [ClassElement].
|
||||
|
@ -200,14 +292,6 @@ abstract class ClassMemberElement implements Element {
|
|||
// TODO(brianwilkerson) Either remove this class or rename it to something
|
||||
// more correct.
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
Element get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
Element get enclosingElement2;
|
||||
|
||||
@override
|
||||
Element get enclosingElement3;
|
||||
|
||||
|
@ -241,23 +325,10 @@ abstract class CompilationUnitElement implements UriReferencedElement {
|
|||
/// unit.
|
||||
List<ClassElement> get classes;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
LibraryElement get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
LibraryOrAugmentationElement get enclosingElement2;
|
||||
|
||||
/// Return the library, or library augmentation that encloses this unit.
|
||||
@override
|
||||
LibraryOrAugmentationElement get enclosingElement3;
|
||||
|
||||
/// Return a list containing all of the enums contained in this compilation
|
||||
/// unit.
|
||||
@Deprecated('Use enums2 instead')
|
||||
List<ClassElement> get enums;
|
||||
|
||||
/// Return a list containing all of the enums contained in this compilation
|
||||
/// unit.
|
||||
List<EnumElement> get enums2;
|
||||
|
@ -273,11 +344,6 @@ abstract class CompilationUnitElement implements UriReferencedElement {
|
|||
/// Return the [LineInfo] for the [source].
|
||||
LineInfo get lineInfo;
|
||||
|
||||
/// Return a list containing all of the mixins contained in this compilation
|
||||
/// unit.
|
||||
@Deprecated('Use mixins2 instead')
|
||||
List<ClassElement> get mixins;
|
||||
|
||||
/// Return a list containing all of the mixins contained in this compilation
|
||||
/// unit.
|
||||
List<MixinElement> get mixins2;
|
||||
|
@ -298,22 +364,10 @@ abstract class CompilationUnitElement implements UriReferencedElement {
|
|||
/// the given name.
|
||||
ClassElement? getClass(String name);
|
||||
|
||||
/// Return the enum defined in this compilation unit that has the given
|
||||
/// [name], or `null` if this compilation unit does not define an enum with
|
||||
/// the given name.
|
||||
@Deprecated('Use getEnum2() instead')
|
||||
ClassElement? getEnum(String name);
|
||||
|
||||
/// Return the enum defined in this compilation unit that has the given
|
||||
/// [name], or `null` if this compilation unit does not define an enum with
|
||||
/// the given name.
|
||||
EnumElement? getEnum2(String name);
|
||||
|
||||
/// Return the class defined in this compilation unit that has the given
|
||||
/// [name], or `null` if this compilation unit does not define a class with
|
||||
/// the given name.
|
||||
@Deprecated('Use getClass() instead')
|
||||
ClassElement? getType(String name);
|
||||
}
|
||||
|
||||
/// An element representing a constructor augmentation.
|
||||
|
@ -346,14 +400,6 @@ abstract class ConstructorElement
|
|||
@override
|
||||
String get displayName;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
ClassElement get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
ClassElement get enclosingElement2;
|
||||
|
||||
@override
|
||||
InterfaceElement get enclosingElement3;
|
||||
|
||||
|
@ -497,18 +543,6 @@ abstract class Element implements AnalysisTarget {
|
|||
/// documentation.
|
||||
String? get documentationComment;
|
||||
|
||||
/// Return the element that either physically or logically encloses this
|
||||
/// element. This will be `null` if this element is a library because
|
||||
/// libraries are the top-level elements in the model.
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
Element? get enclosingElement;
|
||||
|
||||
/// Return the element that either physically or logically encloses this
|
||||
/// element. This will be `null` if this element is a library because
|
||||
/// libraries are the top-level elements in the model.
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
Element? get enclosingElement2;
|
||||
|
||||
/// Return the element that either physically or logically encloses this
|
||||
/// element. This will be `null` if this element is a library because
|
||||
/// libraries are the top-level elements in the model.
|
||||
|
@ -683,16 +717,6 @@ abstract class Element implements AnalysisTarget {
|
|||
// TODO(brianwilkerson) Make the parameter optional.
|
||||
String getExtendedDisplayName(String? shortName);
|
||||
|
||||
/// Return `true` if this element, assuming that it is within scope, is
|
||||
/// accessible to code in the given [library]. This is defined by the Dart
|
||||
/// Language Specification in section 3.2:
|
||||
/// <blockquote>
|
||||
/// A declaration <i>m</i> is accessible to library <i>L</i> if <i>m</i> is
|
||||
/// declared in <i>L</i> or if <i>m</i> is public.
|
||||
/// </blockquote>
|
||||
@Deprecated('Use isAccessibleIn2() instead')
|
||||
bool isAccessibleIn(LibraryElement? library);
|
||||
|
||||
/// Return `true` if this element, assuming that it is within scope, is
|
||||
/// accessible to code in the given [library]. This is defined by the Dart
|
||||
/// Language Specification in section 6.2:
|
||||
|
@ -1019,9 +1043,6 @@ abstract class ElementVisitor<R> {
|
|||
|
||||
R? visitEnumElement(EnumElement element);
|
||||
|
||||
@Deprecated('Override visitLibraryExportElement() instead')
|
||||
R? visitExportElement(ExportElement element);
|
||||
|
||||
R? visitExtensionElement(ExtensionElement element);
|
||||
|
||||
R? visitFieldElement(FieldElement element);
|
||||
|
@ -1032,9 +1053,6 @@ abstract class ElementVisitor<R> {
|
|||
|
||||
R? visitGenericFunctionTypeElement(GenericFunctionTypeElement element);
|
||||
|
||||
@Deprecated('Override visitLibraryImportElement() instead')
|
||||
R? visitImportElement(ImportElement element);
|
||||
|
||||
R? visitLabelElement(LabelElement element);
|
||||
|
||||
R? visitLibraryAugmentationElement(LibraryAugmentationElement element);
|
||||
|
@ -1088,10 +1106,7 @@ abstract class EnumAugmentationElement implements EnumOrAugmentationElement {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class EnumElement
|
||||
implements
|
||||
EnumOrAugmentationElement,
|
||||
InterfaceElement,
|
||||
_TmpSharedClassElement {
|
||||
implements EnumOrAugmentationElement, InterfaceElement {
|
||||
/// Returns the result of applying augmentations to this element.
|
||||
AugmentedEnumElement get augmented;
|
||||
}
|
||||
|
@ -1119,14 +1134,6 @@ abstract class ExecutableElement implements FunctionTypedElement {
|
|||
@override
|
||||
String get displayName;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
Element get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
Element get enclosingElement2;
|
||||
|
||||
@override
|
||||
Element get enclosingElement3;
|
||||
|
||||
|
@ -1169,20 +1176,6 @@ abstract class ExecutableElement implements FunctionTypedElement {
|
|||
String get name;
|
||||
}
|
||||
|
||||
/// An export directive within a library.
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
@Deprecated('Use LibraryExportElement instead')
|
||||
abstract class ExportElement implements UriReferencedElement {
|
||||
/// Return a list containing the combinators that were specified as part of
|
||||
/// the export directive in the order in which they were specified.
|
||||
List<NamespaceCombinator> get combinators;
|
||||
|
||||
/// Return the library that is exported from this library by this export
|
||||
/// directive, or `null` if the URI has invalid syntax or cannot be resolved.
|
||||
LibraryElement? get exportedLibrary;
|
||||
}
|
||||
|
||||
/// An element that represents an extension.
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
|
@ -1191,14 +1184,6 @@ abstract class ExtensionElement implements TypeParameterizedElement {
|
|||
/// declared in this extension.
|
||||
List<PropertyAccessorElement> get accessors;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement2;
|
||||
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement3;
|
||||
|
||||
|
@ -1349,30 +1334,6 @@ abstract class HideElementCombinator implements NamespaceCombinator {
|
|||
List<String> get hiddenNames;
|
||||
}
|
||||
|
||||
/// A single import directive within a library.
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
@Deprecated('Use LibraryImportElement instead')
|
||||
abstract class ImportElement implements UriReferencedElement {
|
||||
/// Return a list containing the combinators that were specified as part of
|
||||
/// the import directive in the order in which they were specified.
|
||||
List<NamespaceCombinator> get combinators;
|
||||
|
||||
/// Return the library that is imported into this library by this import
|
||||
/// directive, or `null` if the URI has invalid syntax or cannot be resolved.
|
||||
LibraryElement? get importedLibrary;
|
||||
|
||||
/// Return `true` if this import is for a deferred library.
|
||||
bool get isDeferred;
|
||||
|
||||
/// The [Namespace] that this directive contributes to the containing library.
|
||||
Namespace get namespace;
|
||||
|
||||
/// Return the prefix that was specified as part of the import directive, or
|
||||
/// `null` if there was no prefix specified.
|
||||
PrefixElement? get prefix;
|
||||
}
|
||||
|
||||
/// Usage of a [PrefixElement] in an `import` directive.
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
|
@ -1561,14 +1522,6 @@ abstract class InterfaceOrAugmentationElement
|
|||
/// class, as is the case when this element represents an enum or a mixin.
|
||||
List<ConstructorElement> get constructors;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement2;
|
||||
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement3;
|
||||
|
||||
|
@ -1610,14 +1563,6 @@ abstract class InterfaceOrAugmentationElement
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class LabelElement implements Element {
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
ExecutableElement get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
ExecutableElement get enclosingElement2;
|
||||
|
||||
@override
|
||||
ExecutableElement get enclosingElement3;
|
||||
|
||||
|
@ -1684,12 +1629,6 @@ abstract class LibraryElement
|
|||
@override
|
||||
String get name;
|
||||
|
||||
/// Return a list containing all of the compilation units that are included in
|
||||
/// this library using a `part` directive. This does not include the defining
|
||||
/// compilation unit that contains the `part` directives.
|
||||
@Deprecated('Use parts2 instead')
|
||||
List<CompilationUnitElement> get parts;
|
||||
|
||||
/// Returns the list of `part` directives of this library.
|
||||
List<PartElement> get parts2;
|
||||
|
||||
|
@ -1710,16 +1649,6 @@ abstract class LibraryElement
|
|||
/// `null` if this library does not define a class with the given name.
|
||||
ClassElement? getClass(String name);
|
||||
|
||||
/// Return a list containing all of the imports that share the given [prefix],
|
||||
/// or an empty array if there are no such imports.
|
||||
@Deprecated('Use PrefixElement.imports instead')
|
||||
List<ImportElement> getImportsWithPrefix(PrefixElement prefix);
|
||||
|
||||
/// Return the class defined in this library that has the given [name], or
|
||||
/// `null` if this library does not define a class with the given name.
|
||||
@Deprecated('Use getClass() instead')
|
||||
ClassElement? getType(String className);
|
||||
|
||||
/// If a legacy library, return the legacy view on the [element].
|
||||
/// Otherwise, return the original element.
|
||||
T toLegacyElementIfOptOut<T extends Element>(T element);
|
||||
|
@ -1806,10 +1735,6 @@ abstract class LibraryOrAugmentationElement implements Element {
|
|||
/// Return the compilation unit that defines this library.
|
||||
CompilationUnitElement get definingCompilationUnit;
|
||||
|
||||
/// Return a list containing all of the exports defined in this library.
|
||||
@Deprecated('Use libraryExports instead')
|
||||
List<ExportElement> get exports;
|
||||
|
||||
/// The set of features available to this library.
|
||||
///
|
||||
/// Determined by the combination of the language version for the enclosing
|
||||
|
@ -1817,10 +1742,6 @@ abstract class LibraryOrAugmentationElement implements Element {
|
|||
/// version override comment at the top of the file.
|
||||
FeatureSet get featureSet;
|
||||
|
||||
/// Return a list containing all of the imports defined in this library.
|
||||
@Deprecated('Use libraryImports instead')
|
||||
List<ImportElement> get imports;
|
||||
|
||||
bool get isNonNullableByDefault;
|
||||
|
||||
/// The language version for this library.
|
||||
|
@ -1915,10 +1836,7 @@ abstract class MixinAugmentationElement implements MixinOrAugmentationElement {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class MixinElement
|
||||
implements
|
||||
MixinOrAugmentationElement,
|
||||
InterfaceElement,
|
||||
_TmpSharedClassElement {
|
||||
implements MixinOrAugmentationElement, InterfaceElement {
|
||||
/// Returns the result of applying augmentations to this element.
|
||||
AugmentedMixinElement get augmented;
|
||||
|
||||
|
@ -1931,7 +1849,6 @@ abstract class MixinElement
|
|||
/// safe to assume that the inheritance structure of a class does not contain
|
||||
/// a cycle. Clients that traverse the inheritance structure must explicitly
|
||||
/// guard against infinite loops.
|
||||
@override
|
||||
List<InterfaceType> get superclassConstraints;
|
||||
}
|
||||
|
||||
|
@ -2002,18 +1919,6 @@ abstract class ParameterElement
|
|||
/// are considered required.
|
||||
bool get isNamed;
|
||||
|
||||
/// Return `true` if this parameter is a required parameter. Required
|
||||
/// parameters are always positional, unless the experiment 'non-nullable' is
|
||||
/// enabled, in which case named parameters can also be required.
|
||||
///
|
||||
/// Note: regardless of the state of the 'non-nullable' experiment, the
|
||||
/// presence or absence of the `@required` annotation does not change the
|
||||
/// meaning of this getter. The parameter `{@required int x}` will return
|
||||
/// `false` and the parameter `{@required required int x}` will return
|
||||
/// `true`
|
||||
@Deprecated('Use isRequired instead')
|
||||
bool get isNotOptional;
|
||||
|
||||
/// Return `true` if this parameter is an optional parameter. Optional
|
||||
/// parameters can either be positional or named. Named parameters that are
|
||||
/// annotated with the `@required` annotation are considered optional. Named
|
||||
|
@ -2095,22 +2000,10 @@ abstract class PartElement implements _ExistingElement {
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class PrefixElement implements _ExistingElement {
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
LibraryElement get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
LibraryOrAugmentationElement get enclosingElement2;
|
||||
|
||||
/// Return the library, or library augmentation that encloses this element.
|
||||
@override
|
||||
LibraryOrAugmentationElement get enclosingElement3;
|
||||
|
||||
/// Return the imports that share this prefix.
|
||||
@Deprecated('Use imports2 instead')
|
||||
List<ImportElement> get imports;
|
||||
|
||||
/// Return the imports that share this prefix.
|
||||
List<LibraryImportElement> get imports2;
|
||||
|
||||
|
@ -2180,14 +2073,6 @@ abstract class PropertyAccessorElement implements ExecutableElement {
|
|||
@override
|
||||
PropertyAccessorElement get declaration;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
Element get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
Element get enclosingElement2;
|
||||
|
||||
@override
|
||||
Element get enclosingElement3;
|
||||
|
||||
|
@ -2307,14 +2192,6 @@ abstract class TypeAliasElement
|
|||
/// a [FunctionType].
|
||||
DartType get aliasedType;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement;
|
||||
|
||||
@Deprecated('Use enclosingElement3 instead')
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement2;
|
||||
|
||||
@override
|
||||
CompilationUnitElement get enclosingElement3;
|
||||
|
||||
|
@ -2474,127 +2351,3 @@ abstract class _ExistingElement implements Element {
|
|||
@override
|
||||
Source get source;
|
||||
}
|
||||
|
||||
/// Properties that existed in [ClassElement], so we should keep them for
|
||||
/// backward compatibility for now. But we want them to be either moved, or
|
||||
/// removed.
|
||||
abstract class _TmpSharedClassElement {
|
||||
/// Return `true` if this class or its superclass declares a non-final
|
||||
/// instance field.
|
||||
bool get hasNonFinalField;
|
||||
|
||||
/// Return `true` if this class declares a static member.
|
||||
@Deprecated('Not useful for clients')
|
||||
bool get hasStaticMember;
|
||||
|
||||
/// Return `true` if this class is abstract. A class is abstract if it has an
|
||||
/// explicit `abstract` modifier or if it is implicitly abstract, such as a
|
||||
/// class defined by a mixin declaration. Note, that this definition of
|
||||
/// <i>abstract</i> is different from <i>has unimplemented members</i>.
|
||||
/// TODO(scheglov) Deprecate and replace it.
|
||||
bool get isAbstract;
|
||||
|
||||
/// Return `true` if this class represents the class 'Enum' defined in the
|
||||
/// dart:core library.
|
||||
bool get isDartCoreEnum;
|
||||
|
||||
/// Return `true` if this class represents the class 'Object' defined in the
|
||||
/// dart:core library.
|
||||
bool get isDartCoreObject;
|
||||
|
||||
/// Return `true` if this class is defined by an enum declaration.
|
||||
@Deprecated('Use `is EnumElement` instead')
|
||||
bool get isEnum;
|
||||
|
||||
/// Return `true` if this class is defined by a mixin declaration.
|
||||
@Deprecated('Use `is MixinElement` instead')
|
||||
bool get isMixin;
|
||||
|
||||
/// Return `true` if this class is a mixin application. A class is a mixin
|
||||
/// application if it was declared using the syntax "class A = B with C;".
|
||||
bool get isMixinApplication;
|
||||
|
||||
/// Return `true` if this class can validly be used as a mixin when defining
|
||||
/// another class. For classes defined by a mixin declaration, the result is
|
||||
/// always `true`. For classes defined by a class declaration or a mixin
|
||||
/// application, the behavior of this method is defined by the Dart Language
|
||||
/// Specification in section 9:
|
||||
/// <blockquote>
|
||||
/// It is a compile-time error if a declared or derived mixin refers to super.
|
||||
/// It is a compile-time error if a declared or derived mixin explicitly
|
||||
/// declares a constructor. It is a compile-time error if a mixin is derived
|
||||
/// from a class whose superclass is not Object.
|
||||
/// </blockquote>
|
||||
/// TODO(scheglov) Deprecate and remove it.
|
||||
bool get isValidMixin;
|
||||
|
||||
/// Return a list containing all of the superclass constraints defined for
|
||||
/// this class. The list will be empty if this class does not represent a
|
||||
/// mixin declaration. If this class _does_ represent a mixin declaration but
|
||||
/// the declaration does not have an `on` clause, then the list will contain
|
||||
/// the type for the class `Object`.
|
||||
///
|
||||
/// <b>Note:</b> Because the element model represents the state of the code,
|
||||
/// it is possible for it to be semantically invalid. In particular, it is not
|
||||
/// safe to assume that the inheritance structure of a class does not contain
|
||||
/// a cycle. Clients that traverse the inheritance structure must explicitly
|
||||
/// guard against infinite loops.
|
||||
/// TODO(scheglov) Deprecate and remove it.
|
||||
List<InterfaceType> get superclassConstraints;
|
||||
|
||||
/// Return the element representing the getter that results from looking up
|
||||
/// the given [getterName] in the superclass of this class with respect to the
|
||||
/// given [library], ignoring abstract getters, or `null` if the look up
|
||||
/// fails. The behavior of this method is defined by the Dart Language
|
||||
/// Specification in section 16.15.2:
|
||||
/// <blockquote>
|
||||
/// The result of looking up getter (respectively setter) <i>m</i> in class
|
||||
/// <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
|
||||
/// instance getter (respectively setter) named <i>m</i> that is accessible to
|
||||
/// <i>L</i>, then that getter (respectively setter) is the result of the
|
||||
/// lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
|
||||
/// of the lookup is the result of looking up getter (respectively setter)
|
||||
/// <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
|
||||
/// lookup has failed.
|
||||
/// </blockquote>
|
||||
/// TODO(scheglov) Deprecate and remove it.
|
||||
PropertyAccessorElement? lookUpInheritedConcreteGetter(
|
||||
String getterName, LibraryElement library);
|
||||
|
||||
/// Return the element representing the method that results from looking up
|
||||
/// the given [methodName] in the superclass of this class with respect to the
|
||||
/// given [library], ignoring abstract methods, or `null` if the look up
|
||||
/// fails. The behavior of this method is defined by the Dart Language
|
||||
/// Specification in section 16.15.1:
|
||||
/// <blockquote>
|
||||
/// The result of looking up method <i>m</i> in class <i>C</i> with respect to
|
||||
/// library <i>L</i> is: If <i>C</i> declares an instance method named
|
||||
/// <i>m</i> that is accessible to <i>L</i>, then that method is the result of
|
||||
/// the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
|
||||
/// result of the lookup is the result of looking up method <i>m</i> in
|
||||
/// <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
|
||||
/// failed.
|
||||
/// </blockquote>
|
||||
/// TODO(scheglov) Deprecate and remove it.
|
||||
MethodElement? lookUpInheritedConcreteMethod(
|
||||
String methodName, LibraryElement library);
|
||||
|
||||
/// Return the element representing the setter that results from looking up
|
||||
/// the given [setterName] in the superclass of this class with respect to the
|
||||
/// given [library], ignoring abstract setters, or `null` if the look up
|
||||
/// fails. The behavior of this method is defined by the Dart Language
|
||||
/// Specification in section 16.15.2:
|
||||
/// <blockquote>
|
||||
/// The result of looking up getter (respectively setter) <i>m</i> in class
|
||||
/// <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
|
||||
/// instance getter (respectively setter) named <i>m</i> that is accessible to
|
||||
/// <i>L</i>, then that getter (respectively setter) is the result of the
|
||||
/// lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
|
||||
/// of the lookup is the result of looking up getter (respectively setter)
|
||||
/// <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
|
||||
/// lookup has failed.
|
||||
/// </blockquote>
|
||||
/// TODO(scheglov) Deprecate and remove it.
|
||||
PropertyAccessorElement? lookUpInheritedConcreteSetter(
|
||||
String setterName, LibraryElement library);
|
||||
}
|
||||
|
|
|
@ -33,21 +33,6 @@ abstract class DartType {
|
|||
/// Otherwise return `null`.
|
||||
InstantiatedTypeAliasElement? get alias;
|
||||
|
||||
/// Return the name of this type as it should appear when presented to users
|
||||
/// in contexts such as error messages.
|
||||
///
|
||||
/// Clients should not depend on the content of the returned value as it will
|
||||
/// be changed if doing so would improve the UX.
|
||||
@Deprecated('Use getDisplayString instead')
|
||||
String get displayName;
|
||||
|
||||
/// Return the element representing the declaration of this type, or `null` if
|
||||
/// the type has not, or cannot, be associated with an element. The former
|
||||
/// case will occur if the element model is not yet complete; the latter case
|
||||
/// will occur if this object represents an undefined type.
|
||||
@Deprecated('Use element2 instead')
|
||||
Element? get element;
|
||||
|
||||
/// Return the element representing the declaration of this type, or `null`
|
||||
/// if the type is not associated with an element.
|
||||
Element? get element2;
|
||||
|
@ -210,10 +195,6 @@ abstract class DynamicType implements DartType {}
|
|||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
abstract class FunctionType implements DartType {
|
||||
@Deprecated('Use element2 instead')
|
||||
@override
|
||||
Null get element;
|
||||
|
||||
@override
|
||||
Null get element2;
|
||||
|
||||
|
@ -294,10 +275,6 @@ abstract class InterfaceType implements ParameterizedType {
|
|||
/// Return a list containing all of the constructors declared in this type.
|
||||
List<ConstructorElement> get constructors;
|
||||
|
||||
@Deprecated('Use element2 instead')
|
||||
@override
|
||||
ClassElement get element;
|
||||
|
||||
@override
|
||||
InterfaceElement get element2;
|
||||
|
||||
|
@ -441,10 +418,6 @@ abstract class ParameterizedType implements DartType {
|
|||
/// Clients may not extend, implement or mix-in this class.
|
||||
@experimental
|
||||
abstract class RecordType implements DartType {
|
||||
@Deprecated('Use element2 instead')
|
||||
@override
|
||||
Null get element;
|
||||
|
||||
@override
|
||||
Null get element2;
|
||||
|
||||
|
@ -494,10 +467,6 @@ abstract class TypeParameterType implements DartType {
|
|||
/// Always consult the bound if that could be relevant.
|
||||
ElementLocation get definition;
|
||||
|
||||
@Deprecated('Use element2 instead')
|
||||
@override
|
||||
TypeParameterElement get element;
|
||||
|
||||
@override
|
||||
TypeParameterElement get element2;
|
||||
}
|
||||
|
@ -505,10 +474,6 @@ abstract class TypeParameterType implements DartType {
|
|||
/// The special type `void` is used to indicate that the value of an
|
||||
/// expression is meaningless, and intended to be discarded.
|
||||
abstract class VoidType implements DartType {
|
||||
@Deprecated('Use element2 instead')
|
||||
@override
|
||||
Null get element;
|
||||
|
||||
@override
|
||||
Null get element2;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue