com.intellij.refactoring.RefactoringBundle Java Examples

The following examples show how to use com.intellij.refactoring.RefactoringBundle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MoveFilesOrDirectoriesViewDescriptor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public MoveFilesOrDirectoriesViewDescriptor(PsiElement[] elementsToMove, PsiDirectory newParent) {
  myElementsToMove = elementsToMove;
  if (elementsToMove.length == 1) {
    myProcessedElementsHeader = StringUtil.capitalize(RefactoringBundle.message("move.single.element.elements.header",
                                                                                UsageViewUtil.getType(elementsToMove[0]),
                                                                                newParent.getVirtualFile().getPresentableUrl()));
    myCodeReferencesText = RefactoringBundle.message("references.in.code.to.0.1",
                                                     UsageViewUtil.getType(elementsToMove[0]), UsageViewUtil.getLongName(elementsToMove[0]));
  }
  else {
    if (elementsToMove[0] instanceof PsiFile) {
      myProcessedElementsHeader =
        StringUtil.capitalize(RefactoringBundle.message("move.files.elements.header", newParent.getVirtualFile().getPresentableUrl()));
    }
    else if (elementsToMove[0] instanceof PsiDirectory){
      myProcessedElementsHeader = StringUtil
        .capitalize(RefactoringBundle.message("move.directories.elements.header", newParent.getVirtualFile().getPresentableUrl()));
    }
    myCodeReferencesText = RefactoringBundle.message("references.found.in.code");
  }
}
 
Example #2
Source File: JavaExtractSuperBaseDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
protected JPanel createDestinationRootPanel() {
  final List<VirtualFile> sourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject);
  if (sourceRoots.size() <= 1) return super.createDestinationRootPanel();
  final JPanel panel = new JPanel(new BorderLayout());
  panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
  final JBLabel label = new JBLabel(RefactoringBundle.message("target.destination.folder"));
  panel.add(label, BorderLayout.NORTH);
  label.setLabelFor(myDestinationFolderComboBox);
  myDestinationFolderComboBox.setData(myProject, myTargetDirectory, new Pass<String>() {
    @Override
    public void pass(String s) {
    }
  }, ((PackageNameReferenceEditorCombo)myPackageNameField).getChildComponent());
  panel.add(myDestinationFolderComboBox, BorderLayout.CENTER);
  return panel;
}
 
Example #3
Source File: FlowRenameDialog.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
protected void doAction() {
    LOG.assertTrue(this.myElement.isValid());
    CommandProcessor.getInstance().executeCommand(this.myProject, () -> {
        ApplicationManager.getApplication().runWriteAction(() -> {
            try {
                final List<XmlTag> refs = MuleConfigUtils.findFlowRefsForFlow(this.myTag);
                this.myTag.getAttribute(MuleConfigConstants.NAME_ATTRIBUTE).setValue(this.getNewName());
                for (XmlTag ref : refs) {
                    ref.getAttribute(MuleConfigConstants.NAME_ATTRIBUTE).setValue(this.getNewName());
                }
            } catch (IncorrectOperationException var2) {
                LOG.error(var2);
            }

        });
    }, RefactoringBundle.message("rename.title"), (Object)null);
    this.close(0);
}
 
Example #4
Source File: CSharpClassesViewDescriptor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
public CSharpClassesViewDescriptor(PsiElement[] elementsToMove, PsiDirectory newParent)
{
	myElementsToMove = elementsToMove;
	if(elementsToMove.length == 1)
	{
		myProcessedElementsHeader = StringUtil.capitalize(RefactoringBundle.message("move.single.element.elements.header",
				UsageViewUtil.getType(elementsToMove[0]),
				newParent.getVirtualFile().getPresentableUrl()));
		myCodeReferencesText = RefactoringBundle.message("references.in.code.to.0.1",
				UsageViewUtil.getType(elementsToMove[0]), UsageViewUtil.getLongName(elementsToMove[0]));
	}
	else
	{
		if(elementsToMove[0] instanceof PsiFile)
		{
			myProcessedElementsHeader =
					StringUtil.capitalize(RefactoringBundle.message("move.files.elements.header", newParent.getVirtualFile().getPresentableUrl()));
		}
		else if(elementsToMove[0] instanceof PsiDirectory)
		{
			myProcessedElementsHeader = StringUtil
					.capitalize(RefactoringBundle.message("move.directories.elements.header", newParent.getVirtualFile().getPresentableUrl()));
		}
		myCodeReferencesText = RefactoringBundle.message("references.found.in.code");
	}
}
 
Example #5
Source File: ExtractSuperclassDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(RefactoringBundle.message("members.to.form.superclass"),
                                                                             myMemberInfos, RefactoringBundle.message("make.abstract"));
  panel.add(memberSelectionPanel, BorderLayout.CENTER);
  final MemberInfoModel<PsiMember, MemberInfo> memberInfoModel =
    new UsesAndInterfacesDependencyMemberInfoModel<PsiMember, MemberInfo>(mySourceClass, null, false, myContainmentVerifier) {
      @Override
      public Boolean isFixedAbstract(MemberInfo member) {
        return Boolean.TRUE;
      }
    };
  memberInfoModel.memberInfoChanged(new MemberInfoChange<PsiMember, MemberInfo>(myMemberInfos));
  memberSelectionPanel.getTable().setMemberInfoModel(memberInfoModel);
  memberSelectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);

  panel.add(myDocCommentPanel, BorderLayout.EAST);

  return panel;
}
 
Example #6
Source File: ExtractSuperclassHandler.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  int offset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(offset);
  while (true) {
    if (element == null || element instanceof PsiFile) {
      String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.class"));
      CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.EXTRACT_SUPERCLASS);
      return;
    }
    if (element instanceof PsiClass) {
      invoke(project, new PsiElement[]{element}, dataContext);
      return;
    }
    element = element.getParent();
  }
}
 
Example #7
Source File: HaxePushDownDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(
    RefactoringBundle.message("members.to.be.pushed.down.panel.title"),
    myMemberInfos,
    RefactoringBundle.message("keep.abstract.column.header"));
  panel.add(memberSelectionPanel, BorderLayout.CENTER);

  myMemberInfoModel = new MyMemberInfoModel();
  myMemberInfoModel.memberInfoChanged(new MemberInfoChange<PsiMember, MemberInfo>(myMemberInfos));
  memberSelectionPanel.getTable().setMemberInfoModel(myMemberInfoModel);
  memberSelectionPanel.getTable().addMemberInfoChangeListener(myMemberInfoModel);


  myJavaDocPanel = new DocCommentPanel(RefactoringBundle.message("push.down.javadoc.panel.title"));
  myJavaDocPanel.setPolicy(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC);
  panel.add(myJavaDocPanel, BorderLayout.EAST);
  return panel;
}
 
Example #8
Source File: HaxePushDownHandler.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext context) {
  int offset = editor.getCaretModel().getOffset();
  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  PsiElement element = file.findElementAt(offset);
  while (true) {
    if (element == null || element instanceof PsiFile) {
      String message = RefactoringBundle.getCannotRefactorMessage(
        RefactoringBundle.message("the.caret.should.be.positioned.inside.a.class.to.push.members.from"));
      CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PUSH_DOWN);
      return;
    }

    if (element instanceof HaxeClassDeclaration || element instanceof HaxeFieldDeclaration || element instanceof HaxeMethod) {
      //if (element instanceof JspClass) {
      //  RefactoringMessageUtil.showNotSupportedForJspClassesError(project, editor, REFACTORING_NAME, HelpID.MEMBERS_PUSH_DOWN);
      //  return;
      //}
      invoke(project, new PsiElement[]{element}, context);
      return;
    }
    element = element.getParent();
  }
}
 
Example #9
Source File: ExtractInterfaceHandler.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  int offset = editor.getCaretModel().getOffset();
  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  PsiElement element = file.findElementAt(offset);
  while (true) {
    if (element == null || element instanceof PsiFile) {
      String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.class"));
      CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.EXTRACT_INTERFACE);
      return;
    }
    if (element instanceof PsiClass && !(element instanceof PsiAnonymousClass)) {
      invoke(project, new PsiElement[]{element}, dataContext);
      return;
    }
    element = element.getParent();
  }
}
 
Example #10
Source File: CopyFilesOrDirectoriesDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setMultipleElementCopyLabel(PsiElement[] elements) {
  boolean allFiles = true;
  boolean allDirectories = true;
  for (PsiElement element : elements) {
    if (element instanceof PsiDirectory) {
      allFiles = false;
    }
    else {
      allDirectories = false;
    }
  }
  if (allFiles) {
    myInformationLabel.setText(RefactoringBundle.message("copy.files.copy.specified.files.label"));
  }
  else if (allDirectories) {
    myInformationLabel.setText(RefactoringBundle.message("copy.files.copy.specified.directories.label"));
  }
  else {
    myInformationLabel.setText(RefactoringBundle.message("copy.files.copy.specified.mixed.label"));
  }
}
 
Example #11
Source File: MoveMultipleElementsViewDescriptor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public MoveMultipleElementsViewDescriptor(PsiElement[] psiElements,
                                          String targetName) {
  myPsiElements = psiElements;
  if (psiElements.length == 1) {
    myProcessedElementsHeader = StringUtil.capitalize(
      RefactoringBundle.message("move.single.element.elements.header", UsageViewUtil.getType(psiElements[0]), targetName));
    myCodeReferencesText = RefactoringBundle
      .message("references.in.code.to.0.1", UsageViewUtil.getType(psiElements[0]), UsageViewUtil.getLongName(psiElements[0]));
  }
  else {
    if (psiElements.length > 0) {
      myProcessedElementsHeader = StringUtil.capitalize(
        RefactoringBundle
          .message("move.single.element.elements.header", StringUtil.pluralize(UsageViewUtil.getType(psiElements[0])), targetName));
    }
    myCodeReferencesText = RefactoringBundle.message("references.found.in.code");
  }
}
 
Example #12
Source File: RenameProjectAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  LOG.assertTrue(project instanceof ProjectEx);
  Module module;
  Module[] modules = ModuleManager.getInstance(project).getModules();
  if (modules.length == 1 && project.getName().equals(modules[0].getName())) {
    module = modules[0];
  }
  else {
    module = null;
  }
  Messages.showInputDialog(project, RefactoringBundle.message("enter.new.project.name"), RefactoringBundle.message("rename.project"),
                           Messages.getQuestionIcon(),
                           project.getName(),
                           new RenameProjectHandler.MyInputValidator((ProjectEx)project, module));
}
 
Example #13
Source File: ExtractSuperBaseDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected JComponent createActionComponent() {
  Box box = Box.createHorizontalBox();
  final String s = StringUtil.decapitalize(getEntityName());
  myRbExtractSuperclass = new JRadioButton();
  myRbExtractSuperclass.setText(RefactoringBundle.message("extractSuper.extract", s));
  myRbExtractSubclass = new JRadioButton();
  myRbExtractSubclass.setText(RefactoringBundle.message("extractSuper.rename.original.class", s));
  box.add(myRbExtractSuperclass);
  box.add(myRbExtractSubclass);
  box.add(Box.createHorizontalGlue());
  final ButtonGroup buttonGroup = new ButtonGroup();
  buttonGroup.add(myRbExtractSuperclass);
  buttonGroup.add(myRbExtractSubclass);
  customizeRadiobuttons(box, buttonGroup);
  myRbExtractSuperclass.setSelected(true);

  ItemListener listener = new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent e) {
      updateDialog();
    }
  };
  myRbExtractSuperclass.addItemListener(listener);
  myRbExtractSubclass.addItemListener(listener);
  return box;
}
 
Example #14
Source File: UnsafeUsagesDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  myMessagePane = new JEditorPane(UIUtil.HTML_MIME, "");
  myMessagePane.setEditable(false);
  JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myMessagePane);
  scrollPane.setPreferredSize(new Dimension(500, 400));
  panel.add(new JLabel(RefactoringBundle.message("the.following.problems.were.found")), BorderLayout.NORTH);
  panel.add(scrollPane, BorderLayout.CENTER);

  @NonNls StringBuffer buf = new StringBuffer();
  for (String description : myConflictDescriptions) {
    buf.append(description);
    buf.append("<br><br>");
  }
  myMessagePane.setText(buf.toString());
  return panel;
}
 
Example #15
Source File: RenameUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void showErrorMessage(final IncorrectOperationException e, final PsiElement element, final Project project) {
  // may happen if the file or package cannot be renamed. e.g. locked by another application
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    throw new RuntimeException(e);
    //LOG.error(e);
    //return;
  }
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      final String helpID = RenamePsiElementProcessor.forElement(element).getHelpID(element);
      String message = e.getMessage();
      if (StringUtil.isEmpty(message)) {
        message = RefactoringBundle.message("rename.not.supported");
      }
      CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("rename.title"), message, helpID, project);
    }
  });
}
 
Example #16
Source File: PsiElementRenameHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void invoke(PsiElement element, Project project, PsiElement nameSuggestionContext, @Nullable Editor editor) {
  if (element != null && !canRename(project, editor, element)) {
    return;
  }

  VirtualFile contextFile = PsiUtilCore.getVirtualFile(nameSuggestionContext);

  if (nameSuggestionContext != null &&
      nameSuggestionContext.isPhysical() &&
      (contextFile == null || !ScratchUtil.isScratch(contextFile) && !PsiManager.getInstance(project).isInProject(nameSuggestionContext))) {
    final String message = "Selected element is used from non-project files. These usages won't be renamed. Proceed anyway?";
    if (ApplicationManager.getApplication().isUnitTestMode()) throw new CommonRefactoringUtil.RefactoringErrorHintException(message);
    if (Messages.showYesNoDialog(project, message, RefactoringBundle.getCannotRefactorMessage(null), Messages.getWarningIcon()) != Messages.YES) {
      return;
    }
  }

  FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.rename");

  rename(element, project, nameSuggestionContext, editor);
}
 
Example #17
Source File: ChangeSignatureDialogBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void doAction() {
  if (myParametersTable != null) {
    TableUtil.stopEditing(myParametersTable);
  }
  String message = validateAndCommitData();
  if (message != null) {
    if (message != EXIT_SILENTLY) {
      CommonRefactoringUtil.showErrorMessage(getTitle(), message, getHelpId(), myProject);
    }
    return;
  }
  if (myMethodsToPropagateParameters != null && !mayPropagateParameters()) {
    Messages.showWarningDialog(myProject, RefactoringBundle.message("changeSignature.parameters.wont.propagate"),
                               ChangeSignatureHandler.REFACTORING_NAME);
    myMethodsToPropagateParameters = null;
  }

  invokeRefactoring(createRefactoringProcessor());
}
 
Example #18
Source File: UsedByMemberDependencyGraph.java    From consulo with Apache License 2.0 5 votes vote down vote up
public String getElementTooltip(T element) {
  final Set<? extends T> dependencies = getDependenciesOf(element);
  if (dependencies == null || dependencies.size() == 0) return null;

  ArrayList<String> strings = new ArrayList<String>();
  for (T dep : dependencies) {
    if (dep instanceof PsiNamedElement) {
      strings.add(dep.getName());
    }
  }

  if (strings.isEmpty()) return null;
  return RefactoringBundle.message("uses.0", StringUtil.join(strings, ", "));
}
 
Example #19
Source File: InlineOptionsWithSearchSettingsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final JPanel panel = new JPanel(new GridBagLayout());
  GridBagConstraints gbc = new GridBagConstraints();
  gbc.fill = GridBagConstraints.HORIZONTAL;
  gbc.weightx = 1.0;
  gbc.gridwidth = 2;
  panel.add(super.createCenterPanel(), gbc);


  myCbSearchInComments = new JCheckBox(RefactoringBundle.message("search.in.comments.and.strings"), isSearchInCommentsAndStrings());
  myCbSearchTextOccurences = new JCheckBox(RefactoringBundle.message("search.for.text.occurrences"), isSearchForTextOccurrences());
  gbc.weightx = 0;
  gbc.gridwidth = 1;
  gbc.gridy = 1;
  gbc.gridx = 0;
  panel.add(myCbSearchInComments, gbc);
  gbc.gridx = 1;
  panel.add(myCbSearchTextOccurences, gbc);
  final ActionListener actionListener = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      setEnabledSearchSettngs(myRbInlineAll.isSelected());
    }
  };
  myRbInlineThisOnly.addActionListener(actionListener);
  myRbInlineAll.addActionListener(actionListener);
  setEnabledSearchSettngs(myRbInlineAll.isSelected());
  return panel;
}
 
Example #20
Source File: UsesMemberDependencyGraph.java    From consulo with Apache License 2.0 5 votes vote down vote up
public String getElementTooltip(T element) {
  final Set<? extends T> dependencies = getDependenciesOf(element);
  if(dependencies == null || dependencies.size() == 0) return null;

  ArrayList<String> strings = new ArrayList<String>();
  for (T dep : dependencies) {
    strings.add(dep.getName());
  }

  if(strings.isEmpty()) return null;
  return RefactoringBundle.message("used.by.0", StringUtil.join(strings, ", "));
}
 
Example #21
Source File: RenameViewDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public RenameViewDescriptor(LinkedHashMap<PsiElement, String> renamesMap) {

    myElements = PsiUtilBase.toPsiElementArray(renamesMap.keySet());

    Set<String> processedElementsHeaders = new THashSet<String>();
    Set<String> codeReferences = new THashSet<String>();

    for (final PsiElement element : myElements) {
      LOG.assertTrue(element.isValid(), "Invalid element: " + element.toString());
      String newName = renamesMap.get(element);

      String prefix = "";
      if (element instanceof PsiDirectory/* || element instanceof PsiClass*/) {
        String fullName = UsageViewUtil.getLongName(element);
        int lastDot = fullName.lastIndexOf('.');
        if (lastDot >= 0) {
          prefix = fullName.substring(0, lastDot + 1);
        }
      }

      processedElementsHeaders.add(StringUtil.capitalize(
        RefactoringBundle.message("0.to.be.renamed.to.1.2", UsageViewUtil.getType(element), prefix, newName)));
      codeReferences.add(UsageViewUtil.getType(element) + " " + UsageViewUtil.getLongName(element));
    }


    myProcessedElementsHeader = StringUtil.join(ArrayUtil.toStringArray(processedElementsHeaders), ", ");
    myCodeReferencesText =  RefactoringBundle.message("references.in.code.to.0", StringUtil.join(ArrayUtil.toStringArray(codeReferences),
                                                                                                 ", "));
  }
 
Example #22
Source File: CallerChooserBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private JComponent createCallSitesViewer() {
  Splitter splitter = new Splitter(true);
  myCallerEditor = createEditor();
  myCalleeEditor = createEditor();
  final JComponent callerComponent = myCallerEditor.getComponent();
  callerComponent.setBorder(IdeBorderFactory.createTitledBorder(RefactoringBundle.message("caller.chooser.caller.method"),
                                                                false));
  splitter.setFirstComponent(callerComponent);
  final JComponent calleeComponent = myCalleeEditor.getComponent();
  calleeComponent.setBorder(IdeBorderFactory.createTitledBorder(RefactoringBundle.message("caller.chooser.callee.method"),
                                                                false));
  splitter.setSecondComponent(calleeComponent);
  splitter.setBorder(IdeBorderFactory.createRoundedBorder());
  return splitter;
}
 
Example #23
Source File: CommonRefactoringUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean checkReadOnlyStatus(@Nonnull Project project,
                                           @Nonnull Collection<? extends PsiElement> recursive,
                                           @Nonnull Collection<? extends PsiElement> flat,
                                           @Nonnull String messagePrefix,
                                           boolean notifyOnFail) {
  Collection<VirtualFile> readonly = new THashSet<>();  // not writable, but could be checked out
  Collection<VirtualFile> failed = new THashSet<>();  // those located in read-only filesystem

  boolean seenNonWritablePsiFilesWithoutVirtualFile =
          checkReadOnlyStatus(flat, false, readonly, failed) || checkReadOnlyStatus(recursive, true, readonly, failed);

  ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(readonly);
  ContainerUtil.addAll(failed, status.getReadonlyFiles());

  if (notifyOnFail && (!failed.isEmpty() || seenNonWritablePsiFilesWithoutVirtualFile && readonly.isEmpty())) {
    StringBuilder message = new StringBuilder(messagePrefix).append('\n');
    int i = 0;
    for (VirtualFile virtualFile : failed) {
      String subj = RefactoringBundle.message(virtualFile.isDirectory() ? "directory.description" : "file.description", virtualFile.getPresentableUrl());
      if (virtualFile.getFileSystem().isReadOnly()) {
        message.append(RefactoringBundle.message("0.is.located.in.a.archive.file", subj)).append('\n');
      }
      else {
        message.append(RefactoringBundle.message("0.is.read.only", subj)).append('\n');
      }
      if (i++ > 20) {
        message.append("...\n");
        break;
      }
    }
    showErrorMessage(RefactoringBundle.message("error.title"), message.toString(), null, project);
    return false;
  }

  return failed.isEmpty();
}
 
Example #24
Source File: SafeDeleteProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showUsages(final UsageInfo[] usages) {
  UsageViewPresentation presentation = new UsageViewPresentation();
  presentation.setTabText(RefactoringBundle.message("safe.delete.title"));
  presentation.setTargetsNodeText(RefactoringBundle.message("attempting.to.delete.targets.node.text"));
  presentation.setShowReadOnlyStatusAsRed(true);
  presentation.setShowCancelButton(true);
  presentation.setCodeUsagesString(RefactoringBundle.message("references.found.in.code"));
  presentation.setUsagesInGeneratedCodeString(RefactoringBundle.message("references.found.in.generated.code"));
  presentation.setNonCodeUsagesString(RefactoringBundle.message("occurrences.found.in.comments.strings.and.non.java.files"));
  presentation.setUsagesString(RefactoringBundle.message("usageView.usagesText"));

  UsageViewManager manager = UsageViewManager.getInstance(myProject);
  final UsageView usageView = showUsages(usages, presentation, manager);
  usageView.addPerformOperationAction(new RerunSafeDelete(myProject, myElements, usageView), RefactoringBundle.message("retry.command"), null,
                                      RefactoringBundle.message("rerun.safe.delete"));
  usageView.addPerformOperationAction(new Runnable() {
    @Override
    public void run() {
      UsageInfo[] preprocessedUsages = usages;
      for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
        preprocessedUsages = delegate.preprocessUsages(myProject, preprocessedUsages);
        if (preprocessedUsages == null) return;
      }
      final UsageInfo[] filteredUsages = UsageViewUtil.removeDuplicatedUsages(preprocessedUsages);
      execute(filteredUsages);
    }
  }, "Delete Anyway", RefactoringBundle.message("usageView.need.reRun"), RefactoringBundle.message("usageView.doAction"));
}
 
Example #25
Source File: HaxePullUpHandler.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext context) {
  int offset = editor.getCaretModel().getOffset();
  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  PsiElement element = file.findElementAt(offset);
  //HaxeClassDeclaration classDeclaration;
  //PsiElement parentElement;

  while (true) {
    if (element == null || element instanceof PsiFile) {
      String message = RefactoringBundle
        .getCannotRefactorMessage(RefactoringBundle.message("the.caret.should.be.positioned.inside.a.class.to.pull.members.from"));
      CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
      return;
    }
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, element)) return;

    /*classDeclaration = PsiTreeUtil.getParentOfType(element, HaxeClassDeclaration.class, false);

    parentElement = null;
    parentElement = PsiTreeUtil.getParentOfType(element, HaxeVarDeclaration.class, false);
    if (parentElement == null) {
      parentElement = PsiTreeUtil.getParentOfType(element, HaxeFunctionDeclarationWithAttributes.class, false);
    }*/

    if (element instanceof HaxeClassDeclaration || element instanceof HaxeInterfaceDeclaration || element instanceof PsiField || element instanceof PsiMethod) {
      invoke(project, new PsiElement[]{element}, context);
      return;
    }

    //if (classDeclaration != null) {
    //  invoke(project, context, classDeclaration, parentElement);
    //  return;
    //}
    element = element.getParent();
  }
}
 
Example #26
Source File: HaxePullUpHandler.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkConflicts(final HaxePullUpDialog dialog) {
  final List<MemberInfo> infos = dialog.getSelectedMemberInfos();
  final MemberInfo[] memberInfos = infos.toArray(new MemberInfo[infos.size()]);
  final PsiClass superClass = dialog.getSuperClass();
  if (!checkWritable(superClass, memberInfos)) return false;
  final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
  if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runReadAction(new Runnable() {
        @Override
        public void run() {
          //final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
          //final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
          //conflicts
          //  .putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory,
          //                                                   dialog.getContainmentVerifier()));
        }
      });
    }
  }, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) return false;
  if (!conflicts.isEmpty()) {
    ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
    conflictsDialog.show();
    final boolean ok = conflictsDialog.isOK();
    if (!ok && conflictsDialog.isShowConflicts()) dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
    return ok;
  }
  return true;
}
 
Example #27
Source File: RenameWithOptionalReferencesDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void createCheckboxes(JPanel panel, GridBagConstraints gbConstraints) {
  gbConstraints.insets = new Insets(0, 0, 4, 0);
  gbConstraints.gridwidth = 1;
  gbConstraints.gridx = 0;
  gbConstraints.weighty = 0;
  gbConstraints.weightx = 1;
  gbConstraints.fill = GridBagConstraints.BOTH;
  myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references"));
  myCbSearchForReferences.setSelected(getSearchForReferences());
  panel.add(myCbSearchForReferences, gbConstraints);

  super.createCheckboxes(panel, gbConstraints);
}
 
Example #28
Source File: ExtractIncludeDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doOKAction() {
  final Project project = myCurrentDirectory.getProject();

  final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/');
  final String targetFileName = getTargetFileName();

  if (isFileExist(directoryName, targetFileName)) {
    Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title"));
    return;
  }

  final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName);
  if (type == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          try {
            PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName);
            targetDirectory.checkCreateFile(targetFileName);
            final String webPath = PsiFileSystemItemUtil.getRelativePath(myCurrentDirectory, targetDirectory);
            myTargetDirectory = webPath == null ? null : targetDirectory;
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, e.getMessage(), null, project);
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  }, RefactoringBundle.message("create.directory"), null);
  if (myTargetDirectory == null) return;
  super.doOKAction();
}
 
Example #29
Source File: RenameHandlerRegistry.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected JComponent createNorthPanel() {
  final JPanel radioPanel = new JPanel();
  radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
  final JLabel descriptionLabel = new JLabel(RefactoringBundle.message("what.would.you.like.to.do"));
  descriptionLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
  radioPanel.add(descriptionLabel);
  final ButtonGroup bg = new ButtonGroup();
  boolean selected = true;
  int rIdx = 0;
  for (final String renamer : myRenamers) {
    final JRadioButton rb = new JRadioButton(renamer, selected);
    myRButtons[rIdx++] = rb;
    final ActionListener listener = new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        if (rb.isSelected()) {
          mySelection = renamer;
        }
      }
    };
    rb.addActionListener(listener);
    selected = false;
    bg.add(rb);
    radioPanel.add(rb);
  }
  new RadioUpDownListener(myRButtons);
  return radioPanel;
}
 
Example #30
Source File: CSharpCopyClassHandlerDelegate.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private static void doCopy(@Nonnull CSharpTypeDeclaration typeDeclaration, @Nullable PsiDirectory defaultTargetDirectory, Project project)
{
	PsiDirectory targetDirectory;
	String newName;
	boolean openInEditor;
	VirtualFile virtualFile = PsiUtilCore.getVirtualFile(typeDeclaration);
	CopyFilesOrDirectoriesDialog dialog = new CopyFilesOrDirectoriesDialog(new PsiElement[]{typeDeclaration.getContainingFile()}, defaultTargetDirectory, project, false);
	if(dialog.showAndGet())
	{
		newName = dialog.getNewName();
		targetDirectory = dialog.getTargetDirectory();
		openInEditor = dialog.openInEditor();
	}
	else
	{
		return;
	}

	if(targetDirectory != null)
	{
		PsiManager manager = PsiManager.getInstance(project);
		try
		{
			if(virtualFile.isDirectory())
			{
				PsiFileSystemItem psiElement = manager.findDirectory(virtualFile);
				MoveFilesOrDirectoriesUtil.checkIfMoveIntoSelf(psiElement, targetDirectory);
			}
		}
		catch(IncorrectOperationException e)
		{
			CommonRefactoringUtil.showErrorHint(project, null, e.getMessage(), CommonBundle.getErrorTitle(), null);
			return;
		}

		CommandProcessor.getInstance().executeCommand(project, () -> doCopy(typeDeclaration, newName, targetDirectory, false, openInEditor), RefactoringBundle.message("copy.handler.copy.files" +
				".directories"), null);
	}
}