use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class InferenceContextTest method placingASingleVariableInside.
@Test
public void placingASingleVariableInside() {
ResolvedType result = new InferenceContext(MyObjectProvider.INSTANCE).addPair(listOfE, listOfString);
assertEquals(listOf(new InferenceVariableType(0, MyObjectProvider.INSTANCE)), result);
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class Issue241 method testSolveStaticallyImportedMemberType.
@Test
public void testSolveStaticallyImportedMemberType() {
File src = adaptPath(new File("src/test/resources"));
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(src));
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
CompilationUnit cu = parseSample("Issue241");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "Main");
VariableDeclarator v = Navigator.demandVariableDeclaration(cls, "foo").get();
Type t = v.getType();
ResolvedType t2 = javaParserFacade.convert(t, t);
String typeName = t2.asReferenceType().getQualifiedName();
assertEquals("issue241.TypeWithMemberType.MemberInterface", typeName);
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class Issue347 method resolvingReferenceToEnumDeclarationInSameFile.
@Test
public void resolvingReferenceToEnumDeclarationInSameFile() {
String code = "package foo.bar;\nenum Foo {\n" + " FOO_A, FOO_B\n" + "}\n" + "\n" + "class UsingFoo {\n" + " Foo myFooField;\n" + "}";
CompilationUnit cu = JavaParser.parse(code);
FieldDeclaration fieldDeclaration = Navigator.findNodeOfGivenClass(cu, FieldDeclaration.class);
ResolvedType fieldType = javaParserFacade.getType(fieldDeclaration);
assertEquals(true, fieldType.isReferenceType());
assertEquals(true, fieldType.asReferenceType().getTypeDeclaration().isEnum());
assertEquals("foo.bar.Foo", fieldType.asReferenceType().getQualifiedName());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ExpressionCompatibleWithType method replaceTypeVariablesWithInferenceVariables.
private MethodType replaceTypeVariablesWithInferenceVariables(MethodType methodType) {
// Find all type variable
Map<ResolvedTypeVariable, InferenceVariable> correspondences = new HashMap<>();
List<ResolvedType> newFormalArgumentTypes = new LinkedList<>();
for (ResolvedType formalArg : methodType.getFormalArgumentTypes()) {
newFormalArgumentTypes.add(replaceTypeVariablesWithInferenceVariables(formalArg, correspondences));
}
ResolvedType newReturnType = replaceTypeVariablesWithInferenceVariables(methodType.getReturnType(), correspondences);
return new MethodType(methodType.getTypeParameters(), newFormalArgumentTypes, newReturnType, methodType.getExceptionTypes());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class TypeCompatibleWithType method reduce.
@Override
public ReductionResult reduce(BoundSet currentBoundSet) {
if (isProperType(s) && isProperType(t)) {
if (isCompatibleInALooseInvocationContext(s, t)) {
return ReductionResult.trueResult();
} else {
return ReductionResult.falseResult();
}
}
if (s.isPrimitive()) {
ReflectionTypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType sFirst = new ReferenceTypeImpl(typeSolver.solveType(s.asPrimitive().getBoxTypeQName()), typeSolver);
return ReductionResult.oneConstraint(new TypeCompatibleWithType(typeSolver, sFirst, t));
}
if (t.isPrimitive()) {
ReflectionTypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType tFirst = new ReferenceTypeImpl(typeSolver.solveType(t.asPrimitive().getBoxTypeQName()), typeSolver);
return ReductionResult.oneConstraint(new TypeSameAsType(s, tFirst));
}
if (t.isReferenceType() && !t.asReferenceType().getTypeDeclaration().getTypeParameters().isEmpty()) {
// FIXME I really cannot understand what the specification means...
// there exists a type of the form G<...> that is a supertype of S?
boolean condition1 = t.isAssignableBy(s);
// the raw type G is a supertype of S
ResolvedType G = t.asReferenceType().toRawType();
boolean condition2 = G.isAssignableBy(s);
if (!condition1 && condition2) {
return ReductionResult.trueResult();
}
// throw new UnsupportedOperationException();
}
if (t.isArray()) {
throw new UnsupportedOperationException();
}
return ReductionResult.empty().withConstraint(new TypeSubtypeOfType(typeSolver, s, t));
}
Aggregations