Search in sources :

Example 1 with ResolvedArrayType

use of com.github.javaparser.resolution.types.ResolvedArrayType 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 2 with ResolvedArrayType

use of com.github.javaparser.resolution.types.ResolvedArrayType 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 3 with ResolvedArrayType

use of com.github.javaparser.resolution.types.ResolvedArrayType 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 4 with ResolvedArrayType

use of com.github.javaparser.resolution.types.ResolvedArrayType in project javaparser by javaparser.

the class VoidTypeTest 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 ResolvedArrayType

use of com.github.javaparser.resolution.types.ResolvedArrayType in project javaparser by javaparser.

the class ConstructorResolutionLogic method groupVariadicParamValues.

private static List<ResolvedType> groupVariadicParamValues(List<ResolvedType> argumentsTypes, int startVariadic, ResolvedType variadicType) {
    List<ResolvedType> res = new ArrayList<>(argumentsTypes.subList(0, startVariadic));
    List<ResolvedType> variadicValues = argumentsTypes.subList(startVariadic, argumentsTypes.size());
    if (variadicValues.isEmpty()) {
        // TODO if there are no variadic values we should default to the bound of the formal type
        res.add(variadicType);
    } else {
        ResolvedType componentType = findCommonType(variadicValues);
        res.add(new ResolvedArrayType(componentType));
    }
    return res;
}
Also used : ResolvedArrayType(com.github.javaparser.resolution.types.ResolvedArrayType) ArrayList(java.util.ArrayList) ResolvedType(com.github.javaparser.resolution.types.ResolvedType)

Aggregations

ResolvedArrayType (com.github.javaparser.resolution.types.ResolvedArrayType)9 ReflectionInterfaceDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration)5 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)4 ResolvedTypeVariable (com.github.javaparser.resolution.types.ResolvedTypeVariable)4 ReflectionClassDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration)4 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)4 Before (org.junit.Before)4 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 Parameter (com.github.javaparser.ast.body.Parameter)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)1 VariableDeclarationExpr (com.github.javaparser.ast.expr.VariableDeclarationExpr)1 ResolvedTypeParameterDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration)1 ResolvedPrimitiveType (com.github.javaparser.resolution.types.ResolvedPrimitiveType)1 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 BooleanSchema (io.swagger.v3.oas.models.media.BooleanSchema)1