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

Side by Side Diff: pkg/analyzer_experimental/lib/src/generated/resolver.dart

Issue 18129004: Simplify constructors translation, improve code style. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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; 3 library engine.resolver;
4 import 'dart:collection'; 4 import 'dart:collection';
5 import 'java_core.dart'; 5 import 'java_core.dart';
6 import 'java_engine.dart'; 6 import 'java_engine.dart';
7 import 'instrumentation.dart'; 7 import 'instrumentation.dart';
8 import 'source.dart'; 8 import 'source.dart';
9 import 'error.dart'; 9 import 'error.dart';
10 import 'scanner.dart' as sc; 10 import 'scanner.dart' as sc;
(...skipping 4253 matching lines...) Expand 10 before | Expand all | Expand 10 after
4264 */ 4264 */
4265 Set<Source> get compilationUnitSources => _astMap.keys.toSet(); 4265 Set<Source> get compilationUnitSources => _astMap.keys.toSet();
4266 4266
4267 /** 4267 /**
4268 * Return the AST structure associated with the defining compilation unit for this library. 4268 * Return the AST structure associated with the defining compilation unit for this library.
4269 * 4269 *
4270 * @return the AST structure associated with the defining compilation unit for this library 4270 * @return the AST structure associated with the defining compilation unit for this library
4271 * @throws AnalysisException if an AST structure could not be created for the defining compilation 4271 * @throws AnalysisException if an AST structure could not be created for the defining compilation
4272 * unit 4272 * unit
4273 */ 4273 */
4274 CompilationUnit get definingCompilationUnit => getAST(librarySource); 4274 CompilationUnit get definingCompilationUnit => getAST(_librarySource);
4275 4275
4276 /** 4276 /**
4277 * Return `true` if this library explicitly imports core. 4277 * Return `true` if this library explicitly imports core.
4278 * 4278 *
4279 * @return `true` if this library explicitly imports core 4279 * @return `true` if this library explicitly imports core
4280 */ 4280 */
4281 bool get explicitlyImportsCore => _explicitlyImportsCore; 4281 bool get explicitlyImportsCore => _explicitlyImportsCore;
4282 4282
4283 /** 4283 /**
4284 * Return an array containing the libraries that are exported from this librar y. 4284 * Return an array containing the libraries that are exported from this librar y.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
4391 */ 4391 */
4392 String getUri(UriBasedDirective directive) => _directiveUris[directive]; 4392 String getUri(UriBasedDirective directive) => _directiveUris[directive];
4393 4393
4394 /** 4394 /**
4395 * Set the AST structure associated with the defining compilation unit for thi s library to the 4395 * Set the AST structure associated with the defining compilation unit for thi s library to the
4396 * given AST structure. 4396 * given AST structure.
4397 * 4397 *
4398 * @param unit the AST structure associated with the defining compilation unit for this library 4398 * @param unit the AST structure associated with the defining compilation unit for this library
4399 */ 4399 */
4400 void set definingCompilationUnit(CompilationUnit unit) { 4400 void set definingCompilationUnit(CompilationUnit unit) {
4401 _astMap[librarySource] = unit; 4401 _astMap[_librarySource] = unit;
4402 } 4402 }
4403 4403
4404 /** 4404 /**
4405 * Set whether this library explicitly imports core to match the given value. 4405 * Set whether this library explicitly imports core to match the given value.
4406 * 4406 *
4407 * @param explicitlyImportsCore `true` if this library explicitly imports core 4407 * @param explicitlyImportsCore `true` if this library explicitly imports core
4408 */ 4408 */
4409 void set explicitlyImportsCore(bool explicitlyImportsCore2) { 4409 void set explicitlyImportsCore(bool explicitlyImportsCore2) {
4410 this._explicitlyImportsCore = explicitlyImportsCore2; 4410 this._explicitlyImportsCore = explicitlyImportsCore2;
4411 } 4411 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
4650 * @coverage dart.engine.resolver 4650 * @coverage dart.engine.resolver
4651 */ 4651 */
4652 class LibraryResolver { 4652 class LibraryResolver {
4653 4653
4654 /** 4654 /**
4655 * The analysis context in which the libraries are being analyzed. 4655 * The analysis context in which the libraries are being analyzed.
4656 */ 4656 */
4657 InternalAnalysisContext _analysisContext; 4657 InternalAnalysisContext _analysisContext;
4658 4658
4659 /** 4659 /**
4660 * A flag indicating whether analysis is to generate audit results (e.g. type inference based 4660 * A flag indicating whether analysis is to generate hint results (e.g. type i nference based
4661 * information and pub best practices). 4661 * information and pub best practices).
4662 */ 4662 */
4663 bool _audit = false; 4663 bool _enableHints = false;
4664 4664
4665 /** 4665 /**
4666 * The listener to which analysis errors will be reported, this error listener is either 4666 * The listener to which analysis errors will be reported, this error listener is either
4667 * references [recordingErrorListener], or it unions the passed 4667 * references [recordingErrorListener], or it unions the passed
4668 * [AnalysisErrorListener] with the [recordingErrorListener]. 4668 * [AnalysisErrorListener] with the [recordingErrorListener].
4669 */ 4669 */
4670 RecordingErrorListener _errorListener; 4670 RecordingErrorListener _errorListener;
4671 4671
4672 /** 4672 /**
4673 * A source object representing the core library (dart:core). 4673 * A source object representing the core library (dart:core).
(...skipping 22 matching lines...) Expand all
4696 4696
4697 /** 4697 /**
4698 * Initialize a newly created library resolver to resolve libraries within the given context. 4698 * Initialize a newly created library resolver to resolve libraries within the given context.
4699 * 4699 *
4700 * @param analysisContext the analysis context in which the library is being a nalyzed 4700 * @param analysisContext the analysis context in which the library is being a nalyzed
4701 */ 4701 */
4702 LibraryResolver(InternalAnalysisContext analysisContext) { 4702 LibraryResolver(InternalAnalysisContext analysisContext) {
4703 this._analysisContext = analysisContext; 4703 this._analysisContext = analysisContext;
4704 this._errorListener = new RecordingErrorListener(); 4704 this._errorListener = new RecordingErrorListener();
4705 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE) ; 4705 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE) ;
4706 _audit = analysisContext.analysisOptions.audit; 4706 _enableHints = analysisContext.analysisOptions.hint;
4707 } 4707 }
4708 4708
4709 /** 4709 /**
4710 * Return the analysis context in which the libraries are being analyzed. 4710 * Return the analysis context in which the libraries are being analyzed.
4711 * 4711 *
4712 * @return the analysis context in which the libraries are being analyzed 4712 * @return the analysis context in which the libraries are being analyzed
4713 */ 4713 */
4714 InternalAnalysisContext get analysisContext => _analysisContext; 4714 InternalAnalysisContext get analysisContext => _analysisContext;
4715 4715
4716 /** 4716 /**
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
5255 * the library cannot be analyzed 5255 * the library cannot be analyzed
5256 */ 5256 */
5257 void runAdditionalAnalyses2(Library library) { 5257 void runAdditionalAnalyses2(Library library) {
5258 for (Source source in library.compilationUnitSources) { 5258 for (Source source in library.compilationUnitSources) {
5259 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 5259 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
5260 CompilationUnit unit = library.getAST(source); 5260 CompilationUnit unit = library.getAST(source);
5261 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t ypeProvider); 5261 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t ypeProvider);
5262 unit.accept(constantVerifier); 5262 unit.accept(constantVerifier);
5263 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib raryElement, _typeProvider, library.inheritanceManager); 5263 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib raryElement, _typeProvider, library.inheritanceManager);
5264 unit.accept(errorVerifier); 5264 unit.accept(errorVerifier);
5265 if (_audit) { 5265 if (_enableHints) {
5266 new AuditVerifier(_analysisContext, errorReporter).visitCompilationUnit( unit); 5266 new HintVerifier(_analysisContext, errorReporter).visitCompilationUnit(u nit);
5267 } 5267 }
5268 } 5268 }
5269 } 5269 }
5270 } 5270 }
5271 /** 5271 /**
5272 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single 5272 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single
5273 * compilation unit. 5273 * compilation unit.
5274 * 5274 *
5275 * @coverage dart.engine.resolver 5275 * @coverage dart.engine.resolver
5276 */ 5276 */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5309 TypeOverrideManager _overrideManager = new TypeOverrideManager(); 5309 TypeOverrideManager _overrideManager = new TypeOverrideManager();
5310 5310
5311 /** 5311 /**
5312 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 5312 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
5313 * 5313 *
5314 * @param library the library containing the compilation unit being resolved 5314 * @param library the library containing the compilation unit being resolved
5315 * @param source the source representing the compilation unit being visited 5315 * @param source the source representing the compilation unit being visited
5316 * @param typeProvider the object used to access the types from the core libra ry 5316 * @param typeProvider the object used to access the types from the core libra ry
5317 */ 5317 */
5318 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider ) : super.con1(library, source, typeProvider) { 5318 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider ) : super.con1(library, source, typeProvider) {
5319 _jtd_constructor_277_impl(library, source, typeProvider);
5320 }
5321 _jtd_constructor_277_impl(Library library, Source source, TypeProvider typePro vider) {
5322 this._inheritanceManager = library.inheritanceManager; 5319 this._inheritanceManager = library.inheritanceManager;
5323 this._elementResolver = new ElementResolver(this); 5320 this._elementResolver = new ElementResolver(this);
5324 this._typeAnalyzer = new StaticTypeAnalyzer(this); 5321 this._typeAnalyzer = new StaticTypeAnalyzer(this);
5325 } 5322 }
5326 5323
5327 /** 5324 /**
5328 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 5325 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
5329 * 5326 *
5330 * @param definingLibrary the element for the library containing the compilati on unit being 5327 * @param definingLibrary the element for the library containing the compilati on unit being
5331 * visited 5328 * visited
5332 * @param source the source representing the compilation unit being visited 5329 * @param source the source representing the compilation unit being visited
5333 * @param typeProvider the object used to access the types from the core libra ry 5330 * @param typeProvider the object used to access the types from the core libra ry
5334 * @param errorListener the error listener that will be informed of any errors that are found 5331 * @param errorListener the error listener that will be informed of any errors that are found
5335 * during resolution 5332 * during resolution
5336 */ 5333 */
5337 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, InheritanceManager inheritanceManager2, AnalysisErrorListener e rrorListener) : super.con2(definingLibrary, source, typeProvider, errorListener) { 5334 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, InheritanceManager inheritanceManager, AnalysisErrorListener er rorListener) : super.con2(definingLibrary, source, typeProvider, errorListener) {
5338 _jtd_constructor_278_impl(definingLibrary, source, typeProvider, inheritance Manager2, errorListener); 5335 this._inheritanceManager = inheritanceManager;
5339 }
5340 _jtd_constructor_278_impl(LibraryElement definingLibrary, Source source, TypeP rovider typeProvider, InheritanceManager inheritanceManager2, AnalysisErrorListe ner errorListener) {
5341 this._inheritanceManager = inheritanceManager2;
5342 this._elementResolver = new ElementResolver(this); 5336 this._elementResolver = new ElementResolver(this);
5343 this._typeAnalyzer = new StaticTypeAnalyzer(this); 5337 this._typeAnalyzer = new StaticTypeAnalyzer(this);
5344 } 5338 }
5345 5339
5346 /** 5340 /**
5347 * Return the object keeping track of which elements have had their types over ridden. 5341 * Return the object keeping track of which elements have had their types over ridden.
5348 * 5342 *
5349 * @return the object keeping track of which elements have had their types ove rridden 5343 * @return the object keeping track of which elements have had their types ove rridden
5350 */ 5344 */
5351 TypeOverrideManager get overrideManager => _overrideManager; 5345 TypeOverrideManager get overrideManager => _overrideManager;
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
6085 */ 6079 */
6086 LabelScope _labelScope; 6080 LabelScope _labelScope;
6087 6081
6088 /** 6082 /**
6089 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 6083 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
6090 * 6084 *
6091 * @param library the library containing the compilation unit being resolved 6085 * @param library the library containing the compilation unit being resolved
6092 * @param source the source representing the compilation unit being visited 6086 * @param source the source representing the compilation unit being visited
6093 * @param typeProvider the object used to access the types from the core libra ry 6087 * @param typeProvider the object used to access the types from the core libra ry
6094 */ 6088 */
6095 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2 ) { 6089 ScopedVisitor.con1(Library library, Source source, TypeProvider typeProvider) {
6096 _jtd_constructor_279_impl(library, source2, typeProvider2);
6097 }
6098 _jtd_constructor_279_impl(Library library, Source source2, TypeProvider typePr ovider2) {
6099 this._definingLibrary = library.libraryElement; 6090 this._definingLibrary = library.libraryElement;
6100 this._source = source2; 6091 this._source = source;
6101 LibraryScope libraryScope = library.libraryScope; 6092 LibraryScope libraryScope = library.libraryScope;
6102 this._errorListener = libraryScope.errorListener; 6093 this._errorListener = libraryScope.errorListener;
6103 this._nameScope = libraryScope; 6094 this._nameScope = libraryScope;
6104 this._typeProvider = typeProvider2; 6095 this._typeProvider = typeProvider;
6105 } 6096 }
6106 6097
6107 /** 6098 /**
6108 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 6099 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
6109 * 6100 *
6110 * @param definingLibrary the element for the library containing the compilati on unit being 6101 * @param definingLibrary the element for the library containing the compilati on unit being
6111 * visited 6102 * visited
6112 * @param source the source representing the compilation unit being visited 6103 * @param source the source representing the compilation unit being visited
6113 * @param typeProvider the object used to access the types from the core libra ry 6104 * @param typeProvider the object used to access the types from the core libra ry
6114 * @param errorListener the error listener that will be informed of any errors that are found 6105 * @param errorListener the error listener that will be informed of any errors that are found
6115 * during resolution 6106 * during resolution
6116 */ 6107 */
6117 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid er typeProvider2, AnalysisErrorListener errorListener2) { 6108 ScopedVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvider typeProvider, AnalysisErrorListener errorListener) {
6118 _jtd_constructor_280_impl(definingLibrary2, source2, typeProvider2, errorLis tener2); 6109 this._definingLibrary = definingLibrary;
6119 } 6110 this._source = source;
6120 _jtd_constructor_280_impl(LibraryElement definingLibrary2, Source source2, Typ eProvider typeProvider2, AnalysisErrorListener errorListener2) { 6111 this._errorListener = errorListener;
6121 this._definingLibrary = definingLibrary2; 6112 this._nameScope = new LibraryScope(definingLibrary, errorListener);
6122 this._source = source2; 6113 this._typeProvider = typeProvider;
6123 this._errorListener = errorListener2;
6124 this._nameScope = new LibraryScope(definingLibrary2, errorListener2);
6125 this._typeProvider = typeProvider2;
6126 } 6114 }
6127 6115
6128 /** 6116 /**
6129 * Return the library element for the library containing the compilation unit being resolved. 6117 * Return the library element for the library containing the compilation unit being resolved.
6130 * 6118 *
6131 * @return the library element for the library containing the compilation unit being resolved 6119 * @return the library element for the library containing the compilation unit being resolved
6132 */ 6120 */
6133 LibraryElement get definingLibrary => _definingLibrary; 6121 LibraryElement get definingLibrary => _definingLibrary;
6134 6122
6135 /** 6123 /**
(...skipping 2372 matching lines...) Expand 10 before | Expand all | Expand 10 after
8508 bool _hasReferenceToSuper = false; 8496 bool _hasReferenceToSuper = false;
8509 8497
8510 /** 8498 /**
8511 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 8499 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
8512 * 8500 *
8513 * @param library the library containing the compilation unit being resolved 8501 * @param library the library containing the compilation unit being resolved
8514 * @param source the source representing the compilation unit being visited 8502 * @param source the source representing the compilation unit being visited
8515 * @param typeProvider the object used to access the types from the core libra ry 8503 * @param typeProvider the object used to access the types from the core libra ry
8516 */ 8504 */
8517 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv ider) : super.con1(library, source, typeProvider) { 8505 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv ider) : super.con1(library, source, typeProvider) {
8518 _jtd_constructor_285_impl(library, source, typeProvider);
8519 }
8520 _jtd_constructor_285_impl(Library library, Source source, TypeProvider typePro vider) {
8521 _dynamicType = typeProvider.dynamicType; 8506 _dynamicType = typeProvider.dynamicType;
8522 } 8507 }
8523 8508
8524 /** 8509 /**
8525 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 8510 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
8526 * 8511 *
8527 * @param definingLibrary the element for the library containing the compilati on unit being 8512 * @param definingLibrary the element for the library containing the compilati on unit being
8528 * visited 8513 * visited
8529 * @param source the source representing the compilation unit being visited 8514 * @param source the source representing the compilation unit being visited
8530 * @param typeProvider the object used to access the types from the core libra ry 8515 * @param typeProvider the object used to access the types from the core libra ry
8531 * @param errorListener the error listener that will be informed of any errors that are found 8516 * @param errorListener the error listener that will be informed of any errors that are found
8532 * during resolution 8517 * during resolution
8533 */ 8518 */
8534 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) { 8519 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) {
8535 _jtd_constructor_286_impl(definingLibrary, source, typeProvider, errorListen er);
8536 }
8537 _jtd_constructor_286_impl(LibraryElement definingLibrary, Source source, TypeP rovider typeProvider, AnalysisErrorListener errorListener) {
8538 _dynamicType = typeProvider.dynamicType; 8520 _dynamicType = typeProvider.dynamicType;
8539 } 8521 }
8540 Object visitCatchClause(CatchClause node) { 8522 Object visitCatchClause(CatchClause node) {
8541 super.visitCatchClause(node); 8523 super.visitCatchClause(node);
8542 SimpleIdentifier exception = node.exceptionParameter; 8524 SimpleIdentifier exception = node.exceptionParameter;
8543 if (exception != null) { 8525 if (exception != null) {
8544 TypeName exceptionTypeName = node.exceptionType; 8526 TypeName exceptionTypeName = node.exceptionType;
8545 Type2 exceptionType; 8527 Type2 exceptionType;
8546 if (exceptionTypeName == null) { 8528 if (exceptionTypeName == null) {
8547 exceptionType = typeProvider.objectType; 8529 exceptionType = typeProvider.objectType;
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
9507 9489
9508 /** 9490 /**
9509 * Initialize a newly created scope to represent the potential target of an un labeled 9491 * Initialize a newly created scope to represent the potential target of an un labeled
9510 * `break` or `continue`. 9492 * `break` or `continue`.
9511 * 9493 *
9512 * @param outerScope the label scope enclosing the new label scope 9494 * @param outerScope the label scope enclosing the new label scope
9513 * @param onSwitchStatement `true` if this label is associated with a `switch` 9495 * @param onSwitchStatement `true` if this label is associated with a `switch`
9514 * statement 9496 * statement
9515 * @param onSwitchMember `true` if this label is associated with a `switch` me mber 9497 * @param onSwitchMember `true` if this label is associated with a `switch` me mber
9516 */ 9498 */
9517 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) { 9499 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) : this.con2(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMPTY_LABEL_IDE NTIFIER, onSwitchStatement, onSwitchMember));
9518 _jtd_constructor_291_impl(outerScope, onSwitchStatement, onSwitchMember);
9519 }
9520 _jtd_constructor_291_impl(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMember) {
9521 _jtd_constructor_292_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember));
9522 }
9523 9500
9524 /** 9501 /**
9525 * Initialize a newly created scope to represent the given label. 9502 * Initialize a newly created scope to represent the given label.
9526 * 9503 *
9527 * @param outerScope the label scope enclosing the new label scope 9504 * @param outerScope the label scope enclosing the new label scope
9528 * @param label the label defined in this scope 9505 * @param label the label defined in this scope
9529 * @param element the element to which the label resolves 9506 * @param element the element to which the label resolves
9530 */ 9507 */
9531 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2) { 9508 LabelScope.con2(LabelScope outerScope, String label, LabelElement element) {
9532 _jtd_constructor_292_impl(outerScope2, label2, element2); 9509 this._outerScope = outerScope;
9533 } 9510 this._label = label;
9534 _jtd_constructor_292_impl(LabelScope outerScope2, String label2, LabelElement element2) { 9511 this._element = element;
9535 this._outerScope = outerScope2;
9536 this._label = label2;
9537 this._element = element2;
9538 } 9512 }
9539 9513
9540 /** 9514 /**
9541 * Return the label element corresponding to the given label, or `null` if the given label 9515 * Return the label element corresponding to the given label, or `null` if the given label
9542 * is not defined in this scope. 9516 * is not defined in this scope.
9543 * 9517 *
9544 * @param targetLabel the label being looked up 9518 * @param targetLabel the label being looked up
9545 * @return the label element corresponding to the given label 9519 * @return the label element corresponding to the given label
9546 */ 9520 */
9547 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name) ; 9521 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name) ;
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
10203 if (element is MethodElement) { 10177 if (element is MethodElement) {
10204 MethodElement method = element as MethodElement; 10178 MethodElement method = element as MethodElement;
10205 if (method.name == "-" && method.parameters.length == 0) { 10179 if (method.name == "-" && method.parameters.length == 0) {
10206 return UNARY_MINUS; 10180 return UNARY_MINUS;
10207 } 10181 }
10208 } 10182 }
10209 return element.name; 10183 return element.name;
10210 } 10184 }
10211 } 10185 }
10212 /** 10186 /**
10213 * Instances of the class `AuditVerifier` traverse an AST structure looking for additional
10214 * additional suggestions not mentioned in the Dart Language Specification.
10215 *
10216 * @coverage dart.engine.resolver
10217 */
10218 class AuditVerifier {
10219 DeadCodeVerifier _deadCodeVerifier;
10220 AuditVerifier(AnalysisContext context, ErrorReporter errorReporter) {
10221 _deadCodeVerifier = new DeadCodeVerifier(errorReporter);
10222 }
10223 void visitCompilationUnit(CompilationUnit node) {
10224 node.accept(_deadCodeVerifier);
10225 }
10226 }
10227 /**
10228 * Instances of the class `ConstantVerifier` traverse an AST structure looking f or additional 10187 * Instances of the class `ConstantVerifier` traverse an AST structure looking f or additional
10229 * errors and warnings not covered by the parser and resolver. In particular, it looks for errors 10188 * errors and warnings not covered by the parser and resolver. In particular, it looks for errors
10230 * and warnings related to constant expressions. 10189 * and warnings related to constant expressions.
10231 * 10190 *
10232 * @coverage dart.engine.resolver 10191 * @coverage dart.engine.resolver
10233 */ 10192 */
10234 class ConstantVerifier extends RecursiveASTVisitor<Object> { 10193 class ConstantVerifier extends RecursiveASTVisitor<Object> {
10235 10194
10236 /** 10195 /**
10237 * The error reporter by which errors will be reported. 10196 * The error reporter by which errors will be reported.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
10557 } 10516 }
10558 } 10517 }
10559 return ValidResult.RESULT_OBJECT; 10518 return ValidResult.RESULT_OBJECT;
10560 } 10519 }
10561 } 10520 }
10562 return super.visitSimpleIdentifier(node); 10521 return super.visitSimpleIdentifier(node);
10563 } 10522 }
10564 } 10523 }
10565 /** 10524 /**
10566 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of 10525 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of
10567 * [AuditCode#DEAD_CODE]. 10526 * [HintCode#DEAD_CODE].
10568 * 10527 *
10569 * @coverage dart.engine.resolver 10528 * @coverage dart.engine.resolver
10570 */ 10529 */
10571 class DeadCodeVerifier extends RecursiveASTVisitor<Object> { 10530 class DeadCodeVerifier extends RecursiveASTVisitor<Object> {
10572 10531
10573 /** 10532 /**
10574 * The error reporter by which errors will be reported. 10533 * The error reporter by which errors will be reported.
10575 */ 10534 */
10576 ErrorReporter _errorReporter; 10535 ErrorReporter _errorReporter;
10577 10536
10578 /** 10537 /**
10579 * Create a new instance of the [DeadCodeVerifier]. 10538 * Create a new instance of the [DeadCodeVerifier].
10580 * 10539 *
10581 * @param errorReporter the error reporter 10540 * @param errorReporter the error reporter
10582 */ 10541 */
10583 DeadCodeVerifier(ErrorReporter errorReporter) { 10542 DeadCodeVerifier(ErrorReporter errorReporter) {
10584 this._errorReporter = errorReporter; 10543 this._errorReporter = errorReporter;
10585 } 10544 }
10586 Object visitBinaryExpression(BinaryExpression node) { 10545 Object visitBinaryExpression(BinaryExpression node) {
10587 sc.Token operator = node.operator; 10546 sc.Token operator = node.operator;
10588 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND); 10547 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND);
10589 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR); 10548 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR);
10590 bool foundError = false;
10591 if (isAmpAmp || isBarBar) { 10549 if (isAmpAmp || isBarBar) {
10592 Expression lhsCondition = node.leftOperand; 10550 Expression lhsCondition = node.leftOperand;
10593 ValidResult lhsResult = getConstantBooleanValue(lhsCondition); 10551 ValidResult lhsResult = getConstantBooleanValue(lhsCondition);
10594 if (lhsResult != null) { 10552 if (lhsResult != null) {
10595 if (identical(lhsResult, ValidResult.RESULT_TRUE) && isBarBar) { 10553 if (identical(lhsResult, ValidResult.RESULT_TRUE) && isBarBar) {
10596 _errorReporter.reportError2(AuditCode.DEAD_CODE, node.rightOperand, [] ); 10554 _errorReporter.reportError2(HintCode.DEAD_CODE, node.rightOperand, []) ;
10597 foundError = true; 10555 safelyVisit(lhsCondition);
10556 return null;
10598 } else if (identical(lhsResult, ValidResult.RESULT_FALSE) && isAmpAmp) { 10557 } else if (identical(lhsResult, ValidResult.RESULT_FALSE) && isAmpAmp) {
10599 _errorReporter.reportError2(AuditCode.DEAD_CODE, node.rightOperand, [] ); 10558 _errorReporter.reportError2(HintCode.DEAD_CODE, node.rightOperand, []) ;
10600 foundError = true; 10559 safelyVisit(lhsCondition);
10560 return null;
10601 } 10561 }
10602 } 10562 }
10603 } 10563 }
10604 if (foundError) {
10605 return null;
10606 }
10607 return super.visitBinaryExpression(node); 10564 return super.visitBinaryExpression(node);
10608 } 10565 }
10609 Object visitBlock(Block node) { 10566 Object visitBlock(Block node) {
10610 checkForDeadCodeStatementsAfterReturn(node); 10567 checkForDeadCodeStatementsAfterReturn(node);
10611 return super.visitBlock(node); 10568 return super.visitBlock(node);
10612 } 10569 }
10613 Object visitConditionalExpression(ConditionalExpression node) { 10570 Object visitConditionalExpression(ConditionalExpression node) {
10614 Expression conditionExpression = node.condition; 10571 Expression conditionExpression = node.condition;
10615 ValidResult result = getConstantBooleanValue(conditionExpression); 10572 ValidResult result = getConstantBooleanValue(conditionExpression);
10616 if (result != null) { 10573 if (result != null) {
10617 if (identical(result, ValidResult.RESULT_TRUE)) { 10574 if (identical(result, ValidResult.RESULT_TRUE)) {
10618 _errorReporter.reportError2(AuditCode.DEAD_CODE, node.elseExpression, [] ); 10575 _errorReporter.reportError2(HintCode.DEAD_CODE, node.elseExpression, []) ;
10576 safelyVisit(node.thenExpression);
10577 return null;
10619 } else { 10578 } else {
10620 _errorReporter.reportError2(AuditCode.DEAD_CODE, node.thenExpression, [] ); 10579 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenExpression, []) ;
10580 safelyVisit(node.elseExpression);
10581 return null;
10621 } 10582 }
10622 } 10583 }
10623 return super.visitConditionalExpression(node); 10584 return super.visitConditionalExpression(node);
10624 } 10585 }
10625 Object visitIfStatement(IfStatement node) { 10586 Object visitIfStatement(IfStatement node) {
10626 Expression conditionExpression = node.condition; 10587 Expression conditionExpression = node.condition;
10627 ValidResult result = getConstantBooleanValue(conditionExpression); 10588 ValidResult result = getConstantBooleanValue(conditionExpression);
10628 if (result != null) { 10589 if (result != null) {
10629 if (identical(result, ValidResult.RESULT_TRUE)) { 10590 if (identical(result, ValidResult.RESULT_TRUE)) {
10630 Statement elseStatement = node.elseStatement; 10591 Statement elseStatement = node.elseStatement;
10631 if (elseStatement != null) { 10592 if (elseStatement != null) {
10632 _errorReporter.reportError2(AuditCode.DEAD_CODE, elseStatement, []); 10593 _errorReporter.reportError2(HintCode.DEAD_CODE, elseStatement, []);
10594 safelyVisit(node.thenStatement);
10595 return null;
10633 } 10596 }
10634 } else { 10597 } else {
10635 _errorReporter.reportError2(AuditCode.DEAD_CODE, node.thenStatement, []) ; 10598 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenStatement, []);
10599 safelyVisit(node.elseStatement);
10600 return null;
10636 } 10601 }
10637 } 10602 }
10638 return super.visitIfStatement(node); 10603 return super.visitIfStatement(node);
10639 } 10604 }
10605 Object visitTryStatement(TryStatement node) {
10606 safelyVisit(node.body);
10607 NodeList<CatchClause> catchClauses = node.catchClauses;
10608 int numOfCatchClauses = catchClauses.length;
10609 if (numOfCatchClauses == 0) {
10610 safelyVisit(node.finallyClause);
10611 return null;
10612 }
10613 List<Type2> visitedTypes = new List<Type2>();
10614 for (int i = 0; i < numOfCatchClauses; i++) {
10615 CatchClause catchClause = catchClauses[i];
10616 if (catchClause.onKeyword != null) {
10617 TypeName typeName = catchClause.exceptionType;
10618 if (typeName != null && typeName.type != null) {
10619 Type2 currentType = typeName.type;
10620 if (currentType.isObject) {
10621 safelyVisit(catchClause);
10622 if (i + 1 != numOfCatchClauses) {
10623 CatchClause nextCatchClause = catchClauses[i + 1];
10624 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
10625 int offset = nextCatchClause.offset;
10626 int length = lastCatchClause.end - offset;
10627 _errorReporter.reportError3(HintCode.DEAD_CODE_CATCH_FOLLOWING_CAT CH, offset, length, []);
10628 break;
10629 }
10630 }
10631 for (Type2 type in visitedTypes) {
10632 if (currentType.isSubtypeOf(type)) {
10633 _errorReporter.reportError2(HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, c atchClause, [currentType.displayName, type.displayName]);
10634 continue;
10635 }
10636 }
10637 visitedTypes.add(currentType);
10638 }
10639 safelyVisit(catchClause);
10640 } else {
10641 safelyVisit(catchClause);
10642 if (i + 1 != numOfCatchClauses) {
10643 CatchClause nextCatchClause = catchClauses[i + 1];
10644 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
10645 int offset = nextCatchClause.offset;
10646 int length = lastCatchClause.end - offset;
10647 _errorReporter.reportError3(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length, []);
10648 break;
10649 }
10650 }
10651 }
10652 safelyVisit(node.finallyClause);
10653 return null;
10654 }
10640 Object visitWhileStatement(WhileStatement node) { 10655 Object visitWhileStatement(WhileStatement node) {
10641 Expression conditionExpression = node.condition; 10656 Expression conditionExpression = node.condition;
10642 ValidResult result = getConstantBooleanValue(conditionExpression); 10657 ValidResult result = getConstantBooleanValue(conditionExpression);
10643 if (result != null) { 10658 if (result != null) {
10644 if (identical(result, ValidResult.RESULT_FALSE)) { 10659 if (identical(result, ValidResult.RESULT_FALSE)) {
10645 _errorReporter.reportError2(AuditCode.DEAD_CODE, node.body, []); 10660 _errorReporter.reportError2(HintCode.DEAD_CODE, node.body, []);
10661 safelyVisit(conditionExpression);
10662 return null;
10646 } 10663 }
10647 } 10664 }
10648 return super.visitWhileStatement(node); 10665 return super.visitWhileStatement(node);
10649 } 10666 }
10650 10667
10651 /** 10668 /**
10652 * Given some [Block], this method reports and error on all statements between the end of 10669 * Given some [Block], this method reports and error on all statements between the end of
10653 * the block and the first return statement (assuming there it is not at the e nd of the block.) 10670 * the block and the first return statement (assuming there it is not at the e nd of the block.)
10654 * 10671 *
10655 * @param node the block to evaluate 10672 * @param node the block to evaluate
10656 * @return `true` if and only if an error code is generated on the passed node 10673 * @return `true` if and only if an error code is generated on the passed node
10657 */ 10674 */
10658 bool checkForDeadCodeStatementsAfterReturn(Block node) { 10675 bool checkForDeadCodeStatementsAfterReturn(Block node) {
10659 NodeList<Statement> statements = node.statements; 10676 NodeList<Statement> statements = node.statements;
10660 int size = statements.length; 10677 int size = statements.length;
10661 if (size == 0) { 10678 if (size == 0) {
10662 return false; 10679 return false;
10663 } 10680 }
10664 for (int i = 0; i < size; i++) { 10681 for (int i = 0; i < size; i++) {
10665 Statement currentStatement = statements[i]; 10682 Statement currentStatement = statements[i];
10666 if (currentStatement is ReturnStatement && i != size - 1) { 10683 if (currentStatement is ReturnStatement && i != size - 1) {
10667 Statement nextStatement = statements[i + 1]; 10684 Statement nextStatement = statements[i + 1];
10668 Statement lastStatement = statements[size - 1]; 10685 Statement lastStatement = statements[size - 1];
10669 int offset = nextStatement.offset; 10686 int offset = nextStatement.offset;
10670 int length = lastStatement.end - offset; 10687 int length = lastStatement.end - offset;
10671 _errorReporter.reportError3(AuditCode.DEAD_CODE, offset, length, []); 10688 _errorReporter.reportError3(HintCode.DEAD_CODE, offset, length, []);
10672 return true; 10689 return true;
10673 } 10690 }
10674 } 10691 }
10675 return false; 10692 return false;
10676 } 10693 }
10677 10694
10678 /** 10695 /**
10679 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i t is 10696 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i t is
10680 * `true`, [ValidResult#RESULT_FALSE] if it is `false`, or `null` if the 10697 * `true`, [ValidResult#RESULT_FALSE] if it is `false`, or `null` if the
10681 * expression is not a constant boolean value. 10698 * expression is not a constant boolean value.
(...skipping 13 matching lines...) Expand all
10695 } else { 10712 } else {
10696 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); 10713 EvaluationResultImpl result = expression.accept(new ConstantVisitor());
10697 if (identical(result, ValidResult.RESULT_TRUE)) { 10714 if (identical(result, ValidResult.RESULT_TRUE)) {
10698 return ValidResult.RESULT_TRUE; 10715 return ValidResult.RESULT_TRUE;
10699 } else if (identical(result, ValidResult.RESULT_FALSE)) { 10716 } else if (identical(result, ValidResult.RESULT_FALSE)) {
10700 return ValidResult.RESULT_FALSE; 10717 return ValidResult.RESULT_FALSE;
10701 } 10718 }
10702 return null; 10719 return null;
10703 } 10720 }
10704 } 10721 }
10722
10723 /**
10724 * If the given node is not `null`, visit this instance of the dead code verif ier.
10725 *
10726 * @param node the node to be visited
10727 */
10728 void safelyVisit(ASTNode node) {
10729 if (node != null) {
10730 node.accept(this);
10731 }
10732 }
10705 } 10733 }
10706 /** 10734 /**
10707 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional 10735 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional
10708 * errors and warnings not covered by the parser and resolver. 10736 * errors and warnings not covered by the parser and resolver.
10709 * 10737 *
10710 * @coverage dart.engine.resolver 10738 * @coverage dart.engine.resolver
10711 */ 10739 */
10712 class ErrorVerifier extends RecursiveASTVisitor<Object> { 10740 class ErrorVerifier extends RecursiveASTVisitor<Object> {
10713 10741
10714 /** 10742 /**
(...skipping 3413 matching lines...) Expand 10 before | Expand all | Expand 10 after
14128 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F ORMAL', 2); 14156 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F ORMAL', 2);
14129 static final INIT_STATE INIT_IN_DEFAULT_VALUE = new INIT_STATE('INIT_IN_DEFAUL T_VALUE', 3); 14157 static final INIT_STATE INIT_IN_DEFAULT_VALUE = new INIT_STATE('INIT_IN_DEFAUL T_VALUE', 3);
14130 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL IZERS', 4); 14158 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL IZERS', 4);
14131 static final List<INIT_STATE> values = [NOT_INIT, INIT_IN_DECLARATION, INIT_IN _FIELD_FORMAL, INIT_IN_DEFAULT_VALUE, INIT_IN_INITIALIZERS]; 14159 static final List<INIT_STATE> values = [NOT_INIT, INIT_IN_DECLARATION, INIT_IN _FIELD_FORMAL, INIT_IN_DEFAULT_VALUE, INIT_IN_INITIALIZERS];
14132 14160
14133 /// The name of this enum constant, as declared in the enum declaration. 14161 /// The name of this enum constant, as declared in the enum declaration.
14134 final String name; 14162 final String name;
14135 14163
14136 /// The position in the enum declaration. 14164 /// The position in the enum declaration.
14137 final int ordinal; 14165 final int ordinal;
14138 INIT_STATE(this.name, this.ordinal) { 14166 INIT_STATE(this.name, this.ordinal);
14139 }
14140 int compareTo(INIT_STATE other) => ordinal - other.ordinal; 14167 int compareTo(INIT_STATE other) => ordinal - other.ordinal;
14141 int get hashCode => ordinal; 14168 int get hashCode => ordinal;
14142 String toString() => name; 14169 String toString() => name;
14143 } 14170 }
14144 /** 14171 /**
14172 * Instances of the class `HintVerifier` traverse an AST structure looking for a dditional
14173 * additional suggestions not mentioned in the Dart Language Specification.
14174 *
14175 * @coverage dart.engine.resolver
14176 */
14177 class HintVerifier {
14178 DeadCodeVerifier _deadCodeVerifier;
14179 HintVerifier(AnalysisContext context, ErrorReporter errorReporter) {
14180 _deadCodeVerifier = new DeadCodeVerifier(errorReporter);
14181 }
14182 void visitCompilationUnit(CompilationUnit node) {
14183 node.accept(_deadCodeVerifier);
14184 }
14185 }
14186 /**
14145 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from 14187 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from
14146 * pub best practices. 14188 * pub best practices.
14147 */ 14189 */
14148 class PubVerifier extends RecursiveASTVisitor<Object> { 14190 class PubVerifier extends RecursiveASTVisitor<Object> {
14149 static String _PUBSPEC_YAML = "pubspec.yaml"; 14191 static String _PUBSPEC_YAML = "pubspec.yaml";
14150 14192
14151 /** 14193 /**
14152 * The analysis context containing the sources to be analyzed 14194 * The analysis context containing the sources to be analyzed
14153 */ 14195 */
14154 AnalysisContext _context; 14196 AnalysisContext _context;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
14333 this._type = type; 14375 this._type = type;
14334 this._message = message; 14376 this._message = message;
14335 } 14377 }
14336 ErrorSeverity get errorSeverity => _type.severity; 14378 ErrorSeverity get errorSeverity => _type.severity;
14337 String get message => _message; 14379 String get message => _message;
14338 ErrorType get type => _type; 14380 ErrorType get type => _type;
14339 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; 14381 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal;
14340 int get hashCode => ordinal; 14382 int get hashCode => ordinal;
14341 String toString() => name; 14383 String toString() => name;
14342 } 14384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698