use of com.github.javaparser.ast.expr.IntegerLiteralExpr in project javaparser by javaparser.
the class NodeTest method conditionalTypedFindFirst.
@Test
public void conditionalTypedFindFirst() {
Expression e = parseExpression("1+2+3");
Optional<IntegerLiteralExpr> ints = e.findFirst(IntegerLiteralExpr.class, n -> n.asInt() > 1);
assertEquals("Optional[2]", ints.toString());
}
use of com.github.javaparser.ast.expr.IntegerLiteralExpr in project javaparser by javaparser.
the class ModifierVisitorTest method binaryExprReturnsLeftExpressionWhenRightSideIsRemoved.
@Test
public void binaryExprReturnsLeftExpressionWhenRightSideIsRemoved() {
Expression expression = parseExpression("1+2");
Visitable result = expression.accept(new ModifierVisitor<Void>() {
public Visitable visit(IntegerLiteralExpr integerLiteralExpr, Void arg) {
if (integerLiteralExpr.getValue().equals("1")) {
return null;
}
return integerLiteralExpr;
}
}, null);
assertEquals("2", result.toString());
}
use of com.github.javaparser.ast.expr.IntegerLiteralExpr in project javaparser by javaparser.
the class TreeVisitorTest method issue743ConcurrentModificationProblem.
@Test
public void issue743ConcurrentModificationProblem() {
Expression expression = JavaParser.parseExpression("new int[]{1,2,3,4}");
StringBuilder result = new StringBuilder();
TreeVisitor visitor = new TreeVisitor() {
@Override
public void process(Node node) {
if (node instanceof IntegerLiteralExpr) {
node.getParentNode().ifPresent(parent -> ((ArrayInitializerExpr) parent).getValues().add(new IntegerLiteralExpr("1")));
}
result.append("<").append(node).append("> ");
}
};
visitor.visitPreOrder(expression);
System.out.println(result);
}
use of com.github.javaparser.ast.expr.IntegerLiteralExpr in project javaparser by javaparser.
the class AnnotationMemberDeclarationTransformationsTest method addingDefaultValue.
// Default value
@Test
public void addingDefaultValue() {
AnnotationMemberDeclaration md = consider("int foo();");
md.setDefaultValue(new IntegerLiteralExpr("10"));
assertTransformedToString("int foo() default 10;", md);
}
use of com.github.javaparser.ast.expr.IntegerLiteralExpr in project javaparser by javaparser.
the class ArrayCreationLevelTransformationsTest method addingDimension.
// Dimension
@Test
public void addingDimension() throws IOException {
ArrayCreationLevel it = consider("[]");
it.setDimension(new IntegerLiteralExpr("10"));
assertTransformedToString("[10]", it);
}
Aggregations