test/tools/javac/T6855236.java

Thu, 09 Sep 2010 09:42:45 +0530

author
sundar
date
Thu, 09 Sep 2010 09:42:45 +0530
changeset 678
014cf6234586
parent 554
9d9f26857129
child 683
bbc9765d9ec6
permissions
-rw-r--r--

6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2010, 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  */
    24 /*
    25  * @test
    26  * @bug 6855236
    27  * @summary Compiler Tree API TreePath class generates NullPointerException from Iterator
    28  * @compile T6855236.java
    29  * @compile -processor T6855236 -proc:only T6855236.java
    30  */
    32 import java.util.*;
    34 import javax.annotation.processing.*;
    35 import javax.lang.model.*;
    36 import javax.lang.model.element.*;
    38 import com.sun.source.tree.*;
    39 import com.sun.source.util.*;
    41 @SupportedAnnotationTypes("*")
    42 public class T6855236 extends AbstractProcessor {
    44     private Trees trees;
    46     @Override
    47     public void init(ProcessingEnvironment pe) {
    48         super.init(pe);
    49         trees = Trees.instance(pe);
    50     }
    52     @Override
    53     public boolean process(Set<? extends TypeElement> arg0, RoundEnvironment roundEnvironment) {
    54         // Scanner class to scan through various component elements
    55         CodeVisitor visitor = new CodeVisitor();
    57         for (Element e : roundEnvironment.getRootElements()) {
    58             TreePath tp = trees.getPath(e);
    59             visitor.scan(tp, trees);
    60         }
    62         return true;
    63     }
    65     @Override
    66     public SourceVersion getSupportedSourceVersion() {
    67         return SourceVersion.latest();
    68     }
    70     class CodeVisitor extends TreePathScanner<Object, Trees> {
    72         @Override
    73         public Object visitMethodInvocation(MethodInvocationTree node, Trees p) {
    74             System.out.print("current path: ");
    75             for (Tree t : getCurrentPath()) {
    76                 System.out.print('/');
    77                 System.out.print(t);
    78            }
    79             System.out.println();
    80             System.out.println("parent path: " + getCurrentPath().getParentPath());
    81             System.out.println("method select: " + node.getMethodSelect().toString());
    82             for (ExpressionTree arg : node.getArguments()) {
    83                 System.out.println("argument: " + arg.toString());
    84             }
    85             return super.visitMethodInvocation(node, p);
    86         }
    88         @Override
    89         public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) {
    90             ExpressionTree t = node.getExpression();
    91             System.out.println("expression statement: " + t.toString());
    92             return super.visitExpressionStatement(node, p);
    93         }
    95     }
    97 }

mercurial