Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
177 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java10Validator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
package com.github.javaparser.ast.validator; | |||
|
|||
import com.github.javaparser.ast.type.VarType; | |||
|
|||
/** | |||
* This validator validates according to Java 10 syntax rules. | |||
*/ | |||
public class Java10Validator extends Java9Validator { | |||
|
|||
protected final Validator varOnlyOnLocalVariableDefinitionAndFor = new SingleNodeTypeValidator<>(VarType.class, (n, reporter) -> { | |||
|
|||
}); | |||
|
|||
public Java10Validator() { | |||
super(); | |||
add(varOnlyOnLocalVariableDefinitionAndFor); | |||
/* There is no validator that validates that "var" is not used in Java 9 and lower, since the parser will never create a VarType node, | |||
because that is done by the Java10 postprocessor. You can add it by hand, but that is obscure enough to ignore. */ | |||
} | |||
} |
4 changes: 4 additions & 0 deletions
4
javaparser-core/src/main/java/com/github/javaparser/ast/validator/NoProblemsValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
javaparser-core/src/main/java/com/github/javaparser/version/Java10PostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
package com.github.javaparser.version; | |||
|
|||
import com.github.javaparser.ParseResult; | |||
import com.github.javaparser.ParserConfiguration; | |||
import com.github.javaparser.ast.Node; | |||
import com.github.javaparser.ast.type.ClassOrInterfaceType; | |||
import com.github.javaparser.ast.type.VarType; | |||
import com.github.javaparser.ast.validator.Java10Validator; | |||
import com.github.javaparser.ast.validator.ProblemReporter; | |||
import com.github.javaparser.ast.visitor.ModifierVisitor; | |||
import com.github.javaparser.ast.visitor.Visitable; | |||
|
|||
/** | |||
* Processes the generic AST into a Java 10 AST and validates it. | |||
*/ | |||
public class Java10PostProcessor implements ParseResult.PostProcessor { | |||
private final Java10Validator validator = new Java10Validator(); | |||
|
|||
@Override | |||
public void process(ParseResult<? extends Node> result, ParserConfiguration configuration) { | |||
result.getResult().ifPresent(node -> { | |||
node.findAll(ClassOrInterfaceType.class).forEach(n -> { | |||
if (n.getNameAsString().equals("var")) { | |||
n.replace(new VarType(n.getTokenRange().orElse(null))); | |||
} | |||
}); | |||
validator.accept(node, new ProblemReporter(problem -> result.getProblems().add(problem))); | |||
}); | |||
} | |||
} |
28 changes: 0 additions & 28 deletions
28
javaparser-core/src/main/java/com/github/javaparser/version/Java10Processor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
javaparser-testing/src/test/java/com/github/javaparser/ast/validator/ValidatorTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
javaparser-testing/src/test/java/com/github/javaparser/version/Java10PostProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
package com.github.javaparser.version; | |||
|
|||
import com.github.javaparser.JavaParser; | |||
import com.github.javaparser.ParseResult; | |||
import com.github.javaparser.ParserConfiguration; | |||
import com.github.javaparser.ast.CompilationUnit; | |||
import com.github.javaparser.ast.stmt.Statement; | |||
import com.github.javaparser.ast.type.VarType; | |||
import org.junit.Test; | |||
|
|||
import java.util.List; | |||
|
|||
import static com.github.javaparser.ParseStart.COMPILATION_UNIT; | |||
import static com.github.javaparser.ParseStart.STATEMENT; | |||
import static com.github.javaparser.ParserConfiguration.LanguageLevel.*; | |||
import static com.github.javaparser.Providers.provider; | |||
import static com.github.javaparser.ast.validator.Java1_1ValidatorTest.allModifiers; | |||
import static com.github.javaparser.utils.TestUtils.assertNoProblems; | |||
import static com.github.javaparser.utils.TestUtils.assertProblems; | |||
import static org.junit.jupiter.api.Assertions.assertEquals; | |||
|
|||
public class Java10PostProcessorTest { | |||
public static final JavaParser javaParser = new JavaParser(new ParserConfiguration().setLanguageLevel(JAVA_10)); | |||
|
|||
@Test | |||
public void varIsAType() { | |||
ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("var x=\"\";")); | |||
|
|||
List<VarType> allVarTypes = result.getResult().get().findAll(VarType.class); | |||
|
|||
assertEquals(1, allVarTypes.size()); | |||
} | |||
|
|||
@Test | |||
public void varAllowedInLocalVariableDeclaration() { | |||
ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("var a = 5;")); | |||
assertNoProblems(result); | |||
} | |||
|
|||
@Test | |||
public void varAllowedInForEach() { | |||
ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("for(var a : as){}")); | |||
assertNoProblems(result); | |||
} | |||
|
|||
@Test | |||
public void varAllowedInOldFor() { | |||
ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("for(var a = 5;a<9;a++){}")); | |||
assertNoProblems(result); | |||
} | |||
} |
Oops, something went wrong.