當前位置: 首頁>>代碼示例>>Java>>正文


Java ExpressionUtils.isOffsetArrayAccess方法代碼示例

本文整理匯總了Java中com.siyeh.ig.psiutils.ExpressionUtils.isOffsetArrayAccess方法的典型用法代碼示例。如果您正苦於以下問題:Java ExpressionUtils.isOffsetArrayAccess方法的具體用法?Java ExpressionUtils.isOffsetArrayAccess怎麽用?Java ExpressionUtils.isOffsetArrayAccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.siyeh.ig.psiutils.ExpressionUtils的用法示例。


在下文中一共展示了ExpressionUtils.isOffsetArrayAccess方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bodyIsArrayCopy

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
private static boolean bodyIsArrayCopy(
  PsiStatement body, PsiVariable variable,
  @Nullable PsiVariable variable2) {
  if (body instanceof PsiExpressionStatement) {
    final PsiExpressionStatement exp =
      (PsiExpressionStatement)body;
    final PsiExpression expression = exp.getExpression();
    return expressionIsArrayCopy(expression, variable, variable2);
  }
  else if (body instanceof PsiBlockStatement) {
    final PsiBlockStatement blockStatement =
      (PsiBlockStatement)body;
    final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
    final PsiStatement[] statements = codeBlock.getStatements();
    if (statements.length == 1) {
      return bodyIsArrayCopy(statements[0], variable, variable2);
    }
    else if (statements.length == 2) {
      final PsiStatement statement = statements[0];
      if (!(statement instanceof PsiDeclarationStatement)) {
        return false;
      }
      final PsiDeclarationStatement declarationStatement =
        (PsiDeclarationStatement)statement;
      final PsiElement[] declaredElements =
        declarationStatement.getDeclaredElements();
      if (declaredElements.length != 1) {
        return false;
      }
      final PsiElement declaredElement = declaredElements[0];
      if (!(declaredElement instanceof PsiVariable)) {
        return false;
      }
      final PsiVariable localVariable =
        (PsiVariable)declaredElement;
      final PsiExpression initializer =
        localVariable.getInitializer();
      if (!ExpressionUtils.isOffsetArrayAccess(initializer,
                                               variable)) {
        return false;
      }
      return bodyIsArrayCopy(statements[1], variable,
                             localVariable);
    }
  }
  return false;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:48,代碼來源:ManualArrayCopyInspection.java

示例2: expressionIsArrayCopy

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的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

示例3: bodyIsArrayToCollectionCopy

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的package包/類
private static boolean bodyIsArrayToCollectionCopy(
  PsiStatement body, PsiVariable variable,
  boolean shouldBeOffsetArrayAccess) {
  if (body instanceof PsiExpressionStatement) {
    final PsiExpressionStatement expressionStatement =
      (PsiExpressionStatement)body;
    final PsiExpression expression =
      expressionStatement.getExpression();
    return expressionIsArrayToCollectionCopy(expression, variable,
                                             shouldBeOffsetArrayAccess);
  }
  else if (body instanceof PsiBlockStatement) {
    final PsiBlockStatement blockStatement =
      (PsiBlockStatement)body;
    final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
    final PsiStatement[] statements = codeBlock.getStatements();
    if (statements.length == 1) {
      return bodyIsArrayToCollectionCopy(statements[0], variable,
                                         shouldBeOffsetArrayAccess);
    }
    else if (statements.length == 2) {
      final PsiStatement statement = statements[0];
      if (!(statement instanceof PsiDeclarationStatement)) {
        return false;
      }
      final PsiDeclarationStatement declarationStatement =
        (PsiDeclarationStatement)statement;
      final PsiElement[] declaredElements =
        declarationStatement.getDeclaredElements();
      if (declaredElements.length != 1) {
        return false;
      }
      final PsiElement declaredElement = declaredElements[0];
      if (!(declaredElement instanceof PsiVariable)) {
        return false;
      }
      final PsiVariable localVariable =
        (PsiVariable)declaredElement;
      final PsiExpression initializer =
        localVariable.getInitializer();
      if (!ExpressionUtils.isOffsetArrayAccess(initializer,
                                               variable)) {
        return false;
      }
      return bodyIsArrayToCollectionCopy(statements[1],
                                         localVariable, false);
    }
  }
  return false;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:51,代碼來源:ManualArrayToCollectionCopyInspection.java

示例4: expressionIsArrayToCollectionCopy

import com.siyeh.ig.psiutils.ExpressionUtils; //導入方法依賴的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.ExpressionUtils.isOffsetArrayAccess方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。