use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class ChangeSignatureTest method testPropagateParameter.
public void testPropagateParameter() {
String basePath = getRelativePath() + getTestName(false);
configureByFile(basePath + ".java");
final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
PsiMethod method = (PsiMethod) targetElement;
final PsiClass containingClass = method.getContainingClass();
assertTrue(containingClass != null);
final PsiMethod[] callers = containingClass.findMethodsByName("caller", false);
assertTrue(callers.length > 0);
final PsiMethod caller = callers[0];
final HashSet<PsiMethod> propagateParametersMethods = new HashSet<>();
propagateParametersMethods.add(caller);
final PsiParameter[] parameters = method.getParameterList().getParameters();
new ChangeSignatureProcessor(getProject(), method, false, null, method.getName(), CanonicalTypes.createTypeWrapper(PsiType.VOID), new ParameterInfoImpl[] { new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()), new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN) }, null, propagateParametersMethods, null).run();
checkResultByFile(basePath + "_after.java");
}
use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class ChangeSignatureTest method testPropagateParameterWithOverrider.
public void testPropagateParameterWithOverrider() {
String basePath = getRelativePath() + getTestName(false);
configureByFile(basePath + ".java");
final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
PsiMethod method = (PsiMethod) targetElement;
final PsiClass containingClass = method.getContainingClass();
assertTrue(containingClass != null);
final PsiMethod[] callers = containingClass.findMethodsByName("caller", false);
assertTrue(callers.length > 0);
final PsiMethod caller = callers[0];
final HashSet<PsiMethod> propagateParametersMethods = new HashSet<>();
propagateParametersMethods.add(caller);
final PsiParameter[] parameters = method.getParameterList().getParameters();
new ChangeSignatureProcessor(getProject(), method, false, null, method.getName(), CanonicalTypes.createTypeWrapper(PsiType.VOID), new ParameterInfoImpl[] { new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()), new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "true") }, null, propagateParametersMethods, null).run();
checkResultByFile(basePath + "_after.java");
}
use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class MakePublicStaticVoidFix method doFix.
@Override
protected void doFix(final Project project, ProblemDescriptor descriptor) {
final PsiMethod method = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiMethod.class);
if (method != null) {
ChangeSignatureProcessor csp = new ChangeSignatureProcessor(project, method, false, PsiModifier.PUBLIC, method.getName(), PsiType.VOID, new ParameterInfoImpl[0]) {
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
super.performRefactoring(usages);
PsiUtil.setModifierProperty(method, PsiModifier.STATIC, myMakeStatic);
}
};
csp.run();
}
}
use of com.intellij.refactoring.changeSignature.ChangeSignatureProcessor in project intellij-community by JetBrains.
the class ParameterizedParametersStaticCollectionInspection method buildFix.
@Override
protected InspectionGadgetsFix buildFix(final Object... infos) {
return new InspectionGadgetsFix() {
@Override
protected void doFix(final Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement element = descriptor.getPsiElement();
final PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
if (method != null && infos[1] instanceof PsiType) {
PsiType type = (PsiType) infos[1];
final ChangeSignatureProcessor csp = new ChangeSignatureProcessor(project, method, false, PsiModifier.PUBLIC, method.getName(), type, new ParameterInfoImpl[0]);
csp.run();
} else {
final PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (psiClass != null) {
final CreateMethodQuickFix fix = CreateMethodQuickFix.createFix(psiClass, "@" + PARAMETERS_FQN + " public static java.util.Collection parameters()", "");
if (fix != null) {
fix.applyFix(project, descriptor);
}
}
}
}
@Override
@NotNull
public String getName() {
return infos.length > 0 ? (String) infos[0] : "Create @Parameterized.Parameters data provider";
}
@NotNull
@Override
public String getFamilyName() {
return "Fix data provider signature";
}
};
}
Aggregations