Mon, 03 Oct 2016 11:21:14 -0700
Added tag jdk8u122-b02 for changeset 2baeb96fa198
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. |
duke@1 | 8 | * |
duke@1 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 13 | * accompanied this code). |
duke@1 | 14 | * |
duke@1 | 15 | * You should have received a copy of the GNU General Public License version |
duke@1 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
duke@1 | 22 | */ |
duke@1 | 23 | |
duke@1 | 24 | /* |
duke@1 | 25 | * @test |
duke@1 | 26 | * @bug 6397044 |
duke@1 | 27 | * @summary JCModifiers.getModifiers() returns incorrect Modifiers set. |
duke@1 | 28 | */ |
duke@1 | 29 | |
duke@1 | 30 | import java.io.*; |
duke@1 | 31 | import java.util.*; |
duke@1 | 32 | import javax.tools.*; |
duke@1 | 33 | import javax.lang.model.element.Modifier; |
duke@1 | 34 | import com.sun.source.tree.*; |
duke@1 | 35 | import com.sun.source.util.*; |
duke@1 | 36 | import com.sun.tools.javac.api.JavacTool; |
duke@1 | 37 | import com.sun.tools.javac.code.Flags; |
duke@1 | 38 | import com.sun.tools.javac.tree.JCTree.JCModifiers; |
duke@1 | 39 | |
duke@1 | 40 | public abstract class T6397044 { |
duke@1 | 41 | public static void main(String[] args) throws Exception { |
duke@1 | 42 | String srcDir = System.getProperty("test.src", "."); |
duke@1 | 43 | String self = T6397044.class.getName(); |
duke@1 | 44 | JavacTool tool = JavacTool.create(); |
duke@1 | 45 | StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
duke@1 | 46 | Iterable<? extends JavaFileObject> files |
duke@1 | 47 | = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java"))); |
duke@1 | 48 | JavacTask task = tool.getTask(null, fm, null, null, null, files); |
duke@1 | 49 | Iterable<? extends CompilationUnitTree> trees = task.parse(); |
duke@1 | 50 | Checker checker = new Checker(); |
duke@1 | 51 | for (CompilationUnitTree tree: trees) |
duke@1 | 52 | checker.check(tree); |
duke@1 | 53 | } |
duke@1 | 54 | |
duke@1 | 55 | public int x_public; |
duke@1 | 56 | protected int x_protected; |
duke@1 | 57 | private int x_private; |
duke@1 | 58 | abstract int x_abstract(); |
duke@1 | 59 | static int x_static; |
duke@1 | 60 | final int x_final = 1; |
duke@1 | 61 | transient int x_transient; |
duke@1 | 62 | volatile int x_volatile; |
duke@1 | 63 | synchronized void x_synchronized() { } |
duke@1 | 64 | native int x_native(); |
duke@1 | 65 | strictfp void x_strictfp() { } |
duke@1 | 66 | |
duke@1 | 67 | static class Checker extends TreeScanner<Void,Void> { |
duke@1 | 68 | void check(Tree tree) { |
duke@1 | 69 | if (tree != null) |
duke@1 | 70 | tree.accept(this, null); |
duke@1 | 71 | } |
duke@1 | 72 | |
duke@1 | 73 | void check(List<? extends Tree> trees) { |
duke@1 | 74 | if (trees == null) |
duke@1 | 75 | return; |
duke@1 | 76 | for (Tree tree: trees) |
duke@1 | 77 | check(tree); |
duke@1 | 78 | } |
duke@1 | 79 | |
duke@1 | 80 | public Void visitCompilationUnit(CompilationUnitTree tree, Void ignore) { |
duke@1 | 81 | check(tree.getTypeDecls()); |
duke@1 | 82 | return null; |
duke@1 | 83 | } |
duke@1 | 84 | |
duke@1 | 85 | public Void visitClass(ClassTree tree, Void ignore) { |
duke@1 | 86 | check(tree.getMembers()); |
duke@1 | 87 | return null; |
duke@1 | 88 | } |
duke@1 | 89 | |
duke@1 | 90 | public Void visitMethod(MethodTree tree, Void ignore) { |
duke@1 | 91 | check(tree.getName(), tree.getModifiers()); |
duke@1 | 92 | return null; |
duke@1 | 93 | } |
duke@1 | 94 | |
duke@1 | 95 | public Void visitVariable(VariableTree tree, Void ignore) { |
duke@1 | 96 | check(tree.getName(), tree.getModifiers()); |
duke@1 | 97 | return null; |
duke@1 | 98 | } |
duke@1 | 99 | |
duke@1 | 100 | private void check(CharSequence name, ModifiersTree modifiers) { |
duke@1 | 101 | long sysflags = ((JCModifiers) modifiers).flags; |
duke@1 | 102 | System.err.println(name + ": " + modifiers.getFlags() + " | " + Flags.toString(sysflags)); |
duke@1 | 103 | if (name.toString().startsWith("x_")) { |
duke@1 | 104 | String expected = "[" + name.toString().substring(2) + "]"; |
duke@1 | 105 | String found = modifiers.getFlags().toString(); |
duke@1 | 106 | if (!found.equals(expected)) |
duke@1 | 107 | throw new AssertionError("expected: " + expected + "; found: " + found); |
duke@1 | 108 | } |
duke@1 | 109 | } |
duke@1 | 110 | } |
duke@1 | 111 | } |