Search in sources :

Example 1 with PsiCompiledFile

use of com.intellij.psi.PsiCompiledFile 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 2 with PsiCompiledFile

use of com.intellij.psi.PsiCompiledFile 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 3 with PsiCompiledFile

use of com.intellij.psi.PsiCompiledFile in project intellij-community by JetBrains.

the class CompletionUtilCoreImpl method getOriginalElement.

@Nullable
public static <T extends PsiElement> T getOriginalElement(@NotNull T psi, PsiFile containingFile) {
    if (containingFile == null)
        return psi;
    PsiFile originalFile = containingFile.getOriginalFile();
    TextRange range;
    if (originalFile != containingFile && !(originalFile instanceof PsiCompiledFile) && (range = psi.getTextRange()) != null) {
        Integer start = range.getStartOffset();
        Integer end = range.getEndOffset();
        Document document = containingFile.getViewProvider().getDocument();
        if (document != null) {
            Document hostDocument = document instanceof DocumentWindow ? ((DocumentWindow) document).getDelegate() : document;
            OffsetTranslator translator = hostDocument.getUserData(OffsetTranslator.RANGE_TRANSLATION);
            if (translator != null) {
                if (document instanceof DocumentWindow) {
                    TextRange translated = ((DocumentWindow) document).injectedToHost(new TextRange(start, end));
                    start = translated.getStartOffset();
                    end = translated.getEndOffset();
                }
                start = translator.translateOffset(start);
                end = translator.translateOffset(end);
                if (start == null || end == null) {
                    return null;
                }
                if (document instanceof DocumentWindow) {
                    start = ((DocumentWindow) document).hostToInjected(start);
                    end = ((DocumentWindow) document).hostToInjected(end);
                }
            }
        }
        //noinspection unchecked
        return (T) PsiTreeUtil.findElementOfClassAtRange(originalFile, start, end, psi.getClass());
    }
    return psi;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) PsiCompiledFile(com.intellij.psi.PsiCompiledFile) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiCompiledFile (com.intellij.psi.PsiCompiledFile)3 PsiFile (com.intellij.psi.PsiFile)3 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2 NotNull (org.jetbrains.annotations.NotNull)2 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)1 FlexStructureViewElement (com.intellij.lang.javascript.flex.presentation.FlexStructureViewProvider.FlexStructureViewElement)1 JSElement (com.intellij.lang.javascript.psi.JSElement)1 JSFileImpl (com.intellij.lang.javascript.psi.impl.JSFileImpl)1 JSStructureViewElement (com.intellij.lang.javascript.structureView.JSStructureViewElement)1 Attachment (com.intellij.openapi.diagnostic.Attachment)1 Document (com.intellij.openapi.editor.Document)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 XmlFile (com.intellij.psi.xml.XmlFile)1