langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java
author jjg
Tue, 08 Nov 2011 17:06:58 -0800
changeset 11053 48713f779b1d
parent 10817 d91978895fac
child 23810 b92eb80925f0
permissions -rw-r--r--
7108669: cleanup Log methods for direct printing to streams Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     1
/*
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     4
 *
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     8
 *
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    13
 * accompanied this code).
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    14
 *
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    18
 *
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    21
 * questions.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    22
 */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    23
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    24
import java.io.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    25
import java.util.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    26
import java.util.List;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    27
import javax.tools.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    28
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    29
import com.sun.tools.javac.api.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    30
import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    31
import com.sun.tools.javac.api.Formattable.LocalizedString;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    32
import com.sun.tools.javac.code.Flags.Flag;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    33
import com.sun.tools.javac.code.Kinds.KindName;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.code.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    35
import com.sun.tools.javac.file.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    36
import com.sun.tools.javac.main.Main;
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
    37
import com.sun.tools.javac.main.JavaCompiler;
10817
d91978895fac 7104618: MessageInfo.java is failing after lexer changes
mcimadamore
parents: 10638
diff changeset
    38
import com.sun.tools.javac.parser.Tokens.TokenKind;
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    39
import com.sun.tools.javac.util.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    40
import com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    41
import javax.lang.model.SourceVersion;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    42
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    43
/**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    44
 * Compiler factory for instances of Example.Compiler that use custom
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    45
 * DiagnosticFormatter and Messages objects to track the types of args
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    46
 * when when localizing diagnostics.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    47
 * The compiler objects only support "output" mode, not "check" mode.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    48
 */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    49
class ArgTypeCompilerFactory implements Example.Compiler.Factory {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    50
    // Same code as Example.Compiler.DefaultFactory, but the names resolve differently
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    51
    public Example.Compiler getCompiler(List<String> opts, boolean verbose) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    52
        String first;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    53
        String[] rest;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    54
        if (opts == null || opts.isEmpty()) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    55
            first = null;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    56
            rest = new String[0];
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    57
        } else {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    58
            first = opts.get(0);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    59
            rest = opts.subList(1, opts.size()).toArray(new String[opts.size() - 1]);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    60
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    61
        if (first == null || first.equals("jsr199"))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    62
            return new Jsr199Compiler(verbose, rest);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    63
        else if (first.equals("simple"))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    64
            return new SimpleCompiler(verbose);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    65
        else if (first.equals("backdoor"))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    66
            return new BackdoorCompiler(verbose);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    67
        else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    68
            throw new IllegalArgumentException(first);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    69
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    70
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    71
    /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    72
     * Compile using the JSR 199 API.  The diagnostics generated are
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    73
     * scanned for resource keys.   Not all diagnostic keys are generated
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    74
     * via the JSR 199 API -- for example, rich diagnostics are not directly
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    75
     * accessible, and some diagnostics generated by the file manager may
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    76
     * not be generated (for example, the JSR 199 file manager does not see
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    77
     * -Xlint:path).
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    78
     */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    79
    static class Jsr199Compiler extends Example.Compiler {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    80
        List<String> fmOpts;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    81
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    82
        Jsr199Compiler(boolean verbose, String... args) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    83
            super(verbose);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    84
            for (int i = 0; i < args.length; i++) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    85
                String arg = args[i];
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    86
                if (arg.equals("-filemanager") && (i + 1 < args.length)) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    87
                    fmOpts = Arrays.asList(args[++i].split(","));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    88
                } else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    89
                    throw new IllegalArgumentException(arg);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    90
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    91
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    92
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    93
        @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    94
        boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    95
            assert out != null && keys == null;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    96
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    97
            if (verbose)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    98
                System.err.println("run_jsr199: " + opts + " " + files);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    99
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   100
            JavacTool tool = JavacTool.create();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   101
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   102
            StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   103
            if (fmOpts != null)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   104
                fm = new FileManager(fm, fmOpts);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   105
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   106
            Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   107
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 10817
diff changeset
   108
            Context c = new Context();
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   109
            ArgTypeMessages.preRegister(c);
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   110
            ArgTypeJavaCompiler.preRegister(c);
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 10817
diff changeset
   111
            JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c);
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 10817
diff changeset
   112
            return t.call();
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   113
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   114
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   115
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   116
    /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   117
     * Run the test using the standard simple entry point.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   118
     */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   119
    static class SimpleCompiler extends Example.Compiler {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   120
        SimpleCompiler(boolean verbose) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   121
            super(verbose);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   122
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   123
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   124
        @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   125
        boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   126
            assert out != null && keys == null;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   127
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   128
            if (verbose)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   129
                System.err.println("run_simple: " + opts + " " + files);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   130
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   131
            List<String> args = new ArrayList<String>();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   132
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   133
            args.addAll(opts);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   134
            for (File f: files)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   135
                args.add(f.getPath());
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   136
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   137
            Main main = new Main("javac", out);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   138
            Context c = new Context() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   139
                @Override public void clear() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   140
                    ((JavacFileManager) get(JavaFileManager.class)).close();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   141
                    super.clear();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   142
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   143
            };
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   144
            JavacFileManager.preRegister(c); // can't create it until Log has been set up
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   145
            ArgTypeJavaCompiler.preRegister(c);
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   146
            ArgTypeMessages.preRegister(c);
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 8614
diff changeset
   147
            Main.Result result = main.compile(args.toArray(new String[args.size()]), c);
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   148
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 8614
diff changeset
   149
            return result.isOK();
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   150
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   151
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   152
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   153
    static class BackdoorCompiler extends Example.Compiler {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   154
        BackdoorCompiler(boolean verbose) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   155
            super(verbose);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   156
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   157
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   158
        @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   159
        boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   160
            assert out != null && keys == null;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   161
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   162
            if (verbose)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   163
                System.err.println("run_simple: " + opts + " " + files);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   164
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   165
            List<String> args = new ArrayList<String>(opts);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   166
            for (File f: files)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   167
                args.add(f.getPath());
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   168
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   169
            Context c = new Context();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   170
            JavacFileManager.preRegister(c); // can't create it until Log has been set up
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   171
            ArgTypeJavaCompiler.preRegister(c);
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   172
            ArgTypeMessages.preRegister(c);
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 8614
diff changeset
   173
            Main m = new Main("javac", out);
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 8614
diff changeset
   174
            Main.Result result = m.compile(args.toArray(new String[args.size()]), c);
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   175
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 8614
diff changeset
   176
            return result.isOK();
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   177
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   178
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   179
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   180
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   181
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   182
    // <editor-fold defaultstate="collapsed" desc="Custom Javac components">
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   183
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   184
    /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   185
     * Diagnostic formatter which reports formats a diag as a series of lines
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   186
     * containing a key, and a possibly empty set of descriptive strings for the
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   187
     * arg types.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   188
     */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   189
    static class ArgTypeDiagnosticFormatter extends AbstractDiagnosticFormatter {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   190
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   191
        ArgTypeDiagnosticFormatter(Options options) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   192
            super(null, new SimpleConfiguration(options,
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   193
                    EnumSet.of(DiagnosticPart.SUMMARY,
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   194
                    DiagnosticPart.DETAILS,
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   195
                    DiagnosticPart.SUBDIAGNOSTICS)));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   196
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   197
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   198
        @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   199
        protected String formatDiagnostic(JCDiagnostic d, Locale locale) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   200
            return formatMessage(d, locale);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   201
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   202
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   203
        @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   204
        public String formatMessage(JCDiagnostic d, Locale l) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   205
            StringBuilder buf = new StringBuilder();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   206
            formatMessage(d, buf);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   207
            return buf.toString();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   208
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   209
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   210
        private void formatMessage(JCDiagnostic d, StringBuilder buf) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   211
            String key = d.getCode();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   212
            Object[] args = d.getArgs();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   213
            // report the primary arg types, without recursing into diag fragments
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   214
            buf.append(getKeyArgsString(key, args));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   215
            // report details for any diagnostic fragments
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   216
            for (Object arg: args) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   217
                if (arg instanceof JCDiagnostic) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   218
                    buf.append("\n");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   219
                    formatMessage((JCDiagnostic) arg, buf);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   220
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   221
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   222
            // report details for any subdiagnostics
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   223
            for (String s: formatSubdiagnostics(d, null)) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   224
                buf.append("\n");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   225
                buf.append(s);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   226
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   227
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   228
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   229
        @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   230
        public boolean isRaw() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   231
            return true;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   232
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   233
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   234
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   235
    /**
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   236
     * Trivial subtype of JavaCompiler to get access to the protected compilerKey field.
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   237
     * The factory is used to ensure that the log is initialized with an instance of
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   238
     * ArgTypeDiagnosticFormatter before we create the required JavaCompiler.
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   239
     */
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   240
    static class ArgTypeJavaCompiler extends JavaCompiler {
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   241
        static void preRegister(Context context) {
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   242
            context.put(compilerKey, new Context.Factory<JavaCompiler>() {
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   243
                public JavaCompiler make(Context c) {
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   244
                    Log log = Log.instance(c);
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   245
                    Options options = Options.instance(c);
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   246
                    log.setDiagnosticFormatter(new ArgTypeDiagnosticFormatter(options));
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   247
                    return new JavaCompiler(c);
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   248
                }
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   249
            });
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   250
        }
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   251
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   252
        // not used
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   253
        private ArgTypeJavaCompiler() {
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   254
            super(null);
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   255
        }
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   256
    }
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   257
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   258
    /**
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   259
     * Diagnostic formatter which "localizes" a message as a line
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   260
     * containing a key, and a possibly empty set of descriptive strings for the
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   261
     * arg types.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   262
     */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   263
    static class ArgTypeMessages extends JavacMessages {
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   264
        static void preRegister(Context context) {
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   265
            context.put(JavacMessages.messagesKey, new Context.Factory<JavacMessages>() {
06e42328ddab 7021650: fix Context issues
jjg
parents: 8226
diff changeset
   266
                public JavacMessages make(Context c) {
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   267
                    return new ArgTypeMessages(c) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   268
                        @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   269
                        public String getLocalizedString(Locale l, String key, Object... args) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   270
                            return getKeyArgsString(key, args);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   271
                        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   272
                    };
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   273
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   274
            });
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   275
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   276
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   277
        ArgTypeMessages(Context context) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   278
            super(context);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   279
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   280
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   281
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   282
    /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   283
     * Utility method to generate a string for key and args
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   284
     */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   285
    static String getKeyArgsString(String key, Object... args) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   286
        StringBuilder buf = new StringBuilder();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   287
        buf.append(key);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   288
        String sep = ": ";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   289
        for (Object o : args) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   290
            buf.append(sep);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   291
            buf.append(getArgTypeOrStringValue(o));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   292
            sep = ", ";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   293
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   294
        return buf.toString();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   295
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   296
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   297
    static boolean showStringValues = false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   298
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   299
    static String getArgTypeOrStringValue(Object o) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   300
        if (showStringValues && o instanceof String)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   301
            return "\"" + o + "\"";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   302
        return getArgType(o);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   303
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   304
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   305
    static String getArgType(Object o) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   306
        if (o == null)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   307
            return "null";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   308
        if (o instanceof Name)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   309
            return "name";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   310
        if (o instanceof Boolean)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   311
            return "boolean";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   312
        if (o instanceof Integer)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   313
            return "number";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   314
        if (o instanceof String)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   315
            return "string";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   316
        if (o instanceof Flag)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   317
            return "modifier";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   318
        if (o instanceof KindName)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   319
            return "symbol kind";
10817
d91978895fac 7104618: MessageInfo.java is failing after lexer changes
mcimadamore
parents: 10638
diff changeset
   320
        if (o instanceof TokenKind)
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   321
            return "token";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   322
        if (o instanceof Symbol)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   323
            return "symbol";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   324
        if (o instanceof Type)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   325
            return "type";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   326
        if (o instanceof List) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   327
            List<?> l = (List<?>) o;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   328
            if (l.isEmpty())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   329
                return "list";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   330
            else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   331
                return "list of " + getArgType(l.get(0));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   332
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   333
        if (o instanceof ListBuffer)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   334
            return getArgType(((ListBuffer) o).toList());
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   335
        if (o instanceof Set) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   336
            Set<?> s = (Set<?>) o;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   337
            if (s.isEmpty())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   338
                return "set";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   339
            else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   340
                return "set of " + getArgType(s.iterator().next());
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   341
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   342
        if (o instanceof SourceVersion)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   343
            return "source version";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   344
        if (o instanceof FileObject || o instanceof File)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   345
            return "file name";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   346
        if (o instanceof JCDiagnostic)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   347
            return "message segment";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   348
        if (o instanceof LocalizedString)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   349
            return "message segment";  // only instance is "no arguments"
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   350
        String s = o.getClass().getSimpleName();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   351
        return (s.isEmpty() ? o.getClass().getName() : s);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   352
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   353
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   354
    // </editor-fold>
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   355
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   356
}