use of com.intellij.codeInspection.AnnotateMethodFix in project intellij-community by JetBrains.
the class ReturnNullInspectionBase method buildFix.
@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos) {
final PsiElement elt = (PsiElement) infos[0];
if (!AnnotationUtil.isAnnotatingApplicable(elt)) {
return null;
}
final PsiElement element = PsiTreeUtil.getParentOfType(elt, PsiMethod.class, PsiLambdaExpression.class);
if (element instanceof PsiLambdaExpression) {
return null;
}
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) element;
final PsiType type = method.getReturnType();
if (TypeUtils.isOptional(type)) {
// don't suggest to annotate Optional methods as Nullable
return new ReplaceWithEmptyOptionalFix(((PsiClassType) type).rawType().getCanonicalText());
}
}
final NullableNotNullManager manager = NullableNotNullManager.getInstance(elt.getProject());
return new DelegatingFix(new AnnotateMethodFix(manager.getDefaultNullable(), ArrayUtil.toStringArray(manager.getNotNulls())) {
@Override
public int shouldAnnotateBaseMethod(PsiMethod method, PsiMethod superMethod, Project project) {
return ReturnNullInspectionBase.this.shouldAnnotateBaseMethod(method, superMethod);
}
});
}
Aggregations