Search in sources :

Example 1 with VariableDeclarationExpr

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());
}
Also used : VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) Test(org.junit.Test)

Example 2 with VariableDeclarationExpr

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());
}
Also used : VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) Test(org.junit.Test)

Example 3 with VariableDeclarationExpr

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);
}
Also used : VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) VariableDeclaratorId(com.github.javaparser.ast.body.VariableDeclaratorId) ArrayList(java.util.ArrayList) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator)

Example 4 with VariableDeclarationExpr

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();
}
Also used : VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) Test(org.junit.Test)

Example 5 with VariableDeclarationExpr

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();
}
Also used : VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) Test(org.junit.Test)

Aggregations

VariableDeclarationExpr (com.github.javaparser.ast.expr.VariableDeclarationExpr)38 Test (org.junit.Test)17 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)16 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)12 Expression (com.github.javaparser.ast.expr.Expression)11 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)9 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)8 NameExpr (com.github.javaparser.ast.expr.NameExpr)7 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)7 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)5 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)4 Parameter (com.github.javaparser.ast.body.Parameter)4 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)4 Type (com.github.javaparser.ast.type.Type)4 Node (com.github.javaparser.ast.Node)3 CastExpr (com.github.javaparser.ast.expr.CastExpr)3 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)3 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)3 DrlxParseUtil.toClassOrInterfaceType (org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType)3 ClassExpr (com.github.javaparser.ast.expr.ClassExpr)2