Search in sources :

Example 1 with XmlBackedJSClassImpl

use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.

the class FlexResolveHelper method importClass.

public boolean importClass(final PsiScopeProcessor processor, final PsiNamedElement file) {
    // there is no need to process package stuff at function level
    if (file instanceof JSFunction)
        return true;
    if (file instanceof XmlBackedJSClassImpl) {
        if (!processInlineComponentsInScope((XmlBackedJSClassImpl) file, inlineComponent -> processor.execute(inlineComponent, ResolveState.initial()))) {
            return false;
        }
    }
    final String packageQualifierText = JSResolveUtil.findPackageStatementQualifier(file);
    final Project project = file.getProject();
    GlobalSearchScope scope = JSResolveUtil.getResolveScope(file);
    final MxmlAndFxgFilesProcessor filesProcessor = new MxmlAndFxgFilesProcessor() {

        final PsiManager manager = PsiManager.getInstance(project);

        public void addDependency(final PsiDirectory directory) {
        }

        public boolean processFile(final VirtualFile file, final VirtualFile root) {
            final PsiFile xmlFile = manager.findFile(file);
            if (!(xmlFile instanceof XmlFile))
                return true;
            return processor.execute(XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) xmlFile), ResolveState.initial());
        }
    };
    PsiFile containingFile = file.getContainingFile();
    boolean completion = containingFile.getOriginalFile() != containingFile;
    if (completion) {
        return processAllMxmlAndFxgFiles(scope, project, filesProcessor, null);
    } else {
        if (packageQualifierText != null && packageQualifierText.length() > 0) {
            if (!processMxmlAndFxgFilesInPackage(scope, project, packageQualifierText, filesProcessor))
                return false;
        }
        return processMxmlAndFxgFilesInPackage(scope, project, "", filesProcessor);
    }
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) XmlFile(com.intellij.psi.xml.XmlFile) JSChangeUtil(com.intellij.lang.javascript.psi.impl.JSChangeUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FilenameIndex(com.intellij.psi.search.FilenameIndex) ContainerUtil(com.intellij.util.containers.ContainerUtil) ResolveProcessor(com.intellij.lang.javascript.psi.resolve.ResolveProcessor) DirectoryIndex(com.intellij.openapi.roots.impl.DirectoryIndex) Query(com.intellij.util.Query) Project(com.intellij.openapi.project.Project) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) JSResolveHelper(com.intellij.lang.javascript.flex.JSResolveHelper) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) CssString(com.intellij.psi.css.CssString) JSFile(com.intellij.lang.javascript.psi.JSFile) XmlTag(com.intellij.psi.xml.XmlTag) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) com.intellij.lang.javascript.psi.ecmal4(com.intellij.lang.javascript.psi.ecmal4) JSImportHandlingUtil(com.intellij.lang.javascript.psi.resolve.JSImportHandlingUtil) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) JSResolveUtil(com.intellij.lang.javascript.psi.resolve.JSResolveUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSPsiImplUtils(com.intellij.lang.javascript.psi.impl.JSPsiImplUtils) ImportUtils(com.intellij.lang.javascript.flex.ImportUtils) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Processor(com.intellij.util.Processor) MxmlJSClassProvider(com.intellij.javascript.flex.mxml.MxmlJSClassProvider) com.intellij.psi(com.intellij.psi) Ref(com.intellij.openapi.util.Ref) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) CssString(com.intellij.psi.css.CssString) Project(com.intellij.openapi.project.Project) JSFunction(com.intellij.lang.javascript.psi.JSFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 2 with XmlBackedJSClassImpl

use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.

the class ActionScriptSmartCompletionContributor method getEventsMap.

public static Map<String, String> getEventsMap(JSClass clazzToProcess) {
    if (clazzToProcess == null)
        return Collections.emptyMap();
    final Map<String, String> eventsMap = new THashMap<>();
    class EventsDataCollector extends ResolveProcessor implements ActionScriptResolveUtil.MetaDataProcessor {

        public EventsDataCollector() {
            super(null);
            setToProcessHierarchy(true);
            setToProcessMembers(false);
            setTypeContext(true);
            setLocalResolve(true);
        }

        @Override
        public boolean process(@NotNull final JSAttribute jsAttribute) {
            if ("Event".equals(jsAttribute.getName())) {
                final JSAttributeNameValuePair eventAttr = jsAttribute.getValueByName("name");
                JSAttributeNameValuePair typeAttr = jsAttribute.getValueByName("type");
                if (eventAttr != null && typeAttr != null) {
                    final String simpleValue = eventAttr.getSimpleValue();
                    if (simpleValue != null) {
                        eventsMap.put(simpleValue, typeAttr.getSimpleValue());
                    }
                }
            }
            return true;
        }

        @Override
        public boolean handleOtherElement(final PsiElement el, final PsiElement context, final Ref<PsiElement> continuePassElement) {
            return true;
        }

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if (element instanceof JSClass) {
                ActionScriptResolveUtil.processMetaAttributesForClass(element, this, true);
            }
            return true;
        }
    }
    final EventsDataCollector eventsDataCollector = new EventsDataCollector();
    if (clazzToProcess instanceof XmlBackedJSClassImpl) {
        XmlFile file = (XmlFile) clazzToProcess.getParent().getContainingFile();
        if (file != null && JavaScriptSupportLoader.isFlexMxmFile(file)) {
            final XmlDocument xmlDocument = file.getDocument();
            final XmlTag rootTag = xmlDocument == null ? null : xmlDocument.getRootTag();
            final XmlTag[] tags = rootTag == null ? XmlTag.EMPTY : MxmlJSClass.findLanguageSubTags(rootTag, FlexPredefinedTagNames.METADATA);
            JSResolveUtil.JSInjectedFilesVisitor injectedFilesVisitor = new JSResolveUtil.JSInjectedFilesVisitor() {

                @Override
                protected void process(JSFile file) {
                    for (PsiElement element : file.getChildren()) {
                        if (element instanceof JSAttributeList) {
                            ActionScriptResolveUtil.processAttributeList(eventsDataCollector, null, (JSAttributeList) element, true, true);
                        }
                    }
                }
            };
            for (XmlTag tag : tags) {
                JSResolveUtil.processInjectedFileForTag(tag, injectedFilesVisitor);
            }
        }
    }
    clazzToProcess.processDeclarations(eventsDataCollector, ResolveState.initial(), clazzToProcess, clazzToProcess);
    return eventsMap;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) NotNull(org.jetbrains.annotations.NotNull) ResolveState(com.intellij.psi.ResolveState) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 3 with XmlBackedJSClassImpl

use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.

the class FlexTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    List<AbstractTreeNode> result = new ArrayList<>();
    if (parent instanceof SwfQualifiedNamedElementNode || parent instanceof FlexFileNode) {
        if (((ProjectViewNode) parent).getSettings().isShowMembers()) {
            JSQualifiedNamedElement parentElement = getElement(parent);
            if (parentElement != null) {
                JSStructureViewElement structureViewElement = parentElement instanceof XmlBackedJSClassImpl ? new FlexStructureViewElement(((XmlBackedJSClassImpl) parentElement), (XmlFile) parentElement.getContainingFile(), false) : new JSStructureViewElement(parentElement, false, true);
                StructureViewTreeElement[] structureViewChildren = structureViewElement.getChildren();
                for (final StructureViewTreeElement structureViewChild : structureViewChildren) {
                    if (structureViewChild instanceof JSStructureViewElement) {
                        PsiElement childElement = ((JSStructureViewElement) structureViewChild).getValue();
                        result.add(new FlexClassMemberNode((JSElement) childElement, ((ProjectViewNode) parent).getSettings()));
                    } else {
                        result.add(new UnknownNode(parentElement.getProject(), structureViewChild, ((ProjectViewNode) parent).getSettings()));
                    }
                }
            }
        }
    } else {
        for (final AbstractTreeNode child : children) {
            Object o = child.getValue();
            if (o instanceof JSFileImpl && !(o instanceof PsiCompiledFile) && DialectDetector.isActionScript((PsiFile) o) || o instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) o)) {
                result.add(new FlexFileNode((PsiFile) o, ((ProjectViewNode) parent).getSettings()));
                continue;
            }
            result.add(child);
        }
    }
    return result;
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSStructureViewElement(com.intellij.lang.javascript.structureView.JSStructureViewElement) FlexStructureViewElement(com.intellij.lang.javascript.flex.presentation.FlexStructureViewProvider.FlexStructureViewElement) JSFileImpl(com.intellij.lang.javascript.psi.impl.JSFileImpl) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiCompiledFile(com.intellij.psi.PsiCompiledFile) JSElement(com.intellij.lang.javascript.psi.JSElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with XmlBackedJSClassImpl

use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.

the class FlashUmlDataModel method createEdge.

@Override
@Nullable
public DiagramEdge<Object> createEdge(@NotNull final DiagramNode<Object> from, @NotNull final DiagramNode<Object> to) {
    final JSClass fromClass = (JSClass) from.getIdentifyingElement();
    final JSClass toClass = (JSClass) to.getIdentifyingElement();
    if (fromClass.isEquivalentTo(toClass)) {
        return null;
    }
    if (toClass.isInterface()) {
        if (JSPsiImplUtils.containsEquivalent(fromClass.isInterface() ? fromClass.getSuperClasses() : fromClass.getImplementedInterfaces(), toClass)) {
            return null;
        }
        Callable<DiagramEdge<Object>> callable = () -> {
            String targetQName = toClass.getQualifiedName();
            JSRefactoringUtil.addToSupersList(fromClass, targetQName, true);
            if (targetQName.contains(".") && !(fromClass instanceof XmlBackedJSClassImpl)) {
                List<FormatFixer> formatters = new ArrayList<>();
                formatters.add(ImportUtils.insertImportStatements(fromClass, Collections.singletonList(targetQName)));
                formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
                FormatFixer.fixAll(formatters);
            }
            return addEdgeAndRefresh(from, to, fromClass.isInterface() ? FlashUmlRelationship.GENERALIZATION : FlashUmlRelationship.INTERFACE_GENERALIZATION);
        };
        String commandName = FlexBundle.message(fromClass.isInterface() ? "create.extends.relationship.command.name" : "create.implements.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
        return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
    } else {
        if (fromClass.isInterface()) {
            return null;
        } else if (fromClass instanceof XmlBackedJSClassImpl) {
            JSClass[] superClasses = fromClass.getSuperClasses();
            if (JSPsiImplUtils.containsEquivalent(superClasses, toClass)) {
                return null;
            }
            if (superClasses.length > 0) {
                // if base component is not resolved, replace it silently
                final JSClass currentParent = superClasses[0];
                if (Messages.showYesNoDialog(FlexBundle.message("replace.base.component.prompt", currentParent.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("create.edge.title"), Messages.getQuestionIcon()) == Messages.NO) {
                    return null;
                }
            }
            Callable<DiagramEdge<Object>> callable = () -> {
                NewFlexComponentAction.setParentComponent((MxmlJSClass) fromClass, toClass.getQualifiedName());
                return addEdgeAndRefresh(from, to, DiagramRelationships.GENERALIZATION);
            };
            String commandName = FlexBundle.message("create.extends.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
            return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
        } else {
            final JSClass[] superClasses = fromClass.getSuperClasses();
            if (JSPsiImplUtils.containsEquivalent(superClasses, toClass)) {
                return null;
            }
            if (superClasses.length > 0 && !JSResolveUtil.isObjectClass(superClasses[0])) {
                // if base class is not resolved, replace it silently
                final JSClass currentParent = superClasses[0];
                if (Messages.showYesNoDialog(FlexBundle.message("replace.base.class.prompt", currentParent.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("create.edge.title"), Messages.getQuestionIcon()) == Messages.NO) {
                    return null;
                }
            }
            Callable<DiagramEdge<Object>> callable = () -> {
                List<FormatFixer> formatters = new ArrayList<>();
                boolean optimize = false;
                if (superClasses.length > 0 && !JSResolveUtil.isObjectClass(superClasses[0])) {
                    JSRefactoringUtil.removeFromReferenceList(fromClass.getExtendsList(), superClasses[0], formatters);
                    optimize = needsImport(fromClass, superClasses[0]);
                }
                JSRefactoringUtil.addToSupersList(fromClass, toClass.getQualifiedName(), false);
                if (needsImport(fromClass, toClass)) {
                    formatters.add(ImportUtils.insertImportStatements(fromClass, Collections.singletonList(toClass.getQualifiedName())));
                    optimize = true;
                }
                if (optimize) {
                    formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
                }
                FormatFixer.fixAll(formatters);
                return addEdgeAndRefresh(from, to, DiagramRelationships.GENERALIZATION);
            };
            String commandName = FlexBundle.message("create.extends.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
            return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
        }
    }
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) Callable(java.util.concurrent.Callable) JSReferenceList(com.intellij.lang.javascript.psi.ecmal4.JSReferenceList) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) FormatFixer(com.intellij.lang.javascript.refactoring.FormatFixer) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with XmlBackedJSClassImpl

use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.

the class MyImplicitUsageProvider method isImplicitUsage.

@Override
public boolean isImplicitUsage(PsiElement element) {
    if (!(element instanceof JSFunction)) {
        return false;
    }
    final JSFunction method = (JSFunction) element;
    final String methodName = method.getName();
    if (methodName == null || !Character.isUpperCase(methodName.charAt(0)) || !(method.getParent() instanceof JSClass) || method.getParent() instanceof XmlBackedJSClassImpl) {
        return false;
    }
    final JSClass clazz = (JSClass) method.getParent();
    if (!ActionScriptClassResolver.isParentClass(clazz, "com.intellij.flex.uiDesigner.TestCase")) {
        return false;
    }
    final JSAttributeList attributeList = method.getAttributeList();
    if (attributeList == null || attributeList.getAccessType() != JSAttributeList.AccessType.PUBLIC) {
        return false;
    }
    final VirtualFile projectBaseDir = element.getProject().getBaseDir();
    if (projectBaseDir == null) {
        return false;
    }
    File testSourcePath = new File(projectBaseDir.getPath(), RELATIVE_TEST_DATA_PATH);
    if (!testSourcePath.exists()) {
        testSourcePath = new File(projectBaseDir.getPath(), "flex/tools/flex-ui-designer/" + RELATIVE_TEST_DATA_PATH);
        assert testSourcePath.exists();
    }
    final JSAttributeList classAttributeList = clazz.getAttributeList();
    if (classAttributeList != null) {
        final JSAttribute testAnnotation = classAttributeList.findAttributeByName("Test");
        if (testAnnotation == null) {
            return false;
        }
        return new File(testSourcePath, testAnnotation.getValueByName("dir").getSimpleValue() + File.separatorChar + methodName + ".mxml").exists();
    }
    return false;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)13 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)6 PsiElement (com.intellij.psi.PsiElement)6 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)5 Nullable (org.jetbrains.annotations.Nullable)5 XmlFile (com.intellij.psi.xml.XmlFile)4 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)3 Ref (com.intellij.openapi.util.Ref)3 XmlTag (com.intellij.psi.xml.XmlTag)3 JSFile (com.intellij.lang.javascript.psi.JSFile)2 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)2 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)2 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2 JSReferenceList (com.intellij.lang.javascript.psi.ecmal4.JSReferenceList)2 JSResolveUtil (com.intellij.lang.javascript.psi.resolve.JSResolveUtil)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)2 THashMap (gnu.trove.THashMap)2 THashSet (gnu.trove.THashSet)2