Merge branch 'daniil/priority-action'

# Conflicts:
#	platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java
This commit is contained in:
Daniil Ovchinnikov
2018-03-07 11:36:29 +03:00
7 changed files with 85 additions and 85 deletions
@@ -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<PsiType, String> 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;
@@ -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;
}
}
@@ -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.
* <p/>
* Implement {@link HighPriorityAction HighPriorityAction} or
* {@link LowPriorityAction LowPriorityAction} to change ordering.
* Implement {@link HighPriorityAction HighPriorityAction},
* {@link LowPriorityAction LowPriorityAction} or {@link PriorityAction} to change ordering.
* <p/>
* Can be {@link com.intellij.openapi.project.DumbAware}.
*
@@ -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;
}
}
@@ -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();
}
@@ -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();
@@ -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;