Search in sources :

Example 11 with IntegerLiteralExpr

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

Example 12 with IntegerLiteralExpr

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

Example 13 with IntegerLiteralExpr

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

Example 14 with IntegerLiteralExpr

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);
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 15 with IntegerLiteralExpr

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

Aggregations

IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)16 Test (org.junit.Test)14 Expression (com.github.javaparser.ast.expr.Expression)9 JavaParser.parseExpression (com.github.javaparser.JavaParser.parseExpression)7 AbstractLexicalPreservingTest (com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)4 ArrayCreationLevel (com.github.javaparser.ast.ArrayCreationLevel)2 CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 Node (com.github.javaparser.ast.Node)2 AnnotationMemberDeclaration (com.github.javaparser.ast.body.AnnotationMemberDeclaration)2 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 SimpleName (com.github.javaparser.ast.expr.SimpleName)2 JavaParser.parse (com.github.javaparser.JavaParser.parse)1 JavaParser.parseClassOrInterfaceType (com.github.javaparser.JavaParser.parseClassOrInterfaceType)1 JavaParser.parseName (com.github.javaparser.JavaParser.parseName)1 NodeList (com.github.javaparser.ast.NodeList)1 BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)1 EnumConstantDeclaration (com.github.javaparser.ast.body.EnumConstantDeclaration)1 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1