| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 library engine.ast_test; | 3 library engine.ast_test; |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'package:analyzer_experimental/src/generated/java_core.dart'; | 5 import 'package:analyzer_experimental/src/generated/java_core.dart'; |
| 6 import 'package:analyzer_experimental/src/generated/java_engine.dart'; | 6 import 'package:analyzer_experimental/src/generated/java_engine.dart'; |
| 7 import 'package:analyzer_experimental/src/generated/java_junit.dart'; | 7 import 'package:analyzer_experimental/src/generated/java_junit.dart'; |
| 8 import 'package:analyzer_experimental/src/generated/source.dart'; | 8 import 'package:analyzer_experimental/src/generated/source.dart'; |
| 9 import 'package:analyzer_experimental/src/generated/error.dart'; | 9 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 10 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 10 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 static TryStatement tryStatement2(Block body, List<CatchClause> catchClauses)
=> tryStatement3(body, list(catchClauses), null); | 397 static TryStatement tryStatement2(Block body, List<CatchClause> catchClauses)
=> tryStatement3(body, list(catchClauses), null); |
| 398 static TryStatement tryStatement3(Block body, List<CatchClause> catchClauses,
Block finallyClause) => new TryStatement.full(TokenFactory.token(Keyword.TRY), b
ody, catchClauses, finallyClause == null ? null : TokenFactory.token(Keyword.FIN
ALLY), finallyClause); | 398 static TryStatement tryStatement3(Block body, List<CatchClause> catchClauses,
Block finallyClause) => new TryStatement.full(TokenFactory.token(Keyword.TRY), b
ody, catchClauses, finallyClause == null ? null : TokenFactory.token(Keyword.FIN
ALLY), finallyClause); |
| 399 static FunctionTypeAlias typeAlias(TypeName returnType, String name, TypeParam
eterList typeParameters, FormalParameterList parameters) => new FunctionTypeAlia
s.full(null, null, TokenFactory.token(Keyword.TYPEDEF), returnType, identifier3(
name), typeParameters, parameters, TokenFactory.token3(TokenType.SEMICOLON)); | 399 static FunctionTypeAlias typeAlias(TypeName returnType, String name, TypeParam
eterList typeParameters, FormalParameterList parameters) => new FunctionTypeAlia
s.full(null, null, TokenFactory.token(Keyword.TYPEDEF), returnType, identifier3(
name), typeParameters, parameters, TokenFactory.token3(TokenType.SEMICOLON)); |
| 400 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) => new Type
ArgumentList.full(TokenFactory.token3(TokenType.LT), list(typeNames), TokenFacto
ry.token3(TokenType.GT)); | 400 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) => new Type
ArgumentList.full(TokenFactory.token3(TokenType.LT), list(typeNames), TokenFacto
ry.token3(TokenType.GT)); |
| 401 | 401 |
| 402 /** | 402 /** |
| 403 * Create a type name whose name has been resolved to the given element and wh
ose type has been | 403 * Create a type name whose name has been resolved to the given element and wh
ose type has been |
| 404 * resolved to the type of the given element. | 404 * resolved to the type of the given element. |
| 405 * | 405 * |
| 406 * <b>Note:</b> This method does not correctly handle class elements that have
type parameters. | 406 * <b>Note:</b> This method does not correctly handle class elements that have
type parameters. |
| 407 * |
| 407 * @param element the element defining the type represented by the type name | 408 * @param element the element defining the type represented by the type name |
| 408 * @return the type name that was created | 409 * @return the type name that was created |
| 409 */ | 410 */ |
| 410 static TypeName typeName(ClassElement element2, List<TypeName> arguments) { | 411 static TypeName typeName(ClassElement element2, List<TypeName> arguments) { |
| 411 SimpleIdentifier name = identifier3(element2.name); | 412 SimpleIdentifier name = identifier3(element2.name); |
| 412 name.element = element2; | 413 name.element = element2; |
| 413 TypeName typeName = typeName3(name, arguments); | 414 TypeName typeName = typeName3(name, arguments); |
| 414 typeName.type = element2.type; | 415 typeName.type = element2.type; |
| 415 return typeName; | 416 return typeName; |
| 416 } | 417 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } else if (assignment == AssignmentKind.SIMPLE_RIGHT) { | 588 } else if (assignment == AssignmentKind.SIMPLE_RIGHT) { |
| 588 ASTFactory.assignmentExpression(ASTFactory.identifier3("_"), TokenType.E
Q, expression); | 589 ASTFactory.assignmentExpression(ASTFactory.identifier3("_"), TokenType.E
Q, expression); |
| 589 } | 590 } |
| 590 break; | 591 break; |
| 591 } | 592 } |
| 592 return identifier; | 593 return identifier; |
| 593 } | 594 } |
| 594 | 595 |
| 595 /** | 596 /** |
| 596 * Return the top-most node in the AST structure containing the given identifi
er. | 597 * Return the top-most node in the AST structure containing the given identifi
er. |
| 598 * |
| 597 * @param identifier the identifier in the AST structure being traversed | 599 * @param identifier the identifier in the AST structure being traversed |
| 598 * @return the root of the AST structure containing the identifier | 600 * @return the root of the AST structure containing the identifier |
| 599 */ | 601 */ |
| 600 ASTNode topMostNode(SimpleIdentifier identifier) { | 602 ASTNode topMostNode(SimpleIdentifier identifier) { |
| 601 ASTNode child = identifier; | 603 ASTNode child = identifier; |
| 602 ASTNode parent = identifier.parent; | 604 ASTNode parent = identifier.parent; |
| 603 while (parent != null) { | 605 while (parent != null) { |
| 604 child = parent; | 606 child = parent; |
| 605 parent = parent.parent; | 607 parent = parent.parent; |
| 606 } | 608 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 } | 730 } |
| 729 int compareTo(WrapperKind other) => ordinal - other.ordinal; | 731 int compareTo(WrapperKind other) => ordinal - other.ordinal; |
| 730 int get hashCode => ordinal; | 732 int get hashCode => ordinal; |
| 731 String toString() => name; | 733 String toString() => name; |
| 732 } | 734 } |
| 733 class BreadthFirstVisitorTest extends ParserTestCase { | 735 class BreadthFirstVisitorTest extends ParserTestCase { |
| 734 void testIt() { | 736 void testIt() { |
| 735 String source = EngineTestCase.createSource(["class A {", " bool get g => t
rue;", "}", "class B {", " int f() {", " num q() {", " return 3;", "
}", " return q() + 4;", " }", "}", "A f(var p) {", " if ((p as A).g) {", "
return p;", " } else {", " return null;", " }", "}"]); | 737 String source = EngineTestCase.createSource(["class A {", " bool get g => t
rue;", "}", "class B {", " int f() {", " num q() {", " return 3;", "
}", " return q() + 4;", " }", "}", "A f(var p) {", " if ((p as A).g) {", "
return p;", " } else {", " return null;", " }", "}"]); |
| 736 CompilationUnit unit = ParserTestCase.parseCompilationUnit(source, []); | 738 CompilationUnit unit = ParserTestCase.parseCompilationUnit(source, []); |
| 737 List<ASTNode> nodes = new List<ASTNode>(); | 739 List<ASTNode> nodes = new List<ASTNode>(); |
| 738 BreadthFirstVisitor<Object> visitor = new BreadthFirstVisitor_14(nodes); | 740 BreadthFirstVisitor<Object> visitor = new BreadthFirstVisitor_15(nodes); |
| 739 visitor.visitAllNodes(unit); | 741 visitor.visitAllNodes(unit); |
| 740 EngineTestCase.assertSize(59, nodes); | 742 EngineTestCase.assertSize(59, nodes); |
| 741 EngineTestCase.assertInstanceOf(CompilationUnit, nodes[0]); | 743 EngineTestCase.assertInstanceOf(CompilationUnit, nodes[0]); |
| 742 EngineTestCase.assertInstanceOf(ClassDeclaration, nodes[2]); | 744 EngineTestCase.assertInstanceOf(ClassDeclaration, nodes[2]); |
| 743 EngineTestCase.assertInstanceOf(FunctionDeclaration, nodes[3]); | 745 EngineTestCase.assertInstanceOf(FunctionDeclaration, nodes[3]); |
| 744 EngineTestCase.assertInstanceOf(FunctionDeclarationStatement, nodes[27]); | 746 EngineTestCase.assertInstanceOf(FunctionDeclarationStatement, nodes[27]); |
| 745 EngineTestCase.assertInstanceOf(IntegerLiteral, nodes[58]); | 747 EngineTestCase.assertInstanceOf(IntegerLiteral, nodes[58]); |
| 746 } | 748 } |
| 747 static dartSuite() { | 749 static dartSuite() { |
| 748 _ut.group('BreadthFirstVisitorTest', () { | 750 _ut.group('BreadthFirstVisitorTest', () { |
| 749 _ut.test('testIt', () { | 751 _ut.test('testIt', () { |
| 750 final __test = new BreadthFirstVisitorTest(); | 752 final __test = new BreadthFirstVisitorTest(); |
| 751 runJUnitTest(__test, __test.testIt); | 753 runJUnitTest(__test, __test.testIt); |
| 752 }); | 754 }); |
| 753 }); | 755 }); |
| 754 } | 756 } |
| 755 } | 757 } |
| 756 class BreadthFirstVisitor_14 extends BreadthFirstVisitor<Object> { | 758 class BreadthFirstVisitor_15 extends BreadthFirstVisitor<Object> { |
| 757 List<ASTNode> nodes; | 759 List<ASTNode> nodes; |
| 758 BreadthFirstVisitor_14(this.nodes) : super(); | 760 BreadthFirstVisitor_15(this.nodes) : super(); |
| 759 Object visitNode(ASTNode node) { | 761 Object visitNode(ASTNode node) { |
| 760 nodes.add(node); | 762 nodes.add(node); |
| 761 return super.visitNode(node); | 763 return super.visitNode(node); |
| 762 } | 764 } |
| 763 } | 765 } |
| 764 class ConstantEvaluatorTest extends ParserTestCase { | 766 class ConstantEvaluatorTest extends ParserTestCase { |
| 765 void fail_constructor() { | 767 void fail_constructor() { |
| 766 Object value = getConstantValue("?"); | 768 Object value = getConstantValue("?"); |
| 767 JUnitTestCase.assertEquals(null, value); | 769 JUnitTestCase.assertEquals(null, value); |
| 768 } | 770 } |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1945 void test_visitWithClause_multiple() { | 1947 void test_visitWithClause_multiple() { |
| 1946 assertSource("with A, B, C", ASTFactory.withClause([ASTFactory.typeName4("A"
, []), ASTFactory.typeName4("B", []), ASTFactory.typeName4("C", [])])); | 1948 assertSource("with A, B, C", ASTFactory.withClause([ASTFactory.typeName4("A"
, []), ASTFactory.typeName4("B", []), ASTFactory.typeName4("C", [])])); |
| 1947 } | 1949 } |
| 1948 void test_visitWithClause_single() { | 1950 void test_visitWithClause_single() { |
| 1949 assertSource("with A", ASTFactory.withClause([ASTFactory.typeName4("A", [])]
)); | 1951 assertSource("with A", ASTFactory.withClause([ASTFactory.typeName4("A", [])]
)); |
| 1950 } | 1952 } |
| 1951 | 1953 |
| 1952 /** | 1954 /** |
| 1953 * Assert that a `ToSourceVisitor` will produce the expected source when visit
ing the given | 1955 * Assert that a `ToSourceVisitor` will produce the expected source when visit
ing the given |
| 1954 * node. | 1956 * node. |
| 1957 * |
| 1955 * @param expectedSource the source string that the visitor is expected to pro
duce | 1958 * @param expectedSource the source string that the visitor is expected to pro
duce |
| 1956 * @param node the AST node being visited to produce the actual source | 1959 * @param node the AST node being visited to produce the actual source |
| 1957 * @throws AFE if the visitor does not produce the expected source for the giv
en node | 1960 * @throws AFE if the visitor does not produce the expected source for the giv
en node |
| 1958 */ | 1961 */ |
| 1959 void assertSource(String expectedSource, ASTNode node) { | 1962 void assertSource(String expectedSource, ASTNode node) { |
| 1960 PrintStringWriter writer = new PrintStringWriter(); | 1963 PrintStringWriter writer = new PrintStringWriter(); |
| 1961 node.accept(new ToSourceVisitor(writer)); | 1964 node.accept(new ToSourceVisitor(writer)); |
| 1962 JUnitTestCase.assertEquals(expectedSource, writer.toString()); | 1965 JUnitTestCase.assertEquals(expectedSource, writer.toString()); |
| 1963 } | 1966 } |
| 1964 static dartSuite() { | 1967 static dartSuite() { |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2936 } | 2939 } |
| 2937 main() { | 2940 main() { |
| 2938 ConstantEvaluatorTest.dartSuite(); | 2941 ConstantEvaluatorTest.dartSuite(); |
| 2939 NodeLocatorTest.dartSuite(); | 2942 NodeLocatorTest.dartSuite(); |
| 2940 ToSourceVisitorTest.dartSuite(); | 2943 ToSourceVisitorTest.dartSuite(); |
| 2941 BreadthFirstVisitorTest.dartSuite(); | 2944 BreadthFirstVisitorTest.dartSuite(); |
| 2942 IndexExpressionTest.dartSuite(); | 2945 IndexExpressionTest.dartSuite(); |
| 2943 SimpleIdentifierTest.dartSuite(); | 2946 SimpleIdentifierTest.dartSuite(); |
| 2944 VariableDeclarationTest.dartSuite(); | 2947 VariableDeclarationTest.dartSuite(); |
| 2945 } | 2948 } |
| OLD | NEW |