1.1 --- a/test/tools/javac/processing/model/element/TestExecutableElement.java Tue Apr 02 12:00:48 2013 -0700 1.2 +++ b/test/tools/javac/processing/model/element/TestExecutableElement.java Wed Apr 03 12:27:12 2013 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -23,7 +23,7 @@ 1.11 1.12 /* 1.13 * @test 1.14 - * @bug 8005046 1.15 + * @bug 8005046 8011052 1.16 * @summary Test basic properties of javax.lang.element.Element 1.17 * @author Joseph D. Darcy 1.18 * @library /tools/javac/lib 1.19 @@ -35,6 +35,7 @@ 1.20 import java.util.Formatter; 1.21 import java.util.Set; 1.22 import java.util.Objects; 1.23 +import java.util.regex.*; 1.24 import javax.annotation.processing.*; 1.25 import javax.lang.model.SourceVersion; 1.26 import static javax.lang.model.SourceVersion.*; 1.27 @@ -79,9 +80,39 @@ 1.28 1.29 boolean methodIsDefault = method.isDefault(); 1.30 1.31 + if (expectedDefault) { 1.32 + if (!method.getModifiers().contains(Modifier.DEFAULT)) { 1.33 + messager.printMessage(ERROR, 1.34 + "Modifier \"default\" not present as expected.", 1.35 + method); 1.36 + } 1.37 + 1.38 + // Check printing output 1.39 + java.io.Writer stringWriter = new java.io.StringWriter(); 1.40 + eltUtils.printElements(stringWriter, method); 1.41 + Pattern p = Pattern.compile(expectedIsDefault.expectedTextRegex(), Pattern.DOTALL); 1.42 + 1.43 + if (! p.matcher(stringWriter.toString()).matches()) { 1.44 + messager.printMessage(ERROR, 1.45 + new Formatter().format("Unexpected printing ouptput:%n\tgot %s,%n\texpected pattern %s.", 1.46 + stringWriter.toString(), 1.47 + expectedIsDefault.expectedTextRegex()).toString(), 1.48 + method); 1.49 + } 1.50 + 1.51 + System.out.println("\t" + stringWriter.toString()); 1.52 + 1.53 + } else { 1.54 + if (method.getModifiers().contains(Modifier.DEFAULT)) { 1.55 + messager.printMessage(ERROR, 1.56 + "Modifier \"default\" present when not expected.", 1.57 + method); 1.58 + } 1.59 + } 1.60 + 1.61 if (methodIsDefault != expectedDefault) { 1.62 messager.printMessage(ERROR, 1.63 - new Formatter().format("Unexpected Executable.isDefault result: got %s, expected %s", 1.64 + new Formatter().format("Unexpected Executable.isDefault result: got ``%s'', expected ``%s''.", 1.65 expectedDefault, 1.66 methodIsDefault).toString(), 1.67 method); 1.68 @@ -98,6 +129,7 @@ 1.69 @Target(ElementType.METHOD) 1.70 @interface IsDefault { 1.71 boolean value(); 1.72 + String expectedTextRegex() default ""; 1.73 } 1.74 1.75 /** 1.76 @@ -108,6 +140,6 @@ 1.77 boolean process(Set<? extends TypeElement> annotations, 1.78 RoundEnvironment roundEnv); 1.79 1.80 - @IsDefault(true) 1.81 - default void quux() {}; 1.82 + @IsDefault(value=true, expectedTextRegex="\\s*@IsDefault\\(.*\\)\\s*default strictfp void quux\\(\\);\\s*$") 1.83 + default strictfp void quux() {}; 1.84 }