Search in sources :

Example 1 with SwitchEntryStmt

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);
        }
    }
}
Also used : SwitchEntryStmt(com.github.javaparser.ast.stmt.SwitchEntryStmt)

Example 2 with SwitchEntryStmt

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);
}
Also used : SwitchEntryStmt(com.github.javaparser.ast.stmt.SwitchEntryStmt) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt)

Example 3 with SwitchEntryStmt

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("}");
}
Also used : SwitchEntryStmt(com.github.javaparser.ast.stmt.SwitchEntryStmt)

Example 4 with SwitchEntryStmt

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);
}
Also used : SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) SymbolDeclarator(com.github.javaparser.symbolsolver.resolution.SymbolDeclarator) Statement(com.github.javaparser.ast.stmt.Statement) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) SwitchEntryStmt(com.github.javaparser.ast.stmt.SwitchEntryStmt) ResolvedType(com.github.javaparser.resolution.types.ResolvedType)

Aggregations

SwitchEntryStmt (com.github.javaparser.ast.stmt.SwitchEntryStmt)4 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)1 Statement (com.github.javaparser.ast.stmt.Statement)1 SwitchStmt (com.github.javaparser.ast.stmt.SwitchStmt)1 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)1 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)1 SymbolDeclarator (com.github.javaparser.symbolsolver.resolution.SymbolDeclarator)1