public static TypeMirror getNormalizedCollection(TypeMirror typeMirror) { TypeMirror base = findCollectionStrippedOfExtensions(typeMirror); if (base != null) { //now narrow the component type to what can be valid xml. Collection<TypeMirror> typeArgs = ((DeclaredType) base).getActualTypeArguments(); if (typeArgs.size() == 1) { TypeMirror candidateToNarrow = typeArgs.iterator().next(); NarrowingCollectionComponentVisitor visitor = new NarrowingCollectionComponentVisitor(); candidateToNarrow.accept(visitor); TypeMirror narrowing = visitor.getResult(); if (narrowing != null) { TypeDeclaration decl = ((DeclaredType) base).getDeclaration(); while (decl instanceof DecoratedTypeDeclaration) { decl = (TypeDeclaration) ((DecoratedTypeDeclaration) decl).getDelegate(); } while (narrowing instanceof DecoratedTypeMirror) { narrowing = ((DecoratedTypeMirror) narrowing).getDelegate(); } base = Context.getCurrentEnvironment().getTypeUtils().getDeclaredType(decl, narrowing); } } } return TypeMirrorDecorator.decorate(base); }
/** * Whether this adapter can adapt the specified type. * * @param type The type. * @return Whether this adapter can adapt the specified type. */ public boolean canAdapt(ReferenceType type) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(type); ReferenceType adaptedType = getAdaptedType(); if (adaptedType instanceof DeclaredType) { return ((DeclaredType)adaptedType).getDeclaration() != null && decorated.isInstanceOf(((DeclaredType)adaptedType).getDeclaration().getQualifiedName()); } else if (adaptedType instanceof ArrayType) { if (decorated instanceof ArrayType) { TypeMirror adaptedComponentType = ((ArrayType) adaptedType).getComponentType(); while (adaptedComponentType instanceof DecoratedTypeMirror) { adaptedComponentType = ((DecoratedTypeMirror) adaptedComponentType).getDelegate(); } TypeMirror componentType = ((ArrayType) decorated).getComponentType(); while (componentType instanceof DecoratedTypeMirror) { componentType = ((DecoratedTypeMirror) componentType).getDelegate(); } Types typeUtils = Context.getCurrentEnvironment().getTypeUtils(); return typeUtils.isAssignable(componentType, adaptedComponentType); } } return false; }
resolved = ((DecoratedTypeMirror) resolved).getDelegate();
TypeMirror declaredAdapting = getAdaptingType(); while (declaredAdapting instanceof DecoratedTypeMirror) { declaredAdapting = ((DecoratedTypeMirror) declaredAdapting).getDelegate();