135N/A/*
1451N/A * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
135N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
135N/A *
135N/A * This code is free software; you can redistribute it and/or modify it
135N/A * under the terms of the GNU General Public License version 2 only, as
135N/A * published by the Free Software Foundation.
135N/A *
135N/A * This code is distributed in the hope that it will be useful, but WITHOUT
135N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
135N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
135N/A * version 2 for more details (a copy is included in the LICENSE file that
135N/A * accompanied this code).
135N/A *
135N/A * You should have received a copy of the GNU General Public License version
135N/A * 2 along with this work; if not, write to the Free Software Foundation,
135N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
135N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
135N/A */
135N/A
135N/A/*
135N/A * @test
135N/A * @bug 6443132 6406133 6597678
135N/A * @summary Compiler API ignores locale settings
135N/A * @author Maurizio Cimadamore
135N/A * @library ../lib
1451N/A * @build ToolTester
1451N/A * @run main T6406133
135N/A */
135N/A
135N/Aimport javax.tools.*;
135N/Aimport javax.annotation.processing.*;
135N/Aimport javax.lang.model.element.*;
135N/Aimport java.util.*;
135N/Aimport java.io.*;
135N/A
135N/Apublic class T6406133 extends ToolTester {
135N/A
135N/A List<Locale> locales = Arrays.asList(Locale.US, Locale.JAPAN, Locale.CHINA);
135N/A
135N/A class DiagnosticTester implements DiagnosticListener<JavaFileObject> {
135N/A Locale locale;
135N/A String result;
135N/A
135N/A DiagnosticTester(Locale locale) {
135N/A this.locale = locale;
135N/A }
135N/A public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
135N/A result = diagnostic.getMessage(locale); //6406133
135N/A }
135N/A }
135N/A
135N/A class ProcessorTester extends AbstractProcessor {
135N/A
135N/A Locale locale;
135N/A
135N/A public Set<String> getSupportedAnnotationTypes() {
135N/A return new HashSet<String>(Arrays.asList("*"));
135N/A }
135N/A
135N/A public void init(ProcessingEnvironment env) {
135N/A locale = env.getLocale();
135N/A }
135N/A
135N/A public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
135N/A return true;
135N/A }
135N/A }
135N/A
135N/A void compare(Locale loc1, Locale loc2, boolean useListener) {
135N/A String res1 = exec(useListener, loc1);
135N/A String res2 = exec(useListener, loc2);
135N/A boolean success = (loc1.equals(loc2) && res1.equals(res2)) ||
135N/A (!loc1.equals(loc2) && !res1.equals(res2));
135N/A if (!success)
135N/A throw new AssertionError("Error in diagnostic localization");
135N/A }
135N/A
135N/A String exec(boolean useListener, Locale locale) {
135N/A final Iterable<? extends JavaFileObject> compilationUnits =
135N/A fm.getJavaFileObjects(new File(test_src, "Erroneous.java"));
135N/A StringWriter pw = new StringWriter();
135N/A DiagnosticTester listener = useListener ? new DiagnosticTester(locale) : null;
135N/A ProcessorTester processor = new ProcessorTester();
135N/A task = tool.getTask(pw, fm, listener, null, null, compilationUnits);
135N/A task.setProcessors(Arrays.asList(processor));
135N/A task.setLocale(locale); //6443132
135N/A task.call();
135N/A if (!processor.locale.equals(locale))
135N/A throw new AssertionError("Error in diagnostic localization during annotation processing");
135N/A String res = useListener ? listener.result : pw.toString();
135N/A System.err.println("[locale:"+ locale + ", listener:" + useListener + "] " +res);
135N/A return res;
135N/A }
135N/A
135N/A void test() {
135N/A for (Locale l1 : locales) {
135N/A for (Locale l2 : locales) {
135N/A compare(l1, l2, true);
135N/A compare(l1, l2, false);
135N/A }
135N/A }
135N/A }
135N/A
135N/A public static void main(String... args) throws Exception {
135N/A new T6406133().test();
135N/A }
135N/A}