/** * Whether this REST parameter is a collection or an array. * * @return Whether this REST parameter is a collection or an array. */ public boolean isCollectionType() { DecoratedTypeMirror type = (DecoratedTypeMirror) getType(); return type.isArray() || type.isCollection(); }
/** * The max occurs of the web result. * * @return The max occurs. */ public String getMaxOccurs() { DecoratedTypeMirror typeMirror = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(this.delegate); return typeMirror.isArray() || typeMirror.isCollection() ? "unbounded" : "1"; }
/** * The max occurs of this parameter as a child element. * * @return The max occurs of this parameter as a child element. */ public String getMaxOccurs() { DecoratedTypeMirror paramType = (DecoratedTypeMirror) getType(); return paramType.isArray() || paramType.isCollection() ? "unbounded" : "1"; }
/** * The max occurs of the web result. * * @return The max occurs. */ public String getMaxOccurs() { DecoratedTypeMirror typeMirror = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(this.delegate); boolean unbounded = typeMirror.isCollection() || typeMirror.isArray(); if (typeMirror.isArray()) { TypeMirror componentType = ((ArrayType) typeMirror).getComponentType(); //special case for byte[] if ((componentType instanceof PrimitiveType) && (((PrimitiveType) componentType).getKind() == PrimitiveType.Kind.BYTE)) { unbounded = false; } } return unbounded ? "unbounded" : "1"; }
private boolean isDataHandlers(DecoratedTypeMirror type) { if (type.isCollection()) { Collection<TypeMirror> typeArgs = ((DeclaredType) type).getActualTypeArguments(); if ((typeArgs != null) && (typeArgs.size() == 1)) { return isDataHandler((DecoratedTypeMirror) typeArgs.iterator().next()); } } else if (type.isArray()) { return isDataHandler((DecoratedTypeMirror) ((ArrayType) type).getComponentType()); } return false; }
/** * The max occurs of this parameter as a child element. * * @return The max occurs of this parameter as a child element. */ public String getMaxOccurs() { DecoratedTypeMirror paramType = (DecoratedTypeMirror) getType(); boolean unbounded = paramType.isCollection() || paramType.isArray(); if (paramType.isArray()) { TypeMirror componentType = ((ArrayType) paramType).getComponentType(); //special case for byte[] if ((componentType instanceof PrimitiveType) && (((PrimitiveType) componentType).getKind() == PrimitiveType.Kind.BYTE)) { unbounded = false; } } return unbounded ? "unbounded" : "1"; }
private boolean isDataHandlers(DecoratedTypeMirror type) { if (type.isCollection()) { Collection<TypeMirror> typeArgs = ((DeclaredType) type).getActualTypeArguments(); if ((typeArgs != null) && (typeArgs.size() == 1)) { return isDataHandler((DecoratedTypeMirror) typeArgs.iterator().next()); } } else if (type.isArray()) { return isDataHandler((DecoratedTypeMirror) ((ArrayType) type).getComponentType()); } return false; }
private boolean isDataHandlers(DecoratedTypeMirror type) { if (type.isCollection()) { Collection<TypeMirror> typeArgs = ((DeclaredType) type).getActualTypeArguments(); if ((typeArgs != null) && (typeArgs.size() == 1)) { return isDataHandler((DecoratedTypeMirror) typeArgs.iterator().next()); } } else if (type.isArray()) { return isDataHandler((DecoratedTypeMirror) ((ArrayType) type).getComponentType()); } return false; }
/** * Add the component types of the given type mirror to the given set of imports. * * @param type The type. * @param imports The imports. */ protected void addComponentTypes(TypeMirror type, Set<String> imports) throws TemplateModelException { if (includeComponentTypes) { if (type instanceof MapType) { MapType mapType = ((MapType) type); imports.add(classnameFor.convert(mapType.getKeyType())); imports.add(classnameFor.convert(mapType.getValueType())); } else if (((DecoratedTypeMirror) type).isCollection()) { DeclaredType declaredType = (DeclaredType) type; Iterator<TypeMirror> actualTypeArguments = declaredType.getActualTypeArguments().iterator(); if (actualTypeArguments.hasNext()) { imports.add(classnameFor.convert(actualTypeArguments.next())); } } else if (((DecoratedTypeMirror) type).isArray()) { imports.add(classnameFor.convert(((ArrayType) type).getComponentType())); } } }
private FaultBeanChildElement(PropertyDeclaration property, WebFault webFault) { DecoratedTypeMirror propertyType = (DecoratedTypeMirror) property.getPropertyType(); this.adaperType = AdapterUtil.findAdapterType(property.getGetter()); int minOccurs = propertyType.isPrimitive() ? 1 : 0; boolean unbounded = propertyType.isCollection() || propertyType.isArray(); if (propertyType.isArray()) { TypeMirror componentType = ((ArrayType) propertyType).getComponentType(); //special case for byte[] if ((componentType instanceof PrimitiveType) && (((PrimitiveType) componentType).getKind() == PrimitiveType.Kind.BYTE)) { unbounded = false; } } String maxOccurs = unbounded ? "unbounded" : "1"; this.property = property; this.minOccurs = minOccurs; this.maxOccurs = maxOccurs; this.webFault = webFault; }
/** * Add the component types of the given type mirror to the given set of imports. * * @param type The type. * @param imports The imports. */ protected void addComponentTypes(TypeMirror type, Set<String> imports) throws TemplateModelException { if (includeComponentTypes) { if (type instanceof MapType) { MapType mapType = ((MapType) type); imports.add(classnameFor.convert(mapType.getKeyType())); imports.add(classnameFor.convert(mapType.getValueType())); } else if (((DecoratedTypeMirror) type).isCollection()) { DeclaredType declaredType = (DeclaredType) type; Iterator<TypeMirror> actualTypeArguments = declaredType.getActualTypeArguments().iterator(); if (actualTypeArguments.hasNext()) { imports.add(classnameFor.convert(actualTypeArguments.next())); } } else if (((DecoratedTypeMirror) type).isArray()) { imports.add(classnameFor.convert(((ArrayType) type).getComponentType())); } } }
private FaultBeanChildElement(PropertyDeclaration property) { DecoratedTypeMirror propertyType = (DecoratedTypeMirror) property.getPropertyType(); this.adaperType = AdapterUtil.findAdapterType(property.getGetter()); int minOccurs = propertyType.isPrimitive() ? 1 : 0; String maxOccurs = propertyType.isArray() || propertyType.isCollection() ? "unbounded" : "1"; this.property = property; this.minOccurs = minOccurs; this.maxOccurs = maxOccurs; }
/** * Unwraps the specified type to its component type if its a collection or an array. Otherwise, the * specified type is returned. * * @param typeMirror The type to unwrap if necessary. * @return The component type, or the type itself. */ public static TypeMirror unwrapComponentType(TypeMirror typeMirror) { DecoratedTypeMirror decoratedType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(typeMirror); if (decoratedType.isArray()) { typeMirror = ((ArrayType) decoratedType).getComponentType(); } else if (decoratedType.isCollection()) { //if it's a collection type, the xml type is its component type. Iterator<TypeMirror> actualTypeArguments = ((DeclaredType) decoratedType).getActualTypeArguments().iterator(); if (!actualTypeArguments.hasNext()) { //no type arguments, java.lang.Object type. AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment(); typeMirror = ape.getTypeUtils().getDeclaredType(ape.getTypeDeclaration(Object.class.getName())); } else { typeMirror = actualTypeArguments.next(); } } else { return typeMirror; } return typeMirror; }
/** * Unwraps the specified type to its component type if its a collection or an array. Otherwise, the * specified type is returned. * * @param typeMirror The type to unwrap if necessary. * @return The component type, or the type itself. */ public static TypeMirror unwrapComponentType(TypeMirror typeMirror) { DecoratedTypeMirror decoratedType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(typeMirror); if (decoratedType.isArray()) { typeMirror = ((ArrayType) decoratedType).getComponentType(); } else if (decoratedType.isCollection()) { //if it's a collection type, the xml type is its component type. Iterator<TypeMirror> actualTypeArguments = ((DeclaredType) decoratedType).getActualTypeArguments().iterator(); if (!actualTypeArguments.hasNext()) { //no type arguments, java.lang.Object type. AnnotationProcessorEnvironment ape = Context.getCurrentEnvironment(); typeMirror = ape.getTypeUtils().getDeclaredType(ape.getTypeDeclaration(Object.class.getName())); } else { typeMirror = actualTypeArguments.next(); } } else { return typeMirror; } return typeMirror; }
/** * If this is a collection type, return the type parameter of the collection, or null if this isn't a * parameterized collection type. * * @return the type parameter of the collection. */ public TypeMirror getCollectionItemType() { DecoratedTypeMirror accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAccessorType()); if (accessorType.isArray()) { return ((ArrayType) accessorType).getComponentType(); } else if (accessorType.isCollection()) { Iterator<TypeMirror> itemTypes = ((DeclaredType) accessorType).getActualTypeArguments().iterator(); if (!itemTypes.hasNext()) { AnnotationProcessorEnvironment env = Context.getCurrentEnvironment(); Types typeUtils = env.getTypeUtils(); return TypeMirrorDecorator.decorate(typeUtils.getDeclaredType(env.getTypeDeclaration(java.lang.Object.class.getName()))); } else { return itemTypes.next(); } } return null; }
private JsonPropertyDeclaration(final PropertyDeclaration propertyDeclaration) { super(propertyDeclaration.getGetter(), propertyDeclaration.getSetter()); DecoratedTypeMirror decoratedPropertyType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getPropertyType()); isList = decoratedPropertyType.isCollection() || decoratedPropertyType.isArray(); if (decoratedPropertyType.isCollection() && getPropertyType() instanceof DeclaredType) { final DeclaredType declaredType = (DeclaredType) getPropertyType(); final Collection<TypeMirror> actualTypeArguments = declaredType.getActualTypeArguments(); if(actualTypeArguments != null && actualTypeArguments.size() == 1) { targetType = TypeMirrorDecorator.decorate(actualTypeArguments.iterator().next()); } else { targetType = getPropertyType(); } } else if (decoratedPropertyType.isArray() && getPropertyType() instanceof ArrayType) { final ArrayType arrayType = (ArrayType) getPropertyType(); targetType = TypeMirrorDecorator.decorate(arrayType.getComponentType()); } else { targetType = getPropertyType(); } }
/** * Get the XML type for the specified type mirror. * * @param typeMirror The type mirror. * @return The xml type for the specified type mirror. * @throws XmlTypeException If the type is invalid or unknown as an xml type. */ public static XmlType getXmlType(TypeMirror typeMirror) throws XmlTypeException { XmlTypeVisitor visitor = new XmlTypeVisitor(); DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(typeMirror); visitor.isInCollection = decorated.isCollection(); visitor.isInArray = decorated.isArray(); unwrapComponentType(typeMirror).accept(visitor); if (visitor.getErrorMessage() != null) { throw new XmlTypeException(visitor.getErrorMessage()); } return visitor.getXmlType(); }
return "Array"; else if (decorated.isArray()) { TypeMirror componentType = ((ArrayType) decorated).getComponentType(); if ((componentType instanceof PrimitiveType) && (((PrimitiveType) componentType).getKind() == PrimitiveType.Kind.BYTE)) {
/** * 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(); }