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

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

Issue 1007563003: fix for getting node for class element (Closed) Base URL: http://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.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';
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 LibraryElementImpl library = 851 LibraryElementImpl library =
852 ElementFactory.library(createAnalysisContext(), "lib"); 852 ElementFactory.library(createAnalysisContext(), "lib");
853 ClassElementImpl classA = ElementFactory.classElement2("A"); 853 ClassElementImpl classA = ElementFactory.classElement2("A");
854 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); 854 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
855 classA.supertype = classB.type; 855 classA.supertype = classB.type;
856 (library.definingCompilationUnit as CompilationUnitElementImpl).types = 856 (library.definingCompilationUnit as CompilationUnitElementImpl).types =
857 <ClassElement>[classA, classB]; 857 <ClassElement>[classA, classB];
858 expect(classA.lookUpSetter("s", library), isNull); 858 expect(classA.lookUpSetter("s", library), isNull);
859 } 859 }
860 860
861 void test_node() { 861 void test_node_ClassDeclaration() {
862 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); 862 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
863 AnalysisContext context = contextHelper.context; 863 AnalysisContext context = contextHelper.context;
864 Source source = contextHelper.addSource("/test.dart", r''' 864 Source source = contextHelper.addSource("/test.dart", r'''
865 class A {} 865 class A {}
866 class B {} 866 class B {}
867 enum C {C1, C2, C3}'''); 867 enum C {C1, C2, C3}''');
868 // prepare CompilationUnitElement 868 // prepare CompilationUnitElement
869 LibraryElement libraryElement = context.computeLibraryElement(source); 869 LibraryElement libraryElement = context.computeLibraryElement(source);
870 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; 870 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
871 // A 871 // A
(...skipping 14 matching lines...) Expand all
886 } 886 }
887 // C 887 // C
888 { 888 {
889 ClassElement elementC = unitElement.getEnum("C"); 889 ClassElement elementC = unitElement.getEnum("C");
890 EnumDeclaration nodeC = elementC.node; 890 EnumDeclaration nodeC = elementC.node;
891 expect(nodeC, isNotNull); 891 expect(nodeC, isNotNull);
892 expect(nodeC.name.name, "C"); 892 expect(nodeC.name.name, "C");
893 expect(nodeC.element, same(elementC)); 893 expect(nodeC.element, same(elementC));
894 } 894 }
895 } 895 }
896
897 void test_node_ClassTypeAlias() {
898 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
899 AnalysisContext context = contextHelper.context;
900 Source source = contextHelper.addSource("/test.dart", r'''
901 abstract class A<K, V> = Object with MapMixin<K, V>;
902 ''');
903 // prepare CompilationUnitElement
904 LibraryElement libraryElement = context.computeLibraryElement(source);
905 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit;
906 // A
907 {
908 ClassElement elementA = unitElement.getType("A");
909 ClassTypeAlias nodeA = elementA.node;
910 expect(nodeA, isNotNull);
911 expect(nodeA.name.name, "A");
912 expect(nodeA.element, same(elementA));
913 }
914 }
896 } 915 }
897 916
898
899 @reflectiveTest 917 @reflectiveTest
900 class CompilationUnitElementImplTest extends EngineTestCase { 918 class CompilationUnitElementImplTest extends EngineTestCase {
901 void test_getEnum_declared() { 919 void test_getEnum_declared() {
902 TestTypeProvider typeProvider = new TestTypeProvider(); 920 TestTypeProvider typeProvider = new TestTypeProvider();
903 CompilationUnitElementImpl unit = 921 CompilationUnitElementImpl unit =
904 ElementFactory.compilationUnit("/lib.dart"); 922 ElementFactory.compilationUnit("/lib.dart");
905 String enumName = "E"; 923 String enumName = "E";
906 ClassElement enumElement = 924 ClassElement enumElement =
907 ElementFactory.enumElement(typeProvider, enumName); 925 ElementFactory.enumElement(typeProvider, enumName);
908 unit.enums = <ClassElement>[enumElement]; 926 unit.enums = <ClassElement>[enumElement];
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 FunctionType t = ElementFactory.functionElement4( 1272 FunctionType t = ElementFactory.functionElement4(
1255 "t", null, null, <String>["name"], <ClassElement>[a]).type; 1273 "t", null, null, <String>["name"], <ClassElement>[a]).type;
1256 FunctionType s = ElementFactory.functionElement4( 1274 FunctionType s = ElementFactory.functionElement4(
1257 "s", null, null, <String>["name"], <ClassElement>[b]).type; 1275 "s", null, null, <String>["name"], <ClassElement>[b]).type;
1258 expect(t.isSubtypeOf(s), isTrue); 1276 expect(t.isSubtypeOf(s), isTrue);
1259 expect(s.isSubtypeOf(t), isTrue); 1277 expect(s.isSubtypeOf(t), isTrue);
1260 } 1278 }
1261 1279
1262 void test_isSubtypeOf_namedParameters_isNotAssignable() { 1280 void test_isSubtypeOf_namedParameters_isNotAssignable() {
1263 // ! ({name: A}) -> void <: ({name: B}) -> void 1281 // ! ({name: A}) -> void <: ({name: B}) -> void
1264 FunctionType t = ElementFactory.functionElement4("t", null, null, <String>[ 1282 FunctionType t = ElementFactory.functionElement4("t", null, null,
1265 "name" 1283 <String>["name"],
1266 ], <ClassElement>[ElementFactory.classElement2("A")]).type; 1284 <ClassElement>[ElementFactory.classElement2("A")]).type;
1267 FunctionType s = ElementFactory.functionElement4("s", null, null, <String>[ 1285 FunctionType s = ElementFactory.functionElement4("s", null, null,
1268 "name" 1286 <String>["name"],
1269 ], <ClassElement>[ElementFactory.classElement2("B")]).type; 1287 <ClassElement>[ElementFactory.classElement2("B")]).type;
1270 expect(t.isSubtypeOf(s), isFalse); 1288 expect(t.isSubtypeOf(s), isFalse);
1271 } 1289 }
1272 1290
1273 void test_isSubtypeOf_namedParameters_namesDifferent() { 1291 void test_isSubtypeOf_namedParameters_namesDifferent() {
1274 // B extends A 1292 // B extends A
1275 // void t({A name}) {} 1293 // void t({A name}) {}
1276 // void s({A diff}) {} 1294 // void s({A diff}) {}
1277 // ! t <: s 1295 // ! t <: s
1278 // ! s <: t 1296 // ! s <: t
1279 ClassElement a = ElementFactory.classElement2("A"); 1297 ClassElement a = ElementFactory.classElement2("A");
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after
3462 ElementFactory.compilationUnit("unit_b.dart"); 3480 ElementFactory.compilationUnit("unit_b.dart");
3463 library.parts = <CompilationUnitElement>[unitA, unitB]; 3481 library.parts = <CompilationUnitElement>[unitA, unitB];
3464 expect(library.units, 3482 expect(library.units,
3465 unorderedEquals(<CompilationUnitElement>[unitLib, unitA, unitB])); 3483 unorderedEquals(<CompilationUnitElement>[unitLib, unitA, unitB]));
3466 } 3484 }
3467 3485
3468 void test_getVisibleLibraries_cycle() { 3486 void test_getVisibleLibraries_cycle() {
3469 AnalysisContext context = createAnalysisContext(); 3487 AnalysisContext context = createAnalysisContext();
3470 LibraryElementImpl library = ElementFactory.library(context, "app"); 3488 LibraryElementImpl library = ElementFactory.library(context, "app");
3471 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); 3489 LibraryElementImpl libraryA = ElementFactory.library(context, "A");
3472 libraryA.imports = <ImportElementImpl>[ 3490 libraryA.imports =
3473 ElementFactory.importFor(library, null) 3491 <ImportElementImpl>[ElementFactory.importFor(library, null)];
3474 ]; 3492 library.imports =
3475 library.imports = <ImportElementImpl>[ 3493 <ImportElementImpl>[ElementFactory.importFor(libraryA, null)];
3476 ElementFactory.importFor(libraryA, null)
3477 ];
3478 List<LibraryElement> libraries = library.visibleLibraries; 3494 List<LibraryElement> libraries = library.visibleLibraries;
3479 expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA])); 3495 expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA]));
3480 } 3496 }
3481 3497
3482 void test_getVisibleLibraries_directExports() { 3498 void test_getVisibleLibraries_directExports() {
3483 AnalysisContext context = createAnalysisContext(); 3499 AnalysisContext context = createAnalysisContext();
3484 LibraryElementImpl library = ElementFactory.library(context, "app"); 3500 LibraryElementImpl library = ElementFactory.library(context, "app");
3485 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); 3501 LibraryElementImpl libraryA = ElementFactory.library(context, "A");
3486 library.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryA)]; 3502 library.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryA)];
3487 List<LibraryElement> libraries = library.visibleLibraries; 3503 List<LibraryElement> libraries = library.visibleLibraries;
3488 expect(libraries, unorderedEquals(<LibraryElement>[library])); 3504 expect(libraries, unorderedEquals(<LibraryElement>[library]));
3489 } 3505 }
3490 3506
3491 void test_getVisibleLibraries_directImports() { 3507 void test_getVisibleLibraries_directImports() {
3492 AnalysisContext context = createAnalysisContext(); 3508 AnalysisContext context = createAnalysisContext();
3493 LibraryElementImpl library = ElementFactory.library(context, "app"); 3509 LibraryElementImpl library = ElementFactory.library(context, "app");
3494 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); 3510 LibraryElementImpl libraryA = ElementFactory.library(context, "A");
3495 library.imports = <ImportElementImpl>[ 3511 library.imports =
3496 ElementFactory.importFor(libraryA, null) 3512 <ImportElementImpl>[ElementFactory.importFor(libraryA, null)];
3497 ];
3498 List<LibraryElement> libraries = library.visibleLibraries; 3513 List<LibraryElement> libraries = library.visibleLibraries;
3499 expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA])); 3514 expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA]));
3500 } 3515 }
3501 3516
3502 void test_getVisibleLibraries_indirectExports() { 3517 void test_getVisibleLibraries_indirectExports() {
3503 AnalysisContext context = createAnalysisContext(); 3518 AnalysisContext context = createAnalysisContext();
3504 LibraryElementImpl library = ElementFactory.library(context, "app"); 3519 LibraryElementImpl library = ElementFactory.library(context, "app");
3505 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); 3520 LibraryElementImpl libraryA = ElementFactory.library(context, "A");
3506 LibraryElementImpl libraryAA = ElementFactory.library(context, "AA"); 3521 LibraryElementImpl libraryAA = ElementFactory.library(context, "AA");
3507 libraryA.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryAA)]; 3522 libraryA.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryAA)];
3508 library.imports = <ImportElementImpl>[ 3523 library.imports =
3509 ElementFactory.importFor(libraryA, null) 3524 <ImportElementImpl>[ElementFactory.importFor(libraryA, null)];
3510 ];
3511 List<LibraryElement> libraries = library.visibleLibraries; 3525 List<LibraryElement> libraries = library.visibleLibraries;
3512 expect(libraries, 3526 expect(libraries,
3513 unorderedEquals(<LibraryElement>[library, libraryA, libraryAA])); 3527 unorderedEquals(<LibraryElement>[library, libraryA, libraryAA]));
3514 } 3528 }
3515 3529
3516 void test_getVisibleLibraries_indirectImports() { 3530 void test_getVisibleLibraries_indirectImports() {
3517 AnalysisContext context = createAnalysisContext(); 3531 AnalysisContext context = createAnalysisContext();
3518 LibraryElementImpl library = ElementFactory.library(context, "app"); 3532 LibraryElementImpl library = ElementFactory.library(context, "app");
3519 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); 3533 LibraryElementImpl libraryA = ElementFactory.library(context, "A");
3520 LibraryElementImpl libraryAA = ElementFactory.library(context, "AA"); 3534 LibraryElementImpl libraryAA = ElementFactory.library(context, "AA");
3521 LibraryElementImpl libraryB = ElementFactory.library(context, "B"); 3535 LibraryElementImpl libraryB = ElementFactory.library(context, "B");
3522 libraryA.imports = <ImportElementImpl>[ 3536 libraryA.imports =
3523 ElementFactory.importFor(libraryAA, null) 3537 <ImportElementImpl>[ElementFactory.importFor(libraryAA, null)];
3524 ];
3525 library.imports = <ImportElementImpl>[ 3538 library.imports = <ImportElementImpl>[
3526 ElementFactory.importFor(libraryA, null), 3539 ElementFactory.importFor(libraryA, null),
3527 ElementFactory.importFor(libraryB, null) 3540 ElementFactory.importFor(libraryB, null)
3528 ]; 3541 ];
3529 List<LibraryElement> libraries = library.visibleLibraries; 3542 List<LibraryElement> libraries = library.visibleLibraries;
3530 expect(libraries, unorderedEquals( 3543 expect(libraries, unorderedEquals(
3531 <LibraryElement>[library, libraryA, libraryAA, libraryB])); 3544 <LibraryElement>[library, libraryA, libraryAA, libraryB]));
3532 } 3545 }
3533 3546
3534 void test_getVisibleLibraries_noImports() { 3547 void test_getVisibleLibraries_noImports() {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
3972 } 3985 }
3973 3986
3974 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction 3987 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction
3975 extends InterfaceTypeImpl { 3988 extends InterfaceTypeImpl {
3976 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) 3989 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0)
3977 : super.con1(arg0); 3990 : super.con1(arg0);
3978 3991
3979 @override 3992 @override
3980 bool get isDartCoreFunction => true; 3993 bool get isDartCoreFunction => true;
3981 } 3994 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698