Search in sources :

Example 16 with TreeElement

use of com.intellij.psi.impl.source.tree.TreeElement in project oxy-template-support-plugin by mutant-industries.

the class LineBreaksFixingElementVisitor method visitLeaf.

@Override
public void visitLeaf(LeafElement leaf) {
    if (offsets.isEmpty() || (shift + leaf.getTextOffset() + leaf.getTextLength() < offsets.peekFirst())) {
        return;
    }
    while (!offsets.isEmpty() && offsets.peekFirst() < shift + leaf.getTextOffset()) {
        offsets.pollFirst();
    }
    StringBuilder newText = new StringBuilder(leaf.getText());
    int localShift = 0;
    while (!offsets.isEmpty() && offsets.peekFirst() < shift + leaf.getTextOffset() + leaf.getTextLength()) {
        int index = offsets.pollFirst() - (shift + localShift + leaf.getTextOffset());
        newText.deleteCharAt(index);
        localShift++;
    }
    shift += localShift;
    if (newText.length() > 0) {
        TreeElement newAnchor = Factory.createSingleLeafElement(leaf.getElementType(), newText, 0, newText.length(), null, leaf.getManager());
        leaf.rawInsertBeforeMe(newAnchor);
    }
    leaf.rawRemove();
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 17 with TreeElement

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

the class RequirejsProjectComponent method parsePackage.

private void parsePackage(TreeElement node) {
    if (null == node) {
        return;
    }
    if (node.getElementType() == JSElementTypes.OBJECT_LITERAL_EXPRESSION || node.getElementType() == JSElementTypes.LITERAL_EXPRESSION) {
        // TODO: Not adding not resolve package
        Package p = new Package();
        packageConfig.packages.add(p);
        if (node.getElementType() == JSElementTypes.OBJECT_LITERAL_EXPRESSION) {
            TreeElement prop = (TreeElement) node.findChildByType(JSElementTypes.PROPERTY);
            parsePackageObject(prop, p);
        } else {
            p.name = dequote(node.getText());
        }
        normalizeParsedPackage(p);
        validatePackage(p);
    }
    TreeElement next = node.getTreeNext();
    parsePackage(next);
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 18 with TreeElement

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

the class RequirejsProjectComponent method parseRequireJsPaths.

protected void parseRequireJsPaths(TreeElement node) {
    if (null == node) {
        return;
    }
    if (node.getElementType() == JSElementTypes.PROPERTY) {
        RequirePathAlias pathAlias = new RequirePathAlias();
        pathAlias.alias = getJSPropertyName(node);
        pathAlias.path = getJSPropertyLiteralValue(node);
        requirePaths.addPath(pathAlias);
    }
    TreeElement next = node.getTreeNext();
    if (null != next) {
        parseRequireJsPaths(next);
    }
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 19 with TreeElement

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

the class RequirejsProjectComponent method getJSPropertyLiteralValue.

@Nullable
private static String getJSPropertyLiteralValue(TreeElement jsProperty) {
    TokenSet availablePropertyValueTokenSet = TokenSet.create(JSElementTypes.LITERAL_EXPRESSION, JSElementTypes.BINARY_EXPRESSION, JSElementTypes.CONDITIONAL_EXPRESSION);
    TreeElement jsPropertyValue = (TreeElement) jsProperty.findChildByType(availablePropertyValueTokenSet);
    if (null == jsPropertyValue) {
        return null;
    }
    if (jsPropertyValue.getElementType() != JSElementTypes.LITERAL_EXPRESSION) {
        jsPropertyValue = (TreeElement) jsPropertyValue.findChildByType(JSElementTypes.LITERAL_EXPRESSION);
        if (null == jsPropertyValue) {
            return null;
        }
    }
    return dequote(jsPropertyValue.getText());
}
Also used : TokenSet(com.intellij.psi.tree.TokenSet) TreeElement(com.intellij.psi.impl.source.tree.TreeElement) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with TreeElement

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

the class RequirejsProjectComponent method getJSPropertyName.

protected String getJSPropertyName(TreeElement jsProperty) {
    TreeElement identifier = (TreeElement) jsProperty.findChildByType(TokenSet.create(JSTokenTypes.IDENTIFIER, JSTokenTypes.STRING_LITERAL, JSTokenTypes.PUBLIC_KEYWORD));
    String identifierName = null;
    if (null != identifier) {
        identifierName = dequote(identifier.getText());
    }
    return identifierName;
}
Also used : 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