Community
Participate
Working Groups
The title says it all: we have a custom "Option" type for historical reasons, but it would be better to drop it and use the standard java.util.Optional instead. There are *a lot* of references to the custom type (a quick search shows 2198 references in my workspace). It would be nice if the replacement could be automated, but I'm not sure it can. A possible plan: 1. @Deprecate the current type (and the related Options class). 2. Start replacing the API usages first, leaving the purely internal usages for now. 3. If it's still too much, prioritize core plug-ins, then dialect-specific ones, then UI.
(In reply to Pierre-Charles David from comment #0) > There are *a lot* of references to the custom type (a quick search shows > 2198 references in my workspace). Removing all hits from *.internal.* packages still leaves 1202 references (including tests). Brutally removing the Option & Options types produces 4613 compilation errors (in my workspace, which contains a little more than just the Sirius sources).
Actually, it seems the following script may do the trick: #!/bin/sh find . -type f -name "*.java" -not \( -name "Option.java" -o -name "Options.java" \) -print | while read f; do sed -i -r \ -e 's/org.eclipse.sirius.ext.base.Option</java.util.Optional</g' \ -e 's/\bOption\.some\(/java.util.Optional.isPresent(/g' \ -e 's/\bOption\.get\(/java.util.Optional.isPresent(/g' \ -e 's/\bOptions\.newNone\(/java.util.Optional.empty(/g' \ -e 's/\bOptions\.newSome\(/java.util.Optional.of(/g' \ -e 's/\bOptions\.fromNullable\(/java.util.Optional.ofNullable(/g' \ -e 's/\bOption</java.util.Optional</g' \ -e 's/import org\.eclipse\.sirius\.ext\.base\.Option;//g' \ -e 's/import org\.eclipse\.sirius\.ext\.base\.Options;//g' \ -e 's/\bOption::some/java.util.Optional::isPresent/g' \ -e 's/\bOption::get/java.util.Optional::get/g' \ -e 's/\.some\(\)/.isPresent()/g' \ -e 's/\bOptions.<([A-Za-z<\?>]+)> *newNone\(\)/java.util.Optional.empty()/g' \ -e 's/\bOptions.<([A-Za-z<\?>]+)> *fromNullable\(/java.util.Optional.ofNullable(/g' \ "$f" done The result builds without any error (I have not run the tests), even after removing the old Option & Options classes. A separate "Organize imports" and API change documentation will be needed to finish the job but that's trivial.
New Gerrit change created: https://git.eclipse.org/r/115744
New Gerrit change created: https://git.eclipse.org/r/115743
Actually, I was a little too optimistic. There are (at least) two remaining issues with the current patch: * one is purely cosmetic: the "Organize imports" action leaves the fully qualified java.util.Optional references in the code instead of replacing them with a short name + additional import as I expected; * the other is more problematic: the old Options.newSome() API accepted null as a possible value, producing the equivalent of Options.newNone() in this case. It is actually equivalent to Options.ofNullable(). java.util.Optional.of(null) actually throws an NPE immediately, causing lots of test failures after the transformation. We should probably replace Options.newSome() with Optional.ofNullable(), which is more correct, even though it will highlight the fact that in our current usage of Options.newSome() we very often avoided actually asking ourselves if we'll really return an actual value. But that can be improved over time after the transformation (or not).
New Gerrit change created: https://git.eclipse.org/r/135936
New Gerrit change created: https://git.eclipse.org/r/135935
New Gerrit change created: https://git.eclipse.org/r/135938
New Gerrit change created: https://git.eclipse.org/r/135937
Gerrit change https://git.eclipse.org/r/135938 was merged to [master]. Commit: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=bdeb87b90d30c0879c23eb26cf4f0aa6d9fc1d7a
Gerrit change https://git.eclipse.org/r/135936 was merged to [master]. Commit: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=791ba39ea802690b53ee17a9361931afe288d11e
Gerrit change https://git.eclipse.org/r/135937 was merged to [master]. Commit: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=b83d533e44be4a158df8058ecf060a6add821032
Gerrit change https://git.eclipse.org/r/135935 was merged to [master]. Commit: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=cbe94b82db25ec64e2c4002818fb16a147a3da0c
New Gerrit change created: https://git.eclipse.org/r/136444
Gerrit change https://git.eclipse.org/r/136444 was merged to [master]. Commit: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=1b69251ca8fd2223e07430cf969b944c803ec148
Part of this was merged in 6.2.0, the next step will wait for the next version.
New Gerrit change created: https://git.eclipse.org/r/c/sirius/org.eclipse.sirius/+/189233
Gerrit change https://git.eclipse.org/r/c/sirius/org.eclipse.sirius/+/189233 was merged to [master]. Commit: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=f70b2b27050a8e04a59ac4e8b64f1bba2c064403
We've marked the type as deprecated for removal, and may remove some of its uses, but it will not be gone for 7.0.