Add quick fix to remove duplicate annotation without parameters (IDEA-249508)

GitOrigin-RevId: fea7daeb0bb40724325182d6041a20aa141fbbf2
This commit is contained in:
Bas Leijdekkers
2020-11-23 21:56:24 +00:00
committed by intellij-monorepo-bot
parent f0726e3181
commit 4b18db9bfb
3 changed files with 19 additions and 2 deletions
@@ -1,8 +1,10 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.intention.impl;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.java.JavaBundle;
import com.intellij.java.analysis.JavaAnalysisBundle;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -94,11 +96,15 @@ public final class CollapseAnnotationsFix extends LocalQuickFixAndIntentionActio
}
@Nullable
public static CollapseAnnotationsFix from(PsiAnnotation annotation) {
public static LocalQuickFixAndIntentionActionOnPsiElement from(PsiAnnotation annotation) {
PsiAnnotationOwner owner = annotation.getOwner();
String name = annotation.getQualifiedName();
if (owner == null || name == null) return null;
PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
if (owner == null || name == null || attributes.length != 1) return null;
if (attributes.length == 0) {
return QuickFixFactory.getInstance().createDeleteFix(annotation, JavaAnalysisBundle.message("intention.text.remove.annotation"));
}
if (attributes.length != 1) return null;
PsiNameValuePair attribute = attributes[0];
if (attribute.getValue() == null) return null;
PsiMethod annoMethod = findAttributeMethod(attribute);
@@ -0,0 +1,5 @@
// "Remove" "true"
@XYZ
class X{}
@interface XYZ {}
@@ -0,0 +1,6 @@
// "Remove" "true"
@X<caret>YZ
@XYZ
class X{}
@interface XYZ {}