668N/A/*
668N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
668N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
668N/A *
668N/A * This code is free software; you can redistribute it and/or modify it
668N/A * under the terms of the GNU General Public License version 2 only, as
668N/A * published by the Free Software Foundation.
668N/A *
668N/A * This code is distributed in the hope that it will be useful, but WITHOUT
668N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
668N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
668N/A * version 2 for more details (a copy is included in the LICENSE file that
668N/A * accompanied this code).
668N/A *
668N/A * You should have received a copy of the GNU General Public License version
668N/A * 2 along with this work; if not, write to the Free Software Foundation,
668N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
668N/A *
668N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
668N/A * or visit www.oracle.com if you need additional information or have any
668N/A * questions.
668N/A */
668N/A
668N/A/*
668N/A * @test
668N/A * @bug 6956462
668N/A * @summary AssertionError exception throws in the Compiler Tree API in JDK 7.
668N/A *
668N/A * @build TestClass T6956462
668N/A * @run main T6956462
668N/A */
668N/A
668N/Aimport java.io.*;
668N/Aimport java.net.URISyntaxException;
668N/Aimport java.util.*;
668N/Aimport javax.tools.*;
668N/Aimport javax.tools.JavaCompiler.CompilationTask;
668N/Aimport com.sun.source.tree.*;
668N/Aimport com.sun.source.util.*;
668N/A
668N/Apublic class T6956462 {
668N/A public static void main(String[] args) throws Exception {
668N/A JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
668N/A if (compiler == null) {
668N/A throw new RuntimeException("can't get javax.tools.JavaCompiler!");
668N/A }
668N/A StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
668N/A List<File> files = new ArrayList<File>();
668N/A files.add(new File(T6956462.class.getResource("TestClass.java").toURI()));
668N/A final CompilationTask task = compiler.getTask(null, fm, null,
668N/A null, null, fm.getJavaFileObjectsFromFiles(files));
668N/A JavacTask javacTask = (JavacTask) task;
668N/A for (CompilationUnitTree cu : javacTask.parse()) {
668N/A cu.accept(new MyVisitor(javacTask), null);
668N/A }
668N/A }
668N/A
668N/A private static class MyVisitor extends SimpleTreeVisitor<Tree, Void> {
668N/A private final Trees trees;
668N/A private CompilationUnitTree file;
668N/A
668N/A private MyVisitor(JavacTask javac) {
668N/A this.trees = Trees.instance(javac);
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitCompilationUnit(CompilationUnitTree file, Void v) {
668N/A this.file = file;
668N/A for (Tree typeDecl : file.getTypeDecls()) {
668N/A typeDecl.accept(this, v);
668N/A }
668N/A return null;
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitImport(ImportTree imp, Void v) {
668N/A return null;
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitMethodInvocation(MethodInvocationTree invoke, Void v) {
668N/A invoke.getMethodSelect().accept(this, v);
668N/A return null;
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitBlock(BlockTree block, Void v) {
668N/A for (StatementTree stat : block.getStatements()) {
668N/A stat.accept(this, v);
668N/A }
668N/A return null;
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitClass(ClassTree clazz, Void v) {
668N/A for (Tree member : clazz.getMembers()) {
668N/A member.accept(this, v);
668N/A }
668N/A return null;
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitIdentifier(IdentifierTree ident, Void v) {
668N/A trees.getScope(trees.getPath(file, ident));
668N/A return null;
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitMethod(MethodTree method, Void v) {
668N/A method.getBody().accept(this, v);
668N/A return null;
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitMemberSelect(MemberSelectTree select, Void v) {
668N/A select.getExpression().accept(this, v);
668N/A return null;
668N/A }
668N/A
668N/A @Override
668N/A public Tree visitVariable(VariableTree var, Void v) {
668N/A var.getInitializer().accept(this, v);
668N/A return null;
668N/A }
668N/A }
668N/A}