/** * Get the adapting type for the specified type. This method differs from {@link #getAdaptingType()} because it takes * into account whether the adapted is an array or collection. * * @param adaptedType The type. * @return The adapting type, or null if not adaptable. */ public TypeMirror getAdaptingType(DecoratedTypeMirror adaptedType, EnunciateContext context) { TypeMirror componentType = null; if (adaptedType.isCollection()) { List<? extends TypeMirror> itemTypes = ((DeclaredType) adaptedType).getTypeArguments(); if (itemTypes.isEmpty()) { componentType = TypeMirrorUtils.objectType(context.getProcessingEnvironment()); } else { componentType = itemTypes.get(0); } } else if (adaptedType instanceof ArrayType) { componentType = ((ArrayType) adaptedType).getComponentType(); } if (componentType != null && canAdapt(componentType, context)) { //if we can adapt the component type, then the adapting type is the collection of the declared adapting type. return context.getProcessingEnvironment().getTypeUtils().getDeclaredType((TypeElement) TypeMirrorUtils.collectionType(context.getProcessingEnvironment()).asElement(), componentType); } else { return getAdaptingType(); } }
/** * Get the adapting type for the specified type. This method differs from {@link #getAdaptingType()} because it takes * into account whether the adapted is an array or collection. * * @param adaptedType The type. * @return The adapting type, or null if not adaptable. */ public TypeMirror getAdaptingType(DecoratedTypeMirror adaptedType, EnunciateContext context) { TypeMirror componentType = null; if (adaptedType.isCollection()) { List<? extends TypeMirror> itemTypes = ((DeclaredType) adaptedType).getTypeArguments(); if (itemTypes.isEmpty()) { componentType = TypeMirrorUtils.objectType(context.getProcessingEnvironment()); } else { componentType = itemTypes.get(0); } } else if (adaptedType instanceof ArrayType) { componentType = ((ArrayType) adaptedType).getComponentType(); } if (componentType != null && canAdapt(componentType, context)) { //if we can adapt the component type, then the adapting type is the collection of the declared adapting type. return context.getProcessingEnvironment().getTypeUtils().getDeclaredType((TypeElement) TypeMirrorUtils.collectionType(context.getProcessingEnvironment()).asElement(), componentType); } else { return getAdaptingType(); } }