langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
author jlahoda
Thu, 15 Jun 2017 13:44:42 +0200
changeset 45504 ea7475564d07
parent 42828 cce89649f958
permissions -rw-r--r--
8170326: Inconsistencies between code, compiler.properties and comments Summary: Converting uses of Log and JCDiagnostic.Factory methods to use CompilerProperties instead of plain Strings, fixing inconsistencies, adding crules analyzer to ensure CompilerProperties are used whenever possible. Reviewed-by: mcimadamore
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
/*
39812
6272642715a1 8161019: javac, fold formatter options
vromero
parents: 35348
diff changeset
     2
 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
2984
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3541
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2984
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3541
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2984
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3541
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3541
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3541
diff changeset
    23
 * questions.
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    24
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 29842
diff changeset
    25
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    26
package com.sun.tools.javac.util;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    27
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    28
import java.nio.file.Path;
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14801
diff changeset
    29
import java.util.EnumMap;
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    30
import java.util.EnumSet;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    31
import java.util.HashMap;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    32
import java.util.LinkedHashMap;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    33
import java.util.Locale;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    34
import java.util.Map;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    35
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    36
import com.sun.tools.javac.code.Printer;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.javac.code.Symbol;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    38
import com.sun.tools.javac.code.Symbol.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    39
import com.sun.tools.javac.code.Symtab;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    40
import com.sun.tools.javac.code.Type;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    41
import com.sun.tools.javac.code.Type.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    42
import com.sun.tools.javac.code.Types;
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 42828
diff changeset
    43
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    44
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    45
import static com.sun.tools.javac.code.Flags.*;
27226
53535e4e1b08 8061723: 8060056 breaks tests on Windows
jjg
parents: 27225
diff changeset
    46
import static com.sun.tools.javac.code.TypeTag.*;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
    47
import static com.sun.tools.javac.code.Kinds.*;
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
    48
import static com.sun.tools.javac.code.Kinds.Kind.*;
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    49
import static com.sun.tools.javac.util.LayoutCharacters.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    50
import static com.sun.tools.javac.util.RichDiagnosticFormatter.RichConfiguration.*;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    51
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    52
/**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    53
 * 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
    54
 * 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
    55
 * 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
    56
 * 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
    57
 * 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
    58
 * 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
    59
 * 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
    60
 * 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
    61
 * additional subdiagnostics that provide specific info about type-variables,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    62
 * 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
    63
 * 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
    64
 * 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
    65
 * disambiguated by appending an index to the type variable name.
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 3373
diff changeset
    66
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    67
 * <p><b>This is NOT part of any supported API.
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 3373
diff changeset
    68
 * If you write code that depends on this, you do so at your own risk.
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 3373
diff changeset
    69
 * This code and its internal interfaces are subject to change or
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 3373
diff changeset
    70
 * deletion without notice.</b>
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    71
 */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    72
public class RichDiagnosticFormatter extends
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    73
        ForwardingDiagnosticFormatter<JCDiagnostic, AbstractDiagnosticFormatter> {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    74
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    75
    final Symtab syms;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    76
    final Types types;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    77
    final JCDiagnostic.Factory diags;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    78
    final JavacMessages messages;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    79
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    80
    /* 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
    81
    protected ClassNameSimplifier nameSimplifier;
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
    82
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
    83
    /* 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
    84
    private RichPrinter printer;
2984
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
    /* 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
    87
    Map<WhereClauseKind, Map<Type, JCDiagnostic>> whereClauses;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    88
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    89
    /** Get the DiagnosticFormatter instance for this context. */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    90
    public static RichDiagnosticFormatter instance(Context context) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    91
        RichDiagnosticFormatter instance = context.get(RichDiagnosticFormatter.class);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    92
        if (instance == null)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    93
            instance = new RichDiagnosticFormatter(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    94
        return instance;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    95
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    96
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    97
    protected RichDiagnosticFormatter(Context context) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
    98
        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
    99
        setRichPrinter(new RichPrinter());
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   100
        this.syms = Symtab.instance(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   101
        this.diags = JCDiagnostic.Factory.instance(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   102
        this.types = Types.instance(context);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   103
        this.messages = JavacMessages.instance(context);
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18900
diff changeset
   104
        whereClauses = new EnumMap<>(WhereClauseKind.class);
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   105
        configuration = new RichConfiguration(Options.instance(context), formatter);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   106
        for (WhereClauseKind kind : WhereClauseKind.values())
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   107
            whereClauses.put(kind, new LinkedHashMap<Type, JCDiagnostic>());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   108
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   109
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   110
    @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   111
    public String format(JCDiagnostic diag, Locale l) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   112
        StringBuilder sb = new StringBuilder();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   113
        nameSimplifier = new ClassNameSimplifier();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   114
        for (WhereClauseKind kind : WhereClauseKind.values())
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   115
            whereClauses.get(kind).clear();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   116
        preprocessDiagnostic(diag);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   117
        sb.append(formatter.format(diag, l));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   118
        if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   119
            List<JCDiagnostic> clauses = getWhereClauses();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   120
            String indent = formatter.isRaw() ? "" :
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   121
                formatter.indentString(DetailsInc);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   122
            for (JCDiagnostic d : clauses) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   123
                String whereClause = formatter.format(d, l);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   124
                if (whereClause.length() > 0) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   125
                    sb.append('\n' + indent + whereClause);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   126
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   127
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   128
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   129
        return sb.toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   130
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   131
18006
c1b8a1815c54 7116676: RichDiagnosticFormatter throws NPE when formatMessage is called directly
mcimadamore
parents: 16809
diff changeset
   132
    @Override
c1b8a1815c54 7116676: RichDiagnosticFormatter throws NPE when formatMessage is called directly
mcimadamore
parents: 16809
diff changeset
   133
    public String formatMessage(JCDiagnostic diag, Locale l) {
c1b8a1815c54 7116676: RichDiagnosticFormatter throws NPE when formatMessage is called directly
mcimadamore
parents: 16809
diff changeset
   134
        nameSimplifier = new ClassNameSimplifier();
c1b8a1815c54 7116676: RichDiagnosticFormatter throws NPE when formatMessage is called directly
mcimadamore
parents: 16809
diff changeset
   135
        preprocessDiagnostic(diag);
c1b8a1815c54 7116676: RichDiagnosticFormatter throws NPE when formatMessage is called directly
mcimadamore
parents: 16809
diff changeset
   136
        return super.formatMessage(diag, l);
c1b8a1815c54 7116676: RichDiagnosticFormatter throws NPE when formatMessage is called directly
mcimadamore
parents: 16809
diff changeset
   137
    }
c1b8a1815c54 7116676: RichDiagnosticFormatter throws NPE when formatMessage is called directly
mcimadamore
parents: 16809
diff changeset
   138
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   139
    /**
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   140
     * 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
   141
     * @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
   142
     */
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   143
    protected void setRichPrinter(RichPrinter printer) {
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   144
        this.printer = printer;
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   145
        formatter.setPrinter(printer);
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   146
    }
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   147
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   148
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 22449
diff changeset
   149
     * Returns the type/symbol printer used by this formatter.
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   150
     * @return type/symbol rich printer
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   151
     */
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   152
    protected RichPrinter getRichPrinter() {
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   153
        return printer;
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   154
    }
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   155
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   156
    /**
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   157
     * 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
   158
     * its subdiagnostics (if any). This preprocessing is responsible for
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   159
     * generating info corresponding to features like where clauses, name
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   160
     * simplification, etc.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   161
     *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   162
     * @param diag the diagnostic to be preprocessed
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   163
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   164
    protected void preprocessDiagnostic(JCDiagnostic diag) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   165
        for (Object o : diag.getArgs()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   166
            if (o != null) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   167
                preprocessArgument(o);
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
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   170
        if (diag.isMultiline()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   171
            for (JCDiagnostic d : diag.getSubdiagnostics())
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   172
                preprocessDiagnostic(d);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   173
        }
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
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   176
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   177
     * Preprocess a diagnostic argument. A type/symbol argument is
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   178
     * preprocessed by specialized type/symbol preprocessors.
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
     * @param arg the argument to be translated
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
    protected void preprocessArgument(Object arg) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   183
        if (arg instanceof Type) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   184
            preprocessType((Type)arg);
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
        else if (arg instanceof Symbol) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   187
            preprocessSymbol((Symbol)arg);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   188
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   189
        else if (arg instanceof JCDiagnostic) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   190
            preprocessDiagnostic((JCDiagnostic)arg);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   191
        }
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   192
        else if (arg instanceof Iterable<?> && !(arg instanceof Path)) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   193
            for (Object o : (Iterable<?>)arg) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   194
                preprocessArgument(o);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   195
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   196
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   197
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   198
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   199
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   200
     * 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
   201
     * type-variables, captured types, and intersection types
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
     * @return where clause list
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   204
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   205
    protected List<JCDiagnostic> getWhereClauses() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   206
        List<JCDiagnostic> clauses = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   207
        for (WhereClauseKind kind : WhereClauseKind.values()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   208
            List<JCDiagnostic> lines = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   209
            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
   210
                lines = lines.prepend(entry.getValue());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   211
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   212
            if (!lines.isEmpty()) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   213
                String key = kind.key();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   214
                if (lines.size() > 1)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   215
                    key += ".1";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   216
                JCDiagnostic d = diags.fragment(key, whereClauses.get(kind).keySet());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   217
                d = new JCDiagnostic.MultilineDiagnostic(d, lines.reverse());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   218
                clauses = clauses.prepend(d);
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
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   221
        return clauses.reverse();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   222
    }
3540
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   223
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   224
    private int indexOf(Type type, WhereClauseKind kind) {
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   225
        int index = 1;
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   226
        for (Type t : whereClauses.get(kind).keySet()) {
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   227
            if (t.tsym == type.tsym) {
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   228
                return index;
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   229
            }
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   230
            if (kind != WhereClauseKind.TYPEVAR ||
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   231
                    t.toString().equals(type.toString())) {
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   232
                index++;
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   233
            }
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   234
        }
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   235
        return -1;
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   236
    }
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   237
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   238
    private boolean unique(TypeVar typevar) {
35348
95a9b9409b50 8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents: 34752
diff changeset
   239
        typevar = (TypeVar) typevar.stripMetadata();
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27852
diff changeset
   240
3540
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   241
        int found = 0;
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   242
        for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) {
35348
95a9b9409b50 8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents: 34752
diff changeset
   243
            if (t.stripMetadata().toString().equals(typevar.toString())) {
3540
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   244
                found++;
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   245
            }
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   246
        }
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   247
        if (found < 1)
35348
95a9b9409b50 8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents: 34752
diff changeset
   248
            throw new AssertionError("Missing type variable in where clause: " + typevar);
3540
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   249
        return found == 1;
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   250
    }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   251
    //where
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   252
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   253
     * 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
   254
     * 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
   255
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   256
    enum WhereClauseKind {
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
        /** where clause regarding a type variable */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   259
        TYPEVAR("where.description.typevar"),
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   260
        /** where clause regarding a captured type */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   261
        CAPTURED("where.description.captured"),
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   262
        /** where clause regarding an intersection type */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   263
        INTERSECTION("where.description.intersection");
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   264
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   265
        /** resource key for this where clause kind */
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 14547
diff changeset
   266
        private final String key;
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   267
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   268
        WhereClauseKind(String key) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   269
            this.key = key;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   270
        }
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
        String key() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   273
            return key;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   274
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   275
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   276
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   277
    // <editor-fold defaultstate="collapsed" desc="name simplifier">
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   278
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   279
     * 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
   280
     * 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
   281
     * 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
   282
     * 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
   283
     * 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
   284
     */
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   285
    protected class ClassNameSimplifier {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   286
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   287
        /* table for keeping track of all short name usages */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18900
diff changeset
   288
        Map<Name, List<Symbol>> nameClashes = new HashMap<>();
2984
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
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   291
         * 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
   292
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   293
        protected void addUsage(Symbol sym) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   294
            Name n = sym.getSimpleName();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   295
            List<Symbol> conflicts = nameClashes.get(n);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   296
            if (conflicts == null) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   297
                conflicts = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   298
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   299
            if (!conflicts.contains(sym))
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   300
                nameClashes.put(n, conflicts.append(sym));
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
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   303
        public String simplify(Symbol s) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   304
            String name = s.getQualifiedName().toString();
15361
01f1828683e6 8005299: Add FunctionalInterface checking to javac
mcimadamore
parents: 14801
diff changeset
   305
            if (!s.type.isCompound() && !s.type.isPrimitive()) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   306
                List<Symbol> conflicts = nameClashes.get(s.getSimpleName());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   307
                if (conflicts == null ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   308
                    (conflicts.size() == 1 &&
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   309
                    conflicts.contains(s))) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   310
                    List<Name> l = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   311
                    Symbol s2 = s;
18900
5ed5dd2ee5fe 8017618: NullPointerException in RichDiagnosticFormatter for bad input program
mcimadamore
parents: 18006
diff changeset
   312
                    while (s2.type.hasTag(CLASS) &&
5ed5dd2ee5fe 8017618: NullPointerException in RichDiagnosticFormatter for bad input program
mcimadamore
parents: 18006
diff changeset
   313
                            s2.type.getEnclosingType().hasTag(CLASS) &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   314
                            s2.owner.kind == TYP) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   315
                        l = l.prepend(s2.getSimpleName());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   316
                        s2 = s2.owner;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   317
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   318
                    l = l.prepend(s2.getSimpleName());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   319
                    StringBuilder buf = new StringBuilder();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   320
                    String sep = "";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   321
                    for (Name n2 : l) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   322
                        buf.append(sep);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   323
                        buf.append(n2);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   324
                        sep = ".";
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
                    name = buf.toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   327
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   328
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   329
            return name;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   330
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18900
diff changeset
   331
    }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   332
    // </editor-fold>
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
    // <editor-fold defaultstate="collapsed" desc="rich printer">
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   335
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   336
     * 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
   337
     * 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
   338
     * 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
   339
     * 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
   340
     */
3145
5300990c95bd 6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents: 2984
diff changeset
   341
    protected class RichPrinter extends Printer {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   342
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   343
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   344
        public String localize(Locale locale, String key, Object... args) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   345
            return formatter.localize(locale, key, args);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   346
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   347
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   348
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   349
        public String capturedVarId(CapturedType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   350
            return indexOf(t, WhereClauseKind.CAPTURED) + "";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   351
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   352
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   353
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   354
        public String visitType(Type t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   355
            String s = super.visitType(t, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   356
            if (t == syms.botType)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   357
                s = localize(locale, "compiler.misc.type.null");
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   358
            return s;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   359
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   360
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   361
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   362
        public String visitCapturedType(CapturedType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   363
            if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   364
                return localize(locale,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   365
                    "compiler.misc.captured.type",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   366
                    indexOf(t, WhereClauseKind.CAPTURED));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   367
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   368
            else
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   369
                return super.visitCapturedType(t, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   370
        }
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
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   373
        public String visitClassType(ClassType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   374
            if (t.isCompound() &&
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   375
                    getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   376
                return localize(locale,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   377
                        "compiler.misc.intersection.type",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   378
                        indexOf(t, WhereClauseKind.INTERSECTION));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   379
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   380
            else
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   381
                return super.visitClassType(t, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   382
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   383
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   384
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   385
        protected String className(ClassType t, boolean longform, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   386
            Symbol sym = t.tsym;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   387
            if (sym.name.length() == 0 ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   388
                    !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   389
                return super.className(t, longform, locale);
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
            else if (longform)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   392
                return nameSimplifier.simplify(sym).toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   393
            else
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   394
                return sym.name.toString();
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
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   397
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   398
        public String visitTypeVar(TypeVar t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   399
            if (unique(t) ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   400
                    !getConfiguration().isEnabled(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   401
                return t.toString();
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 localize(locale,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   405
                        "compiler.misc.type.var",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   406
                        t.toString(), indexOf(t, WhereClauseKind.TYPEVAR));
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
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   409
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   410
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   411
        public String visitClassSymbol(ClassSymbol s, Locale locale) {
16809
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16568
diff changeset
   412
            if (s.type.isCompound()) {
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16568
diff changeset
   413
                return visit(s.type, locale);
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16568
diff changeset
   414
            }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   415
            String name = nameSimplifier.simplify(s);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   416
            if (name.length() == 0 ||
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   417
                    !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   418
                return super.visitClassSymbol(s, locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   419
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   420
            else {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   421
                return name;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   422
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   423
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   424
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   425
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   426
        public String visitMethodSymbol(MethodSymbol s, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   427
            String ownerName = visit(s.owner, locale);
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 5847
diff changeset
   428
            if (s.isStaticOrInstanceInit()) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   429
               return ownerName;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   430
            } else {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   431
                String ms = (s.name == s.name.table.names.init)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   432
                    ? ownerName
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   433
                    : s.name.toString();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   434
                if (s.type != null) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14058
diff changeset
   435
                    if (s.type.hasTag(FORALL)) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   436
                        ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   437
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   438
                    ms += "(" + printMethodArgs(
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   439
                            s.type.getParameterTypes(),
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   440
                            (s.flags() & VARARGS) != 0,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   441
                            locale) + ")";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   442
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   443
                return ms;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   444
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   445
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18900
diff changeset
   446
    }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   447
    // </editor-fold>
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
    // <editor-fold defaultstate="collapsed" desc="type scanner">
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   450
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   451
     * 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
   452
     * 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
   453
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   454
    protected void preprocessType(Type t) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   455
        typePreprocessor.visit(t);
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
    //where
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   458
    protected Types.UnaryVisitor<Void> typePreprocessor =
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   459
            new Types.UnaryVisitor<Void>() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   460
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   461
        public Void visit(List<Type> ts) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   462
            for (Type t : ts)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   463
                visit(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   464
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   465
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   466
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   467
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   468
        public Void visitForAll(ForAll t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   469
            visit(t.tvars);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   470
            visit(t.qtype);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   471
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   472
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   473
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   474
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   475
        public Void visitMethodType(MethodType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   476
            visit(t.argtypes);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   477
            visit(t.restype);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   478
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   479
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   480
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   481
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   482
        public Void visitErrorType(ErrorType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   483
            Type ot = t.getOriginalType();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   484
            if (ot != null)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   485
                visit(ot);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   486
            return null;
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
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   489
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   490
        public Void visitArrayType(ArrayType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   491
            visit(t.elemtype);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   492
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   493
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   494
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   495
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   496
        public Void visitWildcardType(WildcardType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   497
            visit(t.type);
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
        public Void visitType(Type t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   502
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   503
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   504
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   505
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   506
        public Void visitCapturedType(CapturedType t, Void ignored) {
3540
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   507
            if (indexOf(t, WhereClauseKind.CAPTURED) == -1) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   508
                String suffix = t.lower == syms.botType ? ".1" : "";
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   509
                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
   510
                whereClauses.get(WhereClauseKind.CAPTURED).put(t, d);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   511
                visit(t.wildcard);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   512
                visit(t.lower);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   513
                visit(t.bound);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   514
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   515
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   516
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   517
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   518
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   519
        public Void visitClassType(ClassType t, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   520
            if (t.isCompound()) {
3540
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   521
                if (indexOf(t, WhereClauseKind.INTERSECTION) == -1) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   522
                    Type supertype = types.supertype(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   523
                    List<Type> interfaces = types.interfaces(t);
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 42828
diff changeset
   524
                    JCDiagnostic d = diags.fragment(Fragments.WhereIntersection(t, interfaces.prepend(supertype)));
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   525
                    whereClauses.get(WhereClauseKind.INTERSECTION).put(t, d);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   526
                    visit(supertype);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   527
                    visit(interfaces);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   528
                }
16568
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   529
            } else if (t.tsym.name.isEmpty()) {
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   530
                //anon class
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   531
                ClassType norm = (ClassType) t.tsym.type;
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   532
                if (norm != null) {
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   533
                    if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   534
                        visit(norm.interfaces_field.head);
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   535
                    } else {
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   536
                        visit(norm.supertype_field);
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   537
                    }
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   538
                }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   539
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   540
            nameSimplifier.addUsage(t.tsym);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   541
            visit(t.getTypeArguments());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   542
            if (t.getEnclosingType() != Type.noType)
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   543
                visit(t.getEnclosingType());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   544
            return null;
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
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   547
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   548
        public Void visitTypeVar(TypeVar t, Void ignored) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27852
diff changeset
   549
            t = (TypeVar)t.stripMetadataIfNeeded();
3540
dceac8629a56 6862608: rich diagnostic sometimes contain wrong type variable numbering
mcimadamore
parents: 3380
diff changeset
   550
            if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) {
3541
46fcb9a809a6 6864382: NPE in the rich formatter when processing an unattributed type-variable
mcimadamore
parents: 3540
diff changeset
   551
                //access the bound type and skip error types
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   552
                Type bound = t.bound;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   553
                while ((bound instanceof ErrorType))
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   554
                    bound = ((ErrorType)bound).getOriginalType();
3541
46fcb9a809a6 6864382: NPE in the rich formatter when processing an unattributed type-variable
mcimadamore
parents: 3540
diff changeset
   555
                //retrieve the bound list - if the type variable
46fcb9a809a6 6864382: NPE in the rich formatter when processing an unattributed type-variable
mcimadamore
parents: 3540
diff changeset
   556
                //has not been attributed the bound is not set
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14359
diff changeset
   557
                List<Type> bounds = (bound != null) &&
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14359
diff changeset
   558
                        (bound.hasTag(CLASS) || bound.hasTag(TYPEVAR)) ?
3541
46fcb9a809a6 6864382: NPE in the rich formatter when processing an unattributed type-variable
mcimadamore
parents: 3540
diff changeset
   559
                    types.getBounds(t) :
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 39812
diff changeset
   560
                    List.nil();
3541
46fcb9a809a6 6864382: NPE in the rich formatter when processing an unattributed type-variable
mcimadamore
parents: 3540
diff changeset
   561
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   562
                nameSimplifier.addUsage(t.tsym);
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
                boolean boundErroneous = bounds.head == null ||
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14058
diff changeset
   565
                                         bounds.head.hasTag(NONE) ||
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14058
diff changeset
   566
                                         bounds.head.hasTag(ERROR);
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   567
12468
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   568
                if ((t.tsym.flags() & SYNTHETIC) == 0) {
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   569
                    //this is a true typevar
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   570
                    JCDiagnostic d = diags.fragment("where.typevar" +
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   571
                        (boundErroneous ? ".1" : ""), t, bounds,
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   572
                        kindName(t.tsym.location()), t.tsym.location());
12468
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   573
                    whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   574
                    symbolPreprocessor.visit(t.tsym.location(), null);
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   575
                    visit(bounds);
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   576
                } else {
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   577
                    Assert.check(!boundErroneous);
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   578
                    //this is a fresh (synthetic) tvar
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 42828
diff changeset
   579
                    JCDiagnostic d = diags.fragment(Fragments.WhereFreshTypevar(t, bounds));
12468
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   580
                    whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   581
                    visit(bounds);
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   582
                }
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 10626
diff changeset
   583
2984
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
            return null;
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
    };
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   588
    // </editor-fold>
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   589
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   590
    // <editor-fold defaultstate="collapsed" desc="symbol scanner">
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
     * Preprocess a given symbol looking for (i) additional info (where clauses) to be
16568
695eacfe0f41 8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
mcimadamore
parents: 15725
diff changeset
   593
     * added to the main diagnostic (ii) names to be compacted
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   594
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   595
    protected void preprocessSymbol(Symbol s) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   596
        symbolPreprocessor.visit(s, null);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   597
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   598
    //where
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   599
    protected Types.DefaultSymbolVisitor<Void, Void> symbolPreprocessor =
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   600
            new Types.DefaultSymbolVisitor<Void, Void>() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   601
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   602
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   603
        public Void visitClassSymbol(ClassSymbol s, Void ignored) {
16809
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16568
diff changeset
   604
            if (s.type.isCompound()) {
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16568
diff changeset
   605
                typePreprocessor.visit(s.type);
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16568
diff changeset
   606
            } else {
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16568
diff changeset
   607
                nameSimplifier.addUsage(s);
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16568
diff changeset
   608
            }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   609
            return null;
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
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   612
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   613
        public Void visitSymbol(Symbol s, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   614
            return null;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   615
        }
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
        @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   618
        public Void visitMethodSymbol(MethodSymbol s, Void ignored) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   619
            visit(s.owner, null);
3373
d62556aed18c 6860795: NullPointerException when compiling a negative java source
mcimadamore
parents: 3145
diff changeset
   620
            if (s.type != null)
d62556aed18c 6860795: NullPointerException when compiling a negative java source
mcimadamore
parents: 3145
diff changeset
   621
                typePreprocessor.visit(s.type);
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   622
            return null;
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
    // </editor-fold>
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   626
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   627
    @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   628
    public RichConfiguration getConfiguration() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   629
        //the following cast is always safe - see init
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   630
        return (RichConfiguration)configuration;
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
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   634
     * Configuration object provided by the rich formatter.
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 static class RichConfiguration extends ForwardingDiagnosticFormatter.ForwardingConfiguration {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   637
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   638
        /** set of enabled rich formatter's features */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   639
        protected java.util.EnumSet<RichFormatterFeature> features;
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
        @SuppressWarnings("fallthrough")
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   642
        public RichConfiguration(Options options, AbstractDiagnosticFormatter formatter) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   643
            super(formatter.getConfiguration());
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   644
            features = formatter.isRaw() ? EnumSet.noneOf(RichFormatterFeature.class) :
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   645
                EnumSet.of(RichFormatterFeature.SIMPLE_NAMES,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   646
                    RichFormatterFeature.WHERE_CLAUSES,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   647
                    RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
39812
6272642715a1 8161019: javac, fold formatter options
vromero
parents: 35348
diff changeset
   648
            String diagOpts = options.get("diags.formatterOptions");
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   649
            if (diagOpts != null) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   650
                for (String args: diagOpts.split(",")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   651
                    if (args.equals("-where")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   652
                        features.remove(RichFormatterFeature.WHERE_CLAUSES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   653
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   654
                    else if (args.equals("where")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   655
                        features.add(RichFormatterFeature.WHERE_CLAUSES);
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
                    if (args.equals("-simpleNames")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   658
                        features.remove(RichFormatterFeature.SIMPLE_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   659
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   660
                    else if (args.equals("simpleNames")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   661
                        features.add(RichFormatterFeature.SIMPLE_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   662
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   663
                    if (args.equals("-disambiguateTvars")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   664
                        features.remove(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   665
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   666
                    else if (args.equals("disambiguateTvars")) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   667
                        features.add(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   668
                    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   669
                }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   670
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   671
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   672
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   673
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   674
         * 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
   675
         * @return list of supported features
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   676
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   677
        public RichFormatterFeature[] getAvailableFeatures() {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   678
            return RichFormatterFeature.values();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   679
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   680
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   681
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   682
         * Enable a specific feature on this rich formatter.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   683
         * @param feature feature to be enabled
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   684
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   685
        public void enable(RichFormatterFeature feature) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   686
            features.add(feature);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   687
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   688
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   689
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   690
         * Disable a specific feature on this rich formatter.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   691
         * @param feature feature to be disabled
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   692
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   693
        public void disable(RichFormatterFeature feature) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   694
            features.remove(feature);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   695
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   696
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   697
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   698
         * Is a given feature enabled on this formatter?
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   699
         * @param feature feature to be tested
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   700
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   701
        public boolean isEnabled(RichFormatterFeature feature) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   702
            return features.contains(feature);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   703
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   704
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   705
        /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   706
         * The advanced formatting features provided by the rich formatter
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   707
         */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   708
        public enum RichFormatterFeature {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   709
            /** 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
   710
            WHERE_CLAUSES,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   711
            /** full class names simplification (where possible) */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   712
            SIMPLE_NAMES,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   713
            /** type-variable names disambiguation */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18900
diff changeset
   714
            UNIQUE_TYPEVAR_NAMES
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   715
        }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   716
    }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
diff changeset
   717
}