-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xtend does not accept annotation @Nullable on parameter #2864
Comments
see also #2360 |
If I understand it correctly, the "culprit" is in @Check
public void checkAnnotationTarget(XAnnotation annotation) {
JvmType annotationType = annotation.getAnnotationType();
if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
return;
}
Set<ElementType> targets = annotationUtil.getAnnotationTargets((JvmAnnotationType) annotationType);
if (targets.isEmpty())
return;
final EObject eContainer = getContainingAnnotationTarget(annotation);
Class<? extends EObject> clazz = eContainer.getClass();
if (eContainer instanceof XtendField && eContainer.eContainer() instanceof XtendAnnotationType) {
clazz = XtendFunction.class;
}
for (Entry<Class<?>, Collection<ElementType>> mapping : targetInfos.asMap().entrySet()) {
if (mapping.getKey().isAssignableFrom(clazz)) {
targets.retainAll(mapping.getValue());
if (targets.isEmpty()) {
error("The annotation @" + annotation.getAnnotationType().getSimpleName()
+ " is disallowed for this location.", annotation, null, INSIGNIFICANT_INDEX,
ANNOTATION_WRONG_TARGET);
}
}
}
} it should be enough to update this initialization accordingly: protected final Multimap<Class<?>, ElementType> targetInfos;
{
ImmutableMultimap.Builder<Class<?>, ElementType> result = ImmutableMultimap.builder();
result.put(XtendClass.class, ElementType.TYPE);
result.put(XtendInterface.class, ElementType.TYPE);
result.put(XtendEnum.class, ElementType.TYPE);
result.putAll(XtendAnnotationType.class, ElementType.ANNOTATION_TYPE, ElementType.TYPE);
result.put(XtendField.class, ElementType.FIELD);
result.put(XtendFunction.class, ElementType.METHOD);
result.put(XtendParameter.class, ElementType.PARAMETER);
targetInfos = result.build();
} Do I underestimate anything? cc @szarnekow |
maybe: |
@cdietrich but that is a syntactic issue for fields. I was focusing on this issue, which is about parameter types. |
|
Do x and y go to the type or the field |
But this issue is about parameters |
So you would allow it just at this place ? |
Just as a first step; I had the feeling that for this issue you don't need to change the grammar but only the validator. For parameters, the grammar already allows the annotation to be placed there, but the validator only allows for |
Using org.eclipse.jdt.annotations.
Is there a problem if the annotation has
like @Nullable/@nonnull have it?
results in: The annotation @nullable is disallowed at this location
The text was updated successfully, but these errors were encountered: