Index: pkg/analyzer/test/src/task/dart_test.dart |
diff --git a/pkg/analyzer/test/src/task/dart_test.dart b/pkg/analyzer/test/src/task/dart_test.dart |
index 40419616f707c0661917e9b087f68b6cbc52d19a..4789a7a405f8d2ed2cc12f02d79faceeb0d0389b 100644 |
--- a/pkg/analyzer/test/src/task/dart_test.dart |
+++ b/pkg/analyzer/test/src/task/dart_test.dart |
@@ -33,6 +33,7 @@ import '../../generated/resolver_test_case.dart'; |
import '../../generated/test_support.dart'; |
import '../../utils.dart'; |
import '../context/abstract_context.dart'; |
+import 'package:analyzer/dart/ast/resolution_accessors.dart'; |
scheglov
2016/12/05 17:10:50
Not sorted.
Paul Berry
2016/12/05 17:50:48
Fixed, thanks.
|
main() { |
defineReflectiveSuite(() { |
@@ -186,7 +187,7 @@ f() { |
unitElement.types[0].fields[0], |
unitElement.functions[0].localVariables[0], |
unitElement.types[0].constructors[0], |
- annotation.elementAnnotation, |
+ elementAnnotationForAnnotation(annotation), |
unitElement.types[0].constructors[0].parameters[0] |
]; |
expect( |
@@ -580,7 +581,7 @@ part 'part.dart';''', |
// Validate metadata |
expect(part.directives[0], new isInstanceOf<PartOfDirective>()); |
expect(part.directives[0].element, same(libraryA)); |
- expect(part.directives[0].element.metadata, isEmpty); |
+ expect(elementForDirective(part.directives[0]).metadata, isEmpty); |
} |
void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
@@ -626,7 +627,8 @@ enum MyEnum { |
matcher: isBuildEnumMemberElementsTask); |
CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
// validate Element |
- ClassElement enumElement = unit.element.getEnum('MyEnum'); |
+ ClassElement enumElement = |
+ elementForCompilationUnit(unit).getEnum('MyEnum'); |
List<FieldElement> fields = enumElement.fields; |
expect(fields, hasLength(4)); |
{ |
@@ -832,7 +834,7 @@ part of 'lib.dart'; |
// CompilationUnitElement(s) |
CompilationUnitElement firstPart; |
CompilationUnitElement secondPart; |
- if (partUnits[0].element.uri == 'part1.dart') { |
+ if (elementForCompilationUnit(partUnits[0]).uri == 'part1.dart') { |
firstPart = partUnits[0].element; |
secondPart = partUnits[1].element; |
} else { |
@@ -1000,10 +1002,12 @@ void set test(_) {} |
''' |
}); |
CompilationUnitElement unitElement1 = partUnits |
- .singleWhere((u) => u.element.name.endsWith('part1.dart')) |
+ .singleWhere( |
+ (u) => elementForCompilationUnit(u).name.endsWith('part1.dart')) |
.element; |
CompilationUnitElement unitElement2 = partUnits |
- .singleWhere((u) => u.element.name.endsWith('part2.dart')) |
+ .singleWhere( |
+ (u) => elementForCompilationUnit(u).name.endsWith('part2.dart')) |
.element; |
PropertyAccessorElement getter = unitElement1.accessors[0]; |
PropertyAccessorElement setter = unitElement2.accessors[0]; |
@@ -1157,19 +1161,22 @@ class D { const D(value); } |
computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
// Find the elements for x and D's constructor, and the annotation on C. |
- List<PropertyAccessorElement> accessors = unit.element.accessors; |
+ CompilationUnitElement compilationUnitElement = |
+ elementForCompilationUnit(unit); |
+ List<PropertyAccessorElement> accessors = compilationUnitElement.accessors; |
Element x = accessors |
.firstWhere((PropertyAccessorElement accessor) => |
accessor.isGetter && accessor.name == 'x') |
.variable; |
- List<ClassElement> types = unit.element.types; |
+ List<ClassElement> types = compilationUnitElement.types; |
Element constructorForD = |
types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0]; |
Annotation annotation = findClassAnnotation(unit, 'C'); |
// Now compute the dependencies for the annotation, and check that it is |
// the set [x, constructorForD]. |
// TODO(paulberry): test librarySource != source |
- computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES, |
+ computeResult( |
+ elementAnnotationForAnnotation(annotation), CONSTANT_DEPENDENCIES, |
matcher: isComputeConstantDependenciesTask); |
expect( |
outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); |
@@ -1197,7 +1204,8 @@ class C { |
Annotation annotation = classC.members[0].metadata[0]; |
// Now compute the dependencies for the annotation, and check that it is |
// the right size. |
- computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES, |
+ computeResult( |
+ elementAnnotationForAnnotation(annotation), CONSTANT_DEPENDENCIES, |
matcher: isComputeConstantDependenciesTask); |
expect(outputs[CONSTANT_DEPENDENCIES], hasLength(1)); |
} |
@@ -1215,7 +1223,8 @@ const x = 1; |
computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
// Find the element for x and the annotation on C. |
- List<PropertyAccessorElement> accessors = unit.element.accessors; |
+ List<PropertyAccessorElement> accessors = |
+ elementForCompilationUnit(unit).accessors; |
Element x = accessors |
.firstWhere((PropertyAccessorElement accessor) => |
accessor.isGetter && accessor.name == 'x') |
@@ -1223,7 +1232,8 @@ const x = 1; |
Annotation annotation = findClassAnnotation(unit, 'C'); |
// Now compute the dependencies for the annotation, and check that it is |
// the list [x]. |
- computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES, |
+ computeResult( |
+ elementAnnotationForAnnotation(annotation), CONSTANT_DEPENDENCIES, |
matcher: isComputeConstantDependenciesTask); |
expect(outputs[CONSTANT_DEPENDENCIES], [x]); |
} |
@@ -1263,7 +1273,8 @@ const y = 1; |
computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
// Find the elements for the constants x and y. |
- List<PropertyAccessorElement> accessors = unit.element.accessors; |
+ List<PropertyAccessorElement> accessors = |
+ elementForCompilationUnit(unit).accessors; |
Element x = accessors |
.firstWhere((PropertyAccessorElement accessor) => |
accessor.isGetter && accessor.name == 'x') |
@@ -1539,8 +1550,10 @@ const b = 0; |
LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
computeResult(target, RESOLVED_UNIT7); |
CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
- TopLevelVariableElement elementA = unit.element.topLevelVariables[0]; |
- TopLevelVariableElement elementB = unit.element.topLevelVariables[1]; |
+ TopLevelVariableElement elementA = |
+ elementForCompilationUnit(unit).topLevelVariables[0]; |
+ TopLevelVariableElement elementB = |
+ elementForCompilationUnit(unit).topLevelVariables[1]; |
computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES, |
matcher: isComputeInferableStaticVariableDependenciesTask); |
@@ -2678,13 +2691,16 @@ class Z {} |
CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
VariableDeclaration field = AstFinder.getFieldInClass(unit, 'B', 'f'); |
MethodDeclaration method = AstFinder.getMethodInClass(unit, 'B', 'm'); |
- DartType typeX = AstFinder.getClass(unit, 'X').element.type; |
- DartType typeY = AstFinder.getClass(unit, 'Y').element.type; |
- DartType typeZ = AstFinder.getClass(unit, 'Z').element.type; |
+ DartType typeX = |
+ elementForClassDeclaration(AstFinder.getClass(unit, 'X')).type; |
+ DartType typeY = |
+ elementForClassDeclaration(AstFinder.getClass(unit, 'Y')).type; |
+ DartType typeZ = |
+ elementForClassDeclaration(AstFinder.getClass(unit, 'Z')).type; |
- expect(field.element.type, typeX); |
- expect(method.element.returnType, typeY); |
- expect(method.element.parameters[0].type, typeZ); |
+ expect(elementForVariableDeclaration(field).type, typeX); |
+ expect(elementForMethodDeclaration(method).returnType, typeY); |
+ expect(elementForMethodDeclaration(method).parameters[0].type, typeZ); |
} |
void test_perform_cross_library_const() { |
@@ -2722,10 +2738,10 @@ class M { |
AstFinder.getFieldInClass(secondUnit, 'M', 'c'); |
InterfaceType stringType = context.typeProvider.stringType; |
- expect(variableA.element.type, stringType); |
- expect(variableB.element.type, stringType); |
+ expect(elementForVariableDeclaration(variableA).type, stringType); |
+ expect(elementForVariableDeclaration(variableB).type, stringType); |
expect(variableB.initializer.staticType, stringType); |
- expect(variableC.element.type, stringType); |
+ expect(elementForVariableDeclaration(variableC).type, stringType); |
expect(variableC.initializer.staticType, stringType); |
} |
@@ -2790,7 +2806,7 @@ class M { |
CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X'); |
InterfaceType stringType = context.typeProvider.stringType; |
- expect(declaration.element.type, stringType); |
+ expect(elementForVariableDeclaration(declaration).type, stringType); |
} |
test_perform_hasParseError() { |
@@ -2853,12 +2869,12 @@ class M {} |
VariableDeclaration variableC = |
AstFinder.getTopLevelVariable(firstUnit, 'c'); |
ClassDeclaration classM = AstFinder.getClass(secondUnit, 'M'); |
- DartType typeM = classM.element.type; |
+ DartType typeM = elementForClassDeclaration(classM).type; |
- expect(variableA.element.type, typeM); |
- expect(variableB.element.type, typeM); |
+ expect(elementForVariableDeclaration(variableA).type, typeM); |
+ expect(elementForVariableDeclaration(variableB).type, typeM); |
expect(variableB.initializer.staticType, typeM); |
- expect(variableC.element.type, typeM); |
+ expect(elementForVariableDeclaration(variableC).type, typeM); |
expect(variableC.initializer.staticType, typeM); |
} |
@@ -4500,7 +4516,8 @@ typedef F<T extends String>(); |
Identifier boundName = boundNode.name; |
expect(boundNode.type.toString(), expectedBoundTypeString); |
expect(boundName.staticType.toString(), expectedBoundTypeString); |
- expect(boundName.staticElement.displayName, expectedBoundElementName); |
+ expect(staticElementForIdentifier(boundName).displayName, |
+ expectedBoundElementName); |
} |
} |
@@ -4584,7 +4601,7 @@ int f(String p) => p.length; |
ClassDeclaration nodeA = unit.declarations[0]; |
ClassDeclaration nodeB = unit.declarations[1]; |
DartType extendsType = nodeB.extendsClause.superclass.type; |
- expect(extendsType, nodeA.element.type); |
+ expect(extendsType, elementForClassDeclaration(nodeA).type); |
} |
{ |
FunctionDeclaration functionNode = unit.declarations[2]; |
@@ -4592,7 +4609,8 @@ int f(String p) => p.length; |
List<FormalParameter> parameters = |
functionNode.functionExpression.parameters.parameters; |
expect(returnType.displayName, 'int'); |
- expect(parameters[0].element.type.displayName, 'String'); |
+ expect( |
+ elementForFormalParameter(parameters[0]).type.displayName, 'String'); |
} |
} |
@@ -4626,15 +4644,15 @@ typedef String G(int p); |
FunctionTypeAlias nodeG = unit.declarations[1]; |
{ |
FormalParameter parameter = nodeF.parameters.parameters[0]; |
- DartType parameterType = parameter.element.type; |
- Element returnTypeElement = nodeF.returnType.type.element; |
+ DartType parameterType = elementForFormalParameter(parameter).type; |
+ Element returnTypeElement = typeForTypeName(nodeF.returnType).element; |
expect(returnTypeElement.displayName, 'int'); |
expect(parameterType.element, nodeG.element); |
} |
{ |
FormalParameter parameter = nodeG.parameters.parameters[0]; |
- DartType parameterType = parameter.element.type; |
- expect(nodeG.returnType.type.element.displayName, 'String'); |
+ DartType parameterType = elementForFormalParameter(parameter).type; |
+ expect(typeForTypeName(nodeG.returnType).element.displayName, 'String'); |
expect(parameterType.element.displayName, 'int'); |
} |
} |
@@ -5305,7 +5323,7 @@ var tau = piFirst ? pi * 2 : 6.28; |
AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
VariableDeclaration decl = |
(statements[0] as VariableDeclarationStatement).variables.variables[0]; |
- expect(decl.element.type, intType); |
+ expect(elementForVariableDeclaration(decl).type, intType); |
expect(decl.initializer.staticType, intType); |
ExpressionStatement statement = statements[1]; |
@@ -5593,7 +5611,7 @@ class _AbstractDartTaskTest extends AbstractContextTest { |
void assertVariableDeclarationTypes( |
VariableDeclaration decl, DartType varType, DartType initializerType) { |
- expect(decl.element.type, varType); |
+ expect(elementForVariableDeclaration(decl).type, varType); |
expect(decl.initializer.staticType, initializerType); |
} |