author | jjg |
Fri, 30 Aug 2013 15:14:51 -0700 | |
changeset 19908 | c48205ab5654 |
parent 5520 | 86e4b9a9da40 |
child 26264 | a09fedde76be |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6457284 |
|
27 |
* @summary Internationalize "unnamed package" when the term is used in diagnostics |
|
28 |
* @author Peter von der Ah\u00e9 |
|
29 |
*/ |
|
30 |
||
31 |
import java.io.IOException; |
|
32 |
import java.net.URI; |
|
33 |
import javax.lang.model.element.Element; |
|
34 |
||
35 |
import com.sun.tools.javac.api.JavacTaskImpl; |
|
36 |
import com.sun.tools.javac.util.Context; |
|
37 |
import com.sun.tools.javac.util.List; |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
10
diff
changeset
|
38 |
import com.sun.tools.javac.util.JavacMessages; |
10 | 39 |
|
40 |
import javax.tools.*; |
|
41 |
||
42 |
public class T6457284 { |
|
43 |
static class MyFileObject extends SimpleJavaFileObject { |
|
44 |
public MyFileObject() { |
|
45 |
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
|
46 |
} |
|
47 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
|
48 |
return "class Test {}"; |
|
49 |
} |
|
50 |
} |
|
51 |
public static void main(String[] args) throws IOException { |
|
52 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
|
53 |
JavacTaskImpl task = (JavacTaskImpl)compiler.getTask(null, null, null, null, null, |
|
54 |
List.of(new MyFileObject())); |
|
55 |
MyMessages.preRegister(task.getContext()); |
|
56 |
task.parse(); |
|
57 |
for (Element e : task.analyze()) { |
|
58 |
if (!e.getEnclosingElement().toString().equals("compiler.misc.unnamed.package")) |
|
59 |
throw new AssertionError(e.getEnclosingElement()); |
|
60 |
System.out.println("OK: " + e.getEnclosingElement()); |
|
61 |
return; |
|
62 |
} |
|
63 |
throw new AssertionError("No top-level classes!"); |
|
64 |
} |
|
65 |
||
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
10
diff
changeset
|
66 |
static class MyMessages extends JavacMessages { |
10 | 67 |
static void preRegister(Context context) { |
68 |
context.put(messagesKey, new MyMessages()); |
|
69 |
} |
|
70 |
MyMessages() { |
|
71 |
super("com.sun.tools.javac.resources.compiler"); |
|
72 |
} |
|
73 |
public String getLocalizedString(String key, Object... args) { |
|
74 |
if (key.equals("compiler.misc.unnamed.package")) |
|
75 |
return key; |
|
76 |
else |
|
77 |
return super.getLocalizedString(key, args); |
|
78 |
} |
|
79 |
} |
|
80 |
} |