langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
author mcimadamore
Wed, 24 Jun 2009 10:51:13 +0100
changeset 3145 5300990c95bd
parent 2984 e15ff3a34054
child 3373 d62556aed18c
permissions -rw-r--r--
6852649: The Rich formatter printer should be an explicit class to facilitate overriding Summary: Improve reusabiliy of the rich formatter by removing anonymous inner classes/changing visibility of fields Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     1
/*
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     4
 *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    10
 *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    15
 * accompanied this code).
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    16
 *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    20
 *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    23
 * have any questions.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    24
 */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    25
package com.sun.tools.javac.util;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    26
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    27
import java.util.EnumSet;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    28
import java.util.HashMap;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    29
import java.util.LinkedHashMap;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    30
import java.util.Locale;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    31
import java.util.Map;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    32
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    33
import com.sun.tools.javac.code.Kinds;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    34
import com.sun.tools.javac.code.Printer;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    35
import com.sun.tools.javac.code.Symbol;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    36
import com.sun.tools.javac.code.Symbol.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.javac.code.Symtab;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    38
import com.sun.tools.javac.code.Type;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    39
import com.sun.tools.javac.code.Type.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    40
import com.sun.tools.javac.code.Types;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    41
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    42
import static com.sun.tools.javac.code.TypeTags.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    43
import static com.sun.tools.javac.code.Flags.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    44
import static com.sun.tools.javac.util.LayoutCharacters.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    45
import static com.sun.tools.javac.util.RichDiagnosticFormatter.RichConfiguration.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    46
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    47
/**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    48
 * A rich diagnostic formatter is a formatter that provides better integration
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    49
 * with javac's type system. A diagostic is first preprocessed in order to keep
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    50
 * track of each types/symbols in it; after these informations are collected,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    51
 * the diagnostic is rendered using a standard formatter, whose type/symbol printer
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    52
 * has been replaced by a more refined version provided by this rich formatter.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    53
 * The rich formatter currently enables three different features: (i) simple class
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    54
 * names - that is class names are displayed used a non qualified name (thus
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    55
 * omitting package info) whenever possible - (ii) where clause list - a list of
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    56
 * additional subdiagnostics that provide specific info about type-variables,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    57
 * captured types, intersection types that occur in the diagnostic that is to be
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    58
 * formatted and (iii) type-variable disambiguation - when the diagnostic refers
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    59
 * to two different type-variables with the same name, their representation is
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    60
 * disambiguated by appending an index to the type variable name.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    61
 */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    62
public class RichDiagnosticFormatter extends
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    63
        ForwardingDiagnosticFormatter<JCDiagnostic, AbstractDiagnosticFormatter> {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    64
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    65
    final Symtab syms;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    66
    final Types types;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    67
    final JCDiagnostic.Factory diags;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    68
    final JavacMessages messages;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    69
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    70
    /* name simplifier used by this formatter */
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
    71
    protected ClassNameSimplifier nameSimplifier;
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
    72
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
    73
    /* type/symbol printer used by this formatter */
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
    74
    private RichPrinter printer;
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    75
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    76
    /* map for keeping track of a where clause associated to a given type */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    77
    Map<WhereClauseKind, Map<Type, JCDiagnostic>> whereClauses;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    78
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    79
    /** Get the DiagnosticFormatter instance for this context. */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    80
    public static RichDiagnosticFormatter instance(Context context) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    81
        RichDiagnosticFormatter instance = context.get(RichDiagnosticFormatter.class);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    82
        if (instance == null)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    83
            instance = new RichDiagnosticFormatter(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    84
        return instance;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    85
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    86
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    87
    protected RichDiagnosticFormatter(Context context) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    88
        super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter());
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
    89
        setRichPrinter(new RichPrinter());
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    90
        this.syms = Symtab.instance(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    91
        this.diags = JCDiagnostic.Factory.instance(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    92
        this.types = Types.instance(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    93
        this.messages = JavacMessages.instance(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    94
        whereClauses = new LinkedHashMap<WhereClauseKind, Map<Type, JCDiagnostic>>();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    95
        configuration = new RichConfiguration(Options.instance(context), formatter);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    96
        for (WhereClauseKind kind : WhereClauseKind.values())
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    97
            whereClauses.put(kind, new LinkedHashMap<Type, JCDiagnostic>());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    98
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    99
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   100
    @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   101
    public String format(JCDiagnostic diag, Locale l) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   102
        StringBuilder sb = new StringBuilder();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   103
        nameSimplifier = new ClassNameSimplifier();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   104
        for (WhereClauseKind kind : WhereClauseKind.values())
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   105
            whereClauses.get(kind).clear();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   106
        preprocessDiagnostic(diag);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   107
        sb.append(formatter.format(diag, l));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   108
        if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   109
            List<JCDiagnostic> clauses = getWhereClauses();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   110
            String indent = formatter.isRaw() ? "" :
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   111
                formatter.indentString(DetailsInc);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   112
            for (JCDiagnostic d : clauses) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   113
                String whereClause = formatter.format(d, l);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   114
                if (whereClause.length() > 0) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   115
                    sb.append('\n' + indent + whereClause);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   116
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   117
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   118
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   119
        return sb.toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   120
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   121
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   122
    /**
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   123
     * Sets the type/symbol printer used by this formatter.
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   124
     * @param printer the rich printer to be set
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   125
     */
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   126
    protected void setRichPrinter(RichPrinter printer) {
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   127
        this.printer = printer;
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   128
        formatter.setPrinter(printer);
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   129
    }
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   130
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   131
    /**
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   132
     * Gets the type/symbol printer used by this formatter.
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   133
     * @return type/symbol rich printer
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   134
     */
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   135
    protected RichPrinter getRichPrinter() {
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   136
        return printer;
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   137
    }
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   138
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   139
    /**
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   140
     * Preprocess a given diagnostic by looking both into its arguments and into
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   141
     * its subdiagnostics (if any). This preprocessing is responsible for
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   142
     * generating info corresponding to features like where clauses, name
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   143
     * simplification, etc.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   144
     *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   145
     * @param diag the diagnostic to be preprocessed
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   146
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   147
    protected void preprocessDiagnostic(JCDiagnostic diag) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   148
        for (Object o : diag.getArgs()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   149
            if (o != null) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   150
                preprocessArgument(o);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   151
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   152
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   153
        if (diag.isMultiline()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   154
            for (JCDiagnostic d : diag.getSubdiagnostics())
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   155
                preprocessDiagnostic(d);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   156
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   157
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   158
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   159
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   160
     * Preprocess a diagnostic argument. A type/symbol argument is
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   161
     * preprocessed by specialized type/symbol preprocessors.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   162
     *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   163
     * @param arg the argument to be translated
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   164
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   165
    protected void preprocessArgument(Object arg) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   166
        if (arg instanceof Type) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   167
            preprocessType((Type)arg);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   168
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   169
        else if (arg instanceof Symbol) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   170
            preprocessSymbol((Symbol)arg);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   171
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   172
        else if (arg instanceof JCDiagnostic) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   173
            preprocessDiagnostic((JCDiagnostic)arg);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   174
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   175
        else if (arg instanceof Iterable<?>) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   176
            for (Object o : (Iterable<?>)arg) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   177
                preprocessArgument(o);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   178
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   179
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   180
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   181
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   182
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   183
     * Build a list of multiline diagnostics containing detailed info about
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   184
     * type-variables, captured types, and intersection types
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   185
     *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   186
     * @return where clause list
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   187
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   188
    protected List<JCDiagnostic> getWhereClauses() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   189
        List<JCDiagnostic> clauses = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   190
        for (WhereClauseKind kind : WhereClauseKind.values()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   191
            List<JCDiagnostic> lines = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   192
            for (Map.Entry<Type, JCDiagnostic> entry : whereClauses.get(kind).entrySet()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   193
                lines = lines.prepend(entry.getValue());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   194
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   195
            if (!lines.isEmpty()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   196
                String key = kind.key();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   197
                if (lines.size() > 1)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   198
                    key += ".1";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   199
                JCDiagnostic d = diags.fragment(key, whereClauses.get(kind).keySet());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   200
                d = new JCDiagnostic.MultilineDiagnostic(d, lines.reverse());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   201
                clauses = clauses.prepend(d);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   202
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   203
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   204
        return clauses.reverse();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   205
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   206
    //where
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   207
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   208
     * This enum defines all posssible kinds of where clauses that can be
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   209
     * attached by a rich diagnostic formatter to a given diagnostic
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   210
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   211
    enum WhereClauseKind {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   212
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   213
        /** where clause regarding a type variable */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   214
        TYPEVAR("where.description.typevar"),
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   215
        /** where clause regarding a captured type */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   216
        CAPTURED("where.description.captured"),
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   217
        /** where clause regarding an intersection type */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   218
        INTERSECTION("where.description.intersection");
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   219
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   220
        /** resource key for this where clause kind */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   221
        private String key;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   222
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   223
        WhereClauseKind(String key) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   224
            this.key = key;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   225
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   226
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   227
        String key() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   228
            return key;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   229
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   230
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   231
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   232
    // <editor-fold defaultstate="collapsed" desc="name simplifier">
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   233
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   234
     * A name simplifier keeps track of class names usages in order to determine
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   235
     * whether a class name can be compacted or not. Short names are not used
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   236
     * if a conflict is detected, e.g. when two classes with the same simple
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   237
     * name belong to different packages - in this case the formatter reverts
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   238
     * to fullnames as compact names might lead to a confusing diagnostic.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   239
     */
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   240
    protected class ClassNameSimplifier {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   241
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   242
        /* table for keeping track of all short name usages */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   243
        Map<Name, List<Symbol>> nameClashes = new HashMap<Name, List<Symbol>>();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   244
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   245
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   246
         * Add a name usage to the simplifier's internal cache
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   247
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   248
        protected void addUsage(Symbol sym) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   249
            Name n = sym.getSimpleName();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   250
            List<Symbol> conflicts = nameClashes.get(n);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   251
            if (conflicts == null) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   252
                conflicts = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   253
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   254
            if (!conflicts.contains(sym))
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   255
                nameClashes.put(n, conflicts.append(sym));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   256
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   257
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   258
        public String simplify(Symbol s) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   259
            String name = s.getQualifiedName().toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   260
            if (!s.type.isCompound()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   261
                List<Symbol> conflicts = nameClashes.get(s.getSimpleName());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   262
                if (conflicts == null ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   263
                    (conflicts.size() == 1 &&
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   264
                    conflicts.contains(s))) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   265
                    List<Name> l = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   266
                    Symbol s2 = s;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   267
                    while (s2.type.getEnclosingType().tag == CLASS
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   268
                            && s2.owner.kind == Kinds.TYP) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   269
                        l = l.prepend(s2.getSimpleName());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   270
                        s2 = s2.owner;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   271
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   272
                    l = l.prepend(s2.getSimpleName());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   273
                    StringBuilder buf = new StringBuilder();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   274
                    String sep = "";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   275
                    for (Name n2 : l) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   276
                        buf.append(sep);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   277
                        buf.append(n2);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   278
                        sep = ".";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   279
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   280
                    name = buf.toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   281
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   282
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   283
            return name;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   284
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   285
    };
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   286
    // </editor-fold>
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   287
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   288
    // <editor-fold defaultstate="collapsed" desc="rich printer">
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   289
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   290
     * Enhanced type/symbol printer that provides support for features like simple names
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   291
     * and type variable disambiguation. This enriched printer exploits the info
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   292
     * discovered during type/symbol preprocessing. This printer is set on the delegate
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   293
     * formatter so that rich type/symbol info can be properly rendered.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   294
     */
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   295
    protected class RichPrinter extends Printer {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   296
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   297
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   298
        public String localize(Locale locale, String key, Object... args) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   299
            return formatter.localize(locale, key, args);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   300
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   301
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   302
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   303
        public String capturedVarId(CapturedType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   304
            return indexOf(t, WhereClauseKind.CAPTURED) + "";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   305
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   306
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   307
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   308
        public String visitType(Type t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   309
            String s = super.visitType(t, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   310
            if (t == syms.botType)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   311
                s = localize(locale, "compiler.misc.type.null");
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   312
            return s;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   313
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   314
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   315
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   316
        public String visitCapturedType(CapturedType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   317
            if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   318
                return localize(locale,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   319
                    "compiler.misc.captured.type",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   320
                    indexOf(t, WhereClauseKind.CAPTURED));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   321
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   322
            else
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   323
                return super.visitCapturedType(t, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   324
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   325
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   326
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   327
        public String visitClassType(ClassType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   328
            if (t.isCompound() &&
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   329
                    getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   330
                return localize(locale,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   331
                        "compiler.misc.intersection.type",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   332
                        indexOf(t, WhereClauseKind.INTERSECTION));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   333
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   334
            else
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   335
                return super.visitClassType(t, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   336
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   337
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   338
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   339
        protected String className(ClassType t, boolean longform, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   340
            Symbol sym = t.tsym;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   341
            if (sym.name.length() == 0 ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   342
                    !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   343
                return super.className(t, longform, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   344
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   345
            else if (longform)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   346
                return nameSimplifier.simplify(sym).toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   347
            else
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   348
                return sym.name.toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   349
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   350
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   351
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   352
        public String visitTypeVar(TypeVar t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   353
            if (unique(t) ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   354
                    !getConfiguration().isEnabled(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   355
                return t.toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   356
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   357
            else {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   358
                return localize(locale,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   359
                        "compiler.misc.type.var",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   360
                        t.toString(), indexOf(t, WhereClauseKind.TYPEVAR));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   361
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   362
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   363
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   364
        private int indexOf(Type type, WhereClauseKind kind) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   365
            int index = 0;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   366
            boolean found = false;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   367
            for (Type t : whereClauses.get(kind).keySet()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   368
                if (t == type) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   369
                    found = true;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   370
                    break;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   371
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   372
                index++;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   373
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   374
            if (!found)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   375
                throw new AssertionError("Missing symbol in where clause " + type);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   376
            return index + 1;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   377
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   378
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   379
        private boolean unique(TypeVar typevar) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   380
            int found = 0;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   381
            for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   382
                if (t.toString().equals(typevar.toString())) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   383
                    found++;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   384
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   385
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   386
            if (found < 1)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   387
                throw new AssertionError("Missing type variable in where clause " + typevar);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   388
            return found == 1;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   389
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   390
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   391
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   392
        protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   393
            return super.printMethodArgs(args, varArgs, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   394
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   395
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   396
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   397
        public String visitClassSymbol(ClassSymbol s, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   398
            String name = nameSimplifier.simplify(s);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   399
            if (name.length() == 0 ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   400
                    !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   401
                return super.visitClassSymbol(s, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   402
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   403
            else {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   404
                return name;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   405
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   406
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   407
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   408
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   409
        public String visitMethodSymbol(MethodSymbol s, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   410
            String ownerName = visit(s.owner, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   411
            if ((s.flags() & BLOCK) != 0) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   412
               return ownerName;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   413
            } else {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   414
                String ms = (s.name == s.name.table.names.init)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   415
                    ? ownerName
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   416
                    : s.name.toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   417
                if (s.type != null) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   418
                    if (s.type.tag == FORALL) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   419
                        ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   420
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   421
                    ms += "(" + printMethodArgs(
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   422
                            s.type.getParameterTypes(),
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   423
                            (s.flags() & VARARGS) != 0,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   424
                            locale) + ")";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   425
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   426
                return ms;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   427
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   428
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   429
    };
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   430
    // </editor-fold>
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   431
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   432
    // <editor-fold defaultstate="collapsed" desc="type scanner">
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   433
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   434
     * Preprocess a given type looking for (i) additional info (where clauses) to be
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   435
     * added to the main diagnostic (ii) names to be compacted.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   436
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   437
    protected void preprocessType(Type t) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   438
        typePreprocessor.visit(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   439
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   440
    //where
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   441
    protected Types.UnaryVisitor<Void> typePreprocessor =
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   442
            new Types.UnaryVisitor<Void>() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   443
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   444
        public Void visit(List<Type> ts) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   445
            for (Type t : ts)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   446
                visit(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   447
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   448
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   449
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   450
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   451
        public Void visitForAll(ForAll t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   452
            visit(t.tvars);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   453
            visit(t.qtype);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   454
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   455
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   456
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   457
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   458
        public Void visitMethodType(MethodType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   459
            visit(t.argtypes);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   460
            visit(t.restype);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   461
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   462
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   463
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   464
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   465
        public Void visitErrorType(ErrorType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   466
            Type ot = t.getOriginalType();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   467
            if (ot != null)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   468
                visit(ot);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   469
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   470
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   471
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   472
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   473
        public Void visitArrayType(ArrayType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   474
            visit(t.elemtype);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   475
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   476
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   477
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   478
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   479
        public Void visitWildcardType(WildcardType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   480
            visit(t.type);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   481
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   482
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   483
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   484
        public Void visitType(Type t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   485
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   486
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   487
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   488
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   489
        public Void visitCapturedType(CapturedType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   490
            if (!whereClauses.get(WhereClauseKind.CAPTURED).containsKey(t)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   491
                String suffix = t.lower == syms.botType ? ".1" : "";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   492
                JCDiagnostic d = diags.fragment("where.captured"+ suffix, t, t.bound, t.lower, t.wildcard);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   493
                whereClauses.get(WhereClauseKind.CAPTURED).put(t, d);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   494
                visit(t.wildcard);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   495
                visit(t.lower);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   496
                visit(t.bound);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   497
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   498
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   499
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   500
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   501
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   502
        public Void visitClassType(ClassType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   503
            if (t.isCompound()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   504
                if (!whereClauses.get(WhereClauseKind.INTERSECTION).containsKey(t)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   505
                    Type supertype = types.supertype(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   506
                    List<Type> interfaces = types.interfaces(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   507
                    JCDiagnostic d = diags.fragment("where.intersection", t, interfaces.prepend(supertype));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   508
                    whereClauses.get(WhereClauseKind.INTERSECTION).put(t, d);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   509
                    visit(supertype);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   510
                    visit(interfaces);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   511
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   512
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   513
            nameSimplifier.addUsage(t.tsym);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   514
            visit(t.getTypeArguments());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   515
            if (t.getEnclosingType() != Type.noType)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   516
                visit(t.getEnclosingType());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   517
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   518
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   519
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   520
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   521
        public Void visitTypeVar(TypeVar t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   522
            if (!whereClauses.get(WhereClauseKind.TYPEVAR).containsKey(t)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   523
                Type bound = t.bound;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   524
                while ((bound instanceof ErrorType))
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   525
                    bound = ((ErrorType)bound).getOriginalType();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   526
                List<Type> bounds  = types.getBounds(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   527
                nameSimplifier.addUsage(t.tsym);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   528
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   529
                boolean boundErroneous = bounds.head == null ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   530
                                         bounds.head.tag == NONE ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   531
                                         bounds.head.tag == ERROR;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   532
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   533
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   534
                JCDiagnostic d = diags.fragment("where.typevar" +
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   535
                        (boundErroneous ? ".1" : ""), t, bounds,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   536
                        Kinds.kindName(t.tsym.location()), t.tsym.location());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   537
                whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   538
                symbolPreprocessor.visit(t.tsym.location(), null);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   539
                visit(bounds);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   540
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   541
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   542
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   543
    };
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   544
    // </editor-fold>
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   545
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   546
    // <editor-fold defaultstate="collapsed" desc="symbol scanner">
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   547
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   548
     * Preprocess a given symbol looking for (i) additional info (where clauses) to be
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   549
     * asdded to the main diagnostic (ii) names to be compacted
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   550
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   551
    protected void preprocessSymbol(Symbol s) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   552
        symbolPreprocessor.visit(s, null);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   553
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   554
    //where
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   555
    protected Types.DefaultSymbolVisitor<Void, Void> symbolPreprocessor =
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   556
            new Types.DefaultSymbolVisitor<Void, Void>() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   557
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   558
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   559
        public Void visitClassSymbol(ClassSymbol s, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   560
            nameSimplifier.addUsage(s);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   561
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   562
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   563
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   564
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   565
        public Void visitSymbol(Symbol s, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   566
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   567
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   568
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   569
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   570
        public Void visitMethodSymbol(MethodSymbol s, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   571
            visit(s.owner, null);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   572
            typePreprocessor.visit(s.type);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   573
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   574
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   575
    };
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   576
    // </editor-fold>
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   577
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   578
    @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   579
    public RichConfiguration getConfiguration() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   580
        //the following cast is always safe - see init
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   581
        return (RichConfiguration)configuration;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   582
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   583
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   584
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   585
     * Configuration object provided by the rich formatter.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   586
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   587
    public static class RichConfiguration extends ForwardingDiagnosticFormatter.ForwardingConfiguration {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   588
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   589
        /** set of enabled rich formatter's features */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   590
        protected java.util.EnumSet<RichFormatterFeature> features;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   591
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   592
        @SuppressWarnings("fallthrough")
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   593
        public RichConfiguration(Options options, AbstractDiagnosticFormatter formatter) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   594
            super(formatter.getConfiguration());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   595
            features = formatter.isRaw() ? EnumSet.noneOf(RichFormatterFeature.class) :
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   596
                EnumSet.of(RichFormatterFeature.SIMPLE_NAMES,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   597
                    RichFormatterFeature.WHERE_CLAUSES,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   598
                    RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   599
            String diagOpts = options.get("diags");
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   600
            if (diagOpts != null) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   601
                for (String args: diagOpts.split(",")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   602
                    if (args.equals("-where")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   603
                        features.remove(RichFormatterFeature.WHERE_CLAUSES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   604
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   605
                    else if (args.equals("where")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   606
                        features.add(RichFormatterFeature.WHERE_CLAUSES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   607
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   608
                    if (args.equals("-simpleNames")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   609
                        features.remove(RichFormatterFeature.SIMPLE_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   610
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   611
                    else if (args.equals("simpleNames")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   612
                        features.add(RichFormatterFeature.SIMPLE_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   613
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   614
                    if (args.equals("-disambiguateTvars")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   615
                        features.remove(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   616
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   617
                    else if (args.equals("disambiguateTvars")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   618
                        features.add(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   619
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   620
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   621
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   622
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   623
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   624
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   625
         * Returns a list of all the features supported by the rich formatter.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   626
         * @return list of supported features
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   627
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   628
        public RichFormatterFeature[] getAvailableFeatures() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   629
            return RichFormatterFeature.values();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   630
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   631
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   632
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   633
         * Enable a specific feature on this rich formatter.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   634
         * @param feature feature to be enabled
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   635
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   636
        public void enable(RichFormatterFeature feature) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   637
            features.add(feature);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   638
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   639
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   640
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   641
         * Disable a specific feature on this rich formatter.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   642
         * @param feature feature to be disabled
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   643
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   644
        public void disable(RichFormatterFeature feature) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   645
            features.remove(feature);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   646
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   647
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   648
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   649
         * Is a given feature enabled on this formatter?
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   650
         * @param feature feature to be tested
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   651
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   652
        public boolean isEnabled(RichFormatterFeature feature) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   653
            return features.contains(feature);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   654
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   655
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   656
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   657
         * The advanced formatting features provided by the rich formatter
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   658
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   659
        public enum RichFormatterFeature {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   660
            /** a list of additional info regarding a given type/symbol */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   661
            WHERE_CLAUSES,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   662
            /** full class names simplification (where possible) */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   663
            SIMPLE_NAMES,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   664
            /** type-variable names disambiguation */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   665
            UNIQUE_TYPEVAR_NAMES;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   666
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   667
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   668
}