当前位置: 首页>>代码示例>>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;未经允许,请勿转载。