| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.dart.element.builder_test; | 5 library analyzer.test.dart.element.builder_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/standard_ast_factory.dart'; | 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 ''').types[0].methods[0]; | 74 ''').types[0].methods[0]; |
| 75 { | 75 { |
| 76 expect(method.parameters, hasLength(2)); | 76 expect(method.parameters, hasLength(2)); |
| 77 expect(method.parameters[0].displayName, 'a'); | 77 expect(method.parameters[0].displayName, 'a'); |
| 78 expect(method.parameters[0].initializer, isNull); | 78 expect(method.parameters[0].initializer, isNull); |
| 79 expect(method.parameters[1].displayName, 'b'); | 79 expect(method.parameters[1].displayName, 'b'); |
| 80 expect(method.parameters[1].initializer, isNull); | 80 expect(method.parameters[1].initializer, isNull); |
| 81 } | 81 } |
| 82 expect(method.localVariables, isEmpty); | |
| 83 expect(method.functions, isEmpty); | 82 expect(method.functions, isEmpty); |
| 84 } | 83 } |
| 85 | 84 |
| 86 void test_api_topLevelFunction_blockBody() { | 85 void test_api_topLevelFunction_blockBody() { |
| 87 FunctionElement function = buildElementsForText(r''' | 86 FunctionElement function = buildElementsForText(r''' |
| 88 void topLevelFunction() { | 87 void topLevelFunction() { |
| 89 int v = 0; | 88 int v = 0; |
| 90 localFunction() {} | 89 localFunction() {} |
| 91 } | 90 } |
| 92 ''').functions[0]; | 91 ''').functions[0]; |
| 93 expect(function.localVariables, isEmpty); | |
| 94 expect(function.functions, isEmpty); | 92 expect(function.functions, isEmpty); |
| 95 } | 93 } |
| 96 | 94 |
| 97 void test_api_topLevelFunction_expressionBody() { | 95 void test_api_topLevelFunction_expressionBody() { |
| 98 FunctionElement function = buildElementsForText(r''' | 96 FunctionElement function = buildElementsForText(r''' |
| 99 topLevelFunction() => () { | 97 topLevelFunction() => () { |
| 100 int localVar = 0; | 98 int localVar = 0; |
| 101 }; | 99 }; |
| 102 ''').functions[0]; | 100 ''').functions[0]; |
| 103 expect(function.localVariables, isEmpty); | |
| 104 expect(function.functions, isEmpty); | 101 expect(function.functions, isEmpty); |
| 105 } | 102 } |
| 106 | 103 |
| 107 void test_api_topLevelFunction_parameters() { | 104 void test_api_topLevelFunction_parameters() { |
| 108 FunctionElement function = buildElementsForText(r''' | 105 FunctionElement function = buildElementsForText(r''' |
| 109 void topLevelFunction(int a, int b(double b2), {c: () {int c2; c3() {} }}) { | 106 void topLevelFunction(int a, int b(double b2), {c: () {int c2; c3() {} }}) { |
| 110 } | 107 } |
| 111 ''').functions[0]; | 108 ''').functions[0]; |
| 112 List<ParameterElement> parameters = function.parameters; | 109 List<ParameterElement> parameters = function.parameters; |
| 113 expect(parameters, hasLength(3)); | 110 expect(parameters, hasLength(3)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 180 } |
| 184 } | 181 } |
| 185 | 182 |
| 186 @override | 183 @override |
| 187 void setUp() { | 184 void setUp() { |
| 188 super.setUp(); | 185 super.setUp(); |
| 189 compilationUnitElement = new CompilationUnitElementImpl('test.dart'); | 186 compilationUnitElement = new CompilationUnitElementImpl('test.dart'); |
| 190 } | 187 } |
| 191 | 188 |
| 192 void test_metadata_localVariableDeclaration() { | 189 void test_metadata_localVariableDeclaration() { |
| 193 List<LocalVariableElement> localVariables = | 190 var code = 'f() { @a int x, y; }'; |
| 194 buildElementsForText('f() { @a int x, y; }') | 191 buildElementsForText(code); |
| 195 .functions[0] | 192 var x = findLocalVariable(code, 'x, '); |
| 196 .localVariables; | 193 var y = findLocalVariable(code, 'x, '); |
| 197 checkMetadata(localVariables[0]); | 194 checkMetadata(x); |
| 198 checkMetadata(localVariables[1]); | 195 checkMetadata(y); |
| 199 expect(localVariables[0].metadata, same(localVariables[1].metadata)); | 196 expect(x.metadata, same(y.metadata)); |
| 200 } | 197 } |
| 201 | 198 |
| 202 void test_metadata_visitDeclaredIdentifier() { | 199 void test_metadata_visitDeclaredIdentifier() { |
| 203 LocalVariableElement localVariableElement = | 200 var code = 'f() { for (@a var x in y) {} }'; |
| 204 buildElementsForText('f() { for (@a var x in y) {} }') | 201 buildElementsForText(code); |
| 205 .functions[0] | 202 var x = findLocalVariable(code, 'x in'); |
| 206 .localVariables[0]; | 203 checkMetadata(x); |
| 207 checkMetadata(localVariableElement); | |
| 208 } | 204 } |
| 209 | 205 |
| 210 void test_visitCatchClause() { | 206 void test_visitCatchClause() { |
| 211 List<LocalVariableElement> variables = | 207 var code = 'f() { try {} catch (e, s) {} }'; |
| 212 buildElementsForText('f() { try {} catch (e, s) {} }') | 208 buildElementsForText(code); |
| 213 .functions[0] | 209 var e = findLocalVariable(code, 'e, '); |
| 214 .localVariables; | 210 var s = findLocalVariable(code, 's) {}'); |
| 215 String exceptionParameterName = "e"; | |
| 216 String stackParameterName = "s"; | |
| 217 expect(variables, hasLength(2)); | |
| 218 | 211 |
| 219 LocalVariableElement exceptionVariable = variables[0]; | 212 expect(e, isNotNull); |
| 220 expect(exceptionVariable, isNotNull); | 213 expect(e.name, 'e'); |
| 221 expect(exceptionVariable.name, exceptionParameterName); | 214 expect(e.hasImplicitType, isTrue); |
| 222 expect(exceptionVariable.hasImplicitType, isTrue); | 215 expect(e.isSynthetic, isFalse); |
| 223 expect(exceptionVariable.isSynthetic, isFalse); | 216 expect(e.isConst, isFalse); |
| 224 expect(exceptionVariable.isConst, isFalse); | 217 expect(e.isFinal, isFalse); |
| 225 expect(exceptionVariable.isFinal, isFalse); | 218 expect(e.initializer, isNull); |
| 226 expect(exceptionVariable.initializer, isNull); | 219 _assertVisibleRange(e, 13, 28); |
| 227 _assertVisibleRange(exceptionVariable, 13, 28); | |
| 228 | 220 |
| 229 LocalVariableElement stackVariable = variables[1]; | 221 expect(s, isNotNull); |
| 230 expect(stackVariable, isNotNull); | 222 expect(s.name, 's'); |
| 231 expect(stackVariable.name, stackParameterName); | 223 expect(s.isSynthetic, isFalse); |
| 232 expect(stackVariable.isSynthetic, isFalse); | 224 expect(s.isConst, isFalse); |
| 233 expect(stackVariable.isConst, isFalse); | 225 expect(s.isFinal, isFalse); |
| 234 expect(stackVariable.isFinal, isFalse); | 226 expect(s.initializer, isNull); |
| 235 expect(stackVariable.initializer, isNull); | 227 _assertVisibleRange(s, 13, 28); |
| 236 _assertVisibleRange(stackVariable, 13, 28); | |
| 237 } | 228 } |
| 238 | 229 |
| 239 void test_visitCatchClause_withType() { | 230 void test_visitCatchClause_withType() { |
| 240 List<LocalVariableElement> variables = | 231 var code = 'f() { try {} on E catch (e) {} }'; |
| 241 buildElementsForText('f() { try {} on E catch (e) {} }') | 232 buildElementsForText(code); |
| 242 .functions[0] | 233 var e = findLocalVariable(code, 'e) {}'); |
| 243 .localVariables; | 234 expect(e, isNotNull); |
| 244 String exceptionParameterName = "e"; | 235 expect(e.name, 'e'); |
| 245 expect(variables, hasLength(1)); | 236 expect(e.hasImplicitType, isFalse); |
| 246 VariableElement exceptionVariable = variables[0]; | |
| 247 expect(exceptionVariable, isNotNull); | |
| 248 expect(exceptionVariable.name, exceptionParameterName); | |
| 249 expect(exceptionVariable.hasImplicitType, isFalse); | |
| 250 } | 237 } |
| 251 | 238 |
| 252 void test_visitCompilationUnit_codeRange() { | 239 void test_visitCompilationUnit_codeRange() { |
| 253 TopLevelVariableDeclaration topLevelVariableDeclaration = AstTestFactory | 240 TopLevelVariableDeclaration topLevelVariableDeclaration = AstTestFactory |
| 254 .topLevelVariableDeclaration(null, AstTestFactory.typeName4('int'), | 241 .topLevelVariableDeclaration(null, AstTestFactory.typeName4('int'), |
| 255 [AstTestFactory.variableDeclaration('V')]); | 242 [AstTestFactory.variableDeclaration('V')]); |
| 256 CompilationUnit unit = astFactory.compilationUnit( | 243 CompilationUnit unit = astFactory.compilationUnit( |
| 257 topLevelVariableDeclaration.beginToken, | 244 topLevelVariableDeclaration.beginToken, |
| 258 null, | 245 null, |
| 259 [], | 246 [], |
| 260 [topLevelVariableDeclaration], | 247 [topLevelVariableDeclaration], |
| 261 topLevelVariableDeclaration.endToken); | 248 topLevelVariableDeclaration.endToken); |
| 262 ElementHolder holder = new ElementHolder(); | 249 ElementHolder holder = new ElementHolder(); |
| 263 ElementBuilder builder = _makeBuilder(holder); | 250 ElementBuilder builder = _makeBuilder(holder); |
| 264 unit.beginToken.offset = 10; | 251 unit.beginToken.offset = 10; |
| 265 unit.endToken.offset = 40; | 252 unit.endToken.offset = 40; |
| 266 unit.accept(builder); | 253 unit.accept(builder); |
| 267 | 254 |
| 268 assertHasCodeRange(compilationUnitElement, 0, 41); | 255 assertHasCodeRange(compilationUnitElement, 0, 41); |
| 269 } | 256 } |
| 270 | 257 |
| 271 void test_visitDeclaredIdentifier_noType() { | 258 void test_visitDeclaredIdentifier_noType() { |
| 272 LocalVariableElement variable = | 259 var code = 'f() { for (var i in []) {} }'; |
| 273 buildElementsForText('f() { for (var i in []) {} }') | 260 buildElementsForText(code); |
| 274 .functions[0] | 261 var variable = findLocalVariable(code, 'i in'); |
| 275 .localVariables[0]; | |
| 276 assertHasCodeRange(variable, 11, 5); | 262 assertHasCodeRange(variable, 11, 5); |
| 277 expect(variable, isNotNull); | 263 expect(variable, isNotNull); |
| 278 expect(variable.hasImplicitType, isTrue); | 264 expect(variable.hasImplicitType, isTrue); |
| 279 expect(variable.isConst, isFalse); | 265 expect(variable.isConst, isFalse); |
| 280 expect(variable.isDeprecated, isFalse); | 266 expect(variable.isDeprecated, isFalse); |
| 281 expect(variable.isFinal, isFalse); | 267 expect(variable.isFinal, isFalse); |
| 282 expect(variable.isOverride, isFalse); | 268 expect(variable.isOverride, isFalse); |
| 283 expect(variable.isPrivate, isFalse); | 269 expect(variable.isPrivate, isFalse); |
| 284 expect(variable.isPublic, isTrue); | 270 expect(variable.isPublic, isTrue); |
| 285 expect(variable.isSynthetic, isFalse); | 271 expect(variable.isSynthetic, isFalse); |
| 286 expect(variable.name, 'i'); | 272 expect(variable.name, 'i'); |
| 287 } | 273 } |
| 288 | 274 |
| 289 void test_visitDeclaredIdentifier_type() { | 275 void test_visitDeclaredIdentifier_type() { |
| 290 LocalVariableElement variable = | 276 var code = 'f() { for (int i in []) {} }'; |
| 291 buildElementsForText('f() { for (int i in []) {} }') | 277 buildElementsForText(code); |
| 292 .functions[0] | 278 var variable = findLocalVariable(code, 'i in'); |
| 293 .localVariables[0]; | |
| 294 assertHasCodeRange(variable, 11, 5); | 279 assertHasCodeRange(variable, 11, 5); |
| 295 expect(variable.hasImplicitType, isFalse); | 280 expect(variable.hasImplicitType, isFalse); |
| 296 expect(variable.isConst, isFalse); | 281 expect(variable.isConst, isFalse); |
| 297 expect(variable.isDeprecated, isFalse); | 282 expect(variable.isDeprecated, isFalse); |
| 298 expect(variable.isFinal, isFalse); | 283 expect(variable.isFinal, isFalse); |
| 299 expect(variable.isOverride, isFalse); | 284 expect(variable.isOverride, isFalse); |
| 300 expect(variable.isPrivate, isFalse); | 285 expect(variable.isPrivate, isFalse); |
| 301 expect(variable.isPublic, isTrue); | 286 expect(variable.isPublic, isTrue); |
| 302 expect(variable.isSynthetic, isFalse); | 287 expect(variable.isSynthetic, isFalse); |
| 303 expect(variable.name, 'i'); | 288 expect(variable.name, 'i'); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 List<LabelElement> labels = | 484 List<LabelElement> labels = |
| 500 buildElementsForText('f() { l: print(42); }').functions[0].labels; | 485 buildElementsForText('f() { l: print(42); }').functions[0].labels; |
| 501 expect(labels, hasLength(1)); | 486 expect(labels, hasLength(1)); |
| 502 LabelElement label = labels[0]; | 487 LabelElement label = labels[0]; |
| 503 expect(label, isNotNull); | 488 expect(label, isNotNull); |
| 504 expect(label.name, 'l'); | 489 expect(label.name, 'l'); |
| 505 expect(label.isSynthetic, isFalse); | 490 expect(label.isSynthetic, isFalse); |
| 506 } | 491 } |
| 507 | 492 |
| 508 void test_visitMethodDeclaration_withMembers() { | 493 void test_visitMethodDeclaration_withMembers() { |
| 509 MethodElement method = buildElementsForText( | 494 var code = 'class C { m(p) { var v; try { l: return; } catch (e) {} } }'; |
| 510 'class C { m(p) { var v; try { l: return; } catch (e) {} } }') | 495 MethodElement method = buildElementsForText(code).types[0].methods[0]; |
| 511 .types[0] | |
| 512 .methods[0]; | |
| 513 String methodName = "m"; | 496 String methodName = "m"; |
| 514 String parameterName = "p"; | 497 String parameterName = "p"; |
| 515 String localVariableName = "v"; | |
| 516 String labelName = "l"; | 498 String labelName = "l"; |
| 517 String exceptionParameterName = "e"; | |
| 518 expect(method, isNotNull); | 499 expect(method, isNotNull); |
| 519 expect(method.hasImplicitReturnType, isTrue); | 500 expect(method.hasImplicitReturnType, isTrue); |
| 520 expect(method.name, methodName); | 501 expect(method.name, methodName); |
| 521 expect(method.typeParameters, hasLength(0)); | 502 expect(method.typeParameters, hasLength(0)); |
| 522 expect(method.isAbstract, isFalse); | 503 expect(method.isAbstract, isFalse); |
| 523 expect(method.isExternal, isFalse); | 504 expect(method.isExternal, isFalse); |
| 524 expect(method.isStatic, isFalse); | 505 expect(method.isStatic, isFalse); |
| 525 expect(method.isSynthetic, isFalse); | 506 expect(method.isSynthetic, isFalse); |
| 526 List<VariableElement> parameters = method.parameters; | 507 List<VariableElement> parameters = method.parameters; |
| 527 expect(parameters, hasLength(1)); | 508 expect(parameters, hasLength(1)); |
| 528 VariableElement parameter = parameters[0]; | 509 VariableElement parameter = parameters[0]; |
| 529 expect(parameter, isNotNull); | 510 expect(parameter, isNotNull); |
| 530 expect(parameter.name, parameterName); | 511 expect(parameter.name, parameterName); |
| 531 List<VariableElement> localVariables = method.localVariables; | 512 |
| 532 expect(localVariables, hasLength(2)); | 513 var v = findLocalVariable(code, 'v;'); |
| 533 VariableElement firstVariable = localVariables[0]; | 514 expect(v.name, 'v'); |
| 534 VariableElement secondVariable = localVariables[1]; | 515 |
| 535 expect(firstVariable, isNotNull); | 516 var e = findLocalVariable(code, 'e) {}'); |
| 536 expect(secondVariable, isNotNull); | 517 expect(e.name, 'e'); |
| 537 expect( | 518 |
| 538 (firstVariable.name == localVariableName && | |
| 539 secondVariable.name == exceptionParameterName) || | |
| 540 (firstVariable.name == exceptionParameterName && | |
| 541 secondVariable.name == localVariableName), | |
| 542 isTrue); | |
| 543 List<LabelElement> labels = method.labels; | 519 List<LabelElement> labels = method.labels; |
| 544 expect(labels, hasLength(1)); | 520 expect(labels, hasLength(1)); |
| 545 LabelElement label = labels[0]; | 521 LabelElement label = labels[0]; |
| 546 expect(label, isNotNull); | 522 expect(label, isNotNull); |
| 547 expect(label.name, labelName); | 523 expect(label.name, labelName); |
| 548 } | 524 } |
| 549 | 525 |
| 550 void test_visitNamedFormalParameter() { | 526 void test_visitNamedFormalParameter() { |
| 551 ElementHolder holder = new ElementHolder(); | 527 ElementHolder holder = new ElementHolder(); |
| 552 ElementBuilder builder = _makeBuilder(holder); | 528 ElementBuilder builder = _makeBuilder(holder); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 List<FieldElement> fields = holder.fields; | 703 List<FieldElement> fields = holder.fields; |
| 728 expect(fields, hasLength(1)); | 704 expect(fields, hasLength(1)); |
| 729 FieldElementImpl field = fields[0]; | 705 FieldElementImpl field = fields[0]; |
| 730 expect(field, isNotNull); | 706 expect(field, isNotNull); |
| 731 PropertyAccessorElementImpl setter = field.setter; | 707 PropertyAccessorElementImpl setter = field.setter; |
| 732 expect(setter, isNotNull); | 708 expect(setter, isNotNull); |
| 733 expect(setter.parameters[0].isCovariant, isTrue); | 709 expect(setter.parameters[0].isCovariant, isTrue); |
| 734 } | 710 } |
| 735 | 711 |
| 736 void test_visitVariableDeclaration_inConstructor() { | 712 void test_visitVariableDeclaration_inConstructor() { |
| 737 List<ConstructorElement> constructors = | 713 var code = 'class C { C() { var v = 1; } }'; |
| 738 buildElementsForText('class C { C() { var v = 1; } }') | 714 buildElementsForText(code); |
| 739 .types[0] | 715 var v = findLocalVariable(code, 'v ='); |
| 740 .constructors; | 716 assertHasCodeRange(v, 16, 10); |
| 741 expect(constructors, hasLength(1)); | 717 expect(v.hasImplicitType, isTrue); |
| 742 List<LocalVariableElement> variableElements = | 718 expect(v.name, 'v'); |
| 743 constructors[0].localVariables; | 719 _assertVisibleRange(v, 14, 28); |
| 744 expect(variableElements, hasLength(1)); | |
| 745 LocalVariableElement variableElement = variableElements[0]; | |
| 746 assertHasCodeRange(variableElement, 16, 10); | |
| 747 expect(variableElement.hasImplicitType, isTrue); | |
| 748 expect(variableElement.name, 'v'); | |
| 749 _assertVisibleRange(variableElement, 14, 28); | |
| 750 } | 720 } |
| 751 | 721 |
| 752 void test_visitVariableDeclaration_inForEachStatement() { | 722 void test_visitVariableDeclaration_inForEachStatement() { |
| 753 ElementHolder holder = new ElementHolder(); | 723 ElementHolder holder = new ElementHolder(); |
| 754 ElementBuilder builder = _makeBuilder(holder); | 724 ElementBuilder builder = _makeBuilder(holder); |
| 755 // | 725 // |
| 756 // m() { for (var v in []) } | 726 // m() { for (var v in []) } |
| 757 // | 727 // |
| 758 String variableName = "v"; | 728 String variableName = "v"; |
| 759 Statement statement = AstTestFactory.forEachStatement( | 729 DeclaredIdentifier variableIdentifier = |
| 760 AstTestFactory.declaredIdentifier3('v'), | 730 AstTestFactory.declaredIdentifier3('v'); |
| 761 AstTestFactory.listLiteral(), | 731 Statement statement = AstTestFactory.forEachStatement(variableIdentifier, |
| 762 AstTestFactory.block()); | 732 AstTestFactory.listLiteral(), AstTestFactory.block()); |
| 763 _setNodeSourceRange(statement, 100, 110); | 733 _setNodeSourceRange(statement, 100, 110); |
| 764 MethodDeclaration method = AstTestFactory.methodDeclaration2( | 734 MethodDeclaration method = AstTestFactory.methodDeclaration2( |
| 765 null, | 735 null, |
| 766 null, | 736 null, |
| 767 null, | 737 null, |
| 768 null, | 738 null, |
| 769 AstTestFactory.identifier3("m"), | 739 AstTestFactory.identifier3("m"), |
| 770 AstTestFactory.formalParameterList(), | 740 AstTestFactory.formalParameterList(), |
| 771 AstTestFactory.blockFunctionBody2([statement])); | 741 AstTestFactory.blockFunctionBody2([statement])); |
| 772 _setBlockBodySourceRange(method.body, 200, 220); | 742 _setBlockBodySourceRange(method.body, 200, 220); |
| 773 method.accept(builder); | 743 method.accept(builder); |
| 774 | 744 |
| 775 List<MethodElement> methods = holder.methods; | 745 List<MethodElement> methods = holder.methods; |
| 776 expect(methods, hasLength(1)); | 746 expect(methods, hasLength(1)); |
| 777 List<LocalVariableElement> variableElements = methods[0].localVariables; | 747 LocalVariableElement variableElement = variableIdentifier.element; |
| 778 expect(variableElements, hasLength(1)); | |
| 779 LocalVariableElement variableElement = variableElements[0]; | |
| 780 expect(variableElement.name, variableName); | 748 expect(variableElement.name, variableName); |
| 781 _assertVisibleRange(variableElement, 100, 110); | 749 _assertVisibleRange(variableElement, 100, 110); |
| 782 } | 750 } |
| 783 | 751 |
| 784 void test_visitVariableDeclaration_inForStatement() { | 752 void test_visitVariableDeclaration_inForStatement() { |
| 785 ElementHolder holder = new ElementHolder(); | 753 ElementHolder holder = new ElementHolder(); |
| 786 ElementBuilder builder = _makeBuilder(holder); | 754 ElementBuilder builder = _makeBuilder(holder); |
| 787 // | 755 // |
| 788 // m() { for (T v;;) } | 756 // m() { for (T v;;) } |
| 789 // | 757 // |
| 790 String variableName = "v"; | 758 String variableName = "v"; |
| 759 VariableDeclaration variableIdentifier = |
| 760 AstTestFactory.variableDeclaration('v'); |
| 791 ForStatement statement = AstTestFactory.forStatement2( | 761 ForStatement statement = AstTestFactory.forStatement2( |
| 792 AstTestFactory.variableDeclarationList( | 762 AstTestFactory.variableDeclarationList( |
| 793 null, | 763 null, AstTestFactory.typeName4('T'), [variableIdentifier]), |
| 794 AstTestFactory.typeName4('T'), | |
| 795 [AstTestFactory.variableDeclaration('v')]), | |
| 796 null, | 764 null, |
| 797 null, | 765 null, |
| 798 AstTestFactory.block()); | 766 AstTestFactory.block()); |
| 799 _setNodeSourceRange(statement, 100, 110); | 767 _setNodeSourceRange(statement, 100, 110); |
| 800 MethodDeclaration method = AstTestFactory.methodDeclaration2( | 768 MethodDeclaration method = AstTestFactory.methodDeclaration2( |
| 801 null, | 769 null, |
| 802 null, | 770 null, |
| 803 null, | 771 null, |
| 804 null, | 772 null, |
| 805 AstTestFactory.identifier3("m"), | 773 AstTestFactory.identifier3("m"), |
| 806 AstTestFactory.formalParameterList(), | 774 AstTestFactory.formalParameterList(), |
| 807 AstTestFactory.blockFunctionBody2([statement])); | 775 AstTestFactory.blockFunctionBody2([statement])); |
| 808 _setBlockBodySourceRange(method.body, 200, 220); | 776 _setBlockBodySourceRange(method.body, 200, 220); |
| 809 method.accept(builder); | 777 method.accept(builder); |
| 810 | 778 |
| 811 List<MethodElement> methods = holder.methods; | 779 List<MethodElement> methods = holder.methods; |
| 812 expect(methods, hasLength(1)); | 780 expect(methods, hasLength(1)); |
| 813 List<LocalVariableElement> variableElements = methods[0].localVariables; | 781 LocalVariableElement variableElement = variableIdentifier.element; |
| 814 expect(variableElements, hasLength(1)); | |
| 815 LocalVariableElement variableElement = variableElements[0]; | |
| 816 expect(variableElement.name, variableName); | 782 expect(variableElement.name, variableName); |
| 817 _assertVisibleRange(variableElement, 100, 110); | 783 _assertVisibleRange(variableElement, 100, 110); |
| 818 } | 784 } |
| 819 | 785 |
| 820 void test_visitVariableDeclaration_inMethod() { | 786 void test_visitVariableDeclaration_inMethod() { |
| 821 ElementHolder holder = new ElementHolder(); | 787 ElementHolder holder = new ElementHolder(); |
| 822 ElementBuilder builder = _makeBuilder(holder); | 788 ElementBuilder builder = _makeBuilder(holder); |
| 823 // | 789 // |
| 824 // m() {T v;} | 790 // m() {T v;} |
| 825 // | 791 // |
| 826 String variableName = "v"; | 792 String variableName = "v"; |
| 827 VariableDeclaration variable = | 793 VariableDeclaration variable = |
| 828 AstTestFactory.variableDeclaration2(variableName, null); | 794 AstTestFactory.variableDeclaration2(variableName, null); |
| 829 Statement statement = AstTestFactory.variableDeclarationStatement( | 795 Statement statement = AstTestFactory.variableDeclarationStatement( |
| 830 null, AstTestFactory.typeName4('T'), [variable]); | 796 null, AstTestFactory.typeName4('T'), [variable]); |
| 831 MethodDeclaration method = AstTestFactory.methodDeclaration2( | 797 MethodDeclaration method = AstTestFactory.methodDeclaration2( |
| 832 null, | 798 null, |
| 833 null, | 799 null, |
| 834 null, | 800 null, |
| 835 null, | 801 null, |
| 836 AstTestFactory.identifier3("m"), | 802 AstTestFactory.identifier3("m"), |
| 837 AstTestFactory.formalParameterList(), | 803 AstTestFactory.formalParameterList(), |
| 838 AstTestFactory.blockFunctionBody2([statement])); | 804 AstTestFactory.blockFunctionBody2([statement])); |
| 839 _setBlockBodySourceRange(method.body, 100, 110); | 805 _setBlockBodySourceRange(method.body, 100, 110); |
| 840 method.accept(builder); | 806 method.accept(builder); |
| 841 | 807 |
| 842 List<MethodElement> methods = holder.methods; | 808 List<MethodElement> methods = holder.methods; |
| 843 expect(methods, hasLength(1)); | 809 expect(methods, hasLength(1)); |
| 844 List<LocalVariableElement> variableElements = methods[0].localVariables; | 810 LocalVariableElement variableElement = variable.element; |
| 845 expect(variableElements, hasLength(1)); | |
| 846 LocalVariableElement variableElement = variableElements[0]; | |
| 847 expect(variableElement.hasImplicitType, isFalse); | 811 expect(variableElement.hasImplicitType, isFalse); |
| 848 expect(variableElement.name, variableName); | 812 expect(variableElement.name, variableName); |
| 849 _assertVisibleRange(variableElement, 100, 110); | 813 _assertVisibleRange(variableElement, 100, 110); |
| 850 } | 814 } |
| 851 | 815 |
| 852 void test_visitVariableDeclaration_localNestedInFunction() { | 816 void test_visitVariableDeclaration_localNestedInFunction() { |
| 853 ElementHolder holder = new ElementHolder(); | 817 ElementHolder holder = new ElementHolder(); |
| 854 ElementBuilder builder = _makeBuilder(holder); | 818 ElementBuilder builder = _makeBuilder(holder); |
| 855 // | 819 // |
| 856 // var f = () {var v;}; | 820 // var f = () {var v;}; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 872 | 836 |
| 873 List<FieldElement> variables = holder.fields; | 837 List<FieldElement> variables = holder.fields; |
| 874 expect(variables, hasLength(1)); | 838 expect(variables, hasLength(1)); |
| 875 FieldElement fieldElement = variables[0]; | 839 FieldElement fieldElement = variables[0]; |
| 876 expect(fieldElement, isNotNull); | 840 expect(fieldElement, isNotNull); |
| 877 FunctionElement initializerElement = fieldElement.initializer; | 841 FunctionElement initializerElement = fieldElement.initializer; |
| 878 expect(initializerElement, isNotNull); | 842 expect(initializerElement, isNotNull); |
| 879 expect(initializerElement.hasImplicitReturnType, isTrue); | 843 expect(initializerElement.hasImplicitReturnType, isTrue); |
| 880 List<FunctionElement> functionElements = initializerElement.functions; | 844 List<FunctionElement> functionElements = initializerElement.functions; |
| 881 expect(functionElements, hasLength(1)); | 845 expect(functionElements, hasLength(1)); |
| 882 List<LocalVariableElement> variableElements = | 846 LocalVariableElement variableElement = variable.element; |
| 883 functionElements[0].localVariables; | |
| 884 expect(variableElements, hasLength(1)); | |
| 885 LocalVariableElement variableElement = variableElements[0]; | |
| 886 expect(variableElement.hasImplicitType, isTrue); | 847 expect(variableElement.hasImplicitType, isTrue); |
| 887 expect(variableElement.isConst, isFalse); | 848 expect(variableElement.isConst, isFalse); |
| 888 expect(variableElement.isFinal, isFalse); | 849 expect(variableElement.isFinal, isFalse); |
| 889 expect(variableElement.isSynthetic, isFalse); | 850 expect(variableElement.isSynthetic, isFalse); |
| 890 expect(variableElement.name, variableName); | 851 expect(variableElement.name, variableName); |
| 891 } | 852 } |
| 892 | 853 |
| 893 void test_visitVariableDeclaration_noInitializer() { | 854 void test_visitVariableDeclaration_noInitializer() { |
| 894 // var v; | 855 // var v; |
| 895 ElementHolder holder = new ElementHolder(); | 856 ElementHolder holder = new ElementHolder(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 } | 985 } |
| 1025 | 986 |
| 1026 @reflectiveTest | 987 @reflectiveTest |
| 1027 class LocalElementBuilderTest extends _BaseTest { | 988 class LocalElementBuilderTest extends _BaseTest { |
| 1028 @override | 989 @override |
| 1029 AstVisitor createElementBuilder(ElementHolder holder) { | 990 AstVisitor createElementBuilder(ElementHolder holder) { |
| 1030 return new LocalElementBuilder(holder, compilationUnitElement); | 991 return new LocalElementBuilder(holder, compilationUnitElement); |
| 1031 } | 992 } |
| 1032 | 993 |
| 1033 void test_buildLocalElements() { | 994 void test_buildLocalElements() { |
| 1034 CompilationUnit unit = parseCompilationUnit(r''' | 995 var code = r''' |
| 1035 main() { | 996 main() { |
| 1036 int v1; | 997 int v1; |
| 1037 f1() { | 998 f1() { |
| 1038 int v2; | 999 int v2; |
| 1039 f2() { | 1000 f2() { |
| 1040 int v3; | 1001 int v3; |
| 1041 } | 1002 } |
| 1042 } | 1003 } |
| 1043 } | 1004 } |
| 1044 '''); | 1005 '''; |
| 1045 var mainAst = unit.declarations.single as FunctionDeclaration; | 1006 _compilationUnit = parseCompilationUnit(code); |
| 1007 var mainAst = _compilationUnit.declarations.single as FunctionDeclaration; |
| 1008 |
| 1046 // Build API elements. | 1009 // Build API elements. |
| 1047 FunctionElementImpl main; | 1010 FunctionElementImpl main; |
| 1048 { | 1011 { |
| 1049 ElementHolder holder = new ElementHolder(); | 1012 ElementHolder holder = new ElementHolder(); |
| 1050 unit.accept(new ApiElementBuilder(holder, compilationUnitElement)); | 1013 _compilationUnit |
| 1014 .accept(new ApiElementBuilder(holder, compilationUnitElement)); |
| 1051 main = holder.functions.single as FunctionElementImpl; | 1015 main = holder.functions.single as FunctionElementImpl; |
| 1052 } | 1016 } |
| 1053 expect(main.localVariables, isEmpty); | |
| 1054 expect(main.functions, isEmpty); | 1017 expect(main.functions, isEmpty); |
| 1018 |
| 1055 // Build local elements in body. | 1019 // Build local elements in body. |
| 1056 ElementHolder holder = new ElementHolder(); | 1020 ElementHolder holder = new ElementHolder(); |
| 1057 FunctionBody mainBody = mainAst.functionExpression.body; | 1021 FunctionBody mainBody = mainAst.functionExpression.body; |
| 1058 mainBody.accept(new LocalElementBuilder(holder, compilationUnitElement)); | 1022 mainBody.accept(new LocalElementBuilder(holder, compilationUnitElement)); |
| 1059 main.functions = holder.functions; | 1023 main.functions = holder.functions; |
| 1060 main.localVariables = holder.localVariables; | 1024 main.localVariables = holder.localVariables; |
| 1061 expect(main.localVariables.map((v) => v.name), ['v1']); | 1025 |
| 1026 var v1 = findLocalVariable(code, 'v1;'); |
| 1027 var v2 = findLocalVariable(code, 'v2;'); |
| 1028 var v3 = findLocalVariable(code, 'v3;'); |
| 1029 |
| 1030 expect(v1.enclosingElement, main); |
| 1062 expect(main.functions, hasLength(1)); | 1031 expect(main.functions, hasLength(1)); |
| 1063 { | 1032 { |
| 1064 FunctionElement f1 = main.functions[0]; | 1033 FunctionElement f1 = main.functions[0]; |
| 1065 expect(f1.name, 'f1'); | 1034 expect(f1.name, 'f1'); |
| 1066 expect(f1.localVariables.map((v) => v.name), ['v2']); | 1035 expect(v2.enclosingElement, f1); |
| 1067 expect(f1.functions, hasLength(1)); | 1036 expect(f1.functions, hasLength(1)); |
| 1068 { | 1037 { |
| 1069 FunctionElement f2 = f1.functions[0]; | 1038 FunctionElement f2 = f1.functions[0]; |
| 1070 expect(f2.name, 'f2'); | 1039 expect(f2.name, 'f2'); |
| 1071 expect(f2.localVariables.map((v) => v.name), ['v3']); | 1040 expect(v3.enclosingElement, f2); |
| 1072 expect(f2.functions, isEmpty); | 1041 expect(f2.functions, isEmpty); |
| 1073 } | 1042 } |
| 1074 } | 1043 } |
| 1075 } | 1044 } |
| 1076 | 1045 |
| 1077 void test_buildParameterInitializer() { | 1046 void test_buildParameterInitializer() { |
| 1078 CompilationUnit unit = parseCompilationUnit('f({p: 42}) {}'); | 1047 CompilationUnit unit = parseCompilationUnit('f({p: 42}) {}'); |
| 1079 var function = unit.declarations.single as FunctionDeclaration; | 1048 var function = unit.declarations.single as FunctionDeclaration; |
| 1080 var parameter = function.functionExpression.parameters.parameters.single | 1049 var parameter = function.functionExpression.parameters.parameters.single |
| 1081 as DefaultFormalParameter; | 1050 as DefaultFormalParameter; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 { | 1108 { |
| 1140 ElementHolder holder = new ElementHolder(); | 1109 ElementHolder holder = new ElementHolder(); |
| 1141 unit.accept(new ApiElementBuilder(holder, compilationUnitElement)); | 1110 unit.accept(new ApiElementBuilder(holder, compilationUnitElement)); |
| 1142 main = holder.functions.single as FunctionElementImpl; | 1111 main = holder.functions.single as FunctionElementImpl; |
| 1143 } | 1112 } |
| 1144 // Build local elements in body. | 1113 // Build local elements in body. |
| 1145 ElementHolder holder = new ElementHolder(); | 1114 ElementHolder holder = new ElementHolder(); |
| 1146 FunctionBody mainBody = mainAst.functionExpression.body; | 1115 FunctionBody mainBody = mainAst.functionExpression.body; |
| 1147 mainBody.accept(new LocalElementBuilder(holder, compilationUnitElement)); | 1116 mainBody.accept(new LocalElementBuilder(holder, compilationUnitElement)); |
| 1148 main.functions = holder.functions; | 1117 main.functions = holder.functions; |
| 1149 main.localVariables = holder.localVariables; | |
| 1150 expect(main.functions, hasLength(1)); | 1118 expect(main.functions, hasLength(1)); |
| 1151 FunctionElement f = main.functions[0]; | 1119 FunctionElement f = main.functions[0]; |
| 1152 expect(f.parameters, hasLength(1)); | 1120 expect(f.parameters, hasLength(1)); |
| 1153 expect(f.parameters[0].initializer, isNotNull); | 1121 expect(f.parameters[0].initializer, isNotNull); |
| 1154 } | 1122 } |
| 1155 | 1123 |
| 1156 void test_visitFieldFormalParameter() { | 1124 void test_visitFieldFormalParameter() { |
| 1157 CompilationUnit unit = parseCompilationUnit( | 1125 CompilationUnit unit = parseCompilationUnit( |
| 1158 r''' | 1126 r''' |
| 1159 main() { | 1127 main() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1184 ParameterElement a = parameters[0].element; | 1152 ParameterElement a = parameters[0].element; |
| 1185 expect(a, isNotNull); | 1153 expect(a, isNotNull); |
| 1186 expect(a.name, 'a'); | 1154 expect(a.name, 'a'); |
| 1187 | 1155 |
| 1188 ParameterElement b = parameters[1].element; | 1156 ParameterElement b = parameters[1].element; |
| 1189 expect(b, isNotNull); | 1157 expect(b, isNotNull); |
| 1190 expect(b.name, 'b'); | 1158 expect(b.name, 'b'); |
| 1191 } | 1159 } |
| 1192 | 1160 |
| 1193 void test_visitVariableDeclaration_local() { | 1161 void test_visitVariableDeclaration_local() { |
| 1194 var holder = buildElementsForText('class C { m() { T v = null; } }'); | 1162 var code = 'class C { m() { T v = null; } }'; |
| 1195 List<LocalVariableElement> variableElements = holder.localVariables; | 1163 buildElementsForText(code); |
| 1196 expect(variableElements, hasLength(1)); | 1164 LocalVariableElement element = findIdentifier(code, 'v =').staticElement; |
| 1197 LocalVariableElement variableElement = variableElements[0]; | 1165 expect(element.hasImplicitType, isFalse); |
| 1198 expect(variableElement.hasImplicitType, isFalse); | 1166 expect(element.name, 'v'); |
| 1199 expect(variableElement.name, 'v'); | 1167 expect(element.initializer, isNotNull); |
| 1200 expect(variableElement.initializer, isNotNull); | 1168 _assertVisibleRange(element, 14, 29); |
| 1201 _assertVisibleRange(variableElement, 14, 29); | |
| 1202 } | 1169 } |
| 1203 } | 1170 } |
| 1204 | 1171 |
| 1205 /** | 1172 /** |
| 1206 * Mixin with test methods for testing element building in [ApiElementBuilder]. | 1173 * Mixin with test methods for testing element building in [ApiElementBuilder]. |
| 1207 * It is used to test the [ApiElementBuilder] itself, and its usage by | 1174 * It is used to test the [ApiElementBuilder] itself, and its usage by |
| 1208 * [ElementBuilder]. | 1175 * [ElementBuilder]. |
| 1209 */ | 1176 */ |
| 1210 abstract class _ApiElementBuilderTestMixin { | 1177 abstract class _ApiElementBuilderTestMixin { |
| 1211 CompilationUnit get compilationUnit; | 1178 CompilationUnit get compilationUnit; |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1634 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
| 1668 List<ConstructorElement> constructors = holder.constructors; | 1635 List<ConstructorElement> constructors = holder.constructors; |
| 1669 expect(constructors, hasLength(1)); | 1636 expect(constructors, hasLength(1)); |
| 1670 ConstructorElement constructor = constructors[0]; | 1637 ConstructorElement constructor = constructors[0]; |
| 1671 expect(constructor, isNotNull); | 1638 expect(constructor, isNotNull); |
| 1672 expect(constructor.isExternal, isTrue); | 1639 expect(constructor.isExternal, isTrue); |
| 1673 expect(constructor.isFactory, isFalse); | 1640 expect(constructor.isFactory, isFalse); |
| 1674 expect(constructor.name, ""); | 1641 expect(constructor.name, ""); |
| 1675 expect(constructor.functions, hasLength(0)); | 1642 expect(constructor.functions, hasLength(0)); |
| 1676 expect(constructor.labels, hasLength(0)); | 1643 expect(constructor.labels, hasLength(0)); |
| 1677 expect(constructor.localVariables, hasLength(0)); | |
| 1678 expect(constructor.parameters, hasLength(0)); | 1644 expect(constructor.parameters, hasLength(0)); |
| 1679 } | 1645 } |
| 1680 | 1646 |
| 1681 void test_visitConstructorDeclaration_factory() { | 1647 void test_visitConstructorDeclaration_factory() { |
| 1682 String className = "A"; | 1648 String className = "A"; |
| 1683 ConstructorDeclaration constructorDeclaration = | 1649 ConstructorDeclaration constructorDeclaration = |
| 1684 AstTestFactory.constructorDeclaration2( | 1650 AstTestFactory.constructorDeclaration2( |
| 1685 null, | 1651 null, |
| 1686 Keyword.FACTORY, | 1652 Keyword.FACTORY, |
| 1687 AstTestFactory.identifier3(className), | 1653 AstTestFactory.identifier3(className), |
| 1688 null, | 1654 null, |
| 1689 AstTestFactory.formalParameterList(), | 1655 AstTestFactory.formalParameterList(), |
| 1690 null, | 1656 null, |
| 1691 AstTestFactory.blockFunctionBody2()); | 1657 AstTestFactory.blockFunctionBody2()); |
| 1692 | 1658 |
| 1693 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1659 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
| 1694 List<ConstructorElement> constructors = holder.constructors; | 1660 List<ConstructorElement> constructors = holder.constructors; |
| 1695 expect(constructors, hasLength(1)); | 1661 expect(constructors, hasLength(1)); |
| 1696 ConstructorElement constructor = constructors[0]; | 1662 ConstructorElement constructor = constructors[0]; |
| 1697 expect(constructor, isNotNull); | 1663 expect(constructor, isNotNull); |
| 1698 expect(constructor.isExternal, isFalse); | 1664 expect(constructor.isExternal, isFalse); |
| 1699 expect(constructor.isFactory, isTrue); | 1665 expect(constructor.isFactory, isTrue); |
| 1700 expect(constructor.name, ""); | 1666 expect(constructor.name, ""); |
| 1701 expect(constructor.functions, hasLength(0)); | 1667 expect(constructor.functions, hasLength(0)); |
| 1702 expect(constructor.labels, hasLength(0)); | 1668 expect(constructor.labels, hasLength(0)); |
| 1703 expect(constructor.localVariables, hasLength(0)); | |
| 1704 expect(constructor.parameters, hasLength(0)); | 1669 expect(constructor.parameters, hasLength(0)); |
| 1705 } | 1670 } |
| 1706 | 1671 |
| 1707 void test_visitConstructorDeclaration_minimal() { | 1672 void test_visitConstructorDeclaration_minimal() { |
| 1708 String className = "A"; | 1673 String className = "A"; |
| 1709 ConstructorDeclaration constructorDeclaration = | 1674 ConstructorDeclaration constructorDeclaration = |
| 1710 AstTestFactory.constructorDeclaration2( | 1675 AstTestFactory.constructorDeclaration2( |
| 1711 null, | 1676 null, |
| 1712 null, | 1677 null, |
| 1713 AstTestFactory.identifier3(className), | 1678 AstTestFactory.identifier3(className), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1725 expect(constructors, hasLength(1)); | 1690 expect(constructors, hasLength(1)); |
| 1726 ConstructorElement constructor = constructors[0]; | 1691 ConstructorElement constructor = constructors[0]; |
| 1727 expect(constructor, isNotNull); | 1692 expect(constructor, isNotNull); |
| 1728 assertHasCodeRange(constructor, 50, 31); | 1693 assertHasCodeRange(constructor, 50, 31); |
| 1729 expect(constructor.documentationComment, '/// aaa'); | 1694 expect(constructor.documentationComment, '/// aaa'); |
| 1730 expect(constructor.isExternal, isFalse); | 1695 expect(constructor.isExternal, isFalse); |
| 1731 expect(constructor.isFactory, isFalse); | 1696 expect(constructor.isFactory, isFalse); |
| 1732 expect(constructor.name, ""); | 1697 expect(constructor.name, ""); |
| 1733 expect(constructor.functions, hasLength(0)); | 1698 expect(constructor.functions, hasLength(0)); |
| 1734 expect(constructor.labels, hasLength(0)); | 1699 expect(constructor.labels, hasLength(0)); |
| 1735 expect(constructor.localVariables, hasLength(0)); | |
| 1736 expect(constructor.parameters, hasLength(0)); | 1700 expect(constructor.parameters, hasLength(0)); |
| 1737 } | 1701 } |
| 1738 | 1702 |
| 1739 void test_visitConstructorDeclaration_named() { | 1703 void test_visitConstructorDeclaration_named() { |
| 1740 String className = "A"; | 1704 String className = "A"; |
| 1741 String constructorName = "c"; | 1705 String constructorName = "c"; |
| 1742 ConstructorDeclaration constructorDeclaration = | 1706 ConstructorDeclaration constructorDeclaration = |
| 1743 AstTestFactory.constructorDeclaration2( | 1707 AstTestFactory.constructorDeclaration2( |
| 1744 null, | 1708 null, |
| 1745 null, | 1709 null, |
| 1746 AstTestFactory.identifier3(className), | 1710 AstTestFactory.identifier3(className), |
| 1747 constructorName, | 1711 constructorName, |
| 1748 AstTestFactory.formalParameterList(), | 1712 AstTestFactory.formalParameterList(), |
| 1749 null, | 1713 null, |
| 1750 AstTestFactory.blockFunctionBody2()); | 1714 AstTestFactory.blockFunctionBody2()); |
| 1751 | 1715 |
| 1752 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1716 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
| 1753 List<ConstructorElement> constructors = holder.constructors; | 1717 List<ConstructorElement> constructors = holder.constructors; |
| 1754 expect(constructors, hasLength(1)); | 1718 expect(constructors, hasLength(1)); |
| 1755 ConstructorElement constructor = constructors[0]; | 1719 ConstructorElement constructor = constructors[0]; |
| 1756 expect(constructor, isNotNull); | 1720 expect(constructor, isNotNull); |
| 1757 expect(constructor.isExternal, isFalse); | 1721 expect(constructor.isExternal, isFalse); |
| 1758 expect(constructor.isFactory, isFalse); | 1722 expect(constructor.isFactory, isFalse); |
| 1759 expect(constructor.name, constructorName); | 1723 expect(constructor.name, constructorName); |
| 1760 expect(constructor.functions, hasLength(0)); | 1724 expect(constructor.functions, hasLength(0)); |
| 1761 expect(constructor.labels, hasLength(0)); | 1725 expect(constructor.labels, hasLength(0)); |
| 1762 expect(constructor.localVariables, hasLength(0)); | |
| 1763 expect(constructor.parameters, hasLength(0)); | 1726 expect(constructor.parameters, hasLength(0)); |
| 1764 expect(constructorDeclaration.name.staticElement, same(constructor)); | 1727 expect(constructorDeclaration.name.staticElement, same(constructor)); |
| 1765 expect(constructorDeclaration.element, same(constructor)); | 1728 expect(constructorDeclaration.element, same(constructor)); |
| 1766 } | 1729 } |
| 1767 | 1730 |
| 1768 void test_visitConstructorDeclaration_unnamed() { | 1731 void test_visitConstructorDeclaration_unnamed() { |
| 1769 String className = "A"; | 1732 String className = "A"; |
| 1770 ConstructorDeclaration constructorDeclaration = | 1733 ConstructorDeclaration constructorDeclaration = |
| 1771 AstTestFactory.constructorDeclaration2( | 1734 AstTestFactory.constructorDeclaration2( |
| 1772 null, | 1735 null, |
| 1773 null, | 1736 null, |
| 1774 AstTestFactory.identifier3(className), | 1737 AstTestFactory.identifier3(className), |
| 1775 null, | 1738 null, |
| 1776 AstTestFactory.formalParameterList(), | 1739 AstTestFactory.formalParameterList(), |
| 1777 null, | 1740 null, |
| 1778 AstTestFactory.blockFunctionBody2()); | 1741 AstTestFactory.blockFunctionBody2()); |
| 1779 | 1742 |
| 1780 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1743 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
| 1781 List<ConstructorElement> constructors = holder.constructors; | 1744 List<ConstructorElement> constructors = holder.constructors; |
| 1782 expect(constructors, hasLength(1)); | 1745 expect(constructors, hasLength(1)); |
| 1783 ConstructorElement constructor = constructors[0]; | 1746 ConstructorElement constructor = constructors[0]; |
| 1784 expect(constructor, isNotNull); | 1747 expect(constructor, isNotNull); |
| 1785 expect(constructor.isExternal, isFalse); | 1748 expect(constructor.isExternal, isFalse); |
| 1786 expect(constructor.isFactory, isFalse); | 1749 expect(constructor.isFactory, isFalse); |
| 1787 expect(constructor.name, ""); | 1750 expect(constructor.name, ""); |
| 1788 expect(constructor.functions, hasLength(0)); | 1751 expect(constructor.functions, hasLength(0)); |
| 1789 expect(constructor.labels, hasLength(0)); | 1752 expect(constructor.labels, hasLength(0)); |
| 1790 expect(constructor.localVariables, hasLength(0)); | |
| 1791 expect(constructor.parameters, hasLength(0)); | 1753 expect(constructor.parameters, hasLength(0)); |
| 1792 expect(constructorDeclaration.element, same(constructor)); | 1754 expect(constructorDeclaration.element, same(constructor)); |
| 1793 } | 1755 } |
| 1794 | 1756 |
| 1795 void test_visitEnumDeclaration() { | 1757 void test_visitEnumDeclaration() { |
| 1796 String enumName = "E"; | 1758 String enumName = "E"; |
| 1797 EnumDeclaration enumDeclaration = | 1759 EnumDeclaration enumDeclaration = |
| 1798 AstTestFactory.enumDeclaration2(enumName, ["ONE"]); | 1760 AstTestFactory.enumDeclaration2(enumName, ["ONE"]); |
| 1799 enumDeclaration.documentationComment = AstTestFactory.documentationComment( | 1761 enumDeclaration.documentationComment = AstTestFactory.documentationComment( |
| 1800 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1762 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2071 | 2033 |
| 2072 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2034 ElementHolder holder = buildElementsForAst(methodDeclaration); |
| 2073 List<MethodElement> methods = holder.methods; | 2035 List<MethodElement> methods = holder.methods; |
| 2074 expect(methods, hasLength(1)); | 2036 expect(methods, hasLength(1)); |
| 2075 MethodElement method = methods[0]; | 2037 MethodElement method = methods[0]; |
| 2076 expect(method, isNotNull); | 2038 expect(method, isNotNull); |
| 2077 expect(method.hasImplicitReturnType, isTrue); | 2039 expect(method.hasImplicitReturnType, isTrue); |
| 2078 expect(method.name, methodName); | 2040 expect(method.name, methodName); |
| 2079 expect(method.functions, hasLength(0)); | 2041 expect(method.functions, hasLength(0)); |
| 2080 expect(method.labels, hasLength(0)); | 2042 expect(method.labels, hasLength(0)); |
| 2081 expect(method.localVariables, hasLength(0)); | |
| 2082 expect(method.parameters, hasLength(0)); | 2043 expect(method.parameters, hasLength(0)); |
| 2083 expect(method.typeParameters, hasLength(0)); | 2044 expect(method.typeParameters, hasLength(0)); |
| 2084 expect(method.isAbstract, isTrue); | 2045 expect(method.isAbstract, isTrue); |
| 2085 expect(method.isExternal, isFalse); | 2046 expect(method.isExternal, isFalse); |
| 2086 expect(method.isStatic, isFalse); | 2047 expect(method.isStatic, isFalse); |
| 2087 expect(method.isSynthetic, isFalse); | 2048 expect(method.isSynthetic, isFalse); |
| 2088 } | 2049 } |
| 2089 | 2050 |
| 2090 void test_visitMethodDeclaration_duplicateField_synthetic() { | 2051 void test_visitMethodDeclaration_duplicateField_synthetic() { |
| 2091 buildElementsForText(r''' | 2052 buildElementsForText(r''' |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2140 | 2101 |
| 2141 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2102 ElementHolder holder = buildElementsForAst(methodDeclaration); |
| 2142 List<MethodElement> methods = holder.methods; | 2103 List<MethodElement> methods = holder.methods; |
| 2143 expect(methods, hasLength(1)); | 2104 expect(methods, hasLength(1)); |
| 2144 MethodElement method = methods[0]; | 2105 MethodElement method = methods[0]; |
| 2145 expect(method, isNotNull); | 2106 expect(method, isNotNull); |
| 2146 expect(method.hasImplicitReturnType, isTrue); | 2107 expect(method.hasImplicitReturnType, isTrue); |
| 2147 expect(method.name, methodName); | 2108 expect(method.name, methodName); |
| 2148 expect(method.functions, hasLength(0)); | 2109 expect(method.functions, hasLength(0)); |
| 2149 expect(method.labels, hasLength(0)); | 2110 expect(method.labels, hasLength(0)); |
| 2150 expect(method.localVariables, hasLength(0)); | |
| 2151 expect(method.parameters, hasLength(0)); | 2111 expect(method.parameters, hasLength(0)); |
| 2152 expect(method.typeParameters, hasLength(0)); | 2112 expect(method.typeParameters, hasLength(0)); |
| 2153 expect(method.isAbstract, isFalse); | 2113 expect(method.isAbstract, isFalse); |
| 2154 expect(method.isExternal, isTrue); | 2114 expect(method.isExternal, isTrue); |
| 2155 expect(method.isStatic, isFalse); | 2115 expect(method.isStatic, isFalse); |
| 2156 expect(method.isSynthetic, isFalse); | 2116 expect(method.isSynthetic, isFalse); |
| 2157 } | 2117 } |
| 2158 | 2118 |
| 2159 void test_visitMethodDeclaration_getter() { | 2119 void test_visitMethodDeclaration_getter() { |
| 2160 // get m() {} | 2120 // get m() {} |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2186 expect(getter.documentationComment, '/// aaa'); | 2146 expect(getter.documentationComment, '/// aaa'); |
| 2187 expect(getter.hasImplicitReturnType, isTrue); | 2147 expect(getter.hasImplicitReturnType, isTrue); |
| 2188 expect(getter.isAbstract, isFalse); | 2148 expect(getter.isAbstract, isFalse); |
| 2189 expect(getter.isExternal, isFalse); | 2149 expect(getter.isExternal, isFalse); |
| 2190 expect(getter.isGetter, isTrue); | 2150 expect(getter.isGetter, isTrue); |
| 2191 expect(getter.isSynthetic, isFalse); | 2151 expect(getter.isSynthetic, isFalse); |
| 2192 expect(getter.name, methodName); | 2152 expect(getter.name, methodName); |
| 2193 expect(getter.variable, field); | 2153 expect(getter.variable, field); |
| 2194 expect(getter.functions, hasLength(0)); | 2154 expect(getter.functions, hasLength(0)); |
| 2195 expect(getter.labels, hasLength(0)); | 2155 expect(getter.labels, hasLength(0)); |
| 2196 expect(getter.localVariables, hasLength(0)); | |
| 2197 expect(getter.parameters, hasLength(0)); | 2156 expect(getter.parameters, hasLength(0)); |
| 2198 } | 2157 } |
| 2199 | 2158 |
| 2200 void test_visitMethodDeclaration_getter_abstract() { | 2159 void test_visitMethodDeclaration_getter_abstract() { |
| 2201 // get m(); | 2160 // get m(); |
| 2202 String methodName = "m"; | 2161 String methodName = "m"; |
| 2203 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2162 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
| 2204 null, | 2163 null, |
| 2205 null, | 2164 null, |
| 2206 Keyword.GET, | 2165 Keyword.GET, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2221 expect(getter, isNotNull); | 2180 expect(getter, isNotNull); |
| 2222 expect(getter.hasImplicitReturnType, isTrue); | 2181 expect(getter.hasImplicitReturnType, isTrue); |
| 2223 expect(getter.isAbstract, isTrue); | 2182 expect(getter.isAbstract, isTrue); |
| 2224 expect(getter.isExternal, isFalse); | 2183 expect(getter.isExternal, isFalse); |
| 2225 expect(getter.isGetter, isTrue); | 2184 expect(getter.isGetter, isTrue); |
| 2226 expect(getter.isSynthetic, isFalse); | 2185 expect(getter.isSynthetic, isFalse); |
| 2227 expect(getter.name, methodName); | 2186 expect(getter.name, methodName); |
| 2228 expect(getter.variable, field); | 2187 expect(getter.variable, field); |
| 2229 expect(getter.functions, hasLength(0)); | 2188 expect(getter.functions, hasLength(0)); |
| 2230 expect(getter.labels, hasLength(0)); | 2189 expect(getter.labels, hasLength(0)); |
| 2231 expect(getter.localVariables, hasLength(0)); | |
| 2232 expect(getter.parameters, hasLength(0)); | 2190 expect(getter.parameters, hasLength(0)); |
| 2233 } | 2191 } |
| 2234 | 2192 |
| 2235 void test_visitMethodDeclaration_getter_external() { | 2193 void test_visitMethodDeclaration_getter_external() { |
| 2236 // external get m(); | 2194 // external get m(); |
| 2237 String methodName = "m"; | 2195 String methodName = "m"; |
| 2238 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( | 2196 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( |
| 2239 null, | 2197 null, |
| 2240 null, | 2198 null, |
| 2241 Keyword.GET, | 2199 Keyword.GET, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2257 expect(getter, isNotNull); | 2215 expect(getter, isNotNull); |
| 2258 expect(getter.hasImplicitReturnType, isTrue); | 2216 expect(getter.hasImplicitReturnType, isTrue); |
| 2259 expect(getter.isAbstract, isFalse); | 2217 expect(getter.isAbstract, isFalse); |
| 2260 expect(getter.isExternal, isTrue); | 2218 expect(getter.isExternal, isTrue); |
| 2261 expect(getter.isGetter, isTrue); | 2219 expect(getter.isGetter, isTrue); |
| 2262 expect(getter.isSynthetic, isFalse); | 2220 expect(getter.isSynthetic, isFalse); |
| 2263 expect(getter.name, methodName); | 2221 expect(getter.name, methodName); |
| 2264 expect(getter.variable, field); | 2222 expect(getter.variable, field); |
| 2265 expect(getter.functions, hasLength(0)); | 2223 expect(getter.functions, hasLength(0)); |
| 2266 expect(getter.labels, hasLength(0)); | 2224 expect(getter.labels, hasLength(0)); |
| 2267 expect(getter.localVariables, hasLength(0)); | |
| 2268 expect(getter.parameters, hasLength(0)); | 2225 expect(getter.parameters, hasLength(0)); |
| 2269 } | 2226 } |
| 2270 | 2227 |
| 2271 void test_visitMethodDeclaration_minimal() { | 2228 void test_visitMethodDeclaration_minimal() { |
| 2272 // T m() {} | 2229 // T m() {} |
| 2273 String methodName = "m"; | 2230 String methodName = "m"; |
| 2274 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2231 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
| 2275 null, | 2232 null, |
| 2276 AstTestFactory.typeName4('T'), | 2233 AstTestFactory.typeName4('T'), |
| 2277 null, | 2234 null, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2288 List<MethodElement> methods = holder.methods; | 2245 List<MethodElement> methods = holder.methods; |
| 2289 expect(methods, hasLength(1)); | 2246 expect(methods, hasLength(1)); |
| 2290 MethodElement method = methods[0]; | 2247 MethodElement method = methods[0]; |
| 2291 expect(method, isNotNull); | 2248 expect(method, isNotNull); |
| 2292 assertHasCodeRange(method, 50, 31); | 2249 assertHasCodeRange(method, 50, 31); |
| 2293 expect(method.documentationComment, '/// aaa'); | 2250 expect(method.documentationComment, '/// aaa'); |
| 2294 expect(method.hasImplicitReturnType, isFalse); | 2251 expect(method.hasImplicitReturnType, isFalse); |
| 2295 expect(method.name, methodName); | 2252 expect(method.name, methodName); |
| 2296 expect(method.functions, hasLength(0)); | 2253 expect(method.functions, hasLength(0)); |
| 2297 expect(method.labels, hasLength(0)); | 2254 expect(method.labels, hasLength(0)); |
| 2298 expect(method.localVariables, hasLength(0)); | |
| 2299 expect(method.parameters, hasLength(0)); | 2255 expect(method.parameters, hasLength(0)); |
| 2300 expect(method.typeParameters, hasLength(0)); | 2256 expect(method.typeParameters, hasLength(0)); |
| 2301 expect(method.isAbstract, isFalse); | 2257 expect(method.isAbstract, isFalse); |
| 2302 expect(method.isExternal, isFalse); | 2258 expect(method.isExternal, isFalse); |
| 2303 expect(method.isStatic, isFalse); | 2259 expect(method.isStatic, isFalse); |
| 2304 expect(method.isSynthetic, isFalse); | 2260 expect(method.isSynthetic, isFalse); |
| 2305 } | 2261 } |
| 2306 | 2262 |
| 2307 void test_visitMethodDeclaration_operator() { | 2263 void test_visitMethodDeclaration_operator() { |
| 2308 // operator +(addend) {} | 2264 // operator +(addend) {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2319 | 2275 |
| 2320 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2276 ElementHolder holder = buildElementsForAst(methodDeclaration); |
| 2321 List<MethodElement> methods = holder.methods; | 2277 List<MethodElement> methods = holder.methods; |
| 2322 expect(methods, hasLength(1)); | 2278 expect(methods, hasLength(1)); |
| 2323 MethodElement method = methods[0]; | 2279 MethodElement method = methods[0]; |
| 2324 expect(method, isNotNull); | 2280 expect(method, isNotNull); |
| 2325 expect(method.hasImplicitReturnType, isTrue); | 2281 expect(method.hasImplicitReturnType, isTrue); |
| 2326 expect(method.name, methodName); | 2282 expect(method.name, methodName); |
| 2327 expect(method.functions, hasLength(0)); | 2283 expect(method.functions, hasLength(0)); |
| 2328 expect(method.labels, hasLength(0)); | 2284 expect(method.labels, hasLength(0)); |
| 2329 expect(method.localVariables, hasLength(0)); | |
| 2330 expect(method.parameters, hasLength(1)); | 2285 expect(method.parameters, hasLength(1)); |
| 2331 expect(method.typeParameters, hasLength(0)); | 2286 expect(method.typeParameters, hasLength(0)); |
| 2332 expect(method.isAbstract, isFalse); | 2287 expect(method.isAbstract, isFalse); |
| 2333 expect(method.isExternal, isFalse); | 2288 expect(method.isExternal, isFalse); |
| 2334 expect(method.isStatic, isFalse); | 2289 expect(method.isStatic, isFalse); |
| 2335 expect(method.isSynthetic, isFalse); | 2290 expect(method.isSynthetic, isFalse); |
| 2336 } | 2291 } |
| 2337 | 2292 |
| 2338 void test_visitMethodDeclaration_setter() { | 2293 void test_visitMethodDeclaration_setter() { |
| 2339 // set m() {} | 2294 // set m() {} |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2367 expect(setter.hasImplicitReturnType, isTrue); | 2322 expect(setter.hasImplicitReturnType, isTrue); |
| 2368 expect(setter.isAbstract, isFalse); | 2323 expect(setter.isAbstract, isFalse); |
| 2369 expect(setter.isExternal, isFalse); | 2324 expect(setter.isExternal, isFalse); |
| 2370 expect(setter.isSetter, isTrue); | 2325 expect(setter.isSetter, isTrue); |
| 2371 expect(setter.isSynthetic, isFalse); | 2326 expect(setter.isSynthetic, isFalse); |
| 2372 expect(setter.name, "$methodName="); | 2327 expect(setter.name, "$methodName="); |
| 2373 expect(setter.displayName, methodName); | 2328 expect(setter.displayName, methodName); |
| 2374 expect(setter.variable, field); | 2329 expect(setter.variable, field); |
| 2375 expect(setter.functions, hasLength(0)); | 2330 expect(setter.functions, hasLength(0)); |
| 2376 expect(setter.labels, hasLength(0)); | 2331 expect(setter.labels, hasLength(0)); |
| 2377 expect(setter.localVariables, hasLength(0)); | |
| 2378 expect(setter.parameters, hasLength(0)); | 2332 expect(setter.parameters, hasLength(0)); |
| 2379 } | 2333 } |
| 2380 | 2334 |
| 2381 void test_visitMethodDeclaration_setter_abstract() { | 2335 void test_visitMethodDeclaration_setter_abstract() { |
| 2382 // set m(); | 2336 // set m(); |
| 2383 String methodName = "m"; | 2337 String methodName = "m"; |
| 2384 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2338 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
| 2385 null, | 2339 null, |
| 2386 null, | 2340 null, |
| 2387 Keyword.SET, | 2341 Keyword.SET, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2403 expect(setter.hasImplicitReturnType, isTrue); | 2357 expect(setter.hasImplicitReturnType, isTrue); |
| 2404 expect(setter.isAbstract, isTrue); | 2358 expect(setter.isAbstract, isTrue); |
| 2405 expect(setter.isExternal, isFalse); | 2359 expect(setter.isExternal, isFalse); |
| 2406 expect(setter.isSetter, isTrue); | 2360 expect(setter.isSetter, isTrue); |
| 2407 expect(setter.isSynthetic, isFalse); | 2361 expect(setter.isSynthetic, isFalse); |
| 2408 expect(setter.name, "$methodName="); | 2362 expect(setter.name, "$methodName="); |
| 2409 expect(setter.displayName, methodName); | 2363 expect(setter.displayName, methodName); |
| 2410 expect(setter.variable, field); | 2364 expect(setter.variable, field); |
| 2411 expect(setter.functions, hasLength(0)); | 2365 expect(setter.functions, hasLength(0)); |
| 2412 expect(setter.labels, hasLength(0)); | 2366 expect(setter.labels, hasLength(0)); |
| 2413 expect(setter.localVariables, hasLength(0)); | |
| 2414 expect(setter.parameters, hasLength(0)); | 2367 expect(setter.parameters, hasLength(0)); |
| 2415 } | 2368 } |
| 2416 | 2369 |
| 2417 void test_visitMethodDeclaration_setter_external() { | 2370 void test_visitMethodDeclaration_setter_external() { |
| 2418 // external m(); | 2371 // external m(); |
| 2419 String methodName = "m"; | 2372 String methodName = "m"; |
| 2420 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( | 2373 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( |
| 2421 null, | 2374 null, |
| 2422 null, | 2375 null, |
| 2423 Keyword.SET, | 2376 Keyword.SET, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2440 expect(setter.hasImplicitReturnType, isTrue); | 2393 expect(setter.hasImplicitReturnType, isTrue); |
| 2441 expect(setter.isAbstract, isFalse); | 2394 expect(setter.isAbstract, isFalse); |
| 2442 expect(setter.isExternal, isTrue); | 2395 expect(setter.isExternal, isTrue); |
| 2443 expect(setter.isSetter, isTrue); | 2396 expect(setter.isSetter, isTrue); |
| 2444 expect(setter.isSynthetic, isFalse); | 2397 expect(setter.isSynthetic, isFalse); |
| 2445 expect(setter.name, "$methodName="); | 2398 expect(setter.name, "$methodName="); |
| 2446 expect(setter.displayName, methodName); | 2399 expect(setter.displayName, methodName); |
| 2447 expect(setter.variable, field); | 2400 expect(setter.variable, field); |
| 2448 expect(setter.functions, hasLength(0)); | 2401 expect(setter.functions, hasLength(0)); |
| 2449 expect(setter.labels, hasLength(0)); | 2402 expect(setter.labels, hasLength(0)); |
| 2450 expect(setter.localVariables, hasLength(0)); | |
| 2451 expect(setter.parameters, hasLength(0)); | 2403 expect(setter.parameters, hasLength(0)); |
| 2452 } | 2404 } |
| 2453 | 2405 |
| 2454 void test_visitMethodDeclaration_static() { | 2406 void test_visitMethodDeclaration_static() { |
| 2455 // static m() {} | 2407 // static m() {} |
| 2456 String methodName = "m"; | 2408 String methodName = "m"; |
| 2457 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2409 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
| 2458 Keyword.STATIC, | 2410 Keyword.STATIC, |
| 2459 null, | 2411 null, |
| 2460 null, | 2412 null, |
| 2461 null, | 2413 null, |
| 2462 AstTestFactory.identifier3(methodName), | 2414 AstTestFactory.identifier3(methodName), |
| 2463 AstTestFactory.formalParameterList(), | 2415 AstTestFactory.formalParameterList(), |
| 2464 AstTestFactory.blockFunctionBody2()); | 2416 AstTestFactory.blockFunctionBody2()); |
| 2465 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2417 ElementHolder holder = buildElementsForAst(methodDeclaration); |
| 2466 List<MethodElement> methods = holder.methods; | 2418 List<MethodElement> methods = holder.methods; |
| 2467 expect(methods, hasLength(1)); | 2419 expect(methods, hasLength(1)); |
| 2468 MethodElement method = methods[0]; | 2420 MethodElement method = methods[0]; |
| 2469 expect(method, isNotNull); | 2421 expect(method, isNotNull); |
| 2470 expect(method.hasImplicitReturnType, isTrue); | 2422 expect(method.hasImplicitReturnType, isTrue); |
| 2471 expect(method.name, methodName); | 2423 expect(method.name, methodName); |
| 2472 expect(method.functions, hasLength(0)); | 2424 expect(method.functions, hasLength(0)); |
| 2473 expect(method.labels, hasLength(0)); | 2425 expect(method.labels, hasLength(0)); |
| 2474 expect(method.localVariables, hasLength(0)); | |
| 2475 expect(method.parameters, hasLength(0)); | 2426 expect(method.parameters, hasLength(0)); |
| 2476 expect(method.typeParameters, hasLength(0)); | 2427 expect(method.typeParameters, hasLength(0)); |
| 2477 expect(method.isAbstract, isFalse); | 2428 expect(method.isAbstract, isFalse); |
| 2478 expect(method.isExternal, isFalse); | 2429 expect(method.isExternal, isFalse); |
| 2479 expect(method.isStatic, isTrue); | 2430 expect(method.isStatic, isTrue); |
| 2480 expect(method.isSynthetic, isFalse); | 2431 expect(method.isSynthetic, isFalse); |
| 2481 } | 2432 } |
| 2482 | 2433 |
| 2483 void test_visitMethodDeclaration_typeParameters() { | 2434 void test_visitMethodDeclaration_typeParameters() { |
| 2484 // m<E>() {} | 2435 // m<E>() {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2495 | 2446 |
| 2496 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2447 ElementHolder holder = buildElementsForAst(methodDeclaration); |
| 2497 List<MethodElement> methods = holder.methods; | 2448 List<MethodElement> methods = holder.methods; |
| 2498 expect(methods, hasLength(1)); | 2449 expect(methods, hasLength(1)); |
| 2499 MethodElement method = methods[0]; | 2450 MethodElement method = methods[0]; |
| 2500 expect(method, isNotNull); | 2451 expect(method, isNotNull); |
| 2501 expect(method.hasImplicitReturnType, isTrue); | 2452 expect(method.hasImplicitReturnType, isTrue); |
| 2502 expect(method.name, methodName); | 2453 expect(method.name, methodName); |
| 2503 expect(method.functions, hasLength(0)); | 2454 expect(method.functions, hasLength(0)); |
| 2504 expect(method.labels, hasLength(0)); | 2455 expect(method.labels, hasLength(0)); |
| 2505 expect(method.localVariables, hasLength(0)); | |
| 2506 expect(method.parameters, hasLength(0)); | 2456 expect(method.parameters, hasLength(0)); |
| 2507 expect(method.typeParameters, hasLength(1)); | 2457 expect(method.typeParameters, hasLength(1)); |
| 2508 expect(method.isAbstract, isFalse); | 2458 expect(method.isAbstract, isFalse); |
| 2509 expect(method.isExternal, isFalse); | 2459 expect(method.isExternal, isFalse); |
| 2510 expect(method.isStatic, isFalse); | 2460 expect(method.isStatic, isFalse); |
| 2511 expect(method.isSynthetic, isFalse); | 2461 expect(method.isSynthetic, isFalse); |
| 2512 } | 2462 } |
| 2513 | 2463 |
| 2514 void test_visitTypeAlias_minimal() { | 2464 void test_visitTypeAlias_minimal() { |
| 2515 String aliasName = "F"; | 2465 String aliasName = "F"; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 expect(element.metadata, hasLength(1)); | 2605 expect(element.metadata, hasLength(1)); |
| 2656 expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>()); | 2606 expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>()); |
| 2657 ElementAnnotationImpl elementAnnotation = element.metadata[0]; | 2607 ElementAnnotationImpl elementAnnotation = element.metadata[0]; |
| 2658 expect(elementAnnotation.element, isNull); // Not yet resolved | 2608 expect(elementAnnotation.element, isNull); // Not yet resolved |
| 2659 expect(elementAnnotation.compilationUnit, isNotNull); | 2609 expect(elementAnnotation.compilationUnit, isNotNull); |
| 2660 expect(elementAnnotation.compilationUnit, compilationUnitElement); | 2610 expect(elementAnnotation.compilationUnit, compilationUnitElement); |
| 2661 } | 2611 } |
| 2662 | 2612 |
| 2663 AstVisitor createElementBuilder(ElementHolder holder); | 2613 AstVisitor createElementBuilder(ElementHolder holder); |
| 2664 | 2614 |
| 2615 SimpleIdentifier findIdentifier(String code, String prefix) { |
| 2616 return EngineTestCase.findSimpleIdentifier(compilationUnit, code, prefix); |
| 2617 } |
| 2618 |
| 2619 LocalVariableElement findLocalVariable(String code, String prefix) { |
| 2620 return findIdentifier(code, prefix).staticElement; |
| 2621 } |
| 2622 |
| 2665 void setUp() { | 2623 void setUp() { |
| 2666 compilationUnitElement = new CompilationUnitElementImpl('test.dart'); | 2624 compilationUnitElement = new CompilationUnitElementImpl('test.dart'); |
| 2667 } | 2625 } |
| 2668 | 2626 |
| 2669 void _assertVisibleRange(LocalElement element, int offset, int end) { | 2627 void _assertVisibleRange(LocalElement element, int offset, int end) { |
| 2670 SourceRange visibleRange = element.visibleRange; | 2628 SourceRange visibleRange = element.visibleRange; |
| 2671 expect(visibleRange.offset, offset); | 2629 expect(visibleRange.offset, offset); |
| 2672 expect(visibleRange.end, end); | 2630 expect(visibleRange.end, end); |
| 2673 } | 2631 } |
| 2674 | 2632 |
| 2675 /** | 2633 /** |
| 2676 * Parse the given [code], and visit it with the given [visitor]. | 2634 * Parse the given [code], and visit it with the given [visitor]. |
| 2677 * Fail if any error is logged. | 2635 * Fail if any error is logged. |
| 2678 */ | 2636 */ |
| 2679 void _visitAstOfCode(String code, AstVisitor visitor) { | 2637 void _visitAstOfCode(String code, AstVisitor visitor) { |
| 2680 TestLogger logger = new TestLogger(); | 2638 TestLogger logger = new TestLogger(); |
| 2681 AnalysisEngine.instance.logger = logger; | 2639 AnalysisEngine.instance.logger = logger; |
| 2682 try { | 2640 try { |
| 2683 _compilationUnit = parseCompilationUnit(code); | 2641 _compilationUnit = parseCompilationUnit(code); |
| 2684 compilationUnit.accept(visitor); | 2642 compilationUnit.accept(visitor); |
| 2685 } finally { | 2643 } finally { |
| 2686 expect(logger.log, hasLength(0)); | 2644 expect(logger.log, hasLength(0)); |
| 2687 AnalysisEngine.instance.logger = Logger.NULL; | 2645 AnalysisEngine.instance.logger = Logger.NULL; |
| 2688 } | 2646 } |
| 2689 } | 2647 } |
| 2690 } | 2648 } |
| OLD | NEW |