Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 2216: wrong order of annotation and type args
- Loading branch information
Showing
3 changed files
with
24 additions
and
6 deletions.
There are no files selected for viewing
11 changes: 10 additions & 1 deletion
11
...-core-testing/src/test/java/com/github/javaparser/ast/body/AnnotationDeclarationTest.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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
package com.github.javaparser.ast.body; | ||
|
||
import com.github.javaparser.ast.stmt.Statement; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static com.github.javaparser.utils.TestParser.parseStatement; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class AnnotationDeclarationTest { | ||
@Test | ||
void cantAddField() { | ||
assertThrows(IllegalStateException.class, () -> new AnnotationDeclaration().addField(Object.class, "oo")); | ||
} | ||
|
||
@Test | ||
void issue2216() { | ||
Statement statement = parseStatement("TT tt = new <String> @TypeAnno @TA2 TT( \"S\" );"); | ||
assertEquals("TT tt = new <String> @TypeAnno @TA2 TT(\"S\");", statement.toString()); | ||
} | ||
} |
17 changes: 13 additions & 4 deletions
17
javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestParser.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 |
---|---|---|
@@ -1,31 +1,40 @@ | ||
package com.github.javaparser.utils; | ||
|
||
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.body.BodyDeclaration; | ||
import com.github.javaparser.ast.expr.Expression; | ||
import com.github.javaparser.ast.stmt.Statement; | ||
|
||
import static com.github.javaparser.ParserConfiguration.LanguageLevel.BLEEDING_EDGE; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class TestParser { | ||
|
||
private static final JavaParser parser = new JavaParser(new ParserConfiguration().setLanguageLevel(BLEEDING_EDGE)); | ||
|
||
public static CompilationUnit parseCompilationUnit(String stmt) { | ||
return parser.parse(stmt).getResult().get(); | ||
return unpack(parser.parse(stmt)); | ||
} | ||
|
||
public static Statement parseStatement(String stmt) { | ||
return parser.parseStatement(stmt).getResult().get(); | ||
return unpack(parser.parseStatement(stmt)); | ||
} | ||
|
||
private static <T> T unpack(ParseResult<T> result) { | ||
if (!result.isSuccessful()) { | ||
fail(result.getProblems().toString()); | ||
} | ||
return result.getResult().get(); | ||
} | ||
|
||
public static Expression parseExpression(String expr) { | ||
return parser.parseExpression(expr).getResult().get(); | ||
return unpack(parser.parseExpression(expr)); | ||
} | ||
|
||
public static BodyDeclaration<?> parseBodyDeclaration(String bd) { | ||
return parser.parseBodyDeclaration(bd).getResult().get(); | ||
return unpack(parser.parseBodyDeclaration(bd)); | ||
} | ||
} |
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