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