Search in sources :

Example 6 with IntegerLiteralExpr

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

the class ModifierVisitorTest method binaryExprReturnsRightExpressionWhenLeftSideIsRemoved.

@Test
public void binaryExprReturnsRightExpressionWhenLeftSideIsRemoved() {
    final Expression expression = parseExpression("1+2");
    final Visitable result = expression.accept(new ModifierVisitor<Void>() {

        public Visitable visit(IntegerLiteralExpr integerLiteralExpr, Void arg) {
            if (integerLiteralExpr.getValue().equals("2")) {
                return null;
            }
            return integerLiteralExpr;
        }
    }, null);
    assertEquals("1", 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 7 with IntegerLiteralExpr

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

the class AnnotationMemberDeclarationTest method removeDefaultValueWhenDefaultValueIsPresent.

@Test
public void removeDefaultValueWhenDefaultValueIsPresent() {
    AnnotationMemberDeclaration decl = new AnnotationMemberDeclaration();
    SimpleName name = new SimpleName("foo");
    decl.setName(name);
    Expression defaultValue = new IntegerLiteralExpr("2");
    decl.setDefaultValue(defaultValue);
    decl.removeDefaultValue();
    assertFalse(defaultValue.getParentNode().isPresent());
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) Expression(com.github.javaparser.ast.expr.Expression) SimpleName(com.github.javaparser.ast.expr.SimpleName) Test(org.junit.Test)

Example 8 with IntegerLiteralExpr

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

the class NodeTest method conditionalFindAll.

@Test
public void conditionalFindAll() {
    Expression e = parseExpression("1+2+3");
    List<IntegerLiteralExpr> ints = e.findAll(IntegerLiteralExpr.class, n -> n.asInt() > 1);
    assertEquals("[2, 3]", 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 9 with IntegerLiteralExpr

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

the class NodeTest method typeOnlyFindFirst.

@Test
public void typeOnlyFindFirst() {
    Expression e = parseExpression("1+2+3");
    Optional<IntegerLiteralExpr> ints = e.findFirst(IntegerLiteralExpr.class);
    assertEquals("Optional[1]", 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 10 with IntegerLiteralExpr

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

the class NodeTest method typeOnlyFindAll.

@Test
public void typeOnlyFindAll() {
    Expression e = parseExpression("1+2+3");
    List<IntegerLiteralExpr> ints = e.findAll(IntegerLiteralExpr.class);
    assertEquals("[1, 2, 3]", 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)

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