use of com.github.javaparser.ast.stmt.SwitchEntryStmt in project javaparser by javaparser.
the class VoidVisitorAdapter method visit.
@Override
public void visit(final SwitchStmt n, final A arg) {
visitComment(n.getComment(), arg);
n.getSelector().accept(this, arg);
if (n.getEntries() != null) {
for (final SwitchEntryStmt e : n.getEntries()) {
e.accept(this, arg);
}
}
}
use of com.github.javaparser.ast.stmt.SwitchEntryStmt in project javaparser by javaparser.
the class TokenKindGenerator method generateValueOfEntry.
private void generateValueOfEntry(SwitchStmt valueOfSwitch, String name, IntegerLiteralExpr kind) {
final SwitchEntryStmt entry = new SwitchEntryStmt(kind, new NodeList<>(new ReturnStmt(name)));
valueOfSwitch.getEntries().addFirst(entry);
}
use of com.github.javaparser.ast.stmt.SwitchEntryStmt in project javaparser by javaparser.
the class DumpVisitor method visit.
@Override
public void visit(final SwitchStmt n, final Object arg) {
printJavaComment(n.getComment(), arg);
printer.print("switch(");
n.getSelector().accept(this, arg);
printer.printLn(") {");
if (n.getEntries() != null) {
printer.indent();
for (final SwitchEntryStmt e : n.getEntries()) {
e.accept(this, arg);
}
printer.unindent();
}
printer.print("}");
}
use of com.github.javaparser.ast.stmt.SwitchEntryStmt 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