25 |
25 |
26 package com.sun.tools.javac.code; |
26 package com.sun.tools.javac.code; |
27 |
27 |
28 import com.sun.tools.javac.code.Lint.LintCategory; |
28 import com.sun.tools.javac.code.Lint.LintCategory; |
29 import com.sun.tools.javac.code.Source.Feature; |
29 import com.sun.tools.javac.code.Source.Feature; |
30 import com.sun.tools.javac.comp.Infer; |
|
31 import com.sun.tools.javac.jvm.Target; |
30 import com.sun.tools.javac.jvm.Target; |
32 import com.sun.tools.javac.resources.CompilerProperties.Errors; |
31 import com.sun.tools.javac.resources.CompilerProperties.Errors; |
33 import com.sun.tools.javac.resources.CompilerProperties.Warnings; |
32 import com.sun.tools.javac.resources.CompilerProperties.Warnings; |
34 import com.sun.tools.javac.util.Assert; |
33 import com.sun.tools.javac.util.Assert; |
35 import com.sun.tools.javac.util.Context; |
34 import com.sun.tools.javac.util.Context; |
36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
35 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
37 import com.sun.tools.javac.util.JCDiagnostic.Error; |
36 import com.sun.tools.javac.util.JCDiagnostic.Error; |
38 import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; |
37 import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; |
|
38 import com.sun.tools.javac.util.JCDiagnostic.Warning; |
39 import com.sun.tools.javac.util.Log; |
39 import com.sun.tools.javac.util.Log; |
40 import com.sun.tools.javac.util.MandatoryWarningHandler; |
40 import com.sun.tools.javac.util.MandatoryWarningHandler; |
41 import com.sun.tools.javac.util.Name; |
|
42 import com.sun.tools.javac.util.Options; |
41 import com.sun.tools.javac.util.Options; |
43 |
42 |
44 import javax.tools.JavaFileObject; |
43 import javax.tools.JavaFileObject; |
45 import java.util.HashMap; |
44 import java.util.HashMap; |
46 import java.util.HashSet; |
|
47 import java.util.Map; |
45 import java.util.Map; |
48 import java.util.Optional; |
|
49 import java.util.Set; |
|
50 |
46 |
51 import static com.sun.tools.javac.main.Option.PREVIEW; |
47 import static com.sun.tools.javac.main.Option.PREVIEW; |
52 |
48 |
53 /** |
49 /** |
54 * Helper class to handle preview language features. This class maps certain language features |
50 * Helper class to handle preview language features. This class maps certain language features |
60 * diagnostics to inform the user of such usages. Such diagnostics can be enabled using the |
56 * diagnostics to inform the user of such usages. Such diagnostics can be enabled using the |
61 * {@link LintCategory#PREVIEW} lint category, and are suppressible by usual means. |
57 * {@link LintCategory#PREVIEW} lint category, and are suppressible by usual means. |
62 */ |
58 */ |
63 public class Preview { |
59 public class Preview { |
64 |
60 |
65 /** flag: are preview featutres enabled */ |
61 /** flag: are preview features enabled */ |
66 private final boolean enabled; |
62 private final boolean enabled; |
67 |
63 |
68 /** the diag handler to manage preview feature usage diagnostics */ |
64 /** the diag handler to manage preview feature usage diagnostics */ |
69 private final MandatoryWarningHandler previewHandler; |
65 private final MandatoryWarningHandler previewHandler; |
70 |
66 |
149 previewHandler.report(null, |
145 previewHandler.report(null, |
150 Warnings.PreviewFeatureUseClassfile(classfile, majorVersionToSource.get(majorVersion).name)); |
146 Warnings.PreviewFeatureUseClassfile(classfile, majorVersionToSource.get(majorVersion).name)); |
151 } |
147 } |
152 } |
148 } |
153 |
149 |
|
150 public void reportPreviewWarning(DiagnosticPosition pos, Warning warnKey) { |
|
151 previewHandler.report(pos, warnKey); |
|
152 } |
|
153 |
154 /** |
154 /** |
155 * Are preview features enabled? |
155 * Are preview features enabled? |
156 * @return true, if preview features are enabled. |
156 * @return true, if preview features are enabled. |
157 */ |
157 */ |
158 public boolean isEnabled() { |
158 public boolean isEnabled() { |