duke@1: /* ohair@554: * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: /* duke@1: * @test duke@1: * @bug 6397044 duke@1: * @summary JCModifiers.getModifiers() returns incorrect Modifiers set. duke@1: */ duke@1: duke@1: import java.io.*; duke@1: import java.util.*; duke@1: import javax.tools.*; duke@1: import javax.lang.model.element.Modifier; duke@1: import com.sun.source.tree.*; duke@1: import com.sun.source.util.*; duke@1: import com.sun.tools.javac.api.JavacTool; duke@1: import com.sun.tools.javac.code.Flags; duke@1: import com.sun.tools.javac.tree.JCTree.JCModifiers; duke@1: duke@1: public abstract class T6397044 { duke@1: public static void main(String[] args) throws Exception { duke@1: String srcDir = System.getProperty("test.src", "."); duke@1: String self = T6397044.class.getName(); duke@1: JavacTool tool = JavacTool.create(); duke@1: StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); duke@1: Iterable files duke@1: = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java"))); duke@1: JavacTask task = tool.getTask(null, fm, null, null, null, files); duke@1: Iterable trees = task.parse(); duke@1: Checker checker = new Checker(); duke@1: for (CompilationUnitTree tree: trees) duke@1: checker.check(tree); duke@1: } duke@1: duke@1: public int x_public; duke@1: protected int x_protected; duke@1: private int x_private; duke@1: abstract int x_abstract(); duke@1: static int x_static; duke@1: final int x_final = 1; duke@1: transient int x_transient; duke@1: volatile int x_volatile; duke@1: synchronized void x_synchronized() { } duke@1: native int x_native(); duke@1: strictfp void x_strictfp() { } duke@1: duke@1: static class Checker extends TreeScanner { duke@1: void check(Tree tree) { duke@1: if (tree != null) duke@1: tree.accept(this, null); duke@1: } duke@1: duke@1: void check(List trees) { duke@1: if (trees == null) duke@1: return; duke@1: for (Tree tree: trees) duke@1: check(tree); duke@1: } duke@1: duke@1: public Void visitCompilationUnit(CompilationUnitTree tree, Void ignore) { duke@1: check(tree.getTypeDecls()); duke@1: return null; duke@1: } duke@1: duke@1: public Void visitClass(ClassTree tree, Void ignore) { duke@1: check(tree.getMembers()); duke@1: return null; duke@1: } duke@1: duke@1: public Void visitMethod(MethodTree tree, Void ignore) { duke@1: check(tree.getName(), tree.getModifiers()); duke@1: return null; duke@1: } duke@1: duke@1: public Void visitVariable(VariableTree tree, Void ignore) { duke@1: check(tree.getName(), tree.getModifiers()); duke@1: return null; duke@1: } duke@1: duke@1: private void check(CharSequence name, ModifiersTree modifiers) { duke@1: long sysflags = ((JCModifiers) modifiers).flags; duke@1: System.err.println(name + ": " + modifiers.getFlags() + " | " + Flags.toString(sysflags)); duke@1: if (name.toString().startsWith("x_")) { duke@1: String expected = "[" + name.toString().substring(2) + "]"; duke@1: String found = modifiers.getFlags().toString(); duke@1: if (!found.equals(expected)) duke@1: throw new AssertionError("expected: " + expected + "; found: " + found); duke@1: } duke@1: } duke@1: } duke@1: }