Search in sources :

Example 21 with TreeElement

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

the class RequirejsProjectComponent method parsePackageObject.

private static void parsePackageObject(TreeElement node, Package p) {
    if (null == node) {
        return;
    }
    if (node.getElementType() == JSElementTypes.PROPERTY) {
        TreeElement identifier = (TreeElement) node.findChildByType(JSTokenTypes.IDENTIFIER);
        String identifierName = null;
        if (null != identifier) {
            identifierName = identifier.getText();
        } else {
            TreeElement identifierString = (TreeElement) node.findChildByType(JSTokenTypes.STRING_LITERAL);
            if (null != identifierString) {
                identifierName = dequote(identifierString.getText());
            }
        }
        if (null != identifierName) {
            if (identifierName.equals("name")) {
                p.name = getJSPropertyLiteralValue(node);
            } else if (identifierName.equals("location")) {
                p.location = getJSPropertyLiteralValue(node);
            } else if (identifierName.equals("main")) {
                p.main = getJSPropertyLiteralValue(node);
            }
        }
    }
    TreeElement next = node.getTreeNext();
    parsePackageObject(next, p);
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 22 with TreeElement

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

the class RequirejsProjectComponent method parseMainJsFile.

public void parseMainJsFile(TreeElement node) {
    TreeElement firstChild = node.getFirstChildNode();
    if (firstChild != null) {
        parseMainJsFile(firstChild);
    }
    TreeElement nextNode = node.getTreeNext();
    if (nextNode != null) {
        parseMainJsFile(nextNode);
    }
    if (node.getElementType() == JSTokenTypes.IDENTIFIER) {
        if (node.getText().equals("requirejs") || node.getText().equals("require")) {
            TreeElement treeParent = node.getTreeParent();
            if (null != treeParent) {
                ASTNode firstTreeChild = treeParent.findChildByType(JSElementTypes.OBJECT_LITERAL_EXPRESSION);
                TreeElement nextTreeElement = treeParent.getTreeNext();
                if (null != firstTreeChild) {
                    parseRequirejsConfig((TreeElement) firstTreeChild.getFirstChildNode());
                } else if (null != nextTreeElement && nextTreeElement.getElementType() == JSTokenTypes.DOT) {
                    nextTreeElement = nextTreeElement.getTreeNext();
                    if (null != nextTreeElement && nextTreeElement.getText().equals("config")) {
                        treeParent = nextTreeElement.getTreeParent();
                        findAndParseConfig(treeParent);
                    }
                } else {
                    findAndParseConfig(treeParent);
                }
            }
        }
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 23 with TreeElement

use of com.intellij.psi.impl.source.tree.TreeElement in project smali by JesusFreke.

the class SmaliModifierList method setModifierProperty.

@Override
public void setModifierProperty(@ModifierConstant @NotNull @NonNls String name, boolean addModifier) throws IncorrectOperationException {
    if (addModifier) {
        final TreeElement leaf = Factory.createSingleLeafElement(SmaliTokens.ACCESS_SPEC, name, null, getManager());
        new WriteCommandAction.Simple(getProject(), getContainingFile()) {

            @Override
            protected void run() throws Throwable {
                addInternal(leaf, leaf, null, null);
            }
        }.execute();
    } else {
        final PsiElement accessSpec = getAccessFlagElement(name);
        if (accessSpec != null) {
            new WriteCommandAction.Simple(getProject(), getContainingFile()) {

                @Override
                protected void run() throws Throwable {
                    accessSpec.delete();
                }
            }.execute();
        }
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) PsiElement(com.intellij.psi.PsiElement) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 24 with TreeElement

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

the class ASTDelegatePsiElement method replace.

@Override
public PsiElement replace(@NotNull final PsiElement newElement) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    TreeElement elementCopy = ChangeUtil.copyToElement(newElement);
    if (getParent() instanceof ASTDelegatePsiElement) {
        final ASTDelegatePsiElement parentElement = (ASTDelegatePsiElement) getParent();
        parentElement.replaceChildInternal(this, elementCopy);
    } else {
        CodeEditUtil.replaceChild(getParent().getNode(), getNode(), elementCopy);
    }
    elementCopy = ChangeUtil.decodeInformation(elementCopy);
    return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 25 with TreeElement

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

the class ASTDelegatePsiElement method addAfter.

@Override
public PsiElement addAfter(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    TreeElement elementCopy = ChangeUtil.copyToElement(element);
    ASTNode treeElement = addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.FALSE);
    if (treeElement instanceof TreeElement) {
        return ChangeUtil.decodeInformation((TreeElement) treeElement).getPsi();
    }
    return treeElement.getPsi();
}
Also used : ASTNode(com.intellij.lang.ASTNode) 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