T6855236.java revision 494
0N/A/*
2362N/A * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2362N/A * have any questions.
2362N/A */
2362N/A
0N/A/*
0N/A * @test
0N/A * @bug 6855236
0N/A * @summary Compiler Tree API TreePath class generates NullPointerException from Iterator
0N/A * @compile T6855236.java
0N/A * @compile -processor T6855236 -proc:only T6855236.java
0N/A */
0N/A
0N/Aimport java.util.*;
0N/A
0N/Aimport javax.annotation.processing.*;
0N/Aimport javax.lang.model.*;
0N/Aimport javax.lang.model.element.*;
0N/A
0N/Aimport com.sun.source.tree.*;
0N/Aimport com.sun.source.util.*;
0N/A
0N/A@SupportedAnnotationTypes("*")
0N/Apublic class T6855236 extends AbstractProcessor {
0N/A
0N/A private Trees trees;
0N/A
0N/A @Override
0N/A public void init(ProcessingEnvironment pe) {
0N/A super.init(pe);
0N/A trees = Trees.instance(pe);
0N/A }
@Override
public boolean process(Set<? extends TypeElement> arg0, RoundEnvironment roundEnvironment) {
// Scanner class to scan through various component elements
CodeVisitor visitor = new CodeVisitor();
for (Element e : roundEnvironment.getRootElements()) {
TreePath tp = trees.getPath(e);
visitor.scan(tp, trees);
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
class CodeVisitor extends TreePathScanner<Object, Trees> {
@Override
public Object visitMethodInvocation(MethodInvocationTree node, Trees p) {
System.out.print("current path: ");
for (Tree t : getCurrentPath()) {
System.out.print('/');
System.out.print(t);
}
System.out.println();
System.out.println("parent path: " + getCurrentPath().getParentPath());
System.out.println("method select: " + node.getMethodSelect().toString());
for (ExpressionTree arg : node.getArguments()) {
System.out.println("argument: " + arg.toString());
}
return super.visitMethodInvocation(node, p);
}
@Override
public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) {
ExpressionTree t = node.getExpression();
System.out.println("expression statement: " + t.toString());
return super.visitExpressionStatement(node, p);
}
}
}