JDK-6911854 : Update TestElementsAnnotatedWith.java to use @compile/proc
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: javax.annotation.processing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-12-18
  • Updated: 2011-07-15
  • Resolved: 2011-07-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b79Fixed
Related Reports
Relates :  
Relates :  
Description
In the course of developing regression tests for 6498938 "Faulty comparison of TypeMirror objects in RoundEnvironment.getElementsAnnotatedWith implementation," it became clear that being able to operate on class file for annotation processing tests would be helpful.  Now that jtreg has that capability via @compile/process (6799634), the test in question, TestElementsAnnotatedWith.java, should be updated to use @compile/proc.

Comments
SUGGESTED FIX # HG changeset patch # User darcy # Date 1261163723 28800 # Node ID 96c71cbc544b758578fb3eaa7838413b2fd354b9 # Parent 0666a8f8766181242990c8a0d14b736cfa860666 6911854: Update TestElementsAnnotatedWith.java to use @compile/proc Reviewed-by: jjg --- a/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java Tue Dec 15 13:26:06 2009 -0800 +++ b/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java Fri Dec 18 11:15:23 2009 -0800 @@ -23,7 +23,7 @@ /* * @test - * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 + * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 * @summary Tests that getElementsAnnotatedWith works properly. * @author Joseph D. Darcy * @compile TestElementsAnnotatedWith.java @@ -33,8 +33,8 @@ * @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java * @compile -processor TestElementsAnnotatedWith -proc:only C2.java * @compile -processor TestElementsAnnotatedWith -proc:only Foo.java - * @compile -XD-d=. Foo.java - * @compile -processor TestElementsAnnotatedWith -proc:only TestElementsAnnotatedWith.java + * @compile Foo.java + * @compile/process -processor TestElementsAnnotatedWith -proc:only Foo */ import java.lang.annotation.Annotation; @@ -89,7 +89,7 @@ public class TestElementsAnnotatedWith e // Verify that the annotation information is as // expected. - Set<String> expectedNames = new HashSet<String>(Arrays.asList(annotatedElementInfo.names())); + Set<String> expectedNames = new HashSet<>(Arrays.asList(annotatedElementInfo.names())); resultsMeta = roundEnvironment. @@ -126,9 +126,6 @@ public class TestElementsAnnotatedWith e System.err.println("AnnotatedElementInfo: " + annotatedElementInfo); throw new RuntimeException(); } - - if("TestElementsAnnotatedWith".equals(firstType.getSimpleName().toString())) - writeClassFile(); // Start another round to test class file input } else { // If processing is over without an error, the specified // elements should be empty so an empty set should be returned. @@ -163,46 +160,12 @@ public class TestElementsAnnotatedWith e } catch(IllegalArgumentException iae) {} try { - Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(processingEnv. - getElementUtils(). - getTypeElement("java.lang.Object") ); + Set<? extends Element> elements = + roundEnvironment.getElementsAnnotatedWith(processingEnv. + getElementUtils(). + getTypeElement("java.lang.Object") ); throw new RuntimeException("Illegal argument exception not thrown"); } catch(IllegalArgumentException iae) {} - } - - /* - * Hack alert! The class file read below is generated by the - * "@compile -XD-d=. Foo.java" directive above. This sneakily - * overrides the output location to the current directory where a - * subsequent @compile can read the file. This could be improved - * if either a new directive like @process accepted class file - * arguments (the javac command accepts such arguments but - * @compile does not) or the test.src and test.classes properties - * were set to be read with @compile jobs. - */ - private void writeClassFile() { - try { - Filer filer = processingEnv.getFiler(); - JavaFileObject jfo = filer.createClassFile("Foo"); - OutputStream os = jfo.openOutputStream(); - // Copy the bytes over - System.out.println((new File(".")).getAbsolutePath()); - InputStream io = new BufferedInputStream(new FileInputStream(new File(".", "Foo.class"))); - try { - int datum = io.read(); - while(datum != -1) { - os.write(datum); - datum = io.read(); - } - } finally { - io.close(); - } - os.close(); - } catch (IOException ioe) { - throw new RuntimeException(ioe); - } - - } @Override
20-12-2009

PUBLIC COMMENTS See http://hg.openjdk.java.net/jdk7/tl/langtools/rev/96c71cbc544b
20-12-2009

EVALUATION A fine idea.
18-12-2009