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..b6ba5ee14f21 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,12 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction return getText(); } + @NotNull + @Override + public Priority getPriority() { + return Priority.LOW; + } + @Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { PsiVariable psiVariable = getVariable(element); @@ -199,13 +205,19 @@ 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; } + @NotNull + @Override + public Priority getPriority() { + return Priority.HIGH; + } + @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..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,20 +1,8 @@ -/* - * 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 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 +11,11 @@ package com.intellij.codeInsight.intention; * @see IntentionAction * @see com.intellij.codeInspection.LocalQuickFix */ -public interface HighPriorityAction { +public interface HighPriorityAction extends PriorityAction { + + @NotNull + @Override + default Priority getPriority() { + return Priority.HIGH; + } } 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..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,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 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 { + + @NotNull + @Override + 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 new file mode 100644 index 000000000000..ad5e0d3926fc --- /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 org.jetbrains.annotations.NotNull; + +/** + * Interface for {@link IntentionAction intentions} and {@link com.intellij.codeInspection.LocalQuickFix quick fixes}. + */ +public interface PriorityAction { + + enum Priority { + HIGH, + NORMAL, + LOW + } + + @NotNull + Priority getPriority(); +} 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..d7a97f5bf597 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,12 @@ public class QuickFixWrapper implements IntentionAction { return myFix; } + @NotNull + @Override + public Priority getPriority() { + return myFix instanceof PriorityAction ? ((PriorityAction)myFix).getPriority() : Priority.NORMAL; + } + @TestOnly public ProblemHighlightType getHighlightType() { return myDescriptor.getHighlightType(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/CachedIntentions.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/CachedIntentions.java index 7d2a73b7f92f..5aa8a5e688a2 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/CachedIntentions.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/CachedIntentions.java @@ -3,9 +3,11 @@ package com.intellij.codeInsight.intention.impl; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass; -import com.intellij.codeInsight.intention.*; +import com.intellij.codeInsight.intention.EmptyIntentionAction; +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.codeInsight.intention.IntentionActionDelegate; +import com.intellij.codeInsight.intention.PriorityAction; 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; @@ -292,29 +294,28 @@ public class CachedIntentions { while (a instanceof IntentionActionDelegate) { a = ((IntentionActionDelegate)a).getDelegate(); } - if (a instanceof HighPriorityAction) { - return group + 3; - } - if (a instanceof LowPriorityAction) { - return group - 3; + if (a instanceof PriorityAction) { + return group + getPriorityWeight(((PriorityAction)a).getPriority()); } if (a instanceof SuppressIntentionActionFromFix) { if (((SuppressIntentionActionFromFix)a).isShouldBeAppliedToInjectionHost() == ThreeState.NO) { return group - 1; } } - if (a instanceof QuickFixWrapper) { - final LocalQuickFix quickFix = ((QuickFixWrapper)a).getFix(); - if (quickFix instanceof HighPriorityAction) { - return group + 3; - } - if (quickFix instanceof LowPriorityAction) { - return group - 3; - } - } return group; } + private static int getPriorityWeight(PriorityAction.Priority priority) { + switch (priority) { + case HIGH: + return 3; + case LOW: + return -3; + default: + return 0; + } + } + public IntentionGroup getGroup(IntentionActionWithTextCaching action) { if (myCachedErrorFixes.contains(action)) { return IntentionGroup.ERROR;