changeset 1671:0d47e6131490

8011052: Add DEFAULT to javax.lang.model.Modifier Reviewed-by: abuckley, jjg
author darcy
date Wed, 03 Apr 2013 12:27:12 -0700
parents 46d2f144ebbd
children e06dc8345d9c
files src/share/classes/com/sun/tools/javac/code/Flags.java src/share/classes/javax/lang/model/element/Modifier.java test/tools/javac/processing/model/element/TestExecutableElement.java
diffstat 3 files changed, 44 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Flags.java	Tue Apr 02 12:00:48 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Flags.java	Wed Apr 03 12:27:12 2013 -0700
@@ -314,6 +314,7 @@
                                           modifiers.add(Modifier.SYNCHRONIZED);
             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
+            if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);
             modifiers = Collections.unmodifiableSet(modifiers);
             modifierSets.put(flags, modifiers);
         }
--- a/src/share/classes/javax/lang/model/element/Modifier.java	Tue Apr 02 12:00:48 2013 -0700
+++ b/src/share/classes/javax/lang/model/element/Modifier.java	Wed Apr 03 12:27:12 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -53,6 +53,11 @@
     /** The modifier {@code protected} */       PROTECTED,
     /** The modifier {@code private} */         PRIVATE,
     /** The modifier {@code abstract} */        ABSTRACT,
+    /**
+     * The modifier {@code default}
+     * @since 1.8
+     */
+     DEFAULT,
     /** The modifier {@code static} */          STATIC,
     /** The modifier {@code final} */           FINAL,
     /** The modifier {@code transient} */       TRANSIENT,
--- a/test/tools/javac/processing/model/element/TestExecutableElement.java	Tue Apr 02 12:00:48 2013 -0700
+++ b/test/tools/javac/processing/model/element/TestExecutableElement.java	Wed Apr 03 12:27:12 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8005046
+ * @bug 8005046 8011052
  * @summary Test basic properties of javax.lang.element.Element
  * @author  Joseph D. Darcy
  * @library /tools/javac/lib
@@ -35,6 +35,7 @@
 import java.util.Formatter;
 import java.util.Set;
 import java.util.Objects;
+import java.util.regex.*;
 import javax.annotation.processing.*;
 import javax.lang.model.SourceVersion;
 import static javax.lang.model.SourceVersion.*;
@@ -79,9 +80,39 @@
 
         boolean methodIsDefault = method.isDefault();
 
+        if (expectedDefault) {
+            if (!method.getModifiers().contains(Modifier.DEFAULT)) {
+                messager.printMessage(ERROR,
+                                      "Modifier \"default\" not present as expected.",
+                                      method);
+            }
+
+            // Check printing output
+            java.io.Writer stringWriter = new java.io.StringWriter();
+            eltUtils.printElements(stringWriter, method);
+            Pattern p = Pattern.compile(expectedIsDefault.expectedTextRegex(), Pattern.DOTALL);
+
+            if (! p.matcher(stringWriter.toString()).matches()) {
+                messager.printMessage(ERROR,
+                                      new Formatter().format("Unexpected printing ouptput:%n\tgot %s,%n\texpected pattern %s.",
+                                                             stringWriter.toString(),
+                                                             expectedIsDefault.expectedTextRegex()).toString(),
+                                      method);
+            }
+
+            System.out.println("\t" + stringWriter.toString());
+
+        } else {
+            if (method.getModifiers().contains(Modifier.DEFAULT)) {
+                messager.printMessage(ERROR,
+                                      "Modifier \"default\" present when not expected.",
+                                      method);
+            }
+        }
+
         if (methodIsDefault != expectedDefault) {
             messager.printMessage(ERROR,
-                                  new Formatter().format("Unexpected Executable.isDefault result: got %s, expected %s",
+                                  new Formatter().format("Unexpected Executable.isDefault result: got ``%s'', expected ``%s''.",
                                                          expectedDefault,
                                                          methodIsDefault).toString(),
                                   method);
@@ -98,6 +129,7 @@
 @Target(ElementType.METHOD)
 @interface IsDefault {
     boolean value();
+    String expectedTextRegex() default "";
 }
 
 /**
@@ -108,6 +140,6 @@
     boolean process(Set<? extends TypeElement> annotations,
                     RoundEnvironment roundEnv);
 
-    @IsDefault(true)
-    default void quux() {};
+    @IsDefault(value=true, expectedTextRegex="\\s*@IsDefault\\(.*\\)\\s*default strictfp void quux\\(\\);\\s*$")
+    default strictfp void quux() {};
 }