181 }
182
183 private Source(String name) {
184 this.name = name;
185 }
186
187 public static final Source MIN = Source.JDK8;
188
189 private static final Source MAX = values()[values().length - 1];
190
191 public static final Source DEFAULT = MAX;
192
193 public static Source lookup(String name) {
194 return tab.get(name);
195 }
196
197 public boolean isSupported() {
198 return this.compareTo(MIN) >= 0;
199 }
200
201 public Target requiredTarget() {
202 return switch(this) {
203 case JDK24 -> Target.JDK1_24;
204 case JDK23 -> Target.JDK1_23;
205 case JDK22 -> Target.JDK1_22;
206 case JDK21 -> Target.JDK1_21;
207 case JDK20 -> Target.JDK1_20;
208 case JDK19 -> Target.JDK1_19;
209 case JDK18 -> Target.JDK1_18;
210 case JDK17 -> Target.JDK1_17;
211 case JDK16 -> Target.JDK1_16;
212 case JDK15 -> Target.JDK1_15;
213 case JDK14 -> Target.JDK1_14;
214 case JDK13 -> Target.JDK1_13;
215 case JDK12 -> Target.JDK1_12;
216 case JDK11 -> Target.JDK1_11;
217 case JDK10 -> Target.JDK1_10;
218 case JDK9 -> Target.JDK1_9;
219 case JDK8 -> Target.JDK1_8;
220 case JDK7 -> Target.JDK1_7;
243 VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
244 IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
245 SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
246 SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
247 SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
248 NO_TARGET_ANNOTATION_APPLICABILITY(JDK14),
249 TEXT_BLOCKS(JDK15, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
250 PATTERN_MATCHING_IN_INSTANCEOF(JDK16, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
251 REIFIABLE_TYPES_INSTANCEOF(JDK16, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
252 RECORDS(JDK16, Fragments.FeatureRecords, DiagKind.PLURAL),
253 SEALED_CLASSES(JDK17, Fragments.FeatureSealedClasses, DiagKind.PLURAL),
254 CASE_NULL(JDK21, Fragments.FeatureCaseNull, DiagKind.NORMAL),
255 PATTERN_SWITCH(JDK21, Fragments.FeaturePatternSwitch, DiagKind.PLURAL),
256 REDUNDANT_STRICTFP(JDK17),
257 UNCONDITIONAL_PATTERN_IN_INSTANCEOF(JDK21, Fragments.FeatureUnconditionalPatternsInInstanceof, DiagKind.PLURAL),
258 RECORD_PATTERNS(JDK21, Fragments.FeatureDeconstructionPatterns, DiagKind.PLURAL),
259 IMPLICIT_CLASSES(JDK21, Fragments.FeatureImplicitClasses, DiagKind.PLURAL),
260 WARN_ON_ILLEGAL_UTF8(MIN, JDK21),
261 UNNAMED_VARIABLES(JDK22, Fragments.FeatureUnnamedVariables, DiagKind.PLURAL),
262 PRIMITIVE_PATTERNS(JDK23, Fragments.FeaturePrimitivePatterns, DiagKind.PLURAL),
263 FLEXIBLE_CONSTRUCTORS(JDK22, Fragments.FeatureFlexibleConstructors, DiagKind.NORMAL),
264 MODULE_IMPORTS(JDK23, Fragments.FeatureModuleImports, DiagKind.PLURAL),
265 ;
266
267 enum DiagKind {
268 NORMAL,
269 PLURAL;
270 }
271
272 private final Source minLevel;
273 private final Source maxLevel;
274 private final Fragment optFragment;
275 private final DiagKind optKind;
276
277 Feature(Source minLevel) {
278 this(minLevel, null, null);
279 }
280
281 Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
282 this(minLevel, MAX, optFragment, optKind);
|
181 }
182
183 private Source(String name) {
184 this.name = name;
185 }
186
187 public static final Source MIN = Source.JDK8;
188
189 private static final Source MAX = values()[values().length - 1];
190
191 public static final Source DEFAULT = MAX;
192
193 public static Source lookup(String name) {
194 return tab.get(name);
195 }
196
197 public boolean isSupported() {
198 return this.compareTo(MIN) >= 0;
199 }
200
201 public static boolean isSupported(Feature feature, int majorVersion) {
202 Source source = null;
203 for (Target target : Target.values()) {
204 if (majorVersion == target.majorVersion) {
205 source = lookup(target.name);
206 }
207 }
208 if (source != null) {
209 return feature.allowedInSource(source);
210 }
211 return false;
212 }
213
214 public Target requiredTarget() {
215 return switch(this) {
216 case JDK24 -> Target.JDK1_24;
217 case JDK23 -> Target.JDK1_23;
218 case JDK22 -> Target.JDK1_22;
219 case JDK21 -> Target.JDK1_21;
220 case JDK20 -> Target.JDK1_20;
221 case JDK19 -> Target.JDK1_19;
222 case JDK18 -> Target.JDK1_18;
223 case JDK17 -> Target.JDK1_17;
224 case JDK16 -> Target.JDK1_16;
225 case JDK15 -> Target.JDK1_15;
226 case JDK14 -> Target.JDK1_14;
227 case JDK13 -> Target.JDK1_13;
228 case JDK12 -> Target.JDK1_12;
229 case JDK11 -> Target.JDK1_11;
230 case JDK10 -> Target.JDK1_10;
231 case JDK9 -> Target.JDK1_9;
232 case JDK8 -> Target.JDK1_8;
233 case JDK7 -> Target.JDK1_7;
256 VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
257 IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
258 SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
259 SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
260 SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
261 NO_TARGET_ANNOTATION_APPLICABILITY(JDK14),
262 TEXT_BLOCKS(JDK15, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
263 PATTERN_MATCHING_IN_INSTANCEOF(JDK16, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
264 REIFIABLE_TYPES_INSTANCEOF(JDK16, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
265 RECORDS(JDK16, Fragments.FeatureRecords, DiagKind.PLURAL),
266 SEALED_CLASSES(JDK17, Fragments.FeatureSealedClasses, DiagKind.PLURAL),
267 CASE_NULL(JDK21, Fragments.FeatureCaseNull, DiagKind.NORMAL),
268 PATTERN_SWITCH(JDK21, Fragments.FeaturePatternSwitch, DiagKind.PLURAL),
269 REDUNDANT_STRICTFP(JDK17),
270 UNCONDITIONAL_PATTERN_IN_INSTANCEOF(JDK21, Fragments.FeatureUnconditionalPatternsInInstanceof, DiagKind.PLURAL),
271 RECORD_PATTERNS(JDK21, Fragments.FeatureDeconstructionPatterns, DiagKind.PLURAL),
272 IMPLICIT_CLASSES(JDK21, Fragments.FeatureImplicitClasses, DiagKind.PLURAL),
273 WARN_ON_ILLEGAL_UTF8(MIN, JDK21),
274 UNNAMED_VARIABLES(JDK22, Fragments.FeatureUnnamedVariables, DiagKind.PLURAL),
275 PRIMITIVE_PATTERNS(JDK23, Fragments.FeaturePrimitivePatterns, DiagKind.PLURAL),
276 VALUE_CLASSES(JDK22, Fragments.FeatureValueClasses, DiagKind.PLURAL),
277 FLEXIBLE_CONSTRUCTORS(JDK22, Fragments.FeatureFlexibleConstructors, DiagKind.NORMAL),
278 MODULE_IMPORTS(JDK23, Fragments.FeatureModuleImports, DiagKind.PLURAL),
279 ;
280
281 enum DiagKind {
282 NORMAL,
283 PLURAL;
284 }
285
286 private final Source minLevel;
287 private final Source maxLevel;
288 private final Fragment optFragment;
289 private final DiagKind optKind;
290
291 Feature(Source minLevel) {
292 this(minLevel, null, null);
293 }
294
295 Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
296 this(minLevel, MAX, optFragment, optKind);
|