DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(adaptedType);
TypeMirror componentType = null;
if (decorated.isCollection()) {
Iterator<TypeMirror> itemTypes = ((DeclaredType) decorated).getActualTypeArguments().iterator();
if (!itemTypes.hasNext()) {
AnnotationProcessorEnvironment env = Context.getCurrentEnvironment();
Types typeUtils = env.getTypeUtils();
componentType = TypeMirrorDecorator.decorate(typeUtils.getDeclaredType(env.getTypeDeclaration(java.lang.Object.class.getName())));
}
else {
componentType = itemTypes.next();
}
}
else if (decorated.isArray()) {
componentType = ((ArrayType) decorated).getComponentType();
}
if (componentType instanceof ReferenceType && canAdapt((ReferenceType) componentType)) {
//if we can adapt the component type, then the adapting type is the collection of the declared adapting type.
AnnotationProcessorEnvironment env = Context.getCurrentEnvironment();
TypeDeclaration collection = env.getTypeDeclaration(java.util.Collection.class.getName());
TypeMirror declaredAdapting = getAdaptingType();
while (declaredAdapting instanceof DecoratedTypeMirror) {
declaredAdapting = ((DecoratedTypeMirror) declaredAdapting).getDelegate();
}
return env.getTypeUtils().getDeclaredType(collection, declaredAdapting);
}
else {
return getAdaptingType();
}
}