TestNonInherited.java revision 3294:9adfb22ff08f
1/* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 8026855 27 * @summary Javac should only look on supertypes for repeatable annotations if 28 * both container and containee are inherited. 29 * @library /tools/javac/lib 30 * @modules jdk.compiler/com.sun.tools.javac.util 31 * @build JavacTestingAbstractProcessor TestNonInherited 32 * @compile -XDaccessInternalAPI -processor TestNonInherited -proc:only TestNonInherited.java 33 */ 34 35import com.sun.tools.javac.util.Assert; 36 37import java.lang.annotation.*; 38import java.util.Arrays; 39import java.util.Set; 40import javax.annotation.processing.*; 41import javax.lang.model.element.*; 42 43import static javax.lang.model.util.ElementFilter.*; 44 45@TestNonInherited.Foo(1) 46public class TestNonInherited extends JavacTestingAbstractProcessor { 47 public boolean process(Set<? extends TypeElement> annotations, 48 RoundEnvironment roundEnv) { 49 if (!roundEnv.processingOver()) { 50 boolean hasRun = false; 51 for (Element element : roundEnv.getRootElements()) 52 for (TypeElement te : typesIn(element.getEnclosedElements())) 53 if (te.getQualifiedName().contentEquals("TestNonInherited.T2")) { 54 hasRun = true; 55 Foo[] foos = te.getAnnotationsByType(Foo.class); 56 System.out.println(" " + te); 57 System.out.println(" " + Arrays.asList(foos)); 58 Assert.check(foos.length == 0, "Should not find any instance of @Foo"); 59 } 60 if (!hasRun) 61 throw new RuntimeException("The annotation processor could not find the declaration of T2, test broken!"); 62 } 63 return true; 64 } 65 66 public static class T2 extends TestNonInherited { 67 } 68 69 @Repeatable(FooContainer.class) 70 public static @interface Foo { 71 int value(); 72 } 73 74 @Inherited 75 public static @interface FooContainer { 76 Foo[] value(); 77 } 78} 79