Java Code Examples for com.intellij.psi.impl.source.tree.TreeElement#findChildByType()
The following examples show how to use
com.intellij.psi.impl.source.tree.TreeElement#findChildByType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 6 votes |
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()); }
Example 2
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 6 votes |
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); }
Example 3
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 5 votes |
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); } } } } }
Example 4
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 5 votes |
protected void findAndParseConfig(TreeElement treeParent) { TreeElement nextTreeElement; if (null != treeParent) { nextTreeElement = treeParent.getTreeNext(); if (null != nextTreeElement) { ASTNode nextChild = nextTreeElement.findChildByType(JSElementTypes.OBJECT_LITERAL_EXPRESSION); if (null != nextChild) { parseRequirejsConfig( (TreeElement) nextChild.getFirstChildNode() ); } } } }
Example 5
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 5 votes |
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; }
Example 6
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 5 votes |
private void parsePackages(TreeElement node) { TokenSet tokenSet = TokenSet.create( JSElementTypes.OBJECT_LITERAL_EXPRESSION, JSElementTypes.LITERAL_EXPRESSION); TreeElement packageNode = (TreeElement) node.findChildByType(tokenSet); parsePackage(packageNode); }
Example 7
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 5 votes |
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); }
Example 8
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 4 votes |
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); } }
Example 9
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 4 votes |
protected void parseMapsConfig(TreeElement mapElement) { TreeElement firstMapConfigElement = (TreeElement) mapElement.findChildByType(JSElementTypes.PROPERTY); parseMapConfigElement(firstMapConfigElement); }