| 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.generated.all_the_rest_test; | 5 library analyzer.test.generated.all_the_rest_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/dart/element/type.dart'; | 8 import 'package:analyzer/dart/element/type.dart'; |
| 9 import 'package:analyzer/file_system/physical_file_system.dart'; | 9 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 _setupVariableDeclaration("v", false, true); | 568 _setupVariableDeclaration("v", false, true); |
| 569 expect(_findConstants(), isEmpty); | 569 expect(_findConstants(), isEmpty); |
| 570 } | 570 } |
| 571 | 571 |
| 572 void test_visitVariableDeclaration_static_const_inClass() { | 572 void test_visitVariableDeclaration_static_const_inClass() { |
| 573 VariableDeclaration field = | 573 VariableDeclaration field = |
| 574 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true); | 574 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true); |
| 575 expect(_findConstants(), contains(field.element)); | 575 expect(_findConstants(), contains(field.element)); |
| 576 } | 576 } |
| 577 | 577 |
| 578 void test_visitVariableDeclaration_static_const_inClassWithConstConstructor()
{ | 578 void |
| 579 test_visitVariableDeclaration_static_const_inClassWithConstConstructor() { |
| 579 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST, | 580 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST, |
| 580 isStatic: true, hasConstConstructor: true); | 581 isStatic: true, hasConstConstructor: true); |
| 581 expect(_findConstants(), contains(field.element)); | 582 expect(_findConstants(), contains(field.element)); |
| 582 } | 583 } |
| 583 | 584 |
| 584 void test_visitVariableDeclaration_static_final_inClassWithConstConstructor()
{ | 585 void |
| 586 test_visitVariableDeclaration_static_final_inClassWithConstConstructor() { |
| 585 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, | 587 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, |
| 586 isStatic: true, hasConstConstructor: true); | 588 isStatic: true, hasConstConstructor: true); |
| 587 expect(_findConstants(), isNot(contains(field.element))); | 589 expect(_findConstants(), isNot(contains(field.element))); |
| 588 } | 590 } |
| 589 | 591 |
| 590 void test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstru
ctor() { | 592 void |
| 593 test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstruc
tor() { |
| 591 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, | 594 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, |
| 592 isInitialized: false, hasConstConstructor: true); | 595 isInitialized: false, hasConstConstructor: true); |
| 593 expect(_findConstants(), isNot(contains(field.element))); | 596 expect(_findConstants(), isNot(contains(field.element))); |
| 594 } | 597 } |
| 595 | 598 |
| 596 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { | 599 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { |
| 597 _setupFieldDeclaration('C', 'f', Keyword.CONST, | 600 _setupFieldDeclaration('C', 'f', Keyword.CONST, |
| 598 isStatic: true, isInitialized: false); | 601 isStatic: true, isInitialized: false); |
| 599 expect(_findConstants(), isEmpty); | 602 expect(_findConstants(), isEmpty); |
| 600 } | 603 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 614 Set<ConstantEvaluationTarget> _findConstants() { | 617 Set<ConstantEvaluationTarget> _findConstants() { |
| 615 ConstantFinder finder = new ConstantFinder(_context, _source, _source); | 618 ConstantFinder finder = new ConstantFinder(_context, _source, _source); |
| 616 _node.accept(finder); | 619 _node.accept(finder); |
| 617 Set<ConstantEvaluationTarget> constants = finder.constantsToCompute; | 620 Set<ConstantEvaluationTarget> constants = finder.constantsToCompute; |
| 618 expect(constants, isNotNull); | 621 expect(constants, isNotNull); |
| 619 return constants; | 622 return constants; |
| 620 } | 623 } |
| 621 | 624 |
| 622 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { | 625 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { |
| 623 Keyword constKeyword = isConst ? Keyword.CONST : null; | 626 Keyword constKeyword = isConst ? Keyword.CONST : null; |
| 624 ConstructorDeclaration constructorDeclaration = AstFactory | 627 ConstructorDeclaration constructorDeclaration = |
| 625 .constructorDeclaration2( | 628 AstFactory.constructorDeclaration2( |
| 626 constKeyword, | 629 constKeyword, |
| 627 null, | 630 null, |
| 628 null, | 631 null, |
| 629 name, | 632 name, |
| 630 AstFactory.formalParameterList(), | 633 AstFactory.formalParameterList(), |
| 631 null, | 634 null, |
| 632 AstFactory.blockFunctionBody2()); | 635 AstFactory.blockFunctionBody2()); |
| 633 ClassElement classElement = ElementFactory.classElement2(name); | 636 ClassElement classElement = ElementFactory.classElement2(name); |
| 634 ConstructorElement element = | 637 ConstructorElement element = |
| 635 ElementFactory.constructorElement(classElement, name, isConst); | 638 ElementFactory.constructorElement(classElement, name, isConst); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 656 FieldDeclaration fieldDeclaration = AstFactory.fieldDeclaration2( | 659 FieldDeclaration fieldDeclaration = AstFactory.fieldDeclaration2( |
| 657 isStatic, keyword, <VariableDeclaration>[variableDeclaration]); | 660 isStatic, keyword, <VariableDeclaration>[variableDeclaration]); |
| 658 ClassDeclaration classDeclaration = | 661 ClassDeclaration classDeclaration = |
| 659 AstFactory.classDeclaration(null, className, null, null, null, null); | 662 AstFactory.classDeclaration(null, className, null, null, null, null); |
| 660 classDeclaration.members.add(fieldDeclaration); | 663 classDeclaration.members.add(fieldDeclaration); |
| 661 _node = classDeclaration; | 664 _node = classDeclaration; |
| 662 ClassElementImpl classElement = ElementFactory.classElement2(className); | 665 ClassElementImpl classElement = ElementFactory.classElement2(className); |
| 663 classElement.fields = <FieldElement>[fieldElement]; | 666 classElement.fields = <FieldElement>[fieldElement]; |
| 664 classDeclaration.name.staticElement = classElement; | 667 classDeclaration.name.staticElement = classElement; |
| 665 if (hasConstConstructor) { | 668 if (hasConstConstructor) { |
| 666 ConstructorDeclaration constructorDeclaration = AstFactory | 669 ConstructorDeclaration constructorDeclaration = |
| 667 .constructorDeclaration2( | 670 AstFactory.constructorDeclaration2( |
| 668 Keyword.CONST, | 671 Keyword.CONST, |
| 669 null, | 672 null, |
| 670 AstFactory.identifier3(className), | 673 AstFactory.identifier3(className), |
| 671 null, | 674 null, |
| 672 AstFactory.formalParameterList(), | 675 AstFactory.formalParameterList(), |
| 673 null, | 676 null, |
| 674 AstFactory.blockFunctionBody2()); | 677 AstFactory.blockFunctionBody2()); |
| 675 classDeclaration.members.add(constructorDeclaration); | 678 classDeclaration.members.add(constructorDeclaration); |
| 676 ConstructorElement constructorElement = | 679 ConstructorElement constructorElement = |
| 677 ElementFactory.constructorElement(classElement, '', true); | 680 ElementFactory.constructorElement(classElement, '', true); |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 const A(int i, int j) : k = 2 * i + j; | 1329 const A(int i, int j) : k = 2 * i + j; |
| 1327 final int k; | 1330 final int k; |
| 1328 }'''); | 1331 }'''); |
| 1329 EvaluationResultImpl result = | 1332 EvaluationResultImpl result = |
| 1330 _evaluateTopLevelVariable(compilationUnit, "foo"); | 1333 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1331 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1334 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1332 expect(fields, hasLength(1)); | 1335 expect(fields, hasLength(1)); |
| 1333 _assertIntField(fields, "k", 13); | 1336 _assertIntField(fields, "k", 13); |
| 1334 } | 1337 } |
| 1335 | 1338 |
| 1336 void test_instanceCreationExpression_computedField_namedOptionalWithDefault()
{ | 1339 void |
| 1340 test_instanceCreationExpression_computedField_namedOptionalWithDefault() { |
| 1337 _checkInstanceCreationOptionalParams(false, true, true); | 1341 _checkInstanceCreationOptionalParams(false, true, true); |
| 1338 } | 1342 } |
| 1339 | 1343 |
| 1340 void test_instanceCreationExpression_computedField_namedOptionalWithoutDefault
() { | 1344 void |
| 1345 test_instanceCreationExpression_computedField_namedOptionalWithoutDefault(
) { |
| 1341 _checkInstanceCreationOptionalParams(false, true, false); | 1346 _checkInstanceCreationOptionalParams(false, true, false); |
| 1342 } | 1347 } |
| 1343 | 1348 |
| 1344 void test_instanceCreationExpression_computedField_unnamedOptionalWithDefault(
) { | 1349 void |
| 1350 test_instanceCreationExpression_computedField_unnamedOptionalWithDefault()
{ |
| 1345 _checkInstanceCreationOptionalParams(false, false, true); | 1351 _checkInstanceCreationOptionalParams(false, false, true); |
| 1346 } | 1352 } |
| 1347 | 1353 |
| 1348 void test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefau
lt() { | 1354 void |
| 1355 test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefaul
t() { |
| 1349 _checkInstanceCreationOptionalParams(false, false, false); | 1356 _checkInstanceCreationOptionalParams(false, false, false); |
| 1350 } | 1357 } |
| 1351 | 1358 |
| 1352 void test_instanceCreationExpression_computedField_usesConstConstructor() { | 1359 void test_instanceCreationExpression_computedField_usesConstConstructor() { |
| 1353 CompilationUnit compilationUnit = resolveSource(r''' | 1360 CompilationUnit compilationUnit = resolveSource(r''' |
| 1354 const foo = const A(3); | 1361 const foo = const A(3); |
| 1355 class A { | 1362 class A { |
| 1356 const A(int i) : b = const B(4); | 1363 const A(int i) : b = const B(4); |
| 1357 final int b; | 1364 final int b; |
| 1358 } | 1365 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 int x; | 1438 int x; |
| 1432 const A(this.x) | 1439 const A(this.x) |
| 1433 }'''); | 1440 }'''); |
| 1434 EvaluationResultImpl result = | 1441 EvaluationResultImpl result = |
| 1435 _evaluateTopLevelVariable(compilationUnit, "foo"); | 1442 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1436 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1443 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1437 expect(fields, hasLength(1)); | 1444 expect(fields, hasLength(1)); |
| 1438 _assertIntField(fields, "x", 42); | 1445 _assertIntField(fields, "x", 42); |
| 1439 } | 1446 } |
| 1440 | 1447 |
| 1441 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDef
ault() { | 1448 void |
| 1449 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDefa
ult() { |
| 1442 _checkInstanceCreationOptionalParams(true, true, true); | 1450 _checkInstanceCreationOptionalParams(true, true, true); |
| 1443 } | 1451 } |
| 1444 | 1452 |
| 1445 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithout
Default() { | 1453 void |
| 1454 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithoutD
efault() { |
| 1446 _checkInstanceCreationOptionalParams(true, true, false); | 1455 _checkInstanceCreationOptionalParams(true, true, false); |
| 1447 } | 1456 } |
| 1448 | 1457 |
| 1449 void test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithD
efault() { | 1458 void |
| 1459 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithDe
fault() { |
| 1450 _checkInstanceCreationOptionalParams(true, false, true); | 1460 _checkInstanceCreationOptionalParams(true, false, true); |
| 1451 } | 1461 } |
| 1452 | 1462 |
| 1453 void test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWitho
utDefault() { | 1463 void |
| 1464 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithou
tDefault() { |
| 1454 _checkInstanceCreationOptionalParams(true, false, false); | 1465 _checkInstanceCreationOptionalParams(true, false, false); |
| 1455 } | 1466 } |
| 1456 | 1467 |
| 1457 void test_instanceCreationExpression_implicitSuper() { | 1468 void test_instanceCreationExpression_implicitSuper() { |
| 1458 CompilationUnit compilationUnit = resolveSource(r''' | 1469 CompilationUnit compilationUnit = resolveSource(r''' |
| 1459 const foo = const B(4); | 1470 const foo = const B(4); |
| 1460 class A { | 1471 class A { |
| 1461 const A() : x = 3; | 1472 const A() : x = 3; |
| 1462 final int x; | 1473 final int x; |
| 1463 } | 1474 } |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2001 expect(result.value, isNotNull); | 2012 expect(result.value, isNotNull); |
| 2002 } else { | 2013 } else { |
| 2003 expect(result.value, isNull); | 2014 expect(result.value, isNull); |
| 2004 } | 2015 } |
| 2005 } | 2016 } |
| 2006 } | 2017 } |
| 2007 } | 2018 } |
| 2008 | 2019 |
| 2009 @reflectiveTest | 2020 @reflectiveTest |
| 2010 class ConstantVisitorTest extends ResolverTestCase { | 2021 class ConstantVisitorTest extends ResolverTestCase { |
| 2022 void test_visitBinaryExpression_questionQuestion_notNull_notNull() { |
| 2023 Expression left = AstFactory.string2('a'); |
| 2024 Expression right = AstFactory.string2('b'); |
| 2025 Expression expression = |
| 2026 AstFactory.binaryExpression(left, TokenType.QUESTION_QUESTION, right); |
| 2027 |
| 2028 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2029 ErrorReporter errorReporter = |
| 2030 new ErrorReporter(errorListener, _dummySource()); |
| 2031 DartObjectImpl result = _evaluate(expression, errorReporter); |
| 2032 expect(result, isNotNull); |
| 2033 expect(result.isNull, isFalse); |
| 2034 expect(result.toStringValue(), 'a'); |
| 2035 errorListener.assertNoErrors(); |
| 2036 } |
| 2037 |
| 2038 void test_visitBinaryExpression_questionQuestion_null_notNull() { |
| 2039 Expression left = AstFactory.nullLiteral(); |
| 2040 Expression right = AstFactory.string2('b'); |
| 2041 Expression expression = |
| 2042 AstFactory.binaryExpression(left, TokenType.QUESTION_QUESTION, right); |
| 2043 |
| 2044 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2045 ErrorReporter errorReporter = |
| 2046 new ErrorReporter(errorListener, _dummySource()); |
| 2047 DartObjectImpl result = _evaluate(expression, errorReporter); |
| 2048 expect(result, isNotNull); |
| 2049 expect(result.isNull, isFalse); |
| 2050 expect(result.toStringValue(), 'b'); |
| 2051 errorListener.assertNoErrors(); |
| 2052 } |
| 2053 |
| 2054 void test_visitBinaryExpression_questionQuestion_null_null() { |
| 2055 Expression left = AstFactory.nullLiteral(); |
| 2056 Expression right = AstFactory.nullLiteral(); |
| 2057 Expression expression = |
| 2058 AstFactory.binaryExpression(left, TokenType.QUESTION_QUESTION, right); |
| 2059 |
| 2060 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2061 ErrorReporter errorReporter = |
| 2062 new ErrorReporter(errorListener, _dummySource()); |
| 2063 DartObjectImpl result = _evaluate(expression, errorReporter); |
| 2064 expect(result, isNotNull); |
| 2065 expect(result.isNull, isTrue); |
| 2066 errorListener.assertNoErrors(); |
| 2067 } |
| 2068 |
| 2011 void test_visitConditionalExpression_false() { | 2069 void test_visitConditionalExpression_false() { |
| 2012 Expression thenExpression = AstFactory.integer(1); | 2070 Expression thenExpression = AstFactory.integer(1); |
| 2013 Expression elseExpression = AstFactory.integer(0); | 2071 Expression elseExpression = AstFactory.integer(0); |
| 2014 ConditionalExpression expression = AstFactory.conditionalExpression( | 2072 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2015 AstFactory.booleanLiteral(false), thenExpression, elseExpression); | 2073 AstFactory.booleanLiteral(false), thenExpression, elseExpression); |
| 2016 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2074 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2017 ErrorReporter errorReporter = | 2075 ErrorReporter errorReporter = |
| 2018 new ErrorReporter(errorListener, _dummySource()); | 2076 new ErrorReporter(errorListener, _dummySource()); |
| 2019 _assertValue( | 2077 _assertValue(0, _evaluate(expression, errorReporter)); |
| 2020 0, | |
| 2021 expression.accept(new ConstantVisitor( | |
| 2022 new ConstantEvaluationEngine( | |
| 2023 new TestTypeProvider(), new DeclaredVariables(), | |
| 2024 typeSystem: new TypeSystemImpl()), | |
| 2025 errorReporter))); | |
| 2026 errorListener.assertNoErrors(); | 2078 errorListener.assertNoErrors(); |
| 2027 } | 2079 } |
| 2028 | 2080 |
| 2029 void test_visitConditionalExpression_nonBooleanCondition() { | 2081 void test_visitConditionalExpression_nonBooleanCondition() { |
| 2030 Expression thenExpression = AstFactory.integer(1); | 2082 Expression thenExpression = AstFactory.integer(1); |
| 2031 Expression elseExpression = AstFactory.integer(0); | 2083 Expression elseExpression = AstFactory.integer(0); |
| 2032 NullLiteral conditionExpression = AstFactory.nullLiteral(); | 2084 NullLiteral conditionExpression = AstFactory.nullLiteral(); |
| 2033 ConditionalExpression expression = AstFactory.conditionalExpression( | 2085 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2034 conditionExpression, thenExpression, elseExpression); | 2086 conditionExpression, thenExpression, elseExpression); |
| 2035 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2087 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2036 ErrorReporter errorReporter = | 2088 ErrorReporter errorReporter = |
| 2037 new ErrorReporter(errorListener, _dummySource()); | 2089 new ErrorReporter(errorListener, _dummySource()); |
| 2038 DartObjectImpl result = expression.accept(new ConstantVisitor( | 2090 DartObjectImpl result = _evaluate(expression, errorReporter); |
| 2039 new ConstantEvaluationEngine( | |
| 2040 new TestTypeProvider(), new DeclaredVariables(), | |
| 2041 typeSystem: new TypeSystemImpl()), | |
| 2042 errorReporter)); | |
| 2043 expect(result, isNull); | 2091 expect(result, isNull); |
| 2044 errorListener | 2092 errorListener |
| 2045 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]); | 2093 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]); |
| 2046 } | 2094 } |
| 2047 | 2095 |
| 2048 void test_visitConditionalExpression_nonConstantElse() { | 2096 void test_visitConditionalExpression_nonConstantElse() { |
| 2049 Expression thenExpression = AstFactory.integer(1); | 2097 Expression thenExpression = AstFactory.integer(1); |
| 2050 Expression elseExpression = AstFactory.identifier3("x"); | 2098 Expression elseExpression = AstFactory.identifier3("x"); |
| 2051 ConditionalExpression expression = AstFactory.conditionalExpression( | 2099 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2052 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2100 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2053 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2101 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2054 ErrorReporter errorReporter = | 2102 ErrorReporter errorReporter = |
| 2055 new ErrorReporter(errorListener, _dummySource()); | 2103 new ErrorReporter(errorListener, _dummySource()); |
| 2056 DartObjectImpl result = expression.accept(new ConstantVisitor( | 2104 DartObjectImpl result = _evaluate(expression, errorReporter); |
| 2057 new ConstantEvaluationEngine( | |
| 2058 new TestTypeProvider(), new DeclaredVariables(), | |
| 2059 typeSystem: new TypeSystemImpl()), | |
| 2060 errorReporter)); | |
| 2061 expect(result, isNull); | 2105 expect(result, isNull); |
| 2062 errorListener | 2106 errorListener |
| 2063 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | 2107 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); |
| 2064 } | 2108 } |
| 2065 | 2109 |
| 2066 void test_visitConditionalExpression_nonConstantThen() { | 2110 void test_visitConditionalExpression_nonConstantThen() { |
| 2067 Expression thenExpression = AstFactory.identifier3("x"); | 2111 Expression thenExpression = AstFactory.identifier3("x"); |
| 2068 Expression elseExpression = AstFactory.integer(0); | 2112 Expression elseExpression = AstFactory.integer(0); |
| 2069 ConditionalExpression expression = AstFactory.conditionalExpression( | 2113 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2070 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2114 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2071 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2115 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2072 ErrorReporter errorReporter = | 2116 ErrorReporter errorReporter = |
| 2073 new ErrorReporter(errorListener, _dummySource()); | 2117 new ErrorReporter(errorListener, _dummySource()); |
| 2074 DartObjectImpl result = expression.accept(new ConstantVisitor( | 2118 DartObjectImpl result = _evaluate(expression, errorReporter); |
| 2075 new ConstantEvaluationEngine( | |
| 2076 new TestTypeProvider(), new DeclaredVariables(), | |
| 2077 typeSystem: new TypeSystemImpl()), | |
| 2078 errorReporter)); | |
| 2079 expect(result, isNull); | 2119 expect(result, isNull); |
| 2080 errorListener | 2120 errorListener |
| 2081 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | 2121 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); |
| 2082 } | 2122 } |
| 2083 | 2123 |
| 2084 void test_visitConditionalExpression_true() { | 2124 void test_visitConditionalExpression_true() { |
| 2085 Expression thenExpression = AstFactory.integer(1); | 2125 Expression thenExpression = AstFactory.integer(1); |
| 2086 Expression elseExpression = AstFactory.integer(0); | 2126 Expression elseExpression = AstFactory.integer(0); |
| 2087 ConditionalExpression expression = AstFactory.conditionalExpression( | 2127 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2088 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2128 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2089 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2129 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2090 ErrorReporter errorReporter = | 2130 ErrorReporter errorReporter = |
| 2091 new ErrorReporter(errorListener, _dummySource()); | 2131 new ErrorReporter(errorListener, _dummySource()); |
| 2092 _assertValue( | 2132 _assertValue(1, _evaluate(expression, errorReporter)); |
| 2093 1, | |
| 2094 expression.accept(new ConstantVisitor( | |
| 2095 new ConstantEvaluationEngine( | |
| 2096 new TestTypeProvider(), new DeclaredVariables(), | |
| 2097 typeSystem: new TypeSystemImpl()), | |
| 2098 errorReporter))); | |
| 2099 errorListener.assertNoErrors(); | 2133 errorListener.assertNoErrors(); |
| 2100 } | 2134 } |
| 2101 | 2135 |
| 2102 void test_visitSimpleIdentifier_className() { | 2136 void test_visitSimpleIdentifier_className() { |
| 2103 CompilationUnit compilationUnit = resolveSource(''' | 2137 CompilationUnit compilationUnit = resolveSource(''' |
| 2104 const a = C; | 2138 const a = C; |
| 2105 class C {} | 2139 class C {} |
| 2106 '''); | 2140 '''); |
| 2107 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); | 2141 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); |
| 2108 expect(result.type, typeProvider.typeType); | 2142 expect(result.type, typeProvider.typeType); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 expect(result, isNotNull); | 2185 expect(result, isNotNull); |
| 2152 expect(result.type.name, "int"); | 2186 expect(result.type.name, "int"); |
| 2153 expect(result.toIntValue(), expectedValue); | 2187 expect(result.toIntValue(), expectedValue); |
| 2154 } | 2188 } |
| 2155 | 2189 |
| 2156 NonExistingSource _dummySource() { | 2190 NonExistingSource _dummySource() { |
| 2157 String path = '/test.dart'; | 2191 String path = '/test.dart'; |
| 2158 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); | 2192 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); |
| 2159 } | 2193 } |
| 2160 | 2194 |
| 2195 DartObjectImpl _evaluate(Expression expression, ErrorReporter errorReporter) { |
| 2196 return expression.accept(new ConstantVisitor( |
| 2197 new ConstantEvaluationEngine( |
| 2198 new TestTypeProvider(), new DeclaredVariables(), |
| 2199 typeSystem: new TypeSystemImpl()), |
| 2200 errorReporter)); |
| 2201 } |
| 2202 |
| 2161 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, | 2203 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, |
| 2162 Map<String, DartObjectImpl> lexicalEnvironment) { | 2204 Map<String, DartObjectImpl> lexicalEnvironment) { |
| 2163 Source source = compilationUnit.element.source; | 2205 Source source = compilationUnit.element.source; |
| 2164 Expression expression = | 2206 Expression expression = |
| 2165 findTopLevelConstantExpression(compilationUnit, name); | 2207 findTopLevelConstantExpression(compilationUnit, name); |
| 2166 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2208 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2167 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 2209 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 2168 DartObjectImpl result = expression.accept(new ConstantVisitor( | 2210 DartObjectImpl result = expression.accept(new ConstantVisitor( |
| 2169 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables(), | 2211 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables(), |
| 2170 typeSystem: typeSystem), | 2212 typeSystem: typeSystem), |
| (...skipping 2679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4850 expect(types, hasLength(1)); | 4892 expect(types, hasLength(1)); |
| 4851 ClassElement type = types[0]; | 4893 ClassElement type = types[0]; |
| 4852 expect(type.typeParameters, hasLength(1)); | 4894 expect(type.typeParameters, hasLength(1)); |
| 4853 expect(type.typeParameters[0].name, equals('T')); | 4895 expect(type.typeParameters[0].name, equals('T')); |
| 4854 } | 4896 } |
| 4855 | 4897 |
| 4856 void test_visitConstructorDeclaration_external() { | 4898 void test_visitConstructorDeclaration_external() { |
| 4857 ElementHolder holder = new ElementHolder(); | 4899 ElementHolder holder = new ElementHolder(); |
| 4858 ElementBuilder builder = new ElementBuilder(holder); | 4900 ElementBuilder builder = new ElementBuilder(holder); |
| 4859 String className = "A"; | 4901 String className = "A"; |
| 4860 ConstructorDeclaration constructorDeclaration = AstFactory | 4902 ConstructorDeclaration constructorDeclaration = |
| 4861 .constructorDeclaration2( | 4903 AstFactory.constructorDeclaration2( |
| 4862 null, | 4904 null, |
| 4863 null, | 4905 null, |
| 4864 AstFactory.identifier3(className), | 4906 AstFactory.identifier3(className), |
| 4865 null, | 4907 null, |
| 4866 AstFactory.formalParameterList(), | 4908 AstFactory.formalParameterList(), |
| 4867 null, | 4909 null, |
| 4868 AstFactory.blockFunctionBody2()); | 4910 AstFactory.blockFunctionBody2()); |
| 4869 constructorDeclaration.externalKeyword = | 4911 constructorDeclaration.externalKeyword = |
| 4870 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 4912 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
| 4871 constructorDeclaration.accept(builder); | 4913 constructorDeclaration.accept(builder); |
| 4872 List<ConstructorElement> constructors = holder.constructors; | 4914 List<ConstructorElement> constructors = holder.constructors; |
| 4873 expect(constructors, hasLength(1)); | 4915 expect(constructors, hasLength(1)); |
| 4874 ConstructorElement constructor = constructors[0]; | 4916 ConstructorElement constructor = constructors[0]; |
| 4875 expect(constructor, isNotNull); | 4917 expect(constructor, isNotNull); |
| 4876 expect(constructor.isExternal, isTrue); | 4918 expect(constructor.isExternal, isTrue); |
| 4877 expect(constructor.isFactory, isFalse); | 4919 expect(constructor.isFactory, isFalse); |
| 4878 expect(constructor.name, ""); | 4920 expect(constructor.name, ""); |
| 4879 expect(constructor.functions, hasLength(0)); | 4921 expect(constructor.functions, hasLength(0)); |
| 4880 expect(constructor.labels, hasLength(0)); | 4922 expect(constructor.labels, hasLength(0)); |
| 4881 expect(constructor.localVariables, hasLength(0)); | 4923 expect(constructor.localVariables, hasLength(0)); |
| 4882 expect(constructor.parameters, hasLength(0)); | 4924 expect(constructor.parameters, hasLength(0)); |
| 4883 } | 4925 } |
| 4884 | 4926 |
| 4885 void test_visitConstructorDeclaration_factory() { | 4927 void test_visitConstructorDeclaration_factory() { |
| 4886 ElementHolder holder = new ElementHolder(); | 4928 ElementHolder holder = new ElementHolder(); |
| 4887 ElementBuilder builder = new ElementBuilder(holder); | 4929 ElementBuilder builder = new ElementBuilder(holder); |
| 4888 String className = "A"; | 4930 String className = "A"; |
| 4889 ConstructorDeclaration constructorDeclaration = AstFactory | 4931 ConstructorDeclaration constructorDeclaration = |
| 4890 .constructorDeclaration2( | 4932 AstFactory.constructorDeclaration2( |
| 4891 null, | 4933 null, |
| 4892 Keyword.FACTORY, | 4934 Keyword.FACTORY, |
| 4893 AstFactory.identifier3(className), | 4935 AstFactory.identifier3(className), |
| 4894 null, | 4936 null, |
| 4895 AstFactory.formalParameterList(), | 4937 AstFactory.formalParameterList(), |
| 4896 null, | 4938 null, |
| 4897 AstFactory.blockFunctionBody2()); | 4939 AstFactory.blockFunctionBody2()); |
| 4898 constructorDeclaration.accept(builder); | 4940 constructorDeclaration.accept(builder); |
| 4899 List<ConstructorElement> constructors = holder.constructors; | 4941 List<ConstructorElement> constructors = holder.constructors; |
| 4900 expect(constructors, hasLength(1)); | 4942 expect(constructors, hasLength(1)); |
| 4901 ConstructorElement constructor = constructors[0]; | 4943 ConstructorElement constructor = constructors[0]; |
| 4902 expect(constructor, isNotNull); | 4944 expect(constructor, isNotNull); |
| 4903 expect(constructor.isExternal, isFalse); | 4945 expect(constructor.isExternal, isFalse); |
| 4904 expect(constructor.isFactory, isTrue); | 4946 expect(constructor.isFactory, isTrue); |
| 4905 expect(constructor.name, ""); | 4947 expect(constructor.name, ""); |
| 4906 expect(constructor.functions, hasLength(0)); | 4948 expect(constructor.functions, hasLength(0)); |
| 4907 expect(constructor.labels, hasLength(0)); | 4949 expect(constructor.labels, hasLength(0)); |
| 4908 expect(constructor.localVariables, hasLength(0)); | 4950 expect(constructor.localVariables, hasLength(0)); |
| 4909 expect(constructor.parameters, hasLength(0)); | 4951 expect(constructor.parameters, hasLength(0)); |
| 4910 } | 4952 } |
| 4911 | 4953 |
| 4912 void test_visitConstructorDeclaration_minimal() { | 4954 void test_visitConstructorDeclaration_minimal() { |
| 4913 ElementHolder holder = new ElementHolder(); | 4955 ElementHolder holder = new ElementHolder(); |
| 4914 ElementBuilder builder = new ElementBuilder(holder); | 4956 ElementBuilder builder = new ElementBuilder(holder); |
| 4915 String className = "A"; | 4957 String className = "A"; |
| 4916 ConstructorDeclaration constructorDeclaration = AstFactory | 4958 ConstructorDeclaration constructorDeclaration = |
| 4917 .constructorDeclaration2( | 4959 AstFactory.constructorDeclaration2( |
| 4918 null, | 4960 null, |
| 4919 null, | 4961 null, |
| 4920 AstFactory.identifier3(className), | 4962 AstFactory.identifier3(className), |
| 4921 null, | 4963 null, |
| 4922 AstFactory.formalParameterList(), | 4964 AstFactory.formalParameterList(), |
| 4923 null, | 4965 null, |
| 4924 AstFactory.blockFunctionBody2()); | 4966 AstFactory.blockFunctionBody2()); |
| 4925 constructorDeclaration.documentationComment = AstFactory | 4967 constructorDeclaration.documentationComment = AstFactory |
| 4926 .documentationComment( | 4968 .documentationComment( |
| 4927 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 4969 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4939 expect(constructor.labels, hasLength(0)); | 4981 expect(constructor.labels, hasLength(0)); |
| 4940 expect(constructor.localVariables, hasLength(0)); | 4982 expect(constructor.localVariables, hasLength(0)); |
| 4941 expect(constructor.parameters, hasLength(0)); | 4983 expect(constructor.parameters, hasLength(0)); |
| 4942 } | 4984 } |
| 4943 | 4985 |
| 4944 void test_visitConstructorDeclaration_named() { | 4986 void test_visitConstructorDeclaration_named() { |
| 4945 ElementHolder holder = new ElementHolder(); | 4987 ElementHolder holder = new ElementHolder(); |
| 4946 ElementBuilder builder = new ElementBuilder(holder); | 4988 ElementBuilder builder = new ElementBuilder(holder); |
| 4947 String className = "A"; | 4989 String className = "A"; |
| 4948 String constructorName = "c"; | 4990 String constructorName = "c"; |
| 4949 ConstructorDeclaration constructorDeclaration = AstFactory | 4991 ConstructorDeclaration constructorDeclaration = |
| 4950 .constructorDeclaration2( | 4992 AstFactory.constructorDeclaration2( |
| 4951 null, | 4993 null, |
| 4952 null, | 4994 null, |
| 4953 AstFactory.identifier3(className), | 4995 AstFactory.identifier3(className), |
| 4954 constructorName, | 4996 constructorName, |
| 4955 AstFactory.formalParameterList(), | 4997 AstFactory.formalParameterList(), |
| 4956 null, | 4998 null, |
| 4957 AstFactory.blockFunctionBody2()); | 4999 AstFactory.blockFunctionBody2()); |
| 4958 constructorDeclaration.accept(builder); | 5000 constructorDeclaration.accept(builder); |
| 4959 List<ConstructorElement> constructors = holder.constructors; | 5001 List<ConstructorElement> constructors = holder.constructors; |
| 4960 expect(constructors, hasLength(1)); | 5002 expect(constructors, hasLength(1)); |
| 4961 ConstructorElement constructor = constructors[0]; | 5003 ConstructorElement constructor = constructors[0]; |
| 4962 expect(constructor, isNotNull); | 5004 expect(constructor, isNotNull); |
| 4963 expect(constructor.isExternal, isFalse); | 5005 expect(constructor.isExternal, isFalse); |
| 4964 expect(constructor.isFactory, isFalse); | 5006 expect(constructor.isFactory, isFalse); |
| 4965 expect(constructor.name, constructorName); | 5007 expect(constructor.name, constructorName); |
| 4966 expect(constructor.functions, hasLength(0)); | 5008 expect(constructor.functions, hasLength(0)); |
| 4967 expect(constructor.labels, hasLength(0)); | 5009 expect(constructor.labels, hasLength(0)); |
| 4968 expect(constructor.localVariables, hasLength(0)); | 5010 expect(constructor.localVariables, hasLength(0)); |
| 4969 expect(constructor.parameters, hasLength(0)); | 5011 expect(constructor.parameters, hasLength(0)); |
| 4970 expect(constructorDeclaration.name.staticElement, same(constructor)); | 5012 expect(constructorDeclaration.name.staticElement, same(constructor)); |
| 4971 expect(constructorDeclaration.element, same(constructor)); | 5013 expect(constructorDeclaration.element, same(constructor)); |
| 4972 } | 5014 } |
| 4973 | 5015 |
| 4974 void test_visitConstructorDeclaration_unnamed() { | 5016 void test_visitConstructorDeclaration_unnamed() { |
| 4975 ElementHolder holder = new ElementHolder(); | 5017 ElementHolder holder = new ElementHolder(); |
| 4976 ElementBuilder builder = new ElementBuilder(holder); | 5018 ElementBuilder builder = new ElementBuilder(holder); |
| 4977 String className = "A"; | 5019 String className = "A"; |
| 4978 ConstructorDeclaration constructorDeclaration = AstFactory | 5020 ConstructorDeclaration constructorDeclaration = |
| 4979 .constructorDeclaration2( | 5021 AstFactory.constructorDeclaration2( |
| 4980 null, | 5022 null, |
| 4981 null, | 5023 null, |
| 4982 AstFactory.identifier3(className), | 5024 AstFactory.identifier3(className), |
| 4983 null, | 5025 null, |
| 4984 AstFactory.formalParameterList(), | 5026 AstFactory.formalParameterList(), |
| 4985 null, | 5027 null, |
| 4986 AstFactory.blockFunctionBody2()); | 5028 AstFactory.blockFunctionBody2()); |
| 4987 constructorDeclaration.accept(builder); | 5029 constructorDeclaration.accept(builder); |
| 4988 List<ConstructorElement> constructors = holder.constructors; | 5030 List<ConstructorElement> constructors = holder.constructors; |
| 4989 expect(constructors, hasLength(1)); | 5031 expect(constructors, hasLength(1)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5049 expect(variable.isPublic, isTrue); | 5091 expect(variable.isPublic, isTrue); |
| 5050 expect(variable.isSynthetic, isFalse); | 5092 expect(variable.isSynthetic, isFalse); |
| 5051 expect(variable.name, variableName); | 5093 expect(variable.name, variableName); |
| 5052 } | 5094 } |
| 5053 | 5095 |
| 5054 void test_visitDefaultFormalParameter_noType() { | 5096 void test_visitDefaultFormalParameter_noType() { |
| 5055 // p = 0 | 5097 // p = 0 |
| 5056 ElementHolder holder = new ElementHolder(); | 5098 ElementHolder holder = new ElementHolder(); |
| 5057 ElementBuilder builder = new ElementBuilder(holder); | 5099 ElementBuilder builder = new ElementBuilder(holder); |
| 5058 String parameterName = 'p'; | 5100 String parameterName = 'p'; |
| 5059 DefaultFormalParameter formalParameter = AstFactory | 5101 DefaultFormalParameter formalParameter = |
| 5060 .positionalFormalParameter( | 5102 AstFactory.positionalFormalParameter( |
| 5061 AstFactory.simpleFormalParameter3(parameterName), | 5103 AstFactory.simpleFormalParameter3(parameterName), |
| 5062 AstFactory.integer(0)); | 5104 AstFactory.integer(0)); |
| 5063 formalParameter.accept(builder); | 5105 formalParameter.accept(builder); |
| 5064 | 5106 |
| 5065 List<ParameterElement> parameters = holder.parameters; | 5107 List<ParameterElement> parameters = holder.parameters; |
| 5066 expect(parameters, hasLength(1)); | 5108 expect(parameters, hasLength(1)); |
| 5067 ParameterElement parameter = parameters[0]; | 5109 ParameterElement parameter = parameters[0]; |
| 5068 expect(parameter.hasImplicitType, isTrue); | 5110 expect(parameter.hasImplicitType, isTrue); |
| 5069 expect(parameter.isConst, isFalse); | 5111 expect(parameter.isConst, isFalse); |
| 5070 expect(parameter.isDeprecated, isFalse); | 5112 expect(parameter.isDeprecated, isFalse); |
| (...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6455 | 6497 |
| 6456 void test_locate_FunctionDeclaration() { | 6498 void test_locate_FunctionDeclaration() { |
| 6457 AstNode id = _findNodeIn("f", "int f() => 3;"); | 6499 AstNode id = _findNodeIn("f", "int f() => 3;"); |
| 6458 FunctionDeclaration declaration = | 6500 FunctionDeclaration declaration = |
| 6459 id.getAncestor((node) => node is FunctionDeclaration); | 6501 id.getAncestor((node) => node is FunctionDeclaration); |
| 6460 Element element = ElementLocator.locate(declaration); | 6502 Element element = ElementLocator.locate(declaration); |
| 6461 EngineTestCase.assertInstanceOf( | 6503 EngineTestCase.assertInstanceOf( |
| 6462 (obj) => obj is FunctionElement, FunctionElement, element); | 6504 (obj) => obj is FunctionElement, FunctionElement, element); |
| 6463 } | 6505 } |
| 6464 | 6506 |
| 6465 void test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPa
rameter() { | 6507 void |
| 6508 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar
ameter() { |
| 6466 AstNode id = _findNodeIndexedIn( | 6509 AstNode id = _findNodeIndexedIn( |
| 6467 "Class", | 6510 "Class", |
| 6468 2, | 6511 2, |
| 6469 r''' | 6512 r''' |
| 6470 class Class { | 6513 class Class { |
| 6471 const Class.name(); | 6514 const Class.name(); |
| 6472 } | 6515 } |
| 6473 void main(@Class.name() parameter) { | 6516 void main(@Class.name() parameter) { |
| 6474 }'''); | 6517 }'''); |
| 6475 Element element = ElementLocator.locate(id); | 6518 Element element = ElementLocator.locate(id); |
| 6476 EngineTestCase.assertInstanceOf( | 6519 EngineTestCase.assertInstanceOf( |
| 6477 (obj) => obj is ClassElement, ClassElement, element); | 6520 (obj) => obj is ClassElement, ClassElement, element); |
| 6478 } | 6521 } |
| 6479 | 6522 |
| 6480 void test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormal
Parameter() { | 6523 void |
| 6524 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP
arameter() { |
| 6481 AstNode id = _findNodeIndexedIn( | 6525 AstNode id = _findNodeIndexedIn( |
| 6482 "Class", | 6526 "Class", |
| 6483 2, | 6527 2, |
| 6484 r''' | 6528 r''' |
| 6485 class Class { | 6529 class Class { |
| 6486 const Class(); | 6530 const Class(); |
| 6487 } | 6531 } |
| 6488 void main(@Class() parameter) { | 6532 void main(@Class() parameter) { |
| 6489 }'''); | 6533 }'''); |
| 6490 Element element = ElementLocator.locate(id); | 6534 Element element = ElementLocator.locate(id); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6577 Element element = ElementLocator.locate(node); | 6621 Element element = ElementLocator.locate(node); |
| 6578 EngineTestCase.assertInstanceOf( | 6622 EngineTestCase.assertInstanceOf( |
| 6579 (obj) => obj is ConstructorElement, ConstructorElement, element); | 6623 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 6580 } | 6624 } |
| 6581 | 6625 |
| 6582 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { | 6626 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { |
| 6583 // prepare: new pref.A() | 6627 // prepare: new pref.A() |
| 6584 SimpleIdentifier identifier = AstFactory.identifier3("A"); | 6628 SimpleIdentifier identifier = AstFactory.identifier3("A"); |
| 6585 PrefixedIdentifier prefixedIdentifier = | 6629 PrefixedIdentifier prefixedIdentifier = |
| 6586 AstFactory.identifier4("pref", identifier); | 6630 AstFactory.identifier4("pref", identifier); |
| 6587 InstanceCreationExpression creation = AstFactory | 6631 InstanceCreationExpression creation = |
| 6588 .instanceCreationExpression2( | 6632 AstFactory.instanceCreationExpression2( |
| 6589 Keyword.NEW, AstFactory.typeName3(prefixedIdentifier)); | 6633 Keyword.NEW, AstFactory.typeName3(prefixedIdentifier)); |
| 6590 // set ClassElement | 6634 // set ClassElement |
| 6591 ClassElement classElement = ElementFactory.classElement2("A"); | 6635 ClassElement classElement = ElementFactory.classElement2("A"); |
| 6592 identifier.staticElement = classElement; | 6636 identifier.staticElement = classElement; |
| 6593 // set ConstructorElement | 6637 // set ConstructorElement |
| 6594 ConstructorElement constructorElement = | 6638 ConstructorElement constructorElement = |
| 6595 ElementFactory.constructorElement2(classElement, null); | 6639 ElementFactory.constructorElement2(classElement, null); |
| 6596 creation.constructorName.staticElement = constructorElement; | 6640 creation.constructorName.staticElement = constructorElement; |
| 6597 // verify that "A" is resolved to ConstructorElement | 6641 // verify that "A" is resolved to ConstructorElement |
| 6598 Element element = ElementLocator.locate(identifier); | 6642 Element element = ElementLocator.locate(identifier); |
| 6599 expect(element, same(classElement)); | 6643 expect(element, same(classElement)); |
| 6600 } | 6644 } |
| 6601 | 6645 |
| 6602 void test_locate_InstanceCreationExpression_type_simpleIdentifier() { | 6646 void test_locate_InstanceCreationExpression_type_simpleIdentifier() { |
| 6603 // prepare: new A() | 6647 // prepare: new A() |
| 6604 SimpleIdentifier identifier = AstFactory.identifier3("A"); | 6648 SimpleIdentifier identifier = AstFactory.identifier3("A"); |
| 6605 InstanceCreationExpression creation = AstFactory | 6649 InstanceCreationExpression creation = |
| 6606 .instanceCreationExpression2( | 6650 AstFactory.instanceCreationExpression2( |
| 6607 Keyword.NEW, AstFactory.typeName3(identifier)); | 6651 Keyword.NEW, AstFactory.typeName3(identifier)); |
| 6608 // set ClassElement | 6652 // set ClassElement |
| 6609 ClassElement classElement = ElementFactory.classElement2("A"); | 6653 ClassElement classElement = ElementFactory.classElement2("A"); |
| 6610 identifier.staticElement = classElement; | 6654 identifier.staticElement = classElement; |
| 6611 // set ConstructorElement | 6655 // set ConstructorElement |
| 6612 ConstructorElement constructorElement = | 6656 ConstructorElement constructorElement = |
| 6613 ElementFactory.constructorElement2(classElement, null); | 6657 ElementFactory.constructorElement2(classElement, null); |
| 6614 creation.constructorName.staticElement = constructorElement; | 6658 creation.constructorName.staticElement = constructorElement; |
| 6615 // verify that "A" is resolved to ConstructorElement | 6659 // verify that "A" is resolved to ConstructorElement |
| 6616 Element element = ElementLocator.locate(identifier); | 6660 Element element = ElementLocator.locate(identifier); |
| (...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8101 } | 8145 } |
| 8102 | 8146 |
| 8103 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) => | 8147 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) => |
| 8104 new ReferenceFinder((ConstantEvaluationTarget dependency) { | 8148 new ReferenceFinder((ConstantEvaluationTarget dependency) { |
| 8105 _referenceGraph.addEdge(source, dependency); | 8149 _referenceGraph.addEdge(source, dependency); |
| 8106 }); | 8150 }); |
| 8107 SuperConstructorInvocation _makeTailSuperConstructorInvocation( | 8151 SuperConstructorInvocation _makeTailSuperConstructorInvocation( |
| 8108 String name, bool isConst) { | 8152 String name, bool isConst) { |
| 8109 List<ConstructorInitializer> initializers = | 8153 List<ConstructorInitializer> initializers = |
| 8110 new List<ConstructorInitializer>(); | 8154 new List<ConstructorInitializer>(); |
| 8111 ConstructorDeclaration constructorDeclaration = AstFactory | 8155 ConstructorDeclaration constructorDeclaration = |
| 8112 .constructorDeclaration(AstFactory.identifier3(name), null, | 8156 AstFactory.constructorDeclaration(AstFactory.identifier3(name), null, |
| 8113 AstFactory.formalParameterList(), initializers); | 8157 AstFactory.formalParameterList(), initializers); |
| 8114 if (isConst) { | 8158 if (isConst) { |
| 8115 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); | 8159 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); |
| 8116 } | 8160 } |
| 8117 ClassElementImpl classElement = ElementFactory.classElement2(name); | 8161 ClassElementImpl classElement = ElementFactory.classElement2(name); |
| 8118 SuperConstructorInvocation superConstructorInvocation = | 8162 SuperConstructorInvocation superConstructorInvocation = |
| 8119 AstFactory.superConstructorInvocation(); | 8163 AstFactory.superConstructorInvocation(); |
| 8120 ConstructorElementImpl constructorElement = | 8164 ConstructorElementImpl constructorElement = |
| 8121 ElementFactory.constructorElement(classElement, name, isConst); | 8165 ElementFactory.constructorElement(classElement, name, isConst); |
| 8122 _tail = constructorElement; | 8166 _tail = constructorElement; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8236 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); | 8280 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); |
| 8237 expect(UriKind.fromEncoding(0x58), same(null)); | 8281 expect(UriKind.fromEncoding(0x58), same(null)); |
| 8238 } | 8282 } |
| 8239 | 8283 |
| 8240 void test_getEncoding() { | 8284 void test_getEncoding() { |
| 8241 expect(UriKind.DART_URI.encoding, 0x64); | 8285 expect(UriKind.DART_URI.encoding, 0x64); |
| 8242 expect(UriKind.FILE_URI.encoding, 0x66); | 8286 expect(UriKind.FILE_URI.encoding, 0x66); |
| 8243 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 8287 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
| 8244 } | 8288 } |
| 8245 } | 8289 } |
| OLD | NEW |