Search in sources :

Example 1 with ReflectionInterfaceDeclaration

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());
}
Also used : Function(java.util.function.Function) Consumer(java.util.function.Consumer) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) ReflectionInterfaceDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Example 2 with ReflectionInterfaceDeclaration

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));
}
Also used : ResolvedArrayType(com.github.javaparser.resolution.types.ResolvedArrayType) ReflectionInterfaceDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 3 with ReflectionInterfaceDeclaration

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));
}
Also used : ResolvedArrayType(com.github.javaparser.resolution.types.ResolvedArrayType) ResolvedTypeVariable(com.github.javaparser.resolution.types.ResolvedTypeVariable) ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) ReflectionInterfaceDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) Before(org.junit.Before)

Example 4 with ReflectionInterfaceDeclaration

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));
}
Also used : ResolvedArrayType(com.github.javaparser.resolution.types.ResolvedArrayType) ResolvedTypeVariable(com.github.javaparser.resolution.types.ResolvedTypeVariable) ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) ReflectionInterfaceDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) Before(org.junit.Before)

Example 5 with ReflectionInterfaceDeclaration

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"));
}
Also used : TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedClassDeclaration(com.github.javaparser.resolution.declarations.ResolvedClassDeclaration) ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) ReflectionInterfaceDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) Test(org.junit.Test)

Aggregations

ReflectionInterfaceDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration)17 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)16 ReflectionClassDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration)14 Test (org.junit.Test)12 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)11 ResolvedClassDeclaration (com.github.javaparser.resolution.declarations.ResolvedClassDeclaration)5 ResolvedArrayType (com.github.javaparser.resolution.types.ResolvedArrayType)5 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 Before (org.junit.Before)5 ResolvedInterfaceDeclaration (com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration)4 ResolvedTypeVariable (com.github.javaparser.resolution.types.ResolvedTypeVariable)4 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)2 ResolvedTypeParameterDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration)2 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)1 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1