| 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; |
| 11 import 'utilities_dart.dart'; | 11 import 'utilities_dart.dart'; |
| 12 import 'ast.dart'; | 12 import 'ast.dart'; |
| 13 import 'parser.dart' show Parser, ParserErrorCode; | 13 import 'parser.dart' show Parser, ParserErrorCode; |
| 14 import 'sdk.dart' show DartSdk, SdkLibrary; | 14 import 'sdk.dart' show DartSdk, SdkLibrary; |
| 15 import 'element.dart' hide Annotation, HideCombinator, ShowCombinator; | 15 import 'element.dart' hide HideCombinator, ShowCombinator; |
| 16 import 'html.dart' as ht; | 16 import 'html.dart' as ht; |
| 17 import 'engine.dart'; | 17 import 'engine.dart'; |
| 18 import 'constant.dart'; | 18 import 'constant.dart'; |
| 19 import 'element.dart' as __imp_combi show HideCombinator, ShowCombinator; | 19 import 'element.dart' as __imp_combi show HideCombinator, ShowCombinator; |
| 20 /** | 20 /** |
| 21 * Instances of the class {@code CompilationUnitBuilder} build an element model
for a single | 21 * Instances of the class {@code CompilationUnitBuilder} build an element model
for a single |
| 22 * compilation unit. | 22 * compilation unit. |
| 23 * @coverage dart.engine.resolver | 23 * @coverage dart.engine.resolver |
| 24 */ | 24 */ |
| 25 class CompilationUnitBuilder { | 25 class CompilationUnitBuilder { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 parameter = new ConstParameterElementImpl(parameterName); | 210 parameter = new ConstParameterElementImpl(parameterName); |
| 211 parameter.const3 = true; | 211 parameter.const3 = true; |
| 212 } else if (node.parameter is FieldFormalParameter) { | 212 } else if (node.parameter is FieldFormalParameter) { |
| 213 parameter = new FieldFormalParameterElementImpl(parameterName); | 213 parameter = new FieldFormalParameterElementImpl(parameterName); |
| 214 } else { | 214 } else { |
| 215 parameter = new ParameterElementImpl(parameterName); | 215 parameter = new ParameterElementImpl(parameterName); |
| 216 } | 216 } |
| 217 parameter.final2 = node.isFinal(); | 217 parameter.final2 = node.isFinal(); |
| 218 parameter.initializer = initializer; | 218 parameter.initializer = initializer; |
| 219 parameter.parameterKind = node.kind; | 219 parameter.parameterKind = node.kind; |
| 220 Expression defaultValue = node.defaultValue; |
| 221 if (defaultValue != null) { |
| 222 parameter.setDefaultValueRange(defaultValue.offset, defaultValue.length); |
| 223 } |
| 220 FunctionBody body = getFunctionBody(node); | 224 FunctionBody body = getFunctionBody(node); |
| 221 if (body != null) { | 225 if (body != null) { |
| 222 parameter.setVisibleRange(body.offset, body.length); | 226 parameter.setVisibleRange(body.offset, body.length); |
| 223 } | 227 } |
| 224 _currentHolder.addParameter(parameter); | 228 _currentHolder.addParameter(parameter); |
| 225 parameterName.element = parameter; | 229 parameterName.element = parameter; |
| 226 node.parameter.accept(this); | 230 node.parameter.accept(this); |
| 227 return null; | 231 return null; |
| 228 } | 232 } |
| 229 Object visitFieldDeclaration(FieldDeclaration node) { | 233 Object visitFieldDeclaration(FieldDeclaration node) { |
| (...skipping 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 setMetadata(node.element, node); | 2213 setMetadata(node.element, node); |
| 2210 return null; | 2214 return null; |
| 2211 } | 2215 } |
| 2212 | 2216 |
| 2213 /** | 2217 /** |
| 2214 * Generate annotation elements for each of the annotations in the given node
list and add them to | 2218 * Generate annotation elements for each of the annotations in the given node
list and add them to |
| 2215 * the given list of elements. | 2219 * the given list of elements. |
| 2216 * @param annotationList the list of elements to which new elements are to be
added | 2220 * @param annotationList the list of elements to which new elements are to be
added |
| 2217 * @param annotations the AST nodes used to generate new elements | 2221 * @param annotations the AST nodes used to generate new elements |
| 2218 */ | 2222 */ |
| 2219 void addAnnotations(List<AnnotationImpl> annotationList, NodeList<Annotation>
annotations) { | 2223 void addAnnotations(List<ElementAnnotationImpl> annotationList, NodeList<Annot
ation> annotations) { |
| 2220 for (Annotation annotationNode in annotations) { | 2224 for (Annotation annotationNode in annotations) { |
| 2221 Element resolvedElement = annotationNode.element; | 2225 Element resolvedElement = annotationNode.element; |
| 2222 if (resolvedElement != null) { | 2226 if (resolvedElement != null) { |
| 2223 annotationList.add(new AnnotationImpl(resolvedElement)); | 2227 annotationList.add(new ElementAnnotationImpl(resolvedElement)); |
| 2224 } | 2228 } |
| 2225 } | 2229 } |
| 2226 } | 2230 } |
| 2227 | 2231 |
| 2228 /** | 2232 /** |
| 2229 * Given that we have found code to invoke the given element, return the error
code that should be | 2233 * Given that we have found code to invoke the given element, return the error
code that should be |
| 2230 * reported, or {@code null} if no error should be reported. | 2234 * reported, or {@code null} if no error should be reported. |
| 2231 * @param target the target of the invocation, or {@code null} if there was no
target | 2235 * @param target the target of the invocation, or {@code null} if there was no
target |
| 2232 * @param element the element to be invoked | 2236 * @param element the element to be invoked |
| 2233 * @return the error code that should be reported | 2237 * @return the error code that should be reported |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3211 * Given a node that can have annotations associated with it and the element t
o which that node | 3215 * Given a node that can have annotations associated with it and the element t
o which that node |
| 3212 * has been resolved, create the annotations in the element model representing
the annotations on | 3216 * has been resolved, create the annotations in the element model representing
the annotations on |
| 3213 * the node. | 3217 * the node. |
| 3214 * @param element the element to which the node has been resolved | 3218 * @param element the element to which the node has been resolved |
| 3215 * @param node the node that can have annotations associated with it | 3219 * @param node the node that can have annotations associated with it |
| 3216 */ | 3220 */ |
| 3217 void setMetadata(Element element, AnnotatedNode node) { | 3221 void setMetadata(Element element, AnnotatedNode node) { |
| 3218 if (element is! ElementImpl) { | 3222 if (element is! ElementImpl) { |
| 3219 return; | 3223 return; |
| 3220 } | 3224 } |
| 3221 List<AnnotationImpl> annotationList = new List<AnnotationImpl>(); | 3225 List<ElementAnnotationImpl> annotationList = new List<ElementAnnotationImpl>
(); |
| 3222 addAnnotations(annotationList, node.metadata); | 3226 addAnnotations(annotationList, node.metadata); |
| 3223 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { | 3227 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { |
| 3224 VariableDeclarationList list = node.parent as VariableDeclarationList; | 3228 VariableDeclarationList list = node.parent as VariableDeclarationList; |
| 3225 addAnnotations(annotationList, list.metadata); | 3229 addAnnotations(annotationList, list.metadata); |
| 3226 if (list.parent is FieldDeclaration) { | 3230 if (list.parent is FieldDeclaration) { |
| 3227 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; | 3231 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; |
| 3228 addAnnotations(annotationList, fieldDeclaration.metadata); | 3232 addAnnotations(annotationList, fieldDeclaration.metadata); |
| 3229 } else if (list.parent is TopLevelVariableDeclaration) { | 3233 } else if (list.parent is TopLevelVariableDeclaration) { |
| 3230 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; | 3234 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; |
| 3231 addAnnotations(annotationList, variableDeclaration.metadata); | 3235 addAnnotations(annotationList, variableDeclaration.metadata); |
| (...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4820 * @param library the library to have the extra analyses processes run | 4824 * @param library the library to have the extra analyses processes run |
| 4821 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 4825 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 4822 * the library cannot be analyzed | 4826 * the library cannot be analyzed |
| 4823 */ | 4827 */ |
| 4824 void runAdditionalAnalyses2(Library library) { | 4828 void runAdditionalAnalyses2(Library library) { |
| 4825 for (Source source in library.compilationUnitSources) { | 4829 for (Source source in library.compilationUnitSources) { |
| 4826 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); | 4830 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); |
| 4827 CompilationUnit unit = library.getAST(source); | 4831 CompilationUnit unit = library.getAST(source); |
| 4828 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); | 4832 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); |
| 4829 unit.accept(errorVerifier); | 4833 unit.accept(errorVerifier); |
| 4830 unit.accept(new PubVerifier(errorReporter)); | 4834 unit.accept(new PubVerifier(_analysisContext, errorReporter)); |
| 4831 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); | 4835 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); |
| 4832 unit.accept(constantVerifier); | 4836 unit.accept(constantVerifier); |
| 4833 } | 4837 } |
| 4834 } | 4838 } |
| 4835 } | 4839 } |
| 4836 /** | 4840 /** |
| 4837 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes
within a single | 4841 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes
within a single |
| 4838 * compilation unit. | 4842 * compilation unit. |
| 4839 * @coverage dart.engine.resolver | 4843 * @coverage dart.engine.resolver |
| 4840 */ | 4844 */ |
| (...skipping 7060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11901 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid
es); | 11905 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid
es); |
| 11902 List<String> stringTypeArray = new List<String>(Math.min(missingOverridesSiz
e, 4)); | 11906 List<String> stringTypeArray = new List<String>(Math.min(missingOverridesSiz
e, 4)); |
| 11903 String GET = "get "; | 11907 String GET = "get "; |
| 11904 String SET = "set "; | 11908 String SET = "set "; |
| 11905 for (int i = 0; i < stringTypeArray.length; i++) { | 11909 for (int i = 0; i < stringTypeArray.length; i++) { |
| 11906 stringTypeArray[i] = StringUtilities.EMPTY; | 11910 stringTypeArray[i] = StringUtilities.EMPTY; |
| 11907 if (missingOverridesArray[i] is PropertyAccessorElement) { | 11911 if (missingOverridesArray[i] is PropertyAccessorElement) { |
| 11908 stringTypeArray[i] = ((missingOverridesArray[i] as PropertyAccessorEleme
nt)).isGetter() ? GET : SET; | 11912 stringTypeArray[i] = ((missingOverridesArray[i] as PropertyAccessorEleme
nt)).isGetter() ? GET : SET; |
| 11909 } | 11913 } |
| 11910 } | 11914 } |
| 11915 AnalysisErrorWithProperties analysisError; |
| 11911 if (missingOverridesSize == 1) { | 11916 if (missingOverridesSize == 1) { |
| 11912 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_ONE, node.name, [stringTypeArray[0], missingOverridesArray[0].en
closingElement.displayName, missingOverridesArray[0].displayName]); | 11917 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, node.name, [stringTypeArray[0], m
issingOverridesArray[0].enclosingElement.displayName, missingOverridesArray[0].d
isplayName]); |
| 11913 } else if (missingOverridesSize == 2) { | 11918 } else if (missingOverridesSize == 2) { |
| 11914 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_TWO, node.name, [stringTypeArray[0], missingOverridesArray[0].en
closingElement.displayName, missingOverridesArray[0].displayName, stringTypeArra
y[1], missingOverridesArray[1].enclosingElement.displayName, missingOverridesArr
ay[1].displayName]); | 11919 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, node.name, [stringTypeArray[0], m
issingOverridesArray[0].enclosingElement.displayName, missingOverridesArray[0].d
isplayName, stringTypeArray[1], missingOverridesArray[1].enclosingElement.displa
yName, missingOverridesArray[1].displayName]); |
| 11915 } else if (missingOverridesSize == 3) { | 11920 } else if (missingOverridesSize == 3) { |
| 11916 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_THREE, node.name, [stringTypeArray[0], missingOverridesArray[0].
enclosingElement.displayName, missingOverridesArray[0].displayName, stringTypeAr
ray[1], missingOverridesArray[1].enclosingElement.displayName, missingOverridesA
rray[1].displayName, stringTypeArray[2], missingOverridesArray[2].enclosingEleme
nt.displayName, missingOverridesArray[2].displayName]); | 11921 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, node.name, [stringTypeArray[0],
missingOverridesArray[0].enclosingElement.displayName, missingOverridesArray[0]
.displayName, stringTypeArray[1], missingOverridesArray[1].enclosingElement.disp
layName, missingOverridesArray[1].displayName, stringTypeArray[2], missingOverri
desArray[2].enclosingElement.displayName, missingOverridesArray[2].displayName])
; |
| 11917 } else if (missingOverridesSize == 4) { | 11922 } else if (missingOverridesSize == 4) { |
| 11918 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FOUR, node.name, [stringTypeArray[0], missingOverridesArray[0].e
nclosingElement.displayName, missingOverridesArray[0].displayName, stringTypeArr
ay[1], missingOverridesArray[1].enclosingElement.displayName, missingOverridesAr
ray[1].displayName, stringTypeArray[2], missingOverridesArray[2].enclosingElemen
t.displayName, missingOverridesArray[2].displayName, stringTypeArray[3], missing
OverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].display
Name]); | 11923 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, node.name, [stringTypeArray[0],
missingOverridesArray[0].enclosingElement.displayName, missingOverridesArray[0].
displayName, stringTypeArray[1], missingOverridesArray[1].enclosingElement.displ
ayName, missingOverridesArray[1].displayName, stringTypeArray[2], missingOverrid
esArray[2].enclosingElement.displayName, missingOverridesArray[2].displayName, s
tringTypeArray[3], missingOverridesArray[3].enclosingElement.displayName, missin
gOverridesArray[3].displayName]); |
| 11919 } else { | 11924 } else { |
| 11920 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FIVE_PLUS, node.name, [stringTypeArray[0], missingOverridesArray
[0].enclosingElement.displayName, missingOverridesArray[0].displayName, stringTy
peArray[1], missingOverridesArray[1].enclosingElement.displayName, missingOverri
desArray[1].displayName, stringTypeArray[2], missingOverridesArray[2].enclosingE
lement.displayName, missingOverridesArray[2].displayName, stringTypeArray[3], mi
ssingOverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].di
splayName, missingOverridesArray.length - 4]); | 11925 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS, node.name, [stringTypeArray
[0], missingOverridesArray[0].enclosingElement.displayName, missingOverridesArra
y[0].displayName, stringTypeArray[1], missingOverridesArray[1].enclosingElement.
displayName, missingOverridesArray[1].displayName, stringTypeArray[2], missingOv
erridesArray[2].enclosingElement.displayName, missingOverridesArray[2].displayNa
me, stringTypeArray[3], missingOverridesArray[3].enclosingElement.displayName, m
issingOverridesArray[3].displayName, missingOverridesArray.length - 4]); |
| 11921 } | 11926 } |
| 11927 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri
desArray); |
| 11928 _errorReporter.reportError(analysisError); |
| 11922 return true; | 11929 return true; |
| 11923 } | 11930 } |
| 11924 | 11931 |
| 11925 /** | 11932 /** |
| 11926 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is | 11933 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is |
| 11927 * reported on the expression. | 11934 * reported on the expression. |
| 11928 * @param condition the conditional expression to test | 11935 * @param condition the conditional expression to test |
| 11929 * @return {@code true} if and only if an error code is generated on the passe
d node | 11936 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11930 * @see StaticTypeWarningCode#NON_BOOL_CONDITION | 11937 * @see StaticTypeWarningCode#NON_BOOL_CONDITION |
| 11931 */ | 11938 */ |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12635 } | 12642 } |
| 12636 int compareTo(INIT_STATE other) => ordinal - other.ordinal; | 12643 int compareTo(INIT_STATE other) => ordinal - other.ordinal; |
| 12637 int get hashCode => ordinal; | 12644 int get hashCode => ordinal; |
| 12638 String toString() => name; | 12645 String toString() => name; |
| 12639 } | 12646 } |
| 12640 /** | 12647 /** |
| 12641 * Instances of the class {@code PubVerifier} traverse an AST structure looking
for deviations from | 12648 * Instances of the class {@code PubVerifier} traverse an AST structure looking
for deviations from |
| 12642 * pub best practices. | 12649 * pub best practices. |
| 12643 */ | 12650 */ |
| 12644 class PubVerifier extends RecursiveASTVisitor<Object> { | 12651 class PubVerifier extends RecursiveASTVisitor<Object> { |
| 12652 static String _PUBSPEC_YAML = "pubspec.yaml"; |
| 12653 |
| 12654 /** |
| 12655 * The analysis context containing the sources to be analyzed |
| 12656 */ |
| 12657 AnalysisContext _context; |
| 12645 | 12658 |
| 12646 /** | 12659 /** |
| 12647 * The error reporter by which errors will be reported. | 12660 * The error reporter by which errors will be reported. |
| 12648 */ | 12661 */ |
| 12649 ErrorReporter _errorReporter; | 12662 ErrorReporter _errorReporter; |
| 12650 PubVerifier(ErrorReporter errorReporter) { | 12663 PubVerifier(AnalysisContext context, ErrorReporter errorReporter) { |
| 12664 this._context = context; |
| 12651 this._errorReporter = errorReporter; | 12665 this._errorReporter = errorReporter; |
| 12652 } | 12666 } |
| 12653 Object visitImportDirective(ImportDirective directive) { | 12667 Object visitImportDirective(ImportDirective directive) { |
| 12654 return null; | 12668 return null; |
| 12655 } | 12669 } |
| 12656 | 12670 |
| 12657 /** | 12671 /** |
| 12658 * Determine if the file file path lies inside the "lib" directory hierarchy b
ut references a file | 12672 * This verifies that the passed file import directive is not contained in a s
ource inside a |
| 12659 * outside that directory hierarchy. | 12673 * package "lib" directory hierarchy referencing a source outside that package
"lib" directory |
| 12660 * @param directive the import directive (not {@code null}) | 12674 * hierarchy. |
| 12675 * @param uriLiteral the import URL (not {@code null}) |
| 12661 * @param path the file path being verified (not {@code null}) | 12676 * @param path the file path being verified (not {@code null}) |
| 12662 * @return {@code true} if the file is inside but references a file outside | 12677 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12678 * @see PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE |
| 12663 */ | 12679 */ |
| 12664 bool checkForFileImportInsideLibReferencesFileOutside(ImportDirective directiv
e, String path) { | 12680 bool checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral
, String path) { |
| 12665 String fullName = getSourceFullName(directive); | 12681 Source source = getSource(uriLiteral); |
| 12682 String fullName = getSourceFullName(source); |
| 12666 if (fullName != null) { | 12683 if (fullName != null) { |
| 12667 int pathIndex = 0; | 12684 int pathIndex = 0; |
| 12668 int fullNameIndex = fullName.length; | 12685 int fullNameIndex = fullName.length; |
| 12669 while (pathIndex < path.length && JavaString.startsWithBefore(path, "../",
pathIndex)) { | 12686 while (pathIndex < path.length && JavaString.startsWithBefore(path, "../",
pathIndex)) { |
| 12670 fullNameIndex = fullName.lastIndexOf('/', fullNameIndex); | 12687 fullNameIndex = fullName.lastIndexOf('/', fullNameIndex); |
| 12671 if (fullNameIndex < 4) { | 12688 if (fullNameIndex < 4) { |
| 12672 return false; | 12689 return false; |
| 12673 } | 12690 } |
| 12674 if (JavaString.startsWithBefore(fullName, "/lib", fullNameIndex - 4)) { | 12691 if (JavaString.startsWithBefore(fullName, "/lib", fullNameIndex - 4)) { |
| 12692 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP
EC_YAML; |
| 12693 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat
ivePubspecPath); |
| 12694 if (pubspecSource.exists()) { |
| 12695 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_INSIDE_LIB
_REFERENCES_FILE_OUTSIDE, uriLiteral, []); |
| 12696 } |
| 12675 return true; | 12697 return true; |
| 12676 } | 12698 } |
| 12677 pathIndex += 3; | 12699 pathIndex += 3; |
| 12678 } | 12700 } |
| 12679 } | 12701 } |
| 12680 return false; | 12702 return false; |
| 12681 } | 12703 } |
| 12682 | 12704 |
| 12683 /** | 12705 /** |
| 12684 * Determine if the given file path lies outside the "lib" directory hierarchy
but references a | 12706 * This verifies that the passed file import directive is not contained in a s
ource outside a |
| 12685 * file inside that directory hierarchy. | 12707 * package "lib" directory hierarchy referencing a source inside that package
"lib" directory |
| 12686 * @param directive the import directive (not {@code null}) | 12708 * hierarchy. |
| 12709 * @param uriLiteral the import URL (not {@code null}) |
| 12687 * @param path the file path being verified (not {@code null}) | 12710 * @param path the file path being verified (not {@code null}) |
| 12688 * @return {@code true} if the file is outside but references a file inside | 12711 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12712 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE |
| 12689 */ | 12713 */ |
| 12690 bool checkForFileImportOutsideLibReferencesFileInside(ImportDirective directiv
e, String path) { | 12714 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral
, String path) { |
| 12691 if (path.startsWith("lib/") || path.contains("/lib/")) { | 12715 if (path.startsWith("lib/")) { |
| 12692 String fullName = getSourceFullName(directive); | 12716 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, 0)
) { |
| 12693 if (fullName != null) { | 12717 return true; |
| 12694 if (!fullName.contains("/lib/")) { | 12718 } |
| 12695 return true; | 12719 } |
| 12696 } | 12720 int pathIndex = path.indexOf("/lib/"); |
| 12721 while (pathIndex != -1) { |
| 12722 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, pa
thIndex + 1)) { |
| 12723 return true; |
| 12724 } |
| 12725 pathIndex = path.indexOf("/lib/", pathIndex + 4); |
| 12726 } |
| 12727 return false; |
| 12728 } |
| 12729 bool checkForFileImportOutsideLibReferencesFileInside2(StringLiteral uriLitera
l, String path, int pathIndex) { |
| 12730 Source source = getSource(uriLiteral); |
| 12731 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; |
| 12732 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub
specPath); |
| 12733 if (!pubspecSource.exists()) { |
| 12734 return false; |
| 12735 } |
| 12736 String fullName = getSourceFullName(source); |
| 12737 if (fullName != null) { |
| 12738 if (!fullName.contains("/lib/")) { |
| 12739 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE
FERENCES_FILE_INSIDE, uriLiteral, []); |
| 12740 return true; |
| 12697 } | 12741 } |
| 12698 } | 12742 } |
| 12699 return false; | 12743 return false; |
| 12700 } | 12744 } |
| 12701 | 12745 |
| 12702 /** | 12746 /** |
| 12703 * Determine if the given package import path contains ".." | 12747 * This verifies that the passed package import directive does not contain "..
" |
| 12748 * @param uriLiteral the import URL (not {@code null}) |
| 12704 * @param path the path to be validated (not {@code null}) | 12749 * @param path the path to be validated (not {@code null}) |
| 12705 * @return {@code true} if the import path contains ".." | 12750 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12751 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT |
| 12706 */ | 12752 */ |
| 12707 bool checkForPackageImportContainsDotDot(String path) => path.startsWith("../"
) || path.contains("/../"); | 12753 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path
) { |
| 12754 if (path.startsWith("../") || path.contains("/../")) { |
| 12755 _errorReporter.reportError2(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_
DOT, uriLiteral, []); |
| 12756 return true; |
| 12757 } |
| 12758 return false; |
| 12759 } |
| 12708 | 12760 |
| 12709 /** | 12761 /** |
| 12710 * Answer the full name of the source associated with the compilation unit con
taining the given | 12762 * Answer the source associated with the compilation unit containing the given
AST node. |
| 12711 * AST node. The returned value will have all {@link File#separatorChar} repla
ce by '/'. | |
| 12712 * @param node the node (not {@code null}) | 12763 * @param node the node (not {@code null}) |
| 12713 * @return the full name or {@code null} if it could not be determined | 12764 * @return the source or {@code null} if it could not be determined |
| 12714 */ | 12765 */ |
| 12715 String getSourceFullName(ASTNode node) { | 12766 Source getSource(ASTNode node) { |
| 12767 Source source = null; |
| 12716 CompilationUnit unit = node.getAncestor(CompilationUnit); | 12768 CompilationUnit unit = node.getAncestor(CompilationUnit); |
| 12717 if (unit != null) { | 12769 if (unit != null) { |
| 12718 CompilationUnitElement element = unit.element; | 12770 CompilationUnitElement element = unit.element; |
| 12719 if (element != null) { | 12771 if (element != null) { |
| 12720 Source librarySource = element.source; | 12772 source = element.source; |
| 12721 if (librarySource != null) { | 12773 } |
| 12722 String fullName = librarySource.fullName; | 12774 } |
| 12723 if (fullName != null) { | 12775 return source; |
| 12724 return fullName.replaceAll(r'\', '/'); | 12776 } |
| 12725 } | 12777 |
| 12726 } | 12778 /** |
| 12779 * Answer the full name of the given source. The returned value will have all{
@link File#separatorChar} replace by '/'. |
| 12780 * @param source the source |
| 12781 * @return the full name or {@code null} if it could not be determined |
| 12782 */ |
| 12783 String getSourceFullName(Source source) { |
| 12784 if (source != null) { |
| 12785 String fullName = source.fullName; |
| 12786 if (fullName != null) { |
| 12787 return fullName.replaceAll(r'\', '/'); |
| 12727 } | 12788 } |
| 12728 } | 12789 } |
| 12729 return null; | 12790 return null; |
| 12730 } | 12791 } |
| 12731 } | 12792 } |
| 12732 /** | 12793 /** |
| 12733 * The enumeration {@code ResolverErrorCode} defines the error codes used for er
rors detected by the | 12794 * The enumeration {@code ResolverErrorCode} defines the error codes used for er
rors detected by the |
| 12734 * resolver. The convention for this class is for the name of the error code to
indicate the problem | 12795 * resolver. The convention for this class is for the name of the error code to
indicate the problem |
| 12735 * that caused the error to be generated and for the error message to explain wh
at is wrong and, | 12796 * that caused the error to be generated and for the error message to explain wh
at is wrong and, |
| 12736 * when appropriate, how the problem can be corrected. | 12797 * when appropriate, how the problem can be corrected. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 12767 this._type = type; | 12828 this._type = type; |
| 12768 this._message = message; | 12829 this._message = message; |
| 12769 } | 12830 } |
| 12770 ErrorSeverity get errorSeverity => _type.severity; | 12831 ErrorSeverity get errorSeverity => _type.severity; |
| 12771 String get message => _message; | 12832 String get message => _message; |
| 12772 ErrorType get type => _type; | 12833 ErrorType get type => _type; |
| 12773 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; | 12834 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; |
| 12774 int get hashCode => ordinal; | 12835 int get hashCode => ordinal; |
| 12775 String toString() => name; | 12836 String toString() => name; |
| 12776 } | 12837 } |
| OLD | NEW |