當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。