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