The refactoring option may not be available in all the cases (the source set should be unmodifiable).
However IntelliJ has inspections that may be more suitable to detect such a case.
See under Java > Java language level migration aids > Java 9 : Immutable collection creation can be replaced with collection factory call :
This inspection helps to convert unmodifiable collections created
before Java 9 to new collection factory methods like List.of
or
Set.of
. Also since Java 10 the conversion to List.copyOf
, etc. could
be suggested.
Note that Java 9 collection factory methods do not
accept null values. Also set elements and map keys are required to be
different. It's not always possible to statically check whether
original elements are different and not null. Using the checkbox you
may enforce the inspection to warn only if original elements are
compile-time constants, so the conversion is guaranteed to be correct.
This inspection is available since Java 9 only.
New in 2017.2
This inspection can be tested with this code :
Set<String> stringSet = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("a", "b", "c")));