| 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_general.dart'; |
| 11 import 'utilities_dart.dart'; | 12 import 'utilities_dart.dart'; |
| 12 import 'ast.dart'; | 13 import 'ast.dart'; |
| 13 import 'parser.dart' show Parser, ParserErrorCode; | 14 import 'parser.dart' show Parser, ParserErrorCode; |
| 14 import 'sdk.dart' show DartSdk, SdkLibrary; | 15 import 'sdk.dart' show DartSdk, SdkLibrary; |
| 15 import 'element.dart'; | 16 import 'element.dart'; |
| 16 import 'html.dart' as ht; | 17 import 'html.dart' as ht; |
| 17 import 'engine.dart'; | 18 import 'engine.dart'; |
| 18 import 'constant.dart'; | 19 import 'constant.dart'; |
| 19 /** | 20 /** |
| 20 * Instances of the class `CompilationUnitBuilder` build an element model for a
single | 21 * Instances of the class `CompilationUnitBuilder` build an element model for a
single |
| 21 * compilation unit. | 22 * compilation unit. |
| 22 * | 23 * |
| 23 * @coverage dart.engine.resolver | 24 * @coverage dart.engine.resolver |
| 24 */ | 25 */ |
| 25 class CompilationUnitBuilder { | 26 class CompilationUnitBuilder { |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Build the compilation unit element for the given source. | 29 * Build the compilation unit element for the given source. |
| 29 * | 30 * |
| 30 * @param source the source describing the compilation unit | 31 * @param source the source describing the compilation unit |
| 31 * @param unit the AST structure representing the compilation unit | 32 * @param unit the AST structure representing the compilation unit |
| 32 * @return the compilation unit element that was built | 33 * @return the compilation unit element that was built |
| 33 * @throws AnalysisException if the analysis could not be performed | 34 * @throws AnalysisException if the analysis could not be performed |
| 34 */ | 35 */ |
| 35 CompilationUnitElementImpl buildCompilationUnit(Source source2, CompilationUni
t unit) { | 36 CompilationUnitElementImpl buildCompilationUnit(Source source2, CompilationUni
t unit) { |
| 37 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st
art(); |
| 36 if (unit == null) { | 38 if (unit == null) { |
| 37 return null; | 39 return null; |
| 38 } | 40 } |
| 39 ElementHolder holder = new ElementHolder(); | 41 ElementHolder holder = new ElementHolder(); |
| 40 ElementBuilder builder = new ElementBuilder(holder); | 42 ElementBuilder builder = new ElementBuilder(holder); |
| 41 unit.accept(builder); | 43 unit.accept(builder); |
| 42 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source2.
shortName); | 44 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source2.
shortName); |
| 43 element.accessors = holder.accessors; | 45 element.accessors = holder.accessors; |
| 44 element.functions = holder.functions; | 46 element.functions = holder.functions; |
| 45 element.source = source2; | 47 element.source = source2; |
| 46 element.typeAliases = holder.typeAliases; | 48 element.typeAliases = holder.typeAliases; |
| 47 element.types = holder.types; | 49 element.types = holder.types; |
| 48 element.topLevelVariables = holder.topLevelVariables; | 50 element.topLevelVariables = holder.topLevelVariables; |
| 49 unit.element = element; | 51 unit.element = element; |
| 52 timeCounter.stop(); |
| 50 return element; | 53 return element; |
| 51 } | 54 } |
| 52 } | 55 } |
| 53 /** | 56 /** |
| 54 * Instances of the class `ElementBuilder` traverse an AST structure and build t
he element | 57 * Instances of the class `ElementBuilder` traverse an AST structure and build t
he element |
| 55 * model representing the AST structure. | 58 * model representing the AST structure. |
| 56 * | 59 * |
| 57 * @coverage dart.engine.resolver | 60 * @coverage dart.engine.resolver |
| 58 */ | 61 */ |
| 59 class ElementBuilder extends RecursiveASTVisitor<Object> { | 62 class ElementBuilder extends RecursiveASTVisitor<Object> { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 121 } |
| 119 return super.visitCatchClause(node); | 122 return super.visitCatchClause(node); |
| 120 } | 123 } |
| 121 Object visitClassDeclaration(ClassDeclaration node) { | 124 Object visitClassDeclaration(ClassDeclaration node) { |
| 122 ElementHolder holder = new ElementHolder(); | 125 ElementHolder holder = new ElementHolder(); |
| 123 _isValidMixin = true; | 126 _isValidMixin = true; |
| 124 _functionTypesToFix = new List<FunctionTypeImpl>(); | 127 _functionTypesToFix = new List<FunctionTypeImpl>(); |
| 125 visitChildren(holder, node); | 128 visitChildren(holder, node); |
| 126 SimpleIdentifier className = node.name; | 129 SimpleIdentifier className = node.name; |
| 127 ClassElementImpl element = new ClassElementImpl(className); | 130 ClassElementImpl element = new ClassElementImpl(className); |
| 128 List<TypeVariableElement> typeVariables = holder.typeVariables; | 131 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 129 List<Type2> typeArguments = createTypeVariableTypes(typeVariables); | 132 List<Type2> typeArguments = createTypeParameterTypes(typeParameters); |
| 130 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); | 133 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); |
| 131 interfaceType.typeArguments = typeArguments; | 134 interfaceType.typeArguments = typeArguments; |
| 132 element.type = interfaceType; | 135 element.type = interfaceType; |
| 133 List<ConstructorElement> constructors = holder.constructors; | 136 List<ConstructorElement> constructors = holder.constructors; |
| 134 if (constructors.length == 0) { | 137 if (constructors.length == 0) { |
| 135 constructors = createDefaultConstructors(interfaceType); | 138 constructors = createDefaultConstructors(interfaceType); |
| 136 } | 139 } |
| 137 element.abstract = node.abstractKeyword != null; | 140 element.abstract = node.abstractKeyword != null; |
| 138 element.accessors = holder.accessors; | 141 element.accessors = holder.accessors; |
| 139 element.constructors = constructors; | 142 element.constructors = constructors; |
| 140 element.fields = holder.fields; | 143 element.fields = holder.fields; |
| 141 element.methods = holder.methods; | 144 element.methods = holder.methods; |
| 142 element.typeVariables = typeVariables; | 145 element.typeParameters = typeParameters; |
| 143 element.validMixin = _isValidMixin; | 146 element.validMixin = _isValidMixin; |
| 144 for (FunctionTypeImpl functionType in _functionTypesToFix) { | 147 for (FunctionTypeImpl functionType in _functionTypesToFix) { |
| 145 functionType.typeArguments = typeArguments; | 148 functionType.typeArguments = typeArguments; |
| 146 } | 149 } |
| 147 _functionTypesToFix = null; | 150 _functionTypesToFix = null; |
| 148 _currentHolder.addType(element); | 151 _currentHolder.addType(element); |
| 149 className.staticElement = element; | 152 className.staticElement = element; |
| 150 holder.validate(); | 153 holder.validate(); |
| 151 return null; | 154 return null; |
| 152 } | 155 } |
| 153 Object visitClassTypeAlias(ClassTypeAlias node) { | 156 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 154 ElementHolder holder = new ElementHolder(); | 157 ElementHolder holder = new ElementHolder(); |
| 155 _functionTypesToFix = new List<FunctionTypeImpl>(); | 158 _functionTypesToFix = new List<FunctionTypeImpl>(); |
| 156 visitChildren(holder, node); | 159 visitChildren(holder, node); |
| 157 SimpleIdentifier className = node.name; | 160 SimpleIdentifier className = node.name; |
| 158 ClassElementImpl element = new ClassElementImpl(className); | 161 ClassElementImpl element = new ClassElementImpl(className); |
| 159 element.abstract = node.abstractKeyword != null; | 162 element.abstract = node.abstractKeyword != null; |
| 160 element.typedef = true; | 163 element.typedef = true; |
| 161 List<TypeVariableElement> typeVariables = holder.typeVariables; | 164 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 162 element.typeVariables = typeVariables; | 165 element.typeParameters = typeParameters; |
| 163 List<Type2> typeArguments = createTypeVariableTypes(typeVariables); | 166 List<Type2> typeArguments = createTypeParameterTypes(typeParameters); |
| 164 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); | 167 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); |
| 165 interfaceType.typeArguments = typeArguments; | 168 interfaceType.typeArguments = typeArguments; |
| 166 element.type = interfaceType; | 169 element.type = interfaceType; |
| 167 element.constructors = createDefaultConstructors(interfaceType); | 170 element.constructors = createDefaultConstructors(interfaceType); |
| 168 for (FunctionTypeImpl functionType in _functionTypesToFix) { | 171 for (FunctionTypeImpl functionType in _functionTypesToFix) { |
| 169 functionType.typeArguments = typeArguments; | 172 functionType.typeArguments = typeArguments; |
| 170 } | 173 } |
| 171 _functionTypesToFix = null; | 174 _functionTypesToFix = null; |
| 172 _currentHolder.addType(element); | 175 _currentHolder.addType(element); |
| 173 className.staticElement = element; | 176 className.staticElement = element; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 parameter = new DefaultParameterElementImpl(parameterName); | 240 parameter = new DefaultParameterElementImpl(parameterName); |
| 238 } | 241 } |
| 239 parameter.const3 = node.isConst; | 242 parameter.const3 = node.isConst; |
| 240 parameter.final2 = node.isFinal; | 243 parameter.final2 = node.isFinal; |
| 241 parameter.initializer = initializer; | 244 parameter.initializer = initializer; |
| 242 parameter.parameterKind = node.kind; | 245 parameter.parameterKind = node.kind; |
| 243 Expression defaultValue = node.defaultValue; | 246 Expression defaultValue = node.defaultValue; |
| 244 if (defaultValue != null) { | 247 if (defaultValue != null) { |
| 245 parameter.setDefaultValueRange(defaultValue.offset, defaultValue.length); | 248 parameter.setDefaultValueRange(defaultValue.offset, defaultValue.length); |
| 246 } | 249 } |
| 247 FunctionBody body = getFunctionBody(node); | 250 setParameterVisibleRange(node, parameter); |
| 248 if (body != null) { | |
| 249 parameter.setVisibleRange(body.offset, body.length); | |
| 250 } | |
| 251 _currentHolder.addParameter(parameter); | 251 _currentHolder.addParameter(parameter); |
| 252 parameterName.staticElement = parameter; | 252 parameterName.staticElement = parameter; |
| 253 node.parameter.accept(this); | 253 node.parameter.accept(this); |
| 254 holder.validate(); | 254 holder.validate(); |
| 255 return null; | 255 return null; |
| 256 } | 256 } |
| 257 Object visitFieldDeclaration(FieldDeclaration node) { | 257 Object visitFieldDeclaration(FieldDeclaration node) { |
| 258 bool wasInField = _inFieldContext; | 258 bool wasInField = _inFieldContext; |
| 259 _inFieldContext = true; | 259 _inFieldContext = true; |
| 260 try { | 260 try { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 309 } |
| 310 _currentHolder.addFunction(element); | 310 _currentHolder.addFunction(element); |
| 311 expression.element = element; | 311 expression.element = element; |
| 312 functionName.staticElement = element; | 312 functionName.staticElement = element; |
| 313 } else { | 313 } else { |
| 314 SimpleIdentifier propertyNameNode = node.name; | 314 SimpleIdentifier propertyNameNode = node.name; |
| 315 if (propertyNameNode == null) { | 315 if (propertyNameNode == null) { |
| 316 return null; | 316 return null; |
| 317 } | 317 } |
| 318 String propertyName = propertyNameNode.name; | 318 String propertyName = propertyNameNode.name; |
| 319 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldE
lementImpl; | 319 TopLevelVariableElementImpl variable = _currentHolder.getTopLevelVariabl
e(propertyName) as TopLevelVariableElementImpl; |
| 320 if (field == null) { | 320 if (variable == null) { |
| 321 field = new FieldElementImpl.con2(node.name.name); | 321 variable = new TopLevelVariableElementImpl.con2(node.name.name); |
| 322 field.final2 = true; | 322 variable.final2 = true; |
| 323 field.static = true; | 323 variable.synthetic = true; |
| 324 _currentHolder.addField(field); | 324 _currentHolder.addTopLevelVariable(variable); |
| 325 } | 325 } |
| 326 if (matches(property, sc.Keyword.GET)) { | 326 if (matches(property, sc.Keyword.GET)) { |
| 327 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.c
on1(propertyNameNode); | 327 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.c
on1(propertyNameNode); |
| 328 getter.functions = holder.functions; | 328 getter.functions = holder.functions; |
| 329 getter.labels = holder.labels; | 329 getter.labels = holder.labels; |
| 330 getter.localVariables = holder.localVariables; | 330 getter.localVariables = holder.localVariables; |
| 331 getter.variable = field; | 331 getter.variable = variable; |
| 332 getter.getter = true; | 332 getter.getter = true; |
| 333 getter.static = true; | 333 getter.static = true; |
| 334 field.getter = getter; | 334 variable.getter = getter; |
| 335 _currentHolder.addAccessor(getter); | 335 _currentHolder.addAccessor(getter); |
| 336 expression.element = getter; |
| 336 propertyNameNode.staticElement = getter; | 337 propertyNameNode.staticElement = getter; |
| 337 } else { | 338 } else { |
| 338 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.c
on1(propertyNameNode); | 339 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.c
on1(propertyNameNode); |
| 339 setter.functions = holder.functions; | 340 setter.functions = holder.functions; |
| 340 setter.labels = holder.labels; | 341 setter.labels = holder.labels; |
| 341 setter.localVariables = holder.localVariables; | 342 setter.localVariables = holder.localVariables; |
| 342 setter.parameters = holder.parameters; | 343 setter.parameters = holder.parameters; |
| 343 setter.variable = field; | 344 setter.variable = variable; |
| 344 setter.setter = true; | 345 setter.setter = true; |
| 345 setter.static = true; | 346 setter.static = true; |
| 346 field.setter = setter; | 347 variable.setter = setter; |
| 347 field.final2 = false; | 348 variable.final2 = false; |
| 348 _currentHolder.addAccessor(setter); | 349 _currentHolder.addAccessor(setter); |
| 350 expression.element = setter; |
| 349 propertyNameNode.staticElement = setter; | 351 propertyNameNode.staticElement = setter; |
| 350 } | 352 } |
| 351 } | 353 } |
| 352 holder.validate(); | 354 holder.validate(); |
| 353 } | 355 } |
| 354 return null; | 356 return null; |
| 355 } | 357 } |
| 356 Object visitFunctionExpression(FunctionExpression node) { | 358 Object visitFunctionExpression(FunctionExpression node) { |
| 357 ElementHolder holder = new ElementHolder(); | 359 ElementHolder holder = new ElementHolder(); |
| 358 bool wasInFunction = _inFunction; | 360 bool wasInFunction = _inFunction; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 383 _currentHolder.addFunction(element); | 385 _currentHolder.addFunction(element); |
| 384 node.element = element; | 386 node.element = element; |
| 385 holder.validate(); | 387 holder.validate(); |
| 386 return null; | 388 return null; |
| 387 } | 389 } |
| 388 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 390 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 389 ElementHolder holder = new ElementHolder(); | 391 ElementHolder holder = new ElementHolder(); |
| 390 visitChildren(holder, node); | 392 visitChildren(holder, node); |
| 391 SimpleIdentifier aliasName = node.name; | 393 SimpleIdentifier aliasName = node.name; |
| 392 List<ParameterElement> parameters = holder.parameters; | 394 List<ParameterElement> parameters = holder.parameters; |
| 393 List<TypeVariableElement> typeVariables = holder.typeVariables; | 395 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 394 FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(alia
sName); | 396 FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(alia
sName); |
| 395 element.parameters = parameters; | 397 element.parameters = parameters; |
| 396 element.typeVariables = typeVariables; | 398 element.typeParameters = typeParameters; |
| 397 FunctionTypeImpl type = new FunctionTypeImpl.con2(element); | 399 FunctionTypeImpl type = new FunctionTypeImpl.con2(element); |
| 398 type.typeArguments = createTypeVariableTypes(typeVariables); | 400 type.typeArguments = createTypeParameterTypes(typeParameters); |
| 399 element.type = type; | 401 element.type = type; |
| 400 _currentHolder.addTypeAlias(element); | 402 _currentHolder.addTypeAlias(element); |
| 401 aliasName.staticElement = element; | 403 aliasName.staticElement = element; |
| 402 holder.validate(); | 404 holder.validate(); |
| 403 return null; | 405 return null; |
| 404 } | 406 } |
| 405 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 407 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 406 if (node.parent is! DefaultFormalParameter) { | 408 if (node.parent is! DefaultFormalParameter) { |
| 407 SimpleIdentifier parameterName = node.identifier; | 409 SimpleIdentifier parameterName = node.identifier; |
| 408 ParameterElementImpl parameter = new ParameterElementImpl.con1(parameterNa
me); | 410 ParameterElementImpl parameter = new ParameterElementImpl.con1(parameterNa
me); |
| 409 parameter.parameterKind = node.kind; | 411 parameter.parameterKind = node.kind; |
| 412 setParameterVisibleRange(node, parameter); |
| 410 _currentHolder.addParameter(parameter); | 413 _currentHolder.addParameter(parameter); |
| 411 parameterName.staticElement = parameter; | 414 parameterName.staticElement = parameter; |
| 412 } | 415 } |
| 413 ElementHolder holder = new ElementHolder(); | 416 ElementHolder holder = new ElementHolder(); |
| 414 visitChildren(holder, node); | 417 visitChildren(holder, node); |
| 415 ((node.element as ParameterElementImpl)).parameters = holder.parameters; | 418 ((node.element as ParameterElementImpl)).parameters = holder.parameters; |
| 416 holder.validate(); | 419 holder.validate(); |
| 417 return null; | 420 return null; |
| 418 } | 421 } |
| 419 Object visitLabeledStatement(LabeledStatement node) { | 422 Object visitLabeledStatement(LabeledStatement node) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 _currentHolder.addMethod(element); | 456 _currentHolder.addMethod(element); |
| 454 methodName.staticElement = element; | 457 methodName.staticElement = element; |
| 455 } else { | 458 } else { |
| 456 SimpleIdentifier propertyNameNode = node.name; | 459 SimpleIdentifier propertyNameNode = node.name; |
| 457 String propertyName = propertyNameNode.name; | 460 String propertyName = propertyNameNode.name; |
| 458 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldEle
mentImpl; | 461 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldEle
mentImpl; |
| 459 if (field == null) { | 462 if (field == null) { |
| 460 field = new FieldElementImpl.con2(node.name.name); | 463 field = new FieldElementImpl.con2(node.name.name); |
| 461 field.final2 = true; | 464 field.final2 = true; |
| 462 field.static = isStatic; | 465 field.static = isStatic; |
| 466 field.synthetic = true; |
| 463 _currentHolder.addField(field); | 467 _currentHolder.addField(field); |
| 464 } | 468 } |
| 465 if (matches(property, sc.Keyword.GET)) { | 469 if (matches(property, sc.Keyword.GET)) { |
| 466 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con
1(propertyNameNode); | 470 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con
1(propertyNameNode); |
| 467 getter.functions = holder.functions; | 471 getter.functions = holder.functions; |
| 468 getter.labels = holder.labels; | 472 getter.labels = holder.labels; |
| 469 getter.localVariables = holder.localVariables; | 473 getter.localVariables = holder.localVariables; |
| 470 getter.variable = field; | 474 getter.variable = field; |
| 471 getter.abstract = node.body is EmptyFunctionBody && node.externalKeyword
== null; | 475 getter.abstract = node.body is EmptyFunctionBody && node.externalKeyword
== null; |
| 472 getter.getter = true; | 476 getter.getter = true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 493 holder.validate(); | 497 holder.validate(); |
| 494 return null; | 498 return null; |
| 495 } | 499 } |
| 496 Object visitSimpleFormalParameter(SimpleFormalParameter node) { | 500 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 497 if (node.parent is! DefaultFormalParameter) { | 501 if (node.parent is! DefaultFormalParameter) { |
| 498 SimpleIdentifier parameterName = node.identifier; | 502 SimpleIdentifier parameterName = node.identifier; |
| 499 ParameterElementImpl parameter = new ParameterElementImpl.con1(parameterNa
me); | 503 ParameterElementImpl parameter = new ParameterElementImpl.con1(parameterNa
me); |
| 500 parameter.const3 = node.isConst; | 504 parameter.const3 = node.isConst; |
| 501 parameter.final2 = node.isFinal; | 505 parameter.final2 = node.isFinal; |
| 502 parameter.parameterKind = node.kind; | 506 parameter.parameterKind = node.kind; |
| 507 setParameterVisibleRange(node, parameter); |
| 503 _currentHolder.addParameter(parameter); | 508 _currentHolder.addParameter(parameter); |
| 504 parameterName.staticElement = parameter; | 509 parameterName.staticElement = parameter; |
| 505 } | 510 } |
| 506 return super.visitSimpleFormalParameter(node); | 511 return super.visitSimpleFormalParameter(node); |
| 507 } | 512 } |
| 508 Object visitSuperExpression(SuperExpression node) { | 513 Object visitSuperExpression(SuperExpression node) { |
| 509 _isValidMixin = false; | 514 _isValidMixin = false; |
| 510 return super.visitSuperExpression(node); | 515 return super.visitSuperExpression(node); |
| 511 } | 516 } |
| 512 Object visitSwitchCase(SwitchCase node) { | 517 Object visitSwitchCase(SwitchCase node) { |
| 513 for (Label label in node.labels) { | 518 for (Label label in node.labels) { |
| 514 SimpleIdentifier labelName = label.label; | 519 SimpleIdentifier labelName = label.label; |
| 515 LabelElementImpl element = new LabelElementImpl(labelName, false, true); | 520 LabelElementImpl element = new LabelElementImpl(labelName, false, true); |
| 516 _currentHolder.addLabel(element); | 521 _currentHolder.addLabel(element); |
| 517 labelName.staticElement = element; | 522 labelName.staticElement = element; |
| 518 } | 523 } |
| 519 return super.visitSwitchCase(node); | 524 return super.visitSwitchCase(node); |
| 520 } | 525 } |
| 521 Object visitSwitchDefault(SwitchDefault node) { | 526 Object visitSwitchDefault(SwitchDefault node) { |
| 522 for (Label label in node.labels) { | 527 for (Label label in node.labels) { |
| 523 SimpleIdentifier labelName = label.label; | 528 SimpleIdentifier labelName = label.label; |
| 524 LabelElementImpl element = new LabelElementImpl(labelName, false, true); | 529 LabelElementImpl element = new LabelElementImpl(labelName, false, true); |
| 525 _currentHolder.addLabel(element); | 530 _currentHolder.addLabel(element); |
| 526 labelName.staticElement = element; | 531 labelName.staticElement = element; |
| 527 } | 532 } |
| 528 return super.visitSwitchDefault(node); | 533 return super.visitSwitchDefault(node); |
| 529 } | 534 } |
| 530 Object visitTypeParameter(TypeParameter node) { | 535 Object visitTypeParameter(TypeParameter node) { |
| 531 SimpleIdentifier parameterName = node.name; | 536 SimpleIdentifier parameterName = node.name; |
| 532 TypeVariableElementImpl element = new TypeVariableElementImpl(parameterName)
; | 537 TypeParameterElementImpl typeParameter = new TypeParameterElementImpl(parame
terName); |
| 533 TypeVariableTypeImpl type = new TypeVariableTypeImpl(element); | 538 TypeParameterTypeImpl typeParameterType = new TypeParameterTypeImpl(typePara
meter); |
| 534 element.type = type; | 539 typeParameter.type = typeParameterType; |
| 535 _currentHolder.addTypeVariable(element); | 540 _currentHolder.addTypeParameter(typeParameter); |
| 536 parameterName.staticElement = element; | 541 parameterName.staticElement = typeParameter; |
| 537 return super.visitTypeParameter(node); | 542 return super.visitTypeParameter(node); |
| 538 } | 543 } |
| 539 Object visitVariableDeclaration(VariableDeclaration node) { | 544 Object visitVariableDeclaration(VariableDeclaration node) { |
| 540 sc.Token keyword = ((node.parent as VariableDeclarationList)).keyword; | 545 sc.Token keyword = ((node.parent as VariableDeclarationList)).keyword; |
| 541 bool isConst = matches(keyword, sc.Keyword.CONST); | 546 bool isConst = matches(keyword, sc.Keyword.CONST); |
| 542 bool isFinal = matches(keyword, sc.Keyword.FINAL); | 547 bool isFinal = matches(keyword, sc.Keyword.FINAL); |
| 543 bool hasInitializer = node.initializer != null; | 548 bool hasInitializer = node.initializer != null; |
| 544 VariableElementImpl element; | 549 VariableElementImpl element; |
| 545 if (_inFieldContext) { | 550 if (_inFieldContext) { |
| 546 SimpleIdentifier fieldName = node.name; | 551 SimpleIdentifier fieldName = node.name; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 ConstructorElementImpl constructor = new ConstructorElementImpl(null); | 639 ConstructorElementImpl constructor = new ConstructorElementImpl(null); |
| 635 constructor.synthetic = true; | 640 constructor.synthetic = true; |
| 636 constructor.returnType = interfaceType; | 641 constructor.returnType = interfaceType; |
| 637 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); | 642 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); |
| 638 _functionTypesToFix.add(type); | 643 _functionTypesToFix.add(type); |
| 639 constructor.type = type; | 644 constructor.type = type; |
| 640 return <ConstructorElement> [constructor]; | 645 return <ConstructorElement> [constructor]; |
| 641 } | 646 } |
| 642 | 647 |
| 643 /** | 648 /** |
| 644 * Create the types associated with the given type variables, setting the type
of each type | 649 * Create the types associated with the given type parameters, setting the typ
e of each type |
| 645 * variable, and return an array of types corresponding to the given variables
. | 650 * parameter, and return an array of types corresponding to the given paramete
rs. |
| 646 * | 651 * |
| 647 * @param typeVariables the type variables for which types are to be created | 652 * @param typeParameters the type parameters for which types are to be created |
| 648 * @return | 653 * @return an array of types corresponding to the given parameters |
| 649 */ | 654 */ |
| 650 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { | 655 List<Type2> createTypeParameterTypes(List<TypeParameterElement> typeParameters
) { |
| 651 int typeVariableCount = typeVariables.length; | 656 int typeParameterCount = typeParameters.length; |
| 652 List<Type2> typeArguments = new List<Type2>(typeVariableCount); | 657 List<Type2> typeArguments = new List<Type2>(typeParameterCount); |
| 653 for (int i = 0; i < typeVariableCount; i++) { | 658 for (int i = 0; i < typeParameterCount; i++) { |
| 654 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; | 659 TypeParameterElementImpl typeParameter = typeParameters[i] as TypeParamete
rElementImpl; |
| 655 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; | 660 TypeParameterTypeImpl typeParameterType = new TypeParameterTypeImpl(typePa
rameter); |
| 656 typeVariable.type = typeArgument; | 661 typeParameter.type = typeParameterType; |
| 657 typeArguments[i] = typeArgument; | 662 typeArguments[i] = typeParameterType; |
| 658 } | 663 } |
| 659 return typeArguments; | 664 return typeArguments; |
| 660 } | 665 } |
| 661 | 666 |
| 662 /** | 667 /** |
| 663 * Return the body of the function that contains the given parameter, or `null
` if no | 668 * Return the body of the function that contains the given parameter, or `null
` if no |
| 664 * function body could be found. | 669 * function body could be found. |
| 665 * | 670 * |
| 666 * @param node the parameter contained in the function whose body is to be ret
urned | 671 * @param node the parameter contained in the function whose body is to be ret
urned |
| 667 * @return the body of the function that contains the given parameter | 672 * @return the body of the function that contains the given parameter |
| 668 */ | 673 */ |
| 669 FunctionBody getFunctionBody(FormalParameter node) { | 674 FunctionBody getFunctionBody(FormalParameter node) { |
| 670 ASTNode parent = node.parent; | 675 ASTNode parent = node.parent; |
| 671 while (parent != null) { | 676 while (parent != null) { |
| 672 if (parent is FunctionExpression) { | 677 if (parent is ConstructorDeclaration) { |
| 678 return ((parent as ConstructorDeclaration)).body; |
| 679 } else if (parent is FunctionExpression) { |
| 673 return ((parent as FunctionExpression)).body; | 680 return ((parent as FunctionExpression)).body; |
| 674 } else if (parent is MethodDeclaration) { | 681 } else if (parent is MethodDeclaration) { |
| 675 return ((parent as MethodDeclaration)).body; | 682 return ((parent as MethodDeclaration)).body; |
| 676 } | 683 } |
| 677 parent = parent.parent; | 684 parent = parent.parent; |
| 678 } | 685 } |
| 679 return null; | 686 return null; |
| 680 } | 687 } |
| 681 | 688 |
| 682 /** | 689 /** |
| 683 * Return `true` if the given token is a token for the given keyword. | 690 * Return `true` if the given token is a token for the given keyword. |
| 684 * | 691 * |
| 685 * @param token the token being tested | 692 * @param token the token being tested |
| 686 * @param keyword the keyword being tested for | 693 * @param keyword the keyword being tested for |
| 687 * @return `true` if the given token is a token for the given keyword | 694 * @return `true` if the given token is a token for the given keyword |
| 688 */ | 695 */ |
| 689 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); | 696 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); |
| 690 | 697 |
| 691 /** | 698 /** |
| 699 * Sets the visible source range for formal parameter. |
| 700 */ |
| 701 void setParameterVisibleRange(FormalParameter node, ParameterElementImpl eleme
nt) { |
| 702 FunctionBody body = getFunctionBody(node); |
| 703 if (body != null) { |
| 704 element.setVisibleRange(body.offset, body.length); |
| 705 } |
| 706 } |
| 707 |
| 708 /** |
| 692 * Make the given holder be the current holder while visiting the given node. | 709 * Make the given holder be the current holder while visiting the given node. |
| 693 * | 710 * |
| 694 * @param holder the holder that will gather elements that are built while vis
iting the children | 711 * @param holder the holder that will gather elements that are built while vis
iting the children |
| 695 * @param node the node to be visited | 712 * @param node the node to be visited |
| 696 */ | 713 */ |
| 697 void visit(ElementHolder holder, ASTNode node) { | 714 void visit(ElementHolder holder, ASTNode node) { |
| 698 if (node != null) { | 715 if (node != null) { |
| 699 ElementHolder previousHolder = _currentHolder; | 716 ElementHolder previousHolder = _currentHolder; |
| 700 _currentHolder = holder; | 717 _currentHolder = holder; |
| 701 try { | 718 try { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 732 */ | 749 */ |
| 733 class ElementHolder { | 750 class ElementHolder { |
| 734 List<PropertyAccessorElement> _accessors; | 751 List<PropertyAccessorElement> _accessors; |
| 735 List<ConstructorElement> _constructors; | 752 List<ConstructorElement> _constructors; |
| 736 List<FieldElement> _fields; | 753 List<FieldElement> _fields; |
| 737 List<FunctionElement> _functions; | 754 List<FunctionElement> _functions; |
| 738 List<LabelElement> _labels; | 755 List<LabelElement> _labels; |
| 739 List<VariableElement> _localVariables; | 756 List<VariableElement> _localVariables; |
| 740 List<MethodElement> _methods; | 757 List<MethodElement> _methods; |
| 741 List<ParameterElement> _parameters; | 758 List<ParameterElement> _parameters; |
| 742 List<VariableElement> _topLevelVariables; | 759 List<TopLevelVariableElement> _topLevelVariables; |
| 743 List<ClassElement> _types; | 760 List<ClassElement> _types; |
| 744 List<FunctionTypeAliasElement> _typeAliases; | 761 List<FunctionTypeAliasElement> _typeAliases; |
| 745 List<TypeVariableElement> _typeVariables; | 762 List<TypeParameterElement> _typeParameters; |
| 746 void addAccessor(PropertyAccessorElement element) { | 763 void addAccessor(PropertyAccessorElement element) { |
| 747 if (_accessors == null) { | 764 if (_accessors == null) { |
| 748 _accessors = new List<PropertyAccessorElement>(); | 765 _accessors = new List<PropertyAccessorElement>(); |
| 749 } | 766 } |
| 750 _accessors.add(element); | 767 _accessors.add(element); |
| 751 } | 768 } |
| 752 void addConstructor(ConstructorElement element) { | 769 void addConstructor(ConstructorElement element) { |
| 753 if (_constructors == null) { | 770 if (_constructors == null) { |
| 754 _constructors = new List<ConstructorElement>(); | 771 _constructors = new List<ConstructorElement>(); |
| 755 } | 772 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 786 _methods.add(element); | 803 _methods.add(element); |
| 787 } | 804 } |
| 788 void addParameter(ParameterElement element) { | 805 void addParameter(ParameterElement element) { |
| 789 if (_parameters == null) { | 806 if (_parameters == null) { |
| 790 _parameters = new List<ParameterElement>(); | 807 _parameters = new List<ParameterElement>(); |
| 791 } | 808 } |
| 792 _parameters.add(element); | 809 _parameters.add(element); |
| 793 } | 810 } |
| 794 void addTopLevelVariable(TopLevelVariableElement element) { | 811 void addTopLevelVariable(TopLevelVariableElement element) { |
| 795 if (_topLevelVariables == null) { | 812 if (_topLevelVariables == null) { |
| 796 _topLevelVariables = new List<VariableElement>(); | 813 _topLevelVariables = new List<TopLevelVariableElement>(); |
| 797 } | 814 } |
| 798 _topLevelVariables.add(element); | 815 _topLevelVariables.add(element); |
| 799 } | 816 } |
| 800 void addType(ClassElement element) { | 817 void addType(ClassElement element) { |
| 801 if (_types == null) { | 818 if (_types == null) { |
| 802 _types = new List<ClassElement>(); | 819 _types = new List<ClassElement>(); |
| 803 } | 820 } |
| 804 _types.add(element); | 821 _types.add(element); |
| 805 } | 822 } |
| 806 void addTypeAlias(FunctionTypeAliasElement element) { | 823 void addTypeAlias(FunctionTypeAliasElement element) { |
| 807 if (_typeAliases == null) { | 824 if (_typeAliases == null) { |
| 808 _typeAliases = new List<FunctionTypeAliasElement>(); | 825 _typeAliases = new List<FunctionTypeAliasElement>(); |
| 809 } | 826 } |
| 810 _typeAliases.add(element); | 827 _typeAliases.add(element); |
| 811 } | 828 } |
| 812 void addTypeVariable(TypeVariableElement element) { | 829 void addTypeParameter(TypeParameterElement element) { |
| 813 if (_typeVariables == null) { | 830 if (_typeParameters == null) { |
| 814 _typeVariables = new List<TypeVariableElement>(); | 831 _typeParameters = new List<TypeParameterElement>(); |
| 815 } | 832 } |
| 816 _typeVariables.add(element); | 833 _typeParameters.add(element); |
| 817 } | 834 } |
| 818 List<PropertyAccessorElement> get accessors { | 835 List<PropertyAccessorElement> get accessors { |
| 819 if (_accessors == null) { | 836 if (_accessors == null) { |
| 820 return PropertyAccessorElementImpl.EMPTY_ARRAY; | 837 return PropertyAccessorElementImpl.EMPTY_ARRAY; |
| 821 } | 838 } |
| 822 List<PropertyAccessorElement> result = new List.from(_accessors); | 839 List<PropertyAccessorElement> result = new List.from(_accessors); |
| 823 _accessors = null; | 840 _accessors = null; |
| 824 return result; | 841 return result; |
| 825 } | 842 } |
| 826 List<ConstructorElement> get constructors { | 843 List<ConstructorElement> get constructors { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 return result; | 900 return result; |
| 884 } | 901 } |
| 885 List<ParameterElement> get parameters { | 902 List<ParameterElement> get parameters { |
| 886 if (_parameters == null) { | 903 if (_parameters == null) { |
| 887 return ParameterElementImpl.EMPTY_ARRAY; | 904 return ParameterElementImpl.EMPTY_ARRAY; |
| 888 } | 905 } |
| 889 List<ParameterElement> result = new List.from(_parameters); | 906 List<ParameterElement> result = new List.from(_parameters); |
| 890 _parameters = null; | 907 _parameters = null; |
| 891 return result; | 908 return result; |
| 892 } | 909 } |
| 910 TopLevelVariableElement getTopLevelVariable(String variableName) { |
| 911 if (_topLevelVariables == null) { |
| 912 return null; |
| 913 } |
| 914 for (TopLevelVariableElement variable in _topLevelVariables) { |
| 915 if (variable.name == variableName) { |
| 916 return variable; |
| 917 } |
| 918 } |
| 919 return null; |
| 920 } |
| 893 List<TopLevelVariableElement> get topLevelVariables { | 921 List<TopLevelVariableElement> get topLevelVariables { |
| 894 if (_topLevelVariables == null) { | 922 if (_topLevelVariables == null) { |
| 895 return TopLevelVariableElementImpl.EMPTY_ARRAY; | 923 return TopLevelVariableElementImpl.EMPTY_ARRAY; |
| 896 } | 924 } |
| 897 List<TopLevelVariableElement> result = new List.from(_topLevelVariables); | 925 List<TopLevelVariableElement> result = new List.from(_topLevelVariables); |
| 898 _topLevelVariables = null; | 926 _topLevelVariables = null; |
| 899 return result; | 927 return result; |
| 900 } | 928 } |
| 901 List<FunctionTypeAliasElement> get typeAliases { | 929 List<FunctionTypeAliasElement> get typeAliases { |
| 902 if (_typeAliases == null) { | 930 if (_typeAliases == null) { |
| 903 return FunctionTypeAliasElementImpl.EMPTY_ARRAY; | 931 return FunctionTypeAliasElementImpl.EMPTY_ARRAY; |
| 904 } | 932 } |
| 905 List<FunctionTypeAliasElement> result = new List.from(_typeAliases); | 933 List<FunctionTypeAliasElement> result = new List.from(_typeAliases); |
| 906 _typeAliases = null; | 934 _typeAliases = null; |
| 907 return result; | 935 return result; |
| 908 } | 936 } |
| 937 List<TypeParameterElement> get typeParameters { |
| 938 if (_typeParameters == null) { |
| 939 return TypeParameterElementImpl.EMPTY_ARRAY; |
| 940 } |
| 941 List<TypeParameterElement> result = new List.from(_typeParameters); |
| 942 _typeParameters = null; |
| 943 return result; |
| 944 } |
| 909 List<ClassElement> get types { | 945 List<ClassElement> get types { |
| 910 if (_types == null) { | 946 if (_types == null) { |
| 911 return ClassElementImpl.EMPTY_ARRAY; | 947 return ClassElementImpl.EMPTY_ARRAY; |
| 912 } | 948 } |
| 913 List<ClassElement> result = new List.from(_types); | 949 List<ClassElement> result = new List.from(_types); |
| 914 _types = null; | 950 _types = null; |
| 915 return result; | 951 return result; |
| 916 } | 952 } |
| 917 List<TypeVariableElement> get typeVariables { | |
| 918 if (_typeVariables == null) { | |
| 919 return TypeVariableElementImpl.EMPTY_ARRAY; | |
| 920 } | |
| 921 List<TypeVariableElement> result = new List.from(_typeVariables); | |
| 922 _typeVariables = null; | |
| 923 return result; | |
| 924 } | |
| 925 void validate() { | 953 void validate() { |
| 926 JavaStringBuilder builder = new JavaStringBuilder(); | 954 JavaStringBuilder builder = new JavaStringBuilder(); |
| 927 if (_accessors != null) { | 955 if (_accessors != null) { |
| 928 builder.append(_accessors.length); | 956 builder.append(_accessors.length); |
| 929 builder.append(" accessors"); | 957 builder.append(" accessors"); |
| 930 } | 958 } |
| 931 if (_constructors != null) { | 959 if (_constructors != null) { |
| 932 if (builder.length > 0) { | 960 if (builder.length > 0) { |
| 933 builder.append("; "); | 961 builder.append("; "); |
| 934 } | 962 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 builder.append(_types.length); | 1019 builder.append(_types.length); |
| 992 builder.append(" types"); | 1020 builder.append(" types"); |
| 993 } | 1021 } |
| 994 if (_typeAliases != null) { | 1022 if (_typeAliases != null) { |
| 995 if (builder.length > 0) { | 1023 if (builder.length > 0) { |
| 996 builder.append("; "); | 1024 builder.append("; "); |
| 997 } | 1025 } |
| 998 builder.append(_typeAliases.length); | 1026 builder.append(_typeAliases.length); |
| 999 builder.append(" type aliases"); | 1027 builder.append(" type aliases"); |
| 1000 } | 1028 } |
| 1001 if (_typeVariables != null) { | 1029 if (_typeParameters != null) { |
| 1002 if (builder.length > 0) { | 1030 if (builder.length > 0) { |
| 1003 builder.append("; "); | 1031 builder.append("; "); |
| 1004 } | 1032 } |
| 1005 builder.append(_typeVariables.length); | 1033 builder.append(_typeParameters.length); |
| 1006 builder.append(" type variables"); | 1034 builder.append(" type parameters"); |
| 1007 } | 1035 } |
| 1008 if (builder.length > 0) { | 1036 if (builder.length > 0) { |
| 1009 AnalysisEngine.instance.logger.logError("Failed to capture elements: ${bui
lder.toString()}"); | 1037 AnalysisEngine.instance.logger.logError("Failed to capture elements: ${bui
lder.toString()}"); |
| 1010 } | 1038 } |
| 1011 } | 1039 } |
| 1012 } | 1040 } |
| 1013 /** | 1041 /** |
| 1014 * Instances of the class `HtmlUnitBuilder` build an element model for a single
HTML unit. | 1042 * Instances of the class `HtmlUnitBuilder` build an element model for a single
HTML unit. |
| 1015 */ | 1043 */ |
| 1016 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { | 1044 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 * @param length the number of characters to be highlighted | 1279 * @param length the number of characters to be highlighted |
| 1252 * @param arguments the arguments used to compose the error message | 1280 * @param arguments the arguments used to compose the error message |
| 1253 */ | 1281 */ |
| 1254 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List
<Object> arguments) { | 1282 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List
<Object> arguments) { |
| 1255 int offset = attribute.value.offset + 1; | 1283 int offset = attribute.value.offset + 1; |
| 1256 int length = attribute.value.length - 2; | 1284 int length = attribute.value.length - 2; |
| 1257 reportError(errorCode, offset, length, arguments); | 1285 reportError(errorCode, offset, length, arguments); |
| 1258 } | 1286 } |
| 1259 } | 1287 } |
| 1260 /** | 1288 /** |
| 1289 * Instances of the class `BestPracticesVerifier` traverse an AST structure look
ing for |
| 1290 * violations of Dart best practices. |
| 1291 * |
| 1292 * @coverage dart.engine.resolver |
| 1293 */ |
| 1294 class BestPracticesVerifier extends RecursiveASTVisitor<Object> { |
| 1295 static String _GETTER = "getter"; |
| 1296 static String _HASHCODE_GETTER_NAME = "hashCode"; |
| 1297 static String _METHOD = "method"; |
| 1298 static String _NULL_TYPE_NAME = "Null"; |
| 1299 static String _OBJECT_TYPE_NAME = "Object"; |
| 1300 static String _SETTER = "setter"; |
| 1301 static String _TO_INT_METHOD_NAME = "toInt"; |
| 1302 |
| 1303 /** |
| 1304 * Given a parenthesized expression, this returns the parent (or recursively g
rand-parent) of the |
| 1305 * expression that is a parenthesized expression, but whose parent is not a pa
renthesized |
| 1306 * expression. |
| 1307 * |
| 1308 * For example given the code `(((e)))`: `(e) -> (((e)))`. |
| 1309 * |
| 1310 * @param parenthesizedExpression some expression whose parent is a parenthesi
zed expression |
| 1311 * @return the first parent or grand-parent that is a parenthesized expression
, that does not have |
| 1312 * a parenthesized expression parent |
| 1313 */ |
| 1314 static ParenthesizedExpression wrapParenthesizedExpression(ParenthesizedExpres
sion parenthesizedExpression) { |
| 1315 if (parenthesizedExpression.parent is ParenthesizedExpression) { |
| 1316 return wrapParenthesizedExpression(parenthesizedExpression.parent as Paren
thesizedExpression); |
| 1317 } |
| 1318 return parenthesizedExpression; |
| 1319 } |
| 1320 |
| 1321 /** |
| 1322 * The class containing the AST nodes being visited, or `null` if we are not i
n the scope of |
| 1323 * a class. |
| 1324 */ |
| 1325 ClassElement _enclosingClass; |
| 1326 |
| 1327 /** |
| 1328 * The error reporter by which errors will be reported. |
| 1329 */ |
| 1330 ErrorReporter _errorReporter; |
| 1331 |
| 1332 /** |
| 1333 * Create a new instance of the [BestPracticesVerifier]. |
| 1334 * |
| 1335 * @param errorReporter the error reporter |
| 1336 */ |
| 1337 BestPracticesVerifier(ErrorReporter errorReporter) { |
| 1338 this._errorReporter = errorReporter; |
| 1339 } |
| 1340 Object visitAsExpression(AsExpression node) { |
| 1341 checkForUnnecessaryCast(node); |
| 1342 return super.visitAsExpression(node); |
| 1343 } |
| 1344 Object visitBinaryExpression(BinaryExpression node) { |
| 1345 checkForDivisionOptimizationHint(node); |
| 1346 return super.visitBinaryExpression(node); |
| 1347 } |
| 1348 Object visitClassDeclaration(ClassDeclaration node) { |
| 1349 ClassElement outerClass = _enclosingClass; |
| 1350 try { |
| 1351 _enclosingClass = node.element; |
| 1352 return super.visitClassDeclaration(node); |
| 1353 } finally { |
| 1354 _enclosingClass = outerClass; |
| 1355 } |
| 1356 } |
| 1357 Object visitIsExpression(IsExpression node) { |
| 1358 checkAllTypeChecks(node); |
| 1359 return super.visitIsExpression(node); |
| 1360 } |
| 1361 Object visitMethodDeclaration(MethodDeclaration node) { |
| 1362 checkForOverridingPrivateMember(node); |
| 1363 return super.visitMethodDeclaration(node); |
| 1364 } |
| 1365 |
| 1366 /** |
| 1367 * Check for the passed is expression for the unnecessary type check hint code
s as well as null |
| 1368 * checks expressed using an is expression. |
| 1369 * |
| 1370 * @param node the is expression to check |
| 1371 * @return `true` if and only if a hint code is generated on the passed node |
| 1372 * @see HintCode#TYPE_CHECK_IS_NOT_NULL |
| 1373 * @see HintCode#TYPE_CHECK_IS_NULL |
| 1374 * @see HintCode#UNNECESSARY_TYPE_CHECK_TRUE |
| 1375 * @see HintCode#UNNECESSARY_TYPE_CHECK_FALSE |
| 1376 */ |
| 1377 bool checkAllTypeChecks(IsExpression node) { |
| 1378 Expression expression = node.expression; |
| 1379 TypeName typeName = node.type; |
| 1380 Type2 lhsType = expression.staticType; |
| 1381 Type2 rhsType = typeName.type; |
| 1382 if (lhsType == null || rhsType == null) { |
| 1383 return false; |
| 1384 } |
| 1385 String rhsNameStr = typeName.name.name; |
| 1386 if ((rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax)) { |
| 1387 if (node.notOperator == null) { |
| 1388 _errorReporter.reportError2(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node,
[]); |
| 1389 } else { |
| 1390 _errorReporter.reportError2(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node,
[]); |
| 1391 } |
| 1392 return true; |
| 1393 } |
| 1394 Element rhsElement = rhsType.element; |
| 1395 LibraryElement libraryElement = rhsElement != null ? rhsElement.library : nu
ll; |
| 1396 if (libraryElement != null && libraryElement.isDartCore) { |
| 1397 if ((rhsType.isObject && rhsNameStr == _OBJECT_TYPE_NAME) || (expression i
s NullLiteral && rhsNameStr == _NULL_TYPE_NAME)) { |
| 1398 if (node.notOperator == null) { |
| 1399 _errorReporter.reportError2(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node
, []); |
| 1400 } else { |
| 1401 _errorReporter.reportError2(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, nod
e, []); |
| 1402 } |
| 1403 return true; |
| 1404 } else if (rhsNameStr == _NULL_TYPE_NAME) { |
| 1405 if (node.notOperator == null) { |
| 1406 _errorReporter.reportError2(HintCode.TYPE_CHECK_IS_NULL, node, []); |
| 1407 } else { |
| 1408 _errorReporter.reportError2(HintCode.TYPE_CHECK_IS_NOT_NULL, node, [])
; |
| 1409 } |
| 1410 return true; |
| 1411 } |
| 1412 } |
| 1413 return false; |
| 1414 } |
| 1415 |
| 1416 /** |
| 1417 * Check for the passed binary expression for the [HintCode#DIVISION_OPTIMIZAT
ION]. |
| 1418 * |
| 1419 * @param node the binary expression to check |
| 1420 * @return `true` if and only if a hint code is generated on the passed node |
| 1421 * @see HintCode#DIVISION_OPTIMIZATION |
| 1422 */ |
| 1423 bool checkForDivisionOptimizationHint(BinaryExpression node) { |
| 1424 if (node.operator.type != sc.TokenType.SLASH) { |
| 1425 return false; |
| 1426 } |
| 1427 MethodElement methodElement = node.bestElement; |
| 1428 if (methodElement == null) { |
| 1429 return false; |
| 1430 } |
| 1431 LibraryElement libraryElement = methodElement.library; |
| 1432 if (libraryElement != null && !libraryElement.isDartCore) { |
| 1433 return false; |
| 1434 } |
| 1435 if (node.parent is ParenthesizedExpression) { |
| 1436 ParenthesizedExpression parenthesizedExpression = wrapParenthesizedExpress
ion(node.parent as ParenthesizedExpression); |
| 1437 if (parenthesizedExpression.parent is MethodInvocation) { |
| 1438 MethodInvocation methodInvocation = parenthesizedExpression.parent as Me
thodInvocation; |
| 1439 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name && methodInv
ocation.argumentList.arguments.isEmpty) { |
| 1440 _errorReporter.reportError2(HintCode.DIVISION_OPTIMIZATION, methodInvo
cation, []); |
| 1441 return true; |
| 1442 } |
| 1443 } |
| 1444 } |
| 1445 return false; |
| 1446 } |
| 1447 |
| 1448 /** |
| 1449 * Check for the passed class declaration for the |
| 1450 * [HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code. |
| 1451 * |
| 1452 * @param node the class declaration to check |
| 1453 * @return `true` if and only if a hint code is generated on the passed node |
| 1454 * @see HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE |
| 1455 */ |
| 1456 bool checkForOverrideEqualsButNotHashCode(ClassDeclaration node) { |
| 1457 ClassElement classElement = node.element; |
| 1458 if (classElement == null) { |
| 1459 return false; |
| 1460 } |
| 1461 MethodElement equalsOperatorMethodElement = classElement.getMethod(sc.TokenT
ype.EQ_EQ.lexeme); |
| 1462 if (equalsOperatorMethodElement != null) { |
| 1463 PropertyAccessorElement hashCodeElement = classElement.getGetter(_HASHCODE
_GETTER_NAME); |
| 1464 if (hashCodeElement == null) { |
| 1465 _errorReporter.reportError2(HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE,
node.name, [classElement.displayName]); |
| 1466 return true; |
| 1467 } |
| 1468 } |
| 1469 return false; |
| 1470 } |
| 1471 |
| 1472 /** |
| 1473 * Check for the passed class declaration for the |
| 1474 * [HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code. |
| 1475 * |
| 1476 * @param node the class declaration to check |
| 1477 * @return `true` if and only if a hint code is generated on the passed node |
| 1478 * @see HintCode#OVERRIDDING_PRIVATE_MEMBER |
| 1479 */ |
| 1480 bool checkForOverridingPrivateMember(MethodDeclaration node) { |
| 1481 if (_enclosingClass == null) { |
| 1482 return false; |
| 1483 } |
| 1484 if (!Identifier.isPrivateName(node.name.name)) { |
| 1485 return false; |
| 1486 } |
| 1487 ExecutableElement executableElement = node.element; |
| 1488 if (executableElement == null) { |
| 1489 return false; |
| 1490 } |
| 1491 String elementName = executableElement.name; |
| 1492 bool isGetterOrSetter = executableElement is PropertyAccessorElement; |
| 1493 InterfaceType superType = _enclosingClass.supertype; |
| 1494 if (superType == null) { |
| 1495 return false; |
| 1496 } |
| 1497 ClassElement classElement = superType.element; |
| 1498 while (classElement != null) { |
| 1499 if (_enclosingClass.library != classElement.library) { |
| 1500 if (isGetterOrSetter) { |
| 1501 PropertyAccessorElement overriddenAccessor = null; |
| 1502 List<PropertyAccessorElement> accessors = classElement.accessors; |
| 1503 for (PropertyAccessorElement propertyAccessorElement in accessors) { |
| 1504 if (elementName == propertyAccessorElement.name) { |
| 1505 overriddenAccessor = propertyAccessorElement; |
| 1506 break; |
| 1507 } |
| 1508 } |
| 1509 if (overriddenAccessor != null) { |
| 1510 String memberType = ((executableElement as PropertyAccessorElement))
.isGetter ? _GETTER : _SETTER; |
| 1511 _errorReporter.reportError2(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod
e.name, [ |
| 1512 memberType, |
| 1513 executableElement.displayName, |
| 1514 classElement.displayName]); |
| 1515 return true; |
| 1516 } |
| 1517 } else { |
| 1518 MethodElement overriddenMethod = classElement.getMethod(elementName); |
| 1519 if (overriddenMethod != null) { |
| 1520 _errorReporter.reportError2(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod
e.name, [ |
| 1521 _METHOD, |
| 1522 executableElement.displayName, |
| 1523 classElement.displayName]); |
| 1524 return true; |
| 1525 } |
| 1526 } |
| 1527 } |
| 1528 superType = classElement.supertype; |
| 1529 classElement = superType != null ? superType.element : null; |
| 1530 } |
| 1531 return false; |
| 1532 } |
| 1533 |
| 1534 /** |
| 1535 * Check for the passed as expression for the [HintCode#UNNECESSARY_CAST] hint
code. |
| 1536 * |
| 1537 * @param node the as expression to check |
| 1538 * @return `true` if and only if a hint code is generated on the passed node |
| 1539 * @see HintCode#UNNECESSARY_CAST |
| 1540 */ |
| 1541 bool checkForUnnecessaryCast(AsExpression node) { |
| 1542 Expression expression = node.expression; |
| 1543 TypeName typeName = node.type; |
| 1544 Type2 lhsType = expression.staticType; |
| 1545 Type2 rhsType = typeName.type; |
| 1546 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD
ynamic && lhsType.isSubtypeOf(rhsType)) { |
| 1547 _errorReporter.reportError2(HintCode.UNNECESSARY_CAST, node, []); |
| 1548 return true; |
| 1549 } |
| 1550 return false; |
| 1551 } |
| 1552 } |
| 1553 /** |
| 1554 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo
r hints for |
| 1555 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE]. |
| 1556 * |
| 1557 * @coverage dart.engine.resolver |
| 1558 */ |
| 1559 class Dart2JSVerifier extends RecursiveASTVisitor<Object> { |
| 1560 |
| 1561 /** |
| 1562 * The error reporter by which errors will be reported. |
| 1563 */ |
| 1564 ErrorReporter _errorReporter; |
| 1565 |
| 1566 /** |
| 1567 * The name of the `double` type. |
| 1568 */ |
| 1569 static String _DOUBLE_TYPE_NAME = "double"; |
| 1570 |
| 1571 /** |
| 1572 * Create a new instance of the [Dart2JSVerifier]. |
| 1573 * |
| 1574 * @param errorReporter the error reporter |
| 1575 */ |
| 1576 Dart2JSVerifier(ErrorReporter errorReporter) { |
| 1577 this._errorReporter = errorReporter; |
| 1578 } |
| 1579 Object visitIsExpression(IsExpression node) { |
| 1580 checkForIsDoubleHints(node); |
| 1581 return super.visitIsExpression(node); |
| 1582 } |
| 1583 |
| 1584 /** |
| 1585 * Check for instances of `x is double`, `x is int`, `x is! double` and |
| 1586 * `x is! int`. |
| 1587 * |
| 1588 * @param node the is expression to check |
| 1589 * @return `true` if and only if a hint code is generated on the passed node |
| 1590 * @see HintCode#IS_DOUBLE |
| 1591 * @see HintCode#IS_INT |
| 1592 * @see HintCode#IS_NOT_DOUBLE |
| 1593 * @see HintCode#IS_NOT_INT |
| 1594 */ |
| 1595 bool checkForIsDoubleHints(IsExpression node) { |
| 1596 TypeName typeName = node.type; |
| 1597 Type2 type = typeName.type; |
| 1598 if (type != null && type.element != null) { |
| 1599 Element element = type.element; |
| 1600 String typeNameStr = element.name; |
| 1601 LibraryElement libraryElement = element.library; |
| 1602 if (typeNameStr == _DOUBLE_TYPE_NAME && libraryElement != null && libraryE
lement.isDartCore) { |
| 1603 if (node.notOperator == null) { |
| 1604 _errorReporter.reportError2(HintCode.IS_DOUBLE, node, []); |
| 1605 } else { |
| 1606 _errorReporter.reportError2(HintCode.IS_NOT_DOUBLE, node, []); |
| 1607 } |
| 1608 return true; |
| 1609 } |
| 1610 } |
| 1611 return false; |
| 1612 } |
| 1613 } |
| 1614 /** |
| 1261 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f
or cases of | 1615 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f
or cases of |
| 1262 * [HintCode#DEAD_CODE]. | 1616 * [HintCode#DEAD_CODE]. |
| 1263 * | 1617 * |
| 1264 * @coverage dart.engine.resolver | 1618 * @coverage dart.engine.resolver |
| 1265 */ | 1619 */ |
| 1266 class DeadCodeVerifier extends RecursiveASTVisitor<Object> { | 1620 class DeadCodeVerifier extends RecursiveASTVisitor<Object> { |
| 1267 | 1621 |
| 1268 /** | 1622 /** |
| 1269 * The error reporter by which errors will be reported. | 1623 * The error reporter by which errors will be reported. |
| 1270 */ | 1624 */ |
| 1271 ErrorReporter _errorReporter; | 1625 ErrorReporter _errorReporter; |
| 1272 | 1626 |
| 1273 /** | 1627 /** |
| 1274 * Create a new instance of the [DeadCodeVerifier]. | 1628 * Create a new instance of the [DeadCodeVerifier]. |
| 1275 * | 1629 * |
| 1276 * @param errorReporter the error reporter | 1630 * @param errorReporter the error reporter |
| 1277 */ | 1631 */ |
| 1278 DeadCodeVerifier(ErrorReporter errorReporter) { | 1632 DeadCodeVerifier(ErrorReporter errorReporter) { |
| 1279 this._errorReporter = errorReporter; | 1633 this._errorReporter = errorReporter; |
| 1280 } | 1634 } |
| 1281 Object visitBinaryExpression(BinaryExpression node) { | 1635 Object visitBinaryExpression(BinaryExpression node) { |
| 1282 sc.Token operator = node.operator; | 1636 sc.Token operator = node.operator; |
| 1283 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND); | 1637 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND); |
| 1284 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR); | 1638 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR); |
| 1285 if (isAmpAmp || isBarBar) { | 1639 if (isAmpAmp || isBarBar) { |
| 1286 Expression lhsCondition = node.leftOperand; | 1640 Expression lhsCondition = node.leftOperand; |
| 1287 ValidResult lhsResult = getConstantBooleanValue(lhsCondition); | 1641 if (!isDebugConstant(lhsCondition)) { |
| 1288 if (lhsResult != null) { | 1642 ValidResult lhsResult = getConstantBooleanValue(lhsCondition); |
| 1289 if (identical(lhsResult, ValidResult.RESULT_TRUE) && isBarBar) { | 1643 if (lhsResult != null) { |
| 1290 _errorReporter.reportError2(HintCode.DEAD_CODE, node.rightOperand, [])
; | 1644 if (identical(lhsResult, ValidResult.RESULT_TRUE) && isBarBar) { |
| 1291 safelyVisit(lhsCondition); | 1645 _errorReporter.reportError2(HintCode.DEAD_CODE, node.rightOperand, [
]); |
| 1292 return null; | 1646 safelyVisit(lhsCondition); |
| 1293 } else if (identical(lhsResult, ValidResult.RESULT_FALSE) && isAmpAmp) { | 1647 return null; |
| 1294 _errorReporter.reportError2(HintCode.DEAD_CODE, node.rightOperand, [])
; | 1648 } else if (identical(lhsResult, ValidResult.RESULT_FALSE) && isAmpAmp)
{ |
| 1295 safelyVisit(lhsCondition); | 1649 _errorReporter.reportError2(HintCode.DEAD_CODE, node.rightOperand, [
]); |
| 1296 return null; | 1650 safelyVisit(lhsCondition); |
| 1651 return null; |
| 1652 } |
| 1297 } | 1653 } |
| 1298 } | 1654 } |
| 1299 } | 1655 } |
| 1300 return super.visitBinaryExpression(node); | 1656 return super.visitBinaryExpression(node); |
| 1301 } | 1657 } |
| 1302 | 1658 |
| 1303 /** | 1659 /** |
| 1304 * For each [Block], this method reports and error on all statements between t
he end of the | 1660 * For each [Block], this method reports and error on all statements between t
he end of the |
| 1305 * block and the first return statement (assuming there it is not at the end o
f the block.) | 1661 * block and the first return statement (assuming there it is not at the end o
f the block.) |
| 1306 * | 1662 * |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1318 int offset = nextStatement.offset; | 1674 int offset = nextStatement.offset; |
| 1319 int length = lastStatement.end - offset; | 1675 int length = lastStatement.end - offset; |
| 1320 _errorReporter.reportError3(HintCode.DEAD_CODE, offset, length, []); | 1676 _errorReporter.reportError3(HintCode.DEAD_CODE, offset, length, []); |
| 1321 return null; | 1677 return null; |
| 1322 } | 1678 } |
| 1323 } | 1679 } |
| 1324 return null; | 1680 return null; |
| 1325 } | 1681 } |
| 1326 Object visitConditionalExpression(ConditionalExpression node) { | 1682 Object visitConditionalExpression(ConditionalExpression node) { |
| 1327 Expression conditionExpression = node.condition; | 1683 Expression conditionExpression = node.condition; |
| 1328 ValidResult result = getConstantBooleanValue(conditionExpression); | 1684 safelyVisit(conditionExpression); |
| 1329 if (result != null) { | 1685 if (!isDebugConstant(conditionExpression)) { |
| 1330 if (identical(result, ValidResult.RESULT_TRUE)) { | 1686 ValidResult result = getConstantBooleanValue(conditionExpression); |
| 1331 _errorReporter.reportError2(HintCode.DEAD_CODE, node.elseExpression, [])
; | 1687 if (result != null) { |
| 1332 safelyVisit(node.thenExpression); | 1688 if (identical(result, ValidResult.RESULT_TRUE)) { |
| 1333 return null; | 1689 _errorReporter.reportError2(HintCode.DEAD_CODE, node.elseExpression, [
]); |
| 1334 } else { | 1690 safelyVisit(node.thenExpression); |
| 1335 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenExpression, [])
; | 1691 return null; |
| 1336 safelyVisit(node.elseExpression); | 1692 } else { |
| 1337 return null; | 1693 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenExpression, [
]); |
| 1694 safelyVisit(node.elseExpression); |
| 1695 return null; |
| 1696 } |
| 1338 } | 1697 } |
| 1339 } | 1698 } |
| 1340 return super.visitConditionalExpression(node); | 1699 return super.visitConditionalExpression(node); |
| 1341 } | 1700 } |
| 1342 Object visitIfStatement(IfStatement node) { | 1701 Object visitIfStatement(IfStatement node) { |
| 1343 Expression conditionExpression = node.condition; | 1702 Expression conditionExpression = node.condition; |
| 1344 ValidResult result = getConstantBooleanValue(conditionExpression); | 1703 safelyVisit(conditionExpression); |
| 1345 if (result != null) { | 1704 if (!isDebugConstant(conditionExpression)) { |
| 1346 if (identical(result, ValidResult.RESULT_TRUE)) { | 1705 ValidResult result = getConstantBooleanValue(conditionExpression); |
| 1347 Statement elseStatement = node.elseStatement; | 1706 if (result != null) { |
| 1348 if (elseStatement != null) { | 1707 if (identical(result, ValidResult.RESULT_TRUE)) { |
| 1349 _errorReporter.reportError2(HintCode.DEAD_CODE, elseStatement, []); | 1708 Statement elseStatement = node.elseStatement; |
| 1350 safelyVisit(node.thenStatement); | 1709 if (elseStatement != null) { |
| 1710 _errorReporter.reportError2(HintCode.DEAD_CODE, elseStatement, []); |
| 1711 safelyVisit(node.thenStatement); |
| 1712 return null; |
| 1713 } |
| 1714 } else { |
| 1715 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenStatement, []
); |
| 1716 safelyVisit(node.elseStatement); |
| 1351 return null; | 1717 return null; |
| 1352 } | 1718 } |
| 1353 } else { | |
| 1354 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenStatement, []); | |
| 1355 safelyVisit(node.elseStatement); | |
| 1356 return null; | |
| 1357 } | 1719 } |
| 1358 } | 1720 } |
| 1359 return super.visitIfStatement(node); | 1721 return super.visitIfStatement(node); |
| 1360 } | 1722 } |
| 1361 Object visitTryStatement(TryStatement node) { | 1723 Object visitTryStatement(TryStatement node) { |
| 1362 safelyVisit(node.body); | 1724 safelyVisit(node.body); |
| 1363 safelyVisit(node.finallyBlock); | 1725 safelyVisit(node.finallyBlock); |
| 1364 NodeList<CatchClause> catchClauses = node.catchClauses; | 1726 NodeList<CatchClause> catchClauses = node.catchClauses; |
| 1365 int numOfCatchClauses = catchClauses.length; | 1727 int numOfCatchClauses = catchClauses.length; |
| 1366 List<Type2> visitedTypes = new List<Type2>(); | 1728 List<Type2> visitedTypes = new List<Type2>(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 _errorReporter.reportError3(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
offset, length, []); | 1765 _errorReporter.reportError3(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
offset, length, []); |
| 1404 return null; | 1766 return null; |
| 1405 } | 1767 } |
| 1406 } | 1768 } |
| 1407 } | 1769 } |
| 1408 return null; | 1770 return null; |
| 1409 } | 1771 } |
| 1410 Object visitWhileStatement(WhileStatement node) { | 1772 Object visitWhileStatement(WhileStatement node) { |
| 1411 Expression conditionExpression = node.condition; | 1773 Expression conditionExpression = node.condition; |
| 1412 safelyVisit(conditionExpression); | 1774 safelyVisit(conditionExpression); |
| 1413 ValidResult result = getConstantBooleanValue(conditionExpression); | 1775 if (!isDebugConstant(conditionExpression)) { |
| 1414 if (result != null) { | 1776 ValidResult result = getConstantBooleanValue(conditionExpression); |
| 1415 if (identical(result, ValidResult.RESULT_FALSE)) { | 1777 if (result != null) { |
| 1416 _errorReporter.reportError2(HintCode.DEAD_CODE, node.body, []); | 1778 if (identical(result, ValidResult.RESULT_FALSE)) { |
| 1417 return null; | 1779 _errorReporter.reportError2(HintCode.DEAD_CODE, node.body, []); |
| 1780 return null; |
| 1781 } |
| 1418 } | 1782 } |
| 1419 } | 1783 } |
| 1420 safelyVisit(node.body); | 1784 safelyVisit(node.body); |
| 1421 return null; | 1785 return null; |
| 1422 } | 1786 } |
| 1423 | 1787 |
| 1424 /** | 1788 /** |
| 1425 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i
t is | 1789 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i
t is |
| 1426 * `true`, [ValidResult#RESULT_FALSE] if it is `false`, or `null` if the | 1790 * `true`, [ValidResult#RESULT_FALSE] if it is `false`, or `null` if the |
| 1427 * expression is not a constant boolean value. | 1791 * expression is not a constant boolean value. |
| 1428 * | 1792 * |
| 1429 * @param expression the expression to evaluate | 1793 * @param expression the expression to evaluate |
| 1430 * @return [ValidResult#RESULT_TRUE] if it is `true`, [ValidResult#RESULT_FALS
E] | 1794 * @return [ValidResult#RESULT_TRUE] if it is `true`, [ValidResult#RESULT_FALS
E] |
| 1431 * if it is `false`, or `null` if the expression is not a constant boo
lean | 1795 * if it is `false`, or `null` if the expression is not a constant boo
lean |
| 1432 * value | 1796 * value |
| 1433 */ | 1797 */ |
| 1434 ValidResult getConstantBooleanValue(Expression expression) { | 1798 ValidResult getConstantBooleanValue(Expression expression) { |
| 1435 if (expression is BooleanLiteral) { | 1799 if (expression is BooleanLiteral) { |
| 1436 if (((expression as BooleanLiteral)).value) { | 1800 if (((expression as BooleanLiteral)).value) { |
| 1437 return ValidResult.RESULT_TRUE; | 1801 return ValidResult.RESULT_TRUE; |
| 1438 } else { | 1802 } else { |
| 1439 return ValidResult.RESULT_FALSE; | 1803 return ValidResult.RESULT_FALSE; |
| 1440 } | 1804 } |
| 1441 } else { | |
| 1442 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); | |
| 1443 if (identical(result, ValidResult.RESULT_TRUE)) { | |
| 1444 return ValidResult.RESULT_TRUE; | |
| 1445 } else if (identical(result, ValidResult.RESULT_FALSE)) { | |
| 1446 return ValidResult.RESULT_FALSE; | |
| 1447 } | |
| 1448 return null; | |
| 1449 } | 1805 } |
| 1806 return null; |
| 1450 } | 1807 } |
| 1451 | 1808 |
| 1452 /** | 1809 /** |
| 1810 * Return `true` if and only if the passed expression is resolved to a constan
t variable. |
| 1811 * |
| 1812 * @param expression some conditional expression |
| 1813 * @return `true` if and only if the passed expression is resolved to a consta
nt variable |
| 1814 */ |
| 1815 bool isDebugConstant(Expression expression) { |
| 1816 Element element = null; |
| 1817 if (expression is Identifier) { |
| 1818 Identifier identifier = expression as Identifier; |
| 1819 element = identifier.staticElement; |
| 1820 } else if (expression is PropertyAccess) { |
| 1821 PropertyAccess propertyAccess = expression as PropertyAccess; |
| 1822 element = propertyAccess.propertyName.staticElement; |
| 1823 } |
| 1824 if (element is PropertyAccessorElement) { |
| 1825 PropertyAccessorElement pae = element as PropertyAccessorElement; |
| 1826 PropertyInducingElement variable = pae.variable; |
| 1827 return variable != null && variable.isConst; |
| 1828 } |
| 1829 return false; |
| 1830 } |
| 1831 |
| 1832 /** |
| 1453 * If the given node is not `null`, visit this instance of the dead code verif
ier. | 1833 * If the given node is not `null`, visit this instance of the dead code verif
ier. |
| 1454 * | 1834 * |
| 1455 * @param node the node to be visited | 1835 * @param node the node to be visited |
| 1456 */ | 1836 */ |
| 1457 void safelyVisit(ASTNode node) { | 1837 void safelyVisit(ASTNode node) { |
| 1458 if (node != null) { | 1838 if (node != null) { |
| 1459 node.accept(this); | 1839 node.accept(this); |
| 1460 } | 1840 } |
| 1461 } | 1841 } |
| 1462 } | 1842 } |
| 1463 /** | 1843 /** |
| 1464 * Instances of the class `HintGenerator` traverse a library's worth of dart cod
e at a time to | 1844 * Instances of the class `HintGenerator` traverse a library's worth of dart cod
e at a time to |
| 1465 * generate hints over the set of sources. | 1845 * generate hints over the set of sources. |
| 1466 * | 1846 * |
| 1467 * @see HintCode | 1847 * @see HintCode |
| 1468 * @coverage dart.engine.resolver | 1848 * @coverage dart.engine.resolver |
| 1469 */ | 1849 */ |
| 1470 class HintGenerator { | 1850 class HintGenerator { |
| 1471 List<CompilationUnit> _compilationUnits; | 1851 List<CompilationUnit> _compilationUnits; |
| 1472 AnalysisContext _context; | 1852 AnalysisContext _context; |
| 1473 AnalysisErrorListener _errorListener; | 1853 AnalysisErrorListener _errorListener; |
| 1474 ImportsVerifier _importsVerifier; | 1854 ImportsVerifier _importsVerifier; |
| 1475 DeadCodeVerifier _deadCodeVerifier; | 1855 bool _enableDart2JSHints = false; |
| 1476 HintGenerator(List<CompilationUnit> compilationUnits, AnalysisContext context,
AnalysisErrorListener errorListener) { | 1856 HintGenerator(List<CompilationUnit> compilationUnits, AnalysisContext context,
AnalysisErrorListener errorListener) { |
| 1477 this._compilationUnits = compilationUnits; | 1857 this._compilationUnits = compilationUnits; |
| 1478 this._context = context; | 1858 this._context = context; |
| 1479 this._errorListener = errorListener; | 1859 this._errorListener = errorListener; |
| 1480 LibraryElement library = compilationUnits[0].element.library; | 1860 LibraryElement library = compilationUnits[0].element.library; |
| 1481 _importsVerifier = new ImportsVerifier(library); | 1861 _importsVerifier = new ImportsVerifier(library); |
| 1862 _enableDart2JSHints = context.analysisOptions.dart2jsHint; |
| 1482 } | 1863 } |
| 1483 void generateForLibrary() { | 1864 void generateForLibrary() { |
| 1865 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.hints.star
t(); |
| 1484 for (int i = 0; i < _compilationUnits.length; i++) { | 1866 for (int i = 0; i < _compilationUnits.length; i++) { |
| 1485 CompilationUnitElement element = _compilationUnits[i].element; | 1867 CompilationUnitElement element = _compilationUnits[i].element; |
| 1486 if (element != null) { | 1868 if (element != null) { |
| 1487 if (i == 0) { | 1869 if (i == 0) { |
| 1488 _importsVerifier.inDefiningCompilationUnit = true; | 1870 _importsVerifier.inDefiningCompilationUnit = true; |
| 1489 generateForCompilationUnit(_compilationUnits[i], element.source); | 1871 generateForCompilationUnit(_compilationUnits[i], element.source); |
| 1490 _importsVerifier.inDefiningCompilationUnit = false; | 1872 _importsVerifier.inDefiningCompilationUnit = false; |
| 1491 } else { | 1873 } else { |
| 1492 generateForCompilationUnit(_compilationUnits[i], element.source); | 1874 generateForCompilationUnit(_compilationUnits[i], element.source); |
| 1493 } | 1875 } |
| 1494 } | 1876 } |
| 1495 } | 1877 } |
| 1496 _importsVerifier.generateUnusedImportHints(new ErrorReporter(_errorListener,
_compilationUnits[0].element.source)); | 1878 ErrorReporter definingCompilationUnitErrorReporter = new ErrorReporter(_erro
rListener, _compilationUnits[0].element.source); |
| 1879 _importsVerifier.generateDuplicateImportHints(definingCompilationUnitErrorRe
porter); |
| 1880 _importsVerifier.generateUnusedImportHints(definingCompilationUnitErrorRepor
ter); |
| 1881 timeCounter.stop(); |
| 1497 } | 1882 } |
| 1498 void generateForCompilationUnit(CompilationUnit unit, Source source) { | 1883 void generateForCompilationUnit(CompilationUnit unit, Source source) { |
| 1499 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); | 1884 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); |
| 1500 _importsVerifier.visitCompilationUnit(unit); | 1885 _importsVerifier.visitCompilationUnit(unit); |
| 1501 _deadCodeVerifier = new DeadCodeVerifier(errorReporter); | 1886 new DeadCodeVerifier(errorReporter).visitCompilationUnit(unit); |
| 1502 _deadCodeVerifier.visitCompilationUnit(unit); | 1887 if (_enableDart2JSHints) { |
| 1888 new Dart2JSVerifier(errorReporter).visitCompilationUnit(unit); |
| 1889 } |
| 1890 new BestPracticesVerifier(errorReporter).visitCompilationUnit(unit); |
| 1503 } | 1891 } |
| 1504 } | 1892 } |
| 1505 /** | 1893 /** |
| 1506 * Instances of the class `ImportsVerifier` visit all of the referenced librarie
s in the | 1894 * Instances of the class `ImportsVerifier` visit all of the referenced librarie
s in the |
| 1507 * source code verifying that all of the imports are used, otherwise a | 1895 * source code verifying that all of the imports are used, otherwise a |
| 1508 * [HintCode#UNUSED_IMPORT] is generated with | 1896 * [HintCode#UNUSED_IMPORT] is generated with |
| 1509 * [generateUnusedImportHints]. | 1897 * [generateUnusedImportHints]. |
| 1510 * | 1898 * |
| 1511 * While this class does not yet have support for an "Organize Imports" action,
this logic built up | 1899 * While this class does not yet have support for an "Organize Imports" action,
this logic built up |
| 1512 * in this class could be used for such an action in the future. | 1900 * in this class could be used for such an action in the future. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1531 * A list of [ImportDirective]s that the current library imports, as identifie
rs are visited | 1919 * A list of [ImportDirective]s that the current library imports, as identifie
rs are visited |
| 1532 * by this visitor and an import has been identified as being used by the libr
ary, the | 1920 * by this visitor and an import has been identified as being used by the libr
ary, the |
| 1533 * [ImportDirective] is removed from this list. After all the sources in the l
ibrary have | 1921 * [ImportDirective] is removed from this list. After all the sources in the l
ibrary have |
| 1534 * been evaluated, this list represents the set of unused imports. | 1922 * been evaluated, this list represents the set of unused imports. |
| 1535 * | 1923 * |
| 1536 * @see ImportsVerifier#generateUnusedImportErrors(ErrorReporter) | 1924 * @see ImportsVerifier#generateUnusedImportErrors(ErrorReporter) |
| 1537 */ | 1925 */ |
| 1538 List<ImportDirective> _unusedImports; | 1926 List<ImportDirective> _unusedImports; |
| 1539 | 1927 |
| 1540 /** | 1928 /** |
| 1929 * After the list of [unusedImports] has been computed, this list is a proper
subset of the |
| 1930 * unused imports that are listed more than once. |
| 1931 */ |
| 1932 List<ImportDirective> _duplicateImports; |
| 1933 |
| 1934 /** |
| 1541 * This is a map between the set of [LibraryElement]s that the current library
imports, and | 1935 * This is a map between the set of [LibraryElement]s that the current library
imports, and |
| 1542 * a list of [ImportDirective]s that imports the library. In cases where the c
urrent library | 1936 * a list of [ImportDirective]s that imports the library. In cases where the c
urrent library |
| 1543 * imports a library with a single directive (such as `import lib1.dart;`), th
e library | 1937 * imports a library with a single directive (such as `import lib1.dart;`), th
e library |
| 1544 * element will map to a list of one [ImportDirective], which will then be rem
oved from the | 1938 * element will map to a list of one [ImportDirective], which will then be rem
oved from the |
| 1545 * [unusedImports] list. In cases where the current library imports a library
with multiple | 1939 * [unusedImports] list. In cases where the current library imports a library
with multiple |
| 1546 * directives (such as `import lib1.dart; import lib1.dart show C;`), the | 1940 * directives (such as `import lib1.dart; import lib1.dart show C;`), the |
| 1547 * [LibraryElement] will be mapped to a list of the import directives, and the
namespace | 1941 * [LibraryElement] will be mapped to a list of the import directives, and the
namespace |
| 1548 * will need to be used to compute the correct [ImportDirective] being used, s
ee | 1942 * will need to be used to compute the correct [ImportDirective] being used, s
ee |
| 1549 * [namespaceMap]. | 1943 * [namespaceMap]. |
| 1550 */ | 1944 */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1567 Map<PrefixElement, ImportDirective> _prefixElementMap; | 1961 Map<PrefixElement, ImportDirective> _prefixElementMap; |
| 1568 | 1962 |
| 1569 /** | 1963 /** |
| 1570 * Create a new instance of the [ImportsVerifier]. | 1964 * Create a new instance of the [ImportsVerifier]. |
| 1571 * | 1965 * |
| 1572 * @param errorReporter the error reporter | 1966 * @param errorReporter the error reporter |
| 1573 */ | 1967 */ |
| 1574 ImportsVerifier(LibraryElement library) { | 1968 ImportsVerifier(LibraryElement library) { |
| 1575 this._currentLibrary = library; | 1969 this._currentLibrary = library; |
| 1576 this._unusedImports = new List<ImportDirective>(); | 1970 this._unusedImports = new List<ImportDirective>(); |
| 1971 this._duplicateImports = new List<ImportDirective>(); |
| 1577 this._libraryMap = new Map<LibraryElement, List<ImportDirective>>(); | 1972 this._libraryMap = new Map<LibraryElement, List<ImportDirective>>(); |
| 1578 this._namespaceMap = new Map<ImportDirective, Namespace>(); | 1973 this._namespaceMap = new Map<ImportDirective, Namespace>(); |
| 1579 this._prefixElementMap = new Map<PrefixElement, ImportDirective>(); | 1974 this._prefixElementMap = new Map<PrefixElement, ImportDirective>(); |
| 1580 } | 1975 } |
| 1581 | 1976 |
| 1582 /** | 1977 /** |
| 1978 * Any time after the defining compilation unit has been visited by this visit
or, this method can |
| 1979 * be called to report an [HintCode#DUPLICATE_IMPORT] hint for each of the imp
ort directives |
| 1980 * in the [duplicateImports] list. |
| 1981 * |
| 1982 * @param errorReporter the error reporter to report the set of [HintCode#DUPL
ICATE_IMPORT] |
| 1983 * hints to |
| 1984 */ |
| 1985 void generateDuplicateImportHints(ErrorReporter errorReporter) { |
| 1986 for (ImportDirective duplicateImport in _duplicateImports) { |
| 1987 errorReporter.reportError2(HintCode.DUPLICATE_IMPORT, duplicateImport.uri,
[]); |
| 1988 } |
| 1989 } |
| 1990 |
| 1991 /** |
| 1583 * After all of the compilation units have been visited by this visitor, this
method can be called | 1992 * After all of the compilation units have been visited by this visitor, this
method can be called |
| 1584 * to report an [HintCode#UNUSED_IMPORT] hint for each of the import directive
s in the | 1993 * to report an [HintCode#UNUSED_IMPORT] hint for each of the import directive
s in the |
| 1585 * [unusedImports] list. | 1994 * [unusedImports] list. |
| 1586 * | 1995 * |
| 1587 * @param errorReporter the error reporter to report the set of [HintCode#UNUS
ED_IMPORT] | 1996 * @param errorReporter the error reporter to report the set of [HintCode#UNUS
ED_IMPORT] |
| 1588 * hints to | 1997 * hints to |
| 1589 */ | 1998 */ |
| 1590 void generateUnusedImportHints(ErrorReporter errorReporter) { | 1999 void generateUnusedImportHints(ErrorReporter errorReporter) { |
| 1591 for (ImportDirective unusedImport in _unusedImports) { | 2000 for (ImportDirective unusedImport in _unusedImports) { |
| 2001 Element element = unusedImport.element; |
| 2002 if (element is ImportElement) { |
| 2003 ImportElement importElement = element as ImportElement; |
| 2004 LibraryElement libraryElement = importElement.importedLibrary; |
| 2005 if (libraryElement != null && libraryElement.isDartCore) { |
| 2006 continue; |
| 2007 } |
| 2008 } |
| 1592 errorReporter.reportError2(HintCode.UNUSED_IMPORT, unusedImport.uri, []); | 2009 errorReporter.reportError2(HintCode.UNUSED_IMPORT, unusedImport.uri, []); |
| 1593 } | 2010 } |
| 1594 } | 2011 } |
| 1595 Object visitCompilationUnit(CompilationUnit node) { | 2012 Object visitCompilationUnit(CompilationUnit node) { |
| 1596 if (_inDefiningCompilationUnit) { | 2013 if (_inDefiningCompilationUnit) { |
| 1597 NodeList<Directive> directives = node.directives; | 2014 NodeList<Directive> directives = node.directives; |
| 1598 for (Directive directive in directives) { | 2015 for (Directive directive in directives) { |
| 1599 if (directive is ImportDirective) { | 2016 if (directive is ImportDirective) { |
| 1600 ImportDirective importDirective = directive as ImportDirective; | 2017 ImportDirective importDirective = directive as ImportDirective; |
| 1601 LibraryElement libraryElement = importDirective.uriElement; | 2018 LibraryElement libraryElement = importDirective.uriElement; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1613 } | 2030 } |
| 1614 putIntoLibraryMap(libraryElement, importDirective); | 2031 putIntoLibraryMap(libraryElement, importDirective); |
| 1615 addAdditionalLibrariesForExports(libraryElement, importDirective, ne
w List<LibraryElement>()); | 2032 addAdditionalLibrariesForExports(libraryElement, importDirective, ne
w List<LibraryElement>()); |
| 1616 } | 2033 } |
| 1617 } | 2034 } |
| 1618 } | 2035 } |
| 1619 } | 2036 } |
| 1620 if (_unusedImports.isEmpty) { | 2037 if (_unusedImports.isEmpty) { |
| 1621 return null; | 2038 return null; |
| 1622 } | 2039 } |
| 2040 if (_unusedImports.length > 1) { |
| 2041 List<ImportDirective> importDirectiveArray = new List.from(_unusedImports)
; |
| 2042 importDirectiveArray.sort(ImportDirective.COMPARATOR); |
| 2043 ImportDirective currentDirective = importDirectiveArray[0]; |
| 2044 for (int i = 1; i < importDirectiveArray.length; i++) { |
| 2045 ImportDirective nextDirective = importDirectiveArray[i]; |
| 2046 if (ImportDirective.COMPARATOR(currentDirective, nextDirective) == 0) { |
| 2047 if (currentDirective.offset < nextDirective.offset) { |
| 2048 _duplicateImports.add(nextDirective); |
| 2049 } else { |
| 2050 _duplicateImports.add(currentDirective); |
| 2051 } |
| 2052 } |
| 2053 currentDirective = nextDirective; |
| 2054 } |
| 2055 } |
| 1623 return super.visitCompilationUnit(node); | 2056 return super.visitCompilationUnit(node); |
| 1624 } | 2057 } |
| 1625 Object visitExportDirective(ExportDirective node) => null; | 2058 Object visitExportDirective(ExportDirective node) => null; |
| 1626 Object visitImportDirective(ImportDirective node) => null; | 2059 Object visitImportDirective(ImportDirective node) => null; |
| 1627 Object visitLibraryDirective(LibraryDirective node) => null; | 2060 Object visitLibraryDirective(LibraryDirective node) => null; |
| 1628 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 2061 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 1629 SimpleIdentifier prefixIdentifier = node.prefix; | 2062 SimpleIdentifier prefixIdentifier = node.prefix; |
| 1630 Element element = prefixIdentifier.staticElement; | 2063 Element element = prefixIdentifier.staticElement; |
| 1631 if (element is PrefixElement) { | 2064 if (element is PrefixElement) { |
| 1632 _unusedImports.remove(_prefixElementMap[element]); | 2065 _unusedImports.remove(_prefixElementMap[element]); |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2172 Object visitSwitchDefault(SwitchDefault node) { | 2605 Object visitSwitchDefault(SwitchDefault node) { |
| 2173 for (Label label in node.labels) { | 2606 for (Label label in node.labels) { |
| 2174 SimpleIdentifier labelName = label.label; | 2607 SimpleIdentifier labelName = label.label; |
| 2175 find3(_enclosingExecutable.labels, labelName); | 2608 find3(_enclosingExecutable.labels, labelName); |
| 2176 } | 2609 } |
| 2177 return super.visitSwitchDefault(node); | 2610 return super.visitSwitchDefault(node); |
| 2178 } | 2611 } |
| 2179 Object visitTypeParameter(TypeParameter node) { | 2612 Object visitTypeParameter(TypeParameter node) { |
| 2180 SimpleIdentifier parameterName = node.name; | 2613 SimpleIdentifier parameterName = node.name; |
| 2181 if (_enclosingClass != null) { | 2614 if (_enclosingClass != null) { |
| 2182 find3(_enclosingClass.typeVariables, parameterName); | 2615 find3(_enclosingClass.typeParameters, parameterName); |
| 2183 } else if (_enclosingAlias != null) { | 2616 } else if (_enclosingAlias != null) { |
| 2184 find3(_enclosingAlias.typeVariables, parameterName); | 2617 find3(_enclosingAlias.typeParameters, parameterName); |
| 2185 } | 2618 } |
| 2186 return super.visitTypeParameter(node); | 2619 return super.visitTypeParameter(node); |
| 2187 } | 2620 } |
| 2188 Object visitVariableDeclaration(VariableDeclaration node) { | 2621 Object visitVariableDeclaration(VariableDeclaration node) { |
| 2189 VariableElement element = null; | 2622 VariableElement element = null; |
| 2190 SimpleIdentifier variableName = node.name; | 2623 SimpleIdentifier variableName = node.name; |
| 2191 if (_enclosingExecutable != null) { | 2624 if (_enclosingExecutable != null) { |
| 2192 element = find3(_enclosingExecutable.localVariables, variableName); | 2625 element = find3(_enclosingExecutable.localVariables, variableName); |
| 2193 } | 2626 } |
| 2194 if (element == null && _enclosingClass != null) { | 2627 if (element == null && _enclosingClass != null) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2207 } | 2640 } |
| 2208 return super.visitVariableDeclaration(node); | 2641 return super.visitVariableDeclaration(node); |
| 2209 } finally { | 2642 } finally { |
| 2210 _enclosingExecutable = outerExecutable; | 2643 _enclosingExecutable = outerExecutable; |
| 2211 } | 2644 } |
| 2212 } | 2645 } |
| 2213 return super.visitVariableDeclaration(node); | 2646 return super.visitVariableDeclaration(node); |
| 2214 } | 2647 } |
| 2215 | 2648 |
| 2216 /** | 2649 /** |
| 2217 * Append the value of the given string literal to the given string builder. | |
| 2218 * | |
| 2219 * @param builder the builder to which the string's value is to be appended | |
| 2220 * @param literal the string literal whose value is to be appended to the buil
der | |
| 2221 * @throws IllegalArgumentException if the string is not a constant string wit
hout any string | |
| 2222 * interpolation | |
| 2223 */ | |
| 2224 void appendStringValue(JavaStringBuilder builder, StringLiteral literal) { | |
| 2225 if (literal is SimpleStringLiteral) { | |
| 2226 builder.append(((literal as SimpleStringLiteral)).value); | |
| 2227 } else if (literal is AdjacentStrings) { | |
| 2228 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings
) { | |
| 2229 appendStringValue(builder, stringLiteral); | |
| 2230 } | |
| 2231 } else { | |
| 2232 throw new IllegalArgumentException(); | |
| 2233 } | |
| 2234 } | |
| 2235 | |
| 2236 /** | |
| 2237 * Return the element for the part with the given source, or `null` if there i
s no element | 2650 * Return the element for the part with the given source, or `null` if there i
s no element |
| 2238 * for the given source. | 2651 * for the given source. |
| 2239 * | 2652 * |
| 2240 * @param parts the elements for the parts | 2653 * @param parts the elements for the parts |
| 2241 * @param partSource the source for the part whose element is to be returned | 2654 * @param partSource the source for the part whose element is to be returned |
| 2242 * @return the element for the part with the given source | 2655 * @return the element for the part with the given source |
| 2243 */ | 2656 */ |
| 2244 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou
rce) { | 2657 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou
rce) { |
| 2245 for (CompilationUnitElement part in parts) { | 2658 for (CompilationUnitElement part in parts) { |
| 2246 if (part.source == partSource) { | 2659 if (part.source == partSource) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2377 * Return the value of the given string literal, or `null` if the string is no
t a constant | 2790 * Return the value of the given string literal, or `null` if the string is no
t a constant |
| 2378 * string without any string interpolation. | 2791 * string without any string interpolation. |
| 2379 * | 2792 * |
| 2380 * @param literal the string literal whose value is to be returned | 2793 * @param literal the string literal whose value is to be returned |
| 2381 * @return the value of the given string literal | 2794 * @return the value of the given string literal |
| 2382 */ | 2795 */ |
| 2383 String getStringValue(StringLiteral literal) { | 2796 String getStringValue(StringLiteral literal) { |
| 2384 if (literal is StringInterpolation) { | 2797 if (literal is StringInterpolation) { |
| 2385 return null; | 2798 return null; |
| 2386 } | 2799 } |
| 2387 JavaStringBuilder builder = new JavaStringBuilder(); | 2800 return literal.stringValue; |
| 2388 try { | |
| 2389 appendStringValue(builder, literal); | |
| 2390 } on IllegalArgumentException catch (exception) { | |
| 2391 return null; | |
| 2392 } | |
| 2393 return builder.toString().trim(); | |
| 2394 } | 2801 } |
| 2395 } | 2802 } |
| 2396 /** | 2803 /** |
| 2397 * Instances of the class `ElementResolver` are used by instances of [ResolverVi
sitor] | 2804 * Instances of the class `ElementResolver` are used by instances of [ResolverVi
sitor] |
| 2398 * to resolve references within the AST structure to the elements being referenc
ed. The requirements | 2805 * to resolve references within the AST structure to the elements being referenc
ed. The requirements |
| 2399 * for the element resolver are: | 2806 * for the element resolver are: |
| 2400 * <ol> | 2807 * <ol> |
| 2401 * * Every [SimpleIdentifier] should be resolved to the element to which it refe
rs. | 2808 * * Every [SimpleIdentifier] should be resolved to the element to which it refe
rs. |
| 2402 * Specifically: | 2809 * Specifically: |
| 2403 * | 2810 * |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3035 } else { | 3442 } else { |
| 3036 element = enclosingClass.getNamedConstructor(name.name); | 3443 element = enclosingClass.getNamedConstructor(name.name); |
| 3037 } | 3444 } |
| 3038 if (element == null) { | 3445 if (element == null) { |
| 3039 return null; | 3446 return null; |
| 3040 } | 3447 } |
| 3041 if (name != null) { | 3448 if (name != null) { |
| 3042 name.staticElement = element; | 3449 name.staticElement = element; |
| 3043 } | 3450 } |
| 3044 node.staticElement = element; | 3451 node.staticElement = element; |
| 3045 node.element = element; | |
| 3046 ArgumentList argumentList = node.argumentList; | 3452 ArgumentList argumentList = node.argumentList; |
| 3047 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu
mentList, element); | 3453 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu
mentList, element); |
| 3048 if (parameters != null) { | 3454 if (parameters != null) { |
| 3049 argumentList.correspondingStaticParameters = parameters; | 3455 argumentList.correspondingStaticParameters = parameters; |
| 3050 } | 3456 } |
| 3051 return null; | 3457 return null; |
| 3052 } | 3458 } |
| 3053 Object visitSimpleIdentifier(SimpleIdentifier node) { | 3459 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 3054 if (node.staticElement != null) { | 3460 if (node.staticElement != null) { |
| 3055 return null; | 3461 return null; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3110 return null; | 3516 return null; |
| 3111 } else { | 3517 } else { |
| 3112 if (element.isFactory) { | 3518 if (element.isFactory) { |
| 3113 _resolver.reportError5(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
node, [element]); | 3519 _resolver.reportError5(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
node, [element]); |
| 3114 } | 3520 } |
| 3115 } | 3521 } |
| 3116 if (name != null) { | 3522 if (name != null) { |
| 3117 name.staticElement = element; | 3523 name.staticElement = element; |
| 3118 } | 3524 } |
| 3119 node.staticElement = element; | 3525 node.staticElement = element; |
| 3120 node.element = element; | |
| 3121 ArgumentList argumentList = node.argumentList; | 3526 ArgumentList argumentList = node.argumentList; |
| 3122 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo
nstructor, argumentList, element); | 3527 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo
nstructor, argumentList, element); |
| 3123 if (parameters != null) { | 3528 if (parameters != null) { |
| 3124 argumentList.correspondingStaticParameters = parameters; | 3529 argumentList.correspondingStaticParameters = parameters; |
| 3125 } | 3530 } |
| 3126 return null; | 3531 return null; |
| 3127 } | 3532 } |
| 3128 Object visitSuperExpression(SuperExpression node) { | 3533 Object visitSuperExpression(SuperExpression node) { |
| 3129 if (!isSuperInValidContext(node)) { | 3534 if (!isSuperInValidContext(node)) { |
| 3130 _resolver.reportError5(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node
, []); | 3535 _resolver.reportError5(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node
, []); |
| 3131 } | 3536 } |
| 3132 return super.visitSuperExpression(node); | 3537 return super.visitSuperExpression(node); |
| 3133 } | 3538 } |
| 3134 Object visitTypeParameter(TypeParameter node) { | 3539 Object visitTypeParameter(TypeParameter node) { |
| 3135 TypeName bound = node.bound; | 3540 TypeName bound = node.bound; |
| 3136 if (bound != null) { | 3541 if (bound != null) { |
| 3137 TypeVariableElementImpl variable = node.name.staticElement as TypeVariable
ElementImpl; | 3542 TypeParameterElementImpl typeParameter = node.name.staticElement as TypePa
rameterElementImpl; |
| 3138 if (variable != null) { | 3543 if (typeParameter != null) { |
| 3139 variable.bound = bound.type; | 3544 typeParameter.bound = bound.type; |
| 3140 } | 3545 } |
| 3141 } | 3546 } |
| 3142 setMetadata(node.element, node); | 3547 setMetadata(node.element, node); |
| 3143 return null; | 3548 return null; |
| 3144 } | 3549 } |
| 3145 Object visitVariableDeclaration(VariableDeclaration node) { | 3550 Object visitVariableDeclaration(VariableDeclaration node) { |
| 3146 setMetadata(node.element, node); | 3551 setMetadata(node.element, node); |
| 3147 return null; | 3552 return null; |
| 3148 } | 3553 } |
| 3149 | 3554 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3324 LibraryElement definingLibrary = _resolver.definingLibrary; | 3729 LibraryElement definingLibrary = _resolver.definingLibrary; |
| 3325 for (ImportElement importElement in definingLibrary.imports) { | 3730 for (ImportElement importElement in definingLibrary.imports) { |
| 3326 PrefixElement prefixElement = importElement.prefix; | 3731 PrefixElement prefixElement = importElement.prefix; |
| 3327 if (prefixElement != null) { | 3732 if (prefixElement != null) { |
| 3328 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier(
"${prefixElement.name}.${identifier.name}"); | 3733 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier(
"${prefixElement.name}.${identifier.name}"); |
| 3329 Element importedElement = nameScope.lookup(prefixedIdentifier, definingL
ibrary); | 3734 Element importedElement = nameScope.lookup(prefixedIdentifier, definingL
ibrary); |
| 3330 if (importedElement != null) { | 3735 if (importedElement != null) { |
| 3331 if (element == null) { | 3736 if (element == null) { |
| 3332 element = importedElement; | 3737 element = importedElement; |
| 3333 } else { | 3738 } else { |
| 3334 element = new MultiplyDefinedElementImpl(definingLibrary.context, el
ement, importedElement); | 3739 element = new MultiplyDefinedElementImpl.con1(definingLibrary.contex
t, element, importedElement); |
| 3335 } | 3740 } |
| 3336 } | 3741 } |
| 3337 } | 3742 } |
| 3338 } | 3743 } |
| 3339 return element; | 3744 return element; |
| 3340 } | 3745 } |
| 3341 | 3746 |
| 3342 /** | 3747 /** |
| 3343 * Return the name of the method invoked by the given postfix expression. | 3748 * Return the name of the method invoked by the given postfix expression. |
| 3344 * | 3749 * |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3367 } | 3772 } |
| 3368 } | 3773 } |
| 3369 | 3774 |
| 3370 /** | 3775 /** |
| 3371 * Return the propagated type of the given expression that is to be used for t
ype analysis. | 3776 * Return the propagated type of the given expression that is to be used for t
ype analysis. |
| 3372 * | 3777 * |
| 3373 * @param expression the expression whose type is to be returned | 3778 * @param expression the expression whose type is to be returned |
| 3374 * @return the type of the given expression | 3779 * @return the type of the given expression |
| 3375 */ | 3780 */ |
| 3376 Type2 getPropagatedType(Expression expression) { | 3781 Type2 getPropagatedType(Expression expression) { |
| 3377 Type2 propagatedType = resolveTypeVariable(expression.propagatedType); | 3782 Type2 propagatedType = resolveTypeParameter(expression.propagatedType); |
| 3378 if (propagatedType is FunctionType) { | 3783 if (propagatedType is FunctionType) { |
| 3379 propagatedType = _resolver.typeProvider.functionType; | 3784 propagatedType = _resolver.typeProvider.functionType; |
| 3380 } | 3785 } |
| 3381 return propagatedType; | 3786 return propagatedType; |
| 3382 } | 3787 } |
| 3383 | 3788 |
| 3384 /** | 3789 /** |
| 3385 * Return the static type of the given expression that is to be used for type
analysis. | 3790 * Return the static type of the given expression that is to be used for type
analysis. |
| 3386 * | 3791 * |
| 3387 * @param expression the expression whose type is to be returned | 3792 * @param expression the expression whose type is to be returned |
| 3388 * @return the type of the given expression | 3793 * @return the type of the given expression |
| 3389 */ | 3794 */ |
| 3390 Type2 getStaticType(Expression expression) { | 3795 Type2 getStaticType(Expression expression) { |
| 3391 if (expression is NullLiteral) { | 3796 if (expression is NullLiteral) { |
| 3392 return _resolver.typeProvider.objectType; | 3797 return _resolver.typeProvider.objectType; |
| 3393 } | 3798 } |
| 3394 Type2 staticType = resolveTypeVariable(expression.staticType); | 3799 Type2 staticType = resolveTypeParameter(expression.staticType); |
| 3395 if (staticType is FunctionType) { | 3800 if (staticType is FunctionType) { |
| 3396 staticType = _resolver.typeProvider.functionType; | 3801 staticType = _resolver.typeProvider.functionType; |
| 3397 } | 3802 } |
| 3398 return staticType; | 3803 return staticType; |
| 3399 } | 3804 } |
| 3400 | 3805 |
| 3401 /** | 3806 /** |
| 3402 * Return the element representing the superclass of the given class. | 3807 * Return the element representing the superclass of the given class. |
| 3403 * | 3808 * |
| 3404 * @param targetClass the class whose superclass is to be returned | 3809 * @param targetClass the class whose superclass is to be returned |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3481 /** | 3886 /** |
| 3482 * Look up the getter with the given name in the given type. Return the elemen
t representing the | 3887 * Look up the getter with the given name in the given type. Return the elemen
t representing the |
| 3483 * getter that was found, or `null` if there is no getter with the given name. | 3888 * getter that was found, or `null` if there is no getter with the given name. |
| 3484 * | 3889 * |
| 3485 * @param target the target of the invocation, or `null` if there is no target | 3890 * @param target the target of the invocation, or `null` if there is no target |
| 3486 * @param type the type in which the getter is defined | 3891 * @param type the type in which the getter is defined |
| 3487 * @param getterName the name of the getter being looked up | 3892 * @param getterName the name of the getter being looked up |
| 3488 * @return the element representing the getter that was found | 3893 * @return the element representing the getter that was found |
| 3489 */ | 3894 */ |
| 3490 PropertyAccessorElement lookUpGetter(Expression target, Type2 type, String get
terName) { | 3895 PropertyAccessorElement lookUpGetter(Expression target, Type2 type, String get
terName) { |
| 3491 type = resolveTypeVariable(type); | 3896 type = resolveTypeParameter(type); |
| 3492 if (type is InterfaceType) { | 3897 if (type is InterfaceType) { |
| 3493 InterfaceType interfaceType = type as InterfaceType; | 3898 InterfaceType interfaceType = type as InterfaceType; |
| 3494 PropertyAccessorElement accessor; | 3899 PropertyAccessorElement accessor; |
| 3495 if (target is SuperExpression) { | 3900 if (target is SuperExpression) { |
| 3496 accessor = interfaceType.lookUpGetterInSuperclass(getterName, _resolver.
definingLibrary); | 3901 accessor = interfaceType.lookUpGetterInSuperclass(getterName, _resolver.
definingLibrary); |
| 3497 } else { | 3902 } else { |
| 3498 accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibr
ary); | 3903 accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibr
ary); |
| 3499 } | 3904 } |
| 3500 if (accessor != null) { | 3905 if (accessor != null) { |
| 3501 return accessor; | 3906 return accessor; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3551 /** | 3956 /** |
| 3552 * Look up the method or getter with the given name in the given type. Return
the element | 3957 * Look up the method or getter with the given name in the given type. Return
the element |
| 3553 * representing the method or getter that was found, or `null` if there is no
method or | 3958 * representing the method or getter that was found, or `null` if there is no
method or |
| 3554 * getter with the given name. | 3959 * getter with the given name. |
| 3555 * | 3960 * |
| 3556 * @param type the type in which the method or getter is defined | 3961 * @param type the type in which the method or getter is defined |
| 3557 * @param memberName the name of the method or getter being looked up | 3962 * @param memberName the name of the method or getter being looked up |
| 3558 * @return the element representing the method or getter that was found | 3963 * @return the element representing the method or getter that was found |
| 3559 */ | 3964 */ |
| 3560 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) { | 3965 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) { |
| 3561 type = resolveTypeVariable(type); | 3966 type = resolveTypeParameter(type); |
| 3562 if (type is InterfaceType) { | 3967 if (type is InterfaceType) { |
| 3563 InterfaceType interfaceType = type as InterfaceType; | 3968 InterfaceType interfaceType = type as InterfaceType; |
| 3564 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve
r.definingLibrary); | 3969 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve
r.definingLibrary); |
| 3565 if (member != null) { | 3970 if (member != null) { |
| 3566 return member; | 3971 return member; |
| 3567 } | 3972 } |
| 3568 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary)
; | 3973 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary)
; |
| 3569 if (member != null) { | 3974 if (member != null) { |
| 3570 return member; | 3975 return member; |
| 3571 } | 3976 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3664 /** | 4069 /** |
| 3665 * Look up the method with the given name in the given type. Return the elemen
t representing the | 4070 * Look up the method with the given name in the given type. Return the elemen
t representing the |
| 3666 * method that was found, or `null` if there is no method with the given name. | 4071 * method that was found, or `null` if there is no method with the given name. |
| 3667 * | 4072 * |
| 3668 * @param target the target of the invocation, or `null` if there is no target | 4073 * @param target the target of the invocation, or `null` if there is no target |
| 3669 * @param type the type in which the method is defined | 4074 * @param type the type in which the method is defined |
| 3670 * @param methodName the name of the method being looked up | 4075 * @param methodName the name of the method being looked up |
| 3671 * @return the element representing the method that was found | 4076 * @return the element representing the method that was found |
| 3672 */ | 4077 */ |
| 3673 MethodElement lookUpMethod(Expression target, Type2 type, String methodName) { | 4078 MethodElement lookUpMethod(Expression target, Type2 type, String methodName) { |
| 3674 type = resolveTypeVariable(type); | 4079 type = resolveTypeParameter(type); |
| 3675 if (type is InterfaceType) { | 4080 if (type is InterfaceType) { |
| 3676 InterfaceType interfaceType = type as InterfaceType; | 4081 InterfaceType interfaceType = type as InterfaceType; |
| 3677 MethodElement method; | 4082 MethodElement method; |
| 3678 if (target is SuperExpression) { | 4083 if (target is SuperExpression) { |
| 3679 method = interfaceType.lookUpMethodInSuperclass(methodName, _resolver.de
finingLibrary); | 4084 method = interfaceType.lookUpMethodInSuperclass(methodName, _resolver.de
finingLibrary); |
| 3680 } else { | 4085 } else { |
| 3681 method = interfaceType.lookUpMethod(methodName, _resolver.definingLibrar
y); | 4086 method = interfaceType.lookUpMethod(methodName, _resolver.definingLibrar
y); |
| 3682 } | 4087 } |
| 3683 if (method != null) { | 4088 if (method != null) { |
| 3684 return method; | 4089 return method; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3734 /** | 4139 /** |
| 3735 * Look up the setter with the given name in the given type. Return the elemen
t representing the | 4140 * Look up the setter with the given name in the given type. Return the elemen
t representing the |
| 3736 * setter that was found, or `null` if there is no setter with the given name. | 4141 * setter that was found, or `null` if there is no setter with the given name. |
| 3737 * | 4142 * |
| 3738 * @param target the target of the invocation, or `null` if there is no target | 4143 * @param target the target of the invocation, or `null` if there is no target |
| 3739 * @param type the type in which the setter is defined | 4144 * @param type the type in which the setter is defined |
| 3740 * @param setterName the name of the setter being looked up | 4145 * @param setterName the name of the setter being looked up |
| 3741 * @return the element representing the setter that was found | 4146 * @return the element representing the setter that was found |
| 3742 */ | 4147 */ |
| 3743 PropertyAccessorElement lookUpSetter(Expression target, Type2 type, String set
terName) { | 4148 PropertyAccessorElement lookUpSetter(Expression target, Type2 type, String set
terName) { |
| 3744 type = resolveTypeVariable(type); | 4149 type = resolveTypeParameter(type); |
| 3745 if (type is InterfaceType) { | 4150 if (type is InterfaceType) { |
| 3746 InterfaceType interfaceType = type as InterfaceType; | 4151 InterfaceType interfaceType = type as InterfaceType; |
| 3747 PropertyAccessorElement accessor; | 4152 PropertyAccessorElement accessor; |
| 3748 if (target is SuperExpression) { | 4153 if (target is SuperExpression) { |
| 3749 accessor = interfaceType.lookUpSetterInSuperclass(setterName, _resolver.
definingLibrary); | 4154 accessor = interfaceType.lookUpSetterInSuperclass(setterName, _resolver.
definingLibrary); |
| 3750 } else { | 4155 } else { |
| 3751 accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibr
ary); | 4156 accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibr
ary); |
| 3752 } | 4157 } |
| 3753 if (accessor != null) { | 4158 if (accessor != null) { |
| 3754 return accessor; | 4159 return accessor; |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4160 element = lookUpGetter(null, enclosingType, node.name); | 4565 element = lookUpGetter(null, enclosingType, node.name); |
| 4161 } | 4566 } |
| 4162 if (element == null) { | 4567 if (element == null) { |
| 4163 element = lookUpMethod(null, enclosingType, node.name); | 4568 element = lookUpMethod(null, enclosingType, node.name); |
| 4164 } | 4569 } |
| 4165 } | 4570 } |
| 4166 return element; | 4571 return element; |
| 4167 } | 4572 } |
| 4168 | 4573 |
| 4169 /** | 4574 /** |
| 4170 * If the given type is a type variable, resolve it to the type that should be
used when looking | 4575 * If the given type is a type parameter, resolve it to the type that should b
e used when looking |
| 4171 * up members. Otherwise, return the original type. | 4576 * up members. Otherwise, return the original type. |
| 4172 * | 4577 * |
| 4173 * @param type the type that is to be resolved if it is a type variable | 4578 * @param type the type that is to be resolved if it is a type parameter |
| 4174 * @return the type that should be used in place of the argument if it is a ty
pe variable, or the | 4579 * @return the type that should be used in place of the argument if it is a ty
pe parameter, or the |
| 4175 * original argument if it isn't a type variable | 4580 * original argument if it isn't a type parameter |
| 4176 */ | 4581 */ |
| 4177 Type2 resolveTypeVariable(Type2 type) { | 4582 Type2 resolveTypeParameter(Type2 type) { |
| 4178 if (type is TypeVariableType) { | 4583 if (type is TypeParameterType) { |
| 4179 Type2 bound = ((type as TypeVariableType)).element.bound; | 4584 Type2 bound = ((type as TypeParameterType)).element.bound; |
| 4180 if (bound == null) { | 4585 if (bound == null) { |
| 4181 return _resolver.typeProvider.objectType; | 4586 return _resolver.typeProvider.objectType; |
| 4182 } | 4587 } |
| 4183 return bound; | 4588 return bound; |
| 4184 } | 4589 } |
| 4185 return type; | 4590 return type; |
| 4186 } | 4591 } |
| 4187 | 4592 |
| 4188 /** | 4593 /** |
| 4189 * Return the propagated element if it is not `null`, or the static element if
it is. | 4594 * Return the propagated element if it is not `null`, or the static element if
it is. |
| (...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5255 * @coverage dart.engine.resolver | 5660 * @coverage dart.engine.resolver |
| 5256 */ | 5661 */ |
| 5257 class LibraryResolver { | 5662 class LibraryResolver { |
| 5258 | 5663 |
| 5259 /** | 5664 /** |
| 5260 * The analysis context in which the libraries are being analyzed. | 5665 * The analysis context in which the libraries are being analyzed. |
| 5261 */ | 5666 */ |
| 5262 InternalAnalysisContext analysisContext; | 5667 InternalAnalysisContext analysisContext; |
| 5263 | 5668 |
| 5264 /** | 5669 /** |
| 5265 * A flag indicating whether analysis is to generate hint results (e.g. type i
nference based | |
| 5266 * information and pub best practices). | |
| 5267 */ | |
| 5268 bool _enableHints = false; | |
| 5269 | |
| 5270 /** | |
| 5271 * The listener to which analysis errors will be reported, this error listener
is either | 5670 * The listener to which analysis errors will be reported, this error listener
is either |
| 5272 * references [recordingErrorListener], or it unions the passed | 5671 * references [recordingErrorListener], or it unions the passed |
| 5273 * [AnalysisErrorListener] with the [recordingErrorListener]. | 5672 * [AnalysisErrorListener] with the [recordingErrorListener]. |
| 5274 */ | 5673 */ |
| 5275 RecordingErrorListener errorListener; | 5674 RecordingErrorListener errorListener; |
| 5276 | 5675 |
| 5277 /** | 5676 /** |
| 5278 * A source object representing the core library (dart:core). | 5677 * A source object representing the core library (dart:core). |
| 5279 */ | 5678 */ |
| 5280 Source _coreLibrarySource; | 5679 Source _coreLibrarySource; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5301 | 5700 |
| 5302 /** | 5701 /** |
| 5303 * Initialize a newly created library resolver to resolve libraries within the
given context. | 5702 * Initialize a newly created library resolver to resolve libraries within the
given context. |
| 5304 * | 5703 * |
| 5305 * @param analysisContext the analysis context in which the library is being a
nalyzed | 5704 * @param analysisContext the analysis context in which the library is being a
nalyzed |
| 5306 */ | 5705 */ |
| 5307 LibraryResolver(InternalAnalysisContext analysisContext) { | 5706 LibraryResolver(InternalAnalysisContext analysisContext) { |
| 5308 this.analysisContext = analysisContext; | 5707 this.analysisContext = analysisContext; |
| 5309 this.errorListener = new RecordingErrorListener(); | 5708 this.errorListener = new RecordingErrorListener(); |
| 5310 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE)
; | 5709 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE)
; |
| 5311 _enableHints = analysisContext.analysisOptions.hint; | |
| 5312 } | 5710 } |
| 5313 | 5711 |
| 5314 /** | 5712 /** |
| 5315 * Resolve the library specified by the given source in the given context. The
library is assumed | 5713 * Resolve the library specified by the given source in the given context. The
library is assumed |
| 5316 * to be embedded in the given source. | 5714 * to be embedded in the given source. |
| 5317 * | 5715 * |
| 5318 * @param librarySource the source specifying the defining compilation unit of
the library to be | 5716 * @param librarySource the source specifying the defining compilation unit of
the library to be |
| 5319 * resolved | 5717 * resolved |
| 5320 * @param modificationStamp the time stamp of the source from which the compil
ation unit was | 5718 * @param modificationStamp the time stamp of the source from which the compil
ation unit was |
| 5321 * created | 5719 * created |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5591 } | 5989 } |
| 5592 } | 5990 } |
| 5593 | 5991 |
| 5594 /** | 5992 /** |
| 5595 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current | 5993 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current |
| 5596 * cycle. | 5994 * cycle. |
| 5597 * | 5995 * |
| 5598 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 5996 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
| 5599 */ | 5997 */ |
| 5600 void buildTypeHierarchies() { | 5998 void buildTypeHierarchies() { |
| 5999 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st
art(); |
| 5601 for (Library library in resolvedLibraries) { | 6000 for (Library library in resolvedLibraries) { |
| 5602 for (Source source in library.compilationUnitSources) { | 6001 for (Source source in library.compilationUnitSources) { |
| 5603 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour
ce, _typeProvider); | 6002 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour
ce, _typeProvider); |
| 5604 library.getAST(source).accept(visitor); | 6003 library.getAST(source).accept(visitor); |
| 5605 } | 6004 } |
| 5606 } | 6005 } |
| 6006 timeCounter.stop(); |
| 5607 } | 6007 } |
| 5608 | 6008 |
| 5609 /** | 6009 /** |
| 5610 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a | 6010 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a |
| 5611 * table that maps individual libraries to a list of the libraries that either
import or export | 6011 * table that maps individual libraries to a list of the libraries that either
import or export |
| 5612 * those libraries. | 6012 * those libraries. |
| 5613 * | 6013 * |
| 5614 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root | 6014 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root |
| 5615 * library. Given that we only add libraries that are reachable from the root
library, when we | 6015 * library. Given that we only add libraries that are reachable from the root
library, when we |
| 5616 * work backward we are guaranteed to only get libraries in the cycle. | 6016 * work backward we are guaranteed to only get libraries in the cycle. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5809 for (int i = 0; i < count; i++) { | 6209 for (int i = 0; i < count; i++) { |
| 5810 identifiers[i] = names[i].name; | 6210 identifiers[i] = names[i].name; |
| 5811 } | 6211 } |
| 5812 return identifiers; | 6212 return identifiers; |
| 5813 } | 6213 } |
| 5814 | 6214 |
| 5815 /** | 6215 /** |
| 5816 * Compute a value for all of the constants in the libraries being analyzed. | 6216 * Compute a value for all of the constants in the libraries being analyzed. |
| 5817 */ | 6217 */ |
| 5818 void performConstantEvaluation() { | 6218 void performConstantEvaluation() { |
| 6219 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st
art(); |
| 5819 ConstantValueComputer computer = new ConstantValueComputer(); | 6220 ConstantValueComputer computer = new ConstantValueComputer(); |
| 5820 for (Library library in resolvedLibraries) { | 6221 for (Library library in resolvedLibraries) { |
| 5821 for (Source source in library.compilationUnitSources) { | 6222 for (Source source in library.compilationUnitSources) { |
| 5822 try { | 6223 try { |
| 5823 CompilationUnit unit = library.getAST(source); | 6224 CompilationUnit unit = library.getAST(source); |
| 5824 if (unit != null) { | 6225 if (unit != null) { |
| 5825 computer.add(unit); | 6226 computer.add(unit); |
| 5826 } | 6227 } |
| 5827 } on AnalysisException catch (exception) { | 6228 } on AnalysisException catch (exception) { |
| 5828 AnalysisEngine.instance.logger.logError2("Internal Error: Could not ac
cess AST for ${source.fullName} during constant evaluation", exception); | 6229 AnalysisEngine.instance.logger.logError2("Internal Error: Could not ac
cess AST for ${source.fullName} during constant evaluation", exception); |
| 5829 } | 6230 } |
| 5830 } | 6231 } |
| 5831 } | 6232 } |
| 5832 computer.computeValues(); | 6233 computer.computeValues(); |
| 6234 timeCounter.stop(); |
| 5833 } | 6235 } |
| 5834 | 6236 |
| 5835 /** | 6237 /** |
| 5836 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. | 6238 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. |
| 5837 * | 6239 * |
| 5838 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the | 6240 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the |
| 5839 * libraries could not have their types analyzed | 6241 * libraries could not have their types analyzed |
| 5840 */ | 6242 */ |
| 5841 void resolveReferencesAndTypes() { | 6243 void resolveReferencesAndTypes() { |
| 5842 for (Library library in resolvedLibraries) { | 6244 for (Library library in resolvedLibraries) { |
| 5843 resolveReferencesAndTypes2(library); | 6245 resolveReferencesAndTypes2(library); |
| 5844 } | 6246 } |
| 5845 } | 6247 } |
| 5846 | 6248 |
| 5847 /** | 6249 /** |
| 5848 * Resolve the identifiers and perform type analysis in the given library. | 6250 * Resolve the identifiers and perform type analysis in the given library. |
| 5849 * | 6251 * |
| 5850 * @param library the library to be resolved | 6252 * @param library the library to be resolved |
| 5851 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 6253 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 5852 * the library cannot be analyzed | 6254 * the library cannot be analyzed |
| 5853 */ | 6255 */ |
| 5854 void resolveReferencesAndTypes2(Library library) { | 6256 void resolveReferencesAndTypes2(Library library) { |
| 6257 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st
art(); |
| 5855 for (Source source in library.compilationUnitSources) { | 6258 for (Source source in library.compilationUnitSources) { |
| 5856 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); | 6259 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); |
| 5857 library.getAST(source).accept(visitor); | 6260 library.getAST(source).accept(visitor); |
| 5858 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyConditi
onalAnalysisErrors) { | 6261 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyConditi
onalAnalysisErrors) { |
| 5859 if (conditionalCode.shouldIncludeErrorCode()) { | 6262 if (conditionalCode.shouldIncludeErrorCode()) { |
| 5860 visitor.reportError(conditionalCode.analysisError); | 6263 visitor.reportError(conditionalCode.analysisError); |
| 5861 } | 6264 } |
| 5862 } | 6265 } |
| 5863 } | 6266 } |
| 6267 timeCounter.stop(); |
| 5864 } | 6268 } |
| 5865 | 6269 |
| 5866 /** | 6270 /** |
| 5867 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 6271 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
| 5868 * given library, or `null` if the URI is not valid. | 6272 * given library, or `null` if the URI is not valid. |
| 5869 * | 6273 * |
| 5870 * @param librarySource the source representing the library containing the dir
ective | 6274 * @param librarySource the source representing the library containing the dir
ective |
| 5871 * @param directive the directive which URI should be resolved | 6275 * @param directive the directive which URI should be resolved |
| 5872 * @return the result of resolving the URI against the URI of the library | 6276 * @return the result of resolving the URI against the URI of the library |
| 5873 */ | 6277 */ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 5899 | 6303 |
| 5900 /** | 6304 /** |
| 5901 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier] | 6305 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier] |
| 5902 * analysis in the given library. | 6306 * analysis in the given library. |
| 5903 * | 6307 * |
| 5904 * @param library the library to have the extra analyses processes run | 6308 * @param library the library to have the extra analyses processes run |
| 5905 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 6309 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 5906 * the library cannot be analyzed | 6310 * the library cannot be analyzed |
| 5907 */ | 6311 */ |
| 5908 void runAdditionalAnalyses2(Library library) { | 6312 void runAdditionalAnalyses2(Library library) { |
| 6313 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.errors.sta
rt(); |
| 5909 for (Source source in library.compilationUnitSources) { | 6314 for (Source source in library.compilationUnitSources) { |
| 5910 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 6315 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 5911 CompilationUnit unit = library.getAST(source); | 6316 CompilationUnit unit = library.getAST(source); |
| 5912 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); | 6317 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); |
| 5913 unit.accept(constantVerifier); | 6318 unit.accept(constantVerifier); |
| 5914 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); | 6319 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); |
| 5915 unit.accept(errorVerifier); | 6320 unit.accept(errorVerifier); |
| 5916 } | 6321 } |
| 5917 if (_enableHints) { | 6322 timeCounter.stop(); |
| 5918 HintGenerator hintGenerator = new HintGenerator(library.compilationUnits,
analysisContext, errorListener); | |
| 5919 hintGenerator.generateForLibrary(); | |
| 5920 } | |
| 5921 } | 6323 } |
| 5922 } | 6324 } |
| 5923 /** | 6325 /** |
| 5924 * This class is a wrapper for an [AnalysisError] which can also be queried afte
r resolution | 6326 * This class is a wrapper for an [AnalysisError] which can also be queried afte
r resolution |
| 5925 * to find out if the error should actually be reported. In this case, these err
ors are conditional | 6327 * to find out if the error should actually be reported. In this case, these err
ors are conditional |
| 5926 * on the non-existence of an `@proxy` annotation. | 6328 * on the non-existence of an `@proxy` annotation. |
| 5927 * | 6329 * |
| 5928 * If we have other conditional error codes in the future, we should have this c
lass implement some | 6330 * If we have other conditional error codes in the future, we should have this c
lass implement some |
| 5929 * ConditionalErrorCode so that after resolution, a list of ConditionalErrorCode
can be visited | 6331 * ConditionalErrorCode so that after resolution, a list of ConditionalErrorCode
can be visited |
| 5930 * instead of multiple lists of *ConditionalErrorCodes. | 6332 * instead of multiple lists of *ConditionalErrorCodes. |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6562 * @param token the token specifying the location of the error | 6964 * @param token the token specifying the location of the error |
| 6563 * @param arguments the arguments to the error, used to compose the error mess
age | 6965 * @param arguments the arguments to the error, used to compose the error mess
age |
| 6564 */ | 6966 */ |
| 6565 void reportErrorProxyConditionalAnalysisError3(Element enclosingElement, Error
Code errorCode, sc.Token token, List<Object> arguments) { | 6967 void reportErrorProxyConditionalAnalysisError3(Element enclosingElement, Error
Code errorCode, sc.Token token, List<Object> arguments) { |
| 6566 proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclosi
ngElement, new AnalysisError.con2(source, token.offset, token.length, errorCode,
arguments))); | 6968 proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclosi
ngElement, new AnalysisError.con2(source, token.offset, token.length, errorCode,
arguments))); |
| 6567 } | 6969 } |
| 6568 void visitForEachStatementInScope(ForEachStatement node) { | 6970 void visitForEachStatementInScope(ForEachStatement node) { |
| 6569 Expression iterator = node.iterator; | 6971 Expression iterator = node.iterator; |
| 6570 safelyVisit(iterator); | 6972 safelyVisit(iterator); |
| 6571 DeclaredIdentifier loopVariable = node.loopVariable; | 6973 DeclaredIdentifier loopVariable = node.loopVariable; |
| 6974 SimpleIdentifier identifier = node.identifier; |
| 6572 safelyVisit(loopVariable); | 6975 safelyVisit(loopVariable); |
| 6976 safelyVisit(identifier); |
| 6573 Statement body = node.body; | 6977 Statement body = node.body; |
| 6574 if (body != null) { | 6978 if (body != null) { |
| 6575 try { | 6979 try { |
| 6576 overrideManager.enterScope(); | 6980 overrideManager.enterScope(); |
| 6577 if (loopVariable != null && iterator != null) { | 6981 if (loopVariable != null && iterator != null) { |
| 6578 LocalVariableElement loopElement = loopVariable.element; | 6982 LocalVariableElement loopElement = loopVariable.element; |
| 6579 if (loopElement != null) { | 6983 if (loopElement != null) { |
| 6580 Type2 iteratorElementType = getIteratorElementType(iterator); | 6984 Type2 iteratorElementType = getIteratorElementType(iterator); |
| 6581 override2(loopElement, iteratorElementType); | 6985 override2(loopElement, iteratorElementType); |
| 6582 recordPropagatedType(loopVariable.identifier, iteratorElementType); | 6986 recordPropagatedType(loopVariable.identifier, iteratorElementType); |
| 6583 } | 6987 } |
| 6988 } else if (identifier != null && iterator != null) { |
| 6989 Element identifierElement = identifier.staticElement; |
| 6990 if (identifierElement is VariableElement) { |
| 6991 Type2 iteratorElementType = getIteratorElementType(iterator); |
| 6992 override2(identifierElement as VariableElement, iteratorElementType)
; |
| 6993 recordPropagatedType(identifier, iteratorElementType); |
| 6994 } |
| 6584 } | 6995 } |
| 6585 visitStatementInScope(body); | 6996 visitStatementInScope(body); |
| 6586 } finally { | 6997 } finally { |
| 6587 overrideManager.exitScope(); | 6998 overrideManager.exitScope(); |
| 6588 } | 6999 } |
| 6589 } | 7000 } |
| 6590 node.accept(_elementResolver); | 7001 node.accept(_elementResolver); |
| 6591 node.accept(_typeAnalyzer); | 7002 node.accept(_typeAnalyzer); |
| 6592 } | 7003 } |
| 6593 void visitForStatementInScope(ForStatement node) { | 7004 void visitForStatementInScope(ForStatement node) { |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7179 } | 7590 } |
| 7180 | 7591 |
| 7181 /** | 7592 /** |
| 7182 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 7593 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
| 7183 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 7594 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
| 7184 * enabled. | 7595 * enabled. |
| 7185 * | 7596 * |
| 7186 * @param node the statement to be visited | 7597 * @param node the statement to be visited |
| 7187 */ | 7598 */ |
| 7188 void visitForEachStatementInScope(ForEachStatement node) { | 7599 void visitForEachStatementInScope(ForEachStatement node) { |
| 7600 safelyVisit(node.identifier); |
| 7189 safelyVisit(node.iterator); | 7601 safelyVisit(node.iterator); |
| 7190 safelyVisit(node.loopVariable); | 7602 safelyVisit(node.loopVariable); |
| 7191 visitStatementInScope(node.body); | 7603 visitStatementInScope(node.body); |
| 7192 } | 7604 } |
| 7193 | 7605 |
| 7194 /** | 7606 /** |
| 7195 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 7607 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
| 7196 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 7608 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
| 7197 * enabled. | 7609 * enabled. |
| 7198 * | 7610 * |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7745 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a
new expression of | 8157 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a
new expression of |
| 7746 * either the form <i>new T.id(a<sub>1</sub>, …, a<sub>n</sub>)</i> or
the form <i>new | 8158 * either the form <i>new T.id(a<sub>1</sub>, …, a<sub>n</sub>)</i> or
the form <i>new |
| 7747 * T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> | 8159 * T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> |
| 7748 * | 8160 * |
| 7749 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a
constant object | 8161 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a
constant object |
| 7750 * expression of either the form <i>const T.id(a<sub>1</sub>, …, a<sub>
n</sub>)</i> or the | 8162 * expression of either the form <i>const T.id(a<sub>1</sub>, …, a<sub>
n</sub>)</i> or the |
| 7751 * form <i>const T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>. </
blockquote> | 8163 * form <i>const T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>. </
blockquote> |
| 7752 */ | 8164 */ |
| 7753 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 8165 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 7754 recordStaticType(node, node.constructorName.type.type); | 8166 recordStaticType(node, node.constructorName.type.type); |
| 7755 ConstructorElement element = node.element; | 8167 ConstructorElement element = node.staticElement; |
| 7756 if (element != null && "Element" == element.enclosingElement.name) { | 8168 if (element != null && "Element" == element.enclosingElement.name) { |
| 7757 String constructorName = element.name; | 8169 LibraryElement library = element.library; |
| 7758 if ("tag" == constructorName) { | 8170 if (isHtmlLibrary(library)) { |
| 7759 LibraryElement library = element.library; | 8171 String constructorName = element.name; |
| 7760 if (isHtmlLibrary(library)) { | 8172 if ("tag" == constructorName) { |
| 7761 Type2 returnType = getFirstArgumentAsType2(library, node.argumentList,
_HTML_ELEMENT_TO_CLASS_MAP); | 8173 Type2 returnType = getFirstArgumentAsType2(library, node.argumentList,
_HTML_ELEMENT_TO_CLASS_MAP); |
| 7762 if (returnType != null) { | 8174 if (returnType != null) { |
| 7763 recordPropagatedType2(node, returnType); | 8175 recordPropagatedType2(node, returnType); |
| 7764 } | 8176 } |
| 7765 } | 8177 } else { |
| 7766 } else { | |
| 7767 LibraryElement library = element.library; | |
| 7768 if (isHtmlLibrary(library)) { | |
| 7769 Type2 returnType = getElementNameAsType(library, constructorName, _HTM
L_ELEMENT_TO_CLASS_MAP); | 8178 Type2 returnType = getElementNameAsType(library, constructorName, _HTM
L_ELEMENT_TO_CLASS_MAP); |
| 7770 if (returnType != null) { | 8179 if (returnType != null) { |
| 7771 recordPropagatedType2(node, returnType); | 8180 recordPropagatedType2(node, returnType); |
| 7772 } | 8181 } |
| 7773 } | 8182 } |
| 7774 } | 8183 } |
| 7775 } | 8184 } |
| 7776 return null; | 8185 return null; |
| 7777 } | 8186 } |
| 7778 | 8187 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8134 staticType = _typeProvider.typeType; | 8543 staticType = _typeProvider.typeType; |
| 8135 } | 8544 } |
| 8136 } else if (staticElement is FunctionTypeAliasElement) { | 8545 } else if (staticElement is FunctionTypeAliasElement) { |
| 8137 staticType = ((staticElement as FunctionTypeAliasElement)).type; | 8546 staticType = ((staticElement as FunctionTypeAliasElement)).type; |
| 8138 } else if (staticElement is MethodElement) { | 8547 } else if (staticElement is MethodElement) { |
| 8139 staticType = ((staticElement as MethodElement)).type; | 8548 staticType = ((staticElement as MethodElement)).type; |
| 8140 } else if (staticElement is PropertyAccessorElement) { | 8549 } else if (staticElement is PropertyAccessorElement) { |
| 8141 staticType = getType(staticElement as PropertyAccessorElement, node.prefix
.staticType); | 8550 staticType = getType(staticElement as PropertyAccessorElement, node.prefix
.staticType); |
| 8142 } else if (staticElement is ExecutableElement) { | 8551 } else if (staticElement is ExecutableElement) { |
| 8143 staticType = ((staticElement as ExecutableElement)).type; | 8552 staticType = ((staticElement as ExecutableElement)).type; |
| 8144 } else if (staticElement is TypeVariableElement) { | 8553 } else if (staticElement is TypeParameterElement) { |
| 8145 staticType = ((staticElement as TypeVariableElement)).type; | 8554 staticType = ((staticElement as TypeParameterElement)).type; |
| 8146 } else if (staticElement is VariableElement) { | 8555 } else if (staticElement is VariableElement) { |
| 8147 staticType = ((staticElement as VariableElement)).type; | 8556 staticType = ((staticElement as VariableElement)).type; |
| 8148 } | 8557 } |
| 8149 recordStaticType(prefixedIdentifier, staticType); | 8558 recordStaticType(prefixedIdentifier, staticType); |
| 8150 recordStaticType(node, staticType); | 8559 recordStaticType(node, staticType); |
| 8151 Element propagatedElement = prefixedIdentifier.propagatedElement; | 8560 Element propagatedElement = prefixedIdentifier.propagatedElement; |
| 8152 Type2 propagatedType = null; | 8561 Type2 propagatedType = null; |
| 8153 if (propagatedElement is ClassElement) { | 8562 if (propagatedElement is ClassElement) { |
| 8154 if (isNotTypeLiteral(node)) { | 8563 if (isNotTypeLiteral(node)) { |
| 8155 propagatedType = ((propagatedElement as ClassElement)).type; | 8564 propagatedType = ((propagatedElement as ClassElement)).type; |
| 8156 } else { | 8565 } else { |
| 8157 propagatedType = _typeProvider.typeType; | 8566 propagatedType = _typeProvider.typeType; |
| 8158 } | 8567 } |
| 8159 } else if (propagatedElement is FunctionTypeAliasElement) { | 8568 } else if (propagatedElement is FunctionTypeAliasElement) { |
| 8160 propagatedType = ((propagatedElement as FunctionTypeAliasElement)).type; | 8569 propagatedType = ((propagatedElement as FunctionTypeAliasElement)).type; |
| 8161 } else if (propagatedElement is MethodElement) { | 8570 } else if (propagatedElement is MethodElement) { |
| 8162 propagatedType = ((propagatedElement as MethodElement)).type; | 8571 propagatedType = ((propagatedElement as MethodElement)).type; |
| 8163 } else if (propagatedElement is PropertyAccessorElement) { | 8572 } else if (propagatedElement is PropertyAccessorElement) { |
| 8164 propagatedType = getType(propagatedElement as PropertyAccessorElement, nod
e.prefix.staticType); | 8573 propagatedType = getType(propagatedElement as PropertyAccessorElement, nod
e.prefix.staticType); |
| 8165 } else if (propagatedElement is ExecutableElement) { | 8574 } else if (propagatedElement is ExecutableElement) { |
| 8166 propagatedType = ((propagatedElement as ExecutableElement)).type; | 8575 propagatedType = ((propagatedElement as ExecutableElement)).type; |
| 8167 } else if (propagatedElement is TypeVariableElement) { | 8576 } else if (propagatedElement is TypeParameterElement) { |
| 8168 propagatedType = ((propagatedElement as TypeVariableElement)).type; | 8577 propagatedType = ((propagatedElement as TypeParameterElement)).type; |
| 8169 } else if (propagatedElement is VariableElement) { | 8578 } else if (propagatedElement is VariableElement) { |
| 8170 propagatedType = ((propagatedElement as VariableElement)).type; | 8579 propagatedType = ((propagatedElement as VariableElement)).type; |
| 8171 } | 8580 } |
| 8172 Type2 overriddenType = _overrideManager.getType(propagatedElement); | 8581 Type2 overriddenType = _overrideManager.getType(propagatedElement); |
| 8173 if (propagatedType == null || (overriddenType != null && overriddenType.isMo
reSpecificThan(propagatedType))) { | 8582 if (propagatedType == null || (overriddenType != null && overriddenType.isMo
reSpecificThan(propagatedType))) { |
| 8174 propagatedType = overriddenType; | 8583 propagatedType = overriddenType; |
| 8175 } | 8584 } |
| 8176 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 8585 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
| 8177 recordPropagatedType2(prefixedIdentifier, propagatedType); | 8586 recordPropagatedType2(prefixedIdentifier, propagatedType); |
| 8178 recordPropagatedType2(node, propagatedType); | 8587 recordPropagatedType2(node, propagatedType); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8333 staticType = _typeProvider.typeType; | 8742 staticType = _typeProvider.typeType; |
| 8334 } | 8743 } |
| 8335 } else if (element is FunctionTypeAliasElement) { | 8744 } else if (element is FunctionTypeAliasElement) { |
| 8336 staticType = ((element as FunctionTypeAliasElement)).type; | 8745 staticType = ((element as FunctionTypeAliasElement)).type; |
| 8337 } else if (element is MethodElement) { | 8746 } else if (element is MethodElement) { |
| 8338 staticType = ((element as MethodElement)).type; | 8747 staticType = ((element as MethodElement)).type; |
| 8339 } else if (element is PropertyAccessorElement) { | 8748 } else if (element is PropertyAccessorElement) { |
| 8340 staticType = getType(element as PropertyAccessorElement, null); | 8749 staticType = getType(element as PropertyAccessorElement, null); |
| 8341 } else if (element is ExecutableElement) { | 8750 } else if (element is ExecutableElement) { |
| 8342 staticType = ((element as ExecutableElement)).type; | 8751 staticType = ((element as ExecutableElement)).type; |
| 8343 } else if (element is TypeVariableElement) { | 8752 } else if (element is TypeParameterElement) { |
| 8344 staticType = ((element as TypeVariableElement)).type; | 8753 staticType = ((element as TypeParameterElement)).type; |
| 8345 } else if (element is VariableElement) { | 8754 } else if (element is VariableElement) { |
| 8346 staticType = ((element as VariableElement)).type; | 8755 staticType = ((element as VariableElement)).type; |
| 8347 } else if (element is PrefixElement) { | 8756 } else if (element is PrefixElement) { |
| 8348 return null; | 8757 return null; |
| 8349 } else { | 8758 } else { |
| 8350 staticType = _dynamicType; | 8759 staticType = _dynamicType; |
| 8351 } | 8760 } |
| 8352 recordStaticType(node, staticType); | 8761 recordStaticType(node, staticType); |
| 8353 Type2 propagatedType = _overrideManager.getType(element); | 8762 Type2 propagatedType = _overrideManager.getType(element); |
| 8354 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 8763 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8459 * @param body the boy of the function whose propagated return type is to be c
omputed | 8868 * @param body the boy of the function whose propagated return type is to be c
omputed |
| 8460 * @return the propagated return type that was computed | 8869 * @return the propagated return type that was computed |
| 8461 */ | 8870 */ |
| 8462 Type2 computePropagatedReturnType2(FunctionBody body) { | 8871 Type2 computePropagatedReturnType2(FunctionBody body) { |
| 8463 if (body is ExpressionFunctionBody) { | 8872 if (body is ExpressionFunctionBody) { |
| 8464 ExpressionFunctionBody expressionBody = body as ExpressionFunctionBody; | 8873 ExpressionFunctionBody expressionBody = body as ExpressionFunctionBody; |
| 8465 return expressionBody.expression.bestType; | 8874 return expressionBody.expression.bestType; |
| 8466 } | 8875 } |
| 8467 if (body is BlockFunctionBody) { | 8876 if (body is BlockFunctionBody) { |
| 8468 List<Type2> result = [null]; | 8877 List<Type2> result = [null]; |
| 8469 body.accept(new GeneralizingASTVisitor_8(result)); | 8878 body.accept(new GeneralizingASTVisitor_7(result)); |
| 8470 return result[0]; | 8879 return result[0]; |
| 8471 } | 8880 } |
| 8472 return null; | 8881 return null; |
| 8473 } | 8882 } |
| 8474 | 8883 |
| 8475 /** | 8884 /** |
| 8476 * Compute the static return type of the method or function represented by the
given element. | 8885 * Compute the static return type of the method or function represented by the
given element. |
| 8477 * | 8886 * |
| 8478 * @param element the element representing the method or function invoked by t
he given node | 8887 * @param element the element representing the method or function invoked by t
he given node |
| 8479 * @return the static return type that was computed | 8888 * @return the static return type that was computed |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8678 PropertyAccessorElement getter = accessor.variable.getter; | 9087 PropertyAccessorElement getter = accessor.variable.getter; |
| 8679 if (getter != null) { | 9088 if (getter != null) { |
| 8680 functionType = getter.type; | 9089 functionType = getter.type; |
| 8681 if (functionType != null) { | 9090 if (functionType != null) { |
| 8682 return functionType.returnType; | 9091 return functionType.returnType; |
| 8683 } | 9092 } |
| 8684 } | 9093 } |
| 8685 return _dynamicType; | 9094 return _dynamicType; |
| 8686 } | 9095 } |
| 8687 Type2 returnType = functionType.returnType; | 9096 Type2 returnType = functionType.returnType; |
| 8688 if (returnType is TypeVariableType && context is InterfaceType) { | 9097 if (returnType is TypeParameterType && context is InterfaceType) { |
| 8689 InterfaceType interfaceTypeContext = context as InterfaceType; | 9098 InterfaceType interfaceTypeContext = context as InterfaceType; |
| 8690 List<TypeVariableElement> parameterElements = interfaceTypeContext.element
!= null ? interfaceTypeContext.element.typeVariables : null; | 9099 List<TypeParameterElement> typeParameterElements = interfaceTypeContext.el
ement != null ? interfaceTypeContext.element.typeParameters : null; |
| 8691 if (parameterElements != null) { | 9100 if (typeParameterElements != null) { |
| 8692 for (int i = 0; i < parameterElements.length; i++) { | 9101 for (int i = 0; i < typeParameterElements.length; i++) { |
| 8693 TypeVariableElement varElt = parameterElements[i]; | 9102 TypeParameterElement typeParameterElement = typeParameterElements[i]; |
| 8694 if (returnType.name == varElt.name) { | 9103 if (returnType.name == typeParameterElement.name) { |
| 8695 return interfaceTypeContext.typeArguments[i]; | 9104 return interfaceTypeContext.typeArguments[i]; |
| 8696 } | 9105 } |
| 8697 } | 9106 } |
| 8698 } | 9107 } |
| 8699 } | 9108 } |
| 8700 return returnType; | 9109 return returnType; |
| 8701 } | 9110 } |
| 8702 | 9111 |
| 8703 /** | 9112 /** |
| 8704 * Return the type represented by the given type name. | 9113 * Return the type represented by the given type name. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8802 * | 9211 * |
| 8803 * @param node the binary expression to analyze | 9212 * @param node the binary expression to analyze |
| 8804 * @param staticType the static type of the expression as resolved | 9213 * @param staticType the static type of the expression as resolved |
| 8805 * @return the better type guess, or the same static type as given | 9214 * @return the better type guess, or the same static type as given |
| 8806 */ | 9215 */ |
| 8807 Type2 refineBinaryExpressionType(BinaryExpression node, Type2 staticType) { | 9216 Type2 refineBinaryExpressionType(BinaryExpression node, Type2 staticType) { |
| 8808 sc.TokenType operator = node.operator.type; | 9217 sc.TokenType operator = node.operator.type; |
| 8809 if (identical(operator, sc.TokenType.AMPERSAND_AMPERSAND) || identical(opera
tor, sc.TokenType.BAR_BAR) || identical(operator, sc.TokenType.EQ_EQ) || identic
al(operator, sc.TokenType.BANG_EQ)) { | 9218 if (identical(operator, sc.TokenType.AMPERSAND_AMPERSAND) || identical(opera
tor, sc.TokenType.BAR_BAR) || identical(operator, sc.TokenType.EQ_EQ) || identic
al(operator, sc.TokenType.BANG_EQ)) { |
| 8810 return _typeProvider.boolType; | 9219 return _typeProvider.boolType; |
| 8811 } | 9220 } |
| 8812 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.TokenT
ype.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc
.TokenType.STAR)) { | 9221 Type2 intType = _typeProvider.intType; |
| 8813 Type2 doubleType = _typeProvider.doubleType; | 9222 if (getStaticType(node.leftOperand) == intType) { |
| 8814 if (identical(getStaticType(node.leftOperand), _typeProvider.intType) && i
dentical(getStaticType(node.rightOperand), doubleType)) { | 9223 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.Toke
nType.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator,
sc.TokenType.STAR)) { |
| 8815 return doubleType; | 9224 Type2 doubleType = _typeProvider.doubleType; |
| 9225 if (getStaticType(node.rightOperand) == doubleType) { |
| 9226 return doubleType; |
| 9227 } |
| 8816 } | 9228 } |
| 8817 } | 9229 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.Toke
nType.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator,
sc.TokenType.STAR) || identical(operator, sc.TokenType.TILDE_SLASH)) { |
| 8818 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.TokenT
ype.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc
.TokenType.STAR) || identical(operator, sc.TokenType.TILDE_SLASH)) { | 9230 if (getStaticType(node.rightOperand) == intType) { |
| 8819 Type2 intType = _typeProvider.intType; | 9231 staticType = intType; |
| 8820 if (identical(getStaticType(node.leftOperand), intType) && identical(getSt
aticType(node.rightOperand), intType)) { | 9232 } |
| 8821 staticType = intType; | |
| 8822 } | 9233 } |
| 8823 } | 9234 } |
| 8824 return staticType; | 9235 return staticType; |
| 8825 } | 9236 } |
| 8826 get thisType_J2DAccessor => _thisType; | 9237 get thisType_J2DAccessor => _thisType; |
| 8827 set thisType_J2DAccessor(__v) => _thisType = __v; | 9238 set thisType_J2DAccessor(__v) => _thisType = __v; |
| 8828 } | 9239 } |
| 8829 class GeneralizingASTVisitor_8 extends GeneralizingASTVisitor<Object> { | 9240 class GeneralizingASTVisitor_7 extends GeneralizingASTVisitor<Object> { |
| 8830 List<Type2> result; | 9241 List<Type2> result; |
| 8831 GeneralizingASTVisitor_8(this.result) : super(); | 9242 GeneralizingASTVisitor_7(this.result) : super(); |
| 8832 Object visitExpression(Expression node) => null; | 9243 Object visitExpression(Expression node) => null; |
| 8833 Object visitReturnStatement(ReturnStatement node) { | 9244 Object visitReturnStatement(ReturnStatement node) { |
| 8834 Type2 type; | 9245 Type2 type; |
| 8835 Expression expression = node.expression; | 9246 Expression expression = node.expression; |
| 8836 if (expression != null) { | 9247 if (expression != null) { |
| 8837 type = expression.bestType; | 9248 type = expression.bestType; |
| 8838 } else { | 9249 } else { |
| 8839 type = BottomTypeImpl.instance; | 9250 type = BottomTypeImpl.instance; |
| 8840 } | 9251 } |
| 8841 if (result[0] == null) { | 9252 if (result[0] == null) { |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9619 node.type = _dynamicType; | 10030 node.type = _dynamicType; |
| 9620 return null; | 10031 return null; |
| 9621 } | 10032 } |
| 9622 Type2 type = null; | 10033 Type2 type = null; |
| 9623 if (element is ClassElement) { | 10034 if (element is ClassElement) { |
| 9624 setElement(typeName, element); | 10035 setElement(typeName, element); |
| 9625 type = ((element as ClassElement)).type; | 10036 type = ((element as ClassElement)).type; |
| 9626 } else if (element is FunctionTypeAliasElement) { | 10037 } else if (element is FunctionTypeAliasElement) { |
| 9627 setElement(typeName, element); | 10038 setElement(typeName, element); |
| 9628 type = ((element as FunctionTypeAliasElement)).type; | 10039 type = ((element as FunctionTypeAliasElement)).type; |
| 9629 } else if (element is TypeVariableElement) { | 10040 } else if (element is TypeParameterElement) { |
| 9630 setElement(typeName, element); | 10041 setElement(typeName, element); |
| 9631 type = ((element as TypeVariableElement)).type; | 10042 type = ((element as TypeParameterElement)).type; |
| 9632 if (argumentList != null) { | 10043 if (argumentList != null) { |
| 9633 } | 10044 } |
| 9634 } else if (element is MultiplyDefinedElement) { | 10045 } else if (element is MultiplyDefinedElement) { |
| 9635 List<Element> elements = ((element as MultiplyDefinedElement)).conflicting
Elements; | 10046 List<Element> elements = ((element as MultiplyDefinedElement)).conflicting
Elements; |
| 9636 type = getType(elements); | 10047 type = getType(elements); |
| 9637 if (type != null) { | 10048 if (type != null) { |
| 9638 node.type = type; | 10049 node.type = type; |
| 9639 } | 10050 } |
| 9640 } else { | 10051 } else { |
| 9641 if (isTypeNameInCatchClause(node)) { | 10052 if (isTypeNameInCatchClause(node)) { |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10104 */ | 10515 */ |
| 10105 void setFunctionTypedParameterType(ParameterElementImpl element, TypeName retu
rnType2, FormalParameterList parameterList) { | 10516 void setFunctionTypedParameterType(ParameterElementImpl element, TypeName retu
rnType2, FormalParameterList parameterList) { |
| 10106 List<ParameterElement> parameters = getElements(parameterList); | 10517 List<ParameterElement> parameters = getElements(parameterList); |
| 10107 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl
(null); | 10518 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl
(null); |
| 10108 aliasElement.synthetic = true; | 10519 aliasElement.synthetic = true; |
| 10109 aliasElement.shareParameters(parameters); | 10520 aliasElement.shareParameters(parameters); |
| 10110 aliasElement.returnType = computeReturnType(returnType2); | 10521 aliasElement.returnType = computeReturnType(returnType2); |
| 10111 FunctionTypeImpl type = new FunctionTypeImpl.con2(aliasElement); | 10522 FunctionTypeImpl type = new FunctionTypeImpl.con2(aliasElement); |
| 10112 ClassElement definingClass = element.getAncestor(ClassElement); | 10523 ClassElement definingClass = element.getAncestor(ClassElement); |
| 10113 if (definingClass != null) { | 10524 if (definingClass != null) { |
| 10114 aliasElement.shareTypeVariables(definingClass.typeVariables); | 10525 aliasElement.shareTypeParameters(definingClass.typeParameters); |
| 10115 type.typeArguments = definingClass.type.typeArguments; | 10526 type.typeArguments = definingClass.type.typeArguments; |
| 10116 } else { | 10527 } else { |
| 10117 FunctionTypeAliasElement alias = element.getAncestor(FunctionTypeAliasElem
ent); | 10528 FunctionTypeAliasElement alias = element.getAncestor(FunctionTypeAliasElem
ent); |
| 10118 while (alias != null && alias.isSynthetic) { | 10529 while (alias != null && alias.isSynthetic) { |
| 10119 alias = alias.getAncestor(FunctionTypeAliasElement); | 10530 alias = alias.getAncestor(FunctionTypeAliasElement); |
| 10120 } | 10531 } |
| 10121 if (alias != null) { | 10532 if (alias != null) { |
| 10122 aliasElement.typeVariables = alias.typeVariables; | 10533 aliasElement.typeParameters = alias.typeParameters; |
| 10123 type.typeArguments = alias.type.typeArguments; | 10534 type.typeArguments = alias.type.typeArguments; |
| 10124 } else { | 10535 } else { |
| 10125 type.typeArguments = TypeVariableTypeImpl.EMPTY_ARRAY; | 10536 type.typeArguments = TypeImpl.EMPTY_ARRAY; |
| 10126 } | 10537 } |
| 10127 } | 10538 } |
| 10128 element.type = type; | 10539 element.type = type; |
| 10129 } | 10540 } |
| 10130 } | 10541 } |
| 10131 /** | 10542 /** |
| 10132 * Instances of the class `ClassScope` implement the scope defined by a class. | 10543 * Instances of the class `ClassScope` implement the scope defined by a class. |
| 10133 * | 10544 * |
| 10134 * @coverage dart.engine.resolver | 10545 * @coverage dart.engine.resolver |
| 10135 */ | 10546 */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10170 } | 10581 } |
| 10171 } | 10582 } |
| 10172 | 10583 |
| 10173 /** | 10584 /** |
| 10174 * Define the type parameters for the class. | 10585 * Define the type parameters for the class. |
| 10175 * | 10586 * |
| 10176 * @param typeElement the element representing the type represented by this sc
ope | 10587 * @param typeElement the element representing the type represented by this sc
ope |
| 10177 */ | 10588 */ |
| 10178 void defineTypeParameters(ClassElement typeElement) { | 10589 void defineTypeParameters(ClassElement typeElement) { |
| 10179 Scope parameterScope = enclosingScope; | 10590 Scope parameterScope = enclosingScope; |
| 10180 for (TypeVariableElement parameter in typeElement.typeVariables) { | 10591 for (TypeParameterElement typeParameter in typeElement.typeParameters) { |
| 10181 parameterScope.define(parameter); | 10592 parameterScope.define(typeParameter); |
| 10182 } | 10593 } |
| 10183 } | 10594 } |
| 10184 } | 10595 } |
| 10185 /** | 10596 /** |
| 10186 * Instances of the class `EnclosedScope` implement a scope that is lexically en
closed in | 10597 * Instances of the class `EnclosedScope` implement a scope that is lexically en
closed in |
| 10187 * another scope. | 10598 * another scope. |
| 10188 * | 10599 * |
| 10189 * @coverage dart.engine.resolver | 10600 * @coverage dart.engine.resolver |
| 10190 */ | 10601 */ |
| 10191 class EnclosedScope extends Scope { | 10602 class EnclosedScope extends Scope { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10283 */ | 10694 */ |
| 10284 class FunctionTypeScope extends EnclosedScope { | 10695 class FunctionTypeScope extends EnclosedScope { |
| 10285 | 10696 |
| 10286 /** | 10697 /** |
| 10287 * Initialize a newly created scope enclosed within another scope. | 10698 * Initialize a newly created scope enclosed within another scope. |
| 10288 * | 10699 * |
| 10289 * @param enclosingScope the scope in which this scope is lexically enclosed | 10700 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 10290 * @param typeElement the element representing the type alias represented by t
his scope | 10701 * @param typeElement the element representing the type alias represented by t
his scope |
| 10291 */ | 10702 */ |
| 10292 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement)
: super(new EnclosedScope(enclosingScope)) { | 10703 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement)
: super(new EnclosedScope(enclosingScope)) { |
| 10293 defineTypeVariables(typeElement); | 10704 defineTypeParameters(typeElement); |
| 10294 defineParameters(typeElement); | 10705 defineParameters(typeElement); |
| 10295 } | 10706 } |
| 10296 | 10707 |
| 10297 /** | 10708 /** |
| 10298 * Define the parameters for the function type alias. | 10709 * Define the parameters for the function type alias. |
| 10299 * | 10710 * |
| 10300 * @param typeElement the element representing the type represented by this sc
ope | 10711 * @param typeElement the element representing the type represented by this sc
ope |
| 10301 */ | 10712 */ |
| 10302 void defineParameters(FunctionTypeAliasElement typeElement) { | 10713 void defineParameters(FunctionTypeAliasElement typeElement) { |
| 10303 for (ParameterElement parameter in typeElement.parameters) { | 10714 for (ParameterElement parameter in typeElement.parameters) { |
| 10304 define(parameter); | 10715 define(parameter); |
| 10305 } | 10716 } |
| 10306 } | 10717 } |
| 10307 | 10718 |
| 10308 /** | 10719 /** |
| 10309 * Define the type variables for the function type alias. | 10720 * Define the type parameters for the function type alias. |
| 10310 * | 10721 * |
| 10311 * @param typeElement the element representing the type represented by this sc
ope | 10722 * @param typeElement the element representing the type represented by this sc
ope |
| 10312 */ | 10723 */ |
| 10313 void defineTypeVariables(FunctionTypeAliasElement typeElement) { | 10724 void defineTypeParameters(FunctionTypeAliasElement typeElement) { |
| 10314 Scope typeVariableScope = enclosingScope; | 10725 Scope typeParameterScope = enclosingScope; |
| 10315 for (TypeVariableElement typeVariable in typeElement.typeVariables) { | 10726 for (TypeParameterElement typeParameter in typeElement.typeParameters) { |
| 10316 typeVariableScope.define(typeVariable); | 10727 typeParameterScope.define(typeParameter); |
| 10317 } | 10728 } |
| 10318 } | 10729 } |
| 10319 } | 10730 } |
| 10320 /** | 10731 /** |
| 10321 * Instances of the class `LabelScope` represent a scope in which a single label
is defined. | 10732 * Instances of the class `LabelScope` represent a scope in which a single label
is defined. |
| 10322 * | 10733 * |
| 10323 * @coverage dart.engine.resolver | 10734 * @coverage dart.engine.resolver |
| 10324 */ | 10735 */ |
| 10325 class LabelScope { | 10736 class LabelScope { |
| 10326 | 10737 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10446 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library) { | 10857 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library) { |
| 10447 Element foundElement = localLookup(name, referencingLibrary); | 10858 Element foundElement = localLookup(name, referencingLibrary); |
| 10448 if (foundElement != null) { | 10859 if (foundElement != null) { |
| 10449 return foundElement; | 10860 return foundElement; |
| 10450 } | 10861 } |
| 10451 for (Namespace nameSpace in _importedNamespaces) { | 10862 for (Namespace nameSpace in _importedNamespaces) { |
| 10452 Element element = nameSpace.get(name); | 10863 Element element = nameSpace.get(name); |
| 10453 if (element != null) { | 10864 if (element != null) { |
| 10454 if (foundElement == null) { | 10865 if (foundElement == null) { |
| 10455 foundElement = element; | 10866 foundElement = element; |
| 10456 } else { | 10867 } else if (foundElement != element) { |
| 10457 foundElement = new MultiplyDefinedElementImpl(_definingLibrary.context
, foundElement, element); | 10868 foundElement = new MultiplyDefinedElementImpl.con1(_definingLibrary.co
ntext, foundElement, element); |
| 10458 } | 10869 } |
| 10459 } | 10870 } |
| 10460 } | 10871 } |
| 10461 if (foundElement is MultiplyDefinedElementImpl) { | 10872 if (foundElement is MultiplyDefinedElementImpl) { |
| 10873 foundElement = removeSdkElements(foundElement as MultiplyDefinedElementImp
l); |
| 10874 } |
| 10875 if (foundElement is MultiplyDefinedElementImpl) { |
| 10462 String foundEltName = foundElement.displayName; | 10876 String foundEltName = foundElement.displayName; |
| 10463 String libName1 = "", libName2 = ""; | 10877 String libName1 = "", libName2 = ""; |
| 10464 List<Element> conflictingMembers = ((foundElement as MultiplyDefinedElemen
tImpl)).conflictingElements; | 10878 List<Element> conflictingMembers = ((foundElement as MultiplyDefinedElemen
tImpl)).conflictingElements; |
| 10465 LibraryElement enclosingLibrary = conflictingMembers[0].getAncestor(Librar
yElement); | 10879 LibraryElement enclosingLibrary = conflictingMembers[0].getAncestor(Librar
yElement); |
| 10466 if (enclosingLibrary != null) { | 10880 if (enclosingLibrary != null) { |
| 10467 libName1 = enclosingLibrary.definingCompilationUnit.displayName; | 10881 libName1 = enclosingLibrary.definingCompilationUnit.displayName; |
| 10468 } | 10882 } |
| 10469 enclosingLibrary = conflictingMembers[1].getAncestor(LibraryElement); | 10883 enclosingLibrary = conflictingMembers[1].getAncestor(LibraryElement); |
| 10470 if (enclosingLibrary != null) { | 10884 if (enclosingLibrary != null) { |
| 10471 libName2 = enclosingLibrary.definingCompilationUnit.displayName; | 10885 libName2 = enclosingLibrary.definingCompilationUnit.displayName; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 10485 * | 10899 * |
| 10486 * @param definingLibrary the element representing the library that imports th
e libraries for | 10900 * @param definingLibrary the element representing the library that imports th
e libraries for |
| 10487 * which namespaces will be created | 10901 * which namespaces will be created |
| 10488 */ | 10902 */ |
| 10489 void createImportedNamespaces(LibraryElement definingLibrary) { | 10903 void createImportedNamespaces(LibraryElement definingLibrary) { |
| 10490 NamespaceBuilder builder = new NamespaceBuilder(); | 10904 NamespaceBuilder builder = new NamespaceBuilder(); |
| 10491 for (ImportElement element in definingLibrary.imports) { | 10905 for (ImportElement element in definingLibrary.imports) { |
| 10492 _importedNamespaces.add(builder.createImportNamespace(element)); | 10906 _importedNamespaces.add(builder.createImportNamespace(element)); |
| 10493 } | 10907 } |
| 10494 } | 10908 } |
| 10909 |
| 10910 /** |
| 10911 * Given a collection of elements that a single name could all be mapped to, r
emove from the list |
| 10912 * all of the names defined in the SDK. Return the element(s) that remain. |
| 10913 * |
| 10914 * @param foundElement the element encapsulating the collection of elements |
| 10915 * @return all of the elements that are not defined in the SDK |
| 10916 */ |
| 10917 Element removeSdkElements(MultiplyDefinedElementImpl foundElement) { |
| 10918 List<Element> conflictingMembers = foundElement.conflictingElements; |
| 10919 int length = conflictingMembers.length; |
| 10920 int to = 0; |
| 10921 for (Element member in conflictingMembers) { |
| 10922 if (!member.library.isInSdk) { |
| 10923 conflictingMembers[to++] = member; |
| 10924 } |
| 10925 } |
| 10926 if (to == length) { |
| 10927 return foundElement; |
| 10928 } else if (to == 1) { |
| 10929 return conflictingMembers[0]; |
| 10930 } |
| 10931 List<Element> remaining = new List<Element>(to); |
| 10932 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to); |
| 10933 return new MultiplyDefinedElementImpl.con2(_definingLibrary.context, remaini
ng); |
| 10934 } |
| 10495 } | 10935 } |
| 10496 /** | 10936 /** |
| 10497 * Instances of the class `LibraryScope` implement a scope containing all of the
names defined | 10937 * Instances of the class `LibraryScope` implement a scope containing all of the
names defined |
| 10498 * in a given library. | 10938 * in a given library. |
| 10499 * | 10939 * |
| 10500 * @coverage dart.engine.resolver | 10940 * @coverage dart.engine.resolver |
| 10501 */ | 10941 */ |
| 10502 class LibraryScope extends EnclosedScope { | 10942 class LibraryScope extends EnclosedScope { |
| 10503 | 10943 |
| 10504 /** | 10944 /** |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11149 result = validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_WI
TH_NON_CONSTANT_VALUE); | 11589 result = validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_WI
TH_NON_CONSTANT_VALUE); |
| 11150 element.evaluationResult = result; | 11590 element.evaluationResult = result; |
| 11151 } else if (result is ErrorResult) { | 11591 } else if (result is ErrorResult) { |
| 11152 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON
STANT_VALUE); | 11592 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON
STANT_VALUE); |
| 11153 } | 11593 } |
| 11154 } | 11594 } |
| 11155 return null; | 11595 return null; |
| 11156 } | 11596 } |
| 11157 | 11597 |
| 11158 /** | 11598 /** |
| 11159 * Return `true` if the given value is the result of evaluating an expression
whose value is | |
| 11160 * a valid key in a const map literal. Keys in const map literals must be eith
er a string, number, | |
| 11161 * boolean, list, map, or null. | |
| 11162 * | |
| 11163 * @param value | |
| 11164 * @return `true` if the given value is a valid key in a const map literal | |
| 11165 */ | |
| 11166 bool isValidConstMapKey(Object value) => true; | |
| 11167 | |
| 11168 /** | |
| 11169 * If the given result represents one or more errors, report those errors. Exc
ept for special | 11599 * If the given result represents one or more errors, report those errors. Exc
ept for special |
| 11170 * cases, use the given error code rather than the one reported in the error. | 11600 * cases, use the given error code rather than the one reported in the error. |
| 11171 * | 11601 * |
| 11172 * @param result the result containing any errors that need to be reported | 11602 * @param result the result containing any errors that need to be reported |
| 11173 * @param errorCode the error code to be used if the result represents an erro
r | 11603 * @param errorCode the error code to be used if the result represents an erro
r |
| 11174 */ | 11604 */ |
| 11175 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode2) { | 11605 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode2) { |
| 11176 if (result is ErrorResult) { | 11606 if (result is ErrorResult) { |
| 11177 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { | 11607 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { |
| 11178 ErrorCode dataErrorCode = data.errorCode; | 11608 ErrorCode dataErrorCode = data.errorCode; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11254 } | 11684 } |
| 11255 | 11685 |
| 11256 /** | 11686 /** |
| 11257 * Validates that the given expression is a compile time constant. | 11687 * Validates that the given expression is a compile time constant. |
| 11258 * | 11688 * |
| 11259 * @param parameterElements the elements of parameters of constant constructor
, they are | 11689 * @param parameterElements the elements of parameters of constant constructor
, they are |
| 11260 * considered as a valid potentially constant expressions | 11690 * considered as a valid potentially constant expressions |
| 11261 * @param expression the expression to validate | 11691 * @param expression the expression to validate |
| 11262 */ | 11692 */ |
| 11263 void validateInitializerExpression(List<ParameterElement> parameterElements, E
xpression expression) { | 11693 void validateInitializerExpression(List<ParameterElement> parameterElements, E
xpression expression) { |
| 11264 EvaluationResultImpl result = expression.accept(new ConstantVisitor_12(this,
parameterElements)); | 11694 EvaluationResultImpl result = expression.accept(new ConstantVisitor_11(this,
parameterElements)); |
| 11265 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER)
; | 11695 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER)
; |
| 11266 } | 11696 } |
| 11267 | 11697 |
| 11268 /** | 11698 /** |
| 11269 * Validates that all of the arguments of a constructor initializer are compil
e time constants. | 11699 * Validates that all of the arguments of a constructor initializer are compil
e time constants. |
| 11270 * | 11700 * |
| 11271 * @param parameterElements the elements of parameters of constant constructor
, they are | 11701 * @param parameterElements the elements of parameters of constant constructor
, they are |
| 11272 * considered as a valid potentially constant expressions | 11702 * considered as a valid potentially constant expressions |
| 11273 * @param argumentList the argument list to validate | 11703 * @param argumentList the argument list to validate |
| 11274 */ | 11704 */ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 11299 RedirectingConstructorInvocation invocation = initializer as Redirecting
ConstructorInvocation; | 11729 RedirectingConstructorInvocation invocation = initializer as Redirecting
ConstructorInvocation; |
| 11300 validateInitializerInvocationArguments(parameterElements, invocation.arg
umentList); | 11730 validateInitializerInvocationArguments(parameterElements, invocation.arg
umentList); |
| 11301 } | 11731 } |
| 11302 if (initializer is SuperConstructorInvocation) { | 11732 if (initializer is SuperConstructorInvocation) { |
| 11303 SuperConstructorInvocation invocation = initializer as SuperConstructorI
nvocation; | 11733 SuperConstructorInvocation invocation = initializer as SuperConstructorI
nvocation; |
| 11304 validateInitializerInvocationArguments(parameterElements, invocation.arg
umentList); | 11734 validateInitializerInvocationArguments(parameterElements, invocation.arg
umentList); |
| 11305 } | 11735 } |
| 11306 } | 11736 } |
| 11307 } | 11737 } |
| 11308 } | 11738 } |
| 11309 class ConstantVisitor_12 extends ConstantVisitor { | 11739 class ConstantVisitor_11 extends ConstantVisitor { |
| 11310 final ConstantVerifier ConstantVerifier_this; | 11740 final ConstantVerifier ConstantVerifier_this; |
| 11311 List<ParameterElement> parameterElements; | 11741 List<ParameterElement> parameterElements; |
| 11312 ConstantVisitor_12(this.ConstantVerifier_this, this.parameterElements) : super
(); | 11742 ConstantVisitor_11(this.ConstantVerifier_this, this.parameterElements) : super
(); |
| 11313 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { | 11743 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { |
| 11314 Element element = node.staticElement; | 11744 Element element = node.staticElement; |
| 11315 for (ParameterElement parameterElement in parameterElements) { | 11745 for (ParameterElement parameterElement in parameterElements) { |
| 11316 if (identical(parameterElement, element) && parameterElement != null) { | 11746 if (identical(parameterElement, element) && parameterElement != null) { |
| 11317 Type2 type = parameterElement.type; | 11747 Type2 type = parameterElement.type; |
| 11318 if (type != null) { | 11748 if (type != null) { |
| 11319 if (type.isDynamic) { | 11749 if (type.isDynamic) { |
| 11320 return ValidResult.RESULT_DYNAMIC; | 11750 return ValidResult.RESULT_DYNAMIC; |
| 11321 } | 11751 } |
| 11322 if (type.isSubtypeOf(ConstantVerifier_this._boolType)) { | 11752 if (type.isSubtypeOf(ConstantVerifier_this._boolType)) { |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11978 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 12408 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 11979 checkForFinalNotInitialized2(node.variables); | 12409 checkForFinalNotInitialized2(node.variables); |
| 11980 return super.visitTopLevelVariableDeclaration(node); | 12410 return super.visitTopLevelVariableDeclaration(node); |
| 11981 } | 12411 } |
| 11982 Object visitTypeName(TypeName node) { | 12412 Object visitTypeName(TypeName node) { |
| 11983 checkForTypeArgumentNotMatchingBounds(node); | 12413 checkForTypeArgumentNotMatchingBounds(node); |
| 11984 checkForTypeParameterReferencedByStatic(node); | 12414 checkForTypeParameterReferencedByStatic(node); |
| 11985 return super.visitTypeName(node); | 12415 return super.visitTypeName(node); |
| 11986 } | 12416 } |
| 11987 Object visitTypeParameter(TypeParameter node) { | 12417 Object visitTypeParameter(TypeParameter node) { |
| 11988 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPE_VARIABLE_NAME); | 12418 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPE_PARAMETER_NAME); |
| 11989 return super.visitTypeParameter(node); | 12419 return super.visitTypeParameter(node); |
| 11990 } | 12420 } |
| 11991 Object visitVariableDeclaration(VariableDeclaration node) { | 12421 Object visitVariableDeclaration(VariableDeclaration node) { |
| 11992 SimpleIdentifier nameNode = node.name; | 12422 SimpleIdentifier nameNode = node.name; |
| 11993 Expression initializerNode = node.initializer; | 12423 Expression initializerNode = node.initializer; |
| 11994 checkForInvalidAssignment2(nameNode, initializerNode); | 12424 checkForInvalidAssignment2(nameNode, initializerNode); |
| 11995 nameNode.accept(this); | 12425 nameNode.accept(this); |
| 11996 String name = nameNode.name; | 12426 String name = nameNode.name; |
| 11997 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name); | 12427 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name); |
| 11998 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; | 12428 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12087 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { | 12517 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { |
| 12088 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_B
Y_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); | 12518 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_B
Y_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); |
| 12089 foundError = true; | 12519 foundError = true; |
| 12090 } | 12520 } |
| 12091 } | 12521 } |
| 12092 } | 12522 } |
| 12093 } | 12523 } |
| 12094 for (MapEntry<FieldElement, INIT_STATE> entry in getMapEntrySet(fieldElement
sMap)) { | 12524 for (MapEntry<FieldElement, INIT_STATE> entry in getMapEntrySet(fieldElement
sMap)) { |
| 12095 if (identical(entry.getValue(), INIT_STATE.NOT_INIT)) { | 12525 if (identical(entry.getValue(), INIT_STATE.NOT_INIT)) { |
| 12096 FieldElement fieldElement = entry.getKey(); | 12526 FieldElement fieldElement = entry.getKey(); |
| 12097 if (fieldElement.isFinal || fieldElement.isConst) { | 12527 if (fieldElement.isConst) { |
| 12528 _errorReporter.reportError2(CompileTimeErrorCode.CONST_NOT_INITIALIZED
, node.returnType, [fieldElement.name]); |
| 12529 foundError = true; |
| 12530 } else if (fieldElement.isFinal) { |
| 12098 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, n
ode.returnType, [fieldElement.name]); | 12531 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, n
ode.returnType, [fieldElement.name]); |
| 12099 foundError = true; | 12532 foundError = true; |
| 12100 } | 12533 } |
| 12101 } | 12534 } |
| 12102 } | 12535 } |
| 12103 return foundError; | 12536 return foundError; |
| 12104 } | 12537 } |
| 12105 | 12538 |
| 12106 /** | 12539 /** |
| 12107 * This checks the passed executable element against override-error codes. | 12540 * This checks the passed executable element against override-error codes. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12171 return false; | 12604 return false; |
| 12172 } | 12605 } |
| 12173 Type2 overridingFTReturnType = overridingFT.returnType; | 12606 Type2 overridingFTReturnType = overridingFT.returnType; |
| 12174 Type2 overriddenFTReturnType = overriddenFT.returnType; | 12607 Type2 overriddenFTReturnType = overriddenFT.returnType; |
| 12175 List<Type2> overridingNormalPT = overridingFT.normalParameterTypes; | 12608 List<Type2> overridingNormalPT = overridingFT.normalParameterTypes; |
| 12176 List<Type2> overriddenNormalPT = overriddenFT.normalParameterTypes; | 12609 List<Type2> overriddenNormalPT = overriddenFT.normalParameterTypes; |
| 12177 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes; | 12610 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes; |
| 12178 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes; | 12611 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes; |
| 12179 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes; | 12612 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes; |
| 12180 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes; | 12613 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes; |
| 12181 if (overridingNormalPT.length != overriddenNormalPT.length) { | 12614 if (overridingNormalPT.length > overriddenNormalPT.length) { |
| 12182 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_REQUIRED, e
rrorNameTarget, [ | 12615 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_REQUIRED, e
rrorNameTarget, [ |
| 12183 overriddenNormalPT.length, | 12616 overriddenNormalPT.length, |
| 12184 overriddenExecutable.enclosingElement.displayName]); | 12617 overriddenExecutable.enclosingElement.displayName]); |
| 12185 return true; | 12618 return true; |
| 12186 } | 12619 } |
| 12187 if (overridingPositionalPT.length < overriddenPositionalPT.length) { | 12620 if (overridingPositionalPT.length < overriddenPositionalPT.length) { |
| 12188 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_POSITIONAL,
errorNameTarget, [ | 12621 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_POSITIONAL,
errorNameTarget, [ |
| 12189 overriddenPositionalPT.length, | 12622 overriddenPositionalPT.length, |
| 12190 overriddenExecutable.enclosingElement.displayName]); | 12623 overriddenExecutable.enclosingElement.displayName]); |
| 12191 return true; | 12624 return true; |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12703 } | 13136 } |
| 12704 | 13137 |
| 12705 /** | 13138 /** |
| 12706 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code | 13139 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code |
| 12707 * on the identifier if it is a keyword. | 13140 * on the identifier if it is a keyword. |
| 12708 * | 13141 * |
| 12709 * @param identifier the identifier to check to ensure that it is not a keywor
d | 13142 * @param identifier the identifier to check to ensure that it is not a keywor
d |
| 12710 * @param errorCode if the passed identifier is a keyword then this error code
is created on the | 13143 * @param errorCode if the passed identifier is a keyword then this error code
is created on the |
| 12711 * identifier, the error code will be one of | 13144 * identifier, the error code will be one of |
| 12712 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME], | 13145 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME], |
| 12713 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME] o
r | 13146 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME]
or |
| 12714 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME] | 13147 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME] |
| 12715 * @return `true` if and only if an error code is generated on the passed node | 13148 * @return `true` if and only if an error code is generated on the passed node |
| 12716 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME | 13149 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME |
| 12717 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME | 13150 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME |
| 12718 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME | 13151 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME |
| 12719 */ | 13152 */ |
| 12720 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { | 13153 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { |
| 12721 sc.Token token = identifier.token; | 13154 sc.Token token = identifier.token; |
| 12722 if (identical(token.type, sc.TokenType.KEYWORD)) { | 13155 if (identical(token.type, sc.TokenType.KEYWORD)) { |
| 12723 _errorReporter.reportError2(errorCode, identifier, [identifier.name]); | 13156 _errorReporter.reportError2(errorCode, identifier, [identifier.name]); |
| 12724 return true; | 13157 return true; |
| 12725 } | 13158 } |
| 12726 return false; | 13159 return false; |
| 12727 } | 13160 } |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13233 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS | 13666 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS |
| 13234 */ | 13667 */ |
| 13235 bool checkForConstWithTypeParameters2(TypeName typeName) { | 13668 bool checkForConstWithTypeParameters2(TypeName typeName) { |
| 13236 if (typeName == null) { | 13669 if (typeName == null) { |
| 13237 return false; | 13670 return false; |
| 13238 } | 13671 } |
| 13239 Identifier name = typeName.name; | 13672 Identifier name = typeName.name; |
| 13240 if (name == null) { | 13673 if (name == null) { |
| 13241 return false; | 13674 return false; |
| 13242 } | 13675 } |
| 13243 if (name.staticElement is TypeVariableElement) { | 13676 if (name.staticElement is TypeParameterElement) { |
| 13244 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETER
S, name, []); | 13677 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETER
S, name, []); |
| 13245 } | 13678 } |
| 13246 TypeArgumentList typeArguments = typeName.typeArguments; | 13679 TypeArgumentList typeArguments = typeName.typeArguments; |
| 13247 if (typeArguments != null) { | 13680 if (typeArguments != null) { |
| 13248 bool hasError = false; | 13681 bool hasError = false; |
| 13249 for (TypeName argument in typeArguments.arguments) { | 13682 for (TypeName argument in typeArguments.arguments) { |
| 13250 hasError = javaBooleanOr(hasError, checkForConstWithTypeParameters2(argu
ment)); | 13683 hasError = javaBooleanOr(hasError, checkForConstWithTypeParameters2(argu
ment)); |
| 13251 } | 13684 } |
| 13252 return hasError; | 13685 return hasError; |
| 13253 } | 13686 } |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13568 return false; | 14001 return false; |
| 13569 } | 14002 } |
| 13570 | 14003 |
| 13571 /** | 14004 /** |
| 13572 * This verifies that final fields that are declared, without any constructors
in the enclosing | 14005 * This verifies that final fields that are declared, without any constructors
in the enclosing |
| 13573 * class, are initialized. Cases in which there is at least one constructor ar
e handled at the end | 14006 * class, are initialized. Cases in which there is at least one constructor ar
e handled at the end |
| 13574 * of [checkForAllFinalInitializedErrorCodes]. | 14007 * of [checkForAllFinalInitializedErrorCodes]. |
| 13575 * | 14008 * |
| 13576 * @param node the class declaration to test | 14009 * @param node the class declaration to test |
| 13577 * @return `true` if and only if an error code is generated on the passed node | 14010 * @return `true` if and only if an error code is generated on the passed node |
| 13578 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 14011 * @see CompileTimeErrorCode#CONST_NOT_INITIALIZED |
| 14012 * @see StaticWarningCode#FINAL_NOT_INITIALIZED |
| 13579 */ | 14013 */ |
| 13580 bool checkForFinalNotInitialized(ClassDeclaration node) { | 14014 bool checkForFinalNotInitialized(ClassDeclaration node) { |
| 13581 NodeList<ClassMember> classMembers = node.members; | 14015 NodeList<ClassMember> classMembers = node.members; |
| 13582 for (ClassMember classMember in classMembers) { | 14016 for (ClassMember classMember in classMembers) { |
| 13583 if (classMember is ConstructorDeclaration) { | 14017 if (classMember is ConstructorDeclaration) { |
| 13584 return false; | 14018 return false; |
| 13585 } | 14019 } |
| 13586 } | 14020 } |
| 13587 bool foundError = false; | 14021 bool foundError = false; |
| 13588 for (ClassMember classMember in classMembers) { | 14022 for (ClassMember classMember in classMembers) { |
| 13589 if (classMember is FieldDeclaration) { | 14023 if (classMember is FieldDeclaration) { |
| 13590 FieldDeclaration field = classMember as FieldDeclaration; | 14024 FieldDeclaration field = classMember as FieldDeclaration; |
| 13591 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel
d.fields)); | 14025 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel
d.fields)); |
| 13592 } | 14026 } |
| 13593 } | 14027 } |
| 13594 return foundError; | 14028 return foundError; |
| 13595 } | 14029 } |
| 13596 | 14030 |
| 13597 /** | 14031 /** |
| 13598 * This verifies that the passed variable declaration list has only initialize
d variables if the | 14032 * This verifies that the passed variable declaration list has only initialize
d variables if the |
| 13599 * list is final or const. This method is called by | 14033 * list is final or const. This method is called by |
| 13600 * [checkForFinalNotInitialized], | 14034 * [checkForFinalNotInitialized], |
| 13601 * [visitTopLevelVariableDeclaration] and | 14035 * [visitTopLevelVariableDeclaration] and |
| 13602 * [visitVariableDeclarationStatement]. | 14036 * [visitVariableDeclarationStatement]. |
| 13603 * | 14037 * |
| 13604 * @param node the class declaration to test | 14038 * @param node the class declaration to test |
| 13605 * @return `true` if and only if an error code is generated on the passed node | 14039 * @return `true` if and only if an error code is generated on the passed node |
| 13606 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 14040 * @see CompileTimeErrorCode#CONST_NOT_INITIALIZED |
| 14041 * @see StaticWarningCode#FINAL_NOT_INITIALIZED |
| 13607 */ | 14042 */ |
| 13608 bool checkForFinalNotInitialized2(VariableDeclarationList node) { | 14043 bool checkForFinalNotInitialized2(VariableDeclarationList node) { |
| 13609 if (_isInNativeClass) { | 14044 if (_isInNativeClass) { |
| 13610 return false; | 14045 return false; |
| 13611 } | 14046 } |
| 13612 bool foundError = false; | 14047 bool foundError = false; |
| 13613 if (!node.isSynthetic && (node.isConst || node.isFinal)) { | 14048 if (!node.isSynthetic) { |
| 13614 NodeList<VariableDeclaration> variables = node.variables; | 14049 NodeList<VariableDeclaration> variables = node.variables; |
| 13615 for (VariableDeclaration variable in variables) { | 14050 for (VariableDeclaration variable in variables) { |
| 13616 if (variable.initializer == null) { | 14051 if (variable.initializer == null) { |
| 13617 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, v
ariable.name, [variable.name.name]); | 14052 if (node.isConst) { |
| 14053 _errorReporter.reportError2(CompileTimeErrorCode.CONST_NOT_INITIALIZ
ED, variable.name, [variable.name.name]); |
| 14054 } else if (node.isFinal) { |
| 14055 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED,
variable.name, [variable.name.name]); |
| 14056 } |
| 13618 foundError = true; | 14057 foundError = true; |
| 13619 } | 14058 } |
| 13620 } | 14059 } |
| 13621 } | 14060 } |
| 13622 return foundError; | 14061 return foundError; |
| 13623 } | 14062 } |
| 13624 | 14063 |
| 13625 /** | 14064 /** |
| 13626 * This verifies that the passed implements clause does not implement classes
such as 'num' or | 14065 * This verifies that the passed implements clause does not implement classes
such as 'num' or |
| 13627 * 'String'. | 14066 * 'String'. |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13954 * | 14393 * |
| 13955 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective | 14394 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective |
| 13956 * [ListLiteral] or [MapLiteral] | 14395 * [ListLiteral] or [MapLiteral] |
| 13957 * @param errorCode either [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONS
T_LIST] or | 14396 * @param errorCode either [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONS
T_LIST] or |
| 13958 * [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP] | 14397 * [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP] |
| 13959 * @return `true` if and only if an error code is generated on the passed node | 14398 * @return `true` if and only if an error code is generated on the passed node |
| 13960 */ | 14399 */ |
| 13961 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen
ts, ErrorCode errorCode) { | 14400 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen
ts, ErrorCode errorCode) { |
| 13962 bool foundError = false; | 14401 bool foundError = false; |
| 13963 for (TypeName typeName in arguments) { | 14402 for (TypeName typeName in arguments) { |
| 13964 if (typeName.type is TypeVariableType) { | 14403 if (typeName.type is TypeParameterType) { |
| 13965 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); | 14404 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); |
| 13966 foundError = true; | 14405 foundError = true; |
| 13967 } | 14406 } |
| 13968 } | 14407 } |
| 13969 return foundError; | 14408 return foundError; |
| 13970 } | 14409 } |
| 13971 | 14410 |
| 13972 /** | 14411 /** |
| 13973 * This verifies that the elements given [ListLiteral] are subtypes of the spe
cified element | 14412 * This verifies that the elements given [ListLiteral] are subtypes of the spe
cified element |
| 13974 * type. | 14413 * type. |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14917 * This verifies that the type arguments in the passed type name are all withi
n their bounds. | 15356 * This verifies that the type arguments in the passed type name are all withi
n their bounds. |
| 14918 * | 15357 * |
| 14919 * @param node the [TypeName] to evaluate | 15358 * @param node the [TypeName] to evaluate |
| 14920 * @return `true` if and only if an error code is generated on the passed node | 15359 * @return `true` if and only if an error code is generated on the passed node |
| 14921 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS | 15360 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS |
| 14922 */ | 15361 */ |
| 14923 bool checkForTypeArgumentNotMatchingBounds(TypeName node) { | 15362 bool checkForTypeArgumentNotMatchingBounds(TypeName node) { |
| 14924 if (node.typeArguments == null) { | 15363 if (node.typeArguments == null) { |
| 14925 return false; | 15364 return false; |
| 14926 } | 15365 } |
| 14927 List<TypeVariableElement> boundingElts = null; | 15366 List<TypeParameterElement> boundingElts = null; |
| 14928 Type2 type = node.type; | 15367 Type2 type = node.type; |
| 14929 if (type == null) { | 15368 if (type == null) { |
| 14930 return false; | 15369 return false; |
| 14931 } | 15370 } |
| 14932 Element element = type.element; | 15371 Element element = type.element; |
| 14933 if (element is ClassElement) { | 15372 if (element is ClassElement) { |
| 14934 boundingElts = ((element as ClassElement)).typeVariables; | 15373 boundingElts = ((element as ClassElement)).typeParameters; |
| 14935 } else { | 15374 } else { |
| 14936 return false; | 15375 return false; |
| 14937 } | 15376 } |
| 14938 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments; | 15377 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments; |
| 14939 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length)
; | 15378 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length)
; |
| 14940 bool foundError = false; | 15379 bool foundError = false; |
| 14941 for (int i = 0; i < loopThroughIndex; i++) { | 15380 for (int i = 0; i < loopThroughIndex; i++) { |
| 14942 TypeName argTypeName = typeNameArgList[i]; | 15381 TypeName argTypeName = typeNameArgList[i]; |
| 14943 Type2 argType = argTypeName.type; | 15382 Type2 argType = argTypeName.type; |
| 14944 Type2 boundType = boundingElts[i].bound; | 15383 Type2 boundType = boundingElts[i].bound; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 14962 * This checks that if the passed type name is a type parameter being used to
define a static | 15401 * This checks that if the passed type name is a type parameter being used to
define a static |
| 14963 * member. | 15402 * member. |
| 14964 * | 15403 * |
| 14965 * @param node the type name to evaluate | 15404 * @param node the type name to evaluate |
| 14966 * @return `true` if and only if an error code is generated on the passed node | 15405 * @return `true` if and only if an error code is generated on the passed node |
| 14967 * @see StaticWarningCode#TYPE_PARAMETER_REFERENCED_BY_STATIC | 15406 * @see StaticWarningCode#TYPE_PARAMETER_REFERENCED_BY_STATIC |
| 14968 */ | 15407 */ |
| 14969 bool checkForTypeParameterReferencedByStatic(TypeName node) { | 15408 bool checkForTypeParameterReferencedByStatic(TypeName node) { |
| 14970 if (_isInStaticMethod || _isInStaticVariableDeclaration) { | 15409 if (_isInStaticMethod || _isInStaticVariableDeclaration) { |
| 14971 Type2 type = node.type; | 15410 Type2 type = node.type; |
| 14972 if (type is TypeVariableType) { | 15411 if (type is TypeParameterType) { |
| 14973 _errorReporter.reportError2(StaticWarningCode.TYPE_PARAMETER_REFERENCED_
BY_STATIC, node, []); | 15412 _errorReporter.reportError2(StaticWarningCode.TYPE_PARAMETER_REFERENCED_
BY_STATIC, node, []); |
| 14974 return true; | 15413 return true; |
| 14975 } | 15414 } |
| 14976 } | 15415 } |
| 14977 return false; | 15416 return false; |
| 14978 } | 15417 } |
| 14979 | 15418 |
| 14980 /** | 15419 /** |
| 14981 * This checks that if the passed generative constructor has neither an explic
it super constructor | 15420 * This checks that if the passed generative constructor has neither an explic
it super constructor |
| 14982 * invocation nor a redirecting constructor invocation, that the superclass ha
s a default | 15421 * invocation nor a redirecting constructor invocation, that the superclass ha
s a default |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15031 /** | 15470 /** |
| 15032 * This checks that if the given name is a reference to a static member it is
defined in the | 15471 * This checks that if the given name is a reference to a static member it is
defined in the |
| 15033 * enclosing class rather than in a superclass. | 15472 * enclosing class rather than in a superclass. |
| 15034 * | 15473 * |
| 15035 * @param name the name to be evaluated | 15474 * @param name the name to be evaluated |
| 15036 * @return `true` if and only if an error code is generated on the passed node | 15475 * @return `true` if and only if an error code is generated on the passed node |
| 15037 * @see StaticTypeWarningCode#UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER | 15476 * @see StaticTypeWarningCode#UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER |
| 15038 */ | 15477 */ |
| 15039 bool checkForUnqualifiedReferenceToNonLocalStaticMember(SimpleIdentifier name2
) { | 15478 bool checkForUnqualifiedReferenceToNonLocalStaticMember(SimpleIdentifier name2
) { |
| 15040 Element element = name2.staticElement; | 15479 Element element = name2.staticElement; |
| 15041 if (element == null || element is TypeVariableElement) { | 15480 if (element == null || element is TypeParameterElement) { |
| 15042 return false; | 15481 return false; |
| 15043 } | 15482 } |
| 15044 Element enclosingElement = element.enclosingElement; | 15483 Element enclosingElement = element.enclosingElement; |
| 15045 if (enclosingElement is! ClassElement) { | 15484 if (enclosingElement is! ClassElement) { |
| 15046 return false; | 15485 return false; |
| 15047 } | 15486 } |
| 15048 if ((element is MethodElement && !((element as MethodElement)).isStatic) ||
(element is PropertyAccessorElement && !((element as PropertyAccessorElement)).i
sStatic)) { | 15487 if ((element is MethodElement && !((element as MethodElement)).isStatic) ||
(element is PropertyAccessorElement && !((element as PropertyAccessorElement)).i
sStatic)) { |
| 15049 return false; | 15488 return false; |
| 15050 } | 15489 } |
| 15051 if (identical(enclosingElement, _enclosingClass)) { | 15490 if (identical(enclosingElement, _enclosingClass)) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15220 current = current.redirectedConstructor; | 15659 current = current.redirectedConstructor; |
| 15221 if (current is ConstructorMember) { | 15660 if (current is ConstructorMember) { |
| 15222 current = ((current as ConstructorMember)).baseElement; | 15661 current = ((current as ConstructorMember)).baseElement; |
| 15223 } | 15662 } |
| 15224 } | 15663 } |
| 15225 return false; | 15664 return false; |
| 15226 } | 15665 } |
| 15227 | 15666 |
| 15228 /** | 15667 /** |
| 15229 * @return <code>true</code> if given [Element] has direct or indirect referen
ce to itself | 15668 * @return <code>true</code> if given [Element] has direct or indirect referen
ce to itself |
| 15230 * form anywhere except [ClassElement] or type variable bounds. | 15669 * from anywhere except [ClassElement] or type parameter bounds. |
| 15231 */ | 15670 */ |
| 15232 bool hasTypedefSelfReference(Element target) { | 15671 bool hasTypedefSelfReference(Element target) { |
| 15233 Set<Element> checked = new Set<Element>(); | 15672 Set<Element> checked = new Set<Element>(); |
| 15234 List<Element> toCheck = new List<Element>(); | 15673 List<Element> toCheck = new List<Element>(); |
| 15235 toCheck.add(target); | 15674 toCheck.add(target); |
| 15236 bool firstIteration = true; | 15675 bool firstIteration = true; |
| 15237 while (true) { | 15676 while (true) { |
| 15238 Element current; | 15677 Element current; |
| 15239 while (true) { | 15678 while (true) { |
| 15240 if (toCheck.isEmpty) { | 15679 if (toCheck.isEmpty) { |
| 15241 return false; | 15680 return false; |
| 15242 } | 15681 } |
| 15243 current = toCheck.removeAt(toCheck.length - 1); | 15682 current = toCheck.removeAt(toCheck.length - 1); |
| 15244 if (target == current) { | 15683 if (target == current) { |
| 15245 if (firstIteration) { | 15684 if (firstIteration) { |
| 15246 firstIteration = false; | 15685 firstIteration = false; |
| 15247 break; | 15686 break; |
| 15248 } else { | 15687 } else { |
| 15249 return true; | 15688 return true; |
| 15250 } | 15689 } |
| 15251 } | 15690 } |
| 15252 if (current != null && !checked.contains(current)) { | 15691 if (current != null && !checked.contains(current)) { |
| 15253 break; | 15692 break; |
| 15254 } | 15693 } |
| 15255 } | 15694 } |
| 15256 current.accept(new GeneralizingElementVisitor_13(target, toCheck)); | 15695 current.accept(new GeneralizingElementVisitor_12(target, toCheck)); |
| 15257 javaSetAdd(checked, current); | 15696 javaSetAdd(checked, current); |
| 15258 } | 15697 } |
| 15259 } | 15698 } |
| 15260 bool isFunctionType(Type2 type) { | 15699 bool isFunctionType(Type2 type) { |
| 15261 if (type.isDynamic || identical(type, BottomTypeImpl.instance)) { | 15700 if (type.isDynamic || identical(type, BottomTypeImpl.instance)) { |
| 15262 return true; | 15701 return true; |
| 15263 } else if (type is InterfaceType) { | 15702 } else if (type is InterfaceType) { |
| 15264 if (identical(type, _typeProvider.functionType)) { | 15703 if (identical(type, _typeProvider.functionType)) { |
| 15265 return true; | 15704 return true; |
| 15266 } | 15705 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15425 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT
ION', 1); | 15864 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT
ION', 1); |
| 15426 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F
ORMAL', 2); | 15865 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F
ORMAL', 2); |
| 15427 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL
IZERS', 3); | 15866 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL
IZERS', 3); |
| 15428 static final List<INIT_STATE> values = [ | 15867 static final List<INIT_STATE> values = [ |
| 15429 NOT_INIT, | 15868 NOT_INIT, |
| 15430 INIT_IN_DECLARATION, | 15869 INIT_IN_DECLARATION, |
| 15431 INIT_IN_FIELD_FORMAL, | 15870 INIT_IN_FIELD_FORMAL, |
| 15432 INIT_IN_INITIALIZERS]; | 15871 INIT_IN_INITIALIZERS]; |
| 15433 INIT_STATE(String name, int ordinal) : super(name, ordinal); | 15872 INIT_STATE(String name, int ordinal) : super(name, ordinal); |
| 15434 } | 15873 } |
| 15435 class GeneralizingElementVisitor_13 extends GeneralizingElementVisitor<Object> { | 15874 class GeneralizingElementVisitor_12 extends GeneralizingElementVisitor<Object> { |
| 15436 Element target; | 15875 Element target; |
| 15437 List<Element> toCheck; | 15876 List<Element> toCheck; |
| 15438 GeneralizingElementVisitor_13(this.target, this.toCheck) : super(); | 15877 GeneralizingElementVisitor_12(this.target, this.toCheck) : super(); |
| 15439 bool _inClass = false; | 15878 bool _inClass = false; |
| 15440 Object visitClassElement(ClassElement element) { | 15879 Object visitClassElement(ClassElement element) { |
| 15441 addTypeToCheck(element.supertype); | 15880 addTypeToCheck(element.supertype); |
| 15442 for (InterfaceType mixin in element.mixins) { | 15881 for (InterfaceType mixin in element.mixins) { |
| 15443 addTypeToCheck(mixin); | 15882 addTypeToCheck(mixin); |
| 15444 } | 15883 } |
| 15445 _inClass = !element.isTypedef; | 15884 _inClass = !element.isTypedef; |
| 15446 try { | 15885 try { |
| 15447 return super.visitClassElement(element); | 15886 return super.visitClassElement(element); |
| 15448 } finally { | 15887 } finally { |
| 15449 _inClass = false; | 15888 _inClass = false; |
| 15450 } | 15889 } |
| 15451 } | 15890 } |
| 15452 Object visitExecutableElement(ExecutableElement element) { | 15891 Object visitExecutableElement(ExecutableElement element) { |
| 15453 if (element.isSynthetic) { | 15892 if (element.isSynthetic) { |
| 15454 return null; | 15893 return null; |
| 15455 } | 15894 } |
| 15456 addTypeToCheck(element.returnType); | 15895 addTypeToCheck(element.returnType); |
| 15457 return super.visitExecutableElement(element); | 15896 return super.visitExecutableElement(element); |
| 15458 } | 15897 } |
| 15459 Object visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { | 15898 Object visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { |
| 15460 addTypeToCheck(element.returnType); | 15899 addTypeToCheck(element.returnType); |
| 15461 return super.visitFunctionTypeAliasElement(element); | 15900 return super.visitFunctionTypeAliasElement(element); |
| 15462 } | 15901 } |
| 15463 Object visitParameterElement(ParameterElement element) { | 15902 Object visitParameterElement(ParameterElement element) { |
| 15464 addTypeToCheck(element.type); | 15903 addTypeToCheck(element.type); |
| 15465 return super.visitParameterElement(element); | 15904 return super.visitParameterElement(element); |
| 15466 } | 15905 } |
| 15467 Object visitTypeVariableElement(TypeVariableElement element) => null; | 15906 Object visitTypeParameterElement(TypeParameterElement element) => null; |
| 15468 Object visitVariableElement(VariableElement element) { | 15907 Object visitVariableElement(VariableElement element) { |
| 15469 addTypeToCheck(element.type); | 15908 addTypeToCheck(element.type); |
| 15470 return super.visitVariableElement(element); | 15909 return super.visitVariableElement(element); |
| 15471 } | 15910 } |
| 15472 void addTypeToCheck(Type2 type) { | 15911 void addTypeToCheck(Type2 type) { |
| 15473 if (type == null) { | 15912 if (type == null) { |
| 15474 return; | 15913 return; |
| 15475 } | 15914 } |
| 15476 Element element = type.element; | 15915 Element element = type.element; |
| 15477 if (_inClass && target == element) { | 15916 if (_inClass && target == element) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15540 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag
e, String correction) : super(name, ordinal) { | 15979 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag
e, String correction) : super(name, ordinal) { |
| 15541 this._type = type; | 15980 this._type = type; |
| 15542 this._message = message; | 15981 this._message = message; |
| 15543 this.correction9 = correction; | 15982 this.correction9 = correction; |
| 15544 } | 15983 } |
| 15545 String get correction => correction9; | 15984 String get correction => correction9; |
| 15546 ErrorSeverity get errorSeverity => _type.severity; | 15985 ErrorSeverity get errorSeverity => _type.severity; |
| 15547 String get message => _message; | 15986 String get message => _message; |
| 15548 ErrorType get type => _type; | 15987 ErrorType get type => _type; |
| 15549 } | 15988 } |
| OLD | NEW |