-
Notifications
You must be signed in to change notification settings - Fork 747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StatementSwitchToExpressionSwitch: only trigger on compatible target versions #3646
Closed
Stephan202
wants to merge
5
commits into
google:master
from
PicnicSupermarket:bugfix/dont-suggest-switch-expressions-pre-jdk14
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a0bb07
StatementSwitchToExpressionSwitch: only trigger on compatible target …
Stephan202 42a036c
Alternative implementation
Stephan202 3690ab1
Javadoc doesn't like `@apiNote`
Stephan202 7806808
Unit test proposal
Stephan202 641c9dc
Avoid reliance on `Source.Feature`
Stephan202 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
check_api/src/main/java/com/google/errorprone/util/TargetVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2023 The Error Prone Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.errorprone.util; | ||
|
||
import com.sun.tools.javac.jvm.Target; | ||
import com.sun.tools.javac.util.Context; | ||
|
||
/** | ||
* JDK target version utilities. | ||
* | ||
* @see RuntimeVersion | ||
*/ | ||
public final class TargetVersion { | ||
/** Returns true if the compiler targets JRE 11 or newer. */ | ||
public static boolean isAtLeast11(Context context) { | ||
return majorVersion(context) >= 55; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 12 or newer. */ | ||
public static boolean isAtLeast12(Context context) { | ||
return majorVersion(context) >= 56; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 13 or newer. */ | ||
public static boolean isAtLeast13(Context context) { | ||
return majorVersion(context) >= 57; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 14 or newer. */ | ||
public static boolean isAtLeast14(Context context) { | ||
return majorVersion(context) >= 58; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 15 or newer. */ | ||
public static boolean isAtLeast15(Context context) { | ||
return majorVersion(context) >= 59; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 16 or newer. */ | ||
public static boolean isAtLeast16(Context context) { | ||
return majorVersion(context) >= 60; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 17 or newer. */ | ||
public static boolean isAtLeast17(Context context) { | ||
return majorVersion(context) >= 61; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 18 or newer. */ | ||
public static boolean isAtLeast18(Context context) { | ||
return majorVersion(context) >= 62; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 19 or newer. */ | ||
public static boolean isAtLeast19(Context context) { | ||
return majorVersion(context) >= 63; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 20 or newer. */ | ||
public static boolean isAtLeast20(Context context) { | ||
return majorVersion(context) >= 64; | ||
} | ||
|
||
/** Returns true if the compiler targets JRE 21 or newer. */ | ||
public static boolean isAtLeast21(Context context) { | ||
return majorVersion(context) >= 65; | ||
} | ||
|
||
private static int majorVersion(Context context) { | ||
return Target.instance(context).majorVersion; | ||
} | ||
|
||
private TargetVersion() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,10 +161,10 @@ | |
<compilerArgs> | ||
<arg>--add-exports=java.base/jdk.internal.javac=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Summary of changes:
|
||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg> | ||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg> | ||
|
@@ -213,6 +213,7 @@ | |
-Xmx1g | ||
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this PR is accepted, then the documentation should also be updated to include this flag. |
||
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems safe to assume that this PR won't be merged before the fireworks ;)