6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"

Mon, 23 Aug 2010 15:13:33 -0700

author
jjg
date
Mon, 23 Aug 2010 15:13:33 -0700
changeset 643
a626d8c1de6e
parent 642
6b95dd682538
child 644
0c81bff15ced
child 654
e9d09e97d669

6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Aug 23 11:56:53 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Aug 23 15:13:33 2010 -0700
     1.3 @@ -40,6 +40,7 @@
     1.4  import static com.sun.tools.javac.code.Flags.*;
     1.5  import static com.sun.tools.javac.code.Kinds.*;
     1.6  import static com.sun.tools.javac.code.TypeTags.*;
     1.7 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
     1.8  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
     1.9  import javax.lang.model.element.ElementVisitor;
    1.10  
    1.11 @@ -1665,8 +1666,10 @@
    1.12              List<Type> typeargtypes) {
    1.13          JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR,
    1.14                  pos, site, name, argtypes, typeargtypes);
    1.15 -        if (d != null)
    1.16 +        if (d != null) {
    1.17 +            d.setFlag(DiagnosticFlag.RESOLVE_ERROR);
    1.18              log.report(d);
    1.19 +        }
    1.20      }
    1.21  
    1.22      private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args");
     2.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Mon Aug 23 11:56:53 2010 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Mon Aug 23 15:13:33 2010 -0700
     2.3 @@ -25,8 +25,10 @@
     2.4  
     2.5  package com.sun.tools.javac.util;
     2.6  
     2.7 +import java.util.EnumSet;
     2.8  import java.util.Locale;
     2.9  import java.util.Map;
    2.10 +import java.util.Set;
    2.11  
    2.12  import javax.tools.Diagnostic;
    2.13  import javax.tools.JavaFileObject;
    2.14 @@ -83,7 +85,7 @@
    2.15           */
    2.16          public JCDiagnostic error(
    2.17                  DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
    2.18 -            return create(ERROR, null, true, source, pos, key, args);
    2.19 +            return create(ERROR, null, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, key, args);
    2.20          }
    2.21  
    2.22          /**
    2.23 @@ -96,7 +98,7 @@
    2.24           */
    2.25          public JCDiagnostic mandatoryWarning(
    2.26                  DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
    2.27 -            return create(WARNING, null, true, source, pos, key, args);
    2.28 +            return create(WARNING, null, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, key, args);
    2.29          }
    2.30  
    2.31          /**
    2.32 @@ -111,7 +113,7 @@
    2.33          public JCDiagnostic mandatoryWarning(
    2.34                  LintCategory lc,
    2.35                  DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
    2.36 -            return create(WARNING, lc, true, source, pos, key, args);
    2.37 +            return create(WARNING, lc, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, key, args);
    2.38          }
    2.39  
    2.40          /**
    2.41 @@ -123,7 +125,7 @@
    2.42           */
    2.43          public JCDiagnostic warning(
    2.44                   LintCategory lc, String key, Object... args) {
    2.45 -            return create(WARNING, lc, false, null, null, key, args);
    2.46 +            return create(WARNING, lc, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args);
    2.47          }
    2.48  
    2.49          /**
    2.50 @@ -135,7 +137,7 @@
    2.51           */
    2.52          public JCDiagnostic warning(
    2.53                  DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
    2.54 -            return create(WARNING, null, false, source, pos, key, args);
    2.55 +            return create(WARNING, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args);
    2.56          }
    2.57  
    2.58          /**
    2.59 @@ -149,7 +151,7 @@
    2.60           */
    2.61          public JCDiagnostic warning(
    2.62                   LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
    2.63 -            return create(WARNING, lc, false, source, pos, key, args);
    2.64 +            return create(WARNING, lc, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args);
    2.65          }
    2.66  
    2.67          /**
    2.68 @@ -159,7 +161,7 @@
    2.69           *  @see MandatoryWarningHandler
    2.70           */
    2.71          public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) {
    2.72 -            return create(NOTE, null, true, source, null, key, args);
    2.73 +            return create(NOTE, null, EnumSet.of(DiagnosticFlag.MANDATORY), source, null, key, args);
    2.74          }
    2.75  
    2.76          /**
    2.77 @@ -168,7 +170,7 @@
    2.78           *  @param args   Fields of the message.
    2.79           */
    2.80          public JCDiagnostic note(String key, Object... args) {
    2.81 -            return create(NOTE, null, false, null, null, key, args);
    2.82 +            return create(NOTE, null, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args);
    2.83          }
    2.84  
    2.85          /**
    2.86 @@ -180,7 +182,7 @@
    2.87           */
    2.88          public JCDiagnostic note(
    2.89                  DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
    2.90 -            return create(NOTE, null, false, source, pos, key, args);
    2.91 +            return create(NOTE, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args);
    2.92          }
    2.93  
    2.94          /**
    2.95 @@ -189,7 +191,7 @@
    2.96           *  @param args   Fields of the message.
    2.97           */
    2.98          public JCDiagnostic fragment(String key, Object... args) {
    2.99 -            return create(FRAGMENT, null, false, null, null, key, args);
   2.100 +            return create(FRAGMENT, null, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args);
   2.101          }
   2.102  
   2.103          /**
   2.104 @@ -204,7 +206,7 @@
   2.105           */
   2.106          public JCDiagnostic create(
   2.107                  DiagnosticType kind, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
   2.108 -            return create(kind, null, false, source, pos, key, args);
   2.109 +            return create(kind, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args);
   2.110          }
   2.111  
   2.112          /**
   2.113 @@ -218,8 +220,8 @@
   2.114           *  @param args        Fields of the message.
   2.115           */
   2.116          public JCDiagnostic create(
   2.117 -                DiagnosticType kind, LintCategory lc, boolean isMandatory, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
   2.118 -            return new JCDiagnostic(formatter, kind, lc, isMandatory, source, pos, qualify(kind, key), args);
   2.119 +                DiagnosticType kind, LintCategory lc, Set<DiagnosticFlag> flags, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
   2.120 +            return new JCDiagnostic(formatter, kind, lc, flags, source, pos, qualify(kind, key), args);
   2.121          }
   2.122  
   2.123          protected String qualify(DiagnosticType t, String key) {
   2.124 @@ -240,7 +242,7 @@
   2.125          return new JCDiagnostic(getFragmentFormatter(),
   2.126                                FRAGMENT,
   2.127                                null,
   2.128 -                              false,
   2.129 +                              EnumSet.noneOf(DiagnosticFlag.class),
   2.130                                null,
   2.131                                null,
   2.132                                "compiler." + FRAGMENT.key + "." + key,
   2.133 @@ -327,6 +329,11 @@
   2.134          private final int pos;
   2.135      }
   2.136  
   2.137 +    public enum DiagnosticFlag {
   2.138 +        MANDATORY,
   2.139 +        RESOLVE_ERROR
   2.140 +    }
   2.141 +
   2.142      private final DiagnosticType type;
   2.143      private final DiagnosticSource source;
   2.144      private final DiagnosticPosition position;
   2.145 @@ -334,7 +341,7 @@
   2.146      private final int column;
   2.147      private final String key;
   2.148      protected final Object[] args;
   2.149 -    private final boolean mandatory;
   2.150 +    private final Set<DiagnosticFlag> flags;
   2.151      private final LintCategory lintCategory;
   2.152  
   2.153      /**
   2.154 @@ -350,7 +357,7 @@
   2.155      protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter,
   2.156                         DiagnosticType dt,
   2.157                         LintCategory lc,
   2.158 -                       boolean mandatory,
   2.159 +                       Set<DiagnosticFlag> flags,
   2.160                         DiagnosticSource source,
   2.161                         DiagnosticPosition pos,
   2.162                         String key,
   2.163 @@ -361,7 +368,7 @@
   2.164          this.defaultFormatter = formatter;
   2.165          this.type = dt;
   2.166          this.lintCategory = lc;
   2.167 -        this.mandatory = mandatory;
   2.168 +        this.flags = flags;
   2.169          this.source = source;
   2.170          this.position = pos;
   2.171          this.key = key;
   2.172 @@ -401,7 +408,7 @@
   2.173       * @return true if this diagnostic is required to be shown.
   2.174       */
   2.175      public boolean isMandatory() {
   2.176 -        return mandatory;
   2.177 +        return flags.contains(DiagnosticFlag.MANDATORY);
   2.178      }
   2.179  
   2.180      /**
   2.181 @@ -520,8 +527,9 @@
   2.182          case NOTE:
   2.183              return Diagnostic.Kind.NOTE;
   2.184          case WARNING:
   2.185 -            return mandatory ? Diagnostic.Kind.MANDATORY_WARNING
   2.186 -                             : Diagnostic.Kind.WARNING;
   2.187 +            return flags.contains(DiagnosticFlag.MANDATORY)
   2.188 +                    ? Diagnostic.Kind.MANDATORY_WARNING
   2.189 +                    : Diagnostic.Kind.WARNING;
   2.190          case ERROR:
   2.191              return Diagnostic.Kind.ERROR;
   2.192          default:
   2.193 @@ -537,6 +545,14 @@
   2.194          return defaultFormatter.formatMessage(this, locale);
   2.195      }
   2.196  
   2.197 +    public void setFlag(DiagnosticFlag flag) {
   2.198 +        flags.add(flag);
   2.199 +    }
   2.200 +
   2.201 +    public boolean isFlagSet(DiagnosticFlag flag) {
   2.202 +        return flags.contains(flag);
   2.203 +    }
   2.204 +
   2.205      public static class MultilineDiagnostic extends JCDiagnostic {
   2.206  
   2.207          private final List<JCDiagnostic> subdiagnostics;
   2.208 @@ -545,7 +561,7 @@
   2.209              super(other.defaultFormatter,
   2.210                    other.getType(),
   2.211                    other.getLintCategory(),
   2.212 -                  other.isMandatory(),
   2.213 +                  other.flags,
   2.214                    other.getDiagnosticSource(),
   2.215                    other.position,
   2.216                    other.getCode(),

mercurial