disable replace constructor with builder action for classes without constructors...
authoranna <Anna.Kozlova@jetbrains.com>
Thu, 19 Jan 2012 20:20:41 +0000 (21:20 +0100)
committeranna <Anna.Kozlova@jetbrains.com>
Thu, 19 Jan 2012 20:20:41 +0000 (21:20 +0100)
java/java-impl/src/com/intellij/refactoring/actions/ReplaceConstructorWithBuilderAction.java
java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderHandler.java
platform/platform-resources-en/src/messages/ActionsBundle.properties

index eae1fecad7037eb5aeacc203a7deac11be86b0e5..429aeed4e6c069ed752a9dfd3fbcb631cf436ca7 100644 (file)
 package com.intellij.refactoring.actions;
 
 import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.psi.PsiClass;
 import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
 import com.intellij.refactoring.RefactoringActionHandler;
 import com.intellij.refactoring.replaceConstructorWithBuilder.ReplaceConstructorWithBuilderHandler;
 
@@ -30,6 +33,14 @@ public class ReplaceConstructorWithBuilderAction extends BaseRefactoringAction{
     return true;
   }
 
+  @Override
+  protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file, DataContext context) {
+    final int offset = editor.getCaretModel().getOffset();
+    final PsiElement elementAt = file.findElementAt(offset);
+    final PsiClass psiClass = ReplaceConstructorWithBuilderHandler.getParentNamedClass(elementAt);
+    return psiClass != null && psiClass.getConstructors().length > 0;
+  }
+
   protected boolean isEnabledOnElements(final PsiElement[] elements) {
     return false;
   }
index 5429f24eac3c090c2c786fc51b507d83ccc74205..d7098ab6976afd7cddd5dc1a813a2a785c9562a2 100644 (file)
@@ -51,7 +51,7 @@ public class ReplaceConstructorWithBuilderHandler implements RefactoringActionHa
   }
 
   @Nullable
-  private static PsiClass getParentNamedClass(PsiElement element) {
+  public static PsiClass getParentNamedClass(PsiElement element) {
     final PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
     if (psiClass instanceof PsiAnonymousClass) {
       return getParentNamedClass(psiClass);
index ecd686600376e6e6e117c0d53193b141048a7370..b56ff755625e497ca0385f6750c80f5da93b24bb 100644 (file)
@@ -1196,7 +1196,7 @@ action.NewModuleInGroup.text=Module
 action.WrapReturnValue.text=Wrap Method Re_turn Value...
 action.WrapReturnValue.description=Wrap return value of the specified method with object
 action.ReplaceConstructorWithBuilder.text=Replace Constructor with Builder...
-action.ReplaceConstructorWithBuilder.description=Replace Constructor with Builder
+action.ReplaceConstructorWithBuilder.description=Replace current class constructors calls with chained calls to the builder
 action.WelcomeScreen.ShowTips.text=Tips of the Day
 action.WelcomeScreen.ShowTips.description=Learn how to increase your coding productivity.
 action.ShelvedChanges.ShowHideDeleted.text=Show/Hide Applied Shelved Changes