Search in sources :

Example 16 with ReflectionInterfaceDeclaration

use of com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration in project javaparser by javaparser.

the class ReferenceTypeTest 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);
    listOfA = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(new ResolvedTypeVariable(ResolvedTypeParameterDeclaration.onType("A", "foo.Bar", Collections.emptyList()))), typeSolver);
    listOfStrings = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver);
    linkedListOfString = new ReferenceTypeImpl(new ReflectionClassDeclaration(LinkedList.class, typeSolver), ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver);
    collectionOfString = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Collection.class, typeSolver), ImmutableList.of(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver)), typeSolver);
    listOfWildcardExtendsString = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(ResolvedWildcard.extendsBound(string)), typeSolver);
    listOfWildcardSuperString = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(List.class, typeSolver), ImmutableList.of(ResolvedWildcard.superBound(string)), typeSolver);
}
Also used : ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) ReflectionInterfaceDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) Before(org.junit.Before)

Example 17 with ReflectionInterfaceDeclaration

use of com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration in project javaparser by javaparser.

the class ReferenceTypeTest method testTypeParamValue.

@Test
public void testTypeParamValue() {
    TypeSolver typeResolver = new ReflectionTypeSolver();
    ResolvedClassDeclaration arraylist = new ReflectionClassDeclaration(ArrayList.class, typeResolver);
    ResolvedClassDeclaration abstractList = new ReflectionClassDeclaration(AbstractList.class, typeResolver);
    ResolvedClassDeclaration abstractCollection = new ReflectionClassDeclaration(AbstractCollection.class, typeResolver);
    ResolvedInterfaceDeclaration list = new ReflectionInterfaceDeclaration(List.class, typeResolver);
    ResolvedInterfaceDeclaration collection = new ReflectionInterfaceDeclaration(Collection.class, typeResolver);
    ResolvedInterfaceDeclaration iterable = new ReflectionInterfaceDeclaration(Iterable.class, typeResolver);
    ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeResolver), typeResolver);
    ResolvedReferenceType arrayListOfString = new ReferenceTypeImpl(arraylist, ImmutableList.of(string), typeResolver);
    assertEquals(Optional.of(string), arrayListOfString.typeParamValue(arraylist.getTypeParameters().get(0)));
    assertEquals(Optional.of(string), arrayListOfString.typeParamValue(abstractList.getTypeParameters().get(0)));
    assertEquals(Optional.of(string), arrayListOfString.typeParamValue(abstractCollection.getTypeParameters().get(0)));
    assertEquals(Optional.of(string), arrayListOfString.typeParamValue(list.getTypeParameters().get(0)));
    assertEquals(Optional.of(string), arrayListOfString.typeParamValue(collection.getTypeParameters().get(0)));
    assertEquals(Optional.of(string), arrayListOfString.typeParamValue(iterable.getTypeParameters().get(0)));
}
Also used : TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedInterfaceDeclaration(com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration) 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