use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class ModifierVisitorAdapter method visit.
@Override
public Node visit(final DoStmt n, final A arg) {
visitComment(n, arg);
final Statement body = (Statement) n.getBody().accept(this, arg);
if (body == null) {
return null;
}
n.setBody(body);
final Expression condition = (Expression) n.getCondition().accept(this, arg);
if (condition == null) {
return null;
}
n.setCondition(condition);
return n;
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class DumpVisitor method visit.
@Override
public void visit(final BlockStmt n, final Object arg) {
printOrphanCommentsBeforeThisChildNode(n);
printJavaComment(n.getComment(), arg);
printer.printLn("{");
if (n.getStmts() != null) {
printer.indent();
for (final Statement s : n.getStmts()) {
s.accept(this, arg);
printer.printLn();
}
printer.unindent();
}
printOrphanCommentsEnding(n);
printer.print("}");
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class DumpVisitor method visit.
@Override
public void visit(final SwitchEntryStmt n, final Object arg) {
printJavaComment(n.getComment(), arg);
if (n.getLabel() != null) {
printer.print("case ");
n.getLabel().accept(this, arg);
printer.print(":");
} else {
printer.print("default:");
}
printer.printLn();
printer.indent();
if (n.getStmts() != null) {
for (final Statement s : n.getStmts()) {
s.accept(this, arg);
printer.printLn();
}
}
printer.unindent();
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class JavaParser method parseStatement.
/**
* Parses the Java statement contained in a {@link String} and returns a
* {@link Statement} that represents it.
*
* @param statement
* {@link String} containing Java statement code
* @return Statement representing the Java statement
* @throws ParseException
* if the source code has parser errors
*/
public static Statement parseStatement(final String statement) {
StringReader sr = new StringReader(statement);
Statement stmt = new ASTParser(sr).Statement();
sr.close();
return stmt;
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class SwitchEntryContext method solveSymbol.
@Override
public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
SwitchStmt switchStmt = (SwitchStmt) requireParentNode(wrappedNode);
ResolvedType type = JavaParserFacade.get(typeSolver).getType(switchStmt.getSelector());
if (type.isReferenceType() && type.asReferenceType().getTypeDeclaration().isEnum()) {
if (type instanceof ReferenceTypeImpl) {
ReferenceTypeImpl typeUsageOfTypeDeclaration = (ReferenceTypeImpl) type;
if (typeUsageOfTypeDeclaration.getTypeDeclaration().hasField(name)) {
return SymbolReference.solved(typeUsageOfTypeDeclaration.getTypeDeclaration().getField(name));
}
} else {
throw new UnsupportedOperationException();
}
}
// look for declaration in other switch statements
for (SwitchEntryStmt seStmt : switchStmt.getEntries()) {
if (!seStmt.equals(wrappedNode)) {
for (Statement stmt : seStmt.getStatements()) {
SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(stmt, typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> symbolReference = solveWith(symbolDeclarator, name);
if (symbolReference.isSolved()) {
return symbolReference;
}
}
}
}
return getParent().solveSymbol(name, typeSolver);
}
Aggregations