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();
}
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);
}
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);
}
}
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());
}
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;
}
Aggregations