| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.element_resolver_test; | 5 library analyzer.test.generated.element_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 _resolver = _createResolver(); | 113 _resolver = _createResolver(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void test_lookUpMethodInInterfaces() { | 116 void test_lookUpMethodInInterfaces() { |
| 117 InterfaceType intType = _typeProvider.intType; | 117 InterfaceType intType = _typeProvider.intType; |
| 118 // | 118 // |
| 119 // abstract class A { int operator[](int index); } | 119 // abstract class A { int operator[](int index); } |
| 120 // | 120 // |
| 121 ClassElementImpl classA = ElementFactory.classElement2("A"); | 121 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 122 MethodElement operator = | 122 MethodElement operator = |
| 123 ElementFactory.methodElement("[]", intType, [intType]); | 123 ElementFactory.methodElement("[]", intType, [intType]); |
| 124 classA.methods = <MethodElement>[operator]; | 124 classA.methods = <MethodElement>[operator]; |
| 125 // | 125 // |
| 126 // class B implements A {} | 126 // class B implements A {} |
| 127 // | 127 // |
| 128 ClassElementImpl classB = ElementFactory.classElement2("B"); | 128 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 129 classB.interfaces = <InterfaceType>[classA.type]; | 129 classB.interfaces = <InterfaceType>[classA.type]; |
| 130 // | 130 // |
| 131 // class C extends Object with B {} | 131 // class C extends Object with B {} |
| 132 // | 132 // |
| 133 ClassElementImpl classC = ElementFactory.classElement2("C"); | 133 ClassElementImpl classC = ElementFactory.classElement2("C"); |
| 134 classC.mixins = <InterfaceType>[classB.type]; | 134 classC.mixins = <InterfaceType>[classB.type]; |
| 135 // | 135 // |
| 136 // class D extends C {} | 136 // class D extends C {} |
| 137 // | 137 // |
| 138 ClassElementImpl classD = ElementFactory.classElement("D", classC.type); | 138 ClassElementImpl classD = ElementFactory.classElement("D", classC.type); |
| 139 // | 139 // |
| 140 // D a; | 140 // D a; |
| 141 // a[i]; | 141 // a[i]; |
| 142 // | 142 // |
| 143 SimpleIdentifier array = AstFactory.identifier3("a"); | 143 SimpleIdentifier array = AstFactory.identifier3("a"); |
| 144 array.staticType = classD.type; | 144 array.staticType = classD.type; |
| 145 IndexExpression expression = | 145 IndexExpression expression = |
| 146 AstFactory.indexExpression(array, AstFactory.identifier3("i")); | 146 AstFactory.indexExpression(array, AstFactory.identifier3("i")); |
| 147 expect(_resolveIndexExpression(expression), same(operator)); | 147 expect(_resolveIndexExpression(expression), same(operator)); |
| 148 _listener.assertNoErrors(); | 148 _listener.assertNoErrors(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void test_visitAssignmentExpression_compound() { | 151 void test_visitAssignmentExpression_compound() { |
| 152 InterfaceType intType = _typeProvider.intType; | 152 InterfaceType intType = _typeProvider.intType; |
| 153 SimpleIdentifier leftHandSide = AstFactory.identifier3("a"); | 153 SimpleIdentifier leftHandSide = AstFactory.identifier3("a"); |
| 154 leftHandSide.staticType = intType; | 154 leftHandSide.staticType = intType; |
| 155 AssignmentExpression assignment = AstFactory.assignmentExpression( | 155 AssignmentExpression assignment = AstFactory.assignmentExpression( |
| 156 leftHandSide, TokenType.PLUS_EQ, AstFactory.integer(1)); | 156 leftHandSide, TokenType.PLUS_EQ, AstFactory.integer(1)); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 void test_visitBreakStatement_withLabel() { | 240 void test_visitBreakStatement_withLabel() { |
| 241 // loop: while (true) { | 241 // loop: while (true) { |
| 242 // break loop; | 242 // break loop; |
| 243 // } | 243 // } |
| 244 String label = "loop"; | 244 String label = "loop"; |
| 245 LabelElementImpl labelElement = new LabelElementImpl.forNode( | 245 LabelElementImpl labelElement = new LabelElementImpl.forNode( |
| 246 AstFactory.identifier3(label), false, false); | 246 AstFactory.identifier3(label), false, false); |
| 247 BreakStatement breakStatement = AstFactory.breakStatement2(label); | 247 BreakStatement breakStatement = AstFactory.breakStatement2(label); |
| 248 Expression condition = AstFactory.booleanLiteral(true); | 248 Expression condition = AstFactory.booleanLiteral(true); |
| 249 WhileStatement whileStatement = | 249 WhileStatement whileStatement = |
| 250 AstFactory.whileStatement(condition, breakStatement); | 250 AstFactory.whileStatement(condition, breakStatement); |
| 251 expect(_resolveBreak(breakStatement, labelElement, whileStatement), | 251 expect(_resolveBreak(breakStatement, labelElement, whileStatement), |
| 252 same(labelElement)); | 252 same(labelElement)); |
| 253 expect(breakStatement.target, same(whileStatement)); | 253 expect(breakStatement.target, same(whileStatement)); |
| 254 _listener.assertNoErrors(); | 254 _listener.assertNoErrors(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void test_visitBreakStatement_withoutLabel() { | 257 void test_visitBreakStatement_withoutLabel() { |
| 258 BreakStatement statement = AstFactory.breakStatement(); | 258 BreakStatement statement = AstFactory.breakStatement(); |
| 259 _resolveStatement(statement, null, null); | 259 _resolveStatement(statement, null, null); |
| 260 _listener.assertNoErrors(); | 260 _listener.assertNoErrors(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void test_visitCommentReference_prefixedIdentifier_class_getter() { | 263 void test_visitCommentReference_prefixedIdentifier_class_getter() { |
| 264 ClassElementImpl classA = ElementFactory.classElement2("A"); | 264 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 265 // set accessors | 265 // set accessors |
| 266 String propName = "p"; | 266 String propName = "p"; |
| 267 PropertyAccessorElement getter = | 267 PropertyAccessorElement getter = |
| 268 ElementFactory.getterElement(propName, false, _typeProvider.intType); | 268 ElementFactory.getterElement(propName, false, _typeProvider.intType); |
| 269 PropertyAccessorElement setter = | 269 PropertyAccessorElement setter = |
| 270 ElementFactory.setterElement(propName, false, _typeProvider.intType); | 270 ElementFactory.setterElement(propName, false, _typeProvider.intType); |
| 271 classA.accessors = <PropertyAccessorElement>[getter, setter]; | 271 classA.accessors = <PropertyAccessorElement>[getter, setter]; |
| 272 // set name scope | 272 // set name scope |
| 273 _visitor.nameScope = new EnclosedScope(null) | 273 _visitor.nameScope = new EnclosedScope(null) |
| 274 ..defineNameWithoutChecking('A', classA); | 274 ..defineNameWithoutChecking('A', classA); |
| 275 // prepare "A.p" | 275 // prepare "A.p" |
| 276 PrefixedIdentifier prefixed = AstFactory.identifier5('A', 'p'); | 276 PrefixedIdentifier prefixed = AstFactory.identifier5('A', 'p'); |
| 277 CommentReference commentReference = new CommentReference(null, prefixed); | 277 CommentReference commentReference = new CommentReference(null, prefixed); |
| 278 // resolve | 278 // resolve |
| 279 _resolveNode(commentReference); | 279 _resolveNode(commentReference); |
| 280 expect(prefixed.prefix.staticElement, classA); | 280 expect(prefixed.prefix.staticElement, classA); |
| 281 expect(prefixed.identifier.staticElement, getter); | 281 expect(prefixed.identifier.staticElement, getter); |
| 282 _listener.assertNoErrors(); | 282 _listener.assertNoErrors(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void test_visitCommentReference_prefixedIdentifier_class_method() { | 285 void test_visitCommentReference_prefixedIdentifier_class_method() { |
| 286 ClassElementImpl classA = ElementFactory.classElement2("A"); | 286 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 287 // set method | 287 // set method |
| 288 MethodElement method = | 288 MethodElement method = |
| 289 ElementFactory.methodElement("m", _typeProvider.intType); | 289 ElementFactory.methodElement("m", _typeProvider.intType); |
| 290 classA.methods = <MethodElement>[method]; | 290 classA.methods = <MethodElement>[method]; |
| 291 // set name scope | 291 // set name scope |
| 292 _visitor.nameScope = new EnclosedScope(null) | 292 _visitor.nameScope = new EnclosedScope(null) |
| 293 ..defineNameWithoutChecking('A', classA); | 293 ..defineNameWithoutChecking('A', classA); |
| 294 // prepare "A.m" | 294 // prepare "A.m" |
| 295 PrefixedIdentifier prefixed = AstFactory.identifier5('A', 'm'); | 295 PrefixedIdentifier prefixed = AstFactory.identifier5('A', 'm'); |
| 296 CommentReference commentReference = new CommentReference(null, prefixed); | 296 CommentReference commentReference = new CommentReference(null, prefixed); |
| 297 // resolve | 297 // resolve |
| 298 _resolveNode(commentReference); | 298 _resolveNode(commentReference); |
| 299 expect(prefixed.prefix.staticElement, classA); | 299 expect(prefixed.prefix.staticElement, classA); |
| 300 expect(prefixed.identifier.staticElement, method); | 300 expect(prefixed.identifier.staticElement, method); |
| 301 _listener.assertNoErrors(); | 301 _listener.assertNoErrors(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void test_visitConstructorName_named() { | 304 void test_visitConstructorName_named() { |
| 305 ClassElementImpl classA = ElementFactory.classElement2("A"); | 305 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 306 String constructorName = "a"; | 306 String constructorName = "a"; |
| 307 ConstructorElement constructor = | 307 ConstructorElement constructor = |
| 308 ElementFactory.constructorElement2(classA, constructorName); | 308 ElementFactory.constructorElement2(classA, constructorName); |
| 309 classA.constructors = <ConstructorElement>[constructor]; | 309 classA.constructors = <ConstructorElement>[constructor]; |
| 310 ConstructorName name = AstFactory.constructorName( | 310 ConstructorName name = AstFactory.constructorName( |
| 311 AstFactory.typeName(classA), constructorName); | 311 AstFactory.typeName(classA), constructorName); |
| 312 _resolveNode(name); | 312 _resolveNode(name); |
| 313 expect(name.staticElement, same(constructor)); | 313 expect(name.staticElement, same(constructor)); |
| 314 _listener.assertNoErrors(); | 314 _listener.assertNoErrors(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void test_visitConstructorName_unnamed() { | 317 void test_visitConstructorName_unnamed() { |
| 318 ClassElementImpl classA = ElementFactory.classElement2("A"); | 318 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 319 String constructorName = null; | 319 String constructorName = null; |
| 320 ConstructorElement constructor = | 320 ConstructorElement constructor = |
| 321 ElementFactory.constructorElement2(classA, constructorName); | 321 ElementFactory.constructorElement2(classA, constructorName); |
| 322 classA.constructors = <ConstructorElement>[constructor]; | 322 classA.constructors = <ConstructorElement>[constructor]; |
| 323 ConstructorName name = AstFactory.constructorName( | 323 ConstructorName name = AstFactory.constructorName( |
| 324 AstFactory.typeName(classA), constructorName); | 324 AstFactory.typeName(classA), constructorName); |
| 325 _resolveNode(name); | 325 _resolveNode(name); |
| 326 expect(name.staticElement, same(constructor)); | 326 expect(name.staticElement, same(constructor)); |
| 327 _listener.assertNoErrors(); | 327 _listener.assertNoErrors(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void test_visitContinueStatement_withLabel() { | 330 void test_visitContinueStatement_withLabel() { |
| 331 // loop: while (true) { | 331 // loop: while (true) { |
| 332 // continue loop; | 332 // continue loop; |
| 333 // } | 333 // } |
| 334 String label = "loop"; | 334 String label = "loop"; |
| 335 LabelElementImpl labelElement = new LabelElementImpl.forNode( | 335 LabelElementImpl labelElement = new LabelElementImpl.forNode( |
| 336 AstFactory.identifier3(label), false, false); | 336 AstFactory.identifier3(label), false, false); |
| 337 ContinueStatement continueStatement = AstFactory.continueStatement(label); | 337 ContinueStatement continueStatement = AstFactory.continueStatement(label); |
| 338 Expression condition = AstFactory.booleanLiteral(true); | 338 Expression condition = AstFactory.booleanLiteral(true); |
| 339 WhileStatement whileStatement = | 339 WhileStatement whileStatement = |
| 340 AstFactory.whileStatement(condition, continueStatement); | 340 AstFactory.whileStatement(condition, continueStatement); |
| 341 expect(_resolveContinue(continueStatement, labelElement, whileStatement), | 341 expect(_resolveContinue(continueStatement, labelElement, whileStatement), |
| 342 same(labelElement)); | 342 same(labelElement)); |
| 343 expect(continueStatement.target, same(whileStatement)); | 343 expect(continueStatement.target, same(whileStatement)); |
| 344 _listener.assertNoErrors(); | 344 _listener.assertNoErrors(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void test_visitContinueStatement_withoutLabel() { | 347 void test_visitContinueStatement_withoutLabel() { |
| 348 ContinueStatement statement = AstFactory.continueStatement(); | 348 ContinueStatement statement = AstFactory.continueStatement(); |
| 349 _resolveStatement(statement, null, null); | 349 _resolveStatement(statement, null, null); |
| 350 _listener.assertNoErrors(); | 350 _listener.assertNoErrors(); |
| 351 } | 351 } |
| 352 | 352 |
| 353 void test_visitEnumDeclaration() { | 353 void test_visitEnumDeclaration() { |
| 354 CompilationUnitElementImpl compilationUnitElement = | 354 CompilationUnitElementImpl compilationUnitElement = |
| 355 ElementFactory.compilationUnit('foo.dart'); | 355 ElementFactory.compilationUnit('foo.dart'); |
| 356 ClassElementImpl enumElement = | 356 ClassElementImpl enumElement = |
| 357 ElementFactory.enumElement(_typeProvider, ('E')); | 357 ElementFactory.enumElement(_typeProvider, ('E')); |
| 358 compilationUnitElement.enums = <ClassElement>[enumElement]; | 358 compilationUnitElement.enums = <ClassElement>[enumElement]; |
| 359 EnumDeclaration enumNode = AstFactory.enumDeclaration2('E', []); | 359 EnumDeclaration enumNode = AstFactory.enumDeclaration2('E', []); |
| 360 Annotation annotationNode = | 360 Annotation annotationNode = |
| 361 AstFactory.annotation(AstFactory.identifier3('a')); | 361 AstFactory.annotation(AstFactory.identifier3('a')); |
| 362 annotationNode.element = ElementFactory.classElement2('A'); | 362 annotationNode.element = ElementFactory.classElement2('A'); |
| 363 annotationNode.elementAnnotation = | 363 annotationNode.elementAnnotation = |
| 364 new ElementAnnotationImpl(compilationUnitElement); | 364 new ElementAnnotationImpl(compilationUnitElement); |
| 365 enumNode.metadata.add(annotationNode); | 365 enumNode.metadata.add(annotationNode); |
| 366 enumNode.name.staticElement = enumElement; | 366 enumNode.name.staticElement = enumElement; |
| 367 List<ElementAnnotation> metadata = <ElementAnnotation>[ | 367 List<ElementAnnotation> metadata = <ElementAnnotation>[ |
| 368 annotationNode.elementAnnotation | 368 annotationNode.elementAnnotation |
| 369 ]; | 369 ]; |
| 370 _resolveNode(enumNode); | 370 _resolveNode(enumNode); |
| 371 expect(metadata[0].element, annotationNode.element); | 371 expect(metadata[0].element, annotationNode.element); |
| 372 } | 372 } |
| 373 | 373 |
| 374 void test_visitExportDirective_noCombinators() { | 374 void test_visitExportDirective_noCombinators() { |
| 375 ExportDirective directive = AstFactory.exportDirective2(null); | 375 ExportDirective directive = AstFactory.exportDirective2(null); |
| 376 directive.element = ElementFactory | 376 directive.element = ElementFactory |
| 377 .exportFor(ElementFactory.library(_definingLibrary.context, "lib")); | 377 .exportFor(ElementFactory.library(_definingLibrary.context, "lib")); |
| 378 _resolveNode(directive); | 378 _resolveNode(directive); |
| 379 _listener.assertNoErrors(); | 379 _listener.assertNoErrors(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void test_visitFieldFormalParameter() { | 382 void test_visitFieldFormalParameter() { |
| 383 String fieldName = "f"; | 383 String fieldName = "f"; |
| 384 InterfaceType intType = _typeProvider.intType; | 384 InterfaceType intType = _typeProvider.intType; |
| 385 FieldElementImpl fieldElement = | 385 FieldElementImpl fieldElement = |
| 386 ElementFactory.fieldElement(fieldName, false, false, false, intType); | 386 ElementFactory.fieldElement(fieldName, false, false, false, intType); |
| 387 ClassElementImpl classA = ElementFactory.classElement2("A"); | 387 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 388 classA.fields = <FieldElement>[fieldElement]; | 388 classA.fields = <FieldElement>[fieldElement]; |
| 389 FieldFormalParameter parameter = | 389 FieldFormalParameter parameter = |
| 390 AstFactory.fieldFormalParameter2(fieldName); | 390 AstFactory.fieldFormalParameter2(fieldName); |
| 391 FieldFormalParameterElementImpl parameterElement = | 391 FieldFormalParameterElementImpl parameterElement = |
| 392 ElementFactory.fieldFormalParameter(parameter.identifier); | 392 ElementFactory.fieldFormalParameter(parameter.identifier); |
| 393 parameterElement.field = fieldElement; | 393 parameterElement.field = fieldElement; |
| 394 parameterElement.type = intType; | 394 parameterElement.type = intType; |
| 395 parameter.identifier.staticElement = parameterElement; | 395 parameter.identifier.staticElement = parameterElement; |
| 396 _resolveInClass(parameter, classA); | 396 _resolveInClass(parameter, classA); |
| 397 expect(parameter.element.type, same(intType)); | 397 expect(parameter.element.type, same(intType)); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void test_visitImportDirective_noCombinators_noPrefix() { | 400 void test_visitImportDirective_noCombinators_noPrefix() { |
| 401 ImportDirective directive = AstFactory.importDirective3(null, null); | 401 ImportDirective directive = AstFactory.importDirective3(null, null); |
| 402 directive.element = ElementFactory.importFor( | 402 directive.element = ElementFactory.importFor( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 413 _definingLibrary.imports = <ImportElement>[importElement]; | 413 _definingLibrary.imports = <ImportElement>[importElement]; |
| 414 ImportDirective directive = AstFactory.importDirective3(null, prefixName); | 414 ImportDirective directive = AstFactory.importDirective3(null, prefixName); |
| 415 directive.element = importElement; | 415 directive.element = importElement; |
| 416 _resolveNode(directive); | 416 _resolveNode(directive); |
| 417 _listener.assertNoErrors(); | 417 _listener.assertNoErrors(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 void test_visitImportDirective_withCombinators() { | 420 void test_visitImportDirective_withCombinators() { |
| 421 ShowCombinator combinator = AstFactory.showCombinator2(["A", "B", "C"]); | 421 ShowCombinator combinator = AstFactory.showCombinator2(["A", "B", "C"]); |
| 422 ImportDirective directive = | 422 ImportDirective directive = |
| 423 AstFactory.importDirective3(null, null, [combinator]); | 423 AstFactory.importDirective3(null, null, [combinator]); |
| 424 LibraryElementImpl library = | 424 LibraryElementImpl library = |
| 425 ElementFactory.library(_definingLibrary.context, "lib"); | 425 ElementFactory.library(_definingLibrary.context, "lib"); |
| 426 TopLevelVariableElementImpl varA = | 426 TopLevelVariableElementImpl varA = |
| 427 ElementFactory.topLevelVariableElement2("A"); | 427 ElementFactory.topLevelVariableElement2("A"); |
| 428 TopLevelVariableElementImpl varB = | 428 TopLevelVariableElementImpl varB = |
| 429 ElementFactory.topLevelVariableElement2("B"); | 429 ElementFactory.topLevelVariableElement2("B"); |
| 430 TopLevelVariableElementImpl varC = | 430 TopLevelVariableElementImpl varC = |
| 431 ElementFactory.topLevelVariableElement2("C"); | 431 ElementFactory.topLevelVariableElement2("C"); |
| 432 CompilationUnitElementImpl unit = | 432 CompilationUnitElementImpl unit = |
| 433 library.definingCompilationUnit as CompilationUnitElementImpl; | 433 library.definingCompilationUnit as CompilationUnitElementImpl; |
| 434 unit.accessors = <PropertyAccessorElement>[ | 434 unit.accessors = <PropertyAccessorElement>[ |
| 435 varA.getter, | 435 varA.getter, |
| 436 varA.setter, | 436 varA.setter, |
| 437 varB.getter, | 437 varB.getter, |
| 438 varC.setter | 438 varC.setter |
| 439 ]; | 439 ]; |
| 440 unit.topLevelVariables = <TopLevelVariableElement>[varA, varB, varC]; | 440 unit.topLevelVariables = <TopLevelVariableElement>[varA, varB, varC]; |
| 441 directive.element = ElementFactory.importFor(library, null); | 441 directive.element = ElementFactory.importFor(library, null); |
| 442 _resolveNode(directive); | 442 _resolveNode(directive); |
| 443 expect(combinator.shownNames[0].staticElement, same(varA)); | 443 expect(combinator.shownNames[0].staticElement, same(varA)); |
| 444 expect(combinator.shownNames[1].staticElement, same(varB)); | 444 expect(combinator.shownNames[1].staticElement, same(varB)); |
| 445 expect(combinator.shownNames[2].staticElement, same(varC)); | 445 expect(combinator.shownNames[2].staticElement, same(varC)); |
| 446 _listener.assertNoErrors(); | 446 _listener.assertNoErrors(); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void test_visitIndexExpression_get() { | 449 void test_visitIndexExpression_get() { |
| 450 ClassElementImpl classA = ElementFactory.classElement2("A"); | 450 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 451 InterfaceType intType = _typeProvider.intType; | 451 InterfaceType intType = _typeProvider.intType; |
| 452 MethodElement getter = | 452 MethodElement getter = |
| 453 ElementFactory.methodElement("[]", intType, [intType]); | 453 ElementFactory.methodElement("[]", intType, [intType]); |
| 454 classA.methods = <MethodElement>[getter]; | 454 classA.methods = <MethodElement>[getter]; |
| 455 SimpleIdentifier array = AstFactory.identifier3("a"); | 455 SimpleIdentifier array = AstFactory.identifier3("a"); |
| 456 array.staticType = classA.type; | 456 array.staticType = classA.type; |
| 457 IndexExpression expression = | 457 IndexExpression expression = |
| 458 AstFactory.indexExpression(array, AstFactory.identifier3("i")); | 458 AstFactory.indexExpression(array, AstFactory.identifier3("i")); |
| 459 expect(_resolveIndexExpression(expression), same(getter)); | 459 expect(_resolveIndexExpression(expression), same(getter)); |
| 460 _listener.assertNoErrors(); | 460 _listener.assertNoErrors(); |
| 461 } | 461 } |
| 462 | 462 |
| 463 void test_visitIndexExpression_set() { | 463 void test_visitIndexExpression_set() { |
| 464 ClassElementImpl classA = ElementFactory.classElement2("A"); | 464 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 465 InterfaceType intType = _typeProvider.intType; | 465 InterfaceType intType = _typeProvider.intType; |
| 466 MethodElement setter = | 466 MethodElement setter = |
| 467 ElementFactory.methodElement("[]=", intType, [intType]); | 467 ElementFactory.methodElement("[]=", intType, [intType]); |
| 468 classA.methods = <MethodElement>[setter]; | 468 classA.methods = <MethodElement>[setter]; |
| 469 SimpleIdentifier array = AstFactory.identifier3("a"); | 469 SimpleIdentifier array = AstFactory.identifier3("a"); |
| 470 array.staticType = classA.type; | 470 array.staticType = classA.type; |
| 471 IndexExpression expression = | 471 IndexExpression expression = |
| 472 AstFactory.indexExpression(array, AstFactory.identifier3("i")); | 472 AstFactory.indexExpression(array, AstFactory.identifier3("i")); |
| 473 AstFactory.assignmentExpression( | 473 AstFactory.assignmentExpression( |
| 474 expression, TokenType.EQ, AstFactory.integer(0)); | 474 expression, TokenType.EQ, AstFactory.integer(0)); |
| 475 expect(_resolveIndexExpression(expression), same(setter)); | 475 expect(_resolveIndexExpression(expression), same(setter)); |
| 476 _listener.assertNoErrors(); | 476 _listener.assertNoErrors(); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void test_visitInstanceCreationExpression_named() { | 479 void test_visitInstanceCreationExpression_named() { |
| 480 ClassElementImpl classA = ElementFactory.classElement2("A"); | 480 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 481 String constructorName = "a"; | 481 String constructorName = "a"; |
| 482 ConstructorElement constructor = | 482 ConstructorElement constructor = |
| 483 ElementFactory.constructorElement2(classA, constructorName); | 483 ElementFactory.constructorElement2(classA, constructorName); |
| 484 classA.constructors = <ConstructorElement>[constructor]; | 484 classA.constructors = <ConstructorElement>[constructor]; |
| 485 ConstructorName name = AstFactory.constructorName( | 485 ConstructorName name = AstFactory.constructorName( |
| 486 AstFactory.typeName(classA), constructorName); | 486 AstFactory.typeName(classA), constructorName); |
| 487 name.staticElement = constructor; | 487 name.staticElement = constructor; |
| 488 InstanceCreationExpression creation = | 488 InstanceCreationExpression creation = |
| 489 AstFactory.instanceCreationExpression(Keyword.NEW, name); | 489 AstFactory.instanceCreationExpression(Keyword.NEW, name); |
| 490 _resolveNode(creation); | 490 _resolveNode(creation); |
| 491 expect(creation.staticElement, same(constructor)); | 491 expect(creation.staticElement, same(constructor)); |
| 492 _listener.assertNoErrors(); | 492 _listener.assertNoErrors(); |
| 493 } | 493 } |
| 494 | 494 |
| 495 void test_visitInstanceCreationExpression_unnamed() { | 495 void test_visitInstanceCreationExpression_unnamed() { |
| 496 ClassElementImpl classA = ElementFactory.classElement2("A"); | 496 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 497 String constructorName = null; | 497 String constructorName = null; |
| 498 ConstructorElement constructor = | 498 ConstructorElement constructor = |
| 499 ElementFactory.constructorElement2(classA, constructorName); | 499 ElementFactory.constructorElement2(classA, constructorName); |
| 500 classA.constructors = <ConstructorElement>[constructor]; | 500 classA.constructors = <ConstructorElement>[constructor]; |
| 501 ConstructorName name = AstFactory.constructorName( | 501 ConstructorName name = AstFactory.constructorName( |
| 502 AstFactory.typeName(classA), constructorName); | 502 AstFactory.typeName(classA), constructorName); |
| 503 name.staticElement = constructor; | 503 name.staticElement = constructor; |
| 504 InstanceCreationExpression creation = | 504 InstanceCreationExpression creation = |
| 505 AstFactory.instanceCreationExpression(Keyword.NEW, name); | 505 AstFactory.instanceCreationExpression(Keyword.NEW, name); |
| 506 _resolveNode(creation); | 506 _resolveNode(creation); |
| 507 expect(creation.staticElement, same(constructor)); | 507 expect(creation.staticElement, same(constructor)); |
| 508 _listener.assertNoErrors(); | 508 _listener.assertNoErrors(); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void test_visitInstanceCreationExpression_unnamed_namedParameter() { | 511 void test_visitInstanceCreationExpression_unnamed_namedParameter() { |
| 512 ClassElementImpl classA = ElementFactory.classElement2("A"); | 512 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 513 String constructorName = null; | 513 String constructorName = null; |
| 514 ConstructorElementImpl constructor = | 514 ConstructorElementImpl constructor = |
| 515 ElementFactory.constructorElement2(classA, constructorName); | 515 ElementFactory.constructorElement2(classA, constructorName); |
| 516 String parameterName = "a"; | 516 String parameterName = "a"; |
| 517 ParameterElement parameter = ElementFactory.namedParameter(parameterName); | 517 ParameterElement parameter = ElementFactory.namedParameter(parameterName); |
| 518 constructor.parameters = <ParameterElement>[parameter]; | 518 constructor.parameters = <ParameterElement>[parameter]; |
| 519 classA.constructors = <ConstructorElement>[constructor]; | 519 classA.constructors = <ConstructorElement>[constructor]; |
| 520 ConstructorName name = AstFactory.constructorName( | 520 ConstructorName name = AstFactory.constructorName( |
| 521 AstFactory.typeName(classA), constructorName); | 521 AstFactory.typeName(classA), constructorName); |
| 522 name.staticElement = constructor; | 522 name.staticElement = constructor; |
| 523 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( | 523 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( |
| 524 Keyword.NEW, | 524 Keyword.NEW, |
| 525 name, | 525 name, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 .staticElement, | 568 .staticElement, |
| 569 same(parameter)); | 569 same(parameter)); |
| 570 _listener.assertNoErrors(); | 570 _listener.assertNoErrors(); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void test_visitPostfixExpression() { | 573 void test_visitPostfixExpression() { |
| 574 InterfaceType numType = _typeProvider.numType; | 574 InterfaceType numType = _typeProvider.numType; |
| 575 SimpleIdentifier operand = AstFactory.identifier3("i"); | 575 SimpleIdentifier operand = AstFactory.identifier3("i"); |
| 576 operand.staticType = numType; | 576 operand.staticType = numType; |
| 577 PostfixExpression expression = | 577 PostfixExpression expression = |
| 578 AstFactory.postfixExpression(operand, TokenType.PLUS_PLUS); | 578 AstFactory.postfixExpression(operand, TokenType.PLUS_PLUS); |
| 579 _resolveNode(expression); | 579 _resolveNode(expression); |
| 580 expect(expression.staticElement, getMethod(numType, "+")); | 580 expect(expression.staticElement, getMethod(numType, "+")); |
| 581 _listener.assertNoErrors(); | 581 _listener.assertNoErrors(); |
| 582 } | 582 } |
| 583 | 583 |
| 584 void test_visitPrefixedIdentifier_dynamic() { | 584 void test_visitPrefixedIdentifier_dynamic() { |
| 585 DartType dynamicType = _typeProvider.dynamicType; | 585 DartType dynamicType = _typeProvider.dynamicType; |
| 586 SimpleIdentifier target = AstFactory.identifier3("a"); | 586 SimpleIdentifier target = AstFactory.identifier3("a"); |
| 587 VariableElementImpl variable = ElementFactory.localVariableElement(target); | 587 VariableElementImpl variable = ElementFactory.localVariableElement(target); |
| 588 variable.type = dynamicType; | 588 variable.type = dynamicType; |
| 589 target.staticElement = variable; | 589 target.staticElement = variable; |
| 590 target.staticType = dynamicType; | 590 target.staticType = dynamicType; |
| 591 PrefixedIdentifier identifier = | 591 PrefixedIdentifier identifier = |
| 592 AstFactory.identifier(target, AstFactory.identifier3("b")); | 592 AstFactory.identifier(target, AstFactory.identifier3("b")); |
| 593 _resolveNode(identifier); | 593 _resolveNode(identifier); |
| 594 expect(identifier.staticElement, isNull); | 594 expect(identifier.staticElement, isNull); |
| 595 expect(identifier.identifier.staticElement, isNull); | 595 expect(identifier.identifier.staticElement, isNull); |
| 596 _listener.assertNoErrors(); | 596 _listener.assertNoErrors(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void test_visitPrefixedIdentifier_nonDynamic() { | 599 void test_visitPrefixedIdentifier_nonDynamic() { |
| 600 ClassElementImpl classA = ElementFactory.classElement2("A"); | 600 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 601 String getterName = "b"; | 601 String getterName = "b"; |
| 602 PropertyAccessorElement getter = | 602 PropertyAccessorElement getter = |
| 603 ElementFactory.getterElement(getterName, false, _typeProvider.intType); | 603 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 604 classA.accessors = <PropertyAccessorElement>[getter]; | 604 classA.accessors = <PropertyAccessorElement>[getter]; |
| 605 SimpleIdentifier target = AstFactory.identifier3("a"); | 605 SimpleIdentifier target = AstFactory.identifier3("a"); |
| 606 VariableElementImpl variable = ElementFactory.localVariableElement(target); | 606 VariableElementImpl variable = ElementFactory.localVariableElement(target); |
| 607 variable.type = classA.type; | 607 variable.type = classA.type; |
| 608 target.staticElement = variable; | 608 target.staticElement = variable; |
| 609 target.staticType = classA.type; | 609 target.staticType = classA.type; |
| 610 PrefixedIdentifier identifier = | 610 PrefixedIdentifier identifier = |
| 611 AstFactory.identifier(target, AstFactory.identifier3(getterName)); | 611 AstFactory.identifier(target, AstFactory.identifier3(getterName)); |
| 612 _resolveNode(identifier); | 612 _resolveNode(identifier); |
| 613 expect(identifier.staticElement, same(getter)); | 613 expect(identifier.staticElement, same(getter)); |
| 614 expect(identifier.identifier.staticElement, same(getter)); | 614 expect(identifier.identifier.staticElement, same(getter)); |
| 615 _listener.assertNoErrors(); | 615 _listener.assertNoErrors(); |
| 616 } | 616 } |
| 617 | 617 |
| 618 void test_visitPrefixedIdentifier_staticClassMember_getter() { | 618 void test_visitPrefixedIdentifier_staticClassMember_getter() { |
| 619 ClassElementImpl classA = ElementFactory.classElement2("A"); | 619 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 620 // set accessors | 620 // set accessors |
| 621 String propName = "b"; | 621 String propName = "b"; |
| 622 PropertyAccessorElement getter = | 622 PropertyAccessorElement getter = |
| 623 ElementFactory.getterElement(propName, false, _typeProvider.intType); | 623 ElementFactory.getterElement(propName, false, _typeProvider.intType); |
| 624 PropertyAccessorElement setter = | 624 PropertyAccessorElement setter = |
| 625 ElementFactory.setterElement(propName, false, _typeProvider.intType); | 625 ElementFactory.setterElement(propName, false, _typeProvider.intType); |
| 626 classA.accessors = <PropertyAccessorElement>[getter, setter]; | 626 classA.accessors = <PropertyAccessorElement>[getter, setter]; |
| 627 // prepare "A.m" | 627 // prepare "A.m" |
| 628 SimpleIdentifier target = AstFactory.identifier3("A"); | 628 SimpleIdentifier target = AstFactory.identifier3("A"); |
| 629 target.staticElement = classA; | 629 target.staticElement = classA; |
| 630 target.staticType = classA.type; | 630 target.staticType = classA.type; |
| 631 PrefixedIdentifier identifier = | 631 PrefixedIdentifier identifier = |
| 632 AstFactory.identifier(target, AstFactory.identifier3(propName)); | 632 AstFactory.identifier(target, AstFactory.identifier3(propName)); |
| 633 // resolve | 633 // resolve |
| 634 _resolveNode(identifier); | 634 _resolveNode(identifier); |
| 635 expect(identifier.staticElement, same(getter)); | 635 expect(identifier.staticElement, same(getter)); |
| 636 expect(identifier.identifier.staticElement, same(getter)); | 636 expect(identifier.identifier.staticElement, same(getter)); |
| 637 _listener.assertNoErrors(); | 637 _listener.assertNoErrors(); |
| 638 } | 638 } |
| 639 | 639 |
| 640 void test_visitPrefixedIdentifier_staticClassMember_method() { | 640 void test_visitPrefixedIdentifier_staticClassMember_method() { |
| 641 ClassElementImpl classA = ElementFactory.classElement2("A"); | 641 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 642 // set methods | 642 // set methods |
| 643 String propName = "m"; | 643 String propName = "m"; |
| 644 MethodElement method = | 644 MethodElement method = |
| 645 ElementFactory.methodElement("m", _typeProvider.intType); | 645 ElementFactory.methodElement("m", _typeProvider.intType); |
| 646 classA.methods = <MethodElement>[method]; | 646 classA.methods = <MethodElement>[method]; |
| 647 // prepare "A.m" | 647 // prepare "A.m" |
| 648 SimpleIdentifier target = AstFactory.identifier3("A"); | 648 SimpleIdentifier target = AstFactory.identifier3("A"); |
| 649 target.staticElement = classA; | 649 target.staticElement = classA; |
| 650 target.staticType = classA.type; | 650 target.staticType = classA.type; |
| 651 PrefixedIdentifier identifier = | 651 PrefixedIdentifier identifier = |
| 652 AstFactory.identifier(target, AstFactory.identifier3(propName)); | 652 AstFactory.identifier(target, AstFactory.identifier3(propName)); |
| 653 AstFactory.assignmentExpression( | 653 AstFactory.assignmentExpression( |
| 654 identifier, TokenType.EQ, AstFactory.nullLiteral()); | 654 identifier, TokenType.EQ, AstFactory.nullLiteral()); |
| 655 // resolve | 655 // resolve |
| 656 _resolveNode(identifier); | 656 _resolveNode(identifier); |
| 657 expect(identifier.staticElement, same(method)); | 657 expect(identifier.staticElement, same(method)); |
| 658 expect(identifier.identifier.staticElement, same(method)); | 658 expect(identifier.identifier.staticElement, same(method)); |
| 659 _listener.assertNoErrors(); | 659 _listener.assertNoErrors(); |
| 660 } | 660 } |
| 661 | 661 |
| 662 void test_visitPrefixedIdentifier_staticClassMember_setter() { | 662 void test_visitPrefixedIdentifier_staticClassMember_setter() { |
| 663 ClassElementImpl classA = ElementFactory.classElement2("A"); | 663 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 664 // set accessors | 664 // set accessors |
| 665 String propName = "b"; | 665 String propName = "b"; |
| 666 PropertyAccessorElement getter = | 666 PropertyAccessorElement getter = |
| 667 ElementFactory.getterElement(propName, false, _typeProvider.intType); | 667 ElementFactory.getterElement(propName, false, _typeProvider.intType); |
| 668 PropertyAccessorElement setter = | 668 PropertyAccessorElement setter = |
| 669 ElementFactory.setterElement(propName, false, _typeProvider.intType); | 669 ElementFactory.setterElement(propName, false, _typeProvider.intType); |
| 670 classA.accessors = <PropertyAccessorElement>[getter, setter]; | 670 classA.accessors = <PropertyAccessorElement>[getter, setter]; |
| 671 // prepare "A.b = null" | 671 // prepare "A.b = null" |
| 672 SimpleIdentifier target = AstFactory.identifier3("A"); | 672 SimpleIdentifier target = AstFactory.identifier3("A"); |
| 673 target.staticElement = classA; | 673 target.staticElement = classA; |
| 674 target.staticType = classA.type; | 674 target.staticType = classA.type; |
| 675 PrefixedIdentifier identifier = | 675 PrefixedIdentifier identifier = |
| 676 AstFactory.identifier(target, AstFactory.identifier3(propName)); | 676 AstFactory.identifier(target, AstFactory.identifier3(propName)); |
| 677 AstFactory.assignmentExpression( | 677 AstFactory.assignmentExpression( |
| 678 identifier, TokenType.EQ, AstFactory.nullLiteral()); | 678 identifier, TokenType.EQ, AstFactory.nullLiteral()); |
| 679 // resolve | 679 // resolve |
| 680 _resolveNode(identifier); | 680 _resolveNode(identifier); |
| 681 expect(identifier.staticElement, same(setter)); | 681 expect(identifier.staticElement, same(setter)); |
| 682 expect(identifier.identifier.staticElement, same(setter)); | 682 expect(identifier.identifier.staticElement, same(setter)); |
| 683 _listener.assertNoErrors(); | 683 _listener.assertNoErrors(); |
| 684 } | 684 } |
| 685 | 685 |
| 686 void test_visitPrefixExpression() { | 686 void test_visitPrefixExpression() { |
| 687 InterfaceType numType = _typeProvider.numType; | 687 InterfaceType numType = _typeProvider.numType; |
| 688 SimpleIdentifier operand = AstFactory.identifier3("i"); | 688 SimpleIdentifier operand = AstFactory.identifier3("i"); |
| 689 operand.staticType = numType; | 689 operand.staticType = numType; |
| 690 PrefixExpression expression = | 690 PrefixExpression expression = |
| 691 AstFactory.prefixExpression(TokenType.PLUS_PLUS, operand); | 691 AstFactory.prefixExpression(TokenType.PLUS_PLUS, operand); |
| 692 _resolveNode(expression); | 692 _resolveNode(expression); |
| 693 expect(expression.staticElement, getMethod(numType, "+")); | 693 expect(expression.staticElement, getMethod(numType, "+")); |
| 694 _listener.assertNoErrors(); | 694 _listener.assertNoErrors(); |
| 695 } | 695 } |
| 696 | 696 |
| 697 void test_visitPropertyAccess_getter_identifier() { | 697 void test_visitPropertyAccess_getter_identifier() { |
| 698 ClassElementImpl classA = ElementFactory.classElement2("A"); | 698 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 699 String getterName = "b"; | 699 String getterName = "b"; |
| 700 PropertyAccessorElement getter = | 700 PropertyAccessorElement getter = |
| 701 ElementFactory.getterElement(getterName, false, _typeProvider.intType); | 701 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 702 classA.accessors = <PropertyAccessorElement>[getter]; | 702 classA.accessors = <PropertyAccessorElement>[getter]; |
| 703 SimpleIdentifier target = AstFactory.identifier3("a"); | 703 SimpleIdentifier target = AstFactory.identifier3("a"); |
| 704 target.staticType = classA.type; | 704 target.staticType = classA.type; |
| 705 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); | 705 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); |
| 706 _resolveNode(access); | 706 _resolveNode(access); |
| 707 expect(access.propertyName.staticElement, same(getter)); | 707 expect(access.propertyName.staticElement, same(getter)); |
| 708 _listener.assertNoErrors(); | 708 _listener.assertNoErrors(); |
| 709 } | 709 } |
| 710 | 710 |
| 711 void test_visitPropertyAccess_getter_super() { | 711 void test_visitPropertyAccess_getter_super() { |
| 712 // | 712 // |
| 713 // class A { | 713 // class A { |
| 714 // int get b; | 714 // int get b; |
| 715 // } | 715 // } |
| 716 // class B { | 716 // class B { |
| 717 // ... super.m ... | 717 // ... super.m ... |
| 718 // } | 718 // } |
| 719 // | 719 // |
| 720 ClassElementImpl classA = ElementFactory.classElement2("A"); | 720 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 721 String getterName = "b"; | 721 String getterName = "b"; |
| 722 PropertyAccessorElement getter = | 722 PropertyAccessorElement getter = |
| 723 ElementFactory.getterElement(getterName, false, _typeProvider.intType); | 723 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 724 classA.accessors = <PropertyAccessorElement>[getter]; | 724 classA.accessors = <PropertyAccessorElement>[getter]; |
| 725 SuperExpression target = AstFactory.superExpression(); | 725 SuperExpression target = AstFactory.superExpression(); |
| 726 target.staticType = ElementFactory.classElement("B", classA.type).type; | 726 target.staticType = ElementFactory.classElement("B", classA.type).type; |
| 727 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); | 727 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); |
| 728 AstFactory.methodDeclaration2( | 728 AstFactory.methodDeclaration2( |
| 729 null, | 729 null, |
| 730 null, | 730 null, |
| 731 null, | 731 null, |
| 732 null, | 732 null, |
| 733 AstFactory.identifier3("m"), | 733 AstFactory.identifier3("m"), |
| 734 AstFactory.formalParameterList(), | 734 AstFactory.formalParameterList(), |
| 735 AstFactory.expressionFunctionBody(access)); | 735 AstFactory.expressionFunctionBody(access)); |
| 736 _resolveNode(access); | 736 _resolveNode(access); |
| 737 expect(access.propertyName.staticElement, same(getter)); | 737 expect(access.propertyName.staticElement, same(getter)); |
| 738 _listener.assertNoErrors(); | 738 _listener.assertNoErrors(); |
| 739 } | 739 } |
| 740 | 740 |
| 741 void test_visitPropertyAccess_setter_this() { | 741 void test_visitPropertyAccess_setter_this() { |
| 742 ClassElementImpl classA = ElementFactory.classElement2("A"); | 742 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 743 String setterName = "b"; | 743 String setterName = "b"; |
| 744 PropertyAccessorElement setter = | 744 PropertyAccessorElement setter = |
| 745 ElementFactory.setterElement(setterName, false, _typeProvider.intType); | 745 ElementFactory.setterElement(setterName, false, _typeProvider.intType); |
| 746 classA.accessors = <PropertyAccessorElement>[setter]; | 746 classA.accessors = <PropertyAccessorElement>[setter]; |
| 747 ThisExpression target = AstFactory.thisExpression(); | 747 ThisExpression target = AstFactory.thisExpression(); |
| 748 target.staticType = classA.type; | 748 target.staticType = classA.type; |
| 749 PropertyAccess access = AstFactory.propertyAccess2(target, setterName); | 749 PropertyAccess access = AstFactory.propertyAccess2(target, setterName); |
| 750 AstFactory.assignmentExpression( | 750 AstFactory.assignmentExpression( |
| 751 access, TokenType.EQ, AstFactory.integer(0)); | 751 access, TokenType.EQ, AstFactory.integer(0)); |
| 752 _resolveNode(access); | 752 _resolveNode(access); |
| 753 expect(access.propertyName.staticElement, same(setter)); | 753 expect(access.propertyName.staticElement, same(setter)); |
| 754 _listener.assertNoErrors(); | 754 _listener.assertNoErrors(); |
| 755 } | 755 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 776 VariableElementImpl element = ElementFactory.localVariableElement(node); | 776 VariableElementImpl element = ElementFactory.localVariableElement(node); |
| 777 expect(_resolveIdentifier(node, [element]), same(element)); | 777 expect(_resolveIdentifier(node, [element]), same(element)); |
| 778 _listener.assertNoErrors(); | 778 _listener.assertNoErrors(); |
| 779 } | 779 } |
| 780 | 780 |
| 781 void test_visitSimpleIdentifier_lexicalScope_field_setter() { | 781 void test_visitSimpleIdentifier_lexicalScope_field_setter() { |
| 782 InterfaceType intType = _typeProvider.intType; | 782 InterfaceType intType = _typeProvider.intType; |
| 783 ClassElementImpl classA = ElementFactory.classElement2("A"); | 783 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 784 String fieldName = "a"; | 784 String fieldName = "a"; |
| 785 FieldElement field = | 785 FieldElement field = |
| 786 ElementFactory.fieldElement(fieldName, false, false, false, intType); | 786 ElementFactory.fieldElement(fieldName, false, false, false, intType); |
| 787 classA.fields = <FieldElement>[field]; | 787 classA.fields = <FieldElement>[field]; |
| 788 classA.accessors = <PropertyAccessorElement>[field.getter, field.setter]; | 788 classA.accessors = <PropertyAccessorElement>[field.getter, field.setter]; |
| 789 SimpleIdentifier node = AstFactory.identifier3(fieldName); | 789 SimpleIdentifier node = AstFactory.identifier3(fieldName); |
| 790 AstFactory.assignmentExpression(node, TokenType.EQ, AstFactory.integer(0)); | 790 AstFactory.assignmentExpression(node, TokenType.EQ, AstFactory.integer(0)); |
| 791 _resolveInClass(node, classA); | 791 _resolveInClass(node, classA); |
| 792 Element element = node.staticElement; | 792 Element element = node.staticElement; |
| 793 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, | 793 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, |
| 794 PropertyAccessorElement, element); | 794 PropertyAccessorElement, element); |
| 795 expect((element as PropertyAccessorElement).isSetter, isTrue); | 795 expect((element as PropertyAccessorElement).isSetter, isTrue); |
| 796 _listener.assertNoErrors(); | 796 _listener.assertNoErrors(); |
| 797 } | 797 } |
| 798 | 798 |
| 799 void test_visitSuperConstructorInvocation() { | 799 void test_visitSuperConstructorInvocation() { |
| 800 ClassElementImpl superclass = ElementFactory.classElement2("A"); | 800 ClassElementImpl superclass = ElementFactory.classElement2("A"); |
| 801 ConstructorElementImpl superConstructor = | 801 ConstructorElementImpl superConstructor = |
| 802 ElementFactory.constructorElement2(superclass, null); | 802 ElementFactory.constructorElement2(superclass, null); |
| 803 superclass.constructors = <ConstructorElement>[superConstructor]; | 803 superclass.constructors = <ConstructorElement>[superConstructor]; |
| 804 ClassElementImpl subclass = | 804 ClassElementImpl subclass = |
| 805 ElementFactory.classElement("B", superclass.type); | 805 ElementFactory.classElement("B", superclass.type); |
| 806 ConstructorElementImpl subConstructor = | 806 ConstructorElementImpl subConstructor = |
| 807 ElementFactory.constructorElement2(subclass, null); | 807 ElementFactory.constructorElement2(subclass, null); |
| 808 subclass.constructors = <ConstructorElement>[subConstructor]; | 808 subclass.constructors = <ConstructorElement>[subConstructor]; |
| 809 SuperConstructorInvocation invocation = | 809 SuperConstructorInvocation invocation = |
| 810 AstFactory.superConstructorInvocation(); | 810 AstFactory.superConstructorInvocation(); |
| 811 _resolveInClass(invocation, subclass); | 811 _resolveInClass(invocation, subclass); |
| 812 expect(invocation.staticElement, superConstructor); | 812 expect(invocation.staticElement, superConstructor); |
| 813 _listener.assertNoErrors(); | 813 _listener.assertNoErrors(); |
| 814 } | 814 } |
| 815 | 815 |
| 816 void test_visitSuperConstructorInvocation_namedParameter() { | 816 void test_visitSuperConstructorInvocation_namedParameter() { |
| 817 ClassElementImpl superclass = ElementFactory.classElement2("A"); | 817 ClassElementImpl superclass = ElementFactory.classElement2("A"); |
| 818 ConstructorElementImpl superConstructor = | 818 ConstructorElementImpl superConstructor = |
| 819 ElementFactory.constructorElement2(superclass, null); | 819 ElementFactory.constructorElement2(superclass, null); |
| 820 String parameterName = "p"; | 820 String parameterName = "p"; |
| 821 ParameterElement parameter = ElementFactory.namedParameter(parameterName); | 821 ParameterElement parameter = ElementFactory.namedParameter(parameterName); |
| 822 superConstructor.parameters = <ParameterElement>[parameter]; | 822 superConstructor.parameters = <ParameterElement>[parameter]; |
| 823 superclass.constructors = <ConstructorElement>[superConstructor]; | 823 superclass.constructors = <ConstructorElement>[superConstructor]; |
| 824 ClassElementImpl subclass = | 824 ClassElementImpl subclass = |
| 825 ElementFactory.classElement("B", superclass.type); | 825 ElementFactory.classElement("B", superclass.type); |
| 826 ConstructorElementImpl subConstructor = | 826 ConstructorElementImpl subConstructor = |
| 827 ElementFactory.constructorElement2(subclass, null); | 827 ElementFactory.constructorElement2(subclass, null); |
| 828 subclass.constructors = <ConstructorElement>[subConstructor]; | 828 subclass.constructors = <ConstructorElement>[subConstructor]; |
| 829 SuperConstructorInvocation invocation = AstFactory | 829 SuperConstructorInvocation invocation = AstFactory |
| 830 .superConstructorInvocation([ | 830 .superConstructorInvocation([ |
| 831 AstFactory.namedExpression2(parameterName, AstFactory.integer(0)) | 831 AstFactory.namedExpression2(parameterName, AstFactory.integer(0)) |
| 832 ]); | 832 ]); |
| 833 _resolveInClass(invocation, subclass); | 833 _resolveInClass(invocation, subclass); |
| 834 expect(invocation.staticElement, superConstructor); | 834 expect(invocation.staticElement, superConstructor); |
| 835 expect( | 835 expect( |
| 836 (invocation.argumentList.arguments[0] as NamedExpression) | 836 (invocation.argumentList.arguments[0] as NamedExpression) |
| 837 .name | 837 .name |
| 838 .label | 838 .label |
| 839 .staticElement, | 839 .staticElement, |
| 840 same(parameter)); | 840 same(parameter)); |
| 841 _listener.assertNoErrors(); | 841 _listener.assertNoErrors(); |
| 842 } | 842 } |
| 843 | 843 |
| 844 /** | 844 /** |
| 845 * Create the resolver used by the tests. | 845 * Create the resolver used by the tests. |
| 846 * | 846 * |
| 847 * @return the resolver that was created | 847 * @return the resolver that was created |
| 848 */ | 848 */ |
| 849 ElementResolver _createResolver() { | 849 ElementResolver _createResolver() { |
| 850 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 850 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 851 FileBasedSource source = | 851 FileBasedSource source = |
| 852 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | 852 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 853 CompilationUnitElementImpl definingCompilationUnit = | 853 CompilationUnitElementImpl definingCompilationUnit = |
| 854 new CompilationUnitElementImpl("test.dart"); | 854 new CompilationUnitElementImpl("test.dart"); |
| 855 definingCompilationUnit.librarySource = | 855 definingCompilationUnit.librarySource = |
| 856 definingCompilationUnit.source = source; | 856 definingCompilationUnit.source = source; |
| 857 _definingLibrary = ElementFactory.library(context, "test"); | 857 _definingLibrary = ElementFactory.library(context, "test"); |
| 858 _definingLibrary.definingCompilationUnit = definingCompilationUnit; | 858 _definingLibrary.definingCompilationUnit = definingCompilationUnit; |
| 859 _visitor = new ResolverVisitor( | 859 _visitor = new ResolverVisitor( |
| 860 _definingLibrary, source, _typeProvider, _listener, | 860 _definingLibrary, source, _typeProvider, _listener, |
| 861 nameScope: new LibraryScope(_definingLibrary, _listener)); | 861 nameScope: new LibraryScope(_definingLibrary, _listener)); |
| 862 try { | 862 try { |
| 863 return _visitor.elementResolver; | 863 return _visitor.elementResolver; |
| 864 } catch (exception) { | 864 } catch (exception) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 _visitor.labelScope = innerScope; | 1002 _visitor.labelScope = innerScope; |
| 1003 statement.accept(_resolver); | 1003 statement.accept(_resolver); |
| 1004 } finally { | 1004 } finally { |
| 1005 _visitor.labelScope = outerScope; | 1005 _visitor.labelScope = outerScope; |
| 1006 } | 1006 } |
| 1007 } catch (exception) { | 1007 } catch (exception) { |
| 1008 throw new IllegalArgumentException("Could not resolve node", exception); | 1008 throw new IllegalArgumentException("Could not resolve node", exception); |
| 1009 } | 1009 } |
| 1010 } | 1010 } |
| 1011 } | 1011 } |
| OLD | NEW |