use of com.intellij.refactoring.listeners.RefactoringElementListenerComposite in project intellij-community by JetBrains.
the class RefactoringScopeElementListenerProvider method getListener.
@Override
public RefactoringElementListener getListener(PsiElement element) {
if (!(element instanceof PsiQualifiedNamedElement) && !(element instanceof PsiDirectory))
return null;
final PsiFile containingFile = element.getContainingFile();
RefactoringElementListenerComposite composite = null;
String oldName = getQualifiedName(element, false);
if (oldName != null) {
composite = getComposite(element, containingFile, null, oldName);
}
if (element instanceof PsiQualifiedNamedElement) {
oldName = getQualifiedName(element, true);
if (oldName != null) {
composite = getComposite(element, containingFile, composite, oldName);
}
}
return composite;
}
use of com.intellij.refactoring.listeners.RefactoringElementListenerComposite in project intellij-community by JetBrains.
the class RunConfigurationRefactoringElementListenerProvider method getListener.
@Override
public RefactoringElementListener getListener(final PsiElement element) {
RefactoringElementListenerComposite composite = null;
final List<RunConfiguration> configurations = RunManager.getInstance(element.getProject()).getAllConfigurationsList();
for (RunConfiguration configuration : configurations) {
if (configuration instanceof RefactoringListenerProvider) {
// todo: perhaps better way to handle listeners?
RefactoringElementListener listener;
try {
listener = ((RefactoringListenerProvider) configuration).getRefactoringElementListener(element);
} catch (Exception e) {
LOG.error(e);
continue;
}
if (listener != null) {
if (configuration instanceof LocatableConfiguration) {
listener = new NameGeneratingListenerDecorator((LocatableConfiguration) configuration, listener);
}
if (composite == null) {
composite = new RefactoringElementListenerComposite();
}
composite.addListener(listener);
}
}
}
return composite;
}
use of com.intellij.refactoring.listeners.RefactoringElementListenerComposite 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;
}
use of com.intellij.refactoring.listeners.RefactoringElementListenerComposite in project intellij-community by JetBrains.
the class PyExtractMethodUtil method processParameters.
private static void processParameters(@NotNull final Project project, @NotNull final PyFunction generatedMethod, @NotNull final AbstractVariableData[] variableData, final boolean isMethod, final boolean isClassMethod, final boolean isStaticMethod) {
final Map<String, String> map = createMap(variableData);
// Rename parameters
for (PyParameter parameter : generatedMethod.getParameterList().getParameters()) {
final String name = parameter.getName();
final String newName = map.get(name);
if (name != null && newName != null && !name.equals(newName)) {
final Map<PsiElement, String> allRenames = new java.util.HashMap<>();
allRenames.put(parameter, newName);
final UsageInfo[] usages = RenameUtil.findUsages(parameter, newName, false, false, allRenames);
try {
RenameUtil.doRename(parameter, newName, usages, project, new RefactoringElementListenerComposite());
} catch (IncorrectOperationException e) {
RenameUtil.showErrorMessage(e, parameter, project);
return;
}
}
}
// Change signature according to pass settings and
final PyFunctionBuilder builder = new PyFunctionBuilder("foo", generatedMethod);
if (isClassMethod) {
builder.parameter("cls");
} else if (isMethod && !isStaticMethod) {
builder.parameter("self");
}
for (AbstractVariableData data : variableData) {
if (data.isPassAsParameter()) {
builder.parameter(data.getName());
}
}
final PyParameterList pyParameterList = builder.buildFunction(project, LanguageLevel.forElement(generatedMethod)).getParameterList();
generatedMethod.getParameterList().replace(pyParameterList);
}
Aggregations