Search in sources :

Example 6 with Expression

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

the class ModifierVisitorAdapter method visit.

@Override
public Node visit(final BinaryExpr n, final A arg) {
    visitComment(n, arg);
    final Expression left = (Expression) n.getLeft().accept(this, arg);
    final Expression right = (Expression) n.getRight().accept(this, arg);
    if (left == null) {
        return right;
    }
    if (right == null) {
        return left;
    }
    n.setLeft(left);
    n.setRight(right);
    return n;
}
Also used : Expression(com.github.javaparser.ast.expr.Expression)

Example 7 with Expression

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

the class ModifierVisitorAdapter method visit.

@Override
public Node visit(final FieldAccessExpr n, final A arg) {
    visitComment(n, arg);
    final Expression scope = (Expression) n.getScope().accept(this, arg);
    if (scope == null) {
        return null;
    }
    n.setScope(scope);
    return n;
}
Also used : Expression(com.github.javaparser.ast.expr.Expression)

Example 8 with Expression

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

the class ModifierVisitorAdapter method visit.

@Override
public Node visit(final ExpressionStmt n, final A arg) {
    visitComment(n, arg);
    final Expression expr = (Expression) n.getExpression().accept(this, arg);
    if (expr == null) {
        return null;
    }
    n.setExpression(expr);
    return n;
}
Also used : Expression(com.github.javaparser.ast.expr.Expression)

Example 9 with Expression

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

the class Issue257 method issue257.

@Test
public void issue257() throws FileNotFoundException {
    String pathToSourceFile = adaptPath("src/test/resources/issue257/A.java.txt");
    CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile));
    Statement statement = cu.getClassByName("A").get().getMethodsByName("run").get(0).getBody().get().getStatement(0);
    ExpressionStmt expressionStmt = (ExpressionStmt) statement;
    Expression expression = expressionStmt.getExpression();
    JavaParserFacade.get(typeSolver).getType(expression);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Expression(com.github.javaparser.ast.expr.Expression) Statement(com.github.javaparser.ast.stmt.Statement) File(java.io.File) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 10 with Expression

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

the class XmlPrinterTest method testWithType.

@Test
public void testWithType() {
    Expression expression = JavaParser.parseExpression("1+1");
    XmlPrinter xmlOutput = new XmlPrinter(true);
    String output = xmlOutput.output(expression);
    assertEquals("<root type='BinaryExpr' operator='PLUS'><left type='IntegerLiteralExpr' value='1'></left><right type='IntegerLiteralExpr' value='1'></right></root>", output);
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) Test(org.junit.Test)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)429 Test (org.junit.Test)166 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)149 NameExpr (com.github.javaparser.ast.expr.NameExpr)135 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)94 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)90 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)84 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)73 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)71 NodeList (com.github.javaparser.ast.NodeList)66 DrlxParser.parseExpression (org.drools.mvel.parser.DrlxParser.parseExpression)61 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)53 CompilationUnit (com.github.javaparser.ast.CompilationUnit)51 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)50 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)49 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)49 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)46 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)44 List (java.util.List)44 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)43