< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java

Print this page

219         PRIVATE_SAFE_VARARGS(JDK9),
220         DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
221         UNDERSCORE_IDENTIFIER(MIN, JDK8),
222         PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
223         LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
224         VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
225         IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
226         SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
227         SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
228         SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
229         TEXT_BLOCKS(JDK15, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
230         PATTERN_MATCHING_IN_INSTANCEOF(JDK16, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
231         REIFIABLE_TYPES_INSTANCEOF(JDK16, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
232         RECORDS(JDK16, Fragments.FeatureRecords, DiagKind.PLURAL),
233         SEALED_CLASSES(JDK17, Fragments.FeatureSealedClasses, DiagKind.PLURAL),
234         CASE_NULL(JDK17, Fragments.FeatureCaseNull, DiagKind.NORMAL),
235         PATTERN_SWITCH(JDK17, Fragments.FeaturePatternSwitch, DiagKind.PLURAL),
236         REDUNDANT_STRICTFP(JDK17),
237         UNCONDITIONAL_PATTERN_IN_INSTANCEOF(JDK19, Fragments.FeatureUnconditionalPatternsInInstanceof, DiagKind.PLURAL),
238         RECORD_PATTERNS(JDK19, Fragments.FeatureDeconstructionPatterns, DiagKind.PLURAL),


239         ;
240 
241         enum DiagKind {
242             NORMAL,
243             PLURAL;
244         }
245 
246         private final Source minLevel;
247         private final Source maxLevel;
248         private final Fragment optFragment;
249         private final DiagKind optKind;
250 
251         Feature(Source minLevel) {
252             this(minLevel, null, null);
253         }
254 
255         Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
256             this(minLevel, MAX, optFragment, optKind);
257         }
258 

274 
275         public boolean isPlural() {
276             Assert.checkNonNull(optKind);
277             return optKind == DiagKind.PLURAL;
278         }
279 
280         public Fragment nameFragment() {
281             Assert.checkNonNull(optFragment);
282             return optFragment;
283         }
284 
285         public Fragment fragment(String sourceName) {
286             Assert.checkNonNull(optFragment);
287             return optKind == DiagKind.NORMAL ?
288                     Fragments.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
289                     Fragments.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
290         }
291 
292         public Error error(String sourceName) {
293             Assert.checkNonNull(optFragment);



294             return optKind == DiagKind.NORMAL ?
295                     Errors.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
296                     Errors.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
297         }
298     }
299 
300     public static SourceVersion toSourceVersion(Source source) {
301         return switch(source) {
302         case JDK1_2 -> RELEASE_2;
303         case JDK1_3 -> RELEASE_3;
304         case JDK1_4 -> RELEASE_4;
305         case JDK5   -> RELEASE_5;
306         case JDK6   -> RELEASE_6;
307         case JDK7   -> RELEASE_7;
308         case JDK8   -> RELEASE_8;
309         case JDK9   -> RELEASE_9;
310         case JDK10  -> RELEASE_10;
311         case JDK11  -> RELEASE_11;
312         case JDK12  -> RELEASE_12;
313         case JDK13  -> RELEASE_13;

219         PRIVATE_SAFE_VARARGS(JDK9),
220         DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
221         UNDERSCORE_IDENTIFIER(MIN, JDK8),
222         PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
223         LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
224         VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
225         IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
226         SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
227         SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
228         SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
229         TEXT_BLOCKS(JDK15, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
230         PATTERN_MATCHING_IN_INSTANCEOF(JDK16, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
231         REIFIABLE_TYPES_INSTANCEOF(JDK16, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
232         RECORDS(JDK16, Fragments.FeatureRecords, DiagKind.PLURAL),
233         SEALED_CLASSES(JDK17, Fragments.FeatureSealedClasses, DiagKind.PLURAL),
234         CASE_NULL(JDK17, Fragments.FeatureCaseNull, DiagKind.NORMAL),
235         PATTERN_SWITCH(JDK17, Fragments.FeaturePatternSwitch, DiagKind.PLURAL),
236         REDUNDANT_STRICTFP(JDK17),
237         UNCONDITIONAL_PATTERN_IN_INSTANCEOF(JDK19, Fragments.FeatureUnconditionalPatternsInInstanceof, DiagKind.PLURAL),
238         RECORD_PATTERNS(JDK19, Fragments.FeatureDeconstructionPatterns, DiagKind.PLURAL),
239         PRIMITIVE_CLASSES(JDK19, Fragments.FeaturePrimitiveClasses, DiagKind.PLURAL),
240         VALUE_CLASSES(JDK19, Fragments.FeatureValueClasses, DiagKind.PLURAL),
241         ;
242 
243         enum DiagKind {
244             NORMAL,
245             PLURAL;
246         }
247 
248         private final Source minLevel;
249         private final Source maxLevel;
250         private final Fragment optFragment;
251         private final DiagKind optKind;
252 
253         Feature(Source minLevel) {
254             this(minLevel, null, null);
255         }
256 
257         Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
258             this(minLevel, MAX, optFragment, optKind);
259         }
260 

276 
277         public boolean isPlural() {
278             Assert.checkNonNull(optKind);
279             return optKind == DiagKind.PLURAL;
280         }
281 
282         public Fragment nameFragment() {
283             Assert.checkNonNull(optFragment);
284             return optFragment;
285         }
286 
287         public Fragment fragment(String sourceName) {
288             Assert.checkNonNull(optFragment);
289             return optKind == DiagKind.NORMAL ?
290                     Fragments.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
291                     Fragments.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
292         }
293 
294         public Error error(String sourceName) {
295             Assert.checkNonNull(optFragment);
296             if (this == PRIMITIVE_CLASSES) {
297                 return Errors.PrimitiveClassesNotSupported(minLevel.name);
298             }
299             return optKind == DiagKind.NORMAL ?
300                     Errors.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
301                     Errors.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
302         }
303     }
304 
305     public static SourceVersion toSourceVersion(Source source) {
306         return switch(source) {
307         case JDK1_2 -> RELEASE_2;
308         case JDK1_3 -> RELEASE_3;
309         case JDK1_4 -> RELEASE_4;
310         case JDK5   -> RELEASE_5;
311         case JDK6   -> RELEASE_6;
312         case JDK7   -> RELEASE_7;
313         case JDK8   -> RELEASE_8;
314         case JDK9   -> RELEASE_9;
315         case JDK10  -> RELEASE_10;
316         case JDK11  -> RELEASE_11;
317         case JDK12  -> RELEASE_12;
318         case JDK13  -> RELEASE_13;
< prev index next >