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

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

Issue 27278004: New analyzer_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 library engine.resolver; 3 library engine.resolver;
4 import 'dart:collection'; 4 import 'dart:collection';
5 import 'java_core.dart'; 5 import 'java_core.dart';
6 import 'java_engine.dart'; 6 import 'java_engine.dart';
7 import 'instrumentation.dart'; 7 import 'instrumentation.dart';
8 import 'source.dart'; 8 import 'source.dart';
9 import 'error.dart'; 9 import 'error.dart';
10 import 'scanner.dart' as sc; 10 import 'scanner.dart' as sc;
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 if (element is PropertyInducingElementImpl) { 610 if (element is PropertyInducingElementImpl) {
611 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl; 611 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl;
612 if (_inFieldContext) { 612 if (_inFieldContext) {
613 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).staticKeyword, sc.Keyword.STATIC); 613 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).staticKeyword, sc.Keyword.STATIC);
614 } 614 }
615 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable); 615 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable);
616 getter.getter = true; 616 getter.getter = true;
617 getter.static = variable.isStatic; 617 getter.static = variable.isStatic;
618 _currentHolder.addAccessor(getter); 618 _currentHolder.addAccessor(getter);
619 variable.getter = getter; 619 variable.getter = getter;
620 if (!isFinal) { 620 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con2( variable);
621 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable); 621 setter.setter = true;
622 setter.setter = true; 622 setter.static = variable.isStatic;
623 setter.static = variable.isStatic; 623 ParameterElementImpl parameter = new ParameterElementImpl.con2("_${variabl e.name}", variable.nameOffset);
624 ParameterElementImpl parameter = new ParameterElementImpl.con2("_${varia ble.name}", variable.nameOffset); 624 parameter.synthetic = true;
625 parameter.synthetic = true; 625 parameter.parameterKind = ParameterKind.REQUIRED;
626 parameter.parameterKind = ParameterKind.REQUIRED; 626 setter.parameters = <ParameterElement> [parameter];
627 setter.parameters = <ParameterElement> [parameter]; 627 _currentHolder.addAccessor(setter);
628 _currentHolder.addAccessor(setter); 628 variable.setter = setter;
629 variable.setter = setter;
630 }
631 } 629 }
632 return null; 630 return null;
633 } 631 }
634 632
635 /** 633 /**
636 * Creates the [ConstructorElement]s array with the single default constructor element. 634 * Creates the [ConstructorElement]s array with the single default constructor element.
637 * 635 *
638 * @param interfaceType the interface type for which to create a default const ructor 636 * @param interfaceType the interface type for which to create a default const ructor
639 * @return the [ConstructorElement]s array with the single default constructor element 637 * @return the [ConstructorElement]s array with the single default constructor element
640 */ 638 */
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementIm pl(node); 1175 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementIm pl(node);
1178 String contents = node.content; 1176 String contents = node.content;
1179 int attributeEnd = node.attributeEnd.end; 1177 int attributeEnd = node.attributeEnd.end;
1180 LineInfo_Location location = _lineInfo.getLocation(attributeEnd); 1178 LineInfo_Location location = _lineInfo.getLocation(attributeEnd);
1181 sc.StringScanner scanner = new sc.StringScanner(htmlSource, contents, errorListener); 1179 sc.StringScanner scanner = new sc.StringScanner(htmlSource, contents, errorListener);
1182 scanner.setSourceStart(location.lineNumber, location.columnNumber, att ributeEnd); 1180 scanner.setSourceStart(location.lineNumber, location.columnNumber, att ributeEnd);
1183 sc.Token firstToken = scanner.tokenize(); 1181 sc.Token firstToken = scanner.tokenize();
1184 List<int> lineStarts = scanner.lineStarts; 1182 List<int> lineStarts = scanner.lineStarts;
1185 Parser parser = new Parser(htmlSource, errorListener); 1183 Parser parser = new Parser(htmlSource, errorListener);
1186 CompilationUnit unit = parser.parseCompilationUnit(firstToken); 1184 CompilationUnit unit = parser.parseCompilationUnit(firstToken);
1187 unit.lineInfo = new LineInfo(lineStarts);
1188 try { 1185 try {
1189 LibraryResolver resolver = new LibraryResolver(_context); 1186 LibraryResolver resolver = new LibraryResolver(_context);
1190 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSou rce, _modificationStamp, unit, true) as LibraryElementImpl; 1187 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSou rce, _modificationStamp, unit, true) as LibraryElementImpl;
1191 script.scriptLibrary = library; 1188 script.scriptLibrary = library;
1192 resolvedLibraries.addAll(resolver.resolvedLibraries); 1189 resolvedLibraries.addAll(resolver.resolvedLibraries);
1193 errorListener.addAll(resolver.errorListener); 1190 errorListener.addAll(resolver.errorListener);
1194 } on AnalysisException catch (exception) { 1191 } on AnalysisException catch (exception) {
1195 AnalysisEngine.instance.logger.logError3(exception); 1192 AnalysisEngine.instance.logger.logError3(exception);
1196 } 1193 }
1197 _scripts.add(script); 1194 _scripts.add(script);
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 /** 1993 /**
1997 * After all of the compilation units have been visited by this visitor, this method can be called 1994 * After all of the compilation units have been visited by this visitor, this method can be called
1998 * to report an [HintCode#UNUSED_IMPORT] hint for each of the import directive s in the 1995 * to report an [HintCode#UNUSED_IMPORT] hint for each of the import directive s in the
1999 * [unusedImports] list. 1996 * [unusedImports] list.
2000 * 1997 *
2001 * @param errorReporter the error reporter to report the set of [HintCode#UNUS ED_IMPORT] 1998 * @param errorReporter the error reporter to report the set of [HintCode#UNUS ED_IMPORT]
2002 * hints to 1999 * hints to
2003 */ 2000 */
2004 void generateUnusedImportHints(ErrorReporter errorReporter) { 2001 void generateUnusedImportHints(ErrorReporter errorReporter) {
2005 for (ImportDirective unusedImport in _unusedImports) { 2002 for (ImportDirective unusedImport in _unusedImports) {
2006 Element element = unusedImport.element; 2003 ImportElement importElement = unusedImport.element;
2007 if (element is ImportElement) { 2004 if (importElement != null) {
2008 ImportElement importElement = element as ImportElement;
2009 LibraryElement libraryElement = importElement.importedLibrary; 2005 LibraryElement libraryElement = importElement.importedLibrary;
2010 if (libraryElement != null && libraryElement.isDartCore) { 2006 if (libraryElement != null && libraryElement.isDartCore) {
2011 continue; 2007 continue;
2012 } 2008 }
2013 } 2009 }
2014 errorReporter.reportError2(HintCode.UNUSED_IMPORT, unusedImport.uri, []); 2010 errorReporter.reportError2(HintCode.UNUSED_IMPORT, unusedImport.uri, []);
2015 } 2011 }
2016 } 2012 }
2017 Object visitCompilationUnit(CompilationUnit node) { 2013 Object visitCompilationUnit(CompilationUnit node) {
2018 if (_inDefiningCompilationUnit) { 2014 if (_inDefiningCompilationUnit) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 * Lookup and return the [Namespace] from the [namespaceMap], if the map does not 2100 * Lookup and return the [Namespace] from the [namespaceMap], if the map does not
2105 * have the computed namespace, compute it and cache it in the map. If the imp ort directive is not 2101 * have the computed namespace, compute it and cache it in the map. If the imp ort directive is not
2106 * resolved or is not resolvable, `null` is returned. 2102 * resolved or is not resolvable, `null` is returned.
2107 * 2103 *
2108 * @param importDirective the import directive used to compute the returned na mespace 2104 * @param importDirective the import directive used to compute the returned na mespace
2109 * @return the computed or looked up [Namespace] 2105 * @return the computed or looked up [Namespace]
2110 */ 2106 */
2111 Namespace computeNamespace(ImportDirective importDirective) { 2107 Namespace computeNamespace(ImportDirective importDirective) {
2112 Namespace namespace = _namespaceMap[importDirective]; 2108 Namespace namespace = _namespaceMap[importDirective];
2113 if (namespace == null) { 2109 if (namespace == null) {
2114 ImportElement importElement = importDirective.element as ImportElement; 2110 ImportElement importElement = importDirective.element;
2115 if (importElement != null) { 2111 if (importElement != null) {
2116 NamespaceBuilder builder = new NamespaceBuilder(); 2112 NamespaceBuilder builder = new NamespaceBuilder();
2117 namespace = builder.createImportNamespace(importElement); 2113 namespace = builder.createImportNamespace(importElement);
2118 _namespaceMap[importDirective] = namespace; 2114 _namespaceMap[importDirective] = namespace;
2119 } 2115 }
2120 } 2116 }
2121 return namespace; 2117 return namespace;
2122 } 2118 }
2123 2119
2124 /** 2120 /**
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
2955 * The type representing the type 'dynamic'. 2951 * The type representing the type 'dynamic'.
2956 */ 2952 */
2957 Type2 _dynamicType; 2953 Type2 _dynamicType;
2958 2954
2959 /** 2955 /**
2960 * The type representing the type 'type'. 2956 * The type representing the type 'type'.
2961 */ 2957 */
2962 Type2 _typeType; 2958 Type2 _typeType;
2963 2959
2964 /** 2960 /**
2961 * A utility class for the resolver to answer the question of "what are my sub types?".
2962 */
2963 SubtypeManager _subtypeManager;
2964
2965 /**
2965 * The name of the method that can be implemented by a class to allow its inst ances to be invoked 2966 * The name of the method that can be implemented by a class to allow its inst ances to be invoked
2966 * as if they were a function. 2967 * as if they were a function.
2967 */ 2968 */
2968 static String CALL_METHOD_NAME = "call"; 2969 static String CALL_METHOD_NAME = "call";
2969 2970
2970 /** 2971 /**
2971 * The name of the method that will be invoked if an attempt is made to invoke an undefined method 2972 * The name of the method that will be invoked if an attempt is made to invoke an undefined method
2972 * on an object. 2973 * on an object.
2973 */ 2974 */
2974 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; 2975 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod";
2975 2976
2976 /** 2977 /**
2977 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 2978 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
2978 * 2979 *
2979 * @param resolver the resolver driving this participant 2980 * @param resolver the resolver driving this participant
2980 */ 2981 */
2981 ElementResolver(ResolverVisitor resolver) { 2982 ElementResolver(ResolverVisitor resolver) {
2982 this._resolver = resolver; 2983 this._resolver = resolver;
2983 AnalysisOptions options = resolver.definingLibrary.context.analysisOptions; 2984 AnalysisOptions options = resolver.definingLibrary.context.analysisOptions;
2984 _strictMode = options.strictMode; 2985 _strictMode = options.strictMode;
2985 _enableHints = options.hint; 2986 _enableHints = options.hint;
2986 _dynamicType = resolver.typeProvider.dynamicType; 2987 _dynamicType = resolver.typeProvider.dynamicType;
2987 _typeType = resolver.typeProvider.typeType; 2988 _typeType = resolver.typeProvider.typeType;
2989 _subtypeManager = new SubtypeManager();
2988 } 2990 }
2989 Object visitAssignmentExpression(AssignmentExpression node) { 2991 Object visitAssignmentExpression(AssignmentExpression node) {
2990 sc.Token operator = node.operator; 2992 sc.Token operator = node.operator;
2991 sc.TokenType operatorType = operator.type; 2993 sc.TokenType operatorType = operator.type;
2992 if (operatorType != sc.TokenType.EQ) { 2994 if (operatorType != sc.TokenType.EQ) {
2993 operatorType = operatorFromCompoundAssignment(operatorType); 2995 operatorType = operatorFromCompoundAssignment(operatorType);
2994 Expression leftHandSide = node.leftHandSide; 2996 Expression leftHandSide = node.leftHandSide;
2995 if (leftHandSide != null) { 2997 if (leftHandSide != null) {
2996 String methodName = operatorType.lexeme; 2998 String methodName = operatorType.lexeme;
2997 Type2 staticType = getStaticType(leftHandSide); 2999 Type2 staticType = getStaticType(leftHandSide);
2998 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth odName); 3000 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth odName);
2999 node.staticElement = staticMethod; 3001 node.staticElement = staticMethod;
3000 Type2 propagatedType = getPropagatedType(leftHandSide); 3002 Type2 propagatedType = getPropagatedType(leftHandSide);
3001 MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedTy pe, methodName); 3003 MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedTy pe, methodName);
3002 node.propagatedElement = propagatedMethod; 3004 node.propagatedElement = propagatedMethod;
3003 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod)); 3005 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod));
3004 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportM issingMember(propagatedType, propagatedMethod) : false; 3006 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false;
3007 if (shouldReportMissingMember_propagated) {
3008 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) {
3009 shouldReportMissingMember_propagated = false;
3010 }
3011 }
3005 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) { 3012 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) {
3006 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode; 3013 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode;
3007 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element , errorCode, operator, [ 3014 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element , errorCode, operator, [
3008 methodName, 3015 methodName,
3009 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 3016 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]);
3010 } 3017 }
3011 } 3018 }
3012 } 3019 }
3013 return null; 3020 return null;
3014 } 3021 }
3015 Object visitBinaryExpression(BinaryExpression node) { 3022 Object visitBinaryExpression(BinaryExpression node) {
3016 sc.Token operator = node.operator; 3023 sc.Token operator = node.operator;
3017 if (operator.isUserDefinableOperator) { 3024 if (operator.isUserDefinableOperator) {
3018 Expression leftOperand = node.leftOperand; 3025 Expression leftOperand = node.leftOperand;
3019 if (leftOperand != null) { 3026 if (leftOperand != null) {
3020 String methodName = operator.lexeme; 3027 String methodName = operator.lexeme;
3021 Type2 staticType = getStaticType(leftOperand); 3028 Type2 staticType = getStaticType(leftOperand);
3022 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho dName); 3029 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho dName);
3023 node.staticElement = staticMethod; 3030 node.staticElement = staticMethod;
3024 Type2 propagatedType = getPropagatedType(leftOperand); 3031 Type2 propagatedType = getPropagatedType(leftOperand);
3025 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp e, methodName); 3032 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp e, methodName);
3026 node.propagatedElement = propagatedMethod; 3033 node.propagatedElement = propagatedMethod;
3027 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod)); 3034 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod));
3028 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportM issingMember(propagatedType, propagatedMethod) : false; 3035 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false;
3036 if (shouldReportMissingMember_propagated) {
3037 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) {
3038 shouldReportMissingMember_propagated = false;
3039 }
3040 }
3029 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) { 3041 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) {
3030 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3042 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3031 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element , errorCode, operator, [ 3043 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element , errorCode, operator, [
3032 methodName, 3044 methodName,
3033 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 3045 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]);
3034 } 3046 }
3035 } 3047 }
3036 } 3048 }
3037 return null; 3049 return null;
3038 } 3050 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
3254 SimpleIdentifier prefixNode = node.prefix; 3266 SimpleIdentifier prefixNode = node.prefix;
3255 if (prefixNode != null) { 3267 if (prefixNode != null) {
3256 String prefixName = prefixNode.name; 3268 String prefixName = prefixNode.name;
3257 for (PrefixElement prefixElement in _resolver.definingLibrary.prefixes) { 3269 for (PrefixElement prefixElement in _resolver.definingLibrary.prefixes) {
3258 if (prefixElement.displayName == prefixName) { 3270 if (prefixElement.displayName == prefixName) {
3259 prefixNode.staticElement = prefixElement; 3271 prefixNode.staticElement = prefixElement;
3260 break; 3272 break;
3261 } 3273 }
3262 } 3274 }
3263 } 3275 }
3264 Element element = node.element; 3276 ImportElement importElement = node.element;
3265 if (element is ImportElement) { 3277 if (importElement != null) {
3266 ImportElement importElement = element as ImportElement;
3267 LibraryElement library = importElement.importedLibrary; 3278 LibraryElement library = importElement.importedLibrary;
3268 if (library != null) { 3279 if (library != null) {
3269 resolveCombinators(library, node.combinators); 3280 resolveCombinators(library, node.combinators);
3270 } 3281 }
3271 setMetadata(element, node); 3282 setMetadata(importElement, node);
3272 } 3283 }
3273 return null; 3284 return null;
3274 } 3285 }
3275 Object visitIndexExpression(IndexExpression node) { 3286 Object visitIndexExpression(IndexExpression node) {
3276 Expression target = node.realTarget; 3287 Expression target = node.realTarget;
3277 Type2 staticType = getStaticType(target); 3288 Type2 staticType = getStaticType(target);
3278 Type2 propagatedType = getPropagatedType(target); 3289 Type2 propagatedType = getPropagatedType(target);
3279 String getterMethodName = sc.TokenType.INDEX.lexeme; 3290 String getterMethodName = sc.TokenType.INDEX.lexeme;
3280 String setterMethodName = sc.TokenType.INDEX_EQ.lexeme; 3291 String setterMethodName = sc.TokenType.INDEX_EQ.lexeme;
3281 bool isInGetterContext = node.inGetterContext(); 3292 bool isInGetterContext = node.inGetterContext();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
3354 if (propagatedElement != null) { 3365 if (propagatedElement != null) {
3355 List<ParameterElement> parameters = computeCorrespondingParameters(argumen tList, propagatedElement); 3366 List<ParameterElement> parameters = computeCorrespondingParameters(argumen tList, propagatedElement);
3356 if (parameters != null) { 3367 if (parameters != null) {
3357 argumentList.correspondingPropagatedParameters = parameters; 3368 argumentList.correspondingPropagatedParameters = parameters;
3358 } 3369 }
3359 } 3370 }
3360 ErrorCode errorCode = checkForInvocationError(target, true, staticElement); 3371 ErrorCode errorCode = checkForInvocationError(target, true, staticElement);
3361 bool generatedWithTypePropagation = false; 3372 bool generatedWithTypePropagation = false;
3362 if (_enableHints && errorCode == null && staticElement == null) { 3373 if (_enableHints && errorCode == null && staticElement == null) {
3363 errorCode = checkForInvocationError(target, false, propagatedElement); 3374 errorCode = checkForInvocationError(target, false, propagatedElement);
3375 if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) {
3376 ClassElement classElementContext = null;
3377 if (target == null) {
3378 classElementContext = _resolver.enclosingClass;
3379 } else {
3380 Type2 type = target.bestType;
3381 if (type != null) {
3382 if (type.element is ClassElement) {
3383 classElementContext = type.element as ClassElement;
3384 }
3385 }
3386 }
3387 if (classElementContext != null) {
3388 _subtypeManager.ensureLibraryVisited(_resolver.definingLibrary);
3389 Set<ClassElement> subtypeElements = _subtypeManager.computeAllSubtypes (classElementContext);
3390 for (ClassElement subtypeElement in subtypeElements) {
3391 if (subtypeElement.getMethod(methodName.name) != null) {
3392 errorCode = null;
3393 }
3394 }
3395 }
3396 }
3364 generatedWithTypePropagation = true; 3397 generatedWithTypePropagation = true;
3365 } 3398 }
3366 if (errorCode == null) { 3399 if (errorCode == null) {
3367 return null; 3400 return null;
3368 } 3401 }
3369 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) { 3402 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) {
3370 _resolver.reportError5(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m ethodName, [methodName.name]); 3403 _resolver.reportError5(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m ethodName, [methodName.name]);
3371 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) { 3404 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) {
3372 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName , [methodName.name]); 3405 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName , [methodName.name]);
3373 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { 3406 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3412 Object visitPostfixExpression(PostfixExpression node) { 3445 Object visitPostfixExpression(PostfixExpression node) {
3413 Expression operand = node.operand; 3446 Expression operand = node.operand;
3414 String methodName = getPostfixOperator(node); 3447 String methodName = getPostfixOperator(node);
3415 Type2 staticType = getStaticType(operand); 3448 Type2 staticType = getStaticType(operand);
3416 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName); 3449 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName);
3417 node.staticElement = staticMethod; 3450 node.staticElement = staticMethod;
3418 Type2 propagatedType = getPropagatedType(operand); 3451 Type2 propagatedType = getPropagatedType(operand);
3419 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, metho dName); 3452 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, metho dName);
3420 node.propagatedElement = propagatedMethod; 3453 node.propagatedElement = propagatedMethod;
3421 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod)); 3454 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod));
3422 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportMissi ngMember(propagatedType, propagatedMethod) : false; 3455 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false;
3456 if (shouldReportMissingMember_propagated) {
3457 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) {
3458 shouldReportMissingMember_propagated = false;
3459 }
3460 }
3423 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 3461 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
3424 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3462 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3425 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element, er rorCode, node.operator, [ 3463 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element, er rorCode, node.operator, [
3426 methodName, 3464 methodName,
3427 shouldReportMissingMember_static ? staticType.displayName : propagated Type.displayName]); 3465 shouldReportMissingMember_static ? staticType.displayName : propagated Type.displayName]);
3428 } 3466 }
3429 return null; 3467 return null;
3430 } 3468 }
3431 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 3469 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
3432 SimpleIdentifier prefix = node.prefix; 3470 SimpleIdentifier prefix = node.prefix;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { 3513 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) {
3476 Expression operand = node.operand; 3514 Expression operand = node.operand;
3477 String methodName = getPrefixOperator(node); 3515 String methodName = getPrefixOperator(node);
3478 Type2 staticType = getStaticType(operand); 3516 Type2 staticType = getStaticType(operand);
3479 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName) ; 3517 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName) ;
3480 node.staticElement = staticMethod; 3518 node.staticElement = staticMethod;
3481 Type2 propagatedType = getPropagatedType(operand); 3519 Type2 propagatedType = getPropagatedType(operand);
3482 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, met hodName); 3520 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, met hodName);
3483 node.propagatedElement = propagatedMethod; 3521 node.propagatedElement = propagatedMethod;
3484 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy pe, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, p ropagatedMethod)); 3522 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy pe, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, p ropagatedMethod));
3485 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportMis singMember(propagatedType, propagatedMethod) : false; 3523 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_sta tic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod ) : false;
3524 if (shouldReportMissingMember_propagated) {
3525 if (memberFoundInSubclass(propagatedType.element, methodName, true, fals e)) {
3526 shouldReportMissingMember_propagated = false;
3527 }
3528 }
3486 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat ed) { 3529 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat ed) {
3487 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3530 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3488 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element, errorCode, operator, [ 3531 _resolver.reportErrorProxyConditionalAnalysisError3(staticType.element, errorCode, operator, [
3489 methodName, 3532 methodName,
3490 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]); 3533 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]);
3491 } 3534 }
3492 } 3535 }
3493 return null; 3536 return null;
3494 } 3537 }
3495 Object visitPropertyAccess(PropertyAccess node) { 3538 Object visitPropertyAccess(PropertyAccess node) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3687 } else if (element == null) { 3730 } else if (element == null) {
3688 return StaticTypeWarningCode.UNDEFINED_METHOD; 3731 return StaticTypeWarningCode.UNDEFINED_METHOD;
3689 } else { 3732 } else {
3690 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; 3733 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION;
3691 } 3734 }
3692 } else { 3735 } else {
3693 Type2 targetType; 3736 Type2 targetType;
3694 if (useStaticContext) { 3737 if (useStaticContext) {
3695 targetType = getStaticType(target); 3738 targetType = getStaticType(target);
3696 } else { 3739 } else {
3697 targetType = getPropagatedType(target); 3740 targetType = target.bestType;
3698 if (targetType == null) {
3699 targetType = getStaticType(target);
3700 }
3701 } 3741 }
3702 if (targetType == null) { 3742 if (targetType == null) {
3703 return CompileTimeErrorCode.UNDEFINED_FUNCTION; 3743 return CompileTimeErrorCode.UNDEFINED_FUNCTION;
3704 } else if (!targetType.isDynamic && !targetType.isBottom) { 3744 } else if (!targetType.isDynamic && !targetType.isBottom) {
3705 return StaticTypeWarningCode.UNDEFINED_METHOD; 3745 return StaticTypeWarningCode.UNDEFINED_METHOD;
3706 } 3746 }
3707 } 3747 }
3708 } 3748 }
3709 } 3749 }
3710 return null; 3750 return null;
3711 } 3751 }
3712 3752
3713 /** 3753 /**
3714 * Check that the for some index expression that the method element was resolv ed, otherwise a 3754 * Check that the for some index expression that the method element was resolv ed, otherwise a
3715 * [StaticWarningCode#UNDEFINED_OPERATOR] is generated. 3755 * [StaticWarningCode#UNDEFINED_OPERATOR] is generated.
3716 * 3756 *
3717 * @param node the index expression to resolve 3757 * @param node the index expression to resolve
3718 * @param target the target of the expression 3758 * @param target the target of the expression
3719 * @param methodName the name of the operator associated with the context of u sing of the given 3759 * @param methodName the name of the operator associated with the context of u sing of the given
3720 * index expression 3760 * index expression
3721 * @return `true` if and only if an error code is generated on the passed node 3761 * @return `true` if and only if an error code is generated on the passed node
3722 */ 3762 */
3723 bool checkForUndefinedIndexOperator(IndexExpression node, Expression target, S tring methodName, MethodElement staticMethod, MethodElement propagatedMethod, Ty pe2 staticType, Type2 propagatedType) { 3763 bool checkForUndefinedIndexOperator(IndexExpression node, Expression target, S tring methodName, MethodElement staticMethod, MethodElement propagatedMethod, Ty pe2 staticType, Type2 propagatedType) {
3724 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod)); 3764 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod));
3725 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportMissi ngMember(propagatedType, propagatedMethod) : false; 3765 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false;
3766 if (shouldReportMissingMember_propagated) {
3767 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) {
3768 shouldReportMissingMember_propagated = false;
3769 }
3770 }
3726 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 3771 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
3727 sc.Token leftBracket = node.leftBracket; 3772 sc.Token leftBracket = node.leftBracket;
3728 sc.Token rightBracket = node.rightBracket; 3773 sc.Token rightBracket = node.rightBracket;
3729 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3774 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3730 if (leftBracket == null || rightBracket == null) { 3775 if (leftBracket == null || rightBracket == null) {
3731 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, e rrorCode, node, [ 3776 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, e rrorCode, node, [
3732 methodName, 3777 methodName,
3733 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]); 3778 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]);
3734 } else { 3779 } else {
3735 int offset = leftBracket.offset; 3780 int offset = leftBracket.offset;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
3816 LibraryElement definingLibrary = _resolver.definingLibrary; 3861 LibraryElement definingLibrary = _resolver.definingLibrary;
3817 for (ImportElement importElement in definingLibrary.imports) { 3862 for (ImportElement importElement in definingLibrary.imports) {
3818 PrefixElement prefixElement = importElement.prefix; 3863 PrefixElement prefixElement = importElement.prefix;
3819 if (prefixElement != null) { 3864 if (prefixElement != null) {
3820 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier( "${prefixElement.name}.${identifier.name}"); 3865 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier( "${prefixElement.name}.${identifier.name}");
3821 Element importedElement = nameScope.lookup(prefixedIdentifier, definingL ibrary); 3866 Element importedElement = nameScope.lookup(prefixedIdentifier, definingL ibrary);
3822 if (importedElement != null) { 3867 if (importedElement != null) {
3823 if (element == null) { 3868 if (element == null) {
3824 element = importedElement; 3869 element = importedElement;
3825 } else { 3870 } else {
3826 element = new MultiplyDefinedElementImpl.con1(definingLibrary.contex t, element, importedElement); 3871 element = MultiplyDefinedElementImpl.fromElements(definingLibrary.co ntext, element, importedElement);
3827 } 3872 }
3828 } 3873 }
3829 } 3874 }
3830 } 3875 }
3831 return element; 3876 return element;
3832 } 3877 }
3833 3878
3834 /** 3879 /**
3835 * Return the name of the method invoked by the given postfix expression. 3880 * Return the name of the method invoked by the given postfix expression.
3836 * 3881 *
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
4010 * @return the element representing the getter that was found 4055 * @return the element representing the getter that was found
4011 */ 4056 */
4012 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, boo l includeTargetType, String getterName, Set<ClassElement> visitedInterfaces) { 4057 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, boo l includeTargetType, String getterName, Set<ClassElement> visitedInterfaces) {
4013 ClassElement targetClass = targetType.element; 4058 ClassElement targetClass = targetType.element;
4014 if (visitedInterfaces.contains(targetClass)) { 4059 if (visitedInterfaces.contains(targetClass)) {
4015 return null; 4060 return null;
4016 } 4061 }
4017 javaSetAdd(visitedInterfaces, targetClass); 4062 javaSetAdd(visitedInterfaces, targetClass);
4018 if (includeTargetType) { 4063 if (includeTargetType) {
4019 PropertyAccessorElement getter = targetType.getGetter(getterName); 4064 PropertyAccessorElement getter = targetType.getGetter(getterName);
4020 if (getter != null) { 4065 if (getter != null && getter.isAccessibleIn(_resolver.definingLibrary)) {
4021 return getter; 4066 return getter;
4022 } 4067 }
4023 } 4068 }
4024 for (InterfaceType interfaceType in targetType.interfaces) { 4069 for (InterfaceType interfaceType in targetType.interfaces) {
4025 PropertyAccessorElement getter = lookUpGetterInInterfaces(interfaceType, t rue, getterName, visitedInterfaces); 4070 PropertyAccessorElement getter = lookUpGetterInInterfaces(interfaceType, t rue, getterName, visitedInterfaces);
4026 if (getter != null) { 4071 if (getter != null) {
4027 return getter; 4072 return getter;
4028 } 4073 }
4029 } 4074 }
4030 for (InterfaceType mixinType in targetType.mixins) { 4075 for (InterfaceType mixinType in targetType.mixins) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
4193 * @return the element representing the method that was found 4238 * @return the element representing the method that was found
4194 */ 4239 */
4195 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, bool includeT argetType, String methodName, Set<ClassElement> visitedInterfaces) { 4240 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, bool includeT argetType, String methodName, Set<ClassElement> visitedInterfaces) {
4196 ClassElement targetClass = targetType.element; 4241 ClassElement targetClass = targetType.element;
4197 if (visitedInterfaces.contains(targetClass)) { 4242 if (visitedInterfaces.contains(targetClass)) {
4198 return null; 4243 return null;
4199 } 4244 }
4200 javaSetAdd(visitedInterfaces, targetClass); 4245 javaSetAdd(visitedInterfaces, targetClass);
4201 if (includeTargetType) { 4246 if (includeTargetType) {
4202 MethodElement method = targetType.getMethod(methodName); 4247 MethodElement method = targetType.getMethod(methodName);
4203 if (method != null) { 4248 if (method != null && method.isAccessibleIn(_resolver.definingLibrary)) {
4204 return method; 4249 return method;
4205 } 4250 }
4206 } 4251 }
4207 for (InterfaceType interfaceType in targetType.interfaces) { 4252 for (InterfaceType interfaceType in targetType.interfaces) {
4208 MethodElement method = lookUpMethodInInterfaces(interfaceType, true, metho dName, visitedInterfaces); 4253 MethodElement method = lookUpMethodInInterfaces(interfaceType, true, metho dName, visitedInterfaces);
4209 if (method != null) { 4254 if (method != null) {
4210 return method; 4255 return method;
4211 } 4256 }
4212 } 4257 }
4213 for (InterfaceType mixinType in targetType.mixins) { 4258 for (InterfaceType mixinType in targetType.mixins) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
4263 * @return the element representing the setter that was found 4308 * @return the element representing the setter that was found
4264 */ 4309 */
4265 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, boo l includeTargetType, String setterName, Set<ClassElement> visitedInterfaces) { 4310 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, boo l includeTargetType, String setterName, Set<ClassElement> visitedInterfaces) {
4266 ClassElement targetClass = targetType.element; 4311 ClassElement targetClass = targetType.element;
4267 if (visitedInterfaces.contains(targetClass)) { 4312 if (visitedInterfaces.contains(targetClass)) {
4268 return null; 4313 return null;
4269 } 4314 }
4270 javaSetAdd(visitedInterfaces, targetClass); 4315 javaSetAdd(visitedInterfaces, targetClass);
4271 if (includeTargetType) { 4316 if (includeTargetType) {
4272 PropertyAccessorElement setter = targetType.getSetter(setterName); 4317 PropertyAccessorElement setter = targetType.getSetter(setterName);
4273 if (setter != null) { 4318 if (setter != null && setter.isAccessibleIn(_resolver.definingLibrary)) {
4274 return setter; 4319 return setter;
4275 } 4320 }
4276 } 4321 }
4277 for (InterfaceType interfaceType in targetType.interfaces) { 4322 for (InterfaceType interfaceType in targetType.interfaces) {
4278 PropertyAccessorElement setter = lookUpSetterInInterfaces(interfaceType, t rue, setterName, visitedInterfaces); 4323 PropertyAccessorElement setter = lookUpSetterInInterfaces(interfaceType, t rue, setterName, visitedInterfaces);
4279 if (setter != null) { 4324 if (setter != null) {
4280 return setter; 4325 return setter;
4281 } 4326 }
4282 } 4327 }
4283 for (InterfaceType mixinType in targetType.mixins) { 4328 for (InterfaceType mixinType in targetType.mixins) {
4284 PropertyAccessorElement setter = lookUpSetterInInterfaces(mixinType, true, setterName, visitedInterfaces); 4329 PropertyAccessorElement setter = lookUpSetterInInterfaces(mixinType, true, setterName, visitedInterfaces);
4285 if (setter != null) { 4330 if (setter != null) {
4286 return setter; 4331 return setter;
4287 } 4332 }
4288 } 4333 }
4289 InterfaceType superclass = targetType.superclass; 4334 InterfaceType superclass = targetType.superclass;
4290 if (superclass == null) { 4335 if (superclass == null) {
4291 return null; 4336 return null;
4292 } 4337 }
4293 return lookUpSetterInInterfaces(superclass, true, setterName, visitedInterfa ces); 4338 return lookUpSetterInInterfaces(superclass, true, setterName, visitedInterfa ces);
4294 } 4339 }
4295 4340
4296 /** 4341 /**
4342 * Given some class element, this method uses [subtypeManager] to find the set of all
4343 * subtypes; the subtypes are then searched for a member (method, getter, or s etter), that matches
4344 * a passed
4345 *
4346 * @param element the class element to search the subtypes of, if a non-ClassE lement element is
4347 * passed, then `false` is returned
4348 * @param memberName the member name to search for
4349 * @param asMethod `true` if the methods should be searched for in the subtype s
4350 * @param asAccessor `true` if the accessors (getters and setters) should be s earched for in
4351 * the subtypes
4352 * @return `true` if and only if the passed memberName was found in a subtype
4353 */
4354 bool memberFoundInSubclass(Element element, String memberName, bool asMethod, bool asAccessor) {
4355 if (element is ClassElement) {
4356 _subtypeManager.ensureLibraryVisited(_resolver.definingLibrary);
4357 Set<ClassElement> subtypeElements = _subtypeManager.computeAllSubtypes(ele ment as ClassElement);
4358 for (ClassElement subtypeElement in subtypeElements) {
4359 if (asMethod && subtypeElement.getMethod(memberName) != null) {
4360 return true;
4361 } else if (asAccessor && (subtypeElement.getGetter(memberName) != null | | subtypeElement.getSetter(memberName) != null)) {
4362 return true;
4363 }
4364 }
4365 }
4366 return false;
4367 }
4368
4369 /**
4297 * Return the binary operator that is invoked by the given compound assignment operator. 4370 * Return the binary operator that is invoked by the given compound assignment operator.
4298 * 4371 *
4299 * @param operator the assignment operator being mapped 4372 * @param operator the assignment operator being mapped
4300 * @return the binary operator that invoked by the given assignment operator 4373 * @return the binary operator that invoked by the given assignment operator
4301 */ 4374 */
4302 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) { 4375 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) {
4303 while (true) { 4376 while (true) {
4304 if (operator == sc.TokenType.AMPERSAND_EQ) { 4377 if (operator == sc.TokenType.AMPERSAND_EQ) {
4305 return sc.TokenType.AMPERSAND; 4378 return sc.TokenType.AMPERSAND;
4306 } else if (operator == sc.TokenType.BAR_EQ) { 4379 } else if (operator == sc.TokenType.BAR_EQ) {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
4588 if (staticElement != null) { 4661 if (staticElement != null) {
4589 propertyName.staticElement = staticElement; 4662 propertyName.staticElement = staticElement;
4590 } 4663 }
4591 return; 4664 return;
4592 } 4665 }
4593 propertyName.staticElement = staticElement; 4666 propertyName.staticElement = staticElement;
4594 Type2 propagatedType = getPropagatedType(target); 4667 Type2 propagatedType = getPropagatedType(target);
4595 ExecutableElement propagatedElement = resolveProperty(target, propagatedType , propertyName); 4668 ExecutableElement propagatedElement = resolveProperty(target, propagatedType , propertyName);
4596 propertyName.propagatedElement = propagatedElement; 4669 propertyName.propagatedElement = propagatedElement;
4597 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement) && (_strictMode || shouldReportMissingMember(propagatedType, pr opagatedElement)); 4670 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement) && (_strictMode || shouldReportMissingMember(propagatedType, pr opagatedElement));
4598 bool shouldReportMissingMember_propagated = _enableHints ? shouldReportMissi ngMember(propagatedType, propagatedElement) : false; 4671 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false;
4672 if (shouldReportMissingMember_propagated) {
4673 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) {
4674 shouldReportMissingMember_propagated = false;
4675 }
4676 }
4599 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 4677 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
4600 Element selectedElement = select(staticElement, propagatedElement); 4678 Element selectedElement = select(staticElement, propagatedElement);
4601 bool isStaticProperty = isStatic(selectedElement); 4679 bool isStaticProperty = isStatic(selectedElement);
4602 if (propertyName.inSetterContext()) { 4680 if (propertyName.inSetterContext()) {
4603 if (isStaticProperty) { 4681 if (isStaticProperty) {
4604 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarnin gCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode; 4682 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarnin gCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode;
4605 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, errorCode, propertyName, [ 4683 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, errorCode, propertyName, [
4606 propertyName.name, 4684 propertyName.name,
4607 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 4685 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]);
4608 } else { 4686 } else {
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after
5979 */ 6057 */
5980 List<NamespaceCombinator> buildCombinators(NamespaceDirective directive) { 6058 List<NamespaceCombinator> buildCombinators(NamespaceDirective directive) {
5981 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>(); 6059 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>();
5982 for (Combinator combinator in directive.combinators) { 6060 for (Combinator combinator in directive.combinators) {
5983 if (combinator is HideCombinator) { 6061 if (combinator is HideCombinator) {
5984 HideElementCombinatorImpl hide = new HideElementCombinatorImpl(); 6062 HideElementCombinatorImpl hide = new HideElementCombinatorImpl();
5985 hide.hiddenNames = getIdentifiers(((combinator as HideCombinator)).hidde nNames); 6063 hide.hiddenNames = getIdentifiers(((combinator as HideCombinator)).hidde nNames);
5986 combinators.add(hide); 6064 combinators.add(hide);
5987 } else { 6065 } else {
5988 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl(); 6066 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl();
6067 show.offset = combinator.offset;
6068 show.end = combinator.end;
5989 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN ames); 6069 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN ames);
5990 combinators.add(show); 6070 combinators.add(show);
5991 } 6071 }
5992 } 6072 }
5993 return new List.from(combinators); 6073 return new List.from(combinators);
5994 } 6074 }
5995 6075
5996 /** 6076 /**
5997 * Every library now has a corresponding [LibraryElement], so it is now possib le to resolve 6077 * Every library now has a corresponding [LibraryElement], so it is now possib le to resolve
5998 * the import and export directives. 6078 * the import and export directives.
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
6727 } 6807 }
6728 } 6808 }
6729 } else { 6809 } else {
6730 safelyVisit(leftOperand); 6810 safelyVisit(leftOperand);
6731 safelyVisit(rightOperand); 6811 safelyVisit(rightOperand);
6732 } 6812 }
6733 node.accept(_elementResolver); 6813 node.accept(_elementResolver);
6734 node.accept(_typeAnalyzer); 6814 node.accept(_typeAnalyzer);
6735 return null; 6815 return null;
6736 } 6816 }
6817 Object visitBlockFunctionBody(BlockFunctionBody node) {
6818 try {
6819 overrideManager.enterScope();
6820 super.visitBlockFunctionBody(node);
6821 } finally {
6822 overrideManager.exitScope();
6823 }
6824 return null;
6825 }
6737 Object visitBreakStatement(BreakStatement node) { 6826 Object visitBreakStatement(BreakStatement node) {
6738 node.accept(_elementResolver); 6827 node.accept(_elementResolver);
6739 node.accept(_typeAnalyzer); 6828 node.accept(_typeAnalyzer);
6740 return null; 6829 return null;
6741 } 6830 }
6742 Object visitClassDeclaration(ClassDeclaration node) { 6831 Object visitClassDeclaration(ClassDeclaration node) {
6743 ClassElement outerType = enclosingClass; 6832 ClassElement outerType = enclosingClass;
6744 try { 6833 try {
6745 enclosingClass = node.element; 6834 enclosingClass = node.element;
6746 _typeAnalyzer.thisType = enclosingClass == null ? null : enclosingClass.ty pe; 6835 _typeAnalyzer.thisType = enclosingClass == null ? null : enclosingClass.ty pe;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
6844 } 6933 }
6845 Object visitDoStatement(DoStatement node) { 6934 Object visitDoStatement(DoStatement node) {
6846 try { 6935 try {
6847 overrideManager.enterScope(); 6936 overrideManager.enterScope();
6848 super.visitDoStatement(node); 6937 super.visitDoStatement(node);
6849 } finally { 6938 } finally {
6850 overrideManager.exitScope(); 6939 overrideManager.exitScope();
6851 } 6940 }
6852 return null; 6941 return null;
6853 } 6942 }
6943 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
6944 try {
6945 overrideManager.enterScope();
6946 super.visitExpressionFunctionBody(node);
6947 } finally {
6948 overrideManager.exitScope();
6949 }
6950 return null;
6951 }
6854 Object visitFieldDeclaration(FieldDeclaration node) { 6952 Object visitFieldDeclaration(FieldDeclaration node) {
6855 try { 6953 try {
6856 overrideManager.enterScope(); 6954 overrideManager.enterScope();
6857 super.visitFieldDeclaration(node); 6955 super.visitFieldDeclaration(node);
6858 } finally { 6956 } finally {
6859 Map<Element, Type2> overrides = overrideManager.captureOverrides(node.fiel ds); 6957 Map<Element, Type2> overrides = overrideManager.captureOverrides(node.fiel ds);
6860 overrideManager.exitScope(); 6958 overrideManager.exitScope();
6861 overrideManager.applyOverrides(overrides); 6959 overrideManager.applyOverrides(overrides);
6862 } 6960 }
6863 return null; 6961 return null;
6864 } 6962 }
6865 Object visitForEachStatement(ForEachStatement node) { 6963 Object visitForEachStatement(ForEachStatement node) {
6866 try { 6964 try {
6867 overrideManager.enterScope(); 6965 overrideManager.enterScope();
6868 super.visitForEachStatement(node); 6966 super.visitForEachStatement(node);
6869 } finally { 6967 } finally {
6870 overrideManager.exitScope(); 6968 overrideManager.exitScope();
6871 } 6969 }
6872 return null; 6970 return null;
6873 } 6971 }
6874 Object visitForStatement(ForStatement node) { 6972 Object visitForStatement(ForStatement node) {
6875 try { 6973 try {
6876 overrideManager.enterScope(); 6974 overrideManager.enterScope();
6877 super.visitForStatement(node); 6975 super.visitForStatement(node);
6878 } finally { 6976 } finally {
6879 overrideManager.exitScope(); 6977 overrideManager.exitScope();
6880 } 6978 }
6881 return null; 6979 return null;
6882 } 6980 }
6883 Object visitFunctionBody(FunctionBody node) {
6884 try {
6885 overrideManager.enterScope();
6886 super.visitFunctionBody(node);
6887 } finally {
6888 overrideManager.exitScope();
6889 }
6890 return null;
6891 }
6892 Object visitFunctionDeclaration(FunctionDeclaration node) { 6981 Object visitFunctionDeclaration(FunctionDeclaration node) {
6893 ExecutableElement outerFunction = enclosingFunction; 6982 ExecutableElement outerFunction = enclosingFunction;
6894 try { 6983 try {
6895 SimpleIdentifier functionName = node.name; 6984 SimpleIdentifier functionName = node.name;
6896 enclosingFunction = functionName.staticElement as ExecutableElement; 6985 enclosingFunction = functionName.staticElement as ExecutableElement;
6897 super.visitFunctionDeclaration(node); 6986 super.visitFunctionDeclaration(node);
6898 } finally { 6987 } finally {
6899 enclosingFunction = outerFunction; 6988 enclosingFunction = outerFunction;
6900 } 6989 }
6901 return null; 6990 return null;
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
7449 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; 7538 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v;
7450 get enclosingClass_J2DAccessor => enclosingClass; 7539 get enclosingClass_J2DAccessor => enclosingClass;
7451 set enclosingClass_J2DAccessor(__v) => enclosingClass = __v; 7540 set enclosingClass_J2DAccessor(__v) => enclosingClass = __v;
7452 } 7541 }
7453 /** 7542 /**
7454 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST structure is 7543 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST structure is
7455 * being visited. 7544 * being visited.
7456 * 7545 *
7457 * @coverage dart.engine.resolver 7546 * @coverage dart.engine.resolver
7458 */ 7547 */
7459 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { 7548 abstract class ScopedVisitor extends UnifyingASTVisitor<Object> {
7460 7549
7461 /** 7550 /**
7462 * The element for the library containing the compilation unit being visited. 7551 * The element for the library containing the compilation unit being visited.
7463 */ 7552 */
7464 LibraryElement definingLibrary; 7553 LibraryElement definingLibrary;
7465 7554
7466 /** 7555 /**
7467 * The source representing the compilation unit being visited. 7556 * The source representing the compilation unit being visited.
7468 */ 7557 */
7469 Source source; 7558 Source source;
(...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after
9479 } 9568 }
9480 if (result[0] == null) { 9569 if (result[0] == null) {
9481 result[0] = type; 9570 result[0] = type;
9482 } else { 9571 } else {
9483 result[0] = result[0].getLeastUpperBound(type); 9572 result[0] = result[0].getLeastUpperBound(type);
9484 } 9573 }
9485 return null; 9574 return null;
9486 } 9575 }
9487 } 9576 }
9488 /** 9577 /**
9578 * Instances of this class manage the knowledge of what the set of subtypes are for a given type.
9579 */
9580 class SubtypeManager {
9581
9582 /**
9583 * A map between [ClassElement]s and a set of [ClassElement]s that are subtype s of the
9584 * key.
9585 */
9586 Map<ClassElement, Set<ClassElement>> _subtypeMap = new Map<ClassElement, Set<C lassElement>>();
9587
9588 /**
9589 * The set of all [LibraryElement]s that have been visited by the manager. Thi s is used both
9590 * to prevent infinite loops in the recursive methods, and also as a marker fo r the scope of the
9591 * libraries visited by this manager.
9592 */
9593 Set<LibraryElement> _visitedLibraries = new Set<LibraryElement>();
9594
9595 /**
9596 * Given some [ClassElement], return the set of all subtypes, and subtypes of subtypes.
9597 *
9598 * @param classElement the class to recursively return the set of subtypes of
9599 */
9600 Set<ClassElement> computeAllSubtypes(ClassElement classElement) {
9601 computeSubtypesInLibrary(classElement.library);
9602 Set<ClassElement> allSubtypes = new Set<ClassElement>();
9603 computeAllSubtypes2(classElement, new Set<ClassElement>(), allSubtypes);
9604 return allSubtypes;
9605 }
9606
9607 /**
9608 * Given some [LibraryElement], visit all of the types in the library, the pas sed library,
9609 * and any imported libraries, will be in the [visitedLibraries] set.
9610 *
9611 * @param libraryElement the library to visit, it it hasn't been visited alrea dy
9612 */
9613 void ensureLibraryVisited(LibraryElement libraryElement) {
9614 computeSubtypesInLibrary(libraryElement);
9615 }
9616
9617 /**
9618 * Given some [ClassElement] and a [HashSet<ClassElement>], this method recurs ively
9619 * adds all of the subtypes of the [ClassElement] to the passed array.
9620 *
9621 * @param classElement the type to compute the set of subtypes of
9622 * @param visitedClasses the set of class elements that this method has alread y recursively seen
9623 * @param allSubtypes the computed set of subtypes of the passed class element
9624 */
9625 void computeAllSubtypes2(ClassElement classElement, Set<ClassElement> visitedC lasses, Set<ClassElement> allSubtypes) {
9626 if (!javaSetAdd(visitedClasses, classElement)) {
9627 return;
9628 }
9629 Set<ClassElement> subtypes = _subtypeMap[classElement];
9630 if (subtypes == null) {
9631 return;
9632 }
9633 for (ClassElement subtype in subtypes) {
9634 computeAllSubtypes2(subtype, visitedClasses, allSubtypes);
9635 }
9636 allSubtypes.addAll(subtypes);
9637 }
9638
9639 /**
9640 * Given some [ClassElement], this method adds all of the pairs combinations o f itself and
9641 * all of its supertypes to the [subtypeMap] map.
9642 *
9643 * @param classElement the class element
9644 */
9645 void computeSubtypesInClass(ClassElement classElement) {
9646 InterfaceType supertypeType = classElement.supertype;
9647 if (supertypeType != null) {
9648 ClassElement supertypeElement = supertypeType.element;
9649 if (supertypeElement != null) {
9650 putInSubtypeMap(supertypeElement, classElement);
9651 }
9652 }
9653 List<InterfaceType> interfaceTypes = classElement.interfaces;
9654 for (InterfaceType interfaceType in interfaceTypes) {
9655 ClassElement interfaceElement = interfaceType.element;
9656 if (interfaceElement != null) {
9657 putInSubtypeMap(interfaceElement, classElement);
9658 }
9659 }
9660 List<InterfaceType> mixinTypes = classElement.mixins;
9661 for (InterfaceType mixinType in mixinTypes) {
9662 ClassElement mixinElement = mixinType.element;
9663 if (mixinElement != null) {
9664 putInSubtypeMap(mixinElement, classElement);
9665 }
9666 }
9667 }
9668
9669 /**
9670 * Given some [CompilationUnitElement], this method calls
9671 * [computeAllSubtypes] on all of the [ClassElement]s in the
9672 * compilation unit.
9673 *
9674 * @param unitElement the compilation unit element
9675 */
9676 void computeSubtypesInCompilationUnit(CompilationUnitElement unitElement) {
9677 List<ClassElement> classElements = unitElement.types;
9678 for (ClassElement classElement in classElements) {
9679 computeSubtypesInClass(classElement);
9680 }
9681 }
9682
9683 /**
9684 * Given some [LibraryElement], this method calls
9685 * [computeAllSubtypes] on all of the [ClassElement]s in the
9686 * compilation unit, and itself for all imported and exported libraries. All v isited libraries are
9687 * added to the [visitedLibraries] set.
9688 *
9689 * @param libraryElement the library element
9690 */
9691 void computeSubtypesInLibrary(LibraryElement libraryElement) {
9692 if (libraryElement == null || _visitedLibraries.contains(libraryElement)) {
9693 return;
9694 }
9695 javaSetAdd(_visitedLibraries, libraryElement);
9696 computeSubtypesInCompilationUnit(libraryElement.definingCompilationUnit);
9697 List<CompilationUnitElement> parts = libraryElement.parts;
9698 for (CompilationUnitElement part in parts) {
9699 computeSubtypesInCompilationUnit(part);
9700 }
9701 List<LibraryElement> imports = libraryElement.importedLibraries;
9702 for (LibraryElement importElt in imports) {
9703 computeSubtypesInLibrary(importElt.library);
9704 }
9705 List<LibraryElement> exports = libraryElement.exportedLibraries;
9706 for (LibraryElement exportElt in exports) {
9707 computeSubtypesInLibrary(exportElt.library);
9708 }
9709 }
9710
9711 /**
9712 * Add some key/ value pair into the [subtypeMap] map.
9713 *
9714 * @param supertypeElement the key for the [subtypeMap] map
9715 * @param subtypeElement the value for the [subtypeMap] map
9716 */
9717 void putInSubtypeMap(ClassElement supertypeElement, ClassElement subtypeElemen t) {
9718 Set<ClassElement> subtypes = _subtypeMap[supertypeElement];
9719 if (subtypes == null) {
9720 subtypes = new Set<ClassElement>();
9721 _subtypeMap[supertypeElement] = subtypes;
9722 }
9723 javaSetAdd(subtypes, subtypeElement);
9724 }
9725 }
9726 /**
9489 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an 9727 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an
9490 * element within a given context. 9728 * element within a given context.
9491 */ 9729 */
9492 class TypeOverrideManager { 9730 class TypeOverrideManager {
9493 9731
9494 /** 9732 /**
9495 * The current override scope, or `null` if no scope has been entered. 9733 * The current override scope, or `null` if no scope has been entered.
9496 */ 9734 */
9497 TypeOverrideManager_TypeOverrideScope _currentScope; 9735 TypeOverrideManager_TypeOverrideScope _currentScope;
9498 9736
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
11123 Element foundElement = localLookup(name, referencingLibrary); 11361 Element foundElement = localLookup(name, referencingLibrary);
11124 if (foundElement != null) { 11362 if (foundElement != null) {
11125 return foundElement; 11363 return foundElement;
11126 } 11364 }
11127 for (Namespace nameSpace in _importedNamespaces) { 11365 for (Namespace nameSpace in _importedNamespaces) {
11128 Element element = nameSpace.get(name); 11366 Element element = nameSpace.get(name);
11129 if (element != null) { 11367 if (element != null) {
11130 if (foundElement == null) { 11368 if (foundElement == null) {
11131 foundElement = element; 11369 foundElement = element;
11132 } else if (foundElement != element) { 11370 } else if (foundElement != element) {
11133 foundElement = new MultiplyDefinedElementImpl.con1(_definingLibrary.co ntext, foundElement, element); 11371 foundElement = MultiplyDefinedElementImpl.fromElements(_definingLibrar y.context, foundElement, element);
11134 } 11372 }
11135 } 11373 }
11136 } 11374 }
11137 if (foundElement is MultiplyDefinedElementImpl) { 11375 if (foundElement is MultiplyDefinedElementImpl) {
11138 foundElement = removeSdkElements(foundElement as MultiplyDefinedElementImp l); 11376 foundElement = removeSdkElements(identifier, name, foundElement as Multipl yDefinedElementImpl);
11139 } 11377 }
11140 if (foundElement is MultiplyDefinedElementImpl) { 11378 if (foundElement is MultiplyDefinedElementImpl) {
11141 String foundEltName = foundElement.displayName; 11379 String foundEltName = foundElement.displayName;
11142 String libName1 = "", libName2 = "";
11143 List<Element> conflictingMembers = ((foundElement as MultiplyDefinedElemen tImpl)).conflictingElements; 11380 List<Element> conflictingMembers = ((foundElement as MultiplyDefinedElemen tImpl)).conflictingElements;
11144 LibraryElement enclosingLibrary = conflictingMembers[0].getAncestor(Librar yElement); 11381 String libName1 = getLibraryName(conflictingMembers[0], "");
11145 if (enclosingLibrary != null) { 11382 String libName2 = getLibraryName(conflictingMembers[1], "");
11146 libName1 = enclosingLibrary.definingCompilationUnit.displayName;
11147 }
11148 enclosingLibrary = conflictingMembers[1].getAncestor(LibraryElement);
11149 if (enclosingLibrary != null) {
11150 libName2 = enclosingLibrary.definingCompilationUnit.displayName;
11151 }
11152 _errorListener.onError(new AnalysisError.con2(getSource2(identifier), iden tifier.offset, identifier.length, StaticWarningCode.AMBIGUOUS_IMPORT, [foundEltN ame, libName1, libName2])); 11383 _errorListener.onError(new AnalysisError.con2(getSource2(identifier), iden tifier.offset, identifier.length, StaticWarningCode.AMBIGUOUS_IMPORT, [foundEltN ame, libName1, libName2]));
11153 return foundElement; 11384 return foundElement;
11154 } 11385 }
11155 if (foundElement != null) { 11386 if (foundElement != null) {
11156 defineWithoutChecking2(name, foundElement); 11387 defineWithoutChecking2(name, foundElement);
11157 } 11388 }
11158 return foundElement; 11389 return foundElement;
11159 } 11390 }
11160 11391
11161 /** 11392 /**
11162 * Create all of the namespaces associated with the libraries imported into th is library. The 11393 * Create all of the namespaces associated with the libraries imported into th is library. The
11163 * names are not added to this scope, but are stored for later reference. 11394 * names are not added to this scope, but are stored for later reference.
11164 * 11395 *
11165 * @param definingLibrary the element representing the library that imports th e libraries for 11396 * @param definingLibrary the element representing the library that imports th e libraries for
11166 * which namespaces will be created 11397 * which namespaces will be created
11167 */ 11398 */
11168 void createImportedNamespaces(LibraryElement definingLibrary) { 11399 void createImportedNamespaces(LibraryElement definingLibrary) {
11169 NamespaceBuilder builder = new NamespaceBuilder(); 11400 NamespaceBuilder builder = new NamespaceBuilder();
11170 for (ImportElement element in definingLibrary.imports) { 11401 for (ImportElement element in definingLibrary.imports) {
11171 _importedNamespaces.add(builder.createImportNamespace(element)); 11402 _importedNamespaces.add(builder.createImportNamespace(element));
11172 } 11403 }
11173 } 11404 }
11174 11405
11175 /** 11406 /**
11407 * Returns the name of the library that defines given element.
11408 *
11409 * @param element the element to get library name
11410 * @param def the default name to use
11411 * @return the name of the library that defines given element
11412 */
11413 String getLibraryName(Element element, String def) {
11414 if (element == null) {
11415 return def;
11416 }
11417 LibraryElement library = element.library;
11418 if (library == null) {
11419 return def;
11420 }
11421 return library.definingCompilationUnit.displayName;
11422 }
11423
11424 /**
11176 * Return the source that contains the given identifier, or the source associa ted with this scope 11425 * Return the source that contains the given identifier, or the source associa ted with this scope
11177 * if the source containing the identifier could not be determined. 11426 * if the source containing the identifier could not be determined.
11178 * 11427 *
11179 * @param identifier the identifier whose source is to be returned 11428 * @param identifier the identifier whose source is to be returned
11180 * @return the source that contains the given identifier 11429 * @return the source that contains the given identifier
11181 */ 11430 */
11182 Source getSource2(Identifier identifier) { 11431 Source getSource2(Identifier identifier) {
11183 CompilationUnit unit = identifier.getAncestor(CompilationUnit); 11432 CompilationUnit unit = identifier.getAncestor(CompilationUnit);
11184 if (unit != null) { 11433 if (unit != null) {
11185 CompilationUnitElement element = unit.element; 11434 CompilationUnitElement element = unit.element;
11186 if (element != null) { 11435 if (element != null) {
11187 Source source = element.source; 11436 Source source = element.source;
11188 if (source != null) { 11437 if (source != null) {
11189 return source; 11438 return source;
11190 } 11439 }
11191 } 11440 }
11192 } 11441 }
11193 return this.source; 11442 return this.source;
11194 } 11443 }
11195 11444
11196 /** 11445 /**
11197 * Given a collection of elements that a single name could all be mapped to, r emove from the list 11446 * Given a collection of elements that a single name could all be mapped to, r emove from the list
11198 * all of the names defined in the SDK. Return the element(s) that remain. 11447 * all of the names defined in the SDK. Return the element(s) that remain.
11199 * 11448 *
11449 * @param identifier the identifier node to lookup element for, used to report correct kind of a
11450 * problem and associate problem with
11451 * @param name the name associated with the element
11200 * @param foundElement the element encapsulating the collection of elements 11452 * @param foundElement the element encapsulating the collection of elements
11201 * @return all of the elements that are not defined in the SDK 11453 * @return all of the elements that are not defined in the SDK
11202 */ 11454 */
11203 Element removeSdkElements(MultiplyDefinedElementImpl foundElement) { 11455 Element removeSdkElements(Identifier identifier, String name, MultiplyDefinedE lementImpl foundElement) {
11204 List<Element> conflictingMembers = foundElement.conflictingElements; 11456 List<Element> conflictingMembers = foundElement.conflictingElements;
11205 int length = conflictingMembers.length; 11457 int length = conflictingMembers.length;
11206 int to = 0; 11458 int to = 0;
11459 Element sdkElement = null;
11207 for (Element member in conflictingMembers) { 11460 for (Element member in conflictingMembers) {
11208 if (!member.library.isInSdk) { 11461 if (member.library.isInSdk) {
11462 sdkElement = member;
11463 } else {
11209 conflictingMembers[to++] = member; 11464 conflictingMembers[to++] = member;
11210 } 11465 }
11211 } 11466 }
11467 if (sdkElement != null && to > 0) {
11468 String sdkLibName = getLibraryName(sdkElement, "");
11469 String otherLibName = getLibraryName(conflictingMembers[0], "");
11470 _errorListener.onError(new AnalysisError.con2(getSource2(identifier), iden tifier.offset, identifier.length, StaticWarningCode.CONFLICTING_DART_IMPORT, [na me, sdkLibName, otherLibName]));
11471 }
11212 if (to == length) { 11472 if (to == length) {
11213 return foundElement; 11473 return foundElement;
11214 } else if (to == 1) { 11474 } else if (to == 1) {
11215 return conflictingMembers[0]; 11475 return conflictingMembers[0];
11216 } else if (to == 0) { 11476 } else if (to == 0) {
11217 AnalysisEngine.instance.logger.logInformation("Multiply defined SDK elemen t: ${foundElement}"); 11477 AnalysisEngine.instance.logger.logInformation("Multiply defined SDK elemen t: ${foundElement}");
11218 return foundElement; 11478 return foundElement;
11219 } 11479 }
11220 List<Element> remaining = new List<Element>(to); 11480 List<Element> remaining = new List<Element>(to);
11221 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to); 11481 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to);
11222 return new MultiplyDefinedElementImpl.con2(_definingLibrary.context, remaini ng); 11482 return new MultiplyDefinedElementImpl(_definingLibrary.context, remaining);
11223 } 11483 }
11224 } 11484 }
11225 /** 11485 /**
11226 * Instances of the class `LibraryScope` implement a scope containing all of the names defined 11486 * Instances of the class `LibraryScope` implement a scope containing all of the names defined
11227 * in a given library. 11487 * in a given library.
11228 * 11488 *
11229 * @coverage dart.engine.resolver 11489 * @coverage dart.engine.resolver
11230 */ 11490 */
11231 class LibraryScope extends EnclosedScope { 11491 class LibraryScope extends EnclosedScope {
11232 11492
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
12304 try { 12564 try {
12305 _isInNativeClass = node.nativeClause != null; 12565 _isInNativeClass = node.nativeClause != null;
12306 _enclosingClass = node.element; 12566 _enclosingClass = node.element;
12307 WithClause withClause = node.withClause; 12567 WithClause withClause = node.withClause;
12308 ImplementsClause implementsClause = node.implementsClause; 12568 ImplementsClause implementsClause = node.implementsClause;
12309 ExtendsClause extendsClause = node.extendsClause; 12569 ExtendsClause extendsClause = node.extendsClause;
12310 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME); 12570 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME);
12311 checkForMemberWithClassName(); 12571 checkForMemberWithClassName();
12312 checkForNoDefaultSuperConstructorImplicit(node); 12572 checkForNoDefaultSuperConstructorImplicit(node);
12313 checkForAllMixinErrorCodes(withClause); 12573 checkForAllMixinErrorCodes(withClause);
12574 checkForConflictingTypeVariableErrorCodes(node);
12314 if (implementsClause != null || extendsClause != null) { 12575 if (implementsClause != null || extendsClause != null) {
12315 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt endsDisallowedClass(extendsClause)) { 12576 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt endsDisallowedClass(extendsClause)) {
12316 checkForNonAbstractClassInheritsAbstractMember(node); 12577 checkForNonAbstractClassInheritsAbstractMember(node);
12317 checkForInconsistentMethodInheritance(); 12578 checkForInconsistentMethodInheritance();
12318 checkForRecursiveInterfaceInheritance(_enclosingClass, new List<ClassE lement>()); 12579 checkForRecursiveInterfaceInheritance(_enclosingClass, new List<ClassE lement>());
12319 } 12580 }
12320 } 12581 }
12321 ClassElement classElement = node.element; 12582 ClassElement classElement = node.element;
12322 if (classElement != null) { 12583 if (classElement != null) {
12323 List<FieldElement> fieldElements = classElement.fields; 12584 List<FieldElement> fieldElements = classElement.fields;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
12540 Object visitListLiteral(ListLiteral node) { 12801 Object visitListLiteral(ListLiteral node) {
12541 if (node.constKeyword != null) { 12802 if (node.constKeyword != null) {
12542 TypeArgumentList typeArguments = node.typeArguments; 12803 TypeArgumentList typeArguments = node.typeArguments;
12543 if (typeArguments != null) { 12804 if (typeArguments != null) {
12544 NodeList<TypeName> arguments = typeArguments.arguments; 12805 NodeList<TypeName> arguments = typeArguments.arguments;
12545 if (arguments.length != 0) { 12806 if (arguments.length != 0) {
12546 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); 12807 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
12547 } 12808 }
12548 } 12809 }
12549 } 12810 }
12811 checkForExpectedOneListTypeArgument(node);
12550 checkForListElementTypeNotAssignable(node); 12812 checkForListElementTypeNotAssignable(node);
12551 return super.visitListLiteral(node); 12813 return super.visitListLiteral(node);
12552 } 12814 }
12553 Object visitMapLiteral(MapLiteral node) { 12815 Object visitMapLiteral(MapLiteral node) {
12554 TypeArgumentList typeArguments = node.typeArguments; 12816 TypeArgumentList typeArguments = node.typeArguments;
12555 if (typeArguments != null) { 12817 if (typeArguments != null) {
12556 NodeList<TypeName> arguments = typeArguments.arguments; 12818 NodeList<TypeName> arguments = typeArguments.arguments;
12557 if (arguments.length != 0) { 12819 if (arguments.length != 0) {
12558 if (node.constKeyword != null) { 12820 if (node.constKeyword != null) {
12559 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 12821 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
12560 } 12822 }
12561 } 12823 }
12562 } 12824 }
12825 checkExpectedTwoMapTypeArguments(typeArguments);
12563 checkForNonConstMapAsExpressionStatement(node); 12826 checkForNonConstMapAsExpressionStatement(node);
12564 checkForMapTypeNotAssignable(node); 12827 checkForMapTypeNotAssignable(node);
12828 checkForConstMapKeyExpressionTypeImplementsEquals2(node);
12565 return super.visitMapLiteral(node); 12829 return super.visitMapLiteral(node);
12566 } 12830 }
12567 Object visitMethodDeclaration(MethodDeclaration node) { 12831 Object visitMethodDeclaration(MethodDeclaration node) {
12568 ExecutableElement previousFunction = _enclosingFunction; 12832 ExecutableElement previousFunction = _enclosingFunction;
12569 try { 12833 try {
12570 _isInStaticMethod = node.isStatic; 12834 _isInStaticMethod = node.isStatic;
12571 _enclosingFunction = node.element; 12835 _enclosingFunction = node.element;
12572 SimpleIdentifier identifier = node.name; 12836 SimpleIdentifier identifier = node.name;
12573 String methodName = ""; 12837 String methodName = "";
12574 if (identifier != null) { 12838 if (identifier != null) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
12698 checkForFinalNotInitialized2(node.variables); 12962 checkForFinalNotInitialized2(node.variables);
12699 return super.visitTopLevelVariableDeclaration(node); 12963 return super.visitTopLevelVariableDeclaration(node);
12700 } 12964 }
12701 Object visitTypeName(TypeName node) { 12965 Object visitTypeName(TypeName node) {
12702 checkForTypeArgumentNotMatchingBounds(node); 12966 checkForTypeArgumentNotMatchingBounds(node);
12703 checkForTypeParameterReferencedByStatic(node); 12967 checkForTypeParameterReferencedByStatic(node);
12704 return super.visitTypeName(node); 12968 return super.visitTypeName(node);
12705 } 12969 }
12706 Object visitTypeParameter(TypeParameter node) { 12970 Object visitTypeParameter(TypeParameter node) {
12707 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_PARAMETER_NAME); 12971 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_PARAMETER_NAME);
12972 checkForTypeParameterSupertypeOfItsBound(node);
12708 return super.visitTypeParameter(node); 12973 return super.visitTypeParameter(node);
12709 } 12974 }
12710 Object visitVariableDeclaration(VariableDeclaration node) { 12975 Object visitVariableDeclaration(VariableDeclaration node) {
12711 SimpleIdentifier nameNode = node.name; 12976 SimpleIdentifier nameNode = node.name;
12712 Expression initializerNode = node.initializer; 12977 Expression initializerNode = node.initializer;
12713 checkForInvalidAssignment2(nameNode, initializerNode); 12978 checkForInvalidAssignment2(nameNode, initializerNode);
12714 nameNode.accept(this); 12979 nameNode.accept(this);
12715 String name = nameNode.name; 12980 String name = nameNode.name;
12716 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name); 12981 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name);
12717 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; 12982 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration;
(...skipping 11 matching lines...) Expand all
12729 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { 12994 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) {
12730 checkForFinalNotInitialized2(node.variables); 12995 checkForFinalNotInitialized2(node.variables);
12731 return super.visitVariableDeclarationStatement(node); 12996 return super.visitVariableDeclarationStatement(node);
12732 } 12997 }
12733 Object visitWhileStatement(WhileStatement node) { 12998 Object visitWhileStatement(WhileStatement node) {
12734 checkForNonBoolCondition(node.condition); 12999 checkForNonBoolCondition(node.condition);
12735 return super.visitWhileStatement(node); 13000 return super.visitWhileStatement(node);
12736 } 13001 }
12737 13002
12738 /** 13003 /**
13004 * This verifies if the passed map literal has type arguments then there is ex actly two.
13005 *
13006 * @param node the map literal to evaluate
13007 * @return `true` if and only if an error code is generated on the passed node
13008 * @see StaticTypeWarningCode#EXPECTED_TWO_MAP_TYPE_ARGUMENTS
13009 */
13010 bool checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) {
13011 if (typeArguments == null) {
13012 return false;
13013 }
13014 int num = typeArguments.arguments.length;
13015 if (num == 2) {
13016 return false;
13017 }
13018 _errorReporter.reportError2(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGU MENTS, typeArguments, [num]);
13019 return true;
13020 }
13021
13022 /**
12739 * This verifies that the passed constructor declaration does not violate any of the error codes 13023 * This verifies that the passed constructor declaration does not violate any of the error codes
12740 * relating to the initialization of fields in the enclosing class. 13024 * relating to the initialization of fields in the enclosing class.
12741 * 13025 *
12742 * @param node the [ConstructorDeclaration] to evaluate 13026 * @param node the [ConstructorDeclaration] to evaluate
12743 * @return `true` if and only if an error code is generated on the passed node 13027 * @return `true` if and only if an error code is generated on the passed node
12744 * @see #initialFieldElementsMap 13028 * @see #initialFieldElementsMap
12745 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR 13029 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR
12746 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES 13030 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES
12747 */ 13031 */
12748 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { 13032 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
12910 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes; 13194 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes;
12911 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes; 13195 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes;
12912 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes; 13196 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes;
12913 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes; 13197 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes;
12914 if (overridingNormalPT.length > overriddenNormalPT.length) { 13198 if (overridingNormalPT.length > overriddenNormalPT.length) {
12915 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_REQUIRED, e rrorNameTarget, [ 13199 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_REQUIRED, e rrorNameTarget, [
12916 overriddenNormalPT.length, 13200 overriddenNormalPT.length,
12917 overriddenExecutable.enclosingElement.displayName]); 13201 overriddenExecutable.enclosingElement.displayName]);
12918 return true; 13202 return true;
12919 } 13203 }
12920 if (overridingPositionalPT.length < overriddenPositionalPT.length) { 13204 if (overridingNormalPT.length + overridingPositionalPT.length < overriddenPo sitionalPT.length + overriddenNormalPT.length) {
12921 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_POSITIONAL, errorNameTarget, [ 13205 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_POSITIONAL, errorNameTarget, [
12922 overriddenPositionalPT.length, 13206 overriddenPositionalPT.length + overriddenNormalPT.length,
12923 overriddenExecutable.enclosingElement.displayName]); 13207 overriddenExecutable.enclosingElement.displayName]);
12924 return true; 13208 return true;
12925 } 13209 }
12926 Set<String> overridingParameterNameSet = overridingNamedPT.keys.toSet(); 13210 Set<String> overridingParameterNameSet = overridingNamedPT.keys.toSet();
12927 JavaIterator<String> overriddenParameterNameIterator = new JavaIterator(over riddenNamedPT.keys.toSet()); 13211 JavaIterator<String> overriddenParameterNameIterator = new JavaIterator(over riddenNamedPT.keys.toSet());
12928 while (overriddenParameterNameIterator.hasNext) { 13212 while (overriddenParameterNameIterator.hasNext) {
12929 String overriddenParamName = overriddenParameterNameIterator.next(); 13213 String overriddenParamName = overriddenParameterNameIterator.next();
12930 if (!overridingParameterNameSet.contains(overriddenParamName)) { 13214 if (!overridingParameterNameSet.contains(overriddenParamName)) {
12931 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_NAMED, er rorNameTarget, [ 13215 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_NAMED, er rorNameTarget, [
12932 overriddenParamName, 13216 overriddenParamName,
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
13174 } 13458 }
13175 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_MISSING_CONSTR UCTOR, redirectedNode, [constructorStrName, redirectedType.displayName]); 13459 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_MISSING_CONSTR UCTOR, redirectedNode, [constructorStrName, redirectedType.displayName]);
13176 return true; 13460 return true;
13177 } 13461 }
13178 return false; 13462 return false;
13179 } 13463 }
13180 FunctionType redirectedType = redirectedElement.type; 13464 FunctionType redirectedType = redirectedElement.type;
13181 Type2 redirectedReturnType = redirectedType.returnType; 13465 Type2 redirectedReturnType = redirectedType.returnType;
13182 FunctionType constructorType = node.element.type; 13466 FunctionType constructorType = node.element.type;
13183 Type2 constructorReturnType = constructorType.returnType; 13467 Type2 constructorReturnType = constructorType.returnType;
13184 if (!redirectedReturnType.isSubtypeOf(constructorReturnType)) { 13468 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) {
13185 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_T YPE, redirectedNode, [redirectedReturnType, constructorReturnType]); 13469 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_T YPE, redirectedNode, [redirectedReturnType, constructorReturnType]);
13186 return true; 13470 return true;
13187 } 13471 }
13188 if (!redirectedType.isSubtypeOf(constructorType)) { 13472 if (!redirectedType.isSubtypeOf(constructorType)) {
13189 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION _TYPE, redirectedNode, [redirectedType, constructorType]); 13473 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION _TYPE, redirectedNode, [redirectedType, constructorType]);
13190 return true; 13474 return true;
13191 } 13475 }
13192 return false; 13476 return false;
13193 } 13477 }
13194 13478
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
13508 /** 13792 /**
13509 * This verifies that the passed switch statement does not have a case express ion with the 13793 * This verifies that the passed switch statement does not have a case express ion with the
13510 * operator '==' overridden. 13794 * operator '==' overridden.
13511 * 13795 *
13512 * @param node the switch statement to evaluate 13796 * @param node the switch statement to evaluate
13513 * @param type the common type of all 'case' expressions 13797 * @param type the common type of all 'case' expressions
13514 * @return `true` if and only if an error code is generated on the passed node 13798 * @return `true` if and only if an error code is generated on the passed node
13515 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS 13799 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
13516 */ 13800 */
13517 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, Type2 ty pe) { 13801 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, Type2 ty pe) {
13518 if (type == null || type == _typeProvider.intType || type == _typeProvider.s tringType) { 13802 if (!implementsEqualsWhenNotAllowed(type)) {
13519 return false; 13803 return false;
13520 } 13804 }
13521 Element element = type.element; 13805 _errorReporter.reportError4(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEM ENTS_EQUALS, node.keyword, [type.displayName]);
13522 if (element is! ClassElement) {
13523 return false;
13524 }
13525 ClassElement classElement = element as ClassElement;
13526 MethodElement method = classElement.lookUpMethod("==", _currentLibrary);
13527 if (method == null || method.enclosingElement.type.isObject) {
13528 return false;
13529 }
13530 _errorReporter.reportError4(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEM ENTS_EQUALS, node.keyword, [element.displayName]);
13531 return true; 13806 return true;
13532 } 13807 }
13533 13808
13534 /** 13809 /**
13535 * This verifies that the passed method declaration is abstract only if the en closing class is 13810 * This verifies that the passed method declaration is abstract only if the en closing class is
13536 * also abstract. 13811 * also abstract.
13537 * 13812 *
13538 * @param node the method declaration to evaluate 13813 * @param node the method declaration to evaluate
13539 * @return `true` if and only if an error code is generated on the passed node 13814 * @return `true` if and only if an error code is generated on the passed node
13540 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER 13815 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
13755 if (member.isStatic) { 14030 if (member.isStatic) {
13756 return false; 14031 return false;
13757 } 14032 }
13758 ClassElement memberClass = member.enclosingElement as ClassElement; 14033 ClassElement memberClass = member.enclosingElement as ClassElement;
13759 InterfaceType memberType = memberClass.type; 14034 InterfaceType memberType = memberClass.type;
13760 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_ INSTANCE_MEMBER, nameNode, [memberType.displayName]); 14035 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_ INSTANCE_MEMBER, nameNode, [memberType.displayName]);
13761 return true; 14036 return true;
13762 } 14037 }
13763 14038
13764 /** 14039 /**
14040 * This verifies all conflicts between type variable and enclosing class. TODO (scheglov)
14041 *
14042 * @param node the class declaration to evaluate
14043 * @return `true` if and only if an error code is generated on the passed node
14044 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_CLASS
14045 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_MEMBER
14046 */
14047 bool checkForConflictingTypeVariableErrorCodes(ClassDeclaration node) {
14048 bool problemReported = false;
14049 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) {
14050 String name = typeParameter.name;
14051 if (_enclosingClass.name == name) {
14052 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_CLASS, typeParameter.nameOffset, name.length, [name]);
14053 problemReported = true;
14054 }
14055 if (_enclosingClass.getMethod(name) != null || _enclosingClass.getGetter(n ame) != null || _enclosingClass.getSetter(name) != null) {
14056 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_MEMBER, typeParameter.nameOffset, name.length, [name]);
14057 problemReported = true;
14058 }
14059 }
14060 return problemReported;
14061 }
14062
14063 /**
13765 * This verifies that if the passed constructor declaration is 'const' then th ere are no 14064 * This verifies that if the passed constructor declaration is 'const' then th ere are no
13766 * invocations of non-'const' super constructors. 14065 * invocations of non-'const' super constructors.
13767 * 14066 *
13768 * @param node the constructor declaration to evaluate 14067 * @param node the constructor declaration to evaluate
13769 * @return `true` if and only if an error code is generated on the passed node 14068 * @return `true` if and only if an error code is generated on the passed node
13770 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER 14069 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER
13771 */ 14070 */
13772 bool checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) { 14071 bool checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) {
13773 if (!_isEnclosingConstructorConst) { 14072 if (!_isEnclosingConstructorConst) {
13774 return false; 14073 return false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
13851 */ 14150 */
13852 bool checkForConstFormalParameter(NormalFormalParameter node) { 14151 bool checkForConstFormalParameter(NormalFormalParameter node) {
13853 if (node.isConst) { 14152 if (node.isConst) {
13854 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n ode, []); 14153 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n ode, []);
13855 return true; 14154 return true;
13856 } 14155 }
13857 return false; 14156 return false;
13858 } 14157 }
13859 14158
13860 /** 14159 /**
14160 * This verifies that the passed expression (used as a key in constant map) ha s class type that
14161 * does not declare operator <i>==<i>.
14162 *
14163 * @param key the expression to evaluate
14164 * @return `true` if and only if an error code is generated on the passed node
14165 * @see CompileTimeErrorCode#CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
14166 */
14167 bool checkForConstMapKeyExpressionTypeImplementsEquals(Expression key) {
14168 Type2 type = key.staticType;
14169 if (!implementsEqualsWhenNotAllowed(type)) {
14170 return false;
14171 }
14172 _errorReporter.reportError2(CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TY PE_IMPLEMENTS_EQUALS, key, [type.displayName]);
14173 return true;
14174 }
14175
14176 /**
14177 * This verifies that the all keys of the passed map literal have class type t hat does not declare
14178 * operator <i>==<i>.
14179 *
14180 * @param key the map literal to evaluate
14181 * @return `true` if and only if an error code is generated on the passed node
14182 * @see CompileTimeErrorCode#CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
14183 */
14184 bool checkForConstMapKeyExpressionTypeImplementsEquals2(MapLiteral node) {
14185 if (node.constKeyword == null) {
14186 return false;
14187 }
14188 bool hasProblems = false;
14189 for (MapLiteralEntry entry in node.entries) {
14190 Expression key = entry.key;
14191 hasProblems = javaBooleanOr(hasProblems, checkForConstMapKeyExpressionType ImplementsEquals(key));
14192 }
14193 return hasProblems;
14194 }
14195
14196 /**
13861 * This verifies that the passed instance creation expression is not being inv oked on an abstract 14197 * This verifies that the passed instance creation expression is not being inv oked on an abstract
13862 * class. 14198 * class.
13863 * 14199 *
13864 * @param node the instance creation expression to evaluate 14200 * @param node the instance creation expression to evaluate
13865 * @param typeName the [TypeName] of the [ConstructorName] from the 14201 * @param typeName the [TypeName] of the [ConstructorName] from the
13866 * [InstanceCreationExpression], this is the AST node that the error is attached to 14202 * [InstanceCreationExpression], this is the AST node that the error is attached to
13867 * @param type the type being constructed with this [InstanceCreationExpressio n] 14203 * @param type the type being constructed with this [InstanceCreationExpressio n]
13868 * @return `true` if and only if an error code is generated on the passed node 14204 * @return `true` if and only if an error code is generated on the passed node
13869 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS 14205 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS
13870 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS 14206 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
14071 return false; 14407 return false;
14072 } 14408 }
14073 if (inheritedMember.isStatic) { 14409 if (inheritedMember.isStatic) {
14074 return false; 14410 return false;
14075 } 14411 }
14076 _errorReporter.reportError3(CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERI TANCE, staticMember.nameOffset, name.length, [name, inheritedMember.enclosingEle ment.displayName]); 14412 _errorReporter.reportError3(CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERI TANCE, staticMember.nameOffset, name.length, [name, inheritedMember.enclosingEle ment.displayName]);
14077 return true; 14413 return true;
14078 } 14414 }
14079 14415
14080 /** 14416 /**
14417 * This verifies if the passed list literal has type arguments then there is e xactly one.
14418 *
14419 * @param node the list literal to evaluate
14420 * @return `true` if and only if an error code is generated on the passed node
14421 * @see StaticTypeWarningCode#EXPECTED_ONE_LIST_TYPE_ARGUMENTS
14422 */
14423 bool checkForExpectedOneListTypeArgument(ListLiteral node) {
14424 TypeArgumentList typeArguments = node.typeArguments;
14425 if (typeArguments == null) {
14426 return false;
14427 }
14428 int num = typeArguments.arguments.length;
14429 if (num == 1) {
14430 return false;
14431 }
14432 _errorReporter.reportError2(StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARG UMENTS, typeArguments, [num]);
14433 return true;
14434 }
14435
14436 /**
14081 * This verifies the passed import has unique name among other exported librar ies. 14437 * This verifies the passed import has unique name among other exported librar ies.
14082 * 14438 *
14083 * @param node the export directive to evaluate 14439 * @param node the export directive to evaluate
14084 * @return `true` if and only if an error code is generated on the passed node 14440 * @return `true` if and only if an error code is generated on the passed node
14085 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME 14441 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME
14086 */ 14442 */
14087 bool checkForExportDuplicateLibraryName(ExportDirective node) { 14443 bool checkForExportDuplicateLibraryName(ExportDirective node) {
14088 Element nodeElement = node.element; 14444 Element nodeElement = node.element;
14089 if (nodeElement is! ExportElement) { 14445 if (nodeElement is! ExportElement) {
14090 return false; 14446 return false;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
14400 } 14756 }
14401 14757
14402 /** 14758 /**
14403 * This verifies the passed import has unique name among other imported librar ies. 14759 * This verifies the passed import has unique name among other imported librar ies.
14404 * 14760 *
14405 * @param node the import directive to evaluate 14761 * @param node the import directive to evaluate
14406 * @return `true` if and only if an error code is generated on the passed node 14762 * @return `true` if and only if an error code is generated on the passed node
14407 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME 14763 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME
14408 */ 14764 */
14409 bool checkForImportDuplicateLibraryName(ImportDirective node) { 14765 bool checkForImportDuplicateLibraryName(ImportDirective node) {
14410 Element nodeElement = node.element; 14766 ImportElement nodeImportElement = node.element;
14411 if (nodeElement is! ImportElement) { 14767 if (nodeImportElement == null) {
14412 return false; 14768 return false;
14413 } 14769 }
14414 ImportElement nodeImportElement = nodeElement as ImportElement;
14415 LibraryElement nodeLibrary = nodeImportElement.importedLibrary; 14770 LibraryElement nodeLibrary = nodeImportElement.importedLibrary;
14416 if (nodeLibrary == null) { 14771 if (nodeLibrary == null) {
14417 return false; 14772 return false;
14418 } 14773 }
14419 String name = nodeLibrary.name; 14774 String name = nodeLibrary.name;
14420 LibraryElement prevLibrary = _nameToImportElement[name]; 14775 LibraryElement prevLibrary = _nameToImportElement[name];
14421 if (prevLibrary != null) { 14776 if (prevLibrary != null) {
14422 if (prevLibrary != nodeLibrary) { 14777 if (prevLibrary != nodeLibrary) {
14423 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_ NAME, node, [ 14778 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_ NAME, node, [
14424 prevLibrary.definingCompilationUnit.displayName, 14779 prevLibrary.definingCompilationUnit.displayName,
(...skipping 12 matching lines...) Expand all
14437 * internal library. 14792 * internal library.
14438 * 14793 *
14439 * @param node the import directive to evaluate 14794 * @param node the import directive to evaluate
14440 * @return `true` if and only if an error code is generated on the passed node 14795 * @return `true` if and only if an error code is generated on the passed node
14441 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY 14796 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY
14442 */ 14797 */
14443 bool checkForImportInternalLibrary(ImportDirective node) { 14798 bool checkForImportInternalLibrary(ImportDirective node) {
14444 if (_isInSystemLibrary) { 14799 if (_isInSystemLibrary) {
14445 return false; 14800 return false;
14446 } 14801 }
14447 Element element = node.element; 14802 ImportElement importElement = node.element;
14448 if (element is! ImportElement) { 14803 if (importElement == null) {
14449 return false; 14804 return false;
14450 } 14805 }
14451 ImportElement importElement = element as ImportElement;
14452 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; 14806 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk;
14453 String uri = importElement.uri; 14807 String uri = importElement.uri;
14454 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); 14808 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri);
14455 if (sdkLibrary == null) { 14809 if (sdkLibrary == null) {
14456 return false; 14810 return false;
14457 } 14811 }
14458 if (!sdkLibrary.isInternal) { 14812 if (!sdkLibrary.isInternal) {
14459 return false; 14813 return false;
14460 } 14814 }
14461 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no de, [node.uri]); 14815 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no de, [node.uri]);
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
15615 * This verifies that the type arguments in the passed type name are all withi n their bounds. 15969 * This verifies that the type arguments in the passed type name are all withi n their bounds.
15616 * 15970 *
15617 * @param node the [TypeName] to evaluate 15971 * @param node the [TypeName] to evaluate
15618 * @return `true` if and only if an error code is generated on the passed node 15972 * @return `true` if and only if an error code is generated on the passed node
15619 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS 15973 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
15620 */ 15974 */
15621 bool checkForTypeArgumentNotMatchingBounds(TypeName node) { 15975 bool checkForTypeArgumentNotMatchingBounds(TypeName node) {
15622 if (node.typeArguments == null) { 15976 if (node.typeArguments == null) {
15623 return false; 15977 return false;
15624 } 15978 }
15625 List<TypeParameterElement> boundingElts = null;
15626 Type2 type = node.type; 15979 Type2 type = node.type;
15627 if (type == null) { 15980 if (type == null) {
15628 return false; 15981 return false;
15629 } 15982 }
15630 Element element = type.element; 15983 Element element = type.element;
15631 if (element is ClassElement) { 15984 if (element is! ClassElement) {
15632 boundingElts = ((element as ClassElement)).typeParameters;
15633 } else {
15634 return false; 15985 return false;
15635 } 15986 }
15987 ClassElement classElement = element as ClassElement;
15988 List<Type2> typeParameters = classElement.type.typeArguments;
15989 List<TypeParameterElement> boundingElts = classElement.typeParameters;
15636 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments; 15990 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments;
15991 List<Type2> typeArguments = ((type as InterfaceType)).typeArguments;
15637 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length) ; 15992 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length) ;
15638 bool foundError = false; 15993 bool foundError = false;
15639 for (int i = 0; i < loopThroughIndex; i++) { 15994 for (int i = 0; i < loopThroughIndex; i++) {
15640 TypeName argTypeName = typeNameArgList[i]; 15995 TypeName argTypeName = typeNameArgList[i];
15641 Type2 argType = argTypeName.type; 15996 Type2 argType = argTypeName.type;
15642 Type2 boundType = boundingElts[i].bound; 15997 Type2 boundType = boundingElts[i].bound;
15643 if (argType != null && boundType != null) { 15998 if (argType != null && boundType != null) {
15999 boundType = boundType.substitute2(typeArguments, typeParameters);
15644 if (!argType.isSubtypeOf(boundType)) { 16000 if (!argType.isSubtypeOf(boundType)) {
15645 ErrorCode errorCode; 16001 ErrorCode errorCode;
15646 if (isInConstConstructorInvocation(node)) { 16002 if (isInConstConstructorInvocation(node)) {
15647 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 16003 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
15648 } else { 16004 } else {
15649 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 16005 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
15650 } 16006 }
15651 _errorReporter.reportError2(errorCode, argTypeName, [argType.displayNa me, boundType.displayName]); 16007 _errorReporter.reportError2(errorCode, argTypeName, [argType.displayNa me, boundType.displayName]);
15652 foundError = true; 16008 foundError = true;
15653 } 16009 }
(...skipping 15 matching lines...) Expand all
15669 Type2 type = node.type; 16025 Type2 type = node.type;
15670 if (type is TypeParameterType) { 16026 if (type is TypeParameterType) {
15671 _errorReporter.reportError2(StaticWarningCode.TYPE_PARAMETER_REFERENCED_ BY_STATIC, node, []); 16027 _errorReporter.reportError2(StaticWarningCode.TYPE_PARAMETER_REFERENCED_ BY_STATIC, node, []);
15672 return true; 16028 return true;
15673 } 16029 }
15674 } 16030 }
15675 return false; 16031 return false;
15676 } 16032 }
15677 16033
15678 /** 16034 /**
16035 * This checks that if the passed type parameter is a supertype of its bound.
16036 *
16037 * @param node the type parameter to evaluate
16038 * @return `true` if and only if an error code is generated on the passed node
16039 * @see StaticTypeWarningCode#TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND
16040 */
16041 bool checkForTypeParameterSupertypeOfItsBound(TypeParameter node) {
16042 TypeParameterElement element = node.element;
16043 Type2 bound = element.bound;
16044 if (bound == null) {
16045 return false;
16046 }
16047 if (!bound.isMoreSpecificThan(element.type)) {
16048 return false;
16049 }
16050 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_O F_ITS_BOUND, node, [element.displayName]);
16051 return true;
16052 }
16053
16054 /**
15679 * This checks that if the passed generative constructor has neither an explic it super constructor 16055 * This checks that if the passed generative constructor has neither an explic it super constructor
15680 * invocation nor a redirecting constructor invocation, that the superclass ha s a default 16056 * invocation nor a redirecting constructor invocation, that the superclass ha s a default
15681 * generative constructor. 16057 * generative constructor.
15682 * 16058 *
15683 * @param node the constructor declaration to evaluate 16059 * @param node the constructor declaration to evaluate
15684 * @return `true` if and only if an error code is generated on the passed node 16060 * @return `true` if and only if an error code is generated on the passed node
15685 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT 16061 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT
15686 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR 16062 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR
15687 * @see StaticWarningCode#NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT 16063 * @see StaticWarningCode#NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT
15688 */ 16064 */
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
15948 } 16324 }
15949 } 16325 }
15950 if (current != null && !checked.contains(current)) { 16326 if (current != null && !checked.contains(current)) {
15951 break; 16327 break;
15952 } 16328 }
15953 } 16329 }
15954 current.accept(new GeneralizingElementVisitor_12(target, toCheck)); 16330 current.accept(new GeneralizingElementVisitor_12(target, toCheck));
15955 javaSetAdd(checked, current); 16331 javaSetAdd(checked, current);
15956 } 16332 }
15957 } 16333 }
16334
16335 /**
16336 * @return `true` if given [Type] implements operator <i>==</i>, and it is not
16337 * <i>int</i> or <i>String</i>.
16338 */
16339 bool implementsEqualsWhenNotAllowed(Type2 type) {
16340 if (type == null || type == _typeProvider.intType || type == _typeProvider.s tringType) {
16341 return false;
16342 }
16343 Element element = type.element;
16344 if (element is! ClassElement) {
16345 return false;
16346 }
16347 ClassElement classElement = element as ClassElement;
16348 MethodElement method = classElement.lookUpMethod("==", _currentLibrary);
16349 if (method == null || method.enclosingElement.type.isObject) {
16350 return false;
16351 }
16352 return true;
16353 }
15958 bool isFunctionType(Type2 type) { 16354 bool isFunctionType(Type2 type) {
15959 if (type.isDynamic || type.isBottom) { 16355 if (type.isDynamic || type.isBottom) {
15960 return true; 16356 return true;
15961 } else if (type is FunctionType || type.isDartCoreFunction) { 16357 } else if (type is FunctionType || type.isDartCoreFunction) {
15962 return true; 16358 return true;
15963 } else if (type is InterfaceType) { 16359 } else if (type is InterfaceType) {
15964 MethodElement callMethod = ((type as InterfaceType)).lookUpMethod(ElementR esolver.CALL_METHOD_NAME, _currentLibrary); 16360 MethodElement callMethod = ((type as InterfaceType)).lookUpMethod(ElementR esolver.CALL_METHOD_NAME, _currentLibrary);
15965 return callMethod != null; 16361 return callMethod != null;
15966 } 16362 }
15967 return false; 16363 return false;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
16235 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag e, String correction) : super(name, ordinal) { 16631 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag e, String correction) : super(name, ordinal) {
16236 this._type = type; 16632 this._type = type;
16237 this._message = message; 16633 this._message = message;
16238 this.correction9 = correction; 16634 this.correction9 = correction;
16239 } 16635 }
16240 String get correction => correction9; 16636 String get correction => correction9;
16241 ErrorSeverity get errorSeverity => _type.severity; 16637 ErrorSeverity get errorSeverity => _type.severity;
16242 String get message => _message; 16638 String get message => _message;
16243 ErrorType get type => _type; 16639 ErrorType get type => _type;
16244 } 16640 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/generated/parser.dart ('k') | pkg/analyzer_experimental/lib/src/generated/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698