Search in sources :

Example 1 with CreateMethodQuickFix

use of com.intellij.codeInsight.daemon.impl.quickfix.CreateMethodQuickFix 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

CreateMethodQuickFix (com.intellij.codeInsight.daemon.impl.quickfix.CreateMethodQuickFix)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 Project (com.intellij.openapi.project.Project)1 ChangeSignatureProcessor (com.intellij.refactoring.changeSignature.ChangeSignatureProcessor)1 InspectionGadgetsFix (com.siyeh.ig.InspectionGadgetsFix)1