| Index: packages/analyzer/test/src/dart/element/element_test.dart
|
| diff --git a/packages/analyzer/test/generated/element_test.dart b/packages/analyzer/test/src/dart/element/element_test.dart
|
| similarity index 86%
|
| rename from packages/analyzer/test/generated/element_test.dart
|
| rename to packages/analyzer/test/src/dart/element/element_test.dart
|
| index 14485e20ea397ffae9fc1c3a9932b55850a30924..a1f72b8faba45a6707293b21f5bf7305e7935453 100644
|
| --- a/packages/analyzer/test/generated/element_test.dart
|
| +++ b/packages/analyzer/test/src/dart/element/element_test.dart
|
| @@ -2,41 +2,49 @@
|
| // 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.
|
|
|
| -library engine.element_test;
|
| -
|
| -import 'package:analyzer/src/generated/ast.dart';
|
| -import 'package:analyzer/src/generated/element.dart';
|
| +library analyzer.test.src.dart.element.element_test;
|
| +
|
| +import 'package:analyzer/dart/ast/ast.dart';
|
| +import 'package:analyzer/dart/constant/value.dart';
|
| +import 'package:analyzer/dart/element/element.dart';
|
| +import 'package:analyzer/dart/element/type.dart';
|
| +import 'package:analyzer/src/dart/element/element.dart';
|
| +import 'package:analyzer/src/dart/element/handle.dart';
|
| +import 'package:analyzer/src/dart/element/type.dart';
|
| import 'package:analyzer/src/generated/engine.dart'
|
| show AnalysisContext, AnalysisOptionsImpl;
|
| -import 'package:analyzer/src/generated/java_core.dart';
|
| import 'package:analyzer/src/generated/source_io.dart';
|
| import 'package:analyzer/src/generated/testing/ast_factory.dart';
|
| import 'package:analyzer/src/generated/testing/element_factory.dart';
|
| import 'package:analyzer/src/generated/testing/test_type_provider.dart';
|
| +import 'package:test_reflective_loader/test_reflective_loader.dart';
|
| import 'package:unittest/unittest.dart';
|
|
|
| -import '../reflective_tests.dart';
|
| -import '../utils.dart';
|
| -import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper;
|
| -import 'test_support.dart';
|
| +import '../../../generated/analysis_context_factory.dart'
|
| + show AnalysisContextHelper;
|
| +import '../../../generated/resolver_test_case.dart';
|
| +import '../../../generated/test_support.dart';
|
| +import '../../../utils.dart';
|
|
|
| main() {
|
| initializeTestEnvironment();
|
| - runReflectiveTests(ElementKindTest);
|
| - runReflectiveTests(FieldElementImplTest);
|
| - runReflectiveTests(FunctionTypeImplTest);
|
| - runReflectiveTests(InterfaceTypeImplTest);
|
| - runReflectiveTests(TypeParameterTypeImplTest);
|
| - runReflectiveTests(VoidTypeImplTest);
|
| - runReflectiveTests(ClassElementImplTest);
|
| - runReflectiveTests(CompilationUnitElementImplTest);
|
| - runReflectiveTests(ElementLocationImplTest);
|
| - runReflectiveTests(ElementImplTest);
|
| - runReflectiveTests(HtmlElementImplTest);
|
| - runReflectiveTests(LibraryElementImplTest);
|
| - runReflectiveTests(MethodElementImplTest);
|
| - runReflectiveTests(MultiplyDefinedElementImplTest);
|
| - runReflectiveTests(ParameterElementImplTest);
|
| + defineReflectiveTests(ElementAnnotationImplTest);
|
| + defineReflectiveTests(FieldElementImplTest);
|
| + defineReflectiveTests(FunctionTypeImplTest);
|
| + defineReflectiveTests(InterfaceTypeImplTest);
|
| + defineReflectiveTests(LocalVariableElementImplTest);
|
| + defineReflectiveTests(TypeParameterTypeImplTest);
|
| + defineReflectiveTests(VoidTypeImplTest);
|
| + defineReflectiveTests(ClassElementImplTest);
|
| + defineReflectiveTests(CompilationUnitElementImplTest);
|
| + defineReflectiveTests(ElementLocationImplTest);
|
| + defineReflectiveTests(ElementImplTest);
|
| + defineReflectiveTests(LibraryElementImplTest);
|
| + defineReflectiveTests(MethodElementImplTest);
|
| + defineReflectiveTests(MultiplyDefinedElementImplTest);
|
| + defineReflectiveTests(ParameterElementImplTest);
|
| + defineReflectiveTests(PropertyAccessorElementImplTest);
|
| + defineReflectiveTests(TopLevelVariableElementImplTest);
|
| }
|
|
|
| @reflectiveTest
|
| @@ -117,6 +125,24 @@ abstract class A<K, V> = Object with MapMixin<K, V>;
|
| }
|
| }
|
|
|
| + void test_constructors_mixinApplicationWithHandle() {
|
| + AnalysisContext context = createAnalysisContext();
|
| + context.sourceFactory = new SourceFactory([]);
|
| +
|
| + ElementLocation location = new ElementLocationImpl.con2('');
|
| + ClassElementImpl classA = ElementFactory.classElement2("A");
|
| + classA.mixinApplication = true;
|
| + TestElementResynthesizer resynthesizer =
|
| + new TestElementResynthesizer(context, {location: classA});
|
| + ClassElementHandle classAHandle =
|
| + new ClassElementHandle(resynthesizer, location);
|
| + ClassElementImpl classB =
|
| + ElementFactory.classElement("B", new InterfaceTypeImpl(classAHandle));
|
| + classB.mixinApplication = true;
|
| +
|
| + expect(classB.constructors, hasLength(1));
|
| + }
|
| +
|
| void test_getAllSupertypes_interface() {
|
| ClassElement classA = ElementFactory.classElement2("A");
|
| ClassElement classB = ElementFactory.classElement("B", classA.type);
|
| @@ -282,8 +308,8 @@ abstract class A<K, V> = Object with MapMixin<K, V>;
|
| void test_isEnum() {
|
| String firstConst = "A";
|
| String secondConst = "B";
|
| - ClassElementImpl enumE = ElementFactory.enumElement(
|
| - new TestTypeProvider(), "E", [firstConst, secondConst]);
|
| + EnumElementImpl enumE = ElementFactory
|
| + .enumElement(new TestTypeProvider(), "E", [firstConst, secondConst]);
|
|
|
| // E is an enum
|
| expect(enumE.isEnum, true);
|
| @@ -634,7 +660,8 @@ abstract class A<K, V> = Object with MapMixin<K, V>;
|
| expect(classB.lookUpInheritedConcreteMethod(methodName, library), isNull);
|
| }
|
|
|
| - void test_lookUpInheritedConcreteMethod_declaredAndInheritedWithAbstractBetween() {
|
| + void
|
| + test_lookUpInheritedConcreteMethod_declaredAndInheritedWithAbstractBetween() {
|
| // class A {
|
| // m() {}
|
| // }
|
| @@ -1067,6 +1094,41 @@ part 'unit_b.dart';
|
| }
|
| }
|
|
|
| +@reflectiveTest
|
| +class ElementAnnotationImplTest extends ResolverTestCase {
|
| + void test_computeConstantValue() {
|
| + addNamedSource(
|
| + '/a.dart',
|
| + r'''
|
| +class A {
|
| + final String f;
|
| + const A(this.f);
|
| +}
|
| +void f(@A('x') int p) {}
|
| +''');
|
| + Source source = addSource(r'''
|
| +import 'a.dart';
|
| +main() {
|
| + f(3);
|
| +}
|
| +''');
|
| + LibraryElement library = resolve2(source);
|
| + CompilationUnit unit = resolveCompilationUnit(source, library);
|
| + FunctionDeclaration main = unit.declarations[0];
|
| + BlockFunctionBody body = main.functionExpression.body;
|
| + ExpressionStatement statement = body.block.statements[0];
|
| + MethodInvocation invocation = statement.expression;
|
| + ParameterElement parameter =
|
| + invocation.argumentList.arguments[0].bestParameterElement;
|
| + ElementAnnotation annotation = parameter.metadata[0];
|
| + expect(annotation.constantValue, isNull);
|
| + DartObject value = annotation.computeConstantValue();
|
| + expect(value, isNotNull);
|
| + expect(value.getField('f').toStringValue(), 'x');
|
| + expect(annotation.constantValue, value);
|
| + }
|
| +}
|
| +
|
| @reflectiveTest
|
| class ElementImplTest extends EngineTestCase {
|
| void test_equals() {
|
| @@ -1163,18 +1225,6 @@ class ElementImplTest extends EngineTestCase {
|
| }
|
| }
|
|
|
| -@reflectiveTest
|
| -class ElementKindTest extends EngineTestCase {
|
| - void test_of_nonNull() {
|
| - expect(ElementKind.of(ElementFactory.classElement2("A")),
|
| - same(ElementKind.CLASS));
|
| - }
|
| -
|
| - void test_of_null() {
|
| - expect(ElementKind.of(null), same(ElementKind.ERROR));
|
| - }
|
| -}
|
| -
|
| @reflectiveTest
|
| class ElementLocationImplTest extends EngineTestCase {
|
| void test_create_encoding() {
|
| @@ -1308,20 +1358,110 @@ class FunctionTypeImplTest extends EngineTestCase {
|
| expect(type.element, typeElement);
|
| }
|
|
|
| - void test_getNamedParameterTypes() {
|
| - FunctionTypeImpl type = new FunctionTypeImpl(
|
| - new FunctionElementImpl.forNode(AstFactory.identifier3("f")));
|
| + void test_getNamedParameterTypes_namedParameters() {
|
| + TestTypeProvider typeProvider = new TestTypeProvider();
|
| + FunctionElement element = ElementFactory
|
| + .functionElementWithParameters('f', VoidTypeImpl.instance, [
|
| + ElementFactory.requiredParameter2('a', typeProvider.intType),
|
| + ElementFactory.requiredParameter('b'),
|
| + ElementFactory.namedParameter2('c', typeProvider.stringType),
|
| + ElementFactory.namedParameter('d')
|
| + ]);
|
| + FunctionTypeImpl type = element.type;
|
| + Map<String, DartType> types = type.namedParameterTypes;
|
| + expect(types, hasLength(2));
|
| + expect(types['c'], typeProvider.stringType);
|
| + expect(types['d'], DynamicTypeImpl.instance);
|
| + }
|
| +
|
| + void test_getNamedParameterTypes_noNamedParameters() {
|
| + TestTypeProvider typeProvider = new TestTypeProvider();
|
| + FunctionElement element = ElementFactory
|
| + .functionElementWithParameters('f', VoidTypeImpl.instance, [
|
| + ElementFactory.requiredParameter2('a', typeProvider.intType),
|
| + ElementFactory.requiredParameter('b'),
|
| + ElementFactory.positionalParameter2('c', typeProvider.stringType)
|
| + ]);
|
| + FunctionTypeImpl type = element.type;
|
| Map<String, DartType> types = type.namedParameterTypes;
|
| expect(types, hasLength(0));
|
| }
|
|
|
| - void test_getNormalParameterTypes() {
|
| - FunctionTypeImpl type = new FunctionTypeImpl(
|
| - new FunctionElementImpl.forNode(AstFactory.identifier3("f")));
|
| + void test_getNamedParameterTypes_noParameters() {
|
| + FunctionTypeImpl type = ElementFactory.functionElement('f').type;
|
| + Map<String, DartType> types = type.namedParameterTypes;
|
| + expect(types, hasLength(0));
|
| + }
|
| +
|
| + void test_getNormalParameterTypes_noNormalParameters() {
|
| + TestTypeProvider typeProvider = new TestTypeProvider();
|
| + FunctionElement element = ElementFactory
|
| + .functionElementWithParameters('f', VoidTypeImpl.instance, [
|
| + ElementFactory.positionalParameter2('c', typeProvider.stringType),
|
| + ElementFactory.positionalParameter('d')
|
| + ]);
|
| + FunctionTypeImpl type = element.type;
|
| + List<DartType> types = type.normalParameterTypes;
|
| + expect(types, hasLength(0));
|
| + }
|
| +
|
| + void test_getNormalParameterTypes_noParameters() {
|
| + FunctionTypeImpl type = ElementFactory.functionElement('f').type;
|
| + List<DartType> types = type.normalParameterTypes;
|
| + expect(types, hasLength(0));
|
| + }
|
| +
|
| + void test_getNormalParameterTypes_normalParameters() {
|
| + TestTypeProvider typeProvider = new TestTypeProvider();
|
| + FunctionElement element = ElementFactory
|
| + .functionElementWithParameters('f', VoidTypeImpl.instance, [
|
| + ElementFactory.requiredParameter2('a', typeProvider.intType),
|
| + ElementFactory.requiredParameter('b'),
|
| + ElementFactory.positionalParameter2('c', typeProvider.stringType)
|
| + ]);
|
| + FunctionTypeImpl type = element.type;
|
| List<DartType> types = type.normalParameterTypes;
|
| + expect(types, hasLength(2));
|
| + expect(types[0], typeProvider.intType);
|
| + expect(types[1], DynamicTypeImpl.instance);
|
| + }
|
| +
|
| + void test_getOptionalParameterTypes_noOptionalParameters() {
|
| + TestTypeProvider typeProvider = new TestTypeProvider();
|
| + FunctionElement element = ElementFactory
|
| + .functionElementWithParameters('f', VoidTypeImpl.instance, [
|
| + ElementFactory.requiredParameter2('a', typeProvider.intType),
|
| + ElementFactory.requiredParameter('b'),
|
| + ElementFactory.namedParameter2('c', typeProvider.stringType),
|
| + ElementFactory.namedParameter('d')
|
| + ]);
|
| + FunctionTypeImpl type = element.type;
|
| + List<DartType> types = type.optionalParameterTypes;
|
| expect(types, hasLength(0));
|
| }
|
|
|
| + void test_getOptionalParameterTypes_noParameters() {
|
| + FunctionTypeImpl type = ElementFactory.functionElement('f').type;
|
| + List<DartType> types = type.optionalParameterTypes;
|
| + expect(types, hasLength(0));
|
| + }
|
| +
|
| + void test_getOptionalParameterTypes_optionalParameters() {
|
| + TestTypeProvider typeProvider = new TestTypeProvider();
|
| + FunctionElement element = ElementFactory
|
| + .functionElementWithParameters('f', VoidTypeImpl.instance, [
|
| + ElementFactory.requiredParameter2('a', typeProvider.intType),
|
| + ElementFactory.requiredParameter('b'),
|
| + ElementFactory.positionalParameter2('c', typeProvider.stringType),
|
| + ElementFactory.positionalParameter('d')
|
| + ]);
|
| + FunctionTypeImpl type = element.type;
|
| + List<DartType> types = type.optionalParameterTypes;
|
| + expect(types, hasLength(2));
|
| + expect(types[0], typeProvider.stringType);
|
| + expect(types[1], DynamicTypeImpl.instance);
|
| + }
|
| +
|
| void test_getReturnType() {
|
| DartType expectedReturnType = VoidTypeImpl.instance;
|
| FunctionElementImpl functionElement =
|
| @@ -1866,6 +2006,14 @@ class FunctionTypeImplTest extends EngineTestCase {
|
| expect(paramType.prunedTypedefs[0], same(f));
|
| }
|
|
|
| + void test_resolveToBound() {
|
| + FunctionElementImpl f = ElementFactory.functionElement('f');
|
| + FunctionTypeImpl type = f.type;
|
| +
|
| + // Returns this.
|
| + expect(type.resolveToBound(null), same(type));
|
| + }
|
| +
|
| void test_returnType_pruned_no_type_arguments() {
|
| FunctionTypeAliasElementImpl f =
|
| ElementFactory.functionTypeAliasElement('f');
|
| @@ -1889,19 +2037,6 @@ class FunctionTypeImplTest extends EngineTestCase {
|
| expect(paramType.prunedTypedefs[0], same(f));
|
| }
|
|
|
| - void test_setTypeArguments() {
|
| - ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]);
|
| - MethodElementImpl methodElement =
|
| - new MethodElementImpl.forNode(AstFactory.identifier3("m"));
|
| - enclosingClass.methods = <MethodElement>[methodElement];
|
| - FunctionTypeImpl type = new FunctionTypeImpl(methodElement);
|
| - DartType expectedType = enclosingClass.typeParameters[0].type;
|
| - type.typeArguments = <DartType>[expectedType];
|
| - List<DartType> arguments = type.typeArguments;
|
| - expect(arguments, hasLength(1));
|
| - expect(arguments[0], expectedType);
|
| - }
|
| -
|
| void test_substitute2_equal() {
|
| ClassElementImpl definingClass = ElementFactory.classElement2("C", ["E"]);
|
| TypeParameterType parameterType = definingClass.typeParameters[0].type;
|
| @@ -1916,11 +2051,10 @@ class FunctionTypeImplTest extends EngineTestCase {
|
| functionElement.returnType = parameterType;
|
| definingClass.methods = <MethodElement>[functionElement];
|
| FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement);
|
| - functionType.typeArguments = <DartType>[parameterType];
|
| InterfaceTypeImpl argumentType = new InterfaceTypeImpl(
|
| new ClassElementImpl.forNode(AstFactory.identifier3("D")));
|
| - FunctionType result = functionType.substitute2(
|
| - <DartType>[argumentType], <DartType>[parameterType]);
|
| + FunctionType result = functionType
|
| + .substitute2(<DartType>[argumentType], <DartType>[parameterType]);
|
| expect(result.returnType, argumentType);
|
| List<DartType> normalParameters = result.normalParameterTypes;
|
| expect(normalParameters, hasLength(1));
|
| @@ -1956,8 +2090,8 @@ class FunctionTypeImplTest extends EngineTestCase {
|
| new ClassElementImpl.forNode(AstFactory.identifier3("D")));
|
| TypeParameterTypeImpl parameterType = new TypeParameterTypeImpl(
|
| new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")));
|
| - FunctionType result = functionType.substitute2(
|
| - <DartType>[argumentType], <DartType>[parameterType]);
|
| + FunctionType result = functionType
|
| + .substitute2(<DartType>[argumentType], <DartType>[parameterType]);
|
| expect(result.returnType, returnType);
|
| List<DartType> normalParameters = result.normalParameterTypes;
|
| expect(normalParameters, hasLength(1));
|
| @@ -1984,37 +2118,150 @@ class FunctionTypeImplTest extends EngineTestCase {
|
| FunctionTypeAliasElementImpl f =
|
| ElementFactory.functionTypeAliasElement('f');
|
| ClassElementImpl c = ElementFactory.classElement2('C', ['T']);
|
| - f.returnType = c.type.substitute4([f.type]);
|
| + f.returnType = c.type.instantiate([f.type]);
|
| expect(f.type.toString(), '() \u2192 C<...>');
|
| }
|
| -}
|
|
|
| -@reflectiveTest
|
| -class HtmlElementImplTest extends EngineTestCase {
|
| - void test_equals_differentSource() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - HtmlElementImpl elementA = ElementFactory.htmlUnit(context, "indexA.html");
|
| - HtmlElementImpl elementB = ElementFactory.htmlUnit(context, "indexB.html");
|
| - expect(elementA == elementB, isFalse);
|
| + void test_typeParameters_genericLocalFunction_genericMethod_genericClass() {
|
| + //
|
| + // class C<S> {
|
| + // Object m<T>() {
|
| + // U f<U>() => null;
|
| + // }
|
| + // }
|
| + //
|
| + ClassElementImpl classElement =
|
| + ElementFactory.classElement('C', null, ['S']);
|
| + MethodElementImpl method = new MethodElementImpl('m', 0);
|
| + method.enclosingElement = classElement;
|
| + method.returnType = ElementFactory.objectType;
|
| + method.typeParameters = ElementFactory.typeParameters(['T']);
|
| + method.type = new FunctionTypeImpl(method);
|
| + FunctionElementImpl function = ElementFactory.functionElement('f');
|
| + function.enclosingElement = method;
|
| + function.typeParameters = ElementFactory.typeParameters(['U']);
|
| + function.returnType = function.typeParameters[0].type;
|
| + function.type = new FunctionTypeImpl(function);
|
| +
|
| + List<TypeParameterElement> inheritedParameters = <TypeParameterElement>[];
|
| + inheritedParameters.addAll(method.typeParameters);
|
| + inheritedParameters.addAll(classElement.typeParameters);
|
| + expect(function.type.typeArguments,
|
| + unorderedEquals(_toTypes(inheritedParameters)));
|
| + expect(function.type.typeFormals, unorderedEquals(function.typeParameters));
|
| + expect(function.type.typeParameters, unorderedEquals(inheritedParameters));
|
| + }
|
| +
|
| + void test_typeParameters_genericMethod_genericClass() {
|
| + //
|
| + // class C<S> {
|
| + // Object m<T>() => null;
|
| + // }
|
| + //
|
| + ClassElementImpl classElement =
|
| + ElementFactory.classElement('C', null, ['S']);
|
| + MethodElementImpl method = new MethodElementImpl('m', 0);
|
| + method.enclosingElement = classElement;
|
| + method.returnType = ElementFactory.objectType;
|
| + method.typeParameters = ElementFactory.typeParameters(['T']);
|
| + method.type = new FunctionTypeImpl(method);
|
| +
|
| + expect(method.type.typeArguments,
|
| + unorderedEquals(_toTypes(classElement.typeParameters)));
|
| + expect(method.type.typeFormals, unorderedEquals(method.typeParameters));
|
| + expect(method.type.typeParameters,
|
| + unorderedEquals(classElement.typeParameters));
|
| }
|
|
|
| - void test_equals_null() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - HtmlElementImpl element = ElementFactory.htmlUnit(context, "index.html");
|
| - expect(element == null, isFalse);
|
| + void test_typeParameters_genericMethod_simpleClass() {
|
| + //
|
| + // class C<S> {
|
| + // Object m<T>() => null;
|
| + // }
|
| + //
|
| + ClassElementImpl classElement = ElementFactory.classElement2('C');
|
| + MethodElementImpl method = new MethodElementImpl('m', 0);
|
| + method.enclosingElement = classElement;
|
| + method.returnType = ElementFactory.objectType;
|
| + method.typeParameters = ElementFactory.typeParameters(['T']);
|
| + method.type = new FunctionTypeImpl(method);
|
| +
|
| + expect(method.type.typeArguments,
|
| + unorderedEquals(_toTypes(classElement.typeParameters)));
|
| + expect(method.type.typeFormals, unorderedEquals(method.typeParameters));
|
| + expect(method.type.typeParameters,
|
| + unorderedEquals(classElement.typeParameters));
|
| }
|
|
|
| - void test_equals_sameSource() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - HtmlElementImpl elementA = ElementFactory.htmlUnit(context, "index.html");
|
| - HtmlElementImpl elementB = ElementFactory.htmlUnit(context, "index.html");
|
| - expect(elementA == elementB, isTrue);
|
| + void test_typeParameters_genericTopLevelFunction() {
|
| + //
|
| + // Object f<T>() => null;
|
| + //
|
| + FunctionElementImpl function = ElementFactory.functionElement('f');
|
| + function.returnType = ElementFactory.objectType;
|
| + function.typeParameters = ElementFactory.typeParameters(['T']);
|
| + function.type = new FunctionTypeImpl(function);
|
| +
|
| + expect(function.type.typeArguments, isEmpty);
|
| + expect(function.type.typeFormals, unorderedEquals(function.typeParameters));
|
| + expect(function.type.typeParameters, isEmpty);
|
| }
|
|
|
| - void test_equals_self() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - HtmlElementImpl element = ElementFactory.htmlUnit(context, "index.html");
|
| - expect(element == element, isTrue);
|
| + void test_typeParameters_simpleMethod_genericClass() {
|
| + //
|
| + // class C<S> {
|
| + // Object m<T>() => null;
|
| + // }
|
| + //
|
| + ClassElementImpl classElement =
|
| + ElementFactory.classElement('C', null, ['S']);
|
| + MethodElementImpl method = new MethodElementImpl('m', 0);
|
| + method.enclosingElement = classElement;
|
| + method.typeParameters = ElementFactory.typeParameters(['T']);
|
| + method.returnType = ElementFactory.objectType;
|
| + method.type = new FunctionTypeImpl(method);
|
| +
|
| + expect(method.type.typeArguments,
|
| + unorderedEquals(_toTypes(classElement.typeParameters)));
|
| + expect(method.type.typeFormals, unorderedEquals(method.typeParameters));
|
| + expect(method.type.typeParameters,
|
| + unorderedEquals(classElement.typeParameters));
|
| + }
|
| +
|
| + void test_typeParameters_simpleMethod_simpleClass() {
|
| + //
|
| + // class C<S> {
|
| + // Object m<T>() => null;
|
| + // }
|
| + //
|
| + ClassElementImpl classElement = ElementFactory.classElement2('C');
|
| + MethodElementImpl method = new MethodElementImpl('m', 0);
|
| + method.enclosingElement = classElement;
|
| + method.typeParameters = ElementFactory.typeParameters(['T']);
|
| + method.returnType = ElementFactory.objectType;
|
| + method.type = new FunctionTypeImpl(method);
|
| +
|
| + expect(method.type.typeArguments,
|
| + unorderedEquals(_toTypes(classElement.typeParameters)));
|
| + expect(method.type.typeFormals, unorderedEquals(method.typeParameters));
|
| + expect(method.type.typeParameters,
|
| + unorderedEquals(classElement.typeParameters));
|
| + }
|
| +
|
| + void test_withTypeArguments() {
|
| + ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]);
|
| + MethodElementImpl methodElement =
|
| + new MethodElementImpl.forNode(AstFactory.identifier3("m"));
|
| + enclosingClass.methods = <MethodElement>[methodElement];
|
| + FunctionTypeImpl type = new FunctionTypeImpl(methodElement);
|
| + DartType expectedType = enclosingClass.typeParameters[0].type;
|
| + List<DartType> arguments = type.typeArguments;
|
| + expect(arguments, hasLength(1));
|
| + expect(arguments[0], expectedType);
|
| + }
|
| +
|
| + Iterable<DartType> _toTypes(List<TypeParameterElement> typeParameters) {
|
| + return typeParameters.map((TypeParameterElement element) => element.type);
|
| }
|
| }
|
|
|
| @@ -2027,6 +2274,7 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
|
|
| @override
|
| void setUp() {
|
| + super.setUp();
|
| _typeProvider = new TestTypeProvider();
|
| }
|
|
|
| @@ -2426,11 +2674,10 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]);
|
| DartType typeE = classA.type.typeArguments[0];
|
| String getterName = "g";
|
| - PropertyAccessorElement getterG =
|
| + PropertyAccessorElementImpl getterG =
|
| ElementFactory.getterElement(getterName, false, typeE);
|
| classA.accessors = <PropertyAccessorElement>[getterG];
|
| - (getterG.type as FunctionTypeImpl).typeArguments =
|
| - classA.type.typeArguments;
|
| + getterG.type = new FunctionTypeImpl(getterG);
|
| //
|
| // A<I>
|
| //
|
| @@ -2496,254 +2743,70 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| expect(result.typeArguments[0], same(typeI));
|
| }
|
|
|
| - void test_getLeastUpperBound_directInterfaceCase() {
|
| - //
|
| - // class A
|
| - // class B implements A
|
| - // class C implements B
|
| - //
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement2("B");
|
| - ClassElementImpl classC = ElementFactory.classElement2("C");
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - classB.interfaces = <InterfaceType>[typeA];
|
| - classC.interfaces = <InterfaceType>[typeB];
|
| - expect(typeB.getLeastUpperBound(typeC), typeB);
|
| - expect(typeC.getLeastUpperBound(typeB), typeB);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_directSubclassCase() {
|
| - //
|
| - // class A
|
| - // class B extends A
|
| - // class C extends B
|
| - //
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
|
| - ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - expect(typeB.getLeastUpperBound(typeC), typeB);
|
| - expect(typeC.getLeastUpperBound(typeB), typeB);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_functionType() {
|
| - DartType interfaceType = ElementFactory.classElement2("A").type;
|
| - FunctionTypeImpl functionType = new FunctionTypeImpl(
|
| - new FunctionElementImpl.forNode(AstFactory.identifier3("f")));
|
| - expect(interfaceType.getLeastUpperBound(functionType), isNull);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_mixinCase() {
|
| + void test_getMethod_implemented() {
|
| //
|
| - // class A
|
| - // class B extends A
|
| - // class C extends A
|
| - // class D extends B with M, N, O, P
|
| + // class A { m() {} }
|
| //
|
| - ClassElement classA = ElementFactory.classElement2("A");
|
| - ClassElement classB = ElementFactory.classElement("B", classA.type);
|
| - ClassElement classC = ElementFactory.classElement("C", classA.type);
|
| - ClassElementImpl classD = ElementFactory.classElement("D", classB.type);
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeC = classC.type;
|
| - InterfaceType typeD = classD.type;
|
| - classD.mixins = <InterfaceType>[
|
| - ElementFactory.classElement2("M").type,
|
| - ElementFactory.classElement2("N").type,
|
| - ElementFactory.classElement2("O").type,
|
| - ElementFactory.classElement2("P").type
|
| - ];
|
| - expect(typeD.getLeastUpperBound(typeC), typeA);
|
| - expect(typeC.getLeastUpperBound(typeD), typeA);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_null() {
|
| - DartType interfaceType = ElementFactory.classElement2("A").type;
|
| - expect(interfaceType.getLeastUpperBound(null), isNull);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_object() {
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement2("B");
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeB = classB.type;
|
| - DartType typeObject = typeA.element.supertype;
|
| - // assert that object does not have a super type
|
| - expect((typeObject.element as ClassElement).supertype, isNull);
|
| - // assert that both A and B have the same super type of Object
|
| - expect(typeB.element.supertype, typeObject);
|
| - // finally, assert that the only least upper bound of A and B is Object
|
| - expect(typeA.getLeastUpperBound(typeB), typeObject);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_self() {
|
| - ClassElement classA = ElementFactory.classElement2("A");
|
| - InterfaceType typeA = classA.type;
|
| - expect(typeA.getLeastUpperBound(typeA), typeA);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_sharedSuperclass1() {
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
|
| - ClassElementImpl classC = ElementFactory.classElement("C", classA.type);
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - expect(typeB.getLeastUpperBound(typeC), typeA);
|
| - expect(typeC.getLeastUpperBound(typeB), typeA);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_sharedSuperclass2() {
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
|
| - ClassElementImpl classC = ElementFactory.classElement("C", classA.type);
|
| - ClassElementImpl classD = ElementFactory.classElement("D", classC.type);
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeD = classD.type;
|
| - expect(typeB.getLeastUpperBound(typeD), typeA);
|
| - expect(typeD.getLeastUpperBound(typeB), typeA);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_sharedSuperclass3() {
|
| ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
|
| - ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
|
| - ClassElementImpl classD = ElementFactory.classElement("D", classB.type);
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - InterfaceType typeD = classD.type;
|
| - expect(typeC.getLeastUpperBound(typeD), typeB);
|
| - expect(typeD.getLeastUpperBound(typeC), typeB);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_sharedSuperclass4() {
|
| - ClassElement classA = ElementFactory.classElement2("A");
|
| - ClassElement classA2 = ElementFactory.classElement2("A2");
|
| - ClassElement classA3 = ElementFactory.classElement2("A3");
|
| - ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
|
| - ClassElementImpl classC = ElementFactory.classElement("C", classA.type);
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeA2 = classA2.type;
|
| - InterfaceType typeA3 = classA3.type;
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - classB.interfaces = <InterfaceType>[typeA2];
|
| - classC.interfaces = <InterfaceType>[typeA3];
|
| - expect(typeB.getLeastUpperBound(typeC), typeA);
|
| - expect(typeC.getLeastUpperBound(typeB), typeA);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_sharedSuperinterface1() {
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement2("B");
|
| - ClassElementImpl classC = ElementFactory.classElement2("C");
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - classB.interfaces = <InterfaceType>[typeA];
|
| - classC.interfaces = <InterfaceType>[typeA];
|
| - expect(typeB.getLeastUpperBound(typeC), typeA);
|
| - expect(typeC.getLeastUpperBound(typeB), typeA);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_sharedSuperinterface2() {
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement2("B");
|
| - ClassElementImpl classC = ElementFactory.classElement2("C");
|
| - ClassElementImpl classD = ElementFactory.classElement2("D");
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - InterfaceType typeD = classD.type;
|
| - classB.interfaces = <InterfaceType>[typeA];
|
| - classC.interfaces = <InterfaceType>[typeA];
|
| - classD.interfaces = <InterfaceType>[typeC];
|
| - expect(typeB.getLeastUpperBound(typeD), typeA);
|
| - expect(typeD.getLeastUpperBound(typeB), typeA);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_sharedSuperinterface3() {
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| - ClassElementImpl classB = ElementFactory.classElement2("B");
|
| - ClassElementImpl classC = ElementFactory.classElement2("C");
|
| - ClassElementImpl classD = ElementFactory.classElement2("D");
|
| - InterfaceType typeA = classA.type;
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - InterfaceType typeD = classD.type;
|
| - classB.interfaces = <InterfaceType>[typeA];
|
| - classC.interfaces = <InterfaceType>[typeB];
|
| - classD.interfaces = <InterfaceType>[typeB];
|
| - expect(typeC.getLeastUpperBound(typeD), typeB);
|
| - expect(typeD.getLeastUpperBound(typeC), typeB);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_sharedSuperinterface4() {
|
| - ClassElement classA = ElementFactory.classElement2("A");
|
| - ClassElement classA2 = ElementFactory.classElement2("A2");
|
| - ClassElement classA3 = ElementFactory.classElement2("A3");
|
| - ClassElementImpl classB = ElementFactory.classElement2("B");
|
| - ClassElementImpl classC = ElementFactory.classElement2("C");
|
| + String methodName = "m";
|
| + MethodElementImpl methodM = ElementFactory.methodElement(methodName, null);
|
| + classA.methods = <MethodElement>[methodM];
|
| InterfaceType typeA = classA.type;
|
| - InterfaceType typeA2 = classA2.type;
|
| - InterfaceType typeA3 = classA3.type;
|
| - InterfaceType typeB = classB.type;
|
| - InterfaceType typeC = classC.type;
|
| - classB.interfaces = <InterfaceType>[typeA, typeA2];
|
| - classC.interfaces = <InterfaceType>[typeA, typeA3];
|
| - expect(typeB.getLeastUpperBound(typeC), typeA);
|
| - expect(typeC.getLeastUpperBound(typeB), typeA);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_twoComparables() {
|
| - InterfaceType string = _typeProvider.stringType;
|
| - InterfaceType num = _typeProvider.numType;
|
| - expect(string.getLeastUpperBound(num), _typeProvider.objectType);
|
| + expect(typeA.getMethod(methodName), same(methodM));
|
| }
|
|
|
| - void test_getLeastUpperBound_typeParameters_different() {
|
| + void test_getMethod_parameterized_doesNotUseTypeParameter() {
|
| //
|
| - // class List<int>
|
| - // class List<double>
|
| + // class A<E> { void m() {} }
|
| + // class B {}
|
| //
|
| - InterfaceType listType = _typeProvider.listType;
|
| - InterfaceType intType = _typeProvider.intType;
|
| - InterfaceType doubleType = _typeProvider.doubleType;
|
| - InterfaceType listOfIntType = listType.substitute4(<DartType>[intType]);
|
| - InterfaceType listOfDoubleType =
|
| - listType.substitute4(<DartType>[doubleType]);
|
| - expect(listOfIntType.getLeastUpperBound(listOfDoubleType),
|
| - _typeProvider.objectType);
|
| - }
|
| -
|
| - void test_getLeastUpperBound_typeParameters_same() {
|
| + ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]);
|
| + InterfaceType typeB = ElementFactory.classElement2("B").type;
|
| + DartType typeE = classA.type.typeArguments[0];
|
| + String methodName = "m";
|
| + MethodElementImpl methodM =
|
| + ElementFactory.methodElement(methodName, typeB, []);
|
| + classA.methods = <MethodElement>[methodM];
|
| + methodM.type = new FunctionTypeImpl(methodM);
|
| //
|
| - // List<int>
|
| - // List<int>
|
| + // A<I>
|
| //
|
| - InterfaceType listType = _typeProvider.listType;
|
| - InterfaceType intType = _typeProvider.intType;
|
| - InterfaceType listOfIntType = listType.substitute4(<DartType>[intType]);
|
| - expect(listOfIntType.getLeastUpperBound(listOfIntType), listOfIntType);
|
| + InterfaceType typeI = ElementFactory.classElement2("I").type;
|
| + InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA);
|
| + typeAI.typeArguments = <DartType>[typeI];
|
| + MethodElement method = typeAI.getMethod(methodName);
|
| + expect(method, isNotNull);
|
| + FunctionType methodType = method.type;
|
| + expect(methodType.typeParameters, [same(typeE.element)]);
|
| + expect(methodType.typeArguments, [same(typeI)]);
|
| }
|
|
|
| - void test_getMethod_implemented() {
|
| + void test_getMethod_parameterized_flushCached_whenVersionChanges() {
|
| //
|
| - // class A { m() {} }
|
| + // class A<E> { E m(E p) {} }
|
| //
|
| - ClassElementImpl classA = ElementFactory.classElement2("A");
|
| + ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]);
|
| + DartType typeE = classA.type.typeArguments[0];
|
| String methodName = "m";
|
| - MethodElementImpl methodM = ElementFactory.methodElement(methodName, null);
|
| + MethodElementImpl methodM =
|
| + ElementFactory.methodElement(methodName, typeE, [typeE]);
|
| classA.methods = <MethodElement>[methodM];
|
| - InterfaceType typeA = classA.type;
|
| - expect(typeA.getMethod(methodName), same(methodM));
|
| + methodM.type = new FunctionTypeImpl(methodM);
|
| + //
|
| + // A<I>
|
| + //
|
| + InterfaceType typeI = ElementFactory.classElement2("I").type;
|
| + InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA);
|
| + typeAI.typeArguments = <DartType>[typeI];
|
| + // Methods list is cached.
|
| + MethodElement method = typeAI.methods.single;
|
| + expect(typeAI.methods.single, same(method));
|
| + // Methods list is flushed on version change.
|
| + classA.version++;
|
| + expect(typeAI.methods.single, isNot(same(method)));
|
| }
|
|
|
| - void test_getMethod_parameterized() {
|
| + void test_getMethod_parameterized_usesTypeParameter() {
|
| //
|
| // class A<E> { E m(E p) {} }
|
| //
|
| @@ -2753,8 +2816,7 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| MethodElementImpl methodM =
|
| ElementFactory.methodElement(methodName, typeE, [typeE]);
|
| classA.methods = <MethodElement>[methodM];
|
| - (methodM.type as FunctionTypeImpl).typeArguments =
|
| - classA.type.typeArguments;
|
| + methodM.type = new FunctionTypeImpl(methodM);
|
| //
|
| // A<I>
|
| //
|
| @@ -2764,6 +2826,8 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| MethodElement method = typeAI.getMethod(methodName);
|
| expect(method, isNotNull);
|
| FunctionType methodType = method.type;
|
| + expect(methodType.typeParameters, [same(typeE.element)]);
|
| + expect(methodType.typeArguments, [same(typeI)]);
|
| expect(methodType.returnType, same(typeI));
|
| List<DartType> parameterTypes = methodType.normalParameterTypes;
|
| expect(parameterTypes, hasLength(1));
|
| @@ -2858,11 +2922,10 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]);
|
| DartType typeE = classA.type.typeArguments[0];
|
| String setterName = "s";
|
| - PropertyAccessorElement setterS =
|
| + PropertyAccessorElementImpl setterS =
|
| ElementFactory.setterElement(setterName, false, typeE);
|
| classA.accessors = <PropertyAccessorElement>[setterS];
|
| - (setterS.type as FunctionTypeImpl).typeArguments =
|
| - classA.type.typeArguments;
|
| + setterS.type = new FunctionTypeImpl(setterS);
|
| //
|
| // A<I>
|
| //
|
| @@ -3026,8 +3089,8 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| ClassElement classB = ElementFactory.classElement2("B");
|
| DartType dynamicType = DynamicTypeImpl.instance;
|
| InterfaceType typeAOfDynamic =
|
| - classA.type.substitute4(<DartType>[dynamicType]);
|
| - InterfaceType typeAOfB = classA.type.substitute4(<DartType>[classB.type]);
|
| + classA.type.instantiate(<DartType>[dynamicType]);
|
| + InterfaceType typeAOfB = classA.type.instantiate(<DartType>[classB.type]);
|
| expect(typeAOfDynamic.isMoreSpecificThan(typeAOfB), isFalse);
|
| expect(typeAOfB.isMoreSpecificThan(typeAOfDynamic), isTrue);
|
| }
|
| @@ -3164,8 +3227,8 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| ClassElement classB = ElementFactory.classElement2("B");
|
| DartType dynamicType = DynamicTypeImpl.instance;
|
| InterfaceType typeAOfDynamic =
|
| - classA.type.substitute4(<DartType>[dynamicType]);
|
| - InterfaceType typeAOfB = classA.type.substitute4(<DartType>[classB.type]);
|
| + classA.type.instantiate(<DartType>[dynamicType]);
|
| + InterfaceType typeAOfB = classA.type.instantiate(<DartType>[classB.type]);
|
| expect(typeAOfDynamic.isSubtypeOf(typeAOfB), isTrue);
|
| expect(typeAOfB.isSubtypeOf(typeAOfDynamic), isTrue);
|
| }
|
| @@ -3251,7 +3314,7 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| ClassElement classJ = ElementFactory.classElement("J", classI.type);
|
| ClassElement classK = ElementFactory.classElement2("K");
|
| InterfaceType typeA = classA.type;
|
| - InterfaceType typeA_dynamic = typeA.substitute4(<DartType>[dynamicType]);
|
| + InterfaceType typeA_dynamic = typeA.instantiate(<DartType>[dynamicType]);
|
| InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA);
|
| InterfaceTypeImpl typeAJ = new InterfaceTypeImpl(classA);
|
| InterfaceTypeImpl typeAK = new InterfaceTypeImpl(classA);
|
| @@ -3523,8 +3586,7 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| MethodElementImpl methodM =
|
| ElementFactory.methodElement(methodName, typeE, [typeE]);
|
| classA.methods = <MethodElement>[methodM];
|
| - (methodM.type as FunctionTypeImpl).typeArguments =
|
| - classA.type.typeArguments;
|
| + methodM.type = new FunctionTypeImpl(methodM);
|
| ClassElementImpl classB = ElementFactory.classElement2("B", ["F"]);
|
| InterfaceType typeB = classB.type;
|
| InterfaceTypeImpl typeAF = new InterfaceTypeImpl(classA);
|
| @@ -3670,6 +3732,14 @@ class InterfaceTypeImplTest extends EngineTestCase {
|
| expect(typeA.lookUpSetter("s", library), isNull);
|
| }
|
|
|
| + void test_resolveToBound() {
|
| + InterfaceTypeImpl type =
|
| + ElementFactory.classElement2("A").type as InterfaceTypeImpl;
|
| +
|
| + // Returns this.
|
| + expect(type.resolveToBound(null), same(type));
|
| + }
|
| +
|
| void test_setTypeArguments() {
|
| InterfaceTypeImpl type =
|
| ElementFactory.classElement2("A").type as InterfaceTypeImpl;
|
| @@ -3800,91 +3870,22 @@ class LibraryElementImplTest extends EngineTestCase {
|
| unorderedEquals(<CompilationUnitElement>[unitLib, unitA, unitB]));
|
| }
|
|
|
| - void test_getVisibleLibraries_cycle() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - LibraryElementImpl library = ElementFactory.library(context, "app");
|
| - LibraryElementImpl libraryA = ElementFactory.library(context, "A");
|
| - libraryA.imports = <ImportElementImpl>[
|
| - ElementFactory.importFor(library, null)
|
| - ];
|
| - library.imports = <ImportElementImpl>[
|
| - ElementFactory.importFor(libraryA, null)
|
| - ];
|
| - List<LibraryElement> libraries = library.visibleLibraries;
|
| - expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA]));
|
| - }
|
| -
|
| - void test_getVisibleLibraries_directExports() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - LibraryElementImpl library = ElementFactory.library(context, "app");
|
| - LibraryElementImpl libraryA = ElementFactory.library(context, "A");
|
| - library.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryA)];
|
| - List<LibraryElement> libraries = library.visibleLibraries;
|
| - expect(libraries, unorderedEquals(<LibraryElement>[library]));
|
| - }
|
| -
|
| - void test_getVisibleLibraries_directImports() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - LibraryElementImpl library = ElementFactory.library(context, "app");
|
| - LibraryElementImpl libraryA = ElementFactory.library(context, "A");
|
| - library.imports = <ImportElementImpl>[
|
| - ElementFactory.importFor(libraryA, null)
|
| - ];
|
| - List<LibraryElement> libraries = library.visibleLibraries;
|
| - expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA]));
|
| - }
|
| -
|
| - void test_getVisibleLibraries_indirectExports() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - LibraryElementImpl library = ElementFactory.library(context, "app");
|
| - LibraryElementImpl libraryA = ElementFactory.library(context, "A");
|
| - LibraryElementImpl libraryAA = ElementFactory.library(context, "AA");
|
| - libraryA.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryAA)];
|
| - library.imports = <ImportElementImpl>[
|
| - ElementFactory.importFor(libraryA, null)
|
| - ];
|
| - List<LibraryElement> libraries = library.visibleLibraries;
|
| - expect(libraries,
|
| - unorderedEquals(<LibraryElement>[library, libraryA, libraryAA]));
|
| - }
|
| -
|
| - void test_getVisibleLibraries_indirectImports() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - LibraryElementImpl library = ElementFactory.library(context, "app");
|
| - LibraryElementImpl libraryA = ElementFactory.library(context, "A");
|
| - LibraryElementImpl libraryAA = ElementFactory.library(context, "AA");
|
| - LibraryElementImpl libraryB = ElementFactory.library(context, "B");
|
| - libraryA.imports = <ImportElementImpl>[
|
| - ElementFactory.importFor(libraryAA, null)
|
| - ];
|
| - library.imports = <ImportElementImpl>[
|
| - ElementFactory.importFor(libraryA, null),
|
| - ElementFactory.importFor(libraryB, null)
|
| - ];
|
| - List<LibraryElement> libraries = library.visibleLibraries;
|
| - expect(
|
| - libraries,
|
| - unorderedEquals(
|
| - <LibraryElement>[library, libraryA, libraryAA, libraryB]));
|
| - }
|
| -
|
| - void test_getVisibleLibraries_noImports() {
|
| - AnalysisContext context = createAnalysisContext();
|
| - LibraryElementImpl library = ElementFactory.library(context, "app");
|
| - expect(
|
| - library.visibleLibraries, unorderedEquals(<LibraryElement>[library]));
|
| - }
|
| -
|
| - void test_isUpToDate() {
|
| + void test_invalidateLibraryCycles_withHandle() {
|
| AnalysisContext context = createAnalysisContext();
|
| context.sourceFactory = new SourceFactory([]);
|
| - LibraryElement library = ElementFactory.library(context, "foo");
|
| - context.setContents(library.definingCompilationUnit.source, "sdfsdff");
|
| - // Assert that we are not up to date if the target has an old time stamp.
|
| - expect(library.isUpToDate(0), isFalse);
|
| - // Assert that we are up to date with a target modification time in the
|
| - // future.
|
| - expect(library.isUpToDate(JavaSystem.currentTimeMillis() + 1000), isTrue);
|
| + LibraryElementImpl library = ElementFactory.library(context, "foo");
|
| + LibraryElementImpl importedLibrary = ElementFactory.library(context, "bar");
|
| + ElementLocation location = new ElementLocationImpl.con2('');
|
| + TestElementResynthesizer resynthesizer =
|
| + new TestElementResynthesizer(context, {location: importedLibrary});
|
| + LibraryElement importedLibraryHandle =
|
| + new LibraryElementHandle(resynthesizer, location);
|
| + ImportElementImpl import =
|
| + ElementFactory.importFor(importedLibraryHandle, null);
|
| + library.imports = <ImportElement>[import];
|
| + library.libraryCycle; // Force computation of the cycle.
|
| +
|
| + library.invalidateLibraryCycles();
|
| }
|
|
|
| void test_setImports() {
|
| @@ -3904,6 +3905,45 @@ class LibraryElementImplTest extends EngineTestCase {
|
| }
|
| }
|
|
|
| +@reflectiveTest
|
| +class LocalVariableElementImplTest extends EngineTestCase {
|
| + void test_computeNode_declaredIdentifier() {
|
| + AnalysisContextHelper contextHelper = new AnalysisContextHelper();
|
| + AnalysisContext context = contextHelper.context;
|
| + Source source = contextHelper.addSource(
|
| + "/test.dart",
|
| + r'''
|
| +main() {
|
| + for (int v in <int>[1, 2, 3]) {}
|
| +}''');
|
| + LibraryElement libraryElement = context.computeLibraryElement(source);
|
| + FunctionElement mainElement = libraryElement.units[0].functions[0];
|
| + LocalVariableElement element = mainElement.localVariables[0];
|
| + DeclaredIdentifier node = element.computeNode() as DeclaredIdentifier;
|
| + expect(node, isNotNull);
|
| + expect(node.identifier.name, 'v');
|
| + expect(node.element, same(element));
|
| + }
|
| +
|
| + void test_computeNode_variableDeclaration() {
|
| + AnalysisContextHelper contextHelper = new AnalysisContextHelper();
|
| + AnalysisContext context = contextHelper.context;
|
| + Source source = contextHelper.addSource(
|
| + "/test.dart",
|
| + r'''
|
| +main() {
|
| + int v = 0;
|
| +}''');
|
| + LibraryElement libraryElement = context.computeLibraryElement(source);
|
| + FunctionElement mainElement = libraryElement.units[0].functions[0];
|
| + LocalVariableElement element = mainElement.localVariables[0];
|
| + VariableDeclaration node = element.computeNode() as VariableDeclaration;
|
| + expect(node, isNotNull);
|
| + expect(node.name.name, 'v');
|
| + expect(node.element, same(element));
|
| + }
|
| +}
|
| +
|
| @reflectiveTest
|
| class MethodElementImplTest extends EngineTestCase {
|
| void test_computeNode() {
|
| @@ -3976,8 +4016,11 @@ abstract class A {
|
| @reflectiveTest
|
| class MultiplyDefinedElementImplTest extends EngineTestCase {
|
| void test_fromElements_conflicting() {
|
| - Element firstElement = ElementFactory.localVariableElement2("xx");
|
| - Element secondElement = ElementFactory.localVariableElement2("yy");
|
| + TopLevelVariableElement firstElement =
|
| + ElementFactory.topLevelVariableElement2('xx');
|
| + TopLevelVariableElement secondElement =
|
| + ElementFactory.topLevelVariableElement2('yy');
|
| + _addToLibrary([firstElement, secondElement]);
|
| Element result = MultiplyDefinedElementImpl.fromElements(
|
| null, firstElement, secondElement);
|
| EngineTestCase.assertInstanceOf(
|
| @@ -3986,15 +4029,19 @@ class MultiplyDefinedElementImplTest extends EngineTestCase {
|
| (result as MultiplyDefinedElement).conflictingElements;
|
| expect(elements, hasLength(2));
|
| for (int i = 0; i < elements.length; i++) {
|
| - EngineTestCase.assertInstanceOf((obj) => obj is LocalVariableElement,
|
| - LocalVariableElement, elements[i]);
|
| + EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
|
| + TopLevelVariableElement, elements[i]);
|
| }
|
| }
|
|
|
| void test_fromElements_multiple() {
|
| - Element firstElement = ElementFactory.localVariableElement2("xx");
|
| - Element secondElement = ElementFactory.localVariableElement2("yy");
|
| - Element thirdElement = ElementFactory.localVariableElement2("zz");
|
| + TopLevelVariableElement firstElement =
|
| + ElementFactory.topLevelVariableElement2('xx');
|
| + TopLevelVariableElement secondElement =
|
| + ElementFactory.topLevelVariableElement2('yy');
|
| + TopLevelVariableElement thirdElement =
|
| + ElementFactory.topLevelVariableElement2('zz');
|
| + _addToLibrary([firstElement, secondElement, thirdElement]);
|
| Element result = MultiplyDefinedElementImpl.fromElements(
|
| null,
|
| MultiplyDefinedElementImpl.fromElements(
|
| @@ -4006,16 +4053,26 @@ class MultiplyDefinedElementImplTest extends EngineTestCase {
|
| (result as MultiplyDefinedElement).conflictingElements;
|
| expect(elements, hasLength(3));
|
| for (int i = 0; i < elements.length; i++) {
|
| - EngineTestCase.assertInstanceOf((obj) => obj is LocalVariableElement,
|
| - LocalVariableElement, elements[i]);
|
| + EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
|
| + TopLevelVariableElement, elements[i]);
|
| }
|
| }
|
|
|
| void test_fromElements_nonConflicting() {
|
| - Element element = ElementFactory.localVariableElement2("xx");
|
| + TopLevelVariableElement element =
|
| + ElementFactory.topLevelVariableElement2('xx');
|
| + _addToLibrary([element]);
|
| expect(MultiplyDefinedElementImpl.fromElements(null, element, element),
|
| same(element));
|
| }
|
| +
|
| + void _addToLibrary(List<TopLevelVariableElement> variables) {
|
| + CompilationUnitElementImpl compilationUnit =
|
| + ElementFactory.compilationUnit('lib.dart');
|
| + LibraryElementImpl library = ElementFactory.library(null, 'lib');
|
| + library.definingCompilationUnit = compilationUnit;
|
| + compilationUnit.topLevelVariables = variables;
|
| + }
|
| }
|
|
|
| @reflectiveTest
|
| @@ -4110,6 +4167,82 @@ main(int p) {
|
| }
|
| }
|
|
|
| +@reflectiveTest
|
| +class PropertyAccessorElementImplTest extends EngineTestCase {
|
| + void test_matchesHandle_getter() {
|
| + CompilationUnitElementImpl compilationUnitElement =
|
| + ElementFactory.compilationUnit('foo.dart');
|
| + ElementFactory.library(null, '')
|
| + ..definingCompilationUnit = compilationUnitElement;
|
| + PropertyAccessorElementImpl element =
|
| + ElementFactory.getterElement('x', true, DynamicTypeImpl.instance);
|
| + compilationUnitElement.accessors = <PropertyAccessorElement>[element];
|
| + PropertyAccessorElementHandle handle =
|
| + new PropertyAccessorElementHandle(null, element.location);
|
| + expect(element.hashCode, handle.hashCode);
|
| + expect(element == handle, isTrue);
|
| + expect(handle == element, isTrue);
|
| + }
|
| +
|
| + void test_matchesHandle_setter() {
|
| + CompilationUnitElementImpl compilationUnitElement =
|
| + ElementFactory.compilationUnit('foo.dart');
|
| + ElementFactory.library(null, '')
|
| + ..definingCompilationUnit = compilationUnitElement;
|
| + PropertyAccessorElementImpl element =
|
| + ElementFactory.setterElement('x', true, DynamicTypeImpl.instance);
|
| + compilationUnitElement.accessors = <PropertyAccessorElement>[element];
|
| + PropertyAccessorElementHandle handle =
|
| + new PropertyAccessorElementHandle(null, element.location);
|
| + expect(element.hashCode, handle.hashCode);
|
| + expect(element == handle, isTrue);
|
| + expect(handle == element, isTrue);
|
| + }
|
| +}
|
| +
|
| +class TestElementResynthesizer extends ElementResynthesizer {
|
| + Map<ElementLocation, Element> locationMap;
|
| +
|
| + TestElementResynthesizer(AnalysisContext context, this.locationMap)
|
| + : super(context);
|
| +
|
| + @override
|
| + Element getElement(ElementLocation location) {
|
| + return locationMap[location];
|
| + }
|
| +}
|
| +
|
| +@reflectiveTest
|
| +class TopLevelVariableElementImplTest extends ResolverTestCase {
|
| + void test_computeConstantValue() {
|
| + addNamedSource(
|
| + '/a.dart',
|
| + r'''
|
| +const int C = 42;
|
| +''');
|
| + Source source = addSource(r'''
|
| +import 'a.dart';
|
| +main() {
|
| + print(C);
|
| +}
|
| +''');
|
| + LibraryElement library = resolve2(source);
|
| + CompilationUnit unit = resolveCompilationUnit(source, library);
|
| + FunctionDeclaration main = unit.declarations[0];
|
| + BlockFunctionBody body = main.functionExpression.body;
|
| + ExpressionStatement statement = body.block.statements[0];
|
| + MethodInvocation invocation = statement.expression;
|
| + SimpleIdentifier argument = invocation.argumentList.arguments[0];
|
| + PropertyAccessorElementImpl getter = argument.bestElement;
|
| + TopLevelVariableElement constant = getter.variable;
|
| + expect(constant.constantValue, isNull);
|
| + DartObject value = constant.computeConstantValue();
|
| + expect(value, isNotNull);
|
| + expect(value.toIntValue(), 42);
|
| + expect(constant.constantValue, value);
|
| + }
|
| +}
|
| +
|
| @reflectiveTest
|
| class TypeParameterTypeImplTest extends EngineTestCase {
|
| void test_creation() {
|
| @@ -4142,7 +4275,7 @@ class TypeParameterTypeImplTest extends EngineTestCase {
|
| expect(type.isMoreSpecificThan(ElementFactory.object.type), isTrue);
|
| }
|
|
|
| - void test_isMoreSpecificThan_typeArguments_resursive() {
|
| + void test_isMoreSpecificThan_typeArguments_recursive() {
|
| ClassElementImpl classS = ElementFactory.classElement2("A");
|
| TypeParameterElementImpl typeParameterU =
|
| new TypeParameterElementImpl.forNode(AstFactory.identifier3("U"));
|
| @@ -4214,6 +4347,36 @@ class TypeParameterTypeImplTest extends EngineTestCase {
|
| expect(typeParameterTypeT.isMoreSpecificThan(classS.type), isTrue);
|
| }
|
|
|
| + void test_resolveToBound_bound() {
|
| + ClassElementImpl classS = ElementFactory.classElement2("A");
|
| + TypeParameterElementImpl element =
|
| + new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"));
|
| + element.bound = classS.type;
|
| + TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
|
| + expect(type.resolveToBound(null), same(classS.type));
|
| + }
|
| +
|
| + void test_resolveToBound_nestedBound() {
|
| + ClassElementImpl classS = ElementFactory.classElement2("A");
|
| + TypeParameterElementImpl elementE =
|
| + new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"));
|
| + elementE.bound = classS.type;
|
| + TypeParameterTypeImpl typeE = new TypeParameterTypeImpl(elementE);
|
| + TypeParameterElementImpl elementF =
|
| + new TypeParameterElementImpl.forNode(AstFactory.identifier3("F"));
|
| + elementF.bound = typeE;
|
| + TypeParameterTypeImpl typeF = new TypeParameterTypeImpl(elementE);
|
| + expect(typeF.resolveToBound(null), same(classS.type));
|
| + }
|
| +
|
| + void test_resolveToBound_unbound() {
|
| + TypeParameterTypeImpl type = new TypeParameterTypeImpl(
|
| + new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")));
|
| + // Returns whatever type is passed to resolveToBound().
|
| + expect(type.resolveToBound(VoidTypeImpl.instance),
|
| + same(VoidTypeImpl.instance));
|
| + }
|
| +
|
| void test_substitute_equal() {
|
| TypeParameterElementImpl element =
|
| new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"));
|
| @@ -4273,6 +4436,11 @@ class VoidTypeImplTest extends EngineTestCase {
|
| void test_isVoid() {
|
| expect(_voidType.isVoid, isTrue);
|
| }
|
| +
|
| + void test_resolveToBound() {
|
| + // Returns this.
|
| + expect(_voidType.resolveToBound(null), same(_voidType));
|
| + }
|
| }
|
|
|
| class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction
|
|
|