本文整理匯總了Java中com.intellij.lang.javascript.psi.impl.JSChangeUtil.createStatementFromText方法的典型用法代碼示例。如果您正苦於以下問題:Java JSChangeUtil.createStatementFromText方法的具體用法?Java JSChangeUtil.createStatementFromText怎麽用?Java JSChangeUtil.createStatementFromText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.lang.javascript.psi.impl.JSChangeUtil
的用法示例。
在下文中一共展示了JSChangeUtil.createStatementFromText方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: surroundElements
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
@Override
@Nullable
public TextRange surroundElements(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements) throws
IncorrectOperationException
{
ASTNode node = JSChangeUtil.createStatementFromText(project, getStatementTemplate(project, elements[0]));
PsiElement container = elements[0].getParent();
container.getNode().addChild(node, elements[0].getNode());
final ASTNode insertBeforeNode = getInsertBeforeNode(node);
for(int i = 0; i < elements.length; i++)
{
final ASTNode childNode = elements[i].getNode();
final ASTNode childNodeCopy = childNode.copyElement();
container.getNode().removeChild(childNode);
insertBeforeNode.getTreeParent().addChild(childNodeCopy, insertBeforeNode);
}
final CodeStyleManager csManager = CodeStyleManager.getInstance(project);
csManager.reformat(node.getPsi());
return getSurroundSelectionRange(node);
}
示例2: replaceExpression
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
protected static void replaceExpression(JSExpression expression,
String newExpression)
throws IncorrectOperationException {
final ASTNode fromText = JSChangeUtil.createStatementFromText(expression.getProject(), newExpression + ';');
final PsiElement element = fromText != null ? fromText.getPsi() : null;
final JSExpressionStatement expressionStatement = element instanceof JSExpressionStatement ? (JSExpressionStatement) element:null;
if (expressionStatement == null) {
return;
}
final JSExpression newExp = expressionStatement.getExpression();
final ASTNode newExpressionNode = newExp.getNode();
final ASTNode expressionNode = expression.getNode();
final PsiElement parent = expression.getParent();
final ASTNode parentNode = parent.getNode();
parentNode.replaceChild(expressionNode, newExpressionNode);
// final CodeStyleManager styleManager = manager.getCodeStyleManager();
// styleManager.reformat(newExpressionNode.getPsi());
}
示例3: replaceStatement
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
protected static void replaceStatement(JSStatement statement,
@NonNls String newStatement)
throws IncorrectOperationException {
final ASTNode fromText = JSChangeUtil.createStatementFromText(statement.getProject(), newStatement);
final PsiElement element = fromText != null ? fromText.getPsi() : null;
final JSStatement newStmt = element instanceof JSStatement ? (JSStatement)element:null;
if (newStmt == null) {
return;
}
final PsiElement parent = statement.getParent();
final ASTNode parentNode = parent.getNode();
final ASTNode statementNode = statement.getNode();
final ASTNode newStatementNode = newStmt.getNode();
parentNode.replaceChild(statementNode, newStatementNode);
// final CodeStyleManager styleManager = manager.getCodeStyleManager();
// styleManager.reformat(newStatementNode.getPsi());
}
示例4: replaceElementWithStatement
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static JSStatement replaceElementWithStatement(@NotNull JSElement element,
@NonNls @NotNull String statementText)
throws IncorrectOperationException {
final ASTNode newStatementNode = JSChangeUtil.createStatementFromText(
element.getProject(),
statementText);
final ASTNode oldStatementParentNode = element.getNode();
final PsiElement parentNode = element.getParent();
final ASTNode newStatementParentNode = parentNode.getNode();
if (newStatementParentNode == null || oldStatementParentNode == null || newStatementNode == null) {
return null;
}
newStatementParentNode.replaceChild(oldStatementParentNode, newStatementNode);
reformat(parentNode);
return (JSStatement) newStatementNode.getPsi();
}
示例5: replaceStatement
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static JSStatement replaceStatement(@NotNull JSStatement statement,
@NonNls @NotNull String text)
throws IncorrectOperationException {
final ASTNode newStatementNode = JSChangeUtil.createStatementFromText(
statement.getProject(),
text);
final ASTNode oldStatementParentNode = statement.getNode();
final PsiElement parentNode = statement.getParent();
final ASTNode newStatementParentNode = parentNode.getNode();
if (newStatementParentNode == null || oldStatementParentNode == null || newStatementNode == null) {
return null;
}
newStatementParentNode.replaceChild(oldStatementParentNode, newStatementNode);
reformat(parentNode);
return (JSStatement) newStatementNode.getPsi();
}
示例6: addStatementBefore
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static JSStatement addStatementBefore(@NotNull JSStatement statement,
@NonNls @NotNull String previousStatementText)
throws IncorrectOperationException {
final ASTNode newStatementNode = JSChangeUtil.createStatementFromText(
statement.getProject(),
previousStatementText);
final ASTNode oldStatementParentNode = statement.getNode();
final PsiElement parentNode = statement.getParent();
final ASTNode newStatementParentNode = parentNode.getNode();
if (newStatementParentNode == null || newStatementNode == null) {
return null;
}
newStatementParentNode.addChild(newStatementNode, oldStatementParentNode);
reformat(parentNode);
return (JSStatement) newStatementNode.getPsi();
}
示例7: addStatementAfter
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static JSStatement addStatementAfter(@NotNull JSStatement statement,
@NonNls @NotNull String nextStatementText)
throws IncorrectOperationException {
final ASTNode newStatementNode = JSChangeUtil.createStatementFromText(
statement.getProject(),
nextStatementText);
final ASTNode statementNode = statement.getNode();
final ASTNode oldStatementParentNode = ((statementNode == null) ? null : statementNode.getTreeNext());
final PsiElement parentNode = statement.getParent();
final ASTNode newStatementParentNode = parentNode.getNode();
if (newStatementParentNode == null || newStatementNode == null) {
return null;
}
newStatementParentNode.addChild(newStatementNode, oldStatementParentNode);
reformat(parentNode);
return (JSStatement) newStatementNode.getPsi();
}
示例8: invoke
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement element, @NotNull PsiElement end) throws IncorrectOperationException {
JSIndexedPropertyAccessExpression indexed = PsiTreeUtil.getParentOfType(element, JSIndexedPropertyAccessExpression.class);
JSReferenceExpression ref = PsiTreeUtil.findChildOfType(indexed, JSReferenceExpression.class);
JSLiteralExpression literalExpression = (JSLiteralExpression) indexed.getIndexExpression();
String path = StringUtil.stripQuotesAroundValue(literalExpression.getText());
ASTNode dotExp = JSChangeUtil.createStatementFromText(project, ref.getText() + '.' + path);
indexed.replace(dotExp.getPsi());
}
示例9: invoke
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement element, @NotNull PsiElement end) throws IncorrectOperationException {
// PsiElement element = descriptor.getPsiElement();
JSBinaryExpression binary = PsiTreeUtil.getParentOfType(element, JSBinaryExpression.class);
JSBinaryExpression binaryClone = (JSBinaryExpression) binary.copy();
binaryClone.getLOperand().replace(binary.getLOperand().getLastChild());
ASTNode negate = JSChangeUtil.createStatementFromText(project, "!(true)");
JSParenthesizedExpression paren = PsiTreeUtil.getChildOfType(negate.getPsi().getFirstChild(), JSParenthesizedExpression.class);
paren.getInnerExpression().replace(binaryClone);
binary.replace(negate.getPsi());
}
示例10: addStatementBeforeElement
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static PsiElement addStatementBeforeElement(PsiElement parent, PsiElement element, String statement, String whitespace)
{
ASTNode node = JSChangeUtil.createStatementFromText(parent.getProject(), statement, JSUtils.getDialect(parent.getContainingFile()));
parent.addBefore(node.getPsi(), element);
if(!whitespace.equals(""))
{
parent.addBefore(JSChangeUtil.createJSTreeFromText(parent.getProject(), whitespace).getPsi(), element);
}
return node.getPsi();
}
示例11: addStatement
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static PsiElement addStatement(PsiElement parent, String statement)
{
ASTNode node = JSChangeUtil.createStatementFromText(parent.getProject(), statement, JSUtils.getDialect(parent.getContainingFile()));
parent.add(node.getPsi());
return node.getPsi();
}
示例12: createStatement
import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static PsiElement createStatement(PsiElement parent, String statement)
{
ASTNode node = JSChangeUtil.createStatementFromText(parent.getProject(), statement, JSUtils.getDialect(parent.getContainingFile()));
return node.getPsi();
}