Search in sources :

Example 11 with ChangeSignatureProcessor

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");
}
Also used : ParameterInfoImpl(com.intellij.refactoring.changeSignature.ParameterInfoImpl) HashSet(java.util.HashSet) ChangeSignatureProcessor(com.intellij.refactoring.changeSignature.ChangeSignatureProcessor)

Example 12 with ChangeSignatureProcessor

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");
}
Also used : ParameterInfoImpl(com.intellij.refactoring.changeSignature.ParameterInfoImpl) HashSet(java.util.HashSet) ChangeSignatureProcessor(com.intellij.refactoring.changeSignature.ChangeSignatureProcessor)

Example 13 with ChangeSignatureProcessor

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();
    }
}
Also used : NotNull(org.jetbrains.annotations.NotNull) ChangeSignatureProcessor(com.intellij.refactoring.changeSignature.ChangeSignatureProcessor)

Example 14 with ChangeSignatureProcessor

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";
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) InspectionGadgetsFix(com.siyeh.ig.InspectionGadgetsFix) CreateMethodQuickFix(com.intellij.codeInsight.daemon.impl.quickfix.CreateMethodQuickFix) ChangeSignatureProcessor(com.intellij.refactoring.changeSignature.ChangeSignatureProcessor)

Aggregations

ChangeSignatureProcessor (com.intellij.refactoring.changeSignature.ChangeSignatureProcessor)14 ParameterInfoImpl (com.intellij.refactoring.changeSignature.ParameterInfoImpl)6 JavaChangeSignatureDialog (com.intellij.refactoring.changeSignature.JavaChangeSignatureDialog)3 NotNull (org.jetbrains.annotations.NotNull)3 Project (com.intellij.openapi.project.Project)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 CreateMethodQuickFix (com.intellij.codeInsight.daemon.impl.quickfix.CreateMethodQuickFix)1 LocalQuickFixAndIntentionActionOnPsiElement (com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 FindUsagesHandler (com.intellij.find.findUsages.FindUsagesHandler)1 FindUsagesManager (com.intellij.find.findUsages.FindUsagesManager)1 JavaMethodFindUsagesOptions (com.intellij.find.findUsages.JavaMethodFindUsagesOptions)1 FindManagerImpl (com.intellij.find.impl.FindManagerImpl)1 Result (com.intellij.openapi.application.Result)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 PsiMethod (com.intellij.psi.PsiMethod)1 CanonicalTypes (com.intellij.refactoring.util.CanonicalTypes)1 UsageInfo (com.intellij.usageView.UsageInfo)1