< prev index next >

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

Print this page

145         // s participates in the preview API
146         return syms.java_base.exports.stream()
147                 .filter(ed -> ed.packge.fullname == names.jdk_internal_javac)
148                 .anyMatch(ed -> ed.modules.contains(m));
149     }
150 
151     /**
152      * Report usage of a preview feature. Usages reported through this method will affect the
153      * set of sourcefiles with dependencies on preview features.
154      * @param flag a flag to set on the diagnostic
155      * @param pos the position at which the preview feature was used.
156      * @param feature the preview feature used.
157      */
158     public void warnPreview(DiagnosticFlag flag, int pos, Feature feature) {
159         warnPreview(flag, new SimpleDiagnosticPosition(pos), feature);
160     }
161 
162     /**
163      * Report usage of a preview feature. Usages reported through this method will affect the
164      * set of sourcefiles with dependencies on preview features.





165      * @param flag a flag to set on the diagnostic
166      * @param pos the position at which the preview feature was used.
167      * @param feature the preview feature used.
168      */
169     public void warnPreview(DiagnosticFlag flag, DiagnosticPosition pos, Feature feature) {
170         Assert.check(isEnabled());
171         Assert.check(isPreview(feature));
172         markUsesPreview(pos);
173         log.warning(flag, pos,
174             feature.isPlural() ?
175                 LintWarnings.PreviewFeatureUsePlural(feature.nameFragment()) :
176                 LintWarnings.PreviewFeatureUse(feature.nameFragment()));
177     }
178 
179     /**
180      * Report usage of a preview feature in classfile.
181      * @param classfile the name of the classfile with preview features enabled
182      * @param majorVersion the major version found in the classfile.
183      */
184     public void warnPreview(JavaFileObject classfile, int majorVersion) {

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 

145         // s participates in the preview API
146         return syms.java_base.exports.stream()
147                 .filter(ed -> ed.packge.fullname == names.jdk_internal_javac)
148                 .anyMatch(ed -> ed.modules.contains(m));
149     }
150 
151     /**
152      * Report usage of a preview feature. Usages reported through this method will affect the
153      * set of sourcefiles with dependencies on preview features.
154      * @param flag a flag to set on the diagnostic
155      * @param pos the position at which the preview feature was used.
156      * @param feature the preview feature used.
157      */
158     public void warnPreview(DiagnosticFlag flag, int pos, Feature feature) {
159         warnPreview(flag, new SimpleDiagnosticPosition(pos), feature);
160     }
161 
162     /**
163      * Report usage of a preview feature. Usages reported through this method will affect the
164      * set of sourcefiles with dependencies on preview features.
165      * <p>
166      * If the source code does not use a preview language feature, but when preview features
167      * are enabled, a different translation strategy is used and the resulting classfile
168      * depends on preview features, we can just {@link #markUsesPreview} silently.
169      *
170      * @param flag a flag to set on the diagnostic
171      * @param pos the position at which the preview feature was used.
172      * @param feature the preview feature used.
173      */
174     public void warnPreview(DiagnosticFlag flag, DiagnosticPosition pos, Feature feature) {
175         Assert.check(isEnabled());
176         Assert.check(isPreview(feature));
177         markUsesPreview(pos);
178         log.warning(flag, pos,
179             feature.isPlural() ?
180                 LintWarnings.PreviewFeatureUsePlural(feature.nameFragment()) :
181                 LintWarnings.PreviewFeatureUse(feature.nameFragment()));
182     }
183 
184     /**
185      * Report usage of a preview feature in classfile.
186      * @param classfile the name of the classfile with preview features enabled
187      * @param majorVersion the major version found in the classfile.
188      */
189     public void warnPreview(JavaFileObject classfile, int majorVersion) {

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