use of com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration in project javaparser by javaparser.
the class FunctionInterfaceLogicTest method testGetFunctionalMethodPositiveCasesOnInterfaces.
@Test
public void testGetFunctionalMethodPositiveCasesOnInterfaces() {
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType function = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Function.class, typeSolver), typeSolver);
assertEquals(true, FunctionalInterfaceLogic.getFunctionalMethod(function).isPresent());
assertEquals("apply", FunctionalInterfaceLogic.getFunctionalMethod(function).get().getName());
ResolvedType consumer = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Consumer.class, typeSolver), typeSolver);
assertEquals(true, FunctionalInterfaceLogic.getFunctionalMethod(consumer).isPresent());
assertEquals("accept", FunctionalInterfaceLogic.getFunctionalMethod(consumer).get().getName());
}
use of com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration in project javaparser by javaparser.
the class ArrayTypeTest method testReplaceParam.
@Test
public void testReplaceParam() {
assertTrue(arrayOfBooleans == arrayOfBooleans.replaceTypeVariables(tpA, OBJECT));
assertTrue(arrayOfStrings == arrayOfStrings.replaceTypeVariables(tpA, OBJECT));
assertEquals(arrayOfListOfStrings, arrayOfListOfStrings.replaceTypeVariables(tpA, OBJECT));
ResolvedArrayType arrayOfListOfObjects = new ResolvedArrayType(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(OBJECT), typeSolver));
assertEquals(true, arrayOfListOfA.replaceTypeVariables(tpA, OBJECT).isArray());
assertEquals(ImmutableList.of(OBJECT), arrayOfListOfA.replaceTypeVariables(tpA, OBJECT).asArrayType().getComponentType().asReferenceType().typeParametersValues());
assertEquals(new ReflectionInterfaceDeclaration(List.class, typeSolver), arrayOfListOfA.replaceTypeVariables(tpA, OBJECT).asArrayType().getComponentType().asReferenceType().getTypeDeclaration());
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(OBJECT), typeSolver), arrayOfListOfA.replaceTypeVariables(tpA, OBJECT).asArrayType().getComponentType());
assertEquals(arrayOfListOfObjects, arrayOfListOfA.replaceTypeVariables(tpA, OBJECT));
assertEquals(arrayOfListOfStrings, arrayOfListOfA.replaceTypeVariables(tpA, STRING));
assertTrue(arrayOfListOfA != arrayOfListOfA.replaceTypeVariables(tpA, OBJECT));
}
use of com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration in project javaparser by javaparser.
the class ArrayTypeTest method setup.
@Before
public void setup() {
typeSolver = new ReflectionTypeSolver();
OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver);
STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver);
arrayOfBooleans = new ResolvedArrayType(ResolvedPrimitiveType.BOOLEAN);
arrayOfStrings = new ResolvedArrayType(STRING);
tpA = ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList());
arrayOfListOfA = new ResolvedArrayType(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(new ResolvedTypeVariable(tpA)), typeSolver));
arrayOfListOfStrings = new ResolvedArrayType(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver));
}
use of com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration in project javaparser by javaparser.
the class NullTypeTest method setup.
@Before
public void setup() {
typeSolver = new ReflectionTypeSolver();
OBJECT = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver);
STRING = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver);
arrayOfBooleans = new ResolvedArrayType(ResolvedPrimitiveType.BOOLEAN);
arrayOfListOfA = new ResolvedArrayType(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))), typeSolver));
}
use of com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration in project javaparser by javaparser.
the class ReferenceTypeTest method testGetAllAncestorsOnRawType.
@Test
public void testGetAllAncestorsOnRawType() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedClassDeclaration arraylist = new ReflectionClassDeclaration(ArrayList.class, typeResolver);
ResolvedReferenceType rawArrayList = new ReferenceTypeImpl(arraylist, typeResolver);
Map<String, ResolvedReferenceType> ancestors = new HashMap<>();
rawArrayList.getAllAncestors().forEach(a -> ancestors.put(a.getQualifiedName(), a));
assertEquals(9, ancestors.size());
ResolvedTypeVariable tv = new ResolvedTypeVariable(arraylist.getTypeParameters().get(0));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(RandomAccess.class, typeResolver), typeResolver), ancestors.get("java.util.RandomAccess"));
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractCollection.class, typeResolver), ImmutableList.of(tv), typeResolver), ancestors.get("java.util.AbstractCollection"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeResolver), ImmutableList.of(tv), 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(tv), typeResolver), ancestors.get("java.util.Collection"));
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(AbstractList.class, typeResolver), ImmutableList.of(tv), 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(tv), typeResolver), ancestors.get("java.lang.Iterable"));
assertEquals(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Serializable.class, typeResolver), typeResolver), ancestors.get("java.io.Serializable"));
}
Aggregations