/* @Nullable */ private ArrayTypeReference doTryConvertToArray( ParameterizedTypeReference typeReference, RecursionGuard<JvmTypeParameter> recursionGuard) { JvmType type = typeReference.getType(); if (recursionGuard.tryNext((JvmTypeParameter) type)) { List<LightweightTypeReference> superTypes = typeReference.getSuperTypes(); for (int i = 0, size = superTypes.size(); i < size; i++) { LightweightTypeReference superType = superTypes.get(i); if (superType.isArray()) { return (ArrayTypeReference) superType; } ArrayTypeReference result = doTryConvertToArray(typeReference); if (result != null) { return result; } else { JvmType rawSuperType = superType.getType(); if (rawSuperType != null && rawSuperType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) { result = doTryConvertToArray((ParameterizedTypeReference) superType, recursionGuard); if (result != null) return result; } } } } return null; }
public LightweightTypeReference convertToList(ArrayTypeReference type) { LightweightTypeReference componentType = type.getComponentType(); LightweightTypeReference wrapper = componentType.getWrapperTypeIfPrimitive(); ITypeReferenceOwner owner = type.getOwner(); JvmType listType = type.getServices() .getTypeReferences() .findDeclaredType(List.class, owner.getContextResourceSet()); if (listType == null) { return owner.newUnknownTypeReference(List.class.getName()); } ParameterizedTypeReference result = owner.newParameterizedTypeReference(listType); result.addTypeArgument(wrapper); return result; }
/* @Nullable */ public ArrayTypeReference tryConvertToArray(ParameterizedTypeReference typeReference) { ArrayTypeReference result = doTryConvertToArray(typeReference); if (result != null) { return result; } else { JvmType type = typeReference.getType(); if (type.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) { return doTryConvertToArray(typeReference, new RecursionGuard<JvmTypeParameter>()); } } return null; }
/* @Nullable */ private ArrayTypeReference doTryConvertToArray(ParameterizedTypeReference typeReference) { LightweightTypeReference parameterizedIterable = typeReference.getSuperType(Iterable.class); if (parameterizedIterable != null) { ITypeReferenceOwner owner = typeReference.getOwner(); if (parameterizedIterable.isRawType()) { // return Object[] List<LightweightTypeReference> superTypes = parameterizedIterable.getSuperTypes(); if (superTypes.isEmpty()) { return null; } LightweightTypeReference objectType = superTypes.get(0); ArrayTypeReference array = owner.newArrayTypeReference(objectType); return array; } else { LightweightTypeReference componentType = parameterizedIterable.getTypeArguments().get(0).getUpperBoundSubstitute(); ArrayTypeReference array = owner.newArrayTypeReference(componentType); return array; } } return null; }