Search in sources :

Example 36 with TreeElement

use of com.intellij.psi.impl.source.tree.TreeElement in project intellij-community by JetBrains.

the class XmlDocumentImpl method addInternal.

@Override
public TreeElement addInternal(final TreeElement first, final ASTNode last, final ASTNode anchor, final Boolean before) {
    final PomModel model = PomManager.getModel(getProject());
    final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
    final TreeElement[] holder = new TreeElement[1];
    try {
        model.runTransaction(new PomTransactionBase(this, aspect) {

            @Override
            public PomModelEvent runInner() {
                holder[0] = XmlDocumentImpl.super.addInternal(first, last, anchor, before);
                return XmlDocumentChangedImpl.createXmlDocumentChanged(model, XmlDocumentImpl.this);
            }
        });
    } catch (IncorrectOperationException ignored) {
    }
    return holder[0];
}
Also used : XmlAspect(com.intellij.pom.xml.XmlAspect) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent) IncorrectOperationException(com.intellij.util.IncorrectOperationException) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 37 with TreeElement

use of com.intellij.psi.impl.source.tree.TreeElement in project intellij-community by JetBrains.

the class XmlElementImpl method findElementByTokenType.

public XmlElement findElementByTokenType(final IElementType type) {
    final XmlElement[] result = new XmlElement[1];
    result[0] = null;
    processElements(new PsiElementProcessor() {

        @Override
        public boolean execute(@NotNull PsiElement element) {
            if (element instanceof TreeElement && ((ASTNode) element).getElementType() == type) {
                result[0] = (XmlElement) element;
                return false;
            }
            return true;
        }
    }, this);
    return result[0];
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) PsiElement(com.intellij.psi.PsiElement) CompositePsiElement(com.intellij.psi.impl.source.tree.CompositePsiElement) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 38 with TreeElement

use of com.intellij.psi.impl.source.tree.TreeElement in project intellij-community by JetBrains.

the class AbstractXmlBlock method findChildAfter.

@Nullable
protected static ASTNode findChildAfter(@NotNull final ASTNode child, final int endOffset) {
    TreeElement fileNode = TreeUtil.getFileElement((TreeElement) child);
    final LeafElement leaf = fileNode.findLeafElementAt(endOffset);
    if (leaf != null && leaf.getStartOffset() == endOffset && endOffset > 0) {
        return fileNode.findLeafElementAt(endOffset - 1);
    }
    return leaf;
}
Also used : LeafElement(com.intellij.psi.impl.source.tree.LeafElement) TreeElement(com.intellij.psi.impl.source.tree.TreeElement) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with TreeElement

use of com.intellij.psi.impl.source.tree.TreeElement in project intellij-elixir by KronicDeth.

the class BeamFileImpl method getMirror.

/**
     * Returns the corresponding PSI element in a decompiled file created by IDEA from
     * the library element.
     *
     * @return the counterpart of the element in decompiled file.
     */
@Override
public PsiElement getMirror() {
    TreeElement mirrorTreeElement = mirrorFileElement;
    if (mirrorTreeElement == null) {
        synchronized (mirrorLock) {
            mirrorTreeElement = mirrorFileElement;
            if (mirrorTreeElement == null) {
                VirtualFile file = getVirtualFile();
                String fileName = file.getNameWithoutExtension() + ".ex";
                final Document document = FileDocumentManager.getInstance().getDocument(file);
                assert document != null : file.getUrl();
                CharSequence mirrorText = document.getImmutableCharSequence();
                PsiFileFactory factory = PsiFileFactory.getInstance(getManager().getProject());
                PsiFile mirror = factory.createFileFromText(fileName, ElixirLanguage.INSTANCE, mirrorText, false, false);
                mirrorTreeElement = SourceTreeToPsiMap.psiToTreeNotNull(mirror);
                try {
                    final TreeElement finalMirrorTreeElement = mirrorTreeElement;
                    ProgressManager.getInstance().executeNonCancelableSection(new Runnable() {

                        public void run() {
                            setMirror(finalMirrorTreeElement);
                            putUserData(MODULE_DOCUMENT_LINK_KEY, document);
                        }
                    });
                } catch (InvalidMirrorException e) {
                    //noinspection ThrowableResultOfMethodCallIgnored
                    LOGGER.error(file.getUrl(), e);
                }
                ((PsiFileImpl) mirror).setOriginalFile(this);
                mirrorFileElement = mirrorTreeElement;
            }
        }
    }
    return mirrorTreeElement.getPsi();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) Document(com.intellij.openapi.editor.Document) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 40 with TreeElement

use of com.intellij.psi.impl.source.tree.TreeElement in project WebStormRequireJsPlugin by Fedott.

the class RequirejsProjectComponent method parsePackages.

private void parsePackages(TreeElement node) {
    TokenSet tokenSet = TokenSet.create(JSElementTypes.OBJECT_LITERAL_EXPRESSION, JSElementTypes.LITERAL_EXPRESSION);
    TreeElement packageNode = (TreeElement) node.findChildByType(tokenSet);
    parsePackage(packageNode);
}
Also used : TokenSet(com.intellij.psi.tree.TokenSet) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Aggregations

TreeElement (com.intellij.psi.impl.source.tree.TreeElement)43 ASTNode (com.intellij.lang.ASTNode)12 IncorrectOperationException (com.intellij.util.IncorrectOperationException)5 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)4 PsiElement (com.intellij.psi.PsiElement)3 CompositeElement (com.intellij.psi.impl.source.tree.CompositeElement)3 Nullable (org.jetbrains.annotations.Nullable)3 Document (com.intellij.openapi.editor.Document)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PomModel (com.intellij.pom.PomModel)2 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)2 XmlAspect (com.intellij.pom.xml.XmlAspect)2 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)2 FileElement (com.intellij.psi.impl.source.tree.FileElement)2 TokenSet (com.intellij.psi.tree.TokenSet)2 CharTable (com.intellij.util.CharTable)2 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 Project (com.intellij.openapi.project.Project)1