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


Java ExpressionUtils.isZero方法代码示例

本文整理汇总了Java中com.siyeh.ig.psiutils.ExpressionUtils.isZero方法的典型用法代码示例。如果您正苦于以下问题:Java ExpressionUtils.isZero方法的具体用法?Java ExpressionUtils.isZero怎么用?Java ExpressionUtils.isZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.siyeh.ig.psiutils.ExpressionUtils的用法示例。


在下文中一共展示了ExpressionUtils.isZero方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitField

import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  if (!field.hasInitializer() || field.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  final PsiExpression initializer = field.getInitializer();
  if (initializer == null) {
    return;
  }
  final String text = initializer.getText();
  final PsiType type = field.getType();
  if (PsiType.BOOLEAN.equals(type)) {
    if (onlyWarnOnNull || !PsiKeyword.FALSE.equals(text)) {
      return;
    }
  } else if (type instanceof PsiPrimitiveType) {
    if (onlyWarnOnNull || !ExpressionUtils.isZero(initializer)) {
      return;
    }
  } else if (!PsiType.NULL.equals(initializer.getType())) {
    return;
  }
  registerError(initializer, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:RedundantFieldInitializationInspection.java

示例2: visitBinaryExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null) {
    return;
  }
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!TypeUtils.hasFloatingPointType(lhs) && !TypeUtils.hasFloatingPointType(rhs)) {
    return;
  }
  if (ExpressionUtils.isZero(lhs) || ExpressionUtils.isZero(rhs)) {
    return;
  }
  registerError(expression);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:FloatingPointEqualityInspection.java

示例3: visitMethodCallExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(
  @NotNull PsiMethodCallExpression expression) {
  super.visitMethodCallExpression(expression);
  final PsiReferenceExpression methodExpression =
    expression.getMethodExpression();
  @NonNls final String methodName =
    methodExpression.getReferenceName();
  if (!"substring".equals(methodName)) {
    return;
  }
  final PsiExpressionList argumentList = expression.getArgumentList();
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length != 1) {
    return;
  }
  final PsiExpression argument = arguments[0];
  if (argument == null) {
    return;
  }
  if (!ExpressionUtils.isZero(argument)) {
    return;
  }
  final PsiMethod method = expression.resolveMethod();
  if (method == null) {
    return;
  }
  final PsiClass aClass = method.getContainingClass();
  if (aClass == null) {
    return;
  }
  final String className = aClass.getQualifiedName();
  if (!CommonClassNames.JAVA_LANG_STRING.equals(className)) {
    return;
  }
  registerError(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:SubstringZeroInspection.java

示例4: buildFromOffsetText

import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
@Nullable
private static String buildFromOffsetText(PsiExpression expression,
                                          PsiLocalVariable variable)
  throws IncorrectOperationException {
  expression = ParenthesesUtils.stripParentheses(expression);
  if (expression == null) {
    return null;
  }
  final String expressionText = expression.getText();
  final String variableName = variable.getName();
  if (expressionText.equals(variableName)) {
    final PsiExpression initialValue = variable.getInitializer();
    if (initialValue == null) {
      return null;
    }
    return initialValue.getText();
  }
  if (expression instanceof PsiBinaryExpression) {
    final PsiBinaryExpression binaryExpression =
      (PsiBinaryExpression)expression;
    final PsiExpression lhs = binaryExpression.getLOperand();
    final PsiExpression rhs = binaryExpression.getROperand();
    final String rhsText = buildFromOffsetText(rhs, variable);
    final PsiJavaToken sign = binaryExpression.getOperationSign();
    final IElementType tokenType = sign.getTokenType();
    if (ExpressionUtils.isZero(lhs)) {
      if (tokenType.equals(JavaTokenType.MINUS)) {
        return '-' + rhsText;
      }
      return rhsText;
    }
    final String lhsText = buildFromOffsetText(lhs, variable);
    if (ExpressionUtils.isZero(rhs)) {
      return lhsText;
    }
    return collapseConstant(lhsText + sign.getText() + rhsText,
                            variable);
  }
  return collapseConstant(expression.getText(), variable);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:ManualArrayToCollectionCopyInspection.java

示例5: isZero

import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
private boolean isZero(PsiExpression expression) {
  if (m_ignoreExpressionsContainingConstants
      && !(expression instanceof PsiLiteralExpression)) {
    return false;
  }
  return ExpressionUtils.isZero(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:PointlessBitwiseExpressionInspection.java

示例6: isZero

import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
boolean isZero(PsiExpression expression) {
  if (m_ignoreExpressionsContainingConstants &&
      !(expression instanceof PsiLiteralExpression)) {
    return false;
  }
  return ExpressionUtils.isZero(expression);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:8,代码来源:PointlessArithmeticExpressionInspection.java

示例7: 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

示例8: isZero

import com.siyeh.ig.psiutils.ExpressionUtils; //导入方法依赖的package包/类
boolean isZero(PsiExpression expression) {
  if (m_ignoreExpressionsContainingConstants && PsiUtil.deparenthesizeExpression(expression) instanceof PsiReferenceExpression) {
    return false;
  }
  return ExpressionUtils.isZero(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PointlessArithmeticExpressionInspection.java


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