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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_handle.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/element_test.dart
diff --git a/pkg/analyzer/test/generated/element_test.dart b/pkg/analyzer/test/generated/element_test.dart
index f94b44a512e9e875b9dc6d30f694c1a248584e80..9d608ee946ce0449d628e6b7c682cff97925266f 100644
--- a/pkg/analyzer/test/generated/element_test.dart
+++ b/pkg/analyzer/test/generated/element_test.dart
@@ -25,6 +25,7 @@ import 'test_support.dart';
main() {
groupSep = ' | ';
runReflectiveTests(ElementKindTest);
+ runReflectiveTests(FieldElementImplTest);
runReflectiveTests(FunctionTypeImplTest);
runReflectiveTests(InterfaceTypeImplTest);
runReflectiveTests(TypeParameterTypeImplTest);
@@ -113,33 +114,6 @@ class ClassElementImplTest extends EngineTestCase {
expect(classA.getMethod("${methodName}x"), isNull);
}
- void test_getNode() {
- AnalysisContextHelper contextHelper = new AnalysisContextHelper();
- AnalysisContext context = contextHelper.context;
- Source source = contextHelper.addSource("/test.dart", r'''
-class A {}
-class B {}''');
- // prepare CompilationUnitElement
- LibraryElement libraryElement = context.computeLibraryElement(source);
- CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
- // A
- {
- ClassElement elementA = unitElement.getType("A");
- ClassDeclaration nodeA = elementA.node;
- expect(nodeA, isNotNull);
- expect(nodeA.name.name, "A");
- expect(nodeA.element, same(elementA));
- }
- // B
- {
- ClassElement elementB = unitElement.getType("B");
- ClassDeclaration nodeB = elementB.node;
- expect(nodeB, isNotNull);
- expect(nodeB.name.name, "B");
- expect(nodeB.element, same(elementB));
- }
- }
-
void test_hasNonFinalField_false_const() {
ClassElementImpl classA = ElementFactory.classElement2("A");
classA.fields = <FieldElement>[
@@ -883,8 +857,45 @@ class B {}''');
<ClassElement>[classA, classB];
expect(classA.lookUpSetter("s", library), isNull);
}
+
+ void test_node() {
+ AnalysisContextHelper contextHelper = new AnalysisContextHelper();
+ AnalysisContext context = contextHelper.context;
+ Source source = contextHelper.addSource("/test.dart", r'''
+class A {}
+class B {}
+enum C {C1, C2, C3}''');
+ // prepare CompilationUnitElement
+ LibraryElement libraryElement = context.computeLibraryElement(source);
+ CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
+ // A
+ {
+ ClassElement elementA = unitElement.getType("A");
+ ClassDeclaration nodeA = elementA.node;
+ expect(nodeA, isNotNull);
+ expect(nodeA.name.name, "A");
+ expect(nodeA.element, same(elementA));
+ }
+ // B
+ {
+ ClassElement elementB = unitElement.getType("B");
+ ClassDeclaration nodeB = elementB.node;
+ expect(nodeB, isNotNull);
+ expect(nodeB.name.name, "B");
+ expect(nodeB.element, same(elementB));
+ }
+ // C
+ {
+ ClassElement elementC = unitElement.getEnum("C");
+ EnumDeclaration nodeC = elementC.node;
+ expect(nodeC, isNotNull);
+ expect(nodeC.name.name, "C");
+ expect(nodeC.element, same(elementC));
+ }
+ }
}
+
@reflectiveTest
class CompilationUnitElementImplTest extends EngineTestCase {
void test_getEnum_declared() {
@@ -1102,6 +1113,38 @@ class ElementLocationImplTest extends EngineTestCase {
}
@reflectiveTest
+class FieldElementImplTest extends EngineTestCase {
+ void test_node() {
+ AnalysisContextHelper contextHelper = new AnalysisContextHelper();
+ AnalysisContext context = contextHelper.context;
+ Source source = contextHelper.addSource("/test.dart", r'''
+class A {
+ int a;
+}
+enum B {B1, B2, B3}''');
+ // prepare CompilationUnitElement
+ LibraryElement libraryElement = context.computeLibraryElement(source);
+ CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
+ // A
+ {
+ FieldElement elementA = unitElement.getType("A").getField('a');
+ VariableDeclaration nodeA = elementA.node;
+ expect(nodeA, isNotNull);
+ expect(nodeA.name.name, "a");
+ expect(nodeA.element, same(elementA));
+ }
+ // B
+ {
+ FieldElement elementB = unitElement.getEnum("B").getField('B2');
+ EnumConstantDeclaration nodeB = elementB.node;
+ expect(nodeB, isNotNull);
+ expect(nodeB.name.name, "B2");
+ expect(nodeB.element, same(elementB));
+ }
+ }
+}
+
+@reflectiveTest
class FunctionTypeImplTest extends EngineTestCase {
void test_creation() {
expect(new FunctionTypeImpl.con1(
« 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