diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CollapseAnnotationsFix.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CollapseAnnotationsFix.java index 1cc6e752638f..c6bab00f0c16 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CollapseAnnotationsFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CollapseAnnotationsFix.java @@ -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); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/collapseAnnotationsFix/afterNoArgs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/collapseAnnotationsFix/afterNoArgs.java new file mode 100644 index 000000000000..899653e3eb9b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/collapseAnnotationsFix/afterNoArgs.java @@ -0,0 +1,5 @@ +// "Remove" "true" + +@XYZ +class X{} +@interface XYZ {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/collapseAnnotationsFix/beforeNoArgs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/collapseAnnotationsFix/beforeNoArgs.java new file mode 100644 index 000000000000..ea938e6a91e1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/collapseAnnotationsFix/beforeNoArgs.java @@ -0,0 +1,6 @@ +// "Remove" "true" + +@XYZ +@XYZ +class X{} +@interface XYZ {} \ No newline at end of file