[
https://issues.apache.org/jira/browse/GROOVY-10278?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17606150#comment-17606150
]
ASF GitHub Bot commented on GROOVY-10278:
-----------------------------------------
daniellansun commented on PR #1760:
URL: https://github.com/apache/groovy/pull/1760#issuecomment-1250104960
Merged. Thanks.
> CompilerConfiguration: improve target bytecode selection
> --------------------------------------------------------
>
> Key: GROOVY-10278
> URL: https://issues.apache.org/jira/browse/GROOVY-10278
> Project: Groovy
> Issue Type: Improvement
> Reporter: Eric Milles
> Assignee: Eric Milles
> Priority: Minor
> Time Spent: 1.5h
> Remaining Estimate: 0h
>
> The current implementation of
> {{CompilerConfiguration#setTargetBytecode(String)}} is to use the default
> version (currently "1.8") if the specified version is not supported. This can
> be a problem in joint compilation situations. If {{javac}} supports JDK19 or
> whatever comes along and {{groovyc}} only supports up to JDK17, then a target
> setting will be JDK19 for Java and JDK8 for Groovy.
> In groovy-eclipse, I have been selecting the nearest version. So if the user
> asks for "19" and "17" is supported, they'll get that. And if the user asks
> for "1.3" (hypothetical) then they'll get "1.4". And if the user still uses
> "9.0" or "11.0" notation, they'll get what they expect.
> {code:java}
> public void setTargetBytecode(final String version) {
> setTargetBytecodeIfValid(version);
> }
> private void setTargetBytecodeIfValid(final String version) {
> /* GRECLIPSE edit
> if (JDK_TO_BYTECODE_VERSION_MAP.containsKey(version)) {
> this.targetBytecode = version;
> }
> */
> int index;
> try { ALLOWED_JDKS[5] = "1.9"; // 9 is out of order for binary search
> index = Arrays.binarySearch(ALLOWED_JDKS,
> !version.startsWith("1") ? "1." + version : version);
> } finally {
> ALLOWED_JDKS[5] = "9";
> }
> if (index >= 0) {
> targetBytecode = ALLOWED_JDKS[index];
> } else {
> index = Math.abs(index) - 2; // closest version
> targetBytecode = ALLOWED_JDKS[Math.max(0, index)];
> }
> // GRECLIPSE end
> }
> {code}
> Note: the current algorithm breaks down when "20" or greater is supplied.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)