The subset of data-driven fixes that can be committed at this point
Change-Id: I76e115efbbef1649d53d01ffdff3473446330f0d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194117 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
43b5d134b3
commit
cf8761d37a
@@ -2,8 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/parameter_reference.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
|
||||
@@ -11,7 +9,7 @@ import 'package:analyzer/dart/ast/ast.dart';
|
||||
abstract class Accessor {
|
||||
/// Return the result of using this accessor to access a value from the
|
||||
/// [target].
|
||||
AccessorResult getValue(Object target);
|
||||
AccessorResult getValue(Object? target);
|
||||
}
|
||||
|
||||
/// The result of using an accessor to get a result.
|
||||
@@ -35,10 +33,10 @@ class ArgumentAccessor extends Accessor {
|
||||
|
||||
/// Initialize a newly created accessor to access the argument that
|
||||
/// corresponds to the given [parameter].
|
||||
ArgumentAccessor(this.parameter) : assert(parameter != null);
|
||||
ArgumentAccessor(this.parameter);
|
||||
|
||||
@override
|
||||
AccessorResult getValue(Object target) {
|
||||
AccessorResult getValue(Object? target) {
|
||||
if (target is AstNode) {
|
||||
var argumentList = _getArgumentList(target);
|
||||
if (argumentList != null) {
|
||||
@@ -55,7 +53,7 @@ class ArgumentAccessor extends Accessor {
|
||||
String toString() => 'arguments[$parameter]';
|
||||
|
||||
/// Return the argument list associated with the [node].
|
||||
ArgumentList _getArgumentList(AstNode node) {
|
||||
ArgumentList? _getArgumentList(AstNode node) {
|
||||
if (node is Annotation) {
|
||||
return node.arguments;
|
||||
} else if (node is ExtensionOverride) {
|
||||
@@ -92,19 +90,16 @@ class TypeArgumentAccessor extends Accessor {
|
||||
|
||||
/// Initialize a newly created accessor to access the type argument at the
|
||||
/// given [index].
|
||||
TypeArgumentAccessor(this.index) : assert(index != null);
|
||||
TypeArgumentAccessor(this.index);
|
||||
|
||||
@override
|
||||
AccessorResult getValue(Object target) {
|
||||
AccessorResult getValue(Object? target) {
|
||||
if (target is AstNode) {
|
||||
var typeArgumentList = _getTypeArgumentList(target);
|
||||
if (typeArgumentList != null) {
|
||||
var arguments = typeArgumentList.arguments;
|
||||
if (arguments.length > index) {
|
||||
var argument = arguments[index];
|
||||
if (argument != null) {
|
||||
return ValidResult(argument);
|
||||
}
|
||||
return ValidResult(arguments[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,7 +110,7 @@ class TypeArgumentAccessor extends Accessor {
|
||||
String toString() => 'typeArguments[$index]';
|
||||
|
||||
/// Return the type argument list associated with the [node].
|
||||
TypeArgumentList _getTypeArgumentList(AstNode node) {
|
||||
TypeArgumentList? _getTypeArgumentList(AstNode node) {
|
||||
if (node is ExtensionOverride) {
|
||||
return node.typeArguments;
|
||||
} else if (node is InstanceCreationExpression) {
|
||||
|
||||
+4
-8
@@ -2,13 +2,10 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
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/type.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// The path to an element.
|
||||
class ElementDescriptor {
|
||||
@@ -27,9 +24,9 @@ class ElementDescriptor {
|
||||
/// within the library is given by the list of [components]. The [kind] of the
|
||||
/// element is represented by the key used in the data file.
|
||||
ElementDescriptor(
|
||||
{@required this.libraryUris,
|
||||
@required this.kind,
|
||||
@required this.components});
|
||||
{required this.libraryUris,
|
||||
required this.kind,
|
||||
required this.components});
|
||||
|
||||
/// Return `true` if the described element is a constructor.
|
||||
bool get isConstructor => kind == ElementKind.constructorKind;
|
||||
@@ -118,7 +115,7 @@ class ElementDescriptor {
|
||||
// that the method might have been in the element's class.
|
||||
return true;
|
||||
}
|
||||
if (components[1] == type.element.name) {
|
||||
if (components[1] == type.element?.name) {
|
||||
return true;
|
||||
}
|
||||
if (type is InterfaceType) {
|
||||
@@ -145,7 +142,6 @@ class ElementDescriptor {
|
||||
// TODO: Handle this case.
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String _nameFromIdentifier(Identifier identifier) {
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
/// An indication of the kind of an element.
|
||||
enum ElementKind {
|
||||
classKind,
|
||||
@@ -23,7 +21,7 @@ enum ElementKind {
|
||||
|
||||
extension ElementKindUtilities on ElementKind {
|
||||
/// Return the element kind corresponding to the given [name].
|
||||
static ElementKind fromName(String name) {
|
||||
static ElementKind? fromName(String name) {
|
||||
for (var kind in ElementKind.values) {
|
||||
if (kind.toString() == 'ElementKind.${name}Kind') {
|
||||
return kind;
|
||||
|
||||
+34
-25
@@ -2,15 +2,12 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/element_descriptor.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/element_kind.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart'
|
||||
show ClassElement, ExtensionElement;
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// An object that can be used to determine whether an element is appropriate
|
||||
/// for a given reference.
|
||||
@@ -31,10 +28,10 @@ class ElementMatcher {
|
||||
/// Initialize a newly created matcher representing a reference to an element
|
||||
/// with the given [name] in a library that imports the [importedUris].
|
||||
ElementMatcher(
|
||||
{@required this.importedUris,
|
||||
@required this.components,
|
||||
List<ElementKind> kinds})
|
||||
: assert(components != null && components.isNotEmpty),
|
||||
{required this.importedUris,
|
||||
required this.components,
|
||||
List<ElementKind>? kinds})
|
||||
: assert(components.isNotEmpty),
|
||||
validKinds = kinds ?? const [];
|
||||
|
||||
/// Return `true` if this matcher matches the given [element].
|
||||
@@ -99,7 +96,7 @@ class ElementMatcher {
|
||||
/// Return an element matcher that will match the element that is, or should
|
||||
/// be, associated with the given [node], or `null` if there is no appropriate
|
||||
/// matcher for the node.
|
||||
static ElementMatcher forNode(AstNode node) {
|
||||
static ElementMatcher? forNode(AstNode? node) {
|
||||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -122,14 +119,14 @@ class ElementMatcher {
|
||||
/// For example, for a constructor this would be the name of the constructor
|
||||
/// followed by the name of the class in which the constructor is declared
|
||||
/// (with an empty string for the unnamed constructor).
|
||||
static List<String> _componentsForNode(AstNode node) {
|
||||
static List<String>? _componentsForNode(AstNode? node) {
|
||||
if (node is SimpleIdentifier) {
|
||||
var parent = node.parent;
|
||||
if (parent is Label && parent.parent is NamedExpression) {
|
||||
// The parent of the named expression is an argument list. Because we
|
||||
// don't represent parameters as elements, the element we need to match
|
||||
// against is the invocation containing those arguments.
|
||||
return _componentsFromParent(parent.parent.parent);
|
||||
return _componentsFromParent(parent.parent!.parent!);
|
||||
} else if (parent is TypeName && parent.parent is ConstructorName) {
|
||||
return ['', node.name];
|
||||
} else if (parent is MethodDeclaration && node == parent.name) {
|
||||
@@ -147,15 +144,20 @@ class ElementMatcher {
|
||||
}
|
||||
return [node.identifier.name];
|
||||
} else if (node is ConstructorName) {
|
||||
return [node.name.name];
|
||||
var constructorName = node.name;
|
||||
if (constructorName != null) {
|
||||
return [constructorName.name];
|
||||
}
|
||||
} else if (node is NamedType) {
|
||||
return [node.name.name];
|
||||
} else if (node is TypeArgumentList) {
|
||||
return _componentsFromParent(node);
|
||||
} else if (node is ArgumentList) {
|
||||
return _componentsFromParent(node);
|
||||
} else if (node?.parent is ArgumentList) {
|
||||
return _componentsFromParent(node.parent);
|
||||
}
|
||||
var parent = node?.parent;
|
||||
if (parent is ArgumentList) {
|
||||
return _componentsFromParent(parent);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -172,9 +174,13 @@ class ElementMatcher {
|
||||
}
|
||||
if (element != null) {
|
||||
var enclosingElement = element.enclosingElement;
|
||||
if (enclosingElement is ClassElement ||
|
||||
enclosingElement is ExtensionElement) {
|
||||
if (enclosingElement is ClassElement) {
|
||||
return [identifier.name, enclosingElement.name];
|
||||
} else if (enclosingElement is ExtensionElement) {
|
||||
var name = enclosingElement.name;
|
||||
if (name != null) {
|
||||
return [identifier.name, name];
|
||||
}
|
||||
}
|
||||
}
|
||||
return [identifier.name];
|
||||
@@ -182,7 +188,7 @@ class ElementMatcher {
|
||||
|
||||
/// Return the components for the element associated with the given [node] by
|
||||
/// looking at the parent of the [node].
|
||||
static List<String> _componentsFromParent(AstNode node) {
|
||||
static List<String>? _componentsFromParent(AstNode node) {
|
||||
var parent = node.parent;
|
||||
if (parent is ArgumentList) {
|
||||
parent = parent.parent;
|
||||
@@ -231,17 +237,20 @@ class ElementMatcher {
|
||||
|
||||
/// Return the URIs of the imports in the library containing the [node], or
|
||||
/// `null` if the imports can't be determined.
|
||||
static List<Uri> _importElementsForNode(AstNode node) {
|
||||
static List<Uri>? _importElementsForNode(AstNode node) {
|
||||
var root = node.root;
|
||||
if (root is! CompilationUnit) {
|
||||
return null;
|
||||
}
|
||||
var importedUris = <Uri>[];
|
||||
var library = (root as CompilationUnit).declaredElement.library;
|
||||
var library = root.declaredElement?.library;
|
||||
if (library == null) {
|
||||
return null;
|
||||
}
|
||||
for (var importElement in library.imports) {
|
||||
// TODO(brianwilkerson) Filter based on combinators to help avoid making
|
||||
// invalid suggestions.
|
||||
var uri = importElement.importedLibrary?.source?.uri;
|
||||
var uri = importElement.importedLibrary?.source.uri;
|
||||
if (uri != null) {
|
||||
// The [uri] is `null` if the literal string is not a valid URI.
|
||||
importedUris.add(uri);
|
||||
@@ -251,9 +260,9 @@ class ElementMatcher {
|
||||
}
|
||||
|
||||
/// Return the kinds of elements that could reasonably be referenced at the
|
||||
/// location of the [node]. If [child] is no `null` then the [node] is a
|
||||
/// parent of the original node.
|
||||
static List<ElementKind> _kindsForNode(AstNode node, {AstNode child}) {
|
||||
/// location of the [node]. If [child] is not `null` then the [node] is a
|
||||
/// parent of the [child].
|
||||
static List<ElementKind>? _kindsForNode(AstNode? node, {AstNode? child}) {
|
||||
if (node is ConstructorName) {
|
||||
return const [ElementKind.constructorKind];
|
||||
} else if (node is ExtensionOverride) {
|
||||
@@ -261,8 +270,8 @@ class ElementMatcher {
|
||||
} else if (node is InstanceCreationExpression) {
|
||||
return const [ElementKind.constructorKind];
|
||||
} else if (node is Label) {
|
||||
var argumentList = node.parent.parent;
|
||||
return _kindsForNode(argumentList.parent, child: argumentList);
|
||||
var argumentList = node.parent?.parent;
|
||||
return _kindsForNode(argumentList?.parent, child: argumentList);
|
||||
} else if (node is MethodInvocation) {
|
||||
assert(child != null);
|
||||
if (node.target == child) {
|
||||
@@ -315,7 +324,7 @@ class ElementMatcher {
|
||||
}
|
||||
|
||||
/// Return the name of the class associated with the given [target].
|
||||
static String _nameOfTarget(Expression target) {
|
||||
static String? _nameOfTarget(Expression? target) {
|
||||
if (target is SimpleIdentifier) {
|
||||
var type = target.staticType;
|
||||
if (type != null) {
|
||||
|
||||
+3
-5
@@ -2,8 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
|
||||
/// A reference to a named parameter.
|
||||
@@ -16,7 +14,7 @@ class NamedParameterReference extends ParameterReference {
|
||||
NamedParameterReference(this.name) : assert(name.isNotEmpty);
|
||||
|
||||
@override
|
||||
Expression argumentFrom(ArgumentList argumentList) {
|
||||
Expression? argumentFrom(ArgumentList argumentList) {
|
||||
for (var argument in argumentList.arguments) {
|
||||
if (argument is NamedExpression && argument.name.label.name == name) {
|
||||
return argument.expression;
|
||||
@@ -35,7 +33,7 @@ abstract class ParameterReference {
|
||||
/// parameter, or `null` if there is no argument corresponding to the
|
||||
/// parameter. Note that for named parameters this will be an expression whose
|
||||
/// parent is a named expression.
|
||||
Expression argumentFrom(ArgumentList argumentList);
|
||||
Expression? argumentFrom(ArgumentList argumentList);
|
||||
}
|
||||
|
||||
/// A reference to a positional parameter.
|
||||
@@ -48,7 +46,7 @@ class PositionalParameterReference extends ParameterReference {
|
||||
PositionalParameterReference(this.index) : assert(index >= 0);
|
||||
|
||||
@override
|
||||
Expression argumentFrom(ArgumentList argumentList) {
|
||||
Expression? argumentFrom(ArgumentList argumentList) {
|
||||
var arguments = argumentList.arguments;
|
||||
if (index >= arguments.length) {
|
||||
return null;
|
||||
|
||||
+2
-6
@@ -2,10 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// A description of a set of changes to a single transform.
|
||||
class TransformOverride {
|
||||
/// The title of the transform being overridden.
|
||||
@@ -13,12 +9,12 @@ class TransformOverride {
|
||||
|
||||
/// The overridden value of the `bulkApply` property of the transform, or
|
||||
/// `null` if the property should not be overridden.
|
||||
final bool bulkApply;
|
||||
final bool? bulkApply;
|
||||
|
||||
/// Initialize a newly created transform override to override the transform
|
||||
/// with the given [title]. The remaining parameters correspond to properties
|
||||
/// of the transform. They should have non-null values when the property is to
|
||||
/// be overridden, and a value of `null` when the property should be
|
||||
/// unchanged.
|
||||
TransformOverride({@required this.title, this.bulkApply});
|
||||
TransformOverride({required this.title, this.bulkApply});
|
||||
}
|
||||
|
||||
+1
-3
@@ -2,8 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_override.dart';
|
||||
|
||||
/// A description of a set of transform overrides.
|
||||
@@ -24,5 +22,5 @@ class TransformOverrideSet {
|
||||
|
||||
/// Return the override for the transform with the given [title] or `null` if
|
||||
/// there is no such override in this set.
|
||||
TransformOverride overrideForTransform(String title) => overrideMap[title];
|
||||
TransformOverride? overrideForTransform(String title) => overrideMap[title];
|
||||
}
|
||||
|
||||
+1
-3
@@ -2,8 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
// ignore_for_file: prefer_single_quotes, slash_for_doc_comments
|
||||
import 'package:analyzer/error/error.dart';
|
||||
|
||||
@@ -160,7 +158,7 @@ class TransformSetErrorCode extends ErrorCode {
|
||||
const TransformSetErrorCode(
|
||||
String name,
|
||||
String message, {
|
||||
String correction,
|
||||
String? correction,
|
||||
bool hasPublishedDocs = false,
|
||||
}) : super(
|
||||
correction: correction,
|
||||
|
||||
Reference in New Issue
Block a user