PsiClass (@NotNull UElement sourceNode, boolean forClassReference) { PsiElement sourcePsi = sourceNode.getSourcePsi(); UClass sourceClass = UastUtils.findContaining(sourcePsi, UClass.class); if (sourceClass == null) return null; if (isReferenceBelongsToEnclosingClass(sourceNode, sourceClass, forClassReference)) { UClass parentClass = UastUtils.getContainingUClass(sourceClass); return parentClass != null ? parentClass.getJavaPsi() : null; } return sourceClass.getJavaPsi(); }