use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class TypeInference method instantiationSetToMethodUsage.
// /
// / Private static methods
// /
private static MethodUsage instantiationSetToMethodUsage(ResolvedMethodDeclaration methodDeclaration, InstantiationSet instantiationSet) {
if (instantiationSet.isEmpty()) {
return new MethodUsage(methodDeclaration);
}
List<ResolvedType> paramTypes = new LinkedList<>();
for (int i = 0; i < methodDeclaration.getNumberOfParams(); i++) {
paramTypes.add(instantiationSet.apply(methodDeclaration.getParam(i).getType()));
}
ResolvedType returnType = instantiationSet.apply(methodDeclaration.getReturnType());
return new MethodUsage(methodDeclaration, paramTypes, returnType);
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class TypeInference method testForApplicabilityByStrictInvocation.
private Optional<ConstraintFormulaSet> testForApplicabilityByStrictInvocation(List<ResolvedType> Fs, List<Expression> es, Substitution theta) {
int n = Fs.size();
int k = es.size();
// ii) Fi is a primitive type but ei is not a standalone expression of a primitive type;
if (k != n) {
return Optional.empty();
}
for (int i = 0; i < n; i++) {
Expression ei = es.get(i);
ResolvedType fi = Fs.get(i);
if (isPertinentToApplicability(ei)) {
if (isStandaloneExpression(ei) && JavaParserFacade.get(typeSolver).getType(ei).isPrimitive() && fi.isReferenceType()) {
return Optional.empty();
}
if (fi.isPrimitive() && (!isStandaloneExpression(ei) || !JavaParserFacade.get(typeSolver).getType(ei).isPrimitive())) {
return Optional.empty();
}
}
}
return Optional.of(constraintSetFromArgumentsSubstitution(Fs, es, theta, k));
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveExistingGenericType.
@Test
public void solveExistingGenericType() {
CompilationUnit cu = parseSample("ClassWithTypeVariables");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
Optional<ResolvedType> a = context.solveGenericType("A", new MemoryTypeSolver());
Optional<ResolvedType> b = context.solveGenericType("B", new MemoryTypeSolver());
Optional<ResolvedType> c = context.solveGenericType("C", new MemoryTypeSolver());
assertEquals(true, a.isPresent());
assertEquals("A", a.get().describe());
assertEquals(true, a.get().isTypeVariable());
assertEquals(true, b.isPresent());
assertEquals("B", b.get().describe());
assertEquals(true, b.get().isTypeVariable());
assertEquals(true, c.isPresent());
assertEquals("C", c.get().describe());
assertEquals(true, c.get().isTypeVariable());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodWithMoreSpecializedParameter.
@Test
public void solveMethodWithMoreSpecializedParameter() {
CompilationUnit cu = parseSample("ClassWithMethods");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
ResolvedType stringType = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver);
SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo4", ImmutableList.of(stringType), false, new ReflectionTypeSolver());
assertEquals(true, ref.isSolved());
assertEquals("A", ref.getCorrespondingDeclaration().declaringType().getName());
assertEquals(1, ref.getCorrespondingDeclaration().getNumberOfParams());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveUnexistingGenericType.
@Test
public void solveUnexistingGenericType() {
CompilationUnit cu = parseSample("ClassWithTypeVariables");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
Optional<ResolvedType> d = context.solveGenericType("D", new MemoryTypeSolver());
assertEquals(false, d.isPresent());
}
Aggregations