< prev index next >

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

Print this page

194 
195     /**
196      * Are preview features enabled?
197      * @return true, if preview features are enabled.
198      */
199     public boolean isEnabled() {
200         return enabled;
201     }
202 
203     /**
204      * Is given feature a preview feature?
205      * @param feature the feature to be tested.
206      * @return true, if given feature is a preview feature.
207      */
208     public boolean isPreview(Feature feature) {
209         return switch (feature) {
210             case STRING_TEMPLATES -> true;
211             case IMPLICIT_CLASSES -> true;
212             case SUPER_INIT -> true;
213             case PRIMITIVE_PATTERNS -> true;

214             //Note: this is a backdoor which allows to optionally treat all features as 'preview' (for testing).
215             //When real preview features will be added, this method can be implemented to return 'true'
216             //for those selected features, and 'false' for all the others.
217             default -> forcePreview;
218         };
219     }
220 
221     /**
222      * Generate an error key which captures the fact that a given preview feature could not be used
223      * due to the preview feature support being disabled.
224      * @param feature the feature for which the diagnostic has to be generated.
225      * @return the diagnostic.
226      */
227     public Error disabledError(Feature feature) {
228         Assert.check(!isEnabled());
229         return feature.isPlural() ?
230                 Errors.PreviewFeatureDisabledPlural(feature.nameFragment()) :
231                 Errors.PreviewFeatureDisabled(feature.nameFragment());
232     }
233 

194 
195     /**
196      * Are preview features enabled?
197      * @return true, if preview features are enabled.
198      */
199     public boolean isEnabled() {
200         return enabled;
201     }
202 
203     /**
204      * Is given feature a preview feature?
205      * @param feature the feature to be tested.
206      * @return true, if given feature is a preview feature.
207      */
208     public boolean isPreview(Feature feature) {
209         return switch (feature) {
210             case STRING_TEMPLATES -> true;
211             case IMPLICIT_CLASSES -> true;
212             case SUPER_INIT -> true;
213             case PRIMITIVE_PATTERNS -> true;
214             case VALUE_CLASSES -> true;
215             //Note: this is a backdoor which allows to optionally treat all features as 'preview' (for testing).
216             //When real preview features will be added, this method can be implemented to return 'true'
217             //for those selected features, and 'false' for all the others.
218             default -> forcePreview;
219         };
220     }
221 
222     /**
223      * Generate an error key which captures the fact that a given preview feature could not be used
224      * due to the preview feature support being disabled.
225      * @param feature the feature for which the diagnostic has to be generated.
226      * @return the diagnostic.
227      */
228     public Error disabledError(Feature feature) {
229         Assert.check(!isEnabled());
230         return feature.isPlural() ?
231                 Errors.PreviewFeatureDisabledPlural(feature.nameFragment()) :
232                 Errors.PreviewFeatureDisabled(feature.nameFragment());
233     }
234 
< prev index next >