Tue, 01 Feb 2011 10:11:05 -0800
6961571: Update visitors to support ARM's ElementKind.RESOURCE_VARIABLE
Reviewed-by: jjg
darcy@515 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
darcy@515 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
darcy@515 | 4 | * |
darcy@515 | 5 | * This code is free software; you can redistribute it and/or modify it |
darcy@515 | 6 | * under the terms of the GNU General Public License version 2 only, as |
darcy@515 | 7 | * published by the Free Software Foundation. |
darcy@515 | 8 | * |
darcy@515 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
darcy@515 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
darcy@515 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
darcy@515 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
darcy@515 | 13 | * accompanied this code). |
darcy@515 | 14 | * |
darcy@515 | 15 | * You should have received a copy of the GNU General Public License version |
darcy@515 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
darcy@515 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
darcy@515 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
darcy@515 | 22 | */ |
darcy@515 | 23 | |
darcy@515 | 24 | import java.io.*; |
darcy@515 | 25 | import javax.annotation.processing.*; |
darcy@515 | 26 | import javax.lang.model.*; |
darcy@515 | 27 | import javax.lang.model.element.*; |
darcy@515 | 28 | import javax.lang.model.type.*; |
darcy@515 | 29 | import javax.lang.model.util.*; |
darcy@515 | 30 | import java.util.*; |
darcy@515 | 31 | import com.sun.source.tree.*; |
darcy@515 | 32 | import com.sun.source.util.*; |
darcy@515 | 33 | import static javax.tools.Diagnostic.Kind.*; |
darcy@515 | 34 | |
darcy@515 | 35 | /** |
darcy@515 | 36 | * Using the tree API, retrieve element representations of anonymous |
darcy@515 | 37 | * classes and verify their names are as specified. |
darcy@515 | 38 | */ |
darcy@699 | 39 | public class TestAnonSourceNames extends JavacTestingAbstractProcessor { |
darcy@515 | 40 | |
darcy@515 | 41 | public boolean process(Set<? extends TypeElement> annotations, |
darcy@515 | 42 | RoundEnvironment roundEnv) { |
darcy@515 | 43 | if (!roundEnv.processingOver()) { |
darcy@515 | 44 | Trees trees = Trees.instance(processingEnv); |
darcy@515 | 45 | |
darcy@515 | 46 | for(Element rootElement : roundEnv.getRootElements()) { |
darcy@515 | 47 | TreePath treePath = trees.getPath(rootElement); |
darcy@515 | 48 | |
darcy@515 | 49 | (new ClassTreeScanner(trees)). |
darcy@515 | 50 | scan(trees.getTree(rootElement), |
darcy@515 | 51 | treePath.getCompilationUnit()); |
darcy@515 | 52 | } |
darcy@515 | 53 | } |
darcy@515 | 54 | return true; |
darcy@515 | 55 | } |
darcy@515 | 56 | |
darcy@515 | 57 | class ClassTreeScanner extends TreeScanner<Void, CompilationUnitTree> { |
darcy@515 | 58 | private Trees trees; |
darcy@515 | 59 | |
darcy@515 | 60 | public ClassTreeScanner(Trees trees) { |
darcy@515 | 61 | super(); |
darcy@515 | 62 | this.trees = trees; |
darcy@515 | 63 | } |
darcy@515 | 64 | @Override |
darcy@515 | 65 | public Void visitClass(ClassTree node, CompilationUnitTree cu) { |
darcy@515 | 66 | Element element = trees.getElement(trees.getPath(cu, node)); |
darcy@515 | 67 | if (element == null) { |
darcy@515 | 68 | processingEnv.getMessager().printMessage(ERROR, |
jjg@672 | 69 | "No element retrieved for node named ''" + |
darcy@515 | 70 | node.getSimpleName() + "''."); |
darcy@515 | 71 | } else { |
darcy@515 | 72 | |
darcy@515 | 73 | System.out.println("\nVisiting class ``" + element.getSimpleName() + |
darcy@515 | 74 | "'' of kind " + element.getKind()); |
darcy@515 | 75 | if (element instanceof TypeElement) { |
darcy@515 | 76 | TypeElement typeElement = (TypeElement) element; |
darcy@515 | 77 | String s = typeElement.getQualifiedName().toString(); |
darcy@515 | 78 | System.out.println("\tqualified name:" + s); |
darcy@515 | 79 | } else { |
darcy@515 | 80 | throw new RuntimeException("TypeElement not gotten from ClassTree."); |
darcy@515 | 81 | } |
darcy@515 | 82 | } |
darcy@515 | 83 | return super.visitClass(node, cu); |
darcy@515 | 84 | } |
darcy@515 | 85 | } |
darcy@515 | 86 | } |