Search in sources :

Example 1 with DocCommentPolicy

use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.

the class PullUpTest method doTest.

private void doTest(final boolean checkMembersMovedCount, String conflictMessage, RefactoringTestUtil.MemberDescriptor... membersToFind) {
    final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
    configureByFile(BASE_PATH + getTestName(false) + ".java");
    PsiElement elementAt = getFile().findElementAt(getEditor().getCaretModel().getOffset());
    final PsiClass sourceClass = PsiTreeUtil.getParentOfType(elementAt, PsiClass.class);
    assertNotNull(sourceClass);
    PsiClass targetClass = sourceClass.getSuperClass();
    assertNotNull(targetClass);
    if (!targetClass.isWritable()) {
        final PsiClass[] interfaces = sourceClass.getInterfaces();
        assertEquals(1, interfaces.length);
        assertTrue(interfaces[0].isWritable());
        targetClass = interfaces[0];
    }
    final MemberInfo[] infos = RefactoringTestUtil.findMembers(sourceClass, membersToFind);
    final int[] countMoved = { 0 };
    final MoveMemberListener listener = (aClass, member) -> {
        assertEquals(sourceClass, aClass);
        countMoved[0]++;
    };
    JavaRefactoringListenerManager.getInstance(getProject()).addMoveMembersListener(listener);
    final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
    final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
    conflictsMap.putAllValues(PullUpConflictsUtil.checkConflicts(infos, sourceClass, targetClass, targetPackage, targetDirectory, psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(infos), psiMethod)));
    final PullUpProcessor helper = new PullUpProcessor(sourceClass, targetClass, infos, new DocCommentPolicy(DocCommentPolicy.ASIS));
    helper.run();
    UIUtil.dispatchAllInvocationEvents();
    JavaRefactoringListenerManager.getInstance(getProject()).removeMoveMembersListener(listener);
    if (conflictMessage != null && conflictsMap.isEmpty()) {
        fail("Conflict was not detected");
    }
    if (conflictMessage == null && !conflictsMap.isEmpty()) {
        fail(conflictsMap.values().iterator().next());
    }
    if (conflictMessage != null && !IGNORE_CONFLICTS.equals(conflictMessage)) {
        TreeSet<String> conflicts = new TreeSet<>(conflictsMap.values());
        assertEquals(conflictMessage, conflicts.iterator().next());
        return;
    }
    if (checkMembersMovedCount) {
        assertEquals(countMoved[0], membersToFind.length);
    }
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
Also used : PullUpConflictsUtil(com.intellij.refactoring.memberPullUp.PullUpConflictsUtil) UIUtil(com.intellij.util.ui.UIUtil) LanguageLevel(com.intellij.pom.java.LanguageLevel) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) Arrays(java.util.Arrays) JavaTestUtil(com.intellij.JavaTestUtil) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) TreeSet(java.util.TreeSet) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) MoveMemberListener(com.intellij.refactoring.listeners.MoveMemberListener) JavaRefactoringListenerManager(com.intellij.refactoring.listeners.JavaRefactoringListenerManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) MultiMap(com.intellij.util.containers.MultiMap) MoveMemberListener(com.intellij.refactoring.listeners.MoveMemberListener) MultiMap(com.intellij.util.containers.MultiMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) TreeSet(java.util.TreeSet) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 2 with DocCommentPolicy

use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.

the class PushDownMultifileTest method doTest.

private void doTest(final boolean fail, final String sourceClassName, final String targetClassName) throws Exception {
    try {
        doTest((rootDir, rootAfter) -> {
            final PsiClass srcClass = myJavaFacade.findClass(sourceClassName, GlobalSearchScope.allScope(myProject));
            assertTrue("Source class not found", srcClass != null);
            final PsiClass targetClass = myJavaFacade.findClass(targetClassName, GlobalSearchScope.allScope(myProject));
            assertTrue("Target class not found", targetClass != null);
            final PsiMethod[] methods = srcClass.getMethods();
            assertTrue("No methods found", methods.length > 0);
            final MemberInfo memberInfo = new MemberInfo(methods[0]);
            memberInfo.setChecked(true);
            new PushDownProcessor<>(srcClass, Collections.singletonList(memberInfo), new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
        //LocalFileSystem.getInstance().refresh(false);
        //FileDocumentManager.getInstance().saveAllDocuments();
        });
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
        if (fail) {
            return;
        } else {
            throw e;
        }
    }
    if (fail) {
        fail("Conflict was not detected");
    }
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 3 with DocCommentPolicy

use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.

the class PushDownMultifileTest method testUsagesInXml.

public void testUsagesInXml() throws Exception {
    try {
        doTest((rootDir, rootAfter) -> {
            final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
            assertTrue("Source class not found", srcClass != null);
            final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
            assertTrue("Target class not found", targetClass != null);
            final PsiField[] fields = srcClass.getFields();
            assertTrue("No methods found", fields.length > 0);
            final MemberInfo memberInfo = new MemberInfo(fields[0]);
            memberInfo.setChecked(true);
            new PushDownProcessor<>(srcClass, Collections.singletonList(memberInfo), new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
        //LocalFileSystem.getInstance().refresh(false);
        //FileDocumentManager.getInstance().saveAllDocuments();
        });
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
        assertEquals(e.getMessage(), "Class <b><code>b.B</code></b> is package-private and will not be accessible from file <b><code>A.form</code></b>.");
        return;
    }
    fail("Conflict was not detected");
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 4 with DocCommentPolicy

use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.

the class ExtractSuperclassHandler method doRefactoring.

// invoked inside Command and Atomic action
private static void doRefactoring(final Project project, final PsiClass subclass, final ExtractSuperclassDialog dialog) {
    final String superclassName = dialog.getExtractedSuperName();
    final PsiDirectory targetDirectory = dialog.getTargetDirectory();
    final MemberInfo[] selectedMemberInfos = ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class);
    final DocCommentPolicy javaDocPolicy = new DocCommentPolicy(dialog.getDocCommentPolicy());
    LocalHistoryAction a = LocalHistory.getInstance().startAction(getCommandName(subclass, superclassName));
    try {
        final PsiClass superclass;
        try {
            superclass = ExtractSuperClassUtil.extractSuperClass(project, targetDirectory, superclassName, subclass, selectedMemberInfos, javaDocPolicy);
        } finally {
            a.finish();
        }
        // ask whether to search references to subclass and turn them into refs to superclass if possible
        ExtractClassUtil.suggestToTurnRefsToSuper(project, superclass, subclass);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) LocalHistoryAction(com.intellij.history.LocalHistoryAction) IncorrectOperationException(com.intellij.util.IncorrectOperationException) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 5 with DocCommentPolicy

use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.

the class PullAsAbstractUpFix method pullUp.

private static void pullUp(PsiMethod method, PsiClass containingClass, PsiClass baseClass) {
    if (!FileModificationService.getInstance().prepareFileForWrite(baseClass.getContainingFile()))
        return;
    final MemberInfo memberInfo = new MemberInfo(method);
    memberInfo.setChecked(true);
    memberInfo.setToAbstract(true);
    new PullUpProcessor(containingClass, baseClass, new MemberInfo[] { memberInfo }, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Aggregations

DocCommentPolicy (com.intellij.refactoring.util.DocCommentPolicy)13 MemberInfo (com.intellij.refactoring.util.classMembers.MemberInfo)10 UsageInfo (com.intellij.usageView.UsageInfo)4 PullUpProcessor (com.intellij.refactoring.memberPullUp.PullUpProcessor)3 Arrays (java.util.Arrays)3 NotNull (org.jetbrains.annotations.NotNull)3 JavaTestUtil (com.intellij.JavaTestUtil)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 com.intellij.psi (com.intellij.psi)2 PsiClass (com.intellij.psi.PsiClass)2 PostprocessReformattingAspect (com.intellij.psi.impl.source.PostprocessReformattingAspect)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 PullUpConflictsUtil (com.intellij.refactoring.memberPullUp.PullUpConflictsUtil)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 MultiMap (com.intellij.util.containers.MultiMap)2 ArrayList (java.util.ArrayList)2 FlexTestUtils (com.intellij.flex.util.FlexTestUtils)1 LocalHistoryAction (com.intellij.history.LocalHistoryAction)1 FlexStylesIndexableSetContributor (com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor)1 FlexSchemaHandler (com.intellij.javascript.flex.mxml.schema.FlexSchemaHandler)1