コード例 #1
0
 private boolean isArrayLookup(PsiElement element, String indexName, PsiVariable arrayVariable) {
   if (element == null) {
     return false;
   }
   if (!(element instanceof PsiArrayAccessExpression)) {
     return false;
   }
   final PsiArrayAccessExpression arrayAccess = (PsiArrayAccessExpression) element;
   final PsiExpression indexExpression = arrayAccess.getIndexExpression();
   if (indexExpression == null) {
     return false;
   }
   if (!indexName.equals(indexExpression.getText())) {
     return false;
   }
   final PsiExpression arrayExpression = arrayAccess.getArrayExpression();
   if (!(arrayExpression instanceof PsiReferenceExpression)) {
     return false;
   }
   final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) arrayExpression;
   final PsiExpression qualifier = referenceExpression.getQualifierExpression();
   if (qualifier != null
       && !(qualifier instanceof PsiThisExpression)
       && !(qualifier instanceof PsiSuperExpression)) {
     return false;
   }
   final PsiElement target = referenceExpression.resolve();
   return arrayVariable.equals(target);
 }
コード例 #2
0
    private boolean isListGetLookup(
        PsiElement element, String indexName, PsiVariable listVariable) {
      if (!(element instanceof PsiExpression)) {
        return false;
      }
      final PsiExpression expression = (PsiExpression) element;
      if (!expressionIsListGetLookup(expression)) {
        return false;
      }
      final PsiMethodCallExpression methodCallExpression =
          (PsiMethodCallExpression) ParenthesesUtils.stripParentheses(expression);
      if (methodCallExpression == null) {
        return false;
      }
      final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
      final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();

      final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
      final PsiExpression[] expressions = argumentList.getExpressions();
      if (expressions.length != 1) {
        return false;
      }
      if (!indexName.equals(expressions[0].getText())) {
        return false;
      }
      if (qualifierExpression == null
          || qualifierExpression instanceof PsiThisExpression
          || qualifierExpression instanceof PsiSuperExpression) {
        return listVariable == null;
      }
      if (!(qualifierExpression instanceof PsiReferenceExpression)) {
        return false;
      }
      final PsiReferenceExpression referenceExpression =
          (PsiReferenceExpression) qualifierExpression;
      final PsiExpression qualifier = referenceExpression.getQualifierExpression();
      if (qualifier != null
          && !(qualifier instanceof PsiThisExpression)
          && !(qualifier instanceof PsiSuperExpression)) {
        return false;
      }
      final PsiElement target = referenceExpression.resolve();
      return listVariable.equals(target);
    }