src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
branchJDK-8226585-branch
changeset 58109 ee07de0d2c16
parent 55622 0b470386f5f7
child 58290 d885633d9de4
equal deleted inserted replaced
58018:a3c63a9dfb2c 58109:ee07de0d2c16
    91     private final JCDiagnostic.Factory diags;
    91     private final JCDiagnostic.Factory diags;
    92     private final JavaFileManager fileManager;
    92     private final JavaFileManager fileManager;
    93     private final Source source;
    93     private final Source source;
    94     private final Target target;
    94     private final Target target;
    95     private final Profile profile;
    95     private final Profile profile;
       
    96     private final Preview preview;
    96     private final boolean warnOnAnyAccessToMembers;
    97     private final boolean warnOnAnyAccessToMembers;
    97 
    98 
    98     // The set of lint options currently in effect. It is initialized
    99     // The set of lint options currently in effect. It is initialized
    99     // from the context, and then is set/reset as needed by Attr as it
   100     // from the context, and then is set/reset as needed by Attr as it
   100     // visits all the various parts of the trees during attribution.
   101     // visits all the various parts of the trees during attribution.
   137 
   138 
   138         Target target = Target.instance(context);
   139         Target target = Target.instance(context);
   139         syntheticNameChar = target.syntheticNameChar();
   140         syntheticNameChar = target.syntheticNameChar();
   140 
   141 
   141         profile = Profile.instance(context);
   142         profile = Profile.instance(context);
       
   143         preview = Preview.instance(context);
   142 
   144 
   143         boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
   145         boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
   144         boolean verboseRemoval = lint.isEnabled(LintCategory.REMOVAL);
   146         boolean verboseRemoval = lint.isEnabled(LintCategory.REMOVAL);
   145         boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
   147         boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
       
   148         boolean verbosePreview = lint.isEnabled(LintCategory.PREVIEW);
   146         boolean enforceMandatoryWarnings = true;
   149         boolean enforceMandatoryWarnings = true;
   147 
   150 
   148         deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
   151         deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
   149                 enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION);
   152                 enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION);
   150         removalHandler = new MandatoryWarningHandler(log, verboseRemoval,
   153         removalHandler = new MandatoryWarningHandler(log, verboseRemoval,
   151                 enforceMandatoryWarnings, "removal", LintCategory.REMOVAL);
   154                 enforceMandatoryWarnings, "removal", LintCategory.REMOVAL);
   152         uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
   155         uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
   153                 enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED);
   156                 enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED);
   154         sunApiHandler = new MandatoryWarningHandler(log, false,
   157         sunApiHandler = new MandatoryWarningHandler(log, false,
   155                 enforceMandatoryWarnings, "sunapi", null);
   158                 enforceMandatoryWarnings, "sunapi", null);
       
   159         previewHandler = new MandatoryWarningHandler(log, verbosePreview,
       
   160                 enforceMandatoryWarnings, "preview", null);
   156 
   161 
   157         deferredLintHandler = DeferredLintHandler.instance(context);
   162         deferredLintHandler = DeferredLintHandler.instance(context);
   158     }
   163     }
   159 
   164 
   160     /** Character for synthetic names
   165     /** Character for synthetic names
   179     private MandatoryWarningHandler uncheckedHandler;
   184     private MandatoryWarningHandler uncheckedHandler;
   180 
   185 
   181     /** A handler for messages about using proprietary API.
   186     /** A handler for messages about using proprietary API.
   182      */
   187      */
   183     private MandatoryWarningHandler sunApiHandler;
   188     private MandatoryWarningHandler sunApiHandler;
       
   189 
       
   190     /** A handler for messages about preview features.
       
   191      */
       
   192     private MandatoryWarningHandler previewHandler;
   184 
   193 
   185     /** A handler for deferred lint warnings.
   194     /** A handler for deferred lint warnings.
   186      */
   195      */
   187     private DeferredLintHandler deferredLintHandler;
   196     private DeferredLintHandler deferredLintHandler;
   188 
   197 
   222                 deprecationHandler.report(pos, Warnings.HasBeenDeprecated(sym, sym.location()));
   231                 deprecationHandler.report(pos, Warnings.HasBeenDeprecated(sym, sym.location()));
   223             }
   232             }
   224         }
   233         }
   225     }
   234     }
   226 
   235 
       
   236     /** Warn about deprecated symbol.
       
   237      *  @param pos        Position to be used for error reporting.
       
   238      *  @param sym        The deprecated symbol.
       
   239      */
       
   240     void warnPreview(DiagnosticPosition pos, Symbol sym) {
       
   241         if ((sym.flags() & PREVIEW_ESSENTIAL_API) != 0) {
       
   242             previewHandler.report(pos, Warnings.IsPreview(sym));
       
   243         } else {
       
   244             warnPreview(pos, Warnings.IsPreview(sym));
       
   245         }
       
   246     }
       
   247 
       
   248     /** Log a preview warning.
       
   249      *  @param pos        Position to be used for error reporting.
       
   250      *  @param msg        A Warning describing the problem.
       
   251      */
       
   252     public void warnPreview(DiagnosticPosition pos, Warning warnKey) {
       
   253         if (!lint.isSuppressed(LintCategory.PREVIEW))
       
   254             previewHandler.report(pos, warnKey);
       
   255     }
       
   256 
   227     /** Warn about unchecked operation.
   257     /** Warn about unchecked operation.
   228      *  @param pos        Position to be used for error reporting.
   258      *  @param pos        Position to be used for error reporting.
   229      *  @param msg        A string describing the problem.
   259      *  @param msg        A string describing the problem.
   230      */
   260      */
   231     public void warnUnchecked(DiagnosticPosition pos, Warning warnKey) {
   261     public void warnUnchecked(DiagnosticPosition pos, Warning warnKey) {
   260     public void reportDeferredDiagnostics() {
   290     public void reportDeferredDiagnostics() {
   261         deprecationHandler.reportDeferredDiagnostic();
   291         deprecationHandler.reportDeferredDiagnostic();
   262         removalHandler.reportDeferredDiagnostic();
   292         removalHandler.reportDeferredDiagnostic();
   263         uncheckedHandler.reportDeferredDiagnostic();
   293         uncheckedHandler.reportDeferredDiagnostic();
   264         sunApiHandler.reportDeferredDiagnostic();
   294         sunApiHandler.reportDeferredDiagnostic();
       
   295         previewHandler.reportDeferredDiagnostic();
   265     }
   296     }
   266 
   297 
   267 
   298 
   268     /** Report a failure to complete a class.
   299     /** Report a failure to complete a class.
   269      *  @param pos        Position to be used for error reporting.
   300      *  @param pos        Position to be used for error reporting.
  3288         if (profile != Profile.DEFAULT && (s.flags() & NOT_IN_PROFILE) != 0) {
  3319         if (profile != Profile.DEFAULT && (s.flags() & NOT_IN_PROFILE) != 0) {
  3289             log.error(pos, Errors.NotInProfile(s, profile));
  3320             log.error(pos, Errors.NotInProfile(s, profile));
  3290         }
  3321         }
  3291     }
  3322     }
  3292 
  3323 
       
  3324     void checkPreview(DiagnosticPosition pos, Symbol s) {
       
  3325         if ((s.flags() & PREVIEW_API) != 0) {
       
  3326             if ((s.flags() & PREVIEW_ESSENTIAL_API) != 0 && !preview.isEnabled()) {
       
  3327                 log.error(pos, Errors.IsPreview(s));
       
  3328             } else {
       
  3329                 deferredLintHandler.report(() -> warnPreview(pos, s));
       
  3330             }
       
  3331         }
       
  3332     }
       
  3333 
  3293 /* *************************************************************************
  3334 /* *************************************************************************
  3294  * Check for recursive annotation elements.
  3335  * Check for recursive annotation elements.
  3295  **************************************************************************/
  3336  **************************************************************************/
  3296 
  3337 
  3297     /** Check for cycles in the graph of annotation elements.
  3338     /** Check for cycles in the graph of annotation elements.