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

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

Issue 1125123006: Add a "librarySource" field to CompilationUnitElementImpl. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 context.sourceFactory = sourceFactory; 111 context.sourceFactory = sourceFactory;
112 AnalysisContext coreContext = sdk.context; 112 AnalysisContext coreContext = sdk.context;
113 // 113 //
114 // dart:core 114 // dart:core
115 // 115 //
116 TestTypeProvider provider = new TestTypeProvider(); 116 TestTypeProvider provider = new TestTypeProvider();
117 CompilationUnitElementImpl coreUnit = 117 CompilationUnitElementImpl coreUnit =
118 new CompilationUnitElementImpl("core.dart"); 118 new CompilationUnitElementImpl("core.dart");
119 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); 119 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE);
120 coreContext.setContents(coreSource, ""); 120 coreContext.setContents(coreSource, "");
121 coreUnit.source = coreSource; 121 coreUnit.librarySource = coreUnit.source = coreSource;
122 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy"); 122 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy");
123 coreUnit.types = <ClassElement>[ 123 coreUnit.types = <ClassElement>[
124 provider.boolType.element, 124 provider.boolType.element,
125 provider.deprecatedType.element, 125 provider.deprecatedType.element,
126 provider.doubleType.element, 126 provider.doubleType.element,
127 provider.functionType.element, 127 provider.functionType.element,
128 provider.intType.element, 128 provider.intType.element,
129 provider.iterableType.element, 129 provider.iterableType.element,
130 provider.iteratorType.element, 130 provider.iteratorType.element,
131 provider.listType.element, 131 provider.listType.element,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( 164 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode(
165 coreContext, AstFactory.libraryIdentifier2(["dart", "core"])); 165 coreContext, AstFactory.libraryIdentifier2(["dart", "core"]));
166 coreLibrary.definingCompilationUnit = coreUnit; 166 coreLibrary.definingCompilationUnit = coreUnit;
167 // 167 //
168 // dart:async 168 // dart:async
169 // 169 //
170 CompilationUnitElementImpl asyncUnit = 170 CompilationUnitElementImpl asyncUnit =
171 new CompilationUnitElementImpl("async.dart"); 171 new CompilationUnitElementImpl("async.dart");
172 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); 172 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
173 coreContext.setContents(asyncSource, ""); 173 coreContext.setContents(asyncSource, "");
174 asyncUnit.source = asyncSource; 174 asyncUnit.librarySource = asyncUnit.source = asyncSource;
175 // Future 175 // Future
176 ClassElementImpl futureElement = 176 ClassElementImpl futureElement =
177 ElementFactory.classElement2("Future", ["T"]); 177 ElementFactory.classElement2("Future", ["T"]);
178 InterfaceType futureType = futureElement.type; 178 InterfaceType futureType = futureElement.type;
179 // factory Future.value([value]) 179 // factory Future.value([value])
180 ConstructorElementImpl futureConstructor = 180 ConstructorElementImpl futureConstructor =
181 ElementFactory.constructorElement2(futureElement, "value"); 181 ElementFactory.constructorElement2(futureElement, "value");
182 futureConstructor.parameters = <ParameterElement>[ 182 futureConstructor.parameters = <ParameterElement>[
183 ElementFactory.positionalParameter2("value", provider.dynamicType) 183 ElementFactory.positionalParameter2("value", provider.dynamicType)
184 ]; 184 ];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( 222 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode(
223 coreContext, AstFactory.libraryIdentifier2(["dart", "async"])); 223 coreContext, AstFactory.libraryIdentifier2(["dart", "async"]));
224 asyncLibrary.definingCompilationUnit = asyncUnit; 224 asyncLibrary.definingCompilationUnit = asyncUnit;
225 // 225 //
226 // dart:html 226 // dart:html
227 // 227 //
228 CompilationUnitElementImpl htmlUnit = 228 CompilationUnitElementImpl htmlUnit =
229 new CompilationUnitElementImpl("html_dartium.dart"); 229 new CompilationUnitElementImpl("html_dartium.dart");
230 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 230 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
231 coreContext.setContents(htmlSource, ""); 231 coreContext.setContents(htmlSource, "");
232 htmlUnit.source = htmlSource; 232 htmlUnit.librarySource = htmlUnit.source = htmlSource;
233 ClassElementImpl elementElement = ElementFactory.classElement2("Element"); 233 ClassElementImpl elementElement = ElementFactory.classElement2("Element");
234 InterfaceType elementType = elementElement.type; 234 InterfaceType elementType = elementElement.type;
235 ClassElementImpl canvasElement = 235 ClassElementImpl canvasElement =
236 ElementFactory.classElement("CanvasElement", elementType); 236 ElementFactory.classElement("CanvasElement", elementType);
237 ClassElementImpl contextElement = 237 ClassElementImpl contextElement =
238 ElementFactory.classElement2("CanvasRenderingContext"); 238 ElementFactory.classElement2("CanvasRenderingContext");
239 InterfaceType contextElementType = contextElement.type; 239 InterfaceType contextElementType = contextElement.type;
240 ClassElementImpl context2dElement = ElementFactory.classElement( 240 ClassElementImpl context2dElement = ElementFactory.classElement(
241 "CanvasRenderingContext2D", contextElementType); 241 "CanvasRenderingContext2D", contextElementType);
242 canvasElement.methods = <MethodElement>[ 242 canvasElement.methods = <MethodElement>[
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode( 283 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(
284 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); 284 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"]));
285 htmlLibrary.definingCompilationUnit = htmlUnit; 285 htmlLibrary.definingCompilationUnit = htmlUnit;
286 // 286 //
287 // dart:math 287 // dart:math
288 // 288 //
289 CompilationUnitElementImpl mathUnit = 289 CompilationUnitElementImpl mathUnit =
290 new CompilationUnitElementImpl("math.dart"); 290 new CompilationUnitElementImpl("math.dart");
291 Source mathSource = sourceFactory.forUri(_DART_MATH); 291 Source mathSource = sourceFactory.forUri(_DART_MATH);
292 coreContext.setContents(mathSource, ""); 292 coreContext.setContents(mathSource, "");
293 mathUnit.source = mathSource; 293 mathUnit.librarySource = mathUnit.source = mathSource;
294 FunctionElement cosElement = ElementFactory.functionElement3("cos", 294 FunctionElement cosElement = ElementFactory.functionElement3("cos",
295 provider.doubleType.element, <ClassElement>[provider.numType.element], 295 provider.doubleType.element, <ClassElement>[provider.numType.element],
296 ClassElement.EMPTY_LIST); 296 ClassElement.EMPTY_LIST);
297 TopLevelVariableElement ln10Element = ElementFactory 297 TopLevelVariableElement ln10Element = ElementFactory
298 .topLevelVariableElement3("LN10", true, false, provider.doubleType); 298 .topLevelVariableElement3("LN10", true, false, provider.doubleType);
299 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( 299 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3(
300 "PI", true, false, provider.doubleType); 300 "PI", true, false, provider.doubleType);
301 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); 301 ClassElementImpl randomElement = ElementFactory.classElement2("Random");
302 randomElement.abstract = true; 302 randomElement.abstract = true;
303 ConstructorElementImpl randomConstructor = 303 ConstructorElementImpl randomConstructor =
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 */ 1889 */
1890 ElementResolver _createResolver() { 1890 ElementResolver _createResolver() {
1891 AnalysisContextImpl context = new AnalysisContextImpl(); 1891 AnalysisContextImpl context = new AnalysisContextImpl();
1892 SourceFactory sourceFactory = new SourceFactory( 1892 SourceFactory sourceFactory = new SourceFactory(
1893 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]); 1893 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]);
1894 context.sourceFactory = sourceFactory; 1894 context.sourceFactory = sourceFactory;
1895 FileBasedSource source = 1895 FileBasedSource source =
1896 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); 1896 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
1897 CompilationUnitElementImpl definingCompilationUnit = 1897 CompilationUnitElementImpl definingCompilationUnit =
1898 new CompilationUnitElementImpl("test.dart"); 1898 new CompilationUnitElementImpl("test.dart");
1899 definingCompilationUnit.source = source; 1899 definingCompilationUnit.librarySource =
1900 definingCompilationUnit.source = source;
1900 _definingLibrary = ElementFactory.library(context, "test"); 1901 _definingLibrary = ElementFactory.library(context, "test");
1901 _definingLibrary.definingCompilationUnit = definingCompilationUnit; 1902 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
1902 Library library = new Library(context, _listener, source); 1903 Library library = new Library(context, _listener, source);
1903 library.libraryElement = _definingLibrary; 1904 library.libraryElement = _definingLibrary;
1904 _visitor = new ResolverVisitor.con1(library, source, _typeProvider); 1905 _visitor = new ResolverVisitor.con1(library, source, _typeProvider);
1905 try { 1906 try {
1906 return _visitor.elementResolver; 1907 return _visitor.elementResolver;
1907 } catch (exception) { 1908 } catch (exception) {
1908 throw new IllegalArgumentException( 1909 throw new IllegalArgumentException(
1909 "Could not create resolver", exception); 1910 "Could not create resolver", exception);
(...skipping 3796 matching lines...) Expand 10 before | Expand all | Expand 10 after
5706 * Create the inheritance manager used by the tests. 5707 * Create the inheritance manager used by the tests.
5707 * 5708 *
5708 * @return the inheritance manager that was created 5709 * @return the inheritance manager that was created
5709 */ 5710 */
5710 InheritanceManager _createInheritanceManager() { 5711 InheritanceManager _createInheritanceManager() {
5711 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore(); 5712 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore();
5712 FileBasedSource source = 5713 FileBasedSource source =
5713 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); 5714 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
5714 CompilationUnitElementImpl definingCompilationUnit = 5715 CompilationUnitElementImpl definingCompilationUnit =
5715 new CompilationUnitElementImpl("test.dart"); 5716 new CompilationUnitElementImpl("test.dart");
5716 definingCompilationUnit.source = source; 5717 definingCompilationUnit.librarySource =
5718 definingCompilationUnit.source = source;
5717 _definingLibrary = ElementFactory.library(context, "test"); 5719 _definingLibrary = ElementFactory.library(context, "test");
5718 _definingLibrary.definingCompilationUnit = definingCompilationUnit; 5720 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
5719 return new InheritanceManager(_definingLibrary); 5721 return new InheritanceManager(_definingLibrary);
5720 } 5722 }
5721 } 5723 }
5722 5724
5723 @reflectiveTest 5725 @reflectiveTest
5724 class LibraryElementBuilderTest extends EngineTestCase { 5726 class LibraryElementBuilderTest extends EngineTestCase {
5725 /** 5727 /**
5726 * The analysis context used to analyze sources. 5728 * The analysis context used to analyze sources.
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after
7772 7774
7773 /** 7775 /**
7774 * Create a library element that represents a library with the given name cont aining a single 7776 * Create a library element that represents a library with the given name cont aining a single
7775 * empty compilation unit. 7777 * empty compilation unit.
7776 * 7778 *
7777 * @param libraryName the name of the library to be created 7779 * @param libraryName the name of the library to be created
7778 * @return the library element that was created 7780 * @return the library element that was created
7779 */ 7781 */
7780 LibraryElementImpl createTestLibrary( 7782 LibraryElementImpl createTestLibrary(
7781 AnalysisContext context, String libraryName, [List<String> typeNames]) { 7783 AnalysisContext context, String libraryName, [List<String> typeNames]) {
7784 String fileName = "$libraryName.dart";
7785 FileBasedSource definingCompilationUnitSource =
7786 _createNamedSource(fileName);
7782 List<CompilationUnitElement> sourcedCompilationUnits; 7787 List<CompilationUnitElement> sourcedCompilationUnits;
7783 if (typeNames == null) { 7788 if (typeNames == null) {
7784 sourcedCompilationUnits = CompilationUnitElement.EMPTY_LIST; 7789 sourcedCompilationUnits = CompilationUnitElement.EMPTY_LIST;
7785 } else { 7790 } else {
7786 int count = typeNames.length; 7791 int count = typeNames.length;
7787 sourcedCompilationUnits = new List<CompilationUnitElement>(count); 7792 sourcedCompilationUnits = new List<CompilationUnitElement>(count);
7788 for (int i = 0; i < count; i++) { 7793 for (int i = 0; i < count; i++) {
7789 String typeName = typeNames[i]; 7794 String typeName = typeNames[i];
7790 ClassElementImpl type = 7795 ClassElementImpl type =
7791 new ClassElementImpl.forNode(AstFactory.identifier3(typeName)); 7796 new ClassElementImpl.forNode(AstFactory.identifier3(typeName));
7792 String fileName = "$typeName.dart"; 7797 String fileName = "$typeName.dart";
7793 CompilationUnitElementImpl compilationUnit = 7798 CompilationUnitElementImpl compilationUnit =
7794 new CompilationUnitElementImpl(fileName); 7799 new CompilationUnitElementImpl(fileName);
7795 compilationUnit.source = _createNamedSource(fileName); 7800 compilationUnit.source = _createNamedSource(fileName);
7801 compilationUnit.librarySource = definingCompilationUnitSource;
7796 compilationUnit.types = <ClassElement>[type]; 7802 compilationUnit.types = <ClassElement>[type];
7797 sourcedCompilationUnits[i] = compilationUnit; 7803 sourcedCompilationUnits[i] = compilationUnit;
7798 } 7804 }
7799 } 7805 }
7800 String fileName = "$libraryName.dart";
7801 CompilationUnitElementImpl compilationUnit = 7806 CompilationUnitElementImpl compilationUnit =
7802 new CompilationUnitElementImpl(fileName); 7807 new CompilationUnitElementImpl(fileName);
7803 compilationUnit.source = _createNamedSource(fileName); 7808 compilationUnit.librarySource =
7809 compilationUnit.source = definingCompilationUnitSource;
7804 LibraryElementImpl library = new LibraryElementImpl.forNode( 7810 LibraryElementImpl library = new LibraryElementImpl.forNode(
7805 context, AstFactory.libraryIdentifier2([libraryName])); 7811 context, AstFactory.libraryIdentifier2([libraryName]));
7806 library.definingCompilationUnit = compilationUnit; 7812 library.definingCompilationUnit = compilationUnit;
7807 library.parts = sourcedCompilationUnits; 7813 library.parts = sourcedCompilationUnits;
7808 return library; 7814 return library;
7809 } 7815 }
7810 7816
7811 Expression findTopLevelConstantExpression( 7817 Expression findTopLevelConstantExpression(
7812 CompilationUnit compilationUnit, String name) => 7818 CompilationUnit compilationUnit, String name) =>
7813 findTopLevelDeclaration(compilationUnit, name).initializer; 7819 findTopLevelDeclaration(compilationUnit, name).initializer;
(...skipping 3174 matching lines...) Expand 10 before | Expand all | Expand 10 after
10988 */ 10994 */
10989 StaticTypeAnalyzer _createAnalyzer() { 10995 StaticTypeAnalyzer _createAnalyzer() {
10990 AnalysisContextImpl context = new AnalysisContextImpl(); 10996 AnalysisContextImpl context = new AnalysisContextImpl();
10991 SourceFactory sourceFactory = new SourceFactory( 10997 SourceFactory sourceFactory = new SourceFactory(
10992 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]); 10998 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]);
10993 context.sourceFactory = sourceFactory; 10999 context.sourceFactory = sourceFactory;
10994 FileBasedSource source = 11000 FileBasedSource source =
10995 new FileBasedSource.con1(FileUtilities2.createFile("/lib.dart")); 11001 new FileBasedSource.con1(FileUtilities2.createFile("/lib.dart"));
10996 CompilationUnitElementImpl definingCompilationUnit = 11002 CompilationUnitElementImpl definingCompilationUnit =
10997 new CompilationUnitElementImpl("lib.dart"); 11003 new CompilationUnitElementImpl("lib.dart");
10998 definingCompilationUnit.source = source; 11004 definingCompilationUnit.librarySource =
11005 definingCompilationUnit.source = source;
10999 LibraryElementImpl definingLibrary = 11006 LibraryElementImpl definingLibrary =
11000 new LibraryElementImpl.forNode(context, null); 11007 new LibraryElementImpl.forNode(context, null);
11001 definingLibrary.definingCompilationUnit = definingCompilationUnit; 11008 definingLibrary.definingCompilationUnit = definingCompilationUnit;
11002 Library library = new Library(context, _listener, source); 11009 Library library = new Library(context, _listener, source);
11003 library.libraryElement = definingLibrary; 11010 library.libraryElement = definingLibrary;
11004 _visitor = new ResolverVisitor.con1(library, source, _typeProvider); 11011 _visitor = new ResolverVisitor.con1(library, source, _typeProvider);
11005 _visitor.overrideManager.enterScope(); 11012 _visitor.overrideManager.enterScope();
11006 try { 11013 try {
11007 return _visitor.typeAnalyzer; 11014 return _visitor.typeAnalyzer;
11008 } catch (exception) { 11015 } catch (exception) {
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
11491 */ 11498 */
11492 CompilationUnitElementImpl _definingCompilationUnit; 11499 CompilationUnitElementImpl _definingCompilationUnit;
11493 11500
11494 @override 11501 @override
11495 void setUp() { 11502 void setUp() {
11496 super.setUp(); 11503 super.setUp();
11497 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore(); 11504 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore();
11498 FileBasedSource source = 11505 FileBasedSource source =
11499 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); 11506 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
11500 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart"); 11507 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart");
11501 _definingCompilationUnit.source = source; 11508 _definingCompilationUnit.librarySource =
11509 _definingCompilationUnit.source = source;
11502 LibraryElementImpl definingLibrary = 11510 LibraryElementImpl definingLibrary =
11503 ElementFactory.library(context, "test"); 11511 ElementFactory.library(context, "test");
11504 definingLibrary.definingCompilationUnit = _definingCompilationUnit; 11512 definingLibrary.definingCompilationUnit = _definingCompilationUnit;
11505 _subtypeManager = new SubtypeManager(); 11513 _subtypeManager = new SubtypeManager();
11506 } 11514 }
11507 11515
11508 void test_computeAllSubtypes_infiniteLoop() { 11516 void test_computeAllSubtypes_infiniteLoop() {
11509 // 11517 //
11510 // class A extends B 11518 // class A extends B
11511 // class B extends A 11519 // class B extends A
(...skipping 2276 matching lines...) Expand 10 before | Expand all | Expand 10 after
13788 // check propagated type 13796 // check propagated type
13789 FunctionType propagatedType = node.propagatedType as FunctionType; 13797 FunctionType propagatedType = node.propagatedType as FunctionType;
13790 expect(propagatedType.returnType, test.typeProvider.stringType); 13798 expect(propagatedType.returnType, test.typeProvider.stringType);
13791 } on AnalysisException catch (e, stackTrace) { 13799 } on AnalysisException catch (e, stackTrace) {
13792 thrownException[0] = new CaughtException(e, stackTrace); 13800 thrownException[0] = new CaughtException(e, stackTrace);
13793 } 13801 }
13794 } 13802 }
13795 return null; 13803 return null;
13796 } 13804 }
13797 } 13805 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/element_test.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698