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

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

Issue 23769004: java2dart improvement - use field if getter/setter are trivial. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 library engine.resolver_test; 3 library engine.resolver_test;
4 import 'package:analyzer_experimental/src/generated/java_core.dart'; 4 import 'package:analyzer_experimental/src/generated/java_core.dart';
5 import 'package:analyzer_experimental/src/generated/java_junit.dart'; 5 import 'package:analyzer_experimental/src/generated/java_junit.dart';
6 import 'package:analyzer_experimental/src/generated/source_io.dart'; 6 import 'package:analyzer_experimental/src/generated/source_io.dart';
7 import 'package:analyzer_experimental/src/generated/error.dart'; 7 import 'package:analyzer_experimental/src/generated/error.dart';
8 import 'package:analyzer_experimental/src/generated/scanner.dart'; 8 import 'package:analyzer_experimental/src/generated/scanner.dart';
9 import 'package:analyzer_experimental/src/generated/ast.dart'; 9 import 'package:analyzer_experimental/src/generated/ast.dart';
10 import 'package:analyzer_experimental/src/generated/parser.dart' show ParserErro rCode; 10 import 'package:analyzer_experimental/src/generated/parser.dart' show ParserErro rCode;
(...skipping 5987 matching lines...) Expand 10 before | Expand all | Expand 10 after
5998 runJUnitTest(__test, __test.test_visitTypeName_void); 5998 runJUnitTest(__test, __test.test_visitTypeName_void);
5999 }); 5999 });
6000 }); 6000 });
6001 } 6001 }
6002 } 6002 }
6003 class ResolverTestCase extends EngineTestCase { 6003 class ResolverTestCase extends EngineTestCase {
6004 6004
6005 /** 6005 /**
6006 * The source factory used to create [Source]. 6006 * The source factory used to create [Source].
6007 */ 6007 */
6008 SourceFactory _sourceFactory; 6008 SourceFactory sourceFactory;
6009 6009
6010 /** 6010 /**
6011 * The analysis context used to parse the compilation units being resolved. 6011 * The analysis context used to parse the compilation units being resolved.
6012 */ 6012 */
6013 AnalysisContextImpl _analysisContext; 6013 AnalysisContextImpl analysisContext;
6014 void setUp() { 6014 void setUp() {
6015 reset(); 6015 reset();
6016 } 6016 }
6017 6017
6018 /** 6018 /**
6019 * Add a source file to the content provider. 6019 * Add a source file to the content provider.
6020 * 6020 *
6021 * @param contents the contents to be returned by the content provider for the specified file 6021 * @param contents the contents to be returned by the content provider for the specified file
6022 * @return the source object representing the added file 6022 * @return the source object representing the added file
6023 */ 6023 */
6024 Source addSource(String contents) => addSource2("/test.dart", contents); 6024 Source addSource(String contents) => addSource2("/test.dart", contents);
6025 6025
6026 /** 6026 /**
6027 * Add a source file to the content provider. The file path should be absolute . 6027 * Add a source file to the content provider. The file path should be absolute .
6028 * 6028 *
6029 * @param filePath the path of the file being added 6029 * @param filePath the path of the file being added
6030 * @param contents the contents to be returned by the content provider for the specified file 6030 * @param contents the contents to be returned by the content provider for the specified file
6031 * @return the source object representing the added file 6031 * @return the source object representing the added file
6032 */ 6032 */
6033 Source addSource2(String filePath, String contents) { 6033 Source addSource2(String filePath, String contents) {
6034 Source source = cacheSource(filePath, contents); 6034 Source source = cacheSource(filePath, contents);
6035 ChangeSet changeSet = new ChangeSet(); 6035 ChangeSet changeSet = new ChangeSet();
6036 changeSet.added(source); 6036 changeSet.added(source);
6037 _analysisContext.applyChanges(changeSet); 6037 analysisContext.applyChanges(changeSet);
6038 return source; 6038 return source;
6039 } 6039 }
6040 6040
6041 /** 6041 /**
6042 * Assert that the number of errors that have been gathered matches the number of errors that are 6042 * Assert that the number of errors that have been gathered matches the number of errors that are
6043 * given and that they have the expected error codes. The order in which the e rrors were gathered 6043 * given and that they have the expected error codes. The order in which the e rrors were gathered
6044 * is ignored. 6044 * is ignored.
6045 * 6045 *
6046 * @param expectedErrorCodes the error codes of the errors that should have be en gathered 6046 * @param expectedErrorCodes the error codes of the errors that should have be en gathered
6047 * @throws AssertionFailedError if a different number of errors have been gath ered than were 6047 * @throws AssertionFailedError if a different number of errors have been gath ered than were
6048 * expected 6048 * expected
6049 */ 6049 */
6050 void assertErrors(List<ErrorCode> expectedErrorCodes) { 6050 void assertErrors(List<ErrorCode> expectedErrorCodes) {
6051 GatheringErrorListener errorListener = new GatheringErrorListener(); 6051 GatheringErrorListener errorListener = new GatheringErrorListener();
6052 for (ChangeNotice notice in _analysisContext.performAnalysisTask()) { 6052 for (ChangeNotice notice in analysisContext.performAnalysisTask()) {
6053 for (AnalysisError error in notice.errors) { 6053 for (AnalysisError error in notice.errors) {
6054 errorListener.onError(error); 6054 errorListener.onError(error);
6055 } 6055 }
6056 } 6056 }
6057 errorListener.assertErrors2(expectedErrorCodes); 6057 errorListener.assertErrors2(expectedErrorCodes);
6058 } 6058 }
6059 6059
6060 /** 6060 /**
6061 * Assert that no errors have been gathered. 6061 * Assert that no errors have been gathered.
6062 * 6062 *
6063 * @throws AssertionFailedError if any errors have been gathered 6063 * @throws AssertionFailedError if any errors have been gathered
6064 */ 6064 */
6065 void assertNoErrors() { 6065 void assertNoErrors() {
6066 GatheringErrorListener errorListener = new GatheringErrorListener(); 6066 GatheringErrorListener errorListener = new GatheringErrorListener();
6067 for (ChangeNotice notice in _analysisContext.performAnalysisTask()) { 6067 for (ChangeNotice notice in analysisContext.performAnalysisTask()) {
6068 for (AnalysisError error in notice.errors) { 6068 for (AnalysisError error in notice.errors) {
6069 errorListener.onError(error); 6069 errorListener.onError(error);
6070 } 6070 }
6071 } 6071 }
6072 errorListener.assertNoErrors(); 6072 errorListener.assertNoErrors();
6073 } 6073 }
6074 6074
6075 /** 6075 /**
6076 * Cache the source file content in the source factory but don't add the sourc e to the analysis 6076 * Cache the source file content in the source factory but don't add the sourc e to the analysis
6077 * context. The file path should be absolute. 6077 * context. The file path should be absolute.
6078 * 6078 *
6079 * @param filePath the path of the file being cached 6079 * @param filePath the path of the file being cached
6080 * @param contents the contents to be returned by the content provider for the specified file 6080 * @param contents the contents to be returned by the content provider for the specified file
6081 * @return the source object representing the cached file 6081 * @return the source object representing the cached file
6082 */ 6082 */
6083 Source cacheSource(String filePath, String contents) { 6083 Source cacheSource(String filePath, String contents) {
6084 Source source = new FileBasedSource.con1(_sourceFactory.contentCache, FileUt ilities2.createFile(filePath)); 6084 Source source = new FileBasedSource.con1(sourceFactory.contentCache, FileUti lities2.createFile(filePath));
6085 _sourceFactory.setContents(source, contents); 6085 sourceFactory.setContents(source, contents);
6086 return source; 6086 return source;
6087 } 6087 }
6088 6088
6089 /** 6089 /**
6090 * Create a library element that represents a library named `"test"` containin g a single 6090 * Create a library element that represents a library named `"test"` containin g a single
6091 * empty compilation unit. 6091 * empty compilation unit.
6092 * 6092 *
6093 * @return the library element that was created 6093 * @return the library element that was created
6094 */ 6094 */
6095 LibraryElementImpl createTestLibrary() => createTestLibrary2(new AnalysisConte xtImpl(), "test", []); 6095 LibraryElementImpl createTestLibrary() => createTestLibrary2(new AnalysisConte xtImpl(), "test", []);
(...skipping 18 matching lines...) Expand all
6114 sourcedCompilationUnits[i] = compilationUnit; 6114 sourcedCompilationUnits[i] = compilationUnit;
6115 } 6115 }
6116 String fileName = "${libraryName}.dart"; 6116 String fileName = "${libraryName}.dart";
6117 CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImpl( fileName); 6117 CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImpl( fileName);
6118 compilationUnit.source = createSource2(fileName); 6118 compilationUnit.source = createSource2(fileName);
6119 LibraryElementImpl library = new LibraryElementImpl(context, ASTFactory.libr aryIdentifier2([libraryName])); 6119 LibraryElementImpl library = new LibraryElementImpl(context, ASTFactory.libr aryIdentifier2([libraryName]));
6120 library.definingCompilationUnit = compilationUnit; 6120 library.definingCompilationUnit = compilationUnit;
6121 library.parts = sourcedCompilationUnits; 6121 library.parts = sourcedCompilationUnits;
6122 return library; 6122 return library;
6123 } 6123 }
6124 AnalysisContext get analysisContext => _analysisContext;
6125 SourceFactory get sourceFactory => _sourceFactory;
6126 6124
6127 /** 6125 /**
6128 * Return a type provider that can be used to test the results of resolution. 6126 * Return a type provider that can be used to test the results of resolution.
6129 * 6127 *
6130 * @return a type provider 6128 * @return a type provider
6131 */ 6129 */
6132 TypeProvider get typeProvider { 6130 TypeProvider get typeProvider {
6133 Source coreSource = _analysisContext.sourceFactory.forUri(DartSdk.DART_CORE) ; 6131 Source coreSource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE);
6134 LibraryElement coreElement = _analysisContext.getLibraryElement(coreSource); 6132 LibraryElement coreElement = analysisContext.getLibraryElement(coreSource);
6135 return new TypeProviderImpl(coreElement); 6133 return new TypeProviderImpl(coreElement);
6136 } 6134 }
6137 6135
6138 /** 6136 /**
6139 * In the rare cases we want to group several tests into single "test_" method , so need a way to 6137 * In the rare cases we want to group several tests into single "test_" method , so need a way to
6140 * reset test instance to reuse it. 6138 * reset test instance to reuse it.
6141 */ 6139 */
6142 void reset() { 6140 void reset() {
6143 _analysisContext = AnalysisContextFactory.contextWithCore(); 6141 analysisContext = AnalysisContextFactory.contextWithCore();
6144 _sourceFactory = _analysisContext.sourceFactory; 6142 sourceFactory = analysisContext.sourceFactory;
6145 } 6143 }
6146 6144
6147 /** 6145 /**
6148 * Given a library and all of its parts, resolve the contents of the library a nd the contents of 6146 * Given a library and all of its parts, resolve the contents of the library a nd the contents of
6149 * the parts. This assumes that the sources for the library and its parts have already been added 6147 * the parts. This assumes that the sources for the library and its parts have already been added
6150 * to the content provider using the method [addSource]. 6148 * to the content provider using the method [addSource].
6151 * 6149 *
6152 * @param librarySource the source for the compilation unit that defines the l ibrary 6150 * @param librarySource the source for the compilation unit that defines the l ibrary
6153 * @return the element representing the resolved library 6151 * @return the element representing the resolved library
6154 * @throws AnalysisException if the analysis could not be performed 6152 * @throws AnalysisException if the analysis could not be performed
6155 */ 6153 */
6156 LibraryElement resolve(Source librarySource) => _analysisContext.computeLibrar yElement(librarySource); 6154 LibraryElement resolve(Source librarySource) => analysisContext.computeLibrary Element(librarySource);
6157 6155
6158 /** 6156 /**
6159 * Return the resolved compilation unit corresponding to the given source in t he given library. 6157 * Return the resolved compilation unit corresponding to the given source in t he given library.
6160 * 6158 *
6161 * @param source the source of the compilation unit to be returned 6159 * @param source the source of the compilation unit to be returned
6162 * @param library the library in which the compilation unit is to be resolved 6160 * @param library the library in which the compilation unit is to be resolved
6163 * @return the resolved compilation unit 6161 * @return the resolved compilation unit
6164 * @throws Exception if the compilation unit could not be resolved 6162 * @throws Exception if the compilation unit could not be resolved
6165 */ 6163 */
6166 CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) => _analysisContext.resolveCompilationUnit(source, library); 6164 CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) => analysisContext.resolveCompilationUnit(source, library);
6167 6165
6168 /** 6166 /**
6169 * Verify that all of the identifiers in the compilation units associated with the given sources 6167 * Verify that all of the identifiers in the compilation units associated with the given sources
6170 * have been resolved. 6168 * have been resolved.
6171 * 6169 *
6172 * @param resolvedElementMap a table mapping the AST nodes that have been reso lved to the element 6170 * @param resolvedElementMap a table mapping the AST nodes that have been reso lved to the element
6173 * to which they were resolved 6171 * to which they were resolved
6174 * @param sources the sources identifying the compilation units to be verified 6172 * @param sources the sources identifying the compilation units to be verified
6175 * @throws Exception if the contents of the compilation unit cannot be accesse d 6173 * @throws Exception if the contents of the compilation unit cannot be accesse d
6176 */ 6174 */
6177 void verify(List<Source> sources) { 6175 void verify(List<Source> sources) {
6178 ResolutionVerifier verifier = new ResolutionVerifier(); 6176 ResolutionVerifier verifier = new ResolutionVerifier();
6179 for (Source source in sources) { 6177 for (Source source in sources) {
6180 _analysisContext.parseCompilationUnit(source).accept(verifier); 6178 analysisContext.parseCompilationUnit(source).accept(verifier);
6181 } 6179 }
6182 verifier.assertResolved(); 6180 verifier.assertResolved();
6183 } 6181 }
6184 6182
6185 /** 6183 /**
6186 * Create a source object representing a file with the given name and give it an empty content. 6184 * Create a source object representing a file with the given name and give it an empty content.
6187 * 6185 *
6188 * @param fileName the name of the file for which a source is to be created 6186 * @param fileName the name of the file for which a source is to be created
6189 * @return the source that was created 6187 * @return the source that was created
6190 */ 6188 */
6191 FileBasedSource createSource2(String fileName) { 6189 FileBasedSource createSource2(String fileName) {
6192 FileBasedSource source = new FileBasedSource.con1(_sourceFactory.contentCach e, FileUtilities2.createFile(fileName)); 6190 FileBasedSource source = new FileBasedSource.con1(sourceFactory.contentCache , FileUtilities2.createFile(fileName));
6193 _sourceFactory.setContents(source, ""); 6191 sourceFactory.setContents(source, "");
6194 return source; 6192 return source;
6195 } 6193 }
6196 static dartSuite() { 6194 static dartSuite() {
6197 _ut.group('ResolverTestCase', () { 6195 _ut.group('ResolverTestCase', () {
6198 }); 6196 });
6199 } 6197 }
6200 } 6198 }
6201 class TypeProviderImplTest extends EngineTestCase { 6199 class TypeProviderImplTest extends EngineTestCase {
6202 void test_creation() { 6200 void test_creation() {
6203 InterfaceType objectType = classElement("Object", null, []).type; 6201 InterfaceType objectType = classElement("Object", null, []).type;
(...skipping 11476 matching lines...) Expand 10 before | Expand all | Expand 10 after
17680 // ErrorResolverTest.dartSuite(); 17678 // ErrorResolverTest.dartSuite();
17681 // HintCodeTest.dartSuite(); 17679 // HintCodeTest.dartSuite();
17682 // NonHintCodeTest.dartSuite(); 17680 // NonHintCodeTest.dartSuite();
17683 // NonErrorResolverTest.dartSuite(); 17681 // NonErrorResolverTest.dartSuite();
17684 // SimpleResolverTest.dartSuite(); 17682 // SimpleResolverTest.dartSuite();
17685 // StaticTypeWarningCodeTest.dartSuite(); 17683 // StaticTypeWarningCodeTest.dartSuite();
17686 // StaticWarningCodeTest.dartSuite(); 17684 // StaticWarningCodeTest.dartSuite();
17687 // StrictModeTest.dartSuite(); 17685 // StrictModeTest.dartSuite();
17688 // TypePropagationTest.dartSuite(); 17686 // TypePropagationTest.dartSuite();
17689 } 17687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698