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