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());
}
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);
}
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);
}
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);
}
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;
}
Aggregations