| 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 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2048 _duplicateImports.add(nextDirective); | 2048 _duplicateImports.add(nextDirective); |
| 2049 } else { | 2049 } else { |
| 2050 _duplicateImports.add(currentDirective); | 2050 _duplicateImports.add(currentDirective); |
| 2051 } | 2051 } |
| 2052 } | 2052 } |
| 2053 currentDirective = nextDirective; | 2053 currentDirective = nextDirective; |
| 2054 } | 2054 } |
| 2055 } | 2055 } |
| 2056 return super.visitCompilationUnit(node); | 2056 return super.visitCompilationUnit(node); |
| 2057 } | 2057 } |
| 2058 Object visitExportDirective(ExportDirective node) => null; | 2058 Object visitExportDirective(ExportDirective node) { |
| 2059 Object visitImportDirective(ImportDirective node) => null; | 2059 visitMetadata(node.metadata); |
| 2060 Object visitLibraryDirective(LibraryDirective node) => null; | 2060 return null; |
| 2061 } |
| 2062 Object visitImportDirective(ImportDirective node) { |
| 2063 visitMetadata(node.metadata); |
| 2064 return null; |
| 2065 } |
| 2066 Object visitLibraryDirective(LibraryDirective node) { |
| 2067 visitMetadata(node.metadata); |
| 2068 return null; |
| 2069 } |
| 2061 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 2070 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 2062 SimpleIdentifier prefixIdentifier = node.prefix; | 2071 SimpleIdentifier prefixIdentifier = node.prefix; |
| 2063 Element element = prefixIdentifier.staticElement; | 2072 Element element = prefixIdentifier.staticElement; |
| 2064 if (element is PrefixElement) { | 2073 if (element is PrefixElement) { |
| 2065 _unusedImports.remove(_prefixElementMap[element]); | 2074 _unusedImports.remove(_prefixElementMap[element]); |
| 2066 return null; | 2075 return null; |
| 2067 } | 2076 } |
| 2068 return visitIdentifier(element, prefixIdentifier.name); | 2077 return visitIdentifier(element, prefixIdentifier.name); |
| 2069 } | 2078 } |
| 2070 Object visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node.st
aticElement, node.name); | 2079 Object visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node.st
aticElement, node.name); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2152 } else { | 2161 } else { |
| 2153 for (ImportDirective importDirective in importsFromSameLibrary) { | 2162 for (ImportDirective importDirective in importsFromSameLibrary) { |
| 2154 Namespace namespace = computeNamespace(importDirective); | 2163 Namespace namespace = computeNamespace(importDirective); |
| 2155 if (namespace != null && namespace.get(name) != null) { | 2164 if (namespace != null && namespace.get(name) != null) { |
| 2156 _unusedImports.remove(importDirective); | 2165 _unusedImports.remove(importDirective); |
| 2157 } | 2166 } |
| 2158 } | 2167 } |
| 2159 } | 2168 } |
| 2160 return null; | 2169 return null; |
| 2161 } | 2170 } |
| 2171 |
| 2172 /** |
| 2173 * Given some [NodeList] of [Annotation]s, ensure that the identifiers are vis
ited by |
| 2174 * this visitor. Specifically, this covers the cases where AST nodes don't hav
e their identifiers |
| 2175 * visited by this visitor, but still need their annotations visited. |
| 2176 * |
| 2177 * @param annotations the list of annotations to visit |
| 2178 */ |
| 2179 void visitMetadata(NodeList<Annotation> annotations) { |
| 2180 for (Annotation annotation in annotations) { |
| 2181 Identifier name = annotation.name; |
| 2182 visitIdentifier(name.staticElement, name.name); |
| 2183 } |
| 2184 } |
| 2162 } | 2185 } |
| 2163 /** | 2186 /** |
| 2164 * Instances of the class `PubVerifier` traverse an AST structure looking for de
viations from | 2187 * Instances of the class `PubVerifier` traverse an AST structure looking for de
viations from |
| 2165 * pub best practices. | 2188 * pub best practices. |
| 2166 */ | 2189 */ |
| 2167 class PubVerifier extends RecursiveASTVisitor<Object> { | 2190 class PubVerifier extends RecursiveASTVisitor<Object> { |
| 2168 static String _PUBSPEC_YAML = "pubspec.yaml"; | 2191 static String _PUBSPEC_YAML = "pubspec.yaml"; |
| 2169 | 2192 |
| 2170 /** | 2193 /** |
| 2171 * The analysis context containing the sources to be analyzed | 2194 * The analysis context containing the sources to be analyzed |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2912 */ | 2935 */ |
| 2913 ResolverVisitor _resolver; | 2936 ResolverVisitor _resolver; |
| 2914 | 2937 |
| 2915 /** | 2938 /** |
| 2916 * A flag indicating whether we are running in strict mode. In strict mode, er
ror reporting is | 2939 * A flag indicating whether we are running in strict mode. In strict mode, er
ror reporting is |
| 2917 * based exclusively on the static type information. | 2940 * based exclusively on the static type information. |
| 2918 */ | 2941 */ |
| 2919 bool _strictMode = false; | 2942 bool _strictMode = false; |
| 2920 | 2943 |
| 2921 /** | 2944 /** |
| 2945 * A flag indicating whether we should generate hints. |
| 2946 */ |
| 2947 bool _enableHints = false; |
| 2948 |
| 2949 /** |
| 2922 * The type representing the type 'dynamic'. | 2950 * The type representing the type 'dynamic'. |
| 2923 */ | 2951 */ |
| 2924 Type2 _dynamicType; | 2952 Type2 _dynamicType; |
| 2925 | 2953 |
| 2926 /** | 2954 /** |
| 2927 * The type representing the type 'type'. | 2955 * The type representing the type 'type'. |
| 2928 */ | 2956 */ |
| 2929 Type2 _typeType; | 2957 Type2 _typeType; |
| 2930 | 2958 |
| 2931 /** | 2959 /** |
| 2932 * The name of the method that can be implemented by a class to allow its inst
ances to be invoked | 2960 * The name of the method that can be implemented by a class to allow its inst
ances to be invoked |
| 2933 * as if they were a function. | 2961 * as if they were a function. |
| 2934 */ | 2962 */ |
| 2935 static String CALL_METHOD_NAME = "call"; | 2963 static String CALL_METHOD_NAME = "call"; |
| 2936 | 2964 |
| 2937 /** | 2965 /** |
| 2938 * The name of the method that will be invoked if an attempt is made to invoke
an undefined method | 2966 * The name of the method that will be invoked if an attempt is made to invoke
an undefined method |
| 2939 * on an object. | 2967 * on an object. |
| 2940 */ | 2968 */ |
| 2941 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; | 2969 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; |
| 2942 | 2970 |
| 2943 /** | 2971 /** |
| 2944 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 2972 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 2945 * | 2973 * |
| 2946 * @param resolver the resolver driving this participant | 2974 * @param resolver the resolver driving this participant |
| 2947 */ | 2975 */ |
| 2948 ElementResolver(ResolverVisitor resolver) { | 2976 ElementResolver(ResolverVisitor resolver) { |
| 2949 this._resolver = resolver; | 2977 this._resolver = resolver; |
| 2950 _strictMode = resolver.definingLibrary.context.analysisOptions.strictMode; | 2978 AnalysisOptions options = resolver.definingLibrary.context.analysisOptions; |
| 2979 _strictMode = options.strictMode; |
| 2980 _enableHints = options.hint; |
| 2951 _dynamicType = resolver.typeProvider.dynamicType; | 2981 _dynamicType = resolver.typeProvider.dynamicType; |
| 2952 _typeType = resolver.typeProvider.typeType; | 2982 _typeType = resolver.typeProvider.typeType; |
| 2953 } | 2983 } |
| 2954 Object visitAssignmentExpression(AssignmentExpression node) { | 2984 Object visitAssignmentExpression(AssignmentExpression node) { |
| 2955 sc.Token operator = node.operator; | 2985 sc.Token operator = node.operator; |
| 2956 sc.TokenType operatorType = operator.type; | 2986 sc.TokenType operatorType = operator.type; |
| 2957 if (operatorType != sc.TokenType.EQ) { | 2987 if (operatorType != sc.TokenType.EQ) { |
| 2958 operatorType = operatorFromCompoundAssignment(operatorType); | 2988 operatorType = operatorFromCompoundAssignment(operatorType); |
| 2959 Expression leftHandSide = node.leftHandSide; | 2989 Expression leftHandSide = node.leftHandSide; |
| 2960 if (leftHandSide != null) { | 2990 if (leftHandSide != null) { |
| 2961 String methodName = operatorType.lexeme; | 2991 String methodName = operatorType.lexeme; |
| 2962 Type2 staticType = getStaticType(leftHandSide); | 2992 Type2 staticType = getStaticType(leftHandSide); |
| 2963 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth
odName); | 2993 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth
odName); |
| 2964 node.staticElement = staticMethod; | 2994 node.staticElement = staticMethod; |
| 2965 Type2 propagatedType = getPropagatedType(leftHandSide); | 2995 Type2 propagatedType = getPropagatedType(leftHandSide); |
| 2966 MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedTy
pe, methodName); | 2996 MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedTy
pe, methodName); |
| 2967 node.propagatedElement = propagatedMethod; | 2997 node.propagatedElement = propagatedMethod; |
| 2968 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode
|| propagatedType == null || shouldReportMissingMember(propagatedType, propagate
dMethod))) { | 2998 bool shouldReportMissingMember_static = shouldReportMissingMember(static
Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType,
propagatedMethod)); |
| 2969 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element
, StaticTypeWarningCode.UNDEFINED_METHOD, operator, [methodName, staticType.disp
layName]); | 2999 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportM
issingMember(propagatedType, propagatedMethod) : false; |
| 3000 if (shouldReportMissingMember_static || shouldReportMissingMember_propag
ated) { |
| 3001 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa
rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode; |
| 3002 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element
, errorCode, operator, [ |
| 3003 methodName, |
| 3004 shouldReportMissingMember_static ? staticType.displayName : propag
atedType.displayName]); |
| 2970 } | 3005 } |
| 2971 } | 3006 } |
| 2972 } | 3007 } |
| 2973 return null; | 3008 return null; |
| 2974 } | 3009 } |
| 2975 Object visitBinaryExpression(BinaryExpression node) { | 3010 Object visitBinaryExpression(BinaryExpression node) { |
| 2976 sc.Token operator = node.operator; | 3011 sc.Token operator = node.operator; |
| 2977 if (operator.isUserDefinableOperator) { | 3012 if (operator.isUserDefinableOperator) { |
| 2978 Expression leftOperand = node.leftOperand; | 3013 Expression leftOperand = node.leftOperand; |
| 2979 if (leftOperand != null) { | 3014 if (leftOperand != null) { |
| 2980 String methodName = operator.lexeme; | 3015 String methodName = operator.lexeme; |
| 2981 Type2 staticType = getStaticType(leftOperand); | 3016 Type2 staticType = getStaticType(leftOperand); |
| 2982 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho
dName); | 3017 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho
dName); |
| 2983 node.staticElement = staticMethod; | 3018 node.staticElement = staticMethod; |
| 2984 Type2 propagatedType = getPropagatedType(leftOperand); | 3019 Type2 propagatedType = getPropagatedType(leftOperand); |
| 2985 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp
e, methodName); | 3020 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp
e, methodName); |
| 2986 node.propagatedElement = propagatedMethod; | 3021 node.propagatedElement = propagatedMethod; |
| 2987 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode
|| propagatedType == null || shouldReportMissingMember(propagatedType, propagate
dMethod))) { | 3022 bool shouldReportMissingMember_static = shouldReportMissingMember(static
Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType,
propagatedMethod)); |
| 2988 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element
, StaticTypeWarningCode.UNDEFINED_OPERATOR, operator, [methodName, staticType.di
splayName]); | 3023 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportM
issingMember(propagatedType, propagatedMethod) : false; |
| 3024 if (shouldReportMissingMember_static || shouldReportMissingMember_propag
ated) { |
| 3025 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa
rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; |
| 3026 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element
, errorCode, operator, [ |
| 3027 methodName, |
| 3028 shouldReportMissingMember_static ? staticType.displayName : propag
atedType.displayName]); |
| 2989 } | 3029 } |
| 2990 } | 3030 } |
| 2991 } | 3031 } |
| 2992 return null; | 3032 return null; |
| 2993 } | 3033 } |
| 2994 Object visitBreakStatement(BreakStatement node) { | 3034 Object visitBreakStatement(BreakStatement node) { |
| 2995 SimpleIdentifier labelNode = node.label; | 3035 SimpleIdentifier labelNode = node.label; |
| 2996 LabelElementImpl labelElement = lookupLabel(node, labelNode); | 3036 LabelElementImpl labelElement = lookupLabel(node, labelNode); |
| 2997 if (labelElement != null && labelElement.isOnSwitchMember) { | 3037 if (labelElement != null && labelElement.isOnSwitchMember) { |
| 2998 _resolver.reportError5(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, lab
elNode, []); | 3038 _resolver.reportError5(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, lab
elNode, []); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3304 if (parameters != null) { | 3344 if (parameters != null) { |
| 3305 argumentList.correspondingStaticParameters = parameters; | 3345 argumentList.correspondingStaticParameters = parameters; |
| 3306 } | 3346 } |
| 3307 } | 3347 } |
| 3308 if (propagatedElement != null) { | 3348 if (propagatedElement != null) { |
| 3309 List<ParameterElement> parameters = computeCorrespondingParameters(argumen
tList, propagatedElement); | 3349 List<ParameterElement> parameters = computeCorrespondingParameters(argumen
tList, propagatedElement); |
| 3310 if (parameters != null) { | 3350 if (parameters != null) { |
| 3311 argumentList.correspondingPropagatedParameters = parameters; | 3351 argumentList.correspondingPropagatedParameters = parameters; |
| 3312 } | 3352 } |
| 3313 } | 3353 } |
| 3314 ErrorCode errorCode = checkForInvocationError(target, staticElement); | 3354 ErrorCode errorCode = checkForInvocationError(target, true, staticElement); |
| 3355 bool generatedWithTypePropagation = false; |
| 3356 if (_enableHints && errorCode == null && staticElement == null) { |
| 3357 errorCode = checkForInvocationError(target, false, propagatedElement); |
| 3358 generatedWithTypePropagation = true; |
| 3359 } |
| 3360 if (errorCode == null) { |
| 3361 return null; |
| 3362 } |
| 3315 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION))
{ | 3363 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION))
{ |
| 3316 _resolver.reportError5(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m
ethodName, [methodName.name]); | 3364 _resolver.reportError5(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m
ethodName, [methodName.name]); |
| 3317 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) { | 3365 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) { |
| 3318 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName
, [methodName.name]); | 3366 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName
, [methodName.name]); |
| 3319 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { | 3367 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { |
| 3320 String targetTypeName; | 3368 String targetTypeName; |
| 3321 if (target == null) { | 3369 if (target == null) { |
| 3322 ClassElement enclosingClass = _resolver.enclosingClass; | 3370 ClassElement enclosingClass = _resolver.enclosingClass; |
| 3323 targetTypeName = enclosingClass.displayName; | 3371 targetTypeName = enclosingClass.displayName; |
| 3324 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl
ass, StaticTypeWarningCode.UNDEFINED_METHOD, methodName, [methodName.name, targe
tTypeName]); | 3372 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE
FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; |
| 3373 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl
ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]); |
| 3325 } else { | 3374 } else { |
| 3326 Type2 targetType = getStaticType(target); | 3375 Type2 targetType = null; |
| 3376 if (!generatedWithTypePropagation) { |
| 3377 targetType = getStaticType(target); |
| 3378 } else { |
| 3379 targetType = getPropagatedType(target); |
| 3380 if (targetType == null) { |
| 3381 targetType = getStaticType(target); |
| 3382 } |
| 3383 } |
| 3327 if (targetType != null && targetType.isDartCoreFunction && methodName.na
me == CALL_METHOD_NAME) { | 3384 if (targetType != null && targetType.isDartCoreFunction && methodName.na
me == CALL_METHOD_NAME) { |
| 3328 return null; | 3385 return null; |
| 3329 } | 3386 } |
| 3330 targetTypeName = targetType == null ? null : targetType.displayName; | 3387 targetTypeName = targetType == null ? null : targetType.displayName; |
| 3331 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, S
taticTypeWarningCode.UNDEFINED_METHOD, methodName, [methodName.name, targetTypeN
ame]); | 3388 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE
FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; |
| 3389 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p
roxyErrorCode, methodName, [methodName.name, targetTypeName]); |
| 3332 } | 3390 } |
| 3333 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD
)) { | 3391 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD
)) { |
| 3334 Type2 targetType = getPropagatedType(target); | 3392 Type2 targetType = getStaticType(target); |
| 3335 if (targetType == null) { | |
| 3336 targetType = getStaticType(target); | |
| 3337 } | |
| 3338 String targetTypeName = targetType == null ? null : targetType.name; | 3393 String targetTypeName = targetType == null ? null : targetType.name; |
| 3339 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho
dName, [methodName.name, targetTypeName]); | 3394 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho
dName, [methodName.name, targetTypeName]); |
| 3340 } | 3395 } |
| 3341 return null; | 3396 return null; |
| 3342 } | 3397 } |
| 3343 Object visitPartDirective(PartDirective node) { | 3398 Object visitPartDirective(PartDirective node) { |
| 3344 setMetadata(node.element, node); | 3399 setMetadata(node.element, node); |
| 3345 return null; | 3400 return null; |
| 3346 } | 3401 } |
| 3347 Object visitPartOfDirective(PartOfDirective node) { | 3402 Object visitPartOfDirective(PartOfDirective node) { |
| 3348 setMetadata(node.element, node); | 3403 setMetadata(node.element, node); |
| 3349 return null; | 3404 return null; |
| 3350 } | 3405 } |
| 3351 Object visitPostfixExpression(PostfixExpression node) { | 3406 Object visitPostfixExpression(PostfixExpression node) { |
| 3352 Expression operand = node.operand; | 3407 Expression operand = node.operand; |
| 3353 String methodName = getPostfixOperator(node); | 3408 String methodName = getPostfixOperator(node); |
| 3354 Type2 staticType = getStaticType(operand); | 3409 Type2 staticType = getStaticType(operand); |
| 3355 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName); | 3410 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName); |
| 3356 node.staticElement = staticMethod; | 3411 node.staticElement = staticMethod; |
| 3357 Type2 propagatedType = getPropagatedType(operand); | 3412 Type2 propagatedType = getPropagatedType(operand); |
| 3358 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, metho
dName); | 3413 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, metho
dName); |
| 3359 node.propagatedElement = propagatedMethod; | 3414 node.propagatedElement = propagatedMethod; |
| 3360 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode || p
ropagatedType == null || shouldReportMissingMember(propagatedType, propagatedMet
hod))) { | 3415 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType
, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro
pagatedMethod)); |
| 3361 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element, St
aticTypeWarningCode.UNDEFINED_OPERATOR, node.operator, [methodName, staticType.d
isplayName]); | 3416 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportMissi
ngMember(propagatedType, propagatedMethod) : false; |
| 3417 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated
) { |
| 3418 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin
gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; |
| 3419 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element, er
rorCode, node.operator, [ |
| 3420 methodName, |
| 3421 shouldReportMissingMember_static ? staticType.displayName : propagated
Type.displayName]); |
| 3362 } | 3422 } |
| 3363 return null; | 3423 return null; |
| 3364 } | 3424 } |
| 3365 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 3425 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 3366 SimpleIdentifier prefix = node.prefix; | 3426 SimpleIdentifier prefix = node.prefix; |
| 3367 SimpleIdentifier identifier = node.identifier; | 3427 SimpleIdentifier identifier = node.identifier; |
| 3368 Element prefixElement = prefix.staticElement; | 3428 Element prefixElement = prefix.staticElement; |
| 3369 if (prefixElement is PrefixElement) { | 3429 if (prefixElement is PrefixElement) { |
| 3370 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra
ry); | 3430 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra
ry); |
| 3371 if (element == null && identifier.inSetterContext()) { | 3431 if (element == null && identifier.inSetterContext()) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3408 sc.TokenType operatorType = operator.type; | 3468 sc.TokenType operatorType = operator.type; |
| 3409 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token
Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { | 3469 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token
Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { |
| 3410 Expression operand = node.operand; | 3470 Expression operand = node.operand; |
| 3411 String methodName = getPrefixOperator(node); | 3471 String methodName = getPrefixOperator(node); |
| 3412 Type2 staticType = getStaticType(operand); | 3472 Type2 staticType = getStaticType(operand); |
| 3413 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName)
; | 3473 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName)
; |
| 3414 node.staticElement = staticMethod; | 3474 node.staticElement = staticMethod; |
| 3415 Type2 propagatedType = getPropagatedType(operand); | 3475 Type2 propagatedType = getPropagatedType(operand); |
| 3416 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, met
hodName); | 3476 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, met
hodName); |
| 3417 node.propagatedElement = propagatedMethod; | 3477 node.propagatedElement = propagatedMethod; |
| 3418 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode ||
propagatedType == null || shouldReportMissingMember(propagatedType, propagatedM
ethod))) { | 3478 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy
pe, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, p
ropagatedMethod)); |
| 3419 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element,
StaticTypeWarningCode.UNDEFINED_OPERATOR, operator, [methodName, staticType.disp
layName]); | 3479 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportMis
singMember(propagatedType, propagatedMethod) : false; |
| 3480 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat
ed) { |
| 3481 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn
ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; |
| 3482 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element,
errorCode, operator, [ |
| 3483 methodName, |
| 3484 shouldReportMissingMember_static ? staticType.displayName : propagat
edType.displayName]); |
| 3420 } | 3485 } |
| 3421 } | 3486 } |
| 3422 return null; | 3487 return null; |
| 3423 } | 3488 } |
| 3424 Object visitPropertyAccess(PropertyAccess node) { | 3489 Object visitPropertyAccess(PropertyAccess node) { |
| 3425 Expression target = node.realTarget; | 3490 Expression target = node.realTarget; |
| 3426 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre
ssion)) { | 3491 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre
ssion)) { |
| 3427 return null; | 3492 return null; |
| 3428 } | 3493 } |
| 3429 SimpleIdentifier propertyName = node.propertyName; | 3494 SimpleIdentifier propertyName = node.propertyName; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3566 annotationList.add(new ElementAnnotationImpl(resolvedElement)); | 3631 annotationList.add(new ElementAnnotationImpl(resolvedElement)); |
| 3567 } | 3632 } |
| 3568 } | 3633 } |
| 3569 } | 3634 } |
| 3570 | 3635 |
| 3571 /** | 3636 /** |
| 3572 * Given that we have found code to invoke the given element, return the error
code that should be | 3637 * Given that we have found code to invoke the given element, return the error
code that should be |
| 3573 * reported, or `null` if no error should be reported. | 3638 * reported, or `null` if no error should be reported. |
| 3574 * | 3639 * |
| 3575 * @param target the target of the invocation, or `null` if there was no targe
t | 3640 * @param target the target of the invocation, or `null` if there was no targe
t |
| 3641 * @param useStaticContext |
| 3576 * @param element the element to be invoked | 3642 * @param element the element to be invoked |
| 3577 * @return the error code that should be reported | 3643 * @return the error code that should be reported |
| 3578 */ | 3644 */ |
| 3579 ErrorCode checkForInvocationError(Expression target, Element element) { | 3645 ErrorCode checkForInvocationError(Expression target, bool useStaticContext, El
ement element) { |
| 3580 if (element is PrefixElement) { | 3646 if (element is PrefixElement) { |
| 3581 element = null; | 3647 element = null; |
| 3582 } | 3648 } |
| 3583 if (element is PropertyAccessorElement) { | 3649 if (element is PropertyAccessorElement) { |
| 3584 FunctionType getterType = ((element as PropertyAccessorElement)).type; | 3650 FunctionType getterType = ((element as PropertyAccessorElement)).type; |
| 3585 if (getterType != null) { | 3651 if (getterType != null) { |
| 3586 Type2 returnType = getterType.returnType; | 3652 Type2 returnType = getterType.returnType; |
| 3587 if (!isExecutableType(returnType)) { | 3653 if (!isExecutableType(returnType)) { |
| 3588 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; | 3654 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; |
| 3589 } | 3655 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3611 if (target == null) { | 3677 if (target == null) { |
| 3612 ClassElement enclosingClass = _resolver.enclosingClass; | 3678 ClassElement enclosingClass = _resolver.enclosingClass; |
| 3613 if (enclosingClass == null) { | 3679 if (enclosingClass == null) { |
| 3614 return CompileTimeErrorCode.UNDEFINED_FUNCTION; | 3680 return CompileTimeErrorCode.UNDEFINED_FUNCTION; |
| 3615 } else if (element == null) { | 3681 } else if (element == null) { |
| 3616 return StaticTypeWarningCode.UNDEFINED_METHOD; | 3682 return StaticTypeWarningCode.UNDEFINED_METHOD; |
| 3617 } else { | 3683 } else { |
| 3618 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; | 3684 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; |
| 3619 } | 3685 } |
| 3620 } else { | 3686 } else { |
| 3621 Type2 targetType = getStaticType(target); | 3687 Type2 targetType; |
| 3688 if (useStaticContext) { |
| 3689 targetType = getStaticType(target); |
| 3690 } else { |
| 3691 targetType = getPropagatedType(target); |
| 3692 if (targetType == null) { |
| 3693 targetType = getStaticType(target); |
| 3694 } |
| 3695 } |
| 3622 if (targetType == null) { | 3696 if (targetType == null) { |
| 3623 return CompileTimeErrorCode.UNDEFINED_FUNCTION; | 3697 return CompileTimeErrorCode.UNDEFINED_FUNCTION; |
| 3624 } else if (!targetType.isDynamic) { | 3698 } else if (!targetType.isDynamic) { |
| 3625 return StaticTypeWarningCode.UNDEFINED_METHOD; | 3699 return StaticTypeWarningCode.UNDEFINED_METHOD; |
| 3626 } | 3700 } |
| 3627 } | 3701 } |
| 3628 } | 3702 } |
| 3629 } | 3703 } |
| 3630 return null; | 3704 return null; |
| 3631 } | 3705 } |
| 3632 | 3706 |
| 3633 /** | 3707 /** |
| 3634 * Check that the for some index expression that the method element was resolv
ed, otherwise a | 3708 * Check that the for some index expression that the method element was resolv
ed, otherwise a |
| 3635 * [StaticWarningCode#UNDEFINED_OPERATOR] is generated. | 3709 * [StaticWarningCode#UNDEFINED_OPERATOR] is generated. |
| 3636 * | 3710 * |
| 3637 * @param node the index expression to resolve | 3711 * @param node the index expression to resolve |
| 3638 * @param target the target of the expression | 3712 * @param target the target of the expression |
| 3639 * @param methodName the name of the operator associated with the context of u
sing of the given | 3713 * @param methodName the name of the operator associated with the context of u
sing of the given |
| 3640 * index expression | 3714 * index expression |
| 3641 * @return `true` if and only if an error code is generated on the passed node | 3715 * @return `true` if and only if an error code is generated on the passed node |
| 3642 */ | 3716 */ |
| 3643 bool checkForUndefinedIndexOperator(IndexExpression node, Expression target, S
tring methodName, MethodElement staticMethod, MethodElement propagatedMethod, Ty
pe2 staticType, Type2 propagatedType) { | 3717 bool checkForUndefinedIndexOperator(IndexExpression node, Expression target, S
tring methodName, MethodElement staticMethod, MethodElement propagatedMethod, Ty
pe2 staticType, Type2 propagatedType) { |
| 3644 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode || p
ropagatedType == null || shouldReportMissingMember(propagatedType, propagatedMet
hod))) { | 3718 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType
, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro
pagatedMethod)); |
| 3719 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportMissi
ngMember(propagatedType, propagatedMethod) : false; |
| 3720 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated
) { |
| 3645 sc.Token leftBracket = node.leftBracket; | 3721 sc.Token leftBracket = node.leftBracket; |
| 3646 sc.Token rightBracket = node.rightBracket; | 3722 sc.Token rightBracket = node.rightBracket; |
| 3723 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin
gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; |
| 3647 if (leftBracket == null || rightBracket == null) { | 3724 if (leftBracket == null || rightBracket == null) { |
| 3648 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, S
taticTypeWarningCode.UNDEFINED_OPERATOR, node, [methodName, staticType.displayNa
me]); | 3725 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, e
rrorCode, node, [ |
| 3726 methodName, |
| 3727 shouldReportMissingMember_static ? staticType.displayName : propagat
edType.displayName]); |
| 3649 } else { | 3728 } else { |
| 3650 int offset = leftBracket.offset; | 3729 int offset = leftBracket.offset; |
| 3651 int length = rightBracket.offset - offset + 1; | 3730 int length = rightBracket.offset - offset + 1; |
| 3652 _resolver.reportErrorProxyConditionalAnalysisError2(staticType.element,
StaticTypeWarningCode.UNDEFINED_OPERATOR, offset, length, [methodName, staticTyp
e.displayName]); | 3731 _resolver.reportErrorProxyConditionalAnalysisError2(staticType.element,
errorCode, offset, length, [ |
| 3732 methodName, |
| 3733 shouldReportMissingMember_static ? staticType.displayName : propagat
edType.displayName]); |
| 3653 } | 3734 } |
| 3654 return true; | 3735 return true; |
| 3655 } | 3736 } |
| 3656 return false; | 3737 return false; |
| 3657 } | 3738 } |
| 3658 | 3739 |
| 3659 /** | 3740 /** |
| 3660 * Given a list of arguments and the element that will be invoked using those
argument, compute | 3741 * Given a list of arguments and the element that will be invoked using those
argument, compute |
| 3661 * the list of parameters that correspond to the list of arguments. Return the
parameters that | 3742 * the list of parameters that correspond to the list of arguments. Return the
parameters that |
| 3662 * correspond to the arguments, or `null` if no correspondence could be comput
ed. | 3743 * correspond to the arguments, or `null` if no correspondence could be comput
ed. |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4500 if (target.parent.parent is Annotation) { | 4581 if (target.parent.parent is Annotation) { |
| 4501 if (staticElement != null) { | 4582 if (staticElement != null) { |
| 4502 propertyName.staticElement = staticElement; | 4583 propertyName.staticElement = staticElement; |
| 4503 } | 4584 } |
| 4504 return; | 4585 return; |
| 4505 } | 4586 } |
| 4506 propertyName.staticElement = staticElement; | 4587 propertyName.staticElement = staticElement; |
| 4507 Type2 propagatedType = getPropagatedType(target); | 4588 Type2 propagatedType = getPropagatedType(target); |
| 4508 ExecutableElement propagatedElement = resolveProperty(target, propagatedType
, propertyName); | 4589 ExecutableElement propagatedElement = resolveProperty(target, propagatedType
, propertyName); |
| 4509 propertyName.propagatedElement = propagatedElement; | 4590 propertyName.propagatedElement = propagatedElement; |
| 4510 if (shouldReportMissingMember(staticType, staticElement) && (_strictMode ||
propagatedType == null || shouldReportMissingMember(propagatedType, propagatedEl
ement))) { | 4591 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType
, staticElement) && (_strictMode || shouldReportMissingMember(propagatedType, pr
opagatedElement)); |
| 4592 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportMissi
ngMember(propagatedType, propagatedElement) : false; |
| 4593 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated
) { |
| 4511 Element selectedElement = select(staticElement, propagatedElement); | 4594 Element selectedElement = select(staticElement, propagatedElement); |
| 4512 bool isStaticProperty = isStatic(selectedElement); | 4595 bool isStaticProperty = isStatic(selectedElement); |
| 4513 if (propertyName.inSetterContext()) { | 4596 if (propertyName.inSetterContext()) { |
| 4514 if (isStaticProperty) { | 4597 if (isStaticProperty) { |
| 4515 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element,
StaticWarningCode.UNDEFINED_SETTER, propertyName, [propertyName.name, staticTyp
e.displayName]); | 4598 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarnin
gCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode; |
| 4599 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element,
errorCode, propertyName, [ |
| 4600 propertyName.name, |
| 4601 shouldReportMissingMember_static ? staticType.displayName : propag
atedType.displayName]); |
| 4516 } else { | 4602 } else { |
| 4517 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element,
StaticTypeWarningCode.UNDEFINED_SETTER, propertyName, [propertyName.name, stati
cType.displayName]); | 4603 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa
rningCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode; |
| 4604 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element,
errorCode, propertyName, [ |
| 4605 propertyName.name, |
| 4606 shouldReportMissingMember_static ? staticType.displayName : propag
atedType.displayName]); |
| 4518 } | 4607 } |
| 4519 } else if (propertyName.inGetterContext()) { | 4608 } else if (propertyName.inGetterContext()) { |
| 4520 if (isStaticProperty) { | 4609 if (isStaticProperty) { |
| 4521 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element,
StaticWarningCode.UNDEFINED_GETTER, propertyName, [propertyName.name, staticTyp
e.displayName]); | 4610 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarnin
gCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode; |
| 4611 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element,
errorCode, propertyName, [ |
| 4612 propertyName.name, |
| 4613 shouldReportMissingMember_static ? staticType.displayName : propag
atedType.displayName]); |
| 4522 } else { | 4614 } else { |
| 4523 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element,
StaticTypeWarningCode.UNDEFINED_GETTER, propertyName, [propertyName.name, stati
cType.displayName]); | 4615 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa
rningCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode; |
| 4616 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element,
errorCode, propertyName, [ |
| 4617 propertyName.name, |
| 4618 shouldReportMissingMember_static ? staticType.displayName : propag
atedType.displayName]); |
| 4524 } | 4619 } |
| 4525 } else { | 4620 } else { |
| 4526 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, S
taticWarningCode.UNDEFINED_IDENTIFIER, propertyName, [propertyName.name]); | 4621 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, S
taticWarningCode.UNDEFINED_IDENTIFIER, propertyName, [propertyName.name]); |
| 4527 } | 4622 } |
| 4528 } | 4623 } |
| 4529 } | 4624 } |
| 4530 | 4625 |
| 4531 /** | 4626 /** |
| 4532 * Resolve the given simple identifier if possible. Return the element to whic
h it could be | 4627 * Resolve the given simple identifier if possible. Return the element to whic
h it could be |
| 4533 * resolved, or `null` if it could not be resolved. This does not record the r
esults of the | 4628 * resolved, or `null` if it could not be resolved. This does not record the r
esults of the |
| (...skipping 6386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10920 int to = 0; | 11015 int to = 0; |
| 10921 for (Element member in conflictingMembers) { | 11016 for (Element member in conflictingMembers) { |
| 10922 if (!member.library.isInSdk) { | 11017 if (!member.library.isInSdk) { |
| 10923 conflictingMembers[to++] = member; | 11018 conflictingMembers[to++] = member; |
| 10924 } | 11019 } |
| 10925 } | 11020 } |
| 10926 if (to == length) { | 11021 if (to == length) { |
| 10927 return foundElement; | 11022 return foundElement; |
| 10928 } else if (to == 1) { | 11023 } else if (to == 1) { |
| 10929 return conflictingMembers[0]; | 11024 return conflictingMembers[0]; |
| 11025 } else if (to == 0) { |
| 11026 AnalysisEngine.instance.logger.logInformation("Multiply defined SDK elemen
t: ${foundElement}"); |
| 11027 return foundElement; |
| 10930 } | 11028 } |
| 10931 List<Element> remaining = new List<Element>(to); | 11029 List<Element> remaining = new List<Element>(to); |
| 10932 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to); | 11030 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to); |
| 10933 return new MultiplyDefinedElementImpl.con2(_definingLibrary.context, remaini
ng); | 11031 return new MultiplyDefinedElementImpl.con2(_definingLibrary.context, remaini
ng); |
| 10934 } | 11032 } |
| 10935 } | 11033 } |
| 10936 /** | 11034 /** |
| 10937 * Instances of the class `LibraryScope` implement a scope containing all of the
names defined | 11035 * Instances of the class `LibraryScope` implement a scope containing all of the
names defined |
| 10938 * in a given library. | 11036 * in a given library. |
| 10939 * | 11037 * |
| (...skipping 5039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15979 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag
e, String correction) : super(name, ordinal) { | 16077 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag
e, String correction) : super(name, ordinal) { |
| 15980 this._type = type; | 16078 this._type = type; |
| 15981 this._message = message; | 16079 this._message = message; |
| 15982 this.correction9 = correction; | 16080 this.correction9 = correction; |
| 15983 } | 16081 } |
| 15984 String get correction => correction9; | 16082 String get correction => correction9; |
| 15985 ErrorSeverity get errorSeverity => _type.severity; | 16083 ErrorSeverity get errorSeverity => _type.severity; |
| 15986 String get message => _message; | 16084 String get message => _message; |
| 15987 ErrorType get type => _type; | 16085 ErrorType get type => _type; |
| 15988 } | 16086 } |
| OLD | NEW |