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 analyzer.test.src.dart.element.element_test; | 5 library analyzer.test.src.dart.element.element_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
(...skipping 2065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2076 } | 2076 } |
2077 | 2077 |
2078 void test_toString_recursive_via_interface_type() { | 2078 void test_toString_recursive_via_interface_type() { |
2079 FunctionTypeAliasElementImpl f = | 2079 FunctionTypeAliasElementImpl f = |
2080 ElementFactory.functionTypeAliasElement('f'); | 2080 ElementFactory.functionTypeAliasElement('f'); |
2081 ClassElementImpl c = ElementFactory.classElement2('C', ['T']); | 2081 ClassElementImpl c = ElementFactory.classElement2('C', ['T']); |
2082 f.returnType = c.type.instantiate([f.type]); | 2082 f.returnType = c.type.instantiate([f.type]); |
2083 expect(f.type.toString(), '() \u2192 C<...>'); | 2083 expect(f.type.toString(), '() \u2192 C<...>'); |
2084 } | 2084 } |
2085 | 2085 |
2086 void test_typeParameters_genericLocalFunction_genericMethod_genericClass() { | |
2087 // | |
2088 // class C<S> { | |
2089 // Object m<T>() { | |
2090 // U f<U>() => null; | |
2091 // } | |
2092 // } | |
2093 // | |
2094 ClassElementImpl classElement = | |
2095 ElementFactory.classElement('C', null, ['S']); | |
2096 MethodElementImpl method = new MethodElementImpl('m', 0); | |
2097 method.enclosingElement = classElement; | |
2098 method.returnType = ElementFactory.objectType; | |
2099 method.typeParameters = ElementFactory.typeParameters(['T']); | |
2100 method.type = new FunctionTypeImpl(method); | |
2101 FunctionElementImpl function = ElementFactory.functionElement('f'); | |
2102 function.enclosingElement = method; | |
2103 function.typeParameters = ElementFactory.typeParameters(['T']); | |
scheglov
2016/04/28 17:14:52
'U' maybe?
Brian Wilkerson
2016/04/28 20:46:11
Done
| |
2104 function.returnType = function.typeParameters[0].type; | |
2105 function.type = new FunctionTypeImpl(function); | |
2106 | |
2107 List<TypeParameterElement> inheritedParameters = <TypeParameterElement>[]; | |
2108 inheritedParameters.addAll(method.typeParameters); | |
2109 inheritedParameters.addAll(classElement.typeParameters); | |
2110 expect(function.type.typeArguments, | |
2111 unorderedEquals(_toTypes(inheritedParameters))); | |
2112 expect(function.type.typeFormals, unorderedEquals(function.typeParameters)); | |
2113 expect(function.type.typeParameters, unorderedEquals(inheritedParameters)); | |
2114 } | |
2115 | |
2116 void test_typeParameters_genericMethod_genericClass() { | |
2117 // | |
2118 // class C<S> { | |
2119 // Object m<T>() => null; | |
2120 // } | |
2121 // | |
2122 ClassElementImpl classElement = | |
2123 ElementFactory.classElement('C', null, ['S']); | |
2124 MethodElementImpl method = new MethodElementImpl('m', 0); | |
2125 method.enclosingElement = classElement; | |
2126 method.returnType = ElementFactory.objectType; | |
2127 method.typeParameters = ElementFactory.typeParameters(['T']); | |
2128 method.type = new FunctionTypeImpl(method); | |
2129 | |
2130 expect(method.type.typeArguments, | |
2131 unorderedEquals(_toTypes(classElement.typeParameters))); | |
2132 expect(method.type.typeFormals, unorderedEquals(method.typeParameters)); | |
2133 expect(method.type.typeParameters, | |
2134 unorderedEquals(classElement.typeParameters)); | |
2135 } | |
2136 | |
2137 void test_typeParameters_genericMethod_simpleClass() { | |
2138 // | |
2139 // class C<S> { | |
2140 // Object m<T>() => null; | |
2141 // } | |
2142 // | |
2143 ClassElementImpl classElement = ElementFactory.classElement2('C'); | |
2144 MethodElementImpl method = new MethodElementImpl('m', 0); | |
2145 method.enclosingElement = classElement; | |
2146 method.returnType = ElementFactory.objectType; | |
2147 method.typeParameters = ElementFactory.typeParameters(['T']); | |
2148 method.type = new FunctionTypeImpl(method); | |
2149 | |
2150 expect(method.type.typeArguments, | |
2151 unorderedEquals(_toTypes(classElement.typeParameters))); | |
2152 expect(method.type.typeFormals, unorderedEquals(method.typeParameters)); | |
2153 expect(method.type.typeParameters, | |
2154 unorderedEquals(classElement.typeParameters)); | |
2155 } | |
2156 | |
2157 void test_typeParameters_genericTopLevelFunction() { | |
2158 // | |
2159 // Object f<T>() => null; | |
2160 // | |
2161 FunctionElementImpl function = ElementFactory.functionElement('f'); | |
2162 function.returnType = ElementFactory.objectType; | |
2163 function.typeParameters = ElementFactory.typeParameters(['T']); | |
2164 function.type = new FunctionTypeImpl(function); | |
2165 | |
2166 expect(function.type.typeArguments, isEmpty); | |
2167 expect(function.type.typeFormals, unorderedEquals(function.typeParameters)); | |
2168 expect(function.type.typeParameters, isEmpty); | |
2169 } | |
2170 | |
2171 void test_typeParameters_simpleMethod_genericClass() { | |
2172 // | |
2173 // class C<S> { | |
2174 // Object m<T>() => null; | |
2175 // } | |
2176 // | |
2177 ClassElementImpl classElement = | |
2178 ElementFactory.classElement('C', null, ['S']); | |
2179 MethodElementImpl method = new MethodElementImpl('m', 0); | |
2180 method.enclosingElement = classElement; | |
2181 method.returnType = ElementFactory.objectType; | |
2182 method.type = new FunctionTypeImpl(method); | |
scheglov
2016/04/28 17:14:52
Why don't we set <T> anywhere in this and the next
Brian Wilkerson
2016/04/28 20:46:11
Oversight. Done.
| |
2183 | |
2184 expect(method.type.typeArguments, | |
2185 unorderedEquals(_toTypes(classElement.typeParameters))); | |
2186 expect(method.type.typeFormals, unorderedEquals(method.typeParameters)); | |
2187 expect(method.type.typeParameters, | |
2188 unorderedEquals(classElement.typeParameters)); | |
2189 } | |
2190 | |
2191 void test_typeParameters_simpleMethod_simpleClass() { | |
2192 // | |
2193 // class C<S> { | |
2194 // Object m<T>() => null; | |
2195 // } | |
2196 // | |
2197 ClassElementImpl classElement = ElementFactory.classElement2('C'); | |
2198 MethodElementImpl method = new MethodElementImpl('m', 0); | |
2199 method.enclosingElement = classElement; | |
2200 method.returnType = ElementFactory.objectType; | |
2201 method.type = new FunctionTypeImpl(method); | |
2202 | |
2203 expect(method.type.typeArguments, | |
2204 unorderedEquals(_toTypes(classElement.typeParameters))); | |
2205 expect(method.type.typeFormals, unorderedEquals(method.typeParameters)); | |
2206 expect(method.type.typeParameters, | |
2207 unorderedEquals(classElement.typeParameters)); | |
2208 } | |
2209 | |
2086 void test_withTypeArguments() { | 2210 void test_withTypeArguments() { |
2087 ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]); | 2211 ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]); |
2088 MethodElementImpl methodElement = | 2212 MethodElementImpl methodElement = |
2089 new MethodElementImpl.forNode(AstFactory.identifier3("m")); | 2213 new MethodElementImpl.forNode(AstFactory.identifier3("m")); |
2090 enclosingClass.methods = <MethodElement>[methodElement]; | 2214 enclosingClass.methods = <MethodElement>[methodElement]; |
2091 FunctionTypeImpl type = new FunctionTypeImpl(methodElement); | 2215 FunctionTypeImpl type = new FunctionTypeImpl(methodElement); |
2092 DartType expectedType = enclosingClass.typeParameters[0].type; | 2216 DartType expectedType = enclosingClass.typeParameters[0].type; |
2093 List<DartType> arguments = type.typeArguments; | 2217 List<DartType> arguments = type.typeArguments; |
2094 expect(arguments, hasLength(1)); | 2218 expect(arguments, hasLength(1)); |
2095 expect(arguments[0], expectedType); | 2219 expect(arguments[0], expectedType); |
2096 } | 2220 } |
2221 | |
2222 Iterable<DartType> _toTypes(List<TypeParameterElement> typeParameters) { | |
2223 return typeParameters.map((TypeParameterElement element) => element.type); | |
2224 } | |
2097 } | 2225 } |
2098 | 2226 |
2099 @reflectiveTest | 2227 @reflectiveTest |
2100 class InterfaceTypeImplTest extends EngineTestCase { | 2228 class InterfaceTypeImplTest extends EngineTestCase { |
2101 /** | 2229 /** |
2102 * The type provider used to access the types. | 2230 * The type provider used to access the types. |
2103 */ | 2231 */ |
2104 TestTypeProvider _typeProvider; | 2232 TestTypeProvider _typeProvider; |
2105 | 2233 |
2106 @override | 2234 @override |
(...skipping 2121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4228 } | 4356 } |
4229 | 4357 |
4230 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction | 4358 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction |
4231 extends InterfaceTypeImpl { | 4359 extends InterfaceTypeImpl { |
4232 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) | 4360 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) |
4233 : super(arg0); | 4361 : super(arg0); |
4234 | 4362 |
4235 @override | 4363 @override |
4236 bool get isDartCoreFunction => true; | 4364 bool get isDartCoreFunction => true; |
4237 } | 4365 } |
OLD | NEW |