langtools/test/tools/javac/T6855236.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 6601 90c4a1a64217
child 30730 d3ce7619db2c
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4693
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4935
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
4693
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
     4
 *
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
     8
 *
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    13
 * accompanied this code).
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    14
 *
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4935
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4935
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4935
diff changeset
    21
 * questions.
4693
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    22
 */
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    23
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    24
/*
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    25
 * @test
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    26
 * @bug 6855236
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    27
 * @summary Compiler Tree API TreePath class generates NullPointerException from Iterator
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    28
 * @compile T6855236.java
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    29
 * @compile -processor T6855236 -proc:only T6855236.java
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    30
 */
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    31
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    32
import java.util.*;
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    33
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    34
import javax.annotation.processing.*;
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    35
import javax.lang.model.*;
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    36
import javax.lang.model.element.*;
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    37
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    38
import com.sun.source.tree.*;
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    39
import com.sun.source.util.*;
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    40
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    41
@SupportedAnnotationTypes("*")
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    42
public class T6855236 extends AbstractProcessor {
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    43
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    44
    private Trees trees;
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    45
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    46
    @Override
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    47
    public void init(ProcessingEnvironment pe) {
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    48
        super.init(pe);
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    49
        trees = Trees.instance(pe);
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    50
    }
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    51
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    52
    @Override
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    53
    public boolean process(Set<? extends TypeElement> arg0, RoundEnvironment roundEnvironment) {
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    54
        // Scanner class to scan through various component elements
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    55
        CodeVisitor visitor = new CodeVisitor();
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    56
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    57
        for (Element e : roundEnvironment.getRootElements()) {
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    58
            TreePath tp = trees.getPath(e);
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    59
            visitor.scan(tp, trees);
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    60
        }
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    61
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    62
        return true;
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    63
    }
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    64
4935
ff8adaa7bb8e 6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents: 4693
diff changeset
    65
    @Override
ff8adaa7bb8e 6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents: 4693
diff changeset
    66
    public SourceVersion getSupportedSourceVersion() {
ff8adaa7bb8e 6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents: 4693
diff changeset
    67
        return SourceVersion.latest();
ff8adaa7bb8e 6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents: 4693
diff changeset
    68
    }
ff8adaa7bb8e 6926699: Annotation processing regression tests should typically return SourceVersion.latest
darcy
parents: 4693
diff changeset
    69
4693
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    70
    class CodeVisitor extends TreePathScanner<Object, Trees> {
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    71
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    72
        @Override
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    73
        public Object visitMethodInvocation(MethodInvocationTree node, Trees p) {
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    74
            System.out.println("current path: ");
4693
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    75
            for (Tree t : getCurrentPath()) {
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    76
                System.out.println("    " + t.getKind() + ": " + trim(t, 64));
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    77
            }
4693
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    78
            System.out.println("parent path: " + getCurrentPath().getParentPath());
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    79
            System.out.println("method select: " + node.getMethodSelect().toString());
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    80
            for (ExpressionTree arg : node.getArguments()) {
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    81
                System.out.println("argument: " + arg.toString());
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    82
            }
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    83
            return super.visitMethodInvocation(node, p);
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    84
        }
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    85
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    86
        @Override
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    87
        public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) {
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    88
            ExpressionTree t = node.getExpression();
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    89
            System.out.println();
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    90
            System.out.println("expression statement: " + trim(t, 64));
4693
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    91
            return super.visitExpressionStatement(node, p);
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    92
        }
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    93
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    94
    }
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
    95
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    96
    private String trim(Tree t, int len) {
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    97
        String s = t.toString().trim().replaceAll("\\s+", " ");
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    98
        if (s.length() > len)
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    99
            s = s.substring(0, len) + "...";
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
   100
        return s;
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
   101
    }
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
   102
4693
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
   103
}
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
   104
1141df255420 6855236: Compiler Tree API TreePath class generates NullPointerException from Iterator
jjg
parents:
diff changeset
   105