PsiClass (@NotNull PsiReferenceExpression expression) { PsiExpression qualifierExpression = expression.getQualifierExpression(); if (qualifierExpression != null) { PsiType expressionType = qualifierExpression.getType(); if (expressionType instanceof PsiCapturedWildcardType) { expressionType = ((PsiCapturedWildcardType)expressionType).getUpperBound(); } PsiClass aClass = PsiUtil.resolveClassInType(expressionType); if (aClass != null) return aClass; if (qualifierExpression instanceof PsiReferenceExpression) { PsiElement qResolved = ((PsiReferenceExpression)qualifierExpression).resolve(); return qResolved instanceof PsiClass ? (PsiClass)qResolved : null; } return null; } return getThisClass(expression); }