| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 library engine.resolver; | 3 library engine.resolver; |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'java_core.dart'; | 5 import 'java_core.dart'; |
| 6 import 'java_engine.dart'; | 6 import 'java_engine.dart'; |
| 7 import 'instrumentation.dart'; | 7 import 'instrumentation.dart'; |
| 8 import 'source.dart'; | 8 import 'source.dart'; |
| 9 import 'error.dart'; | 9 import 'error.dart'; |
| 10 import 'scanner.dart' as sc; | 10 import 'scanner.dart' as sc; |
| 11 import 'utilities_dart.dart'; | 11 import 'utilities_dart.dart'; |
| 12 import 'ast.dart'; | 12 import 'ast.dart'; |
| 13 import 'parser.dart' show Parser, ParserErrorCode; | 13 import 'parser.dart' show Parser, ParserErrorCode; |
| 14 import 'sdk.dart' show DartSdk, SdkLibrary; | 14 import 'sdk.dart' show DartSdk, SdkLibrary; |
| 15 import 'element.dart'; | 15 import 'element.dart'; |
| 16 import 'html.dart' as ht; | 16 import 'html.dart' as ht; |
| 17 import 'engine.dart'; | 17 import 'engine.dart'; |
| 18 import 'constant.dart'; | 18 import 'constant.dart'; |
| 19 /** | 19 /** |
| 20 * Instances of the class {@code CompilationUnitBuilder} build an element model
for a single | 20 * Instances of the class `CompilationUnitBuilder` build an element model for a
single |
| 21 * compilation unit. | 21 * compilation unit. |
| 22 * @coverage dart.engine.resolver | 22 * @coverage dart.engine.resolver |
| 23 */ | 23 */ |
| 24 class CompilationUnitBuilder { | 24 class CompilationUnitBuilder { |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Build the compilation unit element for the given source. | 27 * Build the compilation unit element for the given source. |
| 28 * @param source the source describing the compilation unit | 28 * @param source the source describing the compilation unit |
| 29 * @param unit the AST structure representing the compilation unit | 29 * @param unit the AST structure representing the compilation unit |
| 30 * @return the compilation unit element that was built | 30 * @return the compilation unit element that was built |
| (...skipping 11 matching lines...) Expand all Loading... |
| 42 element.functions = holder.functions; | 42 element.functions = holder.functions; |
| 43 element.source = source2; | 43 element.source = source2; |
| 44 element.typeAliases = holder.typeAliases; | 44 element.typeAliases = holder.typeAliases; |
| 45 element.types = holder.types; | 45 element.types = holder.types; |
| 46 element.topLevelVariables = holder.topLevelVariables; | 46 element.topLevelVariables = holder.topLevelVariables; |
| 47 unit.element = element; | 47 unit.element = element; |
| 48 return element; | 48 return element; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 /** | 51 /** |
| 52 * Instances of the class {@code ElementBuilder} traverse an AST structure and b
uild the element | 52 * Instances of the class `ElementBuilder` traverse an AST structure and build t
he element |
| 53 * model representing the AST structure. | 53 * model representing the AST structure. |
| 54 * @coverage dart.engine.resolver | 54 * @coverage dart.engine.resolver |
| 55 */ | 55 */ |
| 56 class ElementBuilder extends RecursiveASTVisitor<Object> { | 56 class ElementBuilder extends RecursiveASTVisitor<Object> { |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * The element holder associated with the element that is currently being buil
t. | 59 * The element holder associated with the element that is currently being buil
t. |
| 60 */ | 60 */ |
| 61 ElementHolder _currentHolder; | 61 ElementHolder _currentHolder; |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * A flag indicating whether a variable declaration is in the context of a fie
ld declaration. | 64 * A flag indicating whether a variable declaration is in the context of a fie
ld declaration. |
| 65 */ | 65 */ |
| 66 bool _inFieldContext = false; | 66 bool _inFieldContext = false; |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * A flag indicating whether a variable declaration is within the body of a me
thod or function. | 69 * A flag indicating whether a variable declaration is within the body of a me
thod or function. |
| 70 */ | 70 */ |
| 71 bool _inFunction = false; | 71 bool _inFunction = false; |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * A flag indicating whether the class currently being visited can be used as
a mixin. | 74 * A flag indicating whether the class currently being visited can be used as
a mixin. |
| 75 */ | 75 */ |
| 76 bool _isValidMixin = false; | 76 bool _isValidMixin = false; |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * A collection holding the function types defined in a class that need to hav
e their type |
| 80 * arguments set to the types of the type parameters for the class, or `null`
if we are not |
| 81 * currently processing nodes within a class. |
| 82 */ |
| 83 List<FunctionTypeImpl> _functionTypesToFix = null; |
| 84 |
| 85 /** |
| 79 * Initialize a newly created element builder to build the elements for a comp
ilation unit. | 86 * Initialize a newly created element builder to build the elements for a comp
ilation unit. |
| 80 * @param initialHolder the element holder associated with the compilation uni
t being built | 87 * @param initialHolder the element holder associated with the compilation uni
t being built |
| 81 */ | 88 */ |
| 82 ElementBuilder(ElementHolder initialHolder) { | 89 ElementBuilder(ElementHolder initialHolder) { |
| 83 _currentHolder = initialHolder; | 90 _currentHolder = initialHolder; |
| 84 } | 91 } |
| 85 Object visitBlock(Block node) { | 92 Object visitBlock(Block node) { |
| 86 bool wasInField = _inFieldContext; | 93 bool wasInField = _inFieldContext; |
| 87 _inFieldContext = false; | 94 _inFieldContext = false; |
| 88 try { | 95 try { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 103 LocalVariableElementImpl stackTrace = new LocalVariableElementImpl(stack
TraceParameter); | 110 LocalVariableElementImpl stackTrace = new LocalVariableElementImpl(stack
TraceParameter); |
| 104 _currentHolder.addLocalVariable(stackTrace); | 111 _currentHolder.addLocalVariable(stackTrace); |
| 105 stackTraceParameter.element = stackTrace; | 112 stackTraceParameter.element = stackTrace; |
| 106 } | 113 } |
| 107 } | 114 } |
| 108 return super.visitCatchClause(node); | 115 return super.visitCatchClause(node); |
| 109 } | 116 } |
| 110 Object visitClassDeclaration(ClassDeclaration node) { | 117 Object visitClassDeclaration(ClassDeclaration node) { |
| 111 ElementHolder holder = new ElementHolder(); | 118 ElementHolder holder = new ElementHolder(); |
| 112 _isValidMixin = true; | 119 _isValidMixin = true; |
| 120 _functionTypesToFix = new List<FunctionTypeImpl>(); |
| 113 visitChildren(holder, node); | 121 visitChildren(holder, node); |
| 114 SimpleIdentifier className = node.name; | 122 SimpleIdentifier className = node.name; |
| 115 ClassElementImpl element = new ClassElementImpl(className); | 123 ClassElementImpl element = new ClassElementImpl(className); |
| 116 List<TypeVariableElement> typeVariables = holder.typeVariables; | 124 List<TypeVariableElement> typeVariables = holder.typeVariables; |
| 125 List<Type2> typeArguments = createTypeVariableTypes(typeVariables); |
| 117 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); | 126 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); |
| 118 interfaceType.typeArguments = createTypeVariableTypes(typeVariables); | 127 interfaceType.typeArguments = typeArguments; |
| 119 element.type = interfaceType; | 128 element.type = interfaceType; |
| 120 List<ConstructorElement> constructors = holder.constructors; | 129 List<ConstructorElement> constructors = holder.constructors; |
| 121 if (constructors.length == 0) { | 130 if (constructors.length == 0) { |
| 122 constructors = createDefaultConstructors(interfaceType); | 131 constructors = createDefaultConstructors(interfaceType); |
| 123 } | 132 } |
| 124 element.abstract = node.abstractKeyword != null; | 133 element.abstract = node.abstractKeyword != null; |
| 125 element.accessors = holder.accessors; | 134 element.accessors = holder.accessors; |
| 126 element.constructors = constructors; | 135 element.constructors = constructors; |
| 127 element.fields = holder.fields; | 136 element.fields = holder.fields; |
| 128 element.methods = holder.methods; | 137 element.methods = holder.methods; |
| 129 element.typeVariables = typeVariables; | 138 element.typeVariables = typeVariables; |
| 130 element.validMixin = _isValidMixin; | 139 element.validMixin = _isValidMixin; |
| 140 for (FunctionTypeImpl functionType in _functionTypesToFix) { |
| 141 functionType.typeArguments = typeArguments; |
| 142 } |
| 143 _functionTypesToFix = null; |
| 131 _currentHolder.addType(element); | 144 _currentHolder.addType(element); |
| 132 className.element = element; | 145 className.element = element; |
| 146 holder.validate(); |
| 133 return null; | 147 return null; |
| 134 } | 148 } |
| 135 Object visitClassTypeAlias(ClassTypeAlias node) { | 149 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 136 ElementHolder holder = new ElementHolder(); | 150 ElementHolder holder = new ElementHolder(); |
| 151 _functionTypesToFix = new List<FunctionTypeImpl>(); |
| 137 visitChildren(holder, node); | 152 visitChildren(holder, node); |
| 138 SimpleIdentifier className = node.name; | 153 SimpleIdentifier className = node.name; |
| 139 ClassElementImpl element = new ClassElementImpl(className); | 154 ClassElementImpl element = new ClassElementImpl(className); |
| 140 element.abstract = node.abstractKeyword != null; | 155 element.abstract = node.abstractKeyword != null; |
| 141 element.typedef = true; | 156 element.typedef = true; |
| 142 List<TypeVariableElement> typeVariables = holder.typeVariables; | 157 List<TypeVariableElement> typeVariables = holder.typeVariables; |
| 143 element.typeVariables = typeVariables; | 158 element.typeVariables = typeVariables; |
| 159 List<Type2> typeArguments = createTypeVariableTypes(typeVariables); |
| 144 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); | 160 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); |
| 145 interfaceType.typeArguments = createTypeVariableTypes(typeVariables); | 161 interfaceType.typeArguments = typeArguments; |
| 146 element.type = interfaceType; | 162 element.type = interfaceType; |
| 147 element.constructors = createDefaultConstructors(interfaceType); | 163 element.constructors = createDefaultConstructors(interfaceType); |
| 164 for (FunctionTypeImpl functionType in _functionTypesToFix) { |
| 165 functionType.typeArguments = typeArguments; |
| 166 } |
| 167 _functionTypesToFix = null; |
| 148 _currentHolder.addType(element); | 168 _currentHolder.addType(element); |
| 149 className.element = element; | 169 className.element = element; |
| 170 holder.validate(); |
| 150 return null; | 171 return null; |
| 151 } | 172 } |
| 152 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 173 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 153 _isValidMixin = false; | 174 _isValidMixin = false; |
| 154 ElementHolder holder = new ElementHolder(); | 175 ElementHolder holder = new ElementHolder(); |
| 155 bool wasInFunction = _inFunction; | 176 bool wasInFunction = _inFunction; |
| 156 _inFunction = true; | 177 _inFunction = true; |
| 157 try { | 178 try { |
| 158 visitChildren(holder, node); | 179 visitChildren(holder, node); |
| 159 } finally { | 180 } finally { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 _currentHolder.addConstructor(element); | 193 _currentHolder.addConstructor(element); |
| 173 node.element = element; | 194 node.element = element; |
| 174 if (constructorName == null) { | 195 if (constructorName == null) { |
| 175 Identifier returnType = node.returnType; | 196 Identifier returnType = node.returnType; |
| 176 if (returnType != null) { | 197 if (returnType != null) { |
| 177 element.nameOffset = returnType.offset; | 198 element.nameOffset = returnType.offset; |
| 178 } | 199 } |
| 179 } else { | 200 } else { |
| 180 constructorName.element = element; | 201 constructorName.element = element; |
| 181 } | 202 } |
| 203 holder.validate(); |
| 182 return null; | 204 return null; |
| 183 } | 205 } |
| 184 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 206 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 185 SimpleIdentifier variableName = node.identifier; | 207 SimpleIdentifier variableName = node.identifier; |
| 186 sc.Token keyword = node.keyword; | 208 sc.Token keyword = node.keyword; |
| 187 LocalVariableElementImpl element = new LocalVariableElementImpl(variableName
); | 209 LocalVariableElementImpl element = new LocalVariableElementImpl(variableName
); |
| 188 ForEachStatement statement = node.parent as ForEachStatement; | 210 ForEachStatement statement = node.parent as ForEachStatement; |
| 189 int declarationEnd = node.offset + node.length; | 211 int declarationEnd = node.offset + node.length; |
| 190 int statementEnd = statement.offset + statement.length; | 212 int statementEnd = statement.offset + statement.length; |
| 191 element.setVisibleRange(declarationEnd, statementEnd - declarationEnd - 1); | 213 element.setVisibleRange(declarationEnd, statementEnd - declarationEnd - 1); |
| 192 element.const3 = matches(keyword, sc.Keyword.CONST); | 214 element.const3 = matches(keyword, sc.Keyword.CONST); |
| 193 element.final2 = matches(keyword, sc.Keyword.FINAL); | 215 element.final2 = matches(keyword, sc.Keyword.FINAL); |
| 194 _currentHolder.addLocalVariable(element); | 216 _currentHolder.addLocalVariable(element); |
| 195 variableName.element = element; | 217 variableName.element = element; |
| 196 return super.visitDeclaredIdentifier(node); | 218 return super.visitDeclaredIdentifier(node); |
| 197 } | 219 } |
| 198 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 220 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 199 ElementHolder holder = new ElementHolder(); | 221 ElementHolder holder = new ElementHolder(); |
| 200 visit(holder, node.defaultValue); | 222 visit(holder, node.defaultValue); |
| 201 FunctionElementImpl initializer = new FunctionElementImpl(); | 223 FunctionElementImpl initializer = new FunctionElementImpl(); |
| 202 initializer.functions = holder.functions; | 224 initializer.functions = holder.functions; |
| 203 initializer.labels = holder.labels; | 225 initializer.labels = holder.labels; |
| 204 initializer.localVariables = holder.localVariables; | 226 initializer.localVariables = holder.localVariables; |
| 205 initializer.parameters = holder.parameters; | 227 initializer.parameters = holder.parameters; |
| 206 SimpleIdentifier parameterName = node.parameter.identifier; | 228 SimpleIdentifier parameterName = node.parameter.identifier; |
| 207 ParameterElementImpl parameter; | 229 ParameterElementImpl parameter; |
| 208 if (node.isConst()) { | 230 if (node.parameter is FieldFormalParameter) { |
| 209 parameter = new ConstParameterElementImpl(parameterName); | 231 parameter = new DefaultFieldFormalParameterElementImpl(parameterName); |
| 210 parameter.const3 = true; | |
| 211 } else if (node.parameter is FieldFormalParameter) { | |
| 212 parameter = new FieldFormalParameterElementImpl(parameterName); | |
| 213 } else { | 232 } else { |
| 214 parameter = new ParameterElementImpl(parameterName); | 233 parameter = new DefaultParameterElementImpl(parameterName); |
| 215 } | 234 } |
| 235 parameter.const3 = node.isConst(); |
| 216 parameter.final2 = node.isFinal(); | 236 parameter.final2 = node.isFinal(); |
| 217 parameter.initializer = initializer; | 237 parameter.initializer = initializer; |
| 218 parameter.parameterKind = node.kind; | 238 parameter.parameterKind = node.kind; |
| 219 Expression defaultValue = node.defaultValue; | 239 Expression defaultValue = node.defaultValue; |
| 220 if (defaultValue != null) { | 240 if (defaultValue != null) { |
| 221 parameter.setDefaultValueRange(defaultValue.offset, defaultValue.length); | 241 parameter.setDefaultValueRange(defaultValue.offset, defaultValue.length); |
| 222 } | 242 } |
| 223 FunctionBody body = getFunctionBody(node); | 243 FunctionBody body = getFunctionBody(node); |
| 224 if (body != null) { | 244 if (body != null) { |
| 225 parameter.setVisibleRange(body.offset, body.length); | 245 parameter.setVisibleRange(body.offset, body.length); |
| 226 } | 246 } |
| 227 _currentHolder.addParameter(parameter); | 247 _currentHolder.addParameter(parameter); |
| 228 parameterName.element = parameter; | 248 parameterName.element = parameter; |
| 229 node.parameter.accept(this); | 249 node.parameter.accept(this); |
| 250 holder.validate(); |
| 230 return null; | 251 return null; |
| 231 } | 252 } |
| 232 Object visitFieldDeclaration(FieldDeclaration node) { | 253 Object visitFieldDeclaration(FieldDeclaration node) { |
| 233 bool wasInField = _inFieldContext; | 254 bool wasInField = _inFieldContext; |
| 234 _inFieldContext = true; | 255 _inFieldContext = true; |
| 235 try { | 256 try { |
| 236 node.visitChildren(this); | 257 node.visitChildren(this); |
| 237 } finally { | 258 } finally { |
| 238 _inFieldContext = wasInField; | 259 _inFieldContext = wasInField; |
| 239 } | 260 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 263 _inFunction = wasInFunction; | 284 _inFunction = wasInFunction; |
| 264 } | 285 } |
| 265 sc.Token property = node.propertyKeyword; | 286 sc.Token property = node.propertyKeyword; |
| 266 if (property == null) { | 287 if (property == null) { |
| 267 SimpleIdentifier functionName = node.name; | 288 SimpleIdentifier functionName = node.name; |
| 268 FunctionElementImpl element = new FunctionElementImpl.con1(functionName)
; | 289 FunctionElementImpl element = new FunctionElementImpl.con1(functionName)
; |
| 269 element.functions = holder.functions; | 290 element.functions = holder.functions; |
| 270 element.labels = holder.labels; | 291 element.labels = holder.labels; |
| 271 element.localVariables = holder.localVariables; | 292 element.localVariables = holder.localVariables; |
| 272 element.parameters = holder.parameters; | 293 element.parameters = holder.parameters; |
| 273 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); | |
| 274 element.type = type; | |
| 275 _currentHolder.addFunction(element); | 294 _currentHolder.addFunction(element); |
| 276 expression.element = element; | 295 expression.element = element; |
| 277 functionName.element = element; | 296 functionName.element = element; |
| 278 } else { | 297 } else { |
| 279 SimpleIdentifier propertyNameNode = node.name; | 298 SimpleIdentifier propertyNameNode = node.name; |
| 280 if (propertyNameNode == null) { | 299 if (propertyNameNode == null) { |
| 281 return null; | 300 return null; |
| 282 } | 301 } |
| 283 String propertyName = propertyNameNode.name; | 302 String propertyName = propertyNameNode.name; |
| 284 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldE
lementImpl; | 303 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldE
lementImpl; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 307 setter.parameters = holder.parameters; | 326 setter.parameters = holder.parameters; |
| 308 setter.variable = field; | 327 setter.variable = field; |
| 309 setter.setter = true; | 328 setter.setter = true; |
| 310 setter.static = true; | 329 setter.static = true; |
| 311 field.setter = setter; | 330 field.setter = setter; |
| 312 field.final2 = false; | 331 field.final2 = false; |
| 313 _currentHolder.addAccessor(setter); | 332 _currentHolder.addAccessor(setter); |
| 314 propertyNameNode.element = setter; | 333 propertyNameNode.element = setter; |
| 315 } | 334 } |
| 316 } | 335 } |
| 336 holder.validate(); |
| 317 } | 337 } |
| 318 return null; | 338 return null; |
| 319 } | 339 } |
| 320 Object visitFunctionExpression(FunctionExpression node) { | 340 Object visitFunctionExpression(FunctionExpression node) { |
| 321 ElementHolder holder = new ElementHolder(); | 341 ElementHolder holder = new ElementHolder(); |
| 322 bool wasInFunction = _inFunction; | 342 bool wasInFunction = _inFunction; |
| 323 _inFunction = true; | 343 _inFunction = true; |
| 324 try { | 344 try { |
| 325 visitChildren(holder, node); | 345 visitChildren(holder, node); |
| 326 } finally { | 346 } finally { |
| 327 _inFunction = wasInFunction; | 347 _inFunction = wasInFunction; |
| 328 } | 348 } |
| 329 FunctionElementImpl element = new FunctionElementImpl.con2(node.beginToken.o
ffset); | 349 FunctionElementImpl element = new FunctionElementImpl.con2(node.beginToken.o
ffset); |
| 330 element.functions = holder.functions; | 350 element.functions = holder.functions; |
| 331 element.labels = holder.labels; | 351 element.labels = holder.labels; |
| 332 element.localVariables = holder.localVariables; | 352 element.localVariables = holder.localVariables; |
| 333 element.parameters = holder.parameters; | 353 element.parameters = holder.parameters; |
| 334 if (_inFunction) { | 354 if (_inFunction) { |
| 335 Block enclosingBlock = node.getAncestor(Block); | 355 Block enclosingBlock = node.getAncestor(Block); |
| 336 if (enclosingBlock != null) { | 356 if (enclosingBlock != null) { |
| 337 int functionEnd = node.offset + node.length; | 357 int functionEnd = node.offset + node.length; |
| 338 int blockEnd = enclosingBlock.offset + enclosingBlock.length; | 358 int blockEnd = enclosingBlock.offset + enclosingBlock.length; |
| 339 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); | 359 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); |
| 340 } | 360 } |
| 341 } | 361 } |
| 342 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); | 362 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); |
| 363 if (_functionTypesToFix != null) { |
| 364 _functionTypesToFix.add(type); |
| 365 } |
| 343 element.type = type; | 366 element.type = type; |
| 344 _currentHolder.addFunction(element); | 367 _currentHolder.addFunction(element); |
| 345 node.element = element; | 368 node.element = element; |
| 369 holder.validate(); |
| 346 return null; | 370 return null; |
| 347 } | 371 } |
| 348 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 372 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 349 ElementHolder holder = new ElementHolder(); | 373 ElementHolder holder = new ElementHolder(); |
| 350 visitChildren(holder, node); | 374 visitChildren(holder, node); |
| 351 SimpleIdentifier aliasName = node.name; | 375 SimpleIdentifier aliasName = node.name; |
| 352 List<ParameterElement> parameters = holder.parameters; | 376 List<ParameterElement> parameters = holder.parameters; |
| 353 List<TypeVariableElement> typeVariables = holder.typeVariables; | 377 List<TypeVariableElement> typeVariables = holder.typeVariables; |
| 354 FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(alia
sName); | 378 FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(alia
sName); |
| 355 element.parameters = parameters; | 379 element.parameters = parameters; |
| 356 element.typeVariables = typeVariables; | 380 element.typeVariables = typeVariables; |
| 357 FunctionTypeImpl type = new FunctionTypeImpl.con2(element); | 381 FunctionTypeImpl type = new FunctionTypeImpl.con2(element); |
| 358 type.typeArguments = createTypeVariableTypes(typeVariables); | 382 type.typeArguments = createTypeVariableTypes(typeVariables); |
| 359 element.type = type; | 383 element.type = type; |
| 360 _currentHolder.addTypeAlias(element); | 384 _currentHolder.addTypeAlias(element); |
| 361 aliasName.element = element; | 385 aliasName.element = element; |
| 386 holder.validate(); |
| 362 return null; | 387 return null; |
| 363 } | 388 } |
| 364 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 389 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 365 if (node.parent is! DefaultFormalParameter) { | 390 if (node.parent is! DefaultFormalParameter) { |
| 366 SimpleIdentifier parameterName = node.identifier; | 391 SimpleIdentifier parameterName = node.identifier; |
| 367 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); | 392 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); |
| 368 parameter.parameterKind = node.kind; | 393 parameter.parameterKind = node.kind; |
| 369 _currentHolder.addParameter(parameter); | 394 _currentHolder.addParameter(parameter); |
| 370 parameterName.element = parameter; | 395 parameterName.element = parameter; |
| 371 } | 396 } |
| 372 ElementHolder holder = new ElementHolder(); | 397 ElementHolder holder = new ElementHolder(); |
| 373 visitChildren(holder, node); | 398 visitChildren(holder, node); |
| 374 ((node.element as ParameterElementImpl)).parameters = holder.parameters; | 399 ((node.element as ParameterElementImpl)).parameters = holder.parameters; |
| 400 holder.validate(); |
| 375 return null; | 401 return null; |
| 376 } | 402 } |
| 377 Object visitLabeledStatement(LabeledStatement node) { | 403 Object visitLabeledStatement(LabeledStatement node) { |
| 378 bool onSwitchStatement = node.statement is SwitchStatement; | 404 bool onSwitchStatement = node.statement is SwitchStatement; |
| 379 for (Label label in node.labels) { | 405 for (Label label in node.labels) { |
| 380 SimpleIdentifier labelName = label.label; | 406 SimpleIdentifier labelName = label.label; |
| 381 LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStateme
nt, false); | 407 LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStateme
nt, false); |
| 382 _currentHolder.addLabel(element); | 408 _currentHolder.addLabel(element); |
| 383 labelName.element = element; | 409 labelName.element = element; |
| 384 } | 410 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 setter.variable = field; | 467 setter.variable = field; |
| 442 setter.abstract = node.body is EmptyFunctionBody && !matches(node.extern
alKeyword, sc.Keyword.EXTERNAL); | 468 setter.abstract = node.body is EmptyFunctionBody && !matches(node.extern
alKeyword, sc.Keyword.EXTERNAL); |
| 443 setter.setter = true; | 469 setter.setter = true; |
| 444 setter.static = isStatic; | 470 setter.static = isStatic; |
| 445 field.setter = setter; | 471 field.setter = setter; |
| 446 field.final2 = false; | 472 field.final2 = false; |
| 447 _currentHolder.addAccessor(setter); | 473 _currentHolder.addAccessor(setter); |
| 448 propertyNameNode.element = setter; | 474 propertyNameNode.element = setter; |
| 449 } | 475 } |
| 450 } | 476 } |
| 477 holder.validate(); |
| 451 return null; | 478 return null; |
| 452 } | 479 } |
| 453 Object visitSimpleFormalParameter(SimpleFormalParameter node) { | 480 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 454 if (node.parent is! DefaultFormalParameter) { | 481 if (node.parent is! DefaultFormalParameter) { |
| 455 SimpleIdentifier parameterName = node.identifier; | 482 SimpleIdentifier parameterName = node.identifier; |
| 456 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); | 483 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); |
| 457 parameter.const3 = node.isConst(); | 484 parameter.const3 = node.isConst(); |
| 458 parameter.final2 = node.isFinal(); | 485 parameter.final2 = node.isFinal(); |
| 459 parameter.parameterKind = node.kind; | 486 parameter.parameterKind = node.kind; |
| 460 _currentHolder.addParameter(parameter); | 487 _currentHolder.addParameter(parameter); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 visit(holder, node.initializer); | 574 visit(holder, node.initializer); |
| 548 } finally { | 575 } finally { |
| 549 _inFieldContext = wasInFieldContext; | 576 _inFieldContext = wasInFieldContext; |
| 550 } | 577 } |
| 551 FunctionElementImpl initializer = new FunctionElementImpl(); | 578 FunctionElementImpl initializer = new FunctionElementImpl(); |
| 552 initializer.functions = holder.functions; | 579 initializer.functions = holder.functions; |
| 553 initializer.labels = holder.labels; | 580 initializer.labels = holder.labels; |
| 554 initializer.localVariables = holder.localVariables; | 581 initializer.localVariables = holder.localVariables; |
| 555 initializer.synthetic = true; | 582 initializer.synthetic = true; |
| 556 element.initializer = initializer; | 583 element.initializer = initializer; |
| 584 holder.validate(); |
| 557 } | 585 } |
| 558 if (element is PropertyInducingElementImpl) { | 586 if (element is PropertyInducingElementImpl) { |
| 559 PropertyInducingElementImpl variable = element as PropertyInducingElementI
mpl; | 587 PropertyInducingElementImpl variable = element as PropertyInducingElementI
mpl; |
| 560 if (_inFieldContext) { | 588 if (_inFieldContext) { |
| 561 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a
s FieldDeclaration)).keyword, sc.Keyword.STATIC); | 589 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a
s FieldDeclaration)).keyword, sc.Keyword.STATIC); |
| 562 } | 590 } |
| 563 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2(
variable); | 591 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2(
variable); |
| 564 getter.getter = true; | 592 getter.getter = true; |
| 565 getter.static = variable.isStatic(); | 593 getter.static = variable.isStatic(); |
| 566 _currentHolder.addAccessor(getter); | 594 _currentHolder.addAccessor(getter); |
| 567 variable.getter = getter; | 595 variable.getter = getter; |
| 568 if (!isFinal) { | 596 if (!isFinal) { |
| 569 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con
2(variable); | 597 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con
2(variable); |
| 570 setter.setter = true; | 598 setter.setter = true; |
| 571 setter.static = variable.isStatic(); | 599 setter.static = variable.isStatic(); |
| 572 _currentHolder.addAccessor(setter); | 600 _currentHolder.addAccessor(setter); |
| 573 variable.setter = setter; | 601 variable.setter = setter; |
| 574 } | 602 } |
| 575 } | 603 } |
| 576 return null; | 604 return null; |
| 577 } | 605 } |
| 578 | 606 |
| 579 /** | 607 /** |
| 580 * Creates the {@link ConstructorElement}s array with the single default const
ructor element. | 608 * Creates the [ConstructorElement]s array with the single default constructor
element. |
| 581 * @param interfaceType the interface type for which to create a default const
ructor | 609 * @param interfaceType the interface type for which to create a default const
ructor |
| 582 * @return the {@link ConstructorElement}s array with the single default const
ructor element | 610 * @return the [ConstructorElement]s array with the single default constructor
element |
| 583 */ | 611 */ |
| 584 List<ConstructorElement> createDefaultConstructors(InterfaceTypeImpl interface
Type) { | 612 List<ConstructorElement> createDefaultConstructors(InterfaceTypeImpl interface
Type) { |
| 585 ConstructorElementImpl constructor = new ConstructorElementImpl(null); | 613 ConstructorElementImpl constructor = new ConstructorElementImpl(null); |
| 586 constructor.synthetic = true; | 614 constructor.synthetic = true; |
| 615 constructor.returnType = interfaceType; |
| 587 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); | 616 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); |
| 588 type.returnType = interfaceType; | 617 _functionTypesToFix.add(type); |
| 589 constructor.type = type; | 618 constructor.type = type; |
| 590 return <ConstructorElement> [constructor]; | 619 return <ConstructorElement> [constructor]; |
| 591 } | 620 } |
| 621 |
| 622 /** |
| 623 * Create the types associated with the given type variables, setting the type
of each type |
| 624 * variable, and return an array of types corresponding to the given variables
. |
| 625 * @param typeVariables the type variables for which types are to be created |
| 626 * @return |
| 627 */ |
| 592 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { | 628 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { |
| 593 int typeVariableCount = typeVariables.length; | 629 int typeVariableCount = typeVariables.length; |
| 594 List<Type2> typeArguments = new List<Type2>(typeVariableCount); | 630 List<Type2> typeArguments = new List<Type2>(typeVariableCount); |
| 595 for (int i = 0; i < typeVariableCount; i++) { | 631 for (int i = 0; i < typeVariableCount; i++) { |
| 596 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; | 632 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; |
| 597 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; | 633 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; |
| 598 typeVariable.type = typeArgument; | 634 typeVariable.type = typeArgument; |
| 599 typeArguments[i] = typeArgument; | 635 typeArguments[i] = typeArgument; |
| 600 } | 636 } |
| 601 return typeArguments; | 637 return typeArguments; |
| 602 } | 638 } |
| 603 | 639 |
| 604 /** | 640 /** |
| 605 * Return the body of the function that contains the given parameter, or {@cod
e null} if no | 641 * Return the body of the function that contains the given parameter, or `null
` if no |
| 606 * function body could be found. | 642 * function body could be found. |
| 607 * @param node the parameter contained in the function whose body is to be ret
urned | 643 * @param node the parameter contained in the function whose body is to be ret
urned |
| 608 * @return the body of the function that contains the given parameter | 644 * @return the body of the function that contains the given parameter |
| 609 */ | 645 */ |
| 610 FunctionBody getFunctionBody(FormalParameter node) { | 646 FunctionBody getFunctionBody(FormalParameter node) { |
| 611 ASTNode parent = node.parent; | 647 ASTNode parent = node.parent; |
| 612 while (parent != null) { | 648 while (parent != null) { |
| 613 if (parent is FunctionExpression) { | 649 if (parent is FunctionExpression) { |
| 614 return ((parent as FunctionExpression)).body; | 650 return ((parent as FunctionExpression)).body; |
| 615 } else if (parent is MethodDeclaration) { | 651 } else if (parent is MethodDeclaration) { |
| 616 return ((parent as MethodDeclaration)).body; | 652 return ((parent as MethodDeclaration)).body; |
| 617 } | 653 } |
| 618 parent = parent.parent; | 654 parent = parent.parent; |
| 619 } | 655 } |
| 620 return null; | 656 return null; |
| 621 } | 657 } |
| 622 | 658 |
| 623 /** | 659 /** |
| 624 * Return {@code true} if the given token is a token for the given keyword. | 660 * Return `true` if the given token is a token for the given keyword. |
| 625 * @param token the token being tested | 661 * @param token the token being tested |
| 626 * @param keyword the keyword being tested for | 662 * @param keyword the keyword being tested for |
| 627 * @return {@code true} if the given token is a token for the given keyword | 663 * @return `true` if the given token is a token for the given keyword |
| 628 */ | 664 */ |
| 629 bool matches(sc.Token token, sc.Keyword keyword2) => token != null && identica
l(token.type, sc.TokenType.KEYWORD) && identical(((token as sc.KeywordToken)).ke
yword, keyword2); | 665 bool matches(sc.Token token, sc.Keyword keyword2) => token != null && identica
l(token.type, sc.TokenType.KEYWORD) && identical(((token as sc.KeywordToken)).ke
yword, keyword2); |
| 630 | 666 |
| 631 /** | 667 /** |
| 632 * Make the given holder be the current holder while visiting the given node. | 668 * Make the given holder be the current holder while visiting the given node. |
| 633 * @param holder the holder that will gather elements that are built while vis
iting the children | 669 * @param holder the holder that will gather elements that are built while vis
iting the children |
| 634 * @param node the node to be visited | 670 * @param node the node to be visited |
| 635 */ | 671 */ |
| 636 void visit(ElementHolder holder, ASTNode node) { | 672 void visit(ElementHolder holder, ASTNode node) { |
| 637 if (node != null) { | 673 if (node != null) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 656 _currentHolder = holder; | 692 _currentHolder = holder; |
| 657 try { | 693 try { |
| 658 node.visitChildren(this); | 694 node.visitChildren(this); |
| 659 } finally { | 695 } finally { |
| 660 _currentHolder = previousHolder; | 696 _currentHolder = previousHolder; |
| 661 } | 697 } |
| 662 } | 698 } |
| 663 } | 699 } |
| 664 } | 700 } |
| 665 /** | 701 /** |
| 666 * Instances of the class {@code ElementHolder} hold on to elements created whil
e traversing an AST | 702 * Instances of the class `ElementHolder` hold on to elements created while trav
ersing an AST |
| 667 * structure so that they can be accessed when creating their enclosing element. | 703 * structure so that they can be accessed when creating their enclosing element. |
| 668 * @coverage dart.engine.resolver | 704 * @coverage dart.engine.resolver |
| 669 */ | 705 */ |
| 670 class ElementHolder { | 706 class ElementHolder { |
| 671 List<PropertyAccessorElement> _accessors = new List<PropertyAccessorElement>()
; | 707 List<PropertyAccessorElement> _accessors; |
| 672 List<ConstructorElement> _constructors = new List<ConstructorElement>(); | 708 List<ConstructorElement> _constructors; |
| 673 List<FieldElement> _fields = new List<FieldElement>(); | 709 List<FieldElement> _fields; |
| 674 List<FunctionElement> _functions = new List<FunctionElement>(); | 710 List<FunctionElement> _functions; |
| 675 List<LabelElement> _labels = new List<LabelElement>(); | 711 List<LabelElement> _labels; |
| 676 List<VariableElement> _localVariables = new List<VariableElement>(); | 712 List<VariableElement> _localVariables; |
| 677 List<MethodElement> _methods = new List<MethodElement>(); | 713 List<MethodElement> _methods; |
| 678 List<FunctionTypeAliasElement> _typeAliases = new List<FunctionTypeAliasElemen
t>(); | 714 List<ParameterElement> _parameters; |
| 679 List<ParameterElement> _parameters = new List<ParameterElement>(); | 715 List<VariableElement> _topLevelVariables; |
| 680 List<VariableElement> _topLevelVariables = new List<VariableElement>(); | 716 List<ClassElement> _types; |
| 681 List<ClassElement> _types = new List<ClassElement>(); | 717 List<FunctionTypeAliasElement> _typeAliases; |
| 682 List<TypeVariableElement> _typeVariables = new List<TypeVariableElement>(); | 718 List<TypeVariableElement> _typeVariables; |
| 683 void addAccessor(PropertyAccessorElement element) { | 719 void addAccessor(PropertyAccessorElement element) { |
| 720 if (_accessors == null) { |
| 721 _accessors = new List<PropertyAccessorElement>(); |
| 722 } |
| 684 _accessors.add(element); | 723 _accessors.add(element); |
| 685 } | 724 } |
| 686 void addConstructor(ConstructorElement element) { | 725 void addConstructor(ConstructorElement element) { |
| 726 if (_constructors == null) { |
| 727 _constructors = new List<ConstructorElement>(); |
| 728 } |
| 687 _constructors.add(element); | 729 _constructors.add(element); |
| 688 } | 730 } |
| 689 void addField(FieldElement element) { | 731 void addField(FieldElement element) { |
| 732 if (_fields == null) { |
| 733 _fields = new List<FieldElement>(); |
| 734 } |
| 690 _fields.add(element); | 735 _fields.add(element); |
| 691 } | 736 } |
| 692 void addFunction(FunctionElement element) { | 737 void addFunction(FunctionElement element) { |
| 738 if (_functions == null) { |
| 739 _functions = new List<FunctionElement>(); |
| 740 } |
| 693 _functions.add(element); | 741 _functions.add(element); |
| 694 } | 742 } |
| 695 void addLabel(LabelElement element) { | 743 void addLabel(LabelElement element) { |
| 744 if (_labels == null) { |
| 745 _labels = new List<LabelElement>(); |
| 746 } |
| 696 _labels.add(element); | 747 _labels.add(element); |
| 697 } | 748 } |
| 698 void addLocalVariable(LocalVariableElement element) { | 749 void addLocalVariable(LocalVariableElement element) { |
| 750 if (_localVariables == null) { |
| 751 _localVariables = new List<VariableElement>(); |
| 752 } |
| 699 _localVariables.add(element); | 753 _localVariables.add(element); |
| 700 } | 754 } |
| 701 void addMethod(MethodElement element) { | 755 void addMethod(MethodElement element) { |
| 756 if (_methods == null) { |
| 757 _methods = new List<MethodElement>(); |
| 758 } |
| 702 _methods.add(element); | 759 _methods.add(element); |
| 703 } | 760 } |
| 704 void addParameter(ParameterElement element) { | 761 void addParameter(ParameterElement element) { |
| 762 if (_parameters == null) { |
| 763 _parameters = new List<ParameterElement>(); |
| 764 } |
| 705 _parameters.add(element); | 765 _parameters.add(element); |
| 706 } | 766 } |
| 707 void addTopLevelVariable(TopLevelVariableElement element) { | 767 void addTopLevelVariable(TopLevelVariableElement element) { |
| 768 if (_topLevelVariables == null) { |
| 769 _topLevelVariables = new List<VariableElement>(); |
| 770 } |
| 708 _topLevelVariables.add(element); | 771 _topLevelVariables.add(element); |
| 709 } | 772 } |
| 710 void addType(ClassElement element) { | 773 void addType(ClassElement element) { |
| 774 if (_types == null) { |
| 775 _types = new List<ClassElement>(); |
| 776 } |
| 711 _types.add(element); | 777 _types.add(element); |
| 712 } | 778 } |
| 713 void addTypeAlias(FunctionTypeAliasElement element) { | 779 void addTypeAlias(FunctionTypeAliasElement element) { |
| 780 if (_typeAliases == null) { |
| 781 _typeAliases = new List<FunctionTypeAliasElement>(); |
| 782 } |
| 714 _typeAliases.add(element); | 783 _typeAliases.add(element); |
| 715 } | 784 } |
| 716 void addTypeVariable(TypeVariableElement element) { | 785 void addTypeVariable(TypeVariableElement element) { |
| 786 if (_typeVariables == null) { |
| 787 _typeVariables = new List<TypeVariableElement>(); |
| 788 } |
| 717 _typeVariables.add(element); | 789 _typeVariables.add(element); |
| 718 } | 790 } |
| 719 List<PropertyAccessorElement> get accessors { | 791 List<PropertyAccessorElement> get accessors { |
| 720 if (_accessors.isEmpty) { | 792 if (_accessors == null) { |
| 721 return PropertyAccessorElementImpl.EMPTY_ARRAY; | 793 return PropertyAccessorElementImpl.EMPTY_ARRAY; |
| 722 } | 794 } |
| 723 return new List.from(_accessors); | 795 List<PropertyAccessorElement> result = new List.from(_accessors); |
| 796 _accessors = null; |
| 797 return result; |
| 724 } | 798 } |
| 725 List<ConstructorElement> get constructors { | 799 List<ConstructorElement> get constructors { |
| 726 if (_constructors.isEmpty) { | 800 if (_constructors == null) { |
| 727 return ConstructorElementImpl.EMPTY_ARRAY; | 801 return ConstructorElementImpl.EMPTY_ARRAY; |
| 728 } | 802 } |
| 729 return new List.from(_constructors); | 803 List<ConstructorElement> result = new List.from(_constructors); |
| 804 _constructors = null; |
| 805 return result; |
| 730 } | 806 } |
| 731 FieldElement getField(String fieldName) { | 807 FieldElement getField(String fieldName) { |
| 808 if (_fields == null) { |
| 809 return null; |
| 810 } |
| 732 for (FieldElement field in _fields) { | 811 for (FieldElement field in _fields) { |
| 733 if (field.name == fieldName) { | 812 if (field.name == fieldName) { |
| 734 return field; | 813 return field; |
| 735 } | 814 } |
| 736 } | 815 } |
| 737 return null; | 816 return null; |
| 738 } | 817 } |
| 739 List<FieldElement> get fields { | 818 List<FieldElement> get fields { |
| 740 if (_fields.isEmpty) { | 819 if (_fields == null) { |
| 741 return FieldElementImpl.EMPTY_ARRAY; | 820 return FieldElementImpl.EMPTY_ARRAY; |
| 742 } | 821 } |
| 743 return new List.from(_fields); | 822 List<FieldElement> result = new List.from(_fields); |
| 823 _fields = null; |
| 824 return result; |
| 744 } | 825 } |
| 745 List<FunctionElement> get functions { | 826 List<FunctionElement> get functions { |
| 746 if (_functions.isEmpty) { | 827 if (_functions == null) { |
| 747 return FunctionElementImpl.EMPTY_ARRAY; | 828 return FunctionElementImpl.EMPTY_ARRAY; |
| 748 } | 829 } |
| 749 return new List.from(_functions); | 830 List<FunctionElement> result = new List.from(_functions); |
| 831 _functions = null; |
| 832 return result; |
| 750 } | 833 } |
| 751 List<LabelElement> get labels { | 834 List<LabelElement> get labels { |
| 752 if (_labels.isEmpty) { | 835 if (_labels == null) { |
| 753 return LabelElementImpl.EMPTY_ARRAY; | 836 return LabelElementImpl.EMPTY_ARRAY; |
| 754 } | 837 } |
| 755 return new List.from(_labels); | 838 List<LabelElement> result = new List.from(_labels); |
| 839 _labels = null; |
| 840 return result; |
| 756 } | 841 } |
| 757 List<LocalVariableElement> get localVariables { | 842 List<LocalVariableElement> get localVariables { |
| 758 if (_localVariables.isEmpty) { | 843 if (_localVariables == null) { |
| 759 return LocalVariableElementImpl.EMPTY_ARRAY; | 844 return LocalVariableElementImpl.EMPTY_ARRAY; |
| 760 } | 845 } |
| 761 return new List.from(_localVariables); | 846 List<LocalVariableElement> result = new List.from(_localVariables); |
| 847 _localVariables = null; |
| 848 return result; |
| 762 } | 849 } |
| 763 List<MethodElement> get methods { | 850 List<MethodElement> get methods { |
| 764 if (_methods.isEmpty) { | 851 if (_methods == null) { |
| 765 return MethodElementImpl.EMPTY_ARRAY; | 852 return MethodElementImpl.EMPTY_ARRAY; |
| 766 } | 853 } |
| 767 return new List.from(_methods); | 854 List<MethodElement> result = new List.from(_methods); |
| 855 _methods = null; |
| 856 return result; |
| 768 } | 857 } |
| 769 List<ParameterElement> get parameters { | 858 List<ParameterElement> get parameters { |
| 770 if (_parameters.isEmpty) { | 859 if (_parameters == null) { |
| 771 return ParameterElementImpl.EMPTY_ARRAY; | 860 return ParameterElementImpl.EMPTY_ARRAY; |
| 772 } | 861 } |
| 773 return new List.from(_parameters); | 862 List<ParameterElement> result = new List.from(_parameters); |
| 863 _parameters = null; |
| 864 return result; |
| 774 } | 865 } |
| 775 List<TopLevelVariableElement> get topLevelVariables { | 866 List<TopLevelVariableElement> get topLevelVariables { |
| 776 if (_topLevelVariables.isEmpty) { | 867 if (_topLevelVariables == null) { |
| 777 return TopLevelVariableElementImpl.EMPTY_ARRAY; | 868 return TopLevelVariableElementImpl.EMPTY_ARRAY; |
| 778 } | 869 } |
| 779 return new List.from(_topLevelVariables); | 870 List<TopLevelVariableElement> result = new List.from(_topLevelVariables); |
| 871 _topLevelVariables = null; |
| 872 return result; |
| 780 } | 873 } |
| 781 List<FunctionTypeAliasElement> get typeAliases { | 874 List<FunctionTypeAliasElement> get typeAliases { |
| 782 if (_typeAliases.isEmpty) { | 875 if (_typeAliases == null) { |
| 783 return FunctionTypeAliasElementImpl.EMPTY_ARRAY; | 876 return FunctionTypeAliasElementImpl.EMPTY_ARRAY; |
| 784 } | 877 } |
| 785 return new List.from(_typeAliases); | 878 List<FunctionTypeAliasElement> result = new List.from(_typeAliases); |
| 879 _typeAliases = null; |
| 880 return result; |
| 786 } | 881 } |
| 787 List<ClassElement> get types { | 882 List<ClassElement> get types { |
| 788 if (_types.isEmpty) { | 883 if (_types == null) { |
| 789 return ClassElementImpl.EMPTY_ARRAY; | 884 return ClassElementImpl.EMPTY_ARRAY; |
| 790 } | 885 } |
| 791 return new List.from(_types); | 886 List<ClassElement> result = new List.from(_types); |
| 887 _types = null; |
| 888 return result; |
| 792 } | 889 } |
| 793 List<TypeVariableElement> get typeVariables { | 890 List<TypeVariableElement> get typeVariables { |
| 794 if (_typeVariables.isEmpty) { | 891 if (_typeVariables == null) { |
| 795 return TypeVariableElementImpl.EMPTY_ARRAY; | 892 return TypeVariableElementImpl.EMPTY_ARRAY; |
| 796 } | 893 } |
| 797 return new List.from(_typeVariables); | 894 List<TypeVariableElement> result = new List.from(_typeVariables); |
| 895 _typeVariables = null; |
| 896 return result; |
| 897 } |
| 898 void validate() { |
| 899 JavaStringBuilder builder = new JavaStringBuilder(); |
| 900 if (_accessors != null) { |
| 901 builder.append(_accessors.length); |
| 902 builder.append(" accessors"); |
| 903 } |
| 904 if (_constructors != null) { |
| 905 if (builder.length > 0) { |
| 906 builder.append("; "); |
| 907 } |
| 908 builder.append(_constructors.length); |
| 909 builder.append(" constructors"); |
| 910 } |
| 911 if (_fields != null) { |
| 912 if (builder.length > 0) { |
| 913 builder.append("; "); |
| 914 } |
| 915 builder.append(_fields.length); |
| 916 builder.append(" fields"); |
| 917 } |
| 918 if (_functions != null) { |
| 919 if (builder.length > 0) { |
| 920 builder.append("; "); |
| 921 } |
| 922 builder.append(_functions.length); |
| 923 builder.append(" functions"); |
| 924 } |
| 925 if (_labels != null) { |
| 926 if (builder.length > 0) { |
| 927 builder.append("; "); |
| 928 } |
| 929 builder.append(_labels.length); |
| 930 builder.append(" labels"); |
| 931 } |
| 932 if (_localVariables != null) { |
| 933 if (builder.length > 0) { |
| 934 builder.append("; "); |
| 935 } |
| 936 builder.append(_localVariables.length); |
| 937 builder.append(" local variables"); |
| 938 } |
| 939 if (_methods != null) { |
| 940 if (builder.length > 0) { |
| 941 builder.append("; "); |
| 942 } |
| 943 builder.append(_methods.length); |
| 944 builder.append(" methods"); |
| 945 } |
| 946 if (_parameters != null) { |
| 947 if (builder.length > 0) { |
| 948 builder.append("; "); |
| 949 } |
| 950 builder.append(_parameters.length); |
| 951 builder.append(" parameters"); |
| 952 } |
| 953 if (_topLevelVariables != null) { |
| 954 if (builder.length > 0) { |
| 955 builder.append("; "); |
| 956 } |
| 957 builder.append(_topLevelVariables.length); |
| 958 builder.append(" top-level variables"); |
| 959 } |
| 960 if (_types != null) { |
| 961 if (builder.length > 0) { |
| 962 builder.append("; "); |
| 963 } |
| 964 builder.append(_types.length); |
| 965 builder.append(" types"); |
| 966 } |
| 967 if (_typeAliases != null) { |
| 968 if (builder.length > 0) { |
| 969 builder.append("; "); |
| 970 } |
| 971 builder.append(_typeAliases.length); |
| 972 builder.append(" type aliases"); |
| 973 } |
| 974 if (_typeVariables != null) { |
| 975 if (builder.length > 0) { |
| 976 builder.append("; "); |
| 977 } |
| 978 builder.append(_typeVariables.length); |
| 979 builder.append(" type variables"); |
| 980 } |
| 981 if (builder.length > 0) { |
| 982 AnalysisEngine.instance.logger.logError("Failed to capture elements: ${bui
lder.toString()}"); |
| 983 } |
| 798 } | 984 } |
| 799 } | 985 } |
| 800 /** | 986 /** |
| 801 * Instances of the class {@code HtmlUnitBuilder} build an element model for a s
ingle HTML unit. | 987 * Instances of the class `HtmlUnitBuilder` build an element model for a single
HTML unit. |
| 802 */ | 988 */ |
| 803 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { | 989 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { |
| 804 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\""; | 990 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\""; |
| 805 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'"; | 991 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'"; |
| 806 static String _SCRIPT = "script"; | 992 static String _SCRIPT = "script"; |
| 807 static String _SRC = "src"; | 993 static String _SRC = "src"; |
| 808 static String _TYPE = "type"; | 994 static String _TYPE = "type"; |
| 809 | 995 |
| 810 /** | 996 /** |
| 811 * The analysis context in which the element model will be built. | 997 * The analysis context in which the element model will be built. |
| 812 */ | 998 */ |
| 813 InternalAnalysisContext _context; | 999 InternalAnalysisContext _context; |
| 814 | 1000 |
| 815 /** | 1001 /** |
| 816 * The error listener to which errors will be reported. | 1002 * The error listener to which errors will be reported. |
| 817 */ | 1003 */ |
| 818 RecordingErrorListener _errorListener; | 1004 RecordingErrorListener _errorListener; |
| 819 | 1005 |
| 820 /** | 1006 /** |
| 821 * The line information associated with the source for which an element is bei
ng built, or{@code null} if we are not building an element. | 1007 * The line information associated with the source for which an element is bei
ng built, or`null` if we are not building an element. |
| 822 */ | 1008 */ |
| 823 LineInfo _lineInfo; | 1009 LineInfo _lineInfo; |
| 824 | 1010 |
| 825 /** | 1011 /** |
| 826 * The HTML element being built. | 1012 * The HTML element being built. |
| 827 */ | 1013 */ |
| 828 HtmlElementImpl _htmlElement; | 1014 HtmlElementImpl _htmlElement; |
| 829 | 1015 |
| 830 /** | 1016 /** |
| 831 * The elements in the path from the HTML unit to the current tag node. | 1017 * The elements in the path from the HTML unit to the current tag node. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 } else { | 1156 } else { |
| 971 node.visitChildren(this); | 1157 node.visitChildren(this); |
| 972 } | 1158 } |
| 973 } finally { | 1159 } finally { |
| 974 _parentNodes.remove(node); | 1160 _parentNodes.remove(node); |
| 975 } | 1161 } |
| 976 return null; | 1162 return null; |
| 977 } | 1163 } |
| 978 | 1164 |
| 979 /** | 1165 /** |
| 980 * Return the first source attribute for the given tag node, or {@code null} i
f it does not exist. | 1166 * Return the first source attribute for the given tag node, or `null` if it d
oes not exist. |
| 981 * @param node the node containing attributes | 1167 * @param node the node containing attributes |
| 982 * @return the source attribute contained in the given tag | 1168 * @return the source attribute contained in the given tag |
| 983 */ | 1169 */ |
| 984 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) { | 1170 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) { |
| 985 for (ht.XmlAttributeNode attribute in node.attributes) { | 1171 for (ht.XmlAttributeNode attribute in node.attributes) { |
| 986 if (attribute.name.lexeme == _SRC) { | 1172 if (attribute.name.lexeme == _SRC) { |
| 987 return attribute; | 1173 return attribute; |
| 988 } | 1174 } |
| 989 } | 1175 } |
| 990 return null; | 1176 return null; |
| 991 } | 1177 } |
| 992 | 1178 |
| 993 /** | 1179 /** |
| 994 * Determine if the specified node is a Dart script. | 1180 * Determine if the specified node is a Dart script. |
| 995 * @param node the node to be tested (not {@code null}) | 1181 * @param node the node to be tested (not `null`) |
| 996 * @return {@code true} if the node is a Dart script | 1182 * @return `true` if the node is a Dart script |
| 997 */ | 1183 */ |
| 998 bool isScriptNode(ht.XmlTagNode node) { | 1184 bool isScriptNode(ht.XmlTagNode node) { |
| 999 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) { | 1185 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) { |
| 1000 return false; | 1186 return false; |
| 1001 } | 1187 } |
| 1002 for (ht.XmlAttributeNode attribute in node.attributes) { | 1188 for (ht.XmlAttributeNode attribute in node.attributes) { |
| 1003 if (attribute.name.lexeme == _TYPE) { | 1189 if (attribute.name.lexeme == _TYPE) { |
| 1004 ht.Token valueToken = attribute.value; | 1190 ht.Token valueToken = attribute.value; |
| 1005 if (valueToken != null) { | 1191 if (valueToken != null) { |
| 1006 String value = valueToken.lexeme; | 1192 String value = valueToken.lexeme; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1019 * @param errorCode the error code of the error to be reported | 1205 * @param errorCode the error code of the error to be reported |
| 1020 * @param offset the offset of the first character to be highlighted | 1206 * @param offset the offset of the first character to be highlighted |
| 1021 * @param length the number of characters to be highlighted | 1207 * @param length the number of characters to be highlighted |
| 1022 * @param arguments the arguments used to compose the error message | 1208 * @param arguments the arguments used to compose the error message |
| 1023 */ | 1209 */ |
| 1024 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg
uments) { | 1210 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg
uments) { |
| 1025 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l
ength, errorCode, arguments)); | 1211 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l
ength, errorCode, arguments)); |
| 1026 } | 1212 } |
| 1027 } | 1213 } |
| 1028 /** | 1214 /** |
| 1029 * Instances of the class {@code DeclarationResolver} are used to resolve declar
ations in an AST | 1215 * Instances of the class `DeclarationResolver` are used to resolve declarations
in an AST |
| 1030 * structure to already built elements. | 1216 * structure to already built elements. |
| 1031 */ | 1217 */ |
| 1032 class DeclarationResolver extends RecursiveASTVisitor<Object> { | 1218 class DeclarationResolver extends RecursiveASTVisitor<Object> { |
| 1033 | 1219 |
| 1034 /** | 1220 /** |
| 1035 * The compilation unit containing the AST nodes being visited. | 1221 * The compilation unit containing the AST nodes being visited. |
| 1036 */ | 1222 */ |
| 1037 CompilationUnitElement _enclosingUnit; | 1223 CompilationUnitElement _enclosingUnit; |
| 1038 | 1224 |
| 1039 /** | 1225 /** |
| 1040 * The function type alias containing the AST nodes being visited, or {@code n
ull} if we are not | 1226 * The function type alias containing the AST nodes being visited, or `null` i
f we are not |
| 1041 * in the scope of a function type alias. | 1227 * in the scope of a function type alias. |
| 1042 */ | 1228 */ |
| 1043 FunctionTypeAliasElement _enclosingAlias; | 1229 FunctionTypeAliasElement _enclosingAlias; |
| 1044 | 1230 |
| 1045 /** | 1231 /** |
| 1046 * The class containing the AST nodes being visited, or {@code null} if we are
not in the scope of | 1232 * The class containing the AST nodes being visited, or `null` if we are not i
n the scope of |
| 1047 * a class. | 1233 * a class. |
| 1048 */ | 1234 */ |
| 1049 ClassElement _enclosingClass; | 1235 ClassElement _enclosingClass; |
| 1050 | 1236 |
| 1051 /** | 1237 /** |
| 1052 * The method or function containing the AST nodes being visited, or {@code nu
ll} if we are not in | 1238 * The method or function containing the AST nodes being visited, or `null` if
we are not in |
| 1053 * the scope of a method or function. | 1239 * the scope of a method or function. |
| 1054 */ | 1240 */ |
| 1055 ExecutableElement _enclosingExecutable; | 1241 ExecutableElement _enclosingExecutable; |
| 1056 | 1242 |
| 1057 /** | 1243 /** |
| 1058 * The parameter containing the AST nodes being visited, or {@code null} if we
are not in the | 1244 * The parameter containing the AST nodes being visited, or `null` if we are n
ot in the |
| 1059 * scope of a parameter. | 1245 * scope of a parameter. |
| 1060 */ | 1246 */ |
| 1061 ParameterElement _enclosingParameter; | 1247 ParameterElement _enclosingParameter; |
| 1062 | 1248 |
| 1063 /** | 1249 /** |
| 1064 * Resolve the declarations within the given compilation unit to the elements
rooted at the given | 1250 * Resolve the declarations within the given compilation unit to the elements
rooted at the given |
| 1065 * element. | 1251 * element. |
| 1066 * @param unit the compilation unit to be resolved | 1252 * @param unit the compilation unit to be resolved |
| 1067 * @param element the root of the element model used to resolve the AST nodes | 1253 * @param element the root of the element model used to resolve the AST nodes |
| 1068 */ | 1254 */ |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 } else if (literal is AdjacentStrings) { | 1580 } else if (literal is AdjacentStrings) { |
| 1395 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings
) { | 1581 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings
) { |
| 1396 appendStringValue(builder, stringLiteral); | 1582 appendStringValue(builder, stringLiteral); |
| 1397 } | 1583 } |
| 1398 } else { | 1584 } else { |
| 1399 throw new IllegalArgumentException(); | 1585 throw new IllegalArgumentException(); |
| 1400 } | 1586 } |
| 1401 } | 1587 } |
| 1402 | 1588 |
| 1403 /** | 1589 /** |
| 1404 * Return the element for the part with the given source, or {@code null} if t
here is no element | 1590 * Return the element for the part with the given source, or `null` if there i
s no element |
| 1405 * for the given source. | 1591 * for the given source. |
| 1406 * @param parts the elements for the parts | 1592 * @param parts the elements for the parts |
| 1407 * @param partSource the source for the part whose element is to be returned | 1593 * @param partSource the source for the part whose element is to be returned |
| 1408 * @return the element for the part with the given source | 1594 * @return the element for the part with the given source |
| 1409 */ | 1595 */ |
| 1410 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou
rce) { | 1596 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou
rce) { |
| 1411 for (CompilationUnitElement part in parts) { | 1597 for (CompilationUnitElement part in parts) { |
| 1412 if (part.source == partSource) { | 1598 if (part.source == partSource) { |
| 1413 return part; | 1599 return part; |
| 1414 } | 1600 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 Element find4(List<Element> elements, String name, int offset) { | 1635 Element find4(List<Element> elements, String name, int offset) { |
| 1450 for (Element element in elements) { | 1636 for (Element element in elements) { |
| 1451 if (element.displayName == name && element.nameOffset == offset) { | 1637 if (element.displayName == name && element.nameOffset == offset) { |
| 1452 return element; | 1638 return element; |
| 1453 } | 1639 } |
| 1454 } | 1640 } |
| 1455 return null; | 1641 return null; |
| 1456 } | 1642 } |
| 1457 | 1643 |
| 1458 /** | 1644 /** |
| 1459 * Return the export element from the given array whose library has the given
source, or{@code null} if there is no such export. | 1645 * Return the export element from the given array whose library has the given
source, or`null` if there is no such export. |
| 1460 * @param exports the export elements being searched | 1646 * @param exports the export elements being searched |
| 1461 * @param source the source of the library associated with the export element
to being searched | 1647 * @param source the source of the library associated with the export element
to being searched |
| 1462 * for | 1648 * for |
| 1463 * @return the export element whose library has the given source | 1649 * @return the export element whose library has the given source |
| 1464 */ | 1650 */ |
| 1465 ExportElement find5(List<ExportElement> exports, Source source2) { | 1651 ExportElement find5(List<ExportElement> exports, Source source2) { |
| 1466 for (ExportElement export in exports) { | 1652 for (ExportElement export in exports) { |
| 1467 if (export.exportedLibrary.source == source2) { | 1653 if (export.exportedLibrary.source == source2) { |
| 1468 return export; | 1654 return export; |
| 1469 } | 1655 } |
| 1470 } | 1656 } |
| 1471 return null; | 1657 return null; |
| 1472 } | 1658 } |
| 1473 | 1659 |
| 1474 /** | 1660 /** |
| 1475 * Return the import element from the given array whose library has the given
source and that has | 1661 * Return the import element from the given array whose library has the given
source and that has |
| 1476 * the given prefix, or {@code null} if there is no such import. | 1662 * the given prefix, or `null` if there is no such import. |
| 1477 * @param imports the import elements being searched | 1663 * @param imports the import elements being searched |
| 1478 * @param source the source of the library associated with the import element
to being searched | 1664 * @param source the source of the library associated with the import element
to being searched |
| 1479 * for | 1665 * for |
| 1480 * @param prefix the prefix with which the library was imported | 1666 * @param prefix the prefix with which the library was imported |
| 1481 * @return the import element whose library has the given source and prefix | 1667 * @return the import element whose library has the given source and prefix |
| 1482 */ | 1668 */ |
| 1483 ImportElement find6(List<ImportElement> imports, Source source2, SimpleIdentif
ier prefix2) { | 1669 ImportElement find6(List<ImportElement> imports, Source source2, SimpleIdentif
ier prefix2) { |
| 1484 for (ImportElement element in imports) { | 1670 for (ImportElement element in imports) { |
| 1485 if (element.importedLibrary.source == source2) { | 1671 if (element.importedLibrary.source == source2) { |
| 1486 PrefixElement prefixElement = element.prefix; | 1672 PrefixElement prefixElement = element.prefix; |
| 1487 if (prefix2 == null) { | 1673 if (prefix2 == null) { |
| 1488 if (prefixElement == null) { | 1674 if (prefixElement == null) { |
| 1489 return element; | 1675 return element; |
| 1490 } | 1676 } |
| 1491 } else { | 1677 } else { |
| 1492 if (prefixElement != null && prefix2.name == prefixElement.displayName
) { | 1678 if (prefixElement != null && prefix2.name == prefixElement.displayName
) { |
| 1493 return element; | 1679 return element; |
| 1494 } | 1680 } |
| 1495 } | 1681 } |
| 1496 } | 1682 } |
| 1497 } | 1683 } |
| 1498 return null; | 1684 return null; |
| 1499 } | 1685 } |
| 1500 | 1686 |
| 1501 /** | 1687 /** |
| 1502 * Return the value of the given string literal, or {@code null} if the string
is not a constant | 1688 * Return the value of the given string literal, or `null` if the string is no
t a constant |
| 1503 * string without any string interpolation. | 1689 * string without any string interpolation. |
| 1504 * @param literal the string literal whose value is to be returned | 1690 * @param literal the string literal whose value is to be returned |
| 1505 * @return the value of the given string literal | 1691 * @return the value of the given string literal |
| 1506 */ | 1692 */ |
| 1507 String getStringValue(StringLiteral literal) { | 1693 String getStringValue(StringLiteral literal) { |
| 1508 if (literal is StringInterpolation) { | 1694 if (literal is StringInterpolation) { |
| 1509 return null; | 1695 return null; |
| 1510 } | 1696 } |
| 1511 JavaStringBuilder builder = new JavaStringBuilder(); | 1697 JavaStringBuilder builder = new JavaStringBuilder(); |
| 1512 try { | 1698 try { |
| 1513 appendStringValue(builder, literal); | 1699 appendStringValue(builder, literal); |
| 1514 } on IllegalArgumentException catch (exception) { | 1700 } on IllegalArgumentException catch (exception) { |
| 1515 return null; | 1701 return null; |
| 1516 } | 1702 } |
| 1517 return builder.toString().trim(); | 1703 return builder.toString().trim(); |
| 1518 } | 1704 } |
| 1519 } | 1705 } |
| 1520 /** | 1706 /** |
| 1521 * Instances of the class {@code ElementResolver} are used by instances of {@lin
k ResolverVisitor}to resolve references within the AST structure to the elements
being referenced. The requirements | 1707 * Instances of the class `ElementResolver` are used by instances of [ResolverVi
sitor]to resolve references within the AST structure to the elements being refer
enced. The requirements |
| 1522 * for the element resolver are: | 1708 * for the element resolver are: |
| 1523 * <ol> | 1709 * <ol> |
| 1524 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which
it refers. | 1710 * * Every [SimpleIdentifier] should be resolved to the element to which it refe
rs. |
| 1525 * Specifically: | 1711 * Specifically: |
| 1526 * <ul> | 1712 * |
| 1527 * <li>An identifier within the declaration of that name should resolve to the e
lement being | 1713 * * An identifier within the declaration of that name should resolve to the ele
ment being |
| 1528 * declared.</li> | 1714 * declared. |
| 1529 * <li>An identifier denoting a prefix should resolve to the element representin
g the import that | 1715 * * An identifier denoting a prefix should resolve to the element representing
the import that |
| 1530 * defines the prefix (an {@link ImportElement}).</li> | 1716 * defines the prefix (an [ImportElement]). |
| 1531 * <li>An identifier denoting a variable should resolve to the element represent
ing the variable (a{@link VariableElement}).</li> | 1717 * * An identifier denoting a variable should resolve to the element representin
g the variable (a[VariableElement]). |
| 1532 * <li>An identifier denoting a parameter should resolve to the element represen
ting the parameter | 1718 * * An identifier denoting a parameter should resolve to the element representi
ng the parameter |
| 1533 * (a {@link ParameterElement}).</li> | 1719 * (a [ParameterElement]). |
| 1534 * <li>An identifier denoting a field should resolve to the element representing
the getter or | 1720 * * An identifier denoting a field should resolve to the element representing t
he getter or |
| 1535 * setter being invoked (a {@link PropertyAccessorElement}).</li> | 1721 * setter being invoked (a [PropertyAccessorElement]). |
| 1536 * <li>An identifier denoting the name of a method or function being invoked sho
uld resolve to the | 1722 * * An identifier denoting the name of a method or function being invoked shoul
d resolve to the |
| 1537 * element representing the method or function (a {@link ExecutableElement}).</l
i> | 1723 * element representing the method or function (a [ExecutableElement]). |
| 1538 * <li>An identifier denoting a label should resolve to the element representing
the label (a{@link LabelElement}).</li> | 1724 * * An identifier denoting a label should resolve to the element representing t
he label (a[LabelElement]). |
| 1539 * </ul> | 1725 * |
| 1540 * The identifiers within directives are exceptions to this rule and are covered
below.</li> | 1726 * The identifiers within directives are exceptions to this rule and are covered
below. |
| 1541 * <li>Every node containing a token representing an operator that can be overri
dden ({@link BinaryExpression}, {@link PrefixExpression}, {@link PostfixExpressi
on}) should resolve to | 1727 * * Every node containing a token representing an operator that can be overridd
en ([BinaryExpression], [PrefixExpression], [PostfixExpression]) should resolve
to |
| 1542 * the element representing the method invoked by that operator (a {@link Method
Element}).</li> | 1728 * the element representing the method invoked by that operator (a [MethodElemen
t]). |
| 1543 * <li>Every {@link FunctionExpressionInvocation} should resolve to the element
representing the | 1729 * * Every [FunctionExpressionInvocation] should resolve to the element represen
ting the |
| 1544 * function being invoked (a {@link FunctionElement}). This will be the same ele
ment as that to | 1730 * function being invoked (a [FunctionElement]). This will be the same element a
s that to |
| 1545 * which the name is resolved if the function has a name, but is provided for th
ose cases where an | 1731 * which the name is resolved if the function has a name, but is provided for th
ose cases where an |
| 1546 * unnamed function is being invoked.</li> | 1732 * unnamed function is being invoked. |
| 1547 * <li>Every {@link LibraryDirective} and {@link PartOfDirective} should resolve
to the element | 1733 * * Every [LibraryDirective] and [PartOfDirective] should resolve to the elemen
t |
| 1548 * representing the library being specified by the directive (a {@link LibraryEl
ement}) unless, in | 1734 * representing the library being specified by the directive (a [LibraryElement]
) unless, in |
| 1549 * the case of a part-of directive, the specified library does not exist.</li> | 1735 * the case of a part-of directive, the specified library does not exist. |
| 1550 * <li>Every {@link ImportDirective} and {@link ExportDirective} should resolve
to the element | 1736 * * Every [ImportDirective] and [ExportDirective] should resolve to the element |
| 1551 * representing the library being specified by the directive unless the specifie
d library does not | 1737 * representing the library being specified by the directive unless the specifie
d library does not |
| 1552 * exist (an {@link ImportElement} or {@link ExportElement}).</li> | 1738 * exist (an [ImportElement] or [ExportElement]). |
| 1553 * <li>The identifier representing the prefix in an {@link ImportDirective} shou
ld resolve to the | 1739 * * The identifier representing the prefix in an [ImportDirective] should resol
ve to the |
| 1554 * element representing the prefix (a {@link PrefixElement}).</li> | 1740 * element representing the prefix (a [PrefixElement]). |
| 1555 * <li>The identifiers in the hide and show combinators in {@link ImportDirectiv
e}s and{@link ExportDirective}s should resolve to the elements that are being hi
dden or shown, | 1741 * * The identifiers in the hide and show combinators in [ImportDirective]s and[
ExportDirective]s should resolve to the elements that are being hidden or shown, |
| 1556 * respectively, unless those names are not defined in the specified library (or
the specified | 1742 * respectively, unless those names are not defined in the specified library (or
the specified |
| 1557 * library does not exist).</li> | 1743 * library does not exist). |
| 1558 * <li>Every {@link PartDirective} should resolve to the element representing th
e compilation unit | 1744 * * Every [PartDirective] should resolve to the element representing the compil
ation unit |
| 1559 * being specified by the string unless the specified compilation unit does not
exist (a{@link CompilationUnitElement}).</li> | 1745 * being specified by the string unless the specified compilation unit does not
exist (a[CompilationUnitElement]). |
| 1560 * </ol> | 1746 * </ol> |
| 1561 * Note that AST nodes that would represent elements that are not defined are no
t resolved to | 1747 * Note that AST nodes that would represent elements that are not defined are no
t resolved to |
| 1562 * anything. This includes such things as references to undeclared variables (wh
ich is an error) and | 1748 * anything. This includes such things as references to undeclared variables (wh
ich is an error) and |
| 1563 * names in hide and show combinators that are not defined in the imported libra
ry (which is not an | 1749 * names in hide and show combinators that are not defined in the imported libra
ry (which is not an |
| 1564 * error). | 1750 * error). |
| 1565 * @coverage dart.engine.resolver | 1751 * @coverage dart.engine.resolver |
| 1566 */ | 1752 */ |
| 1567 class ElementResolver extends SimpleASTVisitor<Object> { | 1753 class ElementResolver extends SimpleASTVisitor<Object> { |
| 1568 | 1754 |
| 1569 /** | 1755 /** |
| 1570 * @return {@code true} if the given identifier is the return type of a constr
uctor declaration. | 1756 * @return `true` if the given identifier is the return type of a constructor
declaration. |
| 1571 */ | 1757 */ |
| 1572 static bool isConstructorReturnType(SimpleIdentifier node) { | 1758 static bool isConstructorReturnType(SimpleIdentifier node) { |
| 1573 ASTNode parent = node.parent; | 1759 ASTNode parent = node.parent; |
| 1574 if (parent is ConstructorDeclaration) { | 1760 if (parent is ConstructorDeclaration) { |
| 1575 ConstructorDeclaration constructor = parent as ConstructorDeclaration; | 1761 ConstructorDeclaration constructor = parent as ConstructorDeclaration; |
| 1576 return identical(constructor.returnType, node); | 1762 return identical(constructor.returnType, node); |
| 1577 } | 1763 } |
| 1578 return false; | 1764 return false; |
| 1579 } | 1765 } |
| 1580 | 1766 |
| 1581 /** | 1767 /** |
| 1582 * @return {@code true} if the given identifier is the return type of a factor
y constructor | 1768 * @return `true` if the given identifier is the return type of a factory cons
tructor |
| 1583 * declaration. | 1769 * declaration. |
| 1584 */ | 1770 */ |
| 1585 static bool isFactoryConstructorReturnType(SimpleIdentifier node) { | 1771 static bool isFactoryConstructorReturnType(SimpleIdentifier node) { |
| 1586 ASTNode parent = node.parent; | 1772 ASTNode parent = node.parent; |
| 1587 if (parent is ConstructorDeclaration) { | 1773 if (parent is ConstructorDeclaration) { |
| 1588 ConstructorDeclaration constructor = parent as ConstructorDeclaration; | 1774 ConstructorDeclaration constructor = parent as ConstructorDeclaration; |
| 1589 return identical(constructor.returnType, node) && constructor.factoryKeywo
rd != null; | 1775 return identical(constructor.returnType, node) && constructor.factoryKeywo
rd != null; |
| 1590 } | 1776 } |
| 1591 return false; | 1777 return false; |
| 1592 } | 1778 } |
| 1593 | 1779 |
| 1594 /** | 1780 /** |
| 1595 * Checks if the given 'super' expression is used in the valid context. | 1781 * Checks if the given 'super' expression is used in the valid context. |
| 1596 * @param node the 'super' expression to analyze | 1782 * @param node the 'super' expression to analyze |
| 1597 * @return {@code true} if the given 'super' expression is in the valid contex
t | 1783 * @return `true` if the given 'super' expression is in the valid context |
| 1598 */ | 1784 */ |
| 1599 static bool isSuperInValidContext(SuperExpression node) { | 1785 static bool isSuperInValidContext(SuperExpression node) { |
| 1600 for (ASTNode n = node; n != null; n = n.parent) { | 1786 for (ASTNode n = node; n != null; n = n.parent) { |
| 1601 if (n is CompilationUnit) { | 1787 if (n is CompilationUnit) { |
| 1602 return false; | 1788 return false; |
| 1603 } | 1789 } |
| 1604 if (n is ConstructorDeclaration) { | 1790 if (n is ConstructorDeclaration) { |
| 1605 ConstructorDeclaration constructor = n as ConstructorDeclaration; | 1791 ConstructorDeclaration constructor = n as ConstructorDeclaration; |
| 1606 return constructor.factoryKeyword == null; | 1792 return constructor.factoryKeyword == null; |
| 1607 } | 1793 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; | 1895 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; |
| 1710 Element element = resolveSimpleIdentifier(simpleIdentifier); | 1896 Element element = resolveSimpleIdentifier(simpleIdentifier); |
| 1711 if (element == null) { | 1897 if (element == null) { |
| 1712 element = findImportWithoutPrefix(simpleIdentifier); | 1898 element = findImportWithoutPrefix(simpleIdentifier); |
| 1713 if (element is MultiplyDefinedElement) { | 1899 if (element is MultiplyDefinedElement) { |
| 1714 element = null; | 1900 element = null; |
| 1715 } | 1901 } |
| 1716 } | 1902 } |
| 1717 if (element == null) { | 1903 if (element == null) { |
| 1718 } else { | 1904 } else { |
| 1719 if (element.library != _resolver.definingLibrary) { | 1905 if (element.library == null || element.library != _resolver.definingLibr
ary) { |
| 1720 } | 1906 } |
| 1721 recordResolution(simpleIdentifier, element); | 1907 recordResolution(simpleIdentifier, element); |
| 1722 if (node.newKeyword != null) { | 1908 if (node.newKeyword != null) { |
| 1723 if (element is ClassElement) { | 1909 if (element is ClassElement) { |
| 1724 ConstructorElement constructor = ((element as ClassElement)).unnamed
Constructor; | 1910 ConstructorElement constructor = ((element as ClassElement)).unnamed
Constructor; |
| 1725 if (constructor == null) { | 1911 if (constructor == null) { |
| 1726 } else { | 1912 } else { |
| 1727 recordResolution(simpleIdentifier, constructor); | 1913 recordResolution(simpleIdentifier, constructor); |
| 1728 } | 1914 } |
| 1729 } else { | 1915 } else { |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2223 for (Annotation annotationNode in annotations) { | 2409 for (Annotation annotationNode in annotations) { |
| 2224 Element resolvedElement = annotationNode.element; | 2410 Element resolvedElement = annotationNode.element; |
| 2225 if (resolvedElement != null) { | 2411 if (resolvedElement != null) { |
| 2226 annotationList.add(new ElementAnnotationImpl(resolvedElement)); | 2412 annotationList.add(new ElementAnnotationImpl(resolvedElement)); |
| 2227 } | 2413 } |
| 2228 } | 2414 } |
| 2229 } | 2415 } |
| 2230 | 2416 |
| 2231 /** | 2417 /** |
| 2232 * Given that we have found code to invoke the given element, return the error
code that should be | 2418 * Given that we have found code to invoke the given element, return the error
code that should be |
| 2233 * reported, or {@code null} if no error should be reported. | 2419 * reported, or `null` if no error should be reported. |
| 2234 * @param target the target of the invocation, or {@code null} if there was no
target | 2420 * @param target the target of the invocation, or `null` if there was no targe
t |
| 2235 * @param element the element to be invoked | 2421 * @param element the element to be invoked |
| 2236 * @return the error code that should be reported | 2422 * @return the error code that should be reported |
| 2237 */ | 2423 */ |
| 2238 ErrorCode checkForInvocationError(Expression target, Element element2) { | 2424 ErrorCode checkForInvocationError(Expression target, Element element2) { |
| 2239 if (element2 is PropertyAccessorElement) { | 2425 if (element2 is PropertyAccessorElement) { |
| 2240 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; | 2426 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; |
| 2241 if (getterType != null) { | 2427 if (getterType != null) { |
| 2242 Type2 returnType = getterType.returnType; | 2428 Type2 returnType = getterType.returnType; |
| 2243 if (!isExecutableType(returnType)) { | 2429 if (!isExecutableType(returnType)) { |
| 2244 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; | 2430 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2285 } else if (!targetType.isDynamic() && !classDeclaresNoSuchMethod2(targ
etType.element)) { | 2471 } else if (!targetType.isDynamic() && !classDeclaresNoSuchMethod2(targ
etType.element)) { |
| 2286 return StaticTypeWarningCode.UNDEFINED_METHOD; | 2472 return StaticTypeWarningCode.UNDEFINED_METHOD; |
| 2287 } | 2473 } |
| 2288 } | 2474 } |
| 2289 } | 2475 } |
| 2290 } | 2476 } |
| 2291 return null; | 2477 return null; |
| 2292 } | 2478 } |
| 2293 | 2479 |
| 2294 /** | 2480 /** |
| 2295 * Return {@code true} if the given class declares a method named "noSuchMetho
d" and is not the | 2481 * Return `true` if the given class declares a method named "noSuchMethod" and
is not the |
| 2296 * class 'Object'. | 2482 * class 'Object'. |
| 2297 * @param element the class being tested | 2483 * @param element the class being tested |
| 2298 * @return {@code true} if the given class declares a method named "noSuchMeth
od" | 2484 * @return `true` if the given class declares a method named "noSuchMethod" |
| 2299 */ | 2485 */ |
| 2300 bool classDeclaresNoSuchMethod(ClassElement classElement) { | 2486 bool classDeclaresNoSuchMethod(ClassElement classElement) { |
| 2301 if (classElement == null) { | 2487 if (classElement == null) { |
| 2302 return false; | 2488 return false; |
| 2303 } | 2489 } |
| 2304 MethodElement methodElement = classElement.lookUpMethod(_NO_SUCH_METHOD_METH
OD_NAME, _resolver.definingLibrary); | 2490 MethodElement methodElement = classElement.lookUpMethod(_NO_SUCH_METHOD_METH
OD_NAME, _resolver.definingLibrary); |
| 2305 return methodElement != null && methodElement.enclosingElement.supertype !=
null; | 2491 return methodElement != null && methodElement.enclosingElement.supertype !=
null; |
| 2306 } | 2492 } |
| 2307 | 2493 |
| 2308 /** | 2494 /** |
| 2309 * Return {@code true} if the given element represents a class that declares a
method named | 2495 * Return `true` if the given element represents a class that declares a metho
d named |
| 2310 * "noSuchMethod" and is not the class 'Object'. | 2496 * "noSuchMethod" and is not the class 'Object'. |
| 2311 * @param element the element being tested | 2497 * @param element the element being tested |
| 2312 * @return {@code true} if the given element represents a class that declares
a method named | 2498 * @return `true` if the given element represents a class that declares a meth
od named |
| 2313 * "noSuchMethod" | 2499 * "noSuchMethod" |
| 2314 */ | 2500 */ |
| 2315 bool classDeclaresNoSuchMethod2(Element element) { | 2501 bool classDeclaresNoSuchMethod2(Element element) { |
| 2316 if (element is ClassElement) { | 2502 if (element is ClassElement) { |
| 2317 return classDeclaresNoSuchMethod((element as ClassElement)); | 2503 return classDeclaresNoSuchMethod((element as ClassElement)); |
| 2318 } | 2504 } |
| 2319 return false; | 2505 return false; |
| 2320 } | 2506 } |
| 2321 | 2507 |
| 2322 /** | 2508 /** |
| 2323 * Given a list of arguments and the element that will be invoked using those
argument, compute | 2509 * Given a list of arguments and the element that will be invoked using those
argument, compute |
| 2324 * the list of parameters that correspond to the list of arguments. Return the
parameters that | 2510 * the list of parameters that correspond to the list of arguments. Return the
parameters that |
| 2325 * correspond to the arguments, or {@code null} if no correspondence could be
computed. | 2511 * correspond to the arguments, or `null` if no correspondence could be comput
ed. |
| 2326 * @param argumentList the list of arguments being passed to the element | 2512 * @param argumentList the list of arguments being passed to the element |
| 2327 * @param executableElement the element that will be invoked with the argument
s | 2513 * @param executableElement the element that will be invoked with the argument
s |
| 2328 * @return the parameters that correspond to the arguments | 2514 * @return the parameters that correspond to the arguments |
| 2329 */ | 2515 */ |
| 2330 List<ParameterElement> computePropagatedParameters(ArgumentList argumentList,
Element element2) { | 2516 List<ParameterElement> computePropagatedParameters(ArgumentList argumentList,
Element element2) { |
| 2331 if (element2 is PropertyAccessorElement) { | 2517 if (element2 is PropertyAccessorElement) { |
| 2332 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; | 2518 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; |
| 2333 if (getterType != null) { | 2519 if (getterType != null) { |
| 2334 Type2 getterReturnType = getterType.returnType; | 2520 Type2 getterReturnType = getterType.returnType; |
| 2335 if (getterReturnType is InterfaceType) { | 2521 if (getterReturnType is InterfaceType) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2372 */ | 2558 */ |
| 2373 Element convertSetterToGetter(Element element) { | 2559 Element convertSetterToGetter(Element element) { |
| 2374 if (element is PropertyAccessorElement) { | 2560 if (element is PropertyAccessorElement) { |
| 2375 return ((element as PropertyAccessorElement)).variable.getter; | 2561 return ((element as PropertyAccessorElement)).variable.getter; |
| 2376 } | 2562 } |
| 2377 return element; | 2563 return element; |
| 2378 } | 2564 } |
| 2379 | 2565 |
| 2380 /** | 2566 /** |
| 2381 * Look for any declarations of the given identifier that are imported using a
prefix. Return the | 2567 * Look for any declarations of the given identifier that are imported using a
prefix. Return the |
| 2382 * element that was found, or {@code null} if the name is not imported using a
prefix. | 2568 * element that was found, or `null` if the name is not imported using a prefi
x. |
| 2383 * @param identifier the identifier that might have been imported using a pref
ix | 2569 * @param identifier the identifier that might have been imported using a pref
ix |
| 2384 * @return the element that was found | 2570 * @return the element that was found |
| 2385 */ | 2571 */ |
| 2386 Element findImportWithoutPrefix(SimpleIdentifier identifier) { | 2572 Element findImportWithoutPrefix(SimpleIdentifier identifier) { |
| 2387 Element element = null; | 2573 Element element = null; |
| 2388 Scope nameScope = _resolver.nameScope; | 2574 Scope nameScope = _resolver.nameScope; |
| 2389 LibraryElement definingLibrary = _resolver.definingLibrary; | 2575 LibraryElement definingLibrary = _resolver.definingLibrary; |
| 2390 for (ImportElement importElement in definingLibrary.imports) { | 2576 for (ImportElement importElement in definingLibrary.imports) { |
| 2391 PrefixElement prefixElement = importElement.prefix; | 2577 PrefixElement prefixElement = importElement.prefix; |
| 2392 if (prefixElement != null) { | 2578 if (prefixElement != null) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2466 */ | 2652 */ |
| 2467 ClassElement getSuperclass(ClassElement targetClass) { | 2653 ClassElement getSuperclass(ClassElement targetClass) { |
| 2468 InterfaceType superType = targetClass.supertype; | 2654 InterfaceType superType = targetClass.supertype; |
| 2469 if (superType == null) { | 2655 if (superType == null) { |
| 2470 return null; | 2656 return null; |
| 2471 } | 2657 } |
| 2472 return superType.element; | 2658 return superType.element; |
| 2473 } | 2659 } |
| 2474 | 2660 |
| 2475 /** | 2661 /** |
| 2476 * Return {@code true} if the given type represents an object that could be in
voked using the call | 2662 * Return `true` if the given type represents an object that could be invoked
using the call |
| 2477 * operator '()'. | 2663 * operator '()'. |
| 2478 * @param type the type being tested | 2664 * @param type the type being tested |
| 2479 * @return {@code true} if the given type represents an object that could be i
nvoked | 2665 * @return `true` if the given type represents an object that could be invoked |
| 2480 */ | 2666 */ |
| 2481 bool isExecutableType(Type2 type) { | 2667 bool isExecutableType(Type2 type) { |
| 2482 if (type.isDynamic() || (type is FunctionType) || type.isDartCoreFunction())
{ | 2668 if (type.isDynamic() || (type is FunctionType) || type.isDartCoreFunction())
{ |
| 2483 return true; | 2669 return true; |
| 2484 } else if (type is InterfaceType) { | 2670 } else if (type is InterfaceType) { |
| 2485 ClassElement classElement = ((type as InterfaceType)).element; | 2671 ClassElement classElement = ((type as InterfaceType)).element; |
| 2486 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME,
_resolver.definingLibrary); | 2672 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME,
_resolver.definingLibrary); |
| 2487 return methodElement != null; | 2673 return methodElement != null; |
| 2488 } | 2674 } |
| 2489 return false; | 2675 return false; |
| 2490 } | 2676 } |
| 2491 | 2677 |
| 2492 /** | 2678 /** |
| 2493 * Return {@code true} if the given element is a static element. | 2679 * Return `true` if the given element is a static element. |
| 2494 * @param element the element being tested | 2680 * @param element the element being tested |
| 2495 * @return {@code true} if the given element is a static element | 2681 * @return `true` if the given element is a static element |
| 2496 */ | 2682 */ |
| 2497 bool isStatic(Element element) { | 2683 bool isStatic(Element element) { |
| 2498 if (element is ExecutableElement) { | 2684 if (element is ExecutableElement) { |
| 2499 return ((element as ExecutableElement)).isStatic(); | 2685 return ((element as ExecutableElement)).isStatic(); |
| 2500 } else if (element is PropertyInducingElement) { | 2686 } else if (element is PropertyInducingElement) { |
| 2501 return ((element as PropertyInducingElement)).isStatic(); | 2687 return ((element as PropertyInducingElement)).isStatic(); |
| 2502 } | 2688 } |
| 2503 return false; | 2689 return false; |
| 2504 } | 2690 } |
| 2505 | 2691 |
| 2506 /** | 2692 /** |
| 2507 * Looks up the method element with the given name for index expression, repor
ts{@link StaticWarningCode#UNDEFINED_OPERATOR} if not found. | 2693 * Looks up the method element with the given name for index expression, repor
ts[StaticWarningCode#UNDEFINED_OPERATOR] if not found. |
| 2508 * @param node the index expression to resolve | 2694 * @param node the index expression to resolve |
| 2509 * @param target the target of the expression | 2695 * @param target the target of the expression |
| 2510 * @param methodName the name of the operator associated with the context of u
sing of the given | 2696 * @param methodName the name of the operator associated with the context of u
sing of the given |
| 2511 * index expression | 2697 * index expression |
| 2512 * @return {@code true} if and only if an error code is generated on the passe
d node | 2698 * @return `true` if and only if an error code is generated on the passed node |
| 2513 */ | 2699 */ |
| 2514 bool lookUpCheckIndexOperator(IndexExpression node, Expression target, String
methodName, Type2 staticType, Type2 propagatedType) { | 2700 bool lookUpCheckIndexOperator(IndexExpression node, Expression target, String
methodName, Type2 staticType, Type2 propagatedType) { |
| 2515 MethodElement staticMethod = lookUpMethod(target, staticType, methodName); | 2701 MethodElement staticMethod = lookUpMethod(target, staticType, methodName); |
| 2516 MethodElement propagatedMethod = lookUpMethod(target, propagatedType, method
Name); | 2702 MethodElement propagatedMethod = lookUpMethod(target, propagatedType, method
Name); |
| 2517 node.staticElement = staticMethod; | 2703 node.staticElement = staticMethod; |
| 2518 node.element = select3(staticMethod, propagatedMethod); | 2704 node.element = select3(staticMethod, propagatedMethod); |
| 2519 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode || p
ropagatedType == null || shouldReportMissingMember(propagatedType, propagatedMet
hod))) { | 2705 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode || p
ropagatedType == null || shouldReportMissingMember(propagatedType, propagatedMet
hod))) { |
| 2520 sc.Token leftBracket = node.leftBracket; | 2706 sc.Token leftBracket = node.leftBracket; |
| 2521 sc.Token rightBracket = node.rightBracket; | 2707 sc.Token rightBracket = node.rightBracket; |
| 2522 if (leftBracket == null || rightBracket == null) { | 2708 if (leftBracket == null || rightBracket == null) { |
| 2523 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_OPERATOR, node, [m
ethodName, staticType.displayName]); | 2709 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_OPERATOR, node, [m
ethodName, staticType.displayName]); |
| 2524 return true; | 2710 return true; |
| 2525 } else { | 2711 } else { |
| 2526 int offset = leftBracket.offset; | 2712 int offset = leftBracket.offset; |
| 2527 int length = rightBracket.offset - offset + 1; | 2713 int length = rightBracket.offset - offset + 1; |
| 2528 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_OPERATOR, offset,
length, [methodName, staticType.displayName]); | 2714 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_OPERATOR, offset,
length, [methodName, staticType.displayName]); |
| 2529 return true; | 2715 return true; |
| 2530 } | 2716 } |
| 2531 } | 2717 } |
| 2532 return false; | 2718 return false; |
| 2533 } | 2719 } |
| 2534 | 2720 |
| 2535 /** | 2721 /** |
| 2536 * Look up the getter with the given name in the given type. Return the elemen
t representing the | 2722 * Look up the getter with the given name in the given type. Return the elemen
t representing the |
| 2537 * getter that was found, or {@code null} if there is no getter with the given
name. | 2723 * getter that was found, or `null` if there is no getter with the given name. |
| 2538 * @param target the target of the invocation, or {@code null} if there is no
target | 2724 * @param target the target of the invocation, or `null` if there is no target |
| 2539 * @param type the type in which the getter is defined | 2725 * @param type the type in which the getter is defined |
| 2540 * @param getterName the name of the getter being looked up | 2726 * @param getterName the name of the getter being looked up |
| 2541 * @return the element representing the getter that was found | 2727 * @return the element representing the getter that was found |
| 2542 */ | 2728 */ |
| 2543 PropertyAccessorElement lookUpGetter(Expression target, Type2 type, String get
terName) { | 2729 PropertyAccessorElement lookUpGetter(Expression target, Type2 type, String get
terName) { |
| 2544 type = resolveTypeVariable(type); | 2730 type = resolveTypeVariable(type); |
| 2545 if (type is InterfaceType) { | 2731 if (type is InterfaceType) { |
| 2546 InterfaceType interfaceType = type as InterfaceType; | 2732 InterfaceType interfaceType = type as InterfaceType; |
| 2547 PropertyAccessorElement accessor; | 2733 PropertyAccessorElement accessor; |
| 2548 if (target is SuperExpression) { | 2734 if (target is SuperExpression) { |
| 2549 accessor = interfaceType.lookUpGetterInSuperclass(getterName, _resolver.
definingLibrary); | 2735 accessor = interfaceType.lookUpGetterInSuperclass(getterName, _resolver.
definingLibrary); |
| 2550 } else { | 2736 } else { |
| 2551 accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibr
ary); | 2737 accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibr
ary); |
| 2552 } | 2738 } |
| 2553 if (accessor != null) { | 2739 if (accessor != null) { |
| 2554 return accessor; | 2740 return accessor; |
| 2555 } | 2741 } |
| 2556 return lookUpGetterInInterfaces(interfaceType, false, getterName, new Set<
ClassElement>()); | 2742 return lookUpGetterInInterfaces(interfaceType, false, getterName, new Set<
ClassElement>()); |
| 2557 } | 2743 } |
| 2558 return null; | 2744 return null; |
| 2559 } | 2745 } |
| 2560 | 2746 |
| 2561 /** | 2747 /** |
| 2562 * Look up the getter with the given name in the interfaces implemented by the
given type, either | 2748 * Look up the getter with the given name in the interfaces implemented by the
given type, either |
| 2563 * directly or indirectly. Return the element representing the getter that was
found, or{@code null} if there is no getter with the given name. | 2749 * directly or indirectly. Return the element representing the getter that was
found, or`null` if there is no getter with the given name. |
| 2564 * @param targetType the type in which the getter might be defined | 2750 * @param targetType the type in which the getter might be defined |
| 2565 * @param includeTargetType {@code true} if the search should include the targ
et type | 2751 * @param includeTargetType `true` if the search should include the target typ
e |
| 2566 * @param getterName the name of the getter being looked up | 2752 * @param getterName the name of the getter being looked up |
| 2567 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2753 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
| 2568 * to prevent infinite recursion and to optimize the search | 2754 * to prevent infinite recursion and to optimize the search |
| 2569 * @return the element representing the getter that was found | 2755 * @return the element representing the getter that was found |
| 2570 */ | 2756 */ |
| 2571 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, boo
l includeTargetType, String getterName, Set<ClassElement> visitedInterfaces) { | 2757 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, boo
l includeTargetType, String getterName, Set<ClassElement> visitedInterfaces) { |
| 2572 ClassElement targetClass = targetType.element; | 2758 ClassElement targetClass = targetType.element; |
| 2573 if (visitedInterfaces.contains(targetClass)) { | 2759 if (visitedInterfaces.contains(targetClass)) { |
| 2574 return null; | 2760 return null; |
| 2575 } | 2761 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2594 } | 2780 } |
| 2595 InterfaceType superclass = targetType.superclass; | 2781 InterfaceType superclass = targetType.superclass; |
| 2596 if (superclass == null) { | 2782 if (superclass == null) { |
| 2597 return null; | 2783 return null; |
| 2598 } | 2784 } |
| 2599 return lookUpGetterInInterfaces(superclass, true, getterName, visitedInterfa
ces); | 2785 return lookUpGetterInInterfaces(superclass, true, getterName, visitedInterfa
ces); |
| 2600 } | 2786 } |
| 2601 | 2787 |
| 2602 /** | 2788 /** |
| 2603 * Look up the method or getter with the given name in the given type. Return
the element | 2789 * Look up the method or getter with the given name in the given type. Return
the element |
| 2604 * representing the method or getter that was found, or {@code null} if there
is no method or | 2790 * representing the method or getter that was found, or `null` if there is no
method or |
| 2605 * getter with the given name. | 2791 * getter with the given name. |
| 2606 * @param type the type in which the method or getter is defined | 2792 * @param type the type in which the method or getter is defined |
| 2607 * @param memberName the name of the method or getter being looked up | 2793 * @param memberName the name of the method or getter being looked up |
| 2608 * @return the element representing the method or getter that was found | 2794 * @return the element representing the method or getter that was found |
| 2609 */ | 2795 */ |
| 2610 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) { | 2796 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) { |
| 2611 type = resolveTypeVariable(type); | 2797 type = resolveTypeVariable(type); |
| 2612 if (type is InterfaceType) { | 2798 if (type is InterfaceType) { |
| 2613 InterfaceType interfaceType = type as InterfaceType; | 2799 InterfaceType interfaceType = type as InterfaceType; |
| 2614 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve
r.definingLibrary); | 2800 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve
r.definingLibrary); |
| 2615 if (member != null) { | 2801 if (member != null) { |
| 2616 return member; | 2802 return member; |
| 2617 } | 2803 } |
| 2618 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary)
; | 2804 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary)
; |
| 2619 if (member != null) { | 2805 if (member != null) { |
| 2620 return member; | 2806 return member; |
| 2621 } | 2807 } |
| 2622 return lookUpGetterOrMethodInInterfaces(interfaceType, false, memberName,
new Set<ClassElement>()); | 2808 return lookUpGetterOrMethodInInterfaces(interfaceType, false, memberName,
new Set<ClassElement>()); |
| 2623 } | 2809 } |
| 2624 return null; | 2810 return null; |
| 2625 } | 2811 } |
| 2626 | 2812 |
| 2627 /** | 2813 /** |
| 2628 * Look up the method or getter with the given name in the interfaces implemen
ted by the given | 2814 * Look up the method or getter with the given name in the interfaces implemen
ted by the given |
| 2629 * type, either directly or indirectly. Return the element representing the me
thod or getter that | 2815 * type, either directly or indirectly. Return the element representing the me
thod or getter that |
| 2630 * was found, or {@code null} if there is no method or getter with the given n
ame. | 2816 * was found, or `null` if there is no method or getter with the given name. |
| 2631 * @param targetType the type in which the method or getter might be defined | 2817 * @param targetType the type in which the method or getter might be defined |
| 2632 * @param includeTargetType {@code true} if the search should include the targ
et type | 2818 * @param includeTargetType `true` if the search should include the target typ
e |
| 2633 * @param memberName the name of the method or getter being looked up | 2819 * @param memberName the name of the method or getter being looked up |
| 2634 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2820 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
| 2635 * to prevent infinite recursion and to optimize the search | 2821 * to prevent infinite recursion and to optimize the search |
| 2636 * @return the element representing the method or getter that was found | 2822 * @return the element representing the method or getter that was found |
| 2637 */ | 2823 */ |
| 2638 ExecutableElement lookUpGetterOrMethodInInterfaces(InterfaceType targetType, b
ool includeTargetType, String memberName, Set<ClassElement> visitedInterfaces) { | 2824 ExecutableElement lookUpGetterOrMethodInInterfaces(InterfaceType targetType, b
ool includeTargetType, String memberName, Set<ClassElement> visitedInterfaces) { |
| 2639 ClassElement targetClass = targetType.element; | 2825 ClassElement targetClass = targetType.element; |
| 2640 if (visitedInterfaces.contains(targetClass)) { | 2826 if (visitedInterfaces.contains(targetClass)) { |
| 2641 return null; | 2827 return null; |
| 2642 } | 2828 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2704 if (labelContainer != _resolver.enclosingFunction) { | 2890 if (labelContainer != _resolver.enclosingFunction) { |
| 2705 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo
de, [labelNode.name]); | 2891 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo
de, [labelNode.name]); |
| 2706 labelElement = null; | 2892 labelElement = null; |
| 2707 } | 2893 } |
| 2708 } | 2894 } |
| 2709 return labelElement; | 2895 return labelElement; |
| 2710 } | 2896 } |
| 2711 | 2897 |
| 2712 /** | 2898 /** |
| 2713 * Look up the method with the given name in the given type. Return the elemen
t representing the | 2899 * Look up the method with the given name in the given type. Return the elemen
t representing the |
| 2714 * method that was found, or {@code null} if there is no method with the given
name. | 2900 * method that was found, or `null` if there is no method with the given name. |
| 2715 * @param target the target of the invocation, or {@code null} if there is no
target | 2901 * @param target the target of the invocation, or `null` if there is no target |
| 2716 * @param type the type in which the method is defined | 2902 * @param type the type in which the method is defined |
| 2717 * @param methodName the name of the method being looked up | 2903 * @param methodName the name of the method being looked up |
| 2718 * @return the element representing the method that was found | 2904 * @return the element representing the method that was found |
| 2719 */ | 2905 */ |
| 2720 MethodElement lookUpMethod(Expression target, Type2 type, String methodName) { | 2906 MethodElement lookUpMethod(Expression target, Type2 type, String methodName) { |
| 2721 type = resolveTypeVariable(type); | 2907 type = resolveTypeVariable(type); |
| 2722 if (type is InterfaceType) { | 2908 if (type is InterfaceType) { |
| 2723 InterfaceType interfaceType = type as InterfaceType; | 2909 InterfaceType interfaceType = type as InterfaceType; |
| 2724 MethodElement method; | 2910 MethodElement method; |
| 2725 if (target is SuperExpression) { | 2911 if (target is SuperExpression) { |
| 2726 method = interfaceType.lookUpMethodInSuperclass(methodName, _resolver.de
finingLibrary); | 2912 method = interfaceType.lookUpMethodInSuperclass(methodName, _resolver.de
finingLibrary); |
| 2727 } else { | 2913 } else { |
| 2728 method = interfaceType.lookUpMethod(methodName, _resolver.definingLibrar
y); | 2914 method = interfaceType.lookUpMethod(methodName, _resolver.definingLibrar
y); |
| 2729 } | 2915 } |
| 2730 if (method != null) { | 2916 if (method != null) { |
| 2731 return method; | 2917 return method; |
| 2732 } | 2918 } |
| 2733 return lookUpMethodInInterfaces(interfaceType, false, methodName, new Set<
ClassElement>()); | 2919 return lookUpMethodInInterfaces(interfaceType, false, methodName, new Set<
ClassElement>()); |
| 2734 } | 2920 } |
| 2735 return null; | 2921 return null; |
| 2736 } | 2922 } |
| 2737 | 2923 |
| 2738 /** | 2924 /** |
| 2739 * Look up the method with the given name in the interfaces implemented by the
given type, either | 2925 * Look up the method with the given name in the interfaces implemented by the
given type, either |
| 2740 * directly or indirectly. Return the element representing the method that was
found, or{@code null} if there is no method with the given name. | 2926 * directly or indirectly. Return the element representing the method that was
found, or`null` if there is no method with the given name. |
| 2741 * @param targetType the type in which the member might be defined | 2927 * @param targetType the type in which the member might be defined |
| 2742 * @param includeTargetType {@code true} if the search should include the targ
et type | 2928 * @param includeTargetType `true` if the search should include the target typ
e |
| 2743 * @param methodName the name of the method being looked up | 2929 * @param methodName the name of the method being looked up |
| 2744 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2930 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
| 2745 * to prevent infinite recursion and to optimize the search | 2931 * to prevent infinite recursion and to optimize the search |
| 2746 * @return the element representing the method that was found | 2932 * @return the element representing the method that was found |
| 2747 */ | 2933 */ |
| 2748 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, bool includeT
argetType, String methodName, Set<ClassElement> visitedInterfaces) { | 2934 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, bool includeT
argetType, String methodName, Set<ClassElement> visitedInterfaces) { |
| 2749 ClassElement targetClass = targetType.element; | 2935 ClassElement targetClass = targetType.element; |
| 2750 if (visitedInterfaces.contains(targetClass)) { | 2936 if (visitedInterfaces.contains(targetClass)) { |
| 2751 return null; | 2937 return null; |
| 2752 } | 2938 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2771 } | 2957 } |
| 2772 InterfaceType superclass = targetType.superclass; | 2958 InterfaceType superclass = targetType.superclass; |
| 2773 if (superclass == null) { | 2959 if (superclass == null) { |
| 2774 return null; | 2960 return null; |
| 2775 } | 2961 } |
| 2776 return lookUpMethodInInterfaces(superclass, true, methodName, visitedInterfa
ces); | 2962 return lookUpMethodInInterfaces(superclass, true, methodName, visitedInterfa
ces); |
| 2777 } | 2963 } |
| 2778 | 2964 |
| 2779 /** | 2965 /** |
| 2780 * Look up the setter with the given name in the given type. Return the elemen
t representing the | 2966 * Look up the setter with the given name in the given type. Return the elemen
t representing the |
| 2781 * setter that was found, or {@code null} if there is no setter with the given
name. | 2967 * setter that was found, or `null` if there is no setter with the given name. |
| 2782 * @param target the target of the invocation, or {@code null} if there is no
target | 2968 * @param target the target of the invocation, or `null` if there is no target |
| 2783 * @param type the type in which the setter is defined | 2969 * @param type the type in which the setter is defined |
| 2784 * @param setterName the name of the setter being looked up | 2970 * @param setterName the name of the setter being looked up |
| 2785 * @return the element representing the setter that was found | 2971 * @return the element representing the setter that was found |
| 2786 */ | 2972 */ |
| 2787 PropertyAccessorElement lookUpSetter(Expression target, Type2 type, String set
terName) { | 2973 PropertyAccessorElement lookUpSetter(Expression target, Type2 type, String set
terName) { |
| 2788 type = resolveTypeVariable(type); | 2974 type = resolveTypeVariable(type); |
| 2789 if (type is InterfaceType) { | 2975 if (type is InterfaceType) { |
| 2790 InterfaceType interfaceType = type as InterfaceType; | 2976 InterfaceType interfaceType = type as InterfaceType; |
| 2791 PropertyAccessorElement accessor; | 2977 PropertyAccessorElement accessor; |
| 2792 if (target is SuperExpression) { | 2978 if (target is SuperExpression) { |
| 2793 accessor = interfaceType.lookUpSetterInSuperclass(setterName, _resolver.
definingLibrary); | 2979 accessor = interfaceType.lookUpSetterInSuperclass(setterName, _resolver.
definingLibrary); |
| 2794 } else { | 2980 } else { |
| 2795 accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibr
ary); | 2981 accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibr
ary); |
| 2796 } | 2982 } |
| 2797 if (accessor != null) { | 2983 if (accessor != null) { |
| 2798 return accessor; | 2984 return accessor; |
| 2799 } | 2985 } |
| 2800 return lookUpSetterInInterfaces(interfaceType, false, setterName, new Set<
ClassElement>()); | 2986 return lookUpSetterInInterfaces(interfaceType, false, setterName, new Set<
ClassElement>()); |
| 2801 } | 2987 } |
| 2802 return null; | 2988 return null; |
| 2803 } | 2989 } |
| 2804 | 2990 |
| 2805 /** | 2991 /** |
| 2806 * Look up the setter with the given name in the interfaces implemented by the
given type, either | 2992 * Look up the setter with the given name in the interfaces implemented by the
given type, either |
| 2807 * directly or indirectly. Return the element representing the setter that was
found, or{@code null} if there is no setter with the given name. | 2993 * directly or indirectly. Return the element representing the setter that was
found, or`null` if there is no setter with the given name. |
| 2808 * @param targetType the type in which the setter might be defined | 2994 * @param targetType the type in which the setter might be defined |
| 2809 * @param includeTargetType {@code true} if the search should include the targ
et type | 2995 * @param includeTargetType `true` if the search should include the target typ
e |
| 2810 * @param setterName the name of the setter being looked up | 2996 * @param setterName the name of the setter being looked up |
| 2811 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2997 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
| 2812 * to prevent infinite recursion and to optimize the search | 2998 * to prevent infinite recursion and to optimize the search |
| 2813 * @return the element representing the setter that was found | 2999 * @return the element representing the setter that was found |
| 2814 */ | 3000 */ |
| 2815 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, boo
l includeTargetType, String setterName, Set<ClassElement> visitedInterfaces) { | 3001 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, boo
l includeTargetType, String setterName, Set<ClassElement> visitedInterfaces) { |
| 2816 ClassElement targetClass = targetType.element; | 3002 ClassElement targetClass = targetType.element; |
| 2817 if (visitedInterfaces.contains(targetClass)) { | 3003 if (visitedInterfaces.contains(targetClass)) { |
| 2818 return null; | 3004 return null; |
| 2819 } | 3005 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2899 * @return the element that was associated with the node | 3085 * @return the element that was associated with the node |
| 2900 */ | 3086 */ |
| 2901 void recordResolution2(SimpleIdentifier node, Element staticElement2, Element
propagatedElement) { | 3087 void recordResolution2(SimpleIdentifier node, Element staticElement2, Element
propagatedElement) { |
| 2902 node.staticElement = staticElement2; | 3088 node.staticElement = staticElement2; |
| 2903 node.element = propagatedElement == null ? staticElement2 : propagatedElemen
t; | 3089 node.element = propagatedElement == null ? staticElement2 : propagatedElemen
t; |
| 2904 } | 3090 } |
| 2905 | 3091 |
| 2906 /** | 3092 /** |
| 2907 * Given a list of arguments and the element that will be invoked using those
argument, compute | 3093 * Given a list of arguments and the element that will be invoked using those
argument, compute |
| 2908 * the list of parameters that correspond to the list of arguments. Return the
parameters that | 3094 * the list of parameters that correspond to the list of arguments. Return the
parameters that |
| 2909 * correspond to the arguments, or {@code null} if no correspondence could be
computed. | 3095 * correspond to the arguments, or `null` if no correspondence could be comput
ed. |
| 2910 * @param reportError if {@code true} then compile-time error should be report
ed; if {@code false}then compile-time warning | 3096 * @param reportError if `true` then compile-time error should be reported; if
`false`then compile-time warning |
| 2911 * @param argumentList the list of arguments being passed to the element | 3097 * @param argumentList the list of arguments being passed to the element |
| 2912 * @param executableElement the element that will be invoked with the argument
s | 3098 * @param executableElement the element that will be invoked with the argument
s |
| 2913 * @return the parameters that correspond to the arguments | 3099 * @return the parameters that correspond to the arguments |
| 2914 */ | 3100 */ |
| 2915 List<ParameterElement> resolveArgumentsToParameters(bool reportError, Argument
List argumentList, ExecutableElement executableElement) { | 3101 List<ParameterElement> resolveArgumentsToParameters(bool reportError, Argument
List argumentList, ExecutableElement executableElement) { |
| 2916 if (executableElement == null) { | 3102 if (executableElement == null) { |
| 2917 return null; | 3103 return null; |
| 2918 } | 3104 } |
| 2919 List<ParameterElement> parameters = executableElement.parameters; | 3105 List<ParameterElement> parameters = executableElement.parameters; |
| 2920 return resolveArgumentsToParameters2(reportError, argumentList, parameters); | 3106 return resolveArgumentsToParameters2(reportError, argumentList, parameters); |
| 2921 } | 3107 } |
| 2922 | 3108 |
| 2923 /** | 3109 /** |
| 2924 * Given a list of arguments and the parameters related to the element that wi
ll be invoked using | 3110 * Given a list of arguments and the parameters related to the element that wi
ll be invoked using |
| 2925 * those argument, compute the list of parameters that correspond to the list
of arguments. Return | 3111 * those argument, compute the list of parameters that correspond to the list
of arguments. Return |
| 2926 * the parameters that correspond to the arguments. | 3112 * the parameters that correspond to the arguments. |
| 2927 * @param reportError if {@code true} then compile-time error should be report
ed; if {@code false}then compile-time warning | 3113 * @param reportError if `true` then compile-time error should be reported; if
`false`then compile-time warning |
| 2928 * @param argumentList the list of arguments being passed to the element | 3114 * @param argumentList the list of arguments being passed to the element |
| 2929 * @param parameters the of the function that will be invoked with the argumen
ts | 3115 * @param parameters the of the function that will be invoked with the argumen
ts |
| 2930 * @return the parameters that correspond to the arguments | 3116 * @return the parameters that correspond to the arguments |
| 2931 */ | 3117 */ |
| 2932 List<ParameterElement> resolveArgumentsToParameters2(bool reportError2, Argume
ntList argumentList, List<ParameterElement> parameters) { | 3118 List<ParameterElement> resolveArgumentsToParameters2(bool reportError2, Argume
ntList argumentList, List<ParameterElement> parameters) { |
| 2933 List<ParameterElement> requiredParameters = new List<ParameterElement>(); | 3119 List<ParameterElement> requiredParameters = new List<ParameterElement>(); |
| 2934 List<ParameterElement> positionalParameters = new List<ParameterElement>(); | 3120 List<ParameterElement> positionalParameters = new List<ParameterElement>(); |
| 2935 Map<String, ParameterElement> namedParameters = new Map<String, ParameterEle
ment>(); | 3121 Map<String, ParameterElement> namedParameters = new Map<String, ParameterEle
ment>(); |
| 2936 for (ParameterElement parameter in parameters) { | 3122 for (ParameterElement parameter in parameters) { |
| 2937 ParameterKind kind = parameter.parameterKind; | 3123 ParameterKind kind = parameter.parameterKind; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3114 } | 3300 } |
| 3115 } else { | 3301 } else { |
| 3116 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, property
Name, [propertyName.name]); | 3302 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, property
Name, [propertyName.name]); |
| 3117 } | 3303 } |
| 3118 } | 3304 } |
| 3119 } | 3305 } |
| 3120 } | 3306 } |
| 3121 | 3307 |
| 3122 /** | 3308 /** |
| 3123 * Resolve the given simple identifier if possible. Return the element to whic
h it could be | 3309 * Resolve the given simple identifier if possible. Return the element to whic
h it could be |
| 3124 * resolved, or {@code null} if it could not be resolved. This does not record
the results of the | 3310 * resolved, or `null` if it could not be resolved. This does not record the r
esults of the |
| 3125 * resolution. | 3311 * resolution. |
| 3126 * @param node the identifier to be resolved | 3312 * @param node the identifier to be resolved |
| 3127 * @return the element to which the identifier could be resolved | 3313 * @return the element to which the identifier could be resolved |
| 3128 */ | 3314 */ |
| 3129 Element resolveSimpleIdentifier(SimpleIdentifier node) { | 3315 Element resolveSimpleIdentifier(SimpleIdentifier node) { |
| 3130 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary
); | 3316 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary
); |
| 3131 if (element is PropertyAccessorElement && node.inSetterContext()) { | 3317 if (element is PropertyAccessorElement && node.inSetterContext()) { |
| 3132 PropertyInducingElement variable = ((element as PropertyAccessorElement)).
variable; | 3318 PropertyInducingElement variable = ((element as PropertyAccessorElement)).
variable; |
| 3133 if (variable != null) { | 3319 if (variable != null) { |
| 3134 PropertyAccessorElement setter = variable.setter; | 3320 PropertyAccessorElement setter = variable.setter; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3175 return _resolver.typeProvider.objectType; | 3361 return _resolver.typeProvider.objectType; |
| 3176 } | 3362 } |
| 3177 return bound; | 3363 return bound; |
| 3178 } | 3364 } |
| 3179 return type; | 3365 return type; |
| 3180 } | 3366 } |
| 3181 | 3367 |
| 3182 /** | 3368 /** |
| 3183 * Given two possible error codes for the same piece of code, one computed usi
ng static type | 3369 * Given two possible error codes for the same piece of code, one computed usi
ng static type |
| 3184 * information and the other using propagated type information, return the err
or code that should | 3370 * information and the other using propagated type information, return the err
or code that should |
| 3185 * be reported, or {@code null} if no error should be reported. | 3371 * be reported, or `null` if no error should be reported. |
| 3186 * @param staticError the error code computed using static type information | 3372 * @param staticError the error code computed using static type information |
| 3187 * @param propagatedError the error code computed using propagated type inform
ation | 3373 * @param propagatedError the error code computed using propagated type inform
ation |
| 3188 * @return the error code that should be reported | 3374 * @return the error code that should be reported |
| 3189 */ | 3375 */ |
| 3190 ErrorCode select(ErrorCode staticError, ErrorCode propagatedError) { | 3376 ErrorCode select(ErrorCode staticError, ErrorCode propagatedError) { |
| 3191 if (staticError == null || propagatedError == null) { | 3377 if (staticError == null || propagatedError == null) { |
| 3192 return null; | 3378 return null; |
| 3193 } | 3379 } |
| 3194 return propagatedError; | 3380 return propagatedError; |
| 3195 } | 3381 } |
| 3196 | 3382 |
| 3197 /** | 3383 /** |
| 3198 * Return the propagated element if it is not {@code null}, or the static elem
ent if it is. | 3384 * Return the propagated element if it is not `null`, or the static element if
it is. |
| 3199 * @param staticElement the element computed using static type information | 3385 * @param staticElement the element computed using static type information |
| 3200 * @param propagatedElement the element computed using propagated type informa
tion | 3386 * @param propagatedElement the element computed using propagated type informa
tion |
| 3201 * @return the more specific of the two elements | 3387 * @return the more specific of the two elements |
| 3202 */ | 3388 */ |
| 3203 ExecutableElement select2(ExecutableElement staticElement, ExecutableElement p
ropagatedElement) => propagatedElement != null ? propagatedElement : staticEleme
nt; | 3389 ExecutableElement select2(ExecutableElement staticElement, ExecutableElement p
ropagatedElement) => propagatedElement != null ? propagatedElement : staticEleme
nt; |
| 3204 | 3390 |
| 3205 /** | 3391 /** |
| 3206 * Return the propagated method if it is not {@code null}, or the static metho
d if it is. | 3392 * Return the propagated method if it is not `null`, or the static method if i
t is. |
| 3207 * @param staticMethod the method computed using static type information | 3393 * @param staticMethod the method computed using static type information |
| 3208 * @param propagatedMethod the method computed using propagated type informati
on | 3394 * @param propagatedMethod the method computed using propagated type informati
on |
| 3209 * @return the more specific of the two methods | 3395 * @return the more specific of the two methods |
| 3210 */ | 3396 */ |
| 3211 MethodElement select3(MethodElement staticMethod, MethodElement propagatedMeth
od) => propagatedMethod != null ? propagatedMethod : staticMethod; | 3397 MethodElement select3(MethodElement staticMethod, MethodElement propagatedMeth
od) => propagatedMethod != null ? propagatedMethod : staticMethod; |
| 3212 | 3398 |
| 3213 /** | 3399 /** |
| 3214 * Given a node that can have annotations associated with it and the element t
o which that node | 3400 * Given a node that can have annotations associated with it and the element t
o which that node |
| 3215 * has been resolved, create the annotations in the element model representing
the annotations on | 3401 * has been resolved, create the annotations in the element model representing
the annotations on |
| 3216 * the node. | 3402 * the node. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3233 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; | 3419 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; |
| 3234 addAnnotations(annotationList, variableDeclaration.metadata); | 3420 addAnnotations(annotationList, variableDeclaration.metadata); |
| 3235 } | 3421 } |
| 3236 } | 3422 } |
| 3237 if (!annotationList.isEmpty) { | 3423 if (!annotationList.isEmpty) { |
| 3238 ((element as ElementImpl)).metadata = new List.from(annotationList); | 3424 ((element as ElementImpl)).metadata = new List.from(annotationList); |
| 3239 } | 3425 } |
| 3240 } | 3426 } |
| 3241 | 3427 |
| 3242 /** | 3428 /** |
| 3243 * Return {@code true} if we should report an error as a result of looking up
a member in the | 3429 * Return `true` if we should report an error as a result of looking up a memb
er in the |
| 3244 * given type and not finding any member. | 3430 * given type and not finding any member. |
| 3245 * @param type the type in which we attempted to perform the look-up | 3431 * @param type the type in which we attempted to perform the look-up |
| 3246 * @param member the result of the look-up | 3432 * @param member the result of the look-up |
| 3247 * @return {@code true} if we should report an error | 3433 * @return `true` if we should report an error |
| 3248 */ | 3434 */ |
| 3249 bool shouldReportMissingMember(Type2 type, ExecutableElement member) { | 3435 bool shouldReportMissingMember(Type2 type, ExecutableElement member) { |
| 3250 if (member != null || type == null || type.isDynamic()) { | 3436 if (member != null || type == null || type.isDynamic()) { |
| 3251 return false; | 3437 return false; |
| 3252 } | 3438 } |
| 3253 if (type is InterfaceType) { | 3439 if (type is InterfaceType) { |
| 3254 return !classDeclaresNoSuchMethod(((type as InterfaceType)).element); | 3440 return !classDeclaresNoSuchMethod(((type as InterfaceType)).element); |
| 3255 } | 3441 } |
| 3256 return true; | 3442 return true; |
| 3257 } | 3443 } |
| 3258 } | 3444 } |
| 3259 /** | 3445 /** |
| 3260 * Instances of the class {@code SyntheticIdentifier} implement an identifier th
at can be used to | 3446 * Instances of the class `SyntheticIdentifier` implement an identifier that can
be used to |
| 3261 * look up names in the lexical scope when there is no identifier in the AST str
ucture. There is | 3447 * look up names in the lexical scope when there is no identifier in the AST str
ucture. There is |
| 3262 * no identifier in the AST when the parser could not distinguish between a meth
od invocation and | 3448 * no identifier in the AST when the parser could not distinguish between a meth
od invocation and |
| 3263 * an invocation of a top-level function imported with a prefix. | 3449 * an invocation of a top-level function imported with a prefix. |
| 3264 */ | 3450 */ |
| 3265 class ElementResolver_SyntheticIdentifier extends Identifier { | 3451 class ElementResolver_SyntheticIdentifier extends Identifier { |
| 3266 | 3452 |
| 3267 /** | 3453 /** |
| 3268 * The name of the synthetic identifier. | 3454 * The name of the synthetic identifier. |
| 3269 */ | 3455 */ |
| 3270 String _name; | 3456 String _name; |
| 3271 | 3457 |
| 3272 /** | 3458 /** |
| 3273 * Initialize a newly created synthetic identifier to have the given name. | 3459 * Initialize a newly created synthetic identifier to have the given name. |
| 3274 * @param name the name of the synthetic identifier | 3460 * @param name the name of the synthetic identifier |
| 3275 */ | 3461 */ |
| 3276 ElementResolver_SyntheticIdentifier(String name) { | 3462 ElementResolver_SyntheticIdentifier(String name) { |
| 3277 this._name = name; | 3463 this._name = name; |
| 3278 } | 3464 } |
| 3279 accept(ASTVisitor visitor) => null; | 3465 accept(ASTVisitor visitor) => null; |
| 3280 sc.Token get beginToken => null; | 3466 sc.Token get beginToken => null; |
| 3281 Element get element => null; | 3467 Element get element => null; |
| 3282 sc.Token get endToken => null; | 3468 sc.Token get endToken => null; |
| 3283 String get name => _name; | 3469 String get name => _name; |
| 3284 Element get staticElement => null; | 3470 Element get staticElement => null; |
| 3285 void visitChildren(ASTVisitor<Object> visitor) { | 3471 void visitChildren(ASTVisitor<Object> visitor) { |
| 3286 } | 3472 } |
| 3287 } | 3473 } |
| 3288 /** | 3474 /** |
| 3289 * Instances of the class {@code InheritanceManager} manage the knowledge of whe
re class members | 3475 * Instances of the class `InheritanceManager` manage the knowledge of where cla
ss members |
| 3290 * (methods, getters & setters) are inherited from. | 3476 * (methods, getters & setters) are inherited from. |
| 3291 * @coverage dart.engine.resolver | 3477 * @coverage dart.engine.resolver |
| 3292 */ | 3478 */ |
| 3293 class InheritanceManager { | 3479 class InheritanceManager { |
| 3294 | 3480 |
| 3295 /** | 3481 /** |
| 3296 * The {@link LibraryElement} that is managed by this manager. | 3482 * The [LibraryElement] that is managed by this manager. |
| 3297 */ | 3483 */ |
| 3298 LibraryElement _library; | 3484 LibraryElement _library; |
| 3299 | 3485 |
| 3300 /** | 3486 /** |
| 3301 * This is a mapping between each {@link ClassElement} and a map between the {
@link String} member | 3487 * This is a mapping between each [ClassElement] and a map between the [String
] member |
| 3302 * names and the associated {@link ExecutableElement} in the mixin and supercl
ass chain. | 3488 * names and the associated [ExecutableElement] in the mixin and superclass ch
ain. |
| 3303 */ | 3489 */ |
| 3304 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; | 3490 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; |
| 3305 | 3491 |
| 3306 /** | 3492 /** |
| 3307 * This is a mapping between each {@link ClassElement} and a map between the {
@link String} member | 3493 * This is a mapping between each [ClassElement] and a map between the [String
] member |
| 3308 * names and the associated {@link ExecutableElement} in the interface set. | 3494 * names and the associated [ExecutableElement] in the interface set. |
| 3309 */ | 3495 */ |
| 3310 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; | 3496 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; |
| 3311 | 3497 |
| 3312 /** | 3498 /** |
| 3313 * A map between each visited {@link ClassElement} and the set of {@link Analy
sisError}s found on | 3499 * A map between each visited [ClassElement] and the set of [AnalysisError]s f
ound on |
| 3314 * the class element. | 3500 * the class element. |
| 3315 */ | 3501 */ |
| 3316 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = new Map<ClassEle
ment, Set<AnalysisError>>(); | 3502 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = new Map<ClassEle
ment, Set<AnalysisError>>(); |
| 3317 | 3503 |
| 3318 /** | 3504 /** |
| 3319 * Initialize a newly created inheritance manager. | 3505 * Initialize a newly created inheritance manager. |
| 3320 * @param library the library element context that the inheritance mappings ar
e being generated | 3506 * @param library the library element context that the inheritance mappings ar
e being generated |
| 3321 */ | 3507 */ |
| 3322 InheritanceManager(LibraryElement library) { | 3508 InheritanceManager(LibraryElement library) { |
| 3323 this._library = library; | 3509 this._library = library; |
| 3324 _classLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); | 3510 _classLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); |
| 3325 _interfaceLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); | 3511 _interfaceLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); |
| 3326 } | 3512 } |
| 3327 | 3513 |
| 3328 /** | 3514 /** |
| 3329 * Return the set of {@link AnalysisError}s found on the passed {@link ClassEl
ement}, or{@code null} if there are none. | 3515 * Return the set of [AnalysisError]s found on the passed [ClassElement], or`n
ull` if there are none. |
| 3330 * @param classElt the class element to query | 3516 * @param classElt the class element to query |
| 3331 * @return the set of {@link AnalysisError}s found on the passed {@link ClassE
lement}, or{@code null} if there are none | 3517 * @return the set of [AnalysisError]s found on the passed [ClassElement], or`
null` if there are none |
| 3332 */ | 3518 */ |
| 3333 Set<AnalysisError> getErrors(ClassElement classElt) => _errorsInClassElement[c
lassElt]; | 3519 Set<AnalysisError> getErrors(ClassElement classElt) => _errorsInClassElement[c
lassElt]; |
| 3334 | 3520 |
| 3335 /** | 3521 /** |
| 3336 * Get and return a mapping between the set of all string names of the members
inherited from the | 3522 * Get and return a mapping between the set of all string names of the members
inherited from the |
| 3337 * passed {@link ClassElement} superclass hierarchy, and the associated {@link
ExecutableElement}. | 3523 * passed [ClassElement] superclass hierarchy, and the associated [ExecutableE
lement]. |
| 3338 * @param classElt the class element to query | 3524 * @param classElt the class element to query |
| 3339 * @return a mapping between the set of all members inherited from the passed
{@link ClassElement}superclass hierarchy, and the associated {@link ExecutableEl
ement} | 3525 * @return a mapping between the set of all members inherited from the passed
[ClassElement]superclass hierarchy, and the associated [ExecutableElement] |
| 3340 */ | 3526 */ |
| 3341 Map<String, ExecutableElement> getMapOfMembersInheritedFromClasses(ClassElemen
t classElt) => computeClassChainLookupMap(classElt, new Set<ClassElement>()); | 3527 Map<String, ExecutableElement> getMapOfMembersInheritedFromClasses(ClassElemen
t classElt) => computeClassChainLookupMap(classElt, new Set<ClassElement>()); |
| 3342 | 3528 |
| 3343 /** | 3529 /** |
| 3344 * Get and return a mapping between the set of all string names of the members
inherited from the | 3530 * Get and return a mapping between the set of all string names of the members
inherited from the |
| 3345 * passed {@link ClassElement} interface hierarchy, and the associated {@link
ExecutableElement}. | 3531 * passed [ClassElement] interface hierarchy, and the associated [ExecutableEl
ement]. |
| 3346 * @param classElt the class element to query | 3532 * @param classElt the class element to query |
| 3347 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} interface hierarchy, and the associated
{@link ExecutableElement}. | 3533 * @return a mapping between the set of all string names of the members inheri
ted from the passed[ClassElement] interface hierarchy, and the associated [Execu
tableElement]. |
| 3348 */ | 3534 */ |
| 3349 Map<String, ExecutableElement> getMapOfMembersInheritedFromInterfaces(ClassEle
ment classElt) => computeInterfaceLookupMap(classElt, new Set<ClassElement>()); | 3535 Map<String, ExecutableElement> getMapOfMembersInheritedFromInterfaces(ClassEle
ment classElt) => computeInterfaceLookupMap(classElt, new Set<ClassElement>()); |
| 3350 | 3536 |
| 3351 /** | 3537 /** |
| 3352 * Given some {@link ClassElement class element} and some member name, this re
turns the{@link ExecutableElement executable element} that the class inherits fr
om the mixins, | 3538 * Given some [ClassElement class element] and some member name, this returns
the[ExecutableElement executable element] that the class inherits from the mixin
s, |
| 3353 * superclasses or interfaces, that has the member name, if no member is inher
ited {@code null} is | 3539 * superclasses or interfaces, that has the member name, if no member is inher
ited `null` is |
| 3354 * returned. | 3540 * returned. |
| 3355 * @param classElt the class element to query | 3541 * @param classElt the class element to query |
| 3356 * @param memberName the name of the executable element to find and return | 3542 * @param memberName the name of the executable element to find and return |
| 3357 * @return the inherited executable element with the member name, or {@code nu
ll} if no such | 3543 * @return the inherited executable element with the member name, or `null` if
no such |
| 3358 * member exists | 3544 * member exists |
| 3359 */ | 3545 */ |
| 3360 ExecutableElement lookupInheritance(ClassElement classElt, String memberName)
{ | 3546 ExecutableElement lookupInheritance(ClassElement classElt, String memberName)
{ |
| 3361 if (memberName == null || memberName.isEmpty) { | 3547 if (memberName == null || memberName.isEmpty) { |
| 3362 return null; | 3548 return null; |
| 3363 } | 3549 } |
| 3364 ExecutableElement executable = computeClassChainLookupMap(classElt, new Set<
ClassElement>())[memberName]; | 3550 ExecutableElement executable = computeClassChainLookupMap(classElt, new Set<
ClassElement>())[memberName]; |
| 3365 if (executable == null) { | 3551 if (executable == null) { |
| 3366 return computeInterfaceLookupMap(classElt, new Set<ClassElement>())[member
Name]; | 3552 return computeInterfaceLookupMap(classElt, new Set<ClassElement>())[member
Name]; |
| 3367 } | 3553 } |
| 3368 return executable; | 3554 return executable; |
| 3369 } | 3555 } |
| 3370 | 3556 |
| 3371 /** | 3557 /** |
| 3372 * Given some {@link ClassElement class element} and some member name, this re
turns the{@link ExecutableElement executable element} that the class either decl
ares itself, or | 3558 * Given some [ClassElement class element] and some member name, this returns
the[ExecutableElement executable element] that the class either declares itself,
or |
| 3373 * inherits, that has the member name, if no member is inherited {@code null}
is returned. | 3559 * inherits, that has the member name, if no member is inherited `null` is ret
urned. |
| 3374 * @param classElt the class element to query | 3560 * @param classElt the class element to query |
| 3375 * @param memberName the name of the executable element to find and return | 3561 * @param memberName the name of the executable element to find and return |
| 3376 * @return the inherited executable element with the member name, or {@code nu
ll} if no such | 3562 * @return the inherited executable element with the member name, or `null` if
no such |
| 3377 * member exists | 3563 * member exists |
| 3378 */ | 3564 */ |
| 3379 ExecutableElement lookupMember(ClassElement classElt, String memberName) { | 3565 ExecutableElement lookupMember(ClassElement classElt, String memberName) { |
| 3380 ExecutableElement element = lookupMemberInClass(classElt, memberName); | 3566 ExecutableElement element = lookupMemberInClass(classElt, memberName); |
| 3381 if (element != null) { | 3567 if (element != null) { |
| 3382 return element; | 3568 return element; |
| 3383 } | 3569 } |
| 3384 return lookupInheritance(classElt, memberName); | 3570 return lookupInheritance(classElt, memberName); |
| 3385 } | 3571 } |
| 3386 | 3572 |
| 3387 /** | 3573 /** |
| 3388 * Set the new library element context. | 3574 * Set the new library element context. |
| 3389 * @param library the new library element | 3575 * @param library the new library element |
| 3390 */ | 3576 */ |
| 3391 void set libraryElement(LibraryElement library2) { | 3577 void set libraryElement(LibraryElement library2) { |
| 3392 this._library = library2; | 3578 this._library = library2; |
| 3393 } | 3579 } |
| 3394 | 3580 |
| 3395 /** | 3581 /** |
| 3396 * This method takes some inherited {@link FunctionType}, and resolves all the
parameterized types | 3582 * This method takes some inherited [FunctionType], and resolves all the param
eterized types |
| 3397 * in the function type, dependent on the class in which it is being overridde
n. | 3583 * in the function type, dependent on the class in which it is being overridde
n. |
| 3398 * @param baseFunctionType the function type that is being overridden | 3584 * @param baseFunctionType the function type that is being overridden |
| 3399 * @param memberName the name of the member, this is used to lookup the inheri
tance path of the | 3585 * @param memberName the name of the member, this is used to lookup the inheri
tance path of the |
| 3400 * override | 3586 * override |
| 3401 * @param definingType the type that is overriding the member | 3587 * @param definingType the type that is overriding the member |
| 3402 * @return the passed function type with any parameterized types substituted | 3588 * @return the passed function type with any parameterized types substituted |
| 3403 */ | 3589 */ |
| 3404 FunctionType substituteTypeArgumentsInMemberFromInheritance(FunctionType baseF
unctionType, String memberName, InterfaceType definingType) { | 3590 FunctionType substituteTypeArgumentsInMemberFromInheritance(FunctionType baseF
unctionType, String memberName, InterfaceType definingType) { |
| 3405 if (baseFunctionType == null) { | 3591 if (baseFunctionType == null) { |
| 3406 return baseFunctionType; | 3592 return baseFunctionType; |
| 3407 } | 3593 } |
| 3408 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); | 3594 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); |
| 3409 computeInheritancePath(inheritancePath, definingType, memberName); | 3595 computeInheritancePath(inheritancePath, definingType, memberName); |
| 3410 if (inheritancePath == null || inheritancePath.length < 2) { | 3596 if (inheritancePath == null || inheritancePath.length < 2) { |
| 3411 return baseFunctionType; | 3597 return baseFunctionType; |
| 3412 } | 3598 } |
| 3413 FunctionType functionTypeToReturn = baseFunctionType; | 3599 FunctionType functionTypeToReturn = baseFunctionType; |
| 3414 InterfaceType lastType = inheritancePath.removeLast(); | 3600 InterfaceType lastType = inheritancePath.removeLast(); |
| 3415 while (inheritancePath.length > 0) { | 3601 while (inheritancePath.length > 0) { |
| 3416 List<Type2> paramTypes = TypeVariableTypeImpl.getTypes(lastType.element.ty
peVariables); | 3602 List<Type2> parameterTypes = lastType.element.type.typeArguments; |
| 3417 List<Type2> argTypes = lastType.typeArguments; | 3603 List<Type2> argumentTypes = lastType.typeArguments; |
| 3418 functionTypeToReturn = functionTypeToReturn.substitute2(argTypes, paramTyp
es); | 3604 functionTypeToReturn = functionTypeToReturn.substitute2(argumentTypes, par
ameterTypes); |
| 3419 lastType = inheritancePath.removeLast(); | 3605 lastType = inheritancePath.removeLast(); |
| 3420 } | 3606 } |
| 3421 return functionTypeToReturn; | 3607 return functionTypeToReturn; |
| 3422 } | 3608 } |
| 3423 | 3609 |
| 3424 /** | 3610 /** |
| 3425 * Compute and return a mapping between the set of all string names of the mem
bers inherited from | 3611 * Compute and return a mapping between the set of all string names of the mem
bers inherited from |
| 3426 * the passed {@link ClassElement} superclass hierarchy, and the associated{@l
ink ExecutableElement}. | 3612 * the passed [ClassElement] superclass hierarchy, and the associated[Executab
leElement]. |
| 3427 * @param classElt the class element to query | 3613 * @param classElt the class element to query |
| 3428 * @param visitedClasses a set of visited classes passed back into this method
when it calls | 3614 * @param visitedClasses a set of visited classes passed back into this method
when it calls |
| 3429 * itself recursively | 3615 * itself recursively |
| 3430 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} superclass hierarchy, and the associated
{@link ExecutableElement} | 3616 * @return a mapping between the set of all string names of the members inheri
ted from the passed[ClassElement] superclass hierarchy, and the associated [Exec
utableElement] |
| 3431 */ | 3617 */ |
| 3432 Map<String, ExecutableElement> computeClassChainLookupMap(ClassElement classEl
t, Set<ClassElement> visitedClasses) { | 3618 Map<String, ExecutableElement> computeClassChainLookupMap(ClassElement classEl
t, Set<ClassElement> visitedClasses) { |
| 3433 Map<String, ExecutableElement> resultMap = _classLookup[classElt]; | 3619 Map<String, ExecutableElement> resultMap = _classLookup[classElt]; |
| 3434 if (resultMap != null) { | 3620 if (resultMap != null) { |
| 3435 return resultMap; | 3621 return resultMap; |
| 3436 } else { | 3622 } else { |
| 3437 resultMap = new Map<String, ExecutableElement>(); | 3623 resultMap = new Map<String, ExecutableElement>(); |
| 3438 } | 3624 } |
| 3439 ClassElement superclassElt = null; | 3625 ClassElement superclassElt = null; |
| 3440 InterfaceType supertype = classElt.supertype; | 3626 InterfaceType supertype = classElt.supertype; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3462 } | 3648 } |
| 3463 } | 3649 } |
| 3464 _classLookup[classElt] = resultMap; | 3650 _classLookup[classElt] = resultMap; |
| 3465 return resultMap; | 3651 return resultMap; |
| 3466 } | 3652 } |
| 3467 | 3653 |
| 3468 /** | 3654 /** |
| 3469 * Compute and return the inheritance path given the context of a type and a m
ember that is | 3655 * Compute and return the inheritance path given the context of a type and a m
ember that is |
| 3470 * overridden in the inheritance path (for which the type is in the path). | 3656 * overridden in the inheritance path (for which the type is in the path). |
| 3471 * @param chain the inheritance path that is built up as this method calls its
elf recursively, | 3657 * @param chain the inheritance path that is built up as this method calls its
elf recursively, |
| 3472 * when this method is called an empty {@link LinkedList} should be provided | 3658 * when this method is called an empty [LinkedList] should be provided |
| 3473 * @param currentType the current type in the inheritance path | 3659 * @param currentType the current type in the inheritance path |
| 3474 * @param memberName the name of the member that is being looked up the inheri
tance path | 3660 * @param memberName the name of the member that is being looked up the inheri
tance path |
| 3475 */ | 3661 */ |
| 3476 void computeInheritancePath(Queue<InterfaceType> chain, InterfaceType currentT
ype, String memberName) { | 3662 void computeInheritancePath(Queue<InterfaceType> chain, InterfaceType currentT
ype, String memberName) { |
| 3477 chain.add(currentType); | 3663 chain.add(currentType); |
| 3478 ClassElement classElt = currentType.element; | 3664 ClassElement classElt = currentType.element; |
| 3479 InterfaceType supertype = classElt.supertype; | 3665 InterfaceType supertype = classElt.supertype; |
| 3480 if (supertype == null) { | 3666 if (supertype == null) { |
| 3481 return; | 3667 return; |
| 3482 } | 3668 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3506 ClassElement interfaceElement = interfaceType.element; | 3692 ClassElement interfaceElement = interfaceType.element; |
| 3507 if (interfaceElement != null && lookupMember(interfaceElement, memberName)
!= null) { | 3693 if (interfaceElement != null && lookupMember(interfaceElement, memberName)
!= null) { |
| 3508 computeInheritancePath(chain, interfaceType, memberName); | 3694 computeInheritancePath(chain, interfaceType, memberName); |
| 3509 return; | 3695 return; |
| 3510 } | 3696 } |
| 3511 } | 3697 } |
| 3512 } | 3698 } |
| 3513 | 3699 |
| 3514 /** | 3700 /** |
| 3515 * Compute and return a mapping between the set of all string names of the mem
bers inherited from | 3701 * Compute and return a mapping between the set of all string names of the mem
bers inherited from |
| 3516 * the passed {@link ClassElement} interface hierarchy, and the associated{@li
nk ExecutableElement}. | 3702 * the passed [ClassElement] interface hierarchy, and the associated[Executabl
eElement]. |
| 3517 * @param classElt the class element to query | 3703 * @param classElt the class element to query |
| 3518 * @param visitedInterfaces a set of visited classes passed back into this met
hod when it calls | 3704 * @param visitedInterfaces a set of visited classes passed back into this met
hod when it calls |
| 3519 * itself recursively | 3705 * itself recursively |
| 3520 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} interface hierarchy, and the associated
{@link ExecutableElement} | 3706 * @return a mapping between the set of all string names of the members inheri
ted from the passed[ClassElement] interface hierarchy, and the associated [Execu
tableElement] |
| 3521 */ | 3707 */ |
| 3522 Map<String, ExecutableElement> computeInterfaceLookupMap(ClassElement classElt
, Set<ClassElement> visitedInterfaces) { | 3708 Map<String, ExecutableElement> computeInterfaceLookupMap(ClassElement classElt
, Set<ClassElement> visitedInterfaces) { |
| 3523 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; | 3709 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; |
| 3524 if (resultMap != null) { | 3710 if (resultMap != null) { |
| 3525 return resultMap; | 3711 return resultMap; |
| 3526 } else { | 3712 } else { |
| 3527 resultMap = new Map<String, ExecutableElement>(); | 3713 resultMap = new Map<String, ExecutableElement>(); |
| 3528 } | 3714 } |
| 3529 InterfaceType supertype = classElt.supertype; | 3715 InterfaceType supertype = classElt.supertype; |
| 3530 ClassElement superclassElement = supertype != null ? supertype.element : nul
l; | 3716 ClassElement superclassElement = supertype != null ? supertype.element : nul
l; |
| 3531 List<InterfaceType> interfaces = classElt.interfaces; | 3717 List<InterfaceType> interfaces = classElt.interfaces; |
| 3532 if (superclassElement == null || interfaces.length == 0) { | 3718 if ((superclassElement == null || supertype.isObject()) && interfaces.length
== 0) { |
| 3533 _interfaceLookup[classElt] = resultMap; | 3719 _interfaceLookup[classElt] = resultMap; |
| 3534 return resultMap; | 3720 return resultMap; |
| 3535 } | 3721 } |
| 3536 List<Map<String, ExecutableElement>> lookupMaps = new List<Map<String, Execu
tableElement>>(); | 3722 List<Map<String, ExecutableElement>> lookupMaps = new List<Map<String, Execu
tableElement>>(); |
| 3537 if (superclassElement != null) { | 3723 if (superclassElement != null) { |
| 3538 if (!visitedInterfaces.contains(superclassElement)) { | 3724 if (!visitedInterfaces.contains(superclassElement)) { |
| 3539 try { | 3725 try { |
| 3540 javaSetAdd(visitedInterfaces, superclassElement); | 3726 javaSetAdd(visitedInterfaces, superclassElement); |
| 3541 lookupMaps.add(computeInterfaceLookupMap(superclassElement, visitedInt
erfaces)); | 3727 lookupMaps.add(computeInterfaceLookupMap(superclassElement, visitedInt
erfaces)); |
| 3542 } finally { | 3728 } finally { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3708 } | 3894 } |
| 3709 resultMap.remove(entry.getKey()); | 3895 resultMap.remove(entry.getKey()); |
| 3710 } | 3896 } |
| 3711 } | 3897 } |
| 3712 } | 3898 } |
| 3713 _interfaceLookup[classElt] = resultMap; | 3899 _interfaceLookup[classElt] = resultMap; |
| 3714 return resultMap; | 3900 return resultMap; |
| 3715 } | 3901 } |
| 3716 | 3902 |
| 3717 /** | 3903 /** |
| 3718 * Given some {@link ClassElement}, this method finds and returns the {@link E
xecutableElement} of | 3904 * Given some [ClassElement], this method finds and returns the [ExecutableEle
ment] of |
| 3719 * the passed name in the class element. Static members, members in super type
s and members not | 3905 * the passed name in the class element. Static members, members in super type
s and members not |
| 3720 * accessible from the current library are not considered. | 3906 * accessible from the current library are not considered. |
| 3721 * @param classElt the class element to query | 3907 * @param classElt the class element to query |
| 3722 * @param memberName the name of the member to lookup in the class | 3908 * @param memberName the name of the member to lookup in the class |
| 3723 * @return the found {@link ExecutableElement}, or {@code null} if no such mem
ber was found | 3909 * @return the found [ExecutableElement], or `null` if no such member was foun
d |
| 3724 */ | 3910 */ |
| 3725 ExecutableElement lookupMemberInClass(ClassElement classElt, String memberName
) { | 3911 ExecutableElement lookupMemberInClass(ClassElement classElt, String memberName
) { |
| 3726 List<MethodElement> methods = classElt.methods; | 3912 List<MethodElement> methods = classElt.methods; |
| 3727 for (MethodElement method in methods) { | 3913 for (MethodElement method in methods) { |
| 3728 if (memberName == method.name && method.isAccessibleIn(_library) && !metho
d.isStatic()) { | 3914 if (memberName == method.name && method.isAccessibleIn(_library) && !metho
d.isStatic()) { |
| 3729 return method; | 3915 return method; |
| 3730 } | 3916 } |
| 3731 } | 3917 } |
| 3732 List<PropertyAccessorElement> accessors = classElt.accessors; | 3918 List<PropertyAccessorElement> accessors = classElt.accessors; |
| 3733 for (PropertyAccessorElement accessor in accessors) { | 3919 for (PropertyAccessorElement accessor in accessors) { |
| 3734 if (memberName == accessor.name && accessor.isAccessibleIn(_library) && !a
ccessor.isStatic()) { | 3920 if (memberName == accessor.name && accessor.isAccessibleIn(_library) && !a
ccessor.isStatic()) { |
| 3735 return accessor; | 3921 return accessor; |
| 3736 } | 3922 } |
| 3737 } | 3923 } |
| 3738 return null; | 3924 return null; |
| 3739 } | 3925 } |
| 3740 | 3926 |
| 3741 /** | 3927 /** |
| 3742 * Record the passed map with the set of all members (methods, getters and set
ters) in the class | 3928 * Record the passed map with the set of all members (methods, getters and set
ters) in the class |
| 3743 * into the passed map. | 3929 * into the passed map. |
| 3744 * @param map some non-{@code null} | 3930 * @param map some non-`null` |
| 3745 * @param classElt the class element that will be recorded into the passed map | 3931 * @param classElt the class element that will be recorded into the passed map |
| 3746 */ | 3932 */ |
| 3747 void recordMapWithClassMembers(Map<String, ExecutableElement> map, ClassElemen
t classElt) { | 3933 void recordMapWithClassMembers(Map<String, ExecutableElement> map, ClassElemen
t classElt) { |
| 3748 List<MethodElement> methods = classElt.methods; | 3934 List<MethodElement> methods = classElt.methods; |
| 3749 for (MethodElement method in methods) { | 3935 for (MethodElement method in methods) { |
| 3750 if (method.isAccessibleIn(_library) && !method.isStatic()) { | 3936 if (method.isAccessibleIn(_library) && !method.isStatic()) { |
| 3751 map[method.name] = method; | 3937 map[method.name] = method; |
| 3752 } | 3938 } |
| 3753 } | 3939 } |
| 3754 List<PropertyAccessorElement> accessors = classElt.accessors; | 3940 List<PropertyAccessorElement> accessors = classElt.accessors; |
| 3755 for (PropertyAccessorElement accessor in accessors) { | 3941 for (PropertyAccessorElement accessor in accessors) { |
| 3756 if (accessor.isAccessibleIn(_library) && !accessor.isStatic()) { | 3942 if (accessor.isAccessibleIn(_library) && !accessor.isStatic()) { |
| 3757 map[accessor.name] = accessor; | 3943 map[accessor.name] = accessor; |
| 3758 } | 3944 } |
| 3759 } | 3945 } |
| 3760 } | 3946 } |
| 3761 | 3947 |
| 3762 /** | 3948 /** |
| 3763 * This method is used to report errors on when they are found computing inher
itance information. | 3949 * This method is used to report errors on when they are found computing inher
itance information. |
| 3764 * See {@link ErrorVerifier#checkForInconsistentMethodInheritance()} to see wh
ere these generated | 3950 * See [ErrorVerifier#checkForInconsistentMethodInheritance] to see where thes
e generated |
| 3765 * error codes are reported back into the analysis engine. | 3951 * error codes are reported back into the analysis engine. |
| 3766 * @param classElt the location of the source for which the exception occurred | 3952 * @param classElt the location of the source for which the exception occurred |
| 3767 * @param offset the offset of the location of the error | 3953 * @param offset the offset of the location of the error |
| 3768 * @param length the length of the location of the error | 3954 * @param length the length of the location of the error |
| 3769 * @param errorCode the error code to be associated with this error | 3955 * @param errorCode the error code to be associated with this error |
| 3770 * @param arguments the arguments used to build the error message | 3956 * @param arguments the arguments used to build the error message |
| 3771 */ | 3957 */ |
| 3772 void reportError(ClassElement classElt, int offset, int length, ErrorCode erro
rCode, List<Object> arguments) { | 3958 void reportError(ClassElement classElt, int offset, int length, ErrorCode erro
rCode, List<Object> arguments) { |
| 3773 Set<AnalysisError> errorSet = _errorsInClassElement[classElt]; | 3959 Set<AnalysisError> errorSet = _errorsInClassElement[classElt]; |
| 3774 if (errorSet == null) { | 3960 if (errorSet == null) { |
| 3775 errorSet = new Set<AnalysisError>(); | 3961 errorSet = new Set<AnalysisError>(); |
| 3776 _errorsInClassElement[classElt] = errorSet; | 3962 _errorsInClassElement[classElt] = errorSet; |
| 3777 } | 3963 } |
| 3778 javaSetAdd(errorSet, new AnalysisError.con2(classElt.source, offset, length,
errorCode, arguments)); | 3964 javaSetAdd(errorSet, new AnalysisError.con2(classElt.source, offset, length,
errorCode, arguments)); |
| 3779 } | 3965 } |
| 3780 } | 3966 } |
| 3781 /** | 3967 /** |
| 3782 * Instances of the class {@code Library} represent the data about a single libr
ary during the | 3968 * Instances of the class `Library` represent the data about a single library du
ring the |
| 3783 * resolution of some (possibly different) library. They are not intended to be
used except during | 3969 * resolution of some (possibly different) library. They are not intended to be
used except during |
| 3784 * the resolution process. | 3970 * the resolution process. |
| 3785 * @coverage dart.engine.resolver | 3971 * @coverage dart.engine.resolver |
| 3786 */ | 3972 */ |
| 3787 class Library { | 3973 class Library { |
| 3788 | 3974 |
| 3789 /** | 3975 /** |
| 3790 * The analysis context in which this library is being analyzed. | 3976 * The analysis context in which this library is being analyzed. |
| 3791 */ | 3977 */ |
| 3792 InternalAnalysisContext _analysisContext; | 3978 InternalAnalysisContext _analysisContext; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3895 | 4081 |
| 3896 /** | 4082 /** |
| 3897 * Return the AST structure associated with the defining compilation unit for
this library. | 4083 * Return the AST structure associated with the defining compilation unit for
this library. |
| 3898 * @return the AST structure associated with the defining compilation unit for
this library | 4084 * @return the AST structure associated with the defining compilation unit for
this library |
| 3899 * @throws AnalysisException if an AST structure could not be created for the
defining compilation | 4085 * @throws AnalysisException if an AST structure could not be created for the
defining compilation |
| 3900 * unit | 4086 * unit |
| 3901 */ | 4087 */ |
| 3902 CompilationUnit get definingCompilationUnit => getAST(librarySource); | 4088 CompilationUnit get definingCompilationUnit => getAST(librarySource); |
| 3903 | 4089 |
| 3904 /** | 4090 /** |
| 3905 * Return {@code true} if this library explicitly imports core. | 4091 * Return `true` if this library explicitly imports core. |
| 3906 * @return {@code true} if this library explicitly imports core | 4092 * @return `true` if this library explicitly imports core |
| 3907 */ | 4093 */ |
| 3908 bool get explicitlyImportsCore => _explicitlyImportsCore; | 4094 bool get explicitlyImportsCore => _explicitlyImportsCore; |
| 3909 | 4095 |
| 3910 /** | 4096 /** |
| 3911 * Return the library exported by the given directive. | 4097 * Return the library exported by the given directive. |
| 3912 * @param directive the directive that exports the library to be returned | 4098 * @param directive the directive that exports the library to be returned |
| 3913 * @return the library exported by the given directive | 4099 * @return the library exported by the given directive |
| 3914 */ | 4100 */ |
| 3915 Library getExport(ExportDirective directive) => _exportedLibraries[directive]; | 4101 Library getExport(ExportDirective directive) => _exportedLibraries[directive]; |
| 3916 | 4102 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3991 } | 4177 } |
| 3992 | 4178 |
| 3993 /** | 4179 /** |
| 3994 * Return the source specifying the defining compilation unit of this library. | 4180 * Return the source specifying the defining compilation unit of this library. |
| 3995 * @return the source specifying the defining compilation unit of this library | 4181 * @return the source specifying the defining compilation unit of this library |
| 3996 */ | 4182 */ |
| 3997 Source get librarySource => _librarySource; | 4183 Source get librarySource => _librarySource; |
| 3998 | 4184 |
| 3999 /** | 4185 /** |
| 4000 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 4186 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
| 4001 * library, or {@code null} if the URI is not valid. If the URI is not valid,
report the error. | 4187 * library, or `null` if the URI is not valid. If the URI is not valid, report
the error. |
| 4002 * @param directive the directive which URI should be resolved | 4188 * @param directive the directive which URI should be resolved |
| 4003 * @return the result of resolving the URI against the URI of the library | 4189 * @return the result of resolving the URI against the URI of the library |
| 4004 */ | 4190 */ |
| 4005 Source getSource(UriBasedDirective directive) { | 4191 Source getSource(UriBasedDirective directive) { |
| 4006 StringLiteral uriLiteral = directive.uri; | 4192 StringLiteral uriLiteral = directive.uri; |
| 4007 if (uriLiteral is StringInterpolation) { | 4193 if (uriLiteral is StringInterpolation) { |
| 4008 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o
ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); | 4194 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o
ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); |
| 4009 return null; | 4195 return null; |
| 4010 } | 4196 } |
| 4011 String uriContent = uriLiteral.stringValue.trim(); | 4197 String uriContent = uriLiteral.stringValue.trim(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4032 * Set the AST structure associated with the defining compilation unit for thi
s library to the | 4218 * Set the AST structure associated with the defining compilation unit for thi
s library to the |
| 4033 * given AST structure. | 4219 * given AST structure. |
| 4034 * @param unit the AST structure associated with the defining compilation unit
for this library | 4220 * @param unit the AST structure associated with the defining compilation unit
for this library |
| 4035 */ | 4221 */ |
| 4036 void set definingCompilationUnit(CompilationUnit unit) { | 4222 void set definingCompilationUnit(CompilationUnit unit) { |
| 4037 _astMap[librarySource] = unit; | 4223 _astMap[librarySource] = unit; |
| 4038 } | 4224 } |
| 4039 | 4225 |
| 4040 /** | 4226 /** |
| 4041 * Set whether this library explicitly imports core to match the given value. | 4227 * Set whether this library explicitly imports core to match the given value. |
| 4042 * @param explicitlyImportsCore {@code true} if this library explicitly import
s core | 4228 * @param explicitlyImportsCore `true` if this library explicitly imports core |
| 4043 */ | 4229 */ |
| 4044 void set explicitlyImportsCore(bool explicitlyImportsCore2) { | 4230 void set explicitlyImportsCore(bool explicitlyImportsCore2) { |
| 4045 this._explicitlyImportsCore = explicitlyImportsCore2; | 4231 this._explicitlyImportsCore = explicitlyImportsCore2; |
| 4046 } | 4232 } |
| 4047 | 4233 |
| 4048 /** | 4234 /** |
| 4049 * Set the library element representing this library to the given library elem
ent. | 4235 * Set the library element representing this library to the given library elem
ent. |
| 4050 * @param libraryElement the library element representing this library | 4236 * @param libraryElement the library element representing this library |
| 4051 */ | 4237 */ |
| 4052 void set libraryElement(LibraryElementImpl libraryElement2) { | 4238 void set libraryElement(LibraryElementImpl libraryElement2) { |
| 4053 this._libraryElement = libraryElement2; | 4239 this._libraryElement = libraryElement2; |
| 4054 if (_inheritanceManager != null) { | 4240 if (_inheritanceManager != null) { |
| 4055 _inheritanceManager.libraryElement = libraryElement2; | 4241 _inheritanceManager.libraryElement = libraryElement2; |
| 4056 } | 4242 } |
| 4057 } | 4243 } |
| 4058 String toString() => _librarySource.shortName; | 4244 String toString() => _librarySource.shortName; |
| 4059 | 4245 |
| 4060 /** | 4246 /** |
| 4061 * Return the result of resolving the given URI against the URI of the library
, or {@code null} if | 4247 * Return the result of resolving the given URI against the URI of the library
, or `null` if |
| 4062 * the URI is not valid. | 4248 * the URI is not valid. |
| 4063 * @param uri the URI to be resolved | 4249 * @param uri the URI to be resolved |
| 4064 * @return the result of resolving the given URI against the URI of the librar
y | 4250 * @return the result of resolving the given URI against the URI of the librar
y |
| 4065 */ | 4251 */ |
| 4066 Source getSource2(String uri) { | 4252 Source getSource2(String uri) { |
| 4067 if (uri == null) { | 4253 if (uri == null) { |
| 4068 return null; | 4254 return null; |
| 4069 } | 4255 } |
| 4070 return _analysisContext.sourceFactory.resolveUri(_librarySource, uri); | 4256 return _analysisContext.sourceFactory.resolveUri(_librarySource, uri); |
| 4071 } | 4257 } |
| 4072 } | 4258 } |
| 4073 /** | 4259 /** |
| 4074 * Instances of the class {@code LibraryElementBuilder} build an element model f
or a single library. | 4260 * Instances of the class `LibraryElementBuilder` build an element model for a s
ingle library. |
| 4075 * @coverage dart.engine.resolver | 4261 * @coverage dart.engine.resolver |
| 4076 */ | 4262 */ |
| 4077 class LibraryElementBuilder { | 4263 class LibraryElementBuilder { |
| 4078 | 4264 |
| 4079 /** | 4265 /** |
| 4080 * The analysis context in which the element model will be built. | 4266 * The analysis context in which the element model will be built. |
| 4081 */ | 4267 */ |
| 4082 InternalAnalysisContext _analysisContext; | 4268 InternalAnalysisContext _analysisContext; |
| 4083 | 4269 |
| 4084 /** | 4270 /** |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4183 if (!accessor.isSynthetic() && accessor.correspondingGetter == null) { | 4369 if (!accessor.isSynthetic() && accessor.correspondingGetter == null) { |
| 4184 setters.add(accessor); | 4370 setters.add(accessor); |
| 4185 } | 4371 } |
| 4186 } | 4372 } |
| 4187 } | 4373 } |
| 4188 } | 4374 } |
| 4189 | 4375 |
| 4190 /** | 4376 /** |
| 4191 * Search the top-level functions defined in the given compilation unit for th
e entry point. | 4377 * Search the top-level functions defined in the given compilation unit for th
e entry point. |
| 4192 * @param element the compilation unit to be searched | 4378 * @param element the compilation unit to be searched |
| 4193 * @return the entry point that was found, or {@code null} if the compilation
unit does not define | 4379 * @return the entry point that was found, or `null` if the compilation unit d
oes not define |
| 4194 * an entry point | 4380 * an entry point |
| 4195 */ | 4381 */ |
| 4196 FunctionElement findEntryPoint(CompilationUnitElementImpl element) { | 4382 FunctionElement findEntryPoint(CompilationUnitElementImpl element) { |
| 4197 for (FunctionElement function in element.functions) { | 4383 for (FunctionElement function in element.functions) { |
| 4198 if (function.name == _ENTRY_POINT_NAME) { | 4384 if (function.name == _ENTRY_POINT_NAME) { |
| 4199 return function; | 4385 return function; |
| 4200 } | 4386 } |
| 4201 } | 4387 } |
| 4202 return null; | 4388 return null; |
| 4203 } | 4389 } |
| 4204 | 4390 |
| 4205 /** | 4391 /** |
| 4206 * Return the name of the library that the given part is declared to be a part
of, or {@code null}if the part does not contain a part-of directive. | 4392 * Return the name of the library that the given part is declared to be a part
of, or `null`if the part does not contain a part-of directive. |
| 4207 * @param library the library containing the part | 4393 * @param library the library containing the part |
| 4208 * @param partSource the source representing the part | 4394 * @param partSource the source representing the part |
| 4209 * @param directivesToResolve a list of directives that should be resolved to
the library being | 4395 * @param directivesToResolve a list of directives that should be resolved to
the library being |
| 4210 * built | 4396 * built |
| 4211 * @return the name of the library that the given part is declared to be a par
t of | 4397 * @return the name of the library that the given part is declared to be a par
t of |
| 4212 */ | 4398 */ |
| 4213 String getPartLibraryName(Library library, Source partSource, List<Directive>
directivesToResolve) { | 4399 String getPartLibraryName(Library library, Source partSource, List<Directive>
directivesToResolve) { |
| 4214 try { | 4400 try { |
| 4215 CompilationUnit partUnit = library.getAST(partSource); | 4401 CompilationUnit partUnit = library.getAST(partSource); |
| 4216 for (Directive directive in partUnit.directives) { | 4402 for (Directive directive in partUnit.directives) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4244 PropertyAccessorElement getter = getters[setter.displayName]; | 4430 PropertyAccessorElement getter = getters[setter.displayName]; |
| 4245 if (getter != null) { | 4431 if (getter != null) { |
| 4246 PropertyInducingElementImpl variable = getter.variable as PropertyInduci
ngElementImpl; | 4432 PropertyInducingElementImpl variable = getter.variable as PropertyInduci
ngElementImpl; |
| 4247 variable.setter = setter; | 4433 variable.setter = setter; |
| 4248 ((setter as PropertyAccessorElementImpl)).variable = variable; | 4434 ((setter as PropertyAccessorElementImpl)).variable = variable; |
| 4249 } | 4435 } |
| 4250 } | 4436 } |
| 4251 } | 4437 } |
| 4252 } | 4438 } |
| 4253 /** | 4439 /** |
| 4254 * Instances of the class {@code LibraryResolver} are used to resolve one or mor
e mutually dependent | 4440 * Instances of the class `LibraryResolver` are used to resolve one or more mutu
ally dependent |
| 4255 * libraries within a single context. | 4441 * libraries within a single context. |
| 4256 * @coverage dart.engine.resolver | 4442 * @coverage dart.engine.resolver |
| 4257 */ | 4443 */ |
| 4258 class LibraryResolver { | 4444 class LibraryResolver { |
| 4259 | 4445 |
| 4260 /** | 4446 /** |
| 4261 * The analysis context in which the libraries are being analyzed. | 4447 * The analysis context in which the libraries are being analyzed. |
| 4262 */ | 4448 */ |
| 4263 InternalAnalysisContext _analysisContext; | 4449 InternalAnalysisContext _analysisContext; |
| 4264 | 4450 |
| 4265 /** | 4451 /** |
| 4266 * The listener to which analysis errors will be reported, this error listener
is either | 4452 * The listener to which analysis errors will be reported, this error listener
is either |
| 4267 * references {@link #recordingErrorListener}, or it unions the passed{@link A
nalysisErrorListener} with the {@link #recordingErrorListener}. | 4453 * references [recordingErrorListener], or it unions the passed[AnalysisErrorL
istener] with the [recordingErrorListener]. |
| 4268 */ | 4454 */ |
| 4269 RecordingErrorListener _errorListener; | 4455 RecordingErrorListener _errorListener; |
| 4270 | 4456 |
| 4271 /** | 4457 /** |
| 4272 * A source object representing the core library (dart:core). | 4458 * A source object representing the core library (dart:core). |
| 4273 */ | 4459 */ |
| 4274 Source _coreLibrarySource; | 4460 Source _coreLibrarySource; |
| 4275 | 4461 |
| 4276 /** | 4462 /** |
| 4277 * The object representing the core library. | 4463 * The object representing the core library. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4320 * @return an array containing the libraries that were resolved | 4506 * @return an array containing the libraries that were resolved |
| 4321 */ | 4507 */ |
| 4322 Set<Library> get resolvedLibraries => _librariesInCycles; | 4508 Set<Library> get resolvedLibraries => _librariesInCycles; |
| 4323 | 4509 |
| 4324 /** | 4510 /** |
| 4325 * Resolve the library specified by the given source in the given context. The
library is assumed | 4511 * Resolve the library specified by the given source in the given context. The
library is assumed |
| 4326 * to be embedded in the given source. | 4512 * to be embedded in the given source. |
| 4327 * @param librarySource the source specifying the defining compilation unit of
the library to be | 4513 * @param librarySource the source specifying the defining compilation unit of
the library to be |
| 4328 * resolved | 4514 * resolved |
| 4329 * @param unit the compilation unit representing the embedded library | 4515 * @param unit the compilation unit representing the embedded library |
| 4330 * @param fullAnalysis {@code true} if a full analysis should be performed | 4516 * @param fullAnalysis `true` if a full analysis should be performed |
| 4331 * @return the element representing the resolved library | 4517 * @return the element representing the resolved library |
| 4332 * @throws AnalysisException if the library could not be resolved for some rea
son | 4518 * @throws AnalysisException if the library could not be resolved for some rea
son |
| 4333 */ | 4519 */ |
| 4334 LibraryElement resolveEmbeddedLibrary(Source librarySource, CompilationUnit un
it, bool fullAnalysis) { | 4520 LibraryElement resolveEmbeddedLibrary(Source librarySource, CompilationUnit un
it, bool fullAnalysis) { |
| 4335 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveEmbeddedLibrary"); | 4521 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveEmbeddedLibrary"); |
| 4336 try { | 4522 try { |
| 4337 instrumentation.metric("fullAnalysis", fullAnalysis); | 4523 instrumentation.metric("fullAnalysis", fullAnalysis); |
| 4338 instrumentation.data3("fullName", librarySource.fullName); | 4524 instrumentation.data3("fullName", librarySource.fullName); |
| 4339 Library targetLibrary = createLibrary2(librarySource, unit); | 4525 Library targetLibrary = createLibrary2(librarySource, unit); |
| 4340 _coreLibrary = _libraryMap[_coreLibrarySource]; | 4526 _coreLibrary = _libraryMap[_coreLibrarySource]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4364 instrumentation.metric3("runAdditionalAnalyses", "complete"); | 4550 instrumentation.metric3("runAdditionalAnalyses", "complete"); |
| 4365 } | 4551 } |
| 4366 return targetLibrary.libraryElement; | 4552 return targetLibrary.libraryElement; |
| 4367 } finally { | 4553 } finally { |
| 4368 instrumentation.log(); | 4554 instrumentation.log(); |
| 4369 } | 4555 } |
| 4370 } | 4556 } |
| 4371 | 4557 |
| 4372 /** | 4558 /** |
| 4373 * Resolve the library specified by the given source in the given context. | 4559 * Resolve the library specified by the given source in the given context. |
| 4374 * <p> | 4560 * |
| 4375 * Note that because Dart allows circular imports between libraries, it is pos
sible that more than | 4561 * Note that because Dart allows circular imports between libraries, it is pos
sible that more than |
| 4376 * one library will need to be resolved. In such cases the error listener can
receive errors from | 4562 * one library will need to be resolved. In such cases the error listener can
receive errors from |
| 4377 * multiple libraries. | 4563 * multiple libraries. |
| 4378 * @param librarySource the source specifying the defining compilation unit of
the library to be | 4564 * @param librarySource the source specifying the defining compilation unit of
the library to be |
| 4379 * resolved | 4565 * resolved |
| 4380 * @param fullAnalysis {@code true} if a full analysis should be performed | 4566 * @param fullAnalysis `true` if a full analysis should be performed |
| 4381 * @return the element representing the resolved library | 4567 * @return the element representing the resolved library |
| 4382 * @throws AnalysisException if the library could not be resolved for some rea
son | 4568 * @throws AnalysisException if the library could not be resolved for some rea
son |
| 4383 */ | 4569 */ |
| 4384 LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) { | 4570 LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) { |
| 4385 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveLibrary"); | 4571 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveLibrary"); |
| 4386 try { | 4572 try { |
| 4387 instrumentation.metric("fullAnalysis", fullAnalysis); | 4573 instrumentation.metric("fullAnalysis", fullAnalysis); |
| 4388 instrumentation.data3("fullName", librarySource.fullName); | 4574 instrumentation.data3("fullName", librarySource.fullName); |
| 4389 Library targetLibrary = createLibrary(librarySource); | 4575 Library targetLibrary = createLibrary(librarySource); |
| 4390 _coreLibrary = _libraryMap[_coreLibrarySource]; | 4576 _coreLibrary = _libraryMap[_coreLibrarySource]; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4493 } else { | 4679 } else { |
| 4494 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl(); | 4680 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl(); |
| 4495 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN
ames); | 4681 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN
ames); |
| 4496 combinators.add(show); | 4682 combinators.add(show); |
| 4497 } | 4683 } |
| 4498 } | 4684 } |
| 4499 return new List.from(combinators); | 4685 return new List.from(combinators); |
| 4500 } | 4686 } |
| 4501 | 4687 |
| 4502 /** | 4688 /** |
| 4503 * Every library now has a corresponding {@link LibraryElement}, so it is now
possible to resolve | 4689 * Every library now has a corresponding [LibraryElement], so it is now possib
le to resolve |
| 4504 * the import and export directives. | 4690 * the import and export directives. |
| 4505 * @throws AnalysisException if the defining compilation unit for any of the l
ibraries could not | 4691 * @throws AnalysisException if the defining compilation unit for any of the l
ibraries could not |
| 4506 * be accessed | 4692 * be accessed |
| 4507 */ | 4693 */ |
| 4508 void buildDirectiveModels() { | 4694 void buildDirectiveModels() { |
| 4509 for (Library library in _librariesInCycles) { | 4695 for (Library library in _librariesInCycles) { |
| 4510 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle
mentImpl>(); | 4696 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle
mentImpl>(); |
| 4511 List<ImportElement> imports = new List<ImportElement>(); | 4697 List<ImportElement> imports = new List<ImportElement>(); |
| 4512 List<ExportElement> exports = new List<ExportElement>(); | 4698 List<ExportElement> exports = new List<ExportElement>(); |
| 4513 for (Directive directive in library.definingCompilationUnit.directives) { | 4699 for (Directive directive in library.definingCompilationUnit.directives) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4587 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour
ce, _typeProvider); | 4773 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour
ce, _typeProvider); |
| 4588 library.getAST(source).accept(visitor); | 4774 library.getAST(source).accept(visitor); |
| 4589 } | 4775 } |
| 4590 } | 4776 } |
| 4591 } | 4777 } |
| 4592 | 4778 |
| 4593 /** | 4779 /** |
| 4594 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a | 4780 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a |
| 4595 * table that maps individual libraries to a list of the libraries that either
import or export | 4781 * table that maps individual libraries to a list of the libraries that either
import or export |
| 4596 * those libraries. | 4782 * those libraries. |
| 4597 * <p> | 4783 * |
| 4598 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root | 4784 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root |
| 4599 * library. Given that we only add libraries that are reachable from the root
library, when we | 4785 * library. Given that we only add libraries that are reachable from the root
library, when we |
| 4600 * work backward we are guaranteed to only get libraries in the cycle. | 4786 * work backward we are guaranteed to only get libraries in the cycle. |
| 4601 * @param library the library currently being added to the dependency map | 4787 * @param library the library currently being added to the dependency map |
| 4602 */ | 4788 */ |
| 4603 Map<Library, List<Library>> computeDependencyMap(Library library) { | 4789 Map<Library, List<Library>> computeDependencyMap(Library library) { |
| 4604 Map<Library, List<Library>> dependencyMap = new Map<Library, List<Library>>(
); | 4790 Map<Library, List<Library>> dependencyMap = new Map<Library, List<Library>>(
); |
| 4605 addToDependencyMap(library, dependencyMap, new Set<Library>()); | 4791 addToDependencyMap(library, dependencyMap, new Set<Library>()); |
| 4606 return dependencyMap; | 4792 return dependencyMap; |
| 4607 } | 4793 } |
| 4608 | 4794 |
| 4609 /** | 4795 /** |
| 4610 * Return a collection containing all of the libraries reachable from the give
n library that are | 4796 * Return a collection containing all of the libraries reachable from the give
n library that are |
| 4611 * contained in a cycle that includes the given library. | 4797 * contained in a cycle that includes the given library. |
| 4612 * @param library the library that must be included in any cycles whose member
s are to be returned | 4798 * @param library the library that must be included in any cycles whose member
s are to be returned |
| 4613 * @return all of the libraries referenced by the given library that have a ci
rcular reference | 4799 * @return all of the libraries referenced by the given library that have a ci
rcular reference |
| 4614 * back to the given library | 4800 * back to the given library |
| 4615 */ | 4801 */ |
| 4616 Set<Library> computeLibrariesInCycles(Library library) { | 4802 Set<Library> computeLibrariesInCycles(Library library) { |
| 4617 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library); | 4803 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library); |
| 4618 Set<Library> librariesInCycle = new Set<Library>(); | 4804 Set<Library> librariesInCycle = new Set<Library>(); |
| 4619 addLibrariesInCycle(library, librariesInCycle, dependencyMap); | 4805 addLibrariesInCycle(library, librariesInCycle, dependencyMap); |
| 4620 return librariesInCycle; | 4806 return librariesInCycle; |
| 4621 } | 4807 } |
| 4622 | 4808 |
| 4623 /** | 4809 /** |
| 4624 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the | 4810 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the |
| 4625 * class {@link Library} to represent them, and record the references in the l
ibrary objects. | 4811 * class [Library] to represent them, and record the references in the library
objects. |
| 4626 * @param library the library to be processed to find libraries that have not
yet been traversed | 4812 * @param library the library to be processed to find libraries that have not
yet been traversed |
| 4627 * @throws AnalysisException if some portion of the library graph could not be
traversed | 4813 * @throws AnalysisException if some portion of the library graph could not be
traversed |
| 4628 */ | 4814 */ |
| 4629 void computeLibraryDependencies(Library library) { | 4815 void computeLibraryDependencies(Library library) { |
| 4630 bool explicitlyImportsCore = false; | 4816 bool explicitlyImportsCore = false; |
| 4631 CompilationUnit unit = library.definingCompilationUnit; | 4817 CompilationUnit unit = library.definingCompilationUnit; |
| 4632 for (Directive directive in unit.directives) { | 4818 for (Directive directive in unit.directives) { |
| 4633 if (directive is ImportDirective) { | 4819 if (directive is ImportDirective) { |
| 4634 ImportDirective importDirective = directive as ImportDirective; | 4820 ImportDirective importDirective = directive as ImportDirective; |
| 4635 Source importedSource = library.getSource(importDirective); | 4821 Source importedSource = library.getSource(importDirective); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4708 */ | 4894 */ |
| 4709 Library createLibrary2(Source librarySource, CompilationUnit unit) { | 4895 Library createLibrary2(Source librarySource, CompilationUnit unit) { |
| 4710 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); | 4896 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); |
| 4711 library.definingCompilationUnit = unit; | 4897 library.definingCompilationUnit = unit; |
| 4712 _libraryMap[librarySource] = library; | 4898 _libraryMap[librarySource] = library; |
| 4713 return library; | 4899 return library; |
| 4714 } | 4900 } |
| 4715 | 4901 |
| 4716 /** | 4902 /** |
| 4717 * Create an object to represent the information about the library defined by
the compilation unit | 4903 * Create an object to represent the information about the library defined by
the compilation unit |
| 4718 * with the given source. Return the library object that was created, or {@cod
e null} if the | 4904 * with the given source. Return the library object that was created, or `null
` if the |
| 4719 * source is not valid. | 4905 * source is not valid. |
| 4720 * @param librarySource the source of the library's defining compilation unit | 4906 * @param librarySource the source of the library's defining compilation unit |
| 4721 * @return the library object that was created | 4907 * @return the library object that was created |
| 4722 */ | 4908 */ |
| 4723 Library createLibraryOrNull(Source librarySource) { | 4909 Library createLibraryOrNull(Source librarySource) { |
| 4724 if (!librarySource.exists()) { | 4910 if (!librarySource.exists()) { |
| 4725 return null; | 4911 return null; |
| 4726 } | 4912 } |
| 4727 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); | 4913 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); |
| 4728 try { | 4914 try { |
| 4729 library.definingCompilationUnit; | 4915 library.definingCompilationUnit; |
| 4730 } on AnalysisException catch (exception) { | 4916 } on AnalysisException catch (exception) { |
| 4731 return null; | 4917 return null; |
| 4732 } | 4918 } |
| 4733 _libraryMap[librarySource] = library; | 4919 _libraryMap[librarySource] = library; |
| 4734 return library; | 4920 return library; |
| 4735 } | 4921 } |
| 4736 | 4922 |
| 4737 /** | 4923 /** |
| 4738 * Return {@code true} if and only if the passed {@link CompilationUnit} has a
part-of directive. | 4924 * Return `true` if and only if the passed [CompilationUnit] has a part-of dir
ective. |
| 4739 * @param node the {@link CompilationUnit} to test | 4925 * @param node the [CompilationUnit] to test |
| 4740 * @return {@code true} if and only if the passed {@link CompilationUnit} has
a part-of directive | 4926 * @return `true` if and only if the passed [CompilationUnit] has a part-of di
rective |
| 4741 */ | 4927 */ |
| 4742 bool doesCompilationUnitHavePartOfDirective(CompilationUnit node) { | 4928 bool doesCompilationUnitHavePartOfDirective(CompilationUnit node) { |
| 4743 NodeList<Directive> directives = node.directives; | 4929 NodeList<Directive> directives = node.directives; |
| 4744 for (Directive directive in directives) { | 4930 for (Directive directive in directives) { |
| 4745 if (directive is PartOfDirective) { | 4931 if (directive is PartOfDirective) { |
| 4746 return true; | 4932 return true; |
| 4747 } | 4933 } |
| 4748 } | 4934 } |
| 4749 return false; | 4935 return false; |
| 4750 } | 4936 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4801 * the library cannot be analyzed | 4987 * the library cannot be analyzed |
| 4802 */ | 4988 */ |
| 4803 void resolveReferencesAndTypes2(Library library) { | 4989 void resolveReferencesAndTypes2(Library library) { |
| 4804 for (Source source in library.compilationUnitSources) { | 4990 for (Source source in library.compilationUnitSources) { |
| 4805 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); | 4991 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); |
| 4806 library.getAST(source).accept(visitor); | 4992 library.getAST(source).accept(visitor); |
| 4807 } | 4993 } |
| 4808 } | 4994 } |
| 4809 | 4995 |
| 4810 /** | 4996 /** |
| 4811 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er
rorVerifier}analysis in the current cycle. | 4997 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier]
analysis in the current cycle. |
| 4812 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 4998 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 4813 * the library cannot be analyzed | 4999 * the library cannot be analyzed |
| 4814 */ | 5000 */ |
| 4815 void runAdditionalAnalyses() { | 5001 void runAdditionalAnalyses() { |
| 4816 for (Library library in _librariesInCycles) { | 5002 for (Library library in _librariesInCycles) { |
| 4817 runAdditionalAnalyses2(library); | 5003 runAdditionalAnalyses2(library); |
| 4818 } | 5004 } |
| 4819 } | 5005 } |
| 4820 | 5006 |
| 4821 /** | 5007 /** |
| 4822 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er
rorVerifier}analysis in the given library. | 5008 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier]
analysis in the given library. |
| 4823 * @param library the library to have the extra analyses processes run | 5009 * @param library the library to have the extra analyses processes run |
| 4824 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 5010 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 4825 * the library cannot be analyzed | 5011 * the library cannot be analyzed |
| 4826 */ | 5012 */ |
| 4827 void runAdditionalAnalyses2(Library library) { | 5013 void runAdditionalAnalyses2(Library library) { |
| 4828 for (Source source in library.compilationUnitSources) { | 5014 for (Source source in library.compilationUnitSources) { |
| 4829 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); | 5015 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); |
| 4830 CompilationUnit unit = library.getAST(source); | 5016 CompilationUnit unit = library.getAST(source); |
| 5017 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); |
| 5018 unit.accept(constantVerifier); |
| 4831 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); | 5019 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); |
| 4832 unit.accept(errorVerifier); | 5020 unit.accept(errorVerifier); |
| 4833 unit.accept(new PubVerifier(_analysisContext, errorReporter)); | |
| 4834 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); | |
| 4835 unit.accept(constantVerifier); | |
| 4836 } | 5021 } |
| 4837 } | 5022 } |
| 4838 } | 5023 } |
| 4839 /** | 5024 /** |
| 4840 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes
within a single | 5025 * Instances of the class `ResolverVisitor` are used to resolve the nodes within
a single |
| 4841 * compilation unit. | 5026 * compilation unit. |
| 4842 * @coverage dart.engine.resolver | 5027 * @coverage dart.engine.resolver |
| 4843 */ | 5028 */ |
| 4844 class ResolverVisitor extends ScopedVisitor { | 5029 class ResolverVisitor extends ScopedVisitor { |
| 4845 | 5030 |
| 4846 /** | 5031 /** |
| 4847 * The object used to resolve the element associated with the current node. | 5032 * The object used to resolve the element associated with the current node. |
| 4848 */ | 5033 */ |
| 4849 ElementResolver _elementResolver; | 5034 ElementResolver _elementResolver; |
| 4850 | 5035 |
| 4851 /** | 5036 /** |
| 4852 * The object used to compute the type associated with the current node. | 5037 * The object used to compute the type associated with the current node. |
| 4853 */ | 5038 */ |
| 4854 StaticTypeAnalyzer _typeAnalyzer; | 5039 StaticTypeAnalyzer _typeAnalyzer; |
| 4855 | 5040 |
| 4856 /** | 5041 /** |
| 4857 * The class element representing the class containing the current node, or {@
code null} if the | 5042 * The class element representing the class containing the current node, or `n
ull` if the |
| 4858 * current node is not contained in a class. | 5043 * current node is not contained in a class. |
| 4859 */ | 5044 */ |
| 4860 ClassElement _enclosingClass = null; | 5045 ClassElement _enclosingClass = null; |
| 4861 | 5046 |
| 4862 /** | 5047 /** |
| 4863 * The element representing the function containing the current node, or {@cod
e null} if the | 5048 * The element representing the function containing the current node, or `null
` if the |
| 4864 * current node is not contained in a function. | 5049 * current node is not contained in a function. |
| 4865 */ | 5050 */ |
| 4866 ExecutableElement _enclosingFunction = null; | 5051 ExecutableElement _enclosingFunction = null; |
| 4867 | 5052 |
| 4868 /** | 5053 /** |
| 4869 * The object keeping track of which elements have had their types overridden. | 5054 * The object keeping track of which elements have had their types overridden. |
| 4870 */ | 5055 */ |
| 4871 TypeOverrideManager _overrideManager = new TypeOverrideManager(); | 5056 TypeOverrideManager _overrideManager = new TypeOverrideManager(); |
| 4872 | 5057 |
| 4873 /** | 5058 /** |
| 4874 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5059 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 4875 * @param library the library containing the compilation unit being resolved | 5060 * @param library the library containing the compilation unit being resolved |
| 4876 * @param source the source representing the compilation unit being visited | 5061 * @param source the source representing the compilation unit being visited |
| 4877 * @param typeProvider the object used to access the types from the core libra
ry | 5062 * @param typeProvider the object used to access the types from the core libra
ry |
| 4878 */ | 5063 */ |
| 4879 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider
) : super.con1(library, source, typeProvider) { | 5064 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider
) : super.con1(library, source, typeProvider) { |
| 4880 _jtd_constructor_273_impl(library, source, typeProvider); | 5065 _jtd_constructor_274_impl(library, source, typeProvider); |
| 4881 } | 5066 } |
| 4882 _jtd_constructor_273_impl(Library library, Source source, TypeProvider typePro
vider) { | 5067 _jtd_constructor_274_impl(Library library, Source source, TypeProvider typePro
vider) { |
| 4883 this._elementResolver = new ElementResolver(this); | 5068 this._elementResolver = new ElementResolver(this); |
| 4884 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 5069 this._typeAnalyzer = new StaticTypeAnalyzer(this); |
| 4885 } | 5070 } |
| 4886 | 5071 |
| 4887 /** | 5072 /** |
| 4888 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5073 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 4889 * @param definingLibrary the element for the library containing the compilati
on unit being | 5074 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 4890 * visited | 5075 * visited |
| 4891 * @param source the source representing the compilation unit being visited | 5076 * @param source the source representing the compilation unit being visited |
| 4892 * @param typeProvider the object used to access the types from the core libra
ry | 5077 * @param typeProvider the object used to access the types from the core libra
ry |
| 4893 * @param errorListener the error listener that will be informed of any errors
that are found | 5078 * @param errorListener the error listener that will be informed of any errors
that are found |
| 4894 * during resolution | 5079 * during resolution |
| 4895 */ | 5080 */ |
| 4896 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid
er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra
ry, source, typeProvider, errorListener) { | 5081 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid
er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra
ry, source, typeProvider, errorListener) { |
| 4897 _jtd_constructor_274_impl(definingLibrary, source, typeProvider, errorListen
er); | 5082 _jtd_constructor_275_impl(definingLibrary, source, typeProvider, errorListen
er); |
| 4898 } | 5083 } |
| 4899 _jtd_constructor_274_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { | 5084 _jtd_constructor_275_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { |
| 4900 this._elementResolver = new ElementResolver(this); | 5085 this._elementResolver = new ElementResolver(this); |
| 4901 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 5086 this._typeAnalyzer = new StaticTypeAnalyzer(this); |
| 4902 } | 5087 } |
| 4903 | 5088 |
| 4904 /** | 5089 /** |
| 4905 * Return the object keeping track of which elements have had their types over
ridden. | 5090 * Return the object keeping track of which elements have had their types over
ridden. |
| 4906 * @return the object keeping track of which elements have had their types ove
rridden | 5091 * @return the object keeping track of which elements have had their types ove
rridden |
| 4907 */ | 5092 */ |
| 4908 TypeOverrideManager get overrideManager => _overrideManager; | 5093 TypeOverrideManager get overrideManager => _overrideManager; |
| 4909 Object visitAsExpression(AsExpression node) { | 5094 Object visitAsExpression(AsExpression node) { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5268 } finally { | 5453 } finally { |
| 5269 _overrideManager.exitScope(); | 5454 _overrideManager.exitScope(); |
| 5270 } | 5455 } |
| 5271 } | 5456 } |
| 5272 node.accept(_elementResolver); | 5457 node.accept(_elementResolver); |
| 5273 node.accept(_typeAnalyzer); | 5458 node.accept(_typeAnalyzer); |
| 5274 return null; | 5459 return null; |
| 5275 } | 5460 } |
| 5276 | 5461 |
| 5277 /** | 5462 /** |
| 5278 * Return the class element representing the class containing the current node
, or {@code null} if | 5463 * Return the class element representing the class containing the current node
, or `null` if |
| 5279 * the current node is not contained in a class. | 5464 * the current node is not contained in a class. |
| 5280 * @return the class element representing the class containing the current nod
e | 5465 * @return the class element representing the class containing the current nod
e |
| 5281 */ | 5466 */ |
| 5282 ClassElement get enclosingClass => _enclosingClass; | 5467 ClassElement get enclosingClass => _enclosingClass; |
| 5283 | 5468 |
| 5284 /** | 5469 /** |
| 5285 * Return the element representing the function containing the current node, o
r {@code null} if | 5470 * Return the element representing the function containing the current node, o
r `null` if |
| 5286 * the current node is not contained in a function. | 5471 * the current node is not contained in a function. |
| 5287 * @return the element representing the function containing the current node | 5472 * @return the element representing the function containing the current node |
| 5288 */ | 5473 */ |
| 5289 ExecutableElement get enclosingFunction => _enclosingFunction; | 5474 ExecutableElement get enclosingFunction => _enclosingFunction; |
| 5290 | 5475 |
| 5291 /** | 5476 /** |
| 5292 * Return the element associated with the given expression whose type can be o
verridden, or{@code null} if there is no element whose type can be overridden. | 5477 * Return the element associated with the given expression whose type can be o
verridden, or`null` if there is no element whose type can be overridden. |
| 5293 * @param expression the expression with which the element is associated | 5478 * @param expression the expression with which the element is associated |
| 5294 * @return the element associated with the given expression | 5479 * @return the element associated with the given expression |
| 5295 */ | 5480 */ |
| 5296 VariableElement getOverridableElement(Expression expression) { | 5481 VariableElement getOverridableElement(Expression expression) { |
| 5297 Element element = null; | 5482 Element element = null; |
| 5298 if (expression is SimpleIdentifier) { | 5483 if (expression is SimpleIdentifier) { |
| 5299 element = ((expression as SimpleIdentifier)).element; | 5484 element = ((expression as SimpleIdentifier)).element; |
| 5300 } else if (expression is PrefixedIdentifier) { | 5485 } else if (expression is PrefixedIdentifier) { |
| 5301 element = ((expression as PrefixedIdentifier)).element; | 5486 element = ((expression as PrefixedIdentifier)).element; |
| 5302 } else if (expression is PropertyAccess) { | 5487 } else if (expression is PropertyAccess) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5381 } else if (element is ParameterElement) { | 5566 } else if (element is ParameterElement) { |
| 5382 bestType = ((element as ParameterElement)).type; | 5567 bestType = ((element as ParameterElement)).type; |
| 5383 } | 5568 } |
| 5384 } | 5569 } |
| 5385 return bestType; | 5570 return bestType; |
| 5386 } | 5571 } |
| 5387 | 5572 |
| 5388 /** | 5573 /** |
| 5389 * The given expression is the expression used to compute the iterator for a f
or-each statement. | 5574 * The given expression is the expression used to compute the iterator for a f
or-each statement. |
| 5390 * Attempt to compute the type of objects that will be assigned to the loop va
riable and return | 5575 * Attempt to compute the type of objects that will be assigned to the loop va
riable and return |
| 5391 * that type. Return {@code null} if the type could not be determined. | 5576 * that type. Return `null` if the type could not be determined. |
| 5392 * @param iterator the iterator for a for-each statement | 5577 * @param iterator the iterator for a for-each statement |
| 5393 * @return the type of objects that will be assigned to the loop variable | 5578 * @return the type of objects that will be assigned to the loop variable |
| 5394 */ | 5579 */ |
| 5395 Type2 getIteratorElementType(Expression iteratorExpression) { | 5580 Type2 getIteratorElementType(Expression iteratorExpression) { |
| 5396 Type2 expressionType = iteratorExpression.staticType; | 5581 Type2 expressionType = iteratorExpression.staticType; |
| 5397 if (expressionType is InterfaceType) { | 5582 if (expressionType is InterfaceType) { |
| 5398 PropertyAccessorElement iterator = ((expressionType as InterfaceType)).loo
kUpGetter("iterator", definingLibrary); | 5583 PropertyAccessorElement iterator = ((expressionType as InterfaceType)).loo
kUpGetter("iterator", definingLibrary); |
| 5399 if (iterator == null) { | 5584 if (iterator == null) { |
| 5400 return null; | 5585 return null; |
| 5401 } | 5586 } |
| 5402 Type2 iteratorType = iterator.type.returnType; | 5587 Type2 iteratorType = iterator.type.returnType; |
| 5403 if (iteratorType is InterfaceType) { | 5588 if (iteratorType is InterfaceType) { |
| 5404 PropertyAccessorElement current = ((iteratorType as InterfaceType)).look
UpGetter("current", definingLibrary); | 5589 PropertyAccessorElement current = ((iteratorType as InterfaceType)).look
UpGetter("current", definingLibrary); |
| 5405 if (current == null) { | 5590 if (current == null) { |
| 5406 return null; | 5591 return null; |
| 5407 } | 5592 } |
| 5408 return current.type.returnType; | 5593 return current.type.returnType; |
| 5409 } | 5594 } |
| 5410 } | 5595 } |
| 5411 return null; | 5596 return null; |
| 5412 } | 5597 } |
| 5413 | 5598 |
| 5414 /** | 5599 /** |
| 5415 * Return {@code true} if the given expression terminates abruptly (that is, i
f any expression | 5600 * Return `true` if the given expression terminates abruptly (that is, if any
expression |
| 5416 * following the given expression will not be reached). | 5601 * following the given expression will not be reached). |
| 5417 * @param expression the expression being tested | 5602 * @param expression the expression being tested |
| 5418 * @return {@code true} if the given expression terminates abruptly | 5603 * @return `true` if the given expression terminates abruptly |
| 5419 */ | 5604 */ |
| 5420 bool isAbruptTermination(Expression expression2) { | 5605 bool isAbruptTermination(Expression expression2) { |
| 5421 while (expression2 is ParenthesizedExpression) { | 5606 while (expression2 is ParenthesizedExpression) { |
| 5422 expression2 = ((expression2 as ParenthesizedExpression)).expression; | 5607 expression2 = ((expression2 as ParenthesizedExpression)).expression; |
| 5423 } | 5608 } |
| 5424 return expression2 is ThrowExpression || expression2 is RethrowExpression; | 5609 return expression2 is ThrowExpression || expression2 is RethrowExpression; |
| 5425 } | 5610 } |
| 5426 | 5611 |
| 5427 /** | 5612 /** |
| 5428 * Return {@code true} if the given statement terminates abruptly (that is, if
any statement | 5613 * Return `true` if the given statement terminates abruptly (that is, if any s
tatement |
| 5429 * following the given statement will not be reached). | 5614 * following the given statement will not be reached). |
| 5430 * @param statement the statement being tested | 5615 * @param statement the statement being tested |
| 5431 * @return {@code true} if the given statement terminates abruptly | 5616 * @return `true` if the given statement terminates abruptly |
| 5432 */ | 5617 */ |
| 5433 bool isAbruptTermination2(Statement statement) { | 5618 bool isAbruptTermination2(Statement statement) { |
| 5434 if (statement is ReturnStatement || statement is BreakStatement || statement
is ContinueStatement) { | 5619 if (statement is ReturnStatement || statement is BreakStatement || statement
is ContinueStatement) { |
| 5435 return true; | 5620 return true; |
| 5436 } else if (statement is ExpressionStatement) { | 5621 } else if (statement is ExpressionStatement) { |
| 5437 return isAbruptTermination(((statement as ExpressionStatement)).expression
); | 5622 return isAbruptTermination(((statement as ExpressionStatement)).expression
); |
| 5438 } else if (statement is Block) { | 5623 } else if (statement is Block) { |
| 5439 NodeList<Statement> statements = ((statement as Block)).statements; | 5624 NodeList<Statement> statements = ((statement as Block)).statements; |
| 5440 int size = statements.length; | 5625 int size = statements.length; |
| 5441 if (size == 0) { | 5626 if (size == 0) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5518 get labelScope_J2DAccessor => _labelScope; | 5703 get labelScope_J2DAccessor => _labelScope; |
| 5519 set labelScope_J2DAccessor(__v) => _labelScope = __v; | 5704 set labelScope_J2DAccessor(__v) => _labelScope = __v; |
| 5520 get nameScope_J2DAccessor => _nameScope; | 5705 get nameScope_J2DAccessor => _nameScope; |
| 5521 set nameScope_J2DAccessor(__v) => _nameScope = __v; | 5706 set nameScope_J2DAccessor(__v) => _nameScope = __v; |
| 5522 get typeAnalyzer_J2DAccessor => _typeAnalyzer; | 5707 get typeAnalyzer_J2DAccessor => _typeAnalyzer; |
| 5523 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; | 5708 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; |
| 5524 get enclosingClass_J2DAccessor => _enclosingClass; | 5709 get enclosingClass_J2DAccessor => _enclosingClass; |
| 5525 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v; | 5710 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v; |
| 5526 } | 5711 } |
| 5527 /** | 5712 /** |
| 5528 * The abstract class {@code ScopedVisitor} maintains name and label scopes as a
n AST structure is | 5713 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST
structure is |
| 5529 * being visited. | 5714 * being visited. |
| 5530 * @coverage dart.engine.resolver | 5715 * @coverage dart.engine.resolver |
| 5531 */ | 5716 */ |
| 5532 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { | 5717 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { |
| 5533 | 5718 |
| 5534 /** | 5719 /** |
| 5535 * The element for the library containing the compilation unit being visited. | 5720 * The element for the library containing the compilation unit being visited. |
| 5536 */ | 5721 */ |
| 5537 LibraryElement _definingLibrary; | 5722 LibraryElement _definingLibrary; |
| 5538 | 5723 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5550 * The scope used to resolve identifiers. | 5735 * The scope used to resolve identifiers. |
| 5551 */ | 5736 */ |
| 5552 Scope _nameScope; | 5737 Scope _nameScope; |
| 5553 | 5738 |
| 5554 /** | 5739 /** |
| 5555 * The object used to access the types from the core library. | 5740 * The object used to access the types from the core library. |
| 5556 */ | 5741 */ |
| 5557 TypeProvider _typeProvider; | 5742 TypeProvider _typeProvider; |
| 5558 | 5743 |
| 5559 /** | 5744 /** |
| 5560 * The scope used to resolve labels for {@code break} and {@code continue} sta
tements, or{@code null} if no labels have been defined in the current context. | 5745 * The scope used to resolve labels for `break` and `continue` statements, or`
null` if no labels have been defined in the current context. |
| 5561 */ | 5746 */ |
| 5562 LabelScope _labelScope; | 5747 LabelScope _labelScope; |
| 5563 | 5748 |
| 5564 /** | 5749 /** |
| 5565 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5750 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 5566 * @param library the library containing the compilation unit being resolved | 5751 * @param library the library containing the compilation unit being resolved |
| 5567 * @param source the source representing the compilation unit being visited | 5752 * @param source the source representing the compilation unit being visited |
| 5568 * @param typeProvider the object used to access the types from the core libra
ry | 5753 * @param typeProvider the object used to access the types from the core libra
ry |
| 5569 */ | 5754 */ |
| 5570 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2
) { | 5755 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2
) { |
| 5571 _jtd_constructor_275_impl(library, source2, typeProvider2); | 5756 _jtd_constructor_276_impl(library, source2, typeProvider2); |
| 5572 } | 5757 } |
| 5573 _jtd_constructor_275_impl(Library library, Source source2, TypeProvider typePr
ovider2) { | 5758 _jtd_constructor_276_impl(Library library, Source source2, TypeProvider typePr
ovider2) { |
| 5574 this._definingLibrary = library.libraryElement; | 5759 this._definingLibrary = library.libraryElement; |
| 5575 this._source = source2; | 5760 this._source = source2; |
| 5576 LibraryScope libraryScope = library.libraryScope; | 5761 LibraryScope libraryScope = library.libraryScope; |
| 5577 this._errorListener = libraryScope.errorListener; | 5762 this._errorListener = libraryScope.errorListener; |
| 5578 this._nameScope = libraryScope; | 5763 this._nameScope = libraryScope; |
| 5579 this._typeProvider = typeProvider2; | 5764 this._typeProvider = typeProvider2; |
| 5580 } | 5765 } |
| 5581 | 5766 |
| 5582 /** | 5767 /** |
| 5583 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5768 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 5584 * @param definingLibrary the element for the library containing the compilati
on unit being | 5769 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 5585 * visited | 5770 * visited |
| 5586 * @param source the source representing the compilation unit being visited | 5771 * @param source the source representing the compilation unit being visited |
| 5587 * @param typeProvider the object used to access the types from the core libra
ry | 5772 * @param typeProvider the object used to access the types from the core libra
ry |
| 5588 * @param errorListener the error listener that will be informed of any errors
that are found | 5773 * @param errorListener the error listener that will be informed of any errors
that are found |
| 5589 * during resolution | 5774 * during resolution |
| 5590 */ | 5775 */ |
| 5591 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid
er typeProvider2, AnalysisErrorListener errorListener2) { | 5776 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid
er typeProvider2, AnalysisErrorListener errorListener2) { |
| 5592 _jtd_constructor_276_impl(definingLibrary2, source2, typeProvider2, errorLis
tener2); | 5777 _jtd_constructor_277_impl(definingLibrary2, source2, typeProvider2, errorLis
tener2); |
| 5593 } | 5778 } |
| 5594 _jtd_constructor_276_impl(LibraryElement definingLibrary2, Source source2, Typ
eProvider typeProvider2, AnalysisErrorListener errorListener2) { | 5779 _jtd_constructor_277_impl(LibraryElement definingLibrary2, Source source2, Typ
eProvider typeProvider2, AnalysisErrorListener errorListener2) { |
| 5595 this._definingLibrary = definingLibrary2; | 5780 this._definingLibrary = definingLibrary2; |
| 5596 this._source = source2; | 5781 this._source = source2; |
| 5597 this._errorListener = errorListener2; | 5782 this._errorListener = errorListener2; |
| 5598 this._nameScope = new LibraryScope(definingLibrary2, errorListener2); | 5783 this._nameScope = new LibraryScope(definingLibrary2, errorListener2); |
| 5599 this._typeProvider = typeProvider2; | 5784 this._typeProvider = typeProvider2; |
| 5600 } | 5785 } |
| 5601 | 5786 |
| 5602 /** | 5787 /** |
| 5603 * Return the library element for the library containing the compilation unit
being resolved. | 5788 * Return the library element for the library containing the compilation unit
being resolved. |
| 5604 * @return the library element for the library containing the compilation unit
being resolved | 5789 * @return the library element for the library containing the compilation unit
being resolved |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5917 for (Label label in labels) { | 6102 for (Label label in labels) { |
| 5918 SimpleIdentifier labelNameNode = label.label; | 6103 SimpleIdentifier labelNameNode = label.label; |
| 5919 String labelName = labelNameNode.name; | 6104 String labelName = labelNameNode.name; |
| 5920 LabelElement labelElement = labelNameNode.element as LabelElement; | 6105 LabelElement labelElement = labelNameNode.element as LabelElement; |
| 5921 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); | 6106 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); |
| 5922 } | 6107 } |
| 5923 return outerScope; | 6108 return outerScope; |
| 5924 } | 6109 } |
| 5925 } | 6110 } |
| 5926 /** | 6111 /** |
| 5927 * Instances of the class {@code StaticTypeAnalyzer} perform two type-related ta
sks. First, they | 6112 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F
irst, they |
| 5928 * compute the static type of every expression. Second, they look for any static
type errors or | 6113 * compute the static type of every expression. Second, they look for any static
type errors or |
| 5929 * warnings that might need to be generated. The requirements for the type analy
zer are: | 6114 * warnings that might need to be generated. The requirements for the type analy
zer are: |
| 5930 * <ol> | 6115 * <ol> |
| 5931 * <li>Every element that refers to types should be fully populated. | 6116 * * Every element that refers to types should be fully populated. |
| 5932 * <li>Every node representing an expression should be resolved to the Type of t
he expression.</li> | 6117 * * Every node representing an expression should be resolved to the Type of the
expression. |
| 5933 * </ol> | 6118 * </ol> |
| 5934 * @coverage dart.engine.resolver | 6119 * @coverage dart.engine.resolver |
| 5935 */ | 6120 */ |
| 5936 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { | 6121 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { |
| 5937 | 6122 |
| 5938 /** | 6123 /** |
| 5939 * Create a table mapping HTML tag names to the names of the classes (in 'dart
:html') that | 6124 * Create a table mapping HTML tag names to the names of the classes (in 'dart
:html') that |
| 5940 * implement those tags. | 6125 * implement those tags. |
| 5941 * @return the table that was created | 6126 * @return the table that was created |
| 5942 */ | 6127 */ |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6012 * The object providing access to the types defined by the language. | 6197 * The object providing access to the types defined by the language. |
| 6013 */ | 6198 */ |
| 6014 TypeProvider _typeProvider; | 6199 TypeProvider _typeProvider; |
| 6015 | 6200 |
| 6016 /** | 6201 /** |
| 6017 * The type representing the type 'dynamic'. | 6202 * The type representing the type 'dynamic'. |
| 6018 */ | 6203 */ |
| 6019 Type2 _dynamicType; | 6204 Type2 _dynamicType; |
| 6020 | 6205 |
| 6021 /** | 6206 /** |
| 6022 * The type representing the class containing the nodes being analyzed, or {@c
ode null} if the | 6207 * The type representing the class containing the nodes being analyzed, or `nu
ll` if the |
| 6023 * nodes are not within a class. | 6208 * nodes are not within a class. |
| 6024 */ | 6209 */ |
| 6025 InterfaceType _thisType; | 6210 InterfaceType _thisType; |
| 6026 | 6211 |
| 6027 /** | 6212 /** |
| 6028 * The object keeping track of which elements have had their types overridden. | 6213 * The object keeping track of which elements have had their types overridden. |
| 6029 */ | 6214 */ |
| 6030 TypeOverrideManager _overrideManager; | 6215 TypeOverrideManager _overrideManager; |
| 6031 | 6216 |
| 6032 /** | 6217 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6048 | 6233 |
| 6049 /** | 6234 /** |
| 6050 * Set the type of the class being analyzed to the given type. | 6235 * Set the type of the class being analyzed to the given type. |
| 6051 * @param thisType the type representing the class containing the nodes being
analyzed | 6236 * @param thisType the type representing the class containing the nodes being
analyzed |
| 6052 */ | 6237 */ |
| 6053 void set thisType(InterfaceType thisType2) { | 6238 void set thisType(InterfaceType thisType2) { |
| 6054 this._thisType = thisType2; | 6239 this._thisType = thisType2; |
| 6055 } | 6240 } |
| 6056 | 6241 |
| 6057 /** | 6242 /** |
| 6058 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> | 6243 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is`String`.</blockquote> |
| 6059 */ | 6244 */ |
| 6060 Object visitAdjacentStrings(AdjacentStrings node) { | 6245 Object visitAdjacentStrings(AdjacentStrings node) { |
| 6061 recordStaticType(node, _typeProvider.stringType); | 6246 recordStaticType(node, _typeProvider.stringType); |
| 6062 return null; | 6247 return null; |
| 6063 } | 6248 } |
| 6064 | 6249 |
| 6065 /** | 6250 /** |
| 6066 * The Dart Language Specification, 12.33: <blockquote>The static type of an a
rgument definition | 6251 * The Dart Language Specification, 12.33: <blockquote>The static type of an a
rgument definition |
| 6067 * test is {@code bool}.</blockquote> | 6252 * test is `bool`.</blockquote> |
| 6068 */ | 6253 */ |
| 6069 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { | 6254 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { |
| 6070 recordStaticType(node, _typeProvider.boolType); | 6255 recordStaticType(node, _typeProvider.boolType); |
| 6071 return null; | 6256 return null; |
| 6072 } | 6257 } |
| 6073 | 6258 |
| 6074 /** | 6259 /** |
| 6075 * The Dart Language Specification, 12.32: <blockquote>... the cast expression
<i>e as T</i> ... | 6260 * The Dart Language Specification, 12.32: <blockquote>... the cast expression
<i>e as T</i> ... |
| 6076 * <p> | 6261 * |
| 6077 * It is a static warning if <i>T</i> does not denote a type available in the
current lexical | 6262 * It is a static warning if <i>T</i> does not denote a type available in the
current lexical |
| 6078 * scope. | 6263 * scope. |
| 6079 * <p> | 6264 * |
| 6080 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote
> | 6265 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote
> |
| 6081 */ | 6266 */ |
| 6082 Object visitAsExpression(AsExpression node) { | 6267 Object visitAsExpression(AsExpression node) { |
| 6083 recordStaticType(node, getType2(node.type)); | 6268 recordStaticType(node, getType2(node.type)); |
| 6084 return null; | 6269 return null; |
| 6085 } | 6270 } |
| 6086 | 6271 |
| 6087 /** | 6272 /** |
| 6088 * The Dart Language Specification, 12.18: <blockquote>... an assignment <i>a<
/i> of the form <i>v | 6273 * The Dart Language Specification, 12.18: <blockquote>... an assignment <i>a<
/i> of the form <i>v |
| 6089 * = e</i> ... | 6274 * = e</i> ... |
| 6090 * <p> | 6275 * |
| 6091 * It is a static type warning if the static type of <i>e</i> may not be assig
ned to the static | 6276 * It is a static type warning if the static type of <i>e</i> may not be assig
ned to the static |
| 6092 * type of <i>v</i>. | 6277 * type of <i>v</i>. |
| 6093 * <p> | 6278 * |
| 6094 * The static type of the expression <i>v = e</i> is the static type of <i>e</
i>. | 6279 * The static type of the expression <i>v = e</i> is the static type of <i>e</
i>. |
| 6095 * <p> | 6280 * |
| 6096 * ... an assignment of the form <i>C.v = e</i> ... | 6281 * ... an assignment of the form <i>C.v = e</i> ... |
| 6097 * <p> | 6282 * |
| 6098 * It is a static type warning if the static type of <i>e</i> may not be assig
ned to the static | 6283 * It is a static type warning if the static type of <i>e</i> may not be assig
ned to the static |
| 6099 * type of <i>C.v</i>. | 6284 * type of <i>C.v</i>. |
| 6100 * <p> | 6285 * |
| 6101 * The static type of the expression <i>C.v = e</i> is the static type of <i>e
</i>. | 6286 * The static type of the expression <i>C.v = e</i> is the static type of <i>e
</i>. |
| 6102 * <p> | 6287 * |
| 6103 * ... an assignment of the form <i>e<sub>1</sub>.v = e<sub>2</sub></i> ... | 6288 * ... an assignment of the form <i>e<sub>1</sub>.v = e<sub>2</sub></i> ... |
| 6104 * <p> | 6289 * |
| 6105 * Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static typ
e warning if | 6290 * Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static typ
e warning if |
| 6106 * <i>T</i> does not have an accessible instance setter named <i>v=</i>. It is
a static type | 6291 * <i>T</i> does not have an accessible instance setter named <i>v=</i>. It is
a static type |
| 6107 * warning if the static type of <i>e<sub>2</sub></i> may not be assigned to <
i>T</i>. | 6292 * warning if the static type of <i>e<sub>2</sub></i> may not be assigned to <
i>T</i>. |
| 6108 * <p> | 6293 * |
| 6109 * The static type of the expression <i>e<sub>1</sub>.v = e<sub>2</sub></i> is
the static type of | 6294 * The static type of the expression <i>e<sub>1</sub>.v = e<sub>2</sub></i> is
the static type of |
| 6110 * <i>e<sub>2</sub></i>. | 6295 * <i>e<sub>2</sub></i>. |
| 6111 * <p> | 6296 * |
| 6112 * ... an assignment of the form <i>e<sub>1</sub>\[e<sub>2</sub>\] = e<sub>3</
sub></i> ... | 6297 * ... an assignment of the form <i>e<sub>1</sub>\[e<sub>2</sub>\] = e<sub>3</
sub></i> ... |
| 6113 * <p> | 6298 * |
| 6114 * The static type of the expression <i>e<sub>1</sub>\[e<sub>2</sub>\] = e<sub
>3</sub></i> is the | 6299 * The static type of the expression <i>e<sub>1</sub>\[e<sub>2</sub>\] = e<sub
>3</sub></i> is the |
| 6115 * static type of <i>e<sub>3</sub></i>. | 6300 * static type of <i>e<sub>3</sub></i>. |
| 6116 * <p> | 6301 * |
| 6117 * A compound assignment of the form <i>v op= e</i> is equivalent to <i>v = v
op e</i>. A compound | 6302 * A compound assignment of the form <i>v op= e</i> is equivalent to <i>v = v
op e</i>. A compound |
| 6118 * assignment of the form <i>C.v op= e</i> is equivalent to <i>C.v = C.v op e<
/i>. A compound | 6303 * assignment of the form <i>C.v op= e</i> is equivalent to <i>C.v = C.v op e<
/i>. A compound |
| 6119 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale
nt to <i>((x) => x.v | 6304 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale
nt to <i>((x) => x.v |
| 6120 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha
t is not used in | 6305 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha
t is not used in |
| 6121 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>\[e
<sub>2</sub>\] op= | 6306 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>\[e
<sub>2</sub>\] op= |
| 6122 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a\[i\] = a\[i\] op e<sub>3
</sub>)(e<sub>1</sub>, | 6307 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a\[i\] = a\[i\] op e<sub>3
</sub>)(e<sub>1</sub>, |
| 6123 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not
used in | 6308 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not
used in |
| 6124 * <i>e<sub>3</sub></i>.</blockquote> | 6309 * <i>e<sub>3</sub></i>.</blockquote> |
| 6125 */ | 6310 */ |
| 6126 Object visitAssignmentExpression(AssignmentExpression node) { | 6311 Object visitAssignmentExpression(AssignmentExpression node) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 6151 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 6336 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { |
| 6152 recordPropagatedType(node, propagatedType); | 6337 recordPropagatedType(node, propagatedType); |
| 6153 } | 6338 } |
| 6154 } | 6339 } |
| 6155 } | 6340 } |
| 6156 return null; | 6341 return null; |
| 6157 } | 6342 } |
| 6158 | 6343 |
| 6159 /** | 6344 /** |
| 6160 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo
gical boolean | 6345 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo
gical boolean |
| 6161 * expression is {@code bool}.</blockquote> | 6346 * expression is `bool`.</blockquote> |
| 6162 * <p> | 6347 * |
| 6163 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of
the form | 6348 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of
the form |
| 6164 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 6349 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
| 6165 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i
>super op | 6350 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i
>super op |
| 6166 * e<sub>2</sub></i> is equivalent to the method invocation | 6351 * e<sub>2</sub></i> is equivalent to the method invocation |
| 6167 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 6352 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
| 6168 * <p> | 6353 * |
| 6169 * The Dart Language Specification, 12.22: <blockquote>The static type of an e
quality expression | 6354 * The Dart Language Specification, 12.22: <blockquote>The static type of an e
quality expression |
| 6170 * is {@code bool}.</blockquote> | 6355 * is `bool`.</blockquote> |
| 6171 * <p> | 6356 * |
| 6172 * The Dart Language Specification, 12.23: <blockquote>A relational expression
of the form | 6357 * The Dart Language Specification, 12.23: <blockquote>A relational expression
of the form |
| 6173 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 6358 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
| 6174 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A relational expression of the form
<i>super op | 6359 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A relational expression of the form
<i>super op |
| 6175 * e<sub>2</sub></i> is equivalent to the method invocation | 6360 * e<sub>2</sub></i> is equivalent to the method invocation |
| 6176 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 6361 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
| 6177 * <p> | 6362 * |
| 6178 * The Dart Language Specification, 12.24: <blockquote>A shift expression of t
he form | 6363 * The Dart Language Specification, 12.24: <blockquote>A shift expression of t
he form |
| 6179 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 6364 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
| 6180 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A shift expression of the form <i>s
uper op | 6365 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A shift expression of the form <i>s
uper op |
| 6181 * e<sub>2</sub></i> is equivalent to the method invocation | 6366 * e<sub>2</sub></i> is equivalent to the method invocation |
| 6182 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 6367 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
| 6183 * <p> | 6368 * |
| 6184 * The Dart Language Specification, 12.25: <blockquote>An additive expression
of the form | 6369 * The Dart Language Specification, 12.25: <blockquote>An additive expression
of the form |
| 6185 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 6370 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
| 6186 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. An additive expression of the form
<i>super op | 6371 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. An additive expression of the form
<i>super op |
| 6187 * e<sub>2</sub></i> is equivalent to the method invocation | 6372 * e<sub>2</sub></i> is equivalent to the method invocation |
| 6188 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 6373 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
| 6189 * <p> | 6374 * |
| 6190 * The Dart Language Specification, 12.26: <blockquote>A multiplicative expres
sion of the form | 6375 * The Dart Language Specification, 12.26: <blockquote>A multiplicative expres
sion of the form |
| 6191 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 6376 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
| 6192 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the
form <i>super op | 6377 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the
form <i>super op |
| 6193 * e<sub>2</sub></i> is equivalent to the method invocation | 6378 * e<sub>2</sub></i> is equivalent to the method invocation |
| 6194 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 6379 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
| 6195 */ | 6380 */ |
| 6196 Object visitBinaryExpression(BinaryExpression node) { | 6381 Object visitBinaryExpression(BinaryExpression node) { |
| 6197 ExecutableElement staticMethodElement = node.staticElement; | 6382 ExecutableElement staticMethodElement = node.staticElement; |
| 6198 Type2 staticType = computeReturnType(staticMethodElement); | 6383 Type2 staticType = computeReturnType(staticMethodElement); |
| 6199 staticType = refineBinaryExpressionType(node, staticType); | 6384 staticType = refineBinaryExpressionType(node, staticType); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 6224 */ | 6409 */ |
| 6225 Object visitCascadeExpression(CascadeExpression node) { | 6410 Object visitCascadeExpression(CascadeExpression node) { |
| 6226 recordStaticType(node, getStaticType(node.target)); | 6411 recordStaticType(node, getStaticType(node.target)); |
| 6227 recordPropagatedType(node, getPropagatedType(node.target)); | 6412 recordPropagatedType(node, getPropagatedType(node.target)); |
| 6228 return null; | 6413 return null; |
| 6229 } | 6414 } |
| 6230 | 6415 |
| 6231 /** | 6416 /** |
| 6232 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr
ession <i>c</i> of | 6417 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr
ession <i>c</i> of |
| 6233 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... | 6418 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... |
| 6234 * <p> | 6419 * |
| 6235 * It is a static type warning if the type of e<sub>1</sub> may not be assigne
d to {@code bool}. | 6420 * It is a static type warning if the type of e<sub>1</sub> may not be assigne
d to `bool`. |
| 6236 * <p> | 6421 * |
| 6237 * The static type of <i>c</i> is the least upper bound of the static type of
<i>e<sub>2</sub></i> | 6422 * The static type of <i>c</i> is the least upper bound of the static type of
<i>e<sub>2</sub></i> |
| 6238 * and the static type of <i>e<sub>3</sub></i>.</blockquote> | 6423 * and the static type of <i>e<sub>3</sub></i>.</blockquote> |
| 6239 */ | 6424 */ |
| 6240 Object visitConditionalExpression(ConditionalExpression node) { | 6425 Object visitConditionalExpression(ConditionalExpression node) { |
| 6241 Type2 staticThenType = getStaticType(node.thenExpression); | 6426 Type2 staticThenType = getStaticType(node.thenExpression); |
| 6242 Type2 staticElseType = getStaticType(node.elseExpression); | 6427 Type2 staticElseType = getStaticType(node.elseExpression); |
| 6243 if (staticThenType == null) { | 6428 if (staticThenType == null) { |
| 6244 staticThenType = _dynamicType; | 6429 staticThenType = _dynamicType; |
| 6245 } | 6430 } |
| 6246 if (staticElseType == null) { | 6431 if (staticElseType == null) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 6271 /** | 6456 /** |
| 6272 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit
eral double is | 6457 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit
eral double is |
| 6273 * double.</blockquote> | 6458 * double.</blockquote> |
| 6274 */ | 6459 */ |
| 6275 Object visitDoubleLiteral(DoubleLiteral node) { | 6460 Object visitDoubleLiteral(DoubleLiteral node) { |
| 6276 recordStaticType(node, _typeProvider.doubleType); | 6461 recordStaticType(node, _typeProvider.doubleType); |
| 6277 return null; | 6462 return null; |
| 6278 } | 6463 } |
| 6279 Object visitFunctionDeclaration(FunctionDeclaration node) { | 6464 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 6280 FunctionExpression function = node.functionExpression; | 6465 FunctionExpression function = node.functionExpression; |
| 6281 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; | 6466 ExecutableElementImpl functionElement = node.element as ExecutableElementImp
l; |
| 6282 setTypeInformation(functionType, computeReturnType2(node), function.paramete
rs); | 6467 functionElement.returnType = computeReturnType2(node); |
| 6468 FunctionTypeImpl functionType = functionElement.type as FunctionTypeImpl; |
| 6469 setTypeInformation(functionType, function.parameters); |
| 6283 recordStaticType(function, functionType); | 6470 recordStaticType(function, functionType); |
| 6284 return null; | 6471 return null; |
| 6285 } | 6472 } |
| 6286 | 6473 |
| 6287 /** | 6474 /** |
| 6288 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun
ction literal of the | 6475 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun
ction literal of the |
| 6289 * form <i>(T<sub>1</sub> a<sub>1</sub>, …, T<sub>n</sub> a<sub>n</sub>
, \[T<sub>n+1</sub> | 6476 * form <i>(T<sub>1</sub> a<sub>1</sub>, …, T<sub>n</sub> a<sub>n</sub>
, \[T<sub>n+1</sub> |
| 6290 * x<sub>n+1</sub> = d1, …, T<sub>n+k</sub> x<sub>n+k</sub> = dk\]) =>
e</i> is | 6477 * x<sub>n+1</sub> = d1, …, T<sub>n+k</sub> x<sub>n+k</sub> = dk\]) =>
e</i> is |
| 6291 * <i>(T<sub>1</sub>, …, Tn, \[T<sub>n+1</sub> x<sub>n+1</sub>, &hellip
;, T<sub>n+k</sub> | 6478 * <i>(T<sub>1</sub>, …, Tn, \[T<sub>n+1</sub> x<sub>n+1</sub>, &hellip
;, T<sub>n+k</sub> |
| 6292 * x<sub>n+k</sub>\]) → T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is
the static type of | 6479 * x<sub>n+k</sub>\]) → T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is
the static type of |
| 6293 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not
specified, it is | 6480 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not
specified, it is |
| 6294 * considered to have been specified as dynamic. | 6481 * considered to have been specified as dynamic. |
| 6295 * <p> | 6482 * |
| 6296 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, | 6483 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, |
| 6297 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip
;, T<sub>n+k</sub> | 6484 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip
;, T<sub>n+k</sub> |
| 6298 * x<sub>n+k</sub> : dk}) => e</i> is <i>(T<sub>1</sub>, …, T<sub>n</su
b>, {T<sub>n+1</sub> | 6485 * x<sub>n+k</sub> : dk}) => e</i> is <i>(T<sub>1</sub>, …, T<sub>n</su
b>, {T<sub>n+1</sub> |
| 6299 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>}) → T<sub>0
</sub></i>, where | 6486 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>}) → T<sub>0
</sub></i>, where |
| 6300 * <i>T<sub>0</sub></i> is the static type of <i>e</i>. In any case where <i>T
<sub>i</sub>, 1 | 6487 * <i>T<sub>0</sub></i> is the static type of <i>e</i>. In any case where <i>T
<sub>i</sub>, 1 |
| 6301 * <= i <= n</i>, is not specified, it is considered to have been specif
ied as dynamic. | 6488 * <= i <= n</i>, is not specified, it is considered to have been specif
ied as dynamic. |
| 6302 * <p> | 6489 * |
| 6303 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, | 6490 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, |
| 6304 * T<sub>n</sub> a<sub>n</sub>, \[T<sub>n+1</sub> x<sub>n+1</sub> = d1, &helli
p;, T<sub>n+k</sub> | 6491 * T<sub>n</sub> a<sub>n</sub>, \[T<sub>n+1</sub> x<sub>n+1</sub> = d1, &helli
p;, T<sub>n+k</sub> |
| 6305 * x<sub>n+k</sub> = dk\]) {s}</i> is <i>(T<sub>1</sub>, …, T<sub>n</su
b>, \[T<sub>n+1</sub> | 6492 * x<sub>n+k</sub> = dk\]) {s}</i> is <i>(T<sub>1</sub>, …, T<sub>n</su
b>, \[T<sub>n+1</sub> |
| 6306 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>\]) → dynami
c</i>. In any case | 6493 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>\]) → dynami
c</i>. In any case |
| 6307 * where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not specified, it is cons
idered to have been | 6494 * where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not specified, it is cons
idered to have been |
| 6308 * specified as dynamic. | 6495 * specified as dynamic. |
| 6309 * <p> | 6496 * |
| 6310 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, | 6497 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, |
| 6311 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip
;, T<sub>n+k</sub> | 6498 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip
;, T<sub>n+k</sub> |
| 6312 * x<sub>n+k</sub> : dk}) {s}</i> is <i>(T<sub>1</sub>, …, T<sub>n</sub
>, {T<sub>n+1</sub> | 6499 * x<sub>n+k</sub> : dk}) {s}</i> is <i>(T<sub>1</sub>, …, T<sub>n</sub
>, {T<sub>n+1</sub> |
| 6313 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>}) → dynamic
</i>. In any case | 6500 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>}) → dynamic
</i>. In any case |
| 6314 * where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not specified, it is cons
idered to have been | 6501 * where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not specified, it is cons
idered to have been |
| 6315 * specified as dynamic.</blockquote> | 6502 * specified as dynamic.</blockquote> |
| 6316 */ | 6503 */ |
| 6317 Object visitFunctionExpression(FunctionExpression node) { | 6504 Object visitFunctionExpression(FunctionExpression node) { |
| 6318 if (node.parent is FunctionDeclaration) { | 6505 if (node.parent is FunctionDeclaration) { |
| 6319 return null; | 6506 return null; |
| 6320 } | 6507 } |
| 6508 ExecutableElementImpl functionElement = node.element as ExecutableElementImp
l; |
| 6509 functionElement.returnType = computeReturnType3(node); |
| 6321 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; | 6510 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; |
| 6322 setTypeInformation(functionType, computeReturnType3(node), node.parameters); | 6511 setTypeInformation(functionType, node.parameters); |
| 6323 recordStaticType(node, functionType); | 6512 recordStaticType(node, functionType); |
| 6324 return null; | 6513 return null; |
| 6325 } | 6514 } |
| 6326 | 6515 |
| 6327 /** | 6516 /** |
| 6328 * The Dart Language Specification, 12.14.4: <blockquote>A function expression
invocation <i>i</i> | 6517 * The Dart Language Specification, 12.14.4: <blockquote>A function expression
invocation <i>i</i> |
| 6329 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, …, a<sub>n</sub>, x<sub
>n+1</sub>: | 6518 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, …, a<sub>n</sub>, x<sub
>n+1</sub>: |
| 6330 * a<sub>n+1</sub>, …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i>
e<sub>f</sub></i> is | 6519 * a<sub>n+1</sub>, …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i>
e<sub>f</sub></i> is |
| 6331 * an expression. | 6520 * an expression. |
| 6332 * <p> | 6521 * |
| 6333 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub>
</i> may not be | 6522 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub>
</i> may not be |
| 6334 * assigned to a function type. | 6523 * assigned to a function type. |
| 6335 * <p> | 6524 * |
| 6336 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic.
Otherwise the | 6525 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic.
Otherwise the |
| 6337 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot
e> | 6526 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot
e> |
| 6338 */ | 6527 */ |
| 6339 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 6528 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 6340 ExecutableElement staticMethodElement = node.staticElement; | 6529 ExecutableElement staticMethodElement = node.staticElement; |
| 6341 Type2 staticType = computeReturnType(staticMethodElement); | 6530 Type2 staticType = computeReturnType(staticMethodElement); |
| 6342 recordStaticType(node, staticType); | 6531 recordStaticType(node, staticType); |
| 6343 ExecutableElement propagatedMethodElement = node.element; | 6532 ExecutableElement propagatedMethodElement = node.element; |
| 6344 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6533 Type2 propagatedType = computeReturnType(propagatedMethodElement); |
| 6345 if (staticType == null) { | 6534 if (staticType == null) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6379 } | 6568 } |
| 6380 } | 6569 } |
| 6381 } | 6570 } |
| 6382 return null; | 6571 return null; |
| 6383 } | 6572 } |
| 6384 | 6573 |
| 6385 /** | 6574 /** |
| 6386 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a
new expression of | 6575 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a
new expression of |
| 6387 * either the form <i>new T.id(a<sub>1</sub>, …, a<sub>n</sub>)</i> or
the form <i>new | 6576 * either the form <i>new T.id(a<sub>1</sub>, …, a<sub>n</sub>)</i> or
the form <i>new |
| 6388 * T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> | 6577 * T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> |
| 6389 * <p> | 6578 * |
| 6390 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a
constant object | 6579 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a
constant object |
| 6391 * expression of either the form <i>const T.id(a<sub>1</sub>, …, a<sub>
n</sub>)</i> or the | 6580 * expression of either the form <i>const T.id(a<sub>1</sub>, …, a<sub>
n</sub>)</i> or the |
| 6392 * form <i>const T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>. </
blockquote> | 6581 * form <i>const T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>. </
blockquote> |
| 6393 */ | 6582 */ |
| 6394 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 6583 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 6395 recordStaticType(node, node.constructorName.type.type); | 6584 recordStaticType(node, node.constructorName.type.type); |
| 6396 ConstructorElement element = node.element; | 6585 ConstructorElement element = node.element; |
| 6397 if (element != null && "Element" == element.enclosingElement.name && "tag" =
= element.name) { | 6586 if (element != null && "Element" == element.enclosingElement.name && "tag" =
= element.name) { |
| 6398 LibraryElement library = element.library; | 6587 LibraryElement library = element.library; |
| 6399 if (isHtmlLibrary(library)) { | 6588 if (isHtmlLibrary(library)) { |
| 6400 Type2 returnType = getFirstArgumentAsType2(library, node.argumentList, _
HTML_ELEMENT_TO_CLASS_MAP); | 6589 Type2 returnType = getFirstArgumentAsType2(library, node.argumentList, _
HTML_ELEMENT_TO_CLASS_MAP); |
| 6401 if (returnType != null) { | 6590 if (returnType != null) { |
| 6402 recordPropagatedType(node, returnType); | 6591 recordPropagatedType(node, returnType); |
| 6403 } | 6592 } |
| 6404 } | 6593 } |
| 6405 } | 6594 } |
| 6406 return null; | 6595 return null; |
| 6407 } | 6596 } |
| 6408 | 6597 |
| 6409 /** | 6598 /** |
| 6410 * The Dart Language Specification, 12.3: <blockquote>The static type of an in
teger literal is{@code int}.</blockquote> | 6599 * The Dart Language Specification, 12.3: <blockquote>The static type of an in
teger literal is`int`.</blockquote> |
| 6411 */ | 6600 */ |
| 6412 Object visitIntegerLiteral(IntegerLiteral node) { | 6601 Object visitIntegerLiteral(IntegerLiteral node) { |
| 6413 recordStaticType(node, _typeProvider.intType); | 6602 recordStaticType(node, _typeProvider.intType); |
| 6414 return null; | 6603 return null; |
| 6415 } | 6604 } |
| 6416 | 6605 |
| 6417 /** | 6606 /** |
| 6418 * The Dart Language Specification, 12.31: <blockquote>It is a static warning
if <i>T</i> does not | 6607 * The Dart Language Specification, 12.31: <blockquote>It is a static warning
if <i>T</i> does not |
| 6419 * denote a type available in the current lexical scope. | 6608 * denote a type available in the current lexical scope. |
| 6420 * <p> | 6609 * |
| 6421 * The static type of an is-expression is {@code bool}.</blockquote> | 6610 * The static type of an is-expression is `bool`.</blockquote> |
| 6422 */ | 6611 */ |
| 6423 Object visitIsExpression(IsExpression node) { | 6612 Object visitIsExpression(IsExpression node) { |
| 6424 recordStaticType(node, _typeProvider.boolType); | 6613 recordStaticType(node, _typeProvider.boolType); |
| 6425 return null; | 6614 return null; |
| 6426 } | 6615 } |
| 6427 | 6616 |
| 6428 /** | 6617 /** |
| 6429 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis
t literal of the | 6618 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis
t literal of the |
| 6430 * form <i><b>const</b> <E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i
> or the form | 6619 * form <i><b>const</b> <E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i
> or the form |
| 6431 * <i><E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is {@code List&l
t;E>}. The static | 6620 * <i><E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is `List<E>
;`. The static |
| 6432 * type a list literal of the form <i><b>const</b> \[e<sub>1</sub>, …,
e<sub>n</sub>\]</i> or | 6621 * type a list literal of the form <i><b>const</b> \[e<sub>1</sub>, …,
e<sub>n</sub>\]</i> or |
| 6433 * the form <i>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is {@code List&l
t;dynamic>}.</blockquote> | 6622 * the form <i>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is `List<dyna
mic>`.</blockquote> |
| 6434 */ | 6623 */ |
| 6435 Object visitListLiteral(ListLiteral node) { | 6624 Object visitListLiteral(ListLiteral node) { |
| 6436 Type2 staticType = _dynamicType; | 6625 Type2 staticType = _dynamicType; |
| 6437 TypeArgumentList typeArguments = node.typeArguments; | 6626 TypeArgumentList typeArguments = node.typeArguments; |
| 6438 if (typeArguments != null) { | 6627 if (typeArguments != null) { |
| 6439 NodeList<TypeName> arguments = typeArguments.arguments; | 6628 NodeList<TypeName> arguments = typeArguments.arguments; |
| 6440 if (arguments != null && arguments.length == 1) { | 6629 if (arguments != null && arguments.length == 1) { |
| 6441 TypeName argumentTypeName = arguments[0]; | 6630 TypeName argumentTypeName = arguments[0]; |
| 6442 Type2 argumentType = getType2(argumentTypeName); | 6631 Type2 argumentType = getType2(argumentTypeName); |
| 6443 if (argumentType != null) { | 6632 if (argumentType != null) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6465 recordPropagatedType(node, _typeProvider.listType.substitute5(<Type2> [p
ropagatedType])); | 6654 recordPropagatedType(node, _typeProvider.listType.substitute5(<Type2> [p
ropagatedType])); |
| 6466 } | 6655 } |
| 6467 } | 6656 } |
| 6468 return null; | 6657 return null; |
| 6469 } | 6658 } |
| 6470 | 6659 |
| 6471 /** | 6660 /** |
| 6472 * The Dart Language Specification, 12.7: <blockquote>The static type of a map
literal of the form | 6661 * The Dart Language Specification, 12.7: <blockquote>The static type of a map
literal of the form |
| 6473 * <i><b>const</b> <String, V> {k<sub>1</sub>:e<sub>1</sub>, …, | 6662 * <i><b>const</b> <String, V> {k<sub>1</sub>:e<sub>1</sub>, …, |
| 6474 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i><String, V> {k<sub>1<
/sub>:e<sub>1</sub>, | 6663 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i><String, V> {k<sub>1<
/sub>:e<sub>1</sub>, |
| 6475 * …, k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map<String, V>}.
The static type a | 6664 * …, k<sub>n</sub>:e<sub>n</sub>}</i> is `Map<String, V>`. The s
tatic type a |
| 6476 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell
ip;, | 6665 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell
ip;, |
| 6477 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub
>, …, | 6666 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub
>, …, |
| 6478 * k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map<String, dynamic>}. | 6667 * k<sub>n</sub>:e<sub>n</sub>}</i> is `Map<String, dynamic>`. |
| 6479 * <p> | 6668 * |
| 6480 * It is a compile-time error if the first type argument to a map literal is n
ot | 6669 * It is a compile-time error if the first type argument to a map literal is n
ot |
| 6481 * <i>String</i>.</blockquote> | 6670 * <i>String</i>.</blockquote> |
| 6482 */ | 6671 */ |
| 6483 Object visitMapLiteral(MapLiteral node) { | 6672 Object visitMapLiteral(MapLiteral node) { |
| 6484 Type2 staticKeyType = _dynamicType; | 6673 Type2 staticKeyType = _dynamicType; |
| 6485 Type2 staticValueType = _dynamicType; | 6674 Type2 staticValueType = _dynamicType; |
| 6486 TypeArgumentList typeArguments = node.typeArguments; | 6675 TypeArgumentList typeArguments = node.typeArguments; |
| 6487 if (typeArguments != null) { | 6676 if (typeArguments != null) { |
| 6488 NodeList<TypeName> arguments = typeArguments.arguments; | 6677 NodeList<TypeName> arguments = typeArguments.arguments; |
| 6489 if (arguments != null && arguments.length == 2) { | 6678 if (arguments != null && arguments.length == 2) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6539 recordPropagatedType(node, _typeProvider.mapType.substitute5(<Type2> [pr
opagatedKeyType, propagatedValueType])); | 6728 recordPropagatedType(node, _typeProvider.mapType.substitute5(<Type2> [pr
opagatedKeyType, propagatedValueType])); |
| 6540 } | 6729 } |
| 6541 } | 6730 } |
| 6542 return null; | 6731 return null; |
| 6543 } | 6732 } |
| 6544 | 6733 |
| 6545 /** | 6734 /** |
| 6546 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in
vocation <i>i</i> | 6735 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in
vocation <i>i</i> |
| 6547 * has the form <i>o.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>
: a<sub>n+1</sub>, | 6736 * has the form <i>o.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>
: a<sub>n+1</sub>, |
| 6548 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. | 6737 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. |
| 6549 * <p> | 6738 * |
| 6550 * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if
<i>T</i> does not | 6739 * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if
<i>T</i> does not |
| 6551 * have an accessible instance member named <i>m</i>. If <i>T.m</i> exists, it
is a static warning | 6740 * have an accessible instance member named <i>m</i>. If <i>T.m</i> exists, it
is a static warning |
| 6552 * if the type <i>F</i> of <i>T.m</i> may not be assigned to a function type. | 6741 * if the type <i>F</i> of <i>T.m</i> may not be assigned to a function type. |
| 6553 * <p> | 6742 * |
| 6554 * If <i>T.m</i> does not exist, or if <i>F</i> is not a function type, the st
atic type of | 6743 * If <i>T.m</i> does not exist, or if <i>F</i> is not a function type, the st
atic type of |
| 6555 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared
return type of | 6744 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared
return type of |
| 6556 * <i>F</i>.</blockquote> | 6745 * <i>F</i>.</blockquote> |
| 6557 * <p> | 6746 * |
| 6558 * The Dart Language Specification, 11.15.3: <blockquote>A static method invoc
ation <i>i</i> has | 6747 * The Dart Language Specification, 11.15.3: <blockquote>A static method invoc
ation <i>i</i> has |
| 6559 * the form <i>C.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>: a<
sub>n+1</sub>, | 6748 * the form <i>C.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>: a<
sub>n+1</sub>, |
| 6560 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. | 6749 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. |
| 6561 * <p> | 6750 * |
| 6562 * It is a static type warning if the type <i>F</i> of <i>C.m</i> may not be a
ssigned to a | 6751 * It is a static type warning if the type <i>F</i> of <i>C.m</i> may not be a
ssigned to a |
| 6563 * function type. | 6752 * function type. |
| 6564 * <p> | 6753 * |
| 6565 * If <i>F</i> is not a function type, or if <i>C.m</i> does not exist, the st
atic type of i is | 6754 * If <i>F</i> is not a function type, or if <i>C.m</i> does not exist, the st
atic type of i is |
| 6566 * dynamic. Otherwise the static type of <i>i</i> is the declared return type
of | 6755 * dynamic. Otherwise the static type of <i>i</i> is the declared return type
of |
| 6567 * <i>F</i>.</blockquote> | 6756 * <i>F</i>.</blockquote> |
| 6568 * <p> | 6757 * |
| 6569 * The Dart Language Specification, 11.15.4: <blockquote>A super method invoca
tion <i>i</i> has | 6758 * The Dart Language Specification, 11.15.4: <blockquote>A super method invoca
tion <i>i</i> has |
| 6570 * the form <i>super.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>
: a<sub>n+1</sub>, | 6759 * the form <i>super.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>
: a<sub>n+1</sub>, |
| 6571 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. | 6760 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. |
| 6572 * <p> | 6761 * |
| 6573 * It is a static type warning if <i>S</i> does not have an accessible instanc
e member named m. If | 6762 * It is a static type warning if <i>S</i> does not have an accessible instanc
e member named m. If |
| 6574 * <i>S.m</i> exists, it is a static warning if the type <i>F</i> of <i>S.m</i
> may not be | 6763 * <i>S.m</i> exists, it is a static warning if the type <i>F</i> of <i>S.m</i
> may not be |
| 6575 * assigned to a function type. | 6764 * assigned to a function type. |
| 6576 * <p> | 6765 * |
| 6577 * If <i>S.m</i> does not exist, or if <i>F</i> is not a function type, the st
atic type of | 6766 * If <i>S.m</i> does not exist, or if <i>F</i> is not a function type, the st
atic type of |
| 6578 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared
return type of | 6767 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared
return type of |
| 6579 * <i>F</i>.</blockquote> | 6768 * <i>F</i>.</blockquote> |
| 6580 */ | 6769 */ |
| 6581 Object visitMethodInvocation(MethodInvocation node) { | 6770 Object visitMethodInvocation(MethodInvocation node) { |
| 6582 SimpleIdentifier methodNameNode = node.methodName; | 6771 SimpleIdentifier methodNameNode = node.methodName; |
| 6583 Element staticMethodElement = methodNameNode.staticElement; | 6772 Element staticMethodElement = methodNameNode.staticElement; |
| 6584 if (staticMethodElement == null) { | 6773 if (staticMethodElement == null) { |
| 6585 staticMethodElement = methodNameNode.element; | 6774 staticMethodElement = methodNameNode.element; |
| 6586 } | 6775 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6655 return null; | 6844 return null; |
| 6656 } | 6845 } |
| 6657 Object visitNamedExpression(NamedExpression node) { | 6846 Object visitNamedExpression(NamedExpression node) { |
| 6658 Expression expression = node.expression; | 6847 Expression expression = node.expression; |
| 6659 recordStaticType(node, getStaticType(expression)); | 6848 recordStaticType(node, getStaticType(expression)); |
| 6660 recordPropagatedType(node, getPropagatedType(expression)); | 6849 recordPropagatedType(node, getPropagatedType(expression)); |
| 6661 return null; | 6850 return null; |
| 6662 } | 6851 } |
| 6663 | 6852 |
| 6664 /** | 6853 /** |
| 6665 * The Dart Language Specification, 12.2: <blockquote>The static type of {@cod
e null} is bottom. | 6854 * The Dart Language Specification, 12.2: <blockquote>The static type of `null
` is bottom. |
| 6666 * </blockquote> | 6855 * </blockquote> |
| 6667 */ | 6856 */ |
| 6668 Object visitNullLiteral(NullLiteral node) { | 6857 Object visitNullLiteral(NullLiteral node) { |
| 6669 recordStaticType(node, _typeProvider.bottomType); | 6858 recordStaticType(node, _typeProvider.bottomType); |
| 6670 return null; | 6859 return null; |
| 6671 } | 6860 } |
| 6672 Object visitParenthesizedExpression(ParenthesizedExpression node) { | 6861 Object visitParenthesizedExpression(ParenthesizedExpression node) { |
| 6673 Expression expression = node.expression; | 6862 Expression expression = node.expression; |
| 6674 recordStaticType(node, getStaticType(expression)); | 6863 recordStaticType(node, getStaticType(expression)); |
| 6675 recordPropagatedType(node, getPropagatedType(expression)); | 6864 recordPropagatedType(node, getPropagatedType(expression)); |
| 6676 return null; | 6865 return null; |
| 6677 } | 6866 } |
| 6678 | 6867 |
| 6679 /** | 6868 /** |
| 6680 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of
the form | 6869 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of
the form |
| 6681 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r =
v; v = r + 1; | 6870 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r =
v; v = r + 1; |
| 6682 * return r}()</i>. | 6871 * return r}()</i>. |
| 6683 * <p> | 6872 * |
| 6684 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r
= C.v; C.v = r + 1; | 6873 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r
= C.v; C.v = r + 1; |
| 6685 * return r}()</i>. | 6874 * return r}()</i>. |
| 6686 * <p> | 6875 * |
| 6687 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var
r = x.v; x.v = r + | 6876 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var
r = x.v; x.v = r + |
| 6688 * 1; return r}(e1)</i>. | 6877 * 1; return r}(e1)</i>. |
| 6689 * <p> | 6878 * |
| 6690 * A postfix expression of the form <i>e1\[e2\]++</i> is equivalent to <i>(a,
i){var r = a\[i\]; a\[i\] | 6879 * A postfix expression of the form <i>e1\[e2\]++</i> is equivalent to <i>(a,
i){var r = a\[i\]; a\[i\] |
| 6691 * = r + 1; return r}(e1, e2)</i> | 6880 * = r + 1; return r}(e1, e2)</i> |
| 6692 * <p> | 6881 * |
| 6693 * A postfix expression of the form <i>v--</i>, where <i>v</i> is an identifie
r, is equivalent to | 6882 * A postfix expression of the form <i>v--</i>, where <i>v</i> is an identifie
r, is equivalent to |
| 6694 * <i>(){var r = v; v = r - 1; return r}()</i>. | 6883 * <i>(){var r = v; v = r - 1; return r}()</i>. |
| 6695 * <p> | 6884 * |
| 6696 * A postfix expression of the form <i>C.v--</i> is equivalent to <i>(){var r
= C.v; C.v = r - 1; | 6885 * A postfix expression of the form <i>C.v--</i> is equivalent to <i>(){var r
= C.v; C.v = r - 1; |
| 6697 * return r}()</i>. | 6886 * return r}()</i>. |
| 6698 * <p> | 6887 * |
| 6699 * A postfix expression of the form <i>e1.v--</i> is equivalent to <i>(x){var
r = x.v; x.v = r - | 6888 * A postfix expression of the form <i>e1.v--</i> is equivalent to <i>(x){var
r = x.v; x.v = r - |
| 6700 * 1; return r}(e1)</i>. | 6889 * 1; return r}(e1)</i>. |
| 6701 * <p> | 6890 * |
| 6702 * A postfix expression of the form <i>e1\[e2\]--</i> is equivalent to <i>(a,
i){var r = a\[i\]; a\[i\] | 6891 * A postfix expression of the form <i>e1\[e2\]--</i> is equivalent to <i>(a,
i){var r = a\[i\]; a\[i\] |
| 6703 * = r - 1; return r}(e1, e2)</i></blockquote> | 6892 * = r - 1; return r}(e1, e2)</i></blockquote> |
| 6704 */ | 6893 */ |
| 6705 Object visitPostfixExpression(PostfixExpression node) { | 6894 Object visitPostfixExpression(PostfixExpression node) { |
| 6706 Expression operand = node.operand; | 6895 Expression operand = node.operand; |
| 6707 Type2 staticType = getStaticType(operand); | 6896 Type2 staticType = getStaticType(operand); |
| 6708 sc.TokenType operator = node.operator.type; | 6897 sc.TokenType operator = node.operator.type; |
| 6709 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, sc.
TokenType.PLUS_PLUS)) { | 6898 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, sc.
TokenType.PLUS_PLUS)) { |
| 6710 Type2 intType = _typeProvider.intType; | 6899 Type2 intType = _typeProvider.intType; |
| 6711 if (identical(getStaticType(node.operand), intType)) { | 6900 if (identical(getStaticType(node.operand), intType)) { |
| 6712 staticType = intType; | 6901 staticType = intType; |
| 6713 } | 6902 } |
| 6714 } | 6903 } |
| 6715 recordStaticType(node, staticType); | 6904 recordStaticType(node, staticType); |
| 6716 recordPropagatedType(node, getPropagatedType(operand)); | 6905 recordPropagatedType(node, getPropagatedType(operand)); |
| 6717 return null; | 6906 return null; |
| 6718 } | 6907 } |
| 6719 | 6908 |
| 6720 /** | 6909 /** |
| 6721 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}. | 6910 * See [visitSimpleIdentifier]. |
| 6722 */ | 6911 */ |
| 6723 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 6912 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 6724 SimpleIdentifier prefixedIdentifier = node.identifier; | 6913 SimpleIdentifier prefixedIdentifier = node.identifier; |
| 6725 Element element = prefixedIdentifier.element; | 6914 Element element = prefixedIdentifier.element; |
| 6726 Type2 staticType = _dynamicType; | 6915 Type2 staticType = _dynamicType; |
| 6727 if (element is ClassElement) { | 6916 if (element is ClassElement) { |
| 6728 if (isNotTypeLiteral(node)) { | 6917 if (isNotTypeLiteral(node)) { |
| 6729 staticType = ((element as ClassElement)).type; | 6918 staticType = ((element as ClassElement)).type; |
| 6730 } else { | 6919 } else { |
| 6731 staticType = _typeProvider.typeType; | 6920 staticType = _typeProvider.typeType; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6780 } | 6969 } |
| 6781 } | 6970 } |
| 6782 } | 6971 } |
| 6783 return null; | 6972 return null; |
| 6784 } | 6973 } |
| 6785 | 6974 |
| 6786 /** | 6975 /** |
| 6787 * The Dart Language Specification, 12.13: <blockquote> Property extraction al
lows for a member of | 6976 * The Dart Language Specification, 12.13: <blockquote> Property extraction al
lows for a member of |
| 6788 * an object to be concisely extracted from the object. If <i>o</i> is an obje
ct, and if <i>m</i> | 6977 * an object to be concisely extracted from the object. If <i>o</i> is an obje
ct, and if <i>m</i> |
| 6789 * is the name of a method member of <i>o</i>, then | 6978 * is the name of a method member of <i>o</i>, then |
| 6790 * <ul> | 6979 * |
| 6791 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, …,
r<sub>n</sub>, | 6980 * * <i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, …, r
<sub>n</sub>, |
| 6792 * {p<sub>1</sub> : d<sub>1</sub>, …, p<sub>k</sub> : d<sub>k</sub>}){r
eturn | 6981 * {p<sub>1</sub> : d<sub>1</sub>, …, p<sub>k</sub> : d<sub>k</sub>}){r
eturn |
| 6793 * o.m(r<sub>1</sub>, …, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, &
hellip;, | 6982 * o.m(r<sub>1</sub>, …, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, &
hellip;, |
| 6794 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i>
r<sub>1</sub>, | 6983 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i>
r<sub>1</sub>, |
| 6795 * …, r<sub>n</sub></i>, and named parameters <i>p<sub>1</sub> …
p<sub>k</sub></i> | 6984 * …, r<sub>n</sub></i>, and named parameters <i>p<sub>1</sub> …
p<sub>k</sub></i> |
| 6796 * with defaults <i>d<sub>1</sub>, …, d<sub>k</sub></i>.</li> | 6985 * with defaults <i>d<sub>1</sub>, …, d<sub>k</sub></i>. |
| 6797 * <li><i>(r<sub>1</sub>, …, r<sub>n</sub>, \[p<sub>1</sub> = d<sub>1</
sub>, …, | 6986 * * <i>(r<sub>1</sub>, …, r<sub>n</sub>, \[p<sub>1</sub> = d<sub>1</su
b>, …, |
| 6798 * p<sub>k</sub> = d<sub>k</sub>\]){return o.m(r<sub>1</sub>, …, r<sub>
n</sub>, | 6987 * p<sub>k</sub> = d<sub>k</sub>\]){return o.m(r<sub>1</sub>, …, r<sub>
n</sub>, |
| 6799 * p<sub>1</sub>, …, p<sub>k</sub>);}</i> if <i>m</i> has required para
meters | 6988 * p<sub>1</sub>, …, p<sub>k</sub>);}</i> if <i>m</i> has required para
meters |
| 6800 * <i>r<sub>1</sub>, …, r<sub>n</sub></i>, and optional positional para
meters | 6989 * <i>r<sub>1</sub>, …, r<sub>n</sub></i>, and optional positional para
meters |
| 6801 * <i>p<sub>1</sub> … p<sub>k</sub></i> with defaults <i>d<sub>1</sub>,
…, | 6990 * <i>p<sub>1</sub> … p<sub>k</sub></i> with defaults <i>d<sub>1</sub>,
…, |
| 6802 * d<sub>k</sub></i>.</li> | 6991 * d<sub>k</sub></i>. |
| 6803 * </ul> | 6992 * |
| 6804 * Otherwise, if <i>m</i> is the name of a getter member of <i>o</i> (declared
implicitly or | 6993 * Otherwise, if <i>m</i> is the name of a getter member of <i>o</i> (declared
implicitly or |
| 6805 * explicitly) then <i>o.m</i> evaluates to the result of invoking the getter.
</blockquote> | 6994 * explicitly) then <i>o.m</i> evaluates to the result of invoking the getter.
</blockquote> |
| 6806 * <p> | 6995 * |
| 6807 * The Dart Language Specification, 12.17: <blockquote> ... a getter invocatio
n <i>i</i> of the | 6996 * The Dart Language Specification, 12.17: <blockquote> ... a getter invocatio
n <i>i</i> of the |
| 6808 * form <i>e.m</i> ... | 6997 * form <i>e.m</i> ... |
| 6809 * <p> | 6998 * |
| 6810 * Let <i>T</i> be the static type of <i>e</i>. It is a static type warning if
<i>T</i> does not | 6999 * Let <i>T</i> be the static type of <i>e</i>. It is a static type warning if
<i>T</i> does not |
| 6811 * have a getter named <i>m</i>. | 7000 * have a getter named <i>m</i>. |
| 6812 * <p> | 7001 * |
| 6813 * The static type of <i>i</i> is the declared return type of <i>T.m</i>, if <
i>T.m</i> exists; | 7002 * The static type of <i>i</i> is the declared return type of <i>T.m</i>, if <
i>T.m</i> exists; |
| 6814 * otherwise the static type of <i>i</i> is dynamic. | 7003 * otherwise the static type of <i>i</i> is dynamic. |
| 6815 * <p> | 7004 * |
| 6816 * ... a getter invocation <i>i</i> of the form <i>C.m</i> ... | 7005 * ... a getter invocation <i>i</i> of the form <i>C.m</i> ... |
| 6817 * <p> | 7006 * |
| 6818 * It is a static warning if there is no class <i>C</i> in the enclosing lexic
al scope of | 7007 * It is a static warning if there is no class <i>C</i> in the enclosing lexic
al scope of |
| 6819 * <i>i</i>, or if <i>C</i> does not declare, implicitly or explicitly, a gett
er named <i>m</i>. | 7008 * <i>i</i>, or if <i>C</i> does not declare, implicitly or explicitly, a gett
er named <i>m</i>. |
| 6820 * <p> | 7009 * |
| 6821 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it
exists or dynamic | 7010 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it
exists or dynamic |
| 6822 * otherwise. | 7011 * otherwise. |
| 6823 * <p> | 7012 * |
| 6824 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m
</i> is an | 7013 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m
</i> is an |
| 6825 * identifier ... | 7014 * identifier ... |
| 6826 * <p> | 7015 * |
| 6827 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block
quote> | 7016 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block
quote> |
| 6828 */ | 7017 */ |
| 6829 Object visitPropertyAccess(PropertyAccess node) { | 7018 Object visitPropertyAccess(PropertyAccess node) { |
| 6830 SimpleIdentifier propertyName = node.propertyName; | 7019 SimpleIdentifier propertyName = node.propertyName; |
| 6831 Element element = propertyName.element; | 7020 Element element = propertyName.element; |
| 6832 Type2 staticType = _dynamicType; | 7021 Type2 staticType = _dynamicType; |
| 6833 if (element is MethodElement) { | 7022 if (element is MethodElement) { |
| 6834 staticType = ((element as MethodElement)).type; | 7023 staticType = ((element as MethodElement)).type; |
| 6835 } else if (element is PropertyAccessorElement) { | 7024 } else if (element is PropertyAccessorElement) { |
| 6836 staticType = getType((element as PropertyAccessorElement), node.target !=
null ? getStaticType(node.target) : null); | 7025 staticType = getType((element as PropertyAccessorElement), node.target !=
null ? getStaticType(node.target) : null); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6850 * bottom.</blockquote> | 7039 * bottom.</blockquote> |
| 6851 */ | 7040 */ |
| 6852 Object visitRethrowExpression(RethrowExpression node) { | 7041 Object visitRethrowExpression(RethrowExpression node) { |
| 6853 recordStaticType(node, _typeProvider.bottomType); | 7042 recordStaticType(node, _typeProvider.bottomType); |
| 6854 return null; | 7043 return null; |
| 6855 } | 7044 } |
| 6856 | 7045 |
| 6857 /** | 7046 /** |
| 6858 * The Dart Language Specification, 12.30: <blockquote>Evaluation of an identi
fier expression | 7047 * The Dart Language Specification, 12.30: <blockquote>Evaluation of an identi
fier expression |
| 6859 * <i>e</i> of the form <i>id</i> proceeds as follows: | 7048 * <i>e</i> of the form <i>id</i> proceeds as follows: |
| 6860 * <p> | 7049 * |
| 6861 * Let <i>d</i> be the innermost declaration in the enclosing lexical scope wh
ose name is | 7050 * Let <i>d</i> be the innermost declaration in the enclosing lexical scope wh
ose name is |
| 6862 * <i>id</i>. If no such declaration exists in the lexical scope, let <i>d</i>
be the declaration | 7051 * <i>id</i>. If no such declaration exists in the lexical scope, let <i>d</i>
be the declaration |
| 6863 * of the inherited member named <i>id</i> if it exists. | 7052 * of the inherited member named <i>id</i> if it exists. |
| 6864 * <ul> | 7053 * |
| 6865 * <li>If <i>d</i> is a class or type alias <i>T</i>, the value of <i>e</i> is
the unique instance | 7054 * * If <i>d</i> is a class or type alias <i>T</i>, the value of <i>e</i> is t
he unique instance |
| 6866 * of class {@code Type} reifying <i>T</i>. | 7055 * of class `Type` reifying <i>T</i>. |
| 6867 * <li>If <i>d</i> is a type parameter <i>T</i>, then the value of <i>e</i> is
the value of the | 7056 * * If <i>d</i> is a type parameter <i>T</i>, then the value of <i>e</i> is t
he value of the |
| 6868 * actual type argument corresponding to <i>T</i> that was passed to the gener
ative constructor | 7057 * actual type argument corresponding to <i>T</i> that was passed to the gener
ative constructor |
| 6869 * that created the current binding of this. We are assured that this is well
defined, because if | 7058 * that created the current binding of this. We are assured that this is well
defined, because if |
| 6870 * we were in a static member the reference to <i>T</i> would be a compile-tim
e error. | 7059 * we were in a static member the reference to <i>T</i> would be a compile-tim
e error. |
| 6871 * <li>If <i>d</i> is a library variable then: | 7060 * * If <i>d</i> is a library variable then: |
| 6872 * <ul> | 7061 * |
| 6873 * <li>If <i>d</i> is of one of the forms <i>var v = e<sub>i</sub>;</i>, <i>T
v = | 7062 * * If <i>d</i> is of one of the forms <i>var v = e<sub>i</sub>;</i>, <i>T v
= |
| 6874 * e<sub>i</sub>;</i>, <i>final v = e<sub>i</sub>;</i>, <i>final T v = e<sub>i
</sub>;</i>, and no | 7063 * e<sub>i</sub>;</i>, <i>final v = e<sub>i</sub>;</i>, <i>final T v = e<sub>i
</sub>;</i>, and no |
| 6875 * value has yet been stored into <i>v</i> then the initializer expression <i>
e<sub>i</sub></i> is | 7064 * value has yet been stored into <i>v</i> then the initializer expression <i>
e<sub>i</sub></i> is |
| 6876 * evaluated. If, during the evaluation of <i>e<sub>i</sub></i>, the getter fo
r <i>v</i> is | 7065 * evaluated. If, during the evaluation of <i>e<sub>i</sub></i>, the getter fo
r <i>v</i> is |
| 6877 * referenced, a CyclicInitializationError is thrown. If the evaluation succee
ded yielding an | 7066 * referenced, a CyclicInitializationError is thrown. If the evaluation succee
ded yielding an |
| 6878 * object <i>o</i>, let <i>r = o</i>, otherwise let <i>r = null</i>. In any ca
se, <i>r</i> is | 7067 * object <i>o</i>, let <i>r = o</i>, otherwise let <i>r = null</i>. In any ca
se, <i>r</i> is |
| 6879 * stored into <i>v</i>. The value of <i>e</i> is <i>r</i>. | 7068 * stored into <i>v</i>. The value of <i>e</i> is <i>r</i>. |
| 6880 * <li>If <i>d</i> is of one of the forms <i>const v = e;</i> or <i>const T v
= e;</i> the result | 7069 * * If <i>d</i> is of one of the forms <i>const v = e;</i> or <i>const T v =
e;</i> the result |
| 6881 * of the getter is the value of the compile time constant <i>e</i>. Otherwise | 7070 * of the getter is the value of the compile time constant <i>e</i>. Otherwise |
| 6882 * <li><i>e</i> evaluates to the current binding of <i>id</i>. | 7071 * * <i>e</i> evaluates to the current binding of <i>id</i>. |
| 6883 * </ul> | 7072 * |
| 6884 * <li>If <i>d</i> is a local variable or formal parameter then <i>e</i> evalu
ates to the current | 7073 * * If <i>d</i> is a local variable or formal parameter then <i>e</i> evaluat
es to the current |
| 6885 * binding of <i>id</i>. | 7074 * binding of <i>id</i>. |
| 6886 * <li>If <i>d</i> is a static method, top level function or local function th
en <i>e</i> | 7075 * * If <i>d</i> is a static method, top level function or local function then
<i>e</i> |
| 6887 * evaluates to the function defined by <i>d</i>. | 7076 * evaluates to the function defined by <i>d</i>. |
| 6888 * <li>If <i>d</i> is the declaration of a static variable or static getter de
clared in class | 7077 * * If <i>d</i> is the declaration of a static variable or static getter decl
ared in class |
| 6889 * <i>C</i>, then <i>e</i> is equivalent to the getter invocation <i>C.id</i>. | 7078 * <i>C</i>, then <i>e</i> is equivalent to the getter invocation <i>C.id</i>. |
| 6890 * <li>If <i>d</i> is the declaration of a top level getter, then <i>e</i> is
equivalent to the | 7079 * * If <i>d</i> is the declaration of a top level getter, then <i>e</i> is eq
uivalent to the |
| 6891 * getter invocation <i>id</i>. | 7080 * getter invocation <i>id</i>. |
| 6892 * <li>Otherwise, if <i>e</i> occurs inside a top level or static function (be
it function, | 7081 * * Otherwise, if <i>e</i> occurs inside a top level or static function (be i
t function, |
| 6893 * method, getter, or setter) or variable initializer, evaluation of e causes
a NoSuchMethodError | 7082 * method, getter, or setter) or variable initializer, evaluation of e causes
a NoSuchMethodError |
| 6894 * to be thrown. | 7083 * to be thrown. |
| 6895 * <li>Otherwise <i>e</i> is equivalent to the property extraction <i>this.id<
/i>. | 7084 * * Otherwise <i>e</i> is equivalent to the property extraction <i>this.id</i
>. |
| 6896 * </ul> | 7085 * |
| 6897 * </blockquote> | 7086 * </blockquote> |
| 6898 */ | 7087 */ |
| 6899 Object visitSimpleIdentifier(SimpleIdentifier node) { | 7088 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 6900 Element element = node.element; | 7089 Element element = node.element; |
| 6901 Type2 staticType = _dynamicType; | 7090 Type2 staticType = _dynamicType; |
| 6902 if (element is ClassElement) { | 7091 if (element is ClassElement) { |
| 6903 if (isNotTypeLiteral(node)) { | 7092 if (isNotTypeLiteral(node)) { |
| 6904 staticType = ((element as ClassElement)).type; | 7093 staticType = ((element as ClassElement)).type; |
| 6905 } else { | 7094 } else { |
| 6906 staticType = _typeProvider.typeType; | 7095 staticType = _typeProvider.typeType; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6924 } | 7113 } |
| 6925 recordStaticType(node, staticType); | 7114 recordStaticType(node, staticType); |
| 6926 Type2 propagatedType = _overrideManager.getType(element); | 7115 Type2 propagatedType = _overrideManager.getType(element); |
| 6927 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 7116 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
| 6928 recordPropagatedType(node, propagatedType); | 7117 recordPropagatedType(node, propagatedType); |
| 6929 } | 7118 } |
| 6930 return null; | 7119 return null; |
| 6931 } | 7120 } |
| 6932 | 7121 |
| 6933 /** | 7122 /** |
| 6934 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> | 7123 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is`String`.</blockquote> |
| 6935 */ | 7124 */ |
| 6936 Object visitSimpleStringLiteral(SimpleStringLiteral node) { | 7125 Object visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 6937 recordStaticType(node, _typeProvider.stringType); | 7126 recordStaticType(node, _typeProvider.stringType); |
| 6938 return null; | 7127 return null; |
| 6939 } | 7128 } |
| 6940 | 7129 |
| 6941 /** | 7130 /** |
| 6942 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> | 7131 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is`String`.</blockquote> |
| 6943 */ | 7132 */ |
| 6944 Object visitStringInterpolation(StringInterpolation node) { | 7133 Object visitStringInterpolation(StringInterpolation node) { |
| 6945 recordStaticType(node, _typeProvider.stringType); | 7134 recordStaticType(node, _typeProvider.stringType); |
| 6946 return null; | 7135 return null; |
| 6947 } | 7136 } |
| 6948 Object visitSuperExpression(SuperExpression node) { | 7137 Object visitSuperExpression(SuperExpression node) { |
| 6949 if (_thisType == null) { | 7138 if (_thisType == null) { |
| 6950 recordStaticType(node, _dynamicType); | 7139 recordStaticType(node, _dynamicType); |
| 6951 } else { | 7140 } else { |
| 6952 recordStaticType(node, _thisType); | 7141 recordStaticType(node, _thisType); |
| 6953 } | 7142 } |
| 6954 return null; | 7143 return null; |
| 6955 } | 7144 } |
| 6956 | 7145 |
| 6957 /** | 7146 /** |
| 6958 * The Dart Language Specification, 12.10: <blockquote>The static type of {@co
de this} is the | 7147 * The Dart Language Specification, 12.10: <blockquote>The static type of `thi
s` is the |
| 6959 * interface of the immediately enclosing class.</blockquote> | 7148 * interface of the immediately enclosing class.</blockquote> |
| 6960 */ | 7149 */ |
| 6961 Object visitThisExpression(ThisExpression node) { | 7150 Object visitThisExpression(ThisExpression node) { |
| 6962 if (_thisType == null) { | 7151 if (_thisType == null) { |
| 6963 recordStaticType(node, _dynamicType); | 7152 recordStaticType(node, _dynamicType); |
| 6964 } else { | 7153 } else { |
| 6965 recordStaticType(node, _thisType); | 7154 recordStaticType(node, _thisType); |
| 6966 } | 7155 } |
| 6967 return null; | 7156 return null; |
| 6968 } | 7157 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7041 Type2 variableType = ((element as VariableElement)).type; | 7230 Type2 variableType = ((element as VariableElement)).type; |
| 7042 if (variableType is FunctionType) { | 7231 if (variableType is FunctionType) { |
| 7043 return ((variableType as FunctionType)).returnType; | 7232 return ((variableType as FunctionType)).returnType; |
| 7044 } | 7233 } |
| 7045 } | 7234 } |
| 7046 return _dynamicType; | 7235 return _dynamicType; |
| 7047 } | 7236 } |
| 7048 | 7237 |
| 7049 /** | 7238 /** |
| 7050 * Given a function declaration, compute the return type of the function. The
return type of | 7239 * Given a function declaration, compute the return type of the function. The
return type of |
| 7051 * functions with a block body is {@code dynamicType}, with an expression body
it is the type of | 7240 * functions with a block body is `dynamicType`, with an expression body it is
the type of |
| 7052 * the expression. | 7241 * the expression. |
| 7053 * @param node the function expression whose return type is to be computed | 7242 * @param node the function expression whose return type is to be computed |
| 7054 * @return the return type that was computed | 7243 * @return the return type that was computed |
| 7055 */ | 7244 */ |
| 7056 Type2 computeReturnType2(FunctionDeclaration node) { | 7245 Type2 computeReturnType2(FunctionDeclaration node) { |
| 7057 TypeName returnType = node.returnType; | 7246 TypeName returnType = node.returnType; |
| 7058 if (returnType == null) { | 7247 if (returnType == null) { |
| 7059 return _dynamicType; | 7248 return _dynamicType; |
| 7060 } | 7249 } |
| 7061 return returnType.type; | 7250 return returnType.type; |
| 7062 } | 7251 } |
| 7063 | 7252 |
| 7064 /** | 7253 /** |
| 7065 * Given a function expression, compute the return type of the function. The r
eturn type of | 7254 * Given a function expression, compute the return type of the function. The r
eturn type of |
| 7066 * functions with a block body is {@code dynamicType}, with an expression body
it is the type of | 7255 * functions with a block body is `dynamicType`, with an expression body it is
the type of |
| 7067 * the expression. | 7256 * the expression. |
| 7068 * @param node the function expression whose return type is to be computed | 7257 * @param node the function expression whose return type is to be computed |
| 7069 * @return the return type that was computed | 7258 * @return the return type that was computed |
| 7070 */ | 7259 */ |
| 7071 Type2 computeReturnType3(FunctionExpression node) { | 7260 Type2 computeReturnType3(FunctionExpression node) { |
| 7072 FunctionBody body = node.body; | 7261 FunctionBody body = node.body; |
| 7073 if (body is ExpressionFunctionBody) { | 7262 if (body is ExpressionFunctionBody) { |
| 7074 return getStaticType(((body as ExpressionFunctionBody)).expression); | 7263 return getStaticType(((body as ExpressionFunctionBody)).expression); |
| 7075 } | 7264 } |
| 7076 return _dynamicType; | 7265 return _dynamicType; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7189 Type2 type = expression.staticType; | 7378 Type2 type = expression.staticType; |
| 7190 if (type == null) { | 7379 if (type == null) { |
| 7191 return _dynamicType; | 7380 return _dynamicType; |
| 7192 } | 7381 } |
| 7193 return type; | 7382 return type; |
| 7194 } | 7383 } |
| 7195 | 7384 |
| 7196 /** | 7385 /** |
| 7197 * Return the type that should be recorded for a node that resolved to the giv
en accessor. | 7386 * Return the type that should be recorded for a node that resolved to the giv
en accessor. |
| 7198 * @param accessor the accessor that the node resolved to | 7387 * @param accessor the accessor that the node resolved to |
| 7199 * @param context if the accessor element has context \[by being the RHS of a{
@link PrefixedIdentifier} or {@link PropertyAccess}\], and the return type of th
e | 7388 * @param context if the accessor element has context \[by being the RHS of a[
PrefixedIdentifier] or [PropertyAccess]\], and the return type of the |
| 7200 * accessor is a parameter type, then the type of the LHS can be used to get m
ore | 7389 * accessor is a parameter type, then the type of the LHS can be used to get m
ore |
| 7201 * specific type information | 7390 * specific type information |
| 7202 * @return the type that should be recorded for a node that resolved to the gi
ven accessor | 7391 * @return the type that should be recorded for a node that resolved to the gi
ven accessor |
| 7203 */ | 7392 */ |
| 7204 Type2 getType(PropertyAccessorElement accessor, Type2 context) { | 7393 Type2 getType(PropertyAccessorElement accessor, Type2 context) { |
| 7205 FunctionType functionType = accessor.type; | 7394 FunctionType functionType = accessor.type; |
| 7206 if (functionType == null) { | 7395 if (functionType == null) { |
| 7207 return _dynamicType; | 7396 return _dynamicType; |
| 7208 } | 7397 } |
| 7209 if (accessor.isSetter()) { | 7398 if (accessor.isSetter()) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7243 */ | 7432 */ |
| 7244 Type2 getType2(TypeName typeName) { | 7433 Type2 getType2(TypeName typeName) { |
| 7245 Type2 type = typeName.type; | 7434 Type2 type = typeName.type; |
| 7246 if (type == null) { | 7435 if (type == null) { |
| 7247 return _dynamicType; | 7436 return _dynamicType; |
| 7248 } | 7437 } |
| 7249 return type; | 7438 return type; |
| 7250 } | 7439 } |
| 7251 | 7440 |
| 7252 /** | 7441 /** |
| 7253 * Return {@code true} if the given library is the 'dart:html' library. | 7442 * Return `true` if the given library is the 'dart:html' library. |
| 7254 * @param library the library being tested | 7443 * @param library the library being tested |
| 7255 * @return {@code true} if the library is 'dart:html' | 7444 * @return `true` if the library is 'dart:html' |
| 7256 */ | 7445 */ |
| 7257 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html"; | 7446 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html"; |
| 7258 | 7447 |
| 7259 /** | 7448 /** |
| 7260 * Return {@code true} if the given node is not a type literal. | 7449 * Return `true` if the given node is not a type literal. |
| 7261 * @param node the node being tested | 7450 * @param node the node being tested |
| 7262 * @return {@code true} if the given node is not a type literal | 7451 * @return `true` if the given node is not a type literal |
| 7263 */ | 7452 */ |
| 7264 bool isNotTypeLiteral(Identifier node) { | 7453 bool isNotTypeLiteral(Identifier node) { |
| 7265 ASTNode parent = node.parent; | 7454 ASTNode parent = node.parent; |
| 7266 return parent is TypeName || (parent is PrefixedIdentifier && (parent.parent
is TypeName || identical(((parent as PrefixedIdentifier)).prefix, node))) || (p
arent is PropertyAccess && identical(((parent as PropertyAccess)).target, node))
|| (parent is MethodInvocation && identical(node, ((parent as MethodInvocation)
).target)); | 7455 return parent is TypeName || (parent is PrefixedIdentifier && (parent.parent
is TypeName || identical(((parent as PrefixedIdentifier)).prefix, node))) || (p
arent is PropertyAccess && identical(((parent as PropertyAccess)).target, node))
|| (parent is MethodInvocation && identical(node, ((parent as MethodInvocation)
).target)); |
| 7267 } | 7456 } |
| 7268 | 7457 |
| 7269 /** | 7458 /** |
| 7270 * Record that the propagated type of the given node is the given type. | 7459 * Record that the propagated type of the given node is the given type. |
| 7271 * @param expression the node whose type is to be recorded | 7460 * @param expression the node whose type is to be recorded |
| 7272 * @param type the propagated type of the node | 7461 * @param type the propagated type of the node |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7313 staticType = intType; | 7502 staticType = intType; |
| 7314 } | 7503 } |
| 7315 } | 7504 } |
| 7316 return staticType; | 7505 return staticType; |
| 7317 } | 7506 } |
| 7318 | 7507 |
| 7319 /** | 7508 /** |
| 7320 * Set the return type and parameter type information for the given function t
ype based on the | 7509 * Set the return type and parameter type information for the given function t
ype based on the |
| 7321 * given return type and parameter elements. | 7510 * given return type and parameter elements. |
| 7322 * @param functionType the function type to be filled in | 7511 * @param functionType the function type to be filled in |
| 7323 * @param returnType the return type of the function, or {@code null} if no ty
pe was declared | |
| 7324 * @param parameters the elements representing the parameters to the function | 7512 * @param parameters the elements representing the parameters to the function |
| 7325 */ | 7513 */ |
| 7326 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType2, Form
alParameterList parameterList) { | 7514 void setTypeInformation(FunctionTypeImpl functionType, FormalParameterList par
ameterList) { |
| 7327 List<Type2> normalParameterTypes = new List<Type2>(); | 7515 List<Type2> normalParameterTypes = new List<Type2>(); |
| 7328 List<Type2> optionalParameterTypes = new List<Type2>(); | 7516 List<Type2> optionalParameterTypes = new List<Type2>(); |
| 7329 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); | 7517 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); |
| 7330 if (parameterList != null) { | 7518 if (parameterList != null) { |
| 7331 for (ParameterElement parameter in parameterList.elements) { | 7519 for (ParameterElement parameter in parameterList.elements) { |
| 7332 while (true) { | 7520 while (true) { |
| 7333 if (parameter.parameterKind == ParameterKind.REQUIRED) { | 7521 if (parameter.parameterKind == ParameterKind.REQUIRED) { |
| 7334 normalParameterTypes.add(parameter.type); | 7522 normalParameterTypes.add(parameter.type); |
| 7335 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { | 7523 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { |
| 7336 optionalParameterTypes.add(parameter.type); | 7524 optionalParameterTypes.add(parameter.type); |
| 7337 } else if (parameter.parameterKind == ParameterKind.NAMED) { | 7525 } else if (parameter.parameterKind == ParameterKind.NAMED) { |
| 7338 namedParameterTypes[parameter.name] = parameter.type; | 7526 namedParameterTypes[parameter.name] = parameter.type; |
| 7339 } | 7527 } |
| 7340 break; | 7528 break; |
| 7341 } | 7529 } |
| 7342 } | 7530 } |
| 7343 } | 7531 } |
| 7344 functionType.normalParameterTypes = new List.from(normalParameterTypes); | 7532 functionType.normalParameterTypes = new List.from(normalParameterTypes); |
| 7345 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); | 7533 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); |
| 7346 functionType.namedParameterTypes = namedParameterTypes; | 7534 functionType.namedParameterTypes = namedParameterTypes; |
| 7347 functionType.returnType = returnType2; | |
| 7348 } | 7535 } |
| 7349 get thisType_J2DAccessor => _thisType; | 7536 get thisType_J2DAccessor => _thisType; |
| 7350 set thisType_J2DAccessor(__v) => _thisType = __v; | 7537 set thisType_J2DAccessor(__v) => _thisType = __v; |
| 7351 } | 7538 } |
| 7352 /** | 7539 /** |
| 7353 * Instances of the class {@code TypeOverrideManager} manage the ability to over
ride the type of an | 7540 * Instances of the class `TypeOverrideManager` manage the ability to override t
he type of an |
| 7354 * element within a given context. | 7541 * element within a given context. |
| 7355 */ | 7542 */ |
| 7356 class TypeOverrideManager { | 7543 class TypeOverrideManager { |
| 7357 | 7544 |
| 7358 /** | 7545 /** |
| 7359 * The current override scope, or {@code null} if no scope has been entered. | 7546 * The current override scope, or `null` if no scope has been entered. |
| 7360 */ | 7547 */ |
| 7361 TypeOverrideManager_TypeOverrideScope _currentScope; | 7548 TypeOverrideManager_TypeOverrideScope _currentScope; |
| 7362 | 7549 |
| 7363 /** | 7550 /** |
| 7364 * Apply a set of overrides that were previously captured. | 7551 * Apply a set of overrides that were previously captured. |
| 7365 * @param overrides the overrides to be applied | 7552 * @param overrides the overrides to be applied |
| 7366 */ | 7553 */ |
| 7367 void applyOverrides(Map<Element, Type2> overrides) { | 7554 void applyOverrides(Map<Element, Type2> overrides) { |
| 7368 if (_currentScope == null) { | 7555 if (_currentScope == null) { |
| 7369 throw new IllegalStateException("Cannot apply overrides without a scope"); | 7556 throw new IllegalStateException("Cannot apply overrides without a scope"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7407 * Exit the current override scope. | 7594 * Exit the current override scope. |
| 7408 */ | 7595 */ |
| 7409 void exitScope() { | 7596 void exitScope() { |
| 7410 if (_currentScope == null) { | 7597 if (_currentScope == null) { |
| 7411 throw new IllegalStateException("No scope to exit"); | 7598 throw new IllegalStateException("No scope to exit"); |
| 7412 } | 7599 } |
| 7413 _currentScope = _currentScope._outerScope; | 7600 _currentScope = _currentScope._outerScope; |
| 7414 } | 7601 } |
| 7415 | 7602 |
| 7416 /** | 7603 /** |
| 7417 * Return the overridden type of the given element, or {@code null} if the typ
e of the element has | 7604 * Return the overridden type of the given element, or `null` if the type of t
he element has |
| 7418 * not been overridden. | 7605 * not been overridden. |
| 7419 * @param element the element whose type might have been overridden | 7606 * @param element the element whose type might have been overridden |
| 7420 * @return the overridden type of the given element | 7607 * @return the overridden type of the given element |
| 7421 */ | 7608 */ |
| 7422 Type2 getType(Element element) { | 7609 Type2 getType(Element element) { |
| 7423 if (_currentScope == null) { | 7610 if (_currentScope == null) { |
| 7424 return null; | 7611 return null; |
| 7425 } | 7612 } |
| 7426 return _currentScope.getType(element); | 7613 return _currentScope.getType(element); |
| 7427 } | 7614 } |
| 7428 | 7615 |
| 7429 /** | 7616 /** |
| 7430 * Set the overridden type of the given element to the given type | 7617 * Set the overridden type of the given element to the given type |
| 7431 * @param element the element whose type might have been overridden | 7618 * @param element the element whose type might have been overridden |
| 7432 * @param type the overridden type of the given element | 7619 * @param type the overridden type of the given element |
| 7433 */ | 7620 */ |
| 7434 void setType(Element element, Type2 type) { | 7621 void setType(Element element, Type2 type) { |
| 7435 if (_currentScope == null) { | 7622 if (_currentScope == null) { |
| 7436 throw new IllegalStateException("Cannot override without a scope"); | 7623 throw new IllegalStateException("Cannot override without a scope"); |
| 7437 } | 7624 } |
| 7438 _currentScope.setType(element, type); | 7625 _currentScope.setType(element, type); |
| 7439 } | 7626 } |
| 7440 } | 7627 } |
| 7441 /** | 7628 /** |
| 7442 * Instances of the class {@code TypeOverrideScope} represent a scope in which t
he types of | 7629 * Instances of the class `TypeOverrideScope` represent a scope in which the typ
es of |
| 7443 * elements can be overridden. | 7630 * elements can be overridden. |
| 7444 */ | 7631 */ |
| 7445 class TypeOverrideManager_TypeOverrideScope { | 7632 class TypeOverrideManager_TypeOverrideScope { |
| 7446 | 7633 |
| 7447 /** | 7634 /** |
| 7448 * The outer scope in which types might be overridden. | 7635 * The outer scope in which types might be overridden. |
| 7449 */ | 7636 */ |
| 7450 TypeOverrideManager_TypeOverrideScope _outerScope; | 7637 TypeOverrideManager_TypeOverrideScope _outerScope; |
| 7451 | 7638 |
| 7452 /** | 7639 /** |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7495 if (type != null) { | 7682 if (type != null) { |
| 7496 overrides[element] = type; | 7683 overrides[element] = type; |
| 7497 } | 7684 } |
| 7498 } | 7685 } |
| 7499 } | 7686 } |
| 7500 } | 7687 } |
| 7501 return overrides; | 7688 return overrides; |
| 7502 } | 7689 } |
| 7503 | 7690 |
| 7504 /** | 7691 /** |
| 7505 * Return the overridden type of the given element, or {@code null} if the typ
e of the element | 7692 * Return the overridden type of the given element, or `null` if the type of t
he element |
| 7506 * has not been overridden. | 7693 * has not been overridden. |
| 7507 * @param element the element whose type might have been overridden | 7694 * @param element the element whose type might have been overridden |
| 7508 * @return the overridden type of the given element | 7695 * @return the overridden type of the given element |
| 7509 */ | 7696 */ |
| 7510 Type2 getType(Element element) { | 7697 Type2 getType(Element element) { |
| 7511 Type2 type = _overridenTypes[element]; | 7698 Type2 type = _overridenTypes[element]; |
| 7512 if (type == null && element is PropertyAccessorElement) { | 7699 if (type == null && element is PropertyAccessorElement) { |
| 7513 type = _overridenTypes[((element as PropertyAccessorElement)).variable]; | 7700 type = _overridenTypes[((element as PropertyAccessorElement)).variable]; |
| 7514 } | 7701 } |
| 7515 if (type != null) { | 7702 if (type != null) { |
| 7516 return type; | 7703 return type; |
| 7517 } else if (_outerScope != null) { | 7704 } else if (_outerScope != null) { |
| 7518 return _outerScope.getType(element); | 7705 return _outerScope.getType(element); |
| 7519 } | 7706 } |
| 7520 return null; | 7707 return null; |
| 7521 } | 7708 } |
| 7522 | 7709 |
| 7523 /** | 7710 /** |
| 7524 * Set the overridden type of the given element to the given type | 7711 * Set the overridden type of the given element to the given type |
| 7525 * @param element the element whose type might have been overridden | 7712 * @param element the element whose type might have been overridden |
| 7526 * @param type the overridden type of the given element | 7713 * @param type the overridden type of the given element |
| 7527 */ | 7714 */ |
| 7528 void setType(Element element, Type2 type) { | 7715 void setType(Element element, Type2 type) { |
| 7529 _overridenTypes[element] = type; | 7716 _overridenTypes[element] = type; |
| 7530 } | 7717 } |
| 7531 } | 7718 } |
| 7532 /** | 7719 /** |
| 7533 * The interface {@code TypeProvider} defines the behavior of objects that provi
de access to types | 7720 * The interface `TypeProvider` defines the behavior of objects that provide acc
ess to types |
| 7534 * defined by the language. | 7721 * defined by the language. |
| 7535 * @coverage dart.engine.resolver | 7722 * @coverage dart.engine.resolver |
| 7536 */ | 7723 */ |
| 7537 abstract class TypeProvider { | 7724 abstract class TypeProvider { |
| 7538 | 7725 |
| 7539 /** | 7726 /** |
| 7540 * Return the type representing the built-in type 'bool'. | 7727 * Return the type representing the built-in type 'bool'. |
| 7541 * @return the type representing the built-in type 'bool' | 7728 * @return the type representing the built-in type 'bool' |
| 7542 */ | 7729 */ |
| 7543 InterfaceType get boolType; | 7730 InterfaceType get boolType; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7608 */ | 7795 */ |
| 7609 InterfaceType get stringType; | 7796 InterfaceType get stringType; |
| 7610 | 7797 |
| 7611 /** | 7798 /** |
| 7612 * Return the type representing the built-in type 'Type'. | 7799 * Return the type representing the built-in type 'Type'. |
| 7613 * @return the type representing the built-in type 'Type' | 7800 * @return the type representing the built-in type 'Type' |
| 7614 */ | 7801 */ |
| 7615 InterfaceType get typeType; | 7802 InterfaceType get typeType; |
| 7616 } | 7803 } |
| 7617 /** | 7804 /** |
| 7618 * Instances of the class {@code TypeProviderImpl} provide access to types defin
ed by the language | 7805 * Instances of the class `TypeProviderImpl` provide access to types defined by
the language |
| 7619 * by looking for those types in the element model for the core library. | 7806 * by looking for those types in the element model for the core library. |
| 7620 * @coverage dart.engine.resolver | 7807 * @coverage dart.engine.resolver |
| 7621 */ | 7808 */ |
| 7622 class TypeProviderImpl implements TypeProvider { | 7809 class TypeProviderImpl implements TypeProvider { |
| 7623 | 7810 |
| 7624 /** | 7811 /** |
| 7625 * The type representing the built-in type 'bool'. | 7812 * The type representing the built-in type 'bool'. |
| 7626 */ | 7813 */ |
| 7627 InterfaceType _boolType; | 7814 InterfaceType _boolType; |
| 7628 | 7815 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7701 InterfaceType get intType => _intType; | 7888 InterfaceType get intType => _intType; |
| 7702 InterfaceType get listType => _listType; | 7889 InterfaceType get listType => _listType; |
| 7703 InterfaceType get mapType => _mapType; | 7890 InterfaceType get mapType => _mapType; |
| 7704 InterfaceType get numType => _numType; | 7891 InterfaceType get numType => _numType; |
| 7705 InterfaceType get objectType => _objectType; | 7892 InterfaceType get objectType => _objectType; |
| 7706 InterfaceType get stackTraceType => _stackTraceType; | 7893 InterfaceType get stackTraceType => _stackTraceType; |
| 7707 InterfaceType get stringType => _stringType; | 7894 InterfaceType get stringType => _stringType; |
| 7708 InterfaceType get typeType => _typeType; | 7895 InterfaceType get typeType => _typeType; |
| 7709 | 7896 |
| 7710 /** | 7897 /** |
| 7711 * Return the type with the given name from the given namespace, or {@code nul
l} if there is no | 7898 * Return the type with the given name from the given namespace, or `null` if
there is no |
| 7712 * class with the given name. | 7899 * class with the given name. |
| 7713 * @param namespace the namespace in which to search for the given name | 7900 * @param namespace the namespace in which to search for the given name |
| 7714 * @param typeName the name of the type being searched for | 7901 * @param typeName the name of the type being searched for |
| 7715 * @return the type that was found | 7902 * @return the type that was found |
| 7716 */ | 7903 */ |
| 7717 InterfaceType getType(Namespace namespace, String typeName) { | 7904 InterfaceType getType(Namespace namespace, String typeName) { |
| 7718 Element element = namespace.get(typeName); | 7905 Element element = namespace.get(typeName); |
| 7719 if (element == null) { | 7906 if (element == null) { |
| 7720 AnalysisEngine.instance.logger.logInformation("No definition of type ${typ
eName}"); | 7907 AnalysisEngine.instance.logger.logInformation("No definition of type ${typ
eName}"); |
| 7721 return null; | 7908 return null; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 7738 _listType = getType(namespace, "List"); | 7925 _listType = getType(namespace, "List"); |
| 7739 _mapType = getType(namespace, "Map"); | 7926 _mapType = getType(namespace, "Map"); |
| 7740 _numType = getType(namespace, "num"); | 7927 _numType = getType(namespace, "num"); |
| 7741 _objectType = getType(namespace, "Object"); | 7928 _objectType = getType(namespace, "Object"); |
| 7742 _stackTraceType = getType(namespace, "StackTrace"); | 7929 _stackTraceType = getType(namespace, "StackTrace"); |
| 7743 _stringType = getType(namespace, "String"); | 7930 _stringType = getType(namespace, "String"); |
| 7744 _typeType = getType(namespace, "Type"); | 7931 _typeType = getType(namespace, "Type"); |
| 7745 } | 7932 } |
| 7746 } | 7933 } |
| 7747 /** | 7934 /** |
| 7748 * Instances of the class {@code TypeResolverVisitor} are used to resolve the ty
pes associated with | 7935 * Instances of the class `TypeResolverVisitor` are used to resolve the types as
sociated with |
| 7749 * the elements in the element model. This includes the types of superclasses, m
ixins, interfaces, | 7936 * the elements in the element model. This includes the types of superclasses, m
ixins, interfaces, |
| 7750 * fields, methods, parameters, and local variables. As a side-effect, this also
finishes building | 7937 * fields, methods, parameters, and local variables. As a side-effect, this also
finishes building |
| 7751 * the type hierarchy. | 7938 * the type hierarchy. |
| 7752 * @coverage dart.engine.resolver | 7939 * @coverage dart.engine.resolver |
| 7753 */ | 7940 */ |
| 7754 class TypeResolverVisitor extends ScopedVisitor { | 7941 class TypeResolverVisitor extends ScopedVisitor { |
| 7755 | 7942 |
| 7756 /** | 7943 /** |
| 7757 * The type representing the type 'dynamic'. | 7944 * The type representing the type 'dynamic'. |
| 7758 */ | 7945 */ |
| 7759 Type2 _dynamicType; | 7946 Type2 _dynamicType; |
| 7760 | 7947 |
| 7761 /** | 7948 /** |
| 7762 * The flag specifying if currently visited class references 'super' expressio
n. | 7949 * The flag specifying if currently visited class references 'super' expressio
n. |
| 7763 */ | 7950 */ |
| 7764 bool _hasReferenceToSuper = false; | 7951 bool _hasReferenceToSuper = false; |
| 7765 | 7952 |
| 7766 /** | 7953 /** |
| 7767 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 7954 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 7768 * @param library the library containing the compilation unit being resolved | 7955 * @param library the library containing the compilation unit being resolved |
| 7769 * @param source the source representing the compilation unit being visited | 7956 * @param source the source representing the compilation unit being visited |
| 7770 * @param typeProvider the object used to access the types from the core libra
ry | 7957 * @param typeProvider the object used to access the types from the core libra
ry |
| 7771 */ | 7958 */ |
| 7772 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv
ider) : super.con1(library, source, typeProvider) { | 7959 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv
ider) : super.con1(library, source, typeProvider) { |
| 7773 _jtd_constructor_281_impl(library, source, typeProvider); | 7960 _jtd_constructor_282_impl(library, source, typeProvider); |
| 7774 } | 7961 } |
| 7775 _jtd_constructor_281_impl(Library library, Source source, TypeProvider typePro
vider) { | 7962 _jtd_constructor_282_impl(Library library, Source source, TypeProvider typePro
vider) { |
| 7776 _dynamicType = typeProvider.dynamicType; | 7963 _dynamicType = typeProvider.dynamicType; |
| 7777 } | 7964 } |
| 7778 | 7965 |
| 7779 /** | 7966 /** |
| 7780 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 7967 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 7781 * @param definingLibrary the element for the library containing the compilati
on unit being | 7968 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 7782 * visited | 7969 * visited |
| 7783 * @param source the source representing the compilation unit being visited | 7970 * @param source the source representing the compilation unit being visited |
| 7784 * @param typeProvider the object used to access the types from the core libra
ry | 7971 * @param typeProvider the object used to access the types from the core libra
ry |
| 7785 * @param errorListener the error listener that will be informed of any errors
that are found | 7972 * @param errorListener the error listener that will be informed of any errors
that are found |
| 7786 * during resolution | 7973 * during resolution |
| 7787 */ | 7974 */ |
| 7788 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr
ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL
ibrary, source, typeProvider, errorListener) { | 7975 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr
ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL
ibrary, source, typeProvider, errorListener) { |
| 7789 _jtd_constructor_282_impl(definingLibrary, source, typeProvider, errorListen
er); | 7976 _jtd_constructor_283_impl(definingLibrary, source, typeProvider, errorListen
er); |
| 7790 } | 7977 } |
| 7791 _jtd_constructor_282_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { | 7978 _jtd_constructor_283_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { |
| 7792 _dynamicType = typeProvider.dynamicType; | 7979 _dynamicType = typeProvider.dynamicType; |
| 7793 } | 7980 } |
| 7794 Object visitCatchClause(CatchClause node) { | 7981 Object visitCatchClause(CatchClause node) { |
| 7795 super.visitCatchClause(node); | 7982 super.visitCatchClause(node); |
| 7796 SimpleIdentifier exception = node.exceptionParameter; | 7983 SimpleIdentifier exception = node.exceptionParameter; |
| 7797 if (exception != null) { | 7984 if (exception != null) { |
| 7798 TypeName exceptionTypeName = node.exceptionType; | 7985 TypeName exceptionTypeName = node.exceptionType; |
| 7799 Type2 exceptionType; | 7986 Type2 exceptionType; |
| 7800 if (exceptionTypeName == null) { | 7987 if (exceptionTypeName == null) { |
| 7801 exceptionType = typeProvider.objectType; | 7988 exceptionType = typeProvider.objectType; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7850 } | 8037 } |
| 7851 if (classElement != null && superclassType != null) { | 8038 if (classElement != null && superclassType != null) { |
| 7852 classElement.supertype = superclassType; | 8039 classElement.supertype = superclassType; |
| 7853 } | 8040 } |
| 7854 resolve(classElement, node.withClause, node.implementsClause); | 8041 resolve(classElement, node.withClause, node.implementsClause); |
| 7855 return null; | 8042 return null; |
| 7856 } | 8043 } |
| 7857 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 8044 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 7858 super.visitConstructorDeclaration(node); | 8045 super.visitConstructorDeclaration(node); |
| 7859 ExecutableElementImpl element = node.element as ExecutableElementImpl; | 8046 ExecutableElementImpl element = node.element as ExecutableElementImpl; |
| 8047 ClassElement definingClass = element.enclosingElement as ClassElement; |
| 8048 element.returnType = definingClass.type; |
| 7860 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); | 8049 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); |
| 7861 setTypeInformation(type, null, element.parameters); | 8050 type.typeArguments = definingClass.type.typeArguments; |
| 7862 type.returnType = ((element.enclosingElement as ClassElement)).type; | 8051 setTypeInformation(type, element.parameters); |
| 7863 element.type = type; | 8052 element.type = type; |
| 7864 return null; | 8053 return null; |
| 7865 } | 8054 } |
| 7866 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 8055 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 7867 super.visitDeclaredIdentifier(node); | 8056 super.visitDeclaredIdentifier(node); |
| 7868 Type2 declaredType; | 8057 Type2 declaredType; |
| 7869 TypeName typeName = node.type; | 8058 TypeName typeName = node.type; |
| 7870 if (typeName == null) { | 8059 if (typeName == null) { |
| 7871 declaredType = _dynamicType; | 8060 declaredType = _dynamicType; |
| 7872 } else { | 8061 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 7893 type = getType3(typeName); | 8082 type = getType3(typeName); |
| 7894 } | 8083 } |
| 7895 parameter.type = type; | 8084 parameter.type = type; |
| 7896 } else { | 8085 } else { |
| 7897 } | 8086 } |
| 7898 return null; | 8087 return null; |
| 7899 } | 8088 } |
| 7900 Object visitFunctionDeclaration(FunctionDeclaration node) { | 8089 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 7901 super.visitFunctionDeclaration(node); | 8090 super.visitFunctionDeclaration(node); |
| 7902 ExecutableElementImpl element = node.element as ExecutableElementImpl; | 8091 ExecutableElementImpl element = node.element as ExecutableElementImpl; |
| 8092 element.returnType = computeReturnType(node.returnType); |
| 7903 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); | 8093 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); |
| 7904 setTypeInformation(type, node.returnType, element.parameters); | 8094 ClassElement definingClass = element.getAncestor(ClassElement); |
| 8095 if (definingClass != null) { |
| 8096 type.typeArguments = definingClass.type.typeArguments; |
| 8097 } |
| 8098 setTypeInformation(type, element.parameters); |
| 7905 element.type = type; | 8099 element.type = type; |
| 7906 return null; | 8100 return null; |
| 7907 } | 8101 } |
| 7908 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 8102 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 7909 super.visitFunctionTypeAlias(node); | 8103 super.visitFunctionTypeAlias(node); |
| 7910 FunctionTypeAliasElementImpl element = node.element as FunctionTypeAliasElem
entImpl; | 8104 FunctionTypeAliasElementImpl element = node.element as FunctionTypeAliasElem
entImpl; |
| 8105 element.returnType = computeReturnType(node.returnType); |
| 7911 FunctionTypeImpl type = element.type as FunctionTypeImpl; | 8106 FunctionTypeImpl type = element.type as FunctionTypeImpl; |
| 7912 setTypeInformation(type, node.returnType, element.parameters); | 8107 setTypeInformation(type, element.parameters); |
| 7913 return null; | 8108 return null; |
| 7914 } | 8109 } |
| 7915 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 8110 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 7916 super.visitFunctionTypedFormalParameter(node); | 8111 super.visitFunctionTypedFormalParameter(node); |
| 7917 ParameterElementImpl element = node.identifier.element as ParameterElementIm
pl; | 8112 ParameterElementImpl element = node.identifier.element as ParameterElementIm
pl; |
| 7918 AnonymousFunctionTypeImpl type = new AnonymousFunctionTypeImpl(); | |
| 7919 List<ParameterElement> parameters = getElements(node.parameters); | 8113 List<ParameterElement> parameters = getElements(node.parameters); |
| 7920 setTypeInformation(type, node.returnType, parameters); | 8114 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl
(null); |
| 7921 type.baseParameters = parameters; | 8115 aliasElement.synthetic = true; |
| 8116 aliasElement.parameters = parameters; |
| 8117 aliasElement.returnType = computeReturnType(node.returnType); |
| 8118 FunctionTypeImpl type = new FunctionTypeImpl.con2(aliasElement); |
| 8119 ClassElement definingClass = element.getAncestor(ClassElement); |
| 8120 if (definingClass != null) { |
| 8121 aliasElement.typeVariables = definingClass.typeVariables; |
| 8122 type.typeArguments = definingClass.type.typeArguments; |
| 8123 } else { |
| 8124 FunctionTypeAliasElement alias = element.getAncestor(FunctionTypeAliasElem
ent); |
| 8125 if (alias != null) { |
| 8126 aliasElement.typeVariables = alias.typeVariables; |
| 8127 type.typeArguments = alias.type.typeArguments; |
| 8128 } else { |
| 8129 type.typeArguments = TypeVariableTypeImpl.EMPTY_ARRAY; |
| 8130 } |
| 8131 } |
| 8132 setTypeInformation(type, parameters); |
| 7922 element.type = type; | 8133 element.type = type; |
| 7923 return null; | 8134 return null; |
| 7924 } | 8135 } |
| 7925 Object visitMethodDeclaration(MethodDeclaration node) { | 8136 Object visitMethodDeclaration(MethodDeclaration node) { |
| 7926 super.visitMethodDeclaration(node); | 8137 super.visitMethodDeclaration(node); |
| 7927 ExecutableElementImpl element = node.element as ExecutableElementImpl; | 8138 ExecutableElementImpl element = node.element as ExecutableElementImpl; |
| 8139 element.returnType = computeReturnType(node.returnType); |
| 7928 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); | 8140 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); |
| 7929 setTypeInformation(type, node.returnType, element.parameters); | 8141 ClassElement definingClass = element.getAncestor(ClassElement); |
| 8142 if (definingClass != null) { |
| 8143 type.typeArguments = definingClass.type.typeArguments; |
| 8144 } |
| 8145 setTypeInformation(type, element.parameters); |
| 7930 element.type = type; | 8146 element.type = type; |
| 7931 if (element is PropertyAccessorElement) { | 8147 if (element is PropertyAccessorElement) { |
| 7932 PropertyAccessorElement accessor = element as PropertyAccessorElement; | 8148 PropertyAccessorElement accessor = element as PropertyAccessorElement; |
| 7933 PropertyInducingElementImpl variable = accessor.variable as PropertyInduci
ngElementImpl; | 8149 PropertyInducingElementImpl variable = accessor.variable as PropertyInduci
ngElementImpl; |
| 7934 if (accessor.isGetter()) { | 8150 if (accessor.isGetter()) { |
| 7935 variable.type = type.returnType; | 8151 variable.type = type.returnType; |
| 7936 } else if (variable.type == null) { | 8152 } else if (variable.type == null) { |
| 7937 List<Type2> parameterTypes = type.normalParameterTypes; | 8153 List<Type2> parameterTypes = type.normalParameterTypes; |
| 7938 if (parameterTypes != null && parameterTypes.length > 0) { | 8154 if (parameterTypes != null && parameterTypes.length > 0) { |
| 7939 variable.type = parameterTypes[0]; | 8155 variable.type = parameterTypes[0]; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8136 declaredType = _dynamicType; | 8352 declaredType = _dynamicType; |
| 8137 } else { | 8353 } else { |
| 8138 declaredType = getType3(typeName); | 8354 declaredType = getType3(typeName); |
| 8139 } | 8355 } |
| 8140 Element element = node.name.element; | 8356 Element element = node.name.element; |
| 8141 if (element is VariableElement) { | 8357 if (element is VariableElement) { |
| 8142 ((element as VariableElementImpl)).type = declaredType; | 8358 ((element as VariableElementImpl)).type = declaredType; |
| 8143 if (element is PropertyInducingElement) { | 8359 if (element is PropertyInducingElement) { |
| 8144 PropertyInducingElement variableElement = element as PropertyInducingEle
ment; | 8360 PropertyInducingElement variableElement = element as PropertyInducingEle
ment; |
| 8145 PropertyAccessorElementImpl getter = variableElement.getter as PropertyA
ccessorElementImpl; | 8361 PropertyAccessorElementImpl getter = variableElement.getter as PropertyA
ccessorElementImpl; |
| 8362 getter.returnType = declaredType; |
| 8146 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter); | 8363 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter); |
| 8147 getterType.returnType = declaredType; | 8364 ClassElement definingClass = element.getAncestor(ClassElement); |
| 8365 if (definingClass != null) { |
| 8366 getterType.typeArguments = definingClass.type.typeArguments; |
| 8367 } |
| 8148 getter.type = getterType; | 8368 getter.type = getterType; |
| 8149 PropertyAccessorElementImpl setter = variableElement.setter as PropertyA
ccessorElementImpl; | 8369 PropertyAccessorElementImpl setter = variableElement.setter as PropertyA
ccessorElementImpl; |
| 8150 if (setter != null) { | 8370 if (setter != null) { |
| 8371 setter.returnType = VoidTypeImpl.instance; |
| 8151 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter); | 8372 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter); |
| 8152 setterType.returnType = VoidTypeImpl.instance; | 8373 if (definingClass != null) { |
| 8374 setterType.typeArguments = definingClass.type.typeArguments; |
| 8375 } |
| 8153 setterType.normalParameterTypes = <Type2> [declaredType]; | 8376 setterType.normalParameterTypes = <Type2> [declaredType]; |
| 8154 setter.type = setterType; | 8377 setter.type = setterType; |
| 8155 } | 8378 } |
| 8156 } | 8379 } |
| 8157 } else { | 8380 } else { |
| 8158 } | 8381 } |
| 8159 return null; | 8382 return null; |
| 8160 } | 8383 } |
| 8161 | 8384 |
| 8162 /** | 8385 /** |
| 8386 * Given a type name representing the return type of a function, compute the r
eturn type of the |
| 8387 * function. |
| 8388 * @param returnType the type name representing the return type of the functio
n |
| 8389 * @return the return type that was computed |
| 8390 */ |
| 8391 Type2 computeReturnType(TypeName returnType) { |
| 8392 if (returnType == null) { |
| 8393 return _dynamicType; |
| 8394 } else { |
| 8395 return returnType.type; |
| 8396 } |
| 8397 } |
| 8398 |
| 8399 /** |
| 8163 * Return the class element that represents the class whose name was provided. | 8400 * Return the class element that represents the class whose name was provided. |
| 8164 * @param identifier the name from the declaration of a class | 8401 * @param identifier the name from the declaration of a class |
| 8165 * @return the class element that represents the class | 8402 * @return the class element that represents the class |
| 8166 */ | 8403 */ |
| 8167 ClassElementImpl getClassElement(SimpleIdentifier identifier) { | 8404 ClassElementImpl getClassElement(SimpleIdentifier identifier) { |
| 8168 if (identifier == null) { | 8405 if (identifier == null) { |
| 8169 return null; | 8406 return null; |
| 8170 } | 8407 } |
| 8171 Element element = identifier.element; | 8408 Element element = identifier.element; |
| 8172 if (element is! ClassElementImpl) { | 8409 if (element is! ClassElementImpl) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8210 } else { | 8447 } else { |
| 8211 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS; | 8448 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS; |
| 8212 } | 8449 } |
| 8213 } | 8450 } |
| 8214 } | 8451 } |
| 8215 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; | 8452 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; |
| 8216 } | 8453 } |
| 8217 | 8454 |
| 8218 /** | 8455 /** |
| 8219 * Given the multiple elements to which a single name could potentially be res
olved, return the | 8456 * Given the multiple elements to which a single name could potentially be res
olved, return the |
| 8220 * single interface type that should be used, or {@code null} if there is no c
lear choice. | 8457 * single interface type that should be used, or `null` if there is no clear c
hoice. |
| 8221 * @param elements the elements to which a single name could potentially be re
solved | 8458 * @param elements the elements to which a single name could potentially be re
solved |
| 8222 * @return the single interface type that should be used for the type name | 8459 * @return the single interface type that should be used for the type name |
| 8223 */ | 8460 */ |
| 8224 InterfaceType getType(List<Element> elements) { | 8461 InterfaceType getType(List<Element> elements) { |
| 8225 InterfaceType type = null; | 8462 InterfaceType type = null; |
| 8226 for (Element element in elements) { | 8463 for (Element element in elements) { |
| 8227 if (element is ClassElement) { | 8464 if (element is ClassElement) { |
| 8228 if (type != null) { | 8465 if (type != null) { |
| 8229 return null; | 8466 return null; |
| 8230 } | 8467 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8270 if (typeName is SimpleIdentifier) { | 8507 if (typeName is SimpleIdentifier) { |
| 8271 return typeName as SimpleIdentifier; | 8508 return typeName as SimpleIdentifier; |
| 8272 } else { | 8509 } else { |
| 8273 return ((typeName as PrefixedIdentifier)).identifier; | 8510 return ((typeName as PrefixedIdentifier)).identifier; |
| 8274 } | 8511 } |
| 8275 } | 8512 } |
| 8276 | 8513 |
| 8277 /** | 8514 /** |
| 8278 * Checks if the given type name is used as the type in an as expression. | 8515 * Checks if the given type name is used as the type in an as expression. |
| 8279 * @param typeName the type name to analyzer | 8516 * @param typeName the type name to analyzer |
| 8280 * @return {@code true} if the given type name is used as the type in an as ex
pression | 8517 * @return `true` if the given type name is used as the type in an as expressi
on |
| 8281 */ | 8518 */ |
| 8282 bool isTypeNameInAsExpression(TypeName typeName) { | 8519 bool isTypeNameInAsExpression(TypeName typeName) { |
| 8283 ASTNode parent = typeName.parent; | 8520 ASTNode parent = typeName.parent; |
| 8284 if (parent is AsExpression) { | 8521 if (parent is AsExpression) { |
| 8285 AsExpression asExpression = parent as AsExpression; | 8522 AsExpression asExpression = parent as AsExpression; |
| 8286 return identical(asExpression.type, typeName); | 8523 return identical(asExpression.type, typeName); |
| 8287 } | 8524 } |
| 8288 return false; | 8525 return false; |
| 8289 } | 8526 } |
| 8290 | 8527 |
| 8291 /** | 8528 /** |
| 8292 * Checks if the given type name is used as the exception type in a catch clau
se. | 8529 * Checks if the given type name is used as the exception type in a catch clau
se. |
| 8293 * @param typeName the type name to analyzer | 8530 * @param typeName the type name to analyzer |
| 8294 * @return {@code true} if the given type name is used as the exception type i
n a catch clause | 8531 * @return `true` if the given type name is used as the exception type in a ca
tch clause |
| 8295 */ | 8532 */ |
| 8296 bool isTypeNameInCatchClause(TypeName typeName) { | 8533 bool isTypeNameInCatchClause(TypeName typeName) { |
| 8297 ASTNode parent = typeName.parent; | 8534 ASTNode parent = typeName.parent; |
| 8298 if (parent is CatchClause) { | 8535 if (parent is CatchClause) { |
| 8299 CatchClause catchClause = parent as CatchClause; | 8536 CatchClause catchClause = parent as CatchClause; |
| 8300 return identical(catchClause.exceptionType, typeName); | 8537 return identical(catchClause.exceptionType, typeName); |
| 8301 } | 8538 } |
| 8302 return false; | 8539 return false; |
| 8303 } | 8540 } |
| 8304 | 8541 |
| 8305 /** | 8542 /** |
| 8306 * Checks if the given type name is used as the type in an instance creation e
xpression. | 8543 * Checks if the given type name is used as the type in an instance creation e
xpression. |
| 8307 * @param typeName the type name to analyzer | 8544 * @param typeName the type name to analyzer |
| 8308 * @return {@code true} if the given type name is used as the type in an insta
nce creation | 8545 * @return `true` if the given type name is used as the type in an instance cr
eation |
| 8309 * expression | 8546 * expression |
| 8310 */ | 8547 */ |
| 8311 bool isTypeNameInInstanceCreationExpression(TypeName typeName) { | 8548 bool isTypeNameInInstanceCreationExpression(TypeName typeName) { |
| 8312 ASTNode parent = typeName.parent; | 8549 ASTNode parent = typeName.parent; |
| 8313 if (parent is ConstructorName && parent.parent is InstanceCreationExpression
) { | 8550 if (parent is ConstructorName && parent.parent is InstanceCreationExpression
) { |
| 8314 ConstructorName constructorName = parent as ConstructorName; | 8551 ConstructorName constructorName = parent as ConstructorName; |
| 8315 return constructorName != null && identical(constructorName.type, typeName
); | 8552 return constructorName != null && identical(constructorName.type, typeName
); |
| 8316 } | 8553 } |
| 8317 return false; | 8554 return false; |
| 8318 } | 8555 } |
| 8319 | 8556 |
| 8320 /** | 8557 /** |
| 8321 * Checks if the given type name is used as the type in an is expression. | 8558 * Checks if the given type name is used as the type in an is expression. |
| 8322 * @param typeName the type name to analyzer | 8559 * @param typeName the type name to analyzer |
| 8323 * @return {@code true} if the given type name is used as the type in an is ex
pression | 8560 * @return `true` if the given type name is used as the type in an is expressi
on |
| 8324 */ | 8561 */ |
| 8325 bool isTypeNameInIsExpression(TypeName typeName) { | 8562 bool isTypeNameInIsExpression(TypeName typeName) { |
| 8326 ASTNode parent = typeName.parent; | 8563 ASTNode parent = typeName.parent; |
| 8327 if (parent is IsExpression) { | 8564 if (parent is IsExpression) { |
| 8328 IsExpression isExpression = parent as IsExpression; | 8565 IsExpression isExpression = parent as IsExpression; |
| 8329 return identical(isExpression.type, typeName); | 8566 return identical(isExpression.type, typeName); |
| 8330 } | 8567 } |
| 8331 return false; | 8568 return false; |
| 8332 } | 8569 } |
| 8333 | 8570 |
| 8334 /** | 8571 /** |
| 8335 * Checks if the given type name is the target in a redirected constructor. | 8572 * Checks if the given type name is the target in a redirected constructor. |
| 8336 * @param typeName the type name to analyzer | 8573 * @param typeName the type name to analyzer |
| 8337 * @return {@code true} if the given type name is used as the type in a redire
cted constructor | 8574 * @return `true` if the given type name is used as the type in a redirected c
onstructor |
| 8338 */ | 8575 */ |
| 8339 bool isTypeNameTargetInRedirectedConstructor(TypeName typeName) { | 8576 bool isTypeNameTargetInRedirectedConstructor(TypeName typeName) { |
| 8340 ASTNode parent = typeName.parent; | 8577 ASTNode parent = typeName.parent; |
| 8341 if (parent is ConstructorName) { | 8578 if (parent is ConstructorName) { |
| 8342 ConstructorName constructorName = parent as ConstructorName; | 8579 ConstructorName constructorName = parent as ConstructorName; |
| 8343 parent = constructorName.parent; | 8580 parent = constructorName.parent; |
| 8344 if (parent is ConstructorDeclaration) { | 8581 if (parent is ConstructorDeclaration) { |
| 8345 ConstructorDeclaration constructorDeclaration = parent as ConstructorDec
laration; | 8582 ConstructorDeclaration constructorDeclaration = parent as ConstructorDec
laration; |
| 8346 return constructorName == constructorDeclaration.redirectedConstructor; | 8583 return constructorName == constructorDeclaration.redirectedConstructor; |
| 8347 } | 8584 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8465 prefix.element = prefixElement; | 8702 prefix.element = prefixElement; |
| 8466 } | 8703 } |
| 8467 } | 8704 } |
| 8468 } | 8705 } |
| 8469 } | 8706 } |
| 8470 | 8707 |
| 8471 /** | 8708 /** |
| 8472 * Set the return type and parameter type information for the given function t
ype based on the | 8709 * Set the return type and parameter type information for the given function t
ype based on the |
| 8473 * given return type and parameter elements. | 8710 * given return type and parameter elements. |
| 8474 * @param functionType the function type to be filled in | 8711 * @param functionType the function type to be filled in |
| 8475 * @param returnType the return type of the function, or {@code null} if no ty
pe was declared | |
| 8476 * @param parameters the elements representing the parameters to the function | 8712 * @param parameters the elements representing the parameters to the function |
| 8477 */ | 8713 */ |
| 8478 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType2, L
ist<ParameterElement> parameters) { | 8714 void setTypeInformation(FunctionTypeImpl functionType, List<ParameterElement>
parameters) { |
| 8479 List<Type2> normalParameterTypes = new List<Type2>(); | 8715 List<Type2> normalParameterTypes = new List<Type2>(); |
| 8480 List<Type2> optionalParameterTypes = new List<Type2>(); | 8716 List<Type2> optionalParameterTypes = new List<Type2>(); |
| 8481 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); | 8717 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); |
| 8482 for (ParameterElement parameter in parameters) { | 8718 for (ParameterElement parameter in parameters) { |
| 8483 while (true) { | 8719 while (true) { |
| 8484 if (parameter.parameterKind == ParameterKind.REQUIRED) { | 8720 if (parameter.parameterKind == ParameterKind.REQUIRED) { |
| 8485 normalParameterTypes.add(parameter.type); | 8721 normalParameterTypes.add(parameter.type); |
| 8486 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { | 8722 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { |
| 8487 optionalParameterTypes.add(parameter.type); | 8723 optionalParameterTypes.add(parameter.type); |
| 8488 } else if (parameter.parameterKind == ParameterKind.NAMED) { | 8724 } else if (parameter.parameterKind == ParameterKind.NAMED) { |
| 8489 namedParameterTypes[parameter.name] = parameter.type; | 8725 namedParameterTypes[parameter.name] = parameter.type; |
| 8490 } | 8726 } |
| 8491 break; | 8727 break; |
| 8492 } | 8728 } |
| 8493 } | 8729 } |
| 8494 if (!normalParameterTypes.isEmpty) { | 8730 if (!normalParameterTypes.isEmpty) { |
| 8495 functionType.normalParameterTypes = new List.from(normalParameterTypes); | 8731 functionType.normalParameterTypes = new List.from(normalParameterTypes); |
| 8496 } | 8732 } |
| 8497 if (!optionalParameterTypes.isEmpty) { | 8733 if (!optionalParameterTypes.isEmpty) { |
| 8498 functionType.optionalParameterTypes = new List.from(optionalParameterTypes
); | 8734 functionType.optionalParameterTypes = new List.from(optionalParameterTypes
); |
| 8499 } | 8735 } |
| 8500 if (!namedParameterTypes.isEmpty) { | 8736 if (!namedParameterTypes.isEmpty) { |
| 8501 functionType.namedParameterTypes = namedParameterTypes; | 8737 functionType.namedParameterTypes = namedParameterTypes; |
| 8502 } | 8738 } |
| 8503 if (returnType2 == null) { | |
| 8504 functionType.returnType = _dynamicType; | |
| 8505 } else { | |
| 8506 functionType.returnType = returnType2.type; | |
| 8507 } | |
| 8508 } | 8739 } |
| 8509 } | 8740 } |
| 8510 /** | 8741 /** |
| 8511 * Instances of the class {@code ClassScope} implement the scope defined by a cl
ass. | 8742 * Instances of the class `ClassScope` implement the scope defined by a class. |
| 8512 * @coverage dart.engine.resolver | 8743 * @coverage dart.engine.resolver |
| 8513 */ | 8744 */ |
| 8514 class ClassScope extends EnclosedScope { | 8745 class ClassScope extends EnclosedScope { |
| 8515 | 8746 |
| 8516 /** | 8747 /** |
| 8517 * Initialize a newly created scope enclosed within another scope. | 8748 * Initialize a newly created scope enclosed within another scope. |
| 8518 * @param enclosingScope the scope in which this scope is lexically enclosed | 8749 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 8519 * @param typeElement the element representing the type represented by this sc
ope | 8750 * @param typeElement the element representing the type represented by this sc
ope |
| 8520 */ | 8751 */ |
| 8521 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose
dScope(enclosingScope)) { | 8752 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose
dScope(enclosingScope)) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 8551 * @param typeElement the element representing the type represented by this sc
ope | 8782 * @param typeElement the element representing the type represented by this sc
ope |
| 8552 */ | 8783 */ |
| 8553 void defineTypeParameters(ClassElement typeElement) { | 8784 void defineTypeParameters(ClassElement typeElement) { |
| 8554 Scope parameterScope = enclosingScope; | 8785 Scope parameterScope = enclosingScope; |
| 8555 for (TypeVariableElement parameter in typeElement.typeVariables) { | 8786 for (TypeVariableElement parameter in typeElement.typeVariables) { |
| 8556 parameterScope.define(parameter); | 8787 parameterScope.define(parameter); |
| 8557 } | 8788 } |
| 8558 } | 8789 } |
| 8559 } | 8790 } |
| 8560 /** | 8791 /** |
| 8561 * Instances of the class {@code EnclosedScope} implement a scope that is lexica
lly enclosed in | 8792 * Instances of the class `EnclosedScope` implement a scope that is lexically en
closed in |
| 8562 * another scope. | 8793 * another scope. |
| 8563 * @coverage dart.engine.resolver | 8794 * @coverage dart.engine.resolver |
| 8564 */ | 8795 */ |
| 8565 class EnclosedScope extends Scope { | 8796 class EnclosedScope extends Scope { |
| 8566 | 8797 |
| 8567 /** | 8798 /** |
| 8568 * The scope in which this scope is lexically enclosed. | 8799 * The scope in which this scope is lexically enclosed. |
| 8569 */ | 8800 */ |
| 8570 Scope _enclosingScope; | 8801 Scope _enclosingScope; |
| 8571 | 8802 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 8586 Scope get enclosingScope => _enclosingScope; | 8817 Scope get enclosingScope => _enclosingScope; |
| 8587 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library) { | 8818 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library) { |
| 8588 Element element = localLookup(name, referencingLibrary); | 8819 Element element = localLookup(name, referencingLibrary); |
| 8589 if (element != null) { | 8820 if (element != null) { |
| 8590 return element; | 8821 return element; |
| 8591 } | 8822 } |
| 8592 return _enclosingScope.lookup3(identifier, name, referencingLibrary); | 8823 return _enclosingScope.lookup3(identifier, name, referencingLibrary); |
| 8593 } | 8824 } |
| 8594 } | 8825 } |
| 8595 /** | 8826 /** |
| 8596 * Instances of the class {@code FunctionScope} implement the scope defined by a
function. | 8827 * Instances of the class `FunctionScope` implement the scope defined by a funct
ion. |
| 8597 * @coverage dart.engine.resolver | 8828 * @coverage dart.engine.resolver |
| 8598 */ | 8829 */ |
| 8599 class FunctionScope extends EnclosedScope { | 8830 class FunctionScope extends EnclosedScope { |
| 8600 | 8831 |
| 8601 /** | 8832 /** |
| 8602 * Initialize a newly created scope enclosed within another scope. | 8833 * Initialize a newly created scope enclosed within another scope. |
| 8603 * @param enclosingScope the scope in which this scope is lexically enclosed | 8834 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 8604 * @param functionElement the element representing the type represented by thi
s scope | 8835 * @param functionElement the element representing the type represented by thi
s scope |
| 8605 */ | 8836 */ |
| 8606 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super
(new EnclosedScope(enclosingScope)) { | 8837 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super
(new EnclosedScope(enclosingScope)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 8620 } | 8851 } |
| 8621 } | 8852 } |
| 8622 for (ParameterElement parameter in functionElement.parameters) { | 8853 for (ParameterElement parameter in functionElement.parameters) { |
| 8623 if (!parameter.isInitializingFormal()) { | 8854 if (!parameter.isInitializingFormal()) { |
| 8624 parameterScope.define(parameter); | 8855 parameterScope.define(parameter); |
| 8625 } | 8856 } |
| 8626 } | 8857 } |
| 8627 } | 8858 } |
| 8628 } | 8859 } |
| 8629 /** | 8860 /** |
| 8630 * Instances of the class {@code FunctionTypeScope} implement the scope defined
by a function type | 8861 * Instances of the class `FunctionTypeScope` implement the scope defined by a f
unction type |
| 8631 * alias. | 8862 * alias. |
| 8632 * @coverage dart.engine.resolver | 8863 * @coverage dart.engine.resolver |
| 8633 */ | 8864 */ |
| 8634 class FunctionTypeScope extends EnclosedScope { | 8865 class FunctionTypeScope extends EnclosedScope { |
| 8635 | 8866 |
| 8636 /** | 8867 /** |
| 8637 * Initialize a newly created scope enclosed within another scope. | 8868 * Initialize a newly created scope enclosed within another scope. |
| 8638 * @param enclosingScope the scope in which this scope is lexically enclosed | 8869 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 8639 * @param typeElement the element representing the type alias represented by t
his scope | 8870 * @param typeElement the element representing the type alias represented by t
his scope |
| 8640 */ | 8871 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 8658 * @param typeElement the element representing the type represented by this sc
ope | 8889 * @param typeElement the element representing the type represented by this sc
ope |
| 8659 */ | 8890 */ |
| 8660 void defineTypeVariables(FunctionTypeAliasElement typeElement) { | 8891 void defineTypeVariables(FunctionTypeAliasElement typeElement) { |
| 8661 Scope typeVariableScope = enclosingScope; | 8892 Scope typeVariableScope = enclosingScope; |
| 8662 for (TypeVariableElement typeVariable in typeElement.typeVariables) { | 8893 for (TypeVariableElement typeVariable in typeElement.typeVariables) { |
| 8663 typeVariableScope.define(typeVariable); | 8894 typeVariableScope.define(typeVariable); |
| 8664 } | 8895 } |
| 8665 } | 8896 } |
| 8666 } | 8897 } |
| 8667 /** | 8898 /** |
| 8668 * Instances of the class {@code LabelScope} represent a scope in which a single
label is defined. | 8899 * Instances of the class `LabelScope` represent a scope in which a single label
is defined. |
| 8669 * @coverage dart.engine.resolver | 8900 * @coverage dart.engine.resolver |
| 8670 */ | 8901 */ |
| 8671 class LabelScope { | 8902 class LabelScope { |
| 8672 | 8903 |
| 8673 /** | 8904 /** |
| 8674 * The label scope enclosing this label scope. | 8905 * The label scope enclosing this label scope. |
| 8675 */ | 8906 */ |
| 8676 LabelScope _outerScope; | 8907 LabelScope _outerScope; |
| 8677 | 8908 |
| 8678 /** | 8909 /** |
| 8679 * The label defined in this scope. | 8910 * The label defined in this scope. |
| 8680 */ | 8911 */ |
| 8681 String _label; | 8912 String _label; |
| 8682 | 8913 |
| 8683 /** | 8914 /** |
| 8684 * The element to which the label resolves. | 8915 * The element to which the label resolves. |
| 8685 */ | 8916 */ |
| 8686 LabelElement _element; | 8917 LabelElement _element; |
| 8687 | 8918 |
| 8688 /** | 8919 /** |
| 8689 * The marker used to look up a label element for an unlabeled {@code break} o
r {@code continue}. | 8920 * The marker used to look up a label element for an unlabeled `break` or `con
tinue`. |
| 8690 */ | 8921 */ |
| 8691 static String EMPTY_LABEL = ""; | 8922 static String EMPTY_LABEL = ""; |
| 8692 | 8923 |
| 8693 /** | 8924 /** |
| 8694 * The label element returned for scopes that can be the target of an unlabele
d {@code break} or{@code continue}. | 8925 * The label element returned for scopes that can be the target of an unlabele
d `break` or`continue`. |
| 8695 */ | 8926 */ |
| 8696 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne
w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); | 8927 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne
w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); |
| 8697 | 8928 |
| 8698 /** | 8929 /** |
| 8699 * Initialize a newly created scope to represent the potential target of an un
labeled{@code break} or {@code continue}. | 8930 * Initialize a newly created scope to represent the potential target of an un
labeled`break` or `continue`. |
| 8700 * @param outerScope the label scope enclosing the new label scope | 8931 * @param outerScope the label scope enclosing the new label scope |
| 8701 * @param onSwitchStatement {@code true} if this label is associated with a {@
code switch}statement | 8932 * @param onSwitchStatement `true` if this label is associated with a `switch`
statement |
| 8702 * @param onSwitchMember {@code true} if this label is associated with a {@cod
e switch} member | 8933 * @param onSwitchMember `true` if this label is associated with a `switch` me
mber |
| 8703 */ | 8934 */ |
| 8704 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe
mber) { | 8935 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe
mber) { |
| 8705 _jtd_constructor_287_impl(outerScope, onSwitchStatement, onSwitchMember); | 8936 _jtd_constructor_288_impl(outerScope, onSwitchStatement, onSwitchMember); |
| 8706 } | 8937 } |
| 8707 _jtd_constructor_287_impl(LabelScope outerScope, bool onSwitchStatement, bool
onSwitchMember) { | 8938 _jtd_constructor_288_impl(LabelScope outerScope, bool onSwitchStatement, bool
onSwitchMember) { |
| 8708 _jtd_constructor_288_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP
TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); | 8939 _jtd_constructor_289_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP
TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); |
| 8709 } | 8940 } |
| 8710 | 8941 |
| 8711 /** | 8942 /** |
| 8712 * Initialize a newly created scope to represent the given label. | 8943 * Initialize a newly created scope to represent the given label. |
| 8713 * @param outerScope the label scope enclosing the new label scope | 8944 * @param outerScope the label scope enclosing the new label scope |
| 8714 * @param label the label defined in this scope | 8945 * @param label the label defined in this scope |
| 8715 * @param element the element to which the label resolves | 8946 * @param element the element to which the label resolves |
| 8716 */ | 8947 */ |
| 8717 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2)
{ | 8948 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2)
{ |
| 8718 _jtd_constructor_288_impl(outerScope2, label2, element2); | 8949 _jtd_constructor_289_impl(outerScope2, label2, element2); |
| 8719 } | 8950 } |
| 8720 _jtd_constructor_288_impl(LabelScope outerScope2, String label2, LabelElement
element2) { | 8951 _jtd_constructor_289_impl(LabelScope outerScope2, String label2, LabelElement
element2) { |
| 8721 this._outerScope = outerScope2; | 8952 this._outerScope = outerScope2; |
| 8722 this._label = label2; | 8953 this._label = label2; |
| 8723 this._element = element2; | 8954 this._element = element2; |
| 8724 } | 8955 } |
| 8725 | 8956 |
| 8726 /** | 8957 /** |
| 8727 * Return the label element corresponding to the given label, or {@code null}
if the given label | 8958 * Return the label element corresponding to the given label, or `null` if the
given label |
| 8728 * is not defined in this scope. | 8959 * is not defined in this scope. |
| 8729 * @param targetLabel the label being looked up | 8960 * @param targetLabel the label being looked up |
| 8730 * @return the label element corresponding to the given label | 8961 * @return the label element corresponding to the given label |
| 8731 */ | 8962 */ |
| 8732 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name)
; | 8963 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name)
; |
| 8733 | 8964 |
| 8734 /** | 8965 /** |
| 8735 * Return the label element corresponding to the given label, or {@code null}
if the given label | 8966 * Return the label element corresponding to the given label, or `null` if the
given label |
| 8736 * is not defined in this scope. | 8967 * is not defined in this scope. |
| 8737 * @param targetLabel the label being looked up | 8968 * @param targetLabel the label being looked up |
| 8738 * @return the label element corresponding to the given label | 8969 * @return the label element corresponding to the given label |
| 8739 */ | 8970 */ |
| 8740 LabelElement lookup2(String targetLabel) { | 8971 LabelElement lookup2(String targetLabel) { |
| 8741 if (_label == targetLabel) { | 8972 if (_label == targetLabel) { |
| 8742 return _element; | 8973 return _element; |
| 8743 } else if (_outerScope != null) { | 8974 } else if (_outerScope != null) { |
| 8744 return _outerScope.lookup2(targetLabel); | 8975 return _outerScope.lookup2(targetLabel); |
| 8745 } else { | 8976 } else { |
| 8746 return null; | 8977 return null; |
| 8747 } | 8978 } |
| 8748 } | 8979 } |
| 8749 } | 8980 } |
| 8750 /** | 8981 /** |
| 8751 * Instances of the class {@code LibraryImportScope} represent the scope contain
ing all of the names | 8982 * Instances of the class `LibraryImportScope` represent the scope containing al
l of the names |
| 8752 * available from imported libraries. | 8983 * available from imported libraries. |
| 8753 * @coverage dart.engine.resolver | 8984 * @coverage dart.engine.resolver |
| 8754 */ | 8985 */ |
| 8755 class LibraryImportScope extends Scope { | 8986 class LibraryImportScope extends Scope { |
| 8756 | 8987 |
| 8757 /** | 8988 /** |
| 8758 * @return {@code true} if the given {@link Identifier} is the part of type an
notation. | 8989 * @return `true` if the given [Identifier] is the part of type annotation. |
| 8759 */ | 8990 */ |
| 8760 static bool isTypeAnnotation(Identifier identifier) { | 8991 static bool isTypeAnnotation(Identifier identifier) { |
| 8761 ASTNode parent = identifier.parent; | 8992 ASTNode parent = identifier.parent; |
| 8762 if (parent is TypeName) { | 8993 if (parent is TypeName) { |
| 8763 ASTNode parent2 = parent.parent; | 8994 ASTNode parent2 = parent.parent; |
| 8764 if (parent2 is FunctionDeclaration) { | 8995 if (parent2 is FunctionDeclaration) { |
| 8765 FunctionDeclaration decl = parent2 as FunctionDeclaration; | 8996 FunctionDeclaration decl = parent2 as FunctionDeclaration; |
| 8766 return identical(decl.returnType, parent); | 8997 return identical(decl.returnType, parent); |
| 8767 } | 8998 } |
| 8768 if (parent2 is FunctionTypeAlias) { | 8999 if (parent2 is FunctionTypeAlias) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8877 * which namespaces will be created | 9108 * which namespaces will be created |
| 8878 */ | 9109 */ |
| 8879 void createImportedNamespaces(LibraryElement definingLibrary) { | 9110 void createImportedNamespaces(LibraryElement definingLibrary) { |
| 8880 NamespaceBuilder builder = new NamespaceBuilder(); | 9111 NamespaceBuilder builder = new NamespaceBuilder(); |
| 8881 for (ImportElement element in definingLibrary.imports) { | 9112 for (ImportElement element in definingLibrary.imports) { |
| 8882 _importedNamespaces.add(builder.createImportNamespace(element)); | 9113 _importedNamespaces.add(builder.createImportNamespace(element)); |
| 8883 } | 9114 } |
| 8884 } | 9115 } |
| 8885 } | 9116 } |
| 8886 /** | 9117 /** |
| 8887 * Instances of the class {@code LibraryScope} implement a scope containing all
of the names defined | 9118 * Instances of the class `LibraryScope` implement a scope containing all of the
names defined |
| 8888 * in a given library. | 9119 * in a given library. |
| 8889 * @coverage dart.engine.resolver | 9120 * @coverage dart.engine.resolver |
| 8890 */ | 9121 */ |
| 8891 class LibraryScope extends EnclosedScope { | 9122 class LibraryScope extends EnclosedScope { |
| 8892 | 9123 |
| 8893 /** | 9124 /** |
| 8894 * Initialize a newly created scope representing the names defined in the give
n library. | 9125 * Initialize a newly created scope representing the names defined in the give
n library. |
| 8895 * @param definingLibrary the element representing the library represented by
this scope | 9126 * @param definingLibrary the element representing the library represented by
this scope |
| 8896 * @param errorListener the listener that is to be informed when an error is e
ncountered | 9127 * @param errorListener the listener that is to be informed when an error is e
ncountered |
| 8897 */ | 9128 */ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8942 for (PrefixElement prefix in definingLibrary.prefixes) { | 9173 for (PrefixElement prefix in definingLibrary.prefixes) { |
| 8943 define(prefix); | 9174 define(prefix); |
| 8944 } | 9175 } |
| 8945 defineLocalNames(definingLibrary.definingCompilationUnit); | 9176 defineLocalNames(definingLibrary.definingCompilationUnit); |
| 8946 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { | 9177 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { |
| 8947 defineLocalNames(compilationUnit); | 9178 defineLocalNames(compilationUnit); |
| 8948 } | 9179 } |
| 8949 } | 9180 } |
| 8950 } | 9181 } |
| 8951 /** | 9182 /** |
| 8952 * Instances of the class {@code Namespace} implement a mapping of identifiers t
o the elements | 9183 * Instances of the class `Namespace` implement a mapping of identifiers to the
elements |
| 8953 * represented by those identifiers. Namespaces are the building blocks for scop
es. | 9184 * represented by those identifiers. Namespaces are the building blocks for scop
es. |
| 8954 * @coverage dart.engine.resolver | 9185 * @coverage dart.engine.resolver |
| 8955 */ | 9186 */ |
| 8956 class Namespace { | 9187 class Namespace { |
| 8957 | 9188 |
| 8958 /** | 9189 /** |
| 8959 * A table mapping names that are defined in this namespace to the element rep
resenting the thing | 9190 * A table mapping names that are defined in this namespace to the element rep
resenting the thing |
| 8960 * declared with that name. | 9191 * declared with that name. |
| 8961 */ | 9192 */ |
| 8962 Map<String, Element> _definedNames; | 9193 Map<String, Element> _definedNames; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 8983 */ | 9214 */ |
| 8984 Element get(String name) => _definedNames[name]; | 9215 Element get(String name) => _definedNames[name]; |
| 8985 | 9216 |
| 8986 /** | 9217 /** |
| 8987 * Return a table containing the same mappings as those defined by this namesp
ace. | 9218 * Return a table containing the same mappings as those defined by this namesp
ace. |
| 8988 * @return a table containing the same mappings as those defined by this names
pace | 9219 * @return a table containing the same mappings as those defined by this names
pace |
| 8989 */ | 9220 */ |
| 8990 Map<String, Element> get definedNames => new Map<String, Element>.from(_define
dNames); | 9221 Map<String, Element> get definedNames => new Map<String, Element>.from(_define
dNames); |
| 8991 } | 9222 } |
| 8992 /** | 9223 /** |
| 8993 * Instances of the class {@code NamespaceBuilder} are used to build a {@code Na
mespace}. Namespace | 9224 * Instances of the class `NamespaceBuilder` are used to build a `Namespace`. Na
mespace |
| 8994 * builders are thread-safe and re-usable. | 9225 * builders are thread-safe and re-usable. |
| 8995 * @coverage dart.engine.resolver | 9226 * @coverage dart.engine.resolver |
| 8996 */ | 9227 */ |
| 8997 class NamespaceBuilder { | 9228 class NamespaceBuilder { |
| 8998 | 9229 |
| 8999 /** | 9230 /** |
| 9000 * Create a namespace representing the export namespace of the given {@link Ex
portElement}. | 9231 * Create a namespace representing the export namespace of the given [ExportEl
ement]. |
| 9001 * @param element the export element whose export namespace is to be created | 9232 * @param element the export element whose export namespace is to be created |
| 9002 * @return the export namespace that was created | 9233 * @return the export namespace that was created |
| 9003 */ | 9234 */ |
| 9004 Namespace createExportNamespace(ExportElement element) { | 9235 Namespace createExportNamespace(ExportElement element) { |
| 9005 LibraryElement exportedLibrary = element.exportedLibrary; | 9236 LibraryElement exportedLibrary = element.exportedLibrary; |
| 9006 if (exportedLibrary == null) { | 9237 if (exportedLibrary == null) { |
| 9007 return Namespace.EMPTY; | 9238 return Namespace.EMPTY; |
| 9008 } | 9239 } |
| 9009 Map<String, Element> definedNames = createExportMapping(exportedLibrary, new
Set<LibraryElement>()); | 9240 Map<String, Element> definedNames = createExportMapping(exportedLibrary, new
Set<LibraryElement>()); |
| 9010 definedNames = apply(definedNames, element.combinators); | 9241 definedNames = apply(definedNames, element.combinators); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9195 String setterName = "${name}="; | 9426 String setterName = "${name}="; |
| 9196 element = definedNames[setterName]; | 9427 element = definedNames[setterName]; |
| 9197 if (element != null) { | 9428 if (element != null) { |
| 9198 newNames[setterName] = element; | 9429 newNames[setterName] = element; |
| 9199 } | 9430 } |
| 9200 } | 9431 } |
| 9201 return newNames; | 9432 return newNames; |
| 9202 } | 9433 } |
| 9203 } | 9434 } |
| 9204 /** | 9435 /** |
| 9205 * The abstract class {@code Scope} defines the behavior common to name scopes u
sed by the resolver | 9436 * The abstract class `Scope` defines the behavior common to name scopes used by
the resolver |
| 9206 * to determine which names are visible at any given point in the code. | 9437 * to determine which names are visible at any given point in the code. |
| 9207 * @coverage dart.engine.resolver | 9438 * @coverage dart.engine.resolver |
| 9208 */ | 9439 */ |
| 9209 abstract class Scope { | 9440 abstract class Scope { |
| 9210 | 9441 |
| 9211 /** | 9442 /** |
| 9212 * The prefix used to mark an identifier as being private to its library. | 9443 * The prefix used to mark an identifier as being private to its library. |
| 9213 */ | 9444 */ |
| 9214 static String PRIVATE_NAME_PREFIX = "_"; | 9445 static String PRIVATE_NAME_PREFIX = "_"; |
| 9215 | 9446 |
| 9216 /** | 9447 /** |
| 9217 * The suffix added to the declared name of a setter when looking up the sette
r. Used to | 9448 * The suffix added to the declared name of a setter when looking up the sette
r. Used to |
| 9218 * disambiguate between a getter and a setter that have the same name. | 9449 * disambiguate between a getter and a setter that have the same name. |
| 9219 */ | 9450 */ |
| 9220 static String SETTER_SUFFIX = "="; | 9451 static String SETTER_SUFFIX = "="; |
| 9221 | 9452 |
| 9222 /** | 9453 /** |
| 9223 * The name used to look up the method used to implement the unary minus opera
tor. Used to | 9454 * The name used to look up the method used to implement the unary minus opera
tor. Used to |
| 9224 * disambiguate between the unary and binary operators. | 9455 * disambiguate between the unary and binary operators. |
| 9225 */ | 9456 */ |
| 9226 static String UNARY_MINUS = "unary-"; | 9457 static String UNARY_MINUS = "unary-"; |
| 9227 | 9458 |
| 9228 /** | 9459 /** |
| 9229 * Return {@code true} if the given name is a library-private name. | 9460 * Return `true` if the given name is a library-private name. |
| 9230 * @param name the name being tested | 9461 * @param name the name being tested |
| 9231 * @return {@code true} if the given name is a library-private name | 9462 * @return `true` if the given name is a library-private name |
| 9232 */ | 9463 */ |
| 9233 static bool isPrivateName(String name) => name != null && name.startsWith(PRIV
ATE_NAME_PREFIX); | 9464 static bool isPrivateName(String name) => name != null && name.startsWith(PRIV
ATE_NAME_PREFIX); |
| 9234 | 9465 |
| 9235 /** | 9466 /** |
| 9236 * A table mapping names that are defined in this scope to the element represe
nting the thing | 9467 * A table mapping names that are defined in this scope to the element represe
nting the thing |
| 9237 * declared with that name. | 9468 * declared with that name. |
| 9238 */ | 9469 */ |
| 9239 Map<String, Element> _definedNames = new Map<String, Element>(); | 9470 Map<String, Element> _definedNames = new Map<String, Element>(); |
| 9240 | 9471 |
| 9241 /** | 9472 /** |
| 9242 * Add the given element to this scope. If there is already an element with th
e given name defined | 9473 * Add the given element to this scope. If there is already an element with th
e given name defined |
| 9243 * in this scope, then an error will be generated and the original element wil
l continue to be | 9474 * in this scope, then an error will be generated and the original element wil
l continue to be |
| 9244 * mapped to the name. If there is an element with the given name in an enclos
ing scope, then a | 9475 * mapped to the name. If there is an element with the given name in an enclos
ing scope, then a |
| 9245 * warning will be generated but the given element will hide the inherited ele
ment. | 9476 * warning will be generated but the given element will hide the inherited ele
ment. |
| 9246 * @param element the element to be added to this scope | 9477 * @param element the element to be added to this scope |
| 9247 */ | 9478 */ |
| 9248 void define(Element element) { | 9479 void define(Element element) { |
| 9249 String name = getName(element); | 9480 String name = getName(element); |
| 9250 if (name != null && !name.isEmpty) { | 9481 if (name != null && !name.isEmpty) { |
| 9251 if (_definedNames.containsKey(name)) { | 9482 if (_definedNames.containsKey(name)) { |
| 9252 errorListener.onError(getErrorForDuplicate(_definedNames[name], element)
); | 9483 errorListener.onError(getErrorForDuplicate(_definedNames[name], element)
); |
| 9253 } else { | 9484 } else { |
| 9254 _definedNames[name] = element; | 9485 _definedNames[name] = element; |
| 9255 } | 9486 } |
| 9256 } | 9487 } |
| 9257 } | 9488 } |
| 9258 | 9489 |
| 9259 /** | 9490 /** |
| 9260 * Return the element with which the given identifier is associated, or {@code
null} if the name | 9491 * Return the element with which the given identifier is associated, or `null`
if the name |
| 9261 * is not defined within this scope. | 9492 * is not defined within this scope. |
| 9262 * @param identifier the identifier associated with the element to be returned | 9493 * @param identifier the identifier associated with the element to be returned |
| 9263 * @param referencingLibrary the library that contains the reference to the na
me, used to | 9494 * @param referencingLibrary the library that contains the reference to the na
me, used to |
| 9264 * implement library-level privacy | 9495 * implement library-level privacy |
| 9265 * @return the element with which the given identifier is associated | 9496 * @return the element with which the given identifier is associated |
| 9266 */ | 9497 */ |
| 9267 Element lookup(Identifier identifier, LibraryElement referencingLibrary) => lo
okup3(identifier, identifier.name, referencingLibrary); | 9498 Element lookup(Identifier identifier, LibraryElement referencingLibrary) => lo
okup3(identifier, identifier.name, referencingLibrary); |
| 9268 | 9499 |
| 9269 /** | 9500 /** |
| 9270 * Add the given element to this scope without checking for duplication or hid
ing. | 9501 * Add the given element to this scope without checking for duplication or hid
ing. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9311 AnalysisErrorListener get errorListener; | 9542 AnalysisErrorListener get errorListener; |
| 9312 | 9543 |
| 9313 /** | 9544 /** |
| 9314 * Return the source object representing the compilation unit with which error
s related to this | 9545 * Return the source object representing the compilation unit with which error
s related to this |
| 9315 * scope should be associated. | 9546 * scope should be associated. |
| 9316 * @return the source object with which errors should be associated | 9547 * @return the source object with which errors should be associated |
| 9317 */ | 9548 */ |
| 9318 Source get source => definingLibrary.definingCompilationUnit.source; | 9549 Source get source => definingLibrary.definingCompilationUnit.source; |
| 9319 | 9550 |
| 9320 /** | 9551 /** |
| 9321 * Return the element with which the given name is associated, or {@code null}
if the name is not | 9552 * Return the element with which the given name is associated, or `null` if th
e name is not |
| 9322 * defined within this scope. This method only returns elements that are direc
tly defined within | 9553 * defined within this scope. This method only returns elements that are direc
tly defined within |
| 9323 * this scope, not elements that are defined in an enclosing scope. | 9554 * this scope, not elements that are defined in an enclosing scope. |
| 9324 * @param name the name associated with the element to be returned | 9555 * @param name the name associated with the element to be returned |
| 9325 * @param referencingLibrary the library that contains the reference to the na
me, used to | 9556 * @param referencingLibrary the library that contains the reference to the na
me, used to |
| 9326 * implement library-level privacy | 9557 * implement library-level privacy |
| 9327 * @return the element with which the given name is associated | 9558 * @return the element with which the given name is associated |
| 9328 */ | 9559 */ |
| 9329 Element localLookup(String name, LibraryElement referencingLibrary) => _define
dNames[name]; | 9560 Element localLookup(String name, LibraryElement referencingLibrary) => _define
dNames[name]; |
| 9330 | 9561 |
| 9331 /** | 9562 /** |
| 9332 * Return the element with which the given name is associated, or {@code null}
if the name is not | 9563 * Return the element with which the given name is associated, or `null` if th
e name is not |
| 9333 * defined within this scope. | 9564 * defined within this scope. |
| 9334 * @param identifier the identifier node to lookup element for, used to report
correct kind of a | 9565 * @param identifier the identifier node to lookup element for, used to report
correct kind of a |
| 9335 * problem and associate problem with | 9566 * problem and associate problem with |
| 9336 * @param name the name associated with the element to be returned | 9567 * @param name the name associated with the element to be returned |
| 9337 * @param referencingLibrary the library that contains the reference to the na
me, used to | 9568 * @param referencingLibrary the library that contains the reference to the na
me, used to |
| 9338 * implement library-level privacy | 9569 * implement library-level privacy |
| 9339 * @return the element with which the given name is associated | 9570 * @return the element with which the given name is associated |
| 9340 */ | 9571 */ |
| 9341 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library); | 9572 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library); |
| 9342 | 9573 |
| 9343 /** | 9574 /** |
| 9344 * Return the name that will be used to look up the given element. | 9575 * Return the name that will be used to look up the given element. |
| 9345 * @param element the element whose look-up name is to be returned | 9576 * @param element the element whose look-up name is to be returned |
| 9346 * @return the name that will be used to look up the given element | 9577 * @return the name that will be used to look up the given element |
| 9347 */ | 9578 */ |
| 9348 String getName(Element element) { | 9579 String getName(Element element) { |
| 9349 if (element is MethodElement) { | 9580 if (element is MethodElement) { |
| 9350 MethodElement method = element as MethodElement; | 9581 MethodElement method = element as MethodElement; |
| 9351 if (method.name == "-" && method.parameters.length == 0) { | 9582 if (method.name == "-" && method.parameters.length == 0) { |
| 9352 return UNARY_MINUS; | 9583 return UNARY_MINUS; |
| 9353 } | 9584 } |
| 9354 } | 9585 } |
| 9355 return element.name; | 9586 return element.name; |
| 9356 } | 9587 } |
| 9357 } | 9588 } |
| 9358 /** | 9589 /** |
| 9359 * Instances of the class {@code ConstantVerifier} traverse an AST structure loo
king for additional | 9590 * Instances of the class `ConstantVerifier` traverse an AST structure looking f
or additional |
| 9360 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors | 9591 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors |
| 9361 * and warnings related to constant expressions. | 9592 * and warnings related to constant expressions. |
| 9362 * @coverage dart.engine.resolver | 9593 * @coverage dart.engine.resolver |
| 9363 */ | 9594 */ |
| 9364 class ConstantVerifier extends RecursiveASTVisitor<Object> { | 9595 class ConstantVerifier extends RecursiveASTVisitor<Object> { |
| 9365 | 9596 |
| 9366 /** | 9597 /** |
| 9367 * The error reporter by which errors will be reported. | 9598 * The error reporter by which errors will be reported. |
| 9368 */ | 9599 */ |
| 9369 ErrorReporter _errorReporter; | 9600 ErrorReporter _errorReporter; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 9396 this._errorReporter = errorReporter; | 9627 this._errorReporter = errorReporter; |
| 9397 this._boolType = typeProvider.boolType; | 9628 this._boolType = typeProvider.boolType; |
| 9398 this._intType = typeProvider.intType; | 9629 this._intType = typeProvider.intType; |
| 9399 this._numType = typeProvider.numType; | 9630 this._numType = typeProvider.numType; |
| 9400 this._stringType = typeProvider.stringType; | 9631 this._stringType = typeProvider.stringType; |
| 9401 } | 9632 } |
| 9402 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 9633 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 9403 if (node.constKeyword != null) { | 9634 if (node.constKeyword != null) { |
| 9404 validateInitializers(node); | 9635 validateInitializers(node); |
| 9405 } | 9636 } |
| 9637 validateDefaultValues(node.parameters); |
| 9406 return super.visitConstructorDeclaration(node); | 9638 return super.visitConstructorDeclaration(node); |
| 9407 } | 9639 } |
| 9408 Object visitFunctionExpression(FunctionExpression node) { | 9640 Object visitFunctionExpression(FunctionExpression node) { |
| 9409 super.visitFunctionExpression(node); | 9641 super.visitFunctionExpression(node); |
| 9410 validateDefaultValues(node.parameters); | 9642 validateDefaultValues(node.parameters); |
| 9411 return null; | 9643 return null; |
| 9412 } | 9644 } |
| 9413 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 9645 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 9414 validateConstantArguments(node); | 9646 validateConstantArguments(node); |
| 9415 return super.visitInstanceCreationExpression(node); | 9647 return super.visitInstanceCreationExpression(node); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9483 result = validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_WI
TH_NON_CONSTANT_VALUE); | 9715 result = validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_WI
TH_NON_CONSTANT_VALUE); |
| 9484 element.evaluationResult = result; | 9716 element.evaluationResult = result; |
| 9485 } else if (result is ErrorResult) { | 9717 } else if (result is ErrorResult) { |
| 9486 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON
STANT_VALUE); | 9718 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON
STANT_VALUE); |
| 9487 } | 9719 } |
| 9488 } | 9720 } |
| 9489 return null; | 9721 return null; |
| 9490 } | 9722 } |
| 9491 | 9723 |
| 9492 /** | 9724 /** |
| 9493 * Return {@code true} if the given value is the result of evaluating an expre
ssion whose value is | 9725 * Return `true` if the given value is the result of evaluating an expression
whose value is |
| 9494 * a valid key in a const map literal. Keys in const map literals must be eith
er a string, number, | 9726 * a valid key in a const map literal. Keys in const map literals must be eith
er a string, number, |
| 9495 * boolean, list, map, or null. | 9727 * boolean, list, map, or null. |
| 9496 * @param value | 9728 * @param value |
| 9497 * @return {@code true} if the given value is a valid key in a const map liter
al | 9729 * @return `true` if the given value is a valid key in a const map literal |
| 9498 */ | 9730 */ |
| 9499 bool isValidConstMapKey(Object value) => true; | 9731 bool isValidConstMapKey(Object value) => true; |
| 9500 | 9732 |
| 9501 /** | 9733 /** |
| 9502 * If the given result represents one or more errors, report those errors. Exc
ept for special | 9734 * If the given result represents one or more errors, report those errors. Exc
ept for special |
| 9503 * cases, use the given error code rather than the one reported in the error. | 9735 * cases, use the given error code rather than the one reported in the error. |
| 9504 * @param result the result containing any errors that need to be reported | 9736 * @param result the result containing any errors that need to be reported |
| 9505 * @param errorCode the error code to be used if the result represents an erro
r | 9737 * @param errorCode the error code to be used if the result represents an erro
r |
| 9506 */ | 9738 */ |
| 9507 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode2) { | 9739 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode2) { |
| 9508 if (result is ErrorResult) { | 9740 if (result is ErrorResult) { |
| 9509 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { | 9741 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { |
| 9510 ErrorCode dataErrorCode = data.errorCode; | 9742 ErrorCode dataErrorCode = data.errorCode; |
| 9511 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCE
PTION) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM
_STRING) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL)
|| identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || identic
al(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM)) { | 9743 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCE
PTION) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM
_STRING) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL)
|| identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || identic
al(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM)) { |
| 9512 _errorReporter.reportError2(dataErrorCode, data.node, []); | 9744 _errorReporter.reportError2(dataErrorCode, data.node, []); |
| 9513 } else { | 9745 } else { |
| 9514 _errorReporter.reportError2(errorCode2, data.node, []); | 9746 _errorReporter.reportError2(errorCode2, data.node, []); |
| 9515 } | 9747 } |
| 9516 } | 9748 } |
| 9517 } | 9749 } |
| 9518 } | 9750 } |
| 9519 | 9751 |
| 9520 /** | 9752 /** |
| 9521 * Validate that the given expression is a compile time constant. Return the v
alue of the compile | 9753 * Validate that the given expression is a compile time constant. Return the v
alue of the compile |
| 9522 * time constant, or {@code null} if the expression is not a compile time cons
tant. | 9754 * time constant, or `null` if the expression is not a compile time constant. |
| 9523 * @param expression the expression to be validated | 9755 * @param expression the expression to be validated |
| 9524 * @param errorCode the error code to be used if the expression is not a compi
le time constant | 9756 * @param errorCode the error code to be used if the expression is not a compi
le time constant |
| 9525 * @return the value of the compile time constant | 9757 * @return the value of the compile time constant |
| 9526 */ | 9758 */ |
| 9527 EvaluationResultImpl validate(Expression expression, ErrorCode errorCode) { | 9759 EvaluationResultImpl validate(Expression expression, ErrorCode errorCode) { |
| 9528 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); | 9760 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); |
| 9529 reportErrors(result, errorCode); | 9761 reportErrors(result, errorCode); |
| 9530 return result; | 9762 return result; |
| 9531 } | 9763 } |
| 9532 | 9764 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 9559 void validateDefaultValues(FormalParameterList parameters2) { | 9791 void validateDefaultValues(FormalParameterList parameters2) { |
| 9560 if (parameters2 == null) { | 9792 if (parameters2 == null) { |
| 9561 return; | 9793 return; |
| 9562 } | 9794 } |
| 9563 for (FormalParameter parameter in parameters2.parameters) { | 9795 for (FormalParameter parameter in parameters2.parameters) { |
| 9564 if (parameter is DefaultFormalParameter) { | 9796 if (parameter is DefaultFormalParameter) { |
| 9565 DefaultFormalParameter defaultParameter = parameter as DefaultFormalPara
meter; | 9797 DefaultFormalParameter defaultParameter = parameter as DefaultFormalPara
meter; |
| 9566 Expression defaultValue = defaultParameter.defaultValue; | 9798 Expression defaultValue = defaultParameter.defaultValue; |
| 9567 if (defaultValue != null) { | 9799 if (defaultValue != null) { |
| 9568 EvaluationResultImpl result = validate(defaultValue, CompileTimeErrorC
ode.NON_CONSTANT_DEFAULT_VALUE); | 9800 EvaluationResultImpl result = validate(defaultValue, CompileTimeErrorC
ode.NON_CONSTANT_DEFAULT_VALUE); |
| 9569 if (defaultParameter.isConst()) { | 9801 VariableElementImpl element = parameter.element as VariableElementImpl
; |
| 9570 VariableElementImpl element = parameter.element as VariableElementIm
pl; | 9802 element.evaluationResult = result; |
| 9571 element.evaluationResult = result; | |
| 9572 } | |
| 9573 } | 9803 } |
| 9574 } | 9804 } |
| 9575 } | 9805 } |
| 9576 } | 9806 } |
| 9577 | 9807 |
| 9578 /** | 9808 /** |
| 9579 * Validates that the given expression is a compile time constant. | 9809 * Validates that the given expression is a compile time constant. |
| 9580 * @param parameterElements the elements of parameters of constant constructor
, they are | 9810 * @param parameterElements the elements of parameters of constant constructor
, they are |
| 9581 * considered as a valid potentially constant expressions | 9811 * considered as a valid potentially constant expressions |
| 9582 * @param expression the expression to validate | 9812 * @param expression the expression to validate |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9651 return ValidResult.RESULT_STRING; | 9881 return ValidResult.RESULT_STRING; |
| 9652 } | 9882 } |
| 9653 } | 9883 } |
| 9654 return ValidResult.RESULT_OBJECT; | 9884 return ValidResult.RESULT_OBJECT; |
| 9655 } | 9885 } |
| 9656 } | 9886 } |
| 9657 return super.visitSimpleIdentifier(node); | 9887 return super.visitSimpleIdentifier(node); |
| 9658 } | 9888 } |
| 9659 } | 9889 } |
| 9660 /** | 9890 /** |
| 9661 * Instances of the class {@code ErrorVerifier} traverse an AST structure lookin
g for additional | 9891 * Instances of the class `ErrorVerifier` traverse an AST structure looking for
additional |
| 9662 * errors and warnings not covered by the parser and resolver. | 9892 * errors and warnings not covered by the parser and resolver. |
| 9663 * @coverage dart.engine.resolver | 9893 * @coverage dart.engine.resolver |
| 9664 */ | 9894 */ |
| 9665 class ErrorVerifier extends RecursiveASTVisitor<Object> { | 9895 class ErrorVerifier extends RecursiveASTVisitor<Object> { |
| 9666 | 9896 |
| 9667 /** | 9897 /** |
| 9668 * Checks if the given expression is the reference to the type. | 9898 * Checks if the given expression is the reference to the type. |
| 9669 * @param expr the expression to evaluate | 9899 * @param expr the expression to evaluate |
| 9670 * @return {@code true} if the given expression is the reference to the type | 9900 * @return `true` if the given expression is the reference to the type |
| 9671 */ | 9901 */ |
| 9672 static bool isTypeReference(Expression expr) { | 9902 static bool isTypeReference(Expression expr) { |
| 9673 if (expr is Identifier) { | 9903 if (expr is Identifier) { |
| 9674 Identifier identifier = expr as Identifier; | 9904 Identifier identifier = expr as Identifier; |
| 9675 return identifier.element is ClassElement; | 9905 return identifier.element is ClassElement; |
| 9676 } | 9906 } |
| 9677 return false; | 9907 return false; |
| 9678 } | 9908 } |
| 9679 | 9909 |
| 9680 /** | 9910 /** |
| (...skipping 21 matching lines...) Expand all Loading... |
| 9702 */ | 9932 */ |
| 9703 InheritanceManager _inheritanceManager; | 9933 InheritanceManager _inheritanceManager; |
| 9704 | 9934 |
| 9705 /** | 9935 /** |
| 9706 * A flag indicating whether we are running in strict mode. In strict mode, er
ror reporting is | 9936 * A flag indicating whether we are running in strict mode. In strict mode, er
ror reporting is |
| 9707 * based exclusively on the static type information. | 9937 * based exclusively on the static type information. |
| 9708 */ | 9938 */ |
| 9709 bool _strictMode = false; | 9939 bool _strictMode = false; |
| 9710 | 9940 |
| 9711 /** | 9941 /** |
| 9712 * This is set to {@code true} iff the visitor is currently visiting children
nodes of a{@link ConstructorDeclaration} and the constructor is 'const'. | 9942 * This is set to `true` iff the visitor is currently visiting children nodes
of a[ConstructorDeclaration] and the constructor is 'const'. |
| 9713 * @see #visitConstructorDeclaration(ConstructorDeclaration) | 9943 * @see #visitConstructorDeclaration(ConstructorDeclaration) |
| 9714 */ | 9944 */ |
| 9715 bool _isEnclosingConstructorConst = false; | 9945 bool _isEnclosingConstructorConst = false; |
| 9716 | 9946 |
| 9717 /** | 9947 /** |
| 9718 * This is set to {@code true} iff the visitor is currently visiting children
nodes of a{@link CatchClause}. | 9948 * This is set to `true` iff the visitor is currently visiting children nodes
of a[CatchClause]. |
| 9719 * @see #visitCatchClause(CatchClause) | 9949 * @see #visitCatchClause(CatchClause) |
| 9720 */ | 9950 */ |
| 9721 bool _isInCatchClause = false; | 9951 bool _isInCatchClause = false; |
| 9722 | 9952 |
| 9723 /** | 9953 /** |
| 9724 * This is set to {@code true} iff the visitor is currently visiting a{@link C
onstructorInitializer}. | 9954 * This is set to `true` iff the visitor is currently visiting a[ConstructorIn
itializer]. |
| 9725 */ | 9955 */ |
| 9726 bool _isInConstructorInitializer = false; | 9956 bool _isInConstructorInitializer = false; |
| 9727 | 9957 |
| 9728 /** | 9958 /** |
| 9729 * This is set to {@code true} iff the visitor is currently visiting code in t
he SDK. | 9959 * This is set to `true` iff the visitor is currently visiting code in the SDK
. |
| 9730 */ | 9960 */ |
| 9731 bool _isInSystemLibrary = false; | 9961 bool _isInSystemLibrary = false; |
| 9732 | 9962 |
| 9733 /** | 9963 /** |
| 9734 * The class containing the AST nodes being visited, or {@code null} if we are
not in the scope of | 9964 * The class containing the AST nodes being visited, or `null` if we are not i
n the scope of |
| 9735 * a class. | 9965 * a class. |
| 9736 */ | 9966 */ |
| 9737 ClassElement _enclosingClass; | 9967 ClassElement _enclosingClass; |
| 9738 | 9968 |
| 9739 /** | 9969 /** |
| 9740 * The method or function that we are currently visiting, or {@code null} if w
e are not inside a | 9970 * The method or function that we are currently visiting, or `null` if we are
not inside a |
| 9741 * method or function. | 9971 * method or function. |
| 9742 */ | 9972 */ |
| 9743 ExecutableElement _enclosingFunction; | 9973 ExecutableElement _enclosingFunction; |
| 9744 | 9974 |
| 9745 /** | 9975 /** |
| 9746 * This map is initialized when visiting the contents of a class declaration.
If the visitor is | 9976 * This map is initialized when visiting the contents of a class declaration.
If the visitor is |
| 9747 * not in an enclosing class declaration, then the map is set to {@code null}. | 9977 * not in an enclosing class declaration, then the map is set to `null`. |
| 9748 * <p> | 9978 * |
| 9749 * When set the map maps the set of {@link FieldElement}s in the class to an{@
link INIT_STATE#NOT_INIT} or {@link INIT_STATE#INIT_IN_DECLARATION}. <code>check
For*</code> | 9979 * When set the map maps the set of [FieldElement]s in the class to an[INIT_ST
ATE#NOT_INIT] or [INIT_STATE#INIT_IN_DECLARATION]. <code>checkFor*</code> |
| 9750 * methods, specifically {@link #checkForAllFinalInitializedErrorCodes(Constru
ctorDeclaration)}, | 9980 * methods, specifically [checkForAllFinalInitializedErrorCodes], |
| 9751 * can make a copy of the map to compute error code states. <code>checkFor*</c
ode> methods should | 9981 * can make a copy of the map to compute error code states. <code>checkFor*</c
ode> methods should |
| 9752 * only ever make a copy, or read from this map after it has been set in{@link
#visitClassDeclaration(ClassDeclaration)}. | 9982 * only ever make a copy, or read from this map after it has been set in[visit
ClassDeclaration]. |
| 9753 * @see #visitClassDeclaration(ClassDeclaration) | 9983 * @see #visitClassDeclaration(ClassDeclaration) |
| 9754 * @see #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration) | 9984 * @see #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration) |
| 9755 */ | 9985 */ |
| 9756 Map<FieldElement, INIT_STATE> _initialFieldElementsMap; | 9986 Map<FieldElement, INIT_STATE> _initialFieldElementsMap; |
| 9757 | 9987 |
| 9758 /** | 9988 /** |
| 9759 * A table mapping name of the library to the export directive which export th
is library. | 9989 * A table mapping name of the library to the export directive which export th
is library. |
| 9760 */ | 9990 */ |
| 9761 Map<String, LibraryElement> _nameToExportElement = new Map<String, LibraryElem
ent>(); | 9991 Map<String, LibraryElement> _nameToExportElement = new Map<String, LibraryElem
ent>(); |
| 9762 | 9992 |
| 9763 /** | 9993 /** |
| 9764 * A table mapping name of the library to the import directive which import th
is library. | 9994 * A table mapping name of the library to the import directive which import th
is library. |
| 9765 */ | 9995 */ |
| 9766 Map<String, LibraryElement> _nameToImportElement = new Map<String, LibraryElem
ent>(); | 9996 Map<String, LibraryElement> _nameToImportElement = new Map<String, LibraryElem
ent>(); |
| 9767 | 9997 |
| 9768 /** | 9998 /** |
| 9769 * A table mapping names to the export elements exported them. | 9999 * A table mapping names to the export elements exported them. |
| 9770 */ | 10000 */ |
| 9771 Map<String, ExportElement> _exportedNames = new Map<String, ExportElement>(); | 10001 Map<String, ExportElement> _exportedNames = new Map<String, ExportElement>(); |
| 9772 | 10002 |
| 9773 /** | 10003 /** |
| 9774 * A set of the names of the variable initializers we are visiting now. | 10004 * A set of the names of the variable initializers we are visiting now. |
| 9775 */ | 10005 */ |
| 9776 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String
>(); | 10006 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String
>(); |
| 9777 | 10007 |
| 9778 /** | 10008 /** |
| 9779 * A list of types used by the {@link CompileTimeErrorCode#EXTENDS_DISALLOWED_
CLASS} and{@link CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS} error codes. | 10009 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS]
and[CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. |
| 9780 */ | 10010 */ |
| 9781 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; | 10011 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; |
| 9782 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider, InheritanceManager inheritanceManager) { | 10012 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider, InheritanceManager inheritanceManager) { |
| 9783 this._errorReporter = errorReporter; | 10013 this._errorReporter = errorReporter; |
| 9784 this._currentLibrary = currentLibrary; | 10014 this._currentLibrary = currentLibrary; |
| 9785 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary(); | 10015 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary(); |
| 9786 this._typeProvider = typeProvider; | 10016 this._typeProvider = typeProvider; |
| 9787 this._inheritanceManager = inheritanceManager; | 10017 this._inheritanceManager = inheritanceManager; |
| 9788 _strictMode = currentLibrary.context.analysisOptions.strictMode; | 10018 _strictMode = currentLibrary.context.analysisOptions.strictMode; |
| 9789 _isEnclosingConstructorConst = false; | 10019 _isEnclosingConstructorConst = false; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9829 } | 10059 } |
| 9830 Object visitClassDeclaration(ClassDeclaration node) { | 10060 Object visitClassDeclaration(ClassDeclaration node) { |
| 9831 ClassElement outerClass = _enclosingClass; | 10061 ClassElement outerClass = _enclosingClass; |
| 9832 try { | 10062 try { |
| 9833 _enclosingClass = node.element; | 10063 _enclosingClass = node.element; |
| 9834 WithClause withClause = node.withClause; | 10064 WithClause withClause = node.withClause; |
| 9835 ImplementsClause implementsClause = node.implementsClause; | 10065 ImplementsClause implementsClause = node.implementsClause; |
| 9836 ExtendsClause extendsClause = node.extendsClause; | 10066 ExtendsClause extendsClause = node.extendsClause; |
| 9837 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I
DENTIFIER_AS_TYPE_NAME); | 10067 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I
DENTIFIER_AS_TYPE_NAME); |
| 9838 checkForMemberWithClassName(); | 10068 checkForMemberWithClassName(); |
| 10069 checkForNoDefaultSuperConstructorImplicit(node); |
| 9839 checkForAllMixinErrorCodes(withClause); | 10070 checkForAllMixinErrorCodes(withClause); |
| 9840 if (implementsClause != null || extendsClause != null) { | 10071 if (implementsClause != null || extendsClause != null) { |
| 9841 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt
endsDisallowedClass(extendsClause)) { | 10072 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt
endsDisallowedClass(extendsClause)) { |
| 9842 checkForNonAbstractClassInheritsAbstractMember(node); | 10073 checkForNonAbstractClassInheritsAbstractMember(node); |
| 9843 checkForInconsistentMethodInheritance(); | 10074 checkForInconsistentMethodInheritance(); |
| 9844 checkForRecursiveInterfaceInheritance(_enclosingClass, new List<ClassE
lement>()); | 10075 checkForRecursiveInterfaceInheritance(_enclosingClass, new List<ClassE
lement>()); |
| 9845 } | 10076 } |
| 9846 } | 10077 } |
| 9847 ClassElement classElement = node.element; | 10078 ClassElement classElement = node.element; |
| 9848 if (classElement != null) { | 10079 if (classElement != null) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9914 Object visitDoStatement(DoStatement node) { | 10145 Object visitDoStatement(DoStatement node) { |
| 9915 checkForNonBoolCondition(node.condition); | 10146 checkForNonBoolCondition(node.condition); |
| 9916 return super.visitDoStatement(node); | 10147 return super.visitDoStatement(node); |
| 9917 } | 10148 } |
| 9918 Object visitExportDirective(ExportDirective node) { | 10149 Object visitExportDirective(ExportDirective node) { |
| 9919 checkForAmbiguousExport(node); | 10150 checkForAmbiguousExport(node); |
| 9920 checkForExportDuplicateLibraryName(node); | 10151 checkForExportDuplicateLibraryName(node); |
| 9921 checkForExportInternalLibrary(node); | 10152 checkForExportInternalLibrary(node); |
| 9922 return super.visitExportDirective(node); | 10153 return super.visitExportDirective(node); |
| 9923 } | 10154 } |
| 10155 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { |
| 10156 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu
nction.type; |
| 10157 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance :
functionType.returnType; |
| 10158 checkForReturnOfInvalidType(node.expression, expectedReturnType); |
| 10159 return super.visitExpressionFunctionBody(node); |
| 10160 } |
| 9924 Object visitFieldDeclaration(FieldDeclaration node) { | 10161 Object visitFieldDeclaration(FieldDeclaration node) { |
| 9925 if (!node.isStatic()) { | 10162 if (!node.isStatic()) { |
| 9926 VariableDeclarationList variables = node.fields; | 10163 VariableDeclarationList variables = node.fields; |
| 9927 if (variables.isConst()) { | 10164 if (variables.isConst()) { |
| 9928 _errorReporter.reportError4(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v
ariables.keyword, []); | 10165 _errorReporter.reportError4(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v
ariables.keyword, []); |
| 9929 } | 10166 } |
| 9930 } | 10167 } |
| 9931 return super.visitFieldDeclaration(node); | 10168 return super.visitFieldDeclaration(node); |
| 9932 } | 10169 } |
| 9933 Object visitFieldFormalParameter(FieldFormalParameter node) { | 10170 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 9934 checkForConstFormalParameter(node); | 10171 checkForConstFormalParameter(node); |
| 9935 checkForFieldInitializingFormalRedirectingConstructor(node); | 10172 checkForFieldInitializingFormalRedirectingConstructor(node); |
| 9936 return super.visitFieldFormalParameter(node); | 10173 return super.visitFieldFormalParameter(node); |
| 9937 } | 10174 } |
| 9938 Object visitFunctionDeclaration(FunctionDeclaration node) { | 10175 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 9939 ExecutableElement outerFunction = _enclosingFunction; | 10176 ExecutableElement outerFunction = _enclosingFunction; |
| 9940 try { | 10177 try { |
| 9941 SimpleIdentifier identifier = node.name; | 10178 SimpleIdentifier identifier = node.name; |
| 9942 String methoName = ""; | 10179 String methodName = ""; |
| 9943 if (identifier != null) { | 10180 if (identifier != null) { |
| 9944 methoName = identifier.name; | 10181 methodName = identifier.name; |
| 9945 } | 10182 } |
| 9946 _enclosingFunction = node.element; | 10183 _enclosingFunction = node.element; |
| 9947 if (node.isSetter() || node.isGetter()) { | 10184 if (node.isSetter() || node.isGetter()) { |
| 9948 checkForMismatchedAccessorTypes(node, methoName); | 10185 checkForMismatchedAccessorTypes(node, methodName); |
| 9949 if (node.isSetter()) { | 10186 if (node.isSetter()) { |
| 9950 FunctionExpression functionExpression = node.functionExpression; | 10187 FunctionExpression functionExpression = node.functionExpression; |
| 9951 if (functionExpression != null) { | 10188 if (functionExpression != null) { |
| 9952 checkForWrongNumberOfParametersForSetter(node.name, functionExpressi
on.parameters); | 10189 checkForWrongNumberOfParametersForSetter(node.name, functionExpressi
on.parameters); |
| 9953 } | 10190 } |
| 9954 TypeName returnType = node.returnType; | 10191 TypeName returnType = node.returnType; |
| 9955 checkForNonVoidReturnTypeForSetter(returnType); | 10192 checkForNonVoidReturnTypeForSetter(returnType); |
| 9956 } | 10193 } |
| 9957 } | 10194 } |
| 9958 return super.visitFunctionDeclaration(node); | 10195 return super.visitFunctionDeclaration(node); |
| 9959 } finally { | 10196 } finally { |
| 9960 _enclosingFunction = outerFunction; | 10197 _enclosingFunction = outerFunction; |
| 9961 } | 10198 } |
| 9962 } | 10199 } |
| 9963 Object visitFunctionExpression(FunctionExpression node) { | 10200 Object visitFunctionExpression(FunctionExpression node) { |
| 9964 ExecutableElement outerFunction = _enclosingFunction; | 10201 if (node.parent is! FunctionDeclaration) { |
| 9965 try { | 10202 ExecutableElement outerFunction = _enclosingFunction; |
| 9966 _enclosingFunction = node.element; | 10203 try { |
| 10204 _enclosingFunction = node.element; |
| 10205 return super.visitFunctionExpression(node); |
| 10206 } finally { |
| 10207 _enclosingFunction = outerFunction; |
| 10208 } |
| 10209 } else { |
| 9967 return super.visitFunctionExpression(node); | 10210 return super.visitFunctionExpression(node); |
| 9968 } finally { | |
| 9969 _enclosingFunction = outerFunction; | |
| 9970 } | 10211 } |
| 9971 } | 10212 } |
| 9972 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 10213 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 9973 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); | 10214 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); |
| 9974 checkForDefaultValueInFunctionTypeAlias(node); | 10215 checkForDefaultValueInFunctionTypeAlias(node); |
| 9975 return super.visitFunctionTypeAlias(node); | 10216 return super.visitFunctionTypeAlias(node); |
| 9976 } | 10217 } |
| 9977 Object visitIfStatement(IfStatement node) { | 10218 Object visitIfStatement(IfStatement node) { |
| 9978 checkForNonBoolCondition(node.condition); | 10219 checkForNonBoolCondition(node.condition); |
| 9979 return super.visitIfStatement(node); | 10220 return super.visitIfStatement(node); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10169 return super.visitVariableDeclarationStatement(node); | 10410 return super.visitVariableDeclarationStatement(node); |
| 10170 } | 10411 } |
| 10171 Object visitWhileStatement(WhileStatement node) { | 10412 Object visitWhileStatement(WhileStatement node) { |
| 10172 checkForNonBoolCondition(node.condition); | 10413 checkForNonBoolCondition(node.condition); |
| 10173 return super.visitWhileStatement(node); | 10414 return super.visitWhileStatement(node); |
| 10174 } | 10415 } |
| 10175 | 10416 |
| 10176 /** | 10417 /** |
| 10177 * This verifies that the passed constructor declaration does not violate any
of the error codes | 10418 * This verifies that the passed constructor declaration does not violate any
of the error codes |
| 10178 * relating to the initialization of fields in the enclosing class. | 10419 * relating to the initialization of fields in the enclosing class. |
| 10179 * @param node the {@link ConstructorDeclaration} to evaluate | 10420 * @param node the [ConstructorDeclaration] to evaluate |
| 10180 * @return {@code true} if and only if an error code is generated on the passe
d node | 10421 * @return `true` if and only if an error code is generated on the passed node |
| 10181 * @see #initialFieldElementsMap | 10422 * @see #initialFieldElementsMap |
| 10182 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR | 10423 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR |
| 10183 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES | 10424 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES |
| 10184 */ | 10425 */ |
| 10185 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { | 10426 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { |
| 10186 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod
e.externalKeyword != null) { | 10427 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod
e.externalKeyword != null) { |
| 10187 return false; | 10428 return false; |
| 10188 } | 10429 } |
| 10189 bool foundError = false; | 10430 bool foundError = false; |
| 10190 Map<FieldElement, INIT_STATE> fieldElementsMap = new Map<FieldElement, INIT_
STATE>.from(_initialFieldElementsMap); | 10431 Map<FieldElement, INIT_STATE> fieldElementsMap = new Map<FieldElement, INIT_
STATE>.from(_initialFieldElementsMap); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10236 foundError = true; | 10477 foundError = true; |
| 10237 } | 10478 } |
| 10238 } | 10479 } |
| 10239 } | 10480 } |
| 10240 } | 10481 } |
| 10241 return foundError; | 10482 return foundError; |
| 10242 } | 10483 } |
| 10243 | 10484 |
| 10244 /** | 10485 /** |
| 10245 * This checks the passed method declaration against override-error codes. | 10486 * This checks the passed method declaration against override-error codes. |
| 10246 * @param node the {@link MethodDeclaration} to evaluate | 10487 * @param node the [MethodDeclaration] to evaluate |
| 10247 * @return {@code true} if and only if an error code is generated on the passe
d node | 10488 * @return `true` if and only if an error code is generated on the passed node |
| 10248 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 10489 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 10249 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED | 10490 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED |
| 10250 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL | 10491 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL |
| 10251 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED | 10492 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED |
| 10252 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE | 10493 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE |
| 10253 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE | 10494 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 10254 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 10495 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 10255 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE | 10496 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE |
| 10256 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE | 10497 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE |
| 10257 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE | 10498 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE |
| 10499 * @see StaticWarningCode#INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES |
| 10258 */ | 10500 */ |
| 10259 bool checkForAllInvalidOverrideErrorCodes(MethodDeclaration node) { | 10501 bool checkForAllInvalidOverrideErrorCodes(MethodDeclaration node) { |
| 10260 if (_enclosingClass == null || node.isStatic() || node.body is NativeFunctio
nBody) { | 10502 if (_enclosingClass == null || node.isStatic() || node.body is NativeFunctio
nBody) { |
| 10261 return false; | 10503 return false; |
| 10262 } | 10504 } |
| 10263 ExecutableElement executableElement = node.element; | 10505 ExecutableElement executableElement = node.element; |
| 10264 if (executableElement == null) { | 10506 if (executableElement == null) { |
| 10265 return false; | 10507 return false; |
| 10266 } | 10508 } |
| 10267 SimpleIdentifier methodName = node.name; | 10509 SimpleIdentifier methodName = node.name; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10378 break; | 10620 break; |
| 10379 } | 10621 } |
| 10380 } | 10622 } |
| 10381 } | 10623 } |
| 10382 if (parameterToSelect != null) { | 10624 if (parameterToSelect != null) { |
| 10383 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_
NAMED_PARAM_TYPE, parameterToSelect, [overridingType.displayName, overriddenName
dPTEntry.getValue().displayName, overriddenExecutable.enclosingElement.displayNa
me]); | 10625 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_
NAMED_PARAM_TYPE, parameterToSelect, [overridingType.displayName, overriddenName
dPTEntry.getValue().displayName, overriddenExecutable.enclosingElement.displayNa
me]); |
| 10384 return true; | 10626 return true; |
| 10385 } | 10627 } |
| 10386 } | 10628 } |
| 10387 } | 10629 } |
| 10388 return false; | 10630 bool foundError = false; |
| 10631 List<FormalParameter> formalParameters = new List<FormalParameter>(); |
| 10632 List<ParameterElementImpl> parameterElts = new List<ParameterElementImpl>(); |
| 10633 List<ParameterElementImpl> overriddenParameterElts = new List<ParameterEleme
ntImpl>(); |
| 10634 List<ParameterElement> overriddenPEs = overriddenExecutable.parameters; |
| 10635 for (FormalParameter formalParameter in parameterNodeList) { |
| 10636 if (formalParameter.kind.isOptional()) { |
| 10637 formalParameters.add(formalParameter); |
| 10638 parameterElts.add((formalParameter.element as ParameterElementImpl)); |
| 10639 } |
| 10640 } |
| 10641 for (ParameterElement parameterElt in overriddenPEs) { |
| 10642 if (parameterElt.parameterKind.isOptional()) { |
| 10643 overriddenParameterElts.add((parameterElt as ParameterElementImpl)); |
| 10644 } |
| 10645 } |
| 10646 if (parameterElts.length > 0) { |
| 10647 if (identical(parameterElts[0].parameterKind, ParameterKind.NAMED)) { |
| 10648 for (int i = 0; i < parameterElts.length; i++) { |
| 10649 ParameterElementImpl parameterElt = parameterElts[i]; |
| 10650 EvaluationResultImpl result = parameterElt.evaluationResult; |
| 10651 if (result == null || identical(result, ValidResult.RESULT_OBJECT)) { |
| 10652 continue; |
| 10653 } |
| 10654 String parameterName = parameterElt.name; |
| 10655 for (int j = 0; j < overriddenParameterElts.length; j++) { |
| 10656 ParameterElementImpl overriddenParameterElt = overriddenParameterElt
s[j]; |
| 10657 String overriddenParameterName = overriddenParameterElt.name; |
| 10658 if (parameterName != null && parameterName == overriddenParameterNam
e) { |
| 10659 EvaluationResultImpl overriddenResult = overriddenParameterElt.eva
luationResult; |
| 10660 if (overriddenResult == null || identical(result, ValidResult.RESU
LT_OBJECT)) { |
| 10661 break; |
| 10662 } |
| 10663 if (!result.equalValues(overriddenResult)) { |
| 10664 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_D
IFFERENT_DEFAULT_VALUES_NAMED, formalParameters[i], [overriddenExecutable.enclos
ingElement.displayName, overriddenExecutable.displayName, parameterName]); |
| 10665 foundError = true; |
| 10666 } |
| 10667 } |
| 10668 } |
| 10669 } |
| 10670 } else { |
| 10671 for (int i = 0; i < parameterElts.length && i < overriddenParameterElts.
length; i++) { |
| 10672 ParameterElementImpl parameterElt = parameterElts[i]; |
| 10673 EvaluationResultImpl result = parameterElt.evaluationResult; |
| 10674 if (result == null || identical(result, ValidResult.RESULT_OBJECT)) { |
| 10675 continue; |
| 10676 } |
| 10677 ParameterElementImpl overriddenParameterElt = overriddenParameterElts[
i]; |
| 10678 EvaluationResultImpl overriddenResult = overriddenParameterElt.evaluat
ionResult; |
| 10679 if (overriddenResult == null || identical(result, ValidResult.RESULT_O
BJECT)) { |
| 10680 continue; |
| 10681 } |
| 10682 if (!result.equalValues(overriddenResult)) { |
| 10683 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_DIFFE
RENT_DEFAULT_VALUES_POSITIONAL, formalParameters[i], [overriddenExecutable.enclo
singElement.displayName, overriddenExecutable.displayName]); |
| 10684 foundError = true; |
| 10685 } |
| 10686 } |
| 10687 } |
| 10688 } |
| 10689 return foundError; |
| 10389 } | 10690 } |
| 10390 | 10691 |
| 10391 /** | 10692 /** |
| 10392 * This verifies that all classes of the passed 'with' clause are valid. | 10693 * This verifies that all classes of the passed 'with' clause are valid. |
| 10393 * @param node the 'with' clause to evaluate | 10694 * @param node the 'with' clause to evaluate |
| 10394 * @return {@code true} if and only if an error code is generated on the passe
d node | 10695 * @return `true` if and only if an error code is generated on the passed node |
| 10395 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR | 10696 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR |
| 10396 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT | 10697 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT |
| 10397 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER | 10698 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER |
| 10398 */ | 10699 */ |
| 10399 bool checkForAllMixinErrorCodes(WithClause withClause) { | 10700 bool checkForAllMixinErrorCodes(WithClause withClause) { |
| 10400 if (withClause == null) { | 10701 if (withClause == null) { |
| 10401 return false; | 10702 return false; |
| 10402 } | 10703 } |
| 10403 bool problemReported = false; | 10704 bool problemReported = false; |
| 10404 for (TypeName mixinName in withClause.mixinTypes) { | 10705 for (TypeName mixinName in withClause.mixinTypes) { |
| 10405 Type2 mixinType = mixinName.type; | 10706 Type2 mixinType = mixinName.type; |
| 10406 if (mixinType is! InterfaceType) { | 10707 if (mixinType is! InterfaceType) { |
| 10407 continue; | 10708 continue; |
| 10408 } | 10709 } |
| 10409 ClassElement mixinElement = ((mixinType as InterfaceType)).element; | 10710 ClassElement mixinElement = ((mixinType as InterfaceType)).element; |
| 10410 problemReported = javaBooleanOr(problemReported, checkForMixinDeclaresCons
tructor(mixinName, mixinElement)); | 10711 problemReported = javaBooleanOr(problemReported, checkForMixinDeclaresCons
tructor(mixinName, mixinElement)); |
| 10411 problemReported = javaBooleanOr(problemReported, checkForMixinInheritsNotF
romObject(mixinName, mixinElement)); | 10712 problemReported = javaBooleanOr(problemReported, checkForMixinInheritsNotF
romObject(mixinName, mixinElement)); |
| 10412 problemReported = javaBooleanOr(problemReported, checkForMixinReferencesSu
per(mixinName, mixinElement)); | 10713 problemReported = javaBooleanOr(problemReported, checkForMixinReferencesSu
per(mixinName, mixinElement)); |
| 10413 } | 10714 } |
| 10414 return problemReported; | 10715 return problemReported; |
| 10415 } | 10716 } |
| 10416 | 10717 |
| 10417 /** | 10718 /** |
| 10418 * This checks error related to the redirected constructors. | 10719 * This checks error related to the redirected constructors. |
| 10419 * @param node the constructor declaration to evaluate | 10720 * @param node the constructor declaration to evaluate |
| 10420 * @return {@code true} if and only if an error code is generated on the passe
d node | 10721 * @return `true` if and only if an error code is generated on the passed node |
| 10421 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE | 10722 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE |
| 10422 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE | 10723 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE |
| 10423 * @see StaticWarningCode#REDIRECT_TO_MISSING_CONSTRUCTOR | 10724 * @see StaticWarningCode#REDIRECT_TO_MISSING_CONSTRUCTOR |
| 10424 */ | 10725 */ |
| 10425 bool checkForAllRedirectConstructorErrorCodes(ConstructorDeclaration node) { | 10726 bool checkForAllRedirectConstructorErrorCodes(ConstructorDeclaration node) { |
| 10426 ConstructorName redirectedNode = node.redirectedConstructor; | 10727 ConstructorName redirectedNode = node.redirectedConstructor; |
| 10427 if (redirectedNode == null) { | 10728 if (redirectedNode == null) { |
| 10428 return false; | 10729 return false; |
| 10429 } | 10730 } |
| 10430 ConstructorElement redirectedElement = redirectedNode.element; | 10731 ConstructorElement redirectedElement = redirectedNode.element; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 10452 if (!redirectedType.isSubtypeOf(constructorType)) { | 10753 if (!redirectedType.isSubtypeOf(constructorType)) { |
| 10453 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION
_TYPE, redirectedNode, [redirectedType, constructorType]); | 10754 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION
_TYPE, redirectedNode, [redirectedType, constructorType]); |
| 10454 return true; | 10755 return true; |
| 10455 } | 10756 } |
| 10456 return false; | 10757 return false; |
| 10457 } | 10758 } |
| 10458 | 10759 |
| 10459 /** | 10760 /** |
| 10460 * This checks that the return statement of the form <i>return e;</i> is not i
n a generative | 10761 * This checks that the return statement of the form <i>return e;</i> is not i
n a generative |
| 10461 * constructor. | 10762 * constructor. |
| 10462 * <p> | 10763 * |
| 10463 * This checks that return statements without expressions are not in a generat
ive constructor and | 10764 * This checks that return statements without expressions are not in a generat
ive constructor and |
| 10464 * the return type is not assignable to {@code null}; that is, we don't have {
@code return;} if | 10765 * the return type is not assignable to `null`; that is, we don't have `return
;` if |
| 10465 * the enclosing method has a return type. | 10766 * the enclosing method has a return type. |
| 10466 * <p> | 10767 * |
| 10467 * This checks that the return type matches the type of the declared return ty
pe in the enclosing | 10768 * This checks that the return type matches the type of the declared return ty
pe in the enclosing |
| 10468 * method or function. | 10769 * method or function. |
| 10469 * @param node the return statement to evaluate | 10770 * @param node the return statement to evaluate |
| 10470 * @return {@code true} if and only if an error code is generated on the passe
d node | 10771 * @return `true` if and only if an error code is generated on the passed node |
| 10471 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR | 10772 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR |
| 10472 * @see StaticWarningCode#RETURN_WITHOUT_VALUE | 10773 * @see StaticWarningCode#RETURN_WITHOUT_VALUE |
| 10473 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE | 10774 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE |
| 10474 */ | 10775 */ |
| 10475 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) { | 10776 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) { |
| 10476 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu
nction.type; | 10777 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu
nction.type; |
| 10477 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance :
functionType.returnType; | 10778 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance :
functionType.returnType; |
| 10478 Expression returnExpression = node.expression; | 10779 Expression returnExpression = node.expression; |
| 10479 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && !
((_enclosingFunction as ConstructorElement)).isFactory(); | 10780 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && !
((_enclosingFunction as ConstructorElement)).isFactory(); |
| 10480 if (isGenerativeConstructor) { | 10781 if (isGenerativeConstructor) { |
| 10481 if (returnExpression == null) { | 10782 if (returnExpression == null) { |
| 10482 return false; | 10783 return false; |
| 10483 } | 10784 } |
| 10484 _errorReporter.reportError2(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONS
TRUCTOR, returnExpression, []); | 10785 _errorReporter.reportError2(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONS
TRUCTOR, returnExpression, []); |
| 10485 return true; | 10786 return true; |
| 10486 } | 10787 } |
| 10487 if (returnExpression == null) { | 10788 if (returnExpression == null) { |
| 10488 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) { | 10789 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) { |
| 10489 return false; | 10790 return false; |
| 10490 } | 10791 } |
| 10491 _errorReporter.reportError2(StaticWarningCode.RETURN_WITHOUT_VALUE, node,
[]); | 10792 _errorReporter.reportError2(StaticWarningCode.RETURN_WITHOUT_VALUE, node,
[]); |
| 10492 return true; | 10793 return true; |
| 10493 } | 10794 } |
| 10494 Type2 staticReturnType = getStaticType(returnExpression); | 10795 return checkForReturnOfInvalidType(returnExpression, expectedReturnType); |
| 10495 if (expectedReturnType.isVoid()) { | |
| 10496 if (staticReturnType.isVoid() || staticReturnType.isDynamic() || identical
(staticReturnType, BottomTypeImpl.instance)) { | |
| 10497 return false; | |
| 10498 } | |
| 10499 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | |
| 10500 return true; | |
| 10501 } | |
| 10502 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType
); | |
| 10503 Type2 propagatedReturnType = getPropagatedType(returnExpression); | |
| 10504 if (_strictMode || propagatedReturnType == null) { | |
| 10505 if (isStaticAssignable) { | |
| 10506 return false; | |
| 10507 } | |
| 10508 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | |
| 10509 return true; | |
| 10510 } else { | |
| 10511 bool isPropagatedAssignable = propagatedReturnType.isAssignableTo(expected
ReturnType); | |
| 10512 if (isStaticAssignable || isPropagatedAssignable) { | |
| 10513 return false; | |
| 10514 } | |
| 10515 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | |
| 10516 return true; | |
| 10517 } | |
| 10518 } | 10796 } |
| 10519 | 10797 |
| 10520 /** | 10798 /** |
| 10521 * This verifies that the export namespace of the passed export directive does
not export any name | 10799 * This verifies that the export namespace of the passed export directive does
not export any name |
| 10522 * already exported by other export directive. | 10800 * already exported by other export directive. |
| 10523 * @param node the export directive node to report problem on | 10801 * @param node the export directive node to report problem on |
| 10524 * @return {@code true} if and only if an error code is generated on the passe
d node | 10802 * @return `true` if and only if an error code is generated on the passed node |
| 10525 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT | 10803 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT |
| 10526 */ | 10804 */ |
| 10527 bool checkForAmbiguousExport(ExportDirective node) { | 10805 bool checkForAmbiguousExport(ExportDirective node) { |
| 10528 if (node.element is! ExportElement) { | 10806 if (node.element is! ExportElement) { |
| 10529 return false; | 10807 return false; |
| 10530 } | 10808 } |
| 10531 ExportElement exportElement = node.element as ExportElement; | 10809 ExportElement exportElement = node.element as ExportElement; |
| 10532 LibraryElement exportedLibrary = exportElement.exportedLibrary; | 10810 LibraryElement exportedLibrary = exportElement.exportedLibrary; |
| 10533 if (exportedLibrary == null) { | 10811 if (exportedLibrary == null) { |
| 10534 return false; | 10812 return false; |
| 10535 } | 10813 } |
| 10536 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle
ment); | 10814 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle
ment); |
| 10537 Set<String> newNames = namespace.definedNames.keys.toSet(); | 10815 Set<String> newNames = namespace.definedNames.keys.toSet(); |
| 10538 for (String name in newNames) { | 10816 for (String name in newNames) { |
| 10539 ExportElement prevElement = _exportedNames[name]; | 10817 ExportElement prevElement = _exportedNames[name]; |
| 10540 if (prevElement != null && prevElement != exportElement) { | 10818 if (prevElement != null && prevElement != exportElement) { |
| 10541 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node,
[name, prevElement.exportedLibrary.definingCompilationUnit.displayName, exporte
dLibrary.definingCompilationUnit.displayName]); | 10819 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node,
[name, prevElement.exportedLibrary.definingCompilationUnit.displayName, exporte
dLibrary.definingCompilationUnit.displayName]); |
| 10542 return true; | 10820 return true; |
| 10543 } else { | 10821 } else { |
| 10544 _exportedNames[name] = exportElement; | 10822 _exportedNames[name] = exportElement; |
| 10545 } | 10823 } |
| 10546 } | 10824 } |
| 10547 return false; | 10825 return false; |
| 10548 } | 10826 } |
| 10549 | 10827 |
| 10550 /** | 10828 /** |
| 10551 * This verifies that the passed argument definition test identifier is a para
meter. | 10829 * This verifies that the passed argument definition test identifier is a para
meter. |
| 10552 * @param node the {@link ArgumentDefinitionTest} to evaluate | 10830 * @param node the [ArgumentDefinitionTest] to evaluate |
| 10553 * @return {@code true} if and only if an error code is generated on the passe
d node | 10831 * @return `true` if and only if an error code is generated on the passed node |
| 10554 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER | 10832 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER |
| 10555 */ | 10833 */ |
| 10556 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { | 10834 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { |
| 10557 SimpleIdentifier identifier = node.identifier; | 10835 SimpleIdentifier identifier = node.identifier; |
| 10558 Element element = identifier.element; | 10836 Element element = identifier.element; |
| 10559 if (element != null && element is! ParameterElement) { | 10837 if (element != null && element is! ParameterElement) { |
| 10560 _errorReporter.reportError2(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_
NON_PARAMETER, identifier, [identifier.name]); | 10838 _errorReporter.reportError2(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_
NON_PARAMETER, identifier, [identifier.name]); |
| 10561 return true; | 10839 return true; |
| 10562 } | 10840 } |
| 10563 return false; | 10841 return false; |
| 10564 } | 10842 } |
| 10565 | 10843 |
| 10566 /** | 10844 /** |
| 10567 * This verifies that the passed arguments can be assigned to their correspond
ing parameters. | 10845 * This verifies that the passed arguments can be assigned to their correspond
ing parameters. |
| 10568 * @param node the arguments to evaluate | 10846 * @param node the arguments to evaluate |
| 10569 * @return {@code true} if and only if an error code is generated on the passe
d node | 10847 * @return `true` if and only if an error code is generated on the passed node |
| 10570 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE | 10848 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 10571 */ | 10849 */ |
| 10572 bool checkForArgumentTypeNotAssignable(ArgumentList argumentList) { | 10850 bool checkForArgumentTypeNotAssignable(ArgumentList argumentList) { |
| 10573 if (argumentList == null) { | 10851 if (argumentList == null) { |
| 10574 return false; | 10852 return false; |
| 10575 } | 10853 } |
| 10576 bool problemReported = false; | 10854 bool problemReported = false; |
| 10577 for (Expression argument in argumentList.arguments) { | 10855 for (Expression argument in argumentList.arguments) { |
| 10578 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs
signable2(argument)); | 10856 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs
signable2(argument)); |
| 10579 } | 10857 } |
| 10580 return problemReported; | 10858 return problemReported; |
| 10581 } | 10859 } |
| 10582 | 10860 |
| 10583 /** | 10861 /** |
| 10584 * This verifies that the passed argument can be assigned to their correspondi
ng parameters. | 10862 * This verifies that the passed argument can be assigned to their correspondi
ng parameters. |
| 10585 * @param node the argument to evaluate | 10863 * @param node the argument to evaluate |
| 10586 * @return {@code true} if and only if an error code is generated on the passe
d node | 10864 * @return `true` if and only if an error code is generated on the passed node |
| 10587 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE | 10865 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 10588 */ | 10866 */ |
| 10589 bool checkForArgumentTypeNotAssignable2(Expression argument) { | 10867 bool checkForArgumentTypeNotAssignable2(Expression argument) { |
| 10590 if (argument == null) { | 10868 if (argument == null) { |
| 10591 return false; | 10869 return false; |
| 10592 } | 10870 } |
| 10593 ParameterElement staticParameterElement = argument.staticParameterElement; | 10871 ParameterElement staticParameterElement = argument.staticParameterElement; |
| 10594 Type2 staticParameterType = staticParameterElement == null ? null : staticPa
rameterElement.type; | 10872 Type2 staticParameterType = staticParameterElement == null ? null : staticPa
rameterElement.type; |
| 10595 Type2 staticArgumentType = getStaticType(argument); | 10873 Type2 staticArgumentType = getStaticType(argument); |
| 10596 if (staticArgumentType == null || staticParameterType == null) { | 10874 if (staticArgumentType == null || staticParameterType == null) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 10616 if (staticArgumentType.isAssignableTo(staticParameterType) || staticArgument
Type.isAssignableTo(propagatedParameterType) || propagatedArgumentType.isAssigna
bleTo(staticParameterType) || propagatedArgumentType.isAssignableTo(propagatedPa
rameterType)) { | 10894 if (staticArgumentType.isAssignableTo(staticParameterType) || staticArgument
Type.isAssignableTo(propagatedParameterType) || propagatedArgumentType.isAssigna
bleTo(staticParameterType) || propagatedArgumentType.isAssignableTo(propagatedPa
rameterType)) { |
| 10617 return false; | 10895 return false; |
| 10618 } | 10896 } |
| 10619 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
argument, [(propagatedArgumentType == null ? staticArgumentType : propagatedArgu
mentType).displayName, (propagatedParameterType == null ? staticParameterType :
propagatedParameterType).displayName]); | 10897 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
argument, [(propagatedArgumentType == null ? staticArgumentType : propagatedArgu
mentType).displayName, (propagatedParameterType == null ? staticParameterType :
propagatedParameterType).displayName]); |
| 10620 return true; | 10898 return true; |
| 10621 } | 10899 } |
| 10622 | 10900 |
| 10623 /** | 10901 /** |
| 10624 * This verifies that left hand side of the passed assignment expression is no
t final. | 10902 * This verifies that left hand side of the passed assignment expression is no
t final. |
| 10625 * @param node the assignment expression to evaluate | 10903 * @param node the assignment expression to evaluate |
| 10626 * @return {@code true} if and only if an error code is generated on the passe
d node | 10904 * @return `true` if and only if an error code is generated on the passed node |
| 10627 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 10905 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
| 10628 */ | 10906 */ |
| 10629 bool checkForAssignmentToFinal(AssignmentExpression node) { | 10907 bool checkForAssignmentToFinal(AssignmentExpression node) { |
| 10630 Expression leftExpression = node.leftHandSide; | 10908 Expression leftExpression = node.leftHandSide; |
| 10631 return checkForAssignmentToFinal2(leftExpression); | 10909 return checkForAssignmentToFinal2(leftExpression); |
| 10632 } | 10910 } |
| 10633 | 10911 |
| 10634 /** | 10912 /** |
| 10635 * This verifies that the passed expression is not final. | 10913 * This verifies that the passed expression is not final. |
| 10636 * @param node the expression to evaluate | 10914 * @param node the expression to evaluate |
| 10637 * @return {@code true} if and only if an error code is generated on the passe
d node | 10915 * @return `true` if and only if an error code is generated on the passed node |
| 10638 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 10916 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
| 10639 */ | 10917 */ |
| 10640 bool checkForAssignmentToFinal2(Expression expression) { | 10918 bool checkForAssignmentToFinal2(Expression expression) { |
| 10641 Element element = null; | 10919 Element element = null; |
| 10642 if (expression is Identifier) { | 10920 if (expression is Identifier) { |
| 10643 element = ((expression as Identifier)).element; | 10921 element = ((expression as Identifier)).element; |
| 10644 } | 10922 } |
| 10645 if (expression is PropertyAccess) { | 10923 if (expression is PropertyAccess) { |
| 10646 element = ((expression as PropertyAccess)).propertyName.element; | 10924 element = ((expression as PropertyAccess)).propertyName.element; |
| 10647 } | 10925 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 10662 return false; | 10940 return false; |
| 10663 } | 10941 } |
| 10664 return false; | 10942 return false; |
| 10665 } | 10943 } |
| 10666 | 10944 |
| 10667 /** | 10945 /** |
| 10668 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code | 10946 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code |
| 10669 * on the identifier if it is a keyword. | 10947 * on the identifier if it is a keyword. |
| 10670 * @param identifier the identifier to check to ensure that it is not a keywor
d | 10948 * @param identifier the identifier to check to ensure that it is not a keywor
d |
| 10671 * @param errorCode if the passed identifier is a keyword then this error code
is created on the | 10949 * @param errorCode if the passed identifier is a keyword then this error code
is created on the |
| 10672 * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_
IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_T
YPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_
NAME} | 10950 * identifier, the error code will be one of[CompileTimeErrorCode#BUILT_IN_IDE
NTIFIER_AS_TYPE_NAME],[CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE
_NAME] or[CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME] |
| 10673 * @return {@code true} if and only if an error code is generated on the passe
d node | 10951 * @return `true` if and only if an error code is generated on the passed node |
| 10674 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME | 10952 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME |
| 10675 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME | 10953 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME |
| 10676 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME | 10954 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME |
| 10677 */ | 10955 */ |
| 10678 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { | 10956 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { |
| 10679 sc.Token token = identifier.token; | 10957 sc.Token token = identifier.token; |
| 10680 if (identical(token.type, sc.TokenType.KEYWORD)) { | 10958 if (identical(token.type, sc.TokenType.KEYWORD)) { |
| 10681 _errorReporter.reportError2(errorCode, identifier, [identifier.name]); | 10959 _errorReporter.reportError2(errorCode, identifier, [identifier.name]); |
| 10682 return true; | 10960 return true; |
| 10683 } | 10961 } |
| 10684 return false; | 10962 return false; |
| 10685 } | 10963 } |
| 10686 | 10964 |
| 10687 /** | 10965 /** |
| 10688 * This verifies that the passed variable declaration list does not have a bui
lt-in identifier. | 10966 * This verifies that the passed variable declaration list does not have a bui
lt-in identifier. |
| 10689 * @param node the variable declaration list to check | 10967 * @param node the variable declaration list to check |
| 10690 * @return {@code true} if and only if an error code is generated on the passe
d node | 10968 * @return `true` if and only if an error code is generated on the passed node |
| 10691 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE | 10969 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE |
| 10692 */ | 10970 */ |
| 10693 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) { | 10971 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) { |
| 10694 TypeName typeName = node.type; | 10972 TypeName typeName = node.type; |
| 10695 if (typeName != null) { | 10973 if (typeName != null) { |
| 10696 Identifier identifier = typeName.name; | 10974 Identifier identifier = typeName.name; |
| 10697 if (identifier is SimpleIdentifier) { | 10975 if (identifier is SimpleIdentifier) { |
| 10698 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; | 10976 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; |
| 10699 sc.Token token = simpleIdentifier.token; | 10977 sc.Token token = simpleIdentifier.token; |
| 10700 if (identical(token.type, sc.TokenType.KEYWORD)) { | 10978 if (identical(token.type, sc.TokenType.KEYWORD)) { |
| 10701 if (((token as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) { | 10979 if (((token as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) { |
| 10702 _errorReporter.reportError2(CompileTimeErrorCode.BUILT_IN_IDENTIFIER
_AS_TYPE, identifier, [identifier.name]); | 10980 _errorReporter.reportError2(CompileTimeErrorCode.BUILT_IN_IDENTIFIER
_AS_TYPE, identifier, [identifier.name]); |
| 10703 return true; | 10981 return true; |
| 10704 } | 10982 } |
| 10705 } | 10983 } |
| 10706 } | 10984 } |
| 10707 } | 10985 } |
| 10708 return false; | 10986 return false; |
| 10709 } | 10987 } |
| 10710 | 10988 |
| 10711 /** | 10989 /** |
| 10712 * This verifies that the given switch case is terminated with 'break', 'conti
nue', 'return' or | 10990 * This verifies that the given switch case is terminated with 'break', 'conti
nue', 'return' or |
| 10713 * 'throw'. | 10991 * 'throw'. |
| 10714 * @param node the switch case to evaluate | 10992 * @param node the switch case to evaluate |
| 10715 * @return {@code true} if and only if an error code is generated on the passe
d node | 10993 * @return `true` if and only if an error code is generated on the passed node |
| 10716 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED | 10994 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED |
| 10717 */ | 10995 */ |
| 10718 bool checkForCaseBlockNotTerminated(SwitchCase node) { | 10996 bool checkForCaseBlockNotTerminated(SwitchCase node) { |
| 10719 NodeList<Statement> statements = node.statements; | 10997 NodeList<Statement> statements = node.statements; |
| 10720 if (statements.isEmpty) { | 10998 if (statements.isEmpty) { |
| 10721 ASTNode parent = node.parent; | 10999 ASTNode parent = node.parent; |
| 10722 if (parent is SwitchStatement) { | 11000 if (parent is SwitchStatement) { |
| 10723 SwitchStatement switchStatement = parent as SwitchStatement; | 11001 SwitchStatement switchStatement = parent as SwitchStatement; |
| 10724 NodeList<SwitchMember> members = switchStatement.members; | 11002 NodeList<SwitchMember> members = switchStatement.members; |
| 10725 int index = members.indexOf(node); | 11003 int index = members.indexOf(node); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 10740 } | 11018 } |
| 10741 } | 11019 } |
| 10742 _errorReporter.reportError4(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod
e.keyword, []); | 11020 _errorReporter.reportError4(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod
e.keyword, []); |
| 10743 return true; | 11021 return true; |
| 10744 } | 11022 } |
| 10745 | 11023 |
| 10746 /** | 11024 /** |
| 10747 * This verifies that the switch cases in the given switch statement is termin
ated with 'break', | 11025 * This verifies that the switch cases in the given switch statement is termin
ated with 'break', |
| 10748 * 'continue', 'return' or 'throw'. | 11026 * 'continue', 'return' or 'throw'. |
| 10749 * @param node the switch statement containing the cases to be checked | 11027 * @param node the switch statement containing the cases to be checked |
| 10750 * @return {@code true} if and only if an error code is generated on the passe
d node | 11028 * @return `true` if and only if an error code is generated on the passed node |
| 10751 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED | 11029 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED |
| 10752 */ | 11030 */ |
| 10753 bool checkForCaseBlocksNotTerminated(SwitchStatement node) { | 11031 bool checkForCaseBlocksNotTerminated(SwitchStatement node) { |
| 10754 bool foundError = false; | 11032 bool foundError = false; |
| 10755 NodeList<SwitchMember> members = node.members; | 11033 NodeList<SwitchMember> members = node.members; |
| 10756 int lastMember = members.length - 1; | 11034 int lastMember = members.length - 1; |
| 10757 for (int i = 0; i < lastMember; i++) { | 11035 for (int i = 0; i < lastMember; i++) { |
| 10758 SwitchMember member = members[i]; | 11036 SwitchMember member = members[i]; |
| 10759 if (member is SwitchCase) { | 11037 if (member is SwitchCase) { |
| 10760 foundError = javaBooleanOr(foundError, checkForCaseBlockNotTerminated((m
ember as SwitchCase))); | 11038 foundError = javaBooleanOr(foundError, checkForCaseBlockNotTerminated((m
ember as SwitchCase))); |
| 10761 } | 11039 } |
| 10762 } | 11040 } |
| 10763 return foundError; | 11041 return foundError; |
| 10764 } | 11042 } |
| 10765 | 11043 |
| 10766 /** | 11044 /** |
| 10767 * This verifies that the passed switch statement does not have a case express
ion with the | 11045 * This verifies that the passed switch statement does not have a case express
ion with the |
| 10768 * operator '==' overridden. | 11046 * operator '==' overridden. |
| 10769 * @param node the switch statement to evaluate | 11047 * @param node the switch statement to evaluate |
| 10770 * @return {@code true} if and only if an error code is generated on the passe
d node | 11048 * @return `true` if and only if an error code is generated on the passed node |
| 10771 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS | 11049 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS |
| 10772 */ | 11050 */ |
| 10773 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node) { | 11051 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node) { |
| 10774 Expression expression = node.expression; | 11052 Expression expression = node.expression; |
| 10775 Type2 type = getStaticType(expression); | 11053 Type2 type = getStaticType(expression); |
| 10776 if (type != null && type != _typeProvider.intType && type != _typeProvider.s
tringType) { | 11054 if (type != null && type != _typeProvider.intType && type != _typeProvider.s
tringType) { |
| 10777 Element element = type.element; | 11055 Element element = type.element; |
| 10778 if (element is ClassElement) { | 11056 if (element is ClassElement) { |
| 10779 ClassElement classElement = element as ClassElement; | 11057 ClassElement classElement = element as ClassElement; |
| 10780 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); | 11058 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); |
| 10781 if (method != null && method.enclosingElement.type != _typeProvider.obje
ctType) { | 11059 if (method != null && method.enclosingElement.type != _typeProvider.obje
ctType) { |
| 10782 _errorReporter.reportError2(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_
IMPLEMENTS_EQUALS, expression, [element.displayName]); | 11060 _errorReporter.reportError2(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_
IMPLEMENTS_EQUALS, expression, [element.displayName]); |
| 10783 return true; | 11061 return true; |
| 10784 } | 11062 } |
| 10785 } | 11063 } |
| 10786 } | 11064 } |
| 10787 return false; | 11065 return false; |
| 10788 } | 11066 } |
| 10789 | 11067 |
| 10790 /** | 11068 /** |
| 10791 * This verifies that the passed method declaration is abstract only if the en
closing class is | 11069 * This verifies that the passed method declaration is abstract only if the en
closing class is |
| 10792 * also abstract. | 11070 * also abstract. |
| 10793 * @param node the method declaration to evaluate | 11071 * @param node the method declaration to evaluate |
| 10794 * @return {@code true} if and only if an error code is generated on the passe
d node | 11072 * @return `true` if and only if an error code is generated on the passed node |
| 10795 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER | 11073 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER |
| 10796 */ | 11074 */ |
| 10797 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) { | 11075 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) { |
| 10798 if (node.isAbstract() && _enclosingClass != null && !_enclosingClass.isAbstr
act()) { | 11076 if (node.isAbstract() && _enclosingClass != null && !_enclosingClass.isAbstr
act()) { |
| 10799 SimpleIdentifier methodName = node.name; | 11077 SimpleIdentifier methodName = node.name; |
| 10800 _errorReporter.reportError2(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT
_MEMBER, methodName, [methodName.name, _enclosingClass.displayName]); | 11078 _errorReporter.reportError2(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT
_MEMBER, methodName, [methodName.name, _enclosingClass.displayName]); |
| 10801 return true; | 11079 return true; |
| 10802 } | 11080 } |
| 10803 return false; | 11081 return false; |
| 10804 } | 11082 } |
| 10805 | 11083 |
| 10806 /** | 11084 /** |
| 10807 * This verifies all possible conflicts of the constructor name with other con
structors and | 11085 * This verifies all possible conflicts of the constructor name with other con
structors and |
| 10808 * members of the same class. | 11086 * members of the same class. |
| 10809 * @param node the constructor declaration to evaluate | 11087 * @param node the constructor declaration to evaluate |
| 10810 * @return {@code true} if and only if an error code is generated on the passe
d node | 11088 * @return `true` if and only if an error code is generated on the passed node |
| 10811 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT | 11089 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT |
| 10812 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME | 11090 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME |
| 10813 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD | 11091 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD |
| 10814 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD | 11092 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD |
| 10815 */ | 11093 */ |
| 10816 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node)
{ | 11094 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node)
{ |
| 10817 ConstructorElement constructorElement = node.element; | 11095 ConstructorElement constructorElement = node.element; |
| 10818 SimpleIdentifier constructorName = node.name; | 11096 SimpleIdentifier constructorName = node.name; |
| 10819 String name = constructorElement.name; | 11097 String name = constructorElement.name; |
| 10820 ClassElement classElement = constructorElement.enclosingElement; | 11098 ClassElement classElement = constructorElement.enclosingElement; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 10848 } | 11126 } |
| 10849 } | 11127 } |
| 10850 } | 11128 } |
| 10851 return false; | 11129 return false; |
| 10852 } | 11130 } |
| 10853 | 11131 |
| 10854 /** | 11132 /** |
| 10855 * This verifies that the superclass of the enclosing class does not declare a
ccessible static | 11133 * This verifies that the superclass of the enclosing class does not declare a
ccessible static |
| 10856 * member with the same name as the passed instance getter/setter method decla
ration. | 11134 * member with the same name as the passed instance getter/setter method decla
ration. |
| 10857 * @param node the method declaration to evaluate | 11135 * @param node the method declaration to evaluate |
| 10858 * @return {@code true} if and only if an error code is generated on the passe
d node | 11136 * @return `true` if and only if an error code is generated on the passed node |
| 10859 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER | 11137 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER |
| 10860 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER | 11138 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER |
| 10861 */ | 11139 */ |
| 10862 bool checkForConflictingInstanceGetterAndSuperclassMember(MethodDeclaration no
de) { | 11140 bool checkForConflictingInstanceGetterAndSuperclassMember(MethodDeclaration no
de) { |
| 10863 if (node.isStatic()) { | 11141 if (node.isStatic()) { |
| 10864 return false; | 11142 return false; |
| 10865 } | 11143 } |
| 10866 SimpleIdentifier nameNode = node.name; | 11144 SimpleIdentifier nameNode = node.name; |
| 10867 if (nameNode == null) { | 11145 if (nameNode == null) { |
| 10868 return false; | 11146 return false; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 10893 } else { | 11171 } else { |
| 10894 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_SETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); | 11172 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_SETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); |
| 10895 } | 11173 } |
| 10896 return true; | 11174 return true; |
| 10897 } | 11175 } |
| 10898 | 11176 |
| 10899 /** | 11177 /** |
| 10900 * This verifies that the enclosing class does not have an instance member wit
h the same name as | 11178 * This verifies that the enclosing class does not have an instance member wit
h the same name as |
| 10901 * the passed static getter method declaration. | 11179 * the passed static getter method declaration. |
| 10902 * @param node the method declaration to evaluate | 11180 * @param node the method declaration to evaluate |
| 10903 * @return {@code true} if and only if an error code is generated on the passe
d node | 11181 * @return `true` if and only if an error code is generated on the passed node |
| 10904 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER | 11182 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER |
| 10905 */ | 11183 */ |
| 10906 bool checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node)
{ | 11184 bool checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node)
{ |
| 10907 if (!node.isStatic()) { | 11185 if (!node.isStatic()) { |
| 10908 return false; | 11186 return false; |
| 10909 } | 11187 } |
| 10910 SimpleIdentifier nameNode = node.name; | 11188 SimpleIdentifier nameNode = node.name; |
| 10911 if (nameNode == null) { | 11189 if (nameNode == null) { |
| 10912 return false; | 11190 return false; |
| 10913 } | 11191 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 10926 ClassElement setterClass = setter.enclosingElement as ClassElement; | 11204 ClassElement setterClass = setter.enclosingElement as ClassElement; |
| 10927 InterfaceType setterType = setterClass.type; | 11205 InterfaceType setterType = setterClass.type; |
| 10928 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_
INSTANCE_SETTER, nameNode, [setterType.displayName]); | 11206 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_
INSTANCE_SETTER, nameNode, [setterType.displayName]); |
| 10929 return true; | 11207 return true; |
| 10930 } | 11208 } |
| 10931 | 11209 |
| 10932 /** | 11210 /** |
| 10933 * This verifies that the enclosing class does not have an instance member wit
h the same name as | 11211 * This verifies that the enclosing class does not have an instance member wit
h the same name as |
| 10934 * the passed static getter method declaration. | 11212 * the passed static getter method declaration. |
| 10935 * @param node the method declaration to evaluate | 11213 * @param node the method declaration to evaluate |
| 10936 * @return {@code true} if and only if an error code is generated on the passe
d node | 11214 * @return `true` if and only if an error code is generated on the passed node |
| 10937 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER | 11215 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER |
| 10938 */ | 11216 */ |
| 10939 bool checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node)
{ | 11217 bool checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node)
{ |
| 10940 if (!node.isStatic()) { | 11218 if (!node.isStatic()) { |
| 10941 return false; | 11219 return false; |
| 10942 } | 11220 } |
| 10943 SimpleIdentifier nameNode = node.name; | 11221 SimpleIdentifier nameNode = node.name; |
| 10944 if (nameNode == null) { | 11222 if (nameNode == null) { |
| 10945 return false; | 11223 return false; |
| 10946 } | 11224 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 10966 ClassElement memberClass = member.enclosingElement as ClassElement; | 11244 ClassElement memberClass = member.enclosingElement as ClassElement; |
| 10967 InterfaceType memberType = memberClass.type; | 11245 InterfaceType memberType = memberClass.type; |
| 10968 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_
INSTANCE_MEMBER, nameNode, [memberType.displayName]); | 11246 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_
INSTANCE_MEMBER, nameNode, [memberType.displayName]); |
| 10969 return true; | 11247 return true; |
| 10970 } | 11248 } |
| 10971 | 11249 |
| 10972 /** | 11250 /** |
| 10973 * This verifies that the passed constructor declaration is 'const' then there
are no non-final | 11251 * This verifies that the passed constructor declaration is 'const' then there
are no non-final |
| 10974 * instance variable. | 11252 * instance variable. |
| 10975 * @param node the constructor declaration to evaluate | 11253 * @param node the constructor declaration to evaluate |
| 10976 * @return {@code true} if and only if an error code is generated on the passe
d node | 11254 * @return `true` if and only if an error code is generated on the passed node |
| 10977 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD | 11255 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD |
| 10978 */ | 11256 */ |
| 10979 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { | 11257 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { |
| 10980 if (!_isEnclosingConstructorConst) { | 11258 if (!_isEnclosingConstructorConst) { |
| 10981 return false; | 11259 return false; |
| 10982 } | 11260 } |
| 10983 ConstructorElement constructorElement = node.element; | 11261 ConstructorElement constructorElement = node.element; |
| 10984 ClassElement classElement = constructorElement.enclosingElement; | 11262 ClassElement classElement = constructorElement.enclosingElement; |
| 10985 if (!classElement.hasNonFinalField()) { | 11263 if (!classElement.hasNonFinalField()) { |
| 10986 return false; | 11264 return false; |
| 10987 } | 11265 } |
| 10988 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_
FINAL_FIELD, node, []); | 11266 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_
FINAL_FIELD, node, []); |
| 10989 return true; | 11267 return true; |
| 10990 } | 11268 } |
| 10991 | 11269 |
| 10992 /** | 11270 /** |
| 10993 * This verifies that the passed throw expression is not enclosed in a 'const'
constructor | 11271 * This verifies that the passed throw expression is not enclosed in a 'const'
constructor |
| 10994 * declaration. | 11272 * declaration. |
| 10995 * @param node the throw expression expression to evaluate | 11273 * @param node the throw expression expression to evaluate |
| 10996 * @return {@code true} if and only if an error code is generated on the passe
d node | 11274 * @return `true` if and only if an error code is generated on the passed node |
| 10997 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION | 11275 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION |
| 10998 */ | 11276 */ |
| 10999 bool checkForConstEvalThrowsException(ThrowExpression node) { | 11277 bool checkForConstEvalThrowsException(ThrowExpression node) { |
| 11000 if (_isEnclosingConstructorConst) { | 11278 if (_isEnclosingConstructorConst) { |
| 11001 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_
EXCEPTION, node, []); | 11279 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_
EXCEPTION, node, []); |
| 11002 return true; | 11280 return true; |
| 11003 } | 11281 } |
| 11004 return false; | 11282 return false; |
| 11005 } | 11283 } |
| 11006 | 11284 |
| 11007 /** | 11285 /** |
| 11008 * This verifies that the passed normal formal parameter is not 'const'. | 11286 * This verifies that the passed normal formal parameter is not 'const'. |
| 11009 * @param node the normal formal parameter to evaluate | 11287 * @param node the normal formal parameter to evaluate |
| 11010 * @return {@code true} if and only if an error code is generated on the passe
d node | 11288 * @return `true` if and only if an error code is generated on the passed node |
| 11011 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER | 11289 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER |
| 11012 */ | 11290 */ |
| 11013 bool checkForConstFormalParameter(NormalFormalParameter node) { | 11291 bool checkForConstFormalParameter(NormalFormalParameter node) { |
| 11014 if (node.isConst()) { | 11292 if (node.isConst()) { |
| 11015 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n
ode, []); | 11293 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n
ode, []); |
| 11016 return true; | 11294 return true; |
| 11017 } | 11295 } |
| 11018 return false; | 11296 return false; |
| 11019 } | 11297 } |
| 11020 | 11298 |
| 11021 /** | 11299 /** |
| 11022 * This verifies that the passed instance creation expression is not being inv
oked on an abstract | 11300 * This verifies that the passed instance creation expression is not being inv
oked on an abstract |
| 11023 * class. | 11301 * class. |
| 11024 * @param node the instance creation expression to evaluate | 11302 * @param node the instance creation expression to evaluate |
| 11025 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th
e{@link InstanceCreationExpression}, this is the AST node that the error is atta
ched to | 11303 * @param typeName the [TypeName] of the [ConstructorName] from the[InstanceCr
eationExpression], this is the AST node that the error is attached to |
| 11026 * @param type the type being constructed with this {@link InstanceCreationExp
ression} | 11304 * @param type the type being constructed with this [InstanceCreationExpressio
n] |
| 11027 * @return {@code true} if and only if an error code is generated on the passe
d node | 11305 * @return `true` if and only if an error code is generated on the passed node |
| 11028 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS | 11306 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS |
| 11029 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS | 11307 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS |
| 11030 */ | 11308 */ |
| 11031 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type
Name typeName, InterfaceType type) { | 11309 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type
Name typeName, InterfaceType type) { |
| 11032 if (type.element.isAbstract()) { | 11310 if (type.element.isAbstract()) { |
| 11033 ConstructorElement element = node.element; | 11311 ConstructorElement element = node.element; |
| 11034 if (element != null && !element.isFactory()) { | 11312 if (element != null && !element.isFactory()) { |
| 11035 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO
NST)) { | 11313 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO
NST)) { |
| 11036 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS
S, typeName, []); | 11314 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS
S, typeName, []); |
| 11037 } else { | 11315 } else { |
| 11038 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS,
typeName, []); | 11316 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS,
typeName, []); |
| 11039 } | 11317 } |
| 11040 return true; | 11318 return true; |
| 11041 } | 11319 } |
| 11042 } | 11320 } |
| 11043 return false; | 11321 return false; |
| 11044 } | 11322 } |
| 11045 | 11323 |
| 11046 /** | 11324 /** |
| 11047 * This verifies that the passed 'const' instance creation expression is not b
eing invoked on a | 11325 * This verifies that the passed 'const' instance creation expression is not b
eing invoked on a |
| 11048 * constructor that is not 'const'. | 11326 * constructor that is not 'const'. |
| 11049 * <p> | 11327 * |
| 11050 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 11328 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 11051 * @param node the instance creation expression to evaluate | 11329 * @param node the instance creation expression to evaluate |
| 11052 * @return {@code true} if and only if an error code is generated on the passe
d node | 11330 * @return `true` if and only if an error code is generated on the passed node |
| 11053 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST | 11331 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST |
| 11054 */ | 11332 */ |
| 11055 bool checkForConstWithNonConst(InstanceCreationExpression node) { | 11333 bool checkForConstWithNonConst(InstanceCreationExpression node) { |
| 11056 ConstructorElement constructorElement = node.element; | 11334 ConstructorElement constructorElement = node.element; |
| 11057 if (constructorElement != null && !constructorElement.isConst()) { | 11335 if (constructorElement != null && !constructorElement.isConst()) { |
| 11058 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_NON_CONST, nod
e, []); | 11336 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_NON_CONST, nod
e, []); |
| 11059 return true; | 11337 return true; |
| 11060 } | 11338 } |
| 11061 return false; | 11339 return false; |
| 11062 } | 11340 } |
| 11063 | 11341 |
| 11064 /** | 11342 /** |
| 11065 * This verifies that the passed 'const' instance creation expression does not
reference any type | 11343 * This verifies that the passed 'const' instance creation expression does not
reference any type |
| 11066 * parameters. | 11344 * parameters. |
| 11067 * <p> | 11345 * |
| 11068 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 11346 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 11069 * @param node the instance creation expression to evaluate | 11347 * @param node the instance creation expression to evaluate |
| 11070 * @return {@code true} if and only if an error code is generated on the passe
d node | 11348 * @return `true` if and only if an error code is generated on the passed node |
| 11071 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS | 11349 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS |
| 11072 */ | 11350 */ |
| 11073 bool checkForConstWithTypeParameters(InstanceCreationExpression node) { | 11351 bool checkForConstWithTypeParameters(InstanceCreationExpression node) { |
| 11074 ConstructorName constructorName = node.constructorName; | 11352 ConstructorName constructorName = node.constructorName; |
| 11075 if (constructorName == null) { | 11353 if (constructorName == null) { |
| 11076 return false; | 11354 return false; |
| 11077 } | 11355 } |
| 11078 TypeName typeName = constructorName.type; | 11356 TypeName typeName = constructorName.type; |
| 11079 return checkForConstWithTypeParameters2(typeName); | 11357 return checkForConstWithTypeParameters2(typeName); |
| 11080 } | 11358 } |
| 11081 | 11359 |
| 11082 /** | 11360 /** |
| 11083 * This verifies that the passed type name does not reference any type paramet
ers. | 11361 * This verifies that the passed type name does not reference any type paramet
ers. |
| 11084 * @param typeName the type name to evaluate | 11362 * @param typeName the type name to evaluate |
| 11085 * @return {@code true} if and only if an error code is generated on the passe
d node | 11363 * @return `true` if and only if an error code is generated on the passed node |
| 11086 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS | 11364 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS |
| 11087 */ | 11365 */ |
| 11088 bool checkForConstWithTypeParameters2(TypeName typeName) { | 11366 bool checkForConstWithTypeParameters2(TypeName typeName) { |
| 11089 if (typeName == null) { | 11367 if (typeName == null) { |
| 11090 return false; | 11368 return false; |
| 11091 } | 11369 } |
| 11092 Identifier name = typeName.name; | 11370 Identifier name = typeName.name; |
| 11093 if (name == null) { | 11371 if (name == null) { |
| 11094 return false; | 11372 return false; |
| 11095 } | 11373 } |
| 11096 if (name.element is TypeVariableElement) { | 11374 if (name.element is TypeVariableElement) { |
| 11097 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETER
S, name, []); | 11375 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETER
S, name, []); |
| 11098 } | 11376 } |
| 11099 TypeArgumentList typeArguments = typeName.typeArguments; | 11377 TypeArgumentList typeArguments = typeName.typeArguments; |
| 11100 if (typeArguments != null) { | 11378 if (typeArguments != null) { |
| 11101 bool hasError = false; | 11379 bool hasError = false; |
| 11102 for (TypeName argument in typeArguments.arguments) { | 11380 for (TypeName argument in typeArguments.arguments) { |
| 11103 hasError = javaBooleanOr(hasError, checkForConstWithTypeParameters2(argu
ment)); | 11381 hasError = javaBooleanOr(hasError, checkForConstWithTypeParameters2(argu
ment)); |
| 11104 } | 11382 } |
| 11105 return hasError; | 11383 return hasError; |
| 11106 } | 11384 } |
| 11107 return false; | 11385 return false; |
| 11108 } | 11386 } |
| 11109 | 11387 |
| 11110 /** | 11388 /** |
| 11111 * This verifies that if the passed 'const' instance creation expression is be
ing invoked on the | 11389 * This verifies that if the passed 'const' instance creation expression is be
ing invoked on the |
| 11112 * resolved constructor. | 11390 * resolved constructor. |
| 11113 * <p> | 11391 * |
| 11114 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 11392 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 11115 * @param node the instance creation expression to evaluate | 11393 * @param node the instance creation expression to evaluate |
| 11116 * @return {@code true} if and only if an error code is generated on the passe
d node | 11394 * @return `true` if and only if an error code is generated on the passed node |
| 11117 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR | 11395 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR |
| 11118 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT | 11396 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT |
| 11119 */ | 11397 */ |
| 11120 bool checkForConstWithUndefinedConstructor(InstanceCreationExpression node) { | 11398 bool checkForConstWithUndefinedConstructor(InstanceCreationExpression node) { |
| 11121 if (node.element != null) { | 11399 if (node.element != null) { |
| 11122 return false; | 11400 return false; |
| 11123 } | 11401 } |
| 11124 ConstructorName constructorName = node.constructorName; | 11402 ConstructorName constructorName = node.constructorName; |
| 11125 if (constructorName == null) { | 11403 if (constructorName == null) { |
| 11126 return false; | 11404 return false; |
| 11127 } | 11405 } |
| 11128 TypeName type = constructorName.type; | 11406 TypeName type = constructorName.type; |
| 11129 if (type == null) { | 11407 if (type == null) { |
| 11130 return false; | 11408 return false; |
| 11131 } | 11409 } |
| 11132 Identifier className = type.name; | 11410 Identifier className = type.name; |
| 11133 SimpleIdentifier name = constructorName.name; | 11411 SimpleIdentifier name = constructorName.name; |
| 11134 if (name != null) { | 11412 if (name != null) { |
| 11135 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR, name, [className, name]); | 11413 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR, name, [className, name]); |
| 11136 } else { | 11414 } else { |
| 11137 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR_DEFAULT, constructorName, [className]); | 11415 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR_DEFAULT, constructorName, [className]); |
| 11138 } | 11416 } |
| 11139 return true; | 11417 return true; |
| 11140 } | 11418 } |
| 11141 | 11419 |
| 11142 /** | 11420 /** |
| 11143 * This verifies that there are no default parameters in the passed function t
ype alias. | 11421 * This verifies that there are no default parameters in the passed function t
ype alias. |
| 11144 * @param node the function type alias to evaluate | 11422 * @param node the function type alias to evaluate |
| 11145 * @return {@code true} if and only if an error code is generated on the passe
d node | 11423 * @return `true` if and only if an error code is generated on the passed node |
| 11146 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS | 11424 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS |
| 11147 */ | 11425 */ |
| 11148 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { | 11426 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { |
| 11149 bool result = false; | 11427 bool result = false; |
| 11150 FormalParameterList formalParameterList = node.parameters; | 11428 FormalParameterList formalParameterList = node.parameters; |
| 11151 NodeList<FormalParameter> parameters = formalParameterList.parameters; | 11429 NodeList<FormalParameter> parameters = formalParameterList.parameters; |
| 11152 for (FormalParameter formalParameter in parameters) { | 11430 for (FormalParameter formalParameter in parameters) { |
| 11153 if (formalParameter is DefaultFormalParameter) { | 11431 if (formalParameter is DefaultFormalParameter) { |
| 11154 DefaultFormalParameter defaultFormalParameter = formalParameter as Defau
ltFormalParameter; | 11432 DefaultFormalParameter defaultFormalParameter = formalParameter as Defau
ltFormalParameter; |
| 11155 if (defaultFormalParameter.defaultValue != null) { | 11433 if (defaultFormalParameter.defaultValue != null) { |
| 11156 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC
TION_TYPE_ALIAS, node, []); | 11434 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC
TION_TYPE_ALIAS, node, []); |
| 11157 result = true; | 11435 result = true; |
| 11158 } | 11436 } |
| 11159 } | 11437 } |
| 11160 } | 11438 } |
| 11161 return result; | 11439 return result; |
| 11162 } | 11440 } |
| 11163 | 11441 |
| 11164 /** | 11442 /** |
| 11165 * This verifies the passed import has unique name among other exported librar
ies. | 11443 * This verifies the passed import has unique name among other exported librar
ies. |
| 11166 * @param node the export directive to evaluate | 11444 * @param node the export directive to evaluate |
| 11167 * @return {@code true} if and only if an error code is generated on the passe
d node | 11445 * @return `true` if and only if an error code is generated on the passed node |
| 11168 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME | 11446 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME |
| 11169 */ | 11447 */ |
| 11170 bool checkForExportDuplicateLibraryName(ExportDirective node) { | 11448 bool checkForExportDuplicateLibraryName(ExportDirective node) { |
| 11171 Element nodeElement = node.element; | 11449 Element nodeElement = node.element; |
| 11172 if (nodeElement is! ExportElement) { | 11450 if (nodeElement is! ExportElement) { |
| 11173 return false; | 11451 return false; |
| 11174 } | 11452 } |
| 11175 ExportElement nodeExportElement = nodeElement as ExportElement; | 11453 ExportElement nodeExportElement = nodeElement as ExportElement; |
| 11176 LibraryElement nodeLibrary = nodeExportElement.exportedLibrary; | 11454 LibraryElement nodeLibrary = nodeExportElement.exportedLibrary; |
| 11177 if (nodeLibrary == null) { | 11455 if (nodeLibrary == null) { |
| 11178 return false; | 11456 return false; |
| 11179 } | 11457 } |
| 11180 String name = nodeLibrary.name; | 11458 String name = nodeLibrary.name; |
| 11181 LibraryElement prevLibrary = _nameToExportElement[name]; | 11459 LibraryElement prevLibrary = _nameToExportElement[name]; |
| 11182 if (prevLibrary != null) { | 11460 if (prevLibrary != null) { |
| 11183 if (prevLibrary != nodeLibrary) { | 11461 if (prevLibrary != nodeLibrary) { |
| 11184 _errorReporter.reportError2(StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name]); | 11462 _errorReporter.reportError2(StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name]); |
| 11185 return true; | 11463 return true; |
| 11186 } | 11464 } |
| 11187 } else { | 11465 } else { |
| 11188 _nameToExportElement[name] = nodeLibrary; | 11466 _nameToExportElement[name] = nodeLibrary; |
| 11189 } | 11467 } |
| 11190 return false; | 11468 return false; |
| 11191 } | 11469 } |
| 11192 | 11470 |
| 11193 /** | 11471 /** |
| 11194 * Check that if the visiting library is not system, then any passed library s
hould not be SDK | 11472 * Check that if the visiting library is not system, then any passed library s
hould not be SDK |
| 11195 * internal library. | 11473 * internal library. |
| 11196 * @param node the export directive to evaluate | 11474 * @param node the export directive to evaluate |
| 11197 * @return {@code true} if and only if an error code is generated on the passe
d node | 11475 * @return `true` if and only if an error code is generated on the passed node |
| 11198 * @see CompileTimeErrorCode#EXPORT_INTERNAL_LIBRARY | 11476 * @see CompileTimeErrorCode#EXPORT_INTERNAL_LIBRARY |
| 11199 */ | 11477 */ |
| 11200 bool checkForExportInternalLibrary(ExportDirective node) { | 11478 bool checkForExportInternalLibrary(ExportDirective node) { |
| 11201 if (_isInSystemLibrary) { | 11479 if (_isInSystemLibrary) { |
| 11202 return false; | 11480 return false; |
| 11203 } | 11481 } |
| 11204 Element element = node.element; | 11482 Element element = node.element; |
| 11205 if (element is! ExportElement) { | 11483 if (element is! ExportElement) { |
| 11206 return false; | 11484 return false; |
| 11207 } | 11485 } |
| 11208 ExportElement exportElement = element as ExportElement; | 11486 ExportElement exportElement = element as ExportElement; |
| 11209 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; | 11487 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; |
| 11210 String uri = exportElement.uri; | 11488 String uri = exportElement.uri; |
| 11211 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 11489 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
| 11212 if (sdkLibrary == null) { | 11490 if (sdkLibrary == null) { |
| 11213 return false; | 11491 return false; |
| 11214 } | 11492 } |
| 11215 if (!sdkLibrary.isInternal()) { | 11493 if (!sdkLibrary.isInternal()) { |
| 11216 return false; | 11494 return false; |
| 11217 } | 11495 } |
| 11218 _errorReporter.reportError2(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, no
de, [node.uri]); | 11496 _errorReporter.reportError2(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, no
de, [node.uri]); |
| 11219 return true; | 11497 return true; |
| 11220 } | 11498 } |
| 11221 | 11499 |
| 11222 /** | 11500 /** |
| 11223 * This verifies that the passed extends clause does not extend classes such a
s num or String. | 11501 * This verifies that the passed extends clause does not extend classes such a
s num or String. |
| 11224 * @param node the extends clause to test | 11502 * @param node the extends clause to test |
| 11225 * @return {@code true} if and only if an error code is generated on the passe
d node | 11503 * @return `true` if and only if an error code is generated on the passed node |
| 11226 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS | 11504 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS |
| 11227 */ | 11505 */ |
| 11228 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) { | 11506 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) { |
| 11229 if (extendsClause == null) { | 11507 if (extendsClause == null) { |
| 11230 return false; | 11508 return false; |
| 11231 } | 11509 } |
| 11232 return checkForExtendsOrImplementsDisallowedClass(extendsClause.superclass,
CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS); | 11510 return checkForExtendsOrImplementsDisallowedClass(extendsClause.superclass,
CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS); |
| 11233 } | 11511 } |
| 11234 | 11512 |
| 11235 /** | 11513 /** |
| 11236 * This verifies that the passed type name does not extend or implement classe
s such as 'num' or | 11514 * This verifies that the passed type name does not extend or implement classe
s such as 'num' or |
| 11237 * 'String'. | 11515 * 'String'. |
| 11238 * @param node the type name to test | 11516 * @param node the type name to test |
| 11239 * @return {@code true} if and only if an error code is generated on the passe
d node | 11517 * @return `true` if and only if an error code is generated on the passed node |
| 11240 * @see #checkForExtendsDisallowedClass(ExtendsClause) | 11518 * @see #checkForExtendsDisallowedClass(ExtendsClause) |
| 11241 * @see #checkForImplementsDisallowedClass(ImplementsClause) | 11519 * @see #checkForImplementsDisallowedClass(ImplementsClause) |
| 11242 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS | 11520 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS |
| 11243 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS | 11521 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS |
| 11244 */ | 11522 */ |
| 11245 bool checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode e
rrorCode) { | 11523 bool checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode e
rrorCode) { |
| 11246 if (typeName.isSynthetic()) { | 11524 if (typeName.isSynthetic()) { |
| 11247 return false; | 11525 return false; |
| 11248 } | 11526 } |
| 11249 Type2 superType = typeName.type; | 11527 Type2 superType = typeName.type; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 11263 return true; | 11541 return true; |
| 11264 } | 11542 } |
| 11265 } | 11543 } |
| 11266 return false; | 11544 return false; |
| 11267 } | 11545 } |
| 11268 | 11546 |
| 11269 /** | 11547 /** |
| 11270 * This verifies that the passed constructor field initializer has compatible
field and | 11548 * This verifies that the passed constructor field initializer has compatible
field and |
| 11271 * initializer expression types. | 11549 * initializer expression types. |
| 11272 * @param node the constructor field initializer to test | 11550 * @param node the constructor field initializer to test |
| 11273 * @return {@code true} if and only if an error code is generated on the passe
d node | 11551 * @return `true` if and only if an error code is generated on the passed node |
| 11274 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE | 11552 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE |
| 11275 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE | 11553 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE |
| 11276 */ | 11554 */ |
| 11277 bool checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node) { | 11555 bool checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node) { |
| 11278 Element fieldNameElement = node.fieldName.element; | 11556 Element fieldNameElement = node.fieldName.element; |
| 11279 if (fieldNameElement is! FieldElement) { | 11557 if (fieldNameElement is! FieldElement) { |
| 11280 return false; | 11558 return false; |
| 11281 } | 11559 } |
| 11282 FieldElement fieldElement = fieldNameElement as FieldElement; | 11560 FieldElement fieldElement = fieldNameElement as FieldElement; |
| 11283 Type2 fieldType = fieldElement.type; | 11561 Type2 fieldType = fieldElement.type; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 11307 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N
OT_ASSIGNABLE, expression, [(propagatedType == null ? staticType : propagatedTyp
e).displayName, fieldType.displayName]); | 11585 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N
OT_ASSIGNABLE, expression, [(propagatedType == null ? staticType : propagatedTyp
e).displayName, fieldType.displayName]); |
| 11308 } else { | 11586 } else { |
| 11309 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN
ABLE, expression, [(propagatedType == null ? staticType : propagatedType).displa
yName, fieldType.displayName]); | 11587 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN
ABLE, expression, [(propagatedType == null ? staticType : propagatedType).displa
yName, fieldType.displayName]); |
| 11310 } | 11588 } |
| 11311 return true; | 11589 return true; |
| 11312 } | 11590 } |
| 11313 | 11591 |
| 11314 /** | 11592 /** |
| 11315 * This verifies that the passed field formal parameter is in a constructor de
claration. | 11593 * This verifies that the passed field formal parameter is in a constructor de
claration. |
| 11316 * @param node the field formal parameter to test | 11594 * @param node the field formal parameter to test |
| 11317 * @return {@code true} if and only if an error code is generated on the passe
d node | 11595 * @return `true` if and only if an error code is generated on the passed node |
| 11318 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR | 11596 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR |
| 11319 */ | 11597 */ |
| 11320 bool checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamete
r node) { | 11598 bool checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamete
r node) { |
| 11321 ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration
); | 11599 ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration
); |
| 11322 if (constructor == null) { | 11600 if (constructor == null) { |
| 11323 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE
_CONSTRUCTOR, node, []); | 11601 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE
_CONSTRUCTOR, node, []); |
| 11324 return true; | 11602 return true; |
| 11325 } | 11603 } |
| 11326 if (constructor.factoryKeyword != null) { | 11604 if (constructor.factoryKeyword != null) { |
| 11327 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY
_CONSTRUCTOR, node, []); | 11605 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY
_CONSTRUCTOR, node, []); |
| 11328 return true; | 11606 return true; |
| 11329 } | 11607 } |
| 11330 for (ConstructorInitializer initializer in constructor.initializers) { | 11608 for (ConstructorInitializer initializer in constructor.initializers) { |
| 11331 if (initializer is RedirectingConstructorInvocation) { | 11609 if (initializer is RedirectingConstructorInvocation) { |
| 11332 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_REDIR
ECTING_CONSTRUCTOR, node, []); | 11610 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_REDIR
ECTING_CONSTRUCTOR, node, []); |
| 11333 return true; | 11611 return true; |
| 11334 } | 11612 } |
| 11335 } | 11613 } |
| 11336 return false; | 11614 return false; |
| 11337 } | 11615 } |
| 11338 | 11616 |
| 11339 /** | 11617 /** |
| 11340 * This verifies that final fields that are declared, without any constructors
in the enclosing | 11618 * This verifies that final fields that are declared, without any constructors
in the enclosing |
| 11341 * class, are initialized. Cases in which there is at least one constructor ar
e handled at the end | 11619 * class, are initialized. Cases in which there is at least one constructor ar
e handled at the end |
| 11342 * of {@link #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration)}. | 11620 * of [checkForAllFinalInitializedErrorCodes]. |
| 11343 * @param node the class declaration to test | 11621 * @param node the class declaration to test |
| 11344 * @return {@code true} if and only if an error code is generated on the passe
d node | 11622 * @return `true` if and only if an error code is generated on the passed node |
| 11345 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 11623 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED |
| 11346 */ | 11624 */ |
| 11347 bool checkForFinalNotInitialized(ClassDeclaration node) { | 11625 bool checkForFinalNotInitialized(ClassDeclaration node) { |
| 11348 NodeList<ClassMember> classMembers = node.members; | 11626 NodeList<ClassMember> classMembers = node.members; |
| 11349 for (ClassMember classMember in classMembers) { | 11627 for (ClassMember classMember in classMembers) { |
| 11350 if (classMember is ConstructorDeclaration) { | 11628 if (classMember is ConstructorDeclaration) { |
| 11351 return false; | 11629 return false; |
| 11352 } | 11630 } |
| 11353 } | 11631 } |
| 11354 bool foundError = false; | 11632 bool foundError = false; |
| 11355 for (ClassMember classMember in classMembers) { | 11633 for (ClassMember classMember in classMembers) { |
| 11356 if (classMember is FieldDeclaration) { | 11634 if (classMember is FieldDeclaration) { |
| 11357 FieldDeclaration field = classMember as FieldDeclaration; | 11635 FieldDeclaration field = classMember as FieldDeclaration; |
| 11358 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel
d.fields)); | 11636 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel
d.fields)); |
| 11359 } | 11637 } |
| 11360 } | 11638 } |
| 11361 return foundError; | 11639 return foundError; |
| 11362 } | 11640 } |
| 11363 | 11641 |
| 11364 /** | 11642 /** |
| 11365 * This verifies that the passed variable declaration list has only initialize
d variables if the | 11643 * This verifies that the passed variable declaration list has only initialize
d variables if the |
| 11366 * list is final or const. This method is called by{@link #checkForFinalNotIni
tialized(ClassDeclaration)},{@link #visitTopLevelVariableDeclaration(TopLevelVar
iableDeclaration)} and{@link #visitVariableDeclarationStatement(VariableDeclarat
ionStatement)}. | 11644 * list is final or const. This method is called by[checkForFinalNotInitialize
d],[visitTopLevelVariableDeclaration] and[visitVariableDeclarationStatement]. |
| 11367 * @param node the class declaration to test | 11645 * @param node the class declaration to test |
| 11368 * @return {@code true} if and only if an error code is generated on the passe
d node | 11646 * @return `true` if and only if an error code is generated on the passed node |
| 11369 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 11647 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED |
| 11370 */ | 11648 */ |
| 11371 bool checkForFinalNotInitialized2(VariableDeclarationList node) { | 11649 bool checkForFinalNotInitialized2(VariableDeclarationList node) { |
| 11372 bool foundError = false; | 11650 bool foundError = false; |
| 11373 if (!node.isSynthetic() && (node.isConst() || node.isFinal())) { | 11651 if (!node.isSynthetic() && (node.isConst() || node.isFinal())) { |
| 11374 NodeList<VariableDeclaration> variables = node.variables; | 11652 NodeList<VariableDeclaration> variables = node.variables; |
| 11375 for (VariableDeclaration variable in variables) { | 11653 for (VariableDeclaration variable in variables) { |
| 11376 if (variable.initializer == null) { | 11654 if (variable.initializer == null) { |
| 11377 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, v
ariable, [variable.name.name]); | 11655 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, v
ariable, [variable.name.name]); |
| 11378 foundError = true; | 11656 foundError = true; |
| 11379 } | 11657 } |
| 11380 } | 11658 } |
| 11381 } | 11659 } |
| 11382 return foundError; | 11660 return foundError; |
| 11383 } | 11661 } |
| 11384 | 11662 |
| 11385 /** | 11663 /** |
| 11386 * This verifies that the passed implements clause does not implement classes
such as 'num' or | 11664 * This verifies that the passed implements clause does not implement classes
such as 'num' or |
| 11387 * 'String'. | 11665 * 'String'. |
| 11388 * @param node the implements clause to test | 11666 * @param node the implements clause to test |
| 11389 * @return {@code true} if and only if an error code is generated on the passe
d node | 11667 * @return `true` if and only if an error code is generated on the passed node |
| 11390 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS | 11668 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS |
| 11391 */ | 11669 */ |
| 11392 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { | 11670 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { |
| 11393 if (implementsClause == null) { | 11671 if (implementsClause == null) { |
| 11394 return false; | 11672 return false; |
| 11395 } | 11673 } |
| 11396 bool foundError = false; | 11674 bool foundError = false; |
| 11397 for (TypeName type in implementsClause.interfaces) { | 11675 for (TypeName type in implementsClause.interfaces) { |
| 11398 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow
edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); | 11676 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow
edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); |
| 11399 } | 11677 } |
| 11400 return foundError; | 11678 return foundError; |
| 11401 } | 11679 } |
| 11402 | 11680 |
| 11403 /** | 11681 /** |
| 11404 * This verifies that if the passed identifier is part of constructor initiali
zer, then it does | 11682 * This verifies that if the passed identifier is part of constructor initiali
zer, then it does |
| 11405 * not reference implicitly 'this' expression. | 11683 * not reference implicitly 'this' expression. |
| 11406 * @param node the simple identifier to test | 11684 * @param node the simple identifier to test |
| 11407 * @return {@code true} if and only if an error code is generated on the passe
d node | 11685 * @return `true` if and only if an error code is generated on the passed node |
| 11408 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER | 11686 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER |
| 11409 */ | 11687 */ |
| 11410 bool checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { | 11688 bool checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { |
| 11411 if (!_isInConstructorInitializer) { | 11689 if (!_isInConstructorInitializer) { |
| 11412 return false; | 11690 return false; |
| 11413 } | 11691 } |
| 11414 Element element = node.element; | 11692 Element element = node.element; |
| 11415 if (!(element is MethodElement || element is PropertyAccessorElement)) { | 11693 if (!(element is MethodElement || element is PropertyAccessorElement)) { |
| 11416 return false; | 11694 return false; |
| 11417 } | 11695 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 11444 } | 11722 } |
| 11445 } | 11723 } |
| 11446 } | 11724 } |
| 11447 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_
INITIALIZER, node, []); | 11725 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_
INITIALIZER, node, []); |
| 11448 return true; | 11726 return true; |
| 11449 } | 11727 } |
| 11450 | 11728 |
| 11451 /** | 11729 /** |
| 11452 * This verifies the passed import has unique name among other imported librar
ies. | 11730 * This verifies the passed import has unique name among other imported librar
ies. |
| 11453 * @param node the import directive to evaluate | 11731 * @param node the import directive to evaluate |
| 11454 * @return {@code true} if and only if an error code is generated on the passe
d node | 11732 * @return `true` if and only if an error code is generated on the passed node |
| 11455 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME | 11733 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME |
| 11456 */ | 11734 */ |
| 11457 bool checkForImportDuplicateLibraryName(ImportDirective node) { | 11735 bool checkForImportDuplicateLibraryName(ImportDirective node) { |
| 11458 Element nodeElement = node.element; | 11736 Element nodeElement = node.element; |
| 11459 if (nodeElement is! ImportElement) { | 11737 if (nodeElement is! ImportElement) { |
| 11460 return false; | 11738 return false; |
| 11461 } | 11739 } |
| 11462 ImportElement nodeImportElement = nodeElement as ImportElement; | 11740 ImportElement nodeImportElement = nodeElement as ImportElement; |
| 11463 LibraryElement nodeLibrary = nodeImportElement.importedLibrary; | 11741 LibraryElement nodeLibrary = nodeImportElement.importedLibrary; |
| 11464 if (nodeLibrary == null) { | 11742 if (nodeLibrary == null) { |
| 11465 return false; | 11743 return false; |
| 11466 } | 11744 } |
| 11467 String name = nodeLibrary.name; | 11745 String name = nodeLibrary.name; |
| 11468 LibraryElement prevLibrary = _nameToImportElement[name]; | 11746 LibraryElement prevLibrary = _nameToImportElement[name]; |
| 11469 if (prevLibrary != null) { | 11747 if (prevLibrary != null) { |
| 11470 if (prevLibrary != nodeLibrary) { | 11748 if (prevLibrary != nodeLibrary) { |
| 11471 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name]); | 11749 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name]); |
| 11472 return true; | 11750 return true; |
| 11473 } | 11751 } |
| 11474 } else { | 11752 } else { |
| 11475 _nameToImportElement[name] = nodeLibrary; | 11753 _nameToImportElement[name] = nodeLibrary; |
| 11476 } | 11754 } |
| 11477 return false; | 11755 return false; |
| 11478 } | 11756 } |
| 11479 | 11757 |
| 11480 /** | 11758 /** |
| 11481 * Check that if the visiting library is not system, then any passed library s
hould not be SDK | 11759 * Check that if the visiting library is not system, then any passed library s
hould not be SDK |
| 11482 * internal library. | 11760 * internal library. |
| 11483 * @param node the import directive to evaluate | 11761 * @param node the import directive to evaluate |
| 11484 * @return {@code true} if and only if an error code is generated on the passe
d node | 11762 * @return `true` if and only if an error code is generated on the passed node |
| 11485 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY | 11763 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY |
| 11486 */ | 11764 */ |
| 11487 bool checkForImportInternalLibrary(ImportDirective node) { | 11765 bool checkForImportInternalLibrary(ImportDirective node) { |
| 11488 if (_isInSystemLibrary) { | 11766 if (_isInSystemLibrary) { |
| 11489 return false; | 11767 return false; |
| 11490 } | 11768 } |
| 11491 Element element = node.element; | 11769 Element element = node.element; |
| 11492 if (element is! ImportElement) { | 11770 if (element is! ImportElement) { |
| 11493 return false; | 11771 return false; |
| 11494 } | 11772 } |
| 11495 ImportElement importElement = element as ImportElement; | 11773 ImportElement importElement = element as ImportElement; |
| 11496 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; | 11774 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; |
| 11497 String uri = importElement.uri; | 11775 String uri = importElement.uri; |
| 11498 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 11776 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
| 11499 if (sdkLibrary == null) { | 11777 if (sdkLibrary == null) { |
| 11500 return false; | 11778 return false; |
| 11501 } | 11779 } |
| 11502 if (!sdkLibrary.isInternal()) { | 11780 if (!sdkLibrary.isInternal()) { |
| 11503 return false; | 11781 return false; |
| 11504 } | 11782 } |
| 11505 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no
de, [node.uri]); | 11783 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no
de, [node.uri]); |
| 11506 return true; | 11784 return true; |
| 11507 } | 11785 } |
| 11508 | 11786 |
| 11509 /** | 11787 /** |
| 11510 * This verifies that the passed switch statement case expressions all have th
e same type. | 11788 * This verifies that the passed switch statement case expressions all have th
e same type. |
| 11511 * @param node the switch statement to evaluate | 11789 * @param node the switch statement to evaluate |
| 11512 * @return {@code true} if and only if an error code is generated on the passe
d node | 11790 * @return `true` if and only if an error code is generated on the passed node |
| 11513 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES | 11791 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES |
| 11514 */ | 11792 */ |
| 11515 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) { | 11793 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) { |
| 11516 NodeList<SwitchMember> switchMembers = node.members; | 11794 NodeList<SwitchMember> switchMembers = node.members; |
| 11517 bool foundError = false; | 11795 bool foundError = false; |
| 11518 Type2 firstType = null; | 11796 Type2 firstType = null; |
| 11519 for (SwitchMember switchMember in switchMembers) { | 11797 for (SwitchMember switchMember in switchMembers) { |
| 11520 if (switchMember is SwitchCase) { | 11798 if (switchMember is SwitchCase) { |
| 11521 SwitchCase switchCase = switchMember as SwitchCase; | 11799 SwitchCase switchCase = switchMember as SwitchCase; |
| 11522 Expression expression = switchCase.expression; | 11800 Expression expression = switchCase.expression; |
| 11523 if (firstType == null) { | 11801 if (firstType == null) { |
| 11524 firstType = getBestType(expression); | 11802 firstType = getBestType(expression); |
| 11525 } else { | 11803 } else { |
| 11526 Type2 nType = getBestType(expression); | 11804 Type2 nType = getBestType(expression); |
| 11527 if (firstType != nType) { | 11805 if (firstType != nType) { |
| 11528 _errorReporter.reportError2(CompileTimeErrorCode.INCONSISTENT_CASE_E
XPRESSION_TYPES, expression, [expression.toSource(), firstType.displayName]); | 11806 _errorReporter.reportError2(CompileTimeErrorCode.INCONSISTENT_CASE_E
XPRESSION_TYPES, expression, [expression.toSource(), firstType.displayName]); |
| 11529 foundError = true; | 11807 foundError = true; |
| 11530 } | 11808 } |
| 11531 } | 11809 } |
| 11532 } | 11810 } |
| 11533 } | 11811 } |
| 11534 return foundError; | 11812 return foundError; |
| 11535 } | 11813 } |
| 11536 | 11814 |
| 11537 /** | 11815 /** |
| 11538 * For each class declaration, this method is called which verifies that all i
nherited members are | 11816 * For each class declaration, this method is called which verifies that all i
nherited members are |
| 11539 * inherited consistently. | 11817 * inherited consistently. |
| 11540 * @return {@code true} if and only if an error code is generated on the passe
d node | 11818 * @return `true` if and only if an error code is generated on the passed node |
| 11541 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE | 11819 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE |
| 11542 */ | 11820 */ |
| 11543 bool checkForInconsistentMethodInheritance() { | 11821 bool checkForInconsistentMethodInheritance() { |
| 11544 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass); | 11822 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass); |
| 11545 Set<AnalysisError> errors = _inheritanceManager.getErrors(_enclosingClass); | 11823 Set<AnalysisError> errors = _inheritanceManager.getErrors(_enclosingClass); |
| 11546 if (errors == null || errors.isEmpty) { | 11824 if (errors == null || errors.isEmpty) { |
| 11547 return false; | 11825 return false; |
| 11548 } | 11826 } |
| 11549 for (AnalysisError error in errors) { | 11827 for (AnalysisError error in errors) { |
| 11550 _errorReporter.reportError(error); | 11828 _errorReporter.reportError(error); |
| 11551 } | 11829 } |
| 11552 return true; | 11830 return true; |
| 11553 } | 11831 } |
| 11554 | 11832 |
| 11555 /** | 11833 /** |
| 11556 * Given an assignment using a compound assignment operator, this verifies tha
t the given | 11834 * Given an assignment using a compound assignment operator, this verifies tha
t the given |
| 11557 * assignment is valid. | 11835 * assignment is valid. |
| 11558 * @param node the assignment expression being tested | 11836 * @param node the assignment expression being tested |
| 11559 * @return {@code true} if and only if an error code is generated on the passe
d node | 11837 * @return `true` if and only if an error code is generated on the passed node |
| 11560 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT | 11838 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT |
| 11561 */ | 11839 */ |
| 11562 bool checkForInvalidAssignment(AssignmentExpression node) { | 11840 bool checkForInvalidAssignment(AssignmentExpression node) { |
| 11563 Expression lhs = node.leftHandSide; | 11841 Expression lhs = node.leftHandSide; |
| 11564 if (lhs == null) { | 11842 if (lhs == null) { |
| 11565 return false; | 11843 return false; |
| 11566 } | 11844 } |
| 11567 VariableElement leftElement = getVariableElement(lhs); | 11845 VariableElement leftElement = getVariableElement(lhs); |
| 11568 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; | 11846 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; |
| 11569 MethodElement invokedMethod = node.element; | 11847 MethodElement invokedMethod = node.element; |
| 11570 if (invokedMethod == null) { | 11848 if (invokedMethod == null) { |
| 11571 return false; | 11849 return false; |
| 11572 } | 11850 } |
| 11573 Type2 rightType = invokedMethod.type.returnType; | 11851 Type2 rightType = invokedMethod.type.returnType; |
| 11574 if (leftType == null || rightType == null) { | 11852 if (leftType == null || rightType == null) { |
| 11575 return false; | 11853 return false; |
| 11576 } | 11854 } |
| 11577 if (!rightType.isAssignableTo(leftType)) { | 11855 if (!rightType.isAssignableTo(leftType)) { |
| 11578 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, node
.rightHandSide, [rightType.displayName, leftType.displayName]); | 11856 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, node
.rightHandSide, [rightType.displayName, leftType.displayName]); |
| 11579 return true; | 11857 return true; |
| 11580 } | 11858 } |
| 11581 return false; | 11859 return false; |
| 11582 } | 11860 } |
| 11583 | 11861 |
| 11584 /** | 11862 /** |
| 11585 * This verifies that the passed left hand side and right hand side represent
a valid assignment. | 11863 * This verifies that the passed left hand side and right hand side represent
a valid assignment. |
| 11586 * @param lhs the left hand side expression | 11864 * @param lhs the left hand side expression |
| 11587 * @param rhs the right hand side expression | 11865 * @param rhs the right hand side expression |
| 11588 * @return {@code true} if and only if an error code is generated on the passe
d node | 11866 * @return `true` if and only if an error code is generated on the passed node |
| 11589 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT | 11867 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT |
| 11590 */ | 11868 */ |
| 11591 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) { | 11869 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) { |
| 11592 if (lhs == null || rhs == null) { | 11870 if (lhs == null || rhs == null) { |
| 11593 return false; | 11871 return false; |
| 11594 } | 11872 } |
| 11595 VariableElement leftElement = getVariableElement(lhs); | 11873 VariableElement leftElement = getVariableElement(lhs); |
| 11596 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; | 11874 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; |
| 11597 Type2 staticRightType = getStaticType(rhs); | 11875 Type2 staticRightType = getStaticType(rhs); |
| 11598 bool isStaticAssignable = staticRightType.isAssignableTo(leftType); | 11876 bool isStaticAssignable = staticRightType.isAssignableTo(leftType); |
| 11599 Type2 propagatedRightType = getPropagatedType(rhs); | 11877 Type2 propagatedRightType = getPropagatedType(rhs); |
| 11600 if (_strictMode || propagatedRightType == null) { | 11878 if (_strictMode || propagatedRightType == null) { |
| 11601 if (!isStaticAssignable) { | 11879 if (!isStaticAssignable) { |
| 11602 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); | 11880 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); |
| 11603 return true; | 11881 return true; |
| 11604 } | 11882 } |
| 11605 } else { | 11883 } else { |
| 11606 bool isPropagatedAssignable = propagatedRightType.isAssignableTo(leftType)
; | 11884 bool isPropagatedAssignable = propagatedRightType.isAssignableTo(leftType)
; |
| 11607 if (!isStaticAssignable && !isPropagatedAssignable) { | 11885 if (!isStaticAssignable && !isPropagatedAssignable) { |
| 11608 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); | 11886 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); |
| 11609 return true; | 11887 return true; |
| 11610 } | 11888 } |
| 11611 } | 11889 } |
| 11612 return false; | 11890 return false; |
| 11613 } | 11891 } |
| 11614 | 11892 |
| 11615 /** | 11893 /** |
| 11616 * This verifies that the usage of the passed 'this' is valid. | 11894 * This verifies that the usage of the passed 'this' is valid. |
| 11617 * @param node the 'this' expression to evaluate | 11895 * @param node the 'this' expression to evaluate |
| 11618 * @return {@code true} if and only if an error code is generated on the passe
d node | 11896 * @return `true` if and only if an error code is generated on the passed node |
| 11619 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS | 11897 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS |
| 11620 */ | 11898 */ |
| 11621 bool checkForInvalidReferenceToThis(ThisExpression node) { | 11899 bool checkForInvalidReferenceToThis(ThisExpression node) { |
| 11622 if (!isThisInValidContext(node)) { | 11900 if (!isThisInValidContext(node)) { |
| 11623 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS
, node, []); | 11901 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS
, node, []); |
| 11624 return true; | 11902 return true; |
| 11625 } | 11903 } |
| 11626 return false; | 11904 return false; |
| 11627 } | 11905 } |
| 11628 | 11906 |
| 11629 /** | 11907 /** |
| 11630 * Checks to ensure that first type argument to a map literal must be the 'Str
ing' type. | 11908 * Checks to ensure that first type argument to a map literal must be the 'Str
ing' type. |
| 11631 * @param arguments a non-{@code null}, non-empty {@link TypeName} node list f
rom the respective{@link MapLiteral} | 11909 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective[MapLiteral] |
| 11632 * @return {@code true} if and only if an error code is generated on the passe
d node | 11910 * @return `true` if and only if an error code is generated on the passed node |
| 11633 * @see CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_FOR_KEY | 11911 * @see CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_FOR_KEY |
| 11634 */ | 11912 */ |
| 11635 bool checkForInvalidTypeArgumentForKey(NodeList<TypeName> arguments) { | 11913 bool checkForInvalidTypeArgumentForKey(NodeList<TypeName> arguments) { |
| 11636 TypeName firstArgument = arguments[0]; | 11914 TypeName firstArgument = arguments[0]; |
| 11637 Type2 firstArgumentType = firstArgument.type; | 11915 Type2 firstArgumentType = firstArgument.type; |
| 11638 if (firstArgumentType != null && firstArgumentType != _typeProvider.stringTy
pe) { | 11916 if (firstArgumentType != null && firstArgumentType != _typeProvider.stringTy
pe) { |
| 11639 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR
_KEY, firstArgument, []); | 11917 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR
_KEY, firstArgument, []); |
| 11640 return true; | 11918 return true; |
| 11641 } | 11919 } |
| 11642 return false; | 11920 return false; |
| 11643 } | 11921 } |
| 11644 | 11922 |
| 11645 /** | 11923 /** |
| 11646 * Checks to ensure that the passed {@link ListLiteral} or {@link MapLiteral}
does not have a type | 11924 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav
e a type |
| 11647 * parameter as a type argument. | 11925 * parameter as a type argument. |
| 11648 * @param arguments a non-{@code null}, non-empty {@link TypeName} node list f
rom the respective{@link ListLiteral} or {@link MapLiteral} | 11926 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective[ListLiteral] or [MapLiteral] |
| 11649 * @param errorCode either {@link CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_I
N_CONST_LIST} or{@link CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP} | 11927 * @param errorCode either [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONS
T_LIST] or[CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP] |
| 11650 * @return {@code true} if and only if an error code is generated on the passe
d node | 11928 * @return `true` if and only if an error code is generated on the passed node |
| 11651 */ | 11929 */ |
| 11652 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen
ts, ErrorCode errorCode) { | 11930 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen
ts, ErrorCode errorCode) { |
| 11653 bool foundError = false; | 11931 bool foundError = false; |
| 11654 for (TypeName typeName in arguments) { | 11932 for (TypeName typeName in arguments) { |
| 11655 if (typeName.type is TypeVariableType) { | 11933 if (typeName.type is TypeVariableType) { |
| 11656 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); | 11934 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); |
| 11657 foundError = true; | 11935 foundError = true; |
| 11658 } | 11936 } |
| 11659 } | 11937 } |
| 11660 return foundError; | 11938 return foundError; |
| 11661 } | 11939 } |
| 11662 | 11940 |
| 11663 /** | 11941 /** |
| 11664 * This verifies that the {@link #enclosingClass} does not define members with
the same name as | 11942 * This verifies that the [enclosingClass] does not define members with the sa
me name as |
| 11665 * the enclosing class. | 11943 * the enclosing class. |
| 11666 * @return {@code true} if and only if an error code is generated on the passe
d node | 11944 * @return `true` if and only if an error code is generated on the passed node |
| 11667 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME | 11945 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME |
| 11668 */ | 11946 */ |
| 11669 bool checkForMemberWithClassName() { | 11947 bool checkForMemberWithClassName() { |
| 11670 if (_enclosingClass == null) { | 11948 if (_enclosingClass == null) { |
| 11671 return false; | 11949 return false; |
| 11672 } | 11950 } |
| 11673 String className = _enclosingClass.name; | 11951 String className = _enclosingClass.name; |
| 11674 if (className == null) { | 11952 if (className == null) { |
| 11675 return false; | 11953 return false; |
| 11676 } | 11954 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11712 } | 11990 } |
| 11713 if (setterType != null && getterType != null && !getterType.isAssignableTo(s
etterType)) { | 11991 if (setterType != null && getterType != null && !getterType.isAssignableTo(s
etterType)) { |
| 11714 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER
_TYPES, accessorDeclaration, [accessorTextName, setterType.displayName, getterTy
pe.displayName]); | 11992 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER
_TYPES, accessorDeclaration, [accessorTextName, setterType.displayName, getterTy
pe.displayName]); |
| 11715 } | 11993 } |
| 11716 } | 11994 } |
| 11717 | 11995 |
| 11718 /** | 11996 /** |
| 11719 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. | 11997 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. |
| 11720 * @param mixinName the node to report problem on | 11998 * @param mixinName the node to report problem on |
| 11721 * @param mixinElement the mixing to evaluate | 11999 * @param mixinElement the mixing to evaluate |
| 11722 * @return {@code true} if and only if an error code is generated on the passe
d node | 12000 * @return `true` if and only if an error code is generated on the passed node |
| 11723 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR | 12001 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR |
| 11724 */ | 12002 */ |
| 11725 bool checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinEl
ement) { | 12003 bool checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinEl
ement) { |
| 11726 for (ConstructorElement constructor in mixinElement.constructors) { | 12004 for (ConstructorElement constructor in mixinElement.constructors) { |
| 11727 if (!constructor.isSynthetic() && !constructor.isFactory()) { | 12005 if (!constructor.isSynthetic() && !constructor.isFactory()) { |
| 11728 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUC
TOR, mixinName, [mixinElement.name]); | 12006 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUC
TOR, mixinName, [mixinElement.name]); |
| 11729 return true; | 12007 return true; |
| 11730 } | 12008 } |
| 11731 } | 12009 } |
| 11732 return false; | 12010 return false; |
| 11733 } | 12011 } |
| 11734 | 12012 |
| 11735 /** | 12013 /** |
| 11736 * This verifies that the passed mixin has the 'Object' superclass. | 12014 * This verifies that the passed mixin has the 'Object' superclass. |
| 11737 * @param mixinName the node to report problem on | 12015 * @param mixinName the node to report problem on |
| 11738 * @param mixinElement the mixing to evaluate | 12016 * @param mixinElement the mixing to evaluate |
| 11739 * @return {@code true} if and only if an error code is generated on the passe
d node | 12017 * @return `true` if and only if an error code is generated on the passed node |
| 11740 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT | 12018 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT |
| 11741 */ | 12019 */ |
| 11742 bool checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixin
Element) { | 12020 bool checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixin
Element) { |
| 11743 InterfaceType mixinSupertype = mixinElement.supertype; | 12021 InterfaceType mixinSupertype = mixinElement.supertype; |
| 11744 if (mixinSupertype != null) { | 12022 if (mixinSupertype != null) { |
| 11745 if (!mixinSupertype.isObject() || !mixinElement.isTypedef() && mixinElemen
t.mixins.length != 0) { | 12023 if (!mixinSupertype.isObject() || !mixinElement.isTypedef() && mixinElemen
t.mixins.length != 0) { |
| 11746 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT
_OBJECT, mixinName, [mixinElement.name]); | 12024 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT
_OBJECT, mixinName, [mixinElement.name]); |
| 11747 return true; | 12025 return true; |
| 11748 } | 12026 } |
| 11749 } | 12027 } |
| 11750 return false; | 12028 return false; |
| 11751 } | 12029 } |
| 11752 | 12030 |
| 11753 /** | 12031 /** |
| 11754 * This verifies that the passed mixin does not reference 'super'. | 12032 * This verifies that the passed mixin does not reference 'super'. |
| 11755 * @param mixinName the node to report problem on | 12033 * @param mixinName the node to report problem on |
| 11756 * @param mixinElement the mixing to evaluate | 12034 * @param mixinElement the mixing to evaluate |
| 11757 * @return {@code true} if and only if an error code is generated on the passe
d node | 12035 * @return `true` if and only if an error code is generated on the passed node |
| 11758 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER | 12036 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER |
| 11759 */ | 12037 */ |
| 11760 bool checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinElemen
t) { | 12038 bool checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinElemen
t) { |
| 11761 if (mixinElement.hasReferenceToSuper()) { | 12039 if (mixinElement.hasReferenceToSuper()) { |
| 11762 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, m
ixinName, [mixinElement.name]); | 12040 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, m
ixinName, [mixinElement.name]); |
| 11763 } | 12041 } |
| 11764 return false; | 12042 return false; |
| 11765 } | 12043 } |
| 11766 | 12044 |
| 11767 /** | 12045 /** |
| 11768 * This verifies that the passed constructor has at most one 'super' initializ
er. | 12046 * This verifies that the passed constructor has at most one 'super' initializ
er. |
| 11769 * @param node the constructor declaration to evaluate | 12047 * @param node the constructor declaration to evaluate |
| 11770 * @return {@code true} if and only if an error code is generated on the passe
d node | 12048 * @return `true` if and only if an error code is generated on the passed node |
| 11771 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS | 12049 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS |
| 11772 */ | 12050 */ |
| 11773 bool checkForMultipleSuperInitializers(ConstructorDeclaration node) { | 12051 bool checkForMultipleSuperInitializers(ConstructorDeclaration node) { |
| 11774 int numSuperInitializers = 0; | 12052 int numSuperInitializers = 0; |
| 11775 for (ConstructorInitializer initializer in node.initializers) { | 12053 for (ConstructorInitializer initializer in node.initializers) { |
| 11776 if (initializer is SuperConstructorInvocation) { | 12054 if (initializer is SuperConstructorInvocation) { |
| 11777 numSuperInitializers++; | 12055 numSuperInitializers++; |
| 11778 if (numSuperInitializers > 1) { | 12056 if (numSuperInitializers > 1) { |
| 11779 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_SUPER_INITIA
LIZERS, initializer, []); | 12057 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_SUPER_INITIA
LIZERS, initializer, []); |
| 11780 } | 12058 } |
| 11781 } | 12059 } |
| 11782 } | 12060 } |
| 11783 return numSuperInitializers > 0; | 12061 return numSuperInitializers > 0; |
| 11784 } | 12062 } |
| 11785 | 12063 |
| 11786 /** | 12064 /** |
| 11787 * Checks to ensure that native function bodies can only in SDK code. | 12065 * Checks to ensure that native function bodies can only in SDK code. |
| 11788 * @param node the native function body to test | 12066 * @param node the native function body to test |
| 11789 * @return {@code true} if and only if an error code is generated on the passe
d node | 12067 * @return `true` if and only if an error code is generated on the passed node |
| 11790 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE | 12068 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE |
| 11791 */ | 12069 */ |
| 11792 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { | 12070 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { |
| 11793 if (!_isInSystemLibrary) { | 12071 if (!_isInSystemLibrary) { |
| 11794 _errorReporter.reportError2(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD
K_CODE, node, []); | 12072 _errorReporter.reportError2(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD
K_CODE, node, []); |
| 11795 return true; | 12073 return true; |
| 11796 } | 12074 } |
| 11797 return false; | 12075 return false; |
| 11798 } | 12076 } |
| 11799 | 12077 |
| 11800 /** | 12078 /** |
| 11801 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. | 12079 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. |
| 11802 * <p> | 12080 * |
| 11803 * This method assumes that the instance creation was tested to be 'new' befor
e being called. | 12081 * This method assumes that the instance creation was tested to be 'new' befor
e being called. |
| 11804 * @param node the instance creation expression to evaluate | 12082 * @param node the instance creation expression to evaluate |
| 11805 * @return {@code true} if and only if an error code is generated on the passe
d node | 12083 * @return `true` if and only if an error code is generated on the passed node |
| 11806 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR | 12084 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR |
| 11807 */ | 12085 */ |
| 11808 bool checkForNewWithUndefinedConstructor(InstanceCreationExpression node) { | 12086 bool checkForNewWithUndefinedConstructor(InstanceCreationExpression node) { |
| 11809 if (node.element != null) { | 12087 if (node.element != null) { |
| 11810 return false; | 12088 return false; |
| 11811 } | 12089 } |
| 11812 ConstructorName constructorName = node.constructorName; | 12090 ConstructorName constructorName = node.constructorName; |
| 11813 if (constructorName == null) { | 12091 if (constructorName == null) { |
| 11814 return false; | 12092 return false; |
| 11815 } | 12093 } |
| 11816 TypeName type = constructorName.type; | 12094 TypeName type = constructorName.type; |
| 11817 if (type == null) { | 12095 if (type == null) { |
| 11818 return false; | 12096 return false; |
| 11819 } | 12097 } |
| 11820 Identifier className = type.name; | 12098 Identifier className = type.name; |
| 11821 SimpleIdentifier name = constructorName.name; | 12099 SimpleIdentifier name = constructorName.name; |
| 11822 if (name != null) { | 12100 if (name != null) { |
| 11823 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR, name, [className, name]); | 12101 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR, name, [className, name]); |
| 11824 } else { | 12102 } else { |
| 11825 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR_DEFAULT, constructorName, [className]); | 12103 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR_DEFAULT, constructorName, [className]); |
| 11826 } | 12104 } |
| 11827 return true; | 12105 return true; |
| 11828 } | 12106 } |
| 11829 | 12107 |
| 11830 /** | 12108 /** |
| 12109 * This checks that passed if the passed class declaration implicitly calls de
fault constructor of |
| 12110 * its superclass, there should be such default constructor - implicit or expl
icit. |
| 12111 * @param node the [ClassDeclaration] to evaluate |
| 12112 * @return `true` if and only if an error code is generated on the passed node |
| 12113 * @see StaticWarningCode#NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
| 12114 */ |
| 12115 bool checkForNoDefaultSuperConstructorImplicit(ClassDeclaration node) { |
| 12116 List<ConstructorElement> constructors = _enclosingClass.constructors; |
| 12117 if (!constructors[0].isSynthetic()) { |
| 12118 return false; |
| 12119 } |
| 12120 InterfaceType superType = _enclosingClass.supertype; |
| 12121 if (superType == null) { |
| 12122 return false; |
| 12123 } |
| 12124 ClassElement superClass = superType.element; |
| 12125 if (superClass.hasDefaultConstructor()) { |
| 12126 return false; |
| 12127 } |
| 12128 _errorReporter.reportError2(StaticWarningCode.NO_DEFAULT_SUPER_CONSTRUCTOR_I
MPLICIT, node.name, [superType.displayName]); |
| 12129 return true; |
| 12130 } |
| 12131 |
| 12132 /** |
| 11831 * This checks that passed class declaration overrides all members required by
its superclasses | 12133 * This checks that passed class declaration overrides all members required by
its superclasses |
| 11832 * and interfaces. | 12134 * and interfaces. |
| 11833 * @param node the {@link ClassDeclaration} to evaluate | 12135 * @param node the [ClassDeclaration] to evaluate |
| 11834 * @return {@code true} if and only if an error code is generated on the passe
d node | 12136 * @return `true` if and only if an error code is generated on the passed node |
| 11835 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE | 12137 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE |
| 11836 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO | 12138 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO |
| 11837 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE | 12139 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE |
| 11838 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR | 12140 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR |
| 11839 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU
S | 12141 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU
S |
| 11840 */ | 12142 */ |
| 11841 bool checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration node) { | 12143 bool checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration node) { |
| 11842 if (_enclosingClass.isAbstract()) { | 12144 if (_enclosingClass.isAbstract()) { |
| 11843 return false; | 12145 return false; |
| 11844 } | 12146 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11925 } | 12227 } |
| 11926 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri
desArray); | 12228 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri
desArray); |
| 11927 _errorReporter.reportError(analysisError); | 12229 _errorReporter.reportError(analysisError); |
| 11928 return true; | 12230 return true; |
| 11929 } | 12231 } |
| 11930 | 12232 |
| 11931 /** | 12233 /** |
| 11932 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is | 12234 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is |
| 11933 * reported on the expression. | 12235 * reported on the expression. |
| 11934 * @param condition the conditional expression to test | 12236 * @param condition the conditional expression to test |
| 11935 * @return {@code true} if and only if an error code is generated on the passe
d node | 12237 * @return `true` if and only if an error code is generated on the passed node |
| 11936 * @see StaticTypeWarningCode#NON_BOOL_CONDITION | 12238 * @see StaticTypeWarningCode#NON_BOOL_CONDITION |
| 11937 */ | 12239 */ |
| 11938 bool checkForNonBoolCondition(Expression condition) { | 12240 bool checkForNonBoolCondition(Expression condition) { |
| 11939 Type2 conditionType = getStaticType(condition); | 12241 Type2 conditionType = getStaticType(condition); |
| 11940 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo
lType)) { | 12242 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo
lType)) { |
| 11941 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_CONDITION, cond
ition, []); | 12243 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_CONDITION, cond
ition, []); |
| 11942 return true; | 12244 return true; |
| 11943 } | 12245 } |
| 11944 return false; | 12246 return false; |
| 11945 } | 12247 } |
| 11946 | 12248 |
| 11947 /** | 12249 /** |
| 11948 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. | 12250 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. |
| 11949 * @param node the assert statement to evaluate | 12251 * @param node the assert statement to evaluate |
| 11950 * @return {@code true} if and only if an error code is generated on the passe
d node | 12252 * @return `true` if and only if an error code is generated on the passed node |
| 11951 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION | 12253 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION |
| 11952 */ | 12254 */ |
| 11953 bool checkForNonBoolExpression(AssertStatement node) { | 12255 bool checkForNonBoolExpression(AssertStatement node) { |
| 11954 Expression expression = node.condition; | 12256 Expression expression = node.condition; |
| 11955 Type2 type = getStaticType(expression); | 12257 Type2 type = getStaticType(expression); |
| 11956 if (type is InterfaceType) { | 12258 if (type is InterfaceType) { |
| 11957 if (!type.isAssignableTo(_typeProvider.boolType)) { | 12259 if (!type.isAssignableTo(_typeProvider.boolType)) { |
| 11958 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); | 12260 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); |
| 11959 return true; | 12261 return true; |
| 11960 } | 12262 } |
| 11961 } else if (type is FunctionType) { | 12263 } else if (type is FunctionType) { |
| 11962 FunctionType functionType = type as FunctionType; | 12264 FunctionType functionType = type as FunctionType; |
| 11963 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_typeProvider.boolType)) { | 12265 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_typeProvider.boolType)) { |
| 11964 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); | 12266 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); |
| 11965 return true; | 12267 return true; |
| 11966 } | 12268 } |
| 11967 } | 12269 } |
| 11968 return false; | 12270 return false; |
| 11969 } | 12271 } |
| 11970 | 12272 |
| 11971 /** | 12273 /** |
| 11972 * This verifies the passed map literal either: | 12274 * This verifies the passed map literal either: |
| 11973 * <ul> | 12275 * |
| 11974 * <li>has {@code const modifier}</li> | 12276 * * has `const modifier` |
| 11975 * <li>has explicit type arguments</li> | 12277 * * has explicit type arguments |
| 11976 * <li>is not start of the statement</li> | 12278 * * is not start of the statement |
| 11977 * <ul> | 12279 * |
| 11978 * @param node the map literal to evaluate | 12280 * @param node the map literal to evaluate |
| 11979 * @return {@code true} if and only if an error code is generated on the passe
d node | 12281 * @return `true` if and only if an error code is generated on the passed node |
| 11980 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT | 12282 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT |
| 11981 */ | 12283 */ |
| 11982 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) { | 12284 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) { |
| 11983 if (node.modifier != null) { | 12285 if (node.modifier != null) { |
| 11984 return false; | 12286 return false; |
| 11985 } | 12287 } |
| 11986 if (node.typeArguments != null) { | 12288 if (node.typeArguments != null) { |
| 11987 return false; | 12289 return false; |
| 11988 } | 12290 } |
| 11989 Statement statement = node.getAncestor(ExpressionStatement); | 12291 Statement statement = node.getAncestor(ExpressionStatement); |
| 11990 if (statement == null) { | 12292 if (statement == null) { |
| 11991 return false; | 12293 return false; |
| 11992 } | 12294 } |
| 11993 if (statement.beginToken != node.beginToken) { | 12295 if (statement.beginToken != node.beginToken) { |
| 11994 return false; | 12296 return false; |
| 11995 } | 12297 } |
| 11996 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION
_STATEMENT, node, []); | 12298 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION
_STATEMENT, node, []); |
| 11997 return true; | 12299 return true; |
| 11998 } | 12300 } |
| 11999 | 12301 |
| 12000 /** | 12302 /** |
| 12001 * This verifies the passed method declaration of operator {@code \[\]=}, has
{@code void} return | 12303 * This verifies the passed method declaration of operator `\[\]=`, has `void`
return |
| 12002 * type. | 12304 * type. |
| 12003 * @param node the method declaration to evaluate | 12305 * @param node the method declaration to evaluate |
| 12004 * @return {@code true} if and only if an error code is generated on the passe
d node | 12306 * @return `true` if and only if an error code is generated on the passed node |
| 12005 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR | 12307 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR |
| 12006 */ | 12308 */ |
| 12007 bool checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { | 12309 bool checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { |
| 12008 SimpleIdentifier name = node.name; | 12310 SimpleIdentifier name = node.name; |
| 12009 if (name.name != "[]=") { | 12311 if (name.name != "[]=") { |
| 12010 return false; | 12312 return false; |
| 12011 } | 12313 } |
| 12012 TypeName typeName = node.returnType; | 12314 TypeName typeName = node.returnType; |
| 12013 if (typeName != null) { | 12315 if (typeName != null) { |
| 12014 Type2 type = typeName.type; | 12316 Type2 type = typeName.type; |
| 12015 if (type != null && !type.isVoid()) { | 12317 if (type != null && !type.isVoid()) { |
| 12016 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_OPERAT
OR, typeName, []); | 12318 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_OPERAT
OR, typeName, []); |
| 12017 } | 12319 } |
| 12018 } | 12320 } |
| 12019 return false; | 12321 return false; |
| 12020 } | 12322 } |
| 12021 | 12323 |
| 12022 /** | 12324 /** |
| 12023 * This verifies the passed setter has no return type or the {@code void} retu
rn type. | 12325 * This verifies the passed setter has no return type or the `void` return typ
e. |
| 12024 * @param typeName the type name to evaluate | 12326 * @param typeName the type name to evaluate |
| 12025 * @return {@code true} if and only if an error code is generated on the passe
d node | 12327 * @return `true` if and only if an error code is generated on the passed node |
| 12026 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER | 12328 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER |
| 12027 */ | 12329 */ |
| 12028 bool checkForNonVoidReturnTypeForSetter(TypeName typeName) { | 12330 bool checkForNonVoidReturnTypeForSetter(TypeName typeName) { |
| 12029 if (typeName != null) { | 12331 if (typeName != null) { |
| 12030 Type2 type = typeName.type; | 12332 Type2 type = typeName.type; |
| 12031 if (type != null && !type.isVoid()) { | 12333 if (type != null && !type.isVoid()) { |
| 12032 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
, typeName, []); | 12334 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
, typeName, []); |
| 12033 } | 12335 } |
| 12034 } | 12336 } |
| 12035 return false; | 12337 return false; |
| 12036 } | 12338 } |
| 12037 | 12339 |
| 12038 /** | 12340 /** |
| 12039 * This verifies the passed operator-method declaration, does not have an opti
onal parameter. | 12341 * This verifies the passed operator-method declaration, does not have an opti
onal parameter. |
| 12040 * <p> | 12342 * |
| 12041 * This method assumes that the method declaration was tested to be an operato
r declaration before | 12343 * This method assumes that the method declaration was tested to be an operato
r declaration before |
| 12042 * being called. | 12344 * being called. |
| 12043 * @param node the method declaration to evaluate | 12345 * @param node the method declaration to evaluate |
| 12044 * @return {@code true} if and only if an error code is generated on the passe
d node | 12346 * @return `true` if and only if an error code is generated on the passed node |
| 12045 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR | 12347 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR |
| 12046 */ | 12348 */ |
| 12047 bool checkForOptionalParameterInOperator(MethodDeclaration node) { | 12349 bool checkForOptionalParameterInOperator(MethodDeclaration node) { |
| 12048 FormalParameterList parameterList = node.parameters; | 12350 FormalParameterList parameterList = node.parameters; |
| 12049 if (parameterList == null) { | 12351 if (parameterList == null) { |
| 12050 return false; | 12352 return false; |
| 12051 } | 12353 } |
| 12052 bool foundError = false; | 12354 bool foundError = false; |
| 12053 NodeList<FormalParameter> formalParameters = parameterList.parameters; | 12355 NodeList<FormalParameter> formalParameters = parameterList.parameters; |
| 12054 for (FormalParameter formalParameter in formalParameters) { | 12356 for (FormalParameter formalParameter in formalParameters) { |
| 12055 if (formalParameter.kind.isOptional()) { | 12357 if (formalParameter.kind.isOptional()) { |
| 12056 _errorReporter.reportError2(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_O
PERATOR, formalParameter, []); | 12358 _errorReporter.reportError2(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_O
PERATOR, formalParameter, []); |
| 12057 foundError = true; | 12359 foundError = true; |
| 12058 } | 12360 } |
| 12059 } | 12361 } |
| 12060 return foundError; | 12362 return foundError; |
| 12061 } | 12363 } |
| 12062 | 12364 |
| 12063 /** | 12365 /** |
| 12064 * This checks for named optional parameters that begin with '_'. | 12366 * This checks for named optional parameters that begin with '_'. |
| 12065 * @param node the default formal parameter to evaluate | 12367 * @param node the default formal parameter to evaluate |
| 12066 * @return {@code true} if and only if an error code is generated on the passe
d node | 12368 * @return `true` if and only if an error code is generated on the passed node |
| 12067 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER | 12369 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER |
| 12068 */ | 12370 */ |
| 12069 bool checkForPrivateOptionalParameter(DefaultFormalParameter node) { | 12371 bool checkForPrivateOptionalParameter(DefaultFormalParameter node) { |
| 12070 sc.Token separator = node.separator; | 12372 sc.Token separator = node.separator; |
| 12071 if (separator != null && separator.lexeme == ":") { | 12373 if (separator != null && separator.lexeme == ":") { |
| 12072 NormalFormalParameter parameter = node.parameter; | 12374 NormalFormalParameter parameter = node.parameter; |
| 12073 SimpleIdentifier name = parameter.identifier; | 12375 SimpleIdentifier name = parameter.identifier; |
| 12074 if (!name.isSynthetic() && name.name.startsWith("_")) { | 12376 if (!name.isSynthetic() && name.name.startsWith("_")) { |
| 12075 _errorReporter.reportError2(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAME
TER, node, []); | 12377 _errorReporter.reportError2(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAME
TER, node, []); |
| 12076 return true; | 12378 return true; |
| 12077 } | 12379 } |
| 12078 } | 12380 } |
| 12079 return false; | 12381 return false; |
| 12080 } | 12382 } |
| 12081 | 12383 |
| 12082 /** | 12384 /** |
| 12083 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and | 12385 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and |
| 12084 * references itself directly or indirectly. | 12386 * references itself directly or indirectly. |
| 12085 * @param node the constructor declaration to evaluate | 12387 * @param node the constructor declaration to evaluate |
| 12086 * @return {@code true} if and only if an error code is generated on the passe
d node | 12388 * @return `true` if and only if an error code is generated on the passed node |
| 12087 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT | 12389 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT |
| 12088 */ | 12390 */ |
| 12089 bool checkForRecursiveConstructorRedirect(ConstructorDeclaration node) { | 12391 bool checkForRecursiveConstructorRedirect(ConstructorDeclaration node) { |
| 12090 if (node.factoryKeyword != null) { | 12392 if (node.factoryKeyword != null) { |
| 12091 return false; | 12393 return false; |
| 12092 } | 12394 } |
| 12093 for (ConstructorInitializer initializer in node.initializers) { | 12395 for (ConstructorInitializer initializer in node.initializers) { |
| 12094 if (initializer is RedirectingConstructorInvocation) { | 12396 if (initializer is RedirectingConstructorInvocation) { |
| 12095 ConstructorElement element = node.element; | 12397 ConstructorElement element = node.element; |
| 12096 if (!hasRedirectingFactoryConstructorCycle(element)) { | 12398 if (!hasRedirectingFactoryConstructorCycle(element)) { |
| 12097 return false; | 12399 return false; |
| 12098 } | 12400 } |
| 12099 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_R
EDIRECT, initializer, []); | 12401 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_R
EDIRECT, initializer, []); |
| 12100 return true; | 12402 return true; |
| 12101 } | 12403 } |
| 12102 } | 12404 } |
| 12103 return false; | 12405 return false; |
| 12104 } | 12406 } |
| 12105 | 12407 |
| 12106 /** | 12408 /** |
| 12107 * This checks if the passed constructor declaration has redirected constructo
r and references | 12409 * This checks if the passed constructor declaration has redirected constructo
r and references |
| 12108 * itself directly or indirectly. | 12410 * itself directly or indirectly. |
| 12109 * @param node the constructor declaration to evaluate | 12411 * @param node the constructor declaration to evaluate |
| 12110 * @return {@code true} if and only if an error code is generated on the passe
d node | 12412 * @return `true` if and only if an error code is generated on the passed node |
| 12111 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT | 12413 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT |
| 12112 */ | 12414 */ |
| 12113 bool checkForRecursiveFactoryRedirect(ConstructorDeclaration node) { | 12415 bool checkForRecursiveFactoryRedirect(ConstructorDeclaration node) { |
| 12114 ConstructorName redirectedConstructorNode = node.redirectedConstructor; | 12416 ConstructorName redirectedConstructorNode = node.redirectedConstructor; |
| 12115 if (redirectedConstructorNode == null) { | 12417 if (redirectedConstructorNode == null) { |
| 12116 return false; | 12418 return false; |
| 12117 } | 12419 } |
| 12118 ConstructorElement element = node.element; | 12420 ConstructorElement element = node.element; |
| 12119 if (!hasRedirectingFactoryConstructorCycle(element)) { | 12421 if (!hasRedirectingFactoryConstructorCycle(element)) { |
| 12120 return false; | 12422 return false; |
| 12121 } | 12423 } |
| 12122 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
redirectedConstructorNode, []); | 12424 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
redirectedConstructorNode, []); |
| 12123 return true; | 12425 return true; |
| 12124 } | 12426 } |
| 12125 | 12427 |
| 12126 /** | 12428 /** |
| 12127 * This checks the class declaration is not a superinterface to itself. | 12429 * This checks the class declaration is not a superinterface to itself. |
| 12128 * @param classElt the class element to test | 12430 * @param classElt the class element to test |
| 12129 * @param list a list containing the potentially cyclic implements path | 12431 * @param list a list containing the potentially cyclic implements path |
| 12130 * @return {@code true} if and only if an error code is generated on the passe
d element | 12432 * @return `true` if and only if an error code is generated on the passed elem
ent |
| 12131 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE | 12433 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE |
| 12132 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS | 12434 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS |
| 12133 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME
NTS | 12435 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME
NTS |
| 12134 */ | 12436 */ |
| 12135 bool checkForRecursiveInterfaceInheritance(ClassElement classElt, List<ClassEl
ement> list) { | 12437 bool checkForRecursiveInterfaceInheritance(ClassElement classElt, List<ClassEl
ement> list) { |
| 12136 if (classElt == null) { | 12438 if (classElt == null) { |
| 12137 return false; | 12439 return false; |
| 12138 } | 12440 } |
| 12139 InterfaceType supertype = classElt.supertype; | 12441 InterfaceType supertype = classElt.supertype; |
| 12140 list.add(classElt); | 12442 list.add(classElt); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12184 } | 12486 } |
| 12185 } | 12487 } |
| 12186 list.removeAt(list.length - 1); | 12488 list.removeAt(list.length - 1); |
| 12187 return false; | 12489 return false; |
| 12188 } | 12490 } |
| 12189 | 12491 |
| 12190 /** | 12492 /** |
| 12191 * This checks the passed constructor declaration has a valid combination of r
edirected | 12493 * This checks the passed constructor declaration has a valid combination of r
edirected |
| 12192 * constructor invocation(s), super constructor invocations and field initiali
zers. | 12494 * constructor invocation(s), super constructor invocations and field initiali
zers. |
| 12193 * @param node the constructor declaration to evaluate | 12495 * @param node the constructor declaration to evaluate |
| 12194 * @return {@code true} if and only if an error code is generated on the passe
d node | 12496 * @return `true` if and only if an error code is generated on the passed node |
| 12195 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS | 12497 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS |
| 12196 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR | 12498 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR |
| 12197 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR | 12499 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR |
| 12198 */ | 12500 */ |
| 12199 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { | 12501 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { |
| 12200 int numProblems = 0; | 12502 int numProblems = 0; |
| 12201 int numRedirections = 0; | 12503 int numRedirections = 0; |
| 12202 for (ConstructorInitializer initializer in node.initializers) { | 12504 for (ConstructorInitializer initializer in node.initializers) { |
| 12203 if (initializer is RedirectingConstructorInvocation) { | 12505 if (initializer is RedirectingConstructorInvocation) { |
| 12204 if (numRedirections > 0) { | 12506 if (numRedirections > 0) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 12220 } | 12522 } |
| 12221 } | 12523 } |
| 12222 } | 12524 } |
| 12223 return numProblems != 0; | 12525 return numProblems != 0; |
| 12224 } | 12526 } |
| 12225 | 12527 |
| 12226 /** | 12528 /** |
| 12227 * This checks if the passed constructor declaration has redirected constructo
r and references | 12529 * This checks if the passed constructor declaration has redirected constructo
r and references |
| 12228 * itself directly or indirectly. TODO(scheglov) | 12530 * itself directly or indirectly. TODO(scheglov) |
| 12229 * @param node the constructor declaration to evaluate | 12531 * @param node the constructor declaration to evaluate |
| 12230 * @return {@code true} if and only if an error code is generated on the passe
d node | 12532 * @return `true` if and only if an error code is generated on the passed node |
| 12231 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR | 12533 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR |
| 12232 */ | 12534 */ |
| 12233 bool checkForRedirectToNonConstConstructor(ConstructorDeclaration node) { | 12535 bool checkForRedirectToNonConstConstructor(ConstructorDeclaration node) { |
| 12234 ConstructorName redirectedConstructorNode = node.redirectedConstructor; | 12536 ConstructorName redirectedConstructorNode = node.redirectedConstructor; |
| 12235 if (redirectedConstructorNode == null) { | 12537 if (redirectedConstructorNode == null) { |
| 12236 return false; | 12538 return false; |
| 12237 } | 12539 } |
| 12238 ConstructorElement element = node.element; | 12540 ConstructorElement element = node.element; |
| 12239 if (element == null) { | 12541 if (element == null) { |
| 12240 return false; | 12542 return false; |
| 12241 } | 12543 } |
| 12242 if (!element.isConst()) { | 12544 if (!element.isConst()) { |
| 12243 return false; | 12545 return false; |
| 12244 } | 12546 } |
| 12245 ConstructorElement redirectedConstructor = element.redirectedConstructor; | 12547 ConstructorElement redirectedConstructor = element.redirectedConstructor; |
| 12246 if (redirectedConstructor == null) { | 12548 if (redirectedConstructor == null) { |
| 12247 return false; | 12549 return false; |
| 12248 } | 12550 } |
| 12249 if (redirectedConstructor.isConst()) { | 12551 if (redirectedConstructor.isConst()) { |
| 12250 return false; | 12552 return false; |
| 12251 } | 12553 } |
| 12252 _errorReporter.reportError2(CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONST
RUCTOR, redirectedConstructorNode, []); | 12554 _errorReporter.reportError2(CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONST
RUCTOR, redirectedConstructorNode, []); |
| 12253 return true; | 12555 return true; |
| 12254 } | 12556 } |
| 12255 | 12557 |
| 12256 /** | 12558 /** |
| 12257 * This checks if the passed identifier is banned because it is part of the va
riable declaration | 12559 * This checks if the passed identifier is banned because it is part of the va
riable declaration |
| 12258 * with the same name. | 12560 * with the same name. |
| 12259 * @param node the identifier to evaluate | 12561 * @param node the identifier to evaluate |
| 12260 * @return {@code true} if and only if an error code is generated on the passe
d node | 12562 * @return `true` if and only if an error code is generated on the passed node |
| 12261 * @see CompileTimeErrorCode#REFERENCE_TO_DECLARED_VARIABLE_IN_INITIALIZER | 12563 * @see CompileTimeErrorCode#REFERENCE_TO_DECLARED_VARIABLE_IN_INITIALIZER |
| 12262 */ | 12564 */ |
| 12263 bool checkForReferenceToDeclaredVariableInInitializer(SimpleIdentifier node) { | 12565 bool checkForReferenceToDeclaredVariableInInitializer(SimpleIdentifier node) { |
| 12264 ASTNode parent = node.parent; | 12566 ASTNode parent = node.parent; |
| 12265 if (parent is PrefixedIdentifier) { | 12567 if (parent is PrefixedIdentifier) { |
| 12266 PrefixedIdentifier prefixedIdentifier = parent as PrefixedIdentifier; | 12568 PrefixedIdentifier prefixedIdentifier = parent as PrefixedIdentifier; |
| 12267 if (identical(prefixedIdentifier.identifier, node)) { | 12569 if (identical(prefixedIdentifier.identifier, node)) { |
| 12268 return false; | 12570 return false; |
| 12269 } | 12571 } |
| 12270 } | 12572 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 12296 if (!_namesForReferenceToDeclaredVariableInInitializer.contains(name)) { | 12598 if (!_namesForReferenceToDeclaredVariableInInitializer.contains(name)) { |
| 12297 return false; | 12599 return false; |
| 12298 } | 12600 } |
| 12299 _errorReporter.reportError2(CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIA
BLE_IN_INITIALIZER, node, [name]); | 12601 _errorReporter.reportError2(CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIA
BLE_IN_INITIALIZER, node, [name]); |
| 12300 return true; | 12602 return true; |
| 12301 } | 12603 } |
| 12302 | 12604 |
| 12303 /** | 12605 /** |
| 12304 * This checks that the rethrow is inside of a catch clause. | 12606 * This checks that the rethrow is inside of a catch clause. |
| 12305 * @param node the rethrow expression to evaluate | 12607 * @param node the rethrow expression to evaluate |
| 12306 * @return {@code true} if and only if an error code is generated on the passe
d node | 12608 * @return `true` if and only if an error code is generated on the passed node |
| 12307 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH | 12609 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH |
| 12308 */ | 12610 */ |
| 12309 bool checkForRethrowOutsideCatch(RethrowExpression node) { | 12611 bool checkForRethrowOutsideCatch(RethrowExpression node) { |
| 12310 if (!_isInCatchClause) { | 12612 if (!_isInCatchClause) { |
| 12311 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no
de, []); | 12613 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no
de, []); |
| 12312 return true; | 12614 return true; |
| 12313 } | 12615 } |
| 12314 return false; | 12616 return false; |
| 12315 } | 12617 } |
| 12316 | 12618 |
| 12317 /** | 12619 /** |
| 12620 * This checks that a type mis-match between the return type and the expressed
return type by the |
| 12621 * enclosing method or function. |
| 12622 * |
| 12623 * This method is called both by [checkForAllReturnStatementErrorCodes]and [vi
sitExpressionFunctionBody]. |
| 12624 * @param returnExpression the returned expression to evaluate |
| 12625 * @param expectedReturnType the expressed return type by the enclosing method
or function |
| 12626 * @return `true` if and only if an error code is generated on the passed node |
| 12627 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE |
| 12628 */ |
| 12629 bool checkForReturnOfInvalidType(Expression returnExpression, Type2 expectedRe
turnType) { |
| 12630 Type2 staticReturnType = getStaticType(returnExpression); |
| 12631 if (expectedReturnType.isVoid()) { |
| 12632 if (staticReturnType.isVoid() || staticReturnType.isDynamic() || identical
(staticReturnType, BottomTypeImpl.instance)) { |
| 12633 return false; |
| 12634 } |
| 12635 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); |
| 12636 return true; |
| 12637 } |
| 12638 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType
); |
| 12639 Type2 propagatedReturnType = getPropagatedType(returnExpression); |
| 12640 if (_strictMode || propagatedReturnType == null) { |
| 12641 if (isStaticAssignable) { |
| 12642 return false; |
| 12643 } |
| 12644 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); |
| 12645 return true; |
| 12646 } else { |
| 12647 bool isPropagatedAssignable = propagatedReturnType.isAssignableTo(expected
ReturnType); |
| 12648 if (isStaticAssignable || isPropagatedAssignable) { |
| 12649 return false; |
| 12650 } |
| 12651 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); |
| 12652 return true; |
| 12653 } |
| 12654 } |
| 12655 |
| 12656 /** |
| 12318 * This checks that if the given "target" is the type reference then the "name
" is not the | 12657 * This checks that if the given "target" is the type reference then the "name
" is not the |
| 12319 * reference to a instance member. | 12658 * reference to a instance member. |
| 12320 * @param target the target of the name access to evaluate | 12659 * @param target the target of the name access to evaluate |
| 12321 * @param name the accessed name to evaluate | 12660 * @param name the accessed name to evaluate |
| 12322 * @return {@code true} if and only if an error code is generated on the passe
d node | 12661 * @return `true` if and only if an error code is generated on the passed node |
| 12323 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER | 12662 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER |
| 12324 */ | 12663 */ |
| 12325 bool checkForStaticAccessToInstanceMember(Expression target, SimpleIdentifier
name2) { | 12664 bool checkForStaticAccessToInstanceMember(Expression target, SimpleIdentifier
name2) { |
| 12326 Element element = name2.element; | 12665 Element element = name2.element; |
| 12327 if (element is! ExecutableElement) { | 12666 if (element is! ExecutableElement) { |
| 12328 return false; | 12667 return false; |
| 12329 } | 12668 } |
| 12330 ExecutableElement memberElement = element as ExecutableElement; | 12669 ExecutableElement memberElement = element as ExecutableElement; |
| 12331 if (memberElement.isStatic()) { | 12670 if (memberElement.isStatic()) { |
| 12332 return false; | 12671 return false; |
| 12333 } | 12672 } |
| 12334 if (!isTypeReference(target)) { | 12673 if (!isTypeReference(target)) { |
| 12335 return false; | 12674 return false; |
| 12336 } | 12675 } |
| 12337 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB
ER, name2, [name2.name]); | 12676 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB
ER, name2, [name2.name]); |
| 12338 return true; | 12677 return true; |
| 12339 } | 12678 } |
| 12340 | 12679 |
| 12341 /** | 12680 /** |
| 12342 * This checks that the type of the passed 'switch' expression is assignable t
o the type of the | 12681 * This checks that the type of the passed 'switch' expression is assignable t
o the type of the |
| 12343 * 'case' members. | 12682 * 'case' members. |
| 12344 * @param node the 'switch' statement to evaluate | 12683 * @param node the 'switch' statement to evaluate |
| 12345 * @return {@code true} if and only if an error code is generated on the passe
d node | 12684 * @return `true` if and only if an error code is generated on the passed node |
| 12346 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE | 12685 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE |
| 12347 */ | 12686 */ |
| 12348 bool checkForSwitchExpressionNotAssignable(SwitchStatement node) { | 12687 bool checkForSwitchExpressionNotAssignable(SwitchStatement node) { |
| 12349 Expression expression = node.expression; | 12688 Expression expression = node.expression; |
| 12350 Type2 expressionType = getStaticType(expression); | 12689 Type2 expressionType = getStaticType(expression); |
| 12351 if (expressionType == null) { | 12690 if (expressionType == null) { |
| 12352 return false; | 12691 return false; |
| 12353 } | 12692 } |
| 12354 NodeList<SwitchMember> members = node.members; | 12693 NodeList<SwitchMember> members = node.members; |
| 12355 for (SwitchMember switchMember in members) { | 12694 for (SwitchMember switchMember in members) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 12366 return true; | 12705 return true; |
| 12367 } | 12706 } |
| 12368 return false; | 12707 return false; |
| 12369 } | 12708 } |
| 12370 | 12709 |
| 12371 /** | 12710 /** |
| 12372 * This verifies that the type arguments in the passed instance creation expre
ssion are all within | 12711 * This verifies that the type arguments in the passed instance creation expre
ssion are all within |
| 12373 * their bounds as specified by the class element where the constructor \[that
is being invoked\] is | 12712 * their bounds as specified by the class element where the constructor \[that
is being invoked\] is |
| 12374 * declared. | 12713 * declared. |
| 12375 * @param node the instance creation expression to evaluate | 12714 * @param node the instance creation expression to evaluate |
| 12376 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th
e{@link InstanceCreationExpression}, this is the AST node that the error is atta
ched to | 12715 * @param typeName the [TypeName] of the [ConstructorName] from the[InstanceCr
eationExpression], this is the AST node that the error is attached to |
| 12377 * @param constructorElement the {@link ConstructorElement} from the instance
creation expression | 12716 * @param constructorElement the [ConstructorElement] from the instance creati
on expression |
| 12378 * @return {@code true} if and only if an error code is generated on the passe
d node | 12717 * @return `true` if and only if an error code is generated on the passed node |
| 12379 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS | 12718 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS |
| 12380 */ | 12719 */ |
| 12381 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co
nstructorElement constructorElement, TypeName typeName) { | 12720 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co
nstructorElement constructorElement, TypeName typeName) { |
| 12382 if (typeName.typeArguments != null && constructorElement != null) { | 12721 if (typeName.typeArguments != null && constructorElement != null) { |
| 12383 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; | 12722 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; |
| 12384 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme
nt.typeVariables; | 12723 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme
nt.typeVariables; |
| 12385 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt
h); | 12724 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt
h); |
| 12386 for (int i = 0; i < loopThroughIndex; i++) { | 12725 for (int i = 0; i < loopThroughIndex; i++) { |
| 12387 TypeName argTypeName = typeNameArgList[i]; | 12726 TypeName argTypeName = typeNameArgList[i]; |
| 12388 Type2 argType = argTypeName.type; | 12727 Type2 argType = argTypeName.type; |
| 12389 Type2 boundType = boundingElts[i].bound; | 12728 Type2 boundType = boundingElts[i].bound; |
| 12390 if (argType != null && boundType != null) { | 12729 if (argType != null && boundType != null) { |
| 12391 if (!argType.isSubtypeOf(boundType)) { | 12730 if (!argType.isSubtypeOf(boundType)) { |
| 12392 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_
MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].displayName]); | 12731 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_
MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].displayName]); |
| 12393 return true; | 12732 return true; |
| 12394 } | 12733 } |
| 12395 } | 12734 } |
| 12396 } | 12735 } |
| 12397 } | 12736 } |
| 12398 return false; | 12737 return false; |
| 12399 } | 12738 } |
| 12400 | 12739 |
| 12401 /** | 12740 /** |
| 12402 * This checks that if the passed generative constructor has neither an explic
it super constructor | 12741 * This checks that if the passed generative constructor has neither an explic
it super constructor |
| 12403 * invocation nor a redirecting constructor invocation, that the superclass ha
s a default | 12742 * invocation nor a redirecting constructor invocation, that the superclass ha
s a default |
| 12404 * generative constructor. | 12743 * generative constructor. |
| 12405 * @param node the constructor declaration to evaluate | 12744 * @param node the constructor declaration to evaluate |
| 12406 * @return {@code true} if and only if an error code is generated on the passe
d node | 12745 * @return `true` if and only if an error code is generated on the passed node |
| 12407 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 12746 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT |
| 12408 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR | 12747 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR |
| 12748 * @see StaticWarningCode#NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT |
| 12409 */ | 12749 */ |
| 12410 bool checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration
node) { | 12750 bool checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration
node) { |
| 12411 if (node.factoryKeyword != null) { | 12751 if (node.factoryKeyword != null) { |
| 12412 return false; | 12752 return false; |
| 12413 } | 12753 } |
| 12414 for (ConstructorInitializer constructorInitializer in node.initializers) { | 12754 for (ConstructorInitializer constructorInitializer in node.initializers) { |
| 12415 if (constructorInitializer is SuperConstructorInvocation || constructorIni
tializer is RedirectingConstructorInvocation) { | 12755 if (constructorInitializer is SuperConstructorInvocation || constructorIni
tializer is RedirectingConstructorInvocation) { |
| 12416 return false; | 12756 return false; |
| 12417 } | 12757 } |
| 12418 } | 12758 } |
| 12419 if (_enclosingClass == null) { | 12759 if (_enclosingClass == null) { |
| 12420 return false; | 12760 return false; |
| 12421 } | 12761 } |
| 12422 InterfaceType superType = _enclosingClass.supertype; | 12762 InterfaceType superType = _enclosingClass.supertype; |
| 12423 if (superType == null) { | 12763 if (superType == null) { |
| 12424 return false; | 12764 return false; |
| 12425 } | 12765 } |
| 12426 ClassElement superElement = superType.element; | 12766 ClassElement superElement = superType.element; |
| 12427 ConstructorElement superDefaultConstructor = superElement.unnamedConstructor
; | 12767 ConstructorElement superUnnamedConstructor = superElement.unnamedConstructor
; |
| 12428 if (superDefaultConstructor != null) { | 12768 if (superUnnamedConstructor != null) { |
| 12429 if (superDefaultConstructor.isFactory()) { | 12769 if (superUnnamedConstructor.isFactory()) { |
| 12430 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC
TOR, node.returnType, [superDefaultConstructor]); | 12770 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC
TOR, node.returnType, [superUnnamedConstructor]); |
| 12431 return true; | 12771 return true; |
| 12432 } | 12772 } |
| 12773 if (!superUnnamedConstructor.isDefaultConstructor()) { |
| 12774 int offset; |
| 12775 int length; |
| 12776 { |
| 12777 Identifier returnType = node.returnType; |
| 12778 SimpleIdentifier name = node.name; |
| 12779 offset = returnType.offset; |
| 12780 length = (name != null ? name.end : returnType.end) - offset; |
| 12781 } |
| 12782 _errorReporter.reportError3(StaticWarningCode.NO_DEFAULT_SUPER_CONSTRUCT
OR_EXPLICIT, offset, length, [superType.displayName]); |
| 12783 } |
| 12433 return false; | 12784 return false; |
| 12434 } | 12785 } |
| 12435 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN
ITIALIZER_DEFAULT, node.returnType, [superElement.name]); | 12786 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN
ITIALIZER_DEFAULT, node.returnType, [superElement.name]); |
| 12436 return true; | 12787 return true; |
| 12437 } | 12788 } |
| 12438 | 12789 |
| 12439 /** | 12790 /** |
| 12440 * This verifies the passed operator-method declaration, has correct number of
parameters. | 12791 * This verifies the passed operator-method declaration, has correct number of
parameters. |
| 12441 * <p> | 12792 * |
| 12442 * This method assumes that the method declaration was tested to be an operato
r declaration before | 12793 * This method assumes that the method declaration was tested to be an operato
r declaration before |
| 12443 * being called. | 12794 * being called. |
| 12444 * @param node the method declaration to evaluate | 12795 * @param node the method declaration to evaluate |
| 12445 * @return {@code true} if and only if an error code is generated on the passe
d node | 12796 * @return `true` if and only if an error code is generated on the passed node |
| 12446 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR | 12797 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR |
| 12447 */ | 12798 */ |
| 12448 bool checkForWrongNumberOfParametersForOperator(MethodDeclaration node) { | 12799 bool checkForWrongNumberOfParametersForOperator(MethodDeclaration node) { |
| 12449 FormalParameterList parameterList = node.parameters; | 12800 FormalParameterList parameterList = node.parameters; |
| 12450 if (parameterList == null) { | 12801 if (parameterList == null) { |
| 12451 return false; | 12802 return false; |
| 12452 } | 12803 } |
| 12453 int numParameters = parameterList.parameters.length; | 12804 int numParameters = parameterList.parameters.length; |
| 12454 SimpleIdentifier nameNode = node.name; | 12805 SimpleIdentifier nameNode = node.name; |
| 12455 if (nameNode == null) { | 12806 if (nameNode == null) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 12470 } | 12821 } |
| 12471 if ("-" == name && numParameters > 1) { | 12822 if ("-" == name && numParameters > 1) { |
| 12472 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_OPERATOR_MINUS, nameNode, [numParameters]); | 12823 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_OPERATOR_MINUS, nameNode, [numParameters]); |
| 12473 return true; | 12824 return true; |
| 12474 } | 12825 } |
| 12475 return false; | 12826 return false; |
| 12476 } | 12827 } |
| 12477 | 12828 |
| 12478 /** | 12829 /** |
| 12479 * This verifies if the passed setter parameter list have only one parameter. | 12830 * This verifies if the passed setter parameter list have only one parameter. |
| 12480 * <p> | 12831 * |
| 12481 * This method assumes that the method declaration was tested to be a setter b
efore being called. | 12832 * This method assumes that the method declaration was tested to be a setter b
efore being called. |
| 12482 * @param setterName the name of the setter to report problems on | 12833 * @param setterName the name of the setter to report problems on |
| 12483 * @param parameterList the parameter list to evaluate | 12834 * @param parameterList the parameter list to evaluate |
| 12484 * @return {@code true} if and only if an error code is generated on the passe
d node | 12835 * @return `true` if and only if an error code is generated on the passed node |
| 12485 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER | 12836 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER |
| 12486 */ | 12837 */ |
| 12487 bool checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, For
malParameterList parameterList) { | 12838 bool checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, For
malParameterList parameterList) { |
| 12488 if (setterName == null) { | 12839 if (setterName == null) { |
| 12489 return false; | 12840 return false; |
| 12490 } | 12841 } |
| 12491 if (parameterList == null) { | 12842 if (parameterList == null) { |
| 12492 return false; | 12843 return false; |
| 12493 } | 12844 } |
| 12494 int numberOfParameters = parameterList.parameters.length; | 12845 int numberOfParameters = parameterList.parameters.length; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12554 */ | 12905 */ |
| 12555 Type2 getStaticType(Expression expression) { | 12906 Type2 getStaticType(Expression expression) { |
| 12556 Type2 type = expression.staticType; | 12907 Type2 type = expression.staticType; |
| 12557 if (type == null) { | 12908 if (type == null) { |
| 12558 return _dynamicType; | 12909 return _dynamicType; |
| 12559 } | 12910 } |
| 12560 return type; | 12911 return type; |
| 12561 } | 12912 } |
| 12562 | 12913 |
| 12563 /** | 12914 /** |
| 12564 * Return the variable element represented by the given expression, or {@code
null} if there is no | 12915 * Return the variable element represented by the given expression, or `null`
if there is no |
| 12565 * such element. | 12916 * such element. |
| 12566 * @param expression the expression whose element is to be returned | 12917 * @param expression the expression whose element is to be returned |
| 12567 * @return the variable element represented by the expression | 12918 * @return the variable element represented by the expression |
| 12568 */ | 12919 */ |
| 12569 VariableElement getVariableElement(Expression expression) { | 12920 VariableElement getVariableElement(Expression expression) { |
| 12570 if (expression is Identifier) { | 12921 if (expression is Identifier) { |
| 12571 Element element = ((expression as Identifier)).element; | 12922 Element element = ((expression as Identifier)).element; |
| 12572 if (element is VariableElement) { | 12923 if (element is VariableElement) { |
| 12573 return element as VariableElement; | 12924 return element as VariableElement; |
| 12574 } | 12925 } |
| 12575 } | 12926 } |
| 12576 return null; | 12927 return null; |
| 12577 } | 12928 } |
| 12578 | 12929 |
| 12579 /** | 12930 /** |
| 12580 * @return {@code true} if the given constructor redirects to itself, directly
or indirectly | 12931 * @return `true` if the given constructor redirects to itself, directly or in
directly |
| 12581 */ | 12932 */ |
| 12582 bool hasRedirectingFactoryConstructorCycle(ConstructorElement element) { | 12933 bool hasRedirectingFactoryConstructorCycle(ConstructorElement element) { |
| 12583 Set<ConstructorElement> constructors = new Set<ConstructorElement>(); | 12934 Set<ConstructorElement> constructors = new Set<ConstructorElement>(); |
| 12584 ConstructorElement current = element; | 12935 ConstructorElement current = element; |
| 12585 while (current != null) { | 12936 while (current != null) { |
| 12586 if (constructors.contains(current)) { | 12937 if (constructors.contains(current)) { |
| 12587 return identical(current, element); | 12938 return identical(current, element); |
| 12588 } | 12939 } |
| 12589 javaSetAdd(constructors, current); | 12940 javaSetAdd(constructors, current); |
| 12590 current = current.redirectedConstructor; | 12941 current = current.redirectedConstructor; |
| 12591 if (current is ConstructorMember) { | 12942 if (current is ConstructorMember) { |
| 12592 current = ((current as ConstructorMember)).baseElement; | 12943 current = ((current as ConstructorMember)).baseElement; |
| 12593 } | 12944 } |
| 12594 } | 12945 } |
| 12595 return false; | 12946 return false; |
| 12596 } | 12947 } |
| 12597 | 12948 |
| 12598 /** | 12949 /** |
| 12599 * @param node the 'this' expression to analyze | 12950 * @param node the 'this' expression to analyze |
| 12600 * @return {@code true} if the given 'this' expression is in the valid context | 12951 * @return `true` if the given 'this' expression is in the valid context |
| 12601 */ | 12952 */ |
| 12602 bool isThisInValidContext(ThisExpression node) { | 12953 bool isThisInValidContext(ThisExpression node) { |
| 12603 for (ASTNode n = node; n != null; n = n.parent) { | 12954 for (ASTNode n = node; n != null; n = n.parent) { |
| 12604 if (n is CompilationUnit) { | 12955 if (n is CompilationUnit) { |
| 12605 return false; | 12956 return false; |
| 12606 } | 12957 } |
| 12607 if (n is ConstructorDeclaration) { | 12958 if (n is ConstructorDeclaration) { |
| 12608 ConstructorDeclaration constructor = n as ConstructorDeclaration; | 12959 ConstructorDeclaration constructor = n as ConstructorDeclaration; |
| 12609 return constructor.factoryKeyword == null; | 12960 return constructor.factoryKeyword == null; |
| 12610 } | 12961 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 12637 | 12988 |
| 12638 /// The position in the enum declaration. | 12989 /// The position in the enum declaration. |
| 12639 final int ordinal; | 12990 final int ordinal; |
| 12640 INIT_STATE(this.name, this.ordinal) { | 12991 INIT_STATE(this.name, this.ordinal) { |
| 12641 } | 12992 } |
| 12642 int compareTo(INIT_STATE other) => ordinal - other.ordinal; | 12993 int compareTo(INIT_STATE other) => ordinal - other.ordinal; |
| 12643 int get hashCode => ordinal; | 12994 int get hashCode => ordinal; |
| 12644 String toString() => name; | 12995 String toString() => name; |
| 12645 } | 12996 } |
| 12646 /** | 12997 /** |
| 12647 * Instances of the class {@code PubVerifier} traverse an AST structure looking
for deviations from | 12998 * Instances of the class `PubVerifier` traverse an AST structure looking for de
viations from |
| 12648 * pub best practices. | 12999 * pub best practices. |
| 12649 */ | 13000 */ |
| 12650 class PubVerifier extends RecursiveASTVisitor<Object> { | 13001 class PubVerifier extends RecursiveASTVisitor<Object> { |
| 12651 static String _PUBSPEC_YAML = "pubspec.yaml"; | 13002 static String _PUBSPEC_YAML = "pubspec.yaml"; |
| 12652 | 13003 |
| 12653 /** | 13004 /** |
| 12654 * The analysis context containing the sources to be analyzed | 13005 * The analysis context containing the sources to be analyzed |
| 12655 */ | 13006 */ |
| 12656 AnalysisContext _context; | 13007 AnalysisContext _context; |
| 12657 | 13008 |
| 12658 /** | 13009 /** |
| 12659 * The error reporter by which errors will be reported. | 13010 * The error reporter by which errors will be reported. |
| 12660 */ | 13011 */ |
| 12661 ErrorReporter _errorReporter; | 13012 ErrorReporter _errorReporter; |
| 12662 PubVerifier(AnalysisContext context, ErrorReporter errorReporter) { | 13013 PubVerifier(AnalysisContext context, ErrorReporter errorReporter) { |
| 12663 this._context = context; | 13014 this._context = context; |
| 12664 this._errorReporter = errorReporter; | 13015 this._errorReporter = errorReporter; |
| 12665 } | 13016 } |
| 12666 Object visitImportDirective(ImportDirective directive) { | 13017 Object visitImportDirective(ImportDirective directive) { |
| 12667 return null; | 13018 return null; |
| 12668 } | 13019 } |
| 12669 | 13020 |
| 12670 /** | 13021 /** |
| 12671 * This verifies that the passed file import directive is not contained in a s
ource inside a | 13022 * This verifies that the passed file import directive is not contained in a s
ource inside a |
| 12672 * package "lib" directory hierarchy referencing a source outside that package
"lib" directory | 13023 * package "lib" directory hierarchy referencing a source outside that package
"lib" directory |
| 12673 * hierarchy. | 13024 * hierarchy. |
| 12674 * @param uriLiteral the import URL (not {@code null}) | 13025 * @param uriLiteral the import URL (not `null`) |
| 12675 * @param path the file path being verified (not {@code null}) | 13026 * @param path the file path being verified (not `null`) |
| 12676 * @return {@code true} if and only if an error code is generated on the passe
d node | 13027 * @return `true` if and only if an error code is generated on the passed node |
| 12677 * @see PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE | 13028 * @see PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE |
| 12678 */ | 13029 */ |
| 12679 bool checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral
, String path) { | 13030 bool checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral
, String path) { |
| 12680 Source source = getSource(uriLiteral); | 13031 Source source = getSource(uriLiteral); |
| 12681 String fullName = getSourceFullName(source); | 13032 String fullName = getSourceFullName(source); |
| 12682 if (fullName != null) { | 13033 if (fullName != null) { |
| 12683 int pathIndex = 0; | 13034 int pathIndex = 0; |
| 12684 int fullNameIndex = fullName.length; | 13035 int fullNameIndex = fullName.length; |
| 12685 while (pathIndex < path.length && JavaString.startsWithBefore(path, "../",
pathIndex)) { | 13036 while (pathIndex < path.length && JavaString.startsWithBefore(path, "../",
pathIndex)) { |
| 12686 fullNameIndex = fullName.lastIndexOf('/', fullNameIndex); | 13037 fullNameIndex = fullName.lastIndexOf('/', fullNameIndex); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 12698 pathIndex += 3; | 13049 pathIndex += 3; |
| 12699 } | 13050 } |
| 12700 } | 13051 } |
| 12701 return false; | 13052 return false; |
| 12702 } | 13053 } |
| 12703 | 13054 |
| 12704 /** | 13055 /** |
| 12705 * This verifies that the passed file import directive is not contained in a s
ource outside a | 13056 * This verifies that the passed file import directive is not contained in a s
ource outside a |
| 12706 * package "lib" directory hierarchy referencing a source inside that package
"lib" directory | 13057 * package "lib" directory hierarchy referencing a source inside that package
"lib" directory |
| 12707 * hierarchy. | 13058 * hierarchy. |
| 12708 * @param uriLiteral the import URL (not {@code null}) | 13059 * @param uriLiteral the import URL (not `null`) |
| 12709 * @param path the file path being verified (not {@code null}) | 13060 * @param path the file path being verified (not `null`) |
| 12710 * @return {@code true} if and only if an error code is generated on the passe
d node | 13061 * @return `true` if and only if an error code is generated on the passed node |
| 12711 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE | 13062 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE |
| 12712 */ | 13063 */ |
| 12713 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral
, String path) { | 13064 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral
, String path) { |
| 12714 if (path.startsWith("lib/")) { | 13065 if (path.startsWith("lib/")) { |
| 12715 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, 0)
) { | 13066 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, 0)
) { |
| 12716 return true; | 13067 return true; |
| 12717 } | 13068 } |
| 12718 } | 13069 } |
| 12719 int pathIndex = path.indexOf("/lib/"); | 13070 int pathIndex = path.indexOf("/lib/"); |
| 12720 while (pathIndex != -1) { | 13071 while (pathIndex != -1) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 12737 if (!fullName.contains("/lib/")) { | 13088 if (!fullName.contains("/lib/")) { |
| 12738 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE
FERENCES_FILE_INSIDE, uriLiteral, []); | 13089 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE
FERENCES_FILE_INSIDE, uriLiteral, []); |
| 12739 return true; | 13090 return true; |
| 12740 } | 13091 } |
| 12741 } | 13092 } |
| 12742 return false; | 13093 return false; |
| 12743 } | 13094 } |
| 12744 | 13095 |
| 12745 /** | 13096 /** |
| 12746 * This verifies that the passed package import directive does not contain "..
" | 13097 * This verifies that the passed package import directive does not contain "..
" |
| 12747 * @param uriLiteral the import URL (not {@code null}) | 13098 * @param uriLiteral the import URL (not `null`) |
| 12748 * @param path the path to be validated (not {@code null}) | 13099 * @param path the path to be validated (not `null`) |
| 12749 * @return {@code true} if and only if an error code is generated on the passe
d node | 13100 * @return `true` if and only if an error code is generated on the passed node |
| 12750 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT | 13101 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT |
| 12751 */ | 13102 */ |
| 12752 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path
) { | 13103 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path
) { |
| 12753 if (path.startsWith("../") || path.contains("/../")) { | 13104 if (path.startsWith("../") || path.contains("/../")) { |
| 12754 _errorReporter.reportError2(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_
DOT, uriLiteral, []); | 13105 _errorReporter.reportError2(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_
DOT, uriLiteral, []); |
| 12755 return true; | 13106 return true; |
| 12756 } | 13107 } |
| 12757 return false; | 13108 return false; |
| 12758 } | 13109 } |
| 12759 | 13110 |
| 12760 /** | 13111 /** |
| 12761 * Answer the source associated with the compilation unit containing the given
AST node. | 13112 * Answer the source associated with the compilation unit containing the given
AST node. |
| 12762 * @param node the node (not {@code null}) | 13113 * @param node the node (not `null`) |
| 12763 * @return the source or {@code null} if it could not be determined | 13114 * @return the source or `null` if it could not be determined |
| 12764 */ | 13115 */ |
| 12765 Source getSource(ASTNode node) { | 13116 Source getSource(ASTNode node) { |
| 12766 Source source = null; | 13117 Source source = null; |
| 12767 CompilationUnit unit = node.getAncestor(CompilationUnit); | 13118 CompilationUnit unit = node.getAncestor(CompilationUnit); |
| 12768 if (unit != null) { | 13119 if (unit != null) { |
| 12769 CompilationUnitElement element = unit.element; | 13120 CompilationUnitElement element = unit.element; |
| 12770 if (element != null) { | 13121 if (element != null) { |
| 12771 source = element.source; | 13122 source = element.source; |
| 12772 } | 13123 } |
| 12773 } | 13124 } |
| 12774 return source; | 13125 return source; |
| 12775 } | 13126 } |
| 12776 | 13127 |
| 12777 /** | 13128 /** |
| 12778 * Answer the full name of the given source. The returned value will have all{
@link File#separatorChar} replace by '/'. | 13129 * Answer the full name of the given source. The returned value will have all[
File#separatorChar] replace by '/'. |
| 12779 * @param source the source | 13130 * @param source the source |
| 12780 * @return the full name or {@code null} if it could not be determined | 13131 * @return the full name or `null` if it could not be determined |
| 12781 */ | 13132 */ |
| 12782 String getSourceFullName(Source source) { | 13133 String getSourceFullName(Source source) { |
| 12783 if (source != null) { | 13134 if (source != null) { |
| 12784 String fullName = source.fullName; | 13135 String fullName = source.fullName; |
| 12785 if (fullName != null) { | 13136 if (fullName != null) { |
| 12786 return fullName.replaceAll(r'\', '/'); | 13137 return fullName.replaceAll(r'\', '/'); |
| 12787 } | 13138 } |
| 12788 } | 13139 } |
| 12789 return null; | 13140 return null; |
| 12790 } | 13141 } |
| 12791 } | 13142 } |
| 12792 /** | 13143 /** |
| 12793 * The enumeration {@code ResolverErrorCode} defines the error codes used for er
rors detected by the | 13144 * The enumeration `ResolverErrorCode` defines the error codes used for errors d
etected by the |
| 12794 * resolver. The convention for this class is for the name of the error code to
indicate the problem | 13145 * resolver. The convention for this class is for the name of the error code to
indicate the problem |
| 12795 * that caused the error to be generated and for the error message to explain wh
at is wrong and, | 13146 * that caused the error to be generated and for the error message to explain wh
at is wrong and, |
| 12796 * when appropriate, how the problem can be corrected. | 13147 * when appropriate, how the problem can be corrected. |
| 12797 * @coverage dart.engine.resolver | 13148 * @coverage dart.engine.resolver |
| 12798 */ | 13149 */ |
| 12799 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode { | 13150 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode { |
| 12800 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro
rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la
bel resolves to case or default statement"); | 13151 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro
rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la
bel resolves to case or default statement"); |
| 12801 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod
e('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label
resolves to switch, must be loop or switch member"); | 13152 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod
e('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label
resolves to switch, must be loop or switch member"); |
| 12802 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol
verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TIME_ER
ROR, "Libraries that have parts must have a library directive"); | 13153 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol
verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TIME_ER
ROR, "Libraries that have parts must have a library directive"); |
| 12803 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART]; | 13154 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 12827 this._type = type; | 13178 this._type = type; |
| 12828 this._message = message; | 13179 this._message = message; |
| 12829 } | 13180 } |
| 12830 ErrorSeverity get errorSeverity => _type.severity; | 13181 ErrorSeverity get errorSeverity => _type.severity; |
| 12831 String get message => _message; | 13182 String get message => _message; |
| 12832 ErrorType get type => _type; | 13183 ErrorType get type => _type; |
| 12833 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; | 13184 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; |
| 12834 int get hashCode => ordinal; | 13185 int get hashCode => ordinal; |
| 12835 String toString() => name; | 13186 String toString() => name; |
| 12836 } | 13187 } |
| OLD | NEW |