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


Java ExpressionUtils类代码示例

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


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

示例1: isNotNullMatcher

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
private static boolean isNotNullMatcher(PsiExpression expr) {
  if (expr instanceof PsiMethodCallExpression) {
    String calledName = ((PsiMethodCallExpression)expr).getMethodExpression().getReferenceName();
    if ("notNullValue".equals(calledName)) {
      return true;
    }
    if ("not".equals(calledName)) {
      PsiExpression[] notArgs = ((PsiMethodCallExpression)expr).getArgumentList().getExpressions();
      if (notArgs.length == 1 &&
          notArgs[0] instanceof PsiMethodCallExpression &&
          "equalTo".equals(((PsiMethodCallExpression)notArgs[0]).getMethodExpression().getReferenceName())) {
        PsiExpression[] equalArgs = ((PsiMethodCallExpression)notArgs[0]).getArgumentList().getExpressions();
        if (equalArgs.length == 1 && ExpressionUtils.isNullLiteral(equalArgs[0])) {
          return true;
        }
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:HardcodedContracts.java

示例2: visitMethod

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method) {
  final PsiIdentifier nameIdentifier = method.getNameIdentifier();
  if (nameIdentifier == null) {
    return;
  }
  final VariableAccessVisitor visitor = new VariableAccessVisitor();
  method.accept(visitor);
  final Set<PsiField> fields = visitor.getOveraccessedFields();
  for (PsiField field : fields) {
    if (ExpressionUtils.isConstant(field)) {
      continue;
    }
    if (m_ignoreFinalFields &&
        field.hasModifierProperty(PsiModifier.FINAL)) {
      continue;
    }
    registerError(nameIdentifier, field);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:FieldRepeatedlyAccessedInspection.java

示例3: visitArrayInitializerExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
@Override
public void visitArrayInitializerExpression(
  PsiArrayInitializerExpression expression) {
  super.visitArrayInitializerExpression(expression);
  final PsiExpression[] initializers = expression.getInitializers();
  if (initializers.length > 0) {
    return;
  }
  if (expression.getParent() instanceof PsiNewExpression) {
    return;
  }
  if (ExpressionUtils.isDeclaredConstant(expression)) {
    return;
  }
  registerError(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ZeroLengthArrayInitializationInspectionBase.java

示例4: getArgumentFromEqualsCallOn

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
private static PsiVariable getArgumentFromEqualsCallOn(PsiExpression expression, @NotNull PsiVariable variable) {
  expression = ParenthesesUtils.stripParentheses(expression);
  if (!(expression instanceof PsiMethodCallExpression)) {
    return null;
  }
  final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
  final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
  final String methodName = methodExpression.getReferenceName();
  if (!HardcodedMethodConstants.EQUALS.equals(methodName)) {
    return null;
  }
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  if (!VariableAccessUtils.evaluatesToVariable(qualifier, variable)) {
    return null;
  }
  final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
  final PsiExpression[] expressions = argumentList.getExpressions();
  if (expressions.length != 1) {
    return null;
  }
  return ExpressionUtils.getVariable(expressions[0]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:EqualsReplaceableByObjectsCallInspection.java

示例5: looksLikeExpectedArgument

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
private boolean looksLikeExpectedArgument(PsiExpression expression) {
  if (ExpressionUtils.computeConstantExpression(expression) != null || PsiType.NULL.equals(expression.getType())) {
    return true;
  }
  if (expression instanceof PsiReferenceExpression) {
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
    final PsiElement target = referenceExpression.resolve();
    if (target instanceof PsiEnumConstant) {
      return true;
    }
    if ((target instanceof PsiField)) {
      final PsiField field = (PsiField)target;
      if (field.hasModifierProperty(PsiModifier.STATIC) && field.hasModifierProperty(PsiModifier.FINAL)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:MisorderedAssertEqualsArgumentsInspectionBase.java

示例6: containsNonConstantConcatenation

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
private boolean containsNonConstantConcatenation(@Nullable PsiExpression expression) {
  if (expression instanceof PsiParenthesizedExpression) {
    final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression;
    return containsNonConstantConcatenation(parenthesizedExpression.getExpression());
  }
  else if (expression instanceof PsiPolyadicExpression) {
    final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
    if (!ExpressionUtils.hasStringType(polyadicExpression)) {
      return false;
    }
    if (!JavaTokenType.PLUS.equals(polyadicExpression.getOperationTokenType())) {
      return false;
    }
    final PsiExpression[] operands = polyadicExpression.getOperands();
    for (PsiExpression operand : operands) {
      if (!ExpressionUtils.isEvaluatedAtCompileTime(operand)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:StringConcatenationArgumentToLogCallInspectionBase.java

示例7: isNullComparison

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
private static boolean isNullComparison(PsiExpression condition, PsiVariable variable) {
  if (!(condition instanceof PsiBinaryExpression)) {
    return false;
  }
  final PsiBinaryExpression comparison = (PsiBinaryExpression)condition;
  final IElementType tokenType = comparison.getOperationTokenType();
  if (!tokenType.equals(JavaTokenType.EQEQ)) {
    return false;
  }
  final PsiExpression lhs = comparison.getLOperand();
  final PsiExpression rhs = comparison.getROperand();
  if (ExpressionUtils.isNullLiteral(rhs)) {
    return VariableAccessUtils.evaluatesToVariable(lhs, variable);
  }
  else if (ExpressionUtils.isNullLiteral(lhs)) {
    return VariableAccessUtils.evaluatesToVariable(rhs, variable);
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:NonThreadSafeLazyInitializationInspectionBase.java

示例8: visitLiteralExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
@Override
public void visitLiteralExpression(
  @NotNull PsiLiteralExpression expression) {
  super.visitLiteralExpression(expression);
  final PsiType type = expression.getType();
  if (!TypeUtils.isJavaLangString(type)) {
    return;
  }
  final String value = (String)expression.getValue();
  if (value == null || value.length() != 1) {
    return;
  }
  if (!ExpressionUtils.isStringConcatenationOperand(expression) &&
      !isArgumentOfStringAppend(expression)) {
    return;
  }
  registerError(expression, value);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:LengthOneStringsInConcatenationInspection.java

示例9: visitPolyadicExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
@Override
public void visitPolyadicExpression(PsiPolyadicExpression expression) {
  super.visitPolyadicExpression(expression);
  if (!ExpressionUtils.hasStringType(expression)) {
    return;
  }
  final PsiExpression[] operands = expression.getOperands();
  for (PsiExpression operand : operands) {
    operand = ParenthesesUtils.stripParentheses(operand);
    if (operand == null) {
      return;
    }
    if (!ExpressionUtils.isEmptyStringLiteral(operand)) {
      continue;
    }
    if (PsiUtil.isConstantExpression(expression)) {
      return;
    }
    registerError(operand, operand);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:TrivialStringConcatenationInspection.java

示例10: collapseConstant

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
private static String collapseConstant(@NonNls String expressionText,
                                       PsiElement context)
  throws IncorrectOperationException {
  final Project project = context.getProject();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiElementFactory factory = psiFacade.getElementFactory();
  final PsiExpression fromOffsetExpression =
    factory.createExpressionFromText(expressionText, context);
  final Object fromOffsetConstant =
    ExpressionUtils.computeConstantExpression(
      fromOffsetExpression);
  if (fromOffsetConstant != null) {
    return fromOffsetConstant.toString();
  }
  else {
    return expressionText;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ManualArrayCopyInspection.java

示例11: collapseConstant

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
private static String collapseConstant(String expressionText,
                                       PsiElement context)
  throws IncorrectOperationException {
  final Project project = context.getProject();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiElementFactory factory = psiFacade.getElementFactory();
  final PsiExpression fromOffsetExpression =
    factory.createExpressionFromText(expressionText, context);
  final Object fromOffsetConstant =
    ExpressionUtils.computeConstantExpression(
      fromOffsetExpression);
  if (fromOffsetConstant != null) {
    return fromOffsetConstant.toString();
  }
  else {
    return expressionText;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ManualArrayToCollectionCopyInspection.java

示例12: visitPolyadicExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
@Override
public void visitPolyadicExpression(PsiPolyadicExpression expression) {
  super.visitPolyadicExpression(expression);
  final IElementType tokenType = expression.getOperationTokenType();
  if (!JavaTokenType.PLUS.equals(tokenType) || !ExpressionUtils.hasStringType(expression)) {
    return;
  }
  final boolean formatCall = FormatUtils.isFormatCallArgument(expression);
  final PsiExpression[] operands = expression.getOperands();
  PsiExpression lhs = operands[0];
  for (int i = 1; i < operands.length; i++) {
    final PsiExpression rhs = operands[i];
    if (isMissingWhitespace(lhs, rhs, formatCall)) {
      final PsiJavaToken token = expression.getTokenBeforeOperand(rhs);
      if (token != null) {
        registerError(token);
      }
    }
    lhs = rhs;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:StringConcatenationMissingWhitespaceInspection.java

示例13: visitBinaryExpression

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!ExpressionUtils.hasStringType(lhs)) {
    return;
  }
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null || !ExpressionUtils.hasStringType(rhs)) {
    return;
  }
  if (ExpressionUtils.isNullLiteral(lhs) || ExpressionUtils.isNullLiteral(rhs)) {
    return;
  }
  final PsiJavaToken sign = expression.getOperationSign();
  registerError(sign);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:StringEqualityInspection.java

示例14: isParameterCheckNotNeeded

import com.siyeh.ig.psiutils.ExpressionUtils; //导入依赖的package包/类
private static boolean isParameterCheckNotNeeded(PsiCodeBlock body, PsiParameter parameter) {
  final PsiStatement[] statements = body.getStatements();
  if (statements.length == 0) {
    return true; // incomplete code
  }
  if (statements.length != 1) {
    return false;
  }
  final PsiStatement statement = statements[0];
  if (!(statement instanceof PsiReturnStatement)) {
    return true; // incomplete code
  }
  final PsiReturnStatement returnStatement = (PsiReturnStatement)statement;
  final PsiExpression returnValue = returnStatement.getReturnValue();
  final Object constant = ExpressionUtils.computeConstantExpression(returnValue);
  if (Boolean.FALSE.equals(constant)) {
    return true; // incomplete code
  }
  if (isEqualsBuilderReflectionEquals(returnValue)) {
    return true;
  }
  if (isIdentityEquals(returnValue, parameter)) {
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:EqualsWhichDoesntCheckParameterClassInspection.java

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


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