src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File langtools Sdiff src/share/classes/com/sun/tools/javac/util

src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java

Print this page




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.tools.javac.util;
  26 

  27 import java.util.EnumSet;
  28 import java.util.HashMap;
  29 import java.util.LinkedHashMap;
  30 import java.util.Locale;
  31 import java.util.Map;
  32 
  33 import com.sun.tools.javac.code.Kinds;
  34 import com.sun.tools.javac.code.Printer;
  35 import com.sun.tools.javac.code.Symbol;
  36 import com.sun.tools.javac.code.Symbol.*;
  37 import com.sun.tools.javac.code.Symtab;
  38 import com.sun.tools.javac.code.Type;
  39 import com.sun.tools.javac.code.Type.*;
  40 import com.sun.tools.javac.code.Types;
  41 
  42 import static com.sun.tools.javac.code.TypeTag.*;
  43 import static com.sun.tools.javac.code.Flags.*;
  44 import static com.sun.tools.javac.util.LayoutCharacters.*;
  45 import static com.sun.tools.javac.util.RichDiagnosticFormatter.RichConfiguration.*;
  46 


  79     private RichPrinter printer;
  80 
  81     /* map for keeping track of a where clause associated to a given type */
  82     Map<WhereClauseKind, Map<Type, JCDiagnostic>> whereClauses;
  83 
  84     /** Get the DiagnosticFormatter instance for this context. */
  85     public static RichDiagnosticFormatter instance(Context context) {
  86         RichDiagnosticFormatter instance = context.get(RichDiagnosticFormatter.class);
  87         if (instance == null)
  88             instance = new RichDiagnosticFormatter(context);
  89         return instance;
  90     }
  91 
  92     protected RichDiagnosticFormatter(Context context) {
  93         super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter());
  94         setRichPrinter(new RichPrinter());
  95         this.syms = Symtab.instance(context);
  96         this.diags = JCDiagnostic.Factory.instance(context);
  97         this.types = Types.instance(context);
  98         this.messages = JavacMessages.instance(context);
  99         whereClauses = new LinkedHashMap<WhereClauseKind, Map<Type, JCDiagnostic>>();
 100         configuration = new RichConfiguration(Options.instance(context), formatter);
 101         for (WhereClauseKind kind : WhereClauseKind.values())
 102             whereClauses.put(kind, new LinkedHashMap<Type, JCDiagnostic>());
 103     }
 104 
 105     @Override
 106     public String format(JCDiagnostic diag, Locale l) {
 107         StringBuilder sb = new StringBuilder();
 108         nameSimplifier = new ClassNameSimplifier();
 109         for (WhereClauseKind kind : WhereClauseKind.values())
 110             whereClauses.get(kind).clear();
 111         preprocessDiagnostic(diag);
 112         sb.append(formatter.format(diag, l));
 113         if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
 114             List<JCDiagnostic> clauses = getWhereClauses();
 115             String indent = formatter.isRaw() ? "" :
 116                 formatter.indentString(DetailsInc);
 117             for (JCDiagnostic d : clauses) {
 118                 String whereClause = formatter.format(d, l);
 119                 if (whereClause.length() > 0) {




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.tools.javac.util;
  26 
  27 import java.util.EnumMap;
  28 import java.util.EnumSet;
  29 import java.util.HashMap;
  30 import java.util.LinkedHashMap;
  31 import java.util.Locale;
  32 import java.util.Map;
  33 
  34 import com.sun.tools.javac.code.Kinds;
  35 import com.sun.tools.javac.code.Printer;
  36 import com.sun.tools.javac.code.Symbol;
  37 import com.sun.tools.javac.code.Symbol.*;
  38 import com.sun.tools.javac.code.Symtab;
  39 import com.sun.tools.javac.code.Type;
  40 import com.sun.tools.javac.code.Type.*;
  41 import com.sun.tools.javac.code.Types;
  42 
  43 import static com.sun.tools.javac.code.TypeTag.*;
  44 import static com.sun.tools.javac.code.Flags.*;
  45 import static com.sun.tools.javac.util.LayoutCharacters.*;
  46 import static com.sun.tools.javac.util.RichDiagnosticFormatter.RichConfiguration.*;
  47 


  80     private RichPrinter printer;
  81 
  82     /* map for keeping track of a where clause associated to a given type */
  83     Map<WhereClauseKind, Map<Type, JCDiagnostic>> whereClauses;
  84 
  85     /** Get the DiagnosticFormatter instance for this context. */
  86     public static RichDiagnosticFormatter instance(Context context) {
  87         RichDiagnosticFormatter instance = context.get(RichDiagnosticFormatter.class);
  88         if (instance == null)
  89             instance = new RichDiagnosticFormatter(context);
  90         return instance;
  91     }
  92 
  93     protected RichDiagnosticFormatter(Context context) {
  94         super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter());
  95         setRichPrinter(new RichPrinter());
  96         this.syms = Symtab.instance(context);
  97         this.diags = JCDiagnostic.Factory.instance(context);
  98         this.types = Types.instance(context);
  99         this.messages = JavacMessages.instance(context);
 100         whereClauses = new EnumMap<WhereClauseKind, Map<Type, JCDiagnostic>>(WhereClauseKind.class);
 101         configuration = new RichConfiguration(Options.instance(context), formatter);
 102         for (WhereClauseKind kind : WhereClauseKind.values())
 103             whereClauses.put(kind, new LinkedHashMap<Type, JCDiagnostic>());
 104     }
 105 
 106     @Override
 107     public String format(JCDiagnostic diag, Locale l) {
 108         StringBuilder sb = new StringBuilder();
 109         nameSimplifier = new ClassNameSimplifier();
 110         for (WhereClauseKind kind : WhereClauseKind.values())
 111             whereClauses.get(kind).clear();
 112         preprocessDiagnostic(diag);
 113         sb.append(formatter.format(diag, l));
 114         if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
 115             List<JCDiagnostic> clauses = getWhereClauses();
 116             String indent = formatter.isRaw() ? "" :
 117                 formatter.indentString(DetailsInc);
 118             for (JCDiagnostic d : clauses) {
 119                 String whereClause = formatter.format(d, l);
 120                 if (whereClause.length() > 0) {


src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File