< prev index next >

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

Print this page

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


233         ;
234 
235         enum DiagKind {
236             NORMAL,
237             PLURAL;
238         }
239 
240         private final Source minLevel;
241         private final Source maxLevel;
242         private final Fragment optFragment;
243         private final DiagKind optKind;
244 
245         Feature(Source minLevel) {
246             this(minLevel, null, null);
247         }
248 
249         Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
250             this(minLevel, MAX, optFragment, optKind);
251         }
252 

268 
269         public boolean isPlural() {
270             Assert.checkNonNull(optKind);
271             return optKind == DiagKind.PLURAL;
272         }
273 
274         public Fragment nameFragment() {
275             Assert.checkNonNull(optFragment);
276             return optFragment;
277         }
278 
279         public Fragment fragment(String sourceName) {
280             Assert.checkNonNull(optFragment);
281             return optKind == DiagKind.NORMAL ?
282                     Fragments.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
283                     Fragments.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
284         }
285 
286         public Error error(String sourceName) {
287             Assert.checkNonNull(optFragment);



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

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

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