Search in sources :

Example 1 with RemoveMiddlemanProcessor

use of com.intellij.refactoring.removemiddleman.RemoveMiddlemanProcessor in project intellij-community by JetBrains.

the class RemoveMiddleManTest method doTest.

private void doTest(final String conflict) throws Exception {
    doTest((rootDir, rootAfter) -> {
        PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
        if (aClass == null)
            aClass = myJavaFacade.findClass("p.Test", GlobalSearchScope.allScope(getProject()));
        assertNotNull("Class Test not found", aClass);
        final PsiField field = aClass.findFieldByName("myField", false);
        final Set<PsiMethod> methods = DelegationUtils.getDelegatingMethodsForField(field);
        List<MemberInfo> infos = new ArrayList<>();
        for (PsiMethod method : methods) {
            final MemberInfo info = new MemberInfo(method);
            info.setChecked(true);
            info.setToAbstract(true);
            infos.add(info);
        }
        try {
            RemoveMiddlemanProcessor processor = new RemoveMiddlemanProcessor(field, infos);
            processor.run();
            LocalFileSystem.getInstance().refresh(false);
            FileDocumentManager.getInstance().saveAllDocuments();
            if (conflict != null)
                fail("Conflict expected");
        } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
            if (conflict == null)
                throw e;
            assertEquals(conflict, e.getMessage());
        }
    });
}
Also used : RemoveMiddlemanProcessor(com.intellij.refactoring.removemiddleman.RemoveMiddlemanProcessor) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiMethod(com.intellij.psi.PsiMethod) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList)

Aggregations

PsiClass (com.intellij.psi.PsiClass)1 PsiField (com.intellij.psi.PsiField)1 PsiMethod (com.intellij.psi.PsiMethod)1 RemoveMiddlemanProcessor (com.intellij.refactoring.removemiddleman.RemoveMiddlemanProcessor)1 MemberInfo (com.intellij.refactoring.util.classMembers.MemberInfo)1 ArrayList (java.util.ArrayList)1