本文整理汇总了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;
}
示例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();
}
示例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);
}
示例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;
}
}
示例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();
}