當前位置: 首頁>>代碼示例>>Java>>正文


Java JSChangeUtil.createStatementFromText方法代碼示例

本文整理匯總了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);
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:26,代碼來源:JSStatementSurrounder.java

示例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());
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:21,代碼來源:InspectionJSFix.java

示例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());
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:19,代碼來源:InspectionJSFix.java

示例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();
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:20,代碼來源:JSElementFactory.java

示例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();
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:21,代碼來源:JSElementFactory.java

示例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();
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:20,代碼來源:JSElementFactory.java

示例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();
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:21,代碼來源:JSElementFactory.java

示例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());
}
 
開發者ID:idok,項目名稱:eslint-plugin,代碼行數:10,代碼來源:DotNotationActionFix.java

示例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());
    }
 
開發者ID:idok,項目名稱:eslint-plugin,代碼行數:12,代碼來源:NoNegatedInLhsActionFix.java

示例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();
}
 
開發者ID:cefolger,項目名稱:needsmoredojo,代碼行數:13,代碼來源:JSUtil.java

示例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();
}
 
開發者ID:cefolger,項目名稱:needsmoredojo,代碼行數:8,代碼來源:JSUtil.java

示例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();
}
 
開發者ID:cefolger,項目名稱:needsmoredojo,代碼行數:6,代碼來源:JSUtil.java


注:本文中的com.intellij.lang.javascript.psi.impl.JSChangeUtil.createStatementFromText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。