use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class MatchUtil method changeSignature.
public static void changeSignature(@NotNull Match match, @NotNull PsiMethod psiMethod) {
final PsiType expressionType = match.getChangedReturnType(psiMethod);
if (expressionType == null && match.myChangedParams.isEmpty())
return;
final List<ParameterInfoImpl> newParameters = patchParams(match.myChangedParams, psiMethod);
final ChangeSignatureProcessor csp = new ChangeSignatureProcessor(psiMethod.getProject(), psiMethod, false, null, psiMethod.getName(), expressionType != null ? expressionType : psiMethod.getReturnType(), newParameters.toArray(new ParameterInfoImpl[newParameters.size()]));
csp.run();
}
use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class ChangeMethodSignatureFromUsageFix method performChange.
public static List<ParameterInfoImpl> performChange(final Project project, final Editor editor, final PsiFile file, final PsiMethod method, final int minUsagesNumber, final ParameterInfoImpl[] newParametersInfo, final boolean changeAllUsages, final boolean allowDelegation) {
if (!FileModificationService.getInstance().prepareFileForWrite(method.getContainingFile()))
return null;
final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(method, false);
//on failure or cancel (e.g. cancel of super methods dialog)
if (handler == null)
return null;
final JavaMethodFindUsagesOptions options = new JavaMethodFindUsagesOptions(project);
options.isImplementingMethods = true;
options.isOverridingMethods = true;
options.isUsages = true;
options.isSearchForTextOccurrences = false;
final int[] usagesFound = new int[1];
Runnable runnable = () -> {
Processor<UsageInfo> processor = t -> ++usagesFound[0] < minUsagesNumber;
handler.processElementUsages(method, processor, options);
};
String progressTitle = QuickFixBundle.message("searching.for.usages.progress.title");
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, progressTitle, true, project))
return null;
if (ApplicationManager.getApplication().isUnitTestMode() || usagesFound[0] < minUsagesNumber) {
ChangeSignatureProcessor processor = new ChangeSignatureProcessor(project, method, false, null, method.getName(), method.getReturnType(), newParametersInfo) {
@Override
@NotNull
protected UsageInfo[] findUsages() {
return changeAllUsages ? super.findUsages() : UsageInfo.EMPTY_ARRAY;
}
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
CommandProcessor.getInstance().setCurrentCommandName(getCommandName());
super.performRefactoring(usages);
}
};
processor.run();
ApplicationManager.getApplication().runWriteAction(() -> UndoUtil.markPsiFileForUndo(file));
return Arrays.asList(newParametersInfo);
} else {
final List<ParameterInfoImpl> parameterInfos = newParametersInfo != null ? new ArrayList<>(Arrays.asList(newParametersInfo)) : new ArrayList<>();
final PsiReferenceExpression refExpr = JavaTargetElementEvaluator.findReferenceExpression(editor);
JavaChangeSignatureDialog dialog = JavaChangeSignatureDialog.createAndPreselectNew(project, method, parameterInfos, allowDelegation, refExpr);
dialog.setParameterInfos(parameterInfos);
dialog.show();
return dialog.isOK() ? dialog.getParameters() : null;
}
}
use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class RemoveUnusedParameterFix method removeReferences.
private static void removeReferences(PsiParameter parameter) {
PsiMethod method = (PsiMethod) parameter.getDeclarationScope();
ChangeSignatureProcessor processor = new ChangeSignatureProcessor(parameter.getProject(), method, false, null, method.getName(), method.getReturnType(), getNewParametersInfo(method, parameter));
processor.run();
}
use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class ChangeSignatureBaseTest method doTest.
protected void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility, @Nullable String newName, @Nullable String newReturnType, GenParams genParams, GenExceptions genExceptions, boolean generateDelegate, boolean skipConflict) {
String basePath = getRelativePath() + getTestName(false);
configureByFile(basePath + ".java");
PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
PsiMethod method = (PsiMethod) targetElement;
PsiType newType = newReturnType != null ? myFactory.createTypeFromText(newReturnType, method) : method.getReturnType();
new ChangeSignatureProcessor(getProject(), method, generateDelegate, newVisibility, newName != null ? newName : method.getName(), newType, genParams.genParams(method), genExceptions.genExceptions(method)) {
@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
try {
return super.preprocessUsages(refUsages);
} catch (ConflictsInTestsException e) {
if (skipConflict) {
return true;
}
throw e;
}
}
}.run();
checkResultByFile(basePath + "_after.java");
}
use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class ChangeSignaturePropagationTest method doTest.
private void doTest(ParameterInfoImpl[] newParameters, final ThrownExceptionInfo[] newExceptions, Set<PsiMethod> methodsToPropagateParameterChanges, Set<PsiMethod> methodsToPropagateExceptionChanges, PsiMethod primaryMethod) throws Exception {
final String filePath = getBasePath() + getTestName(false) + ".java";
final PsiType returnType = primaryMethod.getReturnType();
final CanonicalTypes.Type type = returnType == null ? null : CanonicalTypes.createTypeWrapper(returnType);
new ChangeSignatureProcessor(getProject(), primaryMethod, false, null, primaryMethod.getName(), type, generateParameterInfos(primaryMethod, newParameters), generateExceptionInfos(primaryMethod, newExceptions), methodsToPropagateParameterChanges, methodsToPropagateExceptionChanges).run();
checkResultByFile(filePath + ".after");
}
Aggregations