Skip to content

Commit

Permalink
Generified Type Variable resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann Beleites committed Dec 7, 2018
1 parent 62686cf commit 5000b8c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 57 deletions.
Expand Up @@ -186,7 +186,15 @@ default Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType>
SymbolReference<ResolvedMethodDeclaration> methodSolved = solveMethod(name, argumentsTypes, false);
if (methodSolved.isSolved()) {
ResolvedMethodDeclaration methodDeclaration = methodSolved.getCorrespondingDeclaration();
MethodUsage methodUsage = ContextHelper.resolveTypeVariables(this, methodDeclaration, argumentsTypes);//methodDeclaration.resolveTypeVariables(this, argumentsTypes);

MethodUsage methodUsage;
if (methodDeclaration instanceof TypeVariableResolutionCapability) {
methodUsage = ((TypeVariableResolutionCapability) methodDeclaration)
.resolveTypeVariables(this, argumentsTypes);
} else {
throw new UnsupportedOperationException();
}

return Optional.of(methodUsage);
} else {
return Optional.empty();
Expand Down

This file was deleted.

@@ -0,0 +1,10 @@
package com.github.javaparser.symbolsolver.core.resolution;

import com.github.javaparser.resolution.MethodUsage;
import com.github.javaparser.resolution.types.ResolvedType;

import java.util.List;

public interface TypeVariableResolutionCapability {
MethodUsage resolveTypeVariables(Context context, List<ResolvedType> parameterTypes);
}
Expand Up @@ -31,6 +31,7 @@
import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap;
import com.github.javaparser.symbolsolver.core.resolution.Context;
import com.github.javaparser.symbolsolver.core.resolution.MethodUsageResolutionCapability;
import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability;
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory;
import com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration;
Expand Down Expand Up @@ -258,7 +259,7 @@ public List<ResolvedEnumConstantDeclaration> getEnumConstants() {
}

// Needed by ContextHelper
public static class ValuesMethod implements ResolvedMethodDeclaration {
public static class ValuesMethod implements ResolvedMethodDeclaration, TypeVariableResolutionCapability {

private JavaParserEnumDeclaration enumDeclaration;
private TypeSolver typeSolver;
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.core.resolution.Context;
import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability;
import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic;
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory;
Expand All @@ -41,7 +42,7 @@
/**
* @author Federico Tomassetti
*/
public class JavaParserMethodDeclaration implements ResolvedMethodDeclaration {
public class JavaParserMethodDeclaration implements ResolvedMethodDeclaration, TypeVariableResolutionCapability {

private com.github.javaparser.ast.body.MethodDeclaration wrappedNode;
private TypeSolver typeSolver;
Expand Down
Expand Up @@ -26,9 +26,9 @@
import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.core.resolution.Context;
import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability;
import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic;
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory;
import javassist.CtMethod;
import javassist.NotFoundException;
import javassist.bytecode.BadBytecode;
Expand All @@ -44,7 +44,7 @@
/**
* @author Federico Tomassetti
*/
public class JavassistMethodDeclaration implements ResolvedMethodDeclaration {
public class JavassistMethodDeclaration implements ResolvedMethodDeclaration, TypeVariableResolutionCapability {
private CtMethod ctMethod;
private TypeSolver typeSolver;

Expand Down
Expand Up @@ -25,6 +25,7 @@
import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.core.resolution.Context;
import com.github.javaparser.symbolsolver.core.resolution.TypeVariableResolutionCapability;
import com.github.javaparser.symbolsolver.declarations.common.MethodDeclarationCommonLogic;
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;

Expand All @@ -38,7 +39,7 @@
/**
* @author Federico Tomassetti
*/
public class ReflectionMethodDeclaration implements ResolvedMethodDeclaration {
public class ReflectionMethodDeclaration implements ResolvedMethodDeclaration, TypeVariableResolutionCapability {

private Method method;
private TypeSolver typeSolver;
Expand Down

0 comments on commit 5000b8c

Please sign in to comment.