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