langtools/test/tools/javac/T6956462/T6956462.java
author sundar
Fri, 03 Sep 2010 12:36:43 +0530
changeset 6587 344aa81a3b35
child 27319 030080f03e4f
permissions -rw-r--r--
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6587
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     1
/*
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     4
 *
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     8
 *
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    13
 * accompanied this code).
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    14
 *
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    18
 *
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    21
 * questions.
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    22
 */
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    23
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    24
/*
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    25
 * @test
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    26
 * @bug 6956462
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    27
 * @summary AssertionError exception throws in the Compiler Tree API in JDK 7.
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    28
 *
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    29
 * @build TestClass T6956462
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    30
 * @run main T6956462
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    31
 */
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    32
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    33
import java.io.*;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    34
import java.net.URISyntaxException;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    35
import java.util.*;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    36
import javax.tools.*;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    37
import javax.tools.JavaCompiler.CompilationTask;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    38
import com.sun.source.tree.*;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    39
import com.sun.source.util.*;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    40
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    41
public class T6956462 {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    43
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    44
        if (compiler == null) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    45
            throw new RuntimeException("can't get javax.tools.JavaCompiler!");
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    46
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    47
        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    48
        List<File> files = new ArrayList<File>();
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    49
        files.add(new File(T6956462.class.getResource("TestClass.java").toURI()));
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    50
        final CompilationTask task = compiler.getTask(null, fm, null,
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    51
            null, null, fm.getJavaFileObjectsFromFiles(files));
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    52
        JavacTask javacTask = (JavacTask) task;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    53
        for (CompilationUnitTree cu : javacTask.parse()) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    54
            cu.accept(new MyVisitor(javacTask), null);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    55
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    56
    }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    57
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    58
    private static class MyVisitor extends SimpleTreeVisitor<Tree, Void> {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    59
        private final Trees trees;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    60
        private CompilationUnitTree file;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    61
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    62
        private MyVisitor(JavacTask javac) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    63
            this.trees = Trees.instance(javac);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    64
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    65
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    66
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    67
        public Tree visitCompilationUnit(CompilationUnitTree file, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    68
            this.file = file;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    69
            for (Tree typeDecl : file.getTypeDecls()) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    70
                typeDecl.accept(this, v);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    71
            }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    72
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    73
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    74
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    75
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    76
        public Tree visitImport(ImportTree imp, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    77
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    78
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    79
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    80
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    81
        public Tree visitMethodInvocation(MethodInvocationTree invoke, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    82
            invoke.getMethodSelect().accept(this, v);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    83
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    84
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    85
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    86
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    87
        public Tree visitBlock(BlockTree block, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    88
            for (StatementTree stat : block.getStatements()) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    89
                stat.accept(this, v);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    90
            }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    91
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    92
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    93
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    94
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    95
        public Tree visitClass(ClassTree clazz, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    96
            for (Tree member : clazz.getMembers()) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    97
                member.accept(this, v);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    98
            }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
    99
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   100
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   101
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   102
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   103
        public Tree visitIdentifier(IdentifierTree ident, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   104
            trees.getScope(trees.getPath(file, ident));
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   105
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   106
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   107
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   108
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   109
        public Tree visitMethod(MethodTree method, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   110
            method.getBody().accept(this, v);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   111
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   112
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   113
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   114
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   115
        public Tree visitMemberSelect(MemberSelectTree select, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   116
            select.getExpression().accept(this, v);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   117
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   118
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   119
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   120
        @Override
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   121
        public Tree visitVariable(VariableTree var, Void v) {
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   122
            var.getInitializer().accept(this, v);
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   123
            return null;
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   124
        }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   125
    }
344aa81a3b35 6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff changeset
   126
}