Search in sources :

Example 21 with SimpleName

use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.

the class TreeVisitorTest method parents.

@Test
public void parents() {
    CompilationUnit cu = JavaParser.parse("class X{int x=1;}");
    SimpleName x = cu.getClassByName("X").get().getMember(0).asFieldDeclaration().getVariable(0).getName();
    Node.ParentsVisitor visitor = new Node.ParentsVisitor(x);
    assertEquals("x = 1", visitor.next().toString());
    assertEquals("int x = 1;", visitor.next().toString());
    assertEqualsNoEol("class X {\n" + "\n" + "    int x = 1;\n" + "}", visitor.next().toString());
    assertEqualsNoEol("class X {\n" + "\n" + "    int x = 1;\n" + "}\n", visitor.next().toString());
    assertEquals(false, visitor.hasNext());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) SimpleName(com.github.javaparser.ast.expr.SimpleName) Node(com.github.javaparser.ast.Node) Test(org.junit.Test)

Example 22 with SimpleName

use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.

the class ConstructorDeclarationTransformationsTest method replacingOnlyParameter.

@Test
public void replacingOnlyParameter() throws IOException {
    ConstructorDeclaration cd = consider("public A(float f){}");
    cd.getParameters().set(0, new Parameter(new ArrayType(PrimitiveType.intType()), new SimpleName("foo")));
    assertTransformedToString("public A(int[] foo){}", cd);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) SimpleName(com.github.javaparser.ast.expr.SimpleName) Parameter(com.github.javaparser.ast.body.Parameter) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 23 with SimpleName

use of com.github.javaparser.ast.expr.SimpleName in project javaparser by javaparser.

the class MethodDeclarationTransformationsTest method replacingOnlyParameter.

@Test
public void replacingOnlyParameter() throws IOException {
    MethodDeclaration it = consider("public void foo(float f){}");
    it.getParameters().set(0, new Parameter(new ArrayType(PrimitiveType.intType()), new SimpleName("foo")));
    assertTransformedToString("public void foo(int[] foo){}", it);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) SimpleName(com.github.javaparser.ast.expr.SimpleName) Parameter(com.github.javaparser.ast.body.Parameter) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 24 with SimpleName

use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.

the class CodegenTestUtils method commonEvaluateConstructor.

public static boolean commonEvaluateConstructor(ConstructorDeclaration constructorDeclaration, String generatedClassName, Map<Integer, Expression> superInvocationExpressionsMap, Map<String, Expression> assignExpressionsMap) {
    assertEquals(new SimpleName(generatedClassName), constructorDeclaration.getName());
    final BlockStmt body = constructorDeclaration.getBody();
    return commonEvaluateSuperInvocationExpr(body, superInvocationExpressionsMap) && commonEvaluateAssignExpr(body, assignExpressionsMap);
}
Also used : SimpleName(com.github.javaparser.ast.expr.SimpleName) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt)

Example 25 with SimpleName

use of com.github.javaparser.ast.expr.SimpleName in project drools by kiegroup.

the class CommonCodegenUtils method createArraysAsListExpression.

/**
 * Create an empty <b>Arrays.asList()</b> <code>ExpressionStmt</code>
 * @return
 */
public static ExpressionStmt createArraysAsListExpression() {
    ExpressionStmt toReturn = new ExpressionStmt();
    MethodCallExpr arraysCallExpression = new MethodCallExpr();
    SimpleName arraysName = new SimpleName(Arrays.class.getName());
    arraysCallExpression.setScope(new NameExpr(arraysName));
    arraysCallExpression.setName(new SimpleName("asList"));
    toReturn.setExpression(arraysCallExpression);
    return toReturn;
}
Also used : SimpleName(com.github.javaparser.ast.expr.SimpleName) NameExpr(com.github.javaparser.ast.expr.NameExpr) Arrays(java.util.Arrays) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

SimpleName (com.github.javaparser.ast.expr.SimpleName)34 Test (org.junit.Test)17 Expression (com.github.javaparser.ast.expr.Expression)15 NameExpr (com.github.javaparser.ast.expr.NameExpr)11 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)9 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)9 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 HalfBinaryExpr (org.drools.mvel.parser.ast.expr.HalfBinaryExpr)8 Parameter (com.github.javaparser.ast.body.Parameter)7 NodeList (com.github.javaparser.ast.NodeList)6 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)6 Node (com.github.javaparser.ast.Node)5 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)5 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)5 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)5 HashMap (java.util.HashMap)5 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)5 CompilationUnit (com.github.javaparser.ast.CompilationUnit)4