本文整理匯總了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();
}