| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.element_test; | 5 library engine.element_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
| 10 show AnalysisContext, AnalysisOptionsImpl; | 10 show AnalysisContext, AnalysisOptionsImpl; |
| (...skipping 1871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 ElementFactory.functionTypeAliasElement('f'); | 1882 ElementFactory.functionTypeAliasElement('f'); |
| 1883 FunctionTypeAliasElementImpl g = | 1883 FunctionTypeAliasElementImpl g = |
| 1884 ElementFactory.functionTypeAliasElement('g'); | 1884 ElementFactory.functionTypeAliasElement('g'); |
| 1885 f.typeParameters = [ElementFactory.typeParameterElement('T')]; | 1885 f.typeParameters = [ElementFactory.typeParameterElement('T')]; |
| 1886 f.returnType = g.type; | 1886 f.returnType = g.type; |
| 1887 FunctionTypeImpl paramType = f.type.returnType; | 1887 FunctionTypeImpl paramType = f.type.returnType; |
| 1888 expect(paramType.prunedTypedefs, hasLength(1)); | 1888 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1889 expect(paramType.prunedTypedefs[0], same(f)); | 1889 expect(paramType.prunedTypedefs[0], same(f)); |
| 1890 } | 1890 } |
| 1891 | 1891 |
| 1892 void test_setTypeArguments() { | 1892 void test_withTypeArguments() { |
| 1893 ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]); | 1893 ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]); |
| 1894 MethodElementImpl methodElement = | 1894 MethodElementImpl methodElement = |
| 1895 new MethodElementImpl.forNode(AstFactory.identifier3("m")); | 1895 new MethodElementImpl.forNode(AstFactory.identifier3("m")); |
| 1896 enclosingClass.methods = <MethodElement>[methodElement]; | 1896 enclosingClass.methods = <MethodElement>[methodElement]; |
| 1897 FunctionTypeImpl type = new FunctionTypeImpl(methodElement); | 1897 FunctionTypeImpl type = new FunctionTypeImpl(methodElement); |
| 1898 DartType expectedType = enclosingClass.typeParameters[0].type; | 1898 DartType expectedType = enclosingClass.typeParameters[0].type; |
| 1899 type.typeArguments = <DartType>[expectedType]; | |
| 1900 List<DartType> arguments = type.typeArguments; | 1899 List<DartType> arguments = type.typeArguments; |
| 1901 expect(arguments, hasLength(1)); | 1900 expect(arguments, hasLength(1)); |
| 1902 expect(arguments[0], expectedType); | 1901 expect(arguments[0], expectedType); |
| 1903 } | 1902 } |
| 1904 | 1903 |
| 1905 void test_substitute2_equal() { | 1904 void test_substitute2_equal() { |
| 1906 ClassElementImpl definingClass = ElementFactory.classElement2("C", ["E"]); | 1905 ClassElementImpl definingClass = ElementFactory.classElement2("C", ["E"]); |
| 1907 TypeParameterType parameterType = definingClass.typeParameters[0].type; | 1906 TypeParameterType parameterType = definingClass.typeParameters[0].type; |
| 1908 MethodElementImpl functionElement = | 1907 MethodElementImpl functionElement = |
| 1909 new MethodElementImpl.forNode(AstFactory.identifier3("m")); | 1908 new MethodElementImpl.forNode(AstFactory.identifier3("m")); |
| 1910 String namedParameterName = "c"; | 1909 String namedParameterName = "c"; |
| 1911 functionElement.parameters = <ParameterElement>[ | 1910 functionElement.parameters = <ParameterElement>[ |
| 1912 ElementFactory.requiredParameter2("a", parameterType), | 1911 ElementFactory.requiredParameter2("a", parameterType), |
| 1913 ElementFactory.positionalParameter2("b", parameterType), | 1912 ElementFactory.positionalParameter2("b", parameterType), |
| 1914 ElementFactory.namedParameter2(namedParameterName, parameterType) | 1913 ElementFactory.namedParameter2(namedParameterName, parameterType) |
| 1915 ]; | 1914 ]; |
| 1916 functionElement.returnType = parameterType; | 1915 functionElement.returnType = parameterType; |
| 1917 definingClass.methods = <MethodElement>[functionElement]; | 1916 definingClass.methods = <MethodElement>[functionElement]; |
| 1918 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); | 1917 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); |
| 1919 functionType.typeArguments = <DartType>[parameterType]; | |
| 1920 InterfaceTypeImpl argumentType = new InterfaceTypeImpl( | 1918 InterfaceTypeImpl argumentType = new InterfaceTypeImpl( |
| 1921 new ClassElementImpl.forNode(AstFactory.identifier3("D"))); | 1919 new ClassElementImpl.forNode(AstFactory.identifier3("D"))); |
| 1922 FunctionType result = functionType.substitute2( | 1920 FunctionType result = functionType.substitute2( |
| 1923 <DartType>[argumentType], <DartType>[parameterType]); | 1921 <DartType>[argumentType], <DartType>[parameterType]); |
| 1924 expect(result.returnType, argumentType); | 1922 expect(result.returnType, argumentType); |
| 1925 List<DartType> normalParameters = result.normalParameterTypes; | 1923 List<DartType> normalParameters = result.normalParameterTypes; |
| 1926 expect(normalParameters, hasLength(1)); | 1924 expect(normalParameters, hasLength(1)); |
| 1927 expect(normalParameters[0], argumentType); | 1925 expect(normalParameters[0], argumentType); |
| 1928 List<DartType> optionalParameters = result.optionalParameterTypes; | 1926 List<DartType> optionalParameters = result.optionalParameterTypes; |
| 1929 expect(optionalParameters, hasLength(1)); | 1927 expect(optionalParameters, hasLength(1)); |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2419 expect(typeA.getGetter(getterName), same(getterG)); | 2417 expect(typeA.getGetter(getterName), same(getterG)); |
| 2420 } | 2418 } |
| 2421 | 2419 |
| 2422 void test_getGetter_parameterized() { | 2420 void test_getGetter_parameterized() { |
| 2423 // | 2421 // |
| 2424 // class A<E> { E get g {} } | 2422 // class A<E> { E get g {} } |
| 2425 // | 2423 // |
| 2426 ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]); | 2424 ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]); |
| 2427 DartType typeE = classA.type.typeArguments[0]; | 2425 DartType typeE = classA.type.typeArguments[0]; |
| 2428 String getterName = "g"; | 2426 String getterName = "g"; |
| 2429 PropertyAccessorElement getterG = | 2427 PropertyAccessorElementImpl getterG = |
| 2430 ElementFactory.getterElement(getterName, false, typeE); | 2428 ElementFactory.getterElement(getterName, false, typeE); |
| 2431 classA.accessors = <PropertyAccessorElement>[getterG]; | 2429 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 2432 (getterG.type as FunctionTypeImpl).typeArguments = | 2430 getterG.type = new FunctionTypeImpl(getterG); |
| 2433 classA.type.typeArguments; | |
| 2434 // | 2431 // |
| 2435 // A<I> | 2432 // A<I> |
| 2436 // | 2433 // |
| 2437 InterfaceType typeI = ElementFactory.classElement2("I").type; | 2434 InterfaceType typeI = ElementFactory.classElement2("I").type; |
| 2438 InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA); | 2435 InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA); |
| 2439 typeAI.typeArguments = <DartType>[typeI]; | 2436 typeAI.typeArguments = <DartType>[typeI]; |
| 2440 PropertyAccessorElement getter = typeAI.getGetter(getterName); | 2437 PropertyAccessorElement getter = typeAI.getGetter(getterName); |
| 2441 expect(getter, isNotNull); | 2438 expect(getter, isNotNull); |
| 2442 FunctionType getterType = getter.type; | 2439 FunctionType getterType = getter.type; |
| 2443 expect(getterType.returnType, same(typeI)); | 2440 expect(getterType.returnType, same(typeI)); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2746 void test_getMethod_parameterized() { | 2743 void test_getMethod_parameterized() { |
| 2747 // | 2744 // |
| 2748 // class A<E> { E m(E p) {} } | 2745 // class A<E> { E m(E p) {} } |
| 2749 // | 2746 // |
| 2750 ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]); | 2747 ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]); |
| 2751 DartType typeE = classA.type.typeArguments[0]; | 2748 DartType typeE = classA.type.typeArguments[0]; |
| 2752 String methodName = "m"; | 2749 String methodName = "m"; |
| 2753 MethodElementImpl methodM = | 2750 MethodElementImpl methodM = |
| 2754 ElementFactory.methodElement(methodName, typeE, [typeE]); | 2751 ElementFactory.methodElement(methodName, typeE, [typeE]); |
| 2755 classA.methods = <MethodElement>[methodM]; | 2752 classA.methods = <MethodElement>[methodM]; |
| 2756 (methodM.type as FunctionTypeImpl).typeArguments = | 2753 methodM.type = new FunctionTypeImpl(methodM); |
| 2757 classA.type.typeArguments; | |
| 2758 // | 2754 // |
| 2759 // A<I> | 2755 // A<I> |
| 2760 // | 2756 // |
| 2761 InterfaceType typeI = ElementFactory.classElement2("I").type; | 2757 InterfaceType typeI = ElementFactory.classElement2("I").type; |
| 2762 InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA); | 2758 InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA); |
| 2763 typeAI.typeArguments = <DartType>[typeI]; | 2759 typeAI.typeArguments = <DartType>[typeI]; |
| 2764 MethodElement method = typeAI.getMethod(methodName); | 2760 MethodElement method = typeAI.getMethod(methodName); |
| 2765 expect(method, isNotNull); | 2761 expect(method, isNotNull); |
| 2766 FunctionType methodType = method.type; | 2762 FunctionType methodType = method.type; |
| 2767 expect(methodType.returnType, same(typeI)); | 2763 expect(methodType.returnType, same(typeI)); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2851 expect(typeA.getSetter(setterName), same(setterS)); | 2847 expect(typeA.getSetter(setterName), same(setterS)); |
| 2852 } | 2848 } |
| 2853 | 2849 |
| 2854 void test_getSetter_parameterized() { | 2850 void test_getSetter_parameterized() { |
| 2855 // | 2851 // |
| 2856 // class A<E> { set s(E p) {} } | 2852 // class A<E> { set s(E p) {} } |
| 2857 // | 2853 // |
| 2858 ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]); | 2854 ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]); |
| 2859 DartType typeE = classA.type.typeArguments[0]; | 2855 DartType typeE = classA.type.typeArguments[0]; |
| 2860 String setterName = "s"; | 2856 String setterName = "s"; |
| 2861 PropertyAccessorElement setterS = | 2857 PropertyAccessorElementImpl setterS = |
| 2862 ElementFactory.setterElement(setterName, false, typeE); | 2858 ElementFactory.setterElement(setterName, false, typeE); |
| 2863 classA.accessors = <PropertyAccessorElement>[setterS]; | 2859 classA.accessors = <PropertyAccessorElement>[setterS]; |
| 2864 (setterS.type as FunctionTypeImpl).typeArguments = | 2860 setterS.type = new FunctionTypeImpl(setterS); |
| 2865 classA.type.typeArguments; | |
| 2866 // | 2861 // |
| 2867 // A<I> | 2862 // A<I> |
| 2868 // | 2863 // |
| 2869 InterfaceType typeI = ElementFactory.classElement2("I").type; | 2864 InterfaceType typeI = ElementFactory.classElement2("I").type; |
| 2870 InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA); | 2865 InterfaceTypeImpl typeAI = new InterfaceTypeImpl(classA); |
| 2871 typeAI.typeArguments = <DartType>[typeI]; | 2866 typeAI.typeArguments = <DartType>[typeI]; |
| 2872 PropertyAccessorElement setter = typeAI.getSetter(setterName); | 2867 PropertyAccessorElement setter = typeAI.getSetter(setterName); |
| 2873 expect(setter, isNotNull); | 2868 expect(setter, isNotNull); |
| 2874 FunctionType setterType = setter.type; | 2869 FunctionType setterType = setter.type; |
| 2875 List<DartType> parameterTypes = setterType.normalParameterTypes; | 2870 List<DartType> parameterTypes = setterType.normalParameterTypes; |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3516 // | 3511 // |
| 3517 // class A<E> { E m(E p) {} } | 3512 // class A<E> { E m(E p) {} } |
| 3518 // class B<F> extends A<F> {} | 3513 // class B<F> extends A<F> {} |
| 3519 // | 3514 // |
| 3520 ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]); | 3515 ClassElementImpl classA = ElementFactory.classElement2("A", ["E"]); |
| 3521 DartType typeE = classA.type.typeArguments[0]; | 3516 DartType typeE = classA.type.typeArguments[0]; |
| 3522 String methodName = "m"; | 3517 String methodName = "m"; |
| 3523 MethodElementImpl methodM = | 3518 MethodElementImpl methodM = |
| 3524 ElementFactory.methodElement(methodName, typeE, [typeE]); | 3519 ElementFactory.methodElement(methodName, typeE, [typeE]); |
| 3525 classA.methods = <MethodElement>[methodM]; | 3520 classA.methods = <MethodElement>[methodM]; |
| 3526 (methodM.type as FunctionTypeImpl).typeArguments = | 3521 methodM.type = new FunctionTypeImpl(methodM); |
| 3527 classA.type.typeArguments; | |
| 3528 ClassElementImpl classB = ElementFactory.classElement2("B", ["F"]); | 3522 ClassElementImpl classB = ElementFactory.classElement2("B", ["F"]); |
| 3529 InterfaceType typeB = classB.type; | 3523 InterfaceType typeB = classB.type; |
| 3530 InterfaceTypeImpl typeAF = new InterfaceTypeImpl(classA); | 3524 InterfaceTypeImpl typeAF = new InterfaceTypeImpl(classA); |
| 3531 typeAF.typeArguments = <DartType>[typeB.typeArguments[0]]; | 3525 typeAF.typeArguments = <DartType>[typeB.typeArguments[0]]; |
| 3532 classB.supertype = typeAF; | 3526 classB.supertype = typeAF; |
| 3533 LibraryElementImpl library = | 3527 LibraryElementImpl library = |
| 3534 ElementFactory.library(createAnalysisContext(), "lib"); | 3528 ElementFactory.library(createAnalysisContext(), "lib"); |
| 3535 CompilationUnitElement unit = library.definingCompilationUnit; | 3529 CompilationUnitElement unit = library.definingCompilationUnit; |
| 3536 (unit as CompilationUnitElementImpl).types = <ClassElement>[classA]; | 3530 (unit as CompilationUnitElementImpl).types = <ClassElement>[classA]; |
| 3537 // | 3531 // |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4276 } | 4270 } |
| 4277 | 4271 |
| 4278 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction | 4272 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction |
| 4279 extends InterfaceTypeImpl { | 4273 extends InterfaceTypeImpl { |
| 4280 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) | 4274 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) |
| 4281 : super(arg0); | 4275 : super(arg0); |
| 4282 | 4276 |
| 4283 @override | 4277 @override |
| 4284 bool get isDartCoreFunction => true; | 4278 bool get isDartCoreFunction => true; |
| 4285 } | 4279 } |
| OLD | NEW |