Search in sources :

Example 41 with TreeElement

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

the class RequirejsProjectComponent method parseMapsConfig.

protected void parseMapsConfig(TreeElement mapElement) {
    TreeElement firstMapConfigElement = (TreeElement) mapElement.findChildByType(JSElementTypes.PROPERTY);
    parseMapConfigElement(firstMapConfigElement);
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 42 with TreeElement

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

the class RequirejsProjectComponent method parseMapConfigElement.

protected void parseMapConfigElement(TreeElement mapConfigElement) {
    if (null == mapConfigElement) {
        return;
    }
    if (mapConfigElement.getElementType() == JSElementTypes.PROPERTY) {
        String module = getJSPropertyName(mapConfigElement);
        TreeElement mapAliasesObject = (TreeElement) mapConfigElement.findChildByType(JSElementTypes.OBJECT_LITERAL_EXPRESSION);
        if (null != mapAliasesObject) {
            RequireMapModule requireMapModule = new RequireMapModule();
            requireMapModule.module = module;
            TreeElement mapAliasProperty = (TreeElement) mapAliasesObject.findChildByType(JSElementTypes.PROPERTY);
            parseMapAliasProperty(requireMapModule, mapAliasProperty);
            requireMap.addModule(requireMapModule);
        }
    }
    parseMapConfigElement(mapConfigElement.getTreeNext());
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 43 with TreeElement

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

the class RequirejsProjectComponent method parseRequirejsConfig.

public void parseRequirejsConfig(TreeElement node) {
    if (null == node) {
        return;
    }
    try {
        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("baseUrl")) {
                    String baseUrl = null;
                    if (!settings.overrideBaseUrl) {
                        ASTNode baseUrlNode = node.findChildByType(JSElementTypes.LITERAL_EXPRESSION);
                        if (null != baseUrlNode) {
                            baseUrl = dequote(baseUrlNode.getText());
                        }
                    } else {
                        LOG.info("baseUrl override is enabled, overriding with '" + settings.baseUrl + "'");
                        baseUrl = settings.baseUrl;
                    }
                    if (null != baseUrl) {
                        LOG.info("Setting baseUrl to '" + baseUrl + "'");
                        setBaseUrl(baseUrl);
                        packageConfig.baseUrl = baseUrl;
                    } else {
                        LOG.debug("BaseUrl not set");
                    }
                } else if (identifierName.equals("paths")) {
                    ASTNode pathsNode = node.findChildByType(JSElementTypes.OBJECT_LITERAL_EXPRESSION);
                    if (null != pathsNode) {
                        parseRequireJsPaths((TreeElement) pathsNode.getFirstChildNode());
                    }
                } else if (identifierName.equals("packages")) {
                    TreeElement packages = (TreeElement) node.findChildByType(JSElementTypes.ARRAY_LITERAL_EXPRESSION);
                    LOG.debug("parsing packages");
                    parsePackages(packages);
                    LOG.debug("parsing packages done, found " + packageConfig.packages.size() + " packages");
                } else if (identifierName.equals("map")) {
                    TreeElement mapElement = (TreeElement) node.findChildByType(JSElementTypes.OBJECT_LITERAL_EXPRESSION);
                    parseMapsConfig(mapElement);
                }
            }
        }
    } catch (NullPointerException exception) {
        LOG.error(exception.getMessage(), exception);
    }
    TreeElement next = node.getTreeNext();
    if (null != next) {
        parseRequirejsConfig(next);
    }
}
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