Search in sources :

Example 1 with MethodCallExprContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext in project javaparser by javaparser.

the class MethodCallExprContextResolutionTest method assertCanSolveGenericMethodCallMustUseProvidedTypeArgs.

private void assertCanSolveGenericMethodCallMustUseProvidedTypeArgs(String callMethodName) {
    MethodCallExpr methodCallExpr = getMethodCallExpr("genericMethodTest", callMethodName);
    CombinedTypeSolver typeSolver = createTypeSolver();
    MethodCallExprContext context = new MethodCallExprContext(methodCallExpr, typeSolver);
    Optional<MethodUsage> ref = context.solveMethodAsUsage(callMethodName, Collections.emptyList(), typeSolver);
    assertTrue(ref.isPresent());
    assertEquals("MethodCalls", ref.get().declaringType().getQualifiedName());
    assertEquals(Collections.singletonList("java.lang.Integer"), ref.get().typeParametersMap().getTypes().stream().map(ty -> ty.asReferenceType().describe()).collect(Collectors.toList()));
}
Also used : MethodCallExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext) MethodUsage(com.github.javaparser.resolution.MethodUsage) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 2 with MethodCallExprContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext in project javaparser by javaparser.

the class MethodCallExprContextResolutionTest method assertCanSolveGenericMethodCallCanInferFromArguments.

private void assertCanSolveGenericMethodCallCanInferFromArguments(String callMethodName) {
    MethodCallExpr methodCallExpr = getMethodCallExpr("genericMethodTest", callMethodName);
    CombinedTypeSolver typeSolver = createTypeSolver();
    MethodCallExprContext context = new MethodCallExprContext(methodCallExpr, typeSolver);
    ResolvedReferenceTypeDeclaration stringType = typeSolver.solveType("java.lang.String");
    List<ResolvedType> argumentsTypes = new ArrayList<>();
    argumentsTypes.add(new ReferenceTypeImpl(stringType, typeSolver));
    Optional<MethodUsage> ref = context.solveMethodAsUsage(callMethodName, argumentsTypes, typeSolver);
    assertTrue(ref.isPresent());
    assertEquals("MethodCalls", ref.get().declaringType().getQualifiedName());
    assertEquals(Collections.singletonList("java.lang.String"), ref.get().typeParametersMap().getTypes().stream().map(ty -> ty.asReferenceType().describe()).collect(Collectors.toList()));
}
Also used : MethodCallExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext) ResolvedReferenceTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) ArrayList(java.util.ArrayList) MethodUsage(com.github.javaparser.resolution.MethodUsage) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 3 with MethodCallExprContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext in project javaparser by javaparser.

the class MethodCallExprContextResolutionTest method solveNestedMethodCallExprContextWithoutScope.

@Test
public void solveNestedMethodCallExprContextWithoutScope() {
    MethodCallExpr methodCallExpr = getMethodCallExpr("bar1", "foo");
    CombinedTypeSolver typeSolver = createTypeSolver();
    Context context = new MethodCallExprContext(methodCallExpr, typeSolver);
    Optional<MethodUsage> ref = context.solveMethodAsUsage("foo", Collections.emptyList(), typeSolver);
    assertTrue(ref.isPresent());
    assertEquals("MethodCalls", ref.get().declaringType().getQualifiedName());
}
Also used : Context(com.github.javaparser.symbolsolver.core.resolution.Context) MethodCallExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext) MethodCallExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext) MethodUsage(com.github.javaparser.resolution.MethodUsage) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)3 MethodUsage (com.github.javaparser.resolution.MethodUsage)3 MethodCallExprContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext)3 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)3 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)1 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)1 Context (com.github.javaparser.symbolsolver.core.resolution.Context)1 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)1 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1