本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}