duke@1: /* duke@1: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: /* duke@1: * @test duke@1: * @bug 6423972 duke@1: * @summary Tests TypeParameter.getBounds. duke@1: * @author Scott Seligman duke@1: * @build TypeParamBounds duke@1: * @compile -processor TypeParamBounds -proc:only TypeParamBounds.java duke@1: */ duke@1: duke@1: import java.util.HashMap; duke@1: import java.util.List; duke@1: import java.util.Map; duke@1: import java.util.Set; duke@1: import javax.annotation.processing.*; duke@1: import javax.lang.model.SourceVersion; duke@1: import javax.lang.model.element.*; duke@1: import javax.lang.model.type.*; duke@1: import javax.lang.model.util.*; duke@1: duke@1: @SupportedAnnotationTypes("*") duke@1: public class TypeParamBounds extends AbstractProcessor { duke@1: duke@1: Elements elements; duke@1: Types types; duke@1: duke@1: public void init(ProcessingEnvironment penv) { duke@1: super.init(penv); duke@1: elements = penv.getElementUtils(); duke@1: types = penv.getTypeUtils(); duke@1: } duke@1: duke@1: public boolean process(Set annoTypes, duke@1: RoundEnvironment round) { duke@1: if (!round.processingOver()) duke@1: doit(annoTypes, round); duke@1: return true; duke@1: } duke@1: darcy@495: @Override darcy@495: public SourceVersion getSupportedSourceVersion() { darcy@495: return SourceVersion.latest(); darcy@495: } darcy@495: duke@1: private void doit(Set annoTypes, duke@1: RoundEnvironment round) { duke@1: TypeElement gen = elements.getTypeElement("TypeParamBounds.Gen"); duke@1: duke@1: // For each type parameter of Gen, compare its bounds with the duke@1: // bounds that are expected. duke@1: // duke@1: for (TypeParameterElement tparam : gen.getTypeParameters()) { duke@1: System.out.println(tparam); duke@1: List bounds = tparam.getBounds(); duke@1: String[] expected = Gen.boundNames.get(tparam + ""); duke@1: duke@1: if (bounds.size() != expected.length) duke@1: throw new AssertionError(); duke@1: int i = 0; duke@1: for (TypeMirror bound : bounds) { duke@1: Name got = types.asElement(bound).getSimpleName(); duke@1: String shoulda = expected[i++]; duke@1: System.out.println(" " + got); duke@1: if (!got.contentEquals(shoulda)) duke@1: throw new AssertionError(shoulda); duke@1: } duke@1: } duke@1: } duke@1: duke@1: duke@1: // Fodder for the processor duke@1: duke@1: static class Gen { duke@1: duke@1: // The names of the bounds of each type parameter of Gen. duke@1: static Map boundNames = duke@1: new HashMap(); duke@1: duke@1: static { duke@1: boundNames.put("T", new String[] {"Object"}); duke@1: boundNames.put("U", new String[] {"Object"}); duke@1: boundNames.put("V", new String[] {"Number"}); duke@1: boundNames.put("W", new String[] {"U"}); duke@1: boundNames.put("X", new String[] {"Runnable"}); duke@1: boundNames.put("Y", new String[] {"CharSequence", "Runnable"}); duke@1: boundNames.put("Z", new String[] {"Object", "Runnable"}); duke@1: } duke@1: } duke@1: }