當前位置: 首頁>>代碼示例>>Java>>正文


Java ExpressionUtils.isOne方法代碼示例

本文整理匯總了Java中com.siyeh.ig.psiutils.ExpressionUtils.isOne方法的典型用法代碼示例。如果您正苦於以下問題:Java ExpressionUtils.isOne方法的具體用法?Java ExpressionUtils.isOne怎麽用?Java ExpressionUtils.isOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.siyeh.ig.psiutils.ExpressionUtils的用法示例。


在下文中一共展示了ExpressionUtils.isOne方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildToOffsetText

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
private static String buildToOffsetText(PsiExpression expression,
                                        boolean plusOne) {
  expression = ParenthesesUtils.stripParentheses(expression);
  if (expression == null) {
    return null;
  }
  if (!plusOne) {
    return expression.getText();
  }
  if (expression instanceof PsiBinaryExpression) {
    final PsiBinaryExpression binaryExpression =
      (PsiBinaryExpression)expression;
    final IElementType tokenType =
      binaryExpression.getOperationTokenType();
    if (tokenType == JavaTokenType.MINUS) {
      final PsiExpression rhs =
        binaryExpression.getROperand();
      if (ExpressionUtils.isOne(rhs)) {
        return binaryExpression.getLOperand().getText();
      }
    }
  }
  final int precedence = ParenthesesUtils.getPrecedence(expression);
  if (precedence > ParenthesesUtils.ADDITIVE_PRECEDENCE) {
    return '(' + expression.getText() + ")+1";
  }
  else {
    return expression.getText() + "+1";
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:31,代碼來源:ManualArrayToCollectionCopyInspection.java

示例2: isOne

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
boolean isOne(PsiExpression expression) {
  if (m_ignoreExpressionsContainingConstants &&
      !(expression instanceof PsiLiteralExpression)) {
    return false;
  }
  return ExpressionUtils.isOne(expression);
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:8,代碼來源:PointlessArithmeticExpressionInspection.java

示例3: buildOffsetText

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
@NonNls
@Nullable
private static String buildOffsetText(PsiExpression expression,
                                      PsiLocalVariable variable,
                                      PsiExpression limitExpression,
                                      boolean plusOne)
  throws IncorrectOperationException {
  if (expression == null) {
    return null;
  }
  final String expressionText = expression.getText();
  final String variableName = variable.getName();
  if (expressionText.equals(variableName)) {
    final PsiExpression initialValue =
      ParenthesesUtils.stripParentheses(limitExpression);
    if (initialValue == null) {
      return null;
    }
    return buildExpressionText(initialValue, plusOne, false);
  }
  else if (expression instanceof PsiBinaryExpression) {
    final PsiBinaryExpression binaryExpression =
      (PsiBinaryExpression)expression;
    final PsiExpression lhs = binaryExpression.getLOperand();
    final PsiExpression rhs = binaryExpression.getROperand();
    final String rhsText =
      buildOffsetText(rhs, variable, limitExpression, plusOne);
    final PsiJavaToken sign = binaryExpression.getOperationSign();
    final IElementType tokenType = sign.getTokenType();
    if (ExpressionUtils.isZero(lhs)) {
      if (tokenType.equals(JavaTokenType.MINUS)) {
        return '-' + rhsText;
      }
      return rhsText;
    }
    if (plusOne && tokenType.equals(JavaTokenType.MINUS) &&
        ExpressionUtils.isOne(rhs)) {
      return buildOffsetText(lhs, variable, limitExpression,
                             false);
    }
    final String lhsText = buildOffsetText(lhs, variable,
                                           limitExpression, plusOne);
    if (ExpressionUtils.isZero(rhs)) {
      return lhsText;
    }
    return collapseConstant(lhsText + sign.getText() + rhsText,
                            variable);
  }
  return collapseConstant(expression.getText(), variable);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:51,代碼來源:ManualArrayCopyInspection.java

示例4: isOne

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
boolean isOne(PsiExpression expression) {
  if (m_ignoreExpressionsContainingConstants && PsiUtil.deparenthesizeExpression(expression) instanceof PsiReferenceExpression) {
    return false;
  }
  return ExpressionUtils.isOne(expression);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:7,代碼來源:PointlessArithmeticExpressionInspection.java

示例5: incrementExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
private static String incrementExpression(PsiExpression expression,
                                          boolean positive) {
  if (expression instanceof PsiLiteralExpression) {
    final PsiLiteralExpression literalExpression =
      (PsiLiteralExpression)expression;
    final Number value = (Number)literalExpression.getValue();
    if (value == null) {
      return null;
    }
    if (positive) {
      return String.valueOf(value.longValue() + 1L);
    }
    else {
      return String.valueOf(value.longValue() - 1L);
    }
  }
  else {
    if (expression instanceof PsiBinaryExpression) {
      // see if we can remove a -1 instead of adding a +1
      final PsiBinaryExpression binaryExpression =
        (PsiBinaryExpression)expression;
      final PsiExpression rhs = binaryExpression.getROperand();
      if (ExpressionUtils.isOne(rhs)) {
        final IElementType tokenType =
          binaryExpression.getOperationTokenType();
        if (tokenType == JavaTokenType.MINUS && positive) {
          return binaryExpression.getLOperand().getText();
        }
        else if (tokenType == JavaTokenType.PLUS && !positive) {
          return binaryExpression.getLOperand().getText();
        }
      }
    }
    final String expressionText;
    if (ParenthesesUtils.getPrecedence(expression) >
        ParenthesesUtils.ADDITIVE_PRECEDENCE) {
      expressionText = '(' + expression.getText() + ')';
    }
    else {
      expressionText = expression.getText();
    }
    if (positive) {
      return expressionText + "+1";
    }
    else {
      return expressionText + "-1";
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:50,代碼來源:ReverseForLoopDirectionIntention.java


注:本文中的com.siyeh.ig.psiutils.ExpressionUtils.isOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。