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


Java JSChangeUtil.createExpressionFromText方法代碼示例

本文整理匯總了Java中com.intellij.lang.javascript.psi.impl.JSChangeUtil.createExpressionFromText方法的典型用法代碼示例。如果您正苦於以下問題:Java JSChangeUtil.createExpressionFromText方法的具體用法?Java JSChangeUtil.createExpressionFromText怎麽用?Java JSChangeUtil.createExpressionFromText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.lang.javascript.psi.impl.JSChangeUtil的用法示例。


在下文中一共展示了JSChangeUtil.createExpressionFromText方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNegated

import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static JSExpression getNegated(JSExpression condition) {
    if (condition instanceof JSPrefixExpression) {
        final JSPrefixExpression prefixExp = (JSPrefixExpression) condition;
        final JSExpression       operand   = prefixExp.getExpression();

        return ParenthesesUtils.stripParentheses(operand);
    } else if (condition instanceof JSBinaryExpression) {
        final JSBinaryExpression binaryExpression = (JSBinaryExpression) condition;
        final IElementType sign        = binaryExpression.getOperationSign();
        final JSExpression lhs         = binaryExpression.getLOperand();
        final JSExpression rhs         = binaryExpression.getROperand();
        final String       negatedSign = ComparisonUtils.getNegatedOperatorText(sign);
        final String       negatedText = lhs.getText() + negatedSign + rhs.getText();

        return (JSExpression) JSChangeUtil.createExpressionFromText(
          condition.getProject(),
          negatedText);
    } else if (condition instanceof JSParenthesizedExpression) {
        return getNegated(((JSParenthesizedExpression) condition).getInnerExpression());
    }
    return condition;
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:23,代碼來源:BoolUtils.java

示例2: addExpression

import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static PsiElement addExpression(PsiElement parent, String statement)
{
    ASTNode node = JSChangeUtil.createExpressionFromText(parent.getProject(), statement, JSUtils.getDialect(parent.getContainingFile()));
    parent.add(node.getPsi());

    return node.getPsi();
}
 
開發者ID:cefolger,項目名稱:needsmoredojo,代碼行數:8,代碼來源:JSUtil.java

示例3: replaceExpression

import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static JSExpression replaceExpression(@NotNull JSExpression   expression,
                                             @NonNls @NotNull String text)
        throws IncorrectOperationException {
    final JSExpression newExpressionNode = JSChangeUtil.createExpressionFromText(
      expression.getProject(),
      text);

    return replaceExpression(expression, newExpressionNode);
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:10,代碼來源:JSElementFactory.java

示例4: getSubexpression

import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
/**
 * Returns the smallest subexpression (if precendence allows it). For instance:
 * variable + 2 + 3 normally gets evaluated left to right -> (variable + 2)
 * + 3 this method returns the right most legal subexpression -> 2 + 3
 * @param expression the expression to analyse
 * @return the found common sub-expression if found, or <tt>null</tt> otherwise.
 */
@Nullable
private static JSBinaryExpression getSubexpression(JSBinaryExpression expression) {
    final JSExpression       rhs               = expression.getROperand();
    final IElementType       sign              = expression.getOperationSign();
    final int                parentPrecendence = ParenthesesUtils.getPrecendence(expression);

    if (rhs == null) {
        return null;
    }

    final JSExpression lhs = expression.getLOperand();

    if (!(lhs instanceof JSBinaryExpression)) {
        return expression;
    }

    final JSBinaryExpression lhsBinaryExpression = (JSBinaryExpression) lhs;
    final int                childPrecendence    = ParenthesesUtils.getPrecendence(lhsBinaryExpression);
    final JSExpression       leftSide            = lhsBinaryExpression.getROperand();

    if (leftSide == null) {
        return null;
    }

    if (parentPrecendence > childPrecendence) {
        return null;
    }

    try {
        final String  subExpressionText = leftSide.getText() + BinaryOperatorUtils.getOperatorText(sign) +
                                          rhs.getText();
        final JSExpression subExpression     = JSChangeUtil.createExpressionFromText(expression.getProject(),
                                                                                subExpressionText);

        return (JSBinaryExpression) subExpression;
    } catch (Throwable ignore) {
        return null;
    }
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:47,代碼來源:JSConstantSubexpressionIntention.java

示例5: createExpression

import com.intellij.lang.javascript.psi.impl.JSChangeUtil; //導入方法依賴的package包/類
public static PsiElement createExpression(PsiElement parent, String statement)
{
    ASTNode node = JSChangeUtil.createExpressionFromText(parent.getProject(), statement, JSUtils.getDialect(parent.getContainingFile()));
    return node.getPsi();
}
 
開發者ID:cefolger,項目名稱:needsmoredojo,代碼行數:6,代碼來源:JSUtil.java


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