From 4f30409292e2ac9234a32266ce757c53408631d9 Mon Sep 17 00:00:00 2001 From: Danila Ponomarenko Date: Sun, 24 Jun 2012 16:02:05 +0400 Subject: [PATCH] got rid of BaseRefactoringAction --- .../intention/impl/BaseRefactoringAction.java | 49 ------------------- .../impl/EncapsulateFieldAction.java | 9 +++- .../IntroduceVariableIntentionAction.java | 10 ++-- .../intention/impl/RefactoringAction.java | 30 ------------ .../intention/impl/RunRefactoringAction.java | 13 ++--- .../impl/IntentionHintComponent.java | 4 +- ...va => BaseRefactoringIntentionAction.java} | 2 +- .../ChangeSignatureDetectorAction.java | 5 +- 8 files changed, 26 insertions(+), 96 deletions(-) delete mode 100644 java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRefactoringAction.java delete mode 100644 java/java-impl/src/com/intellij/codeInsight/intention/impl/RefactoringAction.java rename platform/lang-impl/src/com/intellij/refactoring/{RefactoringBaseIntention.java => BaseRefactoringIntentionAction.java} (78%) diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRefactoringAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRefactoringAction.java deleted file mode 100644 index a22fe17f9301..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRefactoringAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2000-2012 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.codeInsight.intention.impl; - -import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.SyntheticElement; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; - -/** - * @author Danila Ponomarenko - */ -public abstract class BaseRefactoringAction extends PsiElementBaseIntentionAction implements RefactoringAction{ - @Override - public final boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { - return !(element instanceof SyntheticElement) && isAvailableOverride(project, editor, element); - } - - protected abstract boolean isAvailableOverride(@NotNull Project project, Editor editor, @NotNull PsiElement element); - - @Override - public final boolean startInWriteAction() { - return false; - } - - @Override - public final Icon getIcon(int flags) { - return REFACTORING_BULB; - } -} \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java index 73d10c8ef713..18ca4f74e301 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java @@ -19,6 +19,7 @@ import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.refactoring.BaseRefactoringIntentionAction; import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsHandler; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -27,7 +28,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Danila Ponomarenko */ -public class EncapsulateFieldAction extends BaseRefactoringAction { +public class EncapsulateFieldAction extends BaseRefactoringIntentionAction { @NotNull @Override @@ -42,7 +43,11 @@ public class EncapsulateFieldAction extends BaseRefactoringAction { } @Override - protected boolean isAvailableOverride(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + if (element instanceof SyntheticElement){ + return false; + } + final PsiField field = getField(element); return field != null && !field.hasModifierProperty(PsiModifier.FINAL) && !field.hasModifierProperty(PsiModifier.PRIVATE); } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableIntentionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableIntentionAction.java index 491114620aa1..6f8821af27bd 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableIntentionAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableIntentionAction.java @@ -20,15 +20,15 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.refactoring.BaseRefactoringIntentionAction; import com.intellij.refactoring.introduceVariable.IntroduceVariableHandler; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author Danila Ponomarenko */ -public class IntroduceVariableIntentionAction extends BaseRefactoringAction { +public class IntroduceVariableIntentionAction extends BaseRefactoringIntentionAction { @NotNull @Override public String getText() { @@ -42,7 +42,11 @@ public class IntroduceVariableIntentionAction extends BaseRefactoringAction { } @Override - protected boolean isAvailableOverride(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + if (element instanceof SyntheticElement){ + return false; + } + final PsiExpressionStatement statement = PsiTreeUtil.getParentOfType(element,PsiExpressionStatement.class); if (statement == null){ return false; diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/RefactoringAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/RefactoringAction.java deleted file mode 100644 index b581af515168..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/RefactoringAction.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2000-2012 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.codeInsight.intention.impl; - -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInsight.intention.LowPriorityAction; -import com.intellij.icons.AllIcons; -import com.intellij.openapi.util.Iconable; - -import javax.swing.*; - -/** - * @author Danila Ponomarenko - */ -public interface RefactoringAction extends IntentionAction, Iconable, LowPriorityAction { - public static final Icon REFACTORING_BULB = AllIcons.Actions.RefactoringBulb; -} \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java index 2cd350667d25..fb664dfbd516 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -17,7 +17,8 @@ package com.intellij.codeInsight.intention.impl; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiElement; +import com.intellij.refactoring.BaseRefactoringIntentionAction; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -28,7 +29,7 @@ import javax.swing.*; * User: anna * Date: 9/5/11 */ -public class RunRefactoringAction implements RefactoringAction { +public class RunRefactoringAction extends BaseRefactoringIntentionAction { private final RefactoringActionHandler myHandler; private final String myCommandName; @@ -50,13 +51,13 @@ public class RunRefactoringAction implements RefactoringAction { } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { return true; } @Override - public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - myHandler.invoke(project, editor, file, null); + public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + myHandler.invoke(project, editor, element.getContainingFile(), null); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java index 18778111ef20..a68a505b961e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java @@ -47,7 +47,7 @@ import com.intellij.openapi.ui.popup.LightweightWindowEvent; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.util.Disposer; import com.intellij.psi.PsiFile; -import com.intellij.refactoring.RefactoringBaseIntention; +import com.intellij.refactoring.BaseRefactoringIntentionAction; import com.intellij.ui.HintHint; import com.intellij.ui.LightweightHint; import com.intellij.ui.RowIcon; @@ -304,7 +304,7 @@ public class IntentionHintComponent extends JPanel implements Disposable, Scroll boolean showRefactoringsBulb = false; for (HighlightInfo.IntentionActionDescriptor descriptor : intentions.inspectionFixesToShow) { - if (descriptor.getAction() instanceof RefactoringBaseIntention) { + if (descriptor.getAction() instanceof BaseRefactoringIntentionAction) { showRefactoringsBulb = true; break; } diff --git a/platform/lang-impl/src/com/intellij/refactoring/RefactoringBaseIntention.java b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringIntentionAction.java similarity index 78% rename from platform/lang-impl/src/com/intellij/refactoring/RefactoringBaseIntention.java rename to platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringIntentionAction.java index 490e5def12e9..a39fecc749db 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/RefactoringBaseIntention.java +++ b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringIntentionAction.java @@ -11,7 +11,7 @@ import javax.swing.*; * User: anna * Date: 11/11/11 */ -public abstract class RefactoringBaseIntention extends PsiElementBaseIntentionAction implements Iconable, HighPriorityAction { +public abstract class BaseRefactoringIntentionAction extends PsiElementBaseIntentionAction implements Iconable, HighPriorityAction { public static final Icon REFACTORING_BULB = AllIcons.Actions.RefactoringBulb; @Override diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDetectorAction.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDetectorAction.java index 627b1085c74e..5fe93571cd32 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDetectorAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDetectorAction.java @@ -15,12 +15,11 @@ */ package com.intellij.refactoring.changeSignature; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.refactoring.RefactoringBaseIntention; +import com.intellij.refactoring.BaseRefactoringIntentionAction; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -28,7 +27,7 @@ import org.jetbrains.annotations.NotNull; * User: anna * Date: Sep 6, 2010 */ -public class ChangeSignatureDetectorAction extends RefactoringBaseIntention { +public class ChangeSignatureDetectorAction extends BaseRefactoringIntentionAction { public static final String CHANGE_SIGNATURE = "Apply signature change"; public static final String NEW_NAME = "Apply new name";