Search in sources :

Example 11 with JAnnotationUse

use of com.helger.jcodemodel.JAnnotationUse in project adt4j by sviperll.

the class Source method getNullability.

public static GenerationResult<Boolean> getNullability(AbstractJType type, String name, Collection<? extends JAnnotationUse> annotations) {
    boolean hasNonnull = false;
    boolean hasNullable = false;
    for (JAnnotationUse annotationUse : annotations) {
        AbstractJClass annotationClass = annotationUse.getAnnotationClass();
        if (!annotationClass.isError()) {
            String annotationClassName = annotationClass.fullName();
            if (annotationClassName != null) {
                if (annotationClassName.equals("javax.annotation.Nonnull")) {
                    hasNonnull = true;
                }
                if (annotationClassName.equals("javax.annotation.Nullable")) {
                    hasNullable = true;
                }
            }
        }
    }
    if (hasNonnull && hasNullable)
        return new GenerationResult<>(false, Collections.singletonList(MessageFormat.format("Parameter {0} is declared as both @Nullable and @Nonnull", name)));
    if (!type.isReference() && hasNullable)
        return new GenerationResult<>(false, Collections.singletonList(MessageFormat.format("Parameter {0} is non-reference, but declared as @Nullable", name)));
    return new GenerationResult<>(hasNullable, Collections.<String>emptyList());
}
Also used : JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Aggregations

JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)11 AbstractJClass (com.helger.jcodemodel.AbstractJClass)8 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)7 MemberAccess (com.github.sviperll.adt4j.MemberAccess)3 JDefinedClass (com.helger.jcodemodel.JDefinedClass)3 GenerateValueClassForVisitor (com.github.sviperll.adt4j.GenerateValueClassForVisitor)2 ValueClassConfiguration (com.github.sviperll.adt4j.model.config.ValueClassConfiguration)2 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)2 JAnnotationArrayMember (com.helger.jcodemodel.JAnnotationArrayMember)2 JMethod (com.helger.jcodemodel.JMethod)2 JTypeVar (com.helger.jcodemodel.JTypeVar)2 GeneratePredicate (com.github.sviperll.adt4j.GeneratePredicate)1 GenerateValueClassForVisitorProcessor (com.github.sviperll.adt4j.GenerateValueClassForVisitorProcessor)1 WrapsGeneratedValueClass (com.github.sviperll.adt4j.WrapsGeneratedValueClass)1 AbstractJAnnotationValue (com.helger.jcodemodel.AbstractJAnnotationValue)1 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)1 JFieldVar (com.helger.jcodemodel.JFieldVar)1 JFormatter (com.helger.jcodemodel.JFormatter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1