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