test/tools/javac/T6855236.java

Mon, 15 Feb 2010 20:06:11 -0800

author
darcy
date
Mon, 15 Feb 2010 20:06:11 -0800
changeset 495
fe17a9dbef03
parent 458
d4e0ae9b4ecb
child 554
9d9f26857129
permissions
-rw-r--r--

6926699: Annotation processing regression tests should typically return SourceVersion.latest
Reviewed-by: jjg

jjg@458 1 /*
jjg@458 2 * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
jjg@458 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@458 4 *
jjg@458 5 * This code is free software; you can redistribute it and/or modify it
jjg@458 6 * under the terms of the GNU General Public License version 2 only, as
jjg@458 7 * published by the Free Software Foundation.
jjg@458 8 *
jjg@458 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@458 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@458 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@458 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@458 13 * accompanied this code).
jjg@458 14 *
jjg@458 15 * You should have received a copy of the GNU General Public License version
jjg@458 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@458 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@458 18 *
jjg@458 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@458 20 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@458 21 * have any questions.
jjg@458 22 */
jjg@458 23
jjg@458 24 /*
jjg@458 25 * @test
jjg@458 26 * @bug 6855236
jjg@458 27 * @summary Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg@458 28 * @compile T6855236.java
jjg@458 29 * @compile -processor T6855236 -proc:only T6855236.java
jjg@458 30 */
jjg@458 31
jjg@458 32 import java.util.*;
jjg@458 33
jjg@458 34 import javax.annotation.processing.*;
jjg@458 35 import javax.lang.model.*;
jjg@458 36 import javax.lang.model.element.*;
jjg@458 37
jjg@458 38 import com.sun.source.tree.*;
jjg@458 39 import com.sun.source.util.*;
jjg@458 40
jjg@458 41 @SupportedAnnotationTypes("*")
jjg@458 42 public class T6855236 extends AbstractProcessor {
jjg@458 43
jjg@458 44 private Trees trees;
jjg@458 45
jjg@458 46 @Override
jjg@458 47 public void init(ProcessingEnvironment pe) {
jjg@458 48 super.init(pe);
jjg@458 49 trees = Trees.instance(pe);
jjg@458 50 }
jjg@458 51
jjg@458 52 @Override
jjg@458 53 public boolean process(Set<? extends TypeElement> arg0, RoundEnvironment roundEnvironment) {
jjg@458 54 // Scanner class to scan through various component elements
jjg@458 55 CodeVisitor visitor = new CodeVisitor();
jjg@458 56
jjg@458 57 for (Element e : roundEnvironment.getRootElements()) {
jjg@458 58 TreePath tp = trees.getPath(e);
jjg@458 59 visitor.scan(tp, trees);
jjg@458 60 }
jjg@458 61
jjg@458 62 return true;
jjg@458 63 }
jjg@458 64
darcy@495 65 @Override
darcy@495 66 public SourceVersion getSupportedSourceVersion() {
darcy@495 67 return SourceVersion.latest();
darcy@495 68 }
darcy@495 69
jjg@458 70 class CodeVisitor extends TreePathScanner<Object, Trees> {
jjg@458 71
jjg@458 72 @Override
jjg@458 73 public Object visitMethodInvocation(MethodInvocationTree node, Trees p) {
jjg@458 74 System.out.print("current path: ");
jjg@458 75 for (Tree t : getCurrentPath()) {
jjg@458 76 System.out.print('/');
jjg@458 77 System.out.print(t);
jjg@458 78 }
jjg@458 79 System.out.println();
jjg@458 80 System.out.println("parent path: " + getCurrentPath().getParentPath());
jjg@458 81 System.out.println("method select: " + node.getMethodSelect().toString());
jjg@458 82 for (ExpressionTree arg : node.getArguments()) {
jjg@458 83 System.out.println("argument: " + arg.toString());
jjg@458 84 }
jjg@458 85 return super.visitMethodInvocation(node, p);
jjg@458 86 }
jjg@458 87
jjg@458 88 @Override
jjg@458 89 public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) {
jjg@458 90 ExpressionTree t = node.getExpression();
jjg@458 91 System.out.println("expression statement: " + t.toString());
jjg@458 92 return super.visitExpressionStatement(node, p);
jjg@458 93 }
jjg@458 94
jjg@458 95 }
jjg@458 96
jjg@458 97 }
jjg@458 98
jjg@458 99

mercurial