test/tools/javac/T6397044.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/T6397044.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,111 @@
     1.4 +/*
     1.5 + * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 6397044
    1.30 + * @summary JCModifiers.getModifiers() returns incorrect Modifiers set.
    1.31 + */
    1.32 +
    1.33 +import java.io.*;
    1.34 +import java.util.*;
    1.35 +import javax.tools.*;
    1.36 +import javax.lang.model.element.Modifier;
    1.37 +import com.sun.source.tree.*;
    1.38 +import com.sun.source.util.*;
    1.39 +import com.sun.tools.javac.api.JavacTool;
    1.40 +import com.sun.tools.javac.code.Flags;
    1.41 +import com.sun.tools.javac.tree.JCTree.JCModifiers;
    1.42 +
    1.43 +public abstract class T6397044 {
    1.44 +    public static void main(String[] args) throws Exception {
    1.45 +        String srcDir = System.getProperty("test.src", ".");
    1.46 +        String self = T6397044.class.getName();
    1.47 +        JavacTool tool = JavacTool.create();
    1.48 +        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    1.49 +        Iterable<? extends JavaFileObject> files
    1.50 +            = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java")));
    1.51 +        JavacTask task = tool.getTask(null, fm, null, null, null, files);
    1.52 +        Iterable<? extends CompilationUnitTree> trees = task.parse();
    1.53 +        Checker checker = new Checker();
    1.54 +        for (CompilationUnitTree tree: trees)
    1.55 +            checker.check(tree);
    1.56 +    }
    1.57 +
    1.58 +    public int x_public;
    1.59 +    protected int x_protected;
    1.60 +    private int x_private;
    1.61 +    abstract int x_abstract();
    1.62 +    static int x_static;
    1.63 +    final int x_final = 1;
    1.64 +    transient int x_transient;
    1.65 +    volatile int x_volatile;
    1.66 +    synchronized void x_synchronized() { }
    1.67 +    native int x_native();
    1.68 +    strictfp void x_strictfp() { }
    1.69 +
    1.70 +    static class Checker extends TreeScanner<Void,Void> {
    1.71 +        void check(Tree tree) {
    1.72 +            if (tree != null)
    1.73 +                tree.accept(this, null);
    1.74 +        }
    1.75 +
    1.76 +        void check(List<? extends Tree> trees) {
    1.77 +            if (trees == null)
    1.78 +                return;
    1.79 +            for (Tree tree: trees)
    1.80 +                check(tree);
    1.81 +        }
    1.82 +
    1.83 +        public Void visitCompilationUnit(CompilationUnitTree tree, Void ignore) {
    1.84 +            check(tree.getTypeDecls());
    1.85 +            return null;
    1.86 +        }
    1.87 +
    1.88 +        public Void visitClass(ClassTree tree, Void ignore) {
    1.89 +            check(tree.getMembers());
    1.90 +            return null;
    1.91 +        }
    1.92 +
    1.93 +        public Void visitMethod(MethodTree tree, Void ignore) {
    1.94 +            check(tree.getName(), tree.getModifiers());
    1.95 +            return null;
    1.96 +        }
    1.97 +
    1.98 +        public Void visitVariable(VariableTree tree, Void ignore) {
    1.99 +            check(tree.getName(), tree.getModifiers());
   1.100 +            return null;
   1.101 +        }
   1.102 +
   1.103 +        private void check(CharSequence name, ModifiersTree modifiers) {
   1.104 +            long sysflags = ((JCModifiers) modifiers).flags;
   1.105 +            System.err.println(name + ": " + modifiers.getFlags() + " | " + Flags.toString(sysflags));
   1.106 +            if (name.toString().startsWith("x_")) {
   1.107 +                String expected = "[" + name.toString().substring(2) + "]";
   1.108 +                String found = modifiers.getFlags().toString();
   1.109 +                if (!found.equals(expected))
   1.110 +                    throw new AssertionError("expected: " + expected + "; found: " + found);
   1.111 +            }
   1.112 +        }
   1.113 +    }
   1.114 +}

mercurial