PsiType[] () { final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(myMainOccurrence, false, myOccurrenceClassProvider, false); final ArrayList<PsiType> allowedTypes = new ArrayList<>(); CommonJavaRefactoringUtil.processSuperTypes(getDefaultType(), new CommonJavaRefactoringUtil.SuperTypeVisitor() { @Override public void visitType(PsiType aType) { checkIfAllowed(aType); } @Override public void visitClass(PsiClass aClass) { checkIfAllowed(myFactory.createType(aClass)); } private void checkIfAllowed(PsiType type) { if (expectedTypes.length > 0) { final ExpectedTypeInfo typeInfo = ExpectedTypesProvider.createInfo(type, ExpectedTypeInfo.TYPE_STRICTLY, type, TailTypes.noneType()); for (ExpectedTypeInfo expectedType : expectedTypes) { if (expectedType.intersect(typeInfo).length != 0) { allowedTypes.add(type); break; } } } else { allowedTypes.add(type); } } }); collectAllSameShapedTypes(expectedTypes, allowedTypes); ArrayList<PsiType> result = normalizeTypeList(allowedTypes); return result.toArray(PsiType.createArray(result.size())); }