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());
}
Aggregations