static boolean isValidType()

in broker-codegen/src/main/java/org/apache/qpid/server/model/validation/AttributeAnnotationValidator.java [328:452]


    static boolean isValidType(ProcessingEnvironment processingEnv,
                               final TypeMirror type, final boolean allowAbstractManagedTypes)
    {
        Types typeUtils = processingEnv.getTypeUtils();
        Elements elementUtils = processingEnv.getElementUtils();
        Element typeElement = typeUtils.asElement(type);

        if (VALID_PRIMITIVE_TYPES.contains(type.getKind()))
        {
            return true;
        }
        for(TypeKind primitive : VALID_PRIMITIVE_TYPES)
        {
            if(typeUtils.isSameType(type, typeUtils.boxedClass(typeUtils.getPrimitiveType(primitive)).asType()))
            {
                return true;
            }
        }
        if(typeElement != null && typeElement.getKind()==ElementKind.ENUM)
        {
            return true;
        }

        String className = "org.apache.qpid.server.model.ConfiguredObject";
        TypeMirror configuredObjectType = getErasure(processingEnv, className);

        if(typeUtils.isAssignable(typeUtils.erasure(type), configuredObjectType))
        {
            return true;
        }

        final TypeElement managedAttributeTypeValueElement =
                elementUtils.getTypeElement(ManagedAttributeValueTypeValidator.MANAGED_ATTRIBUTE_VALUE_TYPE_CLASS_NAME);
        if(typeElement != null)
        {
            for (AnnotationMirror annotation : typeElement.getAnnotationMirrors())
            {
                if (annotation.getAnnotationType().asElement().equals(managedAttributeTypeValueElement))
                {
                    if(allowAbstractManagedTypes)
                    {
                        return true;
                    }
                    else
                    {
                        final Map<? extends ExecutableElement, ? extends AnnotationValue> annotationValues =
                                elementUtils.getElementValuesWithDefaults(annotation);
                        for(Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> element : annotationValues.entrySet())
                        {
                            if("isAbstract".contentEquals(element.getKey().getSimpleName()))
                            {
                                return element.getValue().getValue().equals(Boolean.FALSE);
                            }
                        }
                        return false;
                    }
                }
            }
        }
        if(typeUtils.isSameType(type,elementUtils.getTypeElement("java.lang.Object").asType()))
        {
            return true;
        }


        if(typeUtils.isSameType(type, elementUtils.getTypeElement("java.lang.String").asType()))
        {
            return true;
        }


        if(typeUtils.isSameType(type,elementUtils.getTypeElement("java.util.UUID").asType()))
        {
            return true;
        }

        if(typeUtils.isSameType(type,elementUtils.getTypeElement("java.util.Date").asType()))
        {
            return true;
        }

        if(typeUtils.isSameType(type,elementUtils.getTypeElement("java.net.URI").asType()))
        {
            return true;
        }

        if(typeUtils.isSameType(type,elementUtils.getTypeElement("java.security.cert.Certificate").asType()))
        {
            return true;
        }

        if(typeUtils.isSameType(type,elementUtils.getTypeElement("java.security.Principal").asType()))
        {
            return true;
        }

        TypeMirror erasedType = typeUtils.erasure(type);
        if(typeUtils.isSameType(erasedType, getErasure(processingEnv, "java.util.List"))
                || typeUtils.isSameType(erasedType, getErasure(processingEnv, "java.util.Set"))
                || typeUtils.isSameType(erasedType, getErasure(processingEnv, "java.util.Collection")))
        {
            for(TypeMirror paramType : ((DeclaredType)type).getTypeArguments())
            {
                if(!isValidType(processingEnv, paramType, allowAbstractManagedTypes))
                {
                    return false;
                }
            }
            return true;
        }

        if(typeUtils.isSameType(erasedType, getErasure(processingEnv, "java.util.Map")))
        {
            List<? extends TypeMirror> args = ((DeclaredType) type).getTypeArguments();
            if (args.size() != 2)
            {
                throw new IllegalArgumentException("Map types " + type + " must have exactly two type arguments");
            }
            return isValidType(processingEnv, args.get(0), false)
                   && (isValidType(processingEnv, args.get(1), false)
                       || typeUtils.isSameType(args.get(1), getErasure(processingEnv, "java.lang.Object")));
        }

        return false;
    }