Skip to content

Commit 140afee

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
analyzer: Prepare some APIs for null safety; specify returns more accurately
Change-Id: Ia71bf5958d28c4229f68c0a1612cf44a2f283419 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175903 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent b0efb37 commit 140afee

File tree

7 files changed

+21
-20
lines changed

7 files changed

+21
-20
lines changed

pkg/analyzer/lib/src/dart/constant/evaluation.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ConstantEvaluationEngine {
8181
/// arguments are correct, `false` if there is an error.
8282
bool checkFromEnvironmentArguments(
8383
LibraryElementImpl library,
84-
NodeList<Expression> arguments,
84+
List<Expression> arguments,
8585
List<DartObjectImpl> argumentValues,
8686
Map<String, DartObjectImpl> namedArgumentValues,
8787
InterfaceType expectedDefaultValueType) {
@@ -271,7 +271,7 @@ class ConstantEvaluationEngine {
271271
constant = (constant as ConstructorElement).declaration;
272272
}
273273
if (constant is VariableElement) {
274-
VariableElementImpl declaration = constant.declaration;
274+
var declaration = constant.declaration as VariableElementImpl;
275275
Expression initializer = declaration.constantInitializer;
276276
if (initializer != null) {
277277
initializer.accept(referenceFinder);
@@ -497,7 +497,7 @@ class ConstantEvaluationEngine {
497497
definingType,
498498
);
499499
}
500-
ConstructorElementImpl constructorBase = constructor.declaration;
500+
var constructorBase = constructor.declaration as ConstructorElementImpl;
501501
List<ConstructorInitializer> initializers =
502502
constructorBase.constantInitializers;
503503
if (initializers == null) {
@@ -1550,7 +1550,7 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
15501550
return false;
15511551
} else if (element is SpreadElement) {
15521552
DartObjectImpl elementResult = element.expression.accept(this);
1553-
Map<DartObject, DartObject> value = elementResult?.toMapValue();
1553+
Map<DartObjectImpl, DartObjectImpl> value = elementResult?.toMapValue();
15541554
if (value == null) {
15551555
return true;
15561556
}
@@ -1662,9 +1662,9 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
16621662
return value.value;
16631663
}
16641664
} else if (variableElement is ExecutableElement) {
1665-
ExecutableElement function = element;
1665+
var function = element as ExecutableElement;
16661666
if (function.isStatic) {
1667-
var functionType = node.staticType;
1667+
var functionType = node.staticType as ParameterizedType;
16681668
return DartObjectImpl(
16691669
typeSystem,
16701670
functionType,

pkg/analyzer/lib/src/dart/element/element.dart

+8-6
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ abstract class AbstractClassElementImpl extends ElementImpl
267267
/// This method should be used only for error recovery during analysis,
268268
/// when instance access to a static class member, defined in this class,
269269
/// or a superclass.
270-
ExecutableElement lookupStaticGetter(String name, LibraryElement library) {
270+
PropertyAccessorElement lookupStaticGetter(
271+
String name, LibraryElement library) {
271272
return _first(_implementationsOfGetter(name).where((element) {
272273
return element.isStatic && element.isAccessibleIn(library);
273274
}));
@@ -278,7 +279,7 @@ abstract class AbstractClassElementImpl extends ElementImpl
278279
/// This method should be used only for error recovery during analysis,
279280
/// when instance access to a static class member, defined in this class,
280281
/// or a superclass.
281-
ExecutableElement lookupStaticMethod(String name, LibraryElement library) {
282+
MethodElement lookupStaticMethod(String name, LibraryElement library) {
282283
return _first(_implementationsOfMethod(name).where((element) {
283284
return element.isStatic && element.isAccessibleIn(library);
284285
}));
@@ -289,7 +290,8 @@ abstract class AbstractClassElementImpl extends ElementImpl
289290
/// This method should be used only for error recovery during analysis,
290291
/// when instance access to a static class member, defined in this class,
291292
/// or a superclass.
292-
ExecutableElement lookupStaticSetter(String name, LibraryElement library) {
293+
PropertyAccessorElement lookupStaticSetter(
294+
String name, LibraryElement library) {
293295
return _first(_implementationsOfSetter(name).where((element) {
294296
return element.isStatic && element.isAccessibleIn(library);
295297
}));
@@ -631,7 +633,7 @@ class ClassElementImpl extends AbstractClassElementImpl
631633
bool get hasNoSuchMethod {
632634
MethodElement method = lookUpConcreteMethod(
633635
FunctionElement.NO_SUCH_METHOD_METHOD_NAME, library);
634-
ClassElement definingClass = method?.enclosingElement;
636+
var definingClass = method?.enclosingElement as ClassElement;
635637
return definingClass != null && !definingClass.isDartCoreObject;
636638
}
637639

@@ -902,7 +904,7 @@ class ClassElementImpl extends AbstractClassElementImpl
902904
return <ConstructorElement>[];
903905
}
904906

905-
ClassElementImpl superElement = supertype.element;
907+
var superElement = supertype.element as ClassElementImpl;
906908

907909
// First get the list of constructors of the superclass which need to be
908910
// forwarded to this class.
@@ -7275,7 +7277,7 @@ class TypeParameterElementImpl extends ElementImpl
72757277
@override
72767278
String get name {
72777279
if (linkedNode != null) {
7278-
TypeParameter node = linkedNode;
7280+
var node = linkedNode as TypeParameter;
72797281
return node.name.name;
72807282
}
72817283
return super.name;

pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ class InheritanceManager3 {
743743
FunctionType resultType;
744744
for (var executable in validOverrides) {
745745
var type = executable.type;
746-
var normalizedType = typeSystem.normalize(type);
746+
var normalizedType = typeSystem.normalize(type) as FunctionType;
747747
if (resultType == null) {
748748
resultType = normalizedType;
749749
} else {

pkg/analyzer/lib/src/dart/element/member.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:analyzer/dart/constant/value.dart';
77
import 'package:analyzer/dart/element/element.dart';
88
import 'package:analyzer/dart/element/nullability_suffix.dart';
99
import 'package:analyzer/dart/element/type.dart';
10-
import 'package:analyzer/dart/element/type_provider.dart';
1110
import 'package:analyzer/src/dart/element/display_string_builder.dart';
1211
import 'package:analyzer/src/dart/element/element.dart';
1312
import 'package:analyzer/src/dart/element/nullability_eliminator.dart';
@@ -220,7 +219,7 @@ abstract class ExecutableMember extends Member implements ExecutableElement {
220219
return null;
221220
}
222221

223-
TypeProvider typeProvider;
222+
TypeProviderImpl typeProvider;
224223
var isLegacy = false;
225224
var combined = substitution;
226225
if (element is ExecutableMember) {
@@ -237,7 +236,7 @@ abstract class ExecutableMember extends Member implements ExecutableElement {
237236
map.addAll(substitution.map);
238237
combined = Substitution.fromMap(map);
239238
} else {
240-
typeProvider = element.library.typeProvider;
239+
typeProvider = element.library.typeProvider as TypeProviderImpl;
241240
}
242241

243242
if (!isLegacy && combined.map.isEmpty) {

pkg/analyzer/lib/src/dart/element/type.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -1468,12 +1468,12 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
14681468
/// search should include the target type. The [visitedInterfaces] is a set
14691469
/// containing all of the interfaces that have been examined, used to prevent
14701470
/// infinite recursion and to optimize the search.
1471-
static ExecutableElement _lookUpMemberInInterfaces(
1471+
static T _lookUpMemberInInterfaces<T extends ExecutableElement>(
14721472
InterfaceType targetType,
14731473
bool includeTargetType,
14741474
LibraryElement library,
14751475
HashSet<ClassElement> visitedInterfaces,
1476-
ExecutableElement Function(InterfaceType type) getMember) {
1476+
T Function(InterfaceType type) getMember) {
14771477
// TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the
14781478
// specification (titled "Inheritance and Overriding" under "Interfaces")
14791479
// describes a much more complex scheme for finding the inherited member.

pkg/analyzer/lib/src/dart/element/type_algebra.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ abstract class Substitution {
160160

161161
/// Substitutes the type parameters on the class of [type] with the
162162
/// type arguments provided in [type].
163-
static Substitution fromInterfaceType(InterfaceType type) {
163+
static MapSubstitution fromInterfaceType(InterfaceType type) {
164164
if (type.typeArguments.isEmpty) {
165165
return _NullSubstitution.instance;
166166
}

pkg/analyzer/lib/src/error/correct_override.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class CovariantParametersVerifier {
189189
/// Return the [Substitution] to convert types of [superMember] to types of
190190
/// [_thisMember].
191191
Substitution _superSubstitution(_SuperMember superMember) {
192-
var result = Substitution.fromInterfaceType(superMember.interface);
192+
Substitution result = Substitution.fromInterfaceType(superMember.interface);
193193

194194
// If the executable has type parameters, ensure that super uses the same.
195195
var thisTypeParameters = _thisMember.typeParameters;

0 commit comments

Comments
 (0)