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


Java VariableAccessUtils类代码示例

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


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

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
private static int findInitialization(PsiElement[] elements, PsiVariable variable, boolean hasInitializer) {
  int result = -1;
  final int statementsLength = elements.length;
  for (int i = 0; i < statementsLength; i++) {
    final PsiElement element = elements[i];
    if (isNormalAssignment(element, variable)) {
      if (result >= 0 && !hasInitializer) {
        return -1;
      }
      if (hasInitializer) {
        return i;
      }
      result = i;
    }
    else if (VariableAccessUtils.variableIsAssigned(variable, element)) {
      return hasInitializer ? i : -1;
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:TryFinallyCanBeTryWithResourcesInspection.java

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

示例5: checkVariable

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
private static boolean checkVariable(PsiVariable variable,
                                     PsiElement context) {
  if (context == null) {
    return false;
  }
  final PsiType type = variable.getType();
  if (type.getArrayDimensions() == 0) {
    return false;
  }
  if (VariableAccessUtils.variableIsAssigned(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsAssignedFrom(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsReturned(variable, context)) {
    return false;
  }
  return !VariableAccessUtils.variableIsUsedInArrayInitializer(variable, context);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:MismatchedArrayReadWriteInspection.java

示例6: visitBinaryExpression

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
@Override
public void visitBinaryExpression(PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (write || passed) {
    return;
  }
  final IElementType tokenType = expression.getOperationTokenType();
  if (!JavaTokenType.EQEQ.equals(tokenType) && !JavaTokenType.NE.equals(tokenType)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!(lhs instanceof PsiBinaryExpression)) {
    if (VariableAccessUtils.mayEvaluateToVariable(lhs, variable)) {
      passed = true;
    }
  }
  final PsiExpression rhs = expression.getROperand();
  if (!(rhs instanceof PsiBinaryExpression)) {
    if (VariableAccessUtils.mayEvaluateToVariable(rhs, variable)) {
      passed = true;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:MismatchedArrayReadWriteInspection.java

示例7: visitMethodCallExpression

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
@Override
public void visitMethodCallExpression(
  @NotNull PsiMethodCallExpression call) {
  if (passed) {
    return;
  }
  super.visitMethodCallExpression(call);
  final PsiExpressionList argumentList = call.getArgumentList();
  final PsiExpression[] arguments = argumentList.getExpressions();
  for (int i = 0; i < arguments.length; i++) {
    final PsiExpression argument = arguments[i];
    if (VariableAccessUtils.mayEvaluateToVariable(argument, variable)) {
      if (write && i == 0 && isCallToSystemArraycopy(call)) {
        return;
      }
      if (!write && i == 2 && isCallToSystemArraycopy(call)) {
        return;
      }
      passed = true;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:MismatchedArrayReadWriteInspection.java

示例8: visitAssignmentExpression

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
@Override
public void visitAssignmentExpression(@NotNull PsiAssignmentExpression assignment) {
  if (mayBeQueried) {
    return;
  }
  super.visitAssignmentExpression(assignment);
  final PsiExpression lhs = assignment.getLExpression();
  if (!VariableAccessUtils.mayEvaluateToVariable(lhs, variable)) {
    return;
  }
  final PsiExpression rhs = assignment.getRExpression();
  if (isEmptyCollectionInitializer(rhs)) {
    return;
  }
  mayBeQueried = true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MismatchedCollectionQueryUpdateInspectionBase.java

示例9: checkVariable

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
private boolean checkVariable(PsiVariable variable, PsiElement context) {
  if (context == null) {
    return false;
  }
  final PsiType type = variable.getType();
  if (!CollectionUtils.isCollectionClassOrInterface(type)) {
    return false;
  }
  if (VariableAccessUtils.variableIsAssignedFrom(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsReturned(variable, context)) {
    return false;
  }
  return !VariableAccessUtils.variableIsUsedInArrayInitializer(variable, context);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MismatchedCollectionQueryUpdateInspectionBase.java

示例10: collectionContentsAreUpdated

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
private boolean collectionContentsAreUpdated(PsiVariable variable, PsiElement context) {
  if (VariableAccessUtils.variableIsPassedAsMethodArgument(variable, context, new UpdateCallProcessor()) ||
      collectionUpdateCalled(variable, context)) {
    return true;
  }
  final PsiExpression initializer = variable.getInitializer();
  if (initializer != null && !isEmptyCollectionInitializer(initializer)) {
    return true;
  }
  if (initializer instanceof PsiNewExpression) {
    final PsiNewExpression newExpression = (PsiNewExpression)initializer;
    final PsiAnonymousClass anonymousClass = newExpression.getAnonymousClass();
    if (anonymousClass != null) {
      if (collectionUpdateCalled(null, anonymousClass)) {
        return true;
      }
      final ThisPassedAsArgumentVisitor visitor = new ThisPassedAsArgumentVisitor();
      anonymousClass.accept(visitor);
      if (visitor.isPassed()) {
        return true;
      }
    }
  }
  return VariableAccessUtils.variableIsAssigned(variable, context);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:MismatchedCollectionQueryUpdateInspectionBase.java

示例11: checkVariable

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
private static boolean checkVariable(PsiVariable variable, PsiElement context) {
  if (context == null) {
    return false;
  }
  if (!TypeUtils.variableHasTypeOrSubtype(variable, CommonClassNames.JAVA_LANG_ABSTRACT_STRING_BUILDER)) {
    return false;
  }
  if (VariableAccessUtils.variableIsAssigned(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsAssignedFrom(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsReturned(variable, context)) {
    return false;
  }
  if (VariableAccessUtils.variableIsPassedAsMethodArgument(variable, context)) {
    return false;
  }
  return !VariableAccessUtils.variableIsUsedInArrayInitializer(variable, context);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MismatchedStringBuilderQueryUpdateInspection.java

示例12: isVariableUsedInFollowingDeclarations

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
private boolean isVariableUsedInFollowingDeclarations(PsiVariable variable, PsiDeclarationStatement declarationStatement) {
  final PsiElement[] declaredElements = declarationStatement.getDeclaredElements();
  if (declaredElements.length == 1) {
    return false;
  }
  boolean check = false;
  for (PsiElement declaredElement : declaredElements) {
    if (!check && variable.equals(declaredElement)) {
      check = true;
    } else {
      if (VariableAccessUtils.variableIsUsed(variable, declaredElement)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:UnnecessaryLocalVariableInspectionBase.java

示例13: visitWhileStatement

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入依赖的package包/类
@Override
public void visitWhileStatement(@NotNull PsiWhileStatement statement) {
  super.visitWhileStatement(statement);
  final PsiStatement body = statement.getBody();
  if (ignoreNonEmtpyLoops && !statementIsEmpty(body)) {
    return;
  }
  final PsiExpression condition = statement.getCondition();
  final PsiField field = getFieldIfSimpleFieldComparison(condition);
  if (field == null) {
    return;
  }
  if (body != null && (VariableAccessUtils.variableIsAssigned(field, body) ||
                       containsWaitCall(body))) {
    return;
  }
  registerStatementError(statement);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:WhileLoopSpinsOnFieldInspection.java

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

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


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