test/tools/javac/tree/T6963934.java

Tue, 08 Nov 2011 11:51:05 -0800

author
jjg
date
Tue, 08 Nov 2011 11:51:05 -0800
changeset 1127
ca49d50318dc
parent 1013
8eb952f43b11
child 2525
2eb010b6cb22
permissions
-rw-r--r--

6921494: provide way to print javac tree tag values
Reviewed-by: jjg, mcimadamore
Contributed-by: vicenterz@yahoo.es

     1 /*
     2  * Copyright (c) 2011, 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     6963934
    27  * @summary JCCompilationUnit.getImports does not report all imports
    28  */
    30 import java.io.File;
    31 import javax.tools.JavaCompiler;
    32 import javax.tools.StandardJavaFileManager;
    33 import javax.tools.ToolProvider;; // NOTE: extra semicolon for test
    35 import com.sun.source.tree.CompilationUnitTree;
    36 import com.sun.source.tree.ImportTree;
    37 import com.sun.source.util.JavacTask;
    38 ; // NOTE: extra semicolon for test
    40 public class T6963934 {
    41     public static void main(String[] args) throws Exception {
    42         File testSrc = new File(System.getProperty("test.src"));
    43         File thisSrc = new File(testSrc, T6963934.class.getSimpleName() + ".java");
    44         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    45         StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    46         JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null,
    47                 fileManager.getJavaFileObjects(thisSrc));
    48         CompilationUnitTree tree = task.parse().iterator().next();
    49         int count = 0;
    50         for (ImportTree importTree : tree.getImports()) {
    51             System.out.println(importTree);
    52             count++;
    53         }
    54         int expected = 7;
    55         if (count != expected)
    56             throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected);
    57     }
    58 }

mercurial