DfEphemeralReferenceType (TypeConstraint constraint, Set<Object> notValues) { if (notValues.isEmpty()) return null; Object value = notValues.iterator().next(); if (!(value instanceof PsiEnumConstant)) return null; PsiClass enumClass = ((PsiEnumConstant)value).getContainingClass(); if (enumClass == null) return null; TypeConstraint enumType = TypeConstraints.instanceOf( JavaPsiFacade.getElementFactory(enumClass.getProject()).createType(enumClass)); if (!enumType.equals(constraint)) return null; Set<PsiEnumConstant> allEnumConstants = StreamEx.of(enumClass.getFields()).select(PsiEnumConstant.class).toSet(); if (notValues.size() != allEnumConstants.size()) return null; for (Object notValue : notValues) { if (!(notValue instanceof PsiEnumConstant)) return null; if (!allEnumConstants.remove(notValue)) return null; } if (allEnumConstants.isEmpty()) { return new DfEphemeralReferenceType(constraint); } return null; }