本文整理汇总了Java中com.intellij.lang.javascript.psi.JSExpressionStatement.getExpression方法的典型用法代码示例。如果您正苦于以下问题:Java JSExpressionStatement.getExpression方法的具体用法?Java JSExpressionStatement.getExpression怎么用?Java JSExpressionStatement.getExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.lang.javascript.psi.JSExpressionStatement
的用法示例。
在下文中一共展示了JSExpressionStatement.getExpression方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceExpression
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入方法依赖的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());
}
示例2: replaceSimplifiableImplicitAssignment
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入方法依赖的package包/类
public static void replaceSimplifiableImplicitAssignment(JSIfStatement statement, boolean negated)
throws IncorrectOperationException {
final JSElement prevStatement = (JSElement) JSElementFactory.getNonWhiteSpaceSibling(statement, false);
final JSExpression condition = statement.getCondition();
final String conditionText = (negated ? BoolUtils.getNegatedExpressionText(condition) : condition.getText());
final JSExpressionStatement assignmentStatement = (JSExpressionStatement) ConditionalUtils.stripBraces(statement.getThen());
final JSAssignmentExpression assignmentExpression = (JSAssignmentExpression) assignmentStatement.getExpression();
final IElementType operator = assignmentExpression.getOperationSign();
final String operand = BinaryOperatorUtils.getOperatorText(operator);
final JSExpression lhs = assignmentExpression.getLOperand();
final String lhsText = lhs.getText();
JSElementFactory.replaceStatement(statement, lhsText + operand + conditionText + ';');
assert (prevStatement != null);
JSElementFactory.removeElement(prevStatement);
}
示例3: visitJSExpressionStatement
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入方法依赖的package包/类
@Override public void visitJSExpressionStatement(
@NotNull JSExpressionStatement statement) {
super.visitJSExpressionStatement(statement);
if (!(statement.getExpression()instanceof JSNewExpression)) {
return;
}
final JSNewExpression newExpression =
(JSNewExpression) statement.getExpression();
final JSExpression methodExpression =
newExpression.getMethodExpression();
if (methodExpression == null) {
return;
}
registerError(methodExpression);
}
示例4: visitJSExpressionStatement
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入方法依赖的package包/类
@Override public void visitJSExpressionStatement(JSExpressionStatement jsExpressionStatement) {
super.visitJSExpressionStatement(jsExpressionStatement);
final JSExpression expression = jsExpressionStatement.getExpression();
if (!(expression instanceof JSReferenceExpression)) {
return;
}
@NonNls final String text = expression.getText();
if (!"debugger".equals(text)) {
return;
}
registerError(expression);
}
示例5: isAssignment
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入方法依赖的package包/类
public static boolean isAssignment(JSStatement statement) {
if (!(statement instanceof JSExpressionStatement)) {
return false;
}
final JSExpressionStatement expressionStatement = (JSExpressionStatement) statement;
return (expressionStatement.getExpression() instanceof JSAssignmentExpression);
}
示例6: replaceSimplifiableAssignment
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入方法依赖的package包/类
public static void replaceSimplifiableAssignment(JSIfStatement statement, boolean negated)
throws IncorrectOperationException {
final JSExpression condition = statement.getCondition();
final String conditionText = (negated ? BoolUtils.getNegatedExpressionText(condition) : condition.getText());
final JSExpressionStatement assignmentStatement = (JSExpressionStatement) ConditionalUtils.stripBraces(statement.getThen());
final JSAssignmentExpression assignmentExpression = (JSAssignmentExpression) assignmentStatement.getExpression();
final IElementType operator = assignmentExpression.getOperationSign();
final String operand = BinaryOperatorUtils.getOperatorText(operator);
final JSExpression lhs = assignmentExpression.getLOperand();
final String lhsText = lhs.getText();
JSElementFactory.replaceStatement(statement, lhsText + operand + conditionText + ';');
}
示例7: getAssignmentReplacement
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入方法依赖的package包/类
private static void getAssignmentReplacement(StringBuilder buffer, JSIfStatement ifStatement) {
final JSExpression condition = ifStatement.getCondition();
final JSExpressionStatement thenBranch = (JSExpressionStatement) ConditionalUtils.stripBraces(ifStatement.getThen());
final JSAssignmentExpression thenAssign = (JSAssignmentExpression) thenBranch.getExpression();
final JSExpression thenRhs = thenAssign.getROperand();
final String operator = BinaryOperatorUtils.getOperatorText(thenAssign.getOperationSign());
final JSStatement elseBranch = ifStatement.getElse();
assert (thenRhs != null);
buffer.append(thenAssign.getLOperand().getText())
.append(operator)
.append(ParenthesesUtils.getParenthesized(condition, ParenthesesUtils.CONDITIONAL_PRECENDENCE))
.append(TERNARY_QUESTION)
.append(ParenthesesUtils.getParenthesized(thenRhs, ParenthesesUtils.CONDITIONAL_PRECENDENCE))
.append(TERNARY_SEMICOLON);
if (elseBranch instanceof JSIfStatement) {
getAssignmentReplacement(buffer, (JSIfStatement) elseBranch);
return;
}
final JSExpressionStatement strippedElseBranch = (JSExpressionStatement) ConditionalUtils.stripBraces(elseBranch);
final JSAssignmentExpression elseAssign = (JSAssignmentExpression) strippedElseBranch.getExpression();
final JSExpression elseRhs = elseAssign.getROperand();
assert (elseRhs != null);
buffer.append(ParenthesesUtils.getParenthesized(elseRhs, ParenthesesUtils.CONDITIONAL_PRECENDENCE));
}
示例8: statementDefinitelyRecurses
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入方法依赖的package包/类
private static boolean statementDefinitelyRecurses(JSStatement statement,
JSFunction method) {
if (statement == null) {
return false;
}
if (statement instanceof JSBreakStatement ||
statement instanceof JSContinueStatement ||
statement instanceof JSThrowStatement ||
statement instanceof JSEmptyStatement) {
return false;
} else if (statement instanceof JSExpressionStatement) {
final JSExpressionStatement expressionStatement =
(JSExpressionStatement)statement;
final JSExpression expression =
expressionStatement.getExpression();
return RecursionUtil.expressionDefinitelyRecurses(expression, method);
} else if (statement instanceof JSVarStatement) {
final JSVarStatement varStatement =
(JSVarStatement) statement;
for(final JSVariable variable : varStatement.getVariables()) {
final JSExpression initializer = variable.getInitializer();
if (RecursionUtil.expressionDefinitelyRecurses(initializer, method)) {
return true;
}
}
return false;
} else if (statement instanceof JSReturnStatement) {
final JSReturnStatement returnStatement =
(JSReturnStatement) statement;
final JSExpression returnValue = returnStatement.getExpression();
if (returnValue != null) {
if (RecursionUtil.expressionDefinitelyRecurses(returnValue, method)) {
return true;
}
}
return false;
} else if (statement instanceof JSForStatement) {
return RecursionUtil.forStatementDefinitelyRecurses((JSForStatement)
statement, method);
} else if (statement instanceof JSForInStatement) {
return RecursionUtil.forInStatementDefinitelyRecurses(
(JSForInStatement) statement, method);
} else if (statement instanceof JSWhileStatement) {
return RecursionUtil.whileStatementDefinitelyRecurses(
(JSWhileStatement) statement, method);
} else if (statement instanceof JSDoWhileStatement) {
return RecursionUtil.doWhileStatementDefinitelyRecurses(
(JSDoWhileStatement) statement, method);
} else if (statement instanceof JSBlockStatement) {
return RecursionUtil.blockStatementDefinitelyRecurses(
(JSBlockStatement) statement, method);
} else if (statement instanceof JSLabeledStatement) {
return RecursionUtil.labeledStatementDefinitelyRecurses(
(JSLabeledStatement) statement, method);
} else if (statement instanceof JSIfStatement) {
return RecursionUtil.ifStatementDefinitelyRecurses(
(JSIfStatement) statement, method);
} else if (statement instanceof JSTryStatement) {
return RecursionUtil.tryStatementDefinitelyRecurses(
(JSTryStatement) statement, method);
} else if (statement instanceof JSSwitchStatement) {
return RecursionUtil.switchStatementDefinitelyRecurses(
(JSSwitchStatement) statement, method);
} else {
// unknown statement type
return false;
}
}