Search in sources :

Example 1 with SymbolDeclarator

use of com.github.javaparser.symbolsolver.resolution.SymbolDeclarator in project javaparser by javaparser.

the class AbstractMethodLikeDeclarationContext method solveSymbol.

public final SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
    for (Parameter parameter : wrappedNode.getParameters()) {
        SymbolDeclarator sb = JavaParserFactory.getSymbolDeclarator(parameter, typeSolver);
        SymbolReference<? extends ResolvedValueDeclaration> symbolReference = AbstractJavaParserContext.solveWith(sb, name);
        if (symbolReference.isSolved()) {
            return symbolReference;
        }
    }
    // if nothing is found we should ask the parent context
    return getParent().solveSymbol(name, typeSolver);
}
Also used : SymbolDeclarator(com.github.javaparser.symbolsolver.resolution.SymbolDeclarator) Parameter(com.github.javaparser.ast.body.Parameter) JavaParserTypeParameter(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter)

Example 2 with SymbolDeclarator

use of com.github.javaparser.symbolsolver.resolution.SymbolDeclarator in project javaparser by javaparser.

the class CatchClauseContext method solveSymbol.

public final SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
    SymbolDeclarator sb = JavaParserFactory.getSymbolDeclarator(wrappedNode.getParameter(), typeSolver);
    SymbolReference<? extends ResolvedValueDeclaration> symbolReference = AbstractJavaParserContext.solveWith(sb, name);
    if (symbolReference.isSolved()) {
        return symbolReference;
    }
    // if nothing is found we should ask the parent context
    return getParent().solveSymbol(name, typeSolver);
}
Also used : SymbolDeclarator(com.github.javaparser.symbolsolver.resolution.SymbolDeclarator)

Example 3 with SymbolDeclarator

use of com.github.javaparser.symbolsolver.resolution.SymbolDeclarator in project javaparser by javaparser.

the class StatementContext method solveInBlockAsValue.

public static Optional<Value> solveInBlockAsValue(String name, TypeSolver typeSolver, Statement stmt) {
    if (!(requireParentNode(stmt) instanceof NodeWithStatements)) {
        throw new IllegalArgumentException();
    }
    NodeWithStatements<?> blockStmt = (NodeWithStatements<?>) requireParentNode(stmt);
    int position = -1;
    for (int i = 0; i < blockStmt.getStatements().size(); i++) {
        if (blockStmt.getStatements().get(i).equals(stmt)) {
            position = i;
        }
    }
    if (position == -1) {
        throw new RuntimeException();
    }
    for (int i = position - 1; i >= 0; i--) {
        SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(blockStmt.getStatements().get(i), typeSolver);
        SymbolReference<? extends ResolvedValueDeclaration> symbolReference = solveWith(symbolDeclarator, name);
        if (symbolReference.isSolved()) {
            return Optional.of(Value.from(symbolReference.getCorrespondingDeclaration()));
        }
    }
    // if nothing is found we should ask the parent context
    return JavaParserFactory.getContext(requireParentNode(stmt), typeSolver).solveSymbolAsValue(name, typeSolver);
}
Also used : SymbolDeclarator(com.github.javaparser.symbolsolver.resolution.SymbolDeclarator) NodeWithStatements(com.github.javaparser.ast.nodeTypes.NodeWithStatements)

Example 4 with SymbolDeclarator

use of com.github.javaparser.symbolsolver.resolution.SymbolDeclarator in project javaparser by javaparser.

the class AbstractMethodLikeDeclarationContext method solveSymbolAsValue.

@Override
public final Optional<Value> solveSymbolAsValue(String name, TypeSolver typeSolver) {
    for (Parameter parameter : wrappedNode.getParameters()) {
        SymbolDeclarator sb = JavaParserFactory.getSymbolDeclarator(parameter, typeSolver);
        Optional<Value> symbolReference = solveWithAsValue(sb, name, typeSolver);
        if (symbolReference.isPresent()) {
            // Perform parameter type substitution as needed
            return symbolReference;
        }
    }
    // if nothing is found we should ask the parent context
    return getParent().solveSymbolAsValue(name, typeSolver);
}
Also used : SymbolDeclarator(com.github.javaparser.symbolsolver.resolution.SymbolDeclarator) Value(com.github.javaparser.symbolsolver.model.resolution.Value) Parameter(com.github.javaparser.ast.body.Parameter) JavaParserTypeParameter(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter)

Example 5 with SymbolDeclarator

use of com.github.javaparser.symbolsolver.resolution.SymbolDeclarator in project javaparser by javaparser.

the class CatchClauseContext method solveSymbolAsValue.

@Override
public final Optional<Value> solveSymbolAsValue(String name, TypeSolver typeSolver) {
    SymbolDeclarator sb = JavaParserFactory.getSymbolDeclarator(wrappedNode.getParameter(), typeSolver);
    Optional<Value> symbolReference = solveWithAsValue(sb, name, typeSolver);
    if (symbolReference.isPresent()) {
        // Perform parameter type substitution as needed
        return symbolReference;
    }
    // if nothing is found we should ask the parent context
    return getParent().solveSymbolAsValue(name, typeSolver);
}
Also used : SymbolDeclarator(com.github.javaparser.symbolsolver.resolution.SymbolDeclarator) Value(com.github.javaparser.symbolsolver.model.resolution.Value)

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