use of com.github.javaparser.ast.expr.VariableDeclarationExpr in project javaparser by javaparser.
the class PrettyPrintVisitorTest method getMaximumCommonTypeWithAnnotations.
@Test
public void getMaximumCommonTypeWithAnnotations() {
VariableDeclarationExpr vde1 = JavaParser.parseVariableDeclarationExpr("int a @Foo [], b[]");
assertEquals("int", vde1.getMaximumCommonType().get().toString());
VariableDeclarationExpr vde2 = JavaParser.parseVariableDeclarationExpr("int[]@Foo [] a[], b[]");
assertEquals("int[] @Foo [][]", vde2.getMaximumCommonType().get().toString());
}
use of com.github.javaparser.ast.expr.VariableDeclarationExpr in project javaparser by javaparser.
the class PrettyPrintVisitorTest method getMaximumCommonTypeWithoutAnnotations.
@Test
public void getMaximumCommonTypeWithoutAnnotations() {
VariableDeclarationExpr vde1 = JavaParser.parseVariableDeclarationExpr("int a[], b[]");
assertEquals("int[]", vde1.getMaximumCommonType().get().toString());
VariableDeclarationExpr vde2 = JavaParser.parseVariableDeclarationExpr("int[][] a[], b[]");
assertEquals("int[][][]", vde2.getMaximumCommonType().get().toString());
VariableDeclarationExpr vde3 = JavaParser.parseVariableDeclarationExpr("int[][] a, b[]");
assertEquals("int[][]", vde3.getMaximumCommonType().get().toString());
}
use of com.github.javaparser.ast.expr.VariableDeclarationExpr in project javaparser by javaparser.
the class ASTHelper method createVariableDeclarationExpr.
/**
* Creates a {@link VariableDeclarationExpr}.
*
* @param type
* type
* @param name
* name
* @return instance of {@link VariableDeclarationExpr}
*/
public static VariableDeclarationExpr createVariableDeclarationExpr(Type type, String name) {
List<VariableDeclarator> vars = new ArrayList<VariableDeclarator>();
vars.add(new VariableDeclarator(new VariableDeclaratorId(name)));
return new VariableDeclarationExpr(type, vars);
}
use of com.github.javaparser.ast.expr.VariableDeclarationExpr in project javaparser by javaparser.
the class NodeWithVariablesTest method getCommonTypeFailsOnDodgySetterUsage.
@Test(expected = AssertionError.class)
public void getCommonTypeFailsOnDodgySetterUsage() {
VariableDeclarationExpr declaration = parseVariableDeclarationExpr("int a,b");
declaration.getVariable(1).setType(String.class);
declaration.getCommonType();
}
use of com.github.javaparser.ast.expr.VariableDeclarationExpr in project javaparser by javaparser.
the class NodeWithVariablesTest method getCommonTypeFailsOnInvalidEmptyVariableList.
@Test(expected = AssertionError.class)
public void getCommonTypeFailsOnInvalidEmptyVariableList() {
VariableDeclarationExpr declaration = parseVariableDeclarationExpr("int a");
declaration.getVariables().clear();
declaration.getCommonType();
}
Aggregations