1/* 2 * Copyright (c) 2006, 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 6350057 7025809 27 * @summary Test that parameters on implicit enum methods have the right kind 28 * @author Joseph D. Darcy 29 * @library /tools/javac/lib 30 * @modules java.compiler 31 * jdk.compiler 32 * @build JavacTestingAbstractProcessor T6350057 33 * @compile -processor T6350057 -proc:only TestEnum.java 34 */ 35 36import java.util.Set; 37import javax.annotation.processing.AbstractProcessor; 38import javax.annotation.processing.RoundEnvironment; 39import javax.annotation.processing.SupportedAnnotationTypes; 40import javax.lang.model.element.*; 41import javax.lang.model.util.*; 42import static javax.tools.Diagnostic.Kind.*; 43 44public class T6350057 extends JavacTestingAbstractProcessor { 45 static class LocalVarAllergy extends ElementKindVisitor<Boolean, Void> { 46 @Override 47 public Boolean visitTypeAsEnum(TypeElement e, Void v) { 48 System.out.println("visitTypeAsEnum: " + e.getSimpleName().toString()); 49 for(Element el: e.getEnclosedElements() ) 50 this.visit(el); 51 return true; 52 } 53 54 @Override 55 public Boolean visitVariableAsLocalVariable(VariableElement e, Void v){ 56 throw new IllegalStateException("Should not see any local variables!"); 57 } 58 59 @Override 60 public Boolean visitVariableAsParameter(VariableElement e, Void v){ 61 String senclm=e.getEnclosingElement().getEnclosingElement().getSimpleName().toString(); 62 String sEncl = senclm+"."+e.getEnclosingElement().getSimpleName().toString(); 63 String stype = e.asType().toString(); 64 String name = e.getSimpleName().toString(); 65 System.out.println("visitVariableAsParameter: " +sEncl+"." + stype + " " + name); 66 return true; 67 } 68 69 @Override 70 public Boolean visitExecutableAsMethod(ExecutableElement e, Void v){ 71 String name=e.getEnclosingElement().getSimpleName().toString(); 72 name = name + "."+e.getSimpleName().toString(); 73 System.out.println("visitExecutableAsMethod: " + name); 74 for (VariableElement ve: e.getParameters()) 75 this.visit(ve); 76 return true; 77 } 78 } 79 80 public boolean process(Set<? extends TypeElement> annotations, 81 RoundEnvironment roundEnvironment) { 82 if (!roundEnvironment.processingOver()) 83 for(Element element : roundEnvironment.getRootElements()) 84 element.accept(new LocalVarAllergy(), null); 85 return true; 86 } 87} 88