file_name stringlengths 6 86 | file_path stringlengths 45 249 | content stringlengths 47 6.26M | file_size int64 47 6.26M | language stringclasses 1 value | extension stringclasses 1 value | repo_name stringclasses 767 values | repo_stars int64 8 14.4k | repo_forks int64 0 1.17k | repo_open_issues int64 0 788 | repo_created_at stringclasses 767 values | repo_pushed_at stringclasses 767 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
Foo.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/importContext/namedPackage/foo/Foo.java | /*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package foo;
import bar.Baz;
class bar {}
class Foo {
public static void main(String[] args) {
Baz.test();
}
}
| 1,182 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Baz.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/importContext/namedPackage/bar/Baz.java | /*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package bar;
public class Baz {
public static void test() {}
}
| 1,120 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Foo.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/importContext/anonPackage/Foo.java | /*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4304112
* @summary Verify that imports are resolved in correct scope.
* @author maddox
*
* @compile Foo.java
*/
import bar.Baz;
class bar {}
class Foo {
public static void main(String[] args) {
Baz.test();
}
}
| 1,306 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Baz.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/importContext/anonPackage/bar/Baz.java | /*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package bar;
public class Baz {
public static void test() {}
}
| 1,120 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4279316d.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/T4279316d.java | /*
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4279316 4758654 4839284
* @summary inconsistency in overload resolution at compile time
* @author gafter
*
* @compile T4279316d.java
*/
abstract class I {
abstract void m(J x);
}
abstract class J extends I {
abstract void m(I x);
}
class T {
void test(J x) {
x.m(x); // ambiguous
}
}
| 1,394 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4279316a.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/T4279316a.java | /*
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4279316 4758654 4839284
* @summary inconsistency in overload resolution at compile time
* @author gafter
*
* @compile T4279316a.java
*/
interface I {
void m(J x);
}
interface J extends I {
void m(I x);
}
abstract class A1 implements J {
void test(J x) {
this.m(x); // ambiguous
}
}
| 1,392 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4279316b.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/T4279316b.java | /*
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4279316 4758654 4839284
* @summary inconsistency in overload resolution at compile time
* @author gafter
*
* @compile T4279316b.java
*/
interface I {
void m(J x);
}
interface J extends I {
void m(I x);
}
class T {
void test(J x) {
x.m(x); // ambiguous
}
}
| 1,366 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4666866.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/T4666866.java | /*
* @test /nodynamiccopyright/
* @bug 4666866 4785453
* @summary REGRESSION: Generated error message unhelpful for missing methods
* @author gafter
*
* @compile/fail/ref=T4666866.out -XDrawDiagnostics T4666866.java
*/
class t implements Runnable {}
| 259 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4528315.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/T4528315.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4528315
* @summary Multiple method inheritance and throws clauses
* @author gafter
*
* @compile T4528315.java
*/
class E1 extends Exception {}
class E2 extends Exception {}
class E3 extends Exception {}
class E4 extends E1 {}
interface I1 {
void foo() throws E1, E2;
}
interface I2 {
void foo() throws E3, E4;
}
interface I3 extends I1, I2 {
// void foo() throws E4;
}
class Blah {
public void foo(I3 i3) {
try {
i3.foo();
} catch (E4 e4) {
}
}
}
| 1,581 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4279316c.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/T4279316c.java | /*
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4279316 4758654 4839284
* @summary inconsistency in overload resolution at compile time
* @author gafter
*
* @compile T4279316c.java
*/
abstract class I {
abstract void m(J x);
}
abstract class J extends I {
abstract void m(I x);
}
abstract class A2 extends J {
void test(J x) {
this.m(x); // ambiguous
}
}
| 1,417 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4711325.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/T4711325.java | /*
* Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4711325 4862139 5009712
* @summary compiler allows unimplementable interfaces
* @author gafter
*
* @compile T4711325.java
* @compile/fail -source 1.4 T4711325.java
*/
interface A {
B f();
}
interface B {
C f();
}
interface C extends A,B {
}
| 1,351 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Tryit.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4686811/Tryit.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4686811
* @summary package private methods do not override across package boundary
* @author gafter
*
* @compile p1/A.java p1/C.java p2/B.java
*/
| 1,223 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
C.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4686811/p1/C.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package p1;
public abstract class C extends p2.B {
void f() {} // overrides noninherited A.f()
}
| 1,154 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
A.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4686811/p1/A.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package p1;
public abstract class A {
abstract void f();
}
| 1,116 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
B.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4686811/p2/B.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package p2;
public abstract class B extends p1.A {
}
class D extends p1.C {
}
| 1,132 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4711056/T1.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4711056
* @summary javac fails to detect conflicting interfaces with separate compilation
* @author gafter
*
* @compile T1.java
* @compile T2.java
* @compile T3.java
* @compile/fail T4.java
*/
interface iclss01004_1 {
abstract int foo(int par);
}
| 1,332 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T3.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4711056/T3.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
abstract class clss01004_b implements iclss01004_1 {
// int foo(int par);
}
| 1,132 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4711056/T4.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
abstract class clss01004_a extends clss01004_b implements iclss01004_2 {
// conflict!
}
| 1,144 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4711056/T2.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
interface iclss01004_2 {
abstract void foo(int par);
}
| 1,111 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6964669.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/6964669/T6964669.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6964669
* @summary javac reports error on miranda methods
* @compile -source 1.2 -target 1.1 pkg/A.java pkg/B.java pkg/C.java
*/
| 1,204 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
C.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/6964669/pkg/C.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg;
public interface C {
public void a();
}
| 1,110 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
A.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/6964669/pkg/A.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg;
public abstract class A implements C {}
| 1,106 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
B.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/6964669/pkg/B.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg;
public class B extends A {
public void a() {}
}
| 1,118 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
AbstractTest.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4686148/AbstractTest.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package one;
public abstract class AbstractTest implements Test
{
}
| 1,121 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ConcreteTest.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4686148/ConcreteTest.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package two;
import one.*;
public class ConcreteTest extends AbstractTest
{
private void perform() // cannot override public with private
{
}
}
| 1,210 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Test.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/miranda/4686148/Test.java | /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4686148
* @summary compiler allows non-public implementation of interface methods
* @author gafter
*
* @compile Test.java AbstractTest.java
* @compile/fail ConcreteTest.java
*/
package one;
public interface Test
{
void perform();
}
| 1,316 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestJavacTask_Lock.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestJavacTask_Lock.java | /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7026509
* @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
*/
import java.io.*;
import java.util.*;
import javax.tools.*;
import javax.tools.JavaCompiler.CompilationTask;
import com.sun.source.util.*;
public class TestJavacTask_Lock {
public static void main(String... args) throws Exception {
new TestJavacTask_Lock().run();
}
enum MethodKind {
CALL {
int test(CompilationTask t) {
boolean ok = t.call();
if (!ok)
throw new Error("compilation failed");
return 1;
}
},
PARSE {
int test(CompilationTask t) {
try {
((JavacTask) t).parse();
return 1;
} catch (IOException ex) {
throw new Error(ex);
}
}
};
abstract int test(CompilationTask t);
}
JavaCompiler comp;
StandardJavaFileManager fm;
void run() throws Exception {
comp = ToolProvider.getSystemJavaCompiler();
fm = comp.getStandardFileManager(null, null, null);
for (MethodKind first: MethodKind.values()) {
for (MethodKind second: MethodKind.values()) {
test(first, second);
}
}
if (errors > 0)
throw new Exception(errors + " errors found");
}
void test(MethodKind first, MethodKind second) {
System.err.println("test: " + first + ", " + second);
File testSrc = new File(System.getProperty("test.src"));
String thisClassName = TestJavacTask_Lock.class.getName();
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java"));
File tmpDir = new File(first + "_" + second);
tmpDir.mkdirs();
List<String> options = Arrays.asList( "-d", tmpDir.getPath() );
CompilationTask t = comp.getTask(null, fm, null, options, null, files);
try {
first.test(t);
second.test(t);
error("No exception thrown");
} catch (IllegalStateException e) {
System.err.println("Expected exception caught: " + e);
} catch (Exception e) {
error("Unexpected exception caught: " + e);
e.printStackTrace(System.err);
}
}
void error(String msg) {
System.err.println("Error: " + msg);
errors++;
}
int errors;
}
| 3,621 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestContainTypes.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestContainTypes.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6981185
* @summary com.sun.tools.model.JavacTypes.contains() calls Type.contains instead of Types.containsType
* @run main TestContainTypes
*/
import java.net.URI;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.DeclaredType;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
import com.sun.source.util.JavacTask;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
public class TestContainTypes {
enum ClassType {
OBJECT("Object"),
NUMBER("Number"),
INTEGER("Integer"),
STRING("String");
String classStub;
ClassType(String classStub) {
this.classStub = classStub;
}
boolean subtypeOf(ClassType that) {
switch (that) {
case OBJECT: return true;
case NUMBER: return this == NUMBER || this == INTEGER;
case INTEGER: return this == INTEGER;
case STRING: return this == STRING;
default: throw new AssertionError("Bad type kind in subtyping test");
}
}
}
enum ParameterType {
INVARIANT("List<#1>"),
COVARIANT("List<? extends #1>"),
CONTRAVARIANT("List<? super #1>"),
BIVARIANT("List<?>");
String paramTypeStub;
ParameterType(String paramTypeStub) {
this.paramTypeStub = paramTypeStub;
}
String instantiate(ClassType ct) {
return paramTypeStub.replace("#1", ct.classStub);
}
static boolean contains(ParameterType pt1, ClassType ct1,
ParameterType pt2, ClassType ct2) {
switch (pt1) {
case INVARIANT: return (pt2 == INVARIANT && ct1 == ct2) ||
(pt2 == CONTRAVARIANT && ct1 == ct2 && ct1 == ClassType.OBJECT);
case COVARIANT: return ((pt2 == INVARIANT || pt2 == COVARIANT) &&
ct2.subtypeOf(ct1)) ||
(ct1 == ClassType.OBJECT);
case CONTRAVARIANT: return (pt2 == INVARIANT || pt2 == CONTRAVARIANT) &&
ct1.subtypeOf(ct2);
case BIVARIANT: return true;
default: throw new AssertionError("Bad type kind in containment test");
}
}
}
static class JavaSource extends SimpleJavaFileObject {
final static String sourceStub =
"import java.util.List;\n" +
"@interface ToCheck {}\n" +
"class Test {\n" +
" @ToCheck void test(#A a, #B b) {}\n" +
"}\n";
String source;
public JavaSource(String typeA, String typeB) {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
source = sourceStub.replace("#A", typeA).replace("#B", typeB);
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return source;
}
}
public static void main(String... args) throws Exception {
for (ClassType ctA : ClassType.values()) {
for (ParameterType ptA : ParameterType.values()) {
for (ClassType ctB : ClassType.values()) {
for (ParameterType ptB : ParameterType.values()) {
compileAndCheck(ptA, ctA, ptB, ctB);
}
}
}
}
}
static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception {
JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB));
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask)tool.getTask(null, null, null,
null, null, Arrays.asList(source));
ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source)));
System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA));
System.err.println("B = " + ptB +" / " + ptB.instantiate(ctB));
System.err.println("Source = " + source.source);
ct.analyze();
}
@SupportedSourceVersion(SourceVersion.RELEASE_7)
static class ContainTypesTester extends AbstractProcessor {
boolean expected;
JavaSource source;
ContainTypesTester(boolean expected, JavaSource source) {
this.expected = expected;
this.source = source;
}
@Override
public Set<String> getSupportedAnnotationTypes() {
Set<String> supportedAnnos = new HashSet();
supportedAnnos.add("*");
return supportedAnnos;
}
private void error(String msg) {
System.err.println(source.source);
throw new AssertionError(msg);
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.getRootElements().size() == 0) {
return true;
}
if (annotations.isEmpty() || annotations.size() > 1) {
error("no anno found/wrong number of annotations found: " + annotations.size());
}
TypeElement anno = (TypeElement)annotations.toArray()[0];
Set<? extends Element> annoElems = roundEnv.getElementsAnnotatedWith(anno);
if (annoElems.isEmpty() || annoElems.size() > 1) {
error("no annotated element found/wrong number of annotated elements found: " + annoElems.size());
}
Element annoElement = (Element)annoElems.toArray()[0];
if (!(annoElement instanceof ExecutableElement)) {
error("annotated element must be a method");
}
ExecutableElement method = (ExecutableElement)annoElement;
if (method.getParameters().size() != 2) {
error("annotated method must have 2 arguments");
}
DeclaredType d1 = (DeclaredType)method.getParameters().get(0).asType();
DeclaredType d2 = (DeclaredType)method.getParameters().get(1).asType();
if (d1.getTypeArguments().size() != 1 ||
d1.getTypeArguments().size() != 1) {
error("parameter type must be generic in one type-variable");
}
TypeMirror t1 = d1.getTypeArguments().get(0);
TypeMirror t2 = d2.getTypeArguments().get(0);
if (processingEnv.getTypeUtils().contains(t1, t2) != expected) {
error("bad type containment result\n" +
"t1 : " + t1 +"\n" +
"t2 : " + t2 +"\n" +
"expected answer : " + expected +"\n");
}
return true;
}
}
}
| 8,472 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6407011.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6407011.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6407011 6407066
* @summary javac crashes in b78 with NPE in JavacFileManager:293
* @author Peter von der Ah\u00e9
*/
import java.io.File;
import javax.tools.*;
public class T6407011 {
public static void main(String... args) {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
String srcdir = System.getProperty("test.src");
File file = new File(srcdir, T6407011.class.getSimpleName() + ".java");
if (tool.run(null, null, null, "-sourcepath", "/x y z", "-d", ".", file.getPath()) != 0)
throw new AssertionError("non zero return code from compiler");
}
}
| 1,696 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6357331.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6357331.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6357331
* @summary NPE from JavacTask.getElements() after calling CompilationTask.run
*/
import java.io.*;
import java.util.Arrays;
import javax.tools.*;
import com.sun.source.util.*;
public class T6357331
{
public static void main(String... args) {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
PrintWriter out = new PrintWriter(new StringWriter());
final JavacTask task = (JavacTask) (tool.getTask(out, null, null, null, null, null));
// set a listener to verify that IllegalStateException is not thrown
// during the compilation
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
task.getElements();
task.getTypes();
}
public void finished(TaskEvent e) { }
});
task.call();
// now the compilation is over, we expect IllegalStateException (not NPE)
try {
task.getElements();
throw new AssertionError("IllegalStateException not thrown");
}
catch (IllegalStateException e) {
// expected
}
try {
task.getTypes();
throw new AssertionError("IllegalStateException not thrown");
}
catch (IllegalStateException e) {
// expected
}
}
}
| 2,453 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6412669.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6412669.java | /*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6412669 6997958
* @summary Should be able to get SourcePositions from 269 world
*/
import java.io.*;
import java.net.*;
import java.util.*;
import javax.annotation.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
@SupportedAnnotationTypes("*")
public class T6412669 extends AbstractProcessor {
public static void main(String... args) throws Exception {
File testSrc = new File(System.getProperty("test.src", "."));
File testClasses = new File(System.getProperty("test.classes", "."));
// Determine location of necessary tools classes. Assume all in one place.
// Likely candidates are typically tools.jar (when testing JDK build)
// or build/classes or dist/javac.jar (when testing langtools, using -Xbootclasspath/p:)
File toolsClasses;
URL u = T6412669.class.getClassLoader().getResource("com/sun/source/util/JavacTask.class");
switch (u.getProtocol()) {
case "file":
toolsClasses = new File(u.toURI());
break;
case "jar":
String s = u.getFile(); // will be file:path!/entry
int sep = s.indexOf("!");
toolsClasses = new File(new URI(s.substring(0, sep)));
break;
default:
throw new AssertionError("Cannot locate tools classes");
}
//System.err.println("toolsClasses: " + toolsClasses);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses, toolsClasses));
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6412669.class.getName()+".java")));
String[] opts = { "-proc:only", "-processor", T6412669.class.getName()};
StringWriter sw = new StringWriter();
JavacTask task = tool.getTask(sw, fm, null, Arrays.asList(opts), null, files);
boolean ok = task.call();
String out = sw.toString();
if (!out.isEmpty())
System.err.println(out);
if (!ok)
throw new AssertionError("compilation of test program failed");
// verify we found an annotated element to exercise the SourcePositions API
if (!out.contains("processing element"))
throw new AssertionError("expected text not found in compilation output");
}
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Trees trees = Trees.instance(processingEnv);
SourcePositions sp = trees.getSourcePositions();
Messager m = processingEnv.getMessager();
m.printMessage(Diagnostic.Kind.NOTE, "processing annotations");
int count = 0;
for (TypeElement anno: annotations) {
count++;
m.printMessage(Diagnostic.Kind.NOTE, " processing annotation " + anno);
for (Element e: roundEnv.getElementsAnnotatedWith(anno)) {
m.printMessage(Diagnostic.Kind.NOTE, " processing element " + e);
TreePath p = trees.getPath(e);
long start = sp.getStartPosition(p.getCompilationUnit(), p.getLeaf());
long end = sp.getEndPosition(p.getCompilationUnit(), p.getLeaf());
Diagnostic.Kind k = (start > 0 && end > 0 && start < end
? Diagnostic.Kind.NOTE : Diagnostic.Kind.ERROR);
m.printMessage(k, "test [" + start + "," + end + "]", e);
}
}
if (count == 0)
m.printMessage(Diagnostic.Kind.NOTE, "no annotations found");
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
| 5,075 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Sibling.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/Sibling.java | /*
* Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6399602
* @summary Verify that files are created relative to sibling
* @author Peter von der Ah\u00e9
*/
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import javax.tools.*;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
import static javax.tools.JavaFileObject.Kind.CLASS;
public class Sibling {
public static void main(String... args) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
JavaFileObject sibling =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File("Test.java")))
.iterator().next();
JavaFileObject classFile = fm.getJavaFileForOutput(CLASS_OUTPUT,
"foo.bar.baz.Test",
CLASS,
sibling);
File file = new File("Test.class").getAbsoluteFile();
if (!classFile.toUri().equals(file.toURI()))
throw new AssertionError("Expected " + file.toURI() + ", got " +
classFile.toUri());
}
}
| 2,341 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestEvalExpression.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestEvalExpression.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4164450
* @summary JSR 199: Standard interface for Java compilers
* @author Peter von der Ah\u00e9
* @compile TestEvalExpression.java evalexpr/ByteArrayClassLoader.java evalexpr/CompileFromString.java evalexpr/MemoryFileManager.java
* @run main TestEvalExpression
*/
import java.lang.reflect.Method;
import java.util.*;
import javax.swing.JOptionPane;
import javax.tools.*;
import static evalexpr.CompileFromString.*;
public class TestEvalExpression {
static int errorCount = 0;
static class Listener implements DiagnosticListener<JavaFileObject> {
public void report(Diagnostic<? extends JavaFileObject> message) {
if (message.getKind() == Diagnostic.Kind.ERROR)
errorCount++;
System.err.println(message);
}
}
public static void main(String[] args) {
// Get a compiler tool
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
final List<String> compilerFlags = new ArrayList();
compilerFlags.add("-Xlint:all"); // report all warnings
compilerFlags.add("-g:none"); // don't generate debug info
final DiagnosticListener<JavaFileObject> listener = new Listener();
String expression = "System.getProperty(\"java.vendor\")";
Object result = null;
try {
result = evalExpression(compiler, listener, compilerFlags, expression);
} catch (Exception e) {
throw new AssertionError(e);
}
if (result == ERROR)
throw new AssertionError(result);
System.out.format("%s => %s%n", expression, result);
if (!System.getProperty("java.vendor").equals(result))
throw new AssertionError(result);
if (errorCount != 0)
throw new AssertionError(errorCount);
try {
result = evalExpression(compiler, listener, compilerFlags, "fisk hest");
} catch (Exception e) {
throw new AssertionError(e);
}
if (errorCount == 0)
throw new AssertionError(errorCount);
}
}
| 3,162 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6400207.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6400207.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6400207
* @summary JSR 199: JavaFileManager.list and unset location
* @author Peter von der Ah\u00e9
*/
import java.util.*;
import javax.tools.*;
import static javax.tools.StandardLocation.*;
import static javax.tools.JavaFileObject.Kind.*;
public class T6400207 {
static void testList(JavaFileManager fm,
JavaFileManager.Location location,
String packageName,
Set<JavaFileObject.Kind> kinds) throws Exception {
boolean expectNpe =
location == null ||
packageName == null ||
kinds == null;
try {
fm.list(location, packageName, kinds, false);
if (expectNpe) {
String message = "NullPointerException not thrown";
if (location == null)
throw new AssertionError(message + " (location is null)");
if (packageName == null)
throw new AssertionError(message + " (packageName is null)");
if (kinds == null)
throw new AssertionError(message + " (kinds is null)");
throw new AssertionError(message);
}
} catch (NullPointerException e) {
if (!expectNpe)
throw e;
}
}
public static void main(String... args) throws Exception {
JavaFileManager fm =
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
JavaFileManager.Location bogusLocation = locationFor("bogus");
JavaFileManager.Location knownLocation = CLASS_PATH;
String packageName = "java.lang";
Set<JavaFileObject.Kind> kinds = EnumSet.of(CLASS);
for (StandardLocation location : StandardLocation.values()) {
if (location != locationFor(location.getName()))
throw new AssertionError(location + " != locationFor(" +
location.getName() + ")");
}
testList(fm, null, null, null);
testList(fm, bogusLocation, packageName, kinds);
testList(fm, knownLocation, packageName, kinds);
testList(fm, null, packageName, kinds);
testList(fm, knownLocation, null, kinds);
testList(fm, knownLocation, packageName, null);
testList(fm, bogusLocation, null, kinds);
testList(fm, bogusLocation, packageName, null);
System.err.println("Test PASSED.");
}
}
| 3,546 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6838467.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6838467.java | /*
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6838467
* @summary JSR199 FileObjects don't obey general contract of equals.
*/
import java.io.*;
import java.util.*;
import java.util.zip.*;
import javax.tools.*;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.OptionName;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
public class T6838467 {
boolean fileSystemIsCaseSignificant = !new File("a").equals(new File("A"));
enum FileKind {
DIR("dir"),
ZIP("zip"),
ZIPFILEINDEX("zip");
FileKind(String path) {
file = new File(path);
}
final File file;
};
enum CompareKind {
SAME {
File other(File f) { return f; }
},
ABSOLUTE {
File other(File f) { return f.getAbsoluteFile(); }
},
DIFFERENT {
File other(File f) { return new File("not_" + f.getPath()); }
},
CASEEQUIV {
File other(File f) { return new File(f.getPath().toUpperCase()); }
};
abstract File other(File f);
};
String[] paths = { "p/A.java", "p/B.java", "p/C.java" };
public static void main(String... args) throws Exception {
new T6838467().run();
}
void run() throws Exception {
// on Windows, verify file system is not case significant
if (System.getProperty("os.name").toLowerCase().startsWith("windows")
&& fileSystemIsCaseSignificant) {
error("fileSystemIsCaseSignificant is set on Windows.");
}
// create a set of directories and zip files to compare
createTestDir(new File("dir"), paths);
createTestDir(new File("not_dir"), paths);
createTestZip(new File("zip"), paths);
createTestZip(new File("not_zip"), paths);
if (fileSystemIsCaseSignificant) {
createTestDir(new File("DIR"), paths);
createTestZip(new File("ZIP"), paths);
}
// test the various sorts of file objects that can be obtained from
// the file manager, and for various values that may or may not match.
for (FileKind fk: FileKind.values()) {
for (CompareKind ck: CompareKind.values()) {
test(fk, ck);
}
}
// verify that the various different types of file object were all
// tested
Set<String> expectClasses = new HashSet<String>(Arrays.asList(
"RegularFileObject", "ZipFileObject", "ZipFileIndexFileObject" ));
if (!foundClasses.equals(expectClasses)) {
error("expected fileobject classes not found\n"
+ "expected: " + expectClasses + "\n"
+ "found: " + foundClasses);
}
if (errors > 0)
throw new Exception(errors + " errors");
}
void test(FileKind fk, CompareKind ck) throws IOException {
File f1 = fk.file;
JavaFileManager fm1 = createFileManager(fk, f1);
File f2 = ck.other(fk.file);
JavaFileManager fm2 = createFileManager(fk, f2);
try {
// If the directories or zip files match, we expect "n" matches in
// the "n-squared" comparisons to come, where "n" is the number of
// entries in the the directories or zip files.
// If the directories or zip files don't themselves match,
// we obviously don't expect any of their contents to match either.
int expect = (f1.getAbsoluteFile().equals(f2.getAbsoluteFile()) ? paths.length : 0);
System.err.println("test " + (++count) + " " + fk + " " + ck + " " + f1 + " " + f2);
test(fm1, fm2, expect);
} finally {
fm1.close();
fm2.close();
}
}
// For a pair of file managers that may or may not have similar entries
// on the classpath, compare all files returned from one against all files
// returned from the other. For each pair of files, verify that if they
// are equal, the hashcode is equal as well, and finally verify that the
// expected number of matches was found.
void test(JavaFileManager fm1, JavaFileManager fm2, int expectEqualCount) throws IOException {
boolean foundFiles1 = false;
boolean foundFiles2 = false;
int foundEqualCount = 0;
Set<JavaFileObject.Kind> kinds = EnumSet.allOf(JavaFileObject.Kind.class);
for (FileObject fo1: fm1.list(StandardLocation.CLASS_PATH, "p", kinds, false)) {
foundFiles1 = true;
foundClasses.add(fo1.getClass().getSimpleName());
for (FileObject fo2: fm2.list(StandardLocation.CLASS_PATH, "p", kinds, false)) {
foundFiles2 = true;
foundClasses.add(fo1.getClass().getSimpleName());
System.err.println("compare " + fo1 + " " + fo2);
if (fo1.equals(fo2)) {
foundEqualCount++;
int hash1 = fo1.hashCode();
int hash2 = fo2.hashCode();
if (hash1 != hash2)
error("hashCode error: " + fo1 + " [" + hash1 + "] "
+ fo2 + " [" + hash2 + "]");
}
}
}
if (!foundFiles1)
error("no files found for file manager 1");
if (!foundFiles2)
error("no files found for file manager 2");
// verify the expected number of matches were found
if (foundEqualCount != expectEqualCount)
error("expected matches not found: expected " + expectEqualCount + ", found " + foundEqualCount);
}
// create a file manager to test a FileKind, with a given directory
// or zip file placed on the classpath
JavaFileManager createFileManager(FileKind fk, File classpath) throws IOException {
StandardJavaFileManager fm = createFileManager(fk == FileKind.ZIP);
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classpath));
return fm;
}
JavacFileManager createFileManager(boolean useOptimizedZip) {
Context ctx = new Context();
Options options = Options.instance(ctx);
options.put("useOptimizedZip", Boolean.toString(useOptimizedZip));
return new JavacFileManager(ctx, false, null);
}
// create a directory containing a given set of paths
void createTestDir(File dir, String[] paths) throws IOException {
for (String p: paths) {
File file = new File(dir, p);
file.getParentFile().mkdirs();
FileWriter out = new FileWriter(file);
try {
out.write(p);
} finally {
out.close();
}
}
}
// create a sip file containing a given set of entries
void createTestZip(File zip, String[] paths) throws IOException {
if (zip.getParentFile() != null)
zip.getParentFile().mkdirs();
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip));
try {
for (String p: paths) {
ZipEntry ze = new ZipEntry(p);
zos.putNextEntry(ze);
byte[] bytes = p.getBytes();
zos.write(bytes, 0, bytes.length);
zos.closeEntry();
}
} finally {
zos.close();
}
}
void error(String msg) {
System.err.println("Error: " + msg);
errors++;
}
int count;
int errors;
Set<String> foundClasses = new HashSet<String>();
}
| 8,670 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestDocComments.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestDocComments.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6985202
* @summary no access to doc comments from Tree API
*/
import java.io.*;
import java.util.*;
import javax.tools.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.JavacTool;
/**
* class-TestDocComments.
*/
public class TestDocComments {
/**
* method-main.
*/
public static void main(String... args) throws Exception {
new TestDocComments().run();
}
/**
* method-run.
*/
void run() throws Exception {
File testSrc = new File(System.getProperty("test.src"));
File file = new File(testSrc, "TestDocComments.java");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
Iterable<? extends CompilationUnitTree> units = task.parse();
Trees trees = Trees.instance(task);
CommentScanner s = new CommentScanner();
int n = s.scan(units, trees);
if (n != 12)
error("Unexpected number of doc comments found: " + n);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
/**
* class-CommentScanner.
*/
class CommentScanner extends TreePathScanner<Integer,Trees> {
/**
* method-visitClass.
*/
@Override
public Integer visitClass(ClassTree t, Trees trees) {
return reduce(super.visitClass(t, trees),
check(trees, "class-" + t.getSimpleName() + "."));
}
/**
* method-visitMethod.
*/
@Override
public Integer visitMethod(MethodTree t, Trees trees) {
return reduce(super.visitMethod(t, trees),
check(trees, "method-" + t.getName() + "."));
}
/**
* method-visitVariable.
*/
@Override
public Integer visitVariable(VariableTree t, Trees trees) {
// for simplicity, only check fields, not parameters or local decls
int n = (getCurrentPath().getParentPath().getLeaf().getKind() == Tree.Kind.CLASS)
? check(trees, "field-" + t.getName() + ".")
: 0;
return reduce(super.visitVariable(t, trees), n);
}
/**
* method-reduce.
*/
@Override
public Integer reduce(Integer i1, Integer i2) {
return (i1 == null) ? i2 : (i2 == null) ? i1 : Integer.valueOf(i1 + i2);
}
/**
* method-check.
*/
int check(Trees trees, String expect) {
TreePath p = getCurrentPath();
String dc = trees.getDocComment(p);
if (dc != null && dc.trim().equals(expect))
return 1;
Tree.Kind k = p.getLeaf().getKind();
if (dc == null)
error("no doc comment for " + k);
else
error("unexpected doc comment for " + k + "\nexpect: " + expect + "\nfound: " + dc);
return 0;
}
}
/**
* method-nullCheck.
*/
int nullCheck(Integer i) {
return (i == null) ? 0 : i;
}
/**
* method-error.
*/
void error(String msg) {
System.err.println("Error: " + msg);
errors++;
}
/**
* field-errors.
*/
int errors;
}
| 4,690 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestClientCodeWrapper.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestClientCodeWrapper.java | /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6437138 6482554
* @summary JSR 199: Compiler doesn't diagnose crash in user code
* @library ../lib
* @build JavacTestingAbstractProcessor TestClientCodeWrapper
* @run main TestClientCodeWrapper
*/
import java.io.*;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
import javax.tools.JavaFileObject.Kind;
public class TestClientCodeWrapper extends JavacTestingAbstractProcessor {
public static void main(String... args) throws Exception {
new TestClientCodeWrapper().run();
}
/**
* Run a series of compilations, each with a different user-provided object
* configured to throw an exception when a specific method is invoked.
* Then, verify the exception is thrown as expected.
*
* Some methods are not invoked from the compiler, and are excluded from the test.
*/
void run() throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
defaultFileManager = compiler.getStandardFileManager(null, null, null);
for (Method m: getMethodsExcept(JavaFileManager.class, "close", "getJavaFileForInput")) {
test(m);
}
for (Method m: getMethodsExcept(FileObject.class, "delete")) {
test(m);
}
for (Method m: getMethods(JavaFileObject.class)) {
test(m);
}
for (Method m: getMethodsExcept(Processor.class, "getCompletions")) {
test(m);
}
for (Method m: DiagnosticListener.class.getDeclaredMethods()) {
test(m);
}
for (Method m: TaskListener.class.getDeclaredMethods()) {
test(m);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
/** Get a sorted set of the methods declared on a class. */
Set<Method> getMethods(Class<?> clazz) {
return getMethodsExcept(clazz, new String[0]);
}
/** Get a sorted set of the methods declared on a class, excluding
* specified methods by name. */
Set<Method> getMethodsExcept(Class<?> clazz, String... exclude) {
Set<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
public int compare(Method m1, Method m2) {
return m1.toString().compareTo(m2.toString());
}
});
Set<String> e = new HashSet<String>(Arrays.asList(exclude));
for (Method m: clazz.getDeclaredMethods()) {
if (!e.contains(m.getName()))
methods.add(m);
}
return methods;
}
/**
* Test a method in a user supplied component, to verify javac's handling
* of any exceptions thrown by that method.
*/
void test(Method m) throws Exception {
testNum++;
File extDirs = new File("empty-extdirs");
extDirs.mkdirs();
File testClasses = new File("test" + testNum);
testClasses.mkdirs();
defaultFileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(testClasses));
System.err.println("test " + testNum + ": "
+ m.getDeclaringClass().getSimpleName() + "." + m.getName());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
List<String> javacOptions = Arrays.asList(
"-extdirs", extDirs.getPath(), // for use by filemanager handleOption
"-processor", TestClientCodeWrapper.class.getName()
);
List<String> classes = Collections.emptyList();
JavacTool tool = JavacTool.create();
try {
JavacTask task = tool.getTask(pw,
getFileManager(m, defaultFileManager),
getDiagnosticListener(m, pw),
javacOptions,
classes,
getCompilationUnits(m));
if (isDeclaredIn(m, Processor.class))
task.setProcessors(getProcessors(m));
if (isDeclaredIn(m, TaskListener.class))
task.setTaskListener(getTaskListener(m, pw));
boolean ok = task.call();
error("compilation " + (ok ? "succeeded" : "failed") + " unexpectedly");
} catch (RuntimeException e) {
System.err.println("caught " + e);
if (e.getClass() == RuntimeException.class) {
Throwable cause = e.getCause();
if (cause instanceof UserError) {
String expect = m.getName();
String found = cause.getMessage();
checkEqual("exception messaqe", expect, found);
} else {
cause.printStackTrace(System.err);
error("Unexpected exception: " + cause);
}
} else {
e.printStackTrace(System.err);
error("Unexpected exception: " + e);
}
}
pw.close();
String out = sw.toString();
System.err.println(out);
}
/** Get a file manager to use for the test compilation. */
JavaFileManager getFileManager(Method m, JavaFileManager defaultFileManager) {
return isDeclaredIn(m, JavaFileManager.class, FileObject.class, JavaFileObject.class)
? new UserFileManager(m, defaultFileManager)
: defaultFileManager;
}
/** Get a diagnostic listener to use for the test compilation. */
DiagnosticListener<JavaFileObject> getDiagnosticListener(Method m, PrintWriter out) {
return isDeclaredIn(m, DiagnosticListener.class)
? new UserDiagnosticListener(m, out)
: null;
}
/** Get a set of file objects to use for the test compilation. */
Iterable<? extends JavaFileObject> getCompilationUnits(Method m) {
File testSrc = new File(System.getProperty("test.src"));
File thisSrc = new File(testSrc, TestClientCodeWrapper.class.getName() + ".java");
Iterable<? extends JavaFileObject> files = defaultFileManager.getJavaFileObjects(thisSrc);
if (isDeclaredIn(m, FileObject.class, JavaFileObject.class))
return Arrays.asList(new UserFileObject(m, files.iterator().next()));
else
return files;
}
/** Get a set of annotation processors to use for the test compilation. */
Iterable<? extends Processor> getProcessors(Method m) {
return Arrays.asList(new UserProcessor(m));
}
/** Get a task listener to use for the test compilation. */
TaskListener getTaskListener(Method m, PrintWriter out) {
return new UserTaskListener(m, out);
}
/** Check if two values are .equal, and report an error if not. */
<T> void checkEqual(String label, T expect, T found) {
if (!expect.equals(found))
error("Unexpected value for " + label + ": " + found + "; expected: " + expect);
}
/** Report an error. */
void error(String msg) {
System.err.println("Error: " + msg);
errors++;
}
/** Check if a method is declared in any of a set of classes */
static boolean isDeclaredIn(Method m, Class<?>... classes) {
Class<?> dc = m.getDeclaringClass();
for (Class<?> c: classes) {
if (c == dc) return true;
}
return false;
}
/** Throw an intentional error if the method has a given name. */
static void throwUserExceptionIfNeeded(Method m, String name) {
if (m != null && m.getName().equals(name))
throw new UserError(name);
}
StandardJavaFileManager defaultFileManager;
int testNum;
int errors;
//--------------------------------------------------------------------------
/**
* Processor used to trigger use of methods not normally used by javac.
*/
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
boolean firstRound = false;
for (Element e: roundEnv.getRootElements()) {
if (e.getSimpleName().contentEquals(TestClientCodeWrapper.class.getSimpleName()))
firstRound = true;
}
if (firstRound) {
try {
FileObject f1 = filer.getResource(StandardLocation.CLASS_PATH, "",
TestClientCodeWrapper.class.getName() + ".java");
f1.openInputStream().close();
f1.openReader(false).close();
FileObject f2 = filer.createResource(
StandardLocation.CLASS_OUTPUT, "", "f2.txt", (Element[]) null);
f2.openOutputStream().close();
FileObject f3 = filer.createResource(
StandardLocation.CLASS_OUTPUT, "", "f3.txt", (Element[]) null);
f3.openWriter().close();
JavaFileObject f4 = filer.createSourceFile("f4", (Element[]) null);
f4.openWriter().close();
f4.getNestingKind();
f4.getAccessLevel();
messager.printMessage(Diagnostic.Kind.NOTE, "informational note",
roundEnv.getRootElements().iterator().next());
} catch (IOException e) {
throw new UserError(e);
}
}
return true;
}
//--------------------------------------------------------------------------
// <editor-fold defaultstate="collapsed" desc="User classes">
static class UserError extends Error {
private static final long serialVersionUID = 1L;
UserError(String msg) {
super(msg);
}
UserError(Throwable t) {
super(t);
}
}
static class UserFileManager extends ForwardingJavaFileManager<JavaFileManager> {
Method fileManagerMethod;
Method fileObjectMethod;
UserFileManager(Method m, JavaFileManager delegate) {
super(delegate);
if (isDeclaredIn(m, JavaFileManager.class)) {
fileManagerMethod = m;
} else if (isDeclaredIn(m, FileObject.class, JavaFileObject.class)) {
fileObjectMethod = m;
} else
assert false;
}
@Override
public ClassLoader getClassLoader(Location location) {
throwUserExceptionIfNeeded(fileManagerMethod, "getClassLoader");
return super.getClassLoader(location);
}
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException {
throwUserExceptionIfNeeded(fileManagerMethod, "list");
return wrap(super.list(location, packageName, kinds, recurse));
}
@Override
public String inferBinaryName(Location location, JavaFileObject file) {
throwUserExceptionIfNeeded(fileManagerMethod, "inferBinaryName");
return super.inferBinaryName(location, unwrap(file));
}
@Override
public boolean isSameFile(FileObject a, FileObject b) {
throwUserExceptionIfNeeded(fileManagerMethod, "isSameFile");
return super.isSameFile(unwrap(a), unwrap(b));
}
@Override
public boolean handleOption(String current, Iterator<String> remaining) {
throwUserExceptionIfNeeded(fileManagerMethod, "handleOption");
return super.handleOption(current, remaining);
}
@Override
public boolean hasLocation(Location location) {
throwUserExceptionIfNeeded(fileManagerMethod, "hasLocation");
return super.hasLocation(location);
}
@Override
public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
throwUserExceptionIfNeeded(fileManagerMethod, "getJavaFileForInput");
return wrap(super.getJavaFileForInput(location, className, kind));
}
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
throwUserExceptionIfNeeded(fileManagerMethod, "getJavaFileForOutput");
return wrap(super.getJavaFileForOutput(location, className, kind, sibling));
}
@Override
public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
throwUserExceptionIfNeeded(fileManagerMethod, "getFileForInput");
return wrap(super.getFileForInput(location, packageName, relativeName));
}
@Override
public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException {
throwUserExceptionIfNeeded(fileManagerMethod, "getFileForOutput");
return wrap(super.getFileForOutput(location, packageName, relativeName, sibling));
}
@Override
public void flush() throws IOException {
throwUserExceptionIfNeeded(fileManagerMethod, "flush");
super.flush();
}
@Override
public void close() throws IOException {
throwUserExceptionIfNeeded(fileManagerMethod, "close");
super.close();
}
@Override
public int isSupportedOption(String option) {
throwUserExceptionIfNeeded(fileManagerMethod, "isSupportedOption");
return super.isSupportedOption(option);
}
public FileObject wrap(FileObject fo) {
if (fileObjectMethod == null)
return fo;
return new UserFileObject(fileObjectMethod, (JavaFileObject)fo);
}
FileObject unwrap(FileObject fo) {
if (fo instanceof UserFileObject)
return ((UserFileObject) fo).unwrap();
else
return fo;
}
public JavaFileObject wrap(JavaFileObject fo) {
if (fileObjectMethod == null)
return fo;
return new UserFileObject(fileObjectMethod, fo);
}
public Iterable<JavaFileObject> wrap(Iterable<? extends JavaFileObject> list) {
List<JavaFileObject> wrapped = new ArrayList<JavaFileObject>();
for (JavaFileObject fo : list)
wrapped.add(wrap(fo));
return Collections.unmodifiableList(wrapped);
}
JavaFileObject unwrap(JavaFileObject fo) {
if (fo instanceof UserFileObject)
return ((UserFileObject) fo).unwrap();
else
return fo;
}
}
static class UserFileObject extends ForwardingJavaFileObject<JavaFileObject> {
Method method;
UserFileObject(Method m, JavaFileObject delegate) {
super(delegate);
assert isDeclaredIn(m, FileObject.class, JavaFileObject.class);
this.method = m;
}
JavaFileObject unwrap() {
return fileObject;
}
@Override
public Kind getKind() {
throwUserExceptionIfNeeded(method, "getKind");
return super.getKind();
}
@Override
public boolean isNameCompatible(String simpleName, Kind kind) {
throwUserExceptionIfNeeded(method, "isNameCompatible");
return super.isNameCompatible(simpleName, kind);
}
@Override
public NestingKind getNestingKind() {
throwUserExceptionIfNeeded(method, "getNestingKind");
return super.getNestingKind();
}
@Override
public Modifier getAccessLevel() {
throwUserExceptionIfNeeded(method, "getAccessLevel");
return super.getAccessLevel();
}
@Override
public URI toUri() {
throwUserExceptionIfNeeded(method, "toUri");
return super.toUri();
}
@Override
public String getName() {
throwUserExceptionIfNeeded(method, "getName");
return super.getName();
}
@Override
public InputStream openInputStream() throws IOException {
throwUserExceptionIfNeeded(method, "openInputStream");
return super.openInputStream();
}
@Override
public OutputStream openOutputStream() throws IOException {
throwUserExceptionIfNeeded(method, "openOutputStream");
return super.openOutputStream();
}
@Override
public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
throwUserExceptionIfNeeded(method, "openReader");
return super.openReader(ignoreEncodingErrors);
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
throwUserExceptionIfNeeded(method, "getCharContent");
return super.getCharContent(ignoreEncodingErrors);
}
@Override
public Writer openWriter() throws IOException {
throwUserExceptionIfNeeded(method, "openWriter");
return super.openWriter();
}
@Override
public long getLastModified() {
throwUserExceptionIfNeeded(method, "getLastModified");
return super.getLastModified();
}
@Override
public boolean delete() {
throwUserExceptionIfNeeded(method, "delete");
return super.delete();
}
}
static class UserProcessor extends JavacTestingAbstractProcessor {
Method method;
UserProcessor(Method m) {
assert isDeclaredIn(m, Processor.class);
method = m;
}
@Override
public Set<String> getSupportedOptions() {
throwUserExceptionIfNeeded(method, "getSupportedOptions");
return super.getSupportedOptions();
}
@Override
public Set<String> getSupportedAnnotationTypes() {
throwUserExceptionIfNeeded(method, "getSupportedAnnotationTypes");
return super.getSupportedAnnotationTypes();
}
@Override
public SourceVersion getSupportedSourceVersion() {
throwUserExceptionIfNeeded(method, "getSupportedSourceVersion");
return super.getSupportedSourceVersion();
}
@Override
public void init(ProcessingEnvironment processingEnv) {
throwUserExceptionIfNeeded(method, "init");
super.init(processingEnv);
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
throwUserExceptionIfNeeded(method, "process");
return true;
}
@Override
public Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
throwUserExceptionIfNeeded(method, "getCompletions");
return super.getCompletions(element, annotation, member, userText);
}
}
static class UserDiagnosticListener implements DiagnosticListener<JavaFileObject> {
Method method;
PrintWriter out;
UserDiagnosticListener(Method m, PrintWriter out) {
assert isDeclaredIn(m, DiagnosticListener.class);
this.method = m;
this.out = out;
}
@Override
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
throwUserExceptionIfNeeded(method, "report");
out.println("report: " + diagnostic);
}
}
static class UserTaskListener implements TaskListener {
Method method;
PrintWriter out;
UserTaskListener(Method m, PrintWriter out) {
assert isDeclaredIn(m, TaskListener.class);
this.method = m;
this.out = out;
}
@Override
public void started(TaskEvent e) {
throwUserExceptionIfNeeded(method, "started");
out.println("started: " + e);
}
@Override
public void finished(TaskEvent e) {
throwUserExceptionIfNeeded(method, "finished");
out.println("finished: " + e);
}
}
// </editor-fold>
}
| 21,613 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestGetElement.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestGetElement.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6930507
* @summary Symbols for anonymous and local classes made too late for use by java tree API
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.tools.Diagnostic;
import static javax.lang.model.util.ElementFilter.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
@SupportedOptions({"test", "last"})
@SupportedAnnotationTypes("*")
public class TestGetElement extends AbstractProcessor {
public static void main(String... args) throws Exception {
new TestGetElement().run();
}
public TestGetElement() { }
public void run() throws Exception {
final String testSrc = System.getProperty("test.src");
final String testClasses = System.getProperty("test.classes");
final String myClassName = getClass().getName();
final String mySrc = new File(testSrc, myClassName + ".java").getPath();
final int NUM_TESTS = 90; // #decls in this source file
for (int i = 1; i <= NUM_TESTS; i++) {
System.err.println("test " + i);
File testDir = new File("test" + i);
File classesDir = new File(testDir, "classes");
classesDir.mkdirs();
String[] args = {
"-d", classesDir.getPath(),
"-processorpath", testClasses,
"-processor", myClassName,
"-proc:only",
"-Atest=" + i,
"-Alast=" + (i == NUM_TESTS),
mySrc
};
// System.err.println("compile: " + Arrays.asList(args));
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
int rc = com.sun.tools.javac.Main.compile(args, pw);
pw.close();
String out = sw.toString();
if (out != null)
System.err.println(out);
if (rc != 0) {
System.err.println("compilation failed: rc=" + rc);
errors++;
}
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
int errors;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment)
{
if (roundEnvironment.processingOver())
return true;
Map<String,String> options = processingEnv.getOptions();
int test = Integer.parseInt(options.get("test"));
boolean _last = Boolean.parseBoolean(options.get("last"));
Trees trees = Trees.instance(processingEnv);
Scanner scanner = new Scanner(trees, _last);
int nelems = 0;
for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
nelems += scanner.scan(trees.getPath(e), test);
}
Messager m = processingEnv.getMessager();
int EXPECT = 1;
if (nelems != EXPECT) {
m.printMessage(Diagnostic.Kind.ERROR,
"Unexpected number of elements found: " + nelems + " expected: " + EXPECT);
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
class Scanner extends TreePathScanner<Integer,Integer> {
final Trees trees;
final boolean last;
int count;
Scanner(Trees trees, boolean last) {
this.trees = trees;
this.last = last;
}
@Override
public Integer visitClass(ClassTree tree, Integer test) {
return reduce(check(test), super.visitClass(tree, test));
}
@Override
public Integer visitMethod(MethodTree tree, Integer test) {
return reduce(check(test), super.visitMethod(tree, test));
}
@Override
public Integer visitVariable(VariableTree tree, Integer test) {
return reduce(check(test), super.visitVariable(tree, test));
}
@Override
public Integer reduce(Integer i1, Integer i2) {
if (i1 == null || i1.intValue() == 0)
return i2;
if (i2 == null || i2.intValue() == 0)
return i1;
return (i1 + i2);
}
int check(int test) {
count++;
if (count != test)
return 0;
TreePath p = getCurrentPath();
Element e = trees.getElement(p);
String text = p.getLeaf().toString().replaceAll("\\s+", " ").trim();
int MAXLEN = 40;
if (text.length() > MAXLEN)
text = text.substring(0, MAXLEN - 3) + "...";
System.err.println(String.format("%3d: %-" + MAXLEN + "s -- %s",
count, text,
(e == null ? "null" : e.getKind() + " " + e)));
Messager m = processingEnv.getMessager();
if (e == null) {
m.printMessage(Diagnostic.Kind.ERROR, "Null element found for " + text);
return 0;
}
if (last && !e.getSimpleName().contentEquals("last")) {
m.printMessage(Diagnostic.Kind.ERROR, "Unexpected name in last test: "
+ e.getSimpleName() + ", expected: last");
}
return 1;
}
}
// following are all fodder for the test
class MemberClass {
class NestedMemberClass { }
}
{
class InnerClassInInit { }
Object o = new Object() { };
}
TestGetElement(TestGetElement unused) {
class InnerClassInConstr { }
Object o = new Object() { };
}
void m() {
class InnerClassInMethod { }
Object o = new Object() { };
class C {
class MemberClass {
class NestedMemberClass { }
}
{
class InnerClassInInit { }
Object o = new Object() { };
}
C(Object unused) {
class InnerClassInConstr { }
Object o = new Object() { };
}
void m() {
class InnerClassInMethod { }
Object o = new Object() { };
}
}
}
int last; // this name is verified by the test to make sure that all decls are checked
}
| 7,484 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6430241.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6430241.java | /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6430241
* @summary Hard to disable symbol file feature through API
*/
import java.io.*;
import java.util.*;
import javax.tools.*;
import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.JavacTool;
public class T6430241 {
public static void main(String... args) throws Exception {
new T6430241().run();
}
void run() throws Exception {
setup();
testCommandLine();
testSimpleAPI();
testTaskAPI();
if (errors > 0)
throw new Exception(errors + " errors found");
}
void setup() throws Exception {
classesDir = new File("classes");
classesDir.mkdirs();
emptyDir = new File("empty");
emptyDir.mkdirs();
bootClassPath = System.getProperty("sun.boot.class.path");
File srcDir = new File("src");
String test = "import sun.misc.Unsafe; class Test { }";
testFile = writeFile(srcDir, "Test.java", test);
}
//----- tests for command line invocation
void testCommandLine() throws Exception {
testCommandLine(true);
testCommandLine(true, "-Xbootclasspath/p:" + emptyDir);
testCommandLine(false, "-Xbootclasspath:" + bootClassPath);
testCommandLine(true, "-Xbootclasspath/a:" + emptyDir);
testCommandLine(false, "-XDignore.symbol.file");
System.err.println();
}
void testCommandLine(boolean expectWarnings, String... opts) throws Exception {
System.err.println("test command line: " + Arrays.asList(opts));
String[] args = initArgs(opts);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
int rc = com.sun.tools.javac.Main.compile(args, pw);
String out = showOutput(sw.toString());
checkCompilationOK(rc);
checkOutput(out, expectWarnings);
}
//----- tests for simple API invocation
void testSimpleAPI() {
testSimpleAPI(true);
testSimpleAPI(true, "-Xbootclasspath/p:" + emptyDir);
testSimpleAPI(false, "-Xbootclasspath:" + bootClassPath);
testSimpleAPI(true, "-Xbootclasspath/a:" + emptyDir);
testSimpleAPI(false, "-XDignore.symbol.file");
System.err.println();
}
void testSimpleAPI(boolean expectWarnings, String... opts) {
System.err.println("test simple API: " + Arrays.asList(opts));
String[] args = initArgs(opts);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
JavacTool tool = JavacTool.create();
int rc = tool.run(null, null, ps, args);
String out = showOutput(baos.toString());
checkCompilationOK(rc);
checkOutput(out, expectWarnings);
}
//----- tests for CompilationTask API invocation
void testTaskAPI() throws Exception {
List<File> bcp = new ArrayList<File>();
for (String f: bootClassPath.split(File.pathSeparator)) {
if (!f.isEmpty())
bcp.add(new File(f));
}
testTaskAPI(true, null);
testTaskAPI(false, bcp);
System.err.println();
}
void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
System.err.println("test task API: " + pcp);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
if (pcp != null)
fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, null, null, null, files);
boolean ok = task.call();
String out = showOutput(sw.toString());
checkCompilationOK(ok);
checkOutput(out, expectWarnings);
}
//----- utility methods
/**
* Create a file with given content.
*/
File writeFile(File dir, String path, String content) throws IOException {
File f = new File(dir, path);
f.getParentFile().mkdirs();
FileWriter out = new FileWriter(f);
try {
out.write(content);
} finally {
out.close();
}
return f;
}
/**
* Initialize args for compilation with given opts.
* @return opts -d classesDir testFile
*/
String[] initArgs(String[] opts) {
List<String> args = new ArrayList<String>();
args.addAll(Arrays.asList(opts));
args.add("-d");
args.add(classesDir.getPath());
args.add(testFile.getPath());
return args.toArray(new String[args.size()]);
}
/**
* Show output from compilation if non empty.
*/
String showOutput(String out) {
if (!out.isEmpty())
System.err.println(out);
return out;
}
/**
* Verify compilation succeeeded.
*/
void checkCompilationOK(boolean ok) {
if (!ok)
error("compilation failed");
}
/**
* Verify compilation succeeeded.
*/
void checkCompilationOK(int rc) {
if (rc != 0)
error("compilation failed, rc: " + rc);
}
/**
* Check whether output contains warnings if and only if warnings
* are expected.
*/
void checkOutput(String out, boolean expectWarnings) {
boolean foundWarnings = out.contains("warning");
if (foundWarnings) {
if (!expectWarnings)
error("unexpected warnings found");
} else {
if (expectWarnings)
error("expected warnings not found");
}
}
/**
* Report an error.
*/
void error(String msg) {
System.err.println("error: " + msg);
errors++;
}
String bootClassPath;
File classesDir;
File emptyDir;
File testFile;
int errors;
}
| 7,847 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestJavacTask.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestJavacTask.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4813736
* @summary Provide a basic test of access to the Java Model from javac
* @author Peter von der Ah\u00e9
* @run main TestJavacTask TestJavacTask.java
*/
import com.sun.tools.javac.api.JavacTaskImpl;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import javax.lang.model.element.TypeElement;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
public class TestJavacTask {
static JavacTaskImpl getTask(JavaCompiler compiler, File... file) {
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
return (JavacTaskImpl)compiler.getTask(null, fm, null, null, null, files);
}
public static void main(String... args) throws IOException {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
String srcdir = System.getProperty("test.src");
File file = new File(srcdir, args[0]);
JavacTaskImpl task = getTask(tool, file);
for (TypeElement clazz : task.enter(task.parse()))
System.out.println(clazz.getSimpleName());
}
}
| 2,362 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestTrees.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestTrees.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6346249 6392177
* @summary new Trees API
*/
import com.sun.source.tree.*;
import com.sun.source.util.*;
import java.io.*;
import java.lang.annotation.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.tools.*;
import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeInfo;
@Anno
@SupportedAnnotationTypes("*")
public class TestTrees extends AbstractProcessor {
@Anno
void annoMethod() { }
@Anno
int annoField;
static final String testSrcDir = System.getProperty("test.src");
static final String testClassDir = System.getProperty("test.classes");
static final String self = TestTrees.class.getName();
static PrintWriter out = new PrintWriter(System.err, true);
public static void main(String[] args) throws IOException {
new TestTrees().run();
}
void run() throws IOException {
JavacTool tool = JavacTool.create();
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic d) {
error(d.toString());
}
};
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
Iterable<String> opts = Arrays.asList("-d", ".");
System.err.println("simple compilation, no processing");
JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
task.setTaskListener(new MyTaskListener(task));
if (!task.call())
throw new AssertionError("compilation failed");
opts = Arrays.asList("-d", ".", "-processorpath", testClassDir, "-processor", self);
System.err.println();
System.err.println("compilation with processing");
task = tool.getTask(out, fm, dl,opts, null, files);
if (!task.call())
throw new AssertionError("compilation failed");
if (errors > 0)
throw new AssertionError(errors + " errors occurred");
}
void testElement(Trees trees, Element e) {
trees.getClass();
e.getClass();
System.err.println("testElement: " + e);
Tree tree = trees.getTree(e);
//System.err.println(tree);
if (TreeInfo.symbolFor((JCTree)tree) != e)
error("bad result from getTree");
TreePath path = trees.getPath(e);
if (path == null) {
error("getPath returned null");
return;
}
if (path.getLeaf() != tree)
error("bad result from getPath");
Element e2 = trees.getElement(path);
if (e2 == null) {
error("getElement returned null");
return;
}
if (e2 != e)
error("bad result from getElement");
// The TypeMirror is not available yet when annotation processing;
// it is set up later during ANALYSE.
TypeMirror t = trees.getTypeMirror(path);
if (t != null && t.getKind() == TypeKind.DECLARED &&
((DeclaredType)t).asElement() != e2)
error("bad result from getTypeMirror");
for (AnnotationMirror m: e.getAnnotationMirrors()) {
testAnnotation(trees, e, m);
}
}
void testAnnotation(Trees trees, Element e, AnnotationMirror a) {
System.err.println("testAnnotation: " + e + " " + a);
Tree tree = trees.getTree(e, a);
if (tree.getKind() != Tree.Kind.ANNOTATION)
error("bad result from getTree");
TreePath path = trees.getPath(e, a);
if (path.getLeaf() != tree)
error("bad result from getPath");
}
void error(String msg) {
if (messager != null)
// annotation processing will happen in a separate instance/classloader
// so pass the message back to the calling instance.
messager.printMessage(Diagnostic.Kind.ERROR, msg);
else {
System.err.println(msg);
errors++;
}
}
Messager messager;
int errors;
public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
Trees trees = Trees.instance(processingEnv);
messager = processingEnv.getMessager();
for (Element e: rEnv.getRootElements()) {
testElement(trees, e);
}
for (TypeElement anno: annos) {
Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno);
System.err.println("anno: " + anno);
System.err.println("elts: " + elts);
if (elts != null) { // 6397298, should return empty set
for (Element e: rEnv.getElementsAnnotatedWith(anno))
testElement(trees, e);
}
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
class MyTaskListener implements TaskListener {
MyTaskListener(JavacTask task) {
this.task = task;
}
public void started(TaskEvent e) {
System.err.println("started " + e);
}
public void finished(TaskEvent e) {
//System.err.println("finished " + e);
switch (e.getKind()) {
case ANALYZE:
testElement(Trees.instance(task), e.getTypeElement());
break;
}
}
private final JavacTask task;
}
}
@Retention(RetentionPolicy.SOURCE)
@interface Anno {
}
| 6,857 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestGetTree.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestGetTree.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6344177 6392177
* @summary Can't get tree from a top level class
* @author Peter von der Ah\u00e9
* @compile TestGetTree.java
* @compile -processor TestGetTree -proc:only TestGetTree.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
import com.sun.source.tree.*;
import com.sun.source.util.Trees;
@SupportedAnnotationTypes("*")
public class TestGetTree extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment)
{
final Trees trees = Trees.instance(processingEnv);
for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
ClassTree node = trees.getTree(e);
System.out.println(node.toString());
}
return true;
}
}
| 2,015 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6437138.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6437138.java | /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6437138
* @summary JSR 199: Compiler doesn't diagnose crash in user code
*/
import java.net.URI;
import java.util.Arrays;
import javax.tools.*;
import static javax.tools.JavaFileObject.Kind.*;
public class T6437138 {
static class JFO extends SimpleJavaFileObject {
public JFO(URI uri, JavaFileObject.Kind kind) {
super(uri, kind);
}
// getCharContent not impl, will throw UnsupportedOperationException
}
public static void main(String... arg) throws Exception {
try {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
JavaFileObject jfo = new JFO(new URI("JFOTest04.java"),SOURCE);
JavaCompiler.CompilationTask ct = javac.getTask(null,null,null,null,
null, Arrays.asList(jfo));
ct.call();
throw new Exception("no exception thrown by JavaCompiler.CompilationTask");
} catch (RuntimeException e) {
if (e.getCause() instanceof UnsupportedOperationException) {
System.err.println("RuntimeException(UnsupportedOperationException) caught as expected");
return;
}
throw new Exception("unexpected exception caught", e);
}
}
}
| 2,338 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6358955.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6358955.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6358955
* @summary JavacFileManager.getFileForInput(dir) shuld throw IAE
*/
import java.io.File;
import java.net.URI;
import java.util.Arrays;
import javax.tools.*;
import static javax.tools.JavaFileObject.Kind.*;
public class T6358955 {
public static void main(String[] args) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
File dir = new File("temp" + args.hashCode());
if (!dir.exists())
dir.mkdir();
if (!dir.isDirectory())
throw new AssertionError("Not a directory " + dir);
try {
jfm.setLocation(StandardLocation.CLASS_OUTPUT,
Arrays.asList(dir.getCanonicalFile().getParentFile()));
try {
jfm.getFileForInput(StandardLocation.CLASS_OUTPUT, "", dir.getPath());
throw new AssertionError("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
System.out.println("OK: " + e.getLocalizedMessage());
}
try {
jfm.getJavaFileObjectsFromFiles(Arrays.asList(dir));
throw new AssertionError("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
System.out.println("OK: " + e.getLocalizedMessage());
}
} finally {
try {
dir.delete(); // cleanup
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
| 2,705 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6397104.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6397104.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6397104
* @summary JSR 199: JavaFileManager.getFileForOutput should have sibling argument
* @author Peter von der Ah\u00e9
*/
import java.io.File;
import java.net.URI;
import java.util.Arrays;
import javax.tools.*;
import javax.tools.JavaFileManager.Location;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
public class T6397104 {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
void test(StandardJavaFileManager fm,
Location location,
File siblingFile,
String relName,
String expectedPath)
throws Exception
{
JavaFileObject sibling = siblingFile == null
? null
: fm.getJavaFileObjectsFromFiles(Arrays.asList(siblingFile)).iterator().next();
FileObject fileObject =
fm.getFileForOutput(location, "java.lang", relName, sibling);
File expectedFile = new File(expectedPath).getCanonicalFile();
File fileObjectFile = new File(fileObject.toUri()).getCanonicalFile();
if (!fileObjectFile.equals(expectedFile))
throw new AssertionError("Expected " + expectedFile +
", got " + fileObjectFile);
System.out.format("OK: (%s, %s) => %s%n", siblingFile, relName, fileObjectFile);
}
void test(boolean hasLocation, File siblingFile, String relName, String expectedPath)
throws Exception
{
StandardJavaFileManager fm;
if (hasLocation) {
for (Location location : StandardLocation.values()) {
fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(location, Arrays.asList(new File(".")));
test(fm, location, siblingFile, relName, expectedPath);
}
} else {
fm = tool.getStandardFileManager(null, null, null);
test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
}
}
public static void main(String... args) throws Exception {
T6397104 tester = new T6397104();
tester.test(false,
new File(new File("foo", "bar"), "baz.java"),
"qux/baz.xml",
"foo/bar/baz.xml");
tester.test(false,
null,
"qux/baz.xml",
"baz.xml"); // sb "java/lang/qux/baz.xml"
tester.test(true,
new File(new File("foo", "bar"), "baz.java"),
"qux/baz.xml",
"./java/lang/qux/baz.xml");
tester.test(true,
null,
"qux/baz.xml",
"./java/lang/qux/baz.xml");
}
}
| 3,779 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6306137.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6306137.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6306137
* @summary JSR 199: encoding option doesn't affect standard file manager
* @author Peter von der Ahé
* @ignore
* Need to make the contentCache in JavacFileManager be aware of changes to the encoding.
* Need to propogate -source (and -encoding?) down to the JavacFileManager
*/
import java.io.File;
import java.util.Arrays;
import javax.tools.*;
public class T6306137 {
boolean error;
final StandardJavaFileManager fm;
final JavaCompiler compiler;
Iterable<? extends JavaFileObject> files;
DiagnosticListener<JavaFileObject> dl;
T6306137() {
dl = new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic<? extends JavaFileObject> message) {
if (message.getKind() == Diagnostic.Kind.ERROR)
error = true;
System.out.println(message.getSource()
+":"+message.getStartPosition()+":"
+message.getStartPosition()+":"+message.getPosition());
System.out.println(message.toString());
System.out.format("Found problem: %s%n", message.getCode());
System.out.flush();
}
};
compiler = ToolProvider.getSystemJavaCompiler();
fm = compiler.getStandardFileManager(dl, null, null);
String srcdir = System.getProperty("test.src");
files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6306137.java")));
}
void test(String encoding, boolean good) {
error = false;
Iterable<String> args = Arrays.asList("-source", "6", "-encoding", encoding, "-d", ".");
compiler.getTask(null, fm, dl, args, null, files).call();
if (error == good) {
if (error) {
throw new AssertionError("Error reported");
} else {
throw new AssertionError("No error reported");
}
}
}
public static void main(String[] args) {
T6306137 self = new T6306137();
self.test("utf-8", true);
self.test("ascii", false);
self.test("utf-8", true);
}
}
| 3,306 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6501502.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6501502.java | /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6501502 6877206 6483788
* @summary JSR 199: FileObject.toUri should return file:///c:/ or file:/c:/ not file://c:/
*/
import java.io.*;
import java.net.URI;
import javax.tools.*;
public class T6501502 {
public static void main(String... args) throws Exception {
new T6501502().run();
}
// The spec for java.io.File includes the following:
// For a given abstract pathname f it is guaranteed that
// new File( f.toURI()).equals( f.getAbsoluteFile())
// For JavaFileObject we test as follows:
// new File( CONVERT_TO_FILEOBJECT(f).toURI()).equals( f.getAbsoluteFile())
// to verify that we get reasonable URIs returned from toURI.
// To make this a general test, and not just a Windows test,
// we test a number of platform-independent paths.
void run() throws Exception {
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
fm = c.getStandardFileManager(null, null, null);
System.err.println(System.getProperties());
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File testSrcDir = new File(System.getProperty("test.src"));
File testClassesDir = new File(System.getProperty("test.classes"));
test(new File("abc.tmp"));
test(new File(tmpDir, "bad.file"));
test(new File(testSrcDir, "T6501501.java"));
test(new File(testClassesDir, "T6501501.class"));
test(new File("a b"));
}
void test(File f) throws Exception {
System.err.println("test " + f);
FileObject fo = fm.getJavaFileObjects(f).iterator().next();
URI uri = fo.toUri();
System.err.println("FileObject uri: " + uri);
if (!new File(uri).equals(f.getAbsoluteFile()))
throw new Exception("unexpected URI returned");
}
StandardJavaFileManager fm;
}
| 2,925 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6392782.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6392782.java | /*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6392782
* @summary TreeScanner.visitImport returns null, not result of nested scan
*/
import java.io.*;
import java.util.*;
import javax.tools.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
public class T6392782 {
public static void main(String... args) throws IOException {
String testSrc = System.getProperty("test.src", ".");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends Tree> trees = task.parse();
TreeScanner<Integer,Void> scanner = new MyScanner();
check(scanner, 6, scanner.scan(trees, null));
CountNodes nodeCounter = new CountNodes();
// 359 nodes with the regular parser; 360 nodes with EndPosParser
// We automatically switch to EndPosParser when calling JavacTask.parse()
check(nodeCounter, 360, nodeCounter.scan(trees, null));
CountIdentifiers idCounter = new CountIdentifiers();
check(idCounter, 107, idCounter.scan(trees, null));
}
private static void check(TreeScanner<?,?> scanner, int expect, int found) {
if (found != expect)
throw new AssertionError(scanner.getClass().getName() + ": expected: " + expect + " found: " + found);
}
static class MyScanner extends TreeScanner<Integer,Void> {
@Override
public Integer visitImport(ImportTree tree, Void ignore) {
//System.err.println(tree);
return 1;
}
@Override
public Integer reduce(Integer i1, Integer i2) {
return (i1 == null ? 0 : i1) + (i2 == null ? 0 : i2);
}
}
static class CountNodes extends TreeScanner<Integer,Void> {
@Override
public Integer scan(Tree node, Void p) {
if (node == null)
return 0;
Integer n = super.scan(node, p);
return (n == null ? 0 : n) + 1;
}
@Override
public Integer reduce(Integer r1, Integer r2) {
return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
}
}
// example from TreeScanner javadoc
static class CountIdentifiers extends TreeScanner<Integer,Void> {
@Override
public Integer visitIdentifier(IdentifierTree node, Void p) {
return 1;
}
@Override
public Integer reduce(Integer r1, Integer r2) {
return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
}
}
}
| 3,851 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6877206.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6877206.java | /*
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6877206
* @summary JavaFileObject.toUri returns bogus URI (win)
*/
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.jar.*;
import java.util.zip.*;
import javax.tools.*;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
// Test URIs returned from JavacFileManager and its support classes.
// For a variety of file objects, verify the validity of FileObject.toUri()
// by verifying the URI exists and points to the same contents as the file
// object itself
public class T6877206 {
public static void main(String... args) throws Exception {
new T6877206().run();
}
Set<String> foundClasses = new TreeSet<String>();
Set<String> foundJars = new TreeSet<String>();
void run() throws Exception {
File rt_jar = findRtJar();
// names for entries to be created in directories and jar files
String[] entries = { "p/A.class", "p/resources/A-1.jpg" };
// test various combinations of directories and jar files, intended to
// cover all sources of URIs within JavacFileManager's support classes
test(createFileManager(), createDir("dir", entries), "p", entries.length);
test(createFileManager(), createDir("a b/dir", entries), "p", entries.length);
for (boolean useOptimizedZip: new boolean[] { false, true }) {
test(createFileManager(useOptimizedZip), createJar("jar", entries), "p", entries.length);
test(createFileManager(useOptimizedZip), createJar("jar jar", entries), "p", entries.length);
for (boolean useSymbolFile: new boolean[] { false, true }) {
test(createFileManager(useOptimizedZip, useSymbolFile), rt_jar, "java.lang.ref", -1);
}
}
// Verify that we hit all the impl classes we intended
checkCoverage("classes", foundClasses,
"RegularFileObject", "SymbolFileObject", "ZipFileIndexFileObject", "ZipFileObject");
// Verify that we hit the jar files we intended, specifically ct.sym as well as rt.jar
checkCoverage("jar files", foundJars,
"ct.sym", "jar", "jar jar", "rt.jar");
}
// use a new file manager for each test
void test(StandardJavaFileManager fm, File f, String pkg, int expect) throws Exception {
JarURLConnection c;
System.err.println("Test " + f);
try {
fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(f));
int count = 0;
for (JavaFileObject fo: fm.list(StandardLocation.CLASS_PATH,
pkg, EnumSet.allOf(JavaFileObject.Kind.class), true)) {
System.err.println("checking " + fo);
// record the file object class name for coverage checks later
foundClasses.add(fo.getClass().getSimpleName());
testFileObject(fo);
count++;
}
if (expect > 0 && count != expect)
throw new Exception("wrong number of entries found: "
+ count + ", expected " + expect);
} finally {
fm.close();
}
}
void testFileObject(JavaFileObject fo) throws Exception {
// test the validity of the result of toUri() by using URLConnection
// and comparing the results of reading from the connection with the
// result of reading from the file object directly.
URI uri = fo.toUri();
System.err.println("uri: " + uri);
URLConnection urlconn = uri.toURL().openConnection();
if (urlconn instanceof JarURLConnection) {
JarURLConnection jarconn = (JarURLConnection) urlconn;
File f = new File(jarconn.getJarFile().getName());
// record access to the jar file for coverage checks later
foundJars.add(f.getName());
}
try {
byte[] uriData = read(urlconn.getInputStream());
byte[] foData = read(fo.openInputStream());
if (!Arrays.equals(uriData, foData)) {
if (uriData.length != foData.length)
throw new Exception("data size differs: uri data "
+ uriData.length + " bytes, fo data " + foData.length+ " bytes");
for (int i = 0; i < uriData.length; i++) {
if (uriData[i] != foData[i])
throw new Exception("unexpected data returned at offset " + i
+ ", uri data " + uriData[i] + ", fo data " + foData[i]);
}
throw new AssertionError("cannot find difference");
}
} finally {
// In principle, simply closing the result of urlconn.getInputStream()
// should have been sufficient. But the internal JarURLConnection
// does not close the JarFile in an expeditious manner, thus preventing
// jtreg from deleting the jar file before starting the next test.
// Therefore we force access to the JarURLConnection to close the
// JarFile when necessary.
if (urlconn instanceof JarURLConnection) {
JarURLConnection jarconn = (JarURLConnection) urlconn;
jarconn.getJarFile().close();
}
}
}
void checkCoverage(String label, Set<String> found, String... expect) throws Exception {
Set<String> e = new TreeSet<String>(Arrays.asList(expect));
if (!found.equals(e)) {
e.removeAll(found);
throw new Exception("expected " + label + " not used: " + e);
}
}
JavacFileManager createFileManager() {
return createFileManager(false, false);
}
JavacFileManager createFileManager(boolean useOptimizedZip) {
return createFileManager(useOptimizedZip, false);
}
JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) {
Context ctx = new Context();
Options options = Options.instance(ctx);
options.put("useOptimizedZip", Boolean.toString(useOptimizedZip));
if (!useSymbolFile) {
options.put("ignore.symbol.file", "true");
}
return new JavacFileManager(ctx, false, null);
}
File createDir(String name, String... entries) throws Exception {
File dir = new File(name);
if (!dir.mkdirs())
throw new Exception("cannot create directories " + dir);
for (String e: entries) {
writeFile(new File(dir, e), e);
}
return dir;
}
File createJar(String name, String... entries) throws IOException {
File jar = new File(name);
OutputStream out = new FileOutputStream(jar);
try {
JarOutputStream jos = new JarOutputStream(out);
for (String e: entries) {
jos.putNextEntry(new ZipEntry(e));
jos.write(e.getBytes());
}
jos.close();
} finally {
out.close();
}
return jar;
}
File findRtJar() throws Exception {
File java_home = new File(System.getProperty("java.home"));
if (java_home.getName().equals("jre"))
java_home = java_home.getParentFile();
File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar");
if (!rt_jar.exists())
throw new Exception("can't find rt.jar");
return rt_jar;
}
byte[] read(InputStream in) throws IOException {
byte[] data = new byte[1024];
int offset = 0;
try {
int n;
while ((n = in.read(data, offset, data.length - offset)) != -1) {
offset += n;
if (offset == data.length)
data = Arrays.copyOf(data, 2 * data.length);
}
} finally {
in.close();
}
return Arrays.copyOf(data, offset);
}
void writeFile(File f, String s) throws IOException {
f.getParentFile().mkdirs();
FileWriter out = new FileWriter(f);
try {
out.write(s);
} finally {
out.close();
}
}
}
| 9,342 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestResolveIdent.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestResolveIdent.java | /*
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6374357 6308351
* @summary PackageElement.getEnclosedElements() throws ClassReader$BadClassFileException
* @author Peter von der Ah\u00e9
* @run main TestResolveIdent
*/
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.JavaCompiler;
import java.io.File;
import java.io.IOException;
import javax.lang.model.element.TypeElement;
import javax.tools.ToolProvider;
public class TestResolveIdent {
@SuppressWarnings("deprecation")
static Class<?> getDeprecatedClass() {
return java.io.StringBufferInputStream.class;
}
public static void main(String[] args) throws IOException {
javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);
JavaCompiler compiler = JavaCompiler.instance(task.getContext());
System.out.println(compiler.resolveIdent(getDeprecatedClass().getCanonicalName()));
}
}
| 2,114 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6345974.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6345974.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6345974
* @summary JCPrimitiveTypeTree.getPrimitiveTypeKind() inappropriately throws an
* AssertionError for "void"
*/
import com.sun.tools.javac.api.JavacTool;
import java.io.File;
import java.io.PrintWriter;
import java.util.Arrays;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.PrimitiveTypeTree;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TreeScanner;
import javax.tools.StandardJavaFileManager;
public class T6345974 {
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
private static class Scanner extends TreeScanner<Void,Void> {
public Void visitPrimitiveType(PrimitiveTypeTree node, Void ignore) {
// The following call of getPrimitiveTypeKind should not throw an AssertionError
System.out.println(node + " " + node.getPrimitiveTypeKind());
return null;
}
}
boolean b;
byte by;
char c;
double d;
float f;
int i;
long l;
short s;
void f() { }
}
| 2,846 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6265137.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6265137.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6265137
* @summary setOption() and setExtendedOption() of JavacTool will throw exception for some defined options
* @author Peter von der Ah\u00e9
*/
import java.io.File;
import java.util.Arrays;
import javax.tools.*;
public class T6265137 {
public static void main(String... args) {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic<? extends JavaFileObject> message) {
System.out.println(message.getSource()
+":"+message.getStartPosition()+":"
+message.getStartPosition()+":"+message.getPosition());
System.out.println(message.toString());
System.out.format("Found problem: %s%n", message.getCode());
System.out.flush();
}
};
StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
String srcdir = System.getProperty("test.src");
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6265137a.java")));
javac.getTask(null, fm, dl, Arrays.asList("-target","1.5"), null, files).call();
}
}
| 2,439 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6358786.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6358786.java | /*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6358786
* @summary Doccomments are not returned from Tree API
* @author Peter von der Ah\u00e9
* @run main T6358786 T6358786.java
*/
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.file.JavacFileManager;
import java.util.Arrays;
import javax.lang.model.util.Elements;
import java.io.*;
import javax.lang.model.element.TypeElement;
import javax.tools.*;
/**
* Tests that doccomments are available from the Tree API.
*/
public class T6358786 {
public static void main(String... args) throws IOException {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
String srcdir = System.getProperty("test.src");
File file = new File(srcdir, args[0]);
JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file)));
Elements elements = task.getElements();
for (TypeElement clazz : task.enter(task.parse())) {
String doc = elements.getDocComment(clazz);
if (doc == null)
throw new AssertionError(clazz.getSimpleName() + ": no doc comment");
System.out.format("%s: %s%n", clazz.getSimpleName(), doc);
}
}
}
| 2,385 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestResolveError.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestResolveError.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6930108
* @summary IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.java
* @library ./lib
* @build ToolTester
* @run main TestResolveError
*/
import java.io.*;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.tools.*;
import com.sun.tools.javac.api.JavacTaskImpl;
/*
* This is a cut down version of TestJavacTaskScanner, which as originally written
* caused an IllegalArgumentException in AbstractDiagnosticFormatter as a result
* of calling task.parseType with a name whose resolution depended on the setting
* of the bootclasspath.
* This test has the same call, task.parseType("List<String>", clazz), but checks
* that the error is handled in a reasonable way by javac.
*/
public class TestResolveError extends ToolTester {
public static void main(String... args) throws Exception {
new TestResolveError().run();
}
void run() throws Exception {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
File file = new File(test_src, "TestResolveError.java");
final Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjects(new File[] {file});
task = (JavacTaskImpl)tool.getTask(pw, fm, null, null, null, compilationUnits);
elements = task.getElements();
types = task.getTypes();
Iterable<? extends TypeElement> toplevels;
try {
toplevels = task.enter(task.parse());
} catch (IOException ex) {
throw new AssertionError(ex);
}
for (TypeElement clazz : toplevels) {
System.out.format("Testing %s:%n%n", clazz.getSimpleName());
// this should not cause any exception from the compiler,
// such as IllegalArgumentException
testParseType(clazz);
}
pw.close();
String out = sw.toString();
System.out.println(out);
if (out.contains("com.sun.tools.javac.util"))
throw new Exception("Unexpected output from compiler");
}
void testParseType(TypeElement clazz) {
DeclaredType type = (DeclaredType)task.parseType("List<String>", clazz);
for (Element member : elements.getAllMembers((TypeElement)type.asElement())) {
TypeMirror mt = types.asMemberOf(type, member);
System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt);
}
}
JavacTaskImpl task;
Elements elements;
Types types;
}
| 3,809 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestJavacTask_ParseAttrGen.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestJavacTask_ParseAttrGen.java | /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7026509
* @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
*/
import java.io.*;
import java.util.*;
import javax.lang.model.element.*;
import javax.tools.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
public class TestJavacTask_ParseAttrGen {
public static void main(String... args) throws Exception {
new TestJavacTask_ParseAttrGen().run();
}
JavaCompiler comp;
StandardJavaFileManager fm;
void run() throws Exception {
comp = ToolProvider.getSystemJavaCompiler();
fm = comp.getStandardFileManager(null, null, null);
final boolean[] booleanValues = { false, true };
for (boolean pk: booleanValues) {
for (boolean ak: booleanValues) {
for (boolean gk: booleanValues) {
test(pk, ak, gk);
}
}
}
}
void test(boolean pk, boolean ak, boolean gk) throws Exception {
if (!pk && !ak && !gk) // nothing to do
return;
System.err.println("test: pk:" + pk + ", ak:" + ak + ", gk: " + gk);
File testSrc = new File(System.getProperty("test.src"));
String thisClassName = TestJavacTask_ParseAttrGen.class.getName();
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java"));
File tmpDir = new File((pk ? "p" : "") + (ak ? "a" : "") + (gk ? "g" : ""));
tmpDir.mkdirs();
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir));
JavacTask t = (JavacTask) comp.getTask(null, fm, null, null, null, files);
//t.setTaskListener(createTaskListener());
try {
if (pk) {
Iterable<? extends CompilationUnitTree> trees = t.parse();
System.err.println(count(trees) + " trees parsed");
}
if (ak) {
Iterable<? extends Element> elems = t.analyze();
System.err.println(count(elems) + " elements analyzed");
}
if (gk) {
Iterable<? extends JavaFileObject> classfiles = t.generate();
System.err.println(count(classfiles) + " class files generated");
}
} catch (IOException e) {
error("unexpected exception caught: " + e);
}
File[] genFiles = tmpDir.listFiles();
int expect = (gk ? 2 : 0); // main class and anon class for TaskListener
if (genFiles.length != expect)
error("unexpected number of files generated: " + genFiles.length
+ ", expected: " + expect);
System.err.println();
}
TaskListener createTaskListener() {
return new TaskListener() {
public void started(TaskEvent e) {
System.err.println(e + " started");
}
public void finished(TaskEvent e) {
System.err.println(e + " finished");
}
};
}
<T> int count(Iterable<T> items) {
int count = 0;
for (T item: items)
count++;
return count;
}
void error(String msg) {
System.err.println("Error: " + msg);
errors++;
}
int errors;
}
| 4,372 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6431879.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6431879.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6431879
* @summary TreePathSCanner(CompilationUnitTree tree, P p) overloading forces use of most specific type
*/
import java.io.*;
import java.util.*;
import javax.tools.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
public class T6431879 {
public static void main(String... args) throws IOException {
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes", ".");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6431879.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends CompilationUnitTree> trees = task.parse();
TreeScanner<Void,Trees> dependencyScanner = new DependencyScanner();
Trees treeUtil = Trees.instance(task);
for (CompilationUnitTree unit : trees) {
//System.err.println("scan " + unit);
dependencyScanner.scan(unit, treeUtil);
}
}
private static class DependencyScanner<R,P> extends TreePathScanner<R,P> {
public R visitIdentifier(IdentifierTree tree, P p) {
//System.err.println(tree);
return null;
}
}
}
| 2,517 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6258271.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6258271.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6258271
* @summary DiagnosticMessage exposes internal name __input
* @author Peter von der Ah\u00e9
*/
import java.io.*;
import java.util.Arrays;
import javax.tools.*;
public class T6258271 {
public static void main(String... args) {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic<? extends JavaFileObject> message) {
JavaFileObject fo = message.getSource();
if ("__input".equals(fo.toUri().getPath()))
throw new AssertionError(fo);
System.out.println(message);
}
};
StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromStrings(Arrays.asList("nofile.java"));
javac.getTask(null, fm, dl, null, null, files).call();
}
}
| 2,110 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestTreePath.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestTreePath.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6473148
* @summary TreePath.iterator() throws NPE
*/
import java.io.*;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import com.sun.source.tree.Tree;
import com.sun.source.util.*;
@SupportedAnnotationTypes("*")
public class TestTreePath extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
final Trees trees = Trees.instance(this.processingEnv);
for (Element element : ElementFilter.typesIn(roundEnv.getRootElements())) {
checkTreePath(trees, element, 2);
for (Element member : element.getEnclosedElements())
checkTreePath(trees, member, 3);
}
return true;
}
private void checkTreePath(Trees trees, Element element, int expectedLength) {
TreePath path = trees.getPath(element);
assert path != null;
int enhancedLength = 0;
for (Tree tree : path)
++enhancedLength;
if (enhancedLength != expectedLength)
throw new RuntimeException("found path length is wrong");
int normalLoopLength = 0;
Iterator<Tree> iter = path.iterator();
while (iter.hasNext()) {
iter.next();
++normalLoopLength;
}
if (normalLoopLength != expectedLength)
throw new RuntimeException("found path length is wrong");
TreePath curr = path;
// using getParent
int whileLoopLength = 0;
while (curr != null) {
++whileLoopLength;
curr = curr.getParentPath();
}
if (whileLoopLength != expectedLength)
throw new RuntimeException("found path length is wrong");
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
File writeTestFile() throws IOException {
File f = new File("Test.java");
PrintWriter out = new PrintWriter(new FileWriter(f));
out.println("class Test { void method() { } }");
out.close();
return f;
}
public void run() throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager
= compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> tests
= fileManager.getJavaFileObjects(writeTestFile());
JavaCompiler.CompilationTask task =
ToolProvider.getSystemJavaCompiler().getTask(
null, null, null,
Arrays.asList("-processor", this.getClass().getName()), null,
tests);
task.call();
}
public static void main(String[] args) throws IOException {
new TestTreePath().run();
}
}
| 4,267 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestJavacTask_Multiple.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestJavacTask_Multiple.java | /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7026509
* @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
*/
import java.io.*;
import java.util.*;
import javax.tools.*;
import javax.tools.JavaCompiler.CompilationTask;
import com.sun.source.util.*;
public class TestJavacTask_Multiple {
public static void main(String... args) throws Exception {
new TestJavacTask_Multiple().run();
}
final int MAX_TASKS = 3;
enum TestKind {
CALL {
int test(CompilationTask t) {
boolean ok = t.call();
if (!ok)
throw new Error("compilation failed");
return 1;
}
},
PARSE {
int test(CompilationTask t) {
try {
((JavacTask) t).parse();
return 1;
} catch (IOException ex) {
throw new Error(ex);
}
}
};
abstract int test(CompilationTask t);
}
int count;
void run() throws Exception {
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
for (TestKind tk: TestKind.values()) {
test(comp, fm, tk);
}
int expect = TestKind.values().length * MAX_TASKS;
if (count != expect) {
throw new Exception("Unexpected number of tests completed: " + count
+ ", expected: " + expect);
}
}
void test(JavaCompiler comp, StandardJavaFileManager fm, TestKind tk) {
System.err.println("test " + tk);
File testSrc = new File(System.getProperty("test.src"));
String thisClassName = TestJavacTask_Multiple.class.getName();
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java"));
List<CompilationTask> tasks = new ArrayList<CompilationTask>();
for (int i = 1; i <= MAX_TASKS; i++) {
File tmpDir = new File(tk + "_" + i);
tmpDir.mkdirs();
List<String> options = Arrays.asList( "-d", tmpDir.getPath() );
CompilationTask t = comp.getTask(null, fm, null, options, null, files);
((JavacTask) t).setTaskListener(createTaskListener(tk, i));
tasks.add(t);
}
for (CompilationTask t: tasks)
count += tk.test(t);
System.err.println();
}
TaskListener createTaskListener(final TestKind tk, final int i) {
return new TaskListener() {
public void started(TaskEvent e) {
System.err.println(tk + "." + i + ": " + e + " started");
}
public void finished(TaskEvent e) {
System.err.println(tk + "." + i + ": " + e + " finished");
}
};
}
}
| 3,979 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6395981.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6395981.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6395981 6458819
* @summary JavaCompilerTool and Tool must specify version of JLS and JVMS
* @author Peter von der Ah\u00e9
* @run main/fail T6395981
* @run main/fail T6395981 RELEASE_3 RELEASE_5 RELEASE_6
* @run main/fail T6395981 RELEASE_0 RELEASE_1 RELEASE_2 RELEASE_3 RELEASE_4 RELEASE_5 RELEASE_6
* @run main T6395981 RELEASE_3 RELEASE_4 RELEASE_5 RELEASE_6 RELEASE_7
*/
import java.util.EnumSet;
import java.util.Set;
import javax.lang.model.SourceVersion;
import javax.tools.Tool;
import javax.tools.ToolProvider;
import static javax.lang.model.SourceVersion.*;
public class T6395981 {
public static void main(String... args) {
Tool compiler = ToolProvider.getSystemJavaCompiler();
Set<SourceVersion> expected = EnumSet.noneOf(SourceVersion.class);
for (String arg : args)
expected.add(SourceVersion.valueOf(arg));
Set<SourceVersion> found = compiler.getSourceVersions();
Set<SourceVersion> notExpected = EnumSet.copyOf(found);
for (SourceVersion version : expected) {
if (!found.contains(version))
throw new AssertionError("Expected source version not found: " + version);
else
notExpected.remove(version);
}
if (!notExpected.isEmpty())
throw new AssertionError("Unexpected source versions: " + notExpected);
}
}
| 2,458 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6400205.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6400205.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6400205
* @summary getClassLoader(location) returns null if getLocation(location) returns null
* @author Peter von der Ah\u00e9
*/
import javax.tools.*;
import static javax.tools.StandardLocation.*;
public class T6400205 {
public static void main(String... args) {
JavaFileManager fm =
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
try {
fm.getClassLoader(null);
throw new AssertionError("NullPointerException not thrown");
} catch (NullPointerException e) {
// expected result
}
ClassLoader cl = fm.getClassLoader(locationFor("bogus"));
if (cl != null)
throw new AssertionError("non-null class loader for bogus location");
System.err.println("Test PASSED.");
}
}
| 1,903 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6265137a.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6265137a.java | /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class
| 1,058 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6483788.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6483788.java | /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6483788
* @summary DefaultFileManager.ZipFileObject.toUri() fails to escape space characters
*/
import java.io.*;
import java.net.*;
import java.util.Collections;
import java.util.jar.*;
import java.util.zip.*;
import javax.tools.*;
public class T6483788 {
public static void main(String[] args) throws Exception {
new T6483788().run();
}
void run() throws Exception {
File jar = createJar();
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(jar));
JavaFileObject fo = fm.getJavaFileForInput(StandardLocation.CLASS_PATH, "dummy", JavaFileObject.Kind.CLASS);
System.err.println("file: " + fo);
URI uri = fo.toUri();
System.err.println("uri: " + uri);
if (uri.toString().contains(" "))
throw new Exception("unexpected space character found");
}
File createJar() throws IOException {
byte[] dummy_data = new byte[10];
File f = new File("a b.jar");
OutputStream out = new FileOutputStream(f);
try {
JarOutputStream jar = new JarOutputStream(out);
jar.putNextEntry(new ZipEntry("dummy.class"));
jar.write(dummy_data);
jar.close();
} finally {
out.close();
}
return f;
}
}
| 2,523 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestOperators.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestOperators.java | /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6338064 6346249 6340951 6392177
* @summary Tree API: can't determine kind of operator
* @author Peter von der Ah\u00e9
* @compile TestOperators.java
* @compile -processor TestOperators -proc:only TestOperators.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.tools.Diagnostic.Kind.*;
import com.sun.source.tree.*;
import com.sun.source.util.Trees;
import static com.sun.source.tree.Tree.Kind.*;
@interface TestMe {
Tree.Kind value();
}
@SupportedAnnotationTypes("TestMe")
public class TestOperators extends AbstractProcessor {
@TestMe(POSTFIX_INCREMENT)
public int test_POSTFIX_INCREMENT(int i) {
return i++;
}
@TestMe(POSTFIX_DECREMENT)
public int test_POSTFIX_DECREMENT(int i) {
return i--;
}
@TestMe(PREFIX_INCREMENT)
public int test_PREFIX_INCREMENT(int i) {
return ++i;
}
@TestMe(PREFIX_DECREMENT)
public int test_PREFIX_DECREMENT(int i) {
return --i;
}
@TestMe(UNARY_PLUS)
public int test_UNARY_PLUS(int i) {
return +i;
}
@TestMe(UNARY_MINUS)
public int test_UNARY_MINUS(int i) {
return -i;
}
@TestMe(BITWISE_COMPLEMENT)
public int test_BITWISE_COMPLEMENT(int i) {
return ~i;
}
@TestMe(LOGICAL_COMPLEMENT)
public boolean test_LOGICAL_COMPLEMENT(boolean b) {
return !b;
}
@TestMe(MULTIPLY)
public int test_MULTIPLY(int i, int j) {
return i * j;
}
@TestMe(DIVIDE)
public int test_DIVIDE(int i, int j) {
return i / j;
}
@TestMe(REMAINDER)
public int test_REMAINDER(int i, int j) {
return i % j;
}
@TestMe(PLUS)
public int test_PLUS(int i, int j) {
return i + j;
}
@TestMe(MINUS)
public int test_MINUS(int i, int j) {
return i - j;
}
@TestMe(LEFT_SHIFT)
public int test_LEFT_SHIFT(int i, int j) {
return i << j;
}
@TestMe(RIGHT_SHIFT)
public int test_RIGHT_SHIFT(int i, int j) {
return i >> j;
}
@TestMe(UNSIGNED_RIGHT_SHIFT)
public int test_UNSIGNED_RIGHT_SHIFT(int i, int j) {
return i >>> j;
}
@TestMe(LESS_THAN)
public boolean test_LESS_THAN(int i, int j) {
return i < j;
}
@TestMe(GREATER_THAN)
public boolean test_GREATER_THAN(int i, int j) {
return i > j;
}
@TestMe(LESS_THAN_EQUAL)
public boolean test_LESS_THAN_EQUAL(int i, int j) {
return i <= j;
}
@TestMe(GREATER_THAN_EQUAL)
public boolean test_GREATER_THAN_EQUAL(int i, int j) {
return i >= j;
}
@TestMe(EQUAL_TO)
public boolean test_EQUAL_TO(int i, int j) {
return i == j;
}
@TestMe(NOT_EQUAL_TO)
public boolean test_NOT_EQUAL_TO(int i, int j) {
return i != j;
}
@TestMe(AND)
public boolean test_AND(boolean a, boolean b) {
return a & b;
}
@TestMe(XOR)
public boolean test_XOR(boolean a, boolean b) {
return a ^ b;
}
@TestMe(OR)
public boolean test_OR(boolean a, boolean b) {
return a | b;
}
@TestMe(CONDITIONAL_AND)
public boolean test_CONDITIONAL_AND(boolean a, boolean b) {
return a && b;
}
@TestMe(CONDITIONAL_OR)
public boolean test_CONDITIONAL_OR(boolean a, boolean b) {
return a || b;
}
@TestMe(MULTIPLY_ASSIGNMENT)
public int test_MULTIPLY_ASSIGNMENT(int i, int j) {
return i *= j;
}
@TestMe(DIVIDE_ASSIGNMENT)
public int test_DIVIDE_ASSIGNMENT(int i, int j) {
return i /= j;
}
@TestMe(REMAINDER_ASSIGNMENT)
public int test_REMAINDER_ASSIGNMENT(int i, int j) {
return i %= j;
}
@TestMe(PLUS_ASSIGNMENT)
public int test_PLUS_ASSIGNMENT(int i, int j) {
return i += j;
}
@TestMe(MINUS_ASSIGNMENT)
public int test_MINUS_ASSIGNMENT(int i, int j) {
return i -= j;
}
@TestMe(LEFT_SHIFT_ASSIGNMENT)
public int test_LEFT_SHIFT_ASSIGNMENT(int i, int j) {
return i <<= j;
}
@TestMe(RIGHT_SHIFT_ASSIGNMENT)
public int test_RIGHT_SHIFT_ASSIGNMENT(int i, int j) {
return i >>= j;
}
@TestMe(UNSIGNED_RIGHT_SHIFT_ASSIGNMENT)
public int test_UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(int i, int j) {
return i >>>= j;
}
@TestMe(AND_ASSIGNMENT)
public boolean test_AND_ASSIGNMENT(boolean a, boolean b) {
return a &= b;
}
@TestMe(XOR_ASSIGNMENT)
public boolean test_XOR_ASSIGNMENT(boolean a, boolean b) {
return a ^= b;
}
@TestMe(OR_ASSIGNMENT)
public boolean test_OR_ASSIGNMENT(boolean a, boolean b) {
return a |= b;
}
@TestMe(INT_LITERAL)
public Object test_INT_LITERAL() {
return 0;
}
@TestMe(LONG_LITERAL)
public Object test_LONG_LITERAL() {
return 0L;
}
@TestMe(FLOAT_LITERAL)
public Object test_FLOAT_LITERAL() {
return 0.0F;
}
@TestMe(DOUBLE_LITERAL)
public Object test_DOUBLE_LITERAL() {
return 0.0;
}
@TestMe(BOOLEAN_LITERAL)
public Object test_BOOLEAN_LITERAL() {
return true;
}
@TestMe(CHAR_LITERAL)
public Object test_CHAR_LITERAL() {
return 'a';
}
@TestMe(STRING_LITERAL)
public Object test_STRING_LITERAL() {
return "a";
}
@TestMe(NULL_LITERAL)
public Object test_NULL_LITERAL() {
return null;
}
@TestMe(UNBOUNDED_WILDCARD)
public Set<?> test_UNBOUNDED_WILDCARD() {
return null;
}
@TestMe(EXTENDS_WILDCARD)
public Set<? extends Number> test_EXTENDS_WILDCARD() {
return null;
}
@TestMe(SUPER_WILDCARD)
public Set<? super Number> test_SUPER_WILDCARD() {
return null;
}
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment)
{
final Trees trees = Trees.instance(processingEnv);
final Messager log = processingEnv.getMessager();
final Elements elements = processingEnv.getElementUtils();
class Scan extends ElementScanner7<Void,Void> {
@Override
public Void visitExecutable(ExecutableElement e, Void p) {
Object debug = e; // info for exception handler
try {
TestMe info = e.getAnnotation(TestMe.class);
if (info == null)
return null;
Tree.Kind kind = info.value();
MethodTree node = trees.getTree(e);
debug = node;
Tree testNode;
switch (kind) {
case UNBOUNDED_WILDCARD:
case EXTENDS_WILDCARD:
case SUPER_WILDCARD:
ParameterizedTypeTree typeTree;
typeTree = (ParameterizedTypeTree) node.getReturnType();
testNode = typeTree.getTypeArguments().get(0);
break;
default:
ReturnTree returnNode;
returnNode = (ReturnTree) node.getBody().getStatements().get(0);
testNode = returnNode.getExpression();
}
if (testNode.getKind() != kind) {
log.printMessage(ERROR, testNode.getKind() + " != " + kind, e);
throw new AssertionError(testNode);
}
System.err.format("OK: %32s %s%n", kind, testNode);
} catch (Error ex) {
System.err.println("Error while looking at " + debug);
throw ex;
}
return null;
}
}
Scan scan = new Scan();
for (Element e : roundEnvironment.getRootElements()) {
scan.scan(e);
}
return true;
}
}
| 9,153 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6257235.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6257235.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6257235
* @summary setOption() and setExtendedOption() of JavacTool throws NullPointerException for undefined options
* @author Peter von der Ah\u00e9
*/
import java.util.Arrays;
import javax.tools.*;
public class T6257235 {
public static void main(String... args) {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
try {
javac.getTask(null, null, null, Arrays.asList("seetharam", "."), null, null);
throw new AssertionError("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) { }
}
}
| 1,663 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6419926.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/T6419926.java | /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6419926
* @summary JSR 199: FileObject.toUri() generates URI without schema (Solaris)
*/
import java.io.*;
import java.net.*;
import java.util.*;
import javax.tools.*;
public class T6419926 {
public static void main(String[] argv) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager mgr = compiler.getStandardFileManager( new DiagnosticCollector<JavaFileObject>(), null, null);
System.out.println( new File( new File(".").toURI() ).getAbsolutePath() );
mgr.setLocation(StandardLocation.CLASS_OUTPUT,
Collections.singleton(new File(".")));
FileObject fo = mgr.getFileForOutput(StandardLocation.CLASS_OUTPUT,
"", "file.to.delete", null);
URI uri = fo.toUri();
System.out.println( uri );
if (!"file".equals(uri.getScheme()))
throw new Exception("unexpected scheme for uri: " + uri.getScheme());
}
}
| 2,075 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestJavacTaskScanner.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/TestJavacTaskScanner.java | /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4813736
* @summary Additional functionality test of task and JSR 269
* @author Peter von der Ah\u00e9
* @library ./lib
* @run main TestJavacTaskScanner TestJavacTaskScanner.java
*/
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.parser.*;
import com.sun.tools.javac.util.*;
import java.io.*;
import java.net.*;
import java.nio.*;
import java.nio.charset.Charset;
import java.util.Arrays;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.tools.*;
import static javax.tools.StandardLocation.CLASS_PATH;
import static javax.tools.StandardLocation.SOURCE_PATH;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
public class TestJavacTaskScanner extends ToolTester {
final JavacTaskImpl task;
final Elements elements;
final Types types;
int numTokens;
int numParseTypeElements;
int numAllMembers;
TestJavacTaskScanner(File file) {
final Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjects(new File[] {file});
StandardJavaFileManager fm = getLocalFileManager(tool, null, null);
task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, compilationUnits);
task.getContext().put(ScannerFactory.scannerFactoryKey,
new MyScanner.Factory(task.getContext(), this));
elements = task.getElements();
types = task.getTypes();
}
public void run() {
Iterable<? extends TypeElement> toplevels;
try {
toplevels = task.enter(task.parse());
} catch (IOException ex) {
throw new AssertionError(ex);
}
for (TypeElement clazz : toplevels) {
System.out.format("Testing %s:%n%n", clazz.getSimpleName());
testParseType(clazz);
testGetAllMembers(clazz);
System.out.println();
System.out.println();
System.out.println();
}
System.out.println("#tokens: " + numTokens);
System.out.println("#parseTypeElements: " + numParseTypeElements);
System.out.println("#allMembers: " + numAllMembers);
check(numTokens, "#Tokens", 1222);
check(numParseTypeElements, "#parseTypeElements", 136);
check(numAllMembers, "#allMembers", 67);
}
void check(int value, String name, int expected) {
// allow some slop in the comparison to allow for minor edits in the
// test and in the platform
if (value < expected * 9 / 10)
throw new Error(name + " lower than expected; expected " + expected + "; found: " + value);
if (value > expected * 11 / 10)
throw new Error(name + " higher than expected; expected " + expected + "; found: " + value);
}
void testParseType(TypeElement clazz) {
DeclaredType type = (DeclaredType)task.parseType("List<String>", clazz);
for (Element member : elements.getAllMembers((TypeElement)type.asElement())) {
TypeMirror mt = types.asMemberOf(type, member);
System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt);
numParseTypeElements++;
}
}
public static void main(String... args) throws IOException {
String srcdir = System.getProperty("test.src");
new TestJavacTaskScanner(new File(srcdir, args[0])).run();
}
private void testGetAllMembers(TypeElement clazz) {
for (Element member : elements.getAllMembers(clazz)) {
System.out.format("%s : %s%n", member.getSimpleName(), member.asType());
numAllMembers++;
}
}
/* Similar to ToolTester.getFileManager, except that this version also ensures
* javac classes will be available on the classpath. The javac classes are assumed
* to be on the classpath used to run this test (this is true when using jtreg).
* The classes are found by obtaining the URL for a sample javac class, using
* getClassLoader().getResource(), and then deconstructing the URL to find the
* underlying directory or jar file to place on the classpath.
*/
public StandardJavaFileManager getLocalFileManager(JavaCompiler tool,
DiagnosticListener<JavaFileObject> dl,
Charset encoding) {
File javac_classes;
try {
final String javacMainClass = "com/sun/tools/javac/Main.class";
URL url = getClass().getClassLoader().getResource(javacMainClass);
if (url == null)
throw new Error("can't locate javac classes");
URI uri = url.toURI();
String scheme = uri.getScheme();
String ssp = uri.getSchemeSpecificPart();
if (scheme.equals("jar")) {
javac_classes = new File(new URI(ssp.substring(0, ssp.indexOf("!/"))));
} else if (scheme.equals("file")) {
javac_classes = new File(ssp.substring(0, ssp.indexOf(javacMainClass)));
} else
throw new Error("unknown URL: " + url);
} catch (URISyntaxException e) {
throw new Error(e);
}
System.err.println("javac_classes: " + javac_classes);
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, encoding);
try {
fm.setLocation(SOURCE_PATH, Arrays.asList(test_src));
fm.setLocation(CLASS_PATH, Arrays.asList(test_classes, javac_classes));
fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
} catch (IOException e) {
throw new AssertionError(e);
}
return fm;
}
}
class MyScanner extends Scanner {
public static class Factory extends ScannerFactory {
public Factory(Context context, TestJavacTaskScanner test) {
super(context);
this.test = test;
}
@Override
public Scanner newScanner(CharSequence input, boolean keepDocComments) {
assert !keepDocComments;
if (input instanceof CharBuffer) {
return new MyScanner(this, (CharBuffer)input, test);
} else {
char[] array = input.toString().toCharArray();
return newScanner(array, array.length, keepDocComments);
}
}
@Override
public Scanner newScanner(char[] input, int inputLength, boolean keepDocComments) {
assert !keepDocComments;
return new MyScanner(this, input, inputLength, test);
}
private TestJavacTaskScanner test;
}
protected MyScanner(ScannerFactory fac, CharBuffer buffer, TestJavacTaskScanner test) {
super(fac, buffer);
this.test = test;
}
protected MyScanner(ScannerFactory fac, char[] input, int inputLength, TestJavacTaskScanner test) {
super(fac, input, inputLength);
this.test = test;
}
public void nextToken() {
super.nextToken();
System.err.format("Saw token %s (%s)%n", token(), name());
test.numTokens++;
}
private TestJavacTaskScanner test;
}
| 8,449 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
CompileFromString.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/evalexpr/CompileFromString.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package evalexpr;
import java.lang.reflect.Method;
import java.util.*;
import javax.swing.JOptionPane;
import javax.tools.*;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
/**
* JSR 199 Demo application: compile from a String.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own
* risk. This code and its internal interfaces are subject to change
* or deletion without notice.</b></p>
*
* @author Peter von der Ahé
*/
public class CompileFromString {
/**
* The name of the class used to evaluate expressions.
*/
private final static String CLASS_NAME = "EvalExpression";
/**
* Object used to signal errors from evalExpression.
*/
public final static Object ERROR = new Object() {
public String toString() { return "error"; }
};
/**
* Compile and evaluate the specified expression using the
* given compiler.
* @param compiler a JSR 199 compiler tool used to compile the given expression
* @param expression a Java Programming Language expression
* @return the value of the expression; ERROR if any errors occured during compilation
* @throws java.lang.Exception exceptions are ignored for brevity
*/
public static Object evalExpression(JavaCompiler compiler,
DiagnosticListener<JavaFileObject> listener,
List<String> flags,
String expression)
throws Exception
{
// Use a customized file manager
MemoryFileManager mfm =
new MemoryFileManager(compiler.getStandardFileManager(listener, null, null));
// Create a file object from a string
JavaFileObject fileObject = mfm.makeSource(CLASS_NAME,
"public class " + CLASS_NAME + " {\n" +
" public static Object eval() throws Throwable {\n" +
" return " + expression + ";\n" +
" }\n}\n");
JavaCompiler.CompilationTask task =
compiler.getTask(null, mfm, listener, flags, null, Arrays.asList(fileObject));
if (task.call()) {
// Obtain a class loader for the compiled classes
ClassLoader cl = mfm.getClassLoader(CLASS_OUTPUT);
// Load the compiled class
Class compiledClass = cl.loadClass(CLASS_NAME);
// Find the eval method
Method eval = compiledClass.getMethod("eval");
// Invoke it
return eval.invoke(null);
} else {
// Report that an error occured
return ERROR;
}
}
/**
* Main entry point for program; ask user for expressions,
* compile, evaluate, and print them.
*
* @param args ignored
* @throws java.lang.Exception exceptions are ignored for brevity
*/
public static void main(String... args) throws Exception {
// Get a compiler tool
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
final List<String> compilerFlags = new ArrayList();
compilerFlags.add("-Xlint:all"); // report all warnings
compilerFlags.add("-g:none"); // don't generate debug info
String expression = "System.getProperty(\"java.vendor\")";
while (true) {
expression = JOptionPane.showInputDialog("Please enter a Java expression",
expression);
if (expression == null)
return; // end program on "cancel"
long time = System.currentTimeMillis();
Object result = evalExpression(compiler, null, compilerFlags, expression);
time = System.currentTimeMillis() - time;
System.out.format("Elapsed time %dms %n", time);
if (result == ERROR)
System.out.format("Error compiling \"%s\"%n", expression);
else
System.out.format("%s => %s%n", expression, result);
}
}
}
| 5,141 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ByteArrayClassLoader.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/evalexpr/ByteArrayClassLoader.java | /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package evalexpr;
import java.util.Map;
/**
* A class loader which loads classes from byte arrays.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own
* risk. This code and its internal interfaces are subject to change
* or deletion without notice.</b></p>
* @author Peter von der Ahé
*/
public class ByteArrayClassLoader extends ClassLoader {
/**
* Maps binary class names to class files stored as byte arrays.
*/
private Map<String, byte[]> classes;
/**
* Creates a new instance of ByteArrayClassLoader
* @param classes a map from binary class names to class files stored as byte arrays
*/
public ByteArrayClassLoader(Map<String, byte[]> classes) {
this.classes = classes;
}
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
try {
return super.loadClass(name);
} catch (ClassNotFoundException e) {
byte[] classData = classes.get(name);
return defineClass(name, classData, 0, classData.length);
}
}
}
| 2,191 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
MemoryFileManager.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/evalexpr/MemoryFileManager.java | /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package evalexpr;
import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.CharBuffer;
import java.util.HashMap;
import java.util.Map;
import javax.tools.*;
import javax.tools.JavaFileObject.Kind;
/**
* A file manager for compiling strings to byte arrays.
* This file manager delegates to another file manager
* to lookup classes on boot class path.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own
* risk. This code and its internal interfaces are subject to change
* or deletion without notice.</b></p>
* @author Peter von der Ahé
*/
public final class MemoryFileManager extends ForwardingJavaFileManager {
/**
* Maps binary class names to class files stored as byte arrays.
*/
private Map<String, byte[]> classes;
/**
* Creates a JavaFileObject representing the given compilation unit.
* @param name a name representing this source code, for example, the name of a class
* @param code a compilation unit (source code for a Java program)
* @return a JavaFileObject represtenting the given compilation unit
*/
public static JavaFileObject makeSource(String name, String code) {
return new JavaSourceFromString(name, code);
}
/**
* Construct a memory file manager which delegates to the specified
* file manager for unknown sources.
* @param fileManager a file manager used to look up class files on class path, etc.
*/
public MemoryFileManager(JavaFileManager fileManager) {
super(fileManager);
classes = new HashMap<String, byte[]>();
}
/**
* Get a class loader which first search the classes stored
* by this file mananger.
* @return a class loader for compiled files
*/
@Override
public ClassLoader getClassLoader(Location location) {
return new ByteArrayClassLoader(classes);
}
@Override
public JavaFileObject getJavaFileForOutput(Location location,
String name,
Kind kind,
FileObject originatingSource)
throws UnsupportedOperationException
{
if (originatingSource instanceof JavaSourceFromString) {
return new JavaClassInArray(name);
} else {
throw new UnsupportedOperationException();
}
}
protected static URI uriFromString(String uri) {
try {
return new URI(uri);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}
/**
* A file object representing a Java class file stored in a byte array.
*/
private class JavaClassInArray extends SimpleJavaFileObject {
private String name;
/**
* Constructs a JavaClassInArray object.
* @param name binary name of the class to be stored in this file object
*/
JavaClassInArray(String name) {
super(uriFromString("mfm:///" + name.replace('.','/') + Kind.CLASS.extension),
Kind.CLASS);
this.name = name;
}
public OutputStream openOutputStream() {
return new FilterOutputStream(new ByteArrayOutputStream()) {
public void close() throws IOException {
out.close();
ByteArrayOutputStream bos = (ByteArrayOutputStream)out;
classes.put(name, bos.toByteArray());
System.out.println("compiled " + name);
}
};
}
}
/**
* A file object used to represent source coming from a string.
*/
private static class JavaSourceFromString extends SimpleJavaFileObject {
/**
* The source code of this "file".
*/
final String code;
/**
* Constructs a new JavaSourceFromString.
* @param name the name of the compilation unit represented by this file object
* @param code the source code for the compilation unit represented by this file object
*/
JavaSourceFromString(String name, String code) {
super(uriFromString("mfm:///" + name.replace('.','/') + Kind.SOURCE.extension),
Kind.SOURCE);
this.code = code;
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return code;
}
}
}
| 5,821 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6733837.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6733837/T6733837.java | /*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6733837
* @summary Compiler API ignores locale settings
* @author Maurizio Cimadamore
* @library ../lib
*/
import java.io.StringWriter;
import java.io.PrintWriter;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import static javax.tools.JavaFileObject.Kind;
import com.sun.source.util.JavacTask;
public class T6733837 extends ToolTester {
public static void main(String... args) {
new T6733837().exec();
}
public void exec() {
JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) {
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "\tclass ErroneousWithTab";
}
};
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
List<? extends JavaFileObject> files = Arrays.asList(sfo);
task = tool.getTask(sw, fm, null, null, null, files);
try {
((JavacTask)task).analyze();
}
catch (Throwable t) {
throw new Error("Compiler threw an exception");
}
System.err.println(sw.toString());
if (!sw.toString().contains("/Test.java"))
throw new Error("Bad source name in diagnostic");
}
}
| 2,435 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6440333.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6440333/T6440333.java | /*
* Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6440333
* @summary SimpleJavaFileObject.toString() generates URI with some extra message
* @author Peter von der Ah\u00e9
* @library ../lib
* @compile T6440333.java
* @run main T6440333
*/
import java.io.File;
import java.io.IOException;
import java.net.URI;
import javax.tools.JavaFileObject;
public class T6440333 extends ToolTester {
void test(String... args) throws IOException {
File path = test_src.getCanonicalFile();
File src = new File(new File(path, "."), "T6440333.java");
JavaFileObject fo = fm.getJavaFileObjects(src).iterator().next();
URI expect = src.getCanonicalFile().toURI();
System.err.println("Expect " + expect);
System.err.println("Found " + fo.toUri());
if (!expect.equals(fo.toUri())) {
throw new AssertionError();
}
}
public static void main(String... args) throws IOException {
new T6440333().test(args);
}
}
| 2,028 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6406133.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6406133/T6406133.java | /*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6443132 6406133 6597678
* @summary Compiler API ignores locale settings
* @author Maurizio Cimadamore
* @library ../lib
*/
import javax.tools.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import java.util.*;
import java.io.*;
public class T6406133 extends ToolTester {
List<Locale> locales = Arrays.asList(Locale.US, Locale.JAPAN, Locale.CHINA);
class DiagnosticTester implements DiagnosticListener<JavaFileObject> {
Locale locale;
String result;
DiagnosticTester(Locale locale) {
this.locale = locale;
}
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
result = diagnostic.getMessage(locale); //6406133
}
}
class ProcessorTester extends AbstractProcessor {
Locale locale;
public Set<String> getSupportedAnnotationTypes() {
return new HashSet<String>(Arrays.asList("*"));
}
public void init(ProcessingEnvironment env) {
locale = env.getLocale();
}
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return true;
}
}
void compare(Locale loc1, Locale loc2, boolean useListener) {
String res1 = exec(useListener, loc1);
String res2 = exec(useListener, loc2);
boolean success = (loc1.equals(loc2) && res1.equals(res2)) ||
(!loc1.equals(loc2) && !res1.equals(res2));
if (!success)
throw new AssertionError("Error in diagnostic localization");
}
String exec(boolean useListener, Locale locale) {
final Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjects(new File(test_src, "Erroneous.java"));
StringWriter pw = new StringWriter();
DiagnosticTester listener = useListener ? new DiagnosticTester(locale) : null;
ProcessorTester processor = new ProcessorTester();
task = tool.getTask(pw, fm, listener, null, null, compilationUnits);
task.setProcessors(Arrays.asList(processor));
task.setLocale(locale); //6443132
task.call();
if (!processor.locale.equals(locale))
throw new AssertionError("Error in diagnostic localization during annotation processing");
String res = useListener ? listener.result : pw.toString();
System.err.println("[locale:"+ locale + ", listener:" + useListener + "] " +res);
return res;
}
void test() {
for (Locale l1 : locales) {
for (Locale l2 : locales) {
compare(l1, l2, true);
compare(l1, l2, false);
}
}
}
public static void main(String... args) throws Exception {
new T6406133().test();
}
}
| 3,908 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Erroneous.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6406133/Erroneous.java | /*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
@Deprecated
class A extends Missing {
}
| 1,098 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ToolProviderTest1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/ToolProvider/ToolProviderTest1.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6604599
* @summary ToolProvider should be less compiler-specific
*/
import java.io.*;
// verify that running accessing ToolProvider by itself does not
// trigger loading com.sun.tools.javac.*
public class ToolProviderTest1 {
public static void main(String... args) throws Exception {
if (args.length > 0) {
System.err.println(Class.forName(args[0], true, null));
return;
}
new ToolProviderTest1().run();
}
void run() throws Exception {
File javaHome = new File(System.getProperty("java.home"));
if (javaHome.getName().equals("jre"))
javaHome = javaHome.getParentFile();
File javaExe = new File(new File(javaHome, "bin"), "java");
String classpath = System.getProperty("java.class.path");
String[] cmd = {
javaExe.getPath(),
"-verbose:class",
"-classpath", classpath,
ToolProviderTest1.class.getName(),
"javax.tools.ToolProvider"
};
ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
Process p = pb.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = r.readLine()) != null) {
System.err.println(line);
if (line.contains("com.sun.tools.javac."))
error(">>> " + line);
}
int rc = p.waitFor();
if (rc != 0)
error("Unexpected exit code: " + rc);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void error(String msg) {
System.err.println(msg);
errors++;
}
int errors;
}
| 2,803 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ToolProviderTest2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/ToolProvider/ToolProviderTest2.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6604599
* @summary ToolProvider should be less compiler-specific
*/
import java.io.*;
import javax.tools.*;
// control for ToolProviderTest1 -- verify that using ToolProvider to
// access the compiler does trigger loading com.sun.tools.javac.*
public class ToolProviderTest2 {
public static void main(String... args) throws Exception {
if (args.length > 0) {
System.err.println(ToolProvider.getSystemJavaCompiler());
return;
}
new ToolProviderTest2().run();
}
void run() throws Exception {
File javaHome = new File(System.getProperty("java.home"));
if (javaHome.getName().equals("jre"))
javaHome = javaHome.getParentFile();
File javaExe = new File(new File(javaHome, "bin"), "java");
String classpath = System.getProperty("java.class.path");
String[] cmd = {
javaExe.getPath(),
"-verbose:class",
"-classpath", classpath,
ToolProviderTest2.class.getName(),
"javax.tools.ToolProvider"
};
ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
Process p = pb.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
boolean found = false;
while ((line = r.readLine()) != null) {
System.err.println(line);
if (line.contains("com.sun.tools.javac."))
found = true;
}
int rc = p.waitFor();
if (rc != 0)
error("Unexpected exit code: " + rc);
if (!found)
System.err.println("expected class name not found");
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void error(String msg) {
System.err.println(msg);
errors++;
}
int errors;
}
| 2,966 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
HelloWorldTest.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/ToolProvider/HelloWorldTest.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6604599
* @summary ToolProvider should be less compiler-specific
*/
import java.io.*;
import java.util.*;
// verify that running a simple program, such as this one, does not trigger
// the loading of ToolProvider or any com.sun.tools.javac class
public class HelloWorldTest {
public static void main(String... args) throws Exception {
if (args.length > 0) {
System.err.println(Arrays.asList(args));
return;
}
new HelloWorldTest().run();
}
void run() throws Exception {
File javaHome = new File(System.getProperty("java.home"));
if (javaHome.getName().equals("jre"))
javaHome = javaHome.getParentFile();
File javaExe = new File(new File(javaHome, "bin"), "java");
String classpath = System.getProperty("java.class.path");
String[] cmd = {
javaExe.getPath(),
"-verbose:class",
"-classpath", classpath,
HelloWorldTest.class.getName(),
"Hello", "World"
};
ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
Process p = pb.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = r.readLine()) != null) {
System.err.println(line);
if (line.contains("javax.tools.ToolProvider") || line.contains("com.sun.tools.javac."))
error(">>> " + line);
}
int rc = p.waitFor();
if (rc != 0)
error("Unexpected exit code: " + rc);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void error(String msg) {
System.err.println(msg);
errors++;
}
int errors;
}
| 2,868 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6421111.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6421111/T6421111.java | /*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6421111
* @summary NullPointerException thrown when retrieving bounds for the type parameter
* @author Peter von der Ah\u00e9
* @library ../lib
* @compile -Xlint:all T6421111.java
* @run main T6421111
*/
import java.io.File;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeVariable;
import javax.tools.SimpleJavaFileObject;
import static javax.tools.JavaFileObject.Kind.SOURCE;
public class T6421111 extends ToolTester {
void test(String... args) {
class Test1 extends SimpleJavaFileObject {
Test1() {
super(URI.create("myfo:///Test1.java"), SOURCE);
}
@Override
public String getCharContent(boolean ignoreEncodingErrors) {
return "class Test1<T extends Thread & Runnable> {}";
}
}
class Test2 extends SimpleJavaFileObject {
Test2() {
super(URI.create("myfo:///Test2.java"), SOURCE);
}
@Override
public String getCharContent(boolean ignoreEncodingErrors) {
return "class Test2<T extends Test2<T> & Runnable> {}";
}
}
task = tool.getTask(null, fm, null, Collections.singleton("-Xlint:all"), null,
Arrays.asList(new Test1(), new Test2()));
task.setProcessors(Collections.singleton(new MyProcessor()));
if (!task.call())
throw new AssertionError("Annotation processor failed");
}
@SupportedAnnotationTypes("*")
static class MyProcessor extends AbstractProcessor {
void test(TypeElement element, boolean fbound) {
TypeParameterElement tpe = element.getTypeParameters().iterator().next();
tpe.getBounds().getClass();
if (fbound) {
DeclaredType type = (DeclaredType)tpe.getBounds().get(0);
if (type.asElement() != element)
throw error("%s != %s", type.asElement(), element);
TypeVariable tv = (TypeVariable)type.getTypeArguments().get(0);
if (tv.asElement() != tpe)
throw error("%s != %s", tv.asElement(), tpe);
}
}
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
test(processingEnv.getElementUtils().getTypeElement("Test1"), false);
test(processingEnv.getElementUtils().getTypeElement("Test2"), true);
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
public static void main(String... args) {
new T6421111().test(args);
}
public static AssertionError error(String format, Object... args) {
return new AssertionError(String.format(format, args));
}
}
| 4,454 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6452876.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6452876/T6452876.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6452876
* @summary JSR 199: DiagnosticCollector.report(null) should throw NPE
* @author Peter von der Ah\u00e9
* @library ../lib
* @compile T6452876.java
* @run main T6452876
*/
import javax.tools.DiagnosticCollector;
public class T6452876 {
public static void main(String... args) {
try {
new DiagnosticCollector<Object>().report(null);
} catch (NullPointerException npe) {
return;
}
throw new AssertionError("Expected NPE not thrown");
}
}
| 1,591 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6412656.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6412656/T6412656.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6412656 6443062
* @summary JSR 199: pass annotation processor instances to compiler
* @author Peter von der Ah\u00e9
* @library ../lib
*/
import java.util.Set;
import java.util.Collections;
import javax.lang.model.element.TypeElement;
import javax.annotation.processing.*;
import com.sun.tools.javac.processing.AnnotationProcessingError;
public class T6412656 extends ToolTester {
int count = 0;
void test(String... args) {
task = tool.getTask(null, fm, null, null,
Collections.singleton(T6412656.class.getName()), null);
task.setProcessors(Collections.singleton(new MyProc(this)));
task.call();
if (count == 0)
throw new AssertionError("Annotation processor not run");
System.out.println("OK");
}
public static void main(String... args) {
new T6412656().test(args);
}
@SupportedAnnotationTypes("*")
static class MyProc extends AbstractProcessor {
T6412656 test;
MyProc(T6412656 test) {
this.test = test;
}
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
test.count++;
return false;
}
}
}
| 2,348 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6420409.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6420409/T6420409.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6420409
* @summary JSR 199: StandardFileManager: cannot set CLASS_PATH location
* @author Peter von der Ah\u00e9
*/
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import javax.tools.JavaFileManager.Location;
import javax.tools.*;
import static javax.tools.StandardLocation.CLASS_PATH;
import static javax.tools.StandardLocation.SOURCE_PATH;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
public class T6420409 {
static final File test_src = new File(System.getProperty("test.src"));
static final File test_classes = new File(System.getProperty("test.classes"));
public static void main(String... args) throws IOException {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
final StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(SOURCE_PATH, Arrays.asList(test_classes)); // switcheroo !!!
fm.setLocation(CLASS_PATH, Arrays.asList(test_src));
fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
final Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(test_src, "T6420409.java")));
tool.getTask(null,
fm,
null,
Arrays.asList("-proc:none"),
null,
compilationUnits).call();
test(fm.getLocation(CLASS_PATH), test_src, CLASS_PATH);
test(fm.getLocation(SOURCE_PATH), test_classes, SOURCE_PATH);
test(fm.getLocation(CLASS_OUTPUT), test_classes, CLASS_OUTPUT);
}
static void test(Iterable<? extends File> path, File file, Location location) {
Iterator<? extends File> it = path.iterator();
if (!it.next().equals(file))
throw new AssertionError(file + " not in " + location);
if (it.hasNext())
throw new AssertionError("Unexpected element in " + location + " : " + it.next());
System.err.format((Locale)null, "OK: %s: %s%n", location, path);
}
}
| 3,223 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ToolTester.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/lib/ToolTester.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import javax.tools.*;
import static javax.tools.StandardLocation.CLASS_PATH;
import static javax.tools.StandardLocation.SOURCE_PATH;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
public class ToolTester {
public final File test_src = new File(System.getProperty("test.src", "."));
public final File test_classes = new File(System.getProperty("test.classes", "."));
public final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
public final StandardJavaFileManager fm = getFileManager(tool, null, null);
public JavaCompiler.CompilationTask task = null;
public final StandardJavaFileManager getFileManager(JavaCompiler tool,
DiagnosticListener<JavaFileObject> dl,
Charset encoding) {
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, encoding);
try {
fm.setLocation(SOURCE_PATH, Arrays.asList(test_src));
fm.setLocation(CLASS_PATH, Arrays.asList(test_classes));
fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
} catch (IOException e) {
throw new AssertionError(e);
}
return fm;
}
}
| 2,424 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6411333.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6411333/T6411333.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6411333 6400208 6400225 6400267
* @summary Ensure 6400208, 6400225, and 6400267 are tested
* @author Peter von der Ah\u00e9
* @library ../lib
* @compile T6411333.java
* @run main T6411333
*/
import java.io.IOException;
import javax.tools.*;
import static javax.tools.StandardLocation.*;
import static javax.tools.JavaFileObject.Kind.*;
// Note: 6400225 (getEffectiveLocation) was dropped eventually.
public class T6411333 extends ToolTester {
// 6400208: JSR 199: failure mode for inferBinaryName
void testInferBinaryName(String binaryName, boolean fail) {
try {
JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
binaryName,
CLASS);
String inferred = fm.inferBinaryName(fail ? CLASS_PATH : PLATFORM_CLASS_PATH,
file);
if (inferred == null && fail)
return;
if (!inferred.equals(binaryName))
throw new AssertionError(String.format("binaryName (%s) != inferred (%s)",
binaryName,
inferred));
} catch (IOException ex) {
throw new AssertionError(ex);
}
}
// 6400267: JSR 199: specify the exact requirements for relative URIs
void testRelativeUri(String name, boolean fail) {
try {
fm.getFileForInput(SOURCE_OUTPUT, "java.lang", name);
} catch (IllegalArgumentException ex) {
if (fail)
return;
} catch (IOException ex) {
throw new AssertionError(ex);
}
if (fail)
throw new AssertionError("Expected failure on " + name);
}
void test(String... args) {
testInferBinaryName("java.lang.Object", false);
testInferBinaryName("java.lang.Object", true);
testRelativeUri("../util/List.java", true);
testRelativeUri("util/List.java", false);
testRelativeUri("/util/List.java", true);
}
public static void main(String... args) {
new T6411333().test(args);
}
}
| 3,329 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6420464.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6420464/T6420464.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6420464
* @summary JSR 199: JavaFileObject.isNameCompatible throws unspecified exception (IllegalArgumentException)
* @author Igor Tseytin
*/
import javax.tools.*;
import java.io.*;
import java.util.Collections;
public class T6420464 {
static final File test_src = new File(System.getProperty("test.src"));
static final File test_classes = new File(System.getProperty("test.classes"));
public static void main(String... args) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager mgr = compiler.getStandardFileManager(null, null, null);
mgr.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(test_src));
JavaFileObject f = mgr.getJavaFileForInput(StandardLocation.SOURCE_PATH,
"T6420464",
JavaFileObject.Kind.SOURCE);
if (!f.isNameCompatible("T6420464", JavaFileObject.Kind.SOURCE))
throw new AssertionError("isNameCompatible(SOURCE) fails on " + f.toUri());
if (f.isNameCompatible("T6420464", JavaFileObject.Kind.OTHER))
throw new AssertionError("isNameCompatible(OTHER) fails on " + f.toUri());
System.out.println("OK");
}
}
| 2,378 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6598108.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6598108/T6598108.java | /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6598108
* @summary com.sun.source.util.Trees.isAccessible incorrect
* @author Jan Lahoda
*/
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.Scope;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TreePath;
import com.sun.source.util.Trees;
import java.net.URI;
import java.util.Arrays;
import javax.lang.model.element.TypeElement;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
public class T6598108 {
public static void main(String[] args) throws Exception {
final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
final JavacTask ct = (JavacTask)tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject()));
CompilationUnitTree cut = ct.parse().iterator().next();
TreePath tp = new TreePath(new TreePath(cut), cut.getTypeDecls().get(0));
Scope s = Trees.instance(ct).getScope(tp);
TypeElement type = ct.getElements().getTypeElement("com.sun.java.util.jar.pack.Package.File");
if (Trees.instance(ct).isAccessible(s, type)) {
//com.sun.java.util.jar.pack.Package.File is a public innerclass inside a non-accessible class, so
//"false" would be expected here.
throw new IllegalStateException("");
}
}
static class MyFileObject extends SimpleJavaFileObject {
public MyFileObject() {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "public class Test<TTT> { public void test() {TTT ttt;}}";
}
}
}
| 2,959 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
package-info.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6431257/package-info.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
@Deprecated
package foo.bar.baz;
| 1,085 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6431257.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6431257/T6431257.java | /*
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6431257
* @summary JSR 199: Changes to JavaFileManager to support JSR 269 Filer API
* @author Peter von der Ah\u00e9
* @library ../lib
* @compile T6431257.java package-info.java
* @run main T6431257 foo.bar.baz foo/bar/baz
*/
import java.io.IOException;
import java.util.EnumSet;
import javax.tools.*;
import static javax.tools.JavaFileObject.Kind.CLASS;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
public class T6431257 extends ToolTester {
void test(String... args) throws IOException {
for (String arg : args)
testPackage(arg);
}
void testPackage(String packageName) throws IOException {
JavaFileObject object
= fm.getJavaFileForInput(PLATFORM_CLASS_PATH, "java.lang.Object", CLASS);
Iterable<? extends JavaFileObject> files
= fm.list(CLASS_OUTPUT, packageName, EnumSet.of(CLASS), false);
boolean found = false;
String binaryPackageName = packageName.replace('/', '.');
for (JavaFileObject file : files) {
System.out.println("Found " + file.getName() + " in " + packageName);
String name = fm.inferBinaryName(CLASS_OUTPUT, file);
found |= name.equals(binaryPackageName + ".package-info");
JavaFileObject other = fm.getJavaFileForInput(CLASS_OUTPUT, name, CLASS);
if (!fm.isSameFile(file, other))
throw new AssertionError(file + " != " + other);
if (fm.isSameFile(file, object))
throw new AssertionError(file + " == " + object);
}
if (!found)
throw new AssertionError("Did not find " + binaryPackageName + ".package-info");
}
public static void main(String... args) throws IOException {
new T6431257().test(args);
}
}
| 2,938 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6410643.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6410643/T6410643.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6410643
* @summary JSR 199: The method JavaCompilerTool.run fails to handle null arguments
* @author Peter von der Ah\u00e9
* @library ../lib
*/
import javax.tools.JavaFileObject;
import static java.util.Collections.singleton;
public class T6410643 extends ToolTester {
void testGetTask(Iterable<String> options,
Iterable<String> classes,
Iterable<? extends JavaFileObject> compilationUnits) {
try {
task = tool.getTask(null, null, null, null, null, singleton((JavaFileObject)null));
throw new AssertionError("Error expected");
} catch (NullPointerException e) {
System.err.println("Expected error occurred: " + e);
}
}
void test(String... args) {
task = tool.getTask(null, null, null, null, null, null);
if (task.call())
throw new AssertionError("Error expected");
System.err.println("Compilation failed as expected!");
Iterable<String> s = singleton(null);
Iterable<JavaFileObject> f = singleton(null);
// case (null, null, null) is tested above
testGetTask(null, null, f);
testGetTask(null, s, null);
testGetTask(null, s, f);
testGetTask(s, null, null);
testGetTask(s, null, f);
testGetTask(s, s, null);
testGetTask(s, s, f);
System.err.println("Test result: PASSED");
}
public static void main(String... args) {
new T6410643().test(args);
}
}
| 2,626 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6422215.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6422215/T6422215.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6422215
* @summary JSR 199: What happens if a directory is missing
* @author Peter von der Ah\u00e9
* @library ../lib
*/
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
public class T6422215 extends ToolTester {
void test(String... args) {
try {
fm.setLocation(CLASS_OUTPUT,
Collections.singleton(new File(test_src, "no_such_dir")));
throw new AssertionError("Expected exception not thrown");
} catch (IOException e) {
System.out.println("OK: caught expected exception: " + e.getLocalizedMessage());
}
}
public static void main(String... args) {
new T6422215().test(args);
}
}
| 1,859 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6852595.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6852595/T6852595.java | /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6852595
* @summary Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
* @author mcimadamore
*/
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
import com.sun.source.util.JavacTask;
import com.sun.source.tree.*;
import com.sun.source.util.TreePath;
import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.tree.JCTree.*;
import static javax.tools.JavaFileObject.Kind;
public class T6852595 {
public static void main(String[] args) throws IOException {
JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) {
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "class BadName { Object o = j; }";
}
};
List<? extends JavaFileObject> files = Arrays.asList(sfo);
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files);
Iterable<? extends CompilationUnitTree> compUnits = ct.parse();
CompilationUnitTree cu = compUnits.iterator().next();
ClassTree cdef = (ClassTree)cu.getTypeDecls().get(0);
JCVariableDecl vdef = (JCVariableDecl)cdef.getMembers().get(0);
TreePath path = TreePath.getPath(cu, vdef.init);
Trees.instance(ct).getScope(path);
}
}
| 2,666 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6411310.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6411310/T6411310.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6411310
* @summary JSR 199: FileObject should support user-friendly names via getName()
* @author Peter von der Ah\u00e9
* @library ../lib
* @compile T6411310.java
* @run main T6411310
*/
import java.io.IOException;
import javax.tools.JavaFileObject;
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
import static javax.tools.StandardLocation.CLASS_PATH;
import static javax.tools.JavaFileObject.Kind.CLASS;
// Limited test while we wait for 6419926: 6419926 is now closed
public class T6411310 extends ToolTester {
void test(String... args) throws IOException {
JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
"java.lang.Object",
CLASS);
String fileName = file.getName();
if (!fileName.matches(".*java/lang/Object.class\\)?")) {
System.err.println(fileName);
throw new AssertionError(file);
}
}
public static void main(String... args) throws IOException {
new T6411310().test(args);
}
}
| 2,195 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Test.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6411310/Test.java | /*
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6410367 6411310
* @summary FileObject should support user-friendly names via getName()
*/
import java.io.*;
import java.util.*;
import java.util.jar.*;
import java.util.zip.*;
import javax.tools.*;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
// Test FileObject.getName returned from JavacFileManager and its support classes.
public class Test {
public static void main(String... args) throws Exception {
new Test().run();
}
Set<String> foundClasses = new TreeSet<String>();
Set<String> foundJars = new TreeSet<String>();
void run() throws Exception {
File rt_jar = findRtJar();
// names for entries to be created in directories and jar files
String[] entries = { "p/A.java", "p/A.class", "p/resources/A-1.html" };
// test various combinations of directories and jar files, intended to
// cover all sources of file objects within JavacFileManager's support classes
test(createFileManager(), createDir("dir", entries), "p", entries);
test(createFileManager(), createDir("a b/dir", entries), "p", entries);
for (boolean useOptimizedZip: new boolean[] { false, true }) {
test(createFileManager(useOptimizedZip), createJar("jar", entries), "p", entries);
test(createFileManager(useOptimizedZip), createJar("jar jar", entries), "p", entries);
for (boolean useSymbolFile: new boolean[] { false, true }) {
test(createFileManager(useOptimizedZip, useSymbolFile), rt_jar, "java.lang.ref", null);
}
}
if (errors > 0)
throw new Exception(errors + " errors found");
// Verify that we hit all the impl classes we intended
checkCoverage("classes", foundClasses,
"RegularFileObject", "SymbolFileObject", "ZipFileIndexFileObject", "ZipFileObject");
// Verify that we hit the jar files we intended, specifically ct.sym as well as rt.jar
checkCoverage("jar files", foundJars,
"ct.sym", "jar", "jar jar", "rt.jar");
}
// use a new file manager for each test
void test(StandardJavaFileManager fm, File f, String pkg, String[] entries) throws Exception {
System.err.println("Test " + f);
try {
if (f.isDirectory()) {
for (File dir: new File[] { f, f.getAbsoluteFile() }) {
for (String e: entries) {
JavaFileObject fo = fm.getJavaFileObjects(new File(dir, e)).iterator().next();
test(fo, dir, e);
}
}
}
fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(f));
fm.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(f.getAbsoluteFile()));
for (StandardLocation l: EnumSet.of(StandardLocation.CLASS_PATH, StandardLocation.SOURCE_PATH)) {
for (JavaFileObject fo: fm.list(l, pkg, EnumSet.allOf(JavaFileObject.Kind.class), true)) {
// we could use fm.getLocation but the following guarantees we preserve the original filename
File dir = (l == StandardLocation.CLASS_PATH ? f : f.getAbsoluteFile());
char sep = (dir.isDirectory() ? File.separatorChar : '/');
String b = fm.inferBinaryName(l, fo);
String e = fo.getKind().extension;
test(fo, dir, b.replace('.', sep) + e);
}
}
} finally {
fm.close();
}
}
void test(JavaFileObject fo, File dir, String p) {
System.err.println("Test: " + fo);
String expect = dir.isDirectory() ? new File(dir, p).getPath() : (dir.getPath() + "(" + p + ")");
String found = fo.getName();
// if ct.sym is found, replace it with the equivalent rt.jar
String found2 = found.replaceAll("lib([\\\\/])ct.sym\\(META-INF/sym/rt.jar/", "jre$1lib$1rt.jar(");
if (!expect.equals(found2)) {
System.err.println("expected: " + expect);
System.err.println(" found: " + found);
if (!found.equals(found2))
System.err.println(" found2: " + found2);
error("Failed: " + fo);
}
// record the file object class name for coverage checks later
foundClasses.add(fo.getClass().getSimpleName());
if (found.contains("(")) {
// record access to the jar file for coverage checks later
foundJars.add(new File(found.substring(0, found.indexOf("("))).getName());
}
}
void checkCoverage(String label, Set<String> found, String... expect) throws Exception {
Set<String> e = new TreeSet<String>(Arrays.asList(expect));
if (!found.equals(e)) {
e.removeAll(found);
throw new Exception("expected " + label + " not used: " + e);
}
}
JavacFileManager createFileManager() {
return createFileManager(false, false);
}
JavacFileManager createFileManager(boolean useOptimizedZip) {
return createFileManager(useOptimizedZip, false);
}
JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) {
Context c = new Context();
Options options = Options.instance(c);
options.put("useOptimizedZip", Boolean.toString(useOptimizedZip));
if (!useSymbolFile) {
options.put("ignore.symbol.file", "true");
}
return new JavacFileManager(c, false, null);
}
File createDir(String name, String... entries) throws Exception {
File dir = new File(name);
if (!dir.mkdirs())
throw new Exception("cannot create directories " + dir);
for (String e: entries) {
writeFile(new File(dir, e), e);
}
return dir;
}
File createJar(String name, String... entries) throws IOException {
File jar = new File(name);
OutputStream out = new FileOutputStream(jar);
try {
JarOutputStream jos = new JarOutputStream(out);
for (String e: entries) {
jos.putNextEntry(new ZipEntry(e));
jos.write(e.getBytes());
}
jos.close();
} finally {
out.close();
}
return jar;
}
File findRtJar() throws Exception {
File java_home = new File(System.getProperty("java.home"));
if (java_home.getName().equals("jre"))
java_home = java_home.getParentFile();
File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar");
if (!rt_jar.exists())
throw new Exception("can't find rt.jar");
return rt_jar;
}
byte[] read(InputStream in) throws IOException {
byte[] data = new byte[1024];
int offset = 0;
try {
int n;
while ((n = in.read(data, offset, data.length - offset)) != -1) {
offset += n;
if (offset == data.length)
data = Arrays.copyOf(data, 2 * data.length);
}
} finally {
in.close();
}
return Arrays.copyOf(data, offset);
}
void writeFile(File f, String s) throws IOException {
f.getParentFile().mkdirs();
FileWriter out = new FileWriter(f);
try {
out.write(s);
} finally {
out.close();
}
}
void error(String msg) {
System.err.println(msg);
errors++;
}
int errors;
}
| 8,771 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6557752.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6557752/T6557752.java | /*
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6557752
* @summary Test for wrapping the original type in ErrorType.
* @library ../lib
* @compile T6557752.java
* @run main T6557752
*/
import com.sun.source.tree.AssignmentTree;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TreePath;
import com.sun.source.util.TreePathScanner;
import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.util.List;
import java.io.IOException;
import java.net.URI;
import javax.lang.model.type.ErrorType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
import javax.lang.model.util.Types;
public class T6557752 {
static class MyFileObject extends SimpleJavaFileObject {
public MyFileObject() {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "import java.util.*;\n"
+ "public class Test {\n"
+ " void foobar() {\n"
+ " Iterator<Number> itr = null;\n"
+ " String str = itr.next();\n"
+ " FooBar fooBar = FooBar.foobar();\n"
+ " }\n"
+ "}";
}
}
static Trees trees;
static JavacTask task = null;
public static void main(String[] args) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
task = (JavacTask) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject()));
Iterable<? extends CompilationUnitTree> asts = task.parse();
task.analyze();
trees = Trees.instance(task);
MyVisitor myVisitor = new MyVisitor();
for (CompilationUnitTree ast : asts) {
myVisitor.compilationUnit = ast;
myVisitor.scan(ast, null);
}
if (!myVisitor.foundError) {
throw new AssertionError("Expected error not found!");
}
}
static class MyVisitor extends TreePathScanner<Void,Void> {
public boolean foundError = false;
CompilationUnitTree compilationUnit = null;
int i = 0;
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void ignored) {
TreePath path = TreePath.getPath(compilationUnit, node);
TypeMirror typeMirror = trees.getTypeMirror(path);
if (typeMirror.getKind() == TypeKind.ERROR) {
if (i == 0) {
String str1 = trees.getOriginalType((ErrorType)typeMirror).toString();
if (!str1.equals("java.lang.Number")) {
throw new AssertionError("Trees.getOriginalType() error!");
}
Types types = task.getTypes();
str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString();
if (!str1.equals("java.lang.Number")) {
throw new AssertionError("Types.asElement() error!");
}
i++;
}
else if (i == 1) {
String str1 = trees.getOriginalType((ErrorType)typeMirror).toString();
if (!str1.equals("FooBar")) {
throw new AssertionError("Trees.getOriginalType() error!");
}
Types types = task.getTypes();
str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString();
if (!str1.equals("FooBar")) {
throw new AssertionError("Types.asElement() error!");
}
foundError = true;
}
}
return null;
}
}
}
| 5,069 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6608214.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6608214/T6608214.java | /*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6608214
* @summary Exception throw while analysing a file with error
* @author Maurizio Cimadamore
*/
import com.sun.source.util.JavacTask;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
import static javax.tools.JavaFileObject.Kind;
public class T6608214 {
public static void main(String[] args) throws IOException {
JavaFileObject sfo = new SimpleJavaFileObject(URI.create(""),Kind.SOURCE) {
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "class Test<S> { <T extends S & Runnable> void test(){}}";
}
};
List<? extends JavaFileObject> files = Arrays.asList(sfo);
String bootPath = System.getProperty("sun.boot.class.path");
List<String> opts = Arrays.asList("-bootclasspath", bootPath, "-Xjcov");
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask)tool.getTask(null, null, null,opts,null,files);
ct.analyze();
}
}
| 2,262 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6437999.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6437999/T6437999.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6437999
* @summary Unit test for encoding argument to standard file manager
* @author Peter von der Ah\u00e9
* @library ../lib
* @compile T6437999.java
* @run main T6437999
*/
import java.io.File;
import java.nio.charset.Charset;
import java.util.Collections;
import javax.tools.*;
public class T6437999 extends ToolTester {
static class MyDiagnosticListener implements DiagnosticListener<JavaFileObject> {
boolean error = false;
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
error |= diagnostic.getKind() == Diagnostic.Kind.ERROR;
System.out.println(diagnostic);
}
}
void test(String... args) {
Iterable<String> sourceLevel = Collections.singleton("6");
MyDiagnosticListener dl = new MyDiagnosticListener();
StandardJavaFileManager fm;
Iterable<? extends JavaFileObject> files;
dl.error = false;
fm = getFileManager(tool, dl, Charset.forName("ASCII"));
fm.handleOption("-source", sourceLevel.iterator());
files = fm.getJavaFileObjects(new File(test_src, "Utf8.java"));
tool.getTask(null, fm, null, null, null, files).call();
if (!dl.error)
throw new AssertionError("No error in ASCII mode");
dl.error = false;
fm = getFileManager(tool, dl, Charset.forName("UTF-8"));
fm.handleOption("-source", sourceLevel.iterator());
files = fm.getJavaFileObjects(new File(test_src, "Utf8.java"));
task = tool.getTask(null, fm, null, null, null, files);
if (dl.error)
throw new AssertionError("Error in UTF-8 mode");
}
public static void main(String... args) {
new T6437999().test(args);
}
}
| 2,822 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Utf8.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6437999/Utf8.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @author Peter von der Ahé
*/
class Utf8 {}
| 1,104 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6422327.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6422327/T6422327.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6422327
* @summary JSR 199: JavaCompilerTool can compile and generate '.class' of non '.java' files
* @author Peter von der Ah\u00e9
* @library ../lib
*/
import java.io.File;
public class T6422327 extends ToolTester {
void test(String... args) {
File file = new File(test_src, "T6422327.other");
try {
task = tool.getTask(null, fm, null, null, null, fm.getJavaFileObjects(file));
throw new AssertionError("Expected exception not thrown");
} catch (IllegalArgumentException e) {
System.err.println("OK, got expected exception: " + e.getLocalizedMessage());
}
}
public static void main(String... args) {
new T6422327().test(args);
}
}
| 1,808 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6468404.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/6468404/T6468404.java | /*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6468404
* @summary ExecutableElement.getParameters() uses raw type for class loaded from -g bytecode
* @author jesse.glick@...
* @author Peter von der Ah\u00e9
* @library ../lib
* @compile T6468404.java
* @run main T6468404
*/
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.ExecutableType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
public class T6468404 extends ToolTester {
void test(String... args) {
System.err.println("Compiling with sources:");
task = tool.getTask(
null, fm, null, null,
null, Collections.singleton(new DummyFO("C")));
task.setProcessors(Collections.singleton(new P()));
if (!task.call())
throw new AssertionError();
System.err.println("Compiling with binaries w/o -g:");
task = tool.getTask(
null, fm, null, null,
null, Collections.singleton(new DummyFO("Dummy")));
task.setProcessors(Collections.singleton(new P()));
if (!task.call())
throw new AssertionError();
task = tool.getTask(
null, fm, null,
Arrays.asList("-g"),
null, Collections.singleton(new DummyFO("C")));
if (!task.call())
throw new AssertionError();
System.err.println("Compiling with binaries w/ -g:");
task = tool.getTask(
null, fm, null, null,
null, Collections.singleton(new DummyFO("Dummy")));
task.setProcessors(Collections.singleton(new P()));
if (!task.call())
throw new AssertionError();
}
public static void main(String... args) {
new T6468404().test(args);
}
}
class DummyFO extends SimpleJavaFileObject {
String n;
public DummyFO(String n) {
super(URI.create("nowhere:/" + n + ".java"), JavaFileObject.Kind.SOURCE);
this.n = n;
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return "public class " + n + " {" + n + "(java.util.List<String> l) {}}";
}
}
@SupportedAnnotationTypes("*")
class P extends AbstractProcessor {
boolean ran = false;
Elements elements;
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
elements = processingEnv.getElementUtils();
}
ExecutableElement getFirstMethodIn(String name) {
return (ExecutableElement)elements.getTypeElement(name).getEnclosedElements().get(0);
}
boolean isParameterized(TypeMirror type) {
return !((DeclaredType)type).getTypeArguments().isEmpty();
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!ran) {
ran = true;
ExecutableElement m = getFirstMethodIn("C");
System.err.println("method: " + m);
TypeMirror type = (DeclaredType)m.getParameters().get(0).asType();
System.err.println("parameters[0]: " + type);
if (!isParameterized(type))
throw new AssertionError(type);
type = ((ExecutableType)m.asType()).getParameterTypes().get(0);
System.err.println("parameterTypes[0]: " + type);
if (!isParameterized(type))
throw new AssertionError(type);
System.err.println();
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
| 5,391 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMe.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/guide/TestMe.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class TestMe extends Old {}
@Deprecated class Old {}
| 1,105 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Test.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/api/guide/Test.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6427274 6347778 6469079
* @summary Various bugs fixed while writing Compiler API Guide
* @author Peter von der Ah\u0081
* @library ../lib
* @compile Test.java
* @run main Test
*/
import javax.tools.*;
import java.io.File;
import java.util.Collections;
public class Test extends ToolTester {
public boolean success = false;
class DiagnosticTester implements DiagnosticListener<JavaFileObject> {
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.NOTE) {
try {
// 6427274: FileObject.openReader throws exception
// 6347778: getSource() returns null for notes
diagnostic.getSource().openReader(true).getClass();
} catch (Exception ex) {
throw new AssertionError(ex);
}
success = true;
}
}
}
void test(String... args) throws Exception {
final Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjects(new File(test_src, "TestMe.java"));
task = tool.getTask(null, fm, new DiagnosticTester(), null, null, compilationUnits);
if (!task.call())
throw new AssertionError("Compilation failed");
if (!success)
throw new AssertionError("Did not see a NOTE");
// 6427274: openReader throws exception
fm.getFileForInput(StandardLocation.PLATFORM_CLASS_PATH,
"java.lang",
"Object.class").openReader(true).getClass();
DiagnosticCollector<JavaFileObject> diags = new DiagnosticCollector<JavaFileObject>();
task = tool.getTask(null, fm, diags, Collections.singleton("-Xlint:all"),
null, compilationUnits);
if (!task.call())
throw new AssertionError("Compilation failed");
String msg = diags.getDiagnostics().get(0).getMessage(null);
long lineno = diags.getDiagnostics().get(0).getLineNumber();
if (msg.contains(":"+lineno+":"))
// 6469079: Diagnostic.getMessage(Locale) includes line numbers
throw new AssertionError(msg);
}
public static void main(String... args) throws Exception {
new Test().test(args);
}
}
| 3,433 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.