test/tools/javac/api/T6306137.java

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/api/T6306137.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,84 @@
     1.4 +/*
     1.5 + * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug     6306137
    1.30 + * @summary JSR 199: encoding option doesn't affect standard file manager
    1.31 + * @author  Peter von der Ahé
    1.32 + * @ignore
    1.33 + *    Need to make the contentCache in JavacFileManager be aware of changes to the encoding.
    1.34 + *    Need to propogate -source (and -encoding?) down to the JavacFileManager
    1.35 + */
    1.36 +
    1.37 +import java.io.File;
    1.38 +import java.util.Arrays;
    1.39 +import javax.tools.*;
    1.40 +
    1.41 +public class T6306137 {
    1.42 +    boolean error;
    1.43 +    final StandardJavaFileManager fm;
    1.44 +    final JavaCompiler compiler;
    1.45 +    Iterable<? extends JavaFileObject> files;
    1.46 +    DiagnosticListener<JavaFileObject> dl;
    1.47 +
    1.48 +    T6306137() {
    1.49 +        dl = new DiagnosticListener<JavaFileObject>() {
    1.50 +                public void report(Diagnostic<? extends JavaFileObject> message) {
    1.51 +                    if (message.getKind() == Diagnostic.Kind.ERROR)
    1.52 +                        error = true;
    1.53 +                    System.out.println(message.getSource()
    1.54 +                                       +":"+message.getStartPosition()+":"
    1.55 +                                       +message.getStartPosition()+":"+message.getPosition());
    1.56 +                    System.out.println(message.toString());
    1.57 +                    System.out.format("Found problem: %s%n", message.getCode());
    1.58 +                    System.out.flush();
    1.59 +                }
    1.60 +        };
    1.61 +        compiler = ToolProvider.getSystemJavaCompiler();
    1.62 +        fm = compiler.getStandardFileManager(dl, null, null);
    1.63 +        String srcdir = System.getProperty("test.src");
    1.64 +        files =
    1.65 +            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6306137.java")));
    1.66 +    }
    1.67 +
    1.68 +    void test(String encoding, boolean good) {
    1.69 +        error = false;
    1.70 +        Iterable<String> args = Arrays.asList("-source", "6", "-encoding", encoding, "-d", ".");
    1.71 +        compiler.getTask(null, fm, dl, args, null, files).call();
    1.72 +        if (error == good) {
    1.73 +            if (error) {
    1.74 +                throw new AssertionError("Error reported");
    1.75 +            } else {
    1.76 +                throw new AssertionError("No error reported");
    1.77 +            }
    1.78 +        }
    1.79 +    }
    1.80 +
    1.81 +    public static void main(String[] args) {
    1.82 +        T6306137 self = new T6306137();
    1.83 +        self.test("utf-8", true);
    1.84 +        self.test("ascii", false);
    1.85 +        self.test("utf-8", true);
    1.86 +    }
    1.87 +}

mercurial