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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
SurfaceAnnotations.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/environment/round/SurfaceAnnotations.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 to hold annotations for ElementsAnnotatedWithTest.
*/
@AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings",
expectedSize=2,
names={"SurfaceAnnotations",
"foo"})
@SuppressWarnings("")
public class SurfaceAnnotations {
@SuppressWarnings("")
private void foo() {return;};
}
| 1,432 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
BuriedAnnotations.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/environment/round/BuriedAnnotations.java | /*
* Copyright (c) 2006, 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.
*/
/**
* Class to hold annotations for ElementsAnnotatedWithTest.
*/
@AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings",
expectedSize=4,
names={"foo",
"bar",
"<init>"})
public class BuriedAnnotations {
@SuppressWarnings("")
private BuriedAnnotations() {}
class Nested {
@SuppressWarnings("")
private Nested() {}
@SuppressWarnings("")
private void foo() {return;};
@SuppressWarnings("")
private void bar() {return;};
}
}
| 1,662 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestElementsAnnotatedWith.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.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 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854
* @summary Tests that getElementsAnnotatedWith works properly.
* @author Joseph D. Darcy
* @library ../../../lib
* @build JavacTestingAbstractProcessor
* @compile TestElementsAnnotatedWith.java
* @compile InheritedAnnotation.java
* @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java
* @compile -processor TestElementsAnnotatedWith -proc:only BuriedAnnotations.java
* @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java
* @compile -processor TestElementsAnnotatedWith -proc:only C2.java
* @compile -processor TestElementsAnnotatedWith -proc:only Foo.java
* @compile Foo.java
* @compile/process -processor TestElementsAnnotatedWith -proc:only Foo
*/
import java.lang.annotation.Annotation;
import java.io.*;
import java.util.Collections;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import javax.annotation.processing.*;
import javax.tools.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
/**
* This processor verifies that the information returned by
* getElementsAnnotatedWith is consistent with the expected results
* stored in an AnnotatedElementInfo annotation.
*/
@AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings", expectedSize=0, names={})
public class TestElementsAnnotatedWith extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
TypeElement annotatedElementInfoElement =
elements.getTypeElement("AnnotatedElementInfo");
Set<? extends Element> resultsMeta = Collections.emptySet();
Set<? extends Element> resultsBase = Collections.emptySet();
if (!roundEnvironment.processingOver()) {
testNonAnnotations(roundEnvironment);
// Verify AnnotatedElementInfo is present on the first
// specified type.
TypeElement firstType = typesIn(roundEnvironment.getRootElements()).iterator().next();
AnnotatedElementInfo annotatedElementInfo = firstType.getAnnotation(AnnotatedElementInfo.class);
boolean failed = false;
if (annotatedElementInfo == null)
throw new IllegalArgumentException("Missing AnnotatedElementInfo annotation on " +
firstType);
else {
// Verify that the annotation information is as
// expected.
Set<String> expectedNames = new HashSet<String>(Arrays.asList(annotatedElementInfo.names()));
resultsMeta =
roundEnvironment.
getElementsAnnotatedWith(elements.getTypeElement(annotatedElementInfo.annotationName()));
System.err.println("Results: " + resultsMeta);
if (resultsMeta.size() != annotatedElementInfo.expectedSize()) {
failed = true;
System.err.printf("Bad number of elements; expected %d, got %d%n",
annotatedElementInfo.expectedSize(), resultsMeta.size());
} else {
for(Element element : resultsMeta) {
String simpleName = element.getSimpleName().toString();
if (!expectedNames.contains(simpleName) ) {
failed = true;
System.err.println("Name ``" + simpleName + "'' not expected.");
}
}
}
}
resultsBase = computeResultsBase(roundEnvironment, annotatedElementInfo.annotationName());
if (!resultsMeta.equals(resultsBase)) {
failed = true;
System.err.println("Base and Meta sets unequal;\n meta: " + resultsMeta +
"\nbase: " + resultsBase);
}
if (failed) {
System.err.println("AnnotatedElementInfo: " + annotatedElementInfo);
throw new RuntimeException();
}
} else {
// If processing is over without an error, the specified
// elements should be empty so an empty set should be returned.
resultsMeta = roundEnvironment.getElementsAnnotatedWith(annotatedElementInfoElement);
resultsBase = roundEnvironment.getElementsAnnotatedWith(AnnotatedElementInfo.class);
if (!resultsMeta.isEmpty())
throw new RuntimeException("Nonempty resultsMeta: " + resultsMeta);
if (!resultsBase.isEmpty())
throw new RuntimeException("Nonempty resultsBase: " + resultsBase);
}
return true;
}
private Set<? extends Element> computeResultsBase(RoundEnvironment roundEnvironment, String name) {
try {
return roundEnvironment.
getElementsAnnotatedWith(Class.forName(name).asSubclass(Annotation.class));
} catch(ClassNotFoundException cnfe) {
throw new RuntimeException(cnfe);
}
}
/**
* Verify non-annotation types result in
* IllegalArgumentExceptions.
*/
private void testNonAnnotations(RoundEnvironment roundEnvironment) {
try {
Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith((Class)Object.class );
throw new RuntimeException("Illegal argument exception not thrown");
} catch(IllegalArgumentException iae) {}
try {
Set<? extends Element> elements =
roundEnvironment.getElementsAnnotatedWith(processingEnv.
getElementUtils().
getTypeElement("java.lang.Object") );
throw new RuntimeException("Illegal argument exception not thrown");
} catch(IllegalArgumentException iae) {}
}
}
| 7,297 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Part1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/environment/round/Part1.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 to hold annotations for ElementsAnnotatedWithTest.
*/
@AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings",
expectedSize=2,
names={"Part2",
"bar"})
public class Part1 {
}
| 1,324 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
AnnotatedElementInfo.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/environment/round/AnnotatedElementInfo.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.*;
/**
* Hold information about the set of elements expected to be annotated
* with a given annotation.
*/
@Retention(RUNTIME)
public @interface AnnotatedElementInfo {
String annotationName();
int expectedSize();
String[] names();
}
| 1,383 | 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/environment/round/Foo.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.
*/
@AnnotatedElementInfo(annotationName="AnnotatedElementInfo",
expectedSize=1,
names="Foo")
public class Foo {}
| 1,206 | 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/environment/round/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.
*/
@InheritedAnnotation
public class C1 {}
| 1,092 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
package-info.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6359313/package-info.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
@Foo
package foo;
| 1,070 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6359313.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6359313/T6359313.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 6359313
* @summary error compiling annotated package
* @author Peter von der Ah\u00e9
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile T6359313.java
* @compile -processor T6359313 package-info.java Foo.java
*/
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.element.TypeElement;
@SupportedAnnotationTypes("Foo")
public class T6359313 extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
return true;
}
}
| 1,817 | 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/6359313/Foo.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.
*/
package foo;
@interface Foo {}
| 1,083 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6634138.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6634138/T6634138.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 6634138
* @author Joseph D. Darcy
* @summary Verify source files output after processing is over are compiled
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile T6634138.java
* @compile -processor T6634138 Dummy.java
* @run main ExerciseDependency
*/
import java.lang.annotation.Annotation;
import java.io.*;
import java.util.Collections;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
public class T6634138 extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
// Write out files *after* processing is over.
if (roundEnvironment.processingOver()) {
System.out.println("Writing out source files.");
try {
PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.WrittenAfterProcessing").openWriter());
try {
pw.println("package foo;");
pw.println("public class WrittenAfterProcessing {");
pw.println(" public WrittenAfterProcessing() {super();}");
pw.println("}");
} finally {
pw.close();
}
pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter());
try {
pw.println("@Deprecated");
pw.println("package foo;");
} finally {
pw.close();
}
} catch(IOException io) {
throw new RuntimeException(io);
}
}
return true;
}
}
| 2,988 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Dummy.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6634138/Dummy.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.
*/
/**
* A dummy class to be compiled.
*/
public class Dummy {}
| 1,115 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ExerciseDependency.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6634138/ExerciseDependency.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.
*/
/**
* Class to exercise dependencies on the two source files generated by
* T6634138.java, foo.WrittenAfterProcessing.java and
* foo.package-info.java.
*/
public class ExerciseDependency {
public static void main(String... args) {
foo.WrittenAfterProcessing wap = new foo.WrittenAfterProcessing();
java.lang.Package pkg = wap.getClass().getPackage();
Deprecated d = pkg.getAnnotation(Deprecated.class);
if (d == null)
throw new RuntimeException();
}
}
| 1,560 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
clss41701.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6511613/clss41701.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 6511613
* @summary javac unexpectedly doesn't fail in some cases if an annotation processor specified
*
* @library ../../lib
* @build JavacTestingAbstractProcessor DummyProcessor
* @compile/fail clss41701.java
* @compile/fail -processor DummyProcessor clss41701.java
*/
import java.io.PrintStream;
interface clss41701i {
void run();
}
class clss41701a<A extends clss41701i,
B extends clss41701i,
C extends A&B> {
}
| 1,535 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
DummyProcessor.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6511613/DummyProcessor.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.
*/
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import java.util.Set;
public class DummyProcessor extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
return true;
}
}
| 1,384 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
MessagerBasics.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/messager/MessagerBasics.java | /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6341173 6341072
* @summary Test presence of Messager methods
* @author Joseph D. Darcy
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile MessagerBasics.java
* @compile -processor MessagerBasics -proc:only MessagerBasics.java
* @compile/fail -processor MessagerBasics -proc:only -AfinalError MessagerBasics.java
* @compile -processor MessagerBasics MessagerBasics.java
* @compile/fail -processor MessagerBasics -AfinalError MessagerBasics.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.tools.Diagnostic.Kind.*;
@SupportedOptions("finalError")
public class MessagerBasics extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
if (processingEnv.getOptions().containsKey("finalError"))
messager.printMessage(ERROR, "Does not compute");
else {
messager.printMessage(NOTE, "Post no bills");
messager.printMessage(WARNING, "Beware the ides of March!");
}
}
return true;
}
}
| 2,352 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6362067.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/messager/6362067/T6362067.java | /*
* @test /nodynamiccopyright/
* @bug 6362067
* @summary Messager methods do not print out source position information
* @library ../../../lib
* @build JavacTestingAbstractProcessor T6362067
* @compile -processor T6362067 -proc:only T6362067.java
* @compile/ref=T6362067.out -XDrawDiagnostics -processor T6362067 -proc:only T6362067.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import static javax.tools.Diagnostic.Kind.*;
@Deprecated // convenient test annotations
@SuppressWarnings({""})
public class T6362067 extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annos,
RoundEnvironment roundEnv) {
for (Element e: roundEnv.getRootElements()) {
messager.printMessage(NOTE, "note:elem", e);
for (AnnotationMirror a: e.getAnnotationMirrors()) {
messager.printMessage(NOTE, "note:anno", e, a);
for (AnnotationValue v: a.getElementValues().values()) {
messager.printMessage(NOTE, "note:value", e, a, v);
}
}
}
if (roundEnv.processingOver())
messager.printMessage(NOTE, "note:nopos");
return true;
}
}
| 1,296 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestSourceVersionWarnings.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/warnings/TestSourceVersionWarnings.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 6376083 6376084 6458819
* @summary Test that warnings about source versions are output as expected.
* @author Joseph D. Darcy
* @compile TestSourceVersionWarnings.java
* @compile/ref=gold_0.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -source 1.5 -Xlint:-options HelloWorld.java
* @compile/ref=gold_sv_warn_0_2.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_0 -source 1.2 -Xlint:-options HelloWorld.java
* @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_2 -source 1.2 -Xlint:-options HelloWorld.java
* @compile/ref=gold_sv_warn_2_3.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_2 -source 1.3 -Xlint:-options HelloWorld.java
* @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_5 -source 1.5 -Xlint:-options HelloWorld.java
* @compile/ref=gold_sv_warn_5_6.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_5 -source 1.6 -Xlint:-options HelloWorld.java
* @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options HelloWorld.java
* @compile/ref=gold_unsp_warn.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options -Aunsupported HelloWorld.java
* @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_7 -source 1.7 HelloWorld.java
*/
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
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.*;
/**
* This processor returns the supported source level as indicated by
* the "SourceLevel" option; therefore, don't use
* JavacTestingAbstractProcessor which returns the latest source level.
*/
@SupportedAnnotationTypes("*")
@SupportedOptions("SourceVersion")
public class TestSourceVersionWarnings extends AbstractProcessor {
@Override
public SourceVersion getSupportedSourceVersion() {
String sourceVersion = processingEnv.getOptions().get("SourceVersion");
if (sourceVersion == null) {
processingEnv.getMessager().printMessage(WARNING,
"No SourceVersion option given");
return SourceVersion.RELEASE_6;
} else {
return SourceVersion.valueOf(sourceVersion);
}
}
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
return true;
}
}
| 4,118 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
HelloWorld.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/warnings/HelloWorld.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.
*/
/**
* Used by TestSourceVersionWarnings.java.
*/
public class HelloWorld {
private HelloWorld(){};
public static void main(String[] argv) {
System.out.println("Hello world.\n");
}
}
| 1,256 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestProcUseImplicitWarning.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/warnings/UseImplicit/TestProcUseImplicitWarning.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 6986892
* @summary confusing warning given after errors in annotation processing
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestProcUseImplicitWarning
* @clean C1 p.C2
* @compile/fail/ref=err.out -XDrawDiagnostics -processor TestProcUseImplicitWarning -Aerror C1.java
* @clean C1 p.C2
* @compile/ref=warn.out -XDrawDiagnostics -processor TestProcUseImplicitWarning C1.java
*/
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import static javax.tools.Diagnostic.Kind.*;
@SupportedOptions("error")
public class TestProcUseImplicitWarning extends JavacTestingAbstractProcessor {
int round = 0;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
round++;
if (round == 1) {
boolean error = options.containsKey("error");
if (error)
messager.printMessage(ERROR, "error generated per option");
}
return false;
}
}
| 2,109 | 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/warnings/UseImplicit/C1.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.
*/
class C1 extends p.C2 { }
| 1,078 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
C2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/warnings/UseImplicit/p/C2.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.
*/
package p;
public class C2 { }
| 1,084 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
package-info.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6499119/package-info.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.
*/
@A package foo;
@interface A {}
| 1,086 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ClassProcessor.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6499119/ClassProcessor.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.
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic.Kind;
/*
* @test
* @bug 6499119
* @summary Created package-info class file modeled improperly
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile ClassProcessor.java package-info.java
* @compile/process -cp . -processor ClassProcessor -Akind=java java.lang.Object
* @compile/process -cp . -processor ClassProcessor -Akind=class java.lang.Object
*/
@SupportedOptions({ "gen", "expect" })
public class ClassProcessor extends JavacTestingAbstractProcessor {
int round = 1;
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (round == 1) {
System.out.println("-- Round 1 --");
createPackageFile();
} else if (round == 2) {
boolean found_foo_A = false;
System.out.println("-- Round 2 --");
for(Element e: roundEnv.getRootElements()) {
System.out.println("ElementKind: " + e.getKind());
System.out.println("Modifiers: " + e.getModifiers());
System.out.println("Annotations: " + e.getAnnotationMirrors());
if (e.getAnnotationMirrors().toString().equals("@foo.A")) {
found_foo_A = true;
checkEqual("ElementKind", e.getKind().toString(), "PACKAGE");
checkEqual("Modifiers", e.getModifiers().toString(), "[]");
}
}
if (!found_foo_A)
error("did not find @foo.A");
}
round++;
return true;
}
private void createPackageFile() {
String kind = processingEnv.getOptions().get("kind");
File pkgInfo;
if (kind.equals("java"))
pkgInfo = new File(System.getProperty("test.src"), "package-info.java");
else
pkgInfo = new File(System.getProperty("test.classes"), "foo/package-info.class");
byte[] bytes = new byte[(int) pkgInfo.length()];
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream(pkgInfo));
in.readFully(bytes);
} catch (IOException ioe) {
error("Couldn't read package info file: " + ioe);
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
error("InputStream closing failed: " + e);
}
}
}
OutputStream out = null;
try {
if (kind.equals("java"))
out = filer.createSourceFile("foo.package-info").openOutputStream();
else
out = filer.createClassFile("foo.package-info").openOutputStream();
out.write(bytes, 0, bytes.length);
} catch (IOException ioe) {
error("Couldn't create package info file: " + ioe);
} finally {
if(out != null) {
try {
out.close();
} catch (IOException e) {
error("OutputStream closing failed: " + e);
}
}
}
}
private void checkEqual(String label, String actual, String expect) {
if (!actual.equals(expect)) {
error("Unexpected value for " + label + "; actual=" + actual + ", expected=" + expect);
}
}
private void error(String msg) {
messager.printMessage(Kind.ERROR, msg);
}
}
| 4,696 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestCompletions.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/completion/TestCompletions.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6341177
* @summary Some simple tests of the methods in Completions
* @author Joseph D. Darcy
*/
import javax.annotation.processing.Completion;
import static javax.annotation.processing.Completions.*;
public class TestCompletions {
public static void main(String... argv) {
String value = "value";
String message = "message";
Completion c = of(value, message);
if (!value.equals(c.getValue()) ||
!message.equals(c.getMessage()))
throw new RuntimeException("Bad full completion" + c);
c = of(value);
if (!value.equals(c.getValue()) ||
!"".equals(c.getMessage()))
throw new RuntimeException("Bad value completion" + c);
}
}
| 1,803 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Marked.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6350124/Marked.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.
*/
@Marker
class Marked {
}
| 1,077 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Marker.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6350124/Marker.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.
*/
public @interface Marker {}
| 1,080 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6350124.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6350124/T6350124.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6350124 6410012
* @summary javac -s does not have the generated source files
*/
import java.io.File;
import java.io.PrintWriter;
import javax.tools.Tool;
import javax.tools.ToolProvider;
public class T6350124 {
public static void main(String[] args) {
String classpath = System.getProperty("java.class.path");
File srcDir = new File(System.getProperty("test.src"));
// ensure the output directories are empty
mkCleanDir(new File("aClasses"));
mkCleanDir(new File("newClasses"));
mkCleanDir(new File("newSrc"));
// compile the annotation processor
compile("-cp", classpath,
"-d", "aClasses", path(srcDir, "HelloWorldAP.java"));
// compile the test program, invoking the anotation processor
compile("-cp", classpath,
"-sourcepath", srcDir.getPath(),
"-d", "newClasses",
"-s", "newSrc",
"-processorpath", "aClasses",
"-processor", "HelloWorldAP", // specify processor for simplicity
"-proc:only",
path(srcDir, "Marked.java"));
File hw = new File("newSrc", "HelloWorld.java");
if (!hw.exists())
throw new AssertionError("generated source file not found");
File dc = new File("newClasses", "HelloWorldAP.class");
if (!dc.exists())
throw new AssertionError("generated class file not found");
}
//--- the following can be considered "library code" for the test
// note: jtreg @clean will only clean class files; not source files
static void clean(File file) {
if (!file.exists())
return;
if (file.isDirectory()) {
for (File f: file.listFiles())
clean(f);
}
file.delete();
}
static void mkCleanDir(File dir) {
clean(dir);
dir.mkdirs();
}
// note: jtreg @compile does not allow -d to be specified
static void compile(String... args) {
StringBuffer sb = new StringBuffer("compile:");
for (String a: args)
sb.append(' ').append(a);
System.err.println(sb);
Tool t = ToolProvider.getSystemJavaCompiler();
int rc = t.run(System.in, System.out, System.err, args);
System.out.flush();
System.err.flush();
if (rc != 0)
throw new Error("compilation failed");
}
static String path(File dir, String name) {
return new File(dir, name).getPath();
}
}
| 3,616 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
HelloWorldAP.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6350124/HelloWorldAP.java | /*
* Copyright (c) 2006, 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.
*/
import java.io.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import static javax.tools.Diagnostic.Kind.*;
import java.util.Set;
@SupportedAnnotationTypes({"*"})
public class HelloWorldAP extends AbstractProcessor {
Messager msgr = null;
Filer filer = null;
boolean DONE=false;
@Override
public void init(ProcessingEnvironment penv) {
processingEnv = penv;
msgr=penv.getMessager();
filer=penv.getFiler();
}
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv ) {
boolean ret = true;
if(!renv.processingOver() && !DONE) {
msgr.printMessage(NOTE, "running process to create HelloWorld.");
try {
Writer pw = filer.createSourceFile("HelloWorld").openWriter();
pw.write("public class HelloWorld {\n");
pw.write(" public static void main (String argv[]) {\n");
pw.write(" System.out.println(\"Hello apt world.\");\n");
pw.write(" }\n");
pw.write("}\n");
pw.flush();
pw.close();
OutputStream os = filer.createClassFile("HelloWorldAP").openOutputStream();
// the easiest way to create a class file is to copy another one
InputStream is = getClass().getResourceAsStream("HelloWorldAP.class");
copy(is, os);
is.close();
os.flush();
os.close();
DONE=true;
}
catch (IOException ioe) {
msgr.printMessage(ERROR, ioe.getMessage());
ret = false;
}
catch (Exception e) {
msgr.printMessage(ERROR, e.getMessage());
ret = false;
}
}
return ret;
}
void copy(InputStream is, OutputStream os) throws IOException {
byte[] buf = new byte[8192];
int n;
while ((n = is.read(buf, 0, buf.length)) > 0)
os.write(buf, 0, n);
}
}
| 3,221 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestImplicitNone.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/options/TestImplicitNone.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 6935638
* @summary -implicit:none prevents compilation with annotation processing
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
@SupportedAnnotationTypes("*")
public class TestImplicitNone extends AbstractProcessor {
public static void main(String... args) throws Exception {
new TestImplicitNone().run();
}
void run() throws Exception {
File classesDir = new File("tmp", "classes");
classesDir.mkdirs();
File test_java = new File(new File("tmp", "src"), "Test.java");
writeFile(test_java, "class Test { }");
// build up list of options and files to be compiled
List<String> opts = new ArrayList<String>();
List<File> files = new ArrayList<File>();
opts.add("-d");
opts.add(classesDir.getPath());
opts.add("-processorpath");
opts.add(System.getProperty("test.classes"));
opts.add("-implicit:none");
opts.add("-processor");
opts.add(TestImplicitNone.class.getName());
files.add(test_java);
compile(opts, files);
File test_class = new File(classesDir, "Test.class");
if (!test_class.exists())
throw new Exception("Test.class not generated");
}
/** Compile files with options provided. */
void compile(List<String> opts, List<File> files) throws Exception {
System.err.println("javac: " + opts + " " + files);
List<String> args = new ArrayList<String>();
args.addAll(opts);
for (File f: files)
args.add(f.getPath());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
pw.flush();
if (sw.getBuffer().length() > 0)
System.err.println(sw.toString());
if (rc != 0)
throw new Exception("compilation failed: rc=" + rc);
}
/** Write a file with a given body. */
void writeFile(File f, String body) throws Exception {
if (f.getParentFile() != null)
f.getParentFile().mkdirs();
Writer out = new FileWriter(f);
try {
out.write(body);
} finally {
out.close();
}
}
//----- annotation processor methods -----
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
| 3,750 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Xprint.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/options/Xprint.java | /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6266828
* @summary JSR 269: Java Language Model API
* @author Peter von der Ah\u00e9
*/
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class Xprint {
public static void main(String[] args) {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
javac.run(System.in, null, null,
"-Xprint",
"com.sun.tools.javac.code.Types",
"com.sun.tools.javac.parser.Parser",
"java.util.EnumSet");
}
}
| 1,600 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
XprintDocComments.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/options/XprintDocComments.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 6861094
* @summary javac -Xprint <file> does not print comments
* @compile/ref=XprintDocComments.out -Xprint XprintDocComments.java
*/
/**
* CLASS XprintDocComments
*/
class XPrintDocComments {
/**
* FIELD i;
*/
int i;
}
| 1,318 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Test.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/options/testPrintProcessorInfo/Test.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 6987384
* @summary -XprintProcessorRoundsInfo message printed with different timing than previous
* @library ../../../lib
* @build JavacTestingAbstractProcessor Test
* @compile/fail/ref=Test.out -XDrawDiagnostics -XprintProcessorInfo -Werror -proc:only -processor Test Test.java
*/
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.*;
public class Test extends JavacTestingAbstractProcessor {
final int MAX_ROUNDS = 3;
int round = 0;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
round++;
messager.printMessage(Diagnostic.Kind.NOTE, "round " + round);
if (round <= MAX_ROUNDS)
generateSource("Gen" + round);
if (roundEnv.processingOver())
messager.printMessage(Diagnostic.Kind.WARNING, "last round");
return true;
}
void generateSource(String name) {
String text = "class " + name + " { }\n";
// avoid try-with-resources so test can be run on older builds
try {
Writer out = filer.createSourceFile(name).openWriter();
try {
out.write(text);
} finally {
out.close();
}
} catch (IOException e) {
throw new Error(e);
}
}
}
| 2,524 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Test.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/options/testCommandLineClasses/Test.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 6930508
* @summary Passing nested class names on javac command line interfere with subsequent name -> class lookup
* @library ../../../lib
* @build JavacTestingAbstractProcessor p.NestedExamples Test
* @run main Test
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import javax.tools.*;
import p.NestedExamples;
public class Test extends JavacTestingAbstractProcessor {
public static void main(String... args) throws Exception {
new Test().run();
}
void run() throws Exception {
NestedExamples e = new NestedExamples();
List<String> names = getNames(e.getClasses());
test(names);
test(reverse(names));
names = Arrays.asList(e.getClassNames());
test(names);
test(reverse(names));
if (errors > 0)
throw new RuntimeException(errors + " errors occurred");
}
List<String> getNames(Class<?>[] classes) {
List<String> names = new ArrayList<String>();
for (Class<?> c: classes)
names.add(c.getName());
return names;
}
void test(List<String> names) throws Exception {
System.err.println("test: " + names);
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
File testClasses = new File(System.getProperty("test.classes"));
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses));
JavaCompiler.CompilationTask task = compiler.getTask(
null, null, null, Arrays.asList("-proc:only"), names, null);
task.setProcessors(Arrays.asList(new Test()));
boolean ok = task.call();
if (!ok)
error("compilation failed");
System.err.println();
}
<T> List<T> reverse(List<T> list) {
List<T> newList = new ArrayList<T>(list);
Collections.reverse(newList);
return newList;
}
int errors = 0;
void error(String msg) {
System.out.println("Error: " + msg);
errors++;
}
//----------
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
for (TypeElement typeElt : ElementFilter.typesIn(roundEnv.getRootElements())) {
messager.printMessage(Diagnostic.Kind.NOTE, "processing " + typeElt);
}
}
return true;
}
}
| 3,700 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
NestedExamples.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/options/testCommandLineClasses/p/NestedExamples.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.
*/
package p;
public class NestedExamples {
static class MemberClass1 { }
class MemberClass2 { }
class Win$$AtVegas { } // Class with funny name.
public Class<?>[] getClasses() {
class LocalClass { }
Object o = new Object() { // An anonymous class
@Override
public String toString() {
return "I have no name!";
}
};
return new Class<?>[] {
NestedExamples.class,
MemberClass1.class,
MemberClass2.class,
Win$$AtVegas.class,
LocalClass.class,
o.getClass()
};
}
public String[] getClassNames() {
return new String[] {
"p.NestedExamples",
"p.NestedExamples.MemberClass1",
"p.NestedExamples.MemberClass2",
"p.NestedExamples.Win$$AtVegas"
};
}
}
| 1,953 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6348193.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6348193/T6348193.java | /*
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6348193
* @summary AS8.1 UR2 BAT test failure with "javac"
* @compile -proc:none T6348193.java
* @run main/othervm T6348193
*/
import java.io.*;
import java.net.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.tools.*;
import com.sun.tools.javac.api.JavacTool;
@SupportedAnnotationTypes({"*"})
public class T6348193 extends AbstractProcessor
{
private static final boolean verbose = true;
enum NoYes { NO, YES };
enum NoGoodBad { NO, GOOD, BAD};
public static final String myName = T6348193.class.getName();
public static void main(String... args) throws IOException {
if (System.getSecurityManager() != null)
throw new AssertionError("unexpected security manager");
for (NoYes secMgr: EnumSet.allOf(NoYes.class))
for (NoGoodBad config: EnumSet.allOf(NoGoodBad.class))
for (NoYes proc: EnumSet.allOf(NoYes.class))
test(secMgr, config, proc);
}
private static File processed = new File("processed");
public static void test(NoYes secMgr, NoGoodBad config, NoYes proc) throws IOException {
if (verbose)
System.err.println("secMgr:" + secMgr + " config:" + config + " proc:" + proc);
if (secMgr == NoYes.YES && System.getSecurityManager() == null)
System.setSecurityManager(new NoLoaderSecurityManager());
installConfigFile(config);
processed.delete();
List<String> args = new ArrayList<String>();
//args.add("-XprintRounds");
if (proc == NoYes.YES) {
args.add("-processor");
args.add(myName);
}
args.add("-processorpath");
args.add(System.getProperty("java.class.path"));
args.add("-d");
args.add(".");
JavacTool t = JavacTool.create(); // avoid using class loader
MyDiagListener dl = new MyDiagListener();
PrintWriter out = new PrintWriter(System.err, true);
StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null);
File file = new File(System.getProperty("test.src"), myName+".java");
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
boolean ok = t.getTask(out, null, dl, args, null, files).call();
if (config == NoGoodBad.GOOD || proc == NoYes.YES) {
if (secMgr == NoYes.YES) {
if (dl.last == null)
throw new AssertionError("Security manager installed, and processors present, "
+ " but no diagnostic received");
}
else {
if (!processed.exists())
throw new AssertionError("No security manager installed, and processors present, "
+ " but no processing occurred");
}
}
else if (config == NoGoodBad.BAD) {
// TODO: should verify that no compiler crash occurred
// needs revised JSR199 spec
}
else {
if (processed.exists())
throw new AssertionError("No processors present, but processing occurred!");
}
if (verbose)
System.err.println("OK");
}
// set up or remove a service configuration file
static void installConfigFile(NoGoodBad type) throws IOException {
File f = new File(System.getProperty("test.classes", "."));
for (String s: new String[] { "META-INF", "services", Processor.class.getName() })
f = new File(f, s);
BufferedWriter out;
switch (type) {
case GOOD:
f.getParentFile().mkdirs();
out = new BufferedWriter(new FileWriter(f));
out.write(myName);
out.newLine();
out.close();
break;
case BAD:
f.getParentFile().mkdirs();
out = new BufferedWriter(new FileWriter(f));
out.write("This is not a valid line");
out.newLine();
out.close();
break;
case NO:
f.delete();
}
}
// annotation processor method
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv )
{
try {
// touch a file to indicate we have run
new FileWriter(processed).close();
} catch (IOException e) {
}
return true;
}
static class MyDiagListener implements DiagnosticListener<JavaFileObject>
{
public void report(Diagnostic<? extends JavaFileObject> message) {
if (verbose)
System.err.println(message);
last = message;
}
Diagnostic<? extends JavaFileObject> last;
}
static class NoLoaderSecurityManager extends SecurityManager
{
public void checkCreateClassLoader() {
throw new SecurityException("Not today, thanks you!");
}
public void checkPropertyAccess(String key) { /*OK*/ }
public void checkDelete(String file) { /*OK*/ }
public void checkRead(FileDescriptor fd) { /*OK*/ }
public void checkRead(String file) { /*OK*/ }
public void checkRead(String file, Object context) { /*OK*/ }
public void checkWrite(String file) { /*OK*/ }
}
}
| 6,497 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6378728.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6378728/T6378728.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6378728
* @summary Verify -proc:only doesn't produce class files
* @author Joseph D. Darcy
* @compile T6378728.java
* @run main T6378728
*/
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.URI;
import java.util.Arrays;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.*;
public class T6378728 {
private static class ExceptionalFileManager extends ForwardingJavaFileManager {
public ExceptionalFileManager(JavaFileManager wrapped) {
super(wrapped);
}
@Override
public FileObject getFileForOutput(Location location,
String packageName,
String relativeName,
FileObject sibling)
{
throw new IllegalArgumentException("No files for you!");
}
@Override
public JavaFileObject getJavaFileForOutput(Location location,
String className,
JavaFileObject.Kind kind,
FileObject sibling)
{
throw new IllegalArgumentException("No files for you!");
}
}
public static void main(String[] args) {
// Get a compiler tool
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
String srcdir = System.getProperty("test.src");
File source = new File(srcdir, "T6378728.java");
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
CompilationTask task =
compiler.getTask(null,
new ExceptionalFileManager(fm),
null,
Arrays.asList("-proc:only"),
null,
fm.getJavaFileObjectsFromFiles(Arrays.asList(source)));
if (!task.call())
throw new RuntimeException("Unexpected compilation failure");
}
}
| 3,193 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestFatalityOfParseErrors.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/errors/TestFatalityOfParseErrors.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 6403459
* @summary Test that generating programs with syntax errors is a fatal condition
* @author Joseph D. Darcy
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile TestReturnCode.java
* @compile TestFatalityOfParseErrors.java
* @compile/fail -XprintRounds -processor TestFatalityOfParseErrors -proc:only TestFatalityOfParseErrors.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.tools.Diagnostic.Kind.*;
import java.io.PrintWriter;
import java.io.IOException;
/**
* Write out an incomplete source file and observe that the next round
* is marked as an error.
*/
public class TestFatalityOfParseErrors extends JavacTestingAbstractProcessor {
int round = 0;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
try {
PrintWriter pw = null;
round++;
switch (round) {
case 1:
pw = new PrintWriter(filer.createSourceFile("SyntaxError").openWriter());
pw.println("class SyntaxError {");
pw.close();
break;
case 2:
pw = new PrintWriter(filer.createSourceFile("SimpleClass").openWriter());
pw.println("class SimpleClass {}");
pw.close();
if (!roundEnvironment.errorRaised() || !roundEnvironment.processingOver() ) {
System.err.println(roundEnvironment);
throw new RuntimeException("Second round not erroneous as expected.");
}
if (!roundEnvironment.getRootElements().isEmpty()) {
System.err.println(roundEnvironment);
throw new RuntimeException("Root elements not empty as expected.");
}
break;
default:
throw new RuntimeException("Unexpected round number " + round);
}
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
return true;
}
}
| 3,373 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestErrorCount.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/errors/TestErrorCount.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 6988079
* @summary Errors reported via Messager.printMessage(ERROR,"error message") are not tallied correctly
* @library ../../lib
* @build JavacTestingAbstractProcessor TestErrorCount
* @compile/fail/ref=TestErrorCount.out -XDrawDiagnostics -processor TestErrorCount TestErrorCount.java
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.tools.*;
public class TestErrorCount extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
messager.printMessage(Diagnostic.Kind.ERROR, "intentional error");
return true;
}
}
| 1,786 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestSuppression.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/errors/TestSuppression.java | /*
* Copyright (c) 2010, 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 6403465
* @summary javac should defer diagnostics until it can be determined they are persistent
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.TypeElement;
import javax.tools.*;
import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.ClientCodeWrapper;
import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.util.JCDiagnostic;
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
public class TestSuppression {
public static void main(String... args) throws Exception {
new TestSuppression().run(args);
}
enum WarningKind { NO, YES };
String[] cases = {
// missing class C
"class X { C c; }",
"class X { C foo() { return null; } }",
"class X { void foo(C c) { } }",
"class X extends C { }",
"class X<T extends C> { }",
// missing interface I
"class X implements I { }",
"interface X extends I { }",
// missing exception E
"class X { void m() throws E { } }",
// missing method m
"class X extends C { int i = m(); }",
// missing field f
"class X extends C { int i = f; }"
};
void run(String... args) throws Exception {
for (String c: cases) {
for (WarningKind wk: WarningKind.values()) {
for (int g = 1; g <= 3; g++) {
try {
test(c, wk, g);
} catch (Throwable t) {
error("caught: " + t);
}
if (errors > 0) throw new AssertionError();
}
}
}
System.err.println(count + " test cases");
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void test(String src, WarningKind wk, int gen) throws Exception {
count++;
System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src);
File testDir = new File("test" + count);
File srcDir = createDir(testDir, "src");
File gensrcDir = createDir(testDir, "gensrc");
File classesDir = createDir(testDir, "classes");
File x = writeFile(new File(srcDir, "X.java"), src);
DiagListener dl = new DiagListener();
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
fm.setLocation(StandardLocation.CLASS_PATH,
Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
List<String> args = new ArrayList<String>();
// args.add("-XprintProcessorInfo");
args.add("-XprintRounds");
args.add("-Agen=" + gen);
if (wk == WarningKind.YES)
args.add("-Xlint:serial");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
task.setProcessors(Arrays.asList(new AnnoProc()));
boolean ok = task.call();
pw.close();
System.err.println("ok:" + ok + " diags:" + dl.counts);
if (sw.toString().length() > 0) {
System.err.println("output:\n" + sw.toString());
}
for (Diagnostic.Kind dk: Diagnostic.Kind.values()) {
Integer v = dl.counts.get(dk);
int found = (v == null) ? 0 : v;
int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
if (found != expect) {
error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
}
}
System.err.println();
}
File createDir(File parent, String name) {
File dir = new File(parent, name);
dir.mkdirs();
return dir;
}
File writeFile(File f, String content) throws IOException {
FileWriter out = new FileWriter(f);
try {
out.write(content);
} finally {
out.close();
}
return f;
}
<T> void add(List<T> list, T... values) {
for (T v: values)
list.add(v);
}
void error(String msg) {
System.err.println("Error: " + msg);
errors++;
}
int count;
int errors;
static class DiagListener implements DiagnosticListener<JavaFileObject> {
int total;
Map<Diagnostic.Kind,Integer> counts = new TreeMap<Diagnostic.Kind,Integer>();
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
System.err.println((++total) + ": "
+ "resolveError:" + isResolveError(unwrap(diagnostic)) + "\n"
+ diagnostic);
Diagnostic.Kind dk = diagnostic.getKind();
Integer c = counts.get(dk);
counts.put(dk, (c == null ? 1 : c + 1));
}
private static boolean isResolveError(JCDiagnostic d) {
return d.isFlagSet(RESOLVE_ERROR);
}
private JCDiagnostic unwrap(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic instanceof JCDiagnostic)
return (JCDiagnostic) diagnostic;
if (diagnostic instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper)
return ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic).d;
throw new IllegalArgumentException();
}
}
@SupportedAnnotationTypes("*")
@SupportedOptions("gen")
public static class AnnoProc extends AbstractProcessor {
Filer f;
Messager m;
int gen;
@Override
public void init(ProcessingEnvironment processingEnv) {
f = processingEnv.getFiler();
m = processingEnv.getMessager();
Map<String,String> options = processingEnv.getOptions();
gen = Integer.parseInt(options.get("gen"));
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
round++;
if (round < gen)
writeSource("Dummy" + round, "class Dummy" + round + " extends java.util.ArrayList{ }");
else if (round == gen) {
writeSource("C", "class C { int f; int m() { return 0; } }");
writeSource("I", "interface I { }");
writeSource("E", "class E extends Exception { }");
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void writeSource(String name, String text) {
try {
JavaFileObject fo = f.createSourceFile(name);
Writer out = fo.openWriter();
out.write(text);
out.close();
} catch (IOException e) {
m.printMessage(Diagnostic.Kind.ERROR, e.toString());
}
}
int round = 0;
}
}
| 8,444 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestReturnCode.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/errors/TestReturnCode.java | /*
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6403468
* @summary Test that an erroneous return code results from raising an error.
* @author Joseph D. Darcy
* @library ../../lib
* @build JavacTestingAbstractProcessor CompileFail
* @compile TestReturnCode.java
*
* @compile -processor TestReturnCode -proc:only Foo.java
* @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnFirst Foo.java
* @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnLast Foo.java
* @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnLast -AErrorOnFirst Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnFirst Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnLast Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnLast -AErrorOnFirst Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnFirst Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnLast Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnLast -AErrorOnFirst Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnFirst Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnLast Foo.java
* @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnLast -AErrorOnFirst Foo.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.*;
/**
* This processor raises errors or throws exceptions on different
* rounds to allow the return code to be test.
*/
@SupportedOptions({"ErrorOnFirst",
"ErrorOnLast",
"ExceptionOnFirst",
"ExceptionOnLast"})
public class TestReturnCode extends JavacTestingAbstractProcessor {
private boolean errorOnFirst;
private boolean errorOnLast;
private boolean exceptionOnFirst;
private boolean exceptionOnLast;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
System.out.format("Variables: %b\t%b\t%b\t%b%n",
errorOnFirst,
errorOnLast,
exceptionOnFirst,
exceptionOnLast);
if (errorOnFirst)
messager.printMessage(ERROR, "Error on first round.");
if (exceptionOnFirst)
throw new RuntimeException("Exception on first round.");
} else {
if (errorOnLast)
messager.printMessage(ERROR, "Error on last round.");
if (exceptionOnLast)
throw new RuntimeException("Exception on last round.");
}
return true;
}
@Override
public void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
Set<String> keySet = processingEnv.getOptions().keySet();
errorOnFirst = keySet.contains("ErrorOnFirst");
errorOnLast = keySet.contains("ErrorOnLast");
exceptionOnFirst = keySet.contains("ExceptionOnFirst");
exceptionOnLast = keySet.contains("ExceptionOnLast");
}
}
| 5,659 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestOptionSyntaxErrors.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/errors/TestOptionSyntaxErrors.java | /*
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6406212
* @summary Test that annotation processor options with illegal syntax are rejected
* @author Joseph D. Darcy
* @library ../../lib
* @build JavacTestingAbstractProcessor CompileFail
* @compile TestOptionSyntaxErrors.java
* @run main CompileFail CMDERR -A TestOptionSyntaxErrors.java
* @run main CompileFail CMDERR -A8adOption TestOptionSyntaxErrors.java
* @run main CompileFail CMDERR -A8adOption=1worseOption TestOptionSyntaxErrors.java
* @run main CompileFail CMDERR -processor TestOptionSyntaxErrors -proc:only -A TestOptionSyntaxErrors.java
* @run main CompileFail CMDERR -processor TestOptionSyntaxErrors -proc:only -A8adOption TestOptionSyntaxErrors.java
* @run main CompileFail CMDERR -processor TestOptionSyntaxErrors -proc:only -A8adOption=1worseOption TestOptionSyntaxErrors.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.tools.Diagnostic.Kind.*;
/**
* No-op processor; should not be run.
*/
public class TestOptionSyntaxErrors extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
return true;
}
}
| 2,435 | 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/errors/Foo.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.
*/
public class Foo {}
| 1,072 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestParseErrors.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/errors/TestParseErrors/TestParseErrors.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 6988407
* @summary javac crashes running processor on errant code; it used to print error message
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestParseErrors
* @compile/fail/ref=TestParseErrors.out -XDrawDiagnostics -proc:only -processor TestParseErrors ParseErrors.java
*/
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
public class TestParseErrors extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
throw new Error("Should not be called");
}
}
| 1,723 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
ParseErrors.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/errors/TestParseErrors/ParseErrors.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.
*/
import java.util.List;
import java.util.Vector;
class test {
public String m(List<? extends String> v, String s ) {
return null;
}
public String m2(Vector<String> vs, String s) {
return null;
}
public void m3(testclass<String>,
}
class testclass<T> {
T t;
}
| 1,355 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6413690.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6413690/T6413690.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 6413690 6380018
* @summary JavacProcessingEnvironment does not enter trees from preceding rounds
* @author Peter von der Ah\u00e9
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile T6413690.java
* @compile -XDfatalEnterError -verbose -processor T6413690 src/Super.java TestMe.java
*/
import java.io.IOException;
import java.io.Writer;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
@SupportedAnnotationTypes("TestMe")
public class T6413690 extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
TypeElement testMe = elements.getTypeElement(TestMe.class.getName());
Set<? extends Element> supers = roundEnvironment.getElementsAnnotatedWith(testMe);
try {
for (Element sup : supers) {
Writer sub = filer.createSourceFile(sup.getSimpleName() + "_GENERATED").openWriter();
sub.write(String.format("class %s_GENERATED extends %s {}",
sup.getSimpleName(),
((TypeElement)sup).getQualifiedName()));
sub.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return true;
}
}
| 2,740 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMe.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6413690/TestMe.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public @interface TestMe {}
| 1,080 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Super.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6413690/src/Super.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.
*/
@TestMe public class Super {}
| 1,082 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
test0.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6430209/test0.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.
*/
public class test0 { }
| 1,075 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
test1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6430209/test1.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.
*/
package dir1;
public class test1 { }
| 1,089 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
b6341534.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6430209/b6341534.java | /*
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.annotation.processing.*;
import 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 java.util.*;
import java.util.Set;
public class b6341534 extends JavacTestingAbstractProcessor {
static int r = 0;
//Create directory 'dir1' and a test class in dir1
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv)
{
if(!renv.errorRaised() && !renv.processingOver()){
r++;
for( TypeElement t : typesIn(renv.getRootElements()) )
System.out.println("Round"+r+ ": " + t.toString());
try {
PackageElement PE = eltUtils.getPackageElement("dir1");
List<? extends Element> LEE = PE.getEnclosedElements(); /* <=This line elicits the error message. */
for(Element e : LEE)
System.out.println("found " + e.toString() + " in dir1.");
}
catch(NullPointerException npe) {
messager.printMessage(ERROR,npe.toString());
//npe.printStackTrace();
return false;
}
}
// on round 1, expect errorRaised == false && processingOver == false
// on round 2, expect errorRaised == true && processingOver == true
if( renv.errorRaised() != renv.processingOver()) {
messager.printMessage(ERROR, "FAILED: round:" + r
+ ", errorRaised:" + renv.errorRaised()
+ ", processingOver:" + renv.processingOver());
}
return true;
}
}
| 2,761 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6430209.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6430209/T6430209.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 6441871
* @summary spurious compiler error elicited by packageElement.getEnclosedElements()
* @library ../../lib
* @build JavacTestingAbstractProcessor b6341534
* @run main T6430209
*/
// Note that 6441871 is an interim partial fix for 6430209 that just removes the javac
// crash message and stacktrace
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
public class T6430209 {
public static void main(String... args) throws IOException {
// set up dir1/test0.java
File dir1 = new File("dir1");
dir1.mkdir();
BufferedWriter fout = new BufferedWriter(new FileWriter(new File(dir1, "test0.java")));
fout.write("public class test0 { }");
fout.close();
// run annotation processor b6341534 so we can check diagnostics
// -proc:only -processor b6341534 -cp . ./src/*.java
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes") + System.getProperty("path.separator") + "../../lib";
JavacTool tool = JavacTool.create();
MyDiagListener dl = new MyDiagListener();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File(".")));
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(
new File(testSrc, "test0.java"), new File(testSrc, "test1.java")));
Iterable<String> opts = Arrays.asList("-proc:only",
"-processor", "b6341534",
"-processorpath", testClasses);
StringWriter out = new StringWriter();
JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
task.call();
String s = out.toString();
System.err.print(s);
// Expect the following 2 diagnostics, and no output to log
System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
if (dl.count != 2 || s.length() != 0)
throw new AssertionError("unexpected output from compiler");
}
static class MyDiagListener implements DiagnosticListener<JavaFileObject> {
public void report(Diagnostic d) {
System.err.println(d);
count++;
}
public int count;
}
}
| 3,631 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6414633.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6414633/T6414633.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 6414633 6440109
* @summary Only the first processor message at a source location is reported
* @library ../../lib
* @build JavacTestingAbstractProcessor A T6414633
* @run main T6414633
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
public class T6414633 {
public static void main(String... args) {
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes", ".");
JavacTool tool = JavacTool.create();
MyDiagListener dl = new MyDiagListener();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
try {
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File(testClasses)));
} catch (IOException e) {
throw new AssertionError(e);
}
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, A.class.getName()+".java")));
String[] opts = { "-proc:only",
"-processor", A.class.getName(),
"-classpath", testClasses + System.getProperty("path.separator") + "../../lib" };
JavacTask task = tool.getTask(null, fm, dl, Arrays.asList(opts), null, files);
task.call();
// two annotations on the same element -- expect 2 diags from the processor
if (dl.diags != 2)
throw new AssertionError(dl.diags + " diagnostics reported");
}
private static class MyDiagListener implements DiagnosticListener<JavaFileObject>
{
public void report(Diagnostic d) {
System.err.println(d);
diags++;
}
int diags;
}
}
| 2,967 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
A.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6414633/A.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.
*/
import java.util.*;
import javax.annotation.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
@SuppressWarnings("")
public class A extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Messager m = processingEnv.getMessager();
for (TypeElement anno: annotations) {
for (Element e: roundEnv.getElementsAnnotatedWith(anno))
m.printMessage(Diagnostic.Kind.ERROR, "test", e);
}
return true;
}
@SuppressWarnings("")
private void foo() {}
}
| 1,726 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestLastRound.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/TestLastRound.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 6966604
* @summary JavacFiler not correctly notified of lastRound
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile TestLastRound.java
* @compile/fail/ref=TestLastRound.out -XDrawDiagnostics -Werror -proc:only -processor TestLastRound TestLastRound.java
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
public class TestLastRound extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
try {
JavaFileObject fo = filer.createSourceFile("LastRound.java");
Writer out = fo.openWriter();
out.write("class LastRound { }");
out.close();
} catch (IOException e) {
}
}
return true;
}
}
| 2,069 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestFilerConstraints.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/TestFilerConstraints.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 6380018 6453386 6457283
* @summary Test that the constraints guaranteed by the Filer and maintained
* @author Joseph D. Darcy
* @library ../../lib
* @build TestFilerConstraints
* @compile -encoding iso-8859-1 -processor TestFilerConstraints -proc:only TestFilerConstraints.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.*;
import java.nio.charset.Charset;
/**
* A processor that verifies the explicit and implicit constraints in
* the Filer contract are maintained:
*
* <blockquote>
*
* During each run of an annotation processing tool, a file with a
* given pathname may be created only once. If that file already
* exists before the first attempt to create it, the old contents
* will be deleted. Any subsequent attempt to create the same file
* during a run will throw a FilerException, as will attempting to
* open both a class file and source file for the same type name.
*
* </blockquote>
*
* Specific checks will include:
*
* <ul>
*
* <li> Source and class files can be written to from either a Writer or an OutputStream.
*
* <li> Calling close multiple times does not re-register the file for
* processing.
*
* </ul>
*/
public class TestFilerConstraints extends JavacTestingAbstractProcessor {
private int round = 0;
private PrintWriter pw_src1 = null;
private PrintWriter pw_src2 = null;
private OutputStream os_classFile1 = null;
private Writer pw_classFile2 = null;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
round++;
try {
switch(round) {
// Open two source files
case 1:
pw_src1 = new PrintWriter(filer.createSourceFile("Src1").openWriter());
pw_src1.println("class Src1 {}");
pw_src1.close();
// Hold open across rounds
pw_src2 = new PrintWriter(new OutputStreamWriter(filer.createSourceFile("Src2").openOutputStream()));
break;
case 2:
testExpectedType(roundEnv, "Src1");
// Close Src1 a second time
pw_src1.close();
pw_src2.println("class Src2 {}");
pw_src2.close();
break;
case 3:
testExpectedType(roundEnv, "Src2");
// Close Src2 a second time
pw_src2.close();
os_classFile1 = filer.createClassFile("ClassFile1").openOutputStream();
for (int value : classFile1Bytes)
os_classFile1.write((byte)value);
os_classFile1.close();
break;
case 4:
testExpectedType(roundEnv, "ClassFile1");
// Close a second time
os_classFile1.close();
testReopening();
pw_classFile2 = new PrintWriter(filer.createClassFile("ClassFile2",
(Element[])null).openWriter());
for(int byteVal : classFile2Bytes) {
// int value = (0xff00 & (classFile2Bytes[i]<<8)) | classFile2Bytes[i+1];
// System.out.print(Integer.toHexString(value));
//if ((i % 4) == 0)
// System.out.println();
pw_classFile2.write((char) (0xff & byteVal));
}
pw_classFile2.close();
break;
case 5:
testExpectedType(roundEnv, "ClassFile2");
// Close a second time
pw_classFile2.close();
break;
case 6:
if (!roundEnv.processingOver() && !roundEnv.errorRaised())
throw new RuntimeException("Bad round state: " + roundEnv);
break;
default:
throw new RuntimeException("Unexpected round number!");
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
return true;
}
/**
* Test that the single expected expected type, name, is the root
* element.
*/
private void testExpectedType(RoundEnvironment roundEnv, String name) {
if (!roundEnv.getRootElements().isEmpty()) {
for(TypeElement type : typesIn(roundEnv.getRootElements())) {
if (!name.contentEquals(type.getSimpleName()))
throw new RuntimeException("Unexpected type " + type.getSimpleName());
}
} else
throw new RuntimeException("Unexpected empty root elements.");
}
private void testReopening() throws IOException {
String[] names = {"Src1", "Src2", "ClassFile1"};
for (String name : names) {
try {
filer.createSourceFile(name);
throw new RuntimeException("Opened a source file for type " + name);
} catch (FilerException fe) {;}
try {
filer.createClassFile(name);
throw new RuntimeException("Opened a class file for type " + name);
} catch (FilerException fe) {;}
}
// Try to open a resource over a source file
try {
filer.createResource(SOURCE_OUTPUT, "", "Src1.java");
throw new RuntimeException("Opened a text file over Src1.java!");
} catch (FilerException fe) {;}
// Try to open a resource over a class file
try {
filer.createResource(CLASS_OUTPUT, "", "ClassFile1.class");
throw new RuntimeException("Opened a text file over Src1.java!");
} catch (FilerException fe) {;}
}
private int[] classFile1Bytes =
{202, 254, 186, 190, 0, 0, 0, 50,
0, 13, 10, 0, 3, 0, 10, 7,
0, 11, 7, 0, 12, 1, 0, 6,
60, 105, 110, 105, 116, 62, 1, 0,
3, 40, 41, 86, 1, 0, 4, 67,
111, 100, 101, 1, 0, 15, 76, 105,
110, 101, 78, 117, 109, 98, 101, 114,
84, 97, 98, 108, 101, 1, 0, 10,
83, 111, 117, 114, 99, 101, 70, 105,
108, 101, 1, 0, 15, 67, 108, 97,
115, 115, 70, 105, 108, 101, 49, 46,
106, 97, 118, 97, 12, 0, 4, 0,
5, 1, 0, 10, 67, 108, 97, 115,
115, 70, 105, 108, 101, 49, 1, 0,
16, 106, 97, 118, 97, 47, 108, 97,
110, 103, 47, 79, 98, 106, 101, 99,
116, 0, 33, 0, 2, 0, 3, 0,
0, 0, 0, 0, 1, 0, 1, 0,
4, 0, 5, 0, 1, 0, 6, 0,
0, 0, 29, 0, 1, 0, 1, 0,
0, 0, 5, 42, 183, 0, 1, 177,
0, 0, 0, 1, 0, 7, 0, 0,
0, 6, 0, 1, 0, 0, 0, 1,
0, 1, 0, 8, 0, 0, 0, 2,
0, 9,};
private int[] classFile2Bytes =
{202, 254, 186, 190, 0, 0, 0, 50,
0, 13, 10, 0, 3, 0, 10, 7,
0, 11, 7, 0, 12, 1, 0, 6,
60, 105, 110, 105, 116, 62, 1, 0,
3, 40, 41, 86, 1, 0, 4, 67,
111, 100, 101, 1, 0, 15, 76, 105,
110, 101, 78, 117, 109, 98, 101, 114,
84, 97, 98, 108, 101, 1, 0, 10,
83, 111, 117, 114, 99, 101, 70, 105,
108, 101, 1, 0, 15, 67, 108, 97,
115, 115, 70, 105, 108, 101, 50, 46,
106, 97, 118, 97, 12, 0, 4, 0,
5, 1, 0, 10, 67, 108, 97, 115,
115, 70, 105, 108, 101, 50, 1, 0,
16, 106, 97, 118, 97, 47, 108, 97,
110, 103, 47, 79, 98, 106, 101, 99,
116, 0, 33, 0, 2, 0, 3, 0,
0, 0, 0, 0, 1, 0, 1, 0,
4, 0, 5, 0, 1, 0, 6, 0,
0, 0, 29, 0, 1, 0, 1, 0,
0, 0, 5, 42, 183, 0, 1, 177,
0, 0, 0, 1, 0, 7, 0, 0,
0, 6, 0, 1, 0, 0, 0, 1,
0, 1, 0, 8, 0, 0, 0, 2,
0, 9,};
}
| 9,464 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestGetResource.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/TestGetResource.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 6380018 6449798
* @summary Test Filer.getResource
* @author Joseph D. Darcy
* @library ../../lib
* @build JavacTestingAbstractProcessor TestGetResource
* @compile -processor TestGetResource -proc:only -Aphase=write TestGetResource.java
* @compile -processor TestGetResource -proc:only -Aphase=read TestGetResource.java
*/
import java.util.Set;
import java.util.Map;
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.IOException;
import java.io.PrintWriter;
/**
* Test basic functionality of the Filer.getResource method. On the
* first run of the annotation processor, write out a resource file
* and on the second run read it in.
*/
@SupportedOptions("phase")
public class TestGetResource extends JavacTestingAbstractProcessor {
private static String CONTENTS = "Hello World.";
private static String PKG = "";
private static String RESOURCE_NAME = "Resource1";
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
try {
if (!roundEnv.processingOver()) {
String phase = options.get("phase");
if (phase.equals("write")) {
PrintWriter pw =
new PrintWriter(filer.createResource(CLASS_OUTPUT, PKG, RESOURCE_NAME).openWriter());
pw.print(CONTENTS);
pw.close();
} else if (phase.equals("read")) {
String contents = filer.getResource(CLASS_OUTPUT,
PKG,
RESOURCE_NAME).getCharContent(false).toString();
if (!contents.equals(CONTENTS))
throw new RuntimeException("Expected \n\t" + CONTENTS +
"\nbut instead got \n\t" +
contents);
// Now try to open the file for writing
filer.createResource(CLASS_OUTPUT,
PKG,
RESOURCE_NAME);
} else {
throw new RuntimeException("Unexpected phase: " + phase);
}
}
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
return false;
}
}
| 3,802 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestGetResource2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/TestGetResource2.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 6929404
* @summary Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
* @library ../../lib
*/
import java.io.*;
import java.security.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
import javax.tools.Diagnostic.Kind;
import javax.tools.JavaCompiler.CompilationTask;
public class TestGetResource2 {
public static void main(String[] args) throws Exception {
new TestGetResource2().run();
}
void run() throws Exception {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
CodeSource cs = javac.getClass().getProtectionDomain().getCodeSource();
if (cs == null) {
System.err.println("got compiler from " +
ClassLoader.getSystemResource(javac.getClass().getName().replace(".", "/")+".class"));
} else {
System.err.println("got compiler from " + cs.getLocation());
}
testSingleSourceDir(javac);
testCompositeSourcePath(javac);
testMissingResource(javac);
}
private void testSingleSourceDir(JavaCompiler javac) throws Exception {
System.err.println("testSingleSourceDir");
File tmpdir = new File("testSingleSourceDir");
File srcdir = new File(tmpdir, "src");
File destdir = new File(tmpdir, "dest");
write(srcdir, "pkg/X.java", "package pkg; class X {}");
write(srcdir, "resources/file.txt", "hello");
destdir.mkdirs();
CompilationTask task = javac.getTask(null, null, null,
Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()),
Collections.singleton("pkg.X"), null);
task.setProcessors(Collections.singleton(new AnnoProc()));
boolean result = task.call();
System.err.println("javac result with single source dir: " + result);
expect(result, true);
}
private void testCompositeSourcePath(JavaCompiler javac) throws Exception {
System.err.println("testCompositeSearchPath");
File tmpdir = new File("testCompositeSourcePath");
File srcdir = new File(tmpdir, "src");
File rsrcdir = new File(tmpdir, "rsrc");
File destdir = new File(tmpdir, "dest");
write(srcdir, "pkg/X.java", "package pkg; class X {}");
write(rsrcdir, "resources/file.txt", "hello");
destdir.mkdirs();
CompilationTask task = javac.getTask(null, null, null,
Arrays.asList("-sourcepath", srcdir + File.pathSeparator + rsrcdir, "-d", destdir.toString()),
Collections.singleton("pkg.X"), null);
task.setProcessors(Collections.singleton(new AnnoProc()));
boolean result = task.call();
System.err.println("javac result with composite source path: " + result);
expect(result, true);
}
private void testMissingResource(JavaCompiler javac) throws Exception {
System.err.println("testMissingResource");
File tmpdir = new File("testMissingResource");
File srcdir = new File(tmpdir, "src");
File destdir = new File(tmpdir, "dest");
write(srcdir, "pkg/X.java", "package pkg; class X {}");
destdir.mkdirs();
CompilationTask task = javac.getTask(null, null, null,
Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()),
Collections.singleton("pkg.X"), null);
task.setProcessors(Collections.singleton(new AnnoProc()));
boolean result = task.call();
System.err.println("javac result when missing resource: " + result);
expect(result, false);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
static class AnnoProc extends JavacTestingAbstractProcessor {
public @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
return false;
}
try {
FileObject resource = filer.getResource(StandardLocation.SOURCE_PATH, "resources", "file.txt");
try {
resource.openInputStream().close();
messager.printMessage(Kind.NOTE, "found: " + resource.toUri());
return true;
} catch (IOException x) {
messager.printMessage(Kind.ERROR, "could not read: " + resource.toUri());
x.printStackTrace();
}
} catch (IOException x) {
messager.printMessage(Kind.ERROR, "did not find resource");
x.printStackTrace();
}
return false;
}
}
private File write(File dir, String path, String contents) throws IOException {
File f = new File(dir, path);
f.getParentFile().mkdirs();
Writer w = new FileWriter(f);
try {
w.write(contents);
} finally {
w.close();
}
return f;
}
void expect(boolean val, boolean expect) {
if (val != expect)
error("Unexpected value: " + val + "; expected: " + expect);
}
void error(String msg) {
System.err.println(msg);
errors++;
}
int errors = 0;
}
| 6,455 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestValidRelativeNames.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/TestValidRelativeNames.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 6999891
* @summary Test valid relative names for Filer.createResource and Filer.getResource
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile TestValidRelativeNames.java
* @compile/process -processor TestValidRelativeNames -Amode=create java.lang.Object
* @compile/process -processor TestValidRelativeNames -Amode=get java.lang.Object
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.Diagnostic;
import javax.tools.StandardLocation;
@SupportedOptions("mode")
public class TestValidRelativeNames extends JavacTestingAbstractProcessor {
enum Kind { READER_WRITER, INPUT_OUTPUT_STREAM };
static final String[] validRelativeNames = {
"foo", "foo.bar", ".foo", ".foo.bar", "foodir/bar", "foodir/.bar"
};
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
String mode = options.get("mode");
for (String relativeBase: validRelativeNames) {
for (Kind kind: Kind.values()) {
if (mode.equals("create"))
testCreate(relativeBase, kind);
else
testGet(relativeBase, kind);
}
}
}
return true;
}
void testCreate(String relativeBase, Kind kind) {
String relative = getRelative(relativeBase, kind);
System.out.println("test create relative path: " + relative + ", kind: " + kind);
try {
switch (kind) {
case READER_WRITER:
try (Writer writer = filer.createResource(
StandardLocation.CLASS_OUTPUT, "", relative).openWriter()) {
writer.write(relative);
}
break;
case INPUT_OUTPUT_STREAM:
try (OutputStream out = filer.createResource(
StandardLocation.CLASS_OUTPUT, "", relative).openOutputStream()) {
out.write(relative.getBytes());
}
break;
}
} catch (Exception e) {
messager.printMessage(Diagnostic.Kind.ERROR,
"relative path: " + relative + ", kind: " + kind + ", unexpected exception: " + e);
}
}
void testGet(String relativeBase, Kind kind) {
String relative = getRelative(relativeBase, kind);
System.out.println("test get relative path: " + relative + ", kind: " + kind);
try {
switch (kind) {
case READER_WRITER:
try (Reader reader = new BufferedReader(filer.getResource(
StandardLocation.CLASS_OUTPUT, "", relative).openReader(true))) {
StringBuilder sb = new StringBuilder();
char[] buf = new char[1024];
int n;
while ((n = reader.read(buf, 0, buf.length)) > 0)
sb.append(new String(buf, 0, n));
if (!sb.toString().equals(relative)) {
messager.printMessage(Diagnostic.Kind.ERROR, "unexpected content: " + sb);
}
}
break;
case INPUT_OUTPUT_STREAM:
try (InputStream in = new DataInputStream(filer.getResource(
StandardLocation.CLASS_OUTPUT, "", relative).openInputStream())) {
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[1024];
int n;
while ((n = in.read(buf, 0, buf.length)) > 0)
sb.append(new String(buf, 0, n));
if (!sb.toString().equals(relative)) {
messager.printMessage(Diagnostic.Kind.ERROR, "unexpected content: " + sb);
}
}
break;
}
} catch (Exception e) {
messager.printMessage(Diagnostic.Kind.ERROR,
"relative path: " + relative + ", kind: " + kind + ", unexpected exception: " + e);
}
}
String getRelative(String relativeBase, Kind kind) {
String suffix = (kind == Kind.READER_WRITER ? "RW" : "IOS");
return relativeBase.replace("foo", "foo" + suffix);
}
}
| 5,683 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestInvalidRelativeNames.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/TestInvalidRelativeNames.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 6502392
* @summary Invalid relative names for Filer.createResource and Filer.getResource
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile TestInvalidRelativeNames.java
* @compile/process -processor TestInvalidRelativeNames java.lang.Object
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.Diagnostic;
import javax.tools.StandardLocation;
public class TestInvalidRelativeNames extends JavacTestingAbstractProcessor {
enum Kind { CREATE_WRITER, GET_READER, CREATE_OUTPUT_STREAM, GET_INPUT_STREAM };
static final String[] invalidRelativeNames = {
"/boo", "goo/../hoo", "./ioo", ""
};
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
for (String relative: invalidRelativeNames) {
for (Kind kind: Kind.values()) {
test(relative, kind);
}
}
}
return true;
}
void test(String relative, Kind kind) {
System.out.println("test relative path: " + relative + ", kind: " + kind);
try {
switch (kind) {
case CREATE_WRITER:
Writer writer = filer.createResource(
StandardLocation.SOURCE_OUTPUT, "", relative).openWriter();
writer.close();
break;
case GET_READER:
Reader reader = filer.getResource(
StandardLocation.SOURCE_OUTPUT, "", relative).openReader(true);
reader.close();
break;
case CREATE_OUTPUT_STREAM:
OutputStream out = filer.createResource(
StandardLocation.SOURCE_OUTPUT, "", relative).openOutputStream();
out.close();
break;
case GET_INPUT_STREAM:
InputStream in = filer.createResource(
StandardLocation.SOURCE_OUTPUT, "", relative).openInputStream();
in.close();
break;
}
} catch (IllegalArgumentException expected) {
System.out.println("expected exception thrown: " + expected);
return;
} catch (Exception e) {
messager.printMessage(Diagnostic.Kind.ERROR,
"relative path: " + relative + ", kind: " + kind + ", unexpected exception: " + e);
return;
}
messager.printMessage(Diagnostic.Kind.ERROR,
"relative path: " + relative + ", kind: " + kind + ", no exception thrown");
}
}
| 3,886 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestPackageInfo.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/TestPackageInfo.java | /*
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6380018 6392177 6993311
* @summary Test the ability to create and process package-info.java files
* @author Joseph D. Darcy
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile TestPackageInfo.java
* @compile -processor TestPackageInfo -proc:only foo/bar/package-info.java TestPackageInfo.java
*/
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
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 the ability to process annotations on package-info.java files:
* 1) Visibility of package-info files from the command line
* 2) Visibility of generated package-info.java source files
*/
public class TestPackageInfo extends JavacTestingAbstractProcessor {
private int round = 0;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
round++;
// Verify annotations are as expected
Set<TypeElement> expectedAnnotations = new HashSet<TypeElement>();
expectedAnnotations.add(eltUtils.getTypeElement("java.lang.Deprecated"));
if (!roundEnv.processingOver()) {
System.out.println("\nRound " + round);
int rootElementSize = roundEnv.getRootElements().size();
for(Element elt : roundEnv.getRootElements()) {
System.out.printf("%nElement %s\tkind: %s%n", elt.getSimpleName(), elt.getKind());
eltUtils.printElements(new PrintWriter(System.out), elt);
}
switch (round) {
case 1:
if (rootElementSize != 2)
throw new RuntimeException("Unexpected root element size " + rootElementSize);
// Note that foo.bar.FuBar, an element of package
// foo.bar, contains @Deprecated which should *not* be
// included in the set of annotations to process
if (!expectedAnnotations.equals(annotations)) {
throw new RuntimeException("Unexpected annotations: " + annotations);
}
try {
try {
filer.createClassFile("package-info");
throw new RuntimeException("Created class file for \"package-info\".");
} catch(FilerException fe) {}
PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter());
pw.println("@Deprecated");
pw.println("package foo;");
pw.close();
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
break;
case 2:
// Expect foo.package-info
Set<Element> expectedElement = new HashSet<Element>();
expectedElement.add(eltUtils.getPackageElement("foo"));
if (!expectedElement.equals(roundEnv.getRootElements()))
throw new RuntimeException("Unexpected root element set " + roundEnv.getRootElements());
if (!expectedAnnotations.equals(annotations)) {
throw new RuntimeException("Unexpected annotations: " + annotations);
}
break;
default:
throw new RuntimeException("Unexpected round number " + round);
}
}
return false;
}
}
| 4,828 | 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/filer/foo/Foo.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.
*/
package foo;
public class Foo{}
| 1,084 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
package-info.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/foo/bar/package-info.java | /*
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Javadoc for the foo.bar package!
*/
@Deprecated
package foo.bar;
| 1,131 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
FuBar.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/filer/foo/bar/FuBar.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.
*/
package foo.bar;
@Deprecated
public class FuBar {}
| 1,104 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
A.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6348499/A.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.
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
public class A extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
try {
OutputStream out = filer.createClassFile(getClass().getName()+"_0").openOutputStream();
out.close();
} catch (IOException e) {
throw new Error(e);
}
return true;
}
}
| 1,580 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6348499.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6348499/T6348499.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 6441871
* @summary javac crashes at com.sun.tools.javac.jvm.ClassReader$BadClassFile
* @library ../../lib
* @build JavacTestingAbstractProcessor A
* @run main T6348499
*/
// Note that 6441871 is an interim partial fix for 6348499 that just removes the javac
// crash message and stacktrace
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
public class T6348499 {
public static void main(String... args) {
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes");
String A_java = new File(testSrc, "A.java").getPath();
JavacTool tool = JavacTool.create();
MyDiagListener dl = new MyDiagListener();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
Iterable<String> opts = Arrays.asList("-proc:only",
"-processor", "A",
"-processorpath", testClasses);
StringWriter out = new StringWriter();
JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
task.call();
String s = out.toString();
System.err.print(s);
// Expect the following 1 multi-line diagnostic, and no output to log
// error: cannot access A_0
// bad class file: A_0.class
// illegal start of class file
// Please remove or make sure it appears in the correct subdirectory of the classpath.
System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
if (dl.count != 1 || s.length() != 0)
throw new AssertionError("unexpected output from compiler");
}
static class MyDiagListener implements DiagnosticListener<JavaFileObject> {
public void report(Diagnostic d) {
System.err.println(d);
count++;
}
public int count;
}
private static String self = T6348499.class.getName();
}
| 3,380 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
SyntaxErrorTest.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6994946/SyntaxErrorTest.java | /*
* @test /nodynamiccopyright/
* @bug 6994946
* @summary option to specify only syntax errors as unrecoverable
* @library ../../lib
* @build JavacTestingAbstractProcessor TestProcessor
* @compile/fail/ref=SyntaxErrorTest.out -XDrawDiagnostics -processor TestProcessor SyntaxErrorTest.java
* @compile/fail/ref=SyntaxErrorTest.out -XDrawDiagnostics -XDonlySyntaxErrorsUnrecoverable -processor TestProcessor SyntaxErrorTest.java
*/
class SyntaxErrorTest {
int i
}
| 508 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestProcessor.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6994946/TestProcessor.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.
*/
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import static javax.tools.Diagnostic.Kind.*;
public class TestProcessor extends JavacTestingAbstractProcessor {
private int round = 0;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (++round == 1)
messager.printMessage(ERROR, "Deliberate Error");
return false;
}
}
| 1,543 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
SemanticErrorTest.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6994946/SemanticErrorTest.java | /*
* @test /nodynamiccopyright/
* @bug 6994946
* @summary option to specify only syntax errors as unrecoverable
* @library ../../lib
* @build JavacTestingAbstractProcessor TestProcessor
* @compile/fail/ref=SemanticErrorTest.1.out -XDrawDiagnostics -processor TestProcessor SemanticErrorTest.java
* @compile/fail/ref=SemanticErrorTest.2.out -XDrawDiagnostics -XDonlySyntaxErrorsUnrecoverable -processor TestProcessor SemanticErrorTest.java
*/
class SemanticErrorTest implements Runnable, Runnable {
public void run() { }
}
| 568 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
WErrorLast.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/werror/WErrorLast.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 6403456
* @summary -Werror should work with annotation processing
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile WErrorLast.java
* @compile -proc:only -processor WErrorLast WErrorLast.java
* @compile/fail/ref=WErrorLast.out -XDrawDiagnostics -Werror -proc:only -processor WErrorLast WErrorLast.java
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
public class WErrorLast extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
messager.printMessage(Diagnostic.Kind.WARNING, "last round");
}
return true;
}
}
| 1,916 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
WErrorGen.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/werror/WErrorGen.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 6403456
* @summary -Werror should work with annotation processing
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile WErrorGen.java
* @compile -proc:only -processor WErrorGen WErrorGen.java
* @compile/fail/ref=WErrorGen.out -XDrawDiagnostics -Werror -Xlint:rawtypes -processor WErrorGen WErrorGen.java
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
public class WErrorGen extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (++round == 1) {
try {
JavaFileObject fo = filer.createSourceFile("Gen");
Writer out = fo.openWriter();
out.write("import java.util.*; class Gen { List l; }");
out.close();
} catch (IOException e) {
}
}
return true;
}
int round = 0;
}
| 2,131 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
WError1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/werror/WError1.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 6403456
* @summary -Werror should work with annotation processing
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile WError1.java
* @compile -proc:only -processor WError1 WError1.java
* @compile/fail/ref=WError1.out -XDrawDiagnostics -Werror -proc:only -processor WError1 WError1.java
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
public class WError1 extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (++round == 1) {
messager.printMessage(Diagnostic.Kind.WARNING, "round 1");
}
return true;
}
int round = 0;
}
| 1,899 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestEnum.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6512707/TestEnum.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.
*/
public enum TestEnum
{
ONE,
TWO
}
| 1,095 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestAnnotation.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6512707/TestAnnotation.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.
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TestAnnotation
{
public TestEnum value() default TestEnum.TWO;
}
| 1,364 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6512707.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/6512707/T6512707.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 6512707
* @summary "incompatible types" after (unrelated) annotation processing
* @author Peter Runge
* @library ../../lib
* @build JavacTestingAbstractProcessor
* @compile T6512707.java
* @compile -processor T6512707 TestAnnotation.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
/**
* Dummy processor to force bug 6512707 to show - it does not matter what
* the annotation processor does for this bug.
*/
public class T6512707 extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
return false;
}
}
| 1,842 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestExceptions.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/TestExceptions.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 6794071
* @summary Test that exceptions have a proper parent class
* @author Joseph D. Darcy
*/
import javax.lang.model.UnknownEntityException;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
/*
* Verify UnknownFooExceptions can be caught with a common parent
* exception.
*/
public class TestExceptions {
public static void main(String... args) {
RuntimeException[] exceptions = {
new UnknownElementException((Element)null, (Object)null),
new UnknownAnnotationValueException((AnnotationValue) null, (Object) null),
new UnknownTypeException((TypeMirror)null, (Object)null)
};
for(RuntimeException exception : exceptions) {
try {
throw exception;
} catch (UnknownEntityException uee) {
;
}
}
}
}
| 1,940 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestSymtabItems.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/TestSymtabItems.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 7021183
* @summary 269: assertion failure getting enclosing element of an undefined name
*/
import java.lang.reflect.Field;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.UnknownElementException;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.UnknownTypeException;
import javax.lang.model.util.ElementScanner7;
import javax.lang.model.util.SimpleTypeVisitor7;
import javax.lang.model.util.Types;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.model.JavacTypes;
import com.sun.tools.javac.util.Context;
/**
* Scan javac Symtab looking for TypeMirrors and Elements, and ensure that
* no exceptions are thrown when used with javax.lang.model visitors.
*
*/
public class TestSymtabItems {
public static void main(String... args) throws Exception {
new TestSymtabItems().run();
}
void run() throws Exception {
Context c = new Context();
JavacFileManager.preRegister(c);
Symtab syms = Symtab.instance(c);
JavacTypes types = JavacTypes.instance(c);
JavaCompiler.instance(c); // will init ClassReader.sourceCompleter
// print("noSymbol", syms.noSymbol);
// print("errSymbol", syms.errSymbol);
// print("unknownSymbol", syms.unknownSymbol);
// print("botType", syms.botType);
// print("errType", syms.errType);
// print("unknownType", syms.unknownType);
for (Field f: Symtab.class.getDeclaredFields()) {
// System.err.println(f.getType() + " " + f.getName());
// Temporarily ignore methodHandle and transientMethodHandle
// during API evolution
if (f.getName().toLowerCase().contains("methodhandle"))
continue;
Class<?> ft = f.getType();
if (TypeMirror.class.isAssignableFrom(ft))
print(f.getName(), (TypeMirror) f.get(syms), types);
else if(Element.class.isAssignableFrom(ft))
print(f.getName(), (Element) f.get(syms));
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void print(String label, Element e) {
ElemPrinter ep = new ElemPrinter();
System.err.println("Test " + label);
ep.visit(e);
System.err.println();
}
void print(String label, TypeMirror t, Types types) {
TypePrinter tp = new TypePrinter();
System.err.println("Test " + label);
tp.visit(t, types);
System.err.println();
}
void error(String msg) {
System.err.println("Error: " + msg);
errors++;
}
int errors;
class ElemPrinter extends ElementScanner7<Void, Void> {
@Override
public Void visitPackage(PackageElement e, Void p) {
show("package", e);
indent(+1);
super.visitPackage(e, p);
indent(-1);
return null;
}
@Override
public Void visitType(TypeElement e, Void p) {
show("type", e);
indent(+1);
super.visitType(e, p);
indent(-1);
return null;
}
@Override
public Void visitVariable(VariableElement e, Void p) {
show("variable", e);
indent(+1);
super.visitVariable(e, p);
indent(-1);
return null;
}
@Override
public Void visitExecutable(ExecutableElement e, Void p) {
show("executable", e);
indent(+1);
super.visitExecutable(e, p);
indent(-1);
return null;
}
@Override
public Void visitTypeParameter(TypeParameterElement e, Void p) {
show("type parameter", e);
indent(+1);
super.visitTypeParameter(e, p);
indent(-1);
return null;
}
@Override
public Void visitUnknown(Element e, Void p) {
show("unknown", e);
indent(+1);
try {
super.visitUnknown(e, p);
} catch (UnknownElementException ex) {
System.err.println("caught " + ex);
}
indent(-1);
return null;
}
void indent(int i) {
indent += i;
}
String sp(int w) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < w; i++)
sb.append(" ");
return sb.toString();
}
void show(String label, Element e) {
System.err.println(sp(indent) + label
+ ": mods:" + e.getModifiers()
+ " " + e.getSimpleName()
+ ", kind: " + e.getKind()
+ ", type: " + e.asType()
+ ", encl: " + e.getEnclosingElement());
// The following checks help establish why NPE might occur when trying to scan children
if (e instanceof ClassSymbol) {
ClassSymbol csym = (ClassSymbol) e;
if (csym.members_field == null)
error("members_field is null");
if (csym.type == null)
System.err.println("type is null");
}
}
int indent;
};
class TypePrinter extends SimpleTypeVisitor7<Void, Types> {
@Override
public Void defaultAction(TypeMirror m, Types types) {
System.err.println(m.getKind() + " " + m + " " + types.asElement(m));
return null;
}
@Override
public Void visitUnknown(TypeMirror t, Types types) {
try {
return super.visitUnknown(t, types);
} catch (UnknownTypeException ex) {
System.err.println("caught " + ex);
return null;
}
}
};
}
| 7,375 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6194785a.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/6194785/T6194785a.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.
*/
package foo;
public class T6194785a {
void foo(String bar) {}
}
| 1,120 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6194785.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/6194785/T6194785.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 6194785
* @summary ParameterDeclaration.getSimpleName does not return actual name from class files
* @author Peter von der Ah\u00e9
* @library ../../../lib
* @build JavacTestingAbstractProcessor
* @compile -g T6194785.java T6194785a.java
* @compile -processor T6194785 foo.T6194785a T6194785.java
*/
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.tools.Diagnostic.Kind.*;
public class T6194785 extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment)
{
class Scan extends ElementScanner7<Void,Void> {
@Override
public Void visitExecutable(ExecutableElement e, Void ignored) {
for (VariableElement p : e.getParameters())
if ("arg0".equals(p.getSimpleName().toString()))
throw new AssertionError(e);
return null;
}
}
Scan scan = new Scan();
for (Element e : roundEnvironment.getRootElements()) {
scan.scan(e);
}
return true;
}
}
| 2,314 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TypeParamBounds.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TypeParamBounds.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 6423972
* @summary Tests TypeParameter.getBounds.
* @author Scott Seligman
* @library ../../../lib
* @build JavacTestingAbstractProcessor TypeParamBounds
* @compile -processor TypeParamBounds -proc:only TypeParamBounds.java
*/
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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 TypeParamBounds 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 gen = elements.getTypeElement("TypeParamBounds.Gen");
// For each type parameter of Gen, compare its bounds with the
// bounds that are expected.
//
for (TypeParameterElement tparam : gen.getTypeParameters()) {
System.out.println(tparam);
List<? extends TypeMirror> bounds = tparam.getBounds();
String[] expected = Gen.boundNames.get(tparam + "");
if (bounds.size() != expected.length)
throw new AssertionError();
int i = 0;
for (TypeMirror bound : bounds) {
Name got = types.asElement(bound).getSimpleName();
String shoulda = expected[i++];
System.out.println(" " + got);
if (!got.contentEquals(shoulda))
throw new AssertionError(shoulda);
}
}
}
// Fodder for the processor
static class Gen<T, U extends Object, V extends Number, W extends U,
X extends Runnable, Y extends CharSequence & Runnable,
Z extends Object & Runnable> {
// The names of the bounds of each type parameter of Gen.
static Map<String, String[]> boundNames =
new HashMap<String, String[]>();
static {
boundNames.put("T", new String[] {"Object"});
boundNames.put("U", new String[] {"Object"});
boundNames.put("V", new String[] {"Number"});
boundNames.put("W", new String[] {"U"});
boundNames.put("X", new String[] {"Runnable"});
boundNames.put("Y", new String[] {"CharSequence", "Runnable"});
boundNames.put("Z", new String[] {"Object", "Runnable"});
}
}
}
| 3,753 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestElement.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestElement.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 basic properties of javax.lang.element.Element
* @author Joseph D. Darcy
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestElement
* @compile -processor TestElement -proc:only TestElement.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 javax.lang.element.Element
*/
public class TestElement extends JavacTestingAbstractProcessor {
/**
* For now, just check that constructors have a simple name of
* "<init>".
*/
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
boolean hasRun = false;
for (Element element : roundEnv.getRootElements()) {
for (ExecutableElement ctor : constructorsIn(element.getEnclosedElements())) {
hasRun = true;
Name ctorName = ctor.getSimpleName();
if (!ctorName.contentEquals("<init>"))
throw new RuntimeException("Unexpected name for constructor " + ctorName);
}
}
if (!hasRun)
throw new RuntimeException("No constructors!");
}
return true;
}
}
| 2,682 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestAnonSourceNames.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestAnonSourceNames.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.
*/
import java.io.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import java.util.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import static javax.tools.Diagnostic.Kind.*;
/**
* Using the tree API, retrieve element representations of anonymous
* classes and verify their names are as specified.
*/
public class TestAnonSourceNames extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
Trees trees = Trees.instance(processingEnv);
for(Element rootElement : roundEnv.getRootElements()) {
TreePath treePath = trees.getPath(rootElement);
(new ClassTreeScanner(trees)).
scan(trees.getTree(rootElement),
treePath.getCompilationUnit());
}
}
return true;
}
class ClassTreeScanner extends TreeScanner<Void, CompilationUnitTree> {
private Trees trees;
public ClassTreeScanner(Trees trees) {
super();
this.trees = trees;
}
@Override
public Void visitClass(ClassTree node, CompilationUnitTree cu) {
Element element = trees.getElement(trees.getPath(cu, node));
if (element == null) {
processingEnv.getMessager().printMessage(ERROR,
"No element retrieved for node named ''" +
node.getSimpleName() + "''.");
} else {
System.out.println("\nVisiting class ``" + element.getSimpleName() +
"'' of kind " + element.getKind());
if (element instanceof TypeElement) {
TypeElement typeElement = (TypeElement) element;
String s = typeElement.getQualifiedName().toString();
System.out.println("\tqualified name:" + s);
} else {
throw new RuntimeException("TypeElement not gotten from ClassTree.");
}
}
return super.visitClass(node, cu);
}
}
}
| 3,427 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestAnonClassNames.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestAnonClassNames.java | /*
* Copyright (c) 2010, 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 6449781 6930508
* @summary Test that reported names of anonymous classes are non-null.
* @author Joseph D. Darcy
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestAnonSourceNames
* @compile -processor TestAnonSourceNames TestAnonClassNames.java
* @run main TestAnonClassNames
*/
/*
* This test operates in phases to test retrieving the qualified name
* of anonymous classes from type elements modeling the anonymous
* class. The type elements are generated using both source files and
* class files as the basis of constructing the elements.
*
* Source files will be tested by the @compile line which runs
* TestAnonSourceNames as an annotation processor over this file.
*
* Class files are tested by the @run command on this type. This
* class gets the names of classes with different nesting kinds,
* including anonymous classes, and then invokes the compiler with an
* annotation processor having the class files names as inputs. The
* compiler is invoked via the javax.tools mechanism.
*/
import java.lang.annotation.*;
import javax.lang.model.element.*;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import javax.tools.*;
import java.util.*;
import static java.lang.annotation.RetentionPolicy.*;
import static javax.lang.model.element.NestingKind.*;
import static javax.lang.model.util.ElementFilter.*;
import static javax.tools.Diagnostic.Kind.*;
import static javax.tools.StandardLocation.*;
@Nesting(TOP_LEVEL)
public class TestAnonClassNames {
@Nesting(MEMBER)
static class MemberClass1{}
@Nesting(MEMBER)
class MemberClass2{}
@Nesting(MEMBER)
class Win$$AtVegas { } // Class with funny name.
public static void main(String... argv) {
@Nesting(LOCAL)
class LocalClass{};
Object o = new /*@Nesting(ANONYMOUS)*/ Object() { // An anonymous annotated class
public String toString() {
return "I have no name!";
}
};
Class<?>[] classes = {
MemberClass1.class,
MemberClass2.class,
LocalClass.class,
Win$$AtVegas.class,
o.getClass(),
TestAnonClassNames.class,
};
List<String> names = new ArrayList<String>();
for(Class<?> clazz : classes) {
String name = clazz.getName();
Nesting anno = clazz.getAnnotation(Nesting.class);
System.out.format("%s is %s%n",
clazz.getName(),
anno == null ? "(unset/ANONYMOUS)" : anno.value());
testClassName(name);
names.add(name);
}
// test all names together
testClassNames(names);
if (errors > 0)
throw new RuntimeException(errors + " errors occurred");
}
/**
* Perform annotation processing on the class file name and verify
* the existence of different flavors of class names when the
* input classes are modeled as elements.
*/
static void testClassName(String className) {
testClassNames(Arrays.asList(className));
}
/**
* Perform annotation processing on a list of class file names and verify
* the existence of different flavors of class names when the
* input classes are modeled as elements.
*/
static void testClassNames(List<String> classNames) {
System.out.println("test: " + classNames);
List<String> options = new ArrayList<String>();
options.add("-proc:only");
options.add("-classpath");
options.add(System.getProperty("test.classes"));
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
JavaCompiler.CompilationTask compileTask =
javaCompiler.getTask(null, // Output
null, // File manager
null, // Diagnostics
options,
classNames,
null); // Sources
List<Processor> processors = new ArrayList<Processor>();
processors.add(new ClassNameProber());
compileTask.setProcessors(processors);
Boolean goodResult = compileTask.call();
if (!goodResult) {
error("Errors found during compile.");
}
}
static int errors = 0;
static void error(String msg) {
System.out.println("Error: " + msg);
errors++;
}
}
@Retention(RUNTIME)
@interface Nesting {
NestingKind value();
}
/**
* Probe at the various kinds of names of a type element.
*/
class ClassNameProber extends JavacTestingAbstractProcessor {
public ClassNameProber(){super();}
private boolean classesFound=false;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
for(TypeElement typeElt : typesIn(roundEnv.getRootElements())) {
classesFound = true;
// Verify different names are non-null; an NPE will
// result in failed compile status being reported.
NestingKind nestingKind = typeElt.getNestingKind();
System.out.printf("\tSimple name: ''%s''\tQualified Name: ''%s''\tKind ''%s''\tNesting ''%s''%n",
typeElt.getSimpleName().toString(),
typeElt.getQualifiedName().toString(),
typeElt.getKind().toString(),
nestingKind.toString());
Nesting anno = typeElt.getAnnotation(Nesting.class);
if ((anno == null ? NestingKind.ANONYMOUS : anno.value()) != nestingKind) {
throw new RuntimeException("Mismatch of expected and reported nesting kind.");
}
}
}
if (!classesFound) {
throw new RuntimeException("Error: no classes processed.");
}
return true;
}
}
| 7,263 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestNames.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestNames.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 6380016
* @summary Test that the constraints guaranteed by the Filer and maintained
* @author Joseph D. Darcy
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestNames
* @compile -processor TestNames -proc:only TestNames.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.*;
/**
* Basic tests of semantics of javax.lang.model.element.Name
*/
public class TestNames extends JavacTestingAbstractProcessor {
private int round = 0;
String stringStringName = "java.lang.String";
Name stringName = null;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
round++;
if (!roundEnv.processingOver()) {
boolean failed = false;
switch(round) {
case 1:
TypeElement stringMirror = eltUtils.getTypeElement(stringStringName);
stringName = stringMirror.getQualifiedName();
Name stringPseudoName = Pseudonym.getName(stringName.toString());
if (stringName.equals(stringPseudoName))
failed = true;
if (!stringName.contentEquals(stringStringName))
failed = true;
if (!stringName.contentEquals(stringPseudoName))
failed = true;
try {
// Force another round with a new context
PrintWriter pw = new PrintWriter(filer.createSourceFile("Foo").openWriter());
pw.println("public class Foo {}");
pw.close();
} catch (IOException ioe) {
throw new RuntimeException();
}
break;
case 2:
Name stringStringAsName = eltUtils.getName(stringStringName);
TypeElement stringMirror2 = eltUtils.getTypeElement(stringStringName);
Name stringName2 = stringMirror2.getQualifiedName();
if (stringStringAsName != stringName ||
stringName != stringName2)
failed = true;
break;
default:
throw new RuntimeException("Unexpected round " + round);
}
if (failed)
throw new RuntimeException("Invalid name equality checks.");
}
return true;
}
private static class Pseudonym implements Name {
private String name;
private Pseudonym(String name) {
this.name = name;
}
public static Pseudonym getName(String name) {
return new Pseudonym(name);
}
public boolean contentEquals(CharSequence cs) {
return name.contentEquals(cs);
}
public char charAt(int index) {
return name.charAt(index);
}
public int length() {
return name.length();
}
public CharSequence subSequence(int start, int end) {
return name.subSequence(start, end);
}
public String toString() {
return name;
}
}
}
| 4,487 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestPackageElement.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestPackageElement.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 6449798 6399404
* @summary Test basic workings of PackageElement
* @author Joseph D. Darcy
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestPackageElement
* @compile -processor TestPackageElement -proc:only TestPackageElement.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 PackageElement.
*/
public class TestPackageElement extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
PackageElement unnamedPkg = eltUtils.getPackageElement("");
if (!unnamedPkg.getQualifiedName().contentEquals(""))
throw new RuntimeException("The unnamed package is named!");
// The next line tests an implementation detail upon which
// some diagnostics depend.
if (!unnamedPkg.toString().equals("unnamed package"))
throw new RuntimeException(
"toString on unnamed package: " + unnamedPkg);
if (!unnamedPkg.isUnnamed())
throw new RuntimeException("The isUnnamed method on the unnamed package returned false!");
PackageElement javaLang = eltUtils.getPackageElement("java.lang");
if (javaLang.isUnnamed())
throw new RuntimeException("Package java.lang is unnamed!");
}
return true;
}
}
| 2,886 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestResourceVariable.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestResourceVariable.java | /*
* Copyright (c) 2010, 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 6911256 6964740 6967842 6961571
* @summary Test that the resource variable kind is appropriately set
* @author Joseph D. Darcy
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestResourceVariable
* @compile -processor TestResourceVariable -proc:only TestResourceVariable.java
*/
import java.io.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import java.util.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import static javax.tools.Diagnostic.Kind.*;
/**
* Using the tree API, retrieve element representations of the
* resource of an ARM block and verify their kind tags are set
* appropriately.
*/
public class TestResourceVariable extends JavacTestingAbstractProcessor implements AutoCloseable {
int resourceVariableCount = 0;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
Trees trees = Trees.instance(processingEnv);
for(Element rootElement : roundEnv.getRootElements()) {
TreePath treePath = trees.getPath(rootElement);
(new ResourceVariableScanner(trees)).
scan(trees.getTree(rootElement),
treePath.getCompilationUnit());
}
if (resourceVariableCount != 3)
throw new RuntimeException("Bad resource variable count " +
resourceVariableCount);
}
return true;
}
@Override
public void close() {}
private void test1() {
try(TestResourceVariable trv = this) {}
}
private void test2() {
try(TestResourceVariable trv1 = this; TestResourceVariable trv2 = trv1) {}
}
/**
* Verify that a resource variable modeled as an element behaves
* as expected under 6 and 7 specific visitors.
*/
private static void testResourceVariable(Element element) {
ElementVisitor visitor6 = new ElementKindVisitor6<Void, Void>() {};
try {
visitor6.visit(element);
throw new RuntimeException("Expected UnknownElementException not thrown.");
} catch (UnknownElementException uee) {
; // Expected.
}
ElementKindVisitor7 visitor7 = new ElementKindVisitor7<Object, Void>() {
@Override
public Object visitVariableAsResourceVariable(VariableElement e,
Void p) {
return e; // a non-null value
}
};
if (visitor7.visit(element) == null) {
throw new RuntimeException("Null result of resource variable visitation.");
}
}
class ResourceVariableScanner extends TreeScanner<Void, CompilationUnitTree> {
private Trees trees;
public ResourceVariableScanner(Trees trees) {
super();
this.trees = trees;
}
@Override
public Void visitVariable(VariableTree node, CompilationUnitTree cu) {
Element element = trees.getElement(trees.getPath(cu, node));
System.out.println("Name: " + element.getSimpleName() +
"\tKind: " + element.getKind());
if (element.getKind() == ElementKind.RESOURCE_VARIABLE) {
testResourceVariable(element);
resourceVariableCount++;
}
return super.visitVariable(node, cu);
}
}
}
| 4,696 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestTypeParameter.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestTypeParameter.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 6505047
* @summary javax.lang.model.element.Element.getEnclosingElement() doesn't return null for type parameter
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestTypeParameter
* @compile -processor TestTypeParameter -proc:only TestTypeParameter.java
*/
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import javax.tools.*;
public class TestTypeParameter<T> extends JavacTestingAbstractProcessor {
int round = 0;
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (++round == 1) {
int found = (new Scanner()).scan(roundEnv.getRootElements(), null);
if (found == expect) {
note("generic elements found and verified: " + found);
} else {
error("unexpected number of results: expected " + expect
+ ", found " + found);
}
}
return true;
}
class Scanner extends ElementScanner7<Integer,Void> {
@Override
public Integer visitExecutable(ExecutableElement e, Void p) {
super.visitExecutable(e, p);
found += check(e, e.getTypeParameters());
return found;
}
@Override
public Integer visitType(TypeElement e, Void p) {
super.visitType(e, p);
found += check(e, e.getTypeParameters());
return found;
}
int found;
}
/**
* Check if type parameters, if any, have expected owner.
* Return 1 if typarams not empty and all have expected owner, else return 0.
*/
int check(Element e, List<? extends TypeParameterElement> typarams) {
note("checking " + e, e);
if (typarams.isEmpty()) {
note("no type parameters found", e);
return 0;
}
for (TypeParameterElement tpe: typarams) {
note("checking type parameter " + tpe, tpe);
if (tpe.getEnclosingElement() != e) {
error("unexpected owner; expected: " + e
+ ", found " + tpe.getEnclosingElement(),
tpe);
return 0;
}
if (tpe.getEnclosingElement() != tpe.getGenericElement()) {
error("unexpected generic element; expected: " + tpe.getGenericElement()
+ ", found " + tpe.getEnclosingElement(),
tpe);
return 0;
}
}
note("verified " + e, e);
return 1;
}
void note(String msg) {
messager.printMessage(Diagnostic.Kind.NOTE, msg);
}
void note(String msg, Element e) {
messager.printMessage(Diagnostic.Kind.NOTE, msg, e);
}
void error(String msg, Element e) {
messager.printMessage(Diagnostic.Kind.ERROR, msg, e);
}
void error(String msg) {
messager.printMessage(Diagnostic.Kind.ERROR, msg);
}
// additional generic elements to test
<X> X m(X x) { return x; }
interface Intf<X> { X m() ; }
class Class<X> {
<Y> Class() { }
}
final int expect = 5; // top level class, plus preceding examples
}
| 4,340 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestResourceElement.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestResourceElement.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 6967842
* @summary Element not returned from tree API for ARM resource variables.
* @author A. Sundararajan
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestResourceElement
* @compile -processor TestResourceElement -proc:only TestResourceElement.java
*/
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import java.util.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
public class TestResourceElement extends JavacTestingAbstractProcessor implements AutoCloseable {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
Trees trees = Trees.instance(processingEnv);
for(Element rootElement : roundEnv.getRootElements()) {
TreePath treePath = trees.getPath(rootElement);
VariableScanner varScanner = new VariableScanner(trees);
varScanner.scan(trees.getTree(rootElement),
treePath.getCompilationUnit());
if (varScanner.getTrvElement() == null) {
throw new AssertionError("Element is null for 'trv'");
}
}
}
return true;
}
@Override
public void close() {}
private void test1() {
// The resource variable "trv"'s Element is checked.
// Do not change the name of the variable.
try(TestResourceElement trv = this) {}
}
class VariableScanner extends TreeScanner<Void, CompilationUnitTree> {
private Trees trees;
private Element trvElement;
public VariableScanner(Trees trees) {
super();
this.trees = trees;
}
@Override
public Void visitVariable(VariableTree node, CompilationUnitTree cu) {
// if this is "trv", get it's element.
if (node.getName().contentEquals("trv")) {
trvElement = trees.getElement(trees.getPath(cu, node));
}
return super.visitVariable(node, cu);
}
Element getTrvElement() {
return trvElement;
}
}
}
| 3,268 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
Generator.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement2/Generator.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.
*/
import java.io.*;
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.*;
public class Generator extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement te: ElementFilter.typesIn(roundEnv.getRootElements())) {
System.err.println(te);
generateIfMissing(te.getSuperclass());
generateIfMissing(te.getInterfaces());
}
return true;
}
void generateIfMissing(List<? extends TypeMirror> ts) {
for (TypeMirror t: ts)
generateIfMissing(t);
}
void generateIfMissing(TypeMirror t) {
if (t == null)
return;
if (t.getKind() == TypeKind.ERROR) {
Element e = ((ErrorType) t).asElement();
if (e == null)
return;
if (e.asType().getKind() == TypeKind.ERROR)
createFile((TypeElement) e);
}
}
void createFile(TypeElement e) {
try {
JavaFileObject fo = filer.createSourceFile(e.getSimpleName());
Writer out = fo.openWriter();
try {
switch (e.getKind()) {
case CLASS:
out.write("import java.util.*;\n");
out.write("class " + signature(e) + " {\n");
out.write(" public void run() {\n");
out.write(" Class<?> c = getClass();\n");
out.write(" System.out.println(\"class: \" + c);\n");
out.write(" System.out.println(\"superclass: \" + c.getSuperclass());\n");
out.write(" System.out.println(\"generic superclass: \" +c.getGenericSuperclass());\n");
out.write(" System.out.println(\"interfaces: \" + Arrays.asList(c.getInterfaces()));\n");
out.write(" System.out.println(\"generic interfaces: \" + Arrays.asList(c.getGenericInterfaces()));\n");
out.write(" }\n");
out.write("}\n");
break;
case INTERFACE:
out.write("interface " + signature(e) + " {\n");
out.write(" void run();\n");
out.write("}\n");
break;
}
} finally {
out.close();
}
} catch (IOException ex) {
messager.printMessage(Diagnostic.Kind.ERROR, "problem writing file: " + ex);
}
}
String signature(TypeElement e) {
System.err.println("signature: " + e + " " + e.getTypeParameters());
StringBuilder sb = new StringBuilder();
sb.append(e.getSimpleName());
if (!e.getTypeParameters().isEmpty()) {
sb.append("<");
String sep = "";
for (TypeParameterElement t : e.getTypeParameters()) {
sb.append(sep);
sb.append(t);
sep = ",";
}
sb.append(">");
}
return sb.toString();
}
}
| 4,394 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMissingInterface.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingInterface.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 6639645
* @summary Modeling type implementing missing interfaces
* @library ../../../../lib
* @build JavacTestingAbstractProcessor Generator
* @compile -XprintRounds -processor Generator TestMissingInterface.java
* @run main TestMissingInterface
*/
import java.util.*;
public class TestMissingInterface implements MissingInterface {
public static void main(String... args) {
new TestMissingInterface().run();
}
@Override
public void run() {
Class<?> c = getClass();
System.out.println("class: " + c);
System.out.println("superclass: " + c.getSuperclass());
System.out.println("generic superclass: " +c.getGenericSuperclass());
System.out.println("interfaces: " + Arrays.asList(c.getInterfaces()));
System.out.println("generic interfaces: " + Arrays.asList(c.getGenericInterfaces()));
}
}
| 1,946 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMissingGenericInterface1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingGenericInterface1.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 6639645
* @summary Modeling type implementing missing interfaces
* @library ../../../../lib
* @clean MissingGenericInterface1
* @build JavacTestingAbstractProcessor Generator
* @compile -XprintRounds -processor Generator TestMissingGenericInterface1.java
* @run main TestMissingGenericInterface1
*/
import java.util.*;
public class TestMissingGenericInterface1 implements MissingGenericInterface1<String> {
public static void main(String... args) {
new TestMissingGenericInterface1().run();
}
@Override
public void run() {
Class<?> c = getClass();
System.out.println("class: " + c);
System.out.println("superclass: " + c.getSuperclass());
System.out.println("generic superclass: " +c.getGenericSuperclass());
System.out.println("interfaces: " + Arrays.asList(c.getInterfaces()));
System.out.println("generic interfaces: " + Arrays.asList(c.getGenericInterfaces()));
}
}
| 2,029 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMissingClass.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingClass.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 6639645
* @summary Modeling type implementing missing interfaces
* @library ../../../../lib
* @build JavacTestingAbstractProcessor Generator
* @compile -XprintRounds -processor Generator TestMissingClass.java
* @run main TestMissingClass
*/
public class TestMissingClass extends MissingClass {
public static void main(String... args) {
new TestMissingClass().run();
}
}
| 1,465 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMissingGenericInterface2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingGenericInterface2.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 6639645
* @summary Modeling type implementing missing interfaces
* @library ../../../../lib
* @clean MissingGenericInterface2
* @build JavacTestingAbstractProcessor Generator
* @compile -XprintRounds -processor Generator TestMissingGenericInterface2.java
* @run main TestMissingGenericInterface2
*/
import java.util.*;
public class TestMissingGenericInterface2 implements MissingGenericInterface2<Integer,String> {
public static void main(String... args) {
new TestMissingGenericInterface2().run();
}
@Override
public void run() {
Class<?> c = getClass();
System.out.println("class: " + c);
System.out.println("superclass: " + c.getSuperclass());
System.out.println("generic superclass: " +c.getGenericSuperclass());
System.out.println("interfaces: " + Arrays.asList(c.getInterfaces()));
System.out.println("generic interfaces: " + Arrays.asList(c.getGenericInterfaces()));
}
}
| 2,037 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMissingGenericClass2.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingGenericClass2.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 6639645
* @summary Modeling type implementing missing interfaces
* @library ../../../../lib
* @clean MissingGenericClass2
* @build JavacTestingAbstractProcessor Generator
* @compile -XprintRounds -processor Generator TestMissingGenericClass2.java
* @run main TestMissingGenericClass2
*/
public class TestMissingGenericClass2 extends MissingGenericClass2<String,Integer> {
public static void main(String... args) {
new TestMissingGenericClass2().run();
}
}
| 1,552 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMissingGenericClass1.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingGenericClass1.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 6639645
* @summary Modeling type implementing missing interfaces
* @library ../../../../lib
* @clean MissingGenericClass1
* @build JavacTestingAbstractProcessor Generator
* @compile -XprintRounds -processor Generator TestMissingGenericClass1.java
* @run main TestMissingGenericClass1
*/
public class TestMissingGenericClass1 extends MissingGenericClass1<String> {
public static void main(String... args) {
new TestMissingGenericClass1().run();
}
}
| 1,544 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
TestMissingElement.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.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 6639645 7026414
* @summary Modeling type implementing missing interfaces
* @library ../../../../lib
* @build JavacTestingAbstractProcessor TestMissingElement
* @compile -proc:only -XprintRounds -processor TestMissingElement InvalidSource.java
*/
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
import static javax.tools.Diagnostic.Kind.*;
public class TestMissingElement extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement te: ElementFilter.typesIn(roundEnv.getRootElements())) {
if (isSimpleName(te, "InvalidSource")) {
for (Element c: te.getEnclosedElements()) {
for (AnnotationMirror am: c.getAnnotationMirrors()) {
Element ate = am.getAnnotationType().asElement();
if (isSimpleName(ate, "ExpectInterfaces")) {
checkInterfaces((TypeElement) c, getValue(am));
} else if (isSimpleName(ate, "ExpectSupertype")) {
checkSupertype((TypeElement) c, getValue(am));
}
}
}
}
}
return true;
}
private boolean isSimpleName(Element e, String name) {
return e.getSimpleName().contentEquals(name);
}
private String getValue(AnnotationMirror am) {
Map<? extends ExecutableElement, ? extends AnnotationValue> map = am.getElementValues();
if (map.size() != 1) throw new IllegalArgumentException();
AnnotationValue v = map.values().iterator().next();
return (String) v.getValue();
}
private void checkInterfaces(TypeElement te, String expect) {
System.err.println("check interfaces: " + te + " -- " + expect);
String found = asString(te.getInterfaces(), ", ");
checkEqual("interfaces", te, found, expect);
}
private void checkSupertype(TypeElement te, String expect) {
System.err.println("check supertype: " + te + " -- " + expect);
String found = asString(te.getSuperclass());
checkEqual("supertype", te, found, expect);
}
private void checkEqual(String label, TypeElement te, String found, String expect) {
if (found.equals(expect)) {
// messager.printMessage(NOTE, "expected " + label + " found: " + expect, te);
} else {
System.err.println("unexpected " + label + ": " + te + "\n"
+ " found: " + found + "\n"
+ "expect: " + expect);
messager.printMessage(ERROR, "unexpected " + label + " found: " + found + "; expected: " + expect, te);
}
}
private String asString(List<? extends TypeMirror> ts, String sep) {
StringBuilder sb = new StringBuilder();
for (TypeMirror t: ts) {
if (sb.length() != 0) sb.append(sep);
sb.append(asString(t));
}
return sb.toString();
}
private String asString(TypeMirror t) {
if (t == null)
return "[typ:null]";
return t.accept(new SimpleTypeVisitor7<String, Void>() {
@Override
public String defaultAction(TypeMirror t, Void ignore) {
return "[typ:" + t.toString() + "]";
}
@Override
public String visitDeclared(DeclaredType t, Void ignore) {
checkEqual(t.asElement(), types.asElement(t));
String s = asString(t.asElement());
List<? extends TypeMirror> args = t.getTypeArguments();
if (!args.isEmpty())
s += "<" + asString(args, ",") + ">";
return s;
}
@Override
public String visitTypeVariable(TypeVariable t, Void ignore) {
return "tvar " + t;
}
@Override
public String visitError(ErrorType t, Void ignore) {
return "!:" + visitDeclared(t, ignore);
}
}, null);
}
private String asString(Element e) {
if (e == null)
return "[elt:null]";
return e.accept(new SimpleElementVisitor7<String, Void>() {
@Override
public String defaultAction(Element e, Void ignore) {
return "[elt:" + e.getKind() + " " + e.toString() + "]";
}
@Override
public String visitPackage(PackageElement e, Void ignore) {
return "pkg " + e.getQualifiedName();
}
@Override
public String visitType(TypeElement e, Void ignore) {
StringBuilder sb = new StringBuilder();
if (e.getEnclosedElements().isEmpty())
sb.append("empty ");
ElementKind ek = e.getKind();
switch (ek) {
case CLASS:
sb.append("clss");
break;
case INTERFACE:
sb.append("intf");
break;
default:
sb.append(ek);
break;
}
sb.append(" ");
Element encl = e.getEnclosingElement();
if (!isUnnamedPackage(encl) && encl.asType().getKind() != TypeKind.NONE) {
sb.append("(");
sb.append(asString(encl));
sb.append(")");
sb.append(".");
}
sb.append(e.getSimpleName());
if (e.asType().getKind() == TypeKind.ERROR) sb.append("!");
return sb.toString();
}
}, null);
}
boolean isUnnamedPackage(Element e) {
return (e != null && e.getKind() == ElementKind.PACKAGE
&& ((PackageElement) e).isUnnamed());
}
void checkEqual(Element e1, Element e2) {
if (e1 != e2) {
throw new AssertionError("elements not equal as expected: "
+ e1 + ", " + e2);
}
}
}
| 7,366 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
InvalidSource.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/element/TestMissingElement/InvalidSource.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.
*/
import java.util.*;
@interface ExpectInterfaces {
String value();
}
@interface ExpectSupertype {
String value();
}
interface OK {
void m();
}
class InvalidSource {
/*
* The following annotations contain a simple description of the expected
* representation of the superclass and superinterfaces of the corresponding
* elements.
* The strings contain a comma-separated list of descriptions.
* Descriptions are composed as follows:
* A leading "!:" indicates the type mirror has kind ERROR.
* "empty" means that the corresponding element has no enclosed elements.
* "clss", "intf" and "tvar" indicate the name refers to a class, interface
* or type variable. Each is followed by the declared name of the element.
* "pkg" indicates the name of a package element.
* An enclosing element is shown in parentheses.
* A trailing "!" indicates that the element's type has kind ERROR.
*/
@ExpectSupertype("!:empty clss A!")
class TestClassMissingClassA extends A { }
@ExpectSupertype("!:empty clss (pkg A).B!")
class TestClassMissingClassAB extends A.B { }
@ExpectSupertype("!:empty clss (pkg java.util).A!")
class TestClassMissingClass_juA extends java.util.A { }
@ExpectSupertype("!:empty clss A!<tvar T>")
class TestClassTMissingClassAT<T> extends A<T> { }
@ExpectInterfaces("!:empty intf A!")
class TestClassMissingIntfA implements A { }
@ExpectInterfaces("!:empty intf (pkg A).B!")
class TestClassMissingIntfAB implements A.B { }
@ExpectInterfaces("!:empty intf A!, intf OK")
abstract class TestClassMissingIntfAOK implements A, OK { }
@ExpectInterfaces("intf OK, !:empty intf A!")
abstract class TestClassOKMissingIntfA implements OK, A { }
@ExpectInterfaces("!:empty intf A!, !:empty intf B!")
class TestClassMissingIntfA_B implements A, B { }
@ExpectInterfaces("!:empty intf A!")
interface TestIntfMissingIntfA extends A { }
@ExpectInterfaces("!:empty intf A!, intf OK")
interface TestIntfMissingIntfAOK extends A, OK { }
@ExpectInterfaces("intf OK, !:empty intf A!")
interface TestIntfOKMissingIntfA extends OK, A { }
@ExpectInterfaces("!:empty intf A!, !:empty intf B!")
interface TestIntfMissingIntfAB extends A, B { }
@ExpectInterfaces("!:empty intf A!<tvar T>")
class TestClassTMissingIntfAT<T> implements A<T> { }
@ExpectInterfaces("!:empty intf A!<tvar T>, !:empty intf B!")
class TestClassTMissingIntfAT_B<T> implements A<T>, B { }
@ExpectInterfaces("!:empty intf A!<tvar T>")
interface TestIntfTMissingIntfAT<T> extends A<T> { }
@ExpectInterfaces("!:empty intf A!<tvar T>, !:empty intf B!")
interface TestIntfTMissingIntfAT_B<T> extends A<T>, B { }
@ExpectInterfaces("intf (pkg java.util).List<!:empty clss X!>")
abstract class TestClassListMissingX implements List<X> { }
}
| 3,982 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
T6341534.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/6341534/T6341534.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 6341534
* @summary PackageElement.getEnclosedElements results in NullPointerException from parse(JavaCompiler.java:429)
* @author Steve Sides
* @author Peter von der Ahe
* @library ../../../lib
* @build JavacTestingAbstractProcessor
* @compile T6341534.java
* @compile -proc:only -processor T6341534 dir/package-info.java
* @compile -processor T6341534 dir/package-info.java
*/
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
import java.util.*;
import java.util.Set;
import static javax.tools.Diagnostic.Kind.*;
public class T6341534 extends JavacTestingAbstractProcessor {
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
messager.printMessage(NOTE,
String.valueOf(eltUtils.getPackageElement("no.such.package")));
PackageElement dir = eltUtils.getPackageElement("dir");
messager.printMessage(NOTE, dir.getQualifiedName().toString());
for (Element e : dir.getEnclosedElements())
messager.printMessage(NOTE, e.toString());
return true;
}
}
| 2,270 | Java | .java | openjdk-mirror/jdk7u-langtools | 9 | 3 | 0 | 2012-05-07T19:45:34Z | 2012-05-08T17:47:06Z |
package-info.java | /FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/processing/model/6341534/dir/package-info.java | /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package dir;
| 1,065 | 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/6341534/dir/Foo.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.
*/
package dir;
public class Foo {}
| 1,085 | 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.