Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set Java 8 as default validation level
* Add Java 9 validators with one more validation than Java 8: _ as identifier is invalid * Sort Problems by beginposition
- Loading branch information
Showing
9 changed files
with
102 additions
and
3 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
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
12 changes: 12 additions & 0 deletions
12
javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java8Validator.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.javaparser.ast.validator; | ||
|
||
/** | ||
* This validator validates according to Java 8 syntax rules. | ||
*/ | ||
public class Java8Validator extends Validators { | ||
public Java8Validator() { | ||
super( | ||
new BaseJavaValidator() | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java9Validator.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.javaparser.ast.validator; | ||
|
||
import com.github.javaparser.ast.Node; | ||
import com.github.javaparser.ast.expr.Name; | ||
import com.github.javaparser.ast.expr.SimpleName; | ||
|
||
/** | ||
* This validator validates according to Java 9 syntax rules. | ||
*/ | ||
public class Java9Validator extends Validators { | ||
public Java9Validator() { | ||
super( | ||
new BaseJavaValidator(), | ||
new VisitorValidator() { | ||
@Override | ||
public void visit(Name n, ProblemReporter arg) { | ||
validateIdentifier(n, n.getIdentifier(), arg); | ||
super.visit(n, arg); | ||
} | ||
|
||
@Override | ||
public void visit(SimpleName n, ProblemReporter arg) { | ||
validateIdentifier(n, n.getIdentifier(), arg); | ||
super.visit(n, arg); | ||
} | ||
} | ||
); | ||
} | ||
|
||
private static void validateIdentifier(Node n, String id, ProblemReporter arg) { | ||
if (id.equals("_")) { | ||
arg.report(n, "'_' is a reserved keyword."); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java8ValidatorTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.github.javaparser.ast.validator; | ||
|
||
public class Java8ValidatorTest { | ||
// Everything is tested in BaseValidatorTest | ||
} |
26 changes: 26 additions & 0 deletions
26
javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java9ValidatorTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.javaparser.ast.validator; | ||
|
||
import com.github.javaparser.JavaParser; | ||
import com.github.javaparser.ParseResult; | ||
import com.github.javaparser.ParserConfiguration; | ||
import com.github.javaparser.ast.stmt.Statement; | ||
import org.junit.Test; | ||
|
||
import static com.github.javaparser.ParseStart.STATEMENT; | ||
import static com.github.javaparser.Providers.provider; | ||
import static com.github.javaparser.utils.TestUtils.assertProblems; | ||
|
||
public class Java9ValidatorTest { | ||
private final JavaParser parser = new JavaParser(new ParserConfiguration().setValidator(new Java9Validator())); | ||
|
||
@Test | ||
public void tryUnderscoreIdentifiers() { | ||
ParseResult<Statement> result = parser.parse(STATEMENT, provider("a.b._.c.d = act(_, _ -> _);")); | ||
assertProblems(result, | ||
"(line 1,col 5) '_' is a reserved keyword.", | ||
"(line 1,col 17) '_' is a reserved keyword.", | ||
"(line 1,col 20) '_' is a reserved keyword.", | ||
"(line 1,col 25) '_' is a reserved keyword." | ||
); | ||
} | ||
} |