use of com.intellij.refactoring.listeners.RefactoringElementListener in project intellij-community by JetBrains.
the class RenameProcessor method performRefactoring.
@Override
public void performRefactoring(@NotNull UsageInfo[] usages) {
List<Runnable> postRenameCallbacks = new ArrayList<>();
final MultiMap<PsiElement, UsageInfo> classified = classifyUsages(myAllRenames.keySet(), usages);
for (final PsiElement element : myAllRenames.keySet()) {
String newName = myAllRenames.get(element);
final RefactoringElementListener elementListener = getTransaction().getElementListener(element);
final RenamePsiElementProcessor renamePsiElementProcessor = RenamePsiElementProcessor.forElement(element);
Runnable postRenameCallback = renamePsiElementProcessor.getPostRenameCallback(element, newName, elementListener);
final Collection<UsageInfo> infos = classified.get(element);
try {
RenameUtil.doRename(element, newName, infos.toArray(new UsageInfo[infos.size()]), myProject, elementListener);
} catch (final IncorrectOperationException e) {
RenameUtil.showErrorMessage(e, element, myProject);
return;
}
if (postRenameCallback != null) {
postRenameCallbacks.add(postRenameCallback);
}
}
for (Runnable runnable : postRenameCallbacks) {
runnable.run();
}
List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>();
for (UsageInfo usage : usages) {
if (usage instanceof NonCodeUsageInfo) {
nonCodeUsages.add((NonCodeUsageInfo) usage);
}
}
myNonCodeUsages = nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
if (!mySkippedUsages.isEmpty()) {
if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
ApplicationManager.getApplication().invokeLater(() -> {
final IdeFrame ideFrame = WindowManager.getInstance().getIdeFrame(myProject);
if (ideFrame != null) {
StatusBarEx statusBar = (StatusBarEx) ideFrame.getStatusBar();
HyperlinkListener listener = new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
return;
Messages.showMessageDialog("<html>Following usages were safely skipped:<br>" + StringUtil.join(mySkippedUsages, unresolvableCollisionUsageInfo -> unresolvableCollisionUsageInfo.getDescription(), "<br>") + "</html>", "Not All Usages Were Renamed", null);
}
};
statusBar.notifyProgressByBalloon(MessageType.WARNING, "<html><body>Unable to rename certain usages. <a href=\"\">Browse</a></body></html>", null, listener);
}
}, ModalityState.NON_MODAL);
}
}
}
use of com.intellij.refactoring.listeners.RefactoringElementListener in project intellij-community by JetBrains.
the class RefactoringTransactionImpl method addAffectedElement.
private void addAffectedElement(PsiElement oldElement) {
if (myOldElementToListenerListMap.get(oldElement) != null)
return;
ArrayList<RefactoringElementListener> listenerList = new ArrayList<>();
for (RefactoringElementListenerProvider provider : myListenerProviders) {
try {
final RefactoringElementListener listener = provider.getListener(oldElement);
if (listener != null) {
listenerList.add(listener);
}
} catch (Throwable e) {
LOG.error(e);
}
}
myOldElementToListenerListMap.put(oldElement, listenerList);
}
use of com.intellij.refactoring.listeners.RefactoringElementListener in project intellij-community by JetBrains.
the class RefactoringTransactionImpl method getElementListener.
@Override
public RefactoringElementListener getElementListener(PsiElement oldElement) {
RefactoringElementListener listener = myOldElementToTransactionListenerMap.get(oldElement);
if (listener == null) {
listener = new MyRefactoringElementListener(oldElement);
myOldElementToTransactionListenerMap.put(oldElement, listener);
}
return listener;
}
use of com.intellij.refactoring.listeners.RefactoringElementListener in project intellij-community by JetBrains.
the class TestsPattern method getListener.
@Nullable
@Override
public RefactoringElementListener getListener(PsiElement element, JUnitConfiguration configuration) {
final RefactoringElementListenerComposite composite = new RefactoringElementListenerComposite();
final JUnitConfiguration.Data data = configuration.getPersistentData();
final Set<String> patterns = data.getPatterns();
for (final String pattern : patterns) {
final PsiClass testClass = getTestClass(configuration.getProject(), pattern.trim());
if (testClass != null && testClass.equals(element)) {
final RefactoringElementListener listeners = RefactoringListeners.getListeners(testClass, new RefactoringListeners.Accessor<PsiClass>() {
private String myOldName = testClass.getQualifiedName();
@Override
public void setName(String qualifiedName) {
final Set<String> replaced = new LinkedHashSet<>();
for (String currentPattern : patterns) {
if (myOldName.equals(currentPattern)) {
replaced.add(qualifiedName);
myOldName = qualifiedName;
} else {
replaced.add(currentPattern);
}
}
patterns.clear();
patterns.addAll(replaced);
}
@Override
public PsiClass getPsiElement() {
return testClass;
}
@Override
public void setPsiElement(PsiClass psiElement) {
if (psiElement == testClass) {
setName(psiElement.getQualifiedName());
}
}
});
if (listeners != null) {
composite.addListener(listeners);
}
}
}
return composite;
}
Aggregations