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


Java VariableAccessUtils.evaluatesToVariable方法代码示例

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


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

示例1: isEquality

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private static boolean isEquality(PsiExpression expression, boolean equals, PsiVariable variable1, PsiVariable variable2) {
  expression = ParenthesesUtils.stripParentheses(expression);
  if (!(expression instanceof PsiBinaryExpression)) {
    return false;
  }
  final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression;
  if (equals) {
    if (!JavaTokenType.EQEQ.equals(binaryExpression.getOperationTokenType())) {
      return false;
    }
  }
  else {
    if (!JavaTokenType.NE.equals(binaryExpression.getOperationTokenType())) {
      return false;
    }
  }
  final PsiExpression lhs = binaryExpression.getLOperand();
  final PsiExpression rhs = binaryExpression.getROperand();
  return (VariableAccessUtils.evaluatesToVariable(lhs, variable1) && VariableAccessUtils.evaluatesToVariable(rhs, variable2)) ||
         (VariableAccessUtils.evaluatesToVariable(lhs, variable2) && VariableAccessUtils.evaluatesToVariable(rhs, variable1));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:EqualsReplaceableByObjectsCallInspection.java

示例2: getArgumentFromEqualsCallOn

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的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

示例3: isNullComparison

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的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

示例4: isNullComparison

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private static boolean isNullComparison(PsiExpression expression, @NotNull PsiVariable variable, boolean equal) {
  expression = ParenthesesUtils.stripParentheses(expression);
  if (!(expression instanceof PsiBinaryExpression)) {
    return false;
  }
  final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression;
  final IElementType tokenType = binaryExpression.getOperationTokenType();
  if (equal) {
    if (!JavaTokenType.EQEQ.equals(tokenType)) {
      return false;
    }
  }
  else {
    if (!JavaTokenType.NE.equals(tokenType)) {
      return false;
    }
  }
  final PsiExpression lhs = binaryExpression.getLOperand();
  final PsiExpression rhs = binaryExpression.getROperand();
  if (rhs == null) {
    return false;
  }
  return PsiType.NULL.equals(rhs.getType()) && VariableAccessUtils.evaluatesToVariable(lhs, variable) ||
         PsiType.NULL.equals(lhs.getType()) && VariableAccessUtils.evaluatesToVariable(rhs, variable);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ObjectsRequireNonNullIntention.java

示例5: isVariableCompared

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
public static boolean isVariableCompared(
  @NotNull PsiVariable variable, @Nullable PsiExpression expression) {
  if (!(expression instanceof PsiBinaryExpression)) {
    return false;
  }
  final PsiBinaryExpression binaryExpression =
    (PsiBinaryExpression)expression;
  final IElementType tokenType = binaryExpression.getOperationTokenType();
  if (!ComparisonUtils.isComparisonOperation(tokenType)) {
    return false;
  }
  final PsiExpression lhs = binaryExpression.getLOperand();
  final PsiExpression rhs = binaryExpression.getROperand();
  if (rhs == null) {
    return false;
  }
  if (VariableAccessUtils.evaluatesToVariable(lhs, variable)) {
    return true;
  }
  else if (VariableAccessUtils.evaluatesToVariable(rhs, variable)) {
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ReverseForLoopDirectionPredicate.java

示例6: isVariableCompared

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
public static boolean isVariableCompared(@NotNull PsiVariable variable, @Nullable PsiExpression expression)
{
	if(!(expression instanceof PsiBinaryExpression))
	{
		return false;
	}
	final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression;
	final IElementType tokenType = binaryExpression.getOperationTokenType();
	if(!ComparisonUtils.isComparisonOperation(tokenType))
	{
		return false;
	}
	final PsiExpression lhs = binaryExpression.getLOperand();
	final PsiExpression rhs = binaryExpression.getROperand();
	if(rhs == null)
	{
		return false;
	}
	if(VariableAccessUtils.evaluatesToVariable(lhs, variable))
	{
		return true;
	}
	else if(VariableAccessUtils.evaluatesToVariable(rhs, variable))
	{
		return true;
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:29,代码来源:ReverseForLoopDirectionPredicate.java

示例7: expressionIsArrayCopy

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private static boolean expressionIsArrayCopy(
  @Nullable PsiExpression expression,
  @NotNull PsiVariable variable,
  @Nullable PsiVariable variable2) {
  final PsiExpression strippedExpression =
    ParenthesesUtils.stripParentheses(expression);
  if (strippedExpression == null) {
    return false;
  }
  if (!(strippedExpression instanceof PsiAssignmentExpression)) {
    return false;
  }
  final PsiAssignmentExpression assignment =
    (PsiAssignmentExpression)strippedExpression;
  final IElementType tokenType = assignment.getOperationTokenType();
  if (!tokenType.equals(JavaTokenType.EQ)) {
    return false;
  }
  final PsiExpression lhs = assignment.getLExpression();
  if (SideEffectChecker.mayHaveSideEffects(lhs)) {
    return false;
  }
  if (!ExpressionUtils.isOffsetArrayAccess(lhs, variable)) {
    return false;
  }
  final PsiExpression rhs = assignment.getRExpression();
  if (rhs == null) {
    return false;
  }
  if (SideEffectChecker.mayHaveSideEffects(rhs)) {
    return false;
  }
  if (!areExpressionsCopyable(lhs, rhs)) {
    return false;
  }
  final PsiType type = lhs.getType();
  if (type instanceof PsiPrimitiveType) {
    final PsiExpression strippedLhs =
      ParenthesesUtils.stripParentheses(lhs);
    final PsiExpression strippedRhs =
      ParenthesesUtils.stripParentheses(rhs);
    if (!areExpressionsCopyable(strippedLhs, strippedRhs)) {
      return false;
    }
  }
  if (variable2 == null) {
    return ExpressionUtils.isOffsetArrayAccess(rhs, variable);
  }
  else {
    return VariableAccessUtils.evaluatesToVariable(rhs, variable2);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:53,代码来源:ManualArrayCopyInspection.java

示例8: expressionIsArrayToCollectionCopy

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private static boolean expressionIsArrayToCollectionCopy(
  PsiExpression expression, PsiVariable variable,
  boolean shouldBeOffsetArrayAccess) {
  expression = ParenthesesUtils.stripParentheses(expression);
  if (expression == null) {
    return false;
  }
  if (!(expression instanceof PsiMethodCallExpression)) {
    return false;
  }
  final PsiMethodCallExpression methodCallExpression =
    (PsiMethodCallExpression)expression;
  final PsiExpressionList argumentList =
    methodCallExpression.getArgumentList();
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length != 1) {
    return false;
  }
  final PsiReferenceExpression methodExpression =
    methodCallExpression.getMethodExpression();
  final PsiExpression qualifier =
    methodExpression.getQualifierExpression();
  if (!(qualifier instanceof PsiReferenceExpression) &&
      !(qualifier instanceof PsiThisExpression) &&
      !(qualifier instanceof PsiSuperExpression)) {
    return false;
  }
  final PsiExpression argument = arguments[0];
  final PsiType argumentType = argument.getType();
  if (argumentType instanceof PsiPrimitiveType) {
    return false;
  }
  if (SideEffectChecker.mayHaveSideEffects(argument)) {
    return false;
  }
  if (shouldBeOffsetArrayAccess) {
    if (!ExpressionUtils.isOffsetArrayAccess(argument, variable)) {
      return false;
    }
  }
  else if (!VariableAccessUtils.evaluatesToVariable(argument,
                                                    variable)) {
    return false;
  }
  final PsiMethod method = methodCallExpression.resolveMethod();
  if (method == null) {
    return false;
  }
  @NonNls final String name = method.getName();
  if (!name.equals("add")) {
    return false;
  }
  final PsiClass containingClass = method.getContainingClass();
  return InheritanceUtil.isInheritor(containingClass,
                                     CommonClassNames.JAVA_UTIL_COLLECTION);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:57,代码来源:ManualArrayToCollectionCopyInspection.java


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