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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
TestUnionType.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/type/TestUnionType.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 7029150
* @summary Test support for union types
* @library ../../../lib
*/
import java.net.URI;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import javax.tools.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
public class TestUnionType extends JavacTestingAbstractProcessor {
enum TestKind {
SingleType("E1", "E1",
"VariableTree: E1 e",
"VariableTree: elem EXCEPTION_PARAMETER e",
"VariableTree: elem.type DECLARED",
"VariableTree: elem.type.elem CLASS E1",
"VariableTree: type DECLARED",
"VariableTree: type.elem CLASS E1",
"VariableTree: type.elem.type DECLARED"),
ValidTypes("E1, E2", "E1 | E2",
"VariableTree: E1 | E2 e",
"VariableTree: elem EXCEPTION_PARAMETER e",
"VariableTree: elem.type UNION Test.E1,Test.E2",
"VariableTree: elem.type.elem null",
"VariableTree: type UNION Test.E1,Test.E2",
"VariableTree: type.elem null"),
InvalidTypes("E1, E2", "E1 | EMissing",
"VariableTree: E1 | EMissing e",
"VariableTree: elem EXCEPTION_PARAMETER e",
"VariableTree: elem.type UNION Test.E1,EMissing",
"VariableTree: elem.type.elem null",
"VariableTree: type UNION Test.E1,EMissing",
"VariableTree: type.elem null"),
Uncaught("E1", "E1 | E2",
"VariableTree: E1 | E2 e",
"VariableTree: elem EXCEPTION_PARAMETER e",
"VariableTree: elem.type UNION Test.E1,Test.E2",
"VariableTree: elem.type.elem null",
"VariableTree: type UNION Test.E1,Test.E2",
"VariableTree: type.elem null");
TestKind(String throwsTypes, String catchTypes, String... gold) {
this.throwsTypes = throwsTypes;
this.catchTypes = catchTypes;
this.gold = Arrays.asList(gold);
}
final String throwsTypes;
final String catchTypes;
final List<String> gold;
}
static class TestFileObject extends SimpleJavaFileObject {
public static final String template =
"class Test {\n"
+ " class E1 extends Exception { }\n"
+ " class E2 extends Exception { }\n"
+ " void doSomething() throws #T { }\n"
+ " void test() {\n"
+ " try {\n"
+ " doSomething();\n"
+ " } catch (#C e) {\n"
+ " }\n"
+ " }\n"
+ "}\n";
public TestFileObject(TestKind tk) {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
this.tk = tk;
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return template
.replace("#T", tk.throwsTypes)
.replace("#C", tk.catchTypes);
}
final TestKind tk;
}
public static void main(String... args) throws Exception {
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
List<String> options = Arrays.asList("-proc:only");
for (TestKind tk: TestKind.values()) {
System.err.println("Test: " + tk);
TestUnionType p = new TestUnionType();
JavaFileObject fo = new TestFileObject(tk);
JavaCompiler.CompilationTask task = comp.getTask(null, null, null, options, null, Arrays.asList(fo));
task.setProcessors(Arrays.asList(p));
boolean ok = task.call();
System.err.println("compilation " + (ok ? "passed" : "failed"));
if (!ok)
throw new Exception("compilation failed unexpectedly");
if (!p.log.equals(tk.gold)) {
System.err.println("Expected output:");
for (String g: tk.gold)
System.err.println(g);
throw new Exception("unexpected output from test");
}
System.err.println();
}
}
Trees trees;
List<String> log;
@Override
public void init(ProcessingEnvironment env) {
super.init(env);
trees = Trees.instance(env);
log = new ArrayList<String>();
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
for (Element e: roundEnv.getRootElements()) {
scan(trees.getPath(e));
}
}
return true;
}
void scan(TreePath path) {
new Scanner().scan(path, null);
}
class Scanner extends TreePathScanner<Void,Void> {
@Override
public Void visitVariable(VariableTree tree, Void ignore) {
TreePath p = getCurrentPath();
Element e = trees.getElement(p);
if (e.getKind() == ElementKind.EXCEPTION_PARAMETER) {
log("VariableTree: " + tree);
log("VariableTree: elem " + print(e));
log("VariableTree: elem.type " + print(e.asType()));
log("VariableTree: elem.type.elem " + print(types.asElement(e.asType())));
TypeMirror tm = trees.getTypeMirror(p);
log("VariableTree: type " + print(tm));
log("VariableTree: type.elem " + print(types.asElement(tm)));
if (types.asElement(tm) != null)
log("VariableTree: type.elem.type " + print(types.asElement(tm).asType()));
}
return super.visitVariable(tree, null);
}
String print(TypeMirror tm) {
return (tm == null) ? null : new TypePrinter().visit(tm);
}
String print(Element e) {
return (e == null) ? null : (e.getKind() + " " + e.getSimpleName());
}
void log(String msg) {
System.err.println(msg);
log.add(msg);
}
}
class TypePrinter extends SimpleTypeVisitor7<String, Void> {
@Override
protected String defaultAction(TypeMirror tm, Void ignore) {
return String.valueOf(tm.getKind());
}
@Override
public String visitUnion(UnionType t, Void ignore) {
return (t.getKind() + " " + t.getAlternatives());
}
}
}
| 7,712 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestTypeKind.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/type/TestTypeKind.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.
*/
/*
* @test
* @bug 6347716
* @summary Test TypeKind.isPrimitive
* @author Joseph D. Darcy
*/
import javax.lang.model.type.TypeKind;
import static javax.lang.model.type.TypeKind.*;
import javax.lang.model.util.*;
import java.util.*;
public class TestTypeKind {
static int testIsPrimitive() {
int failures = 0;
// The eight primitive types
Set<TypeKind> primitives = EnumSet.of(BOOLEAN, // 1
BYTE, // 2
CHAR, // 3
DOUBLE, // 4
FLOAT, // 5
INT, // 6
LONG, // 7
SHORT); // 8
for(TypeKind tk : TypeKind.values()) {
boolean primitiveness;
if ((primitiveness=tk.isPrimitive()) != primitives.contains(tk) ) {
failures++;
System.err.println("Unexpected isPrimitive value " + primitiveness +
"for " + tk);
}
}
return failures;
}
public static void main(String... argv) {
int failures = 0;
failures += testIsPrimitive();
if (failures > 0)
throw new RuntimeException();
}
}
| 2,478 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
NoTypes.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/type/NoTypes.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 6418666 6423973 6453386
* @summary Test the NoTypes: VOID, PACKAGE, NONE
* @author Scott Seligman
* @library ../../../lib
* @build JavacTestingAbstractProcessor
* @compile -g NoTypes.java
* @compile -processor NoTypes -proc:only NoTypes.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import static javax.lang.model.type.TypeKind.*;
public class NoTypes extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
if (!round.processingOver())
doit(annoTypes, round);
return true;
}
private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
// The superclass of Object is NONE.
TypeElement object = elements.getTypeElement("java.lang.Object");
verifyKind(NONE, object.getSuperclass());
// The enclosing type of a top-level class is NONE
verifyKind(NONE, ((DeclaredType)object.asType()).getEnclosingType());
// The superclass of an interface is NONE.
TypeElement i = elements.getTypeElement("NoTypes.I");
verifyKind(NONE, i.getSuperclass());
// The type of a package is PACKAGE.
Element pkg = i.getEnclosingElement().getEnclosingElement();
verifyKind(PACKAGE, pkg.asType());
// A package isn't enclosed. Not yet, anyway.
if (pkg.getEnclosingElement() != null)
throw new AssertionError();
verifyKind(VOID, types.getNoType(VOID));
verifyKind(NONE, types.getNoType(NONE));
// The return type of a constructor or void method is VOID.
class Scanner extends ElementScanner7<Void, Void> {
@Override
public Void visitExecutable(ExecutableElement e, Void p) {
verifyKind(VOID, e.getReturnType());
ExecutableType t = (ExecutableType) e.asType();
verifyKind(VOID, t.getReturnType());
return null;
}
}
TypeElement c = elements.getTypeElement("NoTypes.C");
new Scanner().scan(c);
}
/**
* Verify that a NoType instance is of a particular kind,
* and that TypeKindVisitor7 properly dispatches on it.
*/
private void verifyKind(TypeKind kind, TypeMirror type) {
class Vis extends TypeKindVisitor7<TypeKind, Void> {
@Override
public TypeKind visitNoTypeAsVoid(NoType t, Void p) {
return VOID;
}
@Override
public TypeKind visitNoTypeAsPackage(NoType t, Void p) {
return PACKAGE;
}
@Override
public TypeKind visitNoTypeAsNone(NoType t, Void p) {
return NONE;
}
}
if (kind != type.getKind() || kind != new Vis().visit(type))
throw new AssertionError();
}
// Fodder for the tests
interface I {
}
class C {
C() {}
void m() {}
}
}
| 4,282 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
NpeTest.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/type/MirroredTypeEx/NpeTest.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 6593082
* @summary MirroredTypeException constructor should not accept null
* @author Joseph D. Darcy
*/
import javax.lang.model.type.*;
public class NpeTest {
public static void main(String... args) {
try {
MirroredTypeException mte = new MirroredTypeException(null);
throw new RuntimeException("Expected NPE not thrown.");
} catch (NullPointerException npe) {
; // success
}
}
}
| 1,532 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
OverEager.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/type/MirroredTypeEx/OverEager.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 6362178
* @summary MirroredType[s]Exception shouldn't be created too eagerly
* @author Scott Seligman
* @library ../../../../lib
* @build JavacTestingAbstractProcessor
* @compile -g OverEager.java
* @compile -processor OverEager -proc:only OverEager.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
@SupportedAnnotationTypes("IAm")
@IAm(OverEager.class)
public class OverEager extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
if (!round.processingOver())
doit(annoTypes, round);
return true;
}
private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
for (TypeElement t : typesIn(round.getRootElements())) {
IAm anno = t.getAnnotation(IAm.class);
if (anno != null)
checkAnno(anno);
}
}
private void checkAnno(IAm anno) {
try {
anno.value();
throw new AssertionError();
} catch (MirroredTypeException e) {
System.out.println("Looking for checkAnno in this stack trace:");
e.printStackTrace();
for (StackTraceElement frame : e.getStackTrace()) {
if (frame.getMethodName() == "checkAnno")
return;
}
throw new AssertionError();
}
}
}
@interface IAm {
Class<?> value();
}
| 2,780 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Plurality.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/type/MirroredTypeEx/Plurality.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 6519115
* @summary Verify MirroredTypeException vs MirroredTypesException is thrown
* @library ../../../../lib
* @build JavacTestingAbstractProcessor
* @compile Plurality.java
* @compile -processor Plurality -proc:only Plurality.java
* @author Joseph D. Darcy
*/
import java.lang.annotation.*;
import java.math.BigDecimal;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
@P0
@P1
@P2
@S1
public class Plurality extends JavacTestingAbstractProcessor {
private boolean executed = false;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
executed = true;
// Processing just this type
Element e = elements.getTypeElement("Plurality");
Class[] classes = null;
P0 p0 = e.getAnnotation(P0.class);
try {
classes = p0.value();
} catch (MirroredTypesException mtse) {
if (mtse instanceof MirroredTypeException) {
throw new RuntimeException("Wrong exception type!");
}
List<? extends TypeMirror> types = mtse.getTypeMirrors();
if (types.size() != 0)
throw new RuntimeException("List size != 0: " +
types);
}
P1 p1 = e.getAnnotation(P1.class);
try {
classes = p1.value();
} catch (MirroredTypesException mtse) {
if (mtse instanceof MirroredTypeException) {
throw new RuntimeException("Wrong exception type!");
}
List<? extends TypeMirror> types = mtse.getTypeMirrors();
if (types.size() != 1)
throw new RuntimeException("List size != 1: " +
types);
checkTypeListMatchesClasses(types,
this.getClass().getAnnotation(P1.class).value());
}
P2 p2 = e.getAnnotation(P2.class);
try {
classes = p2.value();
} catch(MirroredTypesException mtse) {
if (mtse instanceof MirroredTypeException) {
throw new RuntimeException("Wrong exception type!");
}
List<? extends TypeMirror> types = mtse.getTypeMirrors();
if (types.size() != 2)
throw new RuntimeException("List size != 2: " +
types);
checkTypeListMatchesClasses(types,
this.getClass().getAnnotation(P2.class).value());
}
Class<?> clazz = null;
S1 s1 = e.getAnnotation(S1.class);
try {
clazz = s1.value();
} catch(MirroredTypesException mtse) {
List<? extends TypeMirror> types = mtse.getTypeMirrors();
if (types.size() != 1)
throw new RuntimeException("List size != 1: " +
types);
Class<?>[] clazzes = new Class<?>[1];
clazzes[0] = this.getClass().getAnnotation(S1.class).value();
checkTypeListMatchesClasses(types,
clazzes);
}
try {
clazz = s1.value();
} catch(MirroredTypeException mte) {
TypeMirror type = mte.getTypeMirror();
if (type == null) {
throw new RuntimeException("Expected null");
}
List<TypeMirror> types = new ArrayList<>();
types.add(type);
Class<?>[] clazzes = new Class<?>[1];
clazzes[0] = this.getClass().getAnnotation(S1.class).value();
checkTypeListMatchesClasses(types, clazzes);
}
} else {
if (!executed) {
throw new RuntimeException("Didn't seem to do anything!");
}
}
return true;
}
private static void checkTypeListMatchesClasses(List<? extends TypeMirror> types,
Class<?>[] classes) {
if (types.size() != classes.length)
throw new RuntimeException("Size mismatch:\n\t" + types +
"\n\t" + Arrays.toString(classes));
int i = -1;
for(Class<?> clazz : classes) {
i++;
String canonicalName = clazz.getCanonicalName();
String toStringName = types.get(i).toString();
if (!canonicalName.equals(toStringName))
throw new RuntimeException("Mismatched names: " +
canonicalName + "\t" +
toStringName);
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@interface P0 {
Class[] value() default {};
}
@Retention(RetentionPolicy.RUNTIME)
@interface P1 {
Class[] value() default {Integer.class};
}
@Retention(RetentionPolicy.RUNTIME)
@interface P2 {
Class[] value() default {String.class, Number.class};
}
@Retention(RetentionPolicy.RUNTIME)
@interface S1 {
Class value() default BigDecimal.class;
}
| 6,637 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Main.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/testgetallmembers/Main.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 6374357 6308351 6707027
* @summary PackageElement.getEnclosedElements() throws ClassReader$BadClassFileException
* @author Peter von der Ah\u00e9
* @run main/othervm -Xmx256m Main
*/
import java.io.File;
import java.util.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.tools.*;
import com.sun.source.util.JavacTask;
import static javax.tools.StandardLocation.CLASS_PATH;
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
import static javax.tools.JavaFileObject.Kind.CLASS;
public class Main {
public static PackageElement getPackage(TypeElement type) {
Element owner = type;
while (owner.getKind() != ElementKind.PACKAGE)
owner = owner.getEnclosingElement();
return (PackageElement)owner;
}
static int progress = 0;
static JavaCompiler tool;
static JavacTask javac;
static Elements elements;
public static void main(String[] args) throws Exception {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(CLASS_PATH, Collections.<File>emptyList());
JavacTask javac = (JavacTask)tool.getTask(null, fm, null, null, null, null);
Elements elements = javac.getElements();
final Set<String> packages = new LinkedHashSet<String>();
int nestedClasses = 0;
int classes = 0;
for (JavaFileObject file : fm.list(PLATFORM_CLASS_PATH, "", EnumSet.of(CLASS), true)) {
String type = fm.inferBinaryName(PLATFORM_CLASS_PATH, file);
if (type.endsWith("package-info"))
continue;
try {
TypeElement elem = elements.getTypeElement(type);
if (elem == null && type.indexOf('$') > 0) {
nestedClasses++;
type = null;
continue;
}
classes++;
packages.add(getPackage(elem).getQualifiedName().toString());
elements.getTypeElement(type).getKind(); // force completion
type = null;
} finally {
if (type != null)
System.err.println("Looking at " + type);
}
}
javac = null;
elements = null;
javac = (JavacTask)tool.getTask(null, fm, null, null, null, null);
elements = javac.getElements();
for (String name : packages) {
PackageElement pe = elements.getPackageElement(name);
for (Element e : pe.getEnclosedElements()) {
e.getSimpleName().getClass();
}
}
/*
* A few sanity checks based on current values:
*
* packages: 775, classes: 12429 + 5917
*
* As the platform evolves the numbers are likely to grow
* monotonically but in case somebody gets a clever idea for
* limiting the number of packages exposed, this number might
* drop. So we test low values.
*/
System.out.format("packages: %s, classes: %s + %s%n",
packages.size(), classes, nestedClasses);
if (classes < 9000)
throw new AssertionError("Too few classes in PLATFORM_CLASS_PATH ;-)");
if (packages.size() < 530)
throw new AssertionError("Too few packages in PLATFORM_CLASS_PATH ;-)");
if (nestedClasses < 3000)
throw new AssertionError("Too few nested classes in PLATFORM_CLASS_PATH ;-)");
}
}
| 4,872 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
NoSupers.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/NoSupers.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 6346453
* @summary directSupertypes should return empty list if arg has no supertypes
* @author Scott Seligman
* @library ../../../lib
* @build JavacTestingAbstractProcessor NoSupers
* @compile -processor NoSupers -proc:only NoSupers.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
public class NoSupers extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> tes,
RoundEnvironment round) {
if (round.processingOver()) return true;
PrimitiveType intType = types.getPrimitiveType(TypeKind.INT);
if (! types.directSupertypes(intType).isEmpty())
throw new AssertionError();
return true;
}
}
| 1,914 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Superless.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/Superless.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.
*/
// A class with a missing superclass. Used by GetTypeElemBadArg.java.
class Superless extends MissingClass {
}
| 1,165 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
GetTypeElemBadArg.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/GetTypeElemBadArg.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 6346506 6408241
* @summary getTypeElement should tolerate a type that can't be found
* @author Scott Seligman
* @library ../../../lib
* @build JavacTestingAbstractProcessor GetTypeElemBadArg
* @compile -processor GetTypeElemBadArg -proc:only GetTypeElemBadArg.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
public class GetTypeElemBadArg extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> tes,
RoundEnvironment round) {
if (round.processingOver()) return true;
// A missing superclass should be tolerated.
TypeElement te = elements.getTypeElement("Superless");
tellAbout(te);
te = elements.getTypeElement("Bo.o.o.gus");
if (te != null) {
tellAbout(te);
throw new AssertionError();
}
return true;
}
private static void tellAbout(TypeElement t) {
System.out.println(t);
System.out.println(t.getClass());
System.out.println(t.getKind());
System.out.println();
}
}
| 2,318 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
OverridesSpecEx.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/OverridesSpecEx.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 6453386
* @summary Verify that example code in Elements.overrides works as spec'ed.
* @author Scott Seligman
* @library ../../../lib
* @build JavacTestingAbstractProcessor
* @compile -g OverridesSpecEx.java
* @compile -processor OverridesSpecEx -proc:only OverridesSpecEx.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
public class OverridesSpecEx extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
if (!round.processingOver())
doit(annoTypes, round);
return true;
}
private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
TypeElement string = elements.getTypeElement("java.lang.String");
TypeElement object = elements.getTypeElement("java.lang.Object");
ExecutableElement m1 = null;
ExecutableElement m2 = null;
for (ExecutableElement m : methodsIn(string.getEnclosedElements())) {
if (m.getSimpleName().contentEquals("hashCode")) {
m1 = m;
break;
}
}
for (ExecutableElement m : methodsIn(object.getEnclosedElements())) {
if (m.getSimpleName().contentEquals("hashCode")) {
m2 = m;
break;
}
}
boolean res =
elements.overrides(m1, m2, (TypeElement) m1.getEnclosingElement());
System.out.println("String.hashCode overrides Object.hashCode? " + res);
checkResult(res);
TypeElement a = elements.getTypeElement("OverridesSpecEx.A");
TypeElement b = elements.getTypeElement("OverridesSpecEx.B");
TypeElement c = elements.getTypeElement("OverridesSpecEx.C");
m1 = null;
m2 = null;
for (ExecutableElement m : methodsIn(a.getEnclosedElements()))
m1 = m;
for (ExecutableElement m : methodsIn(b.getEnclosedElements()))
m2 = m;
res = elements.overrides(m1, m2, a);
System.out.println("A.m overrides B.m in B? " + res);
checkResult(!res);
res = elements.overrides(m1, m2, c);
System.out.println("A.m overrides B.m in C? " + res);
checkResult(res);
}
private static void checkResult(boolean truthiness) {
if (!truthiness)
throw new AssertionError("Bogus result");
}
// Fodder for the processor
class A {
public void m() {}
}
interface B {
void m();
}
class C extends A implements B {
}
}
| 3,897 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
BinaryName.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/BinaryName.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 6346251
* @summary Test Elements.getBinaryName
* @author Scott Seligman
* @library ../../../lib
* @build JavacTestingAbstractProcessor BinaryName
* @compile -processor BinaryName -proc:only BinaryName.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.typesIn;
@HelloIm("BinaryName")
public class BinaryName extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> tes,
RoundEnvironment round) {
if (round.processingOver()) return true;
Set<? extends TypeElement> ts = typesIn(round.getElementsAnnotatedWith(
elements.getTypeElement("HelloIm")));
boolean success = true;
for (TypeElement t : ts) {
String expected = t.getAnnotation(HelloIm.class).value();
CharSequence found = elements.getBinaryName(t);
if (expected.contentEquals(found)) {
System.out.println(expected + " == " + found);
} else {
success = false;
System.out.println(expected + " != " + found + " [FAIL]");
}
}
if (! success)
throw new AssertionError();
return true;
}
@HelloIm("BinaryName$Nested")
private static class Nested {
}
}
@interface HelloIm {
String value();
}
| 2,579 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TypesBadArg.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/TypesBadArg.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 6345812
* @summary Validate argument kinds in Types utilities
* @author Scott Seligman
* @library ../../../lib
* @build JavacTestingAbstractProcessor TypesBadArg
* @compile -processor TypesBadArg -proc:only TypesBadArg.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
public class TypesBadArg extends JavacTestingAbstractProcessor {
boolean success = true;
public boolean process(Set<? extends TypeElement> tes,
RoundEnvironment round) {
if (round.processingOver()) return true;
final Elements elements = processingEnv.getElementUtils();
final Types types = processingEnv.getTypeUtils();
final TypeMirror javaLang =
elements.getPackageElement("java.lang").asType();
makeBadCall(new Runnable() {
public void run() {
types.isSubtype(javaLang, javaLang);
}
});
makeBadCall(new Runnable() {
public void run() {
types.isAssignable(javaLang, javaLang);
}
});
makeBadCall(new Runnable() {
public void run() {
types.contains(javaLang, javaLang);
}
});
makeBadCall(new Runnable() {
public void run() {
types.directSupertypes(javaLang);
}
});
makeBadCall(new Runnable() {
public void run() {
types.erasure(javaLang);
}
});
makeBadCall(new Runnable() {
public void run() {
types.capture(javaLang);
}
});
makeBadCall(new Runnable() {
public void run() {
types.unboxedType(javaLang);
}
});
makeBadCall(new Runnable() {
public void run() {
types.unboxedType(types.getNoType(TypeKind.VOID));
}
});
if (! success)
throw new AssertionError("Some test(s) failed.");
return true;
}
private void makeBadCall(Runnable runnable) {
try {
runnable.run();
System.out.println("Failure: IllegalArgumentException expected");
success = false;
} catch (IllegalArgumentException e) {
System.out.println("IllegalArgumentException as expected");
}
}
}
| 3,574 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
DirectSupersOfErr.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/directSupersOfErr/DirectSupersOfErr.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 6346973
* @summary directSupertypes(t) should not return t
* @author Scott Seligman
* @library ../../../../lib
* @build JavacTestingAbstractProcessor DirectSupersOfErr
* @compile -processor DirectSupersOfErr -proc:only C1.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
public class DirectSupersOfErr extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> tes,
RoundEnvironment round) {
if (round.processingOver()) return true;
for (TypeElement te : typesIn(round.getRootElements())) {
TypeMirror sup = te.getSuperclass();
for (TypeMirror supOfSup : types.directSupertypes(sup)) {
if (sup == supOfSup)
throw new AssertionError("I'm my own supertype.");
}
}
return true;
}
}
| 2,114 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
C1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/directSupersOfErr/C1.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 C1 extends Bogus {
}
| 1,079 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestGetConstantExpression.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/elements/TestGetConstantExpression.java | /*
* Copyright (c) 2009, 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 6471577 6517779
* @summary Test Elements.getConstantExpression
* @author Joseph D. Darcy
* @library ../../../../lib
* @build JavacTestingAbstractProcessor TestGetConstantExpression
* @compile -processor TestGetConstantExpression Foo.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
import static javax.tools.Diagnostic.Kind.*;
import static javax.tools.StandardLocation.*;
import java.io.*;
/**
* Test basic workings of Elements.getConstantExpression.
*/
public class TestGetConstantExpression extends JavacTestingAbstractProcessor {
private int round = 1;
/**
* Check expected behavior on classes and packages.
*/
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
int errors = 0;
boolean processingOver = roundEnv.processingOver();
if (!processingOver && round == 1) {
errors += expectIllegalArgumentException(null);
errors += expectIllegalArgumentException(this);
// Generate source code with various constant values and
// make sure it compiles.
try {
PrintWriter pw = new PrintWriter(filer.createSourceFile("ConstantTest").openWriter());
try {
Boolean[] booleans = {true, false};
Byte[] bytes = {Byte.MIN_VALUE, -1, 0, 1, Byte.MAX_VALUE};
Short[] shorts = {Short.MIN_VALUE, -1, 0, 1, Short.MAX_VALUE};
Integer[] ints = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
Long[] longs = {Long.MIN_VALUE, -1L, 0L,1L, Long.MAX_VALUE};
Character[] chars = {Character.MIN_VALUE, ' ', '\t', 'a', 'b', 'c', '~', Character.MAX_VALUE};
Float[] floats = {Float.NaN, Float.NEGATIVE_INFINITY, -1.0f, -0.0f, 0.0f, 1.0f, Float.POSITIVE_INFINITY};
Double[] doubles = {Double.NaN, Double.NEGATIVE_INFINITY, -1.0, -0.0, 0.0, 1.0, Double.POSITIVE_INFINITY};
pw.println("class ConstantTest {");
pw.println(String.format(" private static boolean[] booleans = {%s};",
printConstants(booleans)));
pw.println(String.format(" private static byte[] bytes = {%s};",
printConstants(bytes)));
pw.println(String.format(" private static short[] shorts = {%s};",
printConstants(shorts)));
pw.println(String.format(" private static int[] ints = {%s};",
printConstants(ints)));
pw.println(String.format(" private static long[] longs = {%s};",
printConstants(longs)));
pw.println(String.format(" private static char[] chars = {%s};",
printConstants(chars)));
pw.println(String.format(" private static float[] floats = {%s};",
printConstants(floats)));
pw.println(String.format(" private static double[] doubles = {%s};",
printConstants(doubles)));
pw.println("}");
} finally {
pw.close();
}
} catch(IOException io) {
throw new RuntimeException(io);
}
round++;
} else if (processingOver) {
if (errors > 0) {
throw new RuntimeException();
}
}
return true;
}
String printConstants(Object[] constants) {
StringBuilder sb = new StringBuilder();
for(Object o : constants) {
sb.append(eltUtils.getConstantExpression(o));
sb.append(", ");
}
return sb.toString();
}
int expectIllegalArgumentException(Object o) {
String s = "";
try {
s = eltUtils.getConstantExpression(o);
System.err.println("Unexpected string returned: " + s);
return 1;
} catch (IllegalArgumentException iae) {
return 0;
}
}
}
| 5,702 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestGetPackageOf.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/elements/TestGetPackageOf.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 6453386
* @summary Test Elements.getPackageOf
* @author Joseph D. Darcy
* @library ../../../../lib
* @build JavacTestingAbstractProcessor TestGetPackageOf
* @compile -processor TestGetPackageOf -proc:only TestGetPackageOf.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
import static javax.tools.Diagnostic.Kind.*;
import static javax.tools.StandardLocation.*;
/**
* Test basic workings of Elements.getPackageOf
*/
public class TestGetPackageOf extends JavacTestingAbstractProcessor {
/**
* Check expected behavior on classes and packages.
*/
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
TypeElement stringElt = eltUtils.getTypeElement("java.lang.String");
PackageElement javaLangPkg = eltUtils.getPackageElement("java.lang");
PackageElement unnamedPkg = eltUtils.getPackageElement("");
PackageElement pkg = null;
if (!javaLangPkg.equals(pkg=eltUtils.getPackageOf(stringElt) ) )
throw new RuntimeException("Unexpected package for String: " + pkg);
if (!javaLangPkg.equals(pkg=eltUtils.getPackageOf(javaLangPkg) ) )
throw new RuntimeException("Unexpected package for java.lang: " + pkg);
if (!unnamedPkg.equals(pkg=eltUtils.getPackageOf(unnamedPkg) ) )
throw new RuntimeException("Unexpected package for unnamed pkg: " + pkg);
}
return true;
}
}
| 2,858 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
VacuousEnum.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/elements/VacuousEnum.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 6937417
* @summary Test -Xprint on enum type with no constants
* @author Joseph D. Darcy
* @compile -Xprint VacuousEnum.java
*/
public enum VacuousEnum {
// But alas, no enum constants!
}
| 1,269 | 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/processing/model/util/elements/Foo.java |
/*
* Copyright (c) 2009, 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.
*/
/**
* Dummy type to compile.
*/
public class Foo {
}
| 1,114 | 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/processing/model/util/elements/doccomments/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 6877202 6986246
* @summary Elements.getDocComment() is not getting JavaDocComments
*/
import com.sun.source.tree.*;
import com.sun.source.util.*;
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import javax.tools.*;
/*
* For a mixture of pre-existing and generated source files, ensure that we can
* get the doc comments.
* The test uses both a standard ElementScanner to find all the elements being
* processed, and a TreeScanner to find all the local and anonymous inner classes
* as well.
* And, because the relevant code paths in the compiler are different for
* command line and JSR 199 invocation, the test covers both ways of invoking the
* compiler.
*/
@SupportedOptions("scan")
@SupportedAnnotationTypes("*")
public class TestDocComments extends AbstractProcessor {
enum CompileKind { API, CMD };
enum ScanKind { TREE, ELEMENT };
// ----- Main test driver: invoke compiler for the various test cases ------
public static void main(String... args) throws Exception {
for (CompileKind ck: CompileKind.values()) {
for (ScanKind sk: ScanKind.values()) {
try {
test(ck, sk);
} catch (IOException e) {
error(e.toString());
}
}
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
static void test(CompileKind ck, ScanKind sk) throws IOException {
String testClasses = System.getProperty("test.classes");
String testSrc = System.getProperty("test.src");
File testDir = new File("test." + ck + "." + sk);
testDir.mkdirs();
String[] opts = {
"-d", testDir.getPath(),
"-implicit:none",
"-processor", TestDocComments.class.getName(),
"-processorpath", testClasses,
//"-XprintRounds",
"-Ascan=" + sk
};
File[] files = {
new File(testSrc, "a/First.java")
};
if (ck == CompileKind.API)
test_javac_api(opts, files);
else
test_javac_cmd(opts, files);
}
static void test_javac_api(String[] opts, File[] files) throws IOException {
System.err.println("test javac api: " + Arrays.asList(opts) + " " + Arrays.asList(files));
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic diagnostic) {
error(diagnostic.toString());
}
};
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> units = fm.getJavaFileObjects(files);
JavacTask t = (JavacTask) c.getTask(null, fm, dl, Arrays.asList(opts), null, units);
t.parse();
t.analyze();
}
static void test_javac_cmd(String[] opts, File[] files) {
System.err.println("test javac cmd: " + Arrays.asList(opts) + " " + Arrays.asList(files));
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
List<String> args = new ArrayList<String>(Arrays.asList(opts));
for (File f: files)
args.add(f.getPath());
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
pw.close();
String out = sw.toString();
if (out.length() > 0)
System.err.println(out);
if (rc > 0)
error("Compilation failed: rc=" + rc);
}
static void error(String msg) {
System.err.println(msg);
errors++;
//throw new Error(msg);
}
static int errors;
// ----- Annotation processor: scan for elements and check doc comments ----
Map<String,String> options;
Filer filer;
Messager messager;
Elements elements;
Trees trees;
ScanKind skind;
int round = 0;
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
@Override
public void init(ProcessingEnvironment pEnv) {
super.init(pEnv);
options = pEnv.getOptions();
filer = pEnv.getFiler();
messager = pEnv.getMessager();
elements = pEnv.getElementUtils();
trees = Trees.instance(processingEnv);
skind = ScanKind.valueOf(options.get("scan"));
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
round++;
// Scan elements using an appropriate scanner, and for each element found,
// call check(Element e) to verify the doc comment on that element
for (Element e: roundEnv.getRootElements()) {
System.err.println("scan " + skind + " " + e.getKind() + " " + e.getSimpleName());
if (skind == ScanKind.TREE) {
new TestTreeScanner().scan(trees.getPath(e), trees);
} else
new TestElementScanner().scan(e);
}
// For a few rounds, generate new source files, so that we can check whether
// doc comments are correctly handled in subsequent processing rounds
final int MAX_ROUNDS = 3;
if (round <= MAX_ROUNDS) {
String pkg = "p";
String currClass = "Gen" + round;
String curr = pkg + "." + currClass;
String next = (round < MAX_ROUNDS) ? (pkg + ".Gen" + (round + 1)) : "z.Last";
StringBuilder text = new StringBuilder();
text.append("package ").append(pkg).append(";\n");
text.append("/** CLASS ").append(currClass).append(" */\n");
text.append("public class ").append(currClass).append(" {\n");
text.append(" /** CONSTRUCTOR <init> **/\n");
text.append(" ").append(currClass).append("() { }\n");
text.append(" /** FIELD x */\n");
text.append(" ").append(next).append(" x;\n");
text.append(" /** METHOD m */\n");
text.append(" void m() { }\n");
text.append("}\n");
try {
JavaFileObject fo = filer.createSourceFile(curr);
Writer out = fo.openWriter();
try {
out.write(text.toString());
} finally {
out.close();
}
} catch (IOException e) {
throw new Error(e);
}
}
return true;
}
/*
* Check that the doc comment on an element is as expected.
* This method is invoked for each element found by the scanners run by process.
*/
void check(Element e) {
System.err.println("Checking " + e);
String dc = elements.getDocComment(e);
System.err.println(" found " + dc);
String expect = (e.getKind() + " " + e.getSimpleName()); // default
Name name = e.getSimpleName();
Element encl = e.getEnclosingElement();
Name enclName = encl.getSimpleName();
ElementKind enclKind = encl.getKind();
switch (e.getKind()) {
case PARAMETER:
case LOCAL_VARIABLE:
// doc comments not retained for these elements
expect = null;
break;
case CONSTRUCTOR:
if (enclName.length() == 0 || enclKind == ElementKind.ENUM) {
// Enum constructor is synthetic
expect = null;
}
break;
case METHOD:
if (enclKind == ElementKind.ENUM
&& (name.contentEquals("values") || name.contentEquals("valueOf"))) {
// synthetic enum methods
expect = null;
}
break;
case CLASS:
if (e.getSimpleName().length() == 0) {
// anon inner class
expect = null;
}
break;
}
System.err.println(" expect " + expect);
if (dc == null ? expect == null : dc.trim().equals(expect))
return;
if (dc == null)
messager.printMessage(Diagnostic.Kind.ERROR, "doc comment is null", e);
else {
messager.printMessage(Diagnostic.Kind.ERROR,
"unexpected comment: \"" + dc + "\", expected \"" + expect + "\"", e);
}
}
// ----- Scanners to find elements -----------------------------------------
class TestElementScanner extends ElementScanner7<Void, Void> {
@Override
public Void visitExecutable(ExecutableElement e, Void _) {
check(e);
return super.visitExecutable(e, _);
}
@Override
public Void visitType(TypeElement e, Void _) {
check(e);
return super.visitType(e, _);
}
@Override
public Void visitVariable(VariableElement e, Void _) {
check(e);
return super.visitVariable(e, _);
}
}
class TestTreeScanner extends TreePathScanner<Void,Trees> {
@Override
public Void visitClass(ClassTree tree, Trees trees) {
check(trees.getElement(getCurrentPath()));
return super.visitClass(tree, trees);
}
@Override
public Void visitMethod(MethodTree tree, Trees trees) {
check(trees.getElement(getCurrentPath()));
return super.visitMethod(tree, trees);
}
@Override
public Void visitVariable(VariableTree tree, Trees trees) {
check(trees.getElement(getCurrentPath()));
return super.visitVariable(tree, trees);
}
}
}
| 11,016 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Last.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/elements/doccomments/z/Last.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 z;
// This class should be read last, implicitly. Therefore it should not
// be subject to anno processing. If it is, the lack of doc comments should
// be detected and will flag an error.
public class Last {
}
| 1,272 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
First.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/elements/doccomments/a/First.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 a;
/** CLASS First */
public class First {
/** CONSTRUCTOR <init> */
First() { }
/** FIELD x */
p.Gen1 x;
/** METHOD m **/
void m(int i) {
/** CLASS Local */
class Local {
/** CONSTRUCTOR <init> */
Local() { }
}
Runnable r = new Runnable() {
/** METHOD run **/
public void run() { }
};
}
/** ENUM E */
enum E {
/** ENUM_CONSTANT e1 */
e1
}
}
| 1,552 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestDeprecation.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/deprecation/TestDeprecation.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 6392818
* @summary Tests Elements.isDeprecated(Element)
* @author Joseph D. Darcy
* @library ../../../../lib
* @build JavacTestingAbstractProcessor
* @compile TestDeprecation.java
* @compile -processor TestDeprecation -proc:only Dep1.java
* @compile Dep1.java
* @compile -processor TestDeprecation -proc:only Dep1 TestDeprecation.java
*/
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.tools.Diagnostic.Kind.*;
import java.io.Writer;
/**
* This processor verifies that the information returned by
* getElementsAnnotatedWith is consistent with the expected results
* stored in an AnnotatedElementInfo annotation.
*/
public class TestDeprecation extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
boolean failure = false;
if (!roundEnv.processingOver()) {
DeprecationChecker deprecationChecker = new DeprecationChecker();
for(Element element: roundEnv.getRootElements() ) {
System.out.println("\nRoot Element: " + element.getSimpleName());
failure = deprecationChecker.scan(element);
}
if (failure)
processingEnv.getMessager().printMessage(ERROR, "Deprecation mismatch found!");
}
return true;
}
private class DeprecationChecker extends ElementScanner7<Boolean,Void> {
private Elements elementUtils;
private boolean failure;
DeprecationChecker() {
super(false);
elementUtils = processingEnv.getElementUtils();
failure = false;
}
@Override
public Boolean scan(Element e, Void p) {
boolean expectedDeprecation = false;
ExpectedDeprecation tmp = e.getAnnotation(ExpectedDeprecation.class);
if (tmp != null)
expectedDeprecation = tmp.value();
boolean actualDeprecation = elementUtils.isDeprecated(e);
System.out.printf("\tVisiting %s\t%s%n", e.getKind(), e.getSimpleName());
if (expectedDeprecation != actualDeprecation) {
failure = true;
java.io.StringWriter w = new java.io.StringWriter();
elementUtils.printElements(w, e);
System.out.printf("For the deprecation of %n\t%s\t, expected %b, got %b.%n",
w.getBuffer().toString(),
expectedDeprecation, actualDeprecation);
}
super.scan(e, p);
return failure;
}
}
}
| 3,896 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Dep1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/deprecation/Dep1.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.
*/
/**
* This class is used as input to TestDeprecation.java.
*/
@ExpectedDeprecation(false)
public class Dep1 {
/**
* @deprecated
*/
@ExpectedDeprecation(true)
public void method1() {}
@Deprecated
@ExpectedDeprecation(true)
public void method2() {}
// Parameters can't be deprecated.
public void method3(/**
* TODO re-deprecate once bug 6404756 is fixed.
* @ deprecated
*/
@ExpectedDeprecation(false)
Object method3_param0) {}
public void method4(// @Deprecated -- TODO uncomment once bug 6404756 is fixed.
@ExpectedDeprecation(false)
Object method4_param0, Object method4_param1) {}
@ExpectedDeprecation(false)
public void methodn() {}
@ExpectedDeprecation(false)
private Object field0;
@Deprecated
@ExpectedDeprecation(true)
private Object field1;
/**
* @deprecated
*/
@ExpectedDeprecation(true)
private Object field3;
@ExpectedDeprecation(true)
@Deprecated
class NestedClass {}
}
| 2,224 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ExpectedDeprecation.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/deprecation/ExpectedDeprecation.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.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* Whether or not an element is expected to be deprecated.
*/
@Retention(RUNTIME)
public @interface ExpectedDeprecation {
boolean value();
}
| 1,287 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestIterables.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/filter/TestIterables.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 6406164
* @summary Test that ElementFilter iterable methods behave properly.
* @author Joseph D. Darcy
* @library ../../../../lib
* @build JavacTestingAbstractProcessor
* @compile TestIterables.java
* @compile -processor TestIterables -proc:only Foo1.java
* @compile Foo1.java
* @compile -processor TestIterables Foo1 TestIterables.java
*/
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import java.util.Iterator;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.tools.Diagnostic.Kind.*;
import static javax.lang.model.util.ElementFilter.*;
/**
* Verify that the {@code ElementFilter} methods taking iterables
* behave correctly by comparing ExpectedElementCounts with actual
* results.
*/
@SupportedAnnotationTypes("ExpectedElementCounts")
@ExpectedElementCounts(methods=2)
public class TestIterables extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
boolean error = false;
int topLevelCount = 0;
for (TypeElement type : typesIn(roundEnv.getRootElements())) {
topLevelCount++;
ExpectedElementCounts elementCounts = type.getAnnotation(ExpectedElementCounts.class);
if (elementCounts == null)
throw new RuntimeException("Missing ExpectedElementCounts annotation!");
Iterable<? extends Element> irritable = type.getEnclosedElements();
int constructorCount = getCount(constructorsIn(irritable));
int fieldCount = getCount(fieldsIn(irritable));
int methodCount = getCount(methodsIn(irritable));
int typeCount = getCount(typesIn(irritable));
System.out.println("\nType: " + type.getQualifiedName());
System.out.format("Element Actual\tExpected%n");
System.out.format("constructors %d\t\t%d%n", constructorCount, elementCounts.constructors());
System.out.format("fields %d\t\t%d%n", fieldCount, elementCounts.fields());
System.out.format("methods %d\t\t%d%n", methodCount, elementCounts.methods());
System.out.format("types %d\t\t%d%n", typeCount, elementCounts.types());
if ((constructorCount != elementCounts.constructors()) ||
(fieldCount != elementCounts.fields()) ||
(methodCount != elementCounts.methods()) ||
(typeCount != elementCounts.types()) )
error = true;
}
if (topLevelCount == 0)
error = true;
if (error)
throw new RuntimeException("A count mismatch has occured.");
}
return true;
}
private int getCount(Iterable<? extends Element> iter) {
int count1 = 0;
int count2 = 0;
Iterator<? extends Element> iterator = iter.iterator();
while (iterator.hasNext() ) {
count1++;
iterator.next();
}
iterator = iter.iterator();
while (iterator.hasNext() ) {
count2++;
iterator.next();
}
if (count1 != count2)
throw new RuntimeException("Inconsistent counts from iterator.");
return count1;
}
}
| 4,731 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ExpectedElementCounts.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/filter/ExpectedElementCounts.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.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* Expected counts of ElementFilter.{fieldsIn, constructorsIn,
* methodsIn, typesIn} on a class.
*/
@Retention(RUNTIME)
public @interface ExpectedElementCounts {
int constructors() default 1;
int fields() default 0;
int methods() default 0;
int types() default 0;
}
| 1,443 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Foo1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/util/filter/Foo1.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.
*/
@ExpectedElementCounts(constructors=2, fields=5, methods=4, types=3)
public class Foo1 {
private Foo1() {}
private Foo1(Object o) {}
private static class Type1 {}
private static class Type2 {}
private static class Type3 {}
static void method1(){};
void method2(){};
static void method3(){};
void method4(){};
static Object field1;
int field2;
int field3 = 3;
Object field4;
static double field5 = 3.14159;
}
| 1,519 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
FallThrough.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/lint/FallThrough.java | /*
* Copyright (c) 2003, 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 4821359 4981267
* @summary Add -Xlint flag
* @author gafter
*
* @compile/fail -Xlint:fallthrough -Werror FallThrough.java
*/
class FallThrough {
int x;
void f(int i) {
switch (i) {
case 0:
x = 0;
case 1:
case 2:
x = 2;
break;
default:
x = 3;
}
}
}
| 1,440 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Unchecked.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/lint/Unchecked.java | /*
* Copyright (c) 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 4821359
* @summary Add -Xlint flag
* @author gafter
*
* @compile/fail -Xlint:unchecked -Werror Unchecked.java
*/
class Unchecked<T> {
void f(Unchecked u) {
Unchecked<String> us = u;
}
}
| 1,280 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
NoWarn.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/lint/NoWarn.java | /**
* @test /nodynamiccopyright/
* @bug 6183484
* @summary verify -nowarn is the same as -Xlint:none
* @compile/ref=NoWarn1.out -XDrawDiagnostics NoWarn.java
* @compile/ref=NoWarn2.out -XDrawDiagnostics -nowarn NoWarn.java
* @compile/ref=NoWarn2.out -XDrawDiagnostics -Xlint:none NoWarn.java
*/
class NoWarn {
void m(Object... args) { }
void foo() {
m(null);
}
}
| 408 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Deprecation.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/lint/Deprecation.java | /*
* Copyright (c) 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 4821359
* @summary Add -Xlint flag
* @author gafter
*
* @compile/fail -Xlint:deprecation -Werror Deprecation.java
*/
/** @deprecated */
class A {
}
class B extends A {
}
| 1,249 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T7102515.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/7102515/T7102515.java | /*
* @test /nodynamiccopyright/
* @bug 7102515
* @summary javac running very very long and not returning
* @compile/fail/ref=T7102515.out -XDrawDiagnostics T7102515.java
*/
class T7102515 {
T7102515 badBinary = new T7102515() + new T7102515();
Object badUnary = badBinary++;
}
| 291 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
RefEqual.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/RefEqual.java | /*
* Copyright (c) 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 4948130
* @summary casting conversion checks changed for covariant returns
* @author gafter
*
* @compile -source 1.4 RefEqual.java
* @compile/fail RefEqual.java
*/
class RefEqual {
{
Class c = null;
if (String.class != Integer.class) ;
}
}
| 1,344 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
CyclicInheritance5.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/CyclicInheritance5.java | /*
* Copyright (c) 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 4862621
* @summary generics: incorrect cyclic inheritance error
*
* @compile CyclicInheritance5.java
*/
class G<N extends G.Node<N>> {
static class Node<N extends Node<N>> {
}
}
class F extends G<F.MyNode> {
static class MyNode extends G.Node<MyNode> {
}
}
| 1,351 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4683314.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4683314.java | /*
* Copyright (c) 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 4683314
* @summary generics: overload resolution error in non-generic code
* @author gafter
*
* @compile T4683314.java
*/
class T4683314a {
java.util.Hashtable tables;
}
class T4683314b {
void main() {
java.util.Properties retries = null;
retries.put("foo", String.valueOf(12));
}
}
| 1,390 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
GenericMerge.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/GenericMerge.java | /*
* Copyright (c) 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 4838146
* @summary generics: compiler crash merging signatures of generic methods
* @author gafter
*
* @compile GenericMerge.java
*/
class Box<T> {}
interface N1 {
<T> Box<T> box(T t);
}
interface N2 {
<T> Box<T> box(T t);
}
abstract class GenericMerge implements N1, N2 {
void f(Object o) {
box(o);
}
}
| 1,409 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4695348.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4695348.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 4695348
* @summary generics: compiler allows ref to type bounds in static members
* @author gafter
*
* @compile/fail T4695348.java
*/
class T4695348<T> {
static T x = null;
}
| 1,258 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Casting4.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Casting4.java | /*
* Copyright (c) 2004, 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 5041230
* @summary Cannot cast Comparable<?>s
* @author gafter
*
* @compile -Werror -Xlint:unchecked Casting4.java
*/
package Casting4;
class Casting4 {
<M> Integer f(Comparable<M> c) {
return (Integer) c;
}
Integer g(Comparable<?> c) {
return (Integer) c;
}
}
| 1,379 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
LoadOrder.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/LoadOrder.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 4629627
* @summary generics: generic class files can cause recursive class loading (crashing javac)
* @author gafter
*
* @compile LoadOrder.java
*/
import java.util.Collections;
class Test2 {
public static void main(String[] args) {
}
}
| 1,324 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InstanceOf2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/InstanceOf2.java | /*
* Copyright (c) 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 4982096 5004321
* @summary the type in an instanceof expression must be reifiable
* @author seligman
*
* @compile/fail InstanceOf2.java
*/
public class InstanceOf2 {
boolean m() {
return this.getClass() instanceof Class<InstanceOf2>;
}
}
| 1,333 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
SilentUnchecked.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/SilentUnchecked.java | /*
* Copyright (c) 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 5029336
* @summary unchecked conversion from raw to reifiable generic requires no warning
* @author gafter
*
* @compile -Xlint:unchecked -Werror SilentUnchecked.java
*/
package silent.unchecked;
class SilentUnchecked {
void f(Class c) {
g(c);
}
void g(Class<?> c) {
}
}
| 1,374 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InheritanceConflict2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/InheritanceConflict2.java | /*
* Copyright (c) 2004, 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 4984158
* @summary two inherited methods with same signature
* @author gafter, Maurizio Cimadamore
*
* @compile InheritanceConflict2.java
*/
package inheritance.conflict2;
class A<T> {
void f(String s) {}
}
class B<T> extends A<T> {
void f(T t) {}
}
class C extends B<String> {
void f(String s) {}
}
| 1,400 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
BridgeOrder.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/BridgeOrder.java | /*
* Copyright (c) 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 4856981
* @summary generics: overridden method gets invoked (bridge method problem)
* @author gafter
*
* @compile BridgeOrder.java
* @run main BridgeOrder
*/
interface A<T> {
public void f(T x);
}
class X {
}
// Moving class B here makes the problem go away
class C<T extends X> extends B<T> implements A<T> {
// This also makes the problem go away.
/*
public void f(T x) {
super.f(x);
} */
}
class B<T extends X> implements A<T> {
public void f(T x) {
System.out.println("B.f()");
}
}
class D extends C<X> {
public void f(X y) {
System.out.println("D.f()");
}
}
public class BridgeOrder {
public static void main(String args[]) {
A<X> x = new D();
x.f(new X());
}
}
| 1,822 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Multibound1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Multibound1.java | /*
* Copyright (c) 2001, 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 4482403
* @summary javac failed to check second bound
* @author gafter
*
* @compile/fail Multibound1.java
*/
package Multibound1;
interface A {}
interface B {}
class C<T extends A&B> {}
class D implements A {}
class E extends C<D> {}
| 1,320 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TyparamStaticScope2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/TyparamStaticScope2.java | /*
* Copyright (c) 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 5046972
* @summary type parameter referenced in static inner class improperly allowed!
* @author gafter
*
* @compile/fail TyparamStaticScope2.java
*/
package typaram.static_.scope2;
class JBug<T> {
static class Inner1 implements Set<T> {}
}
interface Set<T> {}
| 1,346 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ExtendedRaw1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/ExtendedRaw1.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 4463802
* @summary generics: extension of raw not treated as raw.
* @author gafter
*
* @compile ExtendedRaw1.java
*/
class Comparator<T> {}
class Arrays {
public static <U, T extends U> void sort(T[] a, Comparator<U> c) {
throw new Error();
}
}
class JSR14Bug {
public static void main(String[] args) {
Object[] oa = null;
Arrays.sort(oa, new Comparator() {});
}
}
| 1,491 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4711572.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4711572.java | /*
* Copyright (c) 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 4711572
* @summary generics: problem with type inference for recursive methods
* @author gafter
*
* @compile T4683314.java
*/
class T4711572 {
static <T> boolean isOK(T x) {
return isOK(x);
}
static <T> boolean isStillOK(T x) {
return true && isOK(x);
}
static <T> boolean isNoMoreOK(T x) {
return true && isNoMoreOK(x);
}
static <T> boolean isOKAgain(T x) {
boolean res;
return true && (res = isOKAgain(x));
}
}
| 1,567 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6507024.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T6507024.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 6507024
* @summary unchecked conversion between arrays fails after capture conversion
* @author Maurizio Cimadamore
*
* @compile T6507024.java
*/
public class T6507024<T> {
<Z> void m(T6507024<Z>[] results) {
T6507024<Z>[] r = results.getClass().cast(null);
}
}
| 1,360 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
UncheckedCovariance.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/UncheckedCovariance.java | /*
* Copyright (c) 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 4949303
* @summary A method returning a raw type cannot override a method returning a generic type
* @author gafter
*
* @compile UncheckedCovariance.java
* @compile/fail -Xlint:unchecked -Werror UncheckedCovariance.java
*/
class UncheckedCovariance {
static class Box<T> { }
static class A {
Box<Integer> f() { return null; }
}
static class B extends A {
Box f() { return null; }
}
}
| 1,501 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Casting2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Casting2.java | /*
* Copyright (c) 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 4923047
* @summary stack overflow error compiling EnumSet.java
* @author gafter
*
* @compile Casting2.java
*/
import java.util.*;
public abstract class Casting2<E extends Enum<E>> extends AbstractSet<E>
implements Cloneable, java.io.Serializable
{
public static <E extends Enum<E>> Casting2<E> copyOf(Collection<E> s) throws CloneNotSupportedException {
return (Casting2<E>)((Casting2<E>)s).clone();
}
}
| 1,504 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4784219.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4784219.java | /*
* Copyright (c) 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 4784219
* @summary generics: compiler crash after diagnostic
* @author gafter
*
* @compile T4683314.java
*/
public class T4784219 {
static <T, A> T<A, A> genericNew() {
genericNew();
}
}
| 1,282 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
GetClass.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/GetClass.java | /*
* Copyright (c) 2003, 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 4919255 4982096 5004321
* @summary the type of x.getClass() is no longer Class<? extends X>
* @author gafter
*
* @compile/fail GetClass.java
*/
public class GetClass {
public static void main(String[] args) {
Class<? extends Class<GetClass>> x = GetClass.class.getClass();
}
}
| 1,378 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Conditional.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Conditional.java | /*
* Copyright (c) 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 4881179 4883239
* @summary Rule for semantics of ?: in the presence of generics and generic class Class
* @author gafter
*
* @compile Conditional.java
*/
package conditional;
import java.io.Serializable;
interface I {}
interface J {}
class A implements I, J {}
class B implements I, J {}
class C extends B {}
class Conditional {
static boolean cond = String.class.getName().length() == 1;
public static void main(String[] args) {
Class c = cond ? A.class : B.class;
Class<?> d = cond ? A.class : B.class;
Class<? extends B> e = cond ? B.class : C.class;
}
void f(A a, B b) {
I i = cond ? a : b;
J j = cond ? a : b;
}
// required for compatibility
Class g(Class a) {
return cond ? a : B.class;
}
// required for compatibility
byte[] h(byte[] a, byte[] b) {
return cond ? a : b;
}
// This one is hard because of the recursive F-bounds
// The naive result is the infinite type
// Class<? extends Number&Comparable<? extends Number&Comparable<? extends
// ...
Class<? extends Comparable<?>> c =
cond ? Integer.class : Float.class;
Comparable<?> o =
cond ? true : 3;
/*
// See 4942040
void f(Cloneable a, int[] b) {
Cloneable x = cond ? a : b;
}
void f(Serializable a, int[] b) {
Serializable x = cond ? a : b;
}
// See 4941882
void f(float[] a, int[] b) {
Serializable x = cond ? a : b;
}
*/
}
| 2,585 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Nonlinear.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Nonlinear.java | /*
* Copyright (c) 2001, 2007, 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 4607420
* @summary A bug in the original JSR14 generics specification
* created a loophole in the type system.
*
* @compile/fail Nonlinear.java
*/
public class Nonlinear {
// This is an example of lack of type safety for
// the version of javac from jsr14_adding_generics-1_0-ea
// It is a variant of the "classic" problem with polymorphic
// references in SML, which resulted in the usual array of
// fixes: notably value polymorphism.
// This code compiles, but produces a ClassCastException
// when executed, even though there are no explicit casts in
// the program.
public static void main (String [] args) {
Integer x = new Integer (5);
String y = castit (x);
System.out.println (y);
}
static <A,B> A castit (B x) {
// This method casts any type to any other type.
// Oh dear. This shouldn't type check, but does
// because build () returns a type Ref<*>
// which is a subtype of RWRef<A,B>.
final RWRef<A,B> r = build ();
r.set (x);
return r.get ();
}
static <A> Ref<A> build () {
return new Ref<A> ();
}
// Another way of doing this is a variant of the crackit
// example discussed in the draft specification.
//
// The original duplicate was:
//
// static <A> Pair <A,A> duplicate (A x) {
// return new Pair<A,A> (x,x);
// }
//
// which breaks the requirement that a type variable
// instantiated by * only occurs once in the result type.
//
// However, we can achieve the same result with a different
// type for duplicate, which uses its type variables linearly
// in the result:
static <A,B extends Ref<A>> Pair<Ref<A>,B> duplicate (B x) {
return new Pair<Ref<A>,B> (x,x);
}
// the cheat here is that A and B are used linearly in the result
// type, but not in the polymorphic bounds.
// We can use that to give an alternative implementation of
// castit.
static <A,B> A castit2 (B x) {
Pair <Ref<A>, Ref<B>> p = duplicate (build ());
p.snd.set (x);
return p.fst.get ();
}
}
interface RWRef<A,B> {
public A get ();
public void set (B x);
}
class Ref<A> implements RWRef <A,A> {
A contents;
public void set (A x) { contents = x; }
public A get () { return contents; }
}
class Pair<A,B> {
final A fst;
final B snd;
Pair (A fst, B snd) { this.fst = fst; this.snd = snd; }
}
| 3,607 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ExtendedRaw2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/ExtendedRaw2.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 4463802
* @summary generics: extension of raw not treated as raw.
* @author gafter
*
* @compile ExtendedRaw2.java
*/
// from library
interface Comparable<T> { }
interface List<E> { }
class Comparator<T> { }
class Collections {
public static <T extends Object & Comparable<T>>
int binarySearch(List<T> list, T key) {
throw new Error();
}
public static <T>
int binarySearch(List<T> list, T key, Comparator<T> c) {
throw new Error();
}
}
// user code below
class Record implements Comparable { }
class T {
public static void main(String[] arg) {
List records = null;
Record x = null;
int result = Collections.binarySearch(records, x);
}
}
| 1,790 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4711570.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4711570.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 4711570
* @summary generics: problem with methods when type parameter doesn't appear in signature
* @author gafter
*
* @compile T4711570.java
*/
class T4711570 {
public static int fi() {
return fi();
}
public static void gi() {
fi();
gi();
}
public static <T> int f() {
return f();
}
public static <T> void g() {
f(); // incompatible.types found: <T>int required: java.lang.Object
int i = f(); // workaround for f()
g(); // incompatible.types found: <T>void required: java.lang.Object
}
// required type looks strange
public static <T> void h() {
g(); // incompatible.types found: <T>void required: java.lang.Object
}
public static <T> int f(T x) {
return f(x);
}
public static <T> void g(T x) {
f(x);
g(x); // incompatible.types found: <T>void required: java.lang.Object
}
public static <T> void h(T x) {
g(x); // works fine now; why not in void g(T x)?
}
}
| 2,126 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
MissingBridge.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/MissingBridge.java | /*
* Copyright (c) 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 5021445
* @summary Calling inherited generics method via interface causes AbstractMethodError
* @author gafter
*
* @compile MissingBridge.java
* @run main MissingBridge
*/
class GenObject<T>
{
public void foo(T obj)
{
System.out.println("obj = "+obj);
}
}
interface TestInterface
{
void foo(String blah);
}
public class MissingBridge extends GenObject<String> implements TestInterface
{
public static void main(String[] args)
{
MissingBridge test = new MissingBridge();
TestInterface test2 = test;
// works
test.foo("blah");
// fails with AbstractMethodError
test2.foo("blah");
}
}
| 1,750 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4695847.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4695847.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 4695847
* @summary generics: problem with inference of primitive return values
* @author gafter
*
* @compile T4695847.java
*/
public class T4695847<T> {
T4695847<T> next;
static <T> int size(T4695847<T> bt) {
if (bt==null)
return 0;
else
return 1+size(bt.next);
}
static <T> int size2(T4695847<T> bt) {
return (bt==null) ? 0 : 1+size(bt.next);
}
}
| 1,495 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ExtendedRaw3.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/ExtendedRaw3.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 4632984
* @summary generics: bridge method not considered to fulfil interface in abstract class
* @author gafter
*
* @compile ExtendedRaw3.java
*/
interface MyComparable<T extends MyComparable<T>> {
int compareTo(T other);
}
abstract class MyEnum<E extends MyEnum<E>> implements MyComparable<E> {
public int compareTo(E other) {
return 0;
}
}
class MyColor extends MyEnum {
void f() {}
}
| 1,491 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
PrimitiveVariant.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/PrimitiveVariant.java | /*
* Copyright (c) 2001, 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 4471667
* @summary compiler allows overriding with different primitive return type
* @author gafter
*
* @compile/fail PrimitiveVariant.java
*/
package PrimitiveVariant;
interface I {
double m();
}
abstract class J {
int m() { return 2; }
}
class Main extends J implements I {
public short m() { return 1; }
}
| 1,409 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InnerInterface1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/InnerInterface1.java | /*
* Copyright (c) 2001, 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 4452899
* @summary Inner interfaces are not treated as static
* @author gafter
*
* @compile InnerInterface1.java
*/
package InnerInterface1;
interface Iterator<E> {
}
class Set<E> {
Iterator<E> iterator() { return null; }
}
interface Map<K,V> {
public interface Entry<K,V> {
}
public Set<Entry<K,V>> entrySet();
}
class Hashtable<K,V> implements Map<K,V> {
public Set<Entry<K,V>> entrySet() { return null; }
public void foo() {
Iterator<Map.Entry<K,V>> it = entrySet().iterator();
}
}
| 1,611 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
GenLit1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/GenLit1.java | /*
* Copyright (c) 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 4987844
* @summary compiler crash with ill-formed annotation
* @author gafter
*
* @compile/fail GenLit1.java
*/
package genLit1;
@interface X {
Class value();
}
@X(Z.class)
class Y<Z> {
}
| 1,273 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
FinalBridge.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/FinalBridge.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 4633201
* @summary generics: bridge for inherited final method can cause verify error
* @author gafter
*
* @compile FinalBridge.java
* @run main FinalBridge
*/
public class FinalBridge extends MyEnum<FinalBridge> {
public static void main(String[] args) {}
}
interface MyComparable<T extends MyComparable<T>> {
int compareTo(T other);
}
class MyEnum<E extends MyEnum<E>> implements MyComparable<E> {
public final int compareTo(E other) {
return 0;
}
}
| 1,556 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
PrimitiveClass.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/PrimitiveClass.java | /*
* Copyright (c) 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 5028351
* @summary int.class and ilk have wrong type (5028351 rejected)
* @author gafter
*
* @compile PrimitiveClass.java
*/
package primitive._class;
class PrimitiveClass {
Class<Integer> ci = int.class;
}
| 1,291 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ReverseOrder.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/ReverseOrder.java | /*
* Copyright (c) 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 4898502
* @summary problem with generic signature for reverseOrder
* @author gafter
*
* @compile ReverseOrder.java
*/
package test.reverseOrder;
import java.util.*;
class ReverseOrder {
static {
List l = new ArrayList();
Collections.sort(l, Collections.reverseOrder());
}
}
| 1,379 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4661029.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4661029.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.
*/
/*
* @bug 4661029
* @summary generics: assertion error using Arrays.fill
* @author gafter
*
* @compile T4661029.java
*/
public class T4661029 {
public static <E> void bug(E[] a, E e) {
java.util.Arrays.fill(a, 0, 100, e);
}
}
| 1,302 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
UnsoundInference.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/UnsoundInference.java | /*
* Copyright (c) 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 5020448
* @summary Generic method allowing passing of types that don't match collection types
* @author gafter
*
* @compile/fail UnsoundInference.java
*/
import java.util.ArrayList;
import java.util.Collection;
public class UnsoundInference {
public static void main(String[] args) {
Object[] objArray = {new Object()};
ArrayList<String> strList = new ArrayList<String>();
transferBug(objArray, strList);
String str = strList.get(0);
}
public static <Var> void transferBug(Var[] from, Collection<Var> to) {
to.add(from[0]);
}
}
| 1,666 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
MissingCast.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/MissingCast.java | /*
* Copyright (c) 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 5035001
* @summary redundant cast with generified APIs causes verify error
* @author gafter
*
* @compile MissingCast.java
* @run main MissingCast
*/
import java.util.*;
public class MissingCast {
protected Vector<String> v = null;
public void f() {
((String) (v.elementAt(0))).charAt(0);
}
public static void main(String[] args) {}
}
| 1,441 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4738171.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4738171.java | /*
* Copyright (c) 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 4738171
* @summary generics: problem with equivalence of generic types
* @author gafter
*
* @compile/fail T4738171.java
*/
interface If<T> {
final If<T> C0 = null;
}
| 1,249 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6869075.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T6869075.java | /*
* Copyright (c) 2009, 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 6869075
* @summary regression: javac crashes when compiling compound string assignment with generics
* @author mcimadamore
*/
public class T6869075 {
static class Foo<X> {
X x;
Foo (X x) {
this.x = x;
}
}
static void test1(Foo<String> foo) {
String start = foo.x;
equals(foo.x += "foo", start + "foo");
}
static void test2(Foo<String> foo) {
String start = foo.x;
equals((foo.x += "foo"), (start + "foo"));
}
static void test3(Foo<String> foo) {
String start = foo.x;
equals(((foo.x += "foo")), ((start + "foo")));
}
public static void main(String[] args) {
test1(new Foo<String>("Hello!"));
test2(new Foo<String>("Hello!"));
test3(new Foo<String>("Hello!"));
}
static void equals(String found, String req) {
if (!found.equals(req)) {
throw new AssertionError("Error (expected: "+ req +
" - found: " + found + ")");
}
}
}
| 2,135 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
SelfImplement.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/SelfImplement.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 4725668
* @summary generics: reject implementation with incorrect return type
* @author gafter
*
* @compile/fail SelfImplement.java
*/
class SelfImplement {
static abstract class A<T> {
abstract void f(T t);
public int f(Integer t) { return 3; }
}
static abstract class B extends A<Integer> {
// error: A<Integer>.f(Integer) returning int can't implement
// A<Integer>.f(Integer) returning void.
}
}
| 1,534 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Covar4.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Covar4.java | /*
* Copyright (c) 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 4965756
* @summary no covariant returns involving primitives
* @author gafter
*
* @compile/fail Covar4.java
*/
public class Covar4 {
static class A1 {
public long f() { return 12L; }
}
static class B1 extends A1 {
public int f() { return 12; }
}
}
| 1,359 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InstanceOf3.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/InstanceOf3.java | /*
* Copyright (c) 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 4982096 5004321
* @summary the type in an instanceof expression must be reifiable
* @author seligman
*
* @compile/fail InstanceOf3.java
*/
public class InstanceOf3 {
boolean m() {
return this.getClass() instanceof Class<? extends InstanceOf3>;
}
}
| 1,343 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ParenVerify.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/ParenVerify.java | /*
* Copyright (c) 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 4881397
* @summary generics: verify error when redundant parens used!
* @author gafter
*
* @compile ParenVerify.java
* @run main ParenVerify
*/
import java.util.*;
public class ParenVerify {
public static void main(String argss[]) {
for(Iterator<Integer> i = test("Foo"); i.hasNext(); )
System.out.println(i.next());
}
static HashMap<String, LinkedList<Integer>> m
= new HashMap<String, LinkedList<Integer>>();
public static Iterator<Integer> test(String s) {
LinkedList<Integer> lst = new LinkedList<Integer>();
lst.add(new Integer(12));
m.put("Hello", lst);
// jsr14-1.3ea generates code that won't verify.
// Removing the extra set of parenthesis in the
// statement below fixes the problem
lst = (m.get("Hello"));
return lst.iterator();
}
}
| 1,942 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
RelaxedArrays.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/RelaxedArrays.java | /*
* Copyright (c) 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 5009693
* @summary relaxed rules for array of generic type and varargs.
* @author gafter
*
* @compile RelaxedArrays.java
* @run main RelaxedArrays
*/
import java.util.ArrayList;
import java.util.List;
public class RelaxedArrays {
static class StringList extends ArrayList<String> {
}
static <T> T select(T... tl) {
return tl.length == 0 ? null : tl[tl.length - 1];
}
public static void main(String[] args) {
List<String>[] a = new StringList[20];
if (select("A", "B", "C") != "C") throw new Error();
}
}
| 1,635 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Casting.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Casting.java | /*
* Copyright (c) 2001, 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 4468840
* @summary generics problem with casting
* @author gafter
*
* @compile Casting.java
*/
package Casting;
class Test {}
class List<T> {
<T> T[] toArray(T[] a) { return null; }
}
public class Casting {
public static void main(String[] args) {
List<Test> l1 = null;
List<Test> l2 = (List<Test>)l1;
}
}
interface Map<K,V> {
void put(K k, V v);
V get(Object o);
}
interface Set<T> {
<T> T[] toArray(T[] a);
}
class Casting2 {
public static void main(String[] args){
Map<Integer,Set<Integer>> map = null;
if (map.get(new Integer(1)) == map.get(new Integer(2))) ;
}
}
| 1,726 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6660289.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T6660289.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 6660289
* @summary declared bound in inner class referring a type variable of the outer class
* @author Maurizio Cimadamore
* @compile T6660289.java
*/
public class T6660289<E> {
class Inner<S extends E> {}
}
| 1,295 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T5094318.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T5094318.java | /*
* Copyright (c) 2004, 2007, 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 5094318
* @summary REGRESSION: Array cloning is not backwards compatible
*
* @compile -source 1.4 T5094318.java
* @run main T5094318
* @compile T5094318.java
* @run main/fail T5094318
*/
public class T5094318 {
// Tiger
public static void method(int[] array){
System.out.println("You gave me an array of ints");
throw new RuntimeException();
}
// Pre-Tiger
public static void method(Object obj){
System.out.println("You gave me an object");
}
public static void main(String[] args){
method(new int[0].clone());
}
}
| 1,670 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Crash01.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Crash01.java | /*
* Copyright (c) 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 4856978
* @summary generics: crash when using class in bound defined after usage
* @author gafter
*
* @compile Crash01.java
*/
public class Crash01<A extends TestClass1 & IA> {
public A value;
public void testit(){
value.testClass();
}
}
class TestClass1{ public void testClass(){} }
interface IA{}
| 1,389 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ParametricException.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/ParametricException.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 4509267
* @summary generics: parametric exception type versus overriding
* @author gafter
*
* @compile ParametricException.java
*/
import java.io.*;
abstract class AChurchBoolean {
public abstract <Return, Parameter, Throws extends Throwable>
Return accept(IVisitor<Return, Parameter, Throws> visitor, Parameter parameter) throws Throws;
public interface IVisitor<Return, Parameter, Throws extends Throwable> {
public Return caseTrue(Parameter parameter) throws Throws;
public Return caseFalse(Parameter parameter) throws Throws;
}
}
class TrueChurchBoolean extends AChurchBoolean {
private static TrueChurchBoolean instance = new TrueChurchBoolean();
private TrueChurchBoolean() {}
public static TrueChurchBoolean singleton() {
return instance;
}
public <Return, Parameter, Throws extends Throwable>
Return accept(IVisitor<Return, Parameter, Throws> visitor, Parameter parameter) throws Throws {
return visitor.caseTrue(parameter);
}
}
class FalseChurchBoolean extends AChurchBoolean {
private static FalseChurchBoolean instance = new FalseChurchBoolean();
private FalseChurchBoolean() {}
public static FalseChurchBoolean singleton() {
return instance;
}
public <Return, Parameter, Throws extends Throwable>
Return accept(IVisitor<Return, Parameter, Throws> visitor, Parameter parameter) throws Throws {
return visitor.caseFalse(parameter);
}
}
class Pair<T,U> {
private T first;
private U second;
Pair(T first, U second) {
this.first = first;
this.second = second;
}
T getFirst() {
return first;
}
U getSecond() {
return second;
}
}
// Perhaps a bit of a toy example, but relevant nonetheless.
class ChurchBooleanTest {
private AChurchBoolean bool;
public ChurchBooleanTest(AChurchBoolean bool) {
this.bool = bool;
}
public AChurchBoolean readIf(File file, byte[] output) throws IOException {
return bool.accept(new AChurchBoolean.IVisitor<AChurchBoolean, Pair<File, byte[]>, IOException>() {
public AChurchBoolean caseTrue(Pair<File, byte[]> parameter) throws IOException {
FileInputStream input = new FileInputStream(parameter.getFirst()); // throws
input.read(parameter.getSecond()); // throws
input.close(); // throws
return TrueChurchBoolean.singleton();
}
public AChurchBoolean caseFalse(Pair<File, byte[]> parameter) throws IOException {
return FalseChurchBoolean.singleton();
}
}, new Pair<File, byte[]>(file, output));
}
}
| 3,775 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4784207a.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4784207a.java | /*
* Copyright (c) 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 4784207
* @summary generics: method overriding missed with separate compilation
* @author gafter
*
* @compile T4784207a.java
* @compile T4784207b.java
*/
interface T4784207a_i extends Comparable<T4784207a_i>{
}
abstract class T4784207a_p implements T4784207a_i {
public int compareTo(T4784207a_i other) {
return 0;
}
}
| 1,417 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InheritanceConflict3.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/InheritanceConflict3.java | /*
* Copyright (c) 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 4984158
* @summary two inherited methods with same signature
* @author darcy
*
* @compile/fail InheritanceConflict3.java
*/
package inheritance.conflict3;
class X1<T> {
int f(T t) { throw null; }
void f(Object o) {}
}
class X2 extends X1 {
}
| 1,331 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6751514.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T6751514.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.
*/
/*
* @test
* @bug 6751514
* @summary Unary post-increment with type variables crash javac during lowering
* @author Maurizio Cimadamore
*/
public class T6751514 {
static class Foo<X> {
X x;
Foo (X x) {
this.x = x;
}
}
static void test1(Foo<Integer> foo) {
int start = foo.x;
equals(foo.x += 1, start + 1);
equals(foo.x++, start + 1);
equals(++foo.x, start + 3);
equals(foo.x--, start + 3);
equals(foo.x -= 1, start + 1);
equals(--foo.x, start);
}
static void test2(Foo<Integer> foo) {
int start = foo.x;
equals((foo.x) += 1, start + 1);
equals((foo.x)++, start + 1);
equals(++(foo.x), start + 3);
equals((foo.x)--, start + 3);
equals((foo.x) -= 1, start + 1);
equals(--(foo.x), start);
}
static void test3(Foo<Integer> foo) {
int start = foo.x;
equals(((foo.x)) += 1, start + 1);
equals(((foo.x))++, start + 1);
equals(++((foo.x)), start + 3);
equals(((foo.x))--, start + 3);
equals(((foo.x)) -= 1, start + 1);
equals(--((foo.x)), start);
}
public static void main(String[] args) {
test1(new Foo<Integer>(1));
test2(new Foo<Integer>(1));
test3(new Foo<Integer>(1));
}
static void equals(int found, int req) {
if (found != req) {
throw new AssertionError("Error (expected: "+ req +
" - found: " + found + ")");
}
}
}
| 2,631 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6657499.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T6657499.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 6657499
* @summary generics: javac 1.6.0 fails to compile class with inner class
* @author Maurizio Cimadamore
*
*/
public class T6657499<T> {
T t;
public T test() {
class Local {private T t;};
class Local2 {T m() {return t;}};
T t3 = new Local().t;
return new Local2().m();
}
public static void main(String[] args) {
String s = new T6657499<String>().test();
}
}
| 1,504 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ErasureClashCrash.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/ErasureClashCrash.java | /*
* Copyright (c) 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 4951670
* @summary javac crash with improper overrider
* @author gafter
*
* @compile/fail ErasureClashCrash.java
*/
interface Compar<T> {
int compareTo(T o);
}
abstract class ErasureClashCrash implements Compar<ErasureClashCrash> {
public int compareTo(Object o) {
return 1;
}
}
| 1,378 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
BridgeRestype.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/BridgeRestype.java | /*
* Copyright (c) 2003, 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 4902704
* @summary javac generates inappropriate bridge methods in -source 1.4
* @author gafter
*
* @compile -source 1.4 -target 1.4 BridgeRestype.java
* @run main BridgeRestype
*/
import java.util.*;
public class BridgeRestype extends Vector {
public static void main(String[] args) {
BridgeRestype t = new BridgeRestype();
for (int i=0; i<args.length; i++) t.add(args[i]);
Iterator i = t.iterator();
}
}
| 1,524 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ArrayClone.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/ArrayClone.java | /*
* Copyright (c) 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 4900415
* @summary The clone method on arrays should be strongly typed
* @author gafter
*
* @compile ArrayClone.java
* @run main ArrayClone
*/
public class ArrayClone {
public static void main(String... args) {
if (args.length==0)
main("foo", "bar", "xyzzy");
String[] args2 = args.clone();
for (int i=0; i<args2.length; i++)
if (!args[i].equals(args2[i]))
throw new Error(args2[i]);
f1(1, 2, 3, 4, 5);
}
static void f1(int... a) {
int[] b = a.clone();
for (int i=0; i<a.length; i++)
if (a[i] != b[i])
throw new Error(""+b[i]);
}
}
| 1,744 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
GenericOverride.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/GenericOverride.java | /*
* Copyright (c) 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 5041233
* @summary Cannot override non-trivial generic method
* @author gafter
*
* @compile GenericOverride.java
*/
package generic.override;
interface R<T extends R<T>> {}
class B extends A {
<U extends Object & R<U>> void f() {}
}
class A {
<T extends Object & R<T>> void f() {}
}
| 1,373 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6557954.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T6557954.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.
*/
/*
* @test
* @bug 6557954
* @summary Inner class type parameters doesn't get substituted when checking type well-formedness
* @author Maurizio Cimadamore
*
* @compile T6557954.java
*/
class T6557954<T> {
class Foo<U extends T> {}
T6557954<Number>.Foo<Integer> f;
}
| 1,343 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InstanceOf1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/InstanceOf1.java | /*
* Copyright (c) 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 4982096 5004321
* @summary the type in an instanceof expression must be reifiable
* @author seligman
*
* @compile InstanceOf1.java
*/
public class InstanceOf1 {
boolean m() {
return this.getClass() instanceof Class<?>;
}
}
| 1,318 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T5011073.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T5011073.java | /*
* Copyright (c) 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 5011073
* @summary javac should implement JLS3 three-pass overload resolution
* @author gafter
*
* @compile/fail T5011073.java
*/
import java.util.*;
class T5011073 {
static void f(Set<String> s, Class<String> c) {}
static void g(Set<Integer> s, Class c) {
f(s, c);
}
}
| 1,370 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Varargs2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Varargs2.java | /*
* Copyright (c) 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 5014324
* @summary generics + varargs API changes
* @author gafter
*
* @compile Varargs2.java
* @run main Varargs2
*/
import java.util.*;
public enum Varargs2 {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
public static void main(String[] args) {
System.out.println(EnumSet.of(B));
System.out.println(EnumSet.of(B, C));
System.out.println(EnumSet.of(B, C, D));
System.out.println(EnumSet.of(B, C, D, F));
System.out.println(EnumSet.of(B, C, D, F, G));
System.out.println(EnumSet.of(B, C, D, F, G, H));
System.out.println(EnumSet.of(B, C, D, F, G, H, J));
System.out.println(EnumSet.of(B, C, D, F, G, H, J, K));
System.out.println(EnumSet.of(B, C, D, F, G, H, J, K, L));
System.out.println(EnumSet.of(B, C, D, F, G, H, J, K, L, M));
System.out.println(EnumSet.of(B, C, D, F, G, H, J, K, L, M, N));
System.out.println(EnumSet.of(B, C, D, F, G, H, J, K, L, M, N, P));
}
}
| 2,091 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InnerInterface2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/InnerInterface2.java | /*
* Copyright (c) 2001, 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 4482388
* @summary inner interface causes "not within bounds"
* @author gafter
*
* @compile InnerInterface2.java
*/
package InnerInterface2;
class Builder<Community> {
class Produces<B extends AbstractBuilder> {}
interface AbstractBuilder {}
}
class MyBuilder extends Builder<String> {
// the next two lines each generate a "not within bounds" error
Produces<HTMLConsumer> p0;
Produces<MyABuilder> p1;
}
class MyABuilder implements HTMLConsumer {
}
interface HTMLConsumer extends Builder.AbstractBuilder {}
| 1,619 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InterfaceCast1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/InterfaceCast1.java | /*
* Copyright (c) 2001, 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 4453032
* @summary overridden interface method causes the compiler to reject cast
* @author gafter
*
* @compile InterfaceCast1.java
*/
public class InterfaceCast1 {
public static void main(String[] args) throws Exception {
}
}
interface Collection<E> {
<T> T[] toArray(T[] a);
}
interface Set<E> extends Collection<E> {
<T> T[] toArray(T[] a);
}
interface SortedSet<E> extends Set<E> {
}
class TreeSet<E> {
public void addAll(Collection<E> c) {
if (c instanceof SortedSet) {
SortedSet<E> ss = (SortedSet<E>) c;
}
}
}
| 1,658 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
GenericThrowable.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/GenericThrowable.java | /*
* Copyright (c) 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 4984157
* @summary java.lang.Throwable inheritance in parameterized type
* @author gafter
*
* @compile/fail GenericThrowable.java
*/
class GenericThrowable<T> extends NullPointerException {
}
| 1,271 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T4784207b.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/T4784207b.java | /*
* Copyright (c) 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.
*/
public class T4784207b extends T4784207a_p {
}
| 1,099 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Covar2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Covar2.java | /*
* Copyright (c) 2003, 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 4949303 4960369 4965756
* @summary Additional unit tests for covariant returns
* @author gafter
*
* @compile Covar2.java
* @run main Covar2
*/
public class Covar2 {
static class A1 {
public Long f() { return 12L; }
}
static class B1 extends A1 {
public Long f() { return 12L; }
}
static class B2 {
public int f() { return 12; }
}
static class C2 extends B2 {
public int f() { return (short)12; }
}
static class C3 extends B2 {
public int f() { return (short)12; }
}
public static void main(String[] args) {
A1 b1 = new B1();
System.out.println(b1.f());
B2 c2 = new C2();
System.out.println(c2.f());
B2 c3 = new C3();
System.out.println(c3.f());
}
}
| 1,876 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Casting3.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/Casting3.java | /*
* Copyright (c) 2004, 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 5040403
* @summary compiler crash with stack overflow on unchecked cast
* @author gafter
*
* @compile Casting3.java
*/
package Casting3;
class A<T extends A<T>> {
<U extends A<U>> void f() {
A<U> a = (A<U>) this;
}
}
| 1,319 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
SuperTypeargs.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/generics/SuperTypeargs.java | /*
* Copyright (c) 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 4906605
* @summary compilation error for super.<T,E>f() and ClassName.super.<T,E>f()
* @author gafter
*
* @compile SuperTypeargs.java
*/
package superTypeargs;
import java.util.*;
class A {
public void show() {
System.out.println("I am being called from class A");
}
public String toString() {
show();
return "";
}
}
class B {
public void show() {
System.out.println("I am being called from class B");
}
public String toString() {
show();
return "";
}
}
class Test1<T,E> {
public static <T,E> void check1(T val1, E val2) {
val1.toString();
val2.toString();
System.out.println("Static check1 method being invoked from class Test1");
}
public <T,E> Test1(){
System.out.println("The Default Test1 constructor is being called");
}
public <T,E> Test1(T val1, E val2) {
System.out.println("The parameter Test1 constructor is being called");
}
public <T,E> int check2(T val1, E val2) {
val1.toString();
val2.toString();
System.out.println("Instance method check2 being invoked from class Test1");
return 1;
}
}
class Test2<T,E> extends Test1<T,E> {
public static <T,E> void check1(T val1, E val2) {
val1.toString();
val2.toString();
System.out.println("Static check1 method being invoked from class Test2");
}
public Test2() {
<T,E>super();
System.out.println("The Default Test2 constructor is being called");
}
public <T,E> Test2(T val1, E val2) {
<T,E>super(val1,val2);
System.out.println("The parameter Test2 constructor is being called");
}
public <T,E> int check2(T val1, E val2) {
val1.toString();
val2.toString();
System.out.println("Instance method check2 being invoked from class Test2");
return 1;
}
public <T,E> int check3(T val1, E val2) {
System.out.println("Instance method check3 being invoked from class Test2");
super.<T,E>check2(val1,val2);
/*
ParametericMethodsTest13.java:66: <identifier> expected
super . <T,E> check2(val1,val2);
^
ParametericMethodsTest13.java:66: not a statement
super . <T,E> check2(val1,val2);
^
2 errors
*/
this.<T,E>check2(val1,val2);
Test2.super.<T,E>check2(val1,val2);
return 1;
}
/*
ParametericMethodsTest14.java:130: check4(A,B) in Test2<A,B> cannot be applied to <A,B>(A,B)
tRef.<A,B>check4(new A(), new B());
^
1 error
*/
public int check4(T val1, E val2) {
val1.toString();
val2.toString();
System.out.println("Instance method check2 being invoked from class Test2");
return 1;
}
}
class ParametericMethodsTest14 {
public void assertion1() {
Test2.<A,B>check1(new A(), new B());
Test1.<A,B>check1(new A(), new B());
System.out.println("assertion1 passed");
}
public void assertion2() {
Test2<A,B> tRef = new Test2<A,B>();
tRef.<A,B>check1(new A(), new B());
tRef.<A,B>check2(new A(), new B());
Test1<A,B> tRef1 = tRef;
tRef1.<A,B>check1(new A(), new B());
System.out.println("assertion2 passed");
}
public void assertion3() {
Test2<A,B> tRef = new Test2<A,B>();
tRef.<A,B>check3(new A(), new B());
}
public void assertion4() {
Test2<A,B> tRef = new Test2<A,B>(new A(), new B());
tRef.<A,B>check3(new A(), new B());
}
public static void main(String args[]) {
ParametericMethodsTest14 tRef = new ParametericMethodsTest14();
tRef.assertion1();
tRef.assertion2();
tRef.assertion3();
tRef.assertion4();
}
}
| 4,970 | 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.