< prev index next >

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

Print this page

198     public boolean usesPreview(JavaFileObject file) {
199         return sourcesWithPreviewFeatures.contains(file);
200     }
201 
202     /**
203      * Are preview features enabled?
204      * @return true, if preview features are enabled.
205      */
206     public boolean isEnabled() {
207         return enabled;
208     }
209 
210     /**
211      * Is given feature a preview feature?
212      * @param feature the feature to be tested.
213      * @return true, if given feature is a preview feature.
214      */
215     public boolean isPreview(Feature feature) {
216         return switch (feature) {
217             case PRIMITIVE_PATTERNS -> true;

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

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