当前位置: 首页>>代码示例>>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;未经允许,请勿转载。