Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: pkg/analyzer/test/src/dart/element/element_test.dart

Issue 2027893002: Start separating ClassElementImpl for Class and Enum. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/constant/value.dart'; 8 import 'package:analyzer/dart/constant/value.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 2034 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 String namedParameterName = "c"; 2045 String namedParameterName = "c";
2046 functionElement.parameters = <ParameterElement>[ 2046 functionElement.parameters = <ParameterElement>[
2047 ElementFactory.requiredParameter2("a", parameterType), 2047 ElementFactory.requiredParameter2("a", parameterType),
2048 ElementFactory.positionalParameter2("b", parameterType), 2048 ElementFactory.positionalParameter2("b", parameterType),
2049 ElementFactory.namedParameter2(namedParameterName, parameterType) 2049 ElementFactory.namedParameter2(namedParameterName, parameterType)
2050 ]; 2050 ];
2051 functionElement.returnType = parameterType; 2051 functionElement.returnType = parameterType;
2052 definingClass.methods = <MethodElement>[functionElement]; 2052 definingClass.methods = <MethodElement>[functionElement];
2053 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); 2053 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement);
2054 InterfaceTypeImpl argumentType = new InterfaceTypeImpl( 2054 InterfaceTypeImpl argumentType = new InterfaceTypeImpl(
2055 new ClassElementImpl.forNode(AstFactory.identifier3("D"))); 2055 new ClassElementImpl_Class.forNode(AstFactory.identifier3("D")));
2056 FunctionType result = functionType 2056 FunctionType result = functionType
2057 .substitute2(<DartType>[argumentType], <DartType>[parameterType]); 2057 .substitute2(<DartType>[argumentType], <DartType>[parameterType]);
2058 expect(result.returnType, argumentType); 2058 expect(result.returnType, argumentType);
2059 List<DartType> normalParameters = result.normalParameterTypes; 2059 List<DartType> normalParameters = result.normalParameterTypes;
2060 expect(normalParameters, hasLength(1)); 2060 expect(normalParameters, hasLength(1));
2061 expect(normalParameters[0], argumentType); 2061 expect(normalParameters[0], argumentType);
2062 List<DartType> optionalParameters = result.optionalParameterTypes; 2062 List<DartType> optionalParameters = result.optionalParameterTypes;
2063 expect(optionalParameters, hasLength(1)); 2063 expect(optionalParameters, hasLength(1));
2064 expect(optionalParameters[0], argumentType); 2064 expect(optionalParameters[0], argumentType);
2065 Map<String, DartType> namedParameters = result.namedParameterTypes; 2065 Map<String, DartType> namedParameters = result.namedParameterTypes;
2066 expect(namedParameters, hasLength(1)); 2066 expect(namedParameters, hasLength(1));
2067 expect(namedParameters[namedParameterName], argumentType); 2067 expect(namedParameters[namedParameterName], argumentType);
2068 } 2068 }
2069 2069
2070 void test_substitute2_notEqual() { 2070 void test_substitute2_notEqual() {
2071 DartType returnType = new InterfaceTypeImpl( 2071 DartType returnType = new InterfaceTypeImpl(
2072 new ClassElementImpl.forNode(AstFactory.identifier3("R"))); 2072 new ClassElementImpl_Class.forNode(AstFactory.identifier3("R")));
2073 DartType normalParameterType = new InterfaceTypeImpl( 2073 DartType normalParameterType = new InterfaceTypeImpl(
2074 new ClassElementImpl.forNode(AstFactory.identifier3("A"))); 2074 new ClassElementImpl_Class.forNode(AstFactory.identifier3("A")));
2075 DartType optionalParameterType = new InterfaceTypeImpl( 2075 DartType optionalParameterType = new InterfaceTypeImpl(
2076 new ClassElementImpl.forNode(AstFactory.identifier3("B"))); 2076 new ClassElementImpl_Class.forNode(AstFactory.identifier3("B")));
2077 DartType namedParameterType = new InterfaceTypeImpl( 2077 DartType namedParameterType = new InterfaceTypeImpl(
2078 new ClassElementImpl.forNode(AstFactory.identifier3("C"))); 2078 new ClassElementImpl_Class.forNode(AstFactory.identifier3("C")));
2079 FunctionElementImpl functionElement = 2079 FunctionElementImpl functionElement =
2080 new FunctionElementImpl.forNode(AstFactory.identifier3("f")); 2080 new FunctionElementImpl.forNode(AstFactory.identifier3("f"));
2081 String namedParameterName = "c"; 2081 String namedParameterName = "c";
2082 functionElement.parameters = <ParameterElement>[ 2082 functionElement.parameters = <ParameterElement>[
2083 ElementFactory.requiredParameter2("a", normalParameterType), 2083 ElementFactory.requiredParameter2("a", normalParameterType),
2084 ElementFactory.positionalParameter2("b", optionalParameterType), 2084 ElementFactory.positionalParameter2("b", optionalParameterType),
2085 ElementFactory.namedParameter2(namedParameterName, namedParameterType) 2085 ElementFactory.namedParameter2(namedParameterName, namedParameterType)
2086 ]; 2086 ];
2087 functionElement.returnType = returnType; 2087 functionElement.returnType = returnType;
2088 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); 2088 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement);
2089 InterfaceTypeImpl argumentType = new InterfaceTypeImpl( 2089 InterfaceTypeImpl argumentType = new InterfaceTypeImpl(
2090 new ClassElementImpl.forNode(AstFactory.identifier3("D"))); 2090 new ClassElementImpl_Class.forNode(AstFactory.identifier3("D")));
2091 TypeParameterTypeImpl parameterType = new TypeParameterTypeImpl( 2091 TypeParameterTypeImpl parameterType = new TypeParameterTypeImpl(
2092 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"))); 2092 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")));
2093 FunctionType result = functionType 2093 FunctionType result = functionType
2094 .substitute2(<DartType>[argumentType], <DartType>[parameterType]); 2094 .substitute2(<DartType>[argumentType], <DartType>[parameterType]);
2095 expect(result.returnType, returnType); 2095 expect(result.returnType, returnType);
2096 List<DartType> normalParameters = result.normalParameterTypes; 2096 List<DartType> normalParameters = result.normalParameterTypes;
2097 expect(normalParameters, hasLength(1)); 2097 expect(normalParameters, hasLength(1));
2098 expect(normalParameters[0], normalParameterType); 2098 expect(normalParameters[0], normalParameterType);
2099 List<DartType> optionalParameters = result.optionalParameterTypes; 2099 List<DartType> optionalParameters = result.optionalParameterTypes;
2100 expect(optionalParameters, hasLength(1)); 2100 expect(optionalParameters, hasLength(1));
(...skipping 2258 matching lines...) Expand 10 before | Expand all | Expand 10 after
4359 // Returns whatever type is passed to resolveToBound(). 4359 // Returns whatever type is passed to resolveToBound().
4360 expect(type.resolveToBound(VoidTypeImpl.instance), 4360 expect(type.resolveToBound(VoidTypeImpl.instance),
4361 same(VoidTypeImpl.instance)); 4361 same(VoidTypeImpl.instance));
4362 } 4362 }
4363 4363
4364 void test_substitute_equal() { 4364 void test_substitute_equal() {
4365 TypeParameterElementImpl element = 4365 TypeParameterElementImpl element =
4366 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")); 4366 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"));
4367 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); 4367 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
4368 InterfaceTypeImpl argument = new InterfaceTypeImpl( 4368 InterfaceTypeImpl argument = new InterfaceTypeImpl(
4369 new ClassElementImpl.forNode(AstFactory.identifier3("A"))); 4369 new ClassElementImpl_Class.forNode(AstFactory.identifier3("A")));
4370 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(element); 4370 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(element);
4371 expect(type.substitute2(<DartType>[argument], <DartType>[parameter]), 4371 expect(type.substitute2(<DartType>[argument], <DartType>[parameter]),
4372 same(argument)); 4372 same(argument));
4373 } 4373 }
4374 4374
4375 void test_substitute_notEqual() { 4375 void test_substitute_notEqual() {
4376 TypeParameterTypeImpl type = new TypeParameterTypeImpl( 4376 TypeParameterTypeImpl type = new TypeParameterTypeImpl(
4377 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"))); 4377 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")));
4378 InterfaceTypeImpl argument = new InterfaceTypeImpl( 4378 InterfaceTypeImpl argument = new InterfaceTypeImpl(
4379 new ClassElementImpl.forNode(AstFactory.identifier3("A"))); 4379 new ClassElementImpl_Class.forNode(AstFactory.identifier3("A")));
4380 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl( 4380 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(
4381 new TypeParameterElementImpl.forNode(AstFactory.identifier3("F"))); 4381 new TypeParameterElementImpl.forNode(AstFactory.identifier3("F")));
4382 expect(type.substitute2(<DartType>[argument], <DartType>[parameter]), 4382 expect(type.substitute2(<DartType>[argument], <DartType>[parameter]),
4383 same(type)); 4383 same(type));
4384 } 4384 }
4385 } 4385 }
4386 4386
4387 @reflectiveTest 4387 @reflectiveTest
4388 class VoidTypeImplTest extends EngineTestCase { 4388 class VoidTypeImplTest extends EngineTestCase {
4389 /** 4389 /**
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4428 } 4428 }
4429 4429
4430 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction 4430 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction
4431 extends InterfaceTypeImpl { 4431 extends InterfaceTypeImpl {
4432 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) 4432 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0)
4433 : super(arg0); 4433 : super(arg0);
4434 4434
4435 @override 4435 @override
4436 bool get isDartCoreFunction => true; 4436 bool get isDartCoreFunction => true;
4437 } 4437 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698