com.intellij.refactoring.rename.naming.AutomaticRenamerFactory Java Examples

The following examples show how to use com.intellij.refactoring.rename.naming.AutomaticRenamerFactory. 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: RenameImportedProtoTest.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
public void testRenameImportedProtoAtCaretPosition() {
    PsiFile[] files = myFixture.configureByFiles(
            "rename/import/source.proto",
            "rename/import/import.proto"
    );

    PsiElement elementAtCaret = myFixture.getElementAtCaret();
    Project project = myFixture.getProject();
    RenameProcessor processor = new RenameProcessor(project, elementAtCaret, "renamed.proto", false, false);
    for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
        processor.addRenamerFactory(factory);
    }
    processor.run();

    Assert.assertEquals("renamed.proto", files[1].getName());
    Assert.assertEquals("import \"rename/import/renamed.proto\";",
            ((ProtoPsiFileRoot) files[0]).getProtoRoot().getImports().get(0).getText());
}
 
Example #2
Source File: RenameDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void performRename(final String newName) {
  final RenamePsiElementProcessor elementProcessor = RenamePsiElementProcessor.forElement(myPsiElement);
  elementProcessor.setToSearchInComments(myPsiElement, isSearchInComments());
  if (myCbSearchTextOccurences.isEnabled()) {
    elementProcessor.setToSearchForTextOccurrences(myPsiElement, isSearchInNonJavaFiles());
  }
  if (mySuggestedNameInfo != null) {
    mySuggestedNameInfo.nameChosen(newName);
  }

  final RenameProcessor processor = createRenameProcessor(newName);

  for(Map.Entry<AutomaticRenamerFactory, JCheckBox> e: myAutomaticRenamers.entrySet()) {
    e.getKey().setEnabled(e.getValue().isSelected());
    if (e.getValue().isSelected()) {
      processor.addRenamerFactory(e.getKey());
    }
  }

  invokeRefactoring(processor);
}
 
Example #3
Source File: MemberInplaceRenamer.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void performRenameInner(PsiElement element, String newName) {
  final RenamePsiElementProcessor elementProcessor = RenamePsiElementProcessor.forElement(element);
  final RenameProcessor
    renameProcessor = new RenameProcessor(myProject, element, newName,
                                          elementProcessor.isToSearchInComments(element),
                                          elementProcessor.isToSearchForTextOccurrences(element)){
    @Override
    public void doRun() {
      try {
        super.doRun();
      }
      finally {
        restoreCaretOffsetAfterRename();
      }
    }
  };
  for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
    if (factory.getOptionName() != null && factory.isApplicable(element)) {
      renameProcessor.addRenamerFactory(factory);
    }
  }
  renameProcessor.run();
}
 
Example #4
Source File: BashFileReferenceTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private void doRename(PsiFile psiElement, String newName) {
    final RenameProcessor processor = new RenameProcessor(myProject, psiElement, newName, false, false);
    for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
        processor.addRenamerFactory(factory);
    }
    processor.run();

    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
}
 
Example #5
Source File: RenameDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
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;
  myCbSearchInComments = new NonFocusableCheckBox();
  myCbSearchInComments.setText(RefactoringBundle.getSearchInCommentsAndStringsText());
  myCbSearchInComments.setSelected(true);
  panel.add(myCbSearchInComments, gbConstraints);

  gbConstraints.insets = new Insets(0, 0, 4, 0);
  gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
  gbConstraints.gridx = 1;
  gbConstraints.weightx = 1;
  gbConstraints.fill = GridBagConstraints.BOTH;
  myCbSearchTextOccurences = new NonFocusableCheckBox();
  myCbSearchTextOccurences.setText(RefactoringBundle.getSearchForTextOccurrencesText());
  myCbSearchTextOccurences.setSelected(true);
  panel.add(myCbSearchTextOccurences, gbConstraints);
  if (!TextOccurrencesUtil.isSearchTextOccurencesEnabled(myPsiElement)) {
    myCbSearchTextOccurences.setEnabled(false);
    myCbSearchTextOccurences.setSelected(false);
    myCbSearchTextOccurences.setVisible(false);
  }

  for(AutomaticRenamerFactory factory: Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
    if (factory.isApplicable(myPsiElement) && factory.getOptionName() != null) {
      gbConstraints.insets = new Insets(0, 0, 4, 0);
      gbConstraints.gridwidth = myAutomaticRenamers.size() % 2 == 0 ? 1 : GridBagConstraints.REMAINDER;
      gbConstraints.gridx = myAutomaticRenamers.size() % 2;
      gbConstraints.weightx = 1;
      gbConstraints.fill = GridBagConstraints.BOTH;

      JCheckBox checkBox = new NonFocusableCheckBox();
      checkBox.setText(factory.getOptionName());
      checkBox.setSelected(factory.isEnabled());
      panel.add(checkBox, gbConstraints);
      myAutomaticRenamers.put(factory, checkBox);
    }
  }
}
 
Example #6
Source File: RenameProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addRenamerFactory(AutomaticRenamerFactory factory) {
  if (!myRenamerFactories.contains(factory)) {
    myRenamerFactories.add(factory);
  }
}
 
Example #7
Source File: RenameProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void removeRenamerFactory(AutomaticRenamerFactory factory) {
  myRenamerFactories.remove(factory);
}