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

Side by Side Diff: pkg/analyzer/test/generated/element_test.dart

Issue 987263002: Implement 'node' for ClassElement and FieldElement for enums. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_handle.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.element_test; 8 library engine.element_test;
9 9
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart' 12 import 'package:analyzer/src/generated/engine.dart'
13 show AnalysisContext, AnalysisContextImpl; 13 show AnalysisContext, AnalysisContextImpl;
14 import 'package:analyzer/src/generated/java_core.dart'; 14 import 'package:analyzer/src/generated/java_core.dart';
15 import 'package:analyzer/src/generated/source_io.dart'; 15 import 'package:analyzer/src/generated/source_io.dart';
16 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 16 import 'package:analyzer/src/generated/testing/ast_factory.dart';
17 import 'package:analyzer/src/generated/testing/element_factory.dart'; 17 import 'package:analyzer/src/generated/testing/element_factory.dart';
18 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; 18 import 'package:analyzer/src/generated/testing/test_type_provider.dart';
19 import 'package:unittest/unittest.dart'; 19 import 'package:unittest/unittest.dart';
20 20
21 import '../reflective_tests.dart'; 21 import '../reflective_tests.dart';
22 import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper; 22 import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper;
23 import 'test_support.dart'; 23 import 'test_support.dart';
24 24
25 main() { 25 main() {
26 groupSep = ' | '; 26 groupSep = ' | ';
27 runReflectiveTests(ElementKindTest); 27 runReflectiveTests(ElementKindTest);
28 runReflectiveTests(FieldElementImplTest);
28 runReflectiveTests(FunctionTypeImplTest); 29 runReflectiveTests(FunctionTypeImplTest);
29 runReflectiveTests(InterfaceTypeImplTest); 30 runReflectiveTests(InterfaceTypeImplTest);
30 runReflectiveTests(TypeParameterTypeImplTest); 31 runReflectiveTests(TypeParameterTypeImplTest);
31 runReflectiveTests(UnionTypeImplTest); 32 runReflectiveTests(UnionTypeImplTest);
32 runReflectiveTests(VoidTypeImplTest); 33 runReflectiveTests(VoidTypeImplTest);
33 runReflectiveTests(ClassElementImplTest); 34 runReflectiveTests(ClassElementImplTest);
34 runReflectiveTests(CompilationUnitElementImplTest); 35 runReflectiveTests(CompilationUnitElementImplTest);
35 runReflectiveTests(ElementLocationImplTest); 36 runReflectiveTests(ElementLocationImplTest);
36 runReflectiveTests(ElementImplTest); 37 runReflectiveTests(ElementImplTest);
37 runReflectiveTests(HtmlElementImplTest); 38 runReflectiveTests(HtmlElementImplTest);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 107 }
107 108
108 void test_getMethod_undeclared() { 109 void test_getMethod_undeclared() {
109 ClassElementImpl classA = ElementFactory.classElement2("A"); 110 ClassElementImpl classA = ElementFactory.classElement2("A");
110 String methodName = "m"; 111 String methodName = "m";
111 MethodElement method = ElementFactory.methodElement(methodName, null); 112 MethodElement method = ElementFactory.methodElement(methodName, null);
112 classA.methods = <MethodElement>[method]; 113 classA.methods = <MethodElement>[method];
113 expect(classA.getMethod("${methodName}x"), isNull); 114 expect(classA.getMethod("${methodName}x"), isNull);
114 } 115 }
115 116
116 void test_getNode() {
117 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
118 AnalysisContext context = contextHelper.context;
119 Source source = contextHelper.addSource("/test.dart", r'''
120 class A {}
121 class B {}''');
122 // prepare CompilationUnitElement
123 LibraryElement libraryElement = context.computeLibraryElement(source);
124 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
125 // A
126 {
127 ClassElement elementA = unitElement.getType("A");
128 ClassDeclaration nodeA = elementA.node;
129 expect(nodeA, isNotNull);
130 expect(nodeA.name.name, "A");
131 expect(nodeA.element, same(elementA));
132 }
133 // B
134 {
135 ClassElement elementB = unitElement.getType("B");
136 ClassDeclaration nodeB = elementB.node;
137 expect(nodeB, isNotNull);
138 expect(nodeB.name.name, "B");
139 expect(nodeB.element, same(elementB));
140 }
141 }
142
143 void test_hasNonFinalField_false_const() { 117 void test_hasNonFinalField_false_const() {
144 ClassElementImpl classA = ElementFactory.classElement2("A"); 118 ClassElementImpl classA = ElementFactory.classElement2("A");
145 classA.fields = <FieldElement>[ 119 classA.fields = <FieldElement>[
146 ElementFactory.fieldElement("f", false, false, true, classA.type) 120 ElementFactory.fieldElement("f", false, false, true, classA.type)
147 ]; 121 ];
148 expect(classA.hasNonFinalField, isFalse); 122 expect(classA.hasNonFinalField, isFalse);
149 } 123 }
150 124
151 void test_hasNonFinalField_false_final() { 125 void test_hasNonFinalField_false_final() {
152 ClassElementImpl classA = ElementFactory.classElement2("A"); 126 ClassElementImpl classA = ElementFactory.classElement2("A");
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 // } 850 // }
877 LibraryElementImpl library = 851 LibraryElementImpl library =
878 ElementFactory.library(createAnalysisContext(), "lib"); 852 ElementFactory.library(createAnalysisContext(), "lib");
879 ClassElementImpl classA = ElementFactory.classElement2("A"); 853 ClassElementImpl classA = ElementFactory.classElement2("A");
880 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); 854 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
881 classA.supertype = classB.type; 855 classA.supertype = classB.type;
882 (library.definingCompilationUnit as CompilationUnitElementImpl).types = 856 (library.definingCompilationUnit as CompilationUnitElementImpl).types =
883 <ClassElement>[classA, classB]; 857 <ClassElement>[classA, classB];
884 expect(classA.lookUpSetter("s", library), isNull); 858 expect(classA.lookUpSetter("s", library), isNull);
885 } 859 }
860
861 void test_node() {
862 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
863 AnalysisContext context = contextHelper.context;
864 Source source = contextHelper.addSource("/test.dart", r'''
865 class A {}
866 class B {}
867 enum C {C1, C2, C3}''');
868 // prepare CompilationUnitElement
869 LibraryElement libraryElement = context.computeLibraryElement(source);
870 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
871 // A
872 {
873 ClassElement elementA = unitElement.getType("A");
874 ClassDeclaration nodeA = elementA.node;
875 expect(nodeA, isNotNull);
876 expect(nodeA.name.name, "A");
877 expect(nodeA.element, same(elementA));
878 }
879 // B
880 {
881 ClassElement elementB = unitElement.getType("B");
882 ClassDeclaration nodeB = elementB.node;
883 expect(nodeB, isNotNull);
884 expect(nodeB.name.name, "B");
885 expect(nodeB.element, same(elementB));
886 }
887 // C
888 {
889 ClassElement elementC = unitElement.getEnum("C");
890 EnumDeclaration nodeC = elementC.node;
891 expect(nodeC, isNotNull);
892 expect(nodeC.name.name, "C");
893 expect(nodeC.element, same(elementC));
894 }
895 }
886 } 896 }
887 897
898
888 @reflectiveTest 899 @reflectiveTest
889 class CompilationUnitElementImplTest extends EngineTestCase { 900 class CompilationUnitElementImplTest extends EngineTestCase {
890 void test_getEnum_declared() { 901 void test_getEnum_declared() {
891 TestTypeProvider typeProvider = new TestTypeProvider(); 902 TestTypeProvider typeProvider = new TestTypeProvider();
892 CompilationUnitElementImpl unit = 903 CompilationUnitElementImpl unit =
893 ElementFactory.compilationUnit("/lib.dart"); 904 ElementFactory.compilationUnit("/lib.dart");
894 String enumName = "E"; 905 String enumName = "E";
895 ClassElement enumElement = 906 ClassElement enumElement =
896 ElementFactory.enumElement(typeProvider, enumName); 907 ElementFactory.enumElement(typeProvider, enumName);
897 unit.enums = <ClassElement>[enumElement]; 908 unit.enums = <ClassElement>[enumElement];
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 1106
1096 void test_hashCode_equal() { 1107 void test_hashCode_equal() {
1097 String encoding = "a;b;c"; 1108 String encoding = "a;b;c";
1098 ElementLocationImpl first = new ElementLocationImpl.con2(encoding); 1109 ElementLocationImpl first = new ElementLocationImpl.con2(encoding);
1099 ElementLocationImpl second = new ElementLocationImpl.con2(encoding); 1110 ElementLocationImpl second = new ElementLocationImpl.con2(encoding);
1100 expect(first.hashCode == second.hashCode, isTrue); 1111 expect(first.hashCode == second.hashCode, isTrue);
1101 } 1112 }
1102 } 1113 }
1103 1114
1104 @reflectiveTest 1115 @reflectiveTest
1116 class FieldElementImplTest extends EngineTestCase {
1117 void test_node() {
1118 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
1119 AnalysisContext context = contextHelper.context;
1120 Source source = contextHelper.addSource("/test.dart", r'''
1121 class A {
1122 int a;
1123 }
1124 enum B {B1, B2, B3}''');
1125 // prepare CompilationUnitElement
1126 LibraryElement libraryElement = context.computeLibraryElement(source);
1127 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
1128 // A
1129 {
1130 FieldElement elementA = unitElement.getType("A").getField('a');
1131 VariableDeclaration nodeA = elementA.node;
1132 expect(nodeA, isNotNull);
1133 expect(nodeA.name.name, "a");
1134 expect(nodeA.element, same(elementA));
1135 }
1136 // B
1137 {
1138 FieldElement elementB = unitElement.getEnum("B").getField('B2');
1139 EnumConstantDeclaration nodeB = elementB.node;
1140 expect(nodeB, isNotNull);
1141 expect(nodeB.name.name, "B2");
1142 expect(nodeB.element, same(elementB));
1143 }
1144 }
1145 }
1146
1147 @reflectiveTest
1105 class FunctionTypeImplTest extends EngineTestCase { 1148 class FunctionTypeImplTest extends EngineTestCase {
1106 void test_creation() { 1149 void test_creation() {
1107 expect(new FunctionTypeImpl.con1( 1150 expect(new FunctionTypeImpl.con1(
1108 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))), 1151 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))),
1109 isNotNull); 1152 isNotNull);
1110 } 1153 }
1111 1154
1112 void test_getElement() { 1155 void test_getElement() {
1113 FunctionElementImpl typeElement = 1156 FunctionElementImpl typeElement =
1114 new FunctionElementImpl.forNode(AstFactory.identifier3("f")); 1157 new FunctionElementImpl.forNode(AstFactory.identifier3("f"));
(...skipping 2814 matching lines...) Expand 10 before | Expand all | Expand 10 after
3929 } 3972 }
3930 3973
3931 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction 3974 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction
3932 extends InterfaceTypeImpl { 3975 extends InterfaceTypeImpl {
3933 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) 3976 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0)
3934 : super.con1(arg0); 3977 : super.con1(arg0);
3935 3978
3936 @override 3979 @override
3937 bool get isDartCoreFunction => true; 3980 bool get isDartCoreFunction => true;
3938 } 3981 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_handle.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698