test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java

Print this page

        

@@ -21,22 +21,22 @@
  * have any questions.
  */
 
 /*
  * @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
  * @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 -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;
 import java.io.*;
 import java.util.Collections;

@@ -87,11 +87,11 @@
                                                   firstType);
             else {
                 // 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.
                     getElementsAnnotatedWith(elementUtils.
                                              getTypeElement(annotatedElementInfo.

@@ -124,13 +124,10 @@
 
             if (failed) {
                 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.
             resultsMeta = roundEnvironment.getElementsAnnotatedWith(annotatedElementInfoElement);
             resultsBase = roundEnvironment.getElementsAnnotatedWith(AnnotatedElementInfo.class);

@@ -161,52 +158,18 @@
             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.
+            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
     public SourceVersion getSupportedSourceVersion() {
         return SourceVersion.latest();
     }
 }