Search in sources :

Example 11 with SymbolDeclarator

use of com.github.javaparser.symbolsolver.resolution.SymbolDeclarator 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

SymbolDeclarator (com.github.javaparser.symbolsolver.resolution.SymbolDeclarator)11 Parameter (com.github.javaparser.ast.body.Parameter)4 NodeWithStatements (com.github.javaparser.ast.nodeTypes.NodeWithStatements)4 Value (com.github.javaparser.symbolsolver.model.resolution.Value)4 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)2 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)2 ResolvedValueDeclaration (com.github.javaparser.resolution.declarations.ResolvedValueDeclaration)2 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)2 JavaParserTypeParameter (com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter)2 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)2 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 IfStmt (com.github.javaparser.ast.stmt.IfStmt)1 Statement (com.github.javaparser.ast.stmt.Statement)1 SwitchEntryStmt (com.github.javaparser.ast.stmt.SwitchEntryStmt)1 SwitchStmt (com.github.javaparser.ast.stmt.SwitchStmt)1 MethodUsage (com.github.javaparser.resolution.MethodUsage)1 ResolvedLambdaConstraintType (com.github.javaparser.resolution.types.ResolvedLambdaConstraintType)1 Context (com.github.javaparser.symbolsolver.core.resolution.Context)1 InferenceContext (com.github.javaparser.symbolsolver.logic.InferenceContext)1