Search in sources :

Example 26 with JSQualifiedNamedElement

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

the class SwfProjectViewStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    if (!(parent instanceof PsiFileNode)) {
        return children;
    }
    final PsiFile psiFile = ((PsiFileNode) parent).getValue();
    if (!(psiFile instanceof PsiCompiledFile) || !(psiFile instanceof JSFile)) {
        return children;
    }
    final VirtualFile vFile = psiFile.getVirtualFile();
    if (vFile == null || vFile.getFileType() != FlexApplicationComponent.SWF_FILE_TYPE) {
        return children;
    }
    if (isTooManySWFs(vFile.getParent())) {
        return children;
    }
    List<JSQualifiedNamedElement> elements = new ArrayList<>();
    for (JSSourceElement e : ((JSFile) psiFile).getStatements()) {
        if (e instanceof JSQualifiedNamedElement) {
            String qName = ((JSQualifiedNamedElement) e).getQualifiedName();
            if (qName == null) {
                final Attachment attachment = e.getParent() != null ? new Attachment("Parent element.txt", e.getParent().getText()) : new Attachment("Element text.txt", e.getText());
                LOG.error(LogMessageEx.createEvent("Null qname: '" + e.getClass().getName() + "'", DebugUtil.currentStackTrace(), attachment));
                continue;
            }
            elements.add((JSQualifiedNamedElement) e);
        } else if (e instanceof JSVarStatement) {
            Collections.addAll(elements, ((JSVarStatement) e).getVariables());
        }
    }
    Collections.sort(elements, QNAME_COMPARATOR);
    return getChildrenForPackage("", elements, 0, elements.size(), psiFile.getProject(), ((PsiFileNode) parent).getSettings());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) PsiCompiledFile(com.intellij.psi.PsiCompiledFile) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiFile(com.intellij.psi.PsiFile) Attachment(com.intellij.openapi.diagnostic.Attachment) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with JSQualifiedNamedElement

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

the class SwfProjectViewStructureProvider method getChildrenForPackage.

static Collection<AbstractTreeNode> getChildrenForPackage(String aPackage, List<JSQualifiedNamedElement> elements, int from, int to, Project project, ViewSettings settings) {
    List<AbstractTreeNode> packages = new ArrayList<>();
    List<AbstractTreeNode> classes = new ArrayList<>();
    int subpackageStart = -1;
    String currentSubpackage = null;
    for (int i = from; i < to; i++) {
        JSQualifiedNamedElement element = elements.get(i);
        String qName = element.getQualifiedName();
        assert aPackage.isEmpty() || qName.startsWith(aPackage + ".") : qName + " does not start with " + aPackage;
        if (StringUtil.getPackageName(qName).equals(aPackage)) {
            classes.add(new SwfQualifiedNamedElementNode(project, element, settings));
        } else {
            final int endIndex = qName.indexOf('.', aPackage.length() + 1);
            if (endIndex <= 0) {
                final Attachment attachment = element.getParent() != null ? new Attachment("Parent element.txt", element.getParent().getText()) : new Attachment("Element text.txt", element.getText());
                LOG.error(LogMessageEx.createEvent("package=[" + aPackage + "], qName=[" + qName + "]", DebugUtil.currentStackTrace(), attachment));
                continue;
            }
            String subpackage = settings.isFlattenPackages() ? StringUtil.getPackageName(qName) : qName.substring(0, endIndex);
            if (currentSubpackage == null) {
                subpackageStart = i;
            } else if (!currentSubpackage.equals(subpackage)) {
                packages.add(createSubpackageNode(elements, project, settings, subpackageStart, i, currentSubpackage));
                subpackageStart = i;
            }
            currentSubpackage = subpackage;
        }
    }
    if (currentSubpackage != null) {
        packages.add(createSubpackageNode(elements, project, settings, subpackageStart, to, currentSubpackage));
    }
    return ContainerUtil.concat(packages, classes);
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) Attachment(com.intellij.openapi.diagnostic.Attachment)

Aggregations

JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)27 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)13 PsiElement (com.intellij.psi.PsiElement)12 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiFile (com.intellij.psi.PsiFile)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)8 JSFile (com.intellij.lang.javascript.psi.JSFile)4 Project (com.intellij.openapi.project.Project)4 XmlFile (com.intellij.psi.xml.XmlFile)4 Nullable (org.jetbrains.annotations.Nullable)4 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 Module (com.intellij.openapi.module.Module)3 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 ArrayList (java.util.ArrayList)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 Attachment (com.intellij.openapi.diagnostic.Attachment)2