Search in sources :

Example 86 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlashUmlTest method doTestImpl.

private DiagramBuilder doTestImpl(@Nullable File projectRoot, String[] files, String[] additionalClasses, Computable<GlobalSearchScope> scopeProvider, @Nullable EnumSet<FlashUmlDependenciesSettingsOption> dependencies, @Nullable String expectedFileNamePrefix) throws Exception {
    List<VirtualFile> vFiles = new ArrayList<>(files.length);
    for (String file : files) {
        vFiles.add(getVirtualFile(BASE_PATH + file));
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
        final ModifiableRootModel rootModel = rootManager.getModifiableModel();
        ContentEntry[] contentEntries = rootModel.getContentEntries();
        for (ContentEntry contentEntry : contentEntries) {
            rootModel.removeContentEntry(contentEntry);
        }
        rootModel.commit();
    });
    configureByFiles(projectRoot, VfsUtilCore.toVirtualFileArray(vFiles));
    final LinkedHashMap<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
    assertFalse(markers.isEmpty());
    DiagramBuilder builder = null;
    int i = 1;
    for (Map.Entry<Integer, String> marker : markers.entrySet()) {
        getEditor().getCaretModel().moveToOffset(marker.getKey());
        i++;
        String expectedPrefix = StringUtil.isNotEmpty(marker.getValue()) ? marker.getValue() : expectedFileNamePrefix;
        final DataContext dataContext = DataManager.getInstance().getDataContext();
        final DiagramProvider[] providers = DiagramProvider.findProviders(dataContext, "unknown");
        final FlashUmlProvider provider = ContainerUtil.findInstance(providers, FlashUmlProvider.class);
        assertNotNull("Flash UML provider not found", provider);
        final String actualOriginFqn = provider.getVfsResolver().getQualifiedName(provider.getElementManager().findInDataContext(dataContext));
        final Object actualOrigin = provider.getVfsResolver().resolveElementByFQN(actualOriginFqn, getProject());
        builder = UmlGraphBuilderFactory.create(myProject, provider, actualOrigin, null);
        Disposer.register(getTestRootDisposable(), builder);
        final DiagramDataModel<Object> model = builder.getDataModel();
        DiagramConfiguration configuration = DiagramConfiguration.getConfiguration();
        String originalCategories = configuration.categories.get(provider.getID());
        if (dependencies != null) {
            model.setShowDependencies(true);
            EnumSet<FlashUmlDependenciesSettingsOption> disabledOptions = EnumSet.complementOf(dependencies);
            configuration.categories.put(provider.getID(), StringUtil.join(disabledOptions, option -> option.getDisplayName(), ";"));
        } else {
            model.setShowDependencies(false);
        }
        try {
            model.refreshDataModel();
            // first limit elements by scope
            Collection<DiagramNode<Object>> nodesToRemove = new ArrayList<>();
            for (DiagramNode<Object> node : model.getNodes()) {
                if (node.getIdentifyingElement() instanceof JSClass && !scopeProvider.compute().contains(((JSClass) node.getIdentifyingElement()).getContainingFile().getVirtualFile())) {
                    nodesToRemove.add(node);
                }
            }
            for (DiagramNode<Object> node : nodesToRemove) {
                model.removeNode(node);
            }
            builder.updateGraph();
            // then add explicitly required classes
            for (String aClass : additionalClasses) {
                JSClass c = JSTestUtils.findClassByQName(aClass, GlobalSearchScope.allScope(myProject));
                final DiagramNode node = model.addElement(c);
                if (node != null) {
                    builder.createDraggedNode(node, node.getTooltip(), DiagramUtils.getBestPositionForNode(builder));
                    builder.updateGraph();
                }
            }
            assertModel(expectedPrefix, provider, actualOriginFqn, model);
        } finally {
            configuration.categories.put(provider.getID(), originalCategories);
        }
    }
    assert builder != null;
    return builder;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsRootAccess(com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) FlexStylesIndexableSetContributor(com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Disposer(com.intellij.openapi.util.Disposer) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) LoadTextUtil(com.intellij.openapi.fileEditor.impl.LoadTextUtil) DiagramBuilder(com.intellij.diagram.DiagramBuilder) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) JDOMCompare(com.intellij.util.JDOMCompare) Nullable(org.jetbrains.annotations.Nullable) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) VfsUtilCore.convertFromUrl(com.intellij.openapi.vfs.VfsUtilCore.convertFromUrl) UmlDataModelDumper(com.intellij.diagram.util.UmlDataModelDumper) JdomKt(com.intellij.util.JdomKt) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DiagramProvider(com.intellij.diagram.DiagramProvider) VfsUtilCore.urlToPath(com.intellij.openapi.vfs.VfsUtilCore.urlToPath) java.util(java.util) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) ArrayUtil(com.intellij.util.ArrayUtil) DataContext(com.intellij.openapi.actionSystem.DataContext) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) DiagramConfiguration(com.intellij.diagram.settings.DiagramConfiguration) FlashUmlDataModel(com.intellij.lang.javascript.uml.FlashUmlDataModel) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) JDOMResult(org.jdom.transform.JDOMResult) UmlGraphBuilderFactory(com.intellij.uml.UmlGraphBuilderFactory) JDOMUtil(com.intellij.openapi.util.JDOMUtil) ModuleType(com.intellij.openapi.module.ModuleType) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) DataManager(com.intellij.ide.DataManager) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) FlexSchemaHandler(com.intellij.javascript.flex.mxml.schema.FlexSchemaHandler) DiagramUtils(com.intellij.diagram.util.DiagramUtils) FlashUmlDependenciesSettingsOption(com.intellij.lang.javascript.uml.FlashUmlDependenciesSettingsOption) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) JSTestUtils(com.intellij.lang.javascript.JSTestUtils) SkipInHeadlessEnvironment(com.intellij.testFramework.SkipInHeadlessEnvironment) FlashUmlProvider(com.intellij.lang.javascript.uml.FlashUmlProvider) DiagramNode(com.intellij.diagram.DiagramNode) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) DiagramDataModel(com.intellij.diagram.DiagramDataModel) Element(org.jdom.Element) DiagramNode(com.intellij.diagram.DiagramNode) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) DiagramBuilder(com.intellij.diagram.DiagramBuilder) DataContext(com.intellij.openapi.actionSystem.DataContext) DiagramConfiguration(com.intellij.diagram.settings.DiagramConfiguration) FlashUmlProvider(com.intellij.lang.javascript.uml.FlashUmlProvider) FlashUmlDependenciesSettingsOption(com.intellij.lang.javascript.uml.FlashUmlDependenciesSettingsOption) DiagramProvider(com.intellij.diagram.DiagramProvider) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ContentEntry(com.intellij.openapi.roots.ContentEntry) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 87 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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)

Example 88 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlexMoveMembersTest method performAction.

private void performAction(String sourceClassName, final String targetClassName, final String visibility, final String[] memberNames) throws Exception {
    final JSClassResolver resolver = JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver();
    final JSClass sourceClass = (JSClass) resolver.findClassByQName(sourceClassName, ActionScriptMoveMembersDialog.getScope(myProject));
    assertNotNull("Class " + sourceClassName + " not found", sourceClass);
    JSClass targetClass = (JSClass) resolver.findClassByQName(targetClassName, ActionScriptMoveMembersDialog.getScope(myProject));
    assertNotNull("Class " + targetClassName + " not found", targetClass);
    final List<JSMemberInfo> memberInfos = new ArrayList<>();
    JSMemberInfo.extractStaticMembers(sourceClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {

        @Override
        public boolean includeMember(JSAttributeListOwner member) {
            return memberNames.length == 0 || ArrayUtil.contains(member.getName(), memberNames);
        }
    });
    JSMemberInfo.sortByOffset(memberInfos);
    for (JSMemberInfo memberInfo : memberInfos) {
        memberInfo.setChecked(true);
    }
    new JSMoveMembersProcessor(myProject, null, sourceClass, ActionScriptMoveMembersDialog.getScope(myProject), new JSMoveMembersOptions() {

        @Override
        public JSAttributeListOwner[] getSelectedMembers() {
            final JSMemberInfo[] selected = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
            JSAttributeListOwner[] result = new JSAttributeListOwner[selected.length];
            for (int i = 0; i < result.length; i++) {
                result[i] = selected[i].getMember();
            }
            return result;
        }

        @Override
        public String getTargetClassName() {
            return targetClassName;
        }

        @Override
        public String getMemberVisibility() {
            return visibility;
        }
    }).run();
    myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : JSClassResolver(com.intellij.lang.javascript.psi.resolve.JSClassResolver) JSMoveMembersProcessor(com.intellij.lang.javascript.refactoring.moveMembers.JSMoveMembersProcessor) ArrayList(java.util.ArrayList) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) JSMoveMembersOptions(com.intellij.lang.javascript.refactoring.moveMembers.JSMoveMembersOptions) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 89 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlexPullUpTest method getMemberInfos.

public static List<JSMemberInfo> getMemberInfos(final String[] members, JSClass clazz, boolean makeAbstract) {
    final List<JSMemberInfo> memberInfos = new ArrayList<>();
    JSMemberInfo.extractClassMembers(clazz, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {

        @Override
        public boolean includeMember(JSAttributeListOwner member) {
            return ArrayUtil.contains(member.getName(), members);
        }
    });
    //assertTrue("Nothing to process", !memberInfos.isEmpty());
    for (JSMemberInfo memberInfo : memberInfos) {
        memberInfo.setChecked(true);
        if (makeAbstract) {
            memberInfo.setToAbstract(true);
        }
    }
    JSMemberInfo.sortByOffset(memberInfos);
    return memberInfos;
}
Also used : ArrayList(java.util.ArrayList) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase)

Example 90 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlexPullUpTest method performAction.

private void performAction(String from, String to, final int docCommentPolicy, String[] expectedConflicts, final String[] toPullUp) {
    final JSClassResolver resolver = JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver();
    final JSClass sourceClass = (JSClass) resolver.findClassByQName(from, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("source class not found: " + sourceClass, sourceClass);
    final JSClass targetClass = (JSClass) resolver.findClassByQName(to, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("target class not found: " + targetClass, targetClass);
    assertTrue("Source should be a subclass of target", JSInheritanceUtil.isParentClass(sourceClass, targetClass));
    final List<JSMemberInfo> memberInfos = getMemberInfos(toPullUp, sourceClass, false);
    final JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
    MultiMap<PsiElement, String> conflicts = JSPullUpConflictsUtil.checkConflicts(infosArray, sourceClass, targetClass, new JSInterfaceContainmentVerifier() {

        @Override
        public boolean checkedInterfacesContain(JSFunction psiMethod) {
            return JSPullUpHelper.checkedInterfacesContain(memberInfos, psiMethod);
        }
    }, JSVisibilityUtil.DEFAULT_OPTIONS);
    ArrayList<String> messages = new ArrayList<>(conflicts.values());
    for (int i = 0; i < messages.size(); i++) {
        messages.set(i, messages.get(i).replaceAll("<[^>]+>", ""));
    }
    assertSameElements(messages, expectedConflicts);
    if (conflicts.isEmpty()) {
        WriteCommandAction.runWriteCommandAction(null, () -> {
            new JSPullUpHelper(sourceClass, targetClass, infosArray, docCommentPolicy).moveMembersToBase();
            myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
        });
        FileDocumentManager.getInstance().saveAllDocuments();
    }
}
Also used : JSClassResolver(com.intellij.lang.javascript.psi.resolve.JSClassResolver) ArrayList(java.util.ArrayList) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) JSPullUpHelper(com.intellij.lang.javascript.refactoring.memberPullUp.JSPullUpHelper) JSInterfaceContainmentVerifier(com.intellij.lang.javascript.refactoring.util.JSInterfaceContainmentVerifier) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)141 PsiElement (com.intellij.psi.PsiElement)65 Nullable (org.jetbrains.annotations.Nullable)27 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)23 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)22 JSFunction (com.intellij.lang.javascript.psi.JSFunction)18 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)18 Module (com.intellij.openapi.module.Module)17 XmlFile (com.intellij.psi.xml.XmlFile)17 Project (com.intellij.openapi.project.Project)16 PsiFile (com.intellij.psi.PsiFile)16 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)15 ArrayList (java.util.ArrayList)14 PsiDirectory (com.intellij.psi.PsiDirectory)11 XmlTag (com.intellij.psi.xml.XmlTag)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)7