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

Print this page
rev 224 : 6498938: Faulty comparison of TypeMirror objects in getElementsAnnotatedWith implementation
Reviewed-by: jjg

*** 1,7 **** /* ! * Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright 2006-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 21,48 **** * have any questions. */ /* * @test ! * @bug 6397298 6400986 6425592 6449798 6453386 6508401 * @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 TestElementsAnnotatedWith.java * @compile -processor TestElementsAnnotatedWith -proc:only C2.java */ import java.lang.annotation.Annotation; import java.util.Collections; 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.lang.model.util.ElementFilter.*; --- 21,54 ---- * have any questions. */ /* * @test ! * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 * @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 */ 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.*;
*** 118,127 **** --- 124,136 ---- 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);
*** 159,168 **** --- 168,208 ---- 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"))); + int datum = io.read(); + while(datum != -1) { + os.write(datum); + datum = io.read(); + } + os.close(); + } catch (IOException io) { + throw new RuntimeException(io); + } + + + } + @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latest(); } }