| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.parser_test; | 8 library engine.parser_test; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/java_core.dart'; | 10 import 'package:analyzer/src/generated/java_core.dart'; |
| (...skipping 4476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4487 * | 4487 * |
| 4488 * @param source the source to be scanned to produce the token stream being te
sted | 4488 * @param source the source to be scanned to produce the token stream being te
sted |
| 4489 * @return the result of invoking the method | 4489 * @return the result of invoking the method |
| 4490 * @throws Exception if the method could not be invoked or throws an exception | 4490 * @throws Exception if the method could not be invoked or throws an exception |
| 4491 */ | 4491 */ |
| 4492 bool isFunctionExpression(String source) { | 4492 bool isFunctionExpression(String source) { |
| 4493 GatheringErrorListener listener = new GatheringErrorListener(); | 4493 GatheringErrorListener listener = new GatheringErrorListener(); |
| 4494 // | 4494 // |
| 4495 // Scan the source. | 4495 // Scan the source. |
| 4496 // | 4496 // |
| 4497 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 4497 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener
); |
| 4498 Token tokenStream = scanner.tokenize(); | 4498 Token tokenStream = scanner.tokenize(); |
| 4499 // | 4499 // |
| 4500 // Parse the source. | 4500 // Parse the source. |
| 4501 // | 4501 // |
| 4502 Parser parser = new Parser(null, listener); | 4502 Parser parser = new Parser(null, listener); |
| 4503 return invokeParserMethodImpl(parser, "isFunctionExpression", <Object> [toke
nStream], tokenStream) as bool; | 4503 return invokeParserMethodImpl(parser, "isFunctionExpression", <Object> [toke
nStream], tokenStream) as bool; |
| 4504 } | 4504 } |
| 4505 | 4505 |
| 4506 /** | 4506 /** |
| 4507 * Invoke the method [Parser#isInitializedVariableDeclaration] with the parser
set to the | 4507 * Invoke the method [Parser#isInitializedVariableDeclaration] with the parser
set to the |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4537 * @param source the source to be processed by the method | 4537 * @param source the source to be processed by the method |
| 4538 * @return the result of invoking the method | 4538 * @return the result of invoking the method |
| 4539 * @throws Exception if the method could not be invoked or throws an exception | 4539 * @throws Exception if the method could not be invoked or throws an exception |
| 4540 * @throws AssertionFailedError if the result is `null` | 4540 * @throws AssertionFailedError if the result is `null` |
| 4541 */ | 4541 */ |
| 4542 Token skip(String methodName, String source) { | 4542 Token skip(String methodName, String source) { |
| 4543 GatheringErrorListener listener = new GatheringErrorListener(); | 4543 GatheringErrorListener listener = new GatheringErrorListener(); |
| 4544 // | 4544 // |
| 4545 // Scan the source. | 4545 // Scan the source. |
| 4546 // | 4546 // |
| 4547 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 4547 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener
); |
| 4548 Token tokenStream = scanner.tokenize(); | 4548 Token tokenStream = scanner.tokenize(); |
| 4549 // | 4549 // |
| 4550 // Parse the source. | 4550 // Parse the source. |
| 4551 // | 4551 // |
| 4552 Parser parser = new Parser(null, listener); | 4552 Parser parser = new Parser(null, listener); |
| 4553 return invokeParserMethodImpl(parser, methodName, <Object> [tokenStream], to
kenStream) as Token; | 4553 return invokeParserMethodImpl(parser, methodName, <Object> [tokenStream], to
kenStream) as Token; |
| 4554 } | 4554 } |
| 4555 | 4555 |
| 4556 static dartSuite() { | 4556 static dartSuite() { |
| 4557 _ut.group('SimpleParserTest', () { | 4557 _ut.group('SimpleParserTest', () { |
| (...skipping 2838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7396 * Parse the given source as a compilation unit. | 7396 * Parse the given source as a compilation unit. |
| 7397 * | 7397 * |
| 7398 * @param source the source to be parsed | 7398 * @param source the source to be parsed |
| 7399 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 7399 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 7400 * @return the compilation unit that was parsed | 7400 * @return the compilation unit that was parsed |
| 7401 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | 7401 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
| 7402 * not match those that are expected, or if the result would have be
en `null` | 7402 * not match those that are expected, or if the result would have be
en `null` |
| 7403 */ | 7403 */ |
| 7404 static CompilationUnit parseCompilationUnit(String source, List<ErrorCode> err
orCodes) { | 7404 static CompilationUnit parseCompilationUnit(String source, List<ErrorCode> err
orCodes) { |
| 7405 GatheringErrorListener listener = new GatheringErrorListener(); | 7405 GatheringErrorListener listener = new GatheringErrorListener(); |
| 7406 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 7406 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener
); |
| 7407 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 7407 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 7408 Token token = scanner.tokenize(); | 7408 Token token = scanner.tokenize(); |
| 7409 Parser parser = new Parser(null, listener); | 7409 Parser parser = new Parser(null, listener); |
| 7410 CompilationUnit unit = parser.parseCompilationUnit(token); | 7410 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 7411 JUnitTestCase.assertNotNull(unit); | 7411 JUnitTestCase.assertNotNull(unit); |
| 7412 listener.assertErrors2(errorCodes); | 7412 listener.assertErrors2(errorCodes); |
| 7413 return unit; | 7413 return unit; |
| 7414 } | 7414 } |
| 7415 | 7415 |
| 7416 /** | 7416 /** |
| 7417 * Parse the given source as an expression. | 7417 * Parse the given source as an expression. |
| 7418 * | 7418 * |
| 7419 * @param source the source to be parsed | 7419 * @param source the source to be parsed |
| 7420 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 7420 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 7421 * @return the expression that was parsed | 7421 * @return the expression that was parsed |
| 7422 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | 7422 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
| 7423 * not match those that are expected, or if the result would have be
en `null` | 7423 * not match those that are expected, or if the result would have be
en `null` |
| 7424 */ | 7424 */ |
| 7425 static Expression parseExpression(String source, List<ErrorCode> errorCodes) { | 7425 static Expression parseExpression(String source, List<ErrorCode> errorCodes) { |
| 7426 GatheringErrorListener listener = new GatheringErrorListener(); | 7426 GatheringErrorListener listener = new GatheringErrorListener(); |
| 7427 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 7427 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener
); |
| 7428 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 7428 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 7429 Token token = scanner.tokenize(); | 7429 Token token = scanner.tokenize(); |
| 7430 Parser parser = new Parser(null, listener); | 7430 Parser parser = new Parser(null, listener); |
| 7431 Expression expression = parser.parseExpression(token); | 7431 Expression expression = parser.parseExpression(token); |
| 7432 JUnitTestCase.assertNotNull(expression); | 7432 JUnitTestCase.assertNotNull(expression); |
| 7433 listener.assertErrors2(errorCodes); | 7433 listener.assertErrors2(errorCodes); |
| 7434 return expression; | 7434 return expression; |
| 7435 } | 7435 } |
| 7436 | 7436 |
| 7437 /** | 7437 /** |
| 7438 * Parse the given source as a statement. | 7438 * Parse the given source as a statement. |
| 7439 * | 7439 * |
| 7440 * @param source the source to be parsed | 7440 * @param source the source to be parsed |
| 7441 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 7441 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 7442 * @return the statement that was parsed | 7442 * @return the statement that was parsed |
| 7443 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | 7443 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
| 7444 * not match those that are expected, or if the result would have be
en `null` | 7444 * not match those that are expected, or if the result would have be
en `null` |
| 7445 */ | 7445 */ |
| 7446 static Statement parseStatement(String source, List<ErrorCode> errorCodes) { | 7446 static Statement parseStatement(String source, List<ErrorCode> errorCodes) { |
| 7447 GatheringErrorListener listener = new GatheringErrorListener(); | 7447 GatheringErrorListener listener = new GatheringErrorListener(); |
| 7448 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 7448 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener
); |
| 7449 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 7449 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 7450 Token token = scanner.tokenize(); | 7450 Token token = scanner.tokenize(); |
| 7451 Parser parser = new Parser(null, listener); | 7451 Parser parser = new Parser(null, listener); |
| 7452 Statement statement = parser.parseStatement(token); | 7452 Statement statement = parser.parseStatement(token); |
| 7453 JUnitTestCase.assertNotNull(statement); | 7453 JUnitTestCase.assertNotNull(statement); |
| 7454 listener.assertErrors2(errorCodes); | 7454 listener.assertErrors2(errorCodes); |
| 7455 return statement; | 7455 return statement; |
| 7456 } | 7456 } |
| 7457 | 7457 |
| 7458 /** | 7458 /** |
| 7459 * Parse the given source as a sequence of statements. | 7459 * Parse the given source as a sequence of statements. |
| 7460 * | 7460 * |
| 7461 * @param source the source to be parsed | 7461 * @param source the source to be parsed |
| 7462 * @param expectedCount the number of statements that are expected | 7462 * @param expectedCount the number of statements that are expected |
| 7463 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 7463 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 7464 * @return the statements that were parsed | 7464 * @return the statements that were parsed |
| 7465 * @throws Exception if the source could not be parsed, if the number of state
ments does not match | 7465 * @throws Exception if the source could not be parsed, if the number of state
ments does not match |
| 7466 * the expected count, if the compilation errors in the source do no
t match those that | 7466 * the expected count, if the compilation errors in the source do no
t match those that |
| 7467 * are expected, or if the result would have been `null` | 7467 * are expected, or if the result would have been `null` |
| 7468 */ | 7468 */ |
| 7469 static List<Statement> parseStatements(String source, int expectedCount, List<
ErrorCode> errorCodes) { | 7469 static List<Statement> parseStatements(String source, int expectedCount, List<
ErrorCode> errorCodes) { |
| 7470 GatheringErrorListener listener = new GatheringErrorListener(); | 7470 GatheringErrorListener listener = new GatheringErrorListener(); |
| 7471 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 7471 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener
); |
| 7472 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 7472 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 7473 Token token = scanner.tokenize(); | 7473 Token token = scanner.tokenize(); |
| 7474 Parser parser = new Parser(null, listener); | 7474 Parser parser = new Parser(null, listener); |
| 7475 List<Statement> statements = parser.parseStatements(token); | 7475 List<Statement> statements = parser.parseStatements(token); |
| 7476 EngineTestCase.assertSize(expectedCount, statements); | 7476 EngineTestCase.assertSize(expectedCount, statements); |
| 7477 listener.assertErrors2(errorCodes); | 7477 listener.assertErrors2(errorCodes); |
| 7478 return statements; | 7478 return statements; |
| 7479 } | 7479 } |
| 7480 | 7480 |
| 7481 /** | 7481 /** |
| 7482 * Invoke a method in [Parser]. The method is assumed to have the given number
and type of | 7482 * Invoke a method in [Parser]. The method is assumed to have the given number
and type of |
| 7483 * parameters and will be invoked with the given arguments. | 7483 * parameters and will be invoked with the given arguments. |
| 7484 * | 7484 * |
| 7485 * The given source is scanned and the parser is initialized to start with the
first token in the | 7485 * The given source is scanned and the parser is initialized to start with the
first token in the |
| 7486 * source before the method is invoked. | 7486 * source before the method is invoked. |
| 7487 * | 7487 * |
| 7488 * @param methodName the name of the method that should be invoked | 7488 * @param methodName the name of the method that should be invoked |
| 7489 * @param objects the values of the arguments to the method | 7489 * @param objects the values of the arguments to the method |
| 7490 * @param source the source to be processed by the parse method | 7490 * @param source the source to be processed by the parse method |
| 7491 * @param listener the error listener that will be used for both scanning and
parsing | 7491 * @param listener the error listener that will be used for both scanning and
parsing |
| 7492 * @return the result of invoking the method | 7492 * @return the result of invoking the method |
| 7493 * @throws Exception if the method could not be invoked or throws an exception | 7493 * @throws Exception if the method could not be invoked or throws an exception |
| 7494 * @throws AssertionFailedError if the result is `null` or the errors produced
while | 7494 * @throws AssertionFailedError if the result is `null` or the errors produced
while |
| 7495 * scanning and parsing the source do not match the expected errors | 7495 * scanning and parsing the source do not match the expected errors |
| 7496 */ | 7496 */ |
| 7497 static Object invokeParserMethod(String methodName, List<Object> objects, Stri
ng source, GatheringErrorListener listener) { | 7497 static Object invokeParserMethod(String methodName, List<Object> objects, Stri
ng source, GatheringErrorListener listener) { |
| 7498 // | 7498 // |
| 7499 // Scan the source. | 7499 // Scan the source. |
| 7500 // | 7500 // |
| 7501 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 7501 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener
); |
| 7502 Token tokenStream = scanner.tokenize(); | 7502 Token tokenStream = scanner.tokenize(); |
| 7503 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 7503 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 7504 // | 7504 // |
| 7505 // Parse the source. | 7505 // Parse the source. |
| 7506 // | 7506 // |
| 7507 Parser parser = new Parser(null, listener); | 7507 Parser parser = new Parser(null, listener); |
| 7508 parser.parseFunctionBodies = _parseFunctionBodies; | 7508 parser.parseFunctionBodies = _parseFunctionBodies; |
| 7509 Object result = invokeParserMethodImpl(parser, methodName, objects, tokenStr
eam); | 7509 Object result = invokeParserMethodImpl(parser, methodName, objects, tokenStr
eam); |
| 7510 // | 7510 // |
| 7511 // Partially test the results. | 7511 // Partially test the results. |
| (...skipping 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9424 // Compute the information needed to perform the test. | 9424 // Compute the information needed to perform the test. |
| 9425 // | 9425 // |
| 9426 String originalContents = "${prefix}${removed}${suffix}"; | 9426 String originalContents = "${prefix}${removed}${suffix}"; |
| 9427 String modifiedContents = "${prefix}${added}${suffix}"; | 9427 String modifiedContents = "${prefix}${added}${suffix}"; |
| 9428 int replaceStart = prefix.length; | 9428 int replaceStart = prefix.length; |
| 9429 Source source = new TestSource(); | 9429 Source source = new TestSource(); |
| 9430 // | 9430 // |
| 9431 // Parse the original contents. | 9431 // Parse the original contents. |
| 9432 // | 9432 // |
| 9433 GatheringErrorListener originalListener = new GatheringErrorListener(); | 9433 GatheringErrorListener originalListener = new GatheringErrorListener(); |
| 9434 Scanner originalScanner = new Scanner(source, new CharSequenceReader(new Cha
rSequence(originalContents)), originalListener); | 9434 Scanner originalScanner = new Scanner(source, new CharSequenceReader(origina
lContents), originalListener); |
| 9435 Token originalTokens = originalScanner.tokenize(); | 9435 Token originalTokens = originalScanner.tokenize(); |
| 9436 JUnitTestCase.assertNotNull(originalTokens); | 9436 JUnitTestCase.assertNotNull(originalTokens); |
| 9437 Parser originalParser = new Parser(source, originalListener); | 9437 Parser originalParser = new Parser(source, originalListener); |
| 9438 CompilationUnit originalUnit = originalParser.parseCompilationUnit(originalT
okens); | 9438 CompilationUnit originalUnit = originalParser.parseCompilationUnit(originalT
okens); |
| 9439 JUnitTestCase.assertNotNull(originalUnit); | 9439 JUnitTestCase.assertNotNull(originalUnit); |
| 9440 // | 9440 // |
| 9441 // Parse the modified contents. | 9441 // Parse the modified contents. |
| 9442 // | 9442 // |
| 9443 GatheringErrorListener modifiedListener = new GatheringErrorListener(); | 9443 GatheringErrorListener modifiedListener = new GatheringErrorListener(); |
| 9444 Scanner modifiedScanner = new Scanner(source, new CharSequenceReader(new Cha
rSequence(modifiedContents)), modifiedListener); | 9444 Scanner modifiedScanner = new Scanner(source, new CharSequenceReader(modifie
dContents), modifiedListener); |
| 9445 Token modifiedTokens = modifiedScanner.tokenize(); | 9445 Token modifiedTokens = modifiedScanner.tokenize(); |
| 9446 JUnitTestCase.assertNotNull(modifiedTokens); | 9446 JUnitTestCase.assertNotNull(modifiedTokens); |
| 9447 Parser modifiedParser = new Parser(source, modifiedListener); | 9447 Parser modifiedParser = new Parser(source, modifiedListener); |
| 9448 CompilationUnit modifiedUnit = modifiedParser.parseCompilationUnit(modifiedT
okens); | 9448 CompilationUnit modifiedUnit = modifiedParser.parseCompilationUnit(modifiedT
okens); |
| 9449 JUnitTestCase.assertNotNull(modifiedUnit); | 9449 JUnitTestCase.assertNotNull(modifiedUnit); |
| 9450 // | 9450 // |
| 9451 // Incrementally parse the modified contents. | 9451 // Incrementally parse the modified contents. |
| 9452 // | 9452 // |
| 9453 GatheringErrorListener incrementalListener = new GatheringErrorListener(); | 9453 GatheringErrorListener incrementalListener = new GatheringErrorListener(); |
| 9454 IncrementalScanner incrementalScanner = new IncrementalScanner(source, new C
harSequenceReader(new CharSequence(modifiedContents)), incrementalListener); | 9454 IncrementalScanner incrementalScanner = new IncrementalScanner(source, new C
harSequenceReader(modifiedContents), incrementalListener); |
| 9455 Token incrementalTokens = incrementalScanner.rescan(originalTokens, replaceS
tart, removed.length, added.length); | 9455 Token incrementalTokens = incrementalScanner.rescan(originalTokens, replaceS
tart, removed.length, added.length); |
| 9456 JUnitTestCase.assertNotNull(incrementalTokens); | 9456 JUnitTestCase.assertNotNull(incrementalTokens); |
| 9457 IncrementalParser incrementalParser = new IncrementalParser(source, incremen
talScanner.tokenMap, incrementalListener); | 9457 IncrementalParser incrementalParser = new IncrementalParser(source, incremen
talScanner.tokenMap, incrementalListener); |
| 9458 CompilationUnit incrementalUnit = incrementalParser.reparse(originalUnit, in
crementalScanner.leftToken, incrementalScanner.rightToken, replaceStart, prefix.
length + removed.length); | 9458 CompilationUnit incrementalUnit = incrementalParser.reparse(originalUnit, in
crementalScanner.leftToken, incrementalScanner.rightToken, replaceStart, prefix.
length + removed.length); |
| 9459 JUnitTestCase.assertNotNull(incrementalUnit); | 9459 JUnitTestCase.assertNotNull(incrementalUnit); |
| 9460 // | 9460 // |
| 9461 // Validate that the results of the incremental parse are the same as the fu
ll parse of the | 9461 // Validate that the results of the incremental parse are the same as the fu
ll parse of the |
| 9462 // modified source. | 9462 // modified source. |
| 9463 // | 9463 // |
| 9464 JUnitTestCase.assertTrue(ASTComparator.equals4(modifiedUnit, incrementalUnit
)); | 9464 JUnitTestCase.assertTrue(ASTComparator.equals4(modifiedUnit, incrementalUnit
)); |
| (...skipping 2344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11809 'validateModifiersForTopLevelFunction_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelFunction(arg0)), | 11809 'validateModifiersForTopLevelFunction_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelFunction(arg0)), |
| 11810 'validateModifiersForTopLevelVariable_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelVariable(arg0)), | 11810 'validateModifiersForTopLevelVariable_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelVariable(arg0)), |
| 11811 'validateModifiersForTypedef_1': new MethodTrampoline(1, (Parser target, arg0)
=> target.validateModifiersForTypedef(arg0)),}; | 11811 'validateModifiersForTypedef_1': new MethodTrampoline(1, (Parser target, arg0)
=> target.validateModifiersForTypedef(arg0)),}; |
| 11812 | 11812 |
| 11813 | 11813 |
| 11814 Object invokeParserMethodImpl(Parser parser, String methodName, List<Object> obj
ects, Token tokenStream) { | 11814 Object invokeParserMethodImpl(Parser parser, String methodName, List<Object> obj
ects, Token tokenStream) { |
| 11815 parser.currentToken = tokenStream; | 11815 parser.currentToken = tokenStream; |
| 11816 MethodTrampoline method = _methodTable_Parser['${methodName}_${objects.length}
']; | 11816 MethodTrampoline method = _methodTable_Parser['${methodName}_${objects.length}
']; |
| 11817 return method.invoke(parser, objects); | 11817 return method.invoke(parser, objects); |
| 11818 } | 11818 } |
| OLD | NEW |