PsiClass (PsiClassType... types) { if (types.length == 0) { return null; } final PsiClass firstClass = types[0].resolve(); if (firstClass == null || types.length == 1) { return firstClass; } Set<PsiClass> sourceSet = new HashSet<>(); PsiClass aClass = firstClass; while (aClass != null) { sourceSet.add(aClass); aClass = aClass.getSuperClass(); } if (sourceSet.isEmpty()) { return null; } Set<PsiClass> targetSet = new HashSet<>(); final int max = types.length - 1; for (int i = 1; i < max; i++) { final PsiClassType classType = types[i]; PsiClass aClass1 = classType.resolve(); while (aClass1 != null) { if (sourceSet.contains(aClass1)) { targetSet.add(aClass1); } aClass1 = aClass1.getSuperClass(); } sourceSet = targetSet; targetSet = new HashSet<>(); } PsiClass aClass1 = types[max].resolve(); while (aClass1 != null && !sourceSet.contains(aClass1)) { aClass1 = aClass1.getSuperClass(); } return aClass1; }