< prev index next >

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

Print this page

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

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