use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class Issue116 method arrayTypeIsNotPartOfTheTree.
@Test
public void arrayTypeIsNotPartOfTheTree() {
CompilationUnit cu = parseSample("Issue116");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
com.github.javaparser.ast.type.Type typeNode = methodDeclaration.getParameters().get(0).getType();
ResolvedType type = javaParserFacade.convert(typeNode, typeNode);
assertEquals("java.lang.String[]", type.describe());
ExpressionStmt expressionStmt = (ExpressionStmt) methodDeclaration.getBody().get().getStatements().get(0);
Expression argRef = expressionStmt.getExpression();
assertEquals("java.lang.String[]", javaParserFacade.getType(argRef).describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class Issue18 method typeDeclarationSuperClassImplicitlyIncludeObject.
@Test
public void typeDeclarationSuperClassImplicitlyIncludeObject() {
CompilationUnit cu = parseSample("Issue18");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Foo");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "bar");
ExpressionStmt expr = (ExpressionStmt) methodDeclaration.getBody().get().getStatements().get(1);
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
ResolvedType type = javaParserFacade.getType(expr.getExpression());
assertEquals("java.lang.Object", type.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class TypeInference method testForApplicabilityByVariableArityInvocation.
private Optional<ConstraintFormulaSet> testForApplicabilityByVariableArityInvocation(List<ResolvedType> Fs, List<Expression> es, Substitution theta) {
int k = es.size();
// Let F'1, ..., F'k be the first k variable arity parameter types of m (§15.12.2.4). C includes,
// for all i (1 ≤ i ≤ k) where ei is pertinent to applicability, ‹ei → F'i θ›.
List<ResolvedType> FsFirst = new LinkedList<>();
for (int i = 0; i < k; i++) {
ResolvedType FFirstI = i < Fs.size() ? Fs.get(i) : Fs.get(Fs.size() - 1);
FsFirst.add(FFirstI);
}
return Optional.of(constraintSetFromArgumentsSubstitution(FsFirst, es, theta, k));
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class TypeInference method boundSetup.
// /
// / Private instance methods
// /
/**
* When inference begins, a bound set is typically generated from a list of type parameter declarations P1, ..., Pp
* and associated inference variables α1, ..., αp
*
* @param typeParameterDeclarations
* @param inferenceVariables
* @return
*/
private BoundSet boundSetup(List<ResolvedTypeParameterDeclaration> typeParameterDeclarations, List<InferenceVariable> inferenceVariables) {
if (typeParameterDeclarations.size() != inferenceVariables.size()) {
throw new IllegalArgumentException();
}
// When inference begins, a bound set is typically generated from a list of
// type parameter declarations P1, ..., Pp and associated inference variables α1, ..., αp.
// Such a bound set is constructed as follows. For each l (1 ≤ l ≤ p):
BoundSet boundSet = BoundSet.empty();
for (int l = 0; l < typeParameterDeclarations.size(); l++) {
ResolvedTypeParameterDeclaration Pl = typeParameterDeclarations.get(l);
InferenceVariable alphaL = inferenceVariables.get(l);
if (Pl.getBounds().isEmpty()) {
boundSet = boundSet.withBound(new SubtypeOfBound(alphaL, object));
} else {
for (ResolvedTypeParameterDeclaration.Bound bound : Pl.getBounds()) {
ResolvedType T = bound.getType();
Substitution substitution = Substitution.empty();
for (int j = 0; j < typeParameterDeclarations.size(); j++) {
substitution = substitution.withPair(typeParameterDeclarations.get(j), inferenceVariables.get(j));
}
ResolvedType TWithSubstitutions = substitution.apply(T);
boundSet = boundSet.withBound(new SubtypeOfBound(alphaL, TWithSubstitutions));
if (boundSet.getProperUpperBoundsFor(alphaL).isEmpty()) {
boundSet = boundSet.withBound(new SubtypeOfBound(alphaL, object));
}
}
}
}
return boundSet;
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class TypeInference method constraintSetFromArgumentsSubstitution.
private ConstraintFormulaSet constraintSetFromArgumentsSubstitution(List<ResolvedType> Fs, List<Expression> es, Substitution theta, int k) {
ConstraintFormulaSet constraintFormulaSet = ConstraintFormulaSet.empty();
for (int i = 0; i < k; i++) {
Expression ei = es.get(i);
ResolvedType fi = Fs.get(i);
ResolvedType fiTheta = typeWithSubstitution(fi, theta);
constraintFormulaSet = constraintFormulaSet.withConstraint(new ExpressionCompatibleWithType(typeSolver, ei, fiTheta));
}
return constraintFormulaSet;
}
Aggregations