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
14 changed files
with
138 additions
and
98 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
11 changes: 10 additions & 1 deletion
11
javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java7Validator.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
31 changes: 18 additions & 13 deletions
31
...arser-testing/src/test/java/com/github/javaparser/ast/validator/Java1_0ValidatorTest.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 |
---|---|---|---|
@@ -1,75 +1,80 @@ | |||
package com.github.javaparser.ast.validator; | package com.github.javaparser.ast.validator; | ||
|
|
||
import com.github.javaparser.JavaParser; | |||
import com.github.javaparser.ParseResult; | import com.github.javaparser.ParseResult; | ||
import com.github.javaparser.ParserConfiguration; | |||
import com.github.javaparser.ast.CompilationUnit; | import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.expr.Expression; | import com.github.javaparser.ast.expr.Expression; | ||
import com.github.javaparser.ast.stmt.Statement; | import com.github.javaparser.ast.stmt.Statement; | ||
import org.junit.Test; | import org.junit.Test; | ||
|
|
||
import static com.github.javaparser.ParseStart.*; | import static com.github.javaparser.ParseStart.*; | ||
import static com.github.javaparser.Providers.provider; | import static com.github.javaparser.Providers.provider; | ||
import static com.github.javaparser.ast.validator.ValidatorTest.javaParser1_0; | |||
import static com.github.javaparser.utils.TestUtils.assertNoProblems; | import static com.github.javaparser.utils.TestUtils.assertNoProblems; | ||
import static com.github.javaparser.utils.TestUtils.assertProblems; | import static com.github.javaparser.utils.TestUtils.assertProblems; | ||
|
|
||
public class Java1_0ValidatorTest { | public class Java1_0ValidatorTest { | ||
public static final JavaParser javaParser = new JavaParser(new ParserConfiguration().setValidator(new Java1_0Validator())); | |||
|
|||
@Test | @Test | ||
public void tryWithoutAnything() { | public void tryWithoutResources() { | ||
ParseResult<Statement> result = javaParser1_0.parse(STATEMENT, provider("try{}")); | ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("try(X x=new Y()){}")); | ||
assertProblems(result, "(line 1,col 1) Try has no finally, no catch, and no resources."); | assertProblems(result, | ||
"(line 1,col 1) Catch with resource is not supported.", | |||
"(line 1,col 1) Try has no finally and no catch."); | |||
} | } | ||
|
|
||
@Test | @Test | ||
public void classExtendingMoreThanOne() { | public void classExtendingMoreThanOne() { | ||
ParseResult<CompilationUnit> result = javaParser1_0.parse(COMPILATION_UNIT, provider("class X extends Y, Z {}")); | ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("class X extends Y, Z {}")); | ||
assertProblems(result, "(line 1,col 20) A class cannot extend more than one other class."); | assertProblems(result, "(line 1,col 20) A class cannot extend more than one other class."); | ||
} | } | ||
|
|
||
@Test | @Test | ||
public void interfaceUsingImplements() { | public void interfaceUsingImplements() { | ||
ParseResult<CompilationUnit> result = javaParser1_0.parse(COMPILATION_UNIT, provider("interface X implements Y {}")); | ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("interface X implements Y {}")); | ||
assertProblems(result, "(line 1,col 24) An interface cannot implement other interfaces."); | assertProblems(result, "(line 1,col 24) An interface cannot implement other interfaces."); | ||
} | } | ||
|
|
||
@Test | @Test | ||
public void interfaceWithInitializer() { | public void interfaceWithInitializer() { | ||
ParseResult<CompilationUnit> result = javaParser1_0.parse(COMPILATION_UNIT, provider("interface X {{}}")); | ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("interface X {{}}")); | ||
assertProblems(result, "(line 1,col 14) An interface cannot have initializers."); | assertProblems(result, "(line 1,col 14) An interface cannot have initializers."); | ||
} | } | ||
|
|
||
@Test | @Test | ||
public void defaultInClass() { | public void defaultInClass() { | ||
ParseResult<CompilationUnit> result = javaParser1_0.parse(COMPILATION_UNIT, provider("class X {default void a(){};}")); | ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("class X {default void a(){};}")); | ||
assertProblems(result, "(line 1,col 10) 'default' is not allowed here."); | assertProblems(result, "(line 1,col 10) 'default' is not allowed here."); | ||
} | } | ||
|
|
||
@Test | @Test | ||
public void leftHandAssignmentCannotBeAConditional() { | public void leftHandAssignmentCannotBeAConditional() { | ||
ParseResult<Expression> result = javaParser1_0.parse(EXPRESSION, provider("(1==2)=3")); | ParseResult<Expression> result = javaParser.parse(EXPRESSION, provider("(1==2)=3")); | ||
assertProblems(result, "(line 1,col 1) Illegal left hand side of an assignment."); | assertProblems(result, "(line 1,col 1) Illegal left hand side of an assignment."); | ||
} | } | ||
|
|
||
@Test | @Test | ||
public void leftHandAssignmentCannotBeEmptyBraces() { | public void leftHandAssignmentCannotBeEmptyBraces() { | ||
ParseResult<Expression> result = javaParser1_0.parse(EXPRESSION, provider("()=3")); | ParseResult<Expression> result = javaParser.parse(EXPRESSION, provider("()=3")); | ||
assertProblems(result, "(line 1,col 1) Illegal left hand side of an assignment."); | assertProblems(result, "(line 1,col 1) Illegal left hand side of an assignment."); | ||
} | } | ||
|
|
||
@Test | @Test | ||
public void leftHandAssignmentCanBeInBraces() { | public void leftHandAssignmentCanBeInBraces() { | ||
ParseResult<Expression> result = javaParser1_0.parse(EXPRESSION, provider("(i) += (i) += 1")); | ParseResult<Expression> result = javaParser.parse(EXPRESSION, provider("(i) += (i) += 1")); | ||
assertNoProblems(result); | assertNoProblems(result); | ||
} | } | ||
|
|
||
@Test | @Test | ||
public void noInnerClasses() { | public void noInnerClasses() { | ||
ParseResult<CompilationUnit> result = javaParser1_0.parse(COMPILATION_UNIT, provider("class X{class Y{}}")); | ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("class X{class Y{}}")); | ||
assertProblems(result, "(line 1,col 9) inner classes or interfaces are not supported."); | assertProblems(result, "(line 1,col 9) inner classes or interfaces are not supported."); | ||
} | } | ||
|
|
||
@Test | @Test | ||
public void noReflection() { | public void noReflection() { | ||
ParseResult<Expression> result = javaParser1_0.parse(EXPRESSION, provider("Abc.class")); | ParseResult<Expression> result = javaParser.parse(EXPRESSION, provider("Abc.class")); | ||
assertProblems(result, "(line 1,col 1) Reflection is not supported."); | assertProblems(result, "(line 1,col 1) Reflection is not supported."); | ||
} | } | ||
} | } |
Oops, something went wrong.