private @Nullable PsiType getSuperType(PsiClass aClass, boolean checkImmediateSuperInterfaces) {
    if (CommonClassNames.JAVA_LANG_OBJECT.equals(aClass.getQualifiedName())) return null;

    PsiClass containingClass = checkImmediateSuperInterfaces ? PsiTreeUtil.getContextOfType(this, PsiClass.class) : null;
    if (containingClass != null) {
      final PsiClassType[] superTypes;
      if (containingClass.isInterface()) {
        superTypes = containingClass.getExtendsListTypes();
      }
      else if (containingClass instanceof PsiAnonymousClass) {
        if (PsiTreeUtil.isAncestor(((PsiAnonymousClass)containingClass).getArgumentList(), this, true)) {
          containingClass = PsiTreeUtil.getContextOfType(containingClass, PsiClass.class, true);
          superTypes = containingClass != null ? containingClass.getSuperTypes() : PsiClassType.EMPTY_ARRAY;
        }
        else {
          superTypes = new PsiClassType[]{((PsiAnonymousClass)containingClass).getBaseClassType()};
        }
      }
      else {
        superTypes = containingClass.getImplementsListTypes();
      }

      for (PsiClassType superType : superTypes) {
        final PsiClass superClass = superType.resolve();
        if (superClass != null && superClass.isInterface() && aClass.equals(superClass)) return superType;
      }
    }

    if (aClass.isInterface()) {
      return PsiType.getJavaLangObject(getManager(), getResolveScope());
    }

    if (aClass instanceof PsiAnonymousClass) {
      final PsiClassType baseClassType = ((PsiAnonymousClass)aClass).getBaseClassType();
      final PsiClass psiClass = baseClassType.resolve();
      return psiClass != null && !psiClass.isInterface() ? baseClassType : PsiType.getJavaLangObject(getManager(), getResolveScope());
    }

    final PsiClassType[] superTypes = aClass.getExtendsListTypes();
    return superTypes.length == 0 ? PsiType.getJavaLangObject(getManager(), getResolveScope()) : superTypes[0];
  }
private @Nullable PsiType getSuperType(PsiClass aClass, boolean checkImmediateSuperInterfaces)