From 1973043b5638caab36f55db42161cd693042f63f Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 1 Mar 2018 14:52:21 +0100 Subject: [PATCH] More user-friendly API for retrieving intention actions --- .../daemon/GutterIntentionsTest.java | 19 ++------------ .../daemon/impl/ShowIntentionsPass.java | 26 ++++++++----------- .../impl/ShowIntentionActionsHandler.java | 7 ++--- .../ide/actions/ApplyIntentionAction.java | 19 ++------------ .../impl/CodeInsightTestFixtureImpl.java | 3 +-- 5 files changed, 18 insertions(+), 56 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/GutterIntentionsTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/GutterIntentionsTest.java index 6f9cecfd2bbe..d05c680ece00 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/GutterIntentionsTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/GutterIntentionsTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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.java.codeInsight.daemon; import com.intellij.codeInsight.daemon.impl.HighlightInfo; @@ -44,8 +30,7 @@ public class GutterIntentionsTest extends LightCodeInsightFixtureTestCase { "}"); assertSize(1, myFixture.findGuttersAtCaret()); - ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo(); - ShowIntentionsPass.getActionsToShow(getEditor(), getFile(), intentions, -1); + ShowIntentionsPass.IntentionsInfo intentions = ShowIntentionsPass.getActionsToShow(getEditor(), getFile()); final HighlightInfo.IntentionActionDescriptor intentionActionDescriptor = assertOneElement(intentions.guttersToShow); List options = intentionActionDescriptor.getOptions(myFixture.getElementAtCaret(), getEditor()); assertNotNull(options); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java index 0f9b149d4933..47466e76bf8e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.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.daemon.impl; @@ -302,6 +288,16 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass { } } + /** + * Returns the list of actions to show in the Alt-Enter popup at the caret offset in the given editor. + */ + @NotNull + public static IntentionsInfo getActionsToShow(@NotNull Editor hostEditor, @NotNull PsiFile hostFile) { + IntentionsInfo result = new IntentionsInfo(); + getActionsToShow(hostEditor, hostFile, result, -1); + return result; + } + public static void getActionsToShow(@NotNull final Editor hostEditor, @NotNull final PsiFile hostFile, @NotNull final IntentionsInfo intentions, diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java index 7c01b2478fad..636d18e6aab4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 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-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; @@ -65,8 +63,7 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project); letAutoImportComplete(editor, file, codeAnalyzer); - ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo(); - ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1); + ShowIntentionsPass.IntentionsInfo intentions = ShowIntentionsPass.getActionsToShow(editor, file); IntentionHintComponent hintComponent = codeAnalyzer.getLastIntentionHint(); if (hintComponent != null) { IntentionHintComponent.PopupUpdateResult result = hintComponent.isForEditor(editor) diff --git a/platform/lang-impl/src/com/intellij/ide/actions/ApplyIntentionAction.java b/platform/lang-impl/src/com/intellij/ide/actions/ApplyIntentionAction.java index fe5cb5c59cd2..1580ee645e53 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/ApplyIntentionAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/ApplyIntentionAction.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.ide.actions; import com.intellij.codeInsight.daemon.impl.HighlightInfo; @@ -61,8 +47,7 @@ public class ApplyIntentionAction extends AnAction { @Nullable public static ApplyIntentionAction[] getAvailableIntentions(@NotNull Editor editor, @NotNull PsiFile file) { - ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo(); - ShowIntentionsPass.getActionsToShow(editor, file, info, -1); + ShowIntentionsPass.IntentionsInfo info = ShowIntentionsPass.getActionsToShow(editor, file); if (info.isEmpty()) return null; final List actions = new ArrayList<>(); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index ede785afb29b..ffc02bb1402d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -249,8 +249,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull private static List doGetAvailableIntentions(@NotNull Editor editor, @NotNull PsiFile file) { - ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo(); - ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1); + ShowIntentionsPass.IntentionsInfo intentions = ShowIntentionsPass.getActionsToShow(editor, file); List result = new ArrayList<>(); IntentionListStep intentionListStep = new IntentionListStep(null, intentions, editor, file, file.getProject());