Search in sources :

Example 6 with DocCommentPolicy

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

the class PullUpDialog method doAction.

protected void doAction() {
    if (!myCallback.checkConflicts(this))
        return;
    JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy();
    final PsiClass superClass = getSuperClass();
    String name = superClass.getQualifiedName();
    if (name != null) {
        StatisticsManager.getInstance().incUseCount(new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(), name));
    }
    List<MemberInfo> infos = getSelectedMemberInfos();
    invokeRefactoring(new PullUpProcessor(myClass, superClass, infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(getJavaDocPolicy())));
    close(OK_EXIT_CODE);
}
Also used : StatisticsInfo(com.intellij.psi.statistics.StatisticsInfo) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 7 with DocCommentPolicy

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

the class EncapsulateFieldsProcessor method generateAccessors.

private void generateAccessors() {
    // generate accessors
    myNameToGetter = new HashMap<>();
    myNameToSetter = new HashMap<>();
    for (FieldDescriptor fieldDescriptor : myFieldDescriptors) {
        final DocCommentPolicy<PsiDocComment> commentPolicy = new DocCommentPolicy<>(myDescriptor.getJavadocPolicy());
        PsiField field = fieldDescriptor.getField();
        final PsiDocComment docComment = field.getDocComment();
        if (myDescriptor.isToEncapsulateGet()) {
            final PsiMethod prototype = fieldDescriptor.getGetterPrototype();
            assert prototype != null;
            final PsiMethod getter = addOrChangeAccessor(prototype, myNameToGetter);
            if (docComment != null) {
                final PsiDocComment getterJavadoc = (PsiDocComment) getter.addBefore(docComment, getter.getFirstChild());
                commentPolicy.processNewJavaDoc(getterJavadoc);
            }
        }
        if (myDescriptor.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL)) {
            PsiMethod prototype = fieldDescriptor.getSetterPrototype();
            assert prototype != null;
            addOrChangeAccessor(prototype, myNameToSetter);
        }
        if (docComment != null) {
            commentPolicy.processOldJavaDoc(docComment);
        }
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 8 with DocCommentPolicy

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

the class PullUpMultifileTest method doTest.

private void doTest(final String... conflicts) throws Exception {
    final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
    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 PsiMethod[] methods = srcClass.getMethods();
        assertTrue("No methods found", methods.length > 0);
        final MemberInfo[] membersToMove = new MemberInfo[1];
        final MemberInfo memberInfo = new MemberInfo(methods[0]);
        memberInfo.setChecked(true);
        membersToMove[0] = memberInfo;
        final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
        final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
        conflictsMap.putAllValues(PullUpConflictsUtil.checkConflicts(membersToMove, srcClass, targetClass, targetPackage, targetDirectory, psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(membersToMove), psiMethod)));
        new PullUpProcessor(srcClass, targetClass, membersToMove, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
    });
    if (conflicts.length != 0 && conflictsMap.isEmpty()) {
        fail("Conflict was not detected");
    }
    final HashSet<String> values = new HashSet<>(conflictsMap.values());
    final HashSet<String> expected = new HashSet<>(Arrays.asList(conflicts));
    assertEquals(expected.size(), values.size());
    for (String value : values) {
        if (!expected.contains(value)) {
            fail("Conflict: " + value + " is unexpectedly reported");
        }
    }
}
Also used : PullUpConflictsUtil(com.intellij.refactoring.memberPullUp.PullUpConflictsUtil) HashSet(java.util.HashSet) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) Arrays(java.util.Arrays) JavaTestUtil(com.intellij.JavaTestUtil) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) com.intellij.psi(com.intellij.psi) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) NotNull(org.jetbrains.annotations.NotNull) MultiMap(com.intellij.util.containers.MultiMap) MultiMap(com.intellij.util.containers.MultiMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) HashSet(java.util.HashSet)

Example 9 with DocCommentPolicy

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

the class PushDownTest method doTestImplements.

private void doTestImplements(boolean toAbstract, boolean failure) {
    configureByFile(BASE_PATH + getTestName(false) + ".java");
    PsiClass currentClass = JavaPsiFacade.getInstance(getProject()).findClass("Test", GlobalSearchScope.projectScope(getProject()));
    MemberInfoStorage memberInfoStorage = new MemberInfoStorage(currentClass, element -> true);
    List<MemberInfo> members = memberInfoStorage.getClassMemberInfos(currentClass);
    for (MemberInfo member : members) {
        member.setChecked(true);
        if (toAbstract) {
            member.setToAbstract(toAbstract);
        }
    }
    new PushDownProcessor<MemberInfo, PsiMember, PsiClass>(currentClass, members, new DocCommentPolicy(DocCommentPolicy.ASIS)) {

        @Override
        protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
            if (failure == conflicts.isEmpty()) {
                fail(failure ? "Conflict was not detected" : "False conflict was detected");
            }
            return true;
        }
    }.run();
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
Also used : MemberInfoStorage(com.intellij.refactoring.util.classMembers.MemberInfoStorage) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) UsageInfo(com.intellij.usageView.UsageInfo)

Example 10 with DocCommentPolicy

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

the class PushDownTest method doTest.

private void doTest(final boolean failure) {
    configureByFile(BASE_PATH + getTestName(false) + ".java");
    final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    assertTrue("<caret> is not on member name", targetElement instanceof PsiMember);
    final PsiMember psiMember = (PsiMember) targetElement;
    final PsiClass currentClass = psiMember.getContainingClass();
    assert currentClass != null;
    final List<MemberInfo> membersToMove = new ArrayList<>();
    final PsiField fieldByName = currentClass.findFieldByName("fieldToMove", false);
    if (fieldByName != null) {
        final MemberInfo memberInfo = new MemberInfo(fieldByName);
        memberInfo.setChecked(true);
        membersToMove.add(memberInfo);
    }
    final PsiClass classByName = currentClass.findInnerClassByName("ClassToMove", false);
    if (classByName != null) {
        final MemberInfo memberInfo = new MemberInfo(classByName);
        memberInfo.setChecked(true);
        membersToMove.add(memberInfo);
    }
    final MemberInfo memberInfo = new MemberInfo(psiMember);
    memberInfo.setChecked(true);
    membersToMove.add(memberInfo);
    new PushDownProcessor<MemberInfo, PsiMember, PsiClass>(currentClass, membersToMove, new DocCommentPolicy(DocCommentPolicy.ASIS)) {

        @Override
        protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
            if (failure == conflicts.isEmpty()) {
                fail(failure ? "Conflict was not detected" : "False conflict was detected");
            }
            return true;
        }
    }.run();
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
Also used : ArrayList(java.util.ArrayList) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) UsageInfo(com.intellij.usageView.UsageInfo)

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