/** * Get the resolved accessor type for this accessor. * * @return the resolved accessor type for this accessor. */ public TypeMirror getResolvedAccessorType() { TypeMirror accessorType = getAccessorType(); if (isAdapted()) { accessorType = getAdapterType().getAdaptingType(accessorType); } return accessorType; }
/** * Find the specified type of the given adaptable element, if it exists. * * @param adaptable The adaptable element for which to find the specified type. * @return The specified XML type, or null if it doesn't exist. */ public static XmlType findSpecifiedType(Adaptable adaptable) throws XmlTypeException { XmlType xmlType = null; if (adaptable.isAdapted()) { xmlType = getXmlType(adaptable.getAdapterType().getAdaptingType()); } else if (adaptable instanceof Accessor) { //The XML type of accessors can be explicitly defined... xmlType = findExplicitSchemaType((Accessor) adaptable); } return xmlType; }
@Override public String convert(Accessor accessor) throws TemplateModelException { if (accessor.isAdapted()) { //if the type is adapted, the adapting type is already unwrapped. return convert(accessor.getAdapterType().getAdaptingType()); } else { return convert(accessor.getAccessorType()); } }
@Override public String convert(ImplicitChildElement childElement) throws TemplateModelException { if ((childElement instanceof Adaptable) && (((Adaptable) childElement).isAdapted())) { //the adapting type is already unwrapped... return convert(((Adaptable) childElement).getAdapterType().getAdaptingType()); } else { return convert(childElement.getType()); } }
@Override public String convert(Accessor accessor) throws TemplateModelException { TypeMirror accessorType = accessor.getAccessorType(); if (accessor.isAdapted()) { accessorType = accessor.getAdapterType().getAdaptingType(accessor.getAccessorType()); } return convert(accessorType); }
@Override public String convert(ImplicitChildElement childElement) throws TemplateModelException { TypeMirror elementType = childElement.getType(); if ((childElement instanceof Adaptable) && (((Adaptable) childElement).isAdapted())) { elementType = (((Adaptable) childElement).getAdapterType().getAdaptingType(childElement.getType())); } return convert(elementType); }
/** * Narrows the existing declaration down to its adapting declaration, if it's being adapted. Otherwise, the original declaration will be returned. * * @param declaration The declaration to narrow. * @return The narrowed declaration. */ protected ClassDeclaration narrowToAdaptingType(ClassDeclaration declaration) { AdapterType adapterType = AdapterUtil.findAdapterType(declaration); if (adapterType != null) { TypeMirror adaptingType = adapterType.getAdaptingType(); if (!(adaptingType instanceof ClassType)) { return declaration; } else { ClassDeclaration adaptingDeclaration = ((ClassType) adaptingType).getDeclaration(); if (adaptingDeclaration == null) { throw new ValidationException(declaration.getPosition(), String.format("Class %s is being adapted by a type (%s) that doesn't seem to be on the classpath.", declaration.getQualifiedName(), adaptingType)); } return adaptingDeclaration; } } return declaration; }
public void visitInterfaceType(InterfaceType interfaceType) { AdapterType adapterType = AdapterUtil.findAdapterType(interfaceType.getDeclaration()); if (adapterType != null) { adapterType.getAdaptingType().accept(this); } else { MapType mapType = MapTypeUtil.findMapType(interfaceType); if (mapType != null) { setMapXmlType(mapType); } else { this.xmlType = null; this.errorMessage = "An interface type cannot be an xml type."; } } }
@Override public String convert(Accessor accessor) throws TemplateModelException { if (accessor.isAdapted()) { //if the type is adapted, the adapting type might be already unwrapped. return convert(accessor.getAdapterType().getAdaptingType(accessor.getAccessorType())); } else { return convert(accessor.getAccessorType()); } }
@Override public String convert(ImplicitChildElement childElement) throws TemplateModelException { if ((childElement instanceof Adaptable) && (((Adaptable) childElement).isAdapted())) { //the adapting type might be already unwrapped... return convert(((Adaptable) childElement).getAdapterType().getAdaptingType(childElement.getType())); } else { return convert(childElement.getType()); } }
public void visitInterfaceType(InterfaceType interfaceType) { AdapterType adapterType = AdapterUtil.findAdapterType(interfaceType.getDeclaration()); if (adapterType != null) { adapterType.getAdaptingType().accept(this); } else { MapType mapType = MapTypeUtil.findMapType(interfaceType); if (mapType != null) { setMapXmlType(mapType); } else if (isInCollection) { this.xmlType = KnownXmlType.ANY_TYPE; } else { this.xmlType = null; this.errorMessage = "An interface type cannot be an xml type."; } } }
/** * Find the specified type of the given adaptable element, if it exists. * * @param adaptable The adaptable element for which to find the specified type. * @return The specified XML type, or null if it doesn't exist. */ public static XmlType findSpecifiedType(Adaptable adaptable) throws XmlTypeException { XmlType xmlType = null; if (adaptable instanceof Accessor) { XmlSchemaType specified = ((Accessor) adaptable).getAnnotation(XmlSchemaType.class); if (specified != null) { return new SpecifiedXmlType(specified); } } if (adaptable.isAdapted()) { xmlType = getXmlType(adaptable.getAdapterType().getAdaptingType()); } else if (adaptable instanceof Accessor) { //The XML type of accessors can be explicitly defined... xmlType = findExplicitSchemaType((Accessor) adaptable); } return xmlType; }
/** * Whether the given type is supported. * * @param type The type to test for supportability. * @return Whether the given type is supported. */ protected boolean isSupported(TypeMirror type) { if ((type instanceof Adaptable) && ((Adaptable) type).isAdapted()) { return isSupported(((Adaptable) type).getAdapterType().getAdaptingType()); } else if (type instanceof DeclaredType) { DecoratedDeclaredType declaredType = (DecoratedDeclaredType) TypeMirrorDecorator.decorate(type); if ((declaredType.getDeclaration() != null) && (isGWTTransient(declaredType.getDeclaration()))) { return false; } else if ((declaredType.isInstanceOf(Collection.class.getName())) || (declaredType.isInstanceOf(java.util.Map.class.getName()))) { boolean supported = true; for (TypeMirror typeArgument : declaredType.getActualTypeArguments()) { supported &= isSupported(typeArgument); } return supported; } else { return !unsupportedTypes.contains(declaredType.getDeclaration().getQualifiedName()); } } //by default, we're going to assume that the type is complex and is supported. return true; }
/** * Whether the given type is supported. * * @param type The type to test for supportability. * @return Whether the given type is supported. */ protected boolean isSupported(TypeMirror type) { if ((type instanceof Adaptable) && ((Adaptable) type).isAdapted()) { return isSupported(((Adaptable) type).getAdapterType().getAdaptingType()); } else if (type instanceof DeclaredType) { DecoratedDeclaredType declaredType = (DecoratedDeclaredType) TypeMirrorDecorator.decorate(type); if ((declaredType.getDeclaration() != null) && (isGWTTransient(declaredType.getDeclaration()))) { return false; } else if ((declaredType.isInstanceOf(Collection.class.getName())) || (declaredType.isInstanceOf(java.util.Map.class.getName()))) { boolean supported = true; for (TypeMirror typeArgument : declaredType.getActualTypeArguments()) { supported &= isSupported(typeArgument); } return supported; } else { return !unsupportedTypes.contains(declaredType.getDeclaration().getQualifiedName()); } } //by default, we're going to assume that the type is complex and is supported. return true; }
/** * Converts the specified implicit child element. * * @param childElement The implicit child element. * @return The conversion. */ public String convert(ImplicitChildElement childElement) throws TemplateModelException { TypeMirror elementType = childElement.getType(); if ((childElement instanceof Adaptable) && (((Adaptable) childElement).isAdapted())) { boolean isArray = elementType instanceof ArrayType; elementType = (((Adaptable) childElement).getAdapterType().getAdaptingType()); if (isArray) { //the adapting type adapts the component, so we need to convert it back to an array type. AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment(); elementType = ape.getTypeUtils().getArrayType(elementType); } } return convert(elementType); }
/** * Converts the type of an accessor. * * @param accessor The accessor. * @return The accessor. */ public String convert(Accessor accessor) throws TemplateModelException { TypeMirror accessorType = accessor.getAccessorType(); if (accessor.isAdapted()) { boolean isArray = accessorType instanceof ArrayType; accessorType = accessor.getAdapterType().getAdaptingType(); if (isArray) { //the adapting type will adapt the component, so we need to convert it back to an array type. AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment(); accessorType = ape.getTypeUtils().getArrayType(accessorType); } } return convert(accessorType); }
/** * Whether the given type is supported. * * @param type The type to test for supportability. * @return Whether the given type is supported. */ protected boolean isSupported(TypeMirror type) { if ((type instanceof Adaptable) && ((Adaptable) type).isAdapted()) { return isSupported(((Adaptable) type).getAdapterType().getAdaptingType()); } else if (type instanceof DeclaredType) { DecoratedDeclaredType declaredType = (DecoratedDeclaredType) TypeMirrorDecorator.decorate(type); if ((declaredType.getDeclaration() != null) && (isAMFTransient(declaredType.getDeclaration()))) { return false; } else if ((declaredType.isInstanceOf(Collection.class.getName())) || (declaredType.isInstanceOf(java.util.Map.class.getName()))) { boolean supported = true; for (TypeMirror typeArgument : declaredType.getActualTypeArguments()) { supported &= isSupported(typeArgument); } return supported; } else { return declaredType.getDeclaration() != null && !unsupportedTypes.contains(declaredType.getDeclaration().getQualifiedName()); } } //by default, we're going to assume that the type is complex and is supported. return true; }
@Override public String convert(TypeDeclaration declaration) throws TemplateModelException { AdapterType adapterType = AdapterUtil.findAdapterType(declaration); if (adapterType != null) { return convert(adapterType.getAdaptingType()); } if (declaration instanceof ClassDeclaration) { DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(((ClassDeclaration) declaration).getSuperclass()); if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) { //for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement return convert(superType); } } String convertedPackage = convertPackage(declaration.getPackage()); ClientName specifiedName = isUseClientNameConversions() ? declaration.getAnnotation(ClientName.class) : null; String simpleName = specifiedName == null ? declaration.getSimpleName() : specifiedName.value(); return convertedPackage + getPackageSeparator() + simpleName; } }
/** * Whether the accessor type is a collection type. * * @return Whether the accessor type is a collection type. */ public boolean isCollectionType() { if (isXmlList()) { return false; } DecoratedTypeMirror accessorType; if (isAdapted()) { accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAdapterType().getAdaptingType()); } else { accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAccessorType()); } if (accessorType.isArray()) { TypeMirror componentType = ((ArrayType) accessorType).getComponentType(); //special case for byte[] return !(componentType instanceof PrimitiveType) || !(((PrimitiveType) componentType).getKind() == PrimitiveType.Kind.BYTE); } return accessorType.isCollection(); }
/** * Whether the accessor type is a collection type. * * @return Whether the accessor type is a collection type. */ public boolean isCollectionType() { if (isXmlList()) { return false; } DecoratedTypeMirror accessorType; if (isAdapted()) { accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAdapterType().getAdaptingType(getAccessorType())); } else { accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAccessorType()); } if (accessorType.isArray()) { TypeMirror componentType = ((ArrayType) accessorType).getComponentType(); //special case for byte[] return !(componentType instanceof PrimitiveType) || !(((PrimitiveType) componentType).getKind() == PrimitiveType.Kind.BYTE); } return accessorType.isCollection(); }