use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class InlinePropertyHandler method inlineElement.
public void inlineElement(final Project project, Editor editor, PsiElement psiElement) {
if (!(psiElement instanceof IProperty))
return;
IProperty property = (IProperty) psiElement;
final String propertyValue = property.getValue();
if (propertyValue == null)
return;
final List<PsiElement> occurrences = Collections.synchronizedList(ContainerUtil.<PsiElement>newArrayList());
final Collection<PsiFile> containingFiles = Collections.synchronizedSet(new HashSet<PsiFile>());
containingFiles.add(psiElement.getContainingFile());
boolean result = ReferencesSearch.search(psiElement).forEach(psiReference -> {
PsiElement element = psiReference.getElement();
PsiElement parent = element.getParent();
if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiMethodCallExpression) {
if (((PsiExpressionList) parent).getExpressions().length == 1) {
occurrences.add(parent.getParent());
containingFiles.add(element.getContainingFile());
return true;
}
}
return false;
});
if (!result) {
CommonRefactoringUtil.showErrorHint(project, editor, "Property has non-method usages", REFACTORING_NAME, null);
}
if (occurrences.isEmpty()) {
CommonRefactoringUtil.showErrorHint(project, editor, "Property has no usages", REFACTORING_NAME, null);
return;
}
if (!ApplicationManager.getApplication().isUnitTestMode()) {
String occurrencesString = RefactoringBundle.message("occurrences.string", occurrences.size());
String question = PropertiesBundle.message("inline.property.confirmation", property.getName(), propertyValue) + " " + occurrencesString;
RefactoringMessageDialog dialog = new RefactoringMessageDialog(REFACTORING_NAME, question, HelpID.INLINE_VARIABLE, "OptionPane.questionIcon", true, project);
if (!dialog.showAndGet()) {
return;
}
}
final RefactoringEventData data = new RefactoringEventData();
data.addElement(psiElement.copy());
new WriteCommandAction.Simple(project, REFACTORING_NAME, containingFiles.toArray(new PsiFile[containingFiles.size()])) {
@Override
protected void run() throws Throwable {
project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(REFACTORING_ID, data);
PsiLiteral stringLiteral = (PsiLiteral) JavaPsiFacade.getInstance(getProject()).getElementFactory().createExpressionFromText("\"" + StringUtil.escapeStringCharacters(propertyValue) + "\"", null);
for (PsiElement occurrence : occurrences) {
occurrence.replace(stringLiteral.copy());
}
project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(REFACTORING_ID, null);
}
}.execute();
}
use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class PyMembersRefactoringBaseProcessor method getBeforeData.
@Nullable
@Override
protected RefactoringEventData getBeforeData() {
RefactoringEventData data = new RefactoringEventData();
data.addElement(myFrom);
data.addMembers(myMembersToMove.toArray(new PyMemberInfo[myMembersToMove.size()]), info -> info.getMember());
return data;
}
use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class IntroduceParameterProcessor method getBeforeData.
@Nullable
@Override
protected RefactoringEventData getBeforeData() {
RefactoringEventData data = new RefactoringEventData();
data.addElements(new PsiElement[] { myLocalVariable, myExpressionToSearch });
return data;
}
use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class PullUpProcessor method getBeforeData.
@Nullable
@Override
protected RefactoringEventData getBeforeData() {
RefactoringEventData data = new RefactoringEventData();
data.addElement(mySourceClass);
data.addMembers(myMembersToMove, info -> info.getMember());
return data;
}
use of com.intellij.refactoring.listeners.RefactoringEventData in project intellij-community by JetBrains.
the class InlineConstantFieldProcessor method getBeforeData.
@Nullable
@Override
protected RefactoringEventData getBeforeData() {
RefactoringEventData data = new RefactoringEventData();
data.addElement(myField);
return data;
}
Aggregations