当前位置: 首页>>代码示例>>Java>>正文


Java JSExpressionStatement.getExpression方法代码示例

本文整理汇总了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());
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:21,代码来源:InspectionJSFix.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:19,代码来源:ConditionalUtils.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:16,代码来源:ObjectAllocationIgnoredJSInspection.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:14,代码来源:DebuggerStatementJSInspection.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:10,代码来源:ConditionalUtils.java

示例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 + ';');
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:14,代码来源:ConditionalUtils.java

示例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));
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:31,代码来源:JSReplaceIfWithConditionalIntention.java

示例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;
    }
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:69,代码来源:RecursionUtil.java


注:本文中的com.intellij.lang.javascript.psi.JSExpressionStatement.getExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。