Search in sources :

Example 11 with DocCommentPolicy

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

the class InlineSuperClassRefactoringProcessor method performRefactoring.

protected void performRefactoring(@NotNull final UsageInfo[] usages) {
    try {
        final UsageInfo[] infos = ContainerUtil.map2Array(myTargetClasses, UsageInfo.class, UsageInfo::new);
        new PushDownProcessor<>(mySuperClass, Arrays.asList(myMemberInfos), new DocCommentPolicy(myPolicy)).pushDownToClasses(infos);
        CommonRefactoringUtil.sortDepthFirstRightLeftOrder(usages);
        for (UsageInfo usageInfo : usages) {
            if (!(usageInfo instanceof ReplaceExtendsListUsageInfo || usageInfo instanceof RemoveImportUsageInfo)) {
                try {
                    ((FixableUsageInfo) usageInfo).fixUsage();
                } catch (IncorrectOperationException e) {
                    LOG.info(e);
                }
            }
        }
        replaceInnerTypeUsages();
        //postpone broken hierarchy
        for (UsageInfo usage : usages) {
            if (usage instanceof ReplaceExtendsListUsageInfo || usage instanceof RemoveImportUsageInfo) {
                ((FixableUsageInfo) usage).fixUsage();
            }
        }
        //delete the class if all refs replaced
        if (myCurrentInheritor == null) {
            mySuperClass.delete();
        }
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
Also used : FixableUsageInfo(com.intellij.refactoring.util.FixableUsageInfo) IncorrectOperationException(com.intellij.util.IncorrectOperationException) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) UsageInfo(com.intellij.usageView.UsageInfo) FixableUsageInfo(com.intellij.refactoring.util.FixableUsageInfo)

Example 12 with DocCommentPolicy

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

the class ExtractSuperClassTest method testAnonymClass.

public void testAnonymClass() throws Exception {
    String rootBefore = getRoot() + "/before";
    PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk14());
    final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
    PsiClass psiClass = myJavaFacade.findClass("Test", ProjectScope.getAllScope(myProject));
    assertNotNull(psiClass);
    final PsiField[] fields = psiClass.getFields();
    assertTrue(fields.length == 1);
    final PsiExpression initializer = fields[0].getInitializer();
    assertNotNull(initializer);
    assertInstanceOf(initializer, PsiNewExpression.class);
    final PsiAnonymousClass anonymousClass = ((PsiNewExpression) initializer).getAnonymousClass();
    assertNotNull(anonymousClass);
    final ArrayList<MemberInfo> infos = new ArrayList<>();
    MemberInfo.extractClassMembers(anonymousClass, infos, member -> true, false);
    for (MemberInfo info : infos) {
        info.setChecked(true);
    }
    new WriteCommandAction.Simple(myProject) {

        @Override
        protected void run() throws Throwable {
            ExtractSuperClassUtil.extractSuperClass(myProject, psiClass.getContainingFile().getContainingDirectory(), "TestSubclass", anonymousClass, infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(DocCommentPolicy.ASIS));
        }
    }.execute();
    String rootAfter = getRoot() + "/after";
    VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
    myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
    IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ArrayList(java.util.ArrayList) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 13 with DocCommentPolicy

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

the class FlexPushDownTest method performAction.

private void performAction(String from, int docCommentPolicy, boolean makeAbstract, final String[] toPushDown) {
    final JSClass sourceClass = (JSClass) JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver().findClassByQName(from, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("source class not found: " + from, sourceClass);
    assertTrue(sourceClass.getQualifiedName() + " has no inheritors", !JSInheritanceUtil.findDirectSubClasses(sourceClass, false).isEmpty());
    final List<JSMemberInfo> memberInfos = FlexPullUpTest.getMemberInfos(toPushDown, sourceClass, makeAbstract);
    JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
    new JSPushDownProcessor(myProject, infosArray, sourceClass, docCommentPolicy) {

        @Override
        @NotNull
        protected UsageInfo[] findUsages() {
            // ensure stable order
            final UsageInfo[] usages = super.findUsages();
            Arrays.sort(usages, (o1, o2) -> ((JSClass) o1.getElement()).getQualifiedName().compareTo(((JSClass) o2.getElement()).getQualifiedName()));
            return usages;
        }
    }.run();
    myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : VfsRootAccess(com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess) VfsUtilCore.urlToPath(com.intellij.openapi.vfs.VfsUtilCore.urlToPath) Arrays(java.util.Arrays) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSPushDownProcessor(com.intellij.lang.javascript.refactoring.memberPushDown.JSPushDownProcessor) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) UsageInfo(com.intellij.usageView.UsageInfo) BaseRefactoringProcessor(com.intellij.refactoring.BaseRefactoringProcessor) FlexStylesIndexableSetContributor(com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor) Conditions(com.intellij.openapi.util.Conditions) ModuleType(com.intellij.openapi.module.ModuleType) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) StringUtil(com.intellij.openapi.util.text.StringUtil) MultiFileTestCase(com.intellij.refactoring.MultiFileTestCase) FlexSchemaHandler(com.intellij.javascript.flex.mxml.schema.FlexSchemaHandler) JSDialectSpecificHandlersFactory(com.intellij.lang.javascript.dialects.JSDialectSpecificHandlersFactory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) VfsUtilCore.convertFromUrl(com.intellij.openapi.vfs.VfsUtilCore.convertFromUrl) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) NotNull(org.jetbrains.annotations.NotNull) JSInheritanceUtil(com.intellij.lang.javascript.psi.resolve.JSInheritanceUtil) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) JSPushDownProcessor(com.intellij.lang.javascript.refactoring.memberPushDown.JSPushDownProcessor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) NotNull(org.jetbrains.annotations.NotNull)

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