aoqi@0: /* aoqi@0: * Copyright (c) 2013, 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 8011383 aoqi@0: * @summary Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods aoqi@0: */ aoqi@0: aoqi@0: import java.io.File; aoqi@0: import java.io.IOException; aoqi@0: import java.util.Arrays; aoqi@0: aoqi@0: import javax.lang.model.element.*; aoqi@0: import javax.tools.JavaCompiler; aoqi@0: import javax.tools.JavaFileObject; aoqi@0: import javax.tools.StandardJavaFileManager; aoqi@0: import javax.tools.ToolProvider; aoqi@0: aoqi@0: import com.sun.source.util.JavacTask; aoqi@0: import com.sun.source.util.TaskEvent; aoqi@0: import com.sun.source.util.TaskListener; aoqi@0: import com.sun.tools.javac.util.Assert; aoqi@0: aoqi@0: public class DefaultMethodFlags { aoqi@0: aoqi@0: public static void main(String[] args) throws IOException { aoqi@0: new DefaultMethodFlags().run(args); aoqi@0: } aoqi@0: aoqi@0: void run(String[] args) throws IOException { aoqi@0: checkDefaultMethodFlags(); aoqi@0: } aoqi@0: aoqi@0: void checkDefaultMethodFlags() throws IOException { aoqi@0: JavaCompiler c = ToolProvider.getSystemJavaCompiler(); aoqi@0: StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); aoqi@0: Iterable fos = aoqi@0: fm.getJavaFileObjectsFromFiles( aoqi@0: Arrays.asList(new File( aoqi@0: System.getProperty("test.src"), aoqi@0: this.getClass().getSimpleName() + ".java"))); aoqi@0: JavacTask task = (JavacTask) c.getTask(null, fm, null, null, null, fos); aoqi@0: aoqi@0: task.addTaskListener(new TaskListener() { aoqi@0: aoqi@0: @Override aoqi@0: public void started(TaskEvent e) {} aoqi@0: aoqi@0: @Override aoqi@0: public void finished(TaskEvent e) { aoqi@0: if (e.getKind() == TaskEvent.Kind.ANALYZE) { aoqi@0: TypeElement te = e.getTypeElement(); aoqi@0: if (te.getSimpleName().toString().equals("I")) { aoqi@0: checkDefaultInterface(te); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: }); aoqi@0: aoqi@0: task.analyze(); aoqi@0: } aoqi@0: aoqi@0: void checkDefaultInterface(TypeElement te) { aoqi@0: System.err.println("Checking " + te.getSimpleName()); aoqi@0: Assert.check(te.getModifiers().contains(Modifier.ABSTRACT)); aoqi@0: for (Element e : te.getEnclosedElements()) { aoqi@0: if (e.getSimpleName().toString().matches("(\\w)_(default|static|abstract)")) { aoqi@0: boolean abstractExpected = false; aoqi@0: String methodKind = e.getSimpleName().toString().substring(2); aoqi@0: switch (methodKind) { aoqi@0: case "default": aoqi@0: case "static": aoqi@0: break; aoqi@0: case "abstract": aoqi@0: abstractExpected = true; aoqi@0: break; aoqi@0: default: aoqi@0: Assert.error("Cannot get here!" + methodKind); aoqi@0: } aoqi@0: Assert.check(e.getModifiers().contains(Modifier.ABSTRACT) == abstractExpected); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: interface I { aoqi@0: default void m_default() { } aoqi@0: static void m_static() { } aoqi@0: void m_abstract(); aoqi@0: }