当前位置: 首页>>代码示例>>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;未经允许,请勿转载。