< prev index next >

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

Print this page

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