From c087248ed304c9f2cb212ce6ad684777f18edbe7 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Fri, 9 Feb 2018 17:05:16 +0300 Subject: [PATCH 1/3] add and use PriorityAction --- .../ConvertFieldToAtomicIntention.java | 18 ++++++-- .../intention/HighPriorityAction.java | 26 +++++------- .../intention/IntentionAction.java | 20 ++------- .../intention/LowPriorityAction.java | 27 +++++------- .../codeInsight/intention/PriorityAction.java | 19 +++++++++ .../SuppressIntentionActionFromFix.java | 24 ++++------- .../codeInspection/ex/QuickFixWrapper.java | 24 ++++------- .../intention/impl/IntentionListStep.java | 41 +------------------ 8 files changed, 75 insertions(+), 124 deletions(-) create mode 100644 platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java index 8e09c9235005..fbdda96b89d4 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java @@ -1,8 +1,8 @@ +// Copyright 2000-2018 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.refactoring.typeMigration.intentions; import com.intellij.codeInsight.FileModificationService; -import com.intellij.codeInsight.intention.HighPriorityAction; -import com.intellij.codeInsight.intention.LowPriorityAction; +import com.intellij.codeInsight.intention.PriorityAction; import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.application.WriteAction; @@ -33,7 +33,7 @@ import static com.intellij.util.ObjectUtils.assertNotNull; * @author anna * @since 26-Aug-2009 */ -public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction implements LowPriorityAction { +public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction implements PriorityAction { private static final Logger LOG = Logger.getInstance(ConvertFieldToAtomicIntention.class); private final Map myFromToMap = ContainerUtil.newHashMap(); @@ -58,6 +58,11 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction return getText(); } + @Override + public int getPriorityModifier(@NotNull Project project) { + return PriorityAction.LOWER_PRIORITY; + } + @Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { PsiVariable psiVariable = getVariable(element); @@ -199,13 +204,18 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction return false; } - public static class ConvertNonFinalLocalToAtomicFix extends ConvertFieldToAtomicIntention implements HighPriorityAction { + public static class ConvertNonFinalLocalToAtomicFix extends ConvertFieldToAtomicIntention { private final PsiElement myContext; public ConvertNonFinalLocalToAtomicFix(PsiElement context) { myContext = context; } + @Override + public int getPriorityModifier(@NotNull Project project) { + return PriorityAction.HIGHER_PRIORITY; + } + @Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { return getVariable(element) != null; diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java index d389ec4208d0..0b4103cad028 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java @@ -1,20 +1,9 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 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; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + /** * Marker interface for intentions and quick fixes. * Marked actions are shown higher in the list of available quick fixes. @@ -23,5 +12,10 @@ package com.intellij.codeInsight.intention; * @see IntentionAction * @see com.intellij.codeInspection.LocalQuickFix */ -public interface HighPriorityAction { +public interface HighPriorityAction extends PriorityAction { + + @Override + default int getPriorityModifier(@NotNull Project project) { + return HIGHER_PRIORITY; + } } diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionAction.java index 1fca3dd0f684..070ce965cbbc 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionAction.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 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; import com.intellij.openapi.application.Application; @@ -32,8 +18,8 @@ import org.jetbrains.annotations.NotNull; * Implement {@link Iconable Iconable} interface to * change icon in intention popup menu. *

- * Implement {@link HighPriorityAction HighPriorityAction} or - * {@link LowPriorityAction LowPriorityAction} to change ordering. + * Implement {@link HighPriorityAction HighPriorityAction}, + * {@link LowPriorityAction LowPriorityAction} or {@link PriorityAction} to change ordering. *

* Can be {@link com.intellij.openapi.project.DumbAware}. * diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java index b2b241b100a9..ee48cca8c9e8 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java @@ -1,24 +1,19 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 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; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + /** * Marker interface for intentions and quick fixes. * Marked actions are shown lower in the list of available quick fixes. * * @author Max Ishchenko */ -public interface LowPriorityAction { } +public interface LowPriorityAction extends PriorityAction { + + @Override + default int getPriorityModifier(@NotNull Project project) { + return LOWER_PRIORITY; + } +} diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java new file mode 100644 index 000000000000..59e26ecf9824 --- /dev/null +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java @@ -0,0 +1,19 @@ +// Copyright 2000-2018 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; + +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +/** + * Interface for {@link IntentionAction intentions} and {@link com.intellij.codeInspection.LocalQuickFix quick fixes}. + */ +public interface PriorityAction { + + int HIGHER_PRIORITY = 3; + int LOWER_PRIORITY = -3; + + /** + * @return a value (possibly negative) which will be added to default action weight + */ + int getPriorityModifier(@NotNull Project project); +} diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java index 9bc6190b2bda..71cb1954284c 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java @@ -1,20 +1,7 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 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.codeInspection; +import com.intellij.codeInsight.intention.PriorityAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; @@ -25,7 +12,7 @@ import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class SuppressIntentionActionFromFix extends SuppressIntentionAction { +public class SuppressIntentionActionFromFix extends SuppressIntentionAction implements PriorityAction { private final SuppressQuickFix myFix; private SuppressIntentionActionFromFix(@NotNull SuppressQuickFix fix) { @@ -98,4 +85,9 @@ public class SuppressIntentionActionFromFix extends SuppressIntentionAction { public boolean isSuppressAll() { return myFix.isSuppressAll(); } + + @Override + public int getPriorityModifier(@NotNull Project project) { + return isShouldBeAppliedToInjectionHost() == ThreeState.NO ? -1 : 0; + } } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java index 29247b78128d..a12406b9c746 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java @@ -1,23 +1,10 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 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.codeInspection.ex; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.codeInsight.intention.PriorityAction; import com.intellij.codeInspection.LocalQuickFix; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemHighlightType; @@ -36,7 +23,7 @@ import org.jetbrains.annotations.TestOnly; /** * @author max */ -public class QuickFixWrapper implements IntentionAction { +public class QuickFixWrapper implements IntentionAction, PriorityAction { private static final Logger LOG = Logger.getInstance("com.intellij.codeInspection.ex.QuickFixWrapper"); private final ProblemDescriptor myDescriptor; @@ -108,6 +95,11 @@ public class QuickFixWrapper implements IntentionAction { return myFix; } + @Override + public int getPriorityModifier(@NotNull Project project) { + return myFix instanceof PriorityAction ? ((PriorityAction)myFix).getPriorityModifier(project) : 0; + } + @TestOnly public ProblemHighlightType getHighlightType() { return myDescriptor.getHighlightType(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java index 00e7c2afce50..1577009b3dc0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 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; @@ -21,8 +7,6 @@ import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass; import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.intention.*; import com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings; -import com.intellij.codeInspection.LocalQuickFix; -import com.intellij.codeInspection.SuppressIntentionActionFromFix; import com.intellij.codeInspection.ex.QuickFixWrapper; import com.intellij.concurrency.ConcurrentCollectionFactory; import com.intellij.icons.AllIcons; @@ -35,7 +19,6 @@ import com.intellij.openapi.util.Iconable; import com.intellij.psi.*; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.util.PsiUtilBase; -import com.intellij.util.ThreeState; import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashSet; import gnu.trove.TObjectHashingStrategy; @@ -384,27 +367,7 @@ public class IntentionListStep implements ListPopupStep Date: Fri, 9 Feb 2018 17:25:58 +0300 Subject: [PATCH 2/3] remove project parameter from PriorityAction#getPriorityModifier --- .../intentions/ConvertFieldToAtomicIntention.java | 4 ++-- .../intellij/codeInsight/intention/HighPriorityAction.java | 5 +---- .../intellij/codeInsight/intention/LowPriorityAction.java | 5 +---- .../com/intellij/codeInsight/intention/PriorityAction.java | 5 +---- .../codeInspection/SuppressIntentionActionFromFix.java | 2 +- .../src/com/intellij/codeInspection/ex/QuickFixWrapper.java | 4 ++-- .../codeInsight/intention/impl/IntentionListStep.java | 2 +- 7 files changed, 9 insertions(+), 18 deletions(-) diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java index fbdda96b89d4..576129610a27 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java @@ -59,7 +59,7 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction } @Override - public int getPriorityModifier(@NotNull Project project) { + public int getPriorityModifier() { return PriorityAction.LOWER_PRIORITY; } @@ -212,7 +212,7 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction } @Override - public int getPriorityModifier(@NotNull Project project) { + public int getPriorityModifier() { return PriorityAction.HIGHER_PRIORITY; } diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java index 0b4103cad028..af156755e077 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java @@ -1,9 +1,6 @@ // Copyright 2000-2018 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; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; - /** * Marker interface for intentions and quick fixes. * Marked actions are shown higher in the list of available quick fixes. @@ -15,7 +12,7 @@ import org.jetbrains.annotations.NotNull; public interface HighPriorityAction extends PriorityAction { @Override - default int getPriorityModifier(@NotNull Project project) { + default int getPriorityModifier() { return HIGHER_PRIORITY; } } diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java index ee48cca8c9e8..80e885ca4b7d 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java @@ -1,9 +1,6 @@ // Copyright 2000-2018 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; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; - /** * Marker interface for intentions and quick fixes. * Marked actions are shown lower in the list of available quick fixes. @@ -13,7 +10,7 @@ import org.jetbrains.annotations.NotNull; public interface LowPriorityAction extends PriorityAction { @Override - default int getPriorityModifier(@NotNull Project project) { + default int getPriorityModifier() { return LOWER_PRIORITY; } } diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java index 59e26ecf9824..d3f9388de486 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java @@ -1,9 +1,6 @@ // Copyright 2000-2018 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; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; - /** * Interface for {@link IntentionAction intentions} and {@link com.intellij.codeInspection.LocalQuickFix quick fixes}. */ @@ -15,5 +12,5 @@ public interface PriorityAction { /** * @return a value (possibly negative) which will be added to default action weight */ - int getPriorityModifier(@NotNull Project project); + int getPriorityModifier(); } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java index 71cb1954284c..df0de8ad1484 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java @@ -87,7 +87,7 @@ public class SuppressIntentionActionFromFix extends SuppressIntentionAction impl } @Override - public int getPriorityModifier(@NotNull Project project) { + public int getPriorityModifier() { return isShouldBeAppliedToInjectionHost() == ThreeState.NO ? -1 : 0; } } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java index a12406b9c746..e3d27946daa3 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java @@ -96,8 +96,8 @@ public class QuickFixWrapper implements IntentionAction, PriorityAction { } @Override - public int getPriorityModifier(@NotNull Project project) { - return myFix instanceof PriorityAction ? ((PriorityAction)myFix).getPriorityModifier(project) : 0; + public int getPriorityModifier() { + return myFix instanceof PriorityAction ? ((PriorityAction)myFix).getPriorityModifier() : 0; } @TestOnly diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java index 1577009b3dc0..8bde53a1e562 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java @@ -367,7 +367,7 @@ public class IntentionListStep implements ListPopupStep Date: Wed, 14 Feb 2018 17:44:52 +0300 Subject: [PATCH 3/3] define supported priorities for actions in enum --- .../ConvertFieldToAtomicIntention.java | 10 ++++---- .../intention/HighPriorityAction.java | 7 ++++-- .../intention/LowPriorityAction.java | 7 ++++-- .../codeInsight/intention/PriorityAction.java | 15 +++++++----- .../SuppressIntentionActionFromFix.java | 24 ++++++++++++------- .../codeInspection/ex/QuickFixWrapper.java | 5 ++-- .../intention/impl/IntentionListStep.java | 23 +++++++++++++++++- 7 files changed, 66 insertions(+), 25 deletions(-) diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java index 576129610a27..b6ba5ee14f21 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertFieldToAtomicIntention.java @@ -58,9 +58,10 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction return getText(); } + @NotNull @Override - public int getPriorityModifier() { - return PriorityAction.LOWER_PRIORITY; + public Priority getPriority() { + return Priority.LOW; } @Override @@ -211,9 +212,10 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction myContext = context; } + @NotNull @Override - public int getPriorityModifier() { - return PriorityAction.HIGHER_PRIORITY; + public Priority getPriority() { + return Priority.HIGH; } @Override diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java index af156755e077..046190db1ad8 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/HighPriorityAction.java @@ -1,6 +1,8 @@ // Copyright 2000-2018 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; +import org.jetbrains.annotations.NotNull; + /** * Marker interface for intentions and quick fixes. * Marked actions are shown higher in the list of available quick fixes. @@ -11,8 +13,9 @@ package com.intellij.codeInsight.intention; */ public interface HighPriorityAction extends PriorityAction { + @NotNull @Override - default int getPriorityModifier() { - return HIGHER_PRIORITY; + default Priority getPriority() { + return Priority.HIGH; } } diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java index 80e885ca4b7d..8796e5d03235 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/LowPriorityAction.java @@ -1,6 +1,8 @@ // Copyright 2000-2018 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; +import org.jetbrains.annotations.NotNull; + /** * Marker interface for intentions and quick fixes. * Marked actions are shown lower in the list of available quick fixes. @@ -9,8 +11,9 @@ package com.intellij.codeInsight.intention; */ public interface LowPriorityAction extends PriorityAction { + @NotNull @Override - default int getPriorityModifier() { - return LOWER_PRIORITY; + default Priority getPriority() { + return Priority.LOW; } } diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java index d3f9388de486..ad5e0d3926fc 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/PriorityAction.java @@ -1,16 +1,19 @@ // Copyright 2000-2018 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; +import org.jetbrains.annotations.NotNull; + /** * Interface for {@link IntentionAction intentions} and {@link com.intellij.codeInspection.LocalQuickFix quick fixes}. */ public interface PriorityAction { - int HIGHER_PRIORITY = 3; - int LOWER_PRIORITY = -3; + enum Priority { + HIGH, + NORMAL, + LOW + } - /** - * @return a value (possibly negative) which will be added to default action weight - */ - int getPriorityModifier(); + @NotNull + Priority getPriority(); } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java index df0de8ad1484..9bc6190b2bda 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java @@ -1,7 +1,20 @@ -// Copyright 2000-2018 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. +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInspection; -import com.intellij.codeInsight.intention.PriorityAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; @@ -12,7 +25,7 @@ import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class SuppressIntentionActionFromFix extends SuppressIntentionAction implements PriorityAction { +public class SuppressIntentionActionFromFix extends SuppressIntentionAction { private final SuppressQuickFix myFix; private SuppressIntentionActionFromFix(@NotNull SuppressQuickFix fix) { @@ -85,9 +98,4 @@ public class SuppressIntentionActionFromFix extends SuppressIntentionAction impl public boolean isSuppressAll() { return myFix.isSuppressAll(); } - - @Override - public int getPriorityModifier() { - return isShouldBeAppliedToInjectionHost() == ThreeState.NO ? -1 : 0; - } } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java index e3d27946daa3..d7a97f5bf597 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java @@ -95,9 +95,10 @@ public class QuickFixWrapper implements IntentionAction, PriorityAction { return myFix; } + @NotNull @Override - public int getPriorityModifier() { - return myFix instanceof PriorityAction ? ((PriorityAction)myFix).getPriorityModifier() : 0; + public Priority getPriority() { + return myFix instanceof PriorityAction ? ((PriorityAction)myFix).getPriority() : Priority.NORMAL; } @TestOnly diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java index 8bde53a1e562..fd7153adbb8b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java @@ -7,6 +7,7 @@ import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass; import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.intention.*; import com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings; +import com.intellij.codeInspection.SuppressIntentionActionFromFix; import com.intellij.codeInspection.ex.QuickFixWrapper; import com.intellij.concurrency.ConcurrentCollectionFactory; import com.intellij.icons.AllIcons; @@ -19,6 +20,7 @@ import com.intellij.openapi.util.Iconable; import com.intellij.psi.*; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.util.PsiUtilBase; +import com.intellij.util.ThreeState; import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashSet; import gnu.trove.TObjectHashingStrategy; @@ -367,7 +369,26 @@ public class IntentionListStep implements ListPopupStep