author | mcimadamore |
Tue, 25 Oct 2011 15:40:34 +0100 | |
changeset 10817 | d91978895fac |
parent 10638 | c8e9604cf151 |
child 11053 | 48713f779b1d |
permissions | -rw-r--r-- |
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 | 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 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
108 |
JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
109 |
Context c = t.getContext(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
110 |
ArgTypeMessages.preRegister(c); |
8614 | 111 |
ArgTypeJavaCompiler.preRegister(c); |
8226
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
112 |
Boolean ok = t.call(); |
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 |
return ok; |
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 |
|
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 |
* 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
|
120 |
*/ |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
121 |
static class SimpleCompiler extends Example.Compiler { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
122 |
SimpleCompiler(boolean verbose) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
123 |
super(verbose); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
124 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
125 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
126 |
@Override |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
127 |
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
|
128 |
assert out != null && keys == null; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
129 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
130 |
if (verbose) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
131 |
System.err.println("run_simple: " + opts + " " + files); |
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 |
List<String> args = new ArrayList<String>(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
134 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
135 |
args.addAll(opts); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
136 |
for (File f: files) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
137 |
args.add(f.getPath()); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
138 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
139 |
Main main = new Main("javac", out); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
140 |
Context c = new Context() { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
141 |
@Override public void clear() { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
142 |
((JavacFileManager) get(JavaFileManager.class)).close(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
143 |
super.clear(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
144 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
145 |
}; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
146 |
JavacFileManager.preRegister(c); // can't create it until Log has been set up |
8614 | 147 |
ArgTypeJavaCompiler.preRegister(c); |
8226
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
148 |
ArgTypeMessages.preRegister(c); |
10638 | 149 |
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
|
150 |
|
10638 | 151 |
return result.isOK(); |
8226
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 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
154 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
155 |
static class BackdoorCompiler extends Example.Compiler { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
156 |
BackdoorCompiler(boolean verbose) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
157 |
super(verbose); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
158 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
159 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
160 |
@Override |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
161 |
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
|
162 |
assert out != null && keys == null; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
163 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
164 |
if (verbose) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
165 |
System.err.println("run_simple: " + opts + " " + files); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
166 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
167 |
List<String> args = new ArrayList<String>(opts); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
168 |
for (File f: files) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
169 |
args.add(f.getPath()); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
170 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
171 |
Context c = new Context(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
172 |
JavacFileManager.preRegister(c); // can't create it until Log has been set up |
8614 | 173 |
ArgTypeJavaCompiler.preRegister(c); |
8226
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
174 |
ArgTypeMessages.preRegister(c); |
10638 | 175 |
Main m = new Main("javac", out); |
176 |
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
|
177 |
|
10638 | 178 |
return result.isOK(); |
8226
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 |
|
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 |
// <editor-fold defaultstate="collapsed" desc="Custom Javac components"> |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
185 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
186 |
/** |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
187 |
* 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
|
188 |
* 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
|
189 |
* arg types. |
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 |
static class ArgTypeDiagnosticFormatter extends AbstractDiagnosticFormatter { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
192 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
193 |
ArgTypeDiagnosticFormatter(Options options) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
194 |
super(null, new SimpleConfiguration(options, |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
195 |
EnumSet.of(DiagnosticPart.SUMMARY, |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
196 |
DiagnosticPart.DETAILS, |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
197 |
DiagnosticPart.SUBDIAGNOSTICS))); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
198 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
199 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
200 |
@Override |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
201 |
protected String formatDiagnostic(JCDiagnostic d, Locale locale) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
202 |
return formatMessage(d, locale); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
203 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
204 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
205 |
@Override |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
206 |
public String formatMessage(JCDiagnostic d, Locale l) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
207 |
StringBuilder buf = new StringBuilder(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
208 |
formatMessage(d, buf); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
209 |
return buf.toString(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
210 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
211 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
212 |
private void formatMessage(JCDiagnostic d, StringBuilder buf) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
213 |
String key = d.getCode(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
214 |
Object[] args = d.getArgs(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
215 |
// 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
|
216 |
buf.append(getKeyArgsString(key, args)); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
217 |
// report details for any diagnostic fragments |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
218 |
for (Object arg: args) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
219 |
if (arg instanceof JCDiagnostic) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
220 |
buf.append("\n"); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
221 |
formatMessage((JCDiagnostic) arg, buf); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
222 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
223 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
224 |
// report details for any subdiagnostics |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
225 |
for (String s: formatSubdiagnostics(d, null)) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
226 |
buf.append("\n"); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
227 |
buf.append(s); |
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 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
230 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
231 |
@Override |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
232 |
public boolean isRaw() { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
233 |
return true; |
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 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
236 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
237 |
/** |
8614 | 238 |
* Trivial subtype of JavaCompiler to get access to the protected compilerKey field. |
239 |
* The factory is used to ensure that the log is initialized with an instance of |
|
240 |
* ArgTypeDiagnosticFormatter before we create the required JavaCompiler. |
|
241 |
*/ |
|
242 |
static class ArgTypeJavaCompiler extends JavaCompiler { |
|
243 |
static void preRegister(Context context) { |
|
244 |
context.put(compilerKey, new Context.Factory<JavaCompiler>() { |
|
245 |
public JavaCompiler make(Context c) { |
|
246 |
Log log = Log.instance(c); |
|
247 |
Options options = Options.instance(c); |
|
248 |
log.setDiagnosticFormatter(new ArgTypeDiagnosticFormatter(options)); |
|
249 |
return new JavaCompiler(c); |
|
250 |
} |
|
251 |
}); |
|
252 |
} |
|
253 |
||
254 |
// not used |
|
255 |
private ArgTypeJavaCompiler() { |
|
256 |
super(null); |
|
257 |
} |
|
258 |
} |
|
259 |
||
260 |
/** |
|
8226
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
261 |
* 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
|
262 |
* 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
|
263 |
* arg types. |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
264 |
*/ |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
265 |
static class ArgTypeMessages extends JavacMessages { |
8614 | 266 |
static void preRegister(Context context) { |
267 |
context.put(JavacMessages.messagesKey, new Context.Factory<JavacMessages>() { |
|
268 |
public JavacMessages make(Context c) { |
|
8226
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
269 |
return new ArgTypeMessages(c) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
270 |
@Override |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
271 |
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
|
272 |
return getKeyArgsString(key, args); |
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 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
278 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
279 |
ArgTypeMessages(Context context) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
280 |
super(context); |
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 |
|
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 |
* 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
|
286 |
*/ |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
287 |
static String getKeyArgsString(String key, Object... args) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
288 |
StringBuilder buf = new StringBuilder(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
289 |
buf.append(key); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
290 |
String sep = ": "; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
291 |
for (Object o : args) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
292 |
buf.append(sep); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
293 |
buf.append(getArgTypeOrStringValue(o)); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
294 |
sep = ", "; |
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 |
return buf.toString(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
297 |
} |
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 boolean showStringValues = false; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
300 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
301 |
static String getArgTypeOrStringValue(Object o) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
302 |
if (showStringValues && o instanceof String) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
303 |
return "\"" + o + "\""; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
304 |
return getArgType(o); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
305 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
306 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
307 |
static String getArgType(Object o) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
308 |
if (o == null) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
309 |
return "null"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
310 |
if (o instanceof Name) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
311 |
return "name"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
312 |
if (o instanceof Boolean) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
313 |
return "boolean"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
314 |
if (o instanceof Integer) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
315 |
return "number"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
316 |
if (o instanceof String) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
317 |
return "string"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
318 |
if (o instanceof Flag) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
319 |
return "modifier"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
320 |
if (o instanceof KindName) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
321 |
return "symbol kind"; |
10817
d91978895fac
7104618: MessageInfo.java is failing after lexer changes
mcimadamore
parents:
10638
diff
changeset
|
322 |
if (o instanceof TokenKind) |
8226
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
323 |
return "token"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
324 |
if (o instanceof Symbol) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
325 |
return "symbol"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
326 |
if (o instanceof Type) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
327 |
return "type"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
328 |
if (o instanceof List) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
329 |
List<?> l = (List<?>) o; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
330 |
if (l.isEmpty()) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
331 |
return "list"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
332 |
else |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
333 |
return "list of " + getArgType(l.get(0)); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
334 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
335 |
if (o instanceof ListBuffer) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
336 |
return getArgType(((ListBuffer) o).toList()); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
337 |
if (o instanceof Set) { |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
338 |
Set<?> s = (Set<?>) o; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
339 |
if (s.isEmpty()) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
340 |
return "set"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
341 |
else |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
342 |
return "set of " + getArgType(s.iterator().next()); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
343 |
} |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
344 |
if (o instanceof SourceVersion) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
345 |
return "source version"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
346 |
if (o instanceof FileObject || o instanceof File) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
347 |
return "file name"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
348 |
if (o instanceof JCDiagnostic) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
349 |
return "message segment"; |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
350 |
if (o instanceof LocalizedString) |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
351 |
return "message segment"; // only instance is "no arguments" |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
352 |
String s = o.getClass().getSimpleName(); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
353 |
return (s.isEmpty() ? o.getClass().getName() : s); |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
354 |
} |
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 |
// </editor-fold> |
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
357 |
|
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff
changeset
|
358 |
} |