661N/A/*
661N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
661N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
661N/A *
661N/A * This code is free software; you can redistribute it and/or modify it
661N/A * under the terms of the GNU General Public License version 2 only, as
661N/A * published by the Free Software Foundation.
661N/A *
661N/A * This code is distributed in the hope that it will be useful, but WITHOUT
661N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
661N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
661N/A * version 2 for more details (a copy is included in the LICENSE file that
661N/A * accompanied this code).
661N/A *
661N/A * You should have received a copy of the GNU General Public License version
661N/A * 2 along with this work; if not, write to the Free Software Foundation,
661N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
661N/A *
661N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
661N/A * or visit www.oracle.com if you need additional information or have any
661N/A * questions.
661N/A */
661N/A
661N/A/*
661N/A * @test
661N/A * @bug 6570730
661N/A * @summary com.sun.source.tree.ModifiersTree.getFlags() should return class type
661N/A */
661N/A
661N/Aimport java.io.*;
661N/Aimport java.util.*;
661N/Aimport javax.tools.*;
661N/Aimport com.sun.source.tree.*;
661N/Aimport com.sun.source.util.*;
661N/Aimport com.sun.tools.javac.api.*;
661N/A
661N/Apublic class ClassTreeTest {
661N/A public static void main(String... args) throws Exception {
661N/A new ClassTreeTest().run();
661N/A }
661N/A
661N/A void run() throws Exception {
661N/A JavacTool tool = JavacTool.create();
661N/A StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
661N/A List<String> opts = Collections.<String>emptyList();
661N/A File testSrc = new File(System.getProperty("test.src"));
661N/A File thisFile = new File(testSrc, ClassTreeTest.class.getSimpleName() + ".java");
661N/A Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile);
661N/A JavacTask task = tool.getTask(null, fm, null, opts, null, fos);
661N/A for (CompilationUnitTree cu: task.parse()) {
661N/A check(cu, "CLASS", Tree.Kind.CLASS);
661N/A check(cu, "INTERFACE", Tree.Kind.INTERFACE);
661N/A check(cu, "ENUM", Tree.Kind.ENUM);
661N/A check(cu, "ANNOTATION_TYPE", Tree.Kind.ANNOTATION_TYPE);
661N/A }
661N/A
661N/A int expected = 4;
661N/A if (checks != expected)
661N/A error("Unexpected number of checks performed; expected: " + expected + ", found: " + checks);
661N/A
661N/A if (errors > 0)
661N/A throw new Exception(errors + " errors found");
661N/A }
661N/A
661N/A void check(CompilationUnitTree cu, String name, Tree.Kind k) {
661N/A checks++;
661N/A
661N/A TreeScanner<ClassTree,String> s = new TreeScanner<ClassTree,String>() {
661N/A @Override
661N/A public ClassTree visitClass(ClassTree c, String name) {
661N/A if (c.getSimpleName().toString().equals(name))
661N/A return c;
661N/A else
661N/A return super.visitClass(c, name);
661N/A }
661N/A
661N/A @Override
661N/A public ClassTree reduce(ClassTree t1, ClassTree t2) {
661N/A return (t1 != null ? t1 : t2);
661N/A }
661N/A };
661N/A
661N/A ClassTree c = s.scan(cu, name);
661N/A if (c == null)
661N/A error("Can't find node named " + name);
661N/A else if (c.getKind() != k)
661N/A error("Unexpected kind for node named " + name + ": expected: " + k + ", found: " + c.getKind());
661N/A }
661N/A
661N/A void error(String msg) {
661N/A System.err.println("Error: " + msg);
661N/A errors++;
661N/A }
661N/A
661N/A int checks;
661N/A int errors;
661N/A
661N/A class CLASS { }
661N/A interface INTERFACE { }
661N/A enum ENUM { }
661N/A @interface ANNOTATION_TYPE { }
661N/A}