1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/processing/model/inheritedByType/EnsureOrder.java Thu Jul 25 11:02:27 2013 +0200 1.3 @@ -0,0 +1,106 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * @test 1.29 + * @summary test that order is respected when inheriting both legacy container and single anno 1.30 + * @bug 8007961 1.31 + * @library /tools/javac/lib 1.32 + * @build JavacTestingAbstractProcessor EnsureOrder 1.33 + * @compile -processor EnsureOrder -proc:only EnsureOrder.java 1.34 + */ 1.35 + 1.36 +import java.util.Set; 1.37 +import java.lang.annotation.*; 1.38 +import javax.annotation.processing.*; 1.39 +import javax.lang.model.SourceVersion; 1.40 +import static javax.lang.model.SourceVersion.*; 1.41 +import javax.lang.model.element.*; 1.42 +import javax.lang.model.util.*; 1.43 +import static javax.lang.model.util.ElementFilter.*; 1.44 +import static javax.tools.Diagnostic.Kind.*; 1.45 +import static javax.tools.StandardLocation.*; 1.46 +import com.sun.tools.javac.util.Assert; 1.47 + 1.48 +@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE}) 1.49 +@Inherited 1.50 +@Retention(RetentionPolicy.RUNTIME) 1.51 +@Repeatable(Foos.class) 1.52 +@interface Foo { 1.53 + int value(); 1.54 +} 1.55 + 1.56 +@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE}) 1.57 +@Inherited 1.58 +@Retention(RetentionPolicy.RUNTIME) 1.59 +@interface Foos { 1.60 + Foo[] value(); 1.61 +} 1.62 + 1.63 +@Foos({@Foo(0), @Foo(1)}) @Foo(2) 1.64 +class Base {} 1.65 + 1.66 +class Sub extends Base {} 1.67 + 1.68 +public class EnsureOrder<@Foos({@Foo(0), @Foo(1)}) @Foo(2)T> extends JavacTestingAbstractProcessor { 1.69 + public boolean process(Set<? extends TypeElement> annotations, 1.70 + RoundEnvironment roundEnv) { 1.71 + if (!roundEnv.processingOver()) { 1.72 + int hasRun = 0; 1.73 + for (Element element : roundEnv.getRootElements()) { 1.74 + Name elemName = element.getSimpleName(); 1.75 + if (elemName.contentEquals("Base")) { 1.76 + hasRun++; 1.77 + Foo[] foos = element.getAnnotationsByType(Foo.class); 1.78 + Assert.check(foos.length == 3); 1.79 + Assert.check(foos[0].value() == 0); 1.80 + Assert.check(foos[1].value() == 1); 1.81 + Assert.check(foos[2].value() == 2); 1.82 + } 1.83 + if (elemName.contentEquals("Sub")) { 1.84 + hasRun++; 1.85 + Foo[] foos = element.getAnnotationsByType(Foo.class); 1.86 + Assert.check(foos.length == 3); 1.87 + Assert.check(foos[0].value() == 0); 1.88 + Assert.check(foos[1].value() == 1); 1.89 + Assert.check(foos[2].value() == 2); 1.90 + } 1.91 + if (elemName.contentEquals("EnsureOrder")) { 1.92 + for (TypeParameterElement t : ((TypeElement)element).getTypeParameters()) { 1.93 + if (t.getSimpleName().contentEquals("T")) { 1.94 + hasRun++; 1.95 + Foo[] foos = t.getAnnotationsByType(Foo.class); 1.96 + Assert.check(foos.length == 3); 1.97 + Assert.check(foos[0].value() == 0); 1.98 + Assert.check(foos[1].value() == 1); 1.99 + Assert.check(foos[2].value() == 2); 1.100 + } 1.101 + } 1.102 + } 1.103 + } 1.104 + if (hasRun != 3) 1.105 + throw new RuntimeException("Couldn't find elements"); 1.106 + } 1.107 + return true; 1.108 + } 1.109 +}