Search in sources :

Example 1 with ReplaceConstructorWithBuilderProcessor

use of com.intellij.refactoring.replaceConstructorWithBuilder.ReplaceConstructorWithBuilderProcessor in project intellij-community by JetBrains.

the class ReplaceConstructorWithBuilderTest method doTest.

private void doTest(final boolean createNewBuilderClass, final Map<String, String> expectedDefaults, final String conflicts, final String packageName) throws Exception {
    doTest((rootDir, rootAfter) -> {
        final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
        assertNotNull("Class Test not found", aClass);
        final LinkedHashMap<String, ParameterData> map = new LinkedHashMap<>();
        final PsiMethod[] constructors = aClass.getConstructors();
        for (PsiMethod constructor : constructors) {
            ParameterData.createFromConstructor(constructor, "set", map);
        }
        if (expectedDefaults != null) {
            for (Map.Entry<String, String> entry : expectedDefaults.entrySet()) {
                final ParameterData parameterData = map.get(entry.getKey());
                assertNotNull(parameterData);
                assertEquals(entry.getValue(), parameterData.getDefaultValue());
            }
        }
        try {
            new ReplaceConstructorWithBuilderProcessor(getProject(), constructors, map, "Builder", packageName, null, createNewBuilderClass).run();
            if (conflicts != null) {
                fail("Conflicts were not detected:" + conflicts);
            }
        } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
            if (conflicts == null) {
                fail("Conflict detected:" + e.getMessage());
            }
        }
        LocalFileSystem.getInstance().refresh(false);
        FileDocumentManager.getInstance().saveAllDocuments();
    });
}
Also used : ReplaceConstructorWithBuilderProcessor(com.intellij.refactoring.replaceConstructorWithBuilder.ReplaceConstructorWithBuilderProcessor) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ParameterData(com.intellij.refactoring.replaceConstructorWithBuilder.ParameterData) HashMap(com.intellij.util.containers.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PsiClass (com.intellij.psi.PsiClass)1 PsiMethod (com.intellij.psi.PsiMethod)1 ParameterData (com.intellij.refactoring.replaceConstructorWithBuilder.ParameterData)1 ReplaceConstructorWithBuilderProcessor (com.intellij.refactoring.replaceConstructorWithBuilder.ReplaceConstructorWithBuilderProcessor)1 HashMap (com.intellij.util.containers.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1