use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class ReflectionMethodDeclarationTest method testGetGenericReturnType.
@Test
public void testGetGenericReturnType() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedInterfaceDeclaration map = new ReflectionInterfaceDeclaration(Map.class, typeResolver);
ResolvedMethodDeclaration put = map.getAllMethods().stream().filter(m -> m.getName().equals("put")).findFirst().get().getDeclaration();
assertEquals(true, put.getReturnType().isTypeVariable());
assertEquals(true, put.getReturnType().asTypeParameter().declaredOnType());
assertEquals("java.util.Map.V", put.getReturnType().asTypeParameter().getQualifiedName());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class ReferenceTypeTest method testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassAbstractCollection.
@Test
public void testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassAbstractCollection() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedClassDeclaration abstractCollection = new ReflectionClassDeclaration(AbstractCollection.class, typeResolver);
ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver);
ResolvedReferenceType abstractCollectionOfString = new ReferenceTypeImpl(abstractCollection, ImmutableList.of(string), typeResolver);
Map<String, ResolvedReferenceType> ancestors = new HashMap<>();
abstractCollectionOfString.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a));
assertEquals(3, ancestors.size());
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.Collection"));
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.lang.Iterable"));
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class ReferenceTypeTest method testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassArrayList.
@Test
public void testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassArrayList() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedClassDeclaration arraylist = new ReflectionClassDeclaration(ArrayList.class, typeResolver);
ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver);
ResolvedReferenceType arrayListOfString = new ReferenceTypeImpl(arraylist, ImmutableList.of(string), typeResolver);
Map<String, ResolvedReferenceType> ancestors = new HashMap<>();
arrayListOfString.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a));
assertEquals(9, ancestors.size());
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(RandomAccess.class, typeResolver), typeResolver), ancestors.get("java.util.RandomAccess"));
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.AbstractCollection"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.List"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Cloneable.class, typeResolver), typeResolver), ancestors.get("java.lang.Cloneable"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.Collection"));
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractList.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.AbstractList"));
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.lang.Iterable"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Serializable.class, typeResolver), typeResolver), ancestors.get("java.io.Serializable"));
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class ReferenceTypeTest method testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassAbstractList.
@Test
public void testGetAllAncestorsOnTypeWithSpecifiedTypeParametersForClassAbstractList() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedClassDeclaration abstractList = new ReflectionClassDeclaration(AbstractList.class, typeResolver);
ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver);
ResolvedReferenceType abstractListOfString = new ReferenceTypeImpl(abstractList, ImmutableList.of(string), typeResolver);
Map<String, ResolvedReferenceType> ancestors = new HashMap<>();
abstractListOfString.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a));
assertEquals(5, ancestors.size());
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.AbstractCollection"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.List"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.util.Collection"));
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeResolver), typeResolver), ancestors.get("java.lang.Object"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Iterable.class, typeResolver), ImmutableList.of(string), typeResolver), ancestors.get("java.lang.Iterable"));
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class ReferenceTypeTest method testReplaceTypeVariablesWithLambdaInBetween.
@Test
public void testReplaceTypeVariablesWithLambdaInBetween() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedInterfaceDeclaration streamInterface = new ReflectionInterfaceDeclaration(Stream.class, typeResolver);
ResolvedReferenceType stream = new ReferenceTypeImpl(streamInterface, typeResolver);
ResolvedMethodDeclaration streamMap = streamInterface.getDeclaredMethods().stream().filter(m -> m.getName().equals("map")).findFirst().get();
ResolvedTypeParameterDeclaration streamMapR = streamMap.findTypeParameter("T").get();
ResolvedTypeVariable typeVariable = new ResolvedTypeVariable(streamMapR);
stream = stream.deriveTypeParameters(stream.typeParametersMap().toBuilder().setValue(stream.getTypeDeclaration().getTypeParameters().get(0), typeVariable).build());
ResolvedTypeParameterDeclaration tpToReplace = streamInterface.getTypeParameters().get(0);
ResolvedType replaced = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver);
ResolvedType streamReplaced = stream.replaceTypeVariables(tpToReplace, replaced);
assertEquals("java.util.stream.Stream<java.lang.String>", streamReplaced.describe());
}
Aggregations