Community
Participate
Working Groups
Using HEAD, if I start Eclipse with a 1.5 VM, the compiler preferences defaults are automatically set to 5.0 (compliance, source and target). If I start with a 1.6 VM, I get a compliance 1.4. I don't think this is expected.
Darin, you are doing this on startup, no?
Martin, we only set 1.5 defaults currently. Should the default settings be similar to those in 1.5, except use the JavaCore.VERSION_1_6 constant? As follows: options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6); options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
That look good to me. Olivier? Maybe jdt.core could add a helper that sets the options for a given compliance. We have this knowledge currently in JavaModelUtil. public static void setCompilanceOptions(Map map, String compliance) { if (JavaCore.VERSION_1_6.equals(compliance)) { map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6); map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6); map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6); map.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); map.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); } else if (JavaCore.VERSION_1_5.equals(compliance)) { map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); map.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); map.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); } else if (JavaCore.VERSION_1_4.equals(compliance)) { map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); map.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING); map.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING); } else if (JavaCore.VERSION_1_3.equals(compliance)) { map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3); map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1); map.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE); map.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE); } else { throw new IllegalArgumentException("Unsupported compliance: " + compliance); //$NON-NLS-1$ } }
(In reply to comment #2) > options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6); > options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6); > options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6); > options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); > options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); Yes, these are the right settings.
(In reply to comment #3) > That look good to me. Olivier? Maybe jdt.core could add a helper that sets the > options for a given compliance. We have this knowledge currently in > JavaModelUtil. Where would you see this API? JavaCore ?
Yes, JavaCore seems like a good place for this.
+1 for having an API in JDTCore for configuring on compliance basis. It could be #setDefaults(complianceLevel) but, this would only modify the workspace defaults. What about project specific settings ? Maybe something rather like: JavaCore#getDefaultOptions(complianceLevel) ? This would acknowledge the fact that defaults may vary based on compliance.
We often work with maps, so a map modifying API would be the best to have setCompilanceOptions(String compliance, Map map) or getComplianceOptions(String compliance) would be fine too -> map.putAll(JavaCore.getComplianceOptions(compliance)) But make sure that the API name makes it clear that this only the 'compliance settings' setDefault is not clear.
Darin, any preference?
I think the modifying API would work OK: setCompilanceOptions(String compliance, Map map)
Added bug 165954 to take care of the API addition. A patch is available in bug 165954.
Fixed in JavaRuntime.
Please verify, Mike.
verified
Darin, is there any chance that this gets backported to 3.2.2?
*** Bug 180944 has been marked as a duplicate of this bug. ***
Also feels like something to backport to 3.2 maintenance (without new JDT/Core API there).