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