@Override protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { final PsiElement element = descriptor.getPsiElement(); final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(element, PsiAnnotation.class); if (annotation == null) { return; } final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); final String annotationText = buildAnnotationText(annotation); final PsiAnnotation newAnnotation = factory.createAnnotationFromText(annotationText, element); annotation.replace(newAnnotation); }
public static void addSuppressAnnotation( final Project project, final Editor editor, final PsiElement container, final PsiModifierListOwner modifierOwner, final String id) throws IncorrectOperationException { PsiAnnotation annotation = AnnotationUtil.findAnnotation( modifierOwner, SuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME); final PsiAnnotation newAnnotation = createNewAnnotation(project, editor, container, annotation, id); if (newAnnotation != null) { if (annotation != null && annotation.isPhysical()) { annotation.replace(newAnnotation); } else { final PsiNameValuePair[] attributes = newAnnotation.getParameterList().getAttributes(); new AddAnnotationFix( SuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME, modifierOwner, attributes) .invoke(project, editor, container.getContainingFile()); } } }