mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Make externalAnnotation EP dynamic
GitOrigin-RevId: 23c3281b2e870ccf0f322be680c6f455712966ae
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e180905fe2
commit
cba414b385
@@ -74,7 +74,7 @@
|
||||
<extensionPoint qualifiedName="com.intellij.unscrambleSupport" interface="com.intellij.unscramble.UnscrambleSupport" dynamic="true"/>
|
||||
<extensionPoint qualifiedName="com.intellij.java.refactoring.chainCallExtractor" interface="com.intellij.refactoring.chainCall.ChainCallExtractor" dynamic="true"/>
|
||||
<extensionPoint qualifiedName="com.intellij.java.inspection.bulkMethodInfo" interface="com.intellij.codeInspection.bulkOperation.BulkMethodInfoProvider" dynamic="true"/>
|
||||
<extensionPoint qualifiedName="com.intellij.java.externalAnnotation" interface="com.intellij.codeInsight.externalAnnotation.AnnotationProvider"/>
|
||||
<extensionPoint qualifiedName="com.intellij.java.externalAnnotation" interface="com.intellij.codeInsight.externalAnnotation.AnnotationProvider" dynamic="true"/>
|
||||
<extensionPoint qualifiedName="com.intellij.documentationDelegateProvider" interface="com.intellij.codeInsight.javadoc.DocumentationDelegateProvider" dynamic="true"/>
|
||||
<extensionPoint qualifiedName="com.intellij.codeInsight.externalLibraryResolver" interface="com.intellij.codeInsight.daemon.quickFix.ExternalLibraryResolver" dynamic="true"/>
|
||||
<extensionPoint qualifiedName="com.intellij.refactoring.moveClassHandler" interface="com.intellij.refactoring.move.moveClassesOrPackages.MoveClassHandler" dynamic="true"/>
|
||||
|
||||
+37
-38
@@ -5,7 +5,6 @@ package com.intellij.codeInsight.intention.impl;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.ExternalAnnotationsManagerImpl;
|
||||
import com.intellij.codeInsight.externalAnnotation.AnnotationProvider;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationFix;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationPsiFix;
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction;
|
||||
import com.intellij.java.JavaBundle;
|
||||
@@ -31,8 +30,7 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AnnotateIntentionAction extends BaseIntentionAction implements LowPriorityAction {
|
||||
private AnnotationProvider myAnnotationProvider;
|
||||
private boolean mySingleMode;
|
||||
private String mySingleAnnotationName;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -56,19 +54,25 @@ public class AnnotateIntentionAction extends BaseIntentionAction implements LowP
|
||||
*/
|
||||
@TestOnly
|
||||
public boolean selectSingle(Editor editor, PsiFile file, String annotationShortName) {
|
||||
if (mySingleMode) {
|
||||
if (mySingleAnnotationName != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
mySingleMode = true;
|
||||
mySingleAnnotationName = annotationShortName;
|
||||
final PsiModifierListOwner owner = AddAnnotationPsiFix.getContainer(file, editor.getCaretModel().getOffset());
|
||||
if (owner == null || owner.getModifierList() == null || !ExternalAnnotationsManagerImpl.areExternalAnnotationsApplicable(owner)) {
|
||||
return false;
|
||||
}
|
||||
Optional<AnnotationProvider> provider = availableAnnotations(owner, file.getProject())
|
||||
return canAnnotateWith(file, owner, annotationShortName);
|
||||
}
|
||||
|
||||
private static boolean canAnnotateWith(PsiFile file, PsiModifierListOwner owner, String annotationShortName) {
|
||||
return getProviderFor(file, owner, annotationShortName).isPresent();
|
||||
}
|
||||
|
||||
private static Optional<AnnotationProvider> getProviderFor(PsiFile file, PsiModifierListOwner owner, String annotationShortName) {
|
||||
return availableAnnotations(owner, file.getProject())
|
||||
.filter(p -> StringUtil.getShortName(p.getName(file.getProject())).equals(annotationShortName))
|
||||
.collect(MoreCollectors.onlyOne());
|
||||
myAnnotationProvider = provider.orElse(null);
|
||||
return provider.isPresent();
|
||||
}
|
||||
|
||||
private static boolean alreadyAnnotated(PsiModifierListOwner owner, AnnotationProvider p, Project project) {
|
||||
@@ -83,17 +87,14 @@ public class AnnotateIntentionAction extends BaseIntentionAction implements LowP
|
||||
if (owner == null || owner.getModifierList() == null || !ExternalAnnotationsManagerImpl.areExternalAnnotationsApplicable(owner)) {
|
||||
return false;
|
||||
}
|
||||
if (mySingleMode) {
|
||||
return myAnnotationProvider != null && availableAnnotations(owner, project).has(myAnnotationProvider);
|
||||
}
|
||||
List<AnnotationProvider> annotations = availableAnnotations(owner, project).limit(2).collect(Collectors.toList());
|
||||
if (annotations.isEmpty()) return false;
|
||||
if (mySingleAnnotationName != null && canAnnotateWith(file, owner, mySingleAnnotationName)) return true;
|
||||
if (annotations.size() == 1) {
|
||||
myAnnotationProvider = annotations.get(0);
|
||||
setText(AddAnnotationPsiFix.calcText(owner, myAnnotationProvider.getName(project)));
|
||||
String providerName = annotations.get(0).getName(project);
|
||||
setText(AddAnnotationPsiFix.calcText(owner, providerName));
|
||||
}
|
||||
else {
|
||||
myAnnotationProvider = null;
|
||||
setText(AddAnnotationPsiFix.calcText(owner, null));
|
||||
}
|
||||
return true;
|
||||
@@ -103,33 +104,31 @@ public class AnnotateIntentionAction extends BaseIntentionAction implements LowP
|
||||
public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
final PsiModifierListOwner owner = AddAnnotationPsiFix.getContainer(file, editor.getCaretModel().getOffset());
|
||||
assert owner != null;
|
||||
if (myAnnotationProvider != null) {
|
||||
if (alreadyAnnotated(owner, myAnnotationProvider, project)) return;
|
||||
AddAnnotationFix fix = myAnnotationProvider.createFix(owner);
|
||||
fix.invoke(project, editor, file);
|
||||
if (mySingleAnnotationName != null) {
|
||||
getProviderFor(file, owner, mySingleAnnotationName)
|
||||
.ifPresent(provider -> provider.createFix(owner).invoke(project, editor, file));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
List<AnnotationProvider> annotations = availableAnnotations(owner, project).collect(Collectors.toList());
|
||||
if (annotations.isEmpty()) return;
|
||||
JBPopupFactory.getInstance().createListPopup(
|
||||
new BaseListPopupStep<AnnotationProvider>(JavaBundle.message("annotate.intention.chooser.title"), annotations) {
|
||||
@Override
|
||||
public PopupStep onChosen(final AnnotationProvider selectedValue, final boolean finalChoice) {
|
||||
return doFinalStep(() -> selectedValue.createFix(owner).invoke(project, editor, file));
|
||||
}
|
||||
List<AnnotationProvider> annotations = availableAnnotations(owner, project).collect(Collectors.toList());
|
||||
if (annotations.isEmpty()) return;
|
||||
JBPopupFactory.getInstance().createListPopup(
|
||||
new BaseListPopupStep<AnnotationProvider>(JavaBundle.message("annotate.intention.chooser.title"), annotations) {
|
||||
@Override
|
||||
public PopupStep onChosen(final AnnotationProvider selectedValue, final boolean finalChoice) {
|
||||
return doFinalStep(() -> selectedValue.createFix(owner).invoke(project, editor, file));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpeedSearchEnabled() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isSpeedSearchEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getTextFor(final AnnotationProvider value) {
|
||||
return value.getName(project);
|
||||
}
|
||||
}).showInBestPositionFor(editor);
|
||||
}
|
||||
@Override
|
||||
@NotNull
|
||||
public String getTextFor(final AnnotationProvider value) {
|
||||
return value.getName(project);
|
||||
}
|
||||
}).showInBestPositionFor(editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user