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