| OLD | NEW |
| 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 2421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 if (element.isFactory) { | 2432 if (element.isFactory) { |
| 2433 _resolver.reportError(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, n
ode, [element]); | 2433 _resolver.reportError(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, n
ode, [element]); |
| 2434 } | 2434 } |
| 2435 } | 2435 } |
| 2436 if (name != null) { | 2436 if (name != null) { |
| 2437 recordResolution(name, element); | 2437 recordResolution(name, element); |
| 2438 } | 2438 } |
| 2439 node.staticElement = element; | 2439 node.staticElement = element; |
| 2440 node.element = element; | 2440 node.element = element; |
| 2441 ArgumentList argumentList = node.argumentList; | 2441 ArgumentList argumentList = node.argumentList; |
| 2442 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu
mentList, element); | 2442 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo
nstructor, argumentList, element); |
| 2443 if (parameters != null) { | 2443 if (parameters != null) { |
| 2444 argumentList.correspondingStaticParameters = parameters; | 2444 argumentList.correspondingStaticParameters = parameters; |
| 2445 } | 2445 } |
| 2446 return null; | 2446 return null; |
| 2447 } | 2447 } |
| 2448 Object visitSuperExpression(SuperExpression node) { | 2448 Object visitSuperExpression(SuperExpression node) { |
| 2449 if (!isSuperInValidContext(node)) { | 2449 if (!isSuperInValidContext(node)) { |
| 2450 _resolver.reportError(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node,
[]); | 2450 _resolver.reportError(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node,
[]); |
| 2451 } | 2451 } |
| 2452 return super.visitSuperExpression(node); | 2452 return super.visitSuperExpression(node); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2747 return true; | 2747 return true; |
| 2748 } else if (type is InterfaceType) { | 2748 } else if (type is InterfaceType) { |
| 2749 ClassElement classElement = ((type as InterfaceType)).element; | 2749 ClassElement classElement = ((type as InterfaceType)).element; |
| 2750 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME,
_resolver.definingLibrary); | 2750 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME,
_resolver.definingLibrary); |
| 2751 return methodElement != null; | 2751 return methodElement != null; |
| 2752 } | 2752 } |
| 2753 return false; | 2753 return false; |
| 2754 } | 2754 } |
| 2755 | 2755 |
| 2756 /** | 2756 /** |
| 2757 * @return `true` iff current enclosing function is constant constructor decla
ration. |
| 2758 */ |
| 2759 bool get isInConstConstructor { |
| 2760 ExecutableElement function = _resolver.enclosingFunction; |
| 2761 if (function is ConstructorElement) { |
| 2762 return ((function as ConstructorElement)).isConst; |
| 2763 } |
| 2764 return false; |
| 2765 } |
| 2766 |
| 2767 /** |
| 2757 * Return `true` if the given element is a static element. | 2768 * Return `true` if the given element is a static element. |
| 2758 * | 2769 * |
| 2759 * @param element the element being tested | 2770 * @param element the element being tested |
| 2760 * @return `true` if the given element is a static element | 2771 * @return `true` if the given element is a static element |
| 2761 */ | 2772 */ |
| 2762 bool isStatic(Element element) { | 2773 bool isStatic(Element element) { |
| 2763 if (element is ExecutableElement) { | 2774 if (element is ExecutableElement) { |
| 2764 return ((element as ExecutableElement)).isStatic; | 2775 return ((element as ExecutableElement)).isStatic; |
| 2765 } else if (element is PropertyInducingElement) { | 2776 } else if (element is PropertyInducingElement) { |
| 2766 return ((element as PropertyInducingElement)).isStatic; | 2777 return ((element as PropertyInducingElement)).isStatic; |
| (...skipping 1987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4754 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveEmbeddedLibrary"); | 4765 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveEmbeddedLibrary"); |
| 4755 try { | 4766 try { |
| 4756 instrumentation.metric("fullAnalysis", fullAnalysis); | 4767 instrumentation.metric("fullAnalysis", fullAnalysis); |
| 4757 instrumentation.data3("fullName", librarySource.fullName); | 4768 instrumentation.data3("fullName", librarySource.fullName); |
| 4758 Library targetLibrary = createLibrary2(librarySource, unit); | 4769 Library targetLibrary = createLibrary2(librarySource, unit); |
| 4759 _coreLibrary = _libraryMap[_coreLibrarySource]; | 4770 _coreLibrary = _libraryMap[_coreLibrarySource]; |
| 4760 if (_coreLibrary == null) { | 4771 if (_coreLibrary == null) { |
| 4761 _coreLibrary = createLibrary(_coreLibrarySource); | 4772 _coreLibrary = createLibrary(_coreLibrarySource); |
| 4762 } | 4773 } |
| 4763 instrumentation.metric3("createLibrary", "complete"); | 4774 instrumentation.metric3("createLibrary", "complete"); |
| 4764 computeLibraryDependencies(targetLibrary); | 4775 computeLibraryDependencies2(targetLibrary, unit); |
| 4765 _librariesInCycles = computeLibrariesInCycles(targetLibrary); | 4776 _librariesInCycles = computeLibrariesInCycles(targetLibrary); |
| 4766 buildElementModels(); | 4777 buildElementModels(); |
| 4767 instrumentation.metric3("buildElementModels", "complete"); | 4778 instrumentation.metric3("buildElementModels", "complete"); |
| 4768 LibraryElement coreElement = _coreLibrary.libraryElement; | 4779 LibraryElement coreElement = _coreLibrary.libraryElement; |
| 4769 if (coreElement == null) { | 4780 if (coreElement == null) { |
| 4770 throw new AnalysisException.con1("Could not resolve dart:core"); | 4781 throw new AnalysisException.con1("Could not resolve dart:core"); |
| 4771 } | 4782 } |
| 4772 buildDirectiveModels(); | 4783 buildDirectiveModels(); |
| 4773 instrumentation.metric3("buildDirectiveModels", "complete"); | 4784 instrumentation.metric3("buildDirectiveModels", "complete"); |
| 4774 _typeProvider = new TypeProviderImpl(coreElement); | 4785 _typeProvider = new TypeProviderImpl(coreElement); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5065 | 5076 |
| 5066 /** | 5077 /** |
| 5067 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the | 5078 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the |
| 5068 * class [Library] to represent them, and record the references in the library
objects. | 5079 * class [Library] to represent them, and record the references in the library
objects. |
| 5069 * | 5080 * |
| 5070 * @param library the library to be processed to find libraries that have not
yet been traversed | 5081 * @param library the library to be processed to find libraries that have not
yet been traversed |
| 5071 * @throws AnalysisException if some portion of the library graph could not be
traversed | 5082 * @throws AnalysisException if some portion of the library graph could not be
traversed |
| 5072 */ | 5083 */ |
| 5073 void computeLibraryDependencies(Library library) { | 5084 void computeLibraryDependencies(Library library) { |
| 5074 Source librarySource = library.librarySource; | 5085 Source librarySource = library.librarySource; |
| 5086 computeLibraryDependencies3(library, _analysisContext.computeImportedLibrari
es(librarySource), _analysisContext.computeExportedLibraries(librarySource)); |
| 5087 } |
| 5088 |
| 5089 /** |
| 5090 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the |
| 5091 * class [Library] to represent them, and record the references in the library
objects. |
| 5092 * |
| 5093 * @param library the library to be processed to find libraries that have not
yet been traversed |
| 5094 * @throws AnalysisException if some portion of the library graph could not be
traversed |
| 5095 */ |
| 5096 void computeLibraryDependencies2(Library library, CompilationUnit unit) { |
| 5097 Source librarySource = library.librarySource; |
| 5098 Set<Source> exportedSources = new Set<Source>(); |
| 5099 Set<Source> importedSources = new Set<Source>(); |
| 5100 for (Directive directive in unit.directives) { |
| 5101 if (directive is ExportDirective) { |
| 5102 Source exportSource = resolveSource(librarySource, (directive as ExportD
irective)); |
| 5103 if (exportSource != null) { |
| 5104 javaSetAdd(exportedSources, exportSource); |
| 5105 } |
| 5106 } else if (directive is ImportDirective) { |
| 5107 Source importSource = resolveSource(librarySource, (directive as ImportD
irective)); |
| 5108 if (importSource != null) { |
| 5109 javaSetAdd(importedSources, importSource); |
| 5110 } |
| 5111 } |
| 5112 } |
| 5113 computeLibraryDependencies3(library, new List.from(importedSources), new Lis
t.from(exportedSources)); |
| 5114 } |
| 5115 |
| 5116 /** |
| 5117 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the |
| 5118 * class [Library] to represent them, and record the references in the library
objects. |
| 5119 * |
| 5120 * @param library the library to be processed to find libraries that have not
yet been traversed |
| 5121 * @param importedSources an array containing the sources that are imported in
to the given library |
| 5122 * @param exportedSources an array containing the sources that are exported fr
om the given library |
| 5123 * @throws AnalysisException if some portion of the library graph could not be
traversed |
| 5124 */ |
| 5125 void computeLibraryDependencies3(Library library, List<Source> importedSources
, List<Source> exportedSources) { |
| 5075 List<Library> importedLibraries = new List<Library>(); | 5126 List<Library> importedLibraries = new List<Library>(); |
| 5076 bool explicitlyImportsCore = false; | 5127 bool explicitlyImportsCore = false; |
| 5077 for (Source importedSource in _analysisContext.computeImportedLibraries(libr
arySource)) { | 5128 for (Source importedSource in importedSources) { |
| 5078 if (importedSource == _coreLibrarySource) { | 5129 if (importedSource == _coreLibrarySource) { |
| 5079 explicitlyImportsCore = true; | 5130 explicitlyImportsCore = true; |
| 5080 } | 5131 } |
| 5081 Library importedLibrary = _libraryMap[importedSource]; | 5132 Library importedLibrary = _libraryMap[importedSource]; |
| 5082 if (importedLibrary == null) { | 5133 if (importedLibrary == null) { |
| 5083 importedLibrary = createLibraryOrNull(importedSource); | 5134 importedLibrary = createLibraryOrNull(importedSource); |
| 5084 if (importedLibrary != null) { | 5135 if (importedLibrary != null) { |
| 5085 computeLibraryDependencies(importedLibrary); | 5136 computeLibraryDependencies(importedLibrary); |
| 5086 } | 5137 } |
| 5087 } | 5138 } |
| 5088 if (importedLibrary != null) { | 5139 if (importedLibrary != null) { |
| 5089 importedLibraries.add(importedLibrary); | 5140 importedLibraries.add(importedLibrary); |
| 5090 } | 5141 } |
| 5091 } | 5142 } |
| 5092 library.importedLibraries = new List.from(importedLibraries); | 5143 library.importedLibraries = new List.from(importedLibraries); |
| 5093 List<Library> exportedLibraries = new List<Library>(); | 5144 List<Library> exportedLibraries = new List<Library>(); |
| 5094 for (Source exportedSource in _analysisContext.computeExportedLibraries(libr
arySource)) { | 5145 for (Source exportedSource in exportedSources) { |
| 5095 Library exportedLibrary = _libraryMap[exportedSource]; | 5146 Library exportedLibrary = _libraryMap[exportedSource]; |
| 5096 if (exportedLibrary == null) { | 5147 if (exportedLibrary == null) { |
| 5097 exportedLibrary = createLibraryOrNull(exportedSource); | 5148 exportedLibrary = createLibraryOrNull(exportedSource); |
| 5098 if (exportedLibrary != null) { | 5149 if (exportedLibrary != null) { |
| 5099 computeLibraryDependencies(exportedLibrary); | 5150 computeLibraryDependencies(exportedLibrary); |
| 5100 } | 5151 } |
| 5101 } | 5152 } |
| 5102 if (exportedLibrary != null) { | 5153 if (exportedLibrary != null) { |
| 5103 exportedLibraries.add(exportedLibrary); | 5154 exportedLibraries.add(exportedLibrary); |
| 5104 } | 5155 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5239 * the library cannot be analyzed | 5290 * the library cannot be analyzed |
| 5240 */ | 5291 */ |
| 5241 void resolveReferencesAndTypes2(Library library) { | 5292 void resolveReferencesAndTypes2(Library library) { |
| 5242 for (Source source in library.compilationUnitSources) { | 5293 for (Source source in library.compilationUnitSources) { |
| 5243 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); | 5294 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); |
| 5244 library.getAST(source).accept(visitor); | 5295 library.getAST(source).accept(visitor); |
| 5245 } | 5296 } |
| 5246 } | 5297 } |
| 5247 | 5298 |
| 5248 /** | 5299 /** |
| 5300 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
| 5301 * given library, or `null` if the URI is not valid. |
| 5302 * |
| 5303 * @param librarySource the source representing the library containing the dir
ective |
| 5304 * @param directive the directive which URI should be resolved |
| 5305 * @return the result of resolving the URI against the URI of the library |
| 5306 */ |
| 5307 Source resolveSource(Source librarySource, UriBasedDirective directive) { |
| 5308 StringLiteral uriLiteral = directive.uri; |
| 5309 if (uriLiteral is StringInterpolation) { |
| 5310 return null; |
| 5311 } |
| 5312 String uriContent = uriLiteral.stringValue.trim(); |
| 5313 if (uriContent == null) { |
| 5314 return null; |
| 5315 } |
| 5316 try { |
| 5317 parseUriWithException(uriContent); |
| 5318 return _analysisContext.sourceFactory.resolveUri(librarySource, uriContent
); |
| 5319 } on URISyntaxException catch (exception) { |
| 5320 return null; |
| 5321 } |
| 5322 } |
| 5323 |
| 5324 /** |
| 5249 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier] | 5325 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier] |
| 5250 * analysis in the current cycle. | 5326 * analysis in the current cycle. |
| 5251 * | 5327 * |
| 5252 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 5328 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 5253 * the library cannot be analyzed | 5329 * the library cannot be analyzed |
| 5254 */ | 5330 */ |
| 5255 void runAdditionalAnalyses() { | 5331 void runAdditionalAnalyses() { |
| 5256 for (Library library in _librariesInCycles) { | 5332 for (Library library in _librariesInCycles) { |
| 5257 runAdditionalAnalyses2(library); | 5333 runAdditionalAnalyses2(library); |
| 5258 } | 5334 } |
| (...skipping 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7156 } | 7232 } |
| 7157 Type2 staticStaticType = computeStaticReturnType(staticMethodElement); | 7233 Type2 staticStaticType = computeStaticReturnType(staticMethodElement); |
| 7158 recordStaticType(node, staticStaticType); | 7234 recordStaticType(node, staticStaticType); |
| 7159 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement
); | 7235 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement
); |
| 7160 if (staticPropagatedType != null && (staticStaticType == null || staticPropa
gatedType.isMoreSpecificThan(staticStaticType))) { | 7236 if (staticPropagatedType != null && (staticStaticType == null || staticPropa
gatedType.isMoreSpecificThan(staticStaticType))) { |
| 7161 recordPropagatedType2(node, staticPropagatedType); | 7237 recordPropagatedType2(node, staticPropagatedType); |
| 7162 } | 7238 } |
| 7163 String methodName = methodNameNode.name; | 7239 String methodName = methodNameNode.name; |
| 7164 if (methodName == "then") { | 7240 if (methodName == "then") { |
| 7165 Expression target = node.realTarget; | 7241 Expression target = node.realTarget; |
| 7166 Type2 targetType = getBestType(target); | 7242 Type2 targetType = target == null ? null : getBestType(target); |
| 7167 if (isAsyncFutureType(targetType)) { | 7243 if (isAsyncFutureType(targetType)) { |
| 7168 NodeList<Expression> arguments = node.argumentList.arguments; | 7244 NodeList<Expression> arguments = node.argumentList.arguments; |
| 7169 if (arguments.length == 1) { | 7245 if (arguments.length == 1) { |
| 7170 Expression closureArg = arguments[0]; | 7246 Expression closureArg = arguments[0]; |
| 7171 if (closureArg is FunctionExpression) { | 7247 if (closureArg is FunctionExpression) { |
| 7172 FunctionExpression closureExpr = closureArg as FunctionExpression; | 7248 FunctionExpression closureExpr = closureArg as FunctionExpression; |
| 7173 Type2 returnType = computePropagatedReturnType(closureExpr.element); | 7249 Type2 returnType = computePropagatedReturnType(closureExpr.element); |
| 7174 if (returnType != null) { | 7250 if (returnType != null) { |
| 7175 InterfaceTypeImpl newFutureType; | 7251 InterfaceTypeImpl newFutureType; |
| 7176 if (isAsyncFutureType(returnType)) { | 7252 if (isAsyncFutureType(returnType)) { |
| (...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8556 return null; | 8632 return null; |
| 8557 } | 8633 } |
| 8558 Object visitClassDeclaration(ClassDeclaration node) { | 8634 Object visitClassDeclaration(ClassDeclaration node) { |
| 8559 _hasReferenceToSuper = false; | 8635 _hasReferenceToSuper = false; |
| 8560 super.visitClassDeclaration(node); | 8636 super.visitClassDeclaration(node); |
| 8561 ClassElementImpl classElement = getClassElement(node.name); | 8637 ClassElementImpl classElement = getClassElement(node.name); |
| 8562 InterfaceType superclassType = null; | 8638 InterfaceType superclassType = null; |
| 8563 ExtendsClause extendsClause = node.extendsClause; | 8639 ExtendsClause extendsClause = node.extendsClause; |
| 8564 if (extendsClause != null) { | 8640 if (extendsClause != null) { |
| 8565 ErrorCode errorCode = node.withClause == null ? CompileTimeErrorCode.EXTEN
DS_NON_CLASS : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS; | 8641 ErrorCode errorCode = node.withClause == null ? CompileTimeErrorCode.EXTEN
DS_NON_CLASS : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS; |
| 8566 superclassType = resolveType(extendsClause.superclass, errorCode); | 8642 superclassType = resolveType(extendsClause.superclass, errorCode, errorCod
e); |
| 8567 if (superclassType != typeProvider.objectType) { | 8643 if (superclassType != typeProvider.objectType) { |
| 8568 classElement.validMixin = false; | 8644 classElement.validMixin = false; |
| 8569 } | 8645 } |
| 8570 } | 8646 } |
| 8571 if (classElement != null) { | 8647 if (classElement != null) { |
| 8572 if (superclassType == null) { | 8648 if (superclassType == null) { |
| 8573 InterfaceType objectType = typeProvider.objectType; | 8649 InterfaceType objectType = typeProvider.objectType; |
| 8574 if (classElement.type != objectType) { | 8650 if (classElement.type != objectType) { |
| 8575 superclassType = objectType; | 8651 superclassType = objectType; |
| 8576 } | 8652 } |
| 8577 } | 8653 } |
| 8578 classElement.supertype = superclassType; | 8654 classElement.supertype = superclassType; |
| 8579 classElement.hasReferenceToSuper2 = _hasReferenceToSuper; | 8655 classElement.hasReferenceToSuper2 = _hasReferenceToSuper; |
| 8580 } | 8656 } |
| 8581 resolve(classElement, node.withClause, node.implementsClause); | 8657 resolve(classElement, node.withClause, node.implementsClause); |
| 8582 return null; | 8658 return null; |
| 8583 } | 8659 } |
| 8584 Object visitClassTypeAlias(ClassTypeAlias node) { | 8660 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 8585 super.visitClassTypeAlias(node); | 8661 super.visitClassTypeAlias(node); |
| 8586 ClassElementImpl classElement = getClassElement(node.name); | 8662 ClassElementImpl classElement = getClassElement(node.name); |
| 8587 InterfaceType superclassType = resolveType(node.superclass, CompileTimeError
Code.MIXIN_WITH_NON_CLASS_SUPERCLASS); | 8663 ErrorCode errorCode = CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS; |
| 8664 InterfaceType superclassType = resolveType(node.superclass, errorCode, error
Code); |
| 8588 if (superclassType == null) { | 8665 if (superclassType == null) { |
| 8589 superclassType = typeProvider.objectType; | 8666 superclassType = typeProvider.objectType; |
| 8590 } | 8667 } |
| 8591 if (classElement != null && superclassType != null) { | 8668 if (classElement != null && superclassType != null) { |
| 8592 classElement.supertype = superclassType; | 8669 classElement.supertype = superclassType; |
| 8593 } | 8670 } |
| 8594 resolve(classElement, node.withClause, node.implementsClause); | 8671 resolve(classElement, node.withClause, node.implementsClause); |
| 8595 return null; | 8672 return null; |
| 8596 } | 8673 } |
| 8597 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 8674 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9177 * Resolve the types in the given with and implements clauses and associate th
ose types with the | 9254 * Resolve the types in the given with and implements clauses and associate th
ose types with the |
| 9178 * given class element. | 9255 * given class element. |
| 9179 * | 9256 * |
| 9180 * @param classElement the class element with which the mixin and interface ty
pes are to be | 9257 * @param classElement the class element with which the mixin and interface ty
pes are to be |
| 9181 * associated | 9258 * associated |
| 9182 * @param withClause the with clause to be resolved | 9259 * @param withClause the with clause to be resolved |
| 9183 * @param implementsClause the implements clause to be resolved | 9260 * @param implementsClause the implements clause to be resolved |
| 9184 */ | 9261 */ |
| 9185 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC
lause implementsClause) { | 9262 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC
lause implementsClause) { |
| 9186 if (withClause != null) { | 9263 if (withClause != null) { |
| 9187 List<InterfaceType> mixinTypes = resolveTypes(withClause.mixinTypes, Compi
leTimeErrorCode.MIXIN_OF_NON_CLASS); | 9264 List<InterfaceType> mixinTypes = resolveTypes(withClause.mixinTypes, Compi
leTimeErrorCode.MIXIN_OF_NON_CLASS, CompileTimeErrorCode.MIXIN_OF_NON_CLASS); |
| 9188 if (classElement != null) { | 9265 if (classElement != null) { |
| 9189 classElement.mixins = mixinTypes; | 9266 classElement.mixins = mixinTypes; |
| 9190 } | 9267 } |
| 9191 } | 9268 } |
| 9192 if (implementsClause != null) { | 9269 if (implementsClause != null) { |
| 9193 NodeList<TypeName> interfaces = implementsClause.interfaces; | 9270 NodeList<TypeName> interfaces = implementsClause.interfaces; |
| 9194 List<InterfaceType> interfaceTypes = resolveTypes(interfaces, CompileTimeE
rrorCode.IMPLEMENTS_NON_CLASS); | 9271 List<InterfaceType> interfaceTypes = resolveTypes(interfaces, CompileTimeE
rrorCode.IMPLEMENTS_NON_CLASS, CompileTimeErrorCode.IMPLEMENTS_DYNAMIC); |
| 9195 List<TypeName> typeNames = new List.from(interfaces); | 9272 List<TypeName> typeNames = new List.from(interfaces); |
| 9196 String dynamicKeyword = sc.Keyword.DYNAMIC.syntax; | |
| 9197 List<bool> detectedRepeatOnIndex = new List<bool>.filled(typeNames.length,
false); | 9273 List<bool> detectedRepeatOnIndex = new List<bool>.filled(typeNames.length,
false); |
| 9198 for (int i = 0; i < detectedRepeatOnIndex.length; i++) { | 9274 for (int i = 0; i < detectedRepeatOnIndex.length; i++) { |
| 9199 detectedRepeatOnIndex[i] = false; | 9275 detectedRepeatOnIndex[i] = false; |
| 9200 } | 9276 } |
| 9201 for (int i = 0; i < typeNames.length; i++) { | 9277 for (int i = 0; i < typeNames.length; i++) { |
| 9202 TypeName typeName = typeNames[i]; | 9278 TypeName typeName = typeNames[i]; |
| 9203 String name = typeName.name.name; | |
| 9204 if (name == dynamicKeyword) { | |
| 9205 reportError(CompileTimeErrorCode.IMPLEMENTS_DYNAMIC, typeName, []); | |
| 9206 } | |
| 9207 if (!detectedRepeatOnIndex[i]) { | 9279 if (!detectedRepeatOnIndex[i]) { |
| 9208 for (int j = i + 1; j < typeNames.length; j++) { | 9280 for (int j = i + 1; j < typeNames.length; j++) { |
| 9209 Element element = typeName.name.element; | 9281 Element element = typeName.name.element; |
| 9210 TypeName typeName2 = typeNames[j]; | 9282 TypeName typeName2 = typeNames[j]; |
| 9211 Identifier identifier2 = typeName2.name; | 9283 Identifier identifier2 = typeName2.name; |
| 9212 String name2 = identifier2.name; | 9284 String name2 = identifier2.name; |
| 9213 Element element2 = identifier2.element; | 9285 Element element2 = identifier2.element; |
| 9214 if (element != null && element == element2) { | 9286 if (element != null && element == element2) { |
| 9215 detectedRepeatOnIndex[j] = true; | 9287 detectedRepeatOnIndex[j] = true; |
| 9216 reportError(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [
name2]); | 9288 reportError(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [
name2]); |
| 9217 } | 9289 } |
| 9218 } | 9290 } |
| 9219 } | 9291 } |
| 9220 } | 9292 } |
| 9221 if (classElement != null) { | 9293 if (classElement != null) { |
| 9222 classElement.interfaces = interfaceTypes; | 9294 classElement.interfaces = interfaceTypes; |
| 9223 } | 9295 } |
| 9224 } | 9296 } |
| 9225 } | 9297 } |
| 9226 | 9298 |
| 9227 /** | 9299 /** |
| 9228 * Return the type specified by the given name. | 9300 * Return the type specified by the given name. |
| 9229 * | 9301 * |
| 9230 * @param typeName the type name specifying the type to be returned | 9302 * @param typeName the type name specifying the type to be returned |
| 9231 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 9303 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
| 9232 * a type | 9304 * a type |
| 9305 * @param dynamicTypeError the error to produce if the type name is "dynamic" |
| 9233 * @return the type specified by the type name | 9306 * @return the type specified by the type name |
| 9234 */ | 9307 */ |
| 9235 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError) { | 9308 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode
dynamicTypeError) { |
| 9236 Type2 type = typeName.type; | 9309 Type2 type = typeName.type; |
| 9237 if (type is InterfaceType) { | 9310 if (type is InterfaceType) { |
| 9238 return type as InterfaceType; | 9311 return type as InterfaceType; |
| 9239 } | 9312 } |
| 9240 Identifier name = typeName.name; | 9313 Identifier name = typeName.name; |
| 9241 if (name.name != sc.Keyword.DYNAMIC.syntax) { | 9314 if (name.name == sc.Keyword.DYNAMIC.syntax) { |
| 9315 reportError(dynamicTypeError, name, [name.name]); |
| 9316 } else { |
| 9242 reportError(nonTypeError, name, [name.name]); | 9317 reportError(nonTypeError, name, [name.name]); |
| 9243 } | 9318 } |
| 9244 return null; | 9319 return null; |
| 9245 } | 9320 } |
| 9246 | 9321 |
| 9247 /** | 9322 /** |
| 9248 * Resolve the types in the given list of type names. | 9323 * Resolve the types in the given list of type names. |
| 9249 * | 9324 * |
| 9250 * @param typeNames the type names to be resolved | 9325 * @param typeNames the type names to be resolved |
| 9251 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 9326 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
| 9252 * a type | 9327 * a type |
| 9328 * @param dynamicTypeError the error to produce if the type name is "dynamic" |
| 9253 * @return an array containing all of the types that were resolved. | 9329 * @return an array containing all of the types that were resolved. |
| 9254 */ | 9330 */ |
| 9255 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy
peError) { | 9331 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy
peError, ErrorCode dynamicTypeError) { |
| 9256 List<InterfaceType> types = new List<InterfaceType>(); | 9332 List<InterfaceType> types = new List<InterfaceType>(); |
| 9257 for (TypeName typeName in typeNames) { | 9333 for (TypeName typeName in typeNames) { |
| 9258 InterfaceType type = resolveType(typeName, nonTypeError); | 9334 InterfaceType type = resolveType(typeName, nonTypeError, dynamicTypeError)
; |
| 9259 if (type != null) { | 9335 if (type != null) { |
| 9260 types.add(type); | 9336 types.add(type); |
| 9261 } | 9337 } |
| 9262 } | 9338 } |
| 9263 return new List.from(types); | 9339 return new List.from(types); |
| 9264 } | 9340 } |
| 9265 void setElement(Identifier typeName, Element element2) { | 9341 void setElement(Identifier typeName, Element element2) { |
| 9266 if (element2 != null) { | 9342 if (element2 != null) { |
| 9267 if (typeName is SimpleIdentifier) { | 9343 if (typeName is SimpleIdentifier) { |
| 9268 ((typeName as SimpleIdentifier)).staticElement = element2; | 9344 ((typeName as SimpleIdentifier)).staticElement = element2; |
| (...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10819 | 10895 |
| 10820 /** | 10896 /** |
| 10821 * This is set to `true` iff the visitor is currently visiting children nodes
of a | 10897 * This is set to `true` iff the visitor is currently visiting children nodes
of a |
| 10822 * [CatchClause]. | 10898 * [CatchClause]. |
| 10823 * | 10899 * |
| 10824 * @see #visitCatchClause(CatchClause) | 10900 * @see #visitCatchClause(CatchClause) |
| 10825 */ | 10901 */ |
| 10826 bool _isInCatchClause = false; | 10902 bool _isInCatchClause = false; |
| 10827 | 10903 |
| 10828 /** | 10904 /** |
| 10905 * This is set to `true` iff the visitor is currently visiting children nodes
of an |
| 10906 * [InstanceCreationExpression]. |
| 10907 */ |
| 10908 bool _isInConstInstanceCreation = false; |
| 10909 |
| 10910 /** |
| 10911 * This is set to `true` iff the visitor is currently visiting children nodes
of a native |
| 10912 * [ClassDeclaration]. |
| 10913 */ |
| 10914 bool _isInNativeClass = false; |
| 10915 |
| 10916 /** |
| 10829 * This is set to `true` iff the visitor is currently visiting a static variab
le | 10917 * This is set to `true` iff the visitor is currently visiting a static variab
le |
| 10830 * declaration. | 10918 * declaration. |
| 10831 */ | 10919 */ |
| 10832 bool _isInStaticVariableDeclaration = false; | 10920 bool _isInStaticVariableDeclaration = false; |
| 10833 | 10921 |
| 10834 /** | 10922 /** |
| 10835 * This is set to `true` iff the visitor is currently visiting an instance var
iable | 10923 * This is set to `true` iff the visitor is currently visiting an instance var
iable |
| 10836 * declaration. | 10924 * declaration. |
| 10837 */ | 10925 */ |
| 10838 bool _isInInstanceVariableDeclaration = false; | 10926 bool _isInInstanceVariableDeclaration = false; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10922 this._inheritanceManager = inheritanceManager; | 11010 this._inheritanceManager = inheritanceManager; |
| 10923 _strictMode = currentLibrary.context.analysisOptions.strictMode; | 11011 _strictMode = currentLibrary.context.analysisOptions.strictMode; |
| 10924 _isEnclosingConstructorConst = false; | 11012 _isEnclosingConstructorConst = false; |
| 10925 _isInCatchClause = false; | 11013 _isInCatchClause = false; |
| 10926 _isInStaticVariableDeclaration = false; | 11014 _isInStaticVariableDeclaration = false; |
| 10927 _isInInstanceVariableDeclaration = false; | 11015 _isInInstanceVariableDeclaration = false; |
| 10928 _isInInstanceVariableInitializer = false; | 11016 _isInInstanceVariableInitializer = false; |
| 10929 _isInConstructorInitializer = false; | 11017 _isInConstructorInitializer = false; |
| 10930 _isInStaticMethod = false; | 11018 _isInStaticMethod = false; |
| 10931 _dynamicType = typeProvider.dynamicType; | 11019 _dynamicType = typeProvider.dynamicType; |
| 10932 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [typeProvider.num
Type, typeProvider.intType, typeProvider.doubleType, typeProvider.boolType, type
Provider.stringType]; | 11020 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [ |
| 11021 typeProvider.numType, |
| 11022 typeProvider.intType, |
| 11023 typeProvider.doubleType, |
| 11024 typeProvider.boolType, |
| 11025 typeProvider.stringType]; |
| 10933 } | 11026 } |
| 10934 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { | 11027 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { |
| 10935 checkForArgumentDefinitionTestNonParameter(node); | 11028 checkForArgumentDefinitionTestNonParameter(node); |
| 10936 return super.visitArgumentDefinitionTest(node); | 11029 return super.visitArgumentDefinitionTest(node); |
| 10937 } | 11030 } |
| 10938 Object visitArgumentList(ArgumentList node) { | 11031 Object visitArgumentList(ArgumentList node) { |
| 10939 checkForArgumentTypeNotAssignable(node); | 11032 checkForArgumentTypeNotAssignable(node); |
| 10940 return super.visitArgumentList(node); | 11033 return super.visitArgumentList(node); |
| 10941 } | 11034 } |
| 10942 Object visitAssertStatement(AssertStatement node) { | 11035 Object visitAssertStatement(AssertStatement node) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 10963 try { | 11056 try { |
| 10964 _isInCatchClause = true; | 11057 _isInCatchClause = true; |
| 10965 return super.visitCatchClause(node); | 11058 return super.visitCatchClause(node); |
| 10966 } finally { | 11059 } finally { |
| 10967 _isInCatchClause = previousIsInCatchClause; | 11060 _isInCatchClause = previousIsInCatchClause; |
| 10968 } | 11061 } |
| 10969 } | 11062 } |
| 10970 Object visitClassDeclaration(ClassDeclaration node) { | 11063 Object visitClassDeclaration(ClassDeclaration node) { |
| 10971 ClassElement outerClass = _enclosingClass; | 11064 ClassElement outerClass = _enclosingClass; |
| 10972 try { | 11065 try { |
| 11066 _isInNativeClass = node.nativeClause != null; |
| 10973 _enclosingClass = node.element; | 11067 _enclosingClass = node.element; |
| 10974 WithClause withClause = node.withClause; | 11068 WithClause withClause = node.withClause; |
| 10975 ImplementsClause implementsClause = node.implementsClause; | 11069 ImplementsClause implementsClause = node.implementsClause; |
| 10976 ExtendsClause extendsClause = node.extendsClause; | 11070 ExtendsClause extendsClause = node.extendsClause; |
| 10977 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I
DENTIFIER_AS_TYPE_NAME); | 11071 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I
DENTIFIER_AS_TYPE_NAME); |
| 10978 checkForMemberWithClassName(); | 11072 checkForMemberWithClassName(); |
| 10979 checkForNoDefaultSuperConstructorImplicit(node); | 11073 checkForNoDefaultSuperConstructorImplicit(node); |
| 10980 checkForAllMixinErrorCodes(withClause); | 11074 checkForAllMixinErrorCodes(withClause); |
| 10981 if (implementsClause != null || extendsClause != null) { | 11075 if (implementsClause != null || extendsClause != null) { |
| 10982 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt
endsDisallowedClass(extendsClause)) { | 11076 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt
endsDisallowedClass(extendsClause)) { |
| 10983 checkForNonAbstractClassInheritsAbstractMember(node); | 11077 checkForNonAbstractClassInheritsAbstractMember(node); |
| 10984 checkForInconsistentMethodInheritance(); | 11078 checkForInconsistentMethodInheritance(); |
| 10985 checkForRecursiveInterfaceInheritance(_enclosingClass, new List<ClassE
lement>()); | 11079 checkForRecursiveInterfaceInheritance(_enclosingClass, new List<ClassE
lement>()); |
| 10986 } | 11080 } |
| 10987 } | 11081 } |
| 10988 ClassElement classElement = node.element; | 11082 ClassElement classElement = node.element; |
| 10989 if (classElement != null) { | 11083 if (classElement != null) { |
| 10990 List<FieldElement> fieldElements = classElement.fields; | 11084 List<FieldElement> fieldElements = classElement.fields; |
| 10991 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); | 11085 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); |
| 10992 for (FieldElement fieldElement in fieldElements) { | 11086 for (FieldElement fieldElement in fieldElements) { |
| 10993 if (!fieldElement.isSynthetic) { | 11087 if (!fieldElement.isSynthetic) { |
| 10994 _initialFieldElementsMap[fieldElement] = fieldElement.initializer ==
null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; | 11088 _initialFieldElementsMap[fieldElement] = fieldElement.initializer ==
null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; |
| 10995 } | 11089 } |
| 10996 } | 11090 } |
| 10997 } | 11091 } |
| 10998 checkForFinalNotInitialized(node); | 11092 checkForFinalNotInitialized(node); |
| 10999 checkForDuplicateDefinitionInheritance(); | 11093 checkForDuplicateDefinitionInheritance(); |
| 11000 checkForConflictingGetterAndMethod(); | 11094 checkForConflictingGetterAndMethod(); |
| 11095 checkImplementsSuperClass(node); |
| 11001 return super.visitClassDeclaration(node); | 11096 return super.visitClassDeclaration(node); |
| 11002 } finally { | 11097 } finally { |
| 11098 _isInNativeClass = false; |
| 11003 _initialFieldElementsMap = null; | 11099 _initialFieldElementsMap = null; |
| 11004 _enclosingClass = outerClass; | 11100 _enclosingClass = outerClass; |
| 11005 } | 11101 } |
| 11006 } | 11102 } |
| 11007 Object visitClassTypeAlias(ClassTypeAlias node) { | 11103 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 11008 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); | 11104 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); |
| 11009 checkForAllMixinErrorCodes(node.withClause); | 11105 checkForAllMixinErrorCodes(node.withClause); |
| 11010 ClassElement outerClassElement = _enclosingClass; | 11106 ClassElement outerClassElement = _enclosingClass; |
| 11011 try { | 11107 try { |
| 11012 _enclosingClass = node.element; | 11108 _enclosingClass = node.element; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 11028 checkForConstConstructorWithNonFinalField(node); | 11124 checkForConstConstructorWithNonFinalField(node); |
| 11029 checkForConflictingConstructorNameAndMember(node); | 11125 checkForConflictingConstructorNameAndMember(node); |
| 11030 checkForAllFinalInitializedErrorCodes(node); | 11126 checkForAllFinalInitializedErrorCodes(node); |
| 11031 checkForRedirectingConstructorErrorCodes(node); | 11127 checkForRedirectingConstructorErrorCodes(node); |
| 11032 checkForMultipleSuperInitializers(node); | 11128 checkForMultipleSuperInitializers(node); |
| 11033 checkForRecursiveConstructorRedirect(node); | 11129 checkForRecursiveConstructorRedirect(node); |
| 11034 checkForRecursiveFactoryRedirect(node); | 11130 checkForRecursiveFactoryRedirect(node); |
| 11035 checkForAllRedirectConstructorErrorCodes(node); | 11131 checkForAllRedirectConstructorErrorCodes(node); |
| 11036 checkForUndefinedConstructorInInitializerImplicit(node); | 11132 checkForUndefinedConstructorInInitializerImplicit(node); |
| 11037 checkForRedirectToNonConstConstructor(node); | 11133 checkForRedirectToNonConstConstructor(node); |
| 11134 checkForReturnInGenerativeConstructor(node); |
| 11038 return super.visitConstructorDeclaration(node); | 11135 return super.visitConstructorDeclaration(node); |
| 11039 } finally { | 11136 } finally { |
| 11040 _isEnclosingConstructorConst = false; | 11137 _isEnclosingConstructorConst = false; |
| 11041 _enclosingFunction = outerFunction; | 11138 _enclosingFunction = outerFunction; |
| 11042 } | 11139 } |
| 11043 } | 11140 } |
| 11044 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | 11141 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 11045 _isInConstructorInitializer = true; | 11142 _isInConstructorInitializer = true; |
| 11046 try { | 11143 try { |
| 11047 checkForFieldInitializerNotAssignable(node); | 11144 checkForFieldInitializerNotAssignable(node); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 11069 Object visitFieldDeclaration(FieldDeclaration node) { | 11166 Object visitFieldDeclaration(FieldDeclaration node) { |
| 11070 if (!node.isStatic) { | 11167 if (!node.isStatic) { |
| 11071 VariableDeclarationList variables = node.fields; | 11168 VariableDeclarationList variables = node.fields; |
| 11072 if (variables.isConst) { | 11169 if (variables.isConst) { |
| 11073 _errorReporter.reportError4(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v
ariables.keyword, []); | 11170 _errorReporter.reportError4(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v
ariables.keyword, []); |
| 11074 } | 11171 } |
| 11075 } | 11172 } |
| 11076 _isInStaticVariableDeclaration = node.isStatic; | 11173 _isInStaticVariableDeclaration = node.isStatic; |
| 11077 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration; | 11174 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration; |
| 11078 try { | 11175 try { |
| 11176 checkForAllInvalidOverrideErrorCodes2(node); |
| 11079 return super.visitFieldDeclaration(node); | 11177 return super.visitFieldDeclaration(node); |
| 11080 } finally { | 11178 } finally { |
| 11081 _isInStaticVariableDeclaration = false; | 11179 _isInStaticVariableDeclaration = false; |
| 11082 _isInInstanceVariableDeclaration = false; | 11180 _isInInstanceVariableDeclaration = false; |
| 11083 } | 11181 } |
| 11084 } | 11182 } |
| 11085 Object visitFieldFormalParameter(FieldFormalParameter node) { | 11183 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 11086 checkForConstFormalParameter(node); | 11184 checkForConstFormalParameter(node); |
| 11087 checkForPrivateOptionalParameter(node); | 11185 checkForPrivateOptionalParameter(node); |
| 11088 checkForFieldInitializingFormalRedirectingConstructor(node); | 11186 checkForFieldInitializingFormalRedirectingConstructor(node); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11139 Object visitImportDirective(ImportDirective node) { | 11237 Object visitImportDirective(ImportDirective node) { |
| 11140 checkForImportDuplicateLibraryName(node); | 11238 checkForImportDuplicateLibraryName(node); |
| 11141 checkForImportInternalLibrary(node); | 11239 checkForImportInternalLibrary(node); |
| 11142 return super.visitImportDirective(node); | 11240 return super.visitImportDirective(node); |
| 11143 } | 11241 } |
| 11144 Object visitIndexExpression(IndexExpression node) { | 11242 Object visitIndexExpression(IndexExpression node) { |
| 11145 checkForArgumentTypeNotAssignable2(node.index); | 11243 checkForArgumentTypeNotAssignable2(node.index); |
| 11146 return super.visitIndexExpression(node); | 11244 return super.visitIndexExpression(node); |
| 11147 } | 11245 } |
| 11148 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 11246 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 11149 ConstructorName constructorName = node.constructorName; | 11247 _isInConstInstanceCreation = node.isConst; |
| 11150 TypeName typeName = constructorName.type; | 11248 try { |
| 11151 Type2 type = typeName.type; | 11249 ConstructorName constructorName = node.constructorName; |
| 11152 if (type is InterfaceType) { | 11250 TypeName typeName = constructorName.type; |
| 11153 InterfaceType interfaceType = type as InterfaceType; | 11251 Type2 type = typeName.type; |
| 11154 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); | 11252 if (type is InterfaceType) { |
| 11155 if (node.isConst) { | 11253 InterfaceType interfaceType = type as InterfaceType; |
| 11156 checkForConstWithNonConst(node); | 11254 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); |
| 11157 checkForConstWithUndefinedConstructor(node); | 11255 if (_isInConstInstanceCreation) { |
| 11158 checkForConstWithTypeParameters(node); | 11256 checkForConstWithNonConst(node); |
| 11159 } else { | 11257 checkForConstWithUndefinedConstructor(node); |
| 11160 checkForNewWithUndefinedConstructor(node); | 11258 checkForConstWithTypeParameters(node); |
| 11259 } else { |
| 11260 checkForNewWithUndefinedConstructor(node); |
| 11261 } |
| 11161 } | 11262 } |
| 11263 return super.visitInstanceCreationExpression(node); |
| 11264 } finally { |
| 11265 _isInConstInstanceCreation = false; |
| 11162 } | 11266 } |
| 11163 return super.visitInstanceCreationExpression(node); | |
| 11164 } | 11267 } |
| 11165 Object visitListLiteral(ListLiteral node) { | 11268 Object visitListLiteral(ListLiteral node) { |
| 11166 if (node.modifier != null) { | 11269 if (node.modifier != null) { |
| 11167 TypeArgumentList typeArguments = node.typeArguments; | 11270 TypeArgumentList typeArguments = node.typeArguments; |
| 11168 if (typeArguments != null) { | 11271 if (typeArguments != null) { |
| 11169 NodeList<TypeName> arguments = typeArguments.arguments; | 11272 NodeList<TypeName> arguments = typeArguments.arguments; |
| 11170 if (arguments.length != 0) { | 11273 if (arguments.length != 0) { |
| 11171 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE
rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); | 11274 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE
rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); |
| 11172 } | 11275 } |
| 11173 } | 11276 } |
| 11174 } | 11277 } |
| 11278 checkForListElementTypeNotAssignable(node); |
| 11175 return super.visitListLiteral(node); | 11279 return super.visitListLiteral(node); |
| 11176 } | 11280 } |
| 11177 Object visitMapLiteral(MapLiteral node) { | 11281 Object visitMapLiteral(MapLiteral node) { |
| 11178 TypeArgumentList typeArguments = node.typeArguments; | 11282 TypeArgumentList typeArguments = node.typeArguments; |
| 11179 if (typeArguments != null) { | 11283 if (typeArguments != null) { |
| 11180 NodeList<TypeName> arguments = typeArguments.arguments; | 11284 NodeList<TypeName> arguments = typeArguments.arguments; |
| 11181 if (arguments.length != 0) { | 11285 if (arguments.length != 0) { |
| 11182 checkForInvalidTypeArgumentForKey(arguments); | 11286 checkForInvalidTypeArgumentForKey(arguments); |
| 11183 if (node.modifier != null) { | 11287 if (node.modifier != null) { |
| 11184 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE
rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); | 11288 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE
rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); |
| 11185 } | 11289 } |
| 11186 } | 11290 } |
| 11187 } | 11291 } |
| 11188 checkForNonConstMapAsExpressionStatement(node); | 11292 checkForNonConstMapAsExpressionStatement(node); |
| 11293 checkForMapTypeNotAssignable(node); |
| 11189 return super.visitMapLiteral(node); | 11294 return super.visitMapLiteral(node); |
| 11190 } | 11295 } |
| 11191 Object visitMethodDeclaration(MethodDeclaration node) { | 11296 Object visitMethodDeclaration(MethodDeclaration node) { |
| 11192 ExecutableElement previousFunction = _enclosingFunction; | 11297 ExecutableElement previousFunction = _enclosingFunction; |
| 11193 try { | 11298 try { |
| 11194 _isInStaticMethod = node.isStatic; | 11299 _isInStaticMethod = node.isStatic; |
| 11195 _enclosingFunction = node.element; | 11300 _enclosingFunction = node.element; |
| 11196 SimpleIdentifier identifier = node.name; | 11301 SimpleIdentifier identifier = node.name; |
| 11197 String methodName = ""; | 11302 String methodName = ""; |
| 11198 if (identifier != null) { | 11303 if (identifier != null) { |
| 11199 methodName = identifier.name; | 11304 methodName = identifier.name; |
| 11200 } | 11305 } |
| 11201 if (node.isSetter || node.isGetter) { | 11306 if (node.isSetter || node.isGetter) { |
| 11202 checkForMismatchedAccessorTypes(node, methodName); | 11307 checkForMismatchedAccessorTypes(node, methodName); |
| 11203 checkForConflictingInstanceGetterAndSuperclassMember(node); | 11308 checkForConflictingInstanceGetterAndSuperclassMember(node); |
| 11204 } | 11309 } |
| 11205 if (node.isGetter) { | 11310 if (node.isGetter) { |
| 11206 checkForConflictingStaticGetterAndInstanceSetter(node); | 11311 checkForConflictingStaticGetterAndInstanceSetter(node); |
| 11207 } else if (node.isSetter) { | 11312 } else if (node.isSetter) { |
| 11208 checkForWrongNumberOfParametersForSetter(node.name, node.parameters); | 11313 checkForWrongNumberOfParametersForSetter(node.name, node.parameters); |
| 11209 checkForNonVoidReturnTypeForSetter(node.returnType); | 11314 checkForNonVoidReturnTypeForSetter(node.returnType); |
| 11210 checkForConflictingStaticSetterAndInstanceMember(node); | 11315 checkForConflictingStaticSetterAndInstanceMember(node); |
| 11211 } else if (node.isOperator) { | 11316 } else if (node.isOperator) { |
| 11212 checkForOptionalParameterInOperator(node); | 11317 checkForOptionalParameterInOperator(node); |
| 11213 checkForWrongNumberOfParametersForOperator(node); | 11318 checkForWrongNumberOfParametersForOperator(node); |
| 11214 checkForNonVoidReturnTypeForOperator(node); | 11319 checkForNonVoidReturnTypeForOperator(node); |
| 11215 } | 11320 } |
| 11216 checkForConcreteClassWithAbstractMember(node); | 11321 checkForConcreteClassWithAbstractMember(node); |
| 11217 checkForAllInvalidOverrideErrorCodes(node); | 11322 checkForAllInvalidOverrideErrorCodes3(node); |
| 11218 return super.visitMethodDeclaration(node); | 11323 return super.visitMethodDeclaration(node); |
| 11219 } finally { | 11324 } finally { |
| 11220 _enclosingFunction = previousFunction; | 11325 _enclosingFunction = previousFunction; |
| 11221 _isInStaticMethod = false; | 11326 _isInStaticMethod = false; |
| 11222 } | 11327 } |
| 11223 } | 11328 } |
| 11224 Object visitMethodInvocation(MethodInvocation node) { | 11329 Object visitMethodInvocation(MethodInvocation node) { |
| 11225 checkForStaticAccessToInstanceMember(node.target, node.methodName); | 11330 checkForStaticAccessToInstanceMember(node.target, node.methodName); |
| 11226 return super.visitMethodInvocation(node); | 11331 return super.visitMethodInvocation(node); |
| 11227 } | 11332 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11348 * @param node the [ConstructorDeclaration] to evaluate | 11453 * @param node the [ConstructorDeclaration] to evaluate |
| 11349 * @return `true` if and only if an error code is generated on the passed node | 11454 * @return `true` if and only if an error code is generated on the passed node |
| 11350 * @see #initialFieldElementsMap | 11455 * @see #initialFieldElementsMap |
| 11351 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR | 11456 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR |
| 11352 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES | 11457 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES |
| 11353 */ | 11458 */ |
| 11354 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { | 11459 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { |
| 11355 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod
e.externalKeyword != null) { | 11460 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod
e.externalKeyword != null) { |
| 11356 return false; | 11461 return false; |
| 11357 } | 11462 } |
| 11463 if (_isInNativeClass) { |
| 11464 return false; |
| 11465 } |
| 11358 bool foundError = false; | 11466 bool foundError = false; |
| 11359 Map<FieldElement, INIT_STATE> fieldElementsMap = new Map<FieldElement, INIT_
STATE>.from(_initialFieldElementsMap); | 11467 Map<FieldElement, INIT_STATE> fieldElementsMap = new Map<FieldElement, INIT_
STATE>.from(_initialFieldElementsMap); |
| 11360 NodeList<FormalParameter> formalParameters = node.parameters.parameters; | 11468 NodeList<FormalParameter> formalParameters = node.parameters.parameters; |
| 11361 for (FormalParameter formalParameter in formalParameters) { | 11469 for (FormalParameter formalParameter in formalParameters) { |
| 11362 FormalParameter parameter = formalParameter; | 11470 FormalParameter parameter = formalParameter; |
| 11363 if (parameter is DefaultFormalParameter) { | 11471 if (parameter is DefaultFormalParameter) { |
| 11364 parameter = ((parameter as DefaultFormalParameter)).parameter; | 11472 parameter = ((parameter as DefaultFormalParameter)).parameter; |
| 11365 } | 11473 } |
| 11366 if (parameter is FieldFormalParameter) { | 11474 if (parameter is FieldFormalParameter) { |
| 11367 FieldElement fieldElement = ((parameter.element as FieldFormalParameterE
lementImpl)).field; | 11475 FieldElement fieldElement = ((parameter.element as FieldFormalParameterE
lementImpl)).field; |
| 11368 INIT_STATE state = fieldElementsMap[fieldElement]; | 11476 INIT_STATE state = fieldElementsMap[fieldElement]; |
| 11369 if (identical(state, INIT_STATE.NOT_INIT)) { | 11477 if (identical(state, INIT_STATE.NOT_INIT)) { |
| 11370 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; | 11478 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; |
| 11371 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { | 11479 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { |
| 11372 if (fieldElement.isFinal || fieldElement.isConst) { | 11480 if (fieldElement.isFinal || fieldElement.isConst) { |
| 11373 _errorReporter.reportError2(CompileTimeErrorCode.FINAL_INITIALIZED_I
N_DECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.display
Name]); | 11481 _errorReporter.reportError2(CompileTimeErrorCode.FINAL_INITIALIZED_I
N_DECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.display
Name]); |
| 11374 foundError = true; | 11482 foundError = true; |
| 11375 } | 11483 } |
| 11376 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { | 11484 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { |
| 11377 if (fieldElement.isFinal || fieldElement.isConst) { | 11485 if (fieldElement.isFinal || fieldElement.isConst) { |
| 11378 _errorReporter.reportError2(CompileTimeErrorCode.FINAL_INITIALIZED_M
ULTIPLE_TIMES, formalParameter.identifier, [fieldElement.displayName]); | 11486 _errorReporter.reportError2(CompileTimeErrorCode.FINAL_INITIALIZED_M
ULTIPLE_TIMES, formalParameter.identifier, [fieldElement.displayName]); |
| 11379 foundError = true; | 11487 foundError = true; |
| 11380 } | 11488 } |
| 11381 } | 11489 } |
| 11382 } | 11490 } |
| 11383 } | 11491 } |
| 11384 NodeList<ConstructorInitializer> initializers = node.initializers; | 11492 NodeList<ConstructorInitializer> initializers = node.initializers; |
| 11385 for (ConstructorInitializer constructorInitializer in initializers) { | 11493 for (ConstructorInitializer constructorInitializer in initializers) { |
| 11494 if (constructorInitializer is RedirectingConstructorInvocation) { |
| 11495 return false; |
| 11496 } |
| 11386 if (constructorInitializer is ConstructorFieldInitializer) { | 11497 if (constructorInitializer is ConstructorFieldInitializer) { |
| 11387 ConstructorFieldInitializer constructorFieldInitializer = constructorIni
tializer as ConstructorFieldInitializer; | 11498 ConstructorFieldInitializer constructorFieldInitializer = constructorIni
tializer as ConstructorFieldInitializer; |
| 11388 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; | 11499 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; |
| 11389 Element element = fieldName.element; | 11500 Element element = fieldName.element; |
| 11390 if (element is FieldElement) { | 11501 if (element is FieldElement) { |
| 11391 FieldElement fieldElement = element as FieldElement; | 11502 FieldElement fieldElement = element as FieldElement; |
| 11392 INIT_STATE state = fieldElementsMap[fieldElement]; | 11503 INIT_STATE state = fieldElementsMap[fieldElement]; |
| 11393 if (identical(state, INIT_STATE.NOT_INIT)) { | 11504 if (identical(state, INIT_STATE.NOT_INIT)) { |
| 11394 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; | 11505 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; |
| 11395 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { | 11506 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { |
| 11396 if (fieldElement.isFinal || fieldElement.isConst) { | 11507 if (fieldElement.isFinal || fieldElement.isConst) { |
| 11397 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED
_IN_INITIALIZER_AND_DECLARATION, fieldName, []); | 11508 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED
_IN_INITIALIZER_AND_DECLARATION, fieldName, []); |
| 11398 foundError = true; | 11509 foundError = true; |
| 11399 } | 11510 } |
| 11400 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { | 11511 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { |
| 11401 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_I
N_PARAMETER_AND_INITIALIZER, fieldName, []); | 11512 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_I
N_PARAMETER_AND_INITIALIZER, fieldName, []); |
| 11402 foundError = true; | 11513 foundError = true; |
| 11403 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { | 11514 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { |
| 11404 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_B
Y_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); | 11515 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_B
Y_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); |
| 11405 foundError = true; | 11516 foundError = true; |
| 11406 } | 11517 } |
| 11407 } | 11518 } |
| 11408 } | 11519 } |
| 11409 } | 11520 } |
| 11521 for (MapEntry<FieldElement, INIT_STATE> entry in getMapEntrySet(fieldElement
sMap)) { |
| 11522 if (identical(entry.getValue(), INIT_STATE.NOT_INIT)) { |
| 11523 FieldElement fieldElement = entry.getKey(); |
| 11524 if (fieldElement.isFinal || fieldElement.isConst) { |
| 11525 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, n
ode.returnType, [fieldElement.name]); |
| 11526 foundError = true; |
| 11527 } |
| 11528 } |
| 11529 } |
| 11410 return foundError; | 11530 return foundError; |
| 11411 } | 11531 } |
| 11412 | 11532 |
| 11413 /** | 11533 /** |
| 11414 * This checks the passed method declaration against override-error codes. | 11534 * This checks the passed executable element against override-error codes. |
| 11415 * | 11535 * |
| 11416 * @param node the [MethodDeclaration] to evaluate | 11536 * @param executableElement the [ExecutableElement] to evaluate |
| 11537 * @param parameters the parameters of the executable element |
| 11538 * @param errorNameTarget the node to report problems on |
| 11417 * @return `true` if and only if an error code is generated on the passed node | 11539 * @return `true` if and only if an error code is generated on the passed node |
| 11418 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 11540 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 11419 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED | 11541 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED |
| 11420 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL | 11542 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL |
| 11421 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED | 11543 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED |
| 11422 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE | 11544 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE |
| 11423 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE | 11545 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 11424 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 11546 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 11425 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE | 11547 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE |
| 11426 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE | 11548 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE |
| 11427 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE | 11549 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE |
| 11428 * @see StaticWarningCode#INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES | 11550 * @see StaticWarningCode#INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES |
| 11429 */ | 11551 */ |
| 11430 bool checkForAllInvalidOverrideErrorCodes(MethodDeclaration node) { | 11552 bool checkForAllInvalidOverrideErrorCodes(ExecutableElement executableElement,
List<ParameterElement> parameters2, List<ASTNode> parameterLocations, SimpleIde
ntifier errorNameTarget) { |
| 11431 if (_enclosingClass == null || node.isStatic || node.body is NativeFunctionB
ody) { | 11553 String executableElementName = executableElement.name; |
| 11432 return false; | 11554 ExecutableElement overriddenExecutable = _inheritanceManager.lookupInheritan
ce(_enclosingClass, executableElement.name); |
| 11555 bool isGetter = false; |
| 11556 bool isSetter = false; |
| 11557 if (executableElement is PropertyAccessorElement) { |
| 11558 PropertyAccessorElement accessorElement = executableElement as PropertyAcc
essorElement; |
| 11559 isGetter = accessorElement.isGetter; |
| 11560 isSetter = accessorElement.isSetter; |
| 11433 } | 11561 } |
| 11434 ExecutableElement executableElement = node.element; | |
| 11435 if (executableElement == null) { | |
| 11436 return false; | |
| 11437 } | |
| 11438 SimpleIdentifier methodName = node.name; | |
| 11439 if (methodName.isSynthetic) { | |
| 11440 return false; | |
| 11441 } | |
| 11442 String methodNameStr = methodName.name; | |
| 11443 ExecutableElement overriddenExecutable = _inheritanceManager.lookupInheritan
ce(_enclosingClass, executableElement.name); | |
| 11444 if (overriddenExecutable == null) { | 11562 if (overriddenExecutable == null) { |
| 11445 if (!node.isGetter && !node.isSetter && !node.isOperator) { | 11563 if (!isGetter && !isSetter && !executableElement.isOperator) { |
| 11446 Set<ClassElement> visitedClasses = new Set<ClassElement>(); | 11564 Set<ClassElement> visitedClasses = new Set<ClassElement>(); |
| 11447 InterfaceType superclassType = _enclosingClass.supertype; | 11565 InterfaceType superclassType = _enclosingClass.supertype; |
| 11448 ClassElement superclassElement = superclassType == null ? null : supercl
assType.element; | 11566 ClassElement superclassElement = superclassType == null ? null : supercl
assType.element; |
| 11449 while (superclassElement != null && !visitedClasses.contains(superclassE
lement)) { | 11567 while (superclassElement != null && !visitedClasses.contains(superclassE
lement)) { |
| 11450 javaSetAdd(visitedClasses, superclassElement); | 11568 javaSetAdd(visitedClasses, superclassElement); |
| 11451 List<FieldElement> fieldElts = superclassElement.fields; | 11569 List<FieldElement> fieldElts = superclassElement.fields; |
| 11452 for (FieldElement fieldElt in fieldElts) { | 11570 for (FieldElement fieldElt in fieldElts) { |
| 11453 if (fieldElt.name == methodNameStr && fieldElt.isStatic) { | 11571 if (fieldElt.name == executableElementName && fieldElt.isStatic) { |
| 11454 _errorReporter.reportError2(StaticWarningCode.INSTANCE_METHOD_NAME
_COLLIDES_WITH_SUPERCLASS_STATIC, methodName, [methodNameStr, fieldElt.enclosing
Element.displayName]); | 11572 _errorReporter.reportError2(StaticWarningCode.INSTANCE_METHOD_NAME
_COLLIDES_WITH_SUPERCLASS_STATIC, errorNameTarget, [ |
| 11573 executableElementName, |
| 11574 fieldElt.enclosingElement.displayName]); |
| 11455 return true; | 11575 return true; |
| 11456 } | 11576 } |
| 11457 } | 11577 } |
| 11458 List<PropertyAccessorElement> propertyAccessorElts = superclassElement
.accessors; | 11578 List<PropertyAccessorElement> propertyAccessorElts = superclassElement
.accessors; |
| 11459 for (PropertyAccessorElement accessorElt in propertyAccessorElts) { | 11579 for (PropertyAccessorElement accessorElt in propertyAccessorElts) { |
| 11460 if (accessorElt.name == methodNameStr && accessorElt.isStatic) { | 11580 if (accessorElt.name == executableElementName && accessorElt.isStati
c) { |
| 11461 _errorReporter.reportError2(StaticWarningCode.INSTANCE_METHOD_NAME
_COLLIDES_WITH_SUPERCLASS_STATIC, methodName, [methodNameStr, accessorElt.enclos
ingElement.displayName]); | 11581 _errorReporter.reportError2(StaticWarningCode.INSTANCE_METHOD_NAME
_COLLIDES_WITH_SUPERCLASS_STATIC, errorNameTarget, [ |
| 11582 executableElementName, |
| 11583 accessorElt.enclosingElement.displayName]); |
| 11462 return true; | 11584 return true; |
| 11463 } | 11585 } |
| 11464 } | 11586 } |
| 11465 List<MethodElement> methodElements = superclassElement.methods; | 11587 List<MethodElement> methodElements = superclassElement.methods; |
| 11466 for (MethodElement methodElement in methodElements) { | 11588 for (MethodElement methodElement in methodElements) { |
| 11467 if (methodElement.name == methodNameStr && methodElement.isStatic) { | 11589 if (methodElement.name == executableElementName && methodElement.isS
tatic) { |
| 11468 _errorReporter.reportError2(StaticWarningCode.INSTANCE_METHOD_NAME
_COLLIDES_WITH_SUPERCLASS_STATIC, methodName, [methodNameStr, methodElement.encl
osingElement.displayName]); | 11590 _errorReporter.reportError2(StaticWarningCode.INSTANCE_METHOD_NAME
_COLLIDES_WITH_SUPERCLASS_STATIC, errorNameTarget, [ |
| 11591 executableElementName, |
| 11592 methodElement.enclosingElement.displayName]); |
| 11469 return true; | 11593 return true; |
| 11470 } | 11594 } |
| 11471 } | 11595 } |
| 11472 superclassType = superclassElement.supertype; | 11596 superclassType = superclassElement.supertype; |
| 11473 superclassElement = superclassType == null ? null : superclassType.ele
ment; | 11597 superclassElement = superclassType == null ? null : superclassType.ele
ment; |
| 11474 } | 11598 } |
| 11475 } | 11599 } |
| 11476 return false; | 11600 return false; |
| 11477 } | 11601 } |
| 11478 FunctionType overridingFT = executableElement.type; | 11602 FunctionType overridingFT = executableElement.type; |
| 11479 FunctionType overriddenFT = overriddenExecutable.type; | 11603 FunctionType overriddenFT = overriddenExecutable.type; |
| 11480 InterfaceType enclosingType = _enclosingClass.type; | 11604 InterfaceType enclosingType = _enclosingClass.type; |
| 11481 overriddenFT = _inheritanceManager.substituteTypeArgumentsInMemberFromInheri
tance(overriddenFT, methodNameStr, enclosingType); | 11605 overriddenFT = _inheritanceManager.substituteTypeArgumentsInMemberFromInheri
tance(overriddenFT, executableElementName, enclosingType); |
| 11482 if (overridingFT == null || overriddenFT == null) { | 11606 if (overridingFT == null || overriddenFT == null) { |
| 11483 return false; | 11607 return false; |
| 11484 } | 11608 } |
| 11485 Type2 overridingFTReturnType = overridingFT.returnType; | 11609 Type2 overridingFTReturnType = overridingFT.returnType; |
| 11486 Type2 overriddenFTReturnType = overriddenFT.returnType; | 11610 Type2 overriddenFTReturnType = overriddenFT.returnType; |
| 11487 List<Type2> overridingNormalPT = overridingFT.normalParameterTypes; | 11611 List<Type2> overridingNormalPT = overridingFT.normalParameterTypes; |
| 11488 List<Type2> overriddenNormalPT = overriddenFT.normalParameterTypes; | 11612 List<Type2> overriddenNormalPT = overriddenFT.normalParameterTypes; |
| 11489 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes; | 11613 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes; |
| 11490 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes; | 11614 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes; |
| 11491 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes; | 11615 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes; |
| 11492 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes; | 11616 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes; |
| 11493 if (overridingNormalPT.length != overriddenNormalPT.length) { | 11617 if (overridingNormalPT.length != overriddenNormalPT.length) { |
| 11494 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_REQUIRED
, methodName, [overriddenNormalPT.length, overriddenExecutable.enclosingElement.
displayName]); | 11618 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_REQUIRED
, errorNameTarget, [ |
| 11619 overriddenNormalPT.length, |
| 11620 overriddenExecutable.enclosingElement.displayName]); |
| 11495 return true; | 11621 return true; |
| 11496 } | 11622 } |
| 11497 if (overridingPositionalPT.length < overriddenPositionalPT.length) { | 11623 if (overridingPositionalPT.length < overriddenPositionalPT.length) { |
| 11498 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_POSITION
AL, methodName, [overriddenPositionalPT.length, overriddenExecutable.enclosingEl
ement.displayName]); | 11624 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_POSITION
AL, errorNameTarget, [ |
| 11625 overriddenPositionalPT.length, |
| 11626 overriddenExecutable.enclosingElement.displayName]); |
| 11499 return true; | 11627 return true; |
| 11500 } | 11628 } |
| 11501 Set<String> overridingParameterNameSet = overridingNamedPT.keys.toSet(); | 11629 Set<String> overridingParameterNameSet = overridingNamedPT.keys.toSet(); |
| 11502 JavaIterator<String> overriddenParameterNameIterator = new JavaIterator(over
riddenNamedPT.keys.toSet()); | 11630 JavaIterator<String> overriddenParameterNameIterator = new JavaIterator(over
riddenNamedPT.keys.toSet()); |
| 11503 while (overriddenParameterNameIterator.hasNext) { | 11631 while (overriddenParameterNameIterator.hasNext) { |
| 11504 String overriddenParamName = overriddenParameterNameIterator.next(); | 11632 String overriddenParamName = overriddenParameterNameIterator.next(); |
| 11505 if (!overridingParameterNameSet.contains(overriddenParamName)) { | 11633 if (!overridingParameterNameSet.contains(overriddenParamName)) { |
| 11506 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_NAMED,
methodName, [overriddenParamName, overriddenExecutable.enclosingElement.display
Name]); | 11634 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_NAMED,
errorNameTarget, [ |
| 11635 overriddenParamName, |
| 11636 overriddenExecutable.enclosingElement.displayName]); |
| 11507 return true; | 11637 return true; |
| 11508 } | 11638 } |
| 11509 } | 11639 } |
| 11510 if (overriddenFTReturnType != VoidTypeImpl.instance && !overridingFTReturnTy
pe.isAssignableTo(overriddenFTReturnType)) { | 11640 if (overriddenFTReturnType != VoidTypeImpl.instance && !overridingFTReturnTy
pe.isAssignableTo(overriddenFTReturnType)) { |
| 11511 _errorReporter.reportError2(!node.isGetter ? StaticWarningCode.INVALID_MET
HOD_OVERRIDE_RETURN_TYPE : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE
, methodName, [overridingFTReturnType.displayName, overriddenFTReturnType.displa
yName, overriddenExecutable.enclosingElement.displayName]); | 11641 _errorReporter.reportError2(!isGetter ? StaticWarningCode.INVALID_METHOD_O
VERRIDE_RETURN_TYPE : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, err
orNameTarget, [ |
| 11642 overridingFTReturnType.displayName, |
| 11643 overriddenFTReturnType.displayName, |
| 11644 overriddenExecutable.enclosingElement.displayName]); |
| 11512 return true; | 11645 return true; |
| 11513 } | 11646 } |
| 11514 FormalParameterList formalParameterList = node.parameters; | 11647 if (parameterLocations == null) { |
| 11515 if (formalParameterList == null) { | |
| 11516 return false; | 11648 return false; |
| 11517 } | 11649 } |
| 11518 NodeList<FormalParameter> parameterNodeList = formalParameterList.parameters
; | |
| 11519 int parameterIndex = 0; | 11650 int parameterIndex = 0; |
| 11520 for (int i = 0; i < overridingNormalPT.length; i++) { | 11651 for (int i = 0; i < overridingNormalPT.length; i++) { |
| 11521 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { | 11652 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { |
| 11522 _errorReporter.reportError2(!node.isSetter ? StaticWarningCode.INVALID_M
ETHOD_OVERRIDE_NORMAL_PARAM_TYPE : StaticWarningCode.INVALID_SETTER_OVERRIDE_NOR
MAL_PARAM_TYPE, parameterNodeList[parameterIndex], [overridingNormalPT[i].displa
yName, overriddenNormalPT[i].displayName, overriddenExecutable.enclosingElement.
displayName]); | 11653 _errorReporter.reportError2(!isSetter ? StaticWarningCode.INVALID_METHOD
_OVERRIDE_NORMAL_PARAM_TYPE : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_P
ARAM_TYPE, parameterLocations[parameterIndex], [ |
| 11654 overridingNormalPT[i].displayName, |
| 11655 overriddenNormalPT[i].displayName, |
| 11656 overriddenExecutable.enclosingElement.displayName]); |
| 11523 return true; | 11657 return true; |
| 11524 } | 11658 } |
| 11525 parameterIndex++; | 11659 parameterIndex++; |
| 11526 } | 11660 } |
| 11527 for (int i = 0; i < overriddenPositionalPT.length; i++) { | 11661 for (int i = 0; i < overriddenPositionalPT.length; i++) { |
| 11528 if (!overridingPositionalPT[i].isAssignableTo(overriddenPositionalPT[i]))
{ | 11662 if (!overridingPositionalPT[i].isAssignableTo(overriddenPositionalPT[i]))
{ |
| 11529 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_OP
TIONAL_PARAM_TYPE, parameterNodeList[parameterIndex], [overridingPositionalPT[i]
.displayName, overriddenPositionalPT[i].displayName, overriddenExecutable.enclos
ingElement.displayName]); | 11663 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_OP
TIONAL_PARAM_TYPE, parameterLocations[parameterIndex], [ |
| 11664 overridingPositionalPT[i].displayName, |
| 11665 overriddenPositionalPT[i].displayName, |
| 11666 overriddenExecutable.enclosingElement.displayName]); |
| 11530 return true; | 11667 return true; |
| 11531 } | 11668 } |
| 11532 parameterIndex++; | 11669 parameterIndex++; |
| 11533 } | 11670 } |
| 11534 JavaIterator<MapEntry<String, Type2>> overriddenNamedPTIterator = new JavaIt
erator(getMapEntrySet(overriddenNamedPT)); | 11671 JavaIterator<MapEntry<String, Type2>> overriddenNamedPTIterator = new JavaIt
erator(getMapEntrySet(overriddenNamedPT)); |
| 11535 while (overriddenNamedPTIterator.hasNext) { | 11672 while (overriddenNamedPTIterator.hasNext) { |
| 11536 MapEntry<String, Type2> overriddenNamedPTEntry = overriddenNamedPTIterator
.next(); | 11673 MapEntry<String, Type2> overriddenNamedPTEntry = overriddenNamedPTIterator
.next(); |
| 11537 Type2 overridingType = overridingNamedPT[overriddenNamedPTEntry.getKey()]; | 11674 Type2 overridingType = overridingNamedPT[overriddenNamedPTEntry.getKey()]; |
| 11538 if (overridingType == null) { | 11675 if (overridingType == null) { |
| 11539 continue; | 11676 continue; |
| 11540 } | 11677 } |
| 11541 if (!overriddenNamedPTEntry.getValue().isAssignableTo(overridingType)) { | 11678 if (!overriddenNamedPTEntry.getValue().isAssignableTo(overridingType)) { |
| 11542 NormalFormalParameter parameterToSelect = null; | 11679 ParameterElement parameterToSelect = null; |
| 11543 for (FormalParameter formalParameter in parameterNodeList) { | 11680 ASTNode parameterLocationToSelect = null; |
| 11544 if (formalParameter is DefaultFormalParameter && identical(formalParam
eter.kind, ParameterKind.NAMED)) { | 11681 for (int i = 0; i < parameters2.length; i++) { |
| 11545 DefaultFormalParameter defaultFormalParameter = formalParameter as D
efaultFormalParameter; | 11682 ParameterElement parameter = parameters2[i]; |
| 11546 NormalFormalParameter normalFormalParameter = defaultFormalParameter
.parameter; | 11683 if (identical(parameter.parameterKind, ParameterKind.NAMED) && overrid
denNamedPTEntry.getKey() == parameter.name) { |
| 11547 if (overriddenNamedPTEntry.getKey() == normalFormalParameter.identif
ier.name) { | 11684 parameterToSelect = parameter; |
| 11548 parameterToSelect = normalFormalParameter; | 11685 parameterLocationToSelect = parameterLocations[i]; |
| 11549 break; | 11686 break; |
| 11550 } | |
| 11551 } | 11687 } |
| 11552 } | 11688 } |
| 11553 if (parameterToSelect != null) { | 11689 if (parameterToSelect != null) { |
| 11554 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_
NAMED_PARAM_TYPE, parameterToSelect, [overridingType.displayName, overriddenName
dPTEntry.getValue().displayName, overriddenExecutable.enclosingElement.displayNa
me]); | 11690 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_
NAMED_PARAM_TYPE, parameterLocationToSelect, [ |
| 11691 overridingType.displayName, |
| 11692 overriddenNamedPTEntry.getValue().displayName, |
| 11693 overriddenExecutable.enclosingElement.displayName]); |
| 11555 return true; | 11694 return true; |
| 11556 } | 11695 } |
| 11557 } | 11696 } |
| 11558 } | 11697 } |
| 11559 bool foundError = false; | 11698 bool foundError = false; |
| 11560 List<FormalParameter> formalParameters = new List<FormalParameter>(); | 11699 List<ASTNode> formalParameters = new List<ASTNode>(); |
| 11561 List<ParameterElementImpl> parameterElts = new List<ParameterElementImpl>(); | 11700 List<ParameterElementImpl> parameterElts = new List<ParameterElementImpl>(); |
| 11562 List<ParameterElementImpl> overriddenParameterElts = new List<ParameterEleme
ntImpl>(); | 11701 List<ParameterElementImpl> overriddenParameterElts = new List<ParameterEleme
ntImpl>(); |
| 11563 List<ParameterElement> overriddenPEs = overriddenExecutable.parameters; | 11702 List<ParameterElement> overriddenPEs = overriddenExecutable.parameters; |
| 11564 for (FormalParameter formalParameter in parameterNodeList) { | 11703 for (int i = 0; i < parameters2.length; i++) { |
| 11565 if (formalParameter.kind.isOptional) { | 11704 ParameterElement parameter = parameters2[i]; |
| 11566 formalParameters.add(formalParameter); | 11705 if (parameter.parameterKind.isOptional) { |
| 11567 parameterElts.add((formalParameter.element as ParameterElementImpl)); | 11706 formalParameters.add(parameterLocations[i]); |
| 11707 parameterElts.add((parameter as ParameterElementImpl)); |
| 11568 } | 11708 } |
| 11569 } | 11709 } |
| 11570 for (ParameterElement parameterElt in overriddenPEs) { | 11710 for (ParameterElement parameterElt in overriddenPEs) { |
| 11571 if (parameterElt.parameterKind.isOptional) { | 11711 if (parameterElt.parameterKind.isOptional) { |
| 11572 overriddenParameterElts.add((parameterElt as ParameterElementImpl)); | 11712 overriddenParameterElts.add((parameterElt as ParameterElementImpl)); |
| 11573 } | 11713 } |
| 11574 } | 11714 } |
| 11575 if (parameterElts.length > 0) { | 11715 if (parameterElts.length > 0) { |
| 11576 if (identical(parameterElts[0].parameterKind, ParameterKind.NAMED)) { | 11716 if (identical(parameterElts[0].parameterKind, ParameterKind.NAMED)) { |
| 11577 for (int i = 0; i < parameterElts.length; i++) { | 11717 for (int i = 0; i < parameterElts.length; i++) { |
| 11578 ParameterElementImpl parameterElt = parameterElts[i]; | 11718 ParameterElementImpl parameterElt = parameterElts[i]; |
| 11579 EvaluationResultImpl result = parameterElt.evaluationResult; | 11719 EvaluationResultImpl result = parameterElt.evaluationResult; |
| 11580 if (result == null || identical(result, ValidResult.RESULT_OBJECT)) { | 11720 if (result == null || identical(result, ValidResult.RESULT_OBJECT)) { |
| 11581 continue; | 11721 continue; |
| 11582 } | 11722 } |
| 11583 String parameterName = parameterElt.name; | 11723 String parameterName = parameterElt.name; |
| 11584 for (int j = 0; j < overriddenParameterElts.length; j++) { | 11724 for (int j = 0; j < overriddenParameterElts.length; j++) { |
| 11585 ParameterElementImpl overriddenParameterElt = overriddenParameterElt
s[j]; | 11725 ParameterElementImpl overriddenParameterElt = overriddenParameterElt
s[j]; |
| 11586 String overriddenParameterName = overriddenParameterElt.name; | 11726 String overriddenParameterName = overriddenParameterElt.name; |
| 11587 if (parameterName != null && parameterName == overriddenParameterNam
e) { | 11727 if (parameterName != null && parameterName == overriddenParameterNam
e) { |
| 11588 EvaluationResultImpl overriddenResult = overriddenParameterElt.eva
luationResult; | 11728 EvaluationResultImpl overriddenResult = overriddenParameterElt.eva
luationResult; |
| 11589 if (overriddenResult == null || identical(result, ValidResult.RESU
LT_OBJECT)) { | 11729 if (overriddenResult == null || identical(result, ValidResult.RESU
LT_OBJECT)) { |
| 11590 break; | 11730 break; |
| 11591 } | 11731 } |
| 11592 if (!result.equalValues(overriddenResult)) { | 11732 if (!result.equalValues(overriddenResult)) { |
| 11593 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_D
IFFERENT_DEFAULT_VALUES_NAMED, formalParameters[i], [overriddenExecutable.enclos
ingElement.displayName, overriddenExecutable.displayName, parameterName]); | 11733 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_D
IFFERENT_DEFAULT_VALUES_NAMED, formalParameters[i], [ |
| 11734 overriddenExecutable.enclosingElement.displayName, |
| 11735 overriddenExecutable.displayName, |
| 11736 parameterName]); |
| 11594 foundError = true; | 11737 foundError = true; |
| 11595 } | 11738 } |
| 11596 } | 11739 } |
| 11597 } | 11740 } |
| 11598 } | 11741 } |
| 11599 } else { | 11742 } else { |
| 11600 for (int i = 0; i < parameterElts.length && i < overriddenParameterElts.
length; i++) { | 11743 for (int i = 0; i < parameterElts.length && i < overriddenParameterElts.
length; i++) { |
| 11601 ParameterElementImpl parameterElt = parameterElts[i]; | 11744 ParameterElementImpl parameterElt = parameterElts[i]; |
| 11602 EvaluationResultImpl result = parameterElt.evaluationResult; | 11745 EvaluationResultImpl result = parameterElt.evaluationResult; |
| 11603 if (result == null || identical(result, ValidResult.RESULT_OBJECT)) { | 11746 if (result == null || identical(result, ValidResult.RESULT_OBJECT)) { |
| 11604 continue; | 11747 continue; |
| 11605 } | 11748 } |
| 11606 ParameterElementImpl overriddenParameterElt = overriddenParameterElts[
i]; | 11749 ParameterElementImpl overriddenParameterElt = overriddenParameterElts[
i]; |
| 11607 EvaluationResultImpl overriddenResult = overriddenParameterElt.evaluat
ionResult; | 11750 EvaluationResultImpl overriddenResult = overriddenParameterElt.evaluat
ionResult; |
| 11608 if (overriddenResult == null || identical(result, ValidResult.RESULT_O
BJECT)) { | 11751 if (overriddenResult == null || identical(result, ValidResult.RESULT_O
BJECT)) { |
| 11609 continue; | 11752 continue; |
| 11610 } | 11753 } |
| 11611 if (!result.equalValues(overriddenResult)) { | 11754 if (!result.equalValues(overriddenResult)) { |
| 11612 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_DIFFE
RENT_DEFAULT_VALUES_POSITIONAL, formalParameters[i], [overriddenExecutable.enclo
singElement.displayName, overriddenExecutable.displayName]); | 11755 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_DIFFE
RENT_DEFAULT_VALUES_POSITIONAL, formalParameters[i], [ |
| 11756 overriddenExecutable.enclosingElement.displayName, |
| 11757 overriddenExecutable.displayName]); |
| 11613 foundError = true; | 11758 foundError = true; |
| 11614 } | 11759 } |
| 11615 } | 11760 } |
| 11616 } | 11761 } |
| 11617 } | 11762 } |
| 11618 return foundError; | 11763 return foundError; |
| 11619 } | 11764 } |
| 11620 | 11765 |
| 11621 /** | 11766 /** |
| 11767 * This checks the passed field declaration against override-error codes. |
| 11768 * |
| 11769 * @param node the [MethodDeclaration] to evaluate |
| 11770 * @return `true` if and only if an error code is generated on the passed node |
| 11771 * @see #checkForAllInvalidOverrideErrorCodes(ExecutableElement) |
| 11772 */ |
| 11773 bool checkForAllInvalidOverrideErrorCodes2(FieldDeclaration node) { |
| 11774 if (_enclosingClass == null || node.isStatic) { |
| 11775 return false; |
| 11776 } |
| 11777 bool hasProblems = false; |
| 11778 VariableDeclarationList fields = node.fields; |
| 11779 for (VariableDeclaration field in fields.variables) { |
| 11780 FieldElement element = field.element as FieldElement; |
| 11781 if (element == null) { |
| 11782 continue; |
| 11783 } |
| 11784 PropertyAccessorElement getter = element.getter; |
| 11785 PropertyAccessorElement setter = element.setter; |
| 11786 SimpleIdentifier fieldName = field.name; |
| 11787 if (getter != null) { |
| 11788 hasProblems = javaBooleanOr(hasProblems, checkForAllInvalidOverrideError
Codes(getter, ParameterElementImpl.EMPTY_ARRAY, ASTNode.EMPTY_ARRAY, fieldName))
; |
| 11789 } |
| 11790 if (setter != null) { |
| 11791 hasProblems = javaBooleanOr(hasProblems, checkForAllInvalidOverrideError
Codes(setter, setter.parameters, <ASTNode> [fieldName], fieldName)); |
| 11792 } |
| 11793 } |
| 11794 return hasProblems; |
| 11795 } |
| 11796 |
| 11797 /** |
| 11798 * This checks the passed method declaration against override-error codes. |
| 11799 * |
| 11800 * @param node the [MethodDeclaration] to evaluate |
| 11801 * @return `true` if and only if an error code is generated on the passed node |
| 11802 * @see #checkForAllInvalidOverrideErrorCodes(ExecutableElement) |
| 11803 */ |
| 11804 bool checkForAllInvalidOverrideErrorCodes3(MethodDeclaration node) { |
| 11805 if (_enclosingClass == null || node.isStatic || node.body is NativeFunctionB
ody) { |
| 11806 return false; |
| 11807 } |
| 11808 ExecutableElement executableElement = node.element; |
| 11809 if (executableElement == null) { |
| 11810 return false; |
| 11811 } |
| 11812 SimpleIdentifier methodName = node.name; |
| 11813 if (methodName.isSynthetic) { |
| 11814 return false; |
| 11815 } |
| 11816 FormalParameterList formalParameterList = node.parameters; |
| 11817 NodeList<FormalParameter> parameterList = formalParameterList != null ? form
alParameterList.parameters : null; |
| 11818 List<ASTNode> parameters = parameterList != null ? new List.from(parameterLi
st) : null; |
| 11819 return checkForAllInvalidOverrideErrorCodes(executableElement, executableEle
ment.parameters, parameters, methodName); |
| 11820 } |
| 11821 |
| 11822 /** |
| 11622 * This verifies that all classes of the passed 'with' clause are valid. | 11823 * This verifies that all classes of the passed 'with' clause are valid. |
| 11623 * | 11824 * |
| 11624 * @param node the 'with' clause to evaluate | 11825 * @param node the 'with' clause to evaluate |
| 11625 * @return `true` if and only if an error code is generated on the passed node | 11826 * @return `true` if and only if an error code is generated on the passed node |
| 11626 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR | 11827 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR |
| 11627 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT | 11828 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT |
| 11628 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER | 11829 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER |
| 11629 */ | 11830 */ |
| 11630 bool checkForAllMixinErrorCodes(WithClause withClause) { | 11831 bool checkForAllMixinErrorCodes(WithClause withClause) { |
| 11631 if (withClause == null) { | 11832 if (withClause == null) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11742 ExportElement exportElement = node.element as ExportElement; | 11943 ExportElement exportElement = node.element as ExportElement; |
| 11743 LibraryElement exportedLibrary = exportElement.exportedLibrary; | 11944 LibraryElement exportedLibrary = exportElement.exportedLibrary; |
| 11744 if (exportedLibrary == null) { | 11945 if (exportedLibrary == null) { |
| 11745 return false; | 11946 return false; |
| 11746 } | 11947 } |
| 11747 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle
ment); | 11948 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle
ment); |
| 11748 Set<String> newNames = namespace.definedNames.keys.toSet(); | 11949 Set<String> newNames = namespace.definedNames.keys.toSet(); |
| 11749 for (String name in newNames) { | 11950 for (String name in newNames) { |
| 11750 ExportElement prevElement = _exportedNames[name]; | 11951 ExportElement prevElement = _exportedNames[name]; |
| 11751 if (prevElement != null && prevElement != exportElement) { | 11952 if (prevElement != null && prevElement != exportElement) { |
| 11752 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node,
[name, prevElement.exportedLibrary.definingCompilationUnit.displayName, exporte
dLibrary.definingCompilationUnit.displayName]); | 11953 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node,
[ |
| 11954 name, |
| 11955 prevElement.exportedLibrary.definingCompilationUnit.displayName, |
| 11956 exportedLibrary.definingCompilationUnit.displayName]); |
| 11753 return true; | 11957 return true; |
| 11754 } else { | 11958 } else { |
| 11755 _exportedNames[name] = exportElement; | 11959 _exportedNames[name] = exportElement; |
| 11756 } | 11960 } |
| 11757 } | 11961 } |
| 11758 return false; | 11962 return false; |
| 11759 } | 11963 } |
| 11760 | 11964 |
| 11761 /** | 11965 /** |
| 11762 * This verifies that the passed argument definition test identifier is a para
meter. | 11966 * This verifies that the passed argument definition test identifier is a para
meter. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 11787 return false; | 11991 return false; |
| 11788 } | 11992 } |
| 11789 bool problemReported = false; | 11993 bool problemReported = false; |
| 11790 for (Expression argument in argumentList.arguments) { | 11994 for (Expression argument in argumentList.arguments) { |
| 11791 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs
signable2(argument)); | 11995 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs
signable2(argument)); |
| 11792 } | 11996 } |
| 11793 return problemReported; | 11997 return problemReported; |
| 11794 } | 11998 } |
| 11795 | 11999 |
| 11796 /** | 12000 /** |
| 11797 * This verifies that the passed argument can be assigned to their correspondi
ng parameters. | 12001 * This verifies that the passed argument can be assigned to its corresponding
parameter. |
| 11798 * | 12002 * |
| 11799 * @param node the argument to evaluate | 12003 * @param argument the argument to evaluate |
| 11800 * @return `true` if and only if an error code is generated on the passed node | 12004 * @return `true` if and only if an error code is generated on the passed node |
| 11801 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE | 12005 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 12006 * @see CompileTimeErrorCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 11802 */ | 12007 */ |
| 11803 bool checkForArgumentTypeNotAssignable2(Expression argument) { | 12008 bool checkForArgumentTypeNotAssignable2(Expression argument) { |
| 11804 if (argument == null) { | 12009 if (argument == null) { |
| 11805 return false; | 12010 return false; |
| 11806 } | 12011 } |
| 12012 ErrorCode errorCode; |
| 12013 if (_isInConstInstanceCreation || _isEnclosingConstructorConst) { |
| 12014 errorCode = CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE; |
| 12015 } else { |
| 12016 errorCode = StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE; |
| 12017 } |
| 11807 ParameterElement staticParameterElement = argument.staticParameterElement; | 12018 ParameterElement staticParameterElement = argument.staticParameterElement; |
| 11808 Type2 staticParameterType = staticParameterElement == null ? null : staticPa
rameterElement.type; | 12019 Type2 staticParameterType = staticParameterElement == null ? null : staticPa
rameterElement.type; |
| 11809 Type2 staticArgumentType = getStaticType(argument); | 12020 ParameterElement propagatedParameterElement = argument.parameterElement; |
| 11810 if (staticArgumentType == null || staticParameterType == null) { | 12021 Type2 propagatedParameterType = propagatedParameterElement == null ? null :
propagatedParameterElement.type; |
| 12022 return checkForArgumentTypeNotAssignable3(argument, staticParameterType, pro
pagatedParameterType, errorCode); |
| 12023 } |
| 12024 |
| 12025 /** |
| 12026 * This verifies that the passed expression can be assigned to its correspondi
ng parameters. |
| 12027 * |
| 12028 * @param expression the expression to evaluate |
| 12029 * @param expectedStaticType the expected static type |
| 12030 * @param expectedPropagatedType the expected propagated type, may be `null` |
| 12031 * @return `true` if and only if an error code is generated on the passed node |
| 12032 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 12033 * @see CompileTimeErrorCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 12034 */ |
| 12035 bool checkForArgumentTypeNotAssignable3(Expression expression, Type2 expectedS
taticType, Type2 expectedPropagatedType, ErrorCode errorCode) { |
| 12036 Type2 staticArgumentType = getStaticType(expression); |
| 12037 if (staticArgumentType == null || expectedStaticType == null) { |
| 11811 return false; | 12038 return false; |
| 11812 } | 12039 } |
| 11813 if (_strictMode) { | 12040 if (_strictMode) { |
| 11814 if (staticArgumentType.isAssignableTo(staticParameterType)) { | 12041 if (staticArgumentType.isAssignableTo(expectedStaticType)) { |
| 11815 return false; | 12042 return false; |
| 11816 } | 12043 } |
| 11817 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
, argument, [staticArgumentType.displayName, staticParameterType.displayName]); | 12044 _errorReporter.reportError2(errorCode, expression, [ |
| 12045 staticArgumentType.displayName, |
| 12046 expectedStaticType.displayName]); |
| 11818 return true; | 12047 return true; |
| 11819 } | 12048 } |
| 11820 ParameterElement propagatedParameterElement = argument.parameterElement; | 12049 Type2 propagatedArgumentType = getPropagatedType(expression); |
| 11821 Type2 propagatedParameterType = propagatedParameterElement == null ? null :
propagatedParameterElement.type; | 12050 if (propagatedArgumentType == null || expectedPropagatedType == null) { |
| 11822 Type2 propagatedArgumentType = getPropagatedType(argument); | 12051 if (staticArgumentType.isAssignableTo(expectedStaticType)) { |
| 11823 if (propagatedArgumentType == null || propagatedParameterType == null) { | |
| 11824 if (staticArgumentType.isAssignableTo(staticParameterType)) { | |
| 11825 return false; | 12052 return false; |
| 11826 } | 12053 } |
| 11827 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
, argument, [staticArgumentType.displayName, staticParameterType.displayName]); | 12054 _errorReporter.reportError2(errorCode, expression, [ |
| 12055 staticArgumentType.displayName, |
| 12056 expectedStaticType.displayName]); |
| 11828 return true; | 12057 return true; |
| 11829 } | 12058 } |
| 11830 if (staticArgumentType.isAssignableTo(staticParameterType) || staticArgument
Type.isAssignableTo(propagatedParameterType) || propagatedArgumentType.isAssigna
bleTo(staticParameterType) || propagatedArgumentType.isAssignableTo(propagatedPa
rameterType)) { | 12059 if (staticArgumentType.isAssignableTo(expectedStaticType) || staticArgumentT
ype.isAssignableTo(expectedPropagatedType) || propagatedArgumentType.isAssignabl
eTo(expectedStaticType) || propagatedArgumentType.isAssignableTo(expectedPropaga
tedType)) { |
| 11831 return false; | 12060 return false; |
| 11832 } | 12061 } |
| 11833 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
argument, [(propagatedArgumentType == null ? staticArgumentType : propagatedArgu
mentType).displayName, (propagatedParameterType == null ? staticParameterType :
propagatedParameterType).displayName]); | 12062 _errorReporter.reportError2(errorCode, expression, [ |
| 12063 (propagatedArgumentType == null ? staticArgumentType : propagatedArgumen
tType).displayName, |
| 12064 (expectedPropagatedType == null ? expectedStaticType : expectedPropagate
dType).displayName]); |
| 11834 return true; | 12065 return true; |
| 11835 } | 12066 } |
| 11836 | 12067 |
| 11837 /** | 12068 /** |
| 11838 * This verifies that left hand side of the passed assignment expression is no
t final. | 12069 * This verifies that left hand side of the passed assignment expression is no
t final. |
| 11839 * | 12070 * |
| 11840 * @param node the assignment expression to evaluate | 12071 * @param node the assignment expression to evaluate |
| 11841 * @return `true` if and only if an error code is generated on the passed node | 12072 * @return `true` if and only if an error code is generated on the passed node |
| 11842 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 12073 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
| 11843 */ | 12074 */ |
| 11844 bool checkForAssignmentToFinal(AssignmentExpression node) { | 12075 bool checkForAssignmentToFinal(AssignmentExpression node) { |
| 11845 Expression leftExpression = node.leftHandSide; | 12076 Expression leftExpression = node.leftHandSide; |
| 11846 return checkForAssignmentToFinal2(leftExpression); | 12077 return checkForAssignmentToFinal2(leftExpression); |
| 11847 } | 12078 } |
| 11848 | 12079 |
| 11849 /** | 12080 /** |
| 11850 * This verifies that the passed expression is not final. | 12081 * This verifies that the passed expression is not final. |
| 11851 * | 12082 * |
| 11852 * @param node the expression to evaluate | 12083 * @param node the expression to evaluate |
| 11853 * @return `true` if and only if an error code is generated on the passed node | 12084 * @return `true` if and only if an error code is generated on the passed node |
| 11854 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 12085 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
| 12086 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD |
| 11855 */ | 12087 */ |
| 11856 bool checkForAssignmentToFinal2(Expression expression) { | 12088 bool checkForAssignmentToFinal2(Expression expression) { |
| 11857 Element element = null; | 12089 Element element = null; |
| 11858 if (expression is Identifier) { | 12090 if (expression is Identifier) { |
| 11859 element = ((expression as Identifier)).element; | 12091 element = ((expression as Identifier)).element; |
| 11860 } | 12092 } |
| 11861 if (expression is PropertyAccess) { | 12093 if (expression is PropertyAccess) { |
| 11862 element = ((expression as PropertyAccess)).propertyName.element; | 12094 element = ((expression as PropertyAccess)).propertyName.element; |
| 11863 } | 12095 } |
| 11864 if (element is VariableElement) { | 12096 if (element is VariableElement) { |
| 11865 VariableElement leftVar = element as VariableElement; | 12097 VariableElement leftVar = element as VariableElement; |
| 11866 if (leftVar.isFinal) { | 12098 if (leftVar.isFinal) { |
| 11867 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_FINAL, expre
ssion, []); | 12099 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_FINAL, expre
ssion, []); |
| 11868 return true; | 12100 return true; |
| 11869 } | 12101 } |
| 11870 return false; | 12102 return false; |
| 11871 } | 12103 } |
| 11872 if (element is PropertyAccessorElement) { | 12104 if (element is PropertyAccessorElement) { |
| 11873 PropertyAccessorElement leftAccessor = element as PropertyAccessorElement; | 12105 PropertyAccessorElement leftAccessor = element as PropertyAccessorElement; |
| 11874 if (!leftAccessor.isSetter) { | 12106 if (!leftAccessor.isSetter) { |
| 11875 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_FINAL, expre
ssion, []); | 12107 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_FINAL, expre
ssion, []); |
| 11876 return true; | 12108 return true; |
| 11877 } | 12109 } |
| 11878 return false; | 12110 return false; |
| 11879 } | 12111 } |
| 12112 if (element is MethodElement) { |
| 12113 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_METHOD, expres
sion, []); |
| 12114 return true; |
| 12115 } |
| 11880 return false; | 12116 return false; |
| 11881 } | 12117 } |
| 11882 | 12118 |
| 11883 /** | 12119 /** |
| 11884 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code | 12120 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code |
| 11885 * on the identifier if it is a keyword. | 12121 * on the identifier if it is a keyword. |
| 11886 * | 12122 * |
| 11887 * @param identifier the identifier to check to ensure that it is not a keywor
d | 12123 * @param identifier the identifier to check to ensure that it is not a keywor
d |
| 11888 * @param errorCode if the passed identifier is a keyword then this error code
is created on the | 12124 * @param errorCode if the passed identifier is a keyword then this error code
is created on the |
| 11889 * identifier, the error code will be one of | 12125 * identifier, the error code will be one of |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12091 return false; | 12327 return false; |
| 12092 } | 12328 } |
| 12093 bool hasProblem = false; | 12329 bool hasProblem = false; |
| 12094 for (MethodElement method in _enclosingClass.methods) { | 12330 for (MethodElement method in _enclosingClass.methods) { |
| 12095 String name = method.name; | 12331 String name = method.name; |
| 12096 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo
singClass, name); | 12332 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo
singClass, name); |
| 12097 if (inherited is! PropertyAccessorElement) { | 12333 if (inherited is! PropertyAccessorElement) { |
| 12098 continue; | 12334 continue; |
| 12099 } | 12335 } |
| 12100 hasProblem = true; | 12336 hasProblem = true; |
| 12101 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_GETTER_AND_ME
THOD, method.nameOffset, name.length, [_enclosingClass.displayName, inherited.en
closingElement.displayName, name]); | 12337 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_GETTER_AND_ME
THOD, method.nameOffset, name.length, [ |
| 12338 _enclosingClass.displayName, |
| 12339 inherited.enclosingElement.displayName, |
| 12340 name]); |
| 12102 } | 12341 } |
| 12103 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 12342 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
| 12104 if (!accessor.isGetter) { | 12343 if (!accessor.isGetter) { |
| 12105 continue; | 12344 continue; |
| 12106 } | 12345 } |
| 12107 String name = accessor.name; | 12346 String name = accessor.name; |
| 12108 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo
singClass, name); | 12347 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo
singClass, name); |
| 12109 if (inherited is! MethodElement) { | 12348 if (inherited is! MethodElement) { |
| 12110 continue; | 12349 continue; |
| 12111 } | 12350 } |
| 12112 hasProblem = true; | 12351 hasProblem = true; |
| 12113 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_METHOD_AND_GE
TTER, accessor.nameOffset, name.length, [_enclosingClass.displayName, inherited.
enclosingElement.displayName, name]); | 12352 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_METHOD_AND_GE
TTER, accessor.nameOffset, name.length, [ |
| 12353 _enclosingClass.displayName, |
| 12354 inherited.enclosingElement.displayName, |
| 12355 name]); |
| 12114 } | 12356 } |
| 12115 return hasProblem; | 12357 return hasProblem; |
| 12116 } | 12358 } |
| 12117 | 12359 |
| 12118 /** | 12360 /** |
| 12119 * This verifies that the superclass of the enclosing class does not declare a
ccessible static | 12361 * This verifies that the superclass of the enclosing class does not declare a
ccessible static |
| 12120 * member with the same name as the passed instance getter/setter method decla
ration. | 12362 * member with the same name as the passed instance getter/setter method decla
ration. |
| 12121 * | 12363 * |
| 12122 * @param node the method declaration to evaluate | 12364 * @param node the method declaration to evaluate |
| 12123 * @return `true` if and only if an error code is generated on the passed node | 12365 * @return `true` if and only if an error code is generated on the passed node |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12497 } | 12739 } |
| 12498 ExportElement nodeExportElement = nodeElement as ExportElement; | 12740 ExportElement nodeExportElement = nodeElement as ExportElement; |
| 12499 LibraryElement nodeLibrary = nodeExportElement.exportedLibrary; | 12741 LibraryElement nodeLibrary = nodeExportElement.exportedLibrary; |
| 12500 if (nodeLibrary == null) { | 12742 if (nodeLibrary == null) { |
| 12501 return false; | 12743 return false; |
| 12502 } | 12744 } |
| 12503 String name = nodeLibrary.name; | 12745 String name = nodeLibrary.name; |
| 12504 LibraryElement prevLibrary = _nameToExportElement[name]; | 12746 LibraryElement prevLibrary = _nameToExportElement[name]; |
| 12505 if (prevLibrary != null) { | 12747 if (prevLibrary != null) { |
| 12506 if (prevLibrary != nodeLibrary) { | 12748 if (prevLibrary != nodeLibrary) { |
| 12507 _errorReporter.reportError2(StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name]); | 12749 _errorReporter.reportError2(StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_
NAME, node, [ |
| 12750 prevLibrary.definingCompilationUnit.displayName, |
| 12751 nodeLibrary.definingCompilationUnit.displayName, |
| 12752 name]); |
| 12508 return true; | 12753 return true; |
| 12509 } | 12754 } |
| 12510 } else { | 12755 } else { |
| 12511 _nameToExportElement[name] = nodeLibrary; | 12756 _nameToExportElement[name] = nodeLibrary; |
| 12512 } | 12757 } |
| 12513 return false; | 12758 return false; |
| 12514 } | 12759 } |
| 12515 | 12760 |
| 12516 /** | 12761 /** |
| 12517 * Check that if the visiting library is not system, then any passed library s
hould not be SDK | 12762 * Check that if the visiting library is not system, then any passed library s
hould not be SDK |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12624 } else { | 12869 } else { |
| 12625 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSI
GNABLE, expression, [staticType.displayName, fieldType.displayName]); | 12870 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSI
GNABLE, expression, [staticType.displayName, fieldType.displayName]); |
| 12626 } | 12871 } |
| 12627 return true; | 12872 return true; |
| 12628 } | 12873 } |
| 12629 Type2 propagatedType = getPropagatedType(expression); | 12874 Type2 propagatedType = getPropagatedType(expression); |
| 12630 if (propagatedType != null && propagatedType.isAssignableTo(fieldType)) { | 12875 if (propagatedType != null && propagatedType.isAssignableTo(fieldType)) { |
| 12631 return false; | 12876 return false; |
| 12632 } | 12877 } |
| 12633 if (_isEnclosingConstructorConst) { | 12878 if (_isEnclosingConstructorConst) { |
| 12634 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N
OT_ASSIGNABLE, expression, [(propagatedType == null ? staticType : propagatedTyp
e).displayName, fieldType.displayName]); | 12879 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N
OT_ASSIGNABLE, expression, [ |
| 12880 (propagatedType == null ? staticType : propagatedType).displayName, |
| 12881 fieldType.displayName]); |
| 12635 } else { | 12882 } else { |
| 12636 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN
ABLE, expression, [(propagatedType == null ? staticType : propagatedType).displa
yName, fieldType.displayName]); | 12883 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN
ABLE, expression, [ |
| 12884 (propagatedType == null ? staticType : propagatedType).displayName, |
| 12885 fieldType.displayName]); |
| 12637 } | 12886 } |
| 12638 return true; | 12887 return true; |
| 12639 } | 12888 } |
| 12640 | 12889 |
| 12641 /** | 12890 /** |
| 12642 * This verifies that the passed field formal parameter is in a constructor de
claration. | 12891 * This verifies that the passed field formal parameter is in a constructor de
claration. |
| 12643 * | 12892 * |
| 12644 * @param node the field formal parameter to test | 12893 * @param node the field formal parameter to test |
| 12645 * @return `true` if and only if an error code is generated on the passed node | 12894 * @return `true` if and only if an error code is generated on the passed node |
| 12646 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR | 12895 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12695 * list is final or const. This method is called by | 12944 * list is final or const. This method is called by |
| 12696 * [checkForFinalNotInitialized], | 12945 * [checkForFinalNotInitialized], |
| 12697 * [visitTopLevelVariableDeclaration] and | 12946 * [visitTopLevelVariableDeclaration] and |
| 12698 * [visitVariableDeclarationStatement]. | 12947 * [visitVariableDeclarationStatement]. |
| 12699 * | 12948 * |
| 12700 * @param node the class declaration to test | 12949 * @param node the class declaration to test |
| 12701 * @return `true` if and only if an error code is generated on the passed node | 12950 * @return `true` if and only if an error code is generated on the passed node |
| 12702 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 12951 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED |
| 12703 */ | 12952 */ |
| 12704 bool checkForFinalNotInitialized2(VariableDeclarationList node) { | 12953 bool checkForFinalNotInitialized2(VariableDeclarationList node) { |
| 12954 if (_isInNativeClass) { |
| 12955 return false; |
| 12956 } |
| 12705 bool foundError = false; | 12957 bool foundError = false; |
| 12706 if (!node.isSynthetic && (node.isConst || node.isFinal)) { | 12958 if (!node.isSynthetic && (node.isConst || node.isFinal)) { |
| 12707 NodeList<VariableDeclaration> variables = node.variables; | 12959 NodeList<VariableDeclaration> variables = node.variables; |
| 12708 for (VariableDeclaration variable in variables) { | 12960 for (VariableDeclaration variable in variables) { |
| 12709 if (variable.initializer == null) { | 12961 if (variable.initializer == null) { |
| 12710 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, v
ariable, [variable.name.name]); | 12962 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, v
ariable.name, [variable.name.name]); |
| 12711 foundError = true; | 12963 foundError = true; |
| 12712 } | 12964 } |
| 12713 } | 12965 } |
| 12714 } | 12966 } |
| 12715 return foundError; | 12967 return foundError; |
| 12716 } | 12968 } |
| 12717 | 12969 |
| 12718 /** | 12970 /** |
| 12719 * This verifies that the passed implements clause does not implement classes
such as 'num' or | 12971 * This verifies that the passed implements clause does not implement classes
such as 'num' or |
| 12720 * 'String'. | 12972 * 'String'. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 12737 /** | 12989 /** |
| 12738 * This verifies that if the passed identifier is part of constructor initiali
zer, then it does | 12990 * This verifies that if the passed identifier is part of constructor initiali
zer, then it does |
| 12739 * not reference implicitly 'this' expression. | 12991 * not reference implicitly 'this' expression. |
| 12740 * | 12992 * |
| 12741 * @param node the simple identifier to test | 12993 * @param node the simple identifier to test |
| 12742 * @return `true` if and only if an error code is generated on the passed node | 12994 * @return `true` if and only if an error code is generated on the passed node |
| 12743 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER | 12995 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER |
| 12744 * @see CompileTimeErrorCode#INSTANCE_MEMBER_ACCESS_FROM_STATIC TODO(scheglov)
rename thid method | 12996 * @see CompileTimeErrorCode#INSTANCE_MEMBER_ACCESS_FROM_STATIC TODO(scheglov)
rename thid method |
| 12745 */ | 12997 */ |
| 12746 bool checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { | 12998 bool checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { |
| 12747 if (!_isInConstructorInitializer && !_isInStaticMethod && !_isInInstanceVari
ableInitializer) { | 12999 if (!_isInConstructorInitializer && !_isInStaticMethod && !_isInInstanceVari
ableInitializer && !_isInStaticVariableDeclaration) { |
| 12748 return false; | 13000 return false; |
| 12749 } | 13001 } |
| 12750 Element element = node.element; | 13002 Element element = node.element; |
| 12751 if (!(element is MethodElement || element is PropertyAccessorElement)) { | 13003 if (!(element is MethodElement || element is PropertyAccessorElement)) { |
| 12752 return false; | 13004 return false; |
| 12753 } | 13005 } |
| 12754 ExecutableElement executableElement = element as ExecutableElement; | 13006 ExecutableElement executableElement = element as ExecutableElement; |
| 12755 if (executableElement.isStatic) { | 13007 if (executableElement.isStatic) { |
| 12756 return false; | 13008 return false; |
| 12757 } | 13009 } |
| 12758 Element enclosingElement = element.enclosingElement; | 13010 Element enclosingElement = element.enclosingElement; |
| 12759 if (enclosingElement is! ClassElement) { | 13011 if (enclosingElement is! ClassElement) { |
| 12760 return false; | 13012 return false; |
| 12761 } | 13013 } |
| 12762 ASTNode parent = node.parent; | 13014 ASTNode parent = node.parent; |
| 12763 if (parent is CommentReference) { | 13015 if (parent is CommentReference) { |
| 12764 return false; | 13016 return false; |
| 12765 } | 13017 } |
| 12766 if (parent is MethodInvocation) { | 13018 if (parent is MethodInvocation) { |
| 12767 MethodInvocation invocation = parent as MethodInvocation; | 13019 MethodInvocation invocation = parent as MethodInvocation; |
| 12768 if (identical(invocation.methodName, node) && invocation.realTarget != nul
l) { | 13020 if (identical(invocation.methodName, node) && invocation.realTarget != nul
l) { |
| 12769 return false; | 13021 return false; |
| 12770 } | 13022 } |
| 12771 } | 13023 } |
| 12772 { | 13024 if (parent is PropertyAccess) { |
| 12773 if (parent is PropertyAccess) { | 13025 PropertyAccess access = parent as PropertyAccess; |
| 12774 PropertyAccess access = parent as PropertyAccess; | 13026 if (identical(access.propertyName, node) && access.realTarget != null) { |
| 12775 if (identical(access.propertyName, node) && access.realTarget != null) { | 13027 return false; |
| 12776 return false; | |
| 12777 } | |
| 12778 } | |
| 12779 if (parent is PrefixedIdentifier) { | |
| 12780 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; | |
| 12781 if (identical(prefixed.identifier, node)) { | |
| 12782 return false; | |
| 12783 } | |
| 12784 } | 13028 } |
| 12785 } | 13029 } |
| 12786 if (_isInConstructorInitializer || _isInInstanceVariableInitializer) { | 13030 if (parent is PrefixedIdentifier) { |
| 13031 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; |
| 13032 if (identical(prefixed.identifier, node)) { |
| 13033 return false; |
| 13034 } |
| 13035 } |
| 13036 if (_isInStaticMethod) { |
| 13037 _errorReporter.reportError2(CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FR
OM_STATIC, node, []); |
| 13038 } else { |
| 12787 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_I
N_INITIALIZER, node, []); | 13039 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_I
N_INITIALIZER, node, []); |
| 12788 } else if (_isInStaticMethod) { | |
| 12789 _errorReporter.reportError2(CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FR
OM_STATIC, node, []); | |
| 12790 } | 13040 } |
| 12791 return true; | 13041 return true; |
| 12792 } | 13042 } |
| 12793 | 13043 |
| 12794 /** | 13044 /** |
| 12795 * This verifies the passed import has unique name among other imported librar
ies. | 13045 * This verifies the passed import has unique name among other imported librar
ies. |
| 12796 * | 13046 * |
| 12797 * @param node the import directive to evaluate | 13047 * @param node the import directive to evaluate |
| 12798 * @return `true` if and only if an error code is generated on the passed node | 13048 * @return `true` if and only if an error code is generated on the passed node |
| 12799 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME | 13049 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME |
| 12800 */ | 13050 */ |
| 12801 bool checkForImportDuplicateLibraryName(ImportDirective node) { | 13051 bool checkForImportDuplicateLibraryName(ImportDirective node) { |
| 12802 Element nodeElement = node.element; | 13052 Element nodeElement = node.element; |
| 12803 if (nodeElement is! ImportElement) { | 13053 if (nodeElement is! ImportElement) { |
| 12804 return false; | 13054 return false; |
| 12805 } | 13055 } |
| 12806 ImportElement nodeImportElement = nodeElement as ImportElement; | 13056 ImportElement nodeImportElement = nodeElement as ImportElement; |
| 12807 LibraryElement nodeLibrary = nodeImportElement.importedLibrary; | 13057 LibraryElement nodeLibrary = nodeImportElement.importedLibrary; |
| 12808 if (nodeLibrary == null) { | 13058 if (nodeLibrary == null) { |
| 12809 return false; | 13059 return false; |
| 12810 } | 13060 } |
| 12811 String name = nodeLibrary.name; | 13061 String name = nodeLibrary.name; |
| 12812 LibraryElement prevLibrary = _nameToImportElement[name]; | 13062 LibraryElement prevLibrary = _nameToImportElement[name]; |
| 12813 if (prevLibrary != null) { | 13063 if (prevLibrary != null) { |
| 12814 if (prevLibrary != nodeLibrary) { | 13064 if (prevLibrary != nodeLibrary) { |
| 12815 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name]); | 13065 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_
NAME, node, [ |
| 13066 prevLibrary.definingCompilationUnit.displayName, |
| 13067 nodeLibrary.definingCompilationUnit.displayName, |
| 13068 name]); |
| 12816 return true; | 13069 return true; |
| 12817 } | 13070 } |
| 12818 } else { | 13071 } else { |
| 12819 _nameToImportElement[name] = nodeLibrary; | 13072 _nameToImportElement[name] = nodeLibrary; |
| 12820 } | 13073 } |
| 12821 return false; | 13074 return false; |
| 12822 } | 13075 } |
| 12823 | 13076 |
| 12824 /** | 13077 /** |
| 12825 * Check that if the visiting library is not system, then any passed library s
hould not be SDK | 13078 * Check that if the visiting library is not system, then any passed library s
hould not be SDK |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13012 for (TypeName typeName in arguments) { | 13265 for (TypeName typeName in arguments) { |
| 13013 if (typeName.type is TypeVariableType) { | 13266 if (typeName.type is TypeVariableType) { |
| 13014 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); | 13267 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); |
| 13015 foundError = true; | 13268 foundError = true; |
| 13016 } | 13269 } |
| 13017 } | 13270 } |
| 13018 return foundError; | 13271 return foundError; |
| 13019 } | 13272 } |
| 13020 | 13273 |
| 13021 /** | 13274 /** |
| 13275 * This verifies that the elements given [ListLiteral] are subtypes of the spe
cified element |
| 13276 * type. |
| 13277 * |
| 13278 * @param node the list literal to evaluate |
| 13279 * @return `true` if and only if an error code is generated on the passed node |
| 13280 * @see CompileTimeErrorCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE |
| 13281 * @see StaticWarningCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE |
| 13282 */ |
| 13283 bool checkForListElementTypeNotAssignable(ListLiteral node) { |
| 13284 TypeArgumentList typeArgumentList = node.typeArguments; |
| 13285 if (typeArgumentList == null) { |
| 13286 return false; |
| 13287 } |
| 13288 NodeList<TypeName> typeArguments = typeArgumentList.arguments; |
| 13289 if (typeArguments.length < 1) { |
| 13290 return false; |
| 13291 } |
| 13292 Type2 listElementType = typeArguments[0].type; |
| 13293 ErrorCode errorCode; |
| 13294 if (node.modifier != null) { |
| 13295 errorCode = CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE; |
| 13296 } else { |
| 13297 errorCode = StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE; |
| 13298 } |
| 13299 bool hasProblems = false; |
| 13300 for (Expression element in node.elements) { |
| 13301 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable
3(element, listElementType, null, errorCode)); |
| 13302 } |
| 13303 return hasProblems; |
| 13304 } |
| 13305 |
| 13306 /** |
| 13307 * This verifies that the key/value of entries of the given [MapLiteral] are s
ubtypes of the |
| 13308 * key/value types specified in the type arguments. |
| 13309 * |
| 13310 * @param node the map literal to evaluate |
| 13311 * @return `true` if and only if an error code is generated on the passed node |
| 13312 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE |
| 13313 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE |
| 13314 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE |
| 13315 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE |
| 13316 */ |
| 13317 bool checkForMapTypeNotAssignable(MapLiteral node) { |
| 13318 TypeArgumentList typeArgumentList = node.typeArguments; |
| 13319 if (typeArgumentList == null) { |
| 13320 return false; |
| 13321 } |
| 13322 NodeList<TypeName> typeArguments = typeArgumentList.arguments; |
| 13323 if (typeArguments.length < 2) { |
| 13324 return false; |
| 13325 } |
| 13326 Type2 keyType = typeArguments[0].type; |
| 13327 Type2 valueType = typeArguments[1].type; |
| 13328 ErrorCode keyErrorCode; |
| 13329 ErrorCode valueErrorCode; |
| 13330 if (node.modifier != null) { |
| 13331 keyErrorCode = CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE; |
| 13332 valueErrorCode = CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE; |
| 13333 } else { |
| 13334 keyErrorCode = StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE; |
| 13335 valueErrorCode = StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE; |
| 13336 } |
| 13337 bool hasProblems = false; |
| 13338 NodeList<MapLiteralEntry> entries = node.entries; |
| 13339 for (MapLiteralEntry entry in entries) { |
| 13340 Expression key = entry.key; |
| 13341 Expression value = entry.value; |
| 13342 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable
3(key, keyType, null, keyErrorCode)); |
| 13343 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable
3(value, valueType, null, valueErrorCode)); |
| 13344 } |
| 13345 return hasProblems; |
| 13346 } |
| 13347 |
| 13348 /** |
| 13022 * This verifies that the [enclosingClass] does not define members with the sa
me name as | 13349 * This verifies that the [enclosingClass] does not define members with the sa
me name as |
| 13023 * the enclosing class. | 13350 * the enclosing class. |
| 13024 * | 13351 * |
| 13025 * @return `true` if and only if an error code is generated on the passed node | 13352 * @return `true` if and only if an error code is generated on the passed node |
| 13026 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME | 13353 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME |
| 13027 */ | 13354 */ |
| 13028 bool checkForMemberWithClassName() { | 13355 bool checkForMemberWithClassName() { |
| 13029 if (_enclosingClass == null) { | 13356 if (_enclosingClass == null) { |
| 13030 return false; | 13357 return false; |
| 13031 } | 13358 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13064 Type2 setterType = null; | 13391 Type2 setterType = null; |
| 13065 if (propertyAccessorElement.isGetter) { | 13392 if (propertyAccessorElement.isGetter) { |
| 13066 getterType = getGetterType(propertyAccessorElement); | 13393 getterType = getGetterType(propertyAccessorElement); |
| 13067 setterType = getSetterType(counterpartAccessor); | 13394 setterType = getSetterType(counterpartAccessor); |
| 13068 } else if (propertyAccessorElement.isSetter) { | 13395 } else if (propertyAccessorElement.isSetter) { |
| 13069 setterType = getSetterType(propertyAccessorElement); | 13396 setterType = getSetterType(propertyAccessorElement); |
| 13070 counterpartAccessor = propertyAccessorElement.correspondingGetter; | 13397 counterpartAccessor = propertyAccessorElement.correspondingGetter; |
| 13071 getterType = getGetterType(counterpartAccessor); | 13398 getterType = getGetterType(counterpartAccessor); |
| 13072 } | 13399 } |
| 13073 if (setterType != null && getterType != null && !getterType.isAssignableTo(s
etterType)) { | 13400 if (setterType != null && getterType != null && !getterType.isAssignableTo(s
etterType)) { |
| 13074 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER
_TYPES, accessorDeclaration, [accessorTextName, setterType.displayName, getterTy
pe.displayName]); | 13401 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER
_TYPES, accessorDeclaration, [ |
| 13402 accessorTextName, |
| 13403 setterType.displayName, |
| 13404 getterType.displayName]); |
| 13075 } | 13405 } |
| 13076 } | 13406 } |
| 13077 | 13407 |
| 13078 /** | 13408 /** |
| 13079 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. | 13409 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. |
| 13080 * | 13410 * |
| 13081 * @param mixinName the node to report problem on | 13411 * @param mixinName the node to report problem on |
| 13082 * @param mixinElement the mixing to evaluate | 13412 * @param mixinElement the mixing to evaluate |
| 13083 * @return `true` if and only if an error code is generated on the passed node | 13413 * @return `true` if and only if an error code is generated on the passed node |
| 13084 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR | 13414 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13308 stringMembersArrayListSet.add(newStrMember); | 13638 stringMembersArrayListSet.add(newStrMember); |
| 13309 } | 13639 } |
| 13310 } | 13640 } |
| 13311 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); | 13641 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); |
| 13312 AnalysisErrorWithProperties analysisError; | 13642 AnalysisErrorWithProperties analysisError; |
| 13313 if (stringMembersArray.length == 1) { | 13643 if (stringMembersArray.length == 1) { |
| 13314 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, node.name, [stringMembersArray[0]
]); | 13644 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, node.name, [stringMembersArray[0]
]); |
| 13315 } else if (stringMembersArray.length == 2) { | 13645 } else if (stringMembersArray.length == 2) { |
| 13316 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, node.name, [stringMembersArray[0]
, stringMembersArray[1]]); | 13646 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, node.name, [stringMembersArray[0]
, stringMembersArray[1]]); |
| 13317 } else if (stringMembersArray.length == 3) { | 13647 } else if (stringMembersArray.length == 3) { |
| 13318 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, node.name, [stringMembersArray[
0], stringMembersArray[1], stringMembersArray[2]]); | 13648 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, node.name, [ |
| 13649 stringMembersArray[0], |
| 13650 stringMembersArray[1], |
| 13651 stringMembersArray[2]]); |
| 13319 } else if (stringMembersArray.length == 4) { | 13652 } else if (stringMembersArray.length == 4) { |
| 13320 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, node.name, [stringMembersArray[0
], stringMembersArray[1], stringMembersArray[2], stringMembersArray[3]]); | 13653 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, node.name, [ |
| 13654 stringMembersArray[0], |
| 13655 stringMembersArray[1], |
| 13656 stringMembersArray[2], |
| 13657 stringMembersArray[3]]); |
| 13321 } else { | 13658 } else { |
| 13322 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS, node.name, [stringMembersAr
ray[0], stringMembersArray[1], stringMembersArray[2], stringMembersArray[3], str
ingMembersArray.length - 4]); | 13659 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS, node.name, [ |
| 13660 stringMembersArray[0], |
| 13661 stringMembersArray[1], |
| 13662 stringMembersArray[2], |
| 13663 stringMembersArray[3], |
| 13664 stringMembersArray.length - 4]); |
| 13323 } | 13665 } |
| 13324 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri
desArray); | 13666 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri
desArray); |
| 13325 _errorReporter.reportError(analysisError); | 13667 _errorReporter.reportError(analysisError); |
| 13326 return true; | 13668 return true; |
| 13327 } | 13669 } |
| 13328 | 13670 |
| 13329 /** | 13671 /** |
| 13330 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is | 13672 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is |
| 13331 * reported on the expression. | 13673 * reported on the expression. |
| 13332 * | 13674 * |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13719 */ | 14061 */ |
| 13720 bool checkForRethrowOutsideCatch(RethrowExpression node) { | 14062 bool checkForRethrowOutsideCatch(RethrowExpression node) { |
| 13721 if (!_isInCatchClause) { | 14063 if (!_isInCatchClause) { |
| 13722 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no
de, []); | 14064 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no
de, []); |
| 13723 return true; | 14065 return true; |
| 13724 } | 14066 } |
| 13725 return false; | 14067 return false; |
| 13726 } | 14068 } |
| 13727 | 14069 |
| 13728 /** | 14070 /** |
| 14071 * This checks that if the the given constructor declaration is generative, th
en it does not have |
| 14072 * an expression function body. |
| 14073 * |
| 14074 * @param node the constructor to evaluate |
| 14075 * @return `true` if and only if an error code is generated on the passed node |
| 14076 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR |
| 14077 */ |
| 14078 bool checkForReturnInGenerativeConstructor(ConstructorDeclaration node) { |
| 14079 if (node.factoryKeyword != null) { |
| 14080 return false; |
| 14081 } |
| 14082 FunctionBody body = node.body; |
| 14083 if (body is! ExpressionFunctionBody) { |
| 14084 return false; |
| 14085 } |
| 14086 _errorReporter.reportError2(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTR
UCTOR, body, []); |
| 14087 return true; |
| 14088 } |
| 14089 |
| 14090 /** |
| 13729 * This checks that a type mis-match between the return type and the expressed
return type by the | 14091 * This checks that a type mis-match between the return type and the expressed
return type by the |
| 13730 * enclosing method or function. | 14092 * enclosing method or function. |
| 13731 * | 14093 * |
| 13732 * This method is called both by [checkForAllReturnStatementErrorCodes] | 14094 * This method is called both by [checkForAllReturnStatementErrorCodes] |
| 13733 * and [visitExpressionFunctionBody]. | 14095 * and [visitExpressionFunctionBody]. |
| 13734 * | 14096 * |
| 13735 * @param returnExpression the returned expression to evaluate | 14097 * @param returnExpression the returned expression to evaluate |
| 13736 * @param expectedReturnType the expressed return type by the enclosing method
or function | 14098 * @param expectedReturnType the expressed return type by the enclosing method
or function |
| 13737 * @return `true` if and only if an error code is generated on the passed node | 14099 * @return `true` if and only if an error code is generated on the passed node |
| 13738 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE | 14100 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE |
| 13739 */ | 14101 */ |
| 13740 bool checkForReturnOfInvalidType(Expression returnExpression, Type2 expectedRe
turnType) { | 14102 bool checkForReturnOfInvalidType(Expression returnExpression, Type2 expectedRe
turnType) { |
| 13741 Type2 staticReturnType = getStaticType(returnExpression); | 14103 Type2 staticReturnType = getStaticType(returnExpression); |
| 13742 if (expectedReturnType.isVoid) { | 14104 if (expectedReturnType.isVoid) { |
| 13743 if (staticReturnType.isVoid || staticReturnType.isDynamic || identical(sta
ticReturnType, BottomTypeImpl.instance)) { | 14105 if (staticReturnType.isVoid || staticReturnType.isDynamic || identical(sta
ticReturnType, BottomTypeImpl.instance)) { |
| 13744 return false; | 14106 return false; |
| 13745 } | 14107 } |
| 13746 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | 14108 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [ |
| 14109 staticReturnType.displayName, |
| 14110 expectedReturnType.displayName, |
| 14111 _enclosingFunction.displayName]); |
| 13747 return true; | 14112 return true; |
| 13748 } | 14113 } |
| 13749 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType
); | 14114 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType
); |
| 13750 Type2 propagatedReturnType = getPropagatedType(returnExpression); | 14115 Type2 propagatedReturnType = getPropagatedType(returnExpression); |
| 13751 if (_strictMode || propagatedReturnType == null) { | 14116 if (_strictMode || propagatedReturnType == null) { |
| 13752 if (isStaticAssignable) { | 14117 if (isStaticAssignable) { |
| 13753 return false; | 14118 return false; |
| 13754 } | 14119 } |
| 13755 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | 14120 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [ |
| 14121 staticReturnType.displayName, |
| 14122 expectedReturnType.displayName, |
| 14123 _enclosingFunction.displayName]); |
| 13756 return true; | 14124 return true; |
| 13757 } else { | 14125 } else { |
| 13758 bool isPropagatedAssignable = propagatedReturnType.isAssignableTo(expected
ReturnType); | 14126 bool isPropagatedAssignable = propagatedReturnType.isAssignableTo(expected
ReturnType); |
| 13759 if (isStaticAssignable || isPropagatedAssignable) { | 14127 if (isStaticAssignable || isPropagatedAssignable) { |
| 13760 return false; | 14128 return false; |
| 13761 } | 14129 } |
| 13762 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | 14130 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [ |
| 14131 staticReturnType.displayName, |
| 14132 expectedReturnType.displayName, |
| 14133 _enclosingFunction.displayName]); |
| 13763 return true; | 14134 return true; |
| 13764 } | 14135 } |
| 13765 } | 14136 } |
| 13766 | 14137 |
| 13767 /** | 14138 /** |
| 13768 * This checks that if the given "target" is the type reference then the "name
" is not the | 14139 * This checks that if the given "target" is the type reference then the "name
" is not the |
| 13769 * reference to a instance member. | 14140 * reference to a instance member. |
| 13770 * | 14141 * |
| 13771 * @param target the target of the name access to evaluate | 14142 * @param target the target of the name access to evaluate |
| 13772 * @param name the accessed name to evaluate | 14143 * @param name the accessed name to evaluate |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14010 } | 14381 } |
| 14011 NodeList<FormalParameter> parameters = parameterList.parameters; | 14382 NodeList<FormalParameter> parameters = parameterList.parameters; |
| 14012 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED)
{ | 14383 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED)
{ |
| 14013 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_SETTER, setterName, []); | 14384 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_SETTER, setterName, []); |
| 14014 return true; | 14385 return true; |
| 14015 } | 14386 } |
| 14016 return false; | 14387 return false; |
| 14017 } | 14388 } |
| 14018 | 14389 |
| 14019 /** | 14390 /** |
| 14391 * This verifies that the given class declaration does not have the same class
in the 'extends' |
| 14392 * and 'implements' clauses. |
| 14393 * |
| 14394 * @return `true` if and only if an error code is generated on the passed node |
| 14395 * @see CompileTimeErrorCode#IMPLEMENTS_SUPER_CLASS |
| 14396 */ |
| 14397 bool checkImplementsSuperClass(ClassDeclaration node) { |
| 14398 InterfaceType superType = _enclosingClass.supertype; |
| 14399 if (superType == null) { |
| 14400 return false; |
| 14401 } |
| 14402 ImplementsClause implementsClause = node.implementsClause; |
| 14403 if (implementsClause == null) { |
| 14404 return false; |
| 14405 } |
| 14406 bool hasProblem = false; |
| 14407 for (TypeName interfaceNode in implementsClause.interfaces) { |
| 14408 if (interfaceNode.type == superType) { |
| 14409 hasProblem = true; |
| 14410 _errorReporter.reportError2(CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS,
interfaceNode, [superType.displayName]); |
| 14411 } |
| 14412 } |
| 14413 return hasProblem; |
| 14414 } |
| 14415 |
| 14416 /** |
| 14020 * Return the propagated type of the given expression, or the static type if t
here is no | 14417 * Return the propagated type of the given expression, or the static type if t
here is no |
| 14021 * propagated type information. | 14418 * propagated type information. |
| 14022 * | 14419 * |
| 14023 * @param expression the expression whose type is to be returned | 14420 * @param expression the expression whose type is to be returned |
| 14024 * @return the propagated or static type of the given expression, whichever is
best | 14421 * @return the propagated or static type of the given expression, whichever is
best |
| 14025 */ | 14422 */ |
| 14026 Type2 getBestType(Expression expression) { | 14423 Type2 getBestType(Expression expression) { |
| 14027 Type2 type = getPropagatedType(expression); | 14424 Type2 type = getPropagatedType(expression); |
| 14028 if (type == null) { | 14425 if (type == null) { |
| 14029 type = getStaticType(expression); | 14426 type = getStaticType(expression); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14207 } | 14604 } |
| 14208 /** | 14605 /** |
| 14209 * This enum holds one of four states of a field initialization state through a
constructor | 14606 * This enum holds one of four states of a field initialization state through a
constructor |
| 14210 * signature, not initialized, initialized in the field declaration, initialized
in the field | 14607 * signature, not initialized, initialized in the field declaration, initialized
in the field |
| 14211 * formal, and finally, initialized in the initializers list. | 14608 * formal, and finally, initialized in the initializers list. |
| 14212 */ | 14609 */ |
| 14213 class INIT_STATE implements Comparable<INIT_STATE> { | 14610 class INIT_STATE implements Comparable<INIT_STATE> { |
| 14214 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0); | 14611 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0); |
| 14215 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT
ION', 1); | 14612 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT
ION', 1); |
| 14216 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F
ORMAL', 2); | 14613 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F
ORMAL', 2); |
| 14217 static final INIT_STATE INIT_IN_DEFAULT_VALUE = new INIT_STATE('INIT_IN_DEFAUL
T_VALUE', 3); | 14614 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL
IZERS', 3); |
| 14218 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL
IZERS', 4); | 14615 static final List<INIT_STATE> values = [ |
| 14219 static final List<INIT_STATE> values = [NOT_INIT, INIT_IN_DECLARATION, INIT_IN
_FIELD_FORMAL, INIT_IN_DEFAULT_VALUE, INIT_IN_INITIALIZERS]; | 14616 NOT_INIT, |
| 14617 INIT_IN_DECLARATION, |
| 14618 INIT_IN_FIELD_FORMAL, |
| 14619 INIT_IN_INITIALIZERS]; |
| 14220 | 14620 |
| 14221 /// The name of this enum constant, as declared in the enum declaration. | 14621 /// The name of this enum constant, as declared in the enum declaration. |
| 14222 final String name; | 14622 final String name; |
| 14223 | 14623 |
| 14224 /// The position in the enum declaration. | 14624 /// The position in the enum declaration. |
| 14225 final int ordinal; | 14625 final int ordinal; |
| 14226 INIT_STATE(this.name, this.ordinal); | 14626 INIT_STATE(this.name, this.ordinal); |
| 14227 int compareTo(INIT_STATE other) => ordinal - other.ordinal; | 14627 int compareTo(INIT_STATE other) => ordinal - other.ordinal; |
| 14228 int get hashCode => ordinal; | 14628 int get hashCode => ordinal; |
| 14229 String toString() => name; | 14629 String toString() => name; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14400 * resolver. The convention for this class is for the name of the error code to
indicate the problem | 14800 * resolver. The convention for this class is for the name of the error code to
indicate the problem |
| 14401 * that caused the error to be generated and for the error message to explain wh
at is wrong and, | 14801 * that caused the error to be generated and for the error message to explain wh
at is wrong and, |
| 14402 * when appropriate, how the problem can be corrected. | 14802 * when appropriate, how the problem can be corrected. |
| 14403 * | 14803 * |
| 14404 * @coverage dart.engine.resolver | 14804 * @coverage dart.engine.resolver |
| 14405 */ | 14805 */ |
| 14406 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode { | 14806 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode { |
| 14407 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro
rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la
bel resolves to case or default statement"); | 14807 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro
rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la
bel resolves to case or default statement"); |
| 14408 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod
e('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label
resolves to switch, must be loop or switch member"); | 14808 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod
e('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label
resolves to switch, must be loop or switch member"); |
| 14409 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol
verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TIME_ER
ROR, "Libraries that have parts must have a library directive"); | 14809 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol
verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TIME_ER
ROR, "Libraries that have parts must have a library directive"); |
| 14410 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART]; | 14810 static final List<ResolverErrorCode> values = [ |
| 14811 BREAK_LABEL_ON_SWITCH_MEMBER, |
| 14812 CONTINUE_LABEL_ON_SWITCH, |
| 14813 MISSING_LIBRARY_DIRECTIVE_WITH_PART]; |
| 14411 | 14814 |
| 14412 /// The name of this enum constant, as declared in the enum declaration. | 14815 /// The name of this enum constant, as declared in the enum declaration. |
| 14413 final String name; | 14816 final String name; |
| 14414 | 14817 |
| 14415 /// The position in the enum declaration. | 14818 /// The position in the enum declaration. |
| 14416 final int ordinal; | 14819 final int ordinal; |
| 14417 | 14820 |
| 14418 /** | 14821 /** |
| 14419 * The type of this error. | 14822 * The type of this error. |
| 14420 */ | 14823 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 14435 this._type = type; | 14838 this._type = type; |
| 14436 this._message = message; | 14839 this._message = message; |
| 14437 } | 14840 } |
| 14438 ErrorSeverity get errorSeverity => _type.severity; | 14841 ErrorSeverity get errorSeverity => _type.severity; |
| 14439 String get message => _message; | 14842 String get message => _message; |
| 14440 ErrorType get type => _type; | 14843 ErrorType get type => _type; |
| 14441 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; | 14844 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; |
| 14442 int get hashCode => ordinal; | 14845 int get hashCode => ordinal; |
| 14443 String toString() => name; | 14846 String toString() => name; |
| 14444 } | 14847 } |
| OLD | NEW |