1 /*
   2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug      8001457 8027477 8163113
  27  * @author   sogoel
  28  * @summary  Reflection api tests
  29  * @modules jdk.compiler
  30  * @build    Helper
  31  * @compile  expectedFiles/ExpectedBase.java expectedFiles/ExpectedContainer.java
  32  * @run main ReflectionTest
  33  */
  34 import java.io.File;
  35 import java.io.IOException;
  36 import java.lang.annotation.Annotation;
  37 import java.net.MalformedURLException;
  38 import java.net.URL;
  39 import java.net.URLClassLoader;
  40 import java.util.ArrayList;
  41 import java.util.Arrays;
  42 import java.util.List;
  43 
  44 import javax.tools.DiagnosticCollector;
  45 import javax.tools.JavaFileObject;
  46 
  47 import expectedFiles.ExpectedBase;
  48 import expectedFiles.ExpectedContainer;
  49 import java.util.Iterator;
  50 import java.util.regex.Pattern;
  51 
  52 /*
  53  * Objective:
  54  * Test the following 6 methods from java.lang.reflect.AnnotatedElement:
  55  * - getAnnotation(Class<T>)
  56  * - getAnnotations()
  57  * - getDeclaredAnnotations()
  58  * - getDeclaredAnnotation(Class<T>)  // new method in JDK8
  59  * - getAnnotationsByType(Class<T>)         // new method in JDK8
  60  * - getDeclaredAnnotationsByType(Class<T>) // new method in JDK8
  61  * for multiple test cases, for example, BasicNonRepeatable case, BasicRepeatable case
  62  * for each of the src types - class, method, field, package
  63  *
  64  * This test uses following three enums:
  65  * 1. TestCase - Defines the ExpectedBase/ExpectedContainer values for each testCase
  66  *             - getTestFiles() - Creates list of JavaFileObjects for the primary
  67  *                                src types (class, method, field, package)
  68  *             - Each testCase is a new scenario with a combination of @Repeatable
  69  *               relationship present/absent in conjunction with @Inherited.
  70  *               For eg: BasicNonRepeatable_Legacy - It is a pre-JDK8 way of writing a single
  71  *                       annotation on a given srcType( class, method, field, package)
  72  *                       BasicRepeatable - It is a JDK8 way of writing repeating annotations
  73  *                       on a given srcType with a @Repeatable relationship
  74  *                       defined between Foo and FooContainer.
  75  *
  76  * 2. SrcType - Defines templates used in creation of test src
  77  *            - Defines getExpectedBase() and getExpectedContainer() for primary src types
  78  * 3. TestMethod - Defines getActualAnnoBase(), getActualAnnoContainer(), getExpectedAnnoBase(),
  79  *                 and getExpectedAnnoContainer() for each of the 6 methods that are being tested
  80  *                 in java.lang.reflect.AnnotatedElement
  81  *
  82  * Test execution flow:
  83  * - Loop over each of the src types and each test cases
  84  * - Creates test src for each flow, compile it, load the class object
  85  * - Run all 6 methods on this class object
  86  * - Get expected and actual annotations for each object and compare them.
  87  * - Increment the error counter if the annotations don't match.
  88  *
  89  * The test fails if the number of errors is greater than 0.
  90  */
  91 public class ReflectionTest {
  92 
  93     static int errors = 0;
  94     // Variables used in creating test src for a given testcase/testSrcType
  95     static final String TESTPKG = "testpkg";
  96     static final String TESTMETHOD = "testMethod";
  97     static final String TESTFIELD = "testField";
  98     static final String PKGINFONAME = TESTPKG + ".package-info";
  99     static final String SUPERCLASS = "SuperClass";
 100     static final String TESTINTERFACE = "TestInterface";
 101     /*
 102      *  Set it to true to get more debug information
 103      */
 104     static final boolean DEBUG = false;
 105     static boolean CHECKORDERING;
 106 
 107     public static void main(String args[]) throws Exception {
 108         ReflectionTest test = new ReflectionTest();
 109         test.runTest();
 110     }
 111 
 112     public void runTest() throws Exception {
 113 
 114         ClassLoader parentClassLoader = getLoader();
 115         String className = "";
 116         Iterable<? extends JavaFileObject> files = null;
 117 
 118         for (SrcType srcType : SrcType.getSrcTypes()) {
 119             for (TestCase testCase : TestCase.values()) {
 120                 className = testCase + "_" + srcType;
 121                 debugPrint("*****************************************");
 122                 System.out.println("Running Test for ClassName: " + className);
 123 
 124                 // @Inherited only applicable for class, exclude cases for
 125                 // package, method, field
 126                 if (testCase.name().contains("Inherited")
 127                         && (srcType != SrcType.CLASS)) {
 128                     continue;
 129                 }
 130 
 131                 // Get list of JavaFileObjects to be compiled
 132                 files = testCase.getTestFiles(srcType, className);
 133                 if (srcType == SrcType.PACKAGE) {
 134                     className = TESTPKG + "." + className;
 135                 }
 136                 DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
 137 
 138                 // Compile the list of JavaFileObjects
 139                 try {
 140                     Helper.compileCode(diagnostics, files);
 141                 } catch (Exception ex) {
 142                     printTestSrc(files);
 143                     throw new RuntimeException(
 144                             "Exception when compiling class " + className, ex);
 145                 }
 146 
 147                 // Get Class object for the compiled class
 148                 Class<?> c = loadClass(className, parentClassLoader, Helper.destDir);
 149                 if (c != null) {
 150                     // For the loaded class object, compare expected and actual annotation values
 151                     // for each of the methods under test from java.lang.reflect.AnnotatedElement
 152 
 153 
 154                     // Ignoring following test cases since for now they are
 155                     // failing with ordering issues.
 156                     // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
 157                     // fail with ordering issues
 158                     List<String> orderingTestFailures = Arrays.asList(
 159                             "SingleOnSuperContainerOnSub_Inherited_Legacy",
 160                             "SingleOnSuperContainerAndSingleOnSub_Inherited_Legacy",
 161                             "ContainerAndSingleOnSuperSingleOnSub_Inherited_Legacy",
 162                             "SingleAnnoWithContainer",
 163                             "SingleOnSuperContainerAndSingleOnSub_Inherited",
 164                             "RepeatableOnSuperSingleOnSub_Inherited",
 165                             "SingleOnSuperRepeatableOnSub_Inherited",
 166                             "ContainerOnSuperSingleOnSub_Inherited",
 167                             "SingleOnSuperContainerOnSub_Inherited",
 168                             "ContainerAndSingleOnSuperSingleOnSub_Inherited");
 169                     if (orderingTestFailures.contains(testCase.toString())) {
 170                         CHECKORDERING = false;
 171                     } else
 172                         CHECKORDERING = true;
 173 
 174                     checkAnnoValues(srcType, c);
 175                 } else {
 176                     error("Could not load className = " + c);
 177                 }
 178             }
 179         }
 180 
 181         if (getNumErrors() > 0) {
 182             System.err.println("Test failed with " + getNumErrors() + " errors");
 183             throw new RuntimeException();
 184         }
 185     }
 186 
 187     /*
 188      *  Each test case in this enum has the following:
 189      *  - Define each test case with its @ExpectedBase and @ExpectedContainer annotations
 190      *  - Override getTestFiles() that creates list of JavaFileObjects for each case
 191      *    based on the src type.
 192      */
 193     enum TestCase {
 194         BasicNonRepeatable_Legacy(
 195         "@ExpectedBase(value=Foo.class, "
 196                 + "getAnnotationVal = \"@Foo(value=0)\", "
 197                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"}, "
 198                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"}, "
 199                 + "getDeclAnnoVal = \"@Foo(value=0)\", "
 200                 + "getAnnosArgs = {\"@Foo(value=0)\"}, "
 201                 + "getDeclAnnosArgs = {\"@Foo(value=0)\"}) ",
 202         "@ExpectedContainer") {
 203 
 204             @Override
 205             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 206                     String className) {
 207                 String anno = "";
 208                 String replaceVal = "";
 209                 String testSrc = "";
 210                 String pkgInfoContents = "";
 211                 String contents = "";
 212 
 213                 JavaFileObject pkgFileObj = null;
 214                 JavaFileObject srcFileObj = null;
 215                 Iterable<? extends JavaFileObject> files = null;
 216 
 217                 String expectedVals = "\n" + getExpectedBase() + "\n"
 218                         + getExpectedContainer() + "\n";
 219                 StringBuilder commonStmts = new StringBuilder();
 220                 anno = Helper.ContentVars.BASEANNO.getVal();
 221                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
 222                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
 223                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
 224                         .append(Helper.ContentVars.BASE.getVal());
 225                 switch (srcType) {
 226                     case PACKAGE:
 227                         /*
 228                         Sample package-info.java
 229                         @ExpectedBase
 230                         @ExpectedContainer
 231                         @Foo(0)
 232                         package testpkg;
 233 
 234                         @Retention(RetentionPolicy.RUNTIME)
 235                         @interface Foo {int value() default Integer.MAX_VALUE;}
 236 
 237                         Sample testSrc:
 238                         package testpkg;
 239                         class A {}
 240                          */
 241                         testSrc = srcType.getTemplate().replace("#CN", className);
 242                         contents = testSrc;
 243                         srcFileObj = Helper.getFile(className, contents);
 244 
 245                         replaceVal = expectedVals + "\n" + anno;
 246                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
 247                                 .replace("#REPLACE1", replaceVal)
 248                                 .replace("#REPLACE2", commonStmts);
 249                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
 250 
 251                         files = Arrays.asList(pkgFileObj, srcFileObj);
 252                         break;
 253                     default:
 254                         // class, method, field
 255                     /*
 256                         Sample testSrc for class
 257                         @Retention(RetentionPolicy.RUNTIME)
 258                         @interface Foo {int value() default Integer.MAX_VALUE;}
 259 
 260                         @ExpectedBase
 261                         @ExpectedContainer
 262                         @Foo(0)
 263                         class A {}
 264                          */
 265                         replaceVal = expectedVals + anno;
 266                         testSrc = srcType.getTemplate().replace("#CN", className)
 267                                 .replace("#REPLACE", replaceVal);
 268                         contents = commonStmts + testSrc;
 269                         srcFileObj = Helper.getFile(className, contents);
 270                         files = Arrays.asList(srcFileObj);
 271                 }
 272                 return files;
 273             }
 274         },
 275         SingleAnnoInherited_Legacy(
 276         "@ExpectedBase(value=Foo.class, "
 277                 + "getAnnotationVal = \"@Foo(value=0)\", "
 278                 + "getAnnotationsVals = {\"@Foo(value=0)\", \"ExpectedBase\", \"ExpectedContainer\"}, "
 279                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
 280                 + "getDeclAnnoVal = \"NULL\", "
 281                 + "getAnnosArgs = {\"@Foo(value=0)\"}, "
 282                 + "getDeclAnnosArgs = {})",
 283         "@ExpectedContainer") {
 284 
 285             @Override
 286             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 287                     String className) {
 288                 String anno = "";
 289                 String replaceVal = "";
 290                 String contents = "";
 291                 JavaFileObject srcFileObj = null;
 292                 Iterable<? extends JavaFileObject> files = null;
 293 
 294                 String expectedVals = "\n" + getExpectedBase() + "\n"
 295                         + getExpectedContainer() + "\n";
 296                 StringBuilder commonStmts = new StringBuilder();
 297 
 298                 /*
 299                 Sample testSrc:
 300                 @Retention(RetentionPolicy.RUNTIME)
 301                 @Inherited
 302                 @interface Foo {int value() default Integer.MAX_VALUE;}
 303 
 304                 @Foo(0)
 305                 class SuperClass { }
 306 
 307                 @ExpectedBase
 308                 @ExpectedContainer
 309                 class SubClass extends SuperClass {}
 310                  */
 311 
 312                 // @Inherited only works for classes, no switch cases for
 313                 // method, field, package
 314                 anno = Helper.ContentVars.BASEANNO.getVal();
 315                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
 316                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
 317                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
 318                         .append(Helper.ContentVars.INHERITED.getVal())
 319                         .append(Helper.ContentVars.BASE.getVal());
 320 
 321                 if (srcType == SrcType.CLASS) {
 322                     // Contents for SuperClass
 323                     replaceVal = commonStmts + "\n" + anno;
 324                     String superClassContents = srcType.getTemplate()
 325                             .replace("#CN", SUPERCLASS).replace("#REPLACE", replaceVal);
 326 
 327                     // Contents for SubClass that extends SuperClass
 328                     replaceVal = expectedVals;
 329                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
 330                             .replace("#CN", className).replace("#SN", SUPERCLASS)
 331                             .replace("#REPLACE", replaceVal);
 332 
 333                     contents = superClassContents + subClassContents;
 334                     srcFileObj = Helper.getFile(className, contents);
 335                     files = Arrays.asList(srcFileObj);
 336                 }
 337                 return files;
 338             }
 339         },
 340         InheritedAnnoOnInterface_Legacy(
 341         "@ExpectedBase(value=Foo.class, "
 342                 + "getAnnotationVal = \"NULL\", "
 343                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
 344                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"},"
 345                 + "getDeclAnnoVal = \"NULL\"," + "getAnnosArgs = {},"
 346                 + "getDeclAnnosArgs = {})",
 347         "@ExpectedContainer") {
 348 
 349             @Override
 350             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 351                     String className) {
 352                 String anno = "";
 353                 String replaceVal = "";
 354                 String contents = "";
 355                 JavaFileObject srcFileObj = null;
 356                 Iterable<? extends JavaFileObject> files = null;
 357 
 358                 String expectedVals = "\n" + getExpectedBase() + "\n"
 359                         + getExpectedContainer() + "\n";
 360                 StringBuilder commonStmts = new StringBuilder();
 361 
 362                 /*
 363                 Sample test src:
 364                 @Retention(RetentionPolicy.RUNTIME)
 365                 @Inherited
 366                 @interface Foo {int value() default Integer.MAX_VALUE;}
 367 
 368                 @Foo(0)
 369                 interface TestInterface { }
 370 
 371                 @ExpectedBase
 372                 @ExpectedContainer
 373                 class A implements TestInterface {}
 374                  */
 375                 anno = Helper.ContentVars.BASEANNO.getVal();
 376                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
 377                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
 378                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
 379                         .append(Helper.ContentVars.INHERITED.getVal())
 380                         .append(Helper.ContentVars.BASE.getVal());
 381 
 382                 if (srcType == SrcType.CLASS) {
 383                     // Contents for TestInterface
 384                     replaceVal = commonStmts + "\n" + anno;
 385                     String interfaceContents = SrcType.INTERFACE.getTemplate()
 386                             .replace("#IN", TESTINTERFACE)
 387                             .replace("#REPLACE", replaceVal);
 388 
 389                     // Contents for class implementing TestInterface
 390                     replaceVal = expectedVals;
 391                     String classContents = SrcType.INTERFACEIMPL.getTemplate()
 392                             .replace("#CN", className).replace("#IN", TESTINTERFACE)
 393                             .replace("#REPLACE", replaceVal);
 394 
 395                     contents = interfaceContents + classContents;
 396                     srcFileObj = Helper.getFile(className, contents);
 397                     files = Arrays.asList(srcFileObj);
 398                 }
 399                 return files;
 400             }
 401         },
 402         AnnoOnSuperAndSubClass_Inherited_Legacy(
 403         "@ExpectedBase(value=Foo.class, "
 404                 + "getAnnotationVal = \"@Foo(value=2)\", "
 405                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=2)\"}, "
 406                 + // override every annotation on superClass
 407                 "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=2)\"}, "
 408                 + // ignores inherited annotations
 409                 "getDeclAnnoVal = \"@Foo(value=2)\", " // ignores inherited
 410                 + "getAnnosArgs = {\"@Foo(value=2)\"}, "
 411                 + "getDeclAnnosArgs = { \"@Foo(value=2)\" })", // ignores inherited
 412         "@ExpectedContainer(value=FooContainer.class, "
 413                 + "getAnnotationVal = \"NULL\", "
 414                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=2)\"}, "
 415                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=2)\"}, "
 416                 + // ignores inherited annotations
 417                 "getDeclAnnoVal = \"NULL\", " + // ignores inherited
 418                 "getAnnosArgs = {}, " + "getDeclAnnosArgs = {})") { // ignores inherited
 419 
 420             @Override
 421             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 422                     String className) {
 423                 String anno = "";
 424                 String replaceVal = "";
 425                 String contents = "";
 426                 JavaFileObject srcFileObj = null;
 427                 Iterable<? extends JavaFileObject> files = null;
 428 
 429                 String expectedVals = "\n" + getExpectedBase() + "\n"
 430                         + getExpectedContainer() + "\n";
 431                 StringBuilder commonStmts = new StringBuilder();
 432 
 433                 /*
 434                 Sample test src
 435                 @Retention(RetentionPolicy.RUNTIME)
 436                 @Inherited
 437                 @interface Foo {int value() default Integer.MAX_VALUE;}
 438 
 439                 @Inherited
 440                 @interface FooContainer {
 441                 Foo[] value();
 442                 }
 443 
 444                 @Foo(1)
 445                 class SuperClass { }
 446 
 447                 @ExpectedBase
 448                 @ExpectedContainer
 449                 @Foo(2)
 450                 class SubClass extends SuperClass {}
 451                  */
 452                 // @Inherited only works for classes, no switch cases for
 453                 // method, field, package
 454                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
 455                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
 456                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
 457                         .append(Helper.ContentVars.INHERITED.getVal())
 458                         .append(Helper.ContentVars.BASE.getVal())
 459                         .append(Helper.ContentVars.INHERITED.getVal())
 460                         .append(Helper.ContentVars.CONTAINER.getVal());
 461 
 462                 if (srcType == SrcType.CLASS) {
 463                     // Contents for SuperClass
 464                     anno = "@Foo(1)";
 465                     replaceVal = commonStmts + "\n" + anno;
 466                     String superClassContents = srcType.getTemplate()
 467                             .replace("#CN", SUPERCLASS).replace("#REPLACE", replaceVal);
 468 
 469                     // Contents for SubClass that extends SuperClass
 470                     anno = "@Foo(2)";
 471                     replaceVal = expectedVals + "\n" + anno;
 472                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
 473                             .replace("#CN", className).replace("#SN", SUPERCLASS)
 474                             .replace("#REPLACE", replaceVal);
 475 
 476                     contents = superClassContents + subClassContents;
 477                     srcFileObj = Helper.getFile(className, contents);
 478                     files = Arrays.asList(srcFileObj);
 479                 }
 480                 return files;
 481             }
 482         },
 483         BasicContainer_Legacy(
 484         "@ExpectedBase(value = Foo.class, "
 485                 + "getAnnotationVal = \"NULL\","
 486                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 487                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 488                 + "getDeclAnnoVal = \"NULL\", " + "getAnnosArgs = {}, "
 489                 + "getDeclAnnosArgs = {} )",
 490         "@ExpectedContainer(value=FooContainer.class, "
 491                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
 492                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 493                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 494                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
 495                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 496                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"} )") {
 497 
 498             @Override
 499             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 500                     String className) {
 501                 String anno = "";
 502                 String replaceVal = "";
 503                 String testSrc = "";
 504                 String pkgInfoContents = "";
 505                 String contents = "";
 506 
 507                 JavaFileObject pkgFileObj = null;
 508                 JavaFileObject srcFileObj = null;
 509                 Iterable<? extends JavaFileObject> files = null;
 510 
 511                 String expectedVals = "\n" + getExpectedBase() + "\n"
 512                         + getExpectedContainer() + "\n";
 513                 StringBuilder commonStmts = new StringBuilder();
 514 
 515                 anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
 516                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
 517                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
 518                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
 519                         .append(Helper.ContentVars.BASE.getVal())
 520                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
 521                         .append(Helper.ContentVars.CONTAINER.getVal());
 522                 switch (srcType) {
 523                     case PACKAGE:
 524                         /*
 525                         Sample package-info.java
 526                         @ExpectedBase
 527                         @ExpectedContainer
 528                         @FooContainer(value = {@Foo(1), @Foo(2)})
 529                         package testpkg;
 530 
 531                         @Retention(RetentionPolicy.RUNTIME)
 532                         @interface Foo {int value() default Integer.MAX_VALUE;}
 533 
 534                         @Retention(RetentionPolicy.RUNTIME)
 535                         @interface FooContainer {
 536                         Foo[] value();
 537                         }
 538 
 539                         Sample testSrc:
 540                         package testpkg;
 541                         class A {}
 542                          */
 543                         testSrc = srcType.getTemplate().replace("#CN", className);
 544                         contents = testSrc;
 545                         srcFileObj = Helper.getFile(className, contents);
 546 
 547                         replaceVal = "\n" + expectedVals + "\n" + anno;
 548                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
 549                                 .replace("#REPLACE1", replaceVal)
 550                                 .replace("#REPLACE2", commonStmts);
 551                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
 552                         files = Arrays.asList(pkgFileObj, srcFileObj);
 553                         break;
 554                     default:
 555                         /*
 556                         Sample testSrc for class:
 557                         @Retention(RetentionPolicy.RUNTIME)
 558                         @Inherited
 559                         @interface Foo {int value() default Integer.MAX_VALUE;}
 560 
 561                         @Retention(RetentionPolicy.RUNTIME)
 562                         @Inherited
 563                         @interface FooContainer {
 564                         Foo[] value();
 565                         }
 566 
 567                         @ExpectedBase
 568                         @ExpectedContainer
 569                         @FooContainer(value = {@Foo(1), @Foo(2)})
 570                         class A {}
 571                          */
 572                         replaceVal = expectedVals + anno;
 573                         testSrc = srcType.getTemplate().replace("#CN", className)
 574                                 .replace("#REPLACE", replaceVal);
 575                         contents = commonStmts + testSrc;
 576                         srcFileObj = Helper.getFile(className, contents);
 577                         files = Arrays.asList(srcFileObj);
 578                 }
 579                 return files;
 580             }
 581         },
 582         SingleAndContainerOnSuper_Legacy(
 583         "@ExpectedBase(value = Foo.class, "
 584                 + "getAnnotationVal = \"@Foo(value=0)\","
 585                 + "getAnnotationsVals = {"
 586                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 587                 + "getDeclAnnosVals = {"
 588                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 589                 + "getDeclAnnoVal = \"@Foo(value=0)\", "
 590                 + "getAnnosArgs = {\"@Foo(value=0)\"}, "
 591                 + "getDeclAnnosArgs = {\"@Foo(value=0)\"} )",
 592         "@ExpectedContainer(value=FooContainer.class, "
 593                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
 594                 + "getAnnotationsVals = {"
 595                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 596                 + "getDeclAnnosVals = {"
 597                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 598                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
 599                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 600                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"} )") {
 601 
 602             @Override
 603             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 604                     String className) {
 605                 String anno = "";
 606                 String replaceVal = "";
 607                 String testSrc = "";
 608                 String pkgInfoContents = "";
 609                 String contents = "";
 610 
 611                 JavaFileObject pkgFileObj = null;
 612                 JavaFileObject srcFileObj = null;
 613                 Iterable<? extends JavaFileObject> files = null;
 614 
 615                 String expectedVals = "\n" + getExpectedBase() + "\n"
 616                         + getExpectedContainer() + "\n";
 617                 StringBuilder commonStmts = new StringBuilder();
 618 
 619                 anno = Helper.ContentVars.BASEANNO.getVal() +
 620                        Helper.ContentVars.LEGACYCONTAINER.getVal();
 621                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
 622                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
 623                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
 624                         .append(Helper.ContentVars.BASE.getVal())
 625                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
 626                         .append(Helper.ContentVars.CONTAINER.getVal());
 627                 switch (srcType) {
 628                     case PACKAGE:
 629                         /*
 630                         Sample package-info.java
 631                         @ExpectedBase
 632                         @ExpectedContainer
 633                         @Foo(0)
 634                         @FooContainer(value = {@Foo(1), @Foo(2)})
 635                         package testpkg;
 636 
 637                         @Retention(RetentionPolicy.RUNTIME)
 638                         @interface Foo {int value() default Integer.MAX_VALUE;}
 639 
 640                         @Retention(RetentionPolicy.RUNTIME)
 641                         @interface FooContainer {
 642                         Foo[] value();
 643                         }
 644 
 645                         Sample testSrc:
 646                         package testpkg;
 647                         class A {}
 648                          */
 649                         testSrc = srcType.getTemplate().replace("#CN", className);
 650                         contents = testSrc;
 651 
 652                         srcFileObj = Helper.getFile(className, contents);
 653 
 654                         replaceVal = "\n" + expectedVals + "\n" + anno;
 655                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
 656                                 .replace("#REPLACE1", replaceVal)
 657                                 .replace("#REPLACE2", commonStmts);
 658                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
 659                         files = Arrays.asList(pkgFileObj, srcFileObj);
 660                         break;
 661                     default:
 662                         /*
 663                         Sample testSrc for class:
 664                         @Retention(RetentionPolicy.RUNTIME)
 665                         @Inherited
 666                         @interface Foo {int value() default Integer.MAX_VALUE;}
 667 
 668                         @Retention(RetentionPolicy.RUNTIME)
 669                         @Inherited
 670                         @interface FooContainer {
 671                         Foo[] value();
 672                         }
 673 
 674                         @ExpectedBase
 675                         @ExpectedContainer
 676                         @Foo(0)
 677                         @FooContainer(value = {@Foo(1), @Foo(2)})
 678                         class A {}
 679                          */
 680                         replaceVal = expectedVals + anno;
 681                         testSrc = srcType.getTemplate().replace("#CN", className)
 682                                 .replace("#REPLACE", replaceVal);
 683                         contents = commonStmts + testSrc;
 684 
 685                         srcFileObj = Helper.getFile(className, contents);
 686                         files = Arrays.asList(srcFileObj);
 687                 }
 688                 return files;
 689             }
 690         },
 691         BasicContainer_Inherited_Legacy(
 692         "@ExpectedBase(value = Foo.class, "
 693                 + "getAnnotationVal = \"NULL\","
 694                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 695                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
 696                 + "getDeclAnnoVal = \"NULL\", "
 697                 + "getAnnosArgs = {}, "
 698                 + "getDeclAnnosArgs = {} )",
 699         "@ExpectedContainer(value=FooContainer.class, "
 700                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
 701                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 702                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
 703                 + "getDeclAnnoVal = \"NULL\", "
 704                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 705                 + "getDeclAnnosArgs = {} )") {
 706 
 707             @Override
 708             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 709                     String className) {
 710                 String anno = "";
 711                 String replaceVal = "";
 712                 String contents = "";
 713                 JavaFileObject srcFileObj = null;
 714                 Iterable<? extends JavaFileObject> files = null;
 715 
 716                 String expectedVals = "\n" + getExpectedBase() + "\n"
 717                         + getExpectedContainer() + "\n";
 718                 StringBuilder commonStmts = getCommonStmts(false);
 719 
 720                 /*
 721                 Sample testSrc:
 722                 @Retention(RetentionPolicy.RUNTIME)
 723                 @Inherited
 724                 @interface Foo {int value() default Integer.MAX_VALUE;}
 725 
 726                 @Retention(RetentionPolicy.RUNTIME)
 727                 @Inherited
 728                 @interface FooContainer {
 729                 Foo[] value();
 730                 }
 731 
 732                 @FooContainer(value = {@Foo(1), @Foo(2)})
 733                 class SuperClass { }
 734 
 735                 @ExpectedBase
 736                 @ExpectedContainer
 737                 class SubClass extends SuperClass {}
 738                  */
 739                 // @Inherited only works for classes, no switch cases for
 740                 // method, field, package
 741 
 742                 if (srcType == SrcType.CLASS) {
 743                     // Contents for SuperClass
 744                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
 745                     replaceVal = commonStmts + "\n" + anno;
 746                     String superClassContents = srcType.getTemplate()
 747                             .replace("#CN", SUPERCLASS)
 748                             .replace("#REPLACE", replaceVal);
 749 
 750                     // Contents for SubClass that extends SuperClass
 751                     replaceVal = expectedVals;
 752                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
 753                             .replace("#CN", className)
 754                             .replace("#SN", SUPERCLASS)
 755                             .replace("#REPLACE", replaceVal);
 756 
 757                     contents = superClassContents + subClassContents;
 758                     srcFileObj = Helper.getFile(className, contents);
 759                     files = Arrays.asList(srcFileObj);
 760                 }
 761                 return files;
 762             }
 763         },
 764         ContainerOnSuperSingleOnSub_Inherited_Legacy(
 765         "@ExpectedBase(value=Foo.class, "
 766                 + "getAnnotationVal = \"@Foo(value=0)\", "
 767                 + "getAnnotationsVals = {"
 768                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=0)\"}, "
 769                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"},"
 770                 + "getDeclAnnoVal = \"@Foo(value=0)\","
 771                 + "getAnnosArgs = {\"@Foo(value=0)\"},"
 772                 + "getDeclAnnosArgs = {\"@Foo(value=0)\"})",
 773         "@ExpectedContainer(value=FooContainer.class, "
 774                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
 775                 + "getAnnotationsVals = {"
 776                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=0)\"}, "
 777                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"},"
 778                 + "getDeclAnnoVal = \"NULL\","
 779                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
 780                 + "getDeclAnnosArgs = {})") {
 781 
 782             @Override
 783             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 784                     String className) {
 785                 String anno = "";
 786                 String replaceVal = "";
 787                 String contents = "";
 788                 JavaFileObject srcFileObj = null;
 789                 Iterable<? extends JavaFileObject> files = null;
 790 
 791                 String expectedVals = "\n" + getExpectedBase() + "\n"
 792                         + getExpectedContainer() + "\n";
 793                 StringBuilder commonStmts = getCommonStmts(false);
 794 
 795                 /*
 796                 Sample testSrc:
 797                 @Retention(RetentionPolicy.RUNTIME)
 798                 @Inherited
 799                 @interface Foo {int value() default Integer.MAX_VALUE;}
 800 
 801                 @Retention(RetentionPolicy.RUNTIME)
 802                 @Inherited
 803                 @interface FooContainer {
 804                 Foo[] value();
 805                 }
 806 
 807                 @FooContainer(value = {@Foo(1), @Foo(2)})
 808                 class SuperClass { }
 809 
 810                 @ExpectedBase
 811                 @ExpectedContainer
 812                 @Foo(0)
 813                 class SubClass extends SuperClass {}
 814                  */
 815                 // @Inherited only works for classes, no switch cases for
 816                 // method, field, package
 817 
 818                 if (srcType == SrcType.CLASS) {
 819                     // Contents for SuperClass
 820                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
 821                     replaceVal = commonStmts + "\n" + anno;
 822                     String superClassContents = srcType.getTemplate()
 823                             .replace("#CN", SUPERCLASS)
 824                             .replace("#REPLACE", replaceVal);
 825 
 826                     // Contents for SubClass that extends SuperClass
 827                     anno = Helper.ContentVars.BASEANNO.getVal();
 828                     replaceVal = expectedVals + "\n" + anno;
 829                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
 830                             .replace("#CN", className)
 831                             .replace("#SN", SUPERCLASS)
 832                             .replace("#REPLACE", replaceVal);
 833 
 834                     contents = superClassContents + subClassContents;
 835                     srcFileObj = Helper.getFile(className, contents);
 836                     files = Arrays.asList(srcFileObj);
 837                 }
 838                 return files;
 839             }
 840         },
 841         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
 842         // fail with ordering issues
 843         ContainerAndSingleOnSuperSingleOnSub_Inherited_Legacy(
 844         "@ExpectedBase(value=Foo.class, "
 845                 + "getAnnotationVal = \"@Foo(value=0)\", "
 846                 + "getAnnotationsVals = {"
 847                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=0)\"}, "
 848                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"},"
 849                 + "getDeclAnnoVal = \"@Foo(value=0)\","
 850                 + "getAnnosArgs = {\"@Foo(value=0)\"},"
 851                 + "getDeclAnnosArgs = {\"@Foo(value=0)\"})",
 852         "@ExpectedContainer(value=FooContainer.class, "
 853                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
 854                 + "getAnnotationsVals = {"
 855                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=0)\"}, "
 856                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"},"
 857                 + "getDeclAnnoVal = \"NULL\","
 858                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
 859                 + "getDeclAnnosArgs = {})") {
 860 
 861             @Override
 862             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 863                     String className) {
 864                 String anno = "";
 865                 String replaceVal = "";
 866                 String contents = "";
 867                 JavaFileObject srcFileObj = null;
 868                 Iterable<? extends JavaFileObject> files = null;
 869 
 870                 String expectedVals = "\n" + getExpectedBase() + "\n"
 871                         + getExpectedContainer() + "\n";
 872                 StringBuilder commonStmts = getCommonStmts(false);
 873 
 874                 /*
 875                 Sample testSrc:
 876                 @Retention(RetentionPolicy.RUNTIME)
 877                 @Inherited
 878                 @interface Foo {int value() default Integer.MAX_VALUE;}
 879 
 880                 @Retention(RetentionPolicy.RUNTIME)
 881                 @Inherited
 882                 @interface FooContainer {
 883                 Foo[] value();
 884                 }
 885 
 886                 @FooContainer(value = {@Foo(1), @Foo(2)}) @Foo(3)
 887                 class SuperClass { }
 888 
 889                 @ExpectedBase
 890                 @ExpectedContainer
 891                 @Foo(0)
 892                 class SubClass extends SuperClass {}
 893                  */
 894                 // @Inherited only works for classes, no switch cases for
 895                 // method, field, package
 896 
 897                 if (srcType == SrcType.CLASS) {
 898                     // Contents for SuperClass
 899                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
 900                             + "@Foo(3)";
 901                     replaceVal = commonStmts + "\n" + anno;
 902                     String superClassContents = srcType.getTemplate()
 903                             .replace("#CN", SUPERCLASS)
 904                             .replace("#REPLACE", replaceVal);
 905 
 906                     // Contents for SubClass that extends SuperClass
 907                     anno = Helper.ContentVars.BASEANNO.getVal();
 908                     replaceVal = expectedVals + "\n" + anno;
 909                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
 910                             .replace("#CN", className).replace("#SN", SUPERCLASS)
 911                             .replace("#REPLACE", replaceVal);
 912 
 913                     contents = superClassContents + subClassContents;
 914                     srcFileObj = Helper.getFile(className, contents);
 915                     files = Arrays.asList(srcFileObj);
 916                 }
 917                 return files;
 918             }
 919         },
 920         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
 921         // fail with ordering issues
 922         SingleOnSuperContainerOnSub_Inherited_Legacy(
 923         "@ExpectedBase(value=Foo.class, "
 924                 + "getAnnotationVal = \"@Foo(value=0)\", "
 925                 + "getAnnotationsVals = {"
 926                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 927                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
 928                 + "getDeclAnnoVal = \"NULL\","
 929                 + "getAnnosArgs = {\"@Foo(value=0)\"},"
 930                 + "getDeclAnnosArgs = {})",
 931         "@ExpectedContainer(value=FooContainer.class, "
 932                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
 933                 + "getAnnotationsVals = {"
 934                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
 935                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
 936                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
 937                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
 938                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"})") {
 939 
 940             @Override
 941             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
 942                     String className) {
 943                 String anno = "";
 944                 String replaceVal = "";
 945                 String contents = "";
 946 
 947                 JavaFileObject srcFileObj = null;
 948                 Iterable<? extends JavaFileObject> files = null;
 949 
 950                 String expectedVals = "\n" + getExpectedBase() + "\n"
 951                         + getExpectedContainer() + "\n";
 952                 StringBuilder commonStmts = getCommonStmts(false);
 953 
 954                 /*
 955                 Sample testSrc:
 956                 @Retention(RetentionPolicy.RUNTIME)
 957                 @Inherited
 958                 @interface Foo {int value() default Integer.MAX_VALUE;}
 959 
 960                 @Retention(RetentionPolicy.RUNTIME)
 961                 @Inherited
 962                 @interface FooContainer {
 963                 Foo[] value();
 964                 }
 965 
 966                 @Foo(0)
 967                 class SuperClass { }
 968 
 969                 @ExpectedBase
 970                 @ExpectedContainer
 971                 @FooContainer(value = {@Foo(1), @Foo(2)})
 972                 class SubClass extends SuperClass {}
 973                  */
 974 
 975                 if (srcType == SrcType.CLASS) {
 976                     //Contents for SuperClass
 977                     anno = Helper.ContentVars.BASEANNO.getVal();
 978                     replaceVal = commonStmts + "\n" + anno;
 979                     String superClassContents = srcType.getTemplate()
 980                             .replace("#CN", SUPERCLASS)
 981                             .replace("#REPLACE", replaceVal);
 982 
 983                     //Contents for SubClass that extends SuperClass
 984                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
 985                     replaceVal = expectedVals + "\n" + anno;
 986                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
 987                             .replace("#CN", className).replace("#SN", SUPERCLASS)
 988                             .replace("#REPLACE", replaceVal);
 989 
 990                     contents = superClassContents + subClassContents;
 991                     srcFileObj = Helper.getFile(className, contents);
 992                     files = Arrays.asList(srcFileObj);
 993                 }
 994                 return files;
 995             }
 996         },
 997         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
 998         // fail with ordering issues
 999         SingleOnSuperContainerAndSingleOnSub_Inherited_Legacy(
1000         "@ExpectedBase(value=Foo.class, "
1001                 + "getAnnotationVal = \"@Foo(value=3)\", "
1002                 + "getAnnotationsVals = {"
1003                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=3)\"}, "
1004                 + "getDeclAnnosVals = {"
1005                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=3)\"},"
1006                 + "getDeclAnnoVal = \"@Foo(value=3)\","
1007                 + "getAnnosArgs = {\"@Foo(value=3)\"},"
1008                 + "getDeclAnnosArgs = {\"@Foo(value=3)\"})",
1009         "@ExpectedContainer(value=FooContainer.class, "
1010                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1011                 + "getAnnotationsVals = {"
1012                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=3)\"}, "
1013                 + "getDeclAnnosVals = {"
1014                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=3)\"},"
1015                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
1016                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1017                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"})") {
1018 
1019             @Override
1020             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1021                     String className) {
1022                 String anno = "";
1023                 String replaceVal = "";
1024                 String contents = "";
1025 
1026                 JavaFileObject srcFileObj = null;
1027                 Iterable<? extends JavaFileObject> files = null;
1028 
1029                 String expectedVals = "\n" + getExpectedBase() + "\n"
1030                         + getExpectedContainer() + "\n";
1031                 StringBuilder commonStmts = getCommonStmts(false);
1032 
1033                 /*
1034                 Sample testSrc:
1035                 @Retention(RetentionPolicy.RUNTIME)
1036                 @Inherited
1037                 @interface Foo {int value() default Integer.MAX_VALUE;}
1038 
1039                 @Retention(RetentionPolicy.RUNTIME)
1040                 @Inherited
1041                 @interface FooContainer {
1042                 Foo[] value();
1043                 }
1044 
1045                 @Foo(0)
1046                 class SuperClass { }
1047 
1048                 @ExpectedBase
1049                 @ExpectedContainer
1050                 @FooContainer(value = {@Foo(1), @Foo(2)}) @Foo(3)
1051                 class SubClass extends SuperClass {}
1052                  */
1053 
1054                 if (srcType == SrcType.CLASS) {
1055                     //Contents for SuperClass
1056                     anno = Helper.ContentVars.BASEANNO.getVal();
1057                     replaceVal = commonStmts + "\n" + anno;
1058                     String superClassContents = srcType.getTemplate()
1059                             .replace("#CN", SUPERCLASS)
1060                             .replace("#REPLACE", replaceVal);
1061 
1062                     //Contents for SubClass that extends SuperClass
1063                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
1064                             + "@Foo(3)";
1065                     replaceVal = expectedVals + "\n" + anno;
1066                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
1067                             .replace("#CN", className).replace("#SN", SUPERCLASS)
1068                             .replace("#REPLACE", replaceVal);
1069 
1070                     contents = superClassContents + subClassContents;
1071                     srcFileObj = Helper.getFile(className, contents);
1072                     files = Arrays.asList(srcFileObj);
1073                 }
1074                 return files;
1075             }
1076         },
1077         BasicRepeatable(
1078         "@ExpectedBase(value=Foo.class, "
1079                 + "getAnnotationVal = \"NULL\", "
1080                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\" }, "
1081                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1082                 + "getDeclAnnoVal = \"NULL\","
1083                 + "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"},"
1084                 + "getDeclAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"})",
1085         "@ExpectedContainer(value=FooContainer.class, "
1086                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
1087                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1088                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1089                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
1090                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1091                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"} )") {
1092 
1093             @Override
1094             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1095                     String className) {
1096                 String anno = "";
1097                 String replaceVal = "";
1098                 String testSrc = "";
1099                 String pkgInfoContents = "";
1100                 String contents = "";
1101 
1102                 JavaFileObject pkgFileObj = null;
1103                 JavaFileObject srcFileObj = null;
1104                 Iterable<? extends JavaFileObject> files = null;
1105 
1106                 String expectedVals = "\n" + getExpectedBase() + "\n"
1107                         + getExpectedContainer() + "\n";
1108                 StringBuilder commonStmts = new StringBuilder();
1109 
1110                 anno = Helper.ContentVars.REPEATABLEANNO.getVal();
1111                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
1112                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
1113                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
1114                         .append(Helper.ContentVars.REPEATABLE.getVal())
1115                         .append(Helper.ContentVars.BASE.getVal())
1116                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
1117                         .append(Helper.ContentVars.CONTAINER.getVal());
1118                 switch (srcType) {
1119                     case PACKAGE:
1120                         /*
1121                         Sample package-info.java
1122                         @ExpectedBase
1123                         @ExpectedContainer
1124                         @Foo(1) @Foo(2)
1125                         package testpkg;
1126 
1127                         @Retention(RetentionPolicy.RUNTIME)
1128                         @Repeatable(FooContainer.class)
1129                         @interface Foo {int value() default Integer.MAX_VALUE;}
1130 
1131                         @Retention(RetentionPolicy.RUNTIME)
1132                         @interface FooContainer {
1133                         Foo[] value();
1134                         }
1135 
1136                         Sample testSrc:
1137                         package testpkg;
1138                         class A {}
1139                          */
1140                         testSrc = srcType.getTemplate().replace("#CN", className);
1141                         contents = testSrc;
1142                         srcFileObj = Helper.getFile(className, contents);
1143 
1144                         replaceVal = expectedVals + "\n" + anno;
1145                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
1146                                 .replace("#REPLACE1", replaceVal)
1147                                 .replace("#REPLACE2", commonStmts);
1148                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
1149                         files = Arrays.asList(pkgFileObj, srcFileObj);
1150                         break;
1151                     default:
1152                         /*
1153                         Sample testSrc for class:
1154                         @Retention(RetentionPolicy.RUNTIME)
1155                         @Repeatable(FooContainer.class)
1156                         @interface Foo {int value() default Integer.MAX_VALUE;}
1157 
1158                         @Retention(RetentionPolicy.RUNTIME)
1159                         @interface FooContainer {
1160                         Foo[] value();
1161                         }
1162 
1163                         @ExpectedBase
1164                         @ExpectedContainer
1165                         @Foo(1) @Foo(2)
1166                         class A { }
1167                          */
1168                         replaceVal = expectedVals + anno;
1169                         testSrc = srcType.getTemplate().replace("#CN", className)
1170                                 .replace("#REPLACE", replaceVal);
1171                         contents = commonStmts + testSrc;
1172                         srcFileObj = Helper.getFile(className, contents);
1173                         files = Arrays.asList(srcFileObj);
1174                 }
1175                 return files;
1176             }
1177         },
1178         BasicContainerRepeatable(
1179         "@ExpectedBase(value=Foo.class, "
1180                 + "getAnnotationVal = \"NULL\", "
1181                 + "getAnnotationsVals = {"
1182                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1183                 + "getDeclAnnosVals = {"
1184                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1185                 + "getDeclAnnoVal = \"NULL\","
1186                 + "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"},"
1187                 + "getDeclAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"})",
1188         "@ExpectedContainer(value=FooContainer.class, "
1189                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
1190                 + "getAnnotationsVals = {"
1191                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1192                 + "getDeclAnnosVals = {"
1193                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1194                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
1195                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1196                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"} )") {
1197 
1198             @Override
1199             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1200                     String className) {
1201                 String anno = "";
1202                 String replaceVal = "";
1203                 String testSrc = "";
1204                 String pkgInfoContents = "";
1205                 String contents = "";
1206 
1207                 JavaFileObject pkgFileObj = null;
1208                 JavaFileObject srcFileObj = null;
1209                 Iterable<? extends JavaFileObject> files = null;
1210 
1211                 String expectedVals = "\n" + getExpectedBase() + "\n"
1212                         + getExpectedContainer() + "\n";
1213                 StringBuilder commonStmts = new StringBuilder();
1214 
1215                 anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
1216                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
1217                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
1218                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
1219                         .append(Helper.ContentVars.REPEATABLE.getVal())
1220                         .append(Helper.ContentVars.BASE.getVal())
1221                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
1222                         .append(Helper.ContentVars.CONTAINER.getVal());
1223                 switch (srcType) {
1224                     case PACKAGE:
1225                         /*
1226                         Sample package-info.java
1227                         @ExpectedBase
1228                         @ExpectedContainer
1229                         @FooContainer(value = {@Foo(1), @Foo(2)})
1230                         package testpkg;
1231 
1232                         @Retention(RetentionPolicy.RUNTIME)
1233                         @Repeatable(FooContainer.class)
1234                         @interface Foo {int value() default Integer.MAX_VALUE;}
1235 
1236                         @Retention(RetentionPolicy.RUNTIME)
1237                         @interface FooContainer {
1238                         Foo[] value();
1239                         }
1240 
1241                         Sample testSrc:
1242                         package testpkg;
1243                         class A {}
1244                          */
1245                         testSrc = srcType.getTemplate().replace("#CN", className);
1246                         contents = testSrc;
1247                         srcFileObj = Helper.getFile(className, contents);
1248 
1249                         replaceVal = expectedVals + "\n" + anno;
1250                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
1251                                 .replace("#REPLACE1", replaceVal)
1252                                 .replace("#REPLACE2", commonStmts);
1253                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
1254                         files = Arrays.asList(pkgFileObj, srcFileObj);
1255                         break;
1256                     default:
1257                         /*
1258                         Sample testSrc for class:
1259                         @Retention(RetentionPolicy.RUNTIME)
1260                         @Repeatable(FooContainer.class)
1261                         @interface Foo {int value() default Integer.MAX_VALUE;}
1262 
1263                         @Retention(RetentionPolicy.RUNTIME)
1264                         @interface FooContainer {
1265                         Foo[] value();
1266                         }
1267 
1268                         @ExpectedBase
1269                         @ExpectedContainer
1270                         @FooContainer(value = {@Foo(1), @Foo(2)})
1271                         class A { }
1272                          */
1273                         replaceVal = expectedVals + anno;
1274                         testSrc = srcType.getTemplate().replace("#CN", className)
1275                                 .replace("#REPLACE", replaceVal);
1276                         contents = commonStmts + testSrc;
1277                         srcFileObj = Helper.getFile(className, contents);
1278                         files = Arrays.asList(srcFileObj);
1279                 }
1280                 return files;
1281             }
1282         },
1283         BasicContainerRepeatable_Inherited(
1284         "@ExpectedBase(value=Foo.class, "
1285                 + "getAnnotationVal = \"NULL\", "
1286                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1287                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
1288                 + "getDeclAnnoVal = \"NULL\", "
1289                 + "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"}, "
1290                 + "getDeclAnnosArgs = {})",
1291         "@ExpectedContainer(value=FooContainer.class, "
1292                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1293                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1294                 + "getDeclAnnosVals = { \"ExpectedBase\", \"ExpectedContainer\"}, "
1295                 + "getDeclAnnoVal = \"NULL\", "
1296                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1297                 + "getDeclAnnosArgs = {})") {
1298 
1299             @Override
1300             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1301                     String className) {
1302                 String anno = "";
1303                 String replaceVal = "";
1304                 String contents = "";
1305                 JavaFileObject srcFileObj = null;
1306                 Iterable<? extends JavaFileObject> files = null;
1307 
1308                 String expectedVals = "\n" + getExpectedBase() + "\n"
1309                         + getExpectedContainer() + "\n";
1310                 StringBuilder commonStmts = getCommonStmts(true);
1311                 /*
1312                 Sample testSrc:
1313                 @Retention(RetentionPolicy.RUNTIME)
1314                 @Inherited
1315                 @Repeatable(FooContainer.class)
1316                 @interface Foo {int value() default Integer.MAX_VALUE;}
1317 
1318                 @Retention(RetentionPolicy.RUNTIME)
1319                 @Inherited
1320                 @interface FooContainer {
1321                 Foo[] value();
1322                 }
1323 
1324                 @FooContainer(value = {@Foo(1), @Foo(2)})
1325                 class SuperClass { }
1326 
1327                 @ExpectedBase
1328                 @ExpectedContainer
1329                 class SubClass extends SuperClass { }
1330                  */
1331                 // @Inherited only works for classes, no switch cases for
1332                 // method, field, package
1333                 anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
1334 
1335                 if (srcType == SrcType.CLASS) {
1336                     // Contents for SuperClass
1337                     replaceVal = commonStmts + "\n" + anno;
1338                     String superClassContents = srcType.getTemplate()
1339                             .replace("#CN", SUPERCLASS)
1340                             .replace("#REPLACE", replaceVal);
1341 
1342                     // Contents for SubClass that extends SuperClass
1343                     replaceVal = expectedVals;
1344                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
1345                             .replace("#CN", className)
1346                             .replace("#SN", SUPERCLASS)
1347                             .replace("#REPLACE", replaceVal);
1348 
1349                     contents = superClassContents + subClassContents;
1350                     srcFileObj = Helper.getFile(className, contents);
1351                     files = Arrays.asList(srcFileObj);
1352                 }
1353                 return files;
1354             }
1355         },
1356         RepeatableAnnoInherited(
1357         "@ExpectedBase(value=Foo.class, "
1358                 + "getAnnotationVal = \"NULL\", "
1359                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1360                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
1361                 + // ignores inherited annotations
1362                 "getDeclAnnoVal = \"NULL\", "
1363                 + // ignores inherited
1364                 "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"}, "
1365                 + "getDeclAnnosArgs = {})", // ignores inherited
1366         "@ExpectedContainer(value=FooContainer.class, "
1367                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1368                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1369                 + "getDeclAnnosVals = { \"ExpectedBase\", \"ExpectedContainer\"}, "
1370                 + // ignores inherited annotations
1371                 "getDeclAnnoVal = \"NULL\", "
1372                 + // ignores inherited
1373                 "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1374                 + "getDeclAnnosArgs = {})") { // ignores inherited
1375 
1376             @Override
1377             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1378                     String className) {
1379                 String anno = "";
1380                 String replaceVal = "";
1381                 String contents = "";
1382                 JavaFileObject srcFileObj = null;
1383                 Iterable<? extends JavaFileObject> files = null;
1384 
1385                 String expectedVals = "\n" + getExpectedBase() + "\n"
1386                         + getExpectedContainer() + "\n";
1387                 StringBuilder commonStmts = getCommonStmts(true);
1388                 /*
1389                 Sample testSrc:
1390                 @Retention(RetentionPolicy.RUNTIME)
1391                 @Inherited
1392                 @Repeatable(FooContainer.class)
1393                 @interface Foo {int value() default Integer.MAX_VALUE;}
1394 
1395                 @Retention(RetentionPolicy.RUNTIME)
1396                 @Inherited
1397                 @interface FooContainer {
1398                 Foo[] value();
1399                 }
1400 
1401                 @Foo(1) @Foo(2)
1402                 class SuperClass { }
1403 
1404                 @ExpectedBase
1405                 @ExpectedContainer
1406                 class SubClass extends SuperClass { }
1407                  */
1408                 // @Inherited only works for classes, no switch cases for
1409                 // method, field, package
1410                 anno = Helper.ContentVars.REPEATABLEANNO.getVal();
1411 
1412                 if (srcType == SrcType.CLASS) {
1413                     // Contents for SuperClass
1414                     replaceVal = commonStmts + "\n" + anno;
1415                     String superClassContents = srcType.getTemplate()
1416                             .replace("#CN", SUPERCLASS)
1417                             .replace("#REPLACE", replaceVal);
1418 
1419                     // Contents for SubClass that extends SuperClass
1420                     replaceVal = expectedVals;
1421                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
1422                             .replace("#CN", className)
1423                             .replace("#SN", SUPERCLASS)
1424                             .replace("#REPLACE", replaceVal);
1425 
1426                     contents = superClassContents + subClassContents;
1427                     srcFileObj = Helper.getFile(className, contents);
1428                     files = Arrays.asList(srcFileObj);
1429                 }
1430                 return files;
1431             }
1432         },
1433         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
1434         // fail with ordering issues
1435         SingleAnnoWithContainer(
1436         "@ExpectedBase(value=Foo.class, "
1437                 + "getAnnotationVal = \"@Foo(value=0)\", "
1438                 + "getAnnotationsVals = {"
1439                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1440                 + "getDeclAnnosVals = {"
1441                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1442                 + "getDeclAnnoVal = \"@Foo(value=0)\","
1443                 + "getAnnosArgs = {\"@Foo(value=0)\", \"@Foo(value=1)\", \"@Foo(value=2)\"},"
1444                 + "getDeclAnnosArgs = {\"@Foo(value=0)\", \"@Foo(value=1)\",\"@Foo(value=2)\"})",
1445         "@ExpectedContainer(value=FooContainer.class, "
1446                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1447                 + "getAnnotationsVals = {"
1448                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1449                 + "getDeclAnnosVals = {"
1450                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1451                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
1452                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1453                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"})") {
1454 
1455             @Override
1456             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1457                     String className) {
1458                 String anno = "";
1459                 String replaceVal = "";
1460                 String testSrc = "";
1461                 String pkgInfoContents = "";
1462                 String contents = "";
1463 
1464                 JavaFileObject pkgFileObj = null;
1465                 JavaFileObject srcFileObj = null;
1466                 Iterable<? extends JavaFileObject> files = null;
1467 
1468                 String expectedVals = "\n" + getExpectedBase() + "\n"
1469                         + getExpectedContainer() + "\n";
1470                 StringBuilder commonStmts = new StringBuilder();
1471 
1472                 anno = Helper.ContentVars.BASEANNO.getVal() + " "
1473                         + Helper.ContentVars.LEGACYCONTAINER.getVal();
1474                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
1475                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
1476                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
1477                         .append(Helper.ContentVars.REPEATABLE.getVal())
1478                         .append(Helper.ContentVars.BASE.getVal())
1479                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
1480                         .append(Helper.ContentVars.CONTAINER.getVal());
1481                 switch (srcType) {
1482                     case PACKAGE:
1483                         /*
1484                         Sample package-info.java
1485                         @ExpectedBase
1486                         @ExpectedContainer
1487                         @Foo(0) @FooContainer(value = {@Foo(1), @Foo(2)})
1488                         package testpkg;
1489 
1490                         @Retention(RetentionPolicy.RUNTIME)
1491                         @Repeatable(FooContainer.class)
1492                         @interface Foo {int value() default Integer.MAX_VALUE;}
1493 
1494                         @Retention(RetentionPolicy.RUNTIME)
1495                         @interface FooContainer {
1496                         Foo[] value();
1497                         }
1498 
1499                         Sample testSrc:
1500                         package testpkg;
1501                         class A {}
1502                          */
1503                         testSrc = srcType.getTemplate().replace("#CN", className);
1504                         contents = testSrc;
1505                         srcFileObj = Helper.getFile(className, contents);
1506 
1507                         replaceVal = expectedVals + "\n" + anno;
1508                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
1509                                 .replace("#REPLACE1", replaceVal)
1510                                 .replace("#REPLACE2", commonStmts);
1511                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
1512                         files = Arrays.asList(pkgFileObj, srcFileObj);
1513                         break;
1514                     default:
1515                         /*
1516                         Sample testSrc:
1517                         @Retention(RetentionPolicy.RUNTIME)
1518                         @Inherited
1519                         @Repeatable(FooContainer.class)
1520                         @interface Foo {int value() default Integer.MAX_VALUE;}
1521 
1522                         @Retention(RetentionPolicy.RUNTIME)
1523                         @Inherited
1524                         @interface FooContainer {
1525                         Foo[] value();
1526                         }
1527 
1528                         @ExpectedBase
1529                         @ExpectedContainer
1530                         @Foo(0) @FooContainer(value = {@Foo(1), @Foo(2)})
1531                         class A { }
1532                          */
1533                         replaceVal = expectedVals + anno;
1534                         testSrc = srcType.getTemplate()
1535                                 .replace("#CN", className)
1536                                 .replace("#REPLACE", replaceVal);
1537                         contents = commonStmts + testSrc;
1538                         srcFileObj = Helper.getFile(className, contents);
1539                         files = Arrays.asList(srcFileObj);
1540                 }
1541                 return files;
1542             }
1543         },
1544         AnnoOnSuperAndSubClass_Inherited(
1545         "@ExpectedBase(value=Foo.class, "
1546                 + "getAnnotationVal = \"@Foo(value=1)\", "
1547                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=1)\" }, "
1548                 + // override every annotation on superClass
1549                 "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=1)\"}, "
1550                 + // ignores inherited annotations
1551                 "getDeclAnnoVal = \"@Foo(value=1)\", " // ignores inherited
1552                 + "getAnnosArgs = {\"@Foo(value=1)\"}, "
1553                 + "getDeclAnnosArgs = { \"@Foo(value=1)\" })", // ignores inherited
1554         "@ExpectedContainer(value=FooContainer.class, "
1555                 + "getAnnotationVal = \"NULL\", "
1556                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=1)\" }, "
1557                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=1)\"}, "
1558                 + // ignores inherited annotations
1559                 "getDeclAnnoVal = \"NULL\", " + // ignores inherited
1560                 "getAnnosArgs = {}, " + "getDeclAnnosArgs = {})") {
1561 
1562             @Override
1563             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1564                     String className) {
1565                 String anno = "";
1566                 String replaceVal = "";
1567                 String contents = "";
1568                 JavaFileObject srcFileObj = null;
1569                 Iterable<? extends JavaFileObject> files = null;
1570 
1571                 String expectedVals = "\n" + getExpectedBase() + "\n"
1572                         + getExpectedContainer() + "\n";
1573                 StringBuilder commonStmts = getCommonStmts(true);
1574 
1575                 /*
1576                 Sample testSrc:
1577                 @Retention(RetentionPolicy.RUNTIME)
1578                 @Inherited
1579                 @Repeatable(FooContainer.class)
1580                 @interface Foo {int value() default Integer.MAX_VALUE;}
1581 
1582                 @Retention(RetentionPolicy.RUNTIME)
1583                 @Inherited
1584                 @interface FooContainer {
1585                 Foo[] value();
1586                 }
1587 
1588                 @Foo(0)
1589                 class SuperClass { }
1590 
1591                 @ExpectedBase
1592                 @ExpectedContainer
1593                 @Foo(1)
1594                 class SubClass extends SuperClass { }
1595                  */
1596                 // @Inherited only works for classes, no switch cases for
1597                 // method, field, package
1598 
1599                 if (srcType == SrcType.CLASS) {
1600                     // Contents for SuperClass
1601                     anno = Helper.ContentVars.BASEANNO.getVal();
1602                     replaceVal = commonStmts + "\n" + anno;
1603                     String superClassContents = srcType.getTemplate()
1604                             .replace("#CN", SUPERCLASS)
1605                             .replace("#REPLACE", replaceVal);
1606 
1607                     // Contents for SubClass that extends SuperClass
1608                     replaceVal = expectedVals + "\n" + "@Foo(1)";
1609                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
1610                             .replace("#CN", className)
1611                             .replace("#SN", SUPERCLASS)
1612                             .replace("#REPLACE", replaceVal);
1613 
1614                     contents = superClassContents + subClassContents;
1615                     srcFileObj = Helper.getFile(className, contents);
1616                     files = Arrays.asList(srcFileObj);
1617                 }
1618                 return files;
1619             }
1620         },
1621         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
1622         // fail with ordering issues
1623         RepeatableOnSuperSingleOnSub_Inherited(
1624         "@ExpectedBase(value=Foo.class, "
1625                 + "getAnnotationVal = \"@Foo(value=3)\", "
1626                 + "getAnnotationsVals = {"
1627                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=3)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1628                 + //override every annotation on superClass
1629                 "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=3)\"}, "
1630                 + // ignores inherited annotations
1631                 "getDeclAnnoVal = \"@Foo(value=3)\", " // ignores inherited
1632                 + "getAnnosArgs = {\"@Foo(value=3)\"}, "
1633                 + "getDeclAnnosArgs = { \"@Foo(value=3)\" })", // ignores inherited
1634         "@ExpectedContainer(value=FooContainer.class, "
1635                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1636                 + "getAnnotationsVals = {"
1637                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=3)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1638                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=3)\"}, "
1639                 + // ignores inherited annotations
1640                 "getDeclAnnoVal = \"NULL\", "
1641                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1642                 + "getDeclAnnosArgs = {}) // ignores inherited ") {
1643 
1644             @Override
1645             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1646                     String className) {
1647                 String anno = "";
1648                 String replaceVal = "";
1649                 String contents = "";
1650                 JavaFileObject srcFileObj = null;
1651                 Iterable<? extends JavaFileObject> files = null;
1652 
1653                 String expectedVals = "\n" + getExpectedBase() + "\n"
1654                         + getExpectedContainer() + "\n";
1655                 StringBuilder commonStmts = getCommonStmts(true);
1656 
1657                 /*
1658                  Sample testSrc:
1659                  @Retention(RetentionPolicy.RUNTIME)
1660                  @Inherited
1661                  @Repeatable(FooContainer.class)
1662                  @interface Foo {int value() default Integer.MAX_VALUE;}
1663 
1664                  @Retention(RetentionPolicy.RUNTIME)
1665                  @Inherited
1666                  @interface FooContainer {
1667                  Foo[] value();
1668                  }
1669 
1670                  @Foo(1) @Foo(2)
1671                  class SuperClass { }
1672 
1673                  @ExpectedBase
1674                  @ExpectedContainer
1675                  @Foo(3)
1676                  class SubClass extends SuperClass { }
1677                  */
1678                 //@Inherited only works for classes, no switch cases for method, field, package
1679                 if (srcType == SrcType.CLASS) {
1680                     //Contents for SuperClass
1681                     anno = Helper.ContentVars.REPEATABLEANNO.getVal();
1682                     replaceVal = commonStmts + "\n" + anno;
1683                     String superClassContents = srcType.getTemplate()
1684                             .replace("#CN", SUPERCLASS)
1685                             .replace("#REPLACE", replaceVal);
1686 
1687                     //Contents for SubClass that extends SuperClass
1688                     anno = "@Foo(3)";
1689                     replaceVal = expectedVals + "\n" + anno;
1690                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
1691                             .replace("#CN", className)
1692                             .replace("#SN", SUPERCLASS)
1693                             .replace("#REPLACE", replaceVal);
1694                     contents = superClassContents + subClassContents;
1695                     srcFileObj = Helper.getFile(className, contents);
1696                     files = Arrays.asList(srcFileObj);
1697                 }
1698                 return files;
1699             }
1700         },
1701         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
1702         // fail with ordering issues
1703         SingleOnSuperRepeatableOnSub_Inherited(
1704         "@ExpectedBase(value=Foo.class, "
1705                 + "getAnnotationVal = \"@Foo(value=0)\", "
1706                 + "getAnnotationsVals = {"
1707                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1708                 + //override every annotation on superClass
1709                 "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1710                 + // ignores inherited annotations
1711                 "getDeclAnnoVal = \"NULL\","// ignores inherited
1712                 + "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"}, "
1713                 + "getDeclAnnosArgs = { \"@Foo(value=1)\", \"@Foo(value=2)\"})",
1714         "@ExpectedContainer(value=FooContainer.class, "
1715                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1716                 + "getAnnotationsVals = {"
1717                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1718                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1719                 + // ignores inherited annotations
1720                 "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "// ignores inherited
1721                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1722                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"})") {
1723 
1724             @Override
1725             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1726                     String className) {
1727                 String anno = "";
1728                 String replaceVal = "";
1729                 String contents = "";
1730                 JavaFileObject srcFileObj = null;
1731                 Iterable<? extends JavaFileObject> files = null;
1732 
1733                 String expectedVals = "\n" + getExpectedBase() + "\n"
1734                         + getExpectedContainer() + "\n";
1735                 StringBuilder commonStmts = getCommonStmts(true);
1736 
1737                 /*
1738                  Sample testSrc:
1739                  @Retention(RetentionPolicy.RUNTIME)
1740                  @Inherited
1741                  @Repeatable(FooContainer.class)
1742                  @interface Foo {int value() default Integer.MAX_VALUE;}
1743 
1744                  @Retention(RetentionPolicy.RUNTIME)
1745                  @Inherited
1746                  @interface FooContainer {
1747                  Foo[] value();
1748                  }
1749 
1750                  @Foo(0)
1751                  class SuperClass { }
1752 
1753                  @ExpectedBase
1754                  @ExpectedContainer
1755                  @Foo(1) @Foo(2)
1756                  class SubClass extends SuperClass { }
1757                  */
1758                 //@Inherited only works for classes, no switch cases for method, field, package
1759                 if (srcType == SrcType.CLASS) {
1760                     //Contents for SuperClass
1761                     anno = Helper.ContentVars.BASEANNO.getVal();
1762                     replaceVal = commonStmts + "\n" + anno;
1763                     String superClassContents = srcType.getTemplate()
1764                             .replace("#CN", SUPERCLASS)
1765                             .replace("#REPLACE", replaceVal);
1766 
1767                     //Contents for SubClass that extends SuperClass
1768                     anno = Helper.ContentVars.REPEATABLEANNO.getVal();
1769                     replaceVal = expectedVals + "\n" + anno;
1770                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
1771                             .replace("#CN", className)
1772                             .replace("#SN", SUPERCLASS)
1773                             .replace("#REPLACE", replaceVal);
1774 
1775                     contents = superClassContents + subClassContents;
1776                     srcFileObj = Helper.getFile(className, contents);
1777                     files = Arrays.asList(srcFileObj);
1778                 }
1779                 return files;
1780             }
1781         },
1782         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
1783         // fail with ordering issues
1784         ContainerOnSuperSingleOnSub_Inherited(
1785         "@ExpectedBase(value=Foo.class, "
1786                 + "getAnnotationVal = \"@Foo(value=0)\", "
1787                 + "getAnnotationsVals = {"
1788                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1789                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"},"
1790                 + "getDeclAnnoVal = \"@Foo(value=0)\","
1791                 + "getAnnosArgs = {\"@Foo(value=0)\"},"
1792                 + "getDeclAnnosArgs = {\"@Foo(value=0)\"})",
1793         "@ExpectedContainer(value=FooContainer.class, "
1794                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1795                 + "getAnnotationsVals = {"
1796                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1797                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"},"
1798                 + "getDeclAnnoVal = \"NULL\","
1799                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1800                 + "getDeclAnnosArgs = {})") {
1801 
1802             @Override
1803             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1804                     String className) {
1805                 String anno = "";
1806                 String replaceVal = "";
1807                 String contents = "";
1808                 JavaFileObject srcFileObj = null;
1809                 Iterable<? extends JavaFileObject> files = null;
1810 
1811                 String expectedVals = "\n" + getExpectedBase() + "\n"
1812                         + getExpectedContainer() + "\n";
1813                 StringBuilder commonStmts = getCommonStmts(true);
1814 
1815                 /*
1816                  Sample testSrc:
1817                  @Retention(RetentionPolicy.RUNTIME)
1818                  @Inherited
1819                  @Repeatable(FooContainer.class)
1820                  @interface Foo {int value() default Integer.MAX_VALUE;}
1821 
1822                  @Retention(RetentionPolicy.RUNTIME)
1823                  @Inherited
1824                  @interface FooContainer {
1825                  Foo[] value();
1826                  }
1827 
1828                  @FooContainer(value = {@Foo(1), @Foo(2)})
1829                  class SuperClass { }
1830 
1831                  @ExpectedBase
1832                  @ExpectedContainer
1833                  @Foo(0)
1834                  class SubClass extends SuperClass { }
1835                  */
1836                 //@Inherited only works for classes, no switch cases for method, field, package
1837                 if (srcType == SrcType.CLASS) {
1838                     //Contents for SuperClass
1839                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
1840                     replaceVal = commonStmts + "\n" + anno;
1841                     String superClassContents = srcType.getTemplate()
1842                             .replace("#CN", SUPERCLASS)
1843                             .replace("#REPLACE", replaceVal);
1844 
1845                     //Contents for SubClass that extends SuperClass
1846                     anno = Helper.ContentVars.BASEANNO.getVal();
1847                     replaceVal = expectedVals + "\n" + anno;
1848                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
1849                             .replace("#CN", className)
1850                             .replace("#SN", SUPERCLASS)
1851                             .replace("#REPLACE", replaceVal);
1852 
1853                     contents = superClassContents + subClassContents;
1854                     srcFileObj = Helper.getFile(className, contents);
1855                     files = Arrays.asList(srcFileObj);
1856                 }
1857                 return files;
1858             }
1859         },
1860         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
1861         // fail with ordering issues
1862         SingleOnSuperContainerOnSub_Inherited(
1863         "@ExpectedBase(value=Foo.class, "
1864                 + "getAnnotationVal = \"@Foo(value=0)\", "
1865                 + "getAnnotationsVals = {"
1866                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1867                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1868                 + "getDeclAnnoVal = \"NULL\","
1869                 + "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"},"
1870                 + "getDeclAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"})",
1871         "@ExpectedContainer(value=FooContainer.class, "
1872                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1873                 + "getAnnotationsVals = {"
1874                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
1875                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1876                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
1877                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1878                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"})") {
1879 
1880             @Override
1881             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1882                      String className) {
1883                 String anno = "";
1884                 String replaceVal = "";
1885                 String contents = "";
1886                 JavaFileObject srcFileObj = null;
1887                 Iterable<? extends JavaFileObject> files = null;
1888 
1889                 String expectedVals = "\n" + getExpectedBase() + "\n"
1890                         + getExpectedContainer() + "\n";
1891                 StringBuilder commonStmts = getCommonStmts(true);
1892 
1893                 /*
1894                  Sample testSrc:
1895                  @Retention(RetentionPolicy.RUNTIME)
1896                  @Inherited
1897                  @Repeatable(FooContainer.class)
1898                  @interface Foo {int value() default Integer.MAX_VALUE;}
1899 
1900                  @Retention(RetentionPolicy.RUNTIME)
1901                  @Inherited
1902                  @interface FooContainer {
1903                  Foo[] value();
1904                  }
1905 
1906                  @Foo(0)
1907                  class SuperClass { }
1908 
1909                  @ExpectedBase
1910                  @ExpectedContainer
1911                  @FooContainer(value = {@Foo(1), @Foo(2)})
1912                  class SubClass extends SuperClass { }
1913                  */
1914                 //@Inherited only works for classes, no switch cases for method, field, package
1915                 if (srcType == SrcType.CLASS) {
1916                     //Contents for SuperClass
1917                     anno = Helper.ContentVars.BASEANNO.getVal();
1918                     replaceVal = commonStmts + "\n" + anno;
1919                     String superClassContents = srcType.getTemplate()
1920                             .replace("#CN", SUPERCLASS)
1921                             .replace("#REPLACE", replaceVal);
1922 
1923                     //Contents for SubClass that extends SuperClass
1924                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
1925                     replaceVal = expectedVals + "\n" + anno;
1926                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
1927                             .replace("#CN", className)
1928                             .replace("#SN", SUPERCLASS)
1929                             .replace("#REPLACE", replaceVal);
1930 
1931                     contents = superClassContents + subClassContents;
1932                     srcFileObj = Helper.getFile(className, contents);
1933                     files = Arrays.asList(srcFileObj);
1934                 }
1935                 return files;
1936             }
1937         },
1938         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
1939         // fail with ordering issues
1940         SingleOnSuperContainerAndSingleOnSub_Inherited(
1941         "@ExpectedBase(value=Foo.class, "
1942                 + "getAnnotationVal = \"@Foo(value=3)\", "
1943                 + "getAnnotationsVals = {"
1944                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=3)\"}, "
1945                 + "getDeclAnnosVals = {"
1946                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=3)\"},"
1947                 + "getDeclAnnoVal = \"@Foo(value=3)\","
1948                 + "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\", \"@Foo(value=3)\"},"
1949                 + "getDeclAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\", \"@Foo(value=3)\"})",
1950         "@ExpectedContainer(value=FooContainer.class, "
1951                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
1952                 + "getAnnotationsVals = {"
1953                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=3)\"}, "
1954                 + "getDeclAnnosVals = {"
1955                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", \"@Foo(value=3)\"},"
1956                 + "getDeclAnnoVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\","
1957                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
1958                 + "getDeclAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"})") {
1959 
1960             @Override
1961             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
1962                     String className) {
1963                 String anno = "";
1964                 String replaceVal = "";
1965                 String contents = "";
1966                 JavaFileObject srcFileObj = null;
1967                 Iterable<? extends JavaFileObject> files = null;
1968                 String expectedVals = "\n" + getExpectedBase() + "\n"
1969                         + getExpectedContainer() + "\n";
1970                 StringBuilder commonStmts = getCommonStmts(true);
1971 
1972                 /*
1973                 Sample testSrc:
1974                 @Retention(RetentionPolicy.RUNTIME)
1975                 @Inherited
1976                 @interface Foo {int value() default Integer.MAX_VALUE;}
1977 
1978                 @Retention(RetentionPolicy.RUNTIME)
1979                 @Inherited
1980                 @Repeatable(FooContainer.class)
1981                 @interface FooContainer {
1982                 Foo[] value();
1983                 }
1984 
1985                 @Foo(0)
1986                 class SuperClass { }
1987 
1988                 @ExpectedBase
1989                 @ExpectedContainer
1990                 @FooContainer(value = {@Foo(1), @Foo(2)}) @Foo(3)
1991                 class SubClass extends SuperClass {}
1992                  */
1993 
1994                 if (srcType == SrcType.CLASS) {
1995                     //Contents for SuperClass
1996                     anno = Helper.ContentVars.BASEANNO.getVal();
1997                     replaceVal = commonStmts + "\n" + anno;
1998                     String superClassContents = srcType.getTemplate()
1999                             .replace("#CN", SUPERCLASS)
2000                             .replace("#REPLACE", replaceVal);
2001 
2002                     //Contents for SubClass that extends SuperClass
2003                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
2004                             + "@Foo(3)";
2005                     replaceVal = expectedVals + "\n" + anno;
2006                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
2007                             .replace("#CN", className)
2008                             .replace("#SN", SUPERCLASS)
2009                             .replace("#REPLACE", replaceVal);
2010 
2011                     contents = superClassContents + subClassContents;
2012                     srcFileObj = Helper.getFile(className, contents);
2013                     files = Arrays.asList(srcFileObj);
2014                 }
2015                 return files;
2016             }
2017         },
2018         // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest
2019         // fail with ordering issues
2020         ContainerAndSingleOnSuperSingleOnSub_Inherited(
2021         "@ExpectedBase(value=Foo.class, "
2022                 + "getAnnotationVal = \"@Foo(value=0)\", "
2023                 + "getAnnotationsVals = {"
2024                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
2025                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"},"
2026                 + "getDeclAnnoVal = \"@Foo(value=0)\","
2027                 + "getAnnosArgs = {\"@Foo(value=0)\"},"
2028                 + "getDeclAnnosArgs = {\"@Foo(value=0)\"})",
2029         "@ExpectedContainer(value=FooContainer.class, "
2030                 + "getAnnotationVal = \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\", "
2031                 + "getAnnotationsVals = {"
2032                 + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"}, "
2033                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"},"
2034                 + "getDeclAnnoVal = \"NULL\","
2035                 + "getAnnosArgs = {\"@FooContainer(value={@Foo(value=1), @Foo(value=2)})\"},"
2036                 + "getDeclAnnosArgs = {})") {
2037 
2038             @Override
2039             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
2040                     String className) {
2041                 String anno = "";
2042                 String replaceVal = "";
2043                 String contents = "";
2044                 JavaFileObject srcFileObj = null;
2045                 Iterable<? extends JavaFileObject> files = null;
2046 
2047                 String expectedVals = "\n" + getExpectedBase() + "\n"
2048                         + getExpectedContainer() + "\n";
2049                 StringBuilder commonStmts = getCommonStmts(true);
2050 
2051                 /*
2052                  Sample testSrc:
2053                  @Retention(RetentionPolicy.RUNTIME)
2054                  @Inherited
2055                  @Repeatable(FooContainer.class)
2056                  @interface Foo {int value() default Integer.MAX_VALUE;}
2057 
2058                  @Retention(RetentionPolicy.RUNTIME)
2059                  @Inherited
2060                  @interface FooContainer {
2061                  Foo[] value();
2062                  }
2063 
2064                  @FooContainer(value = {@Foo(1), @Foo(2)})
2065                  @Foo(3)
2066                  class SuperClass { }
2067 
2068                  @ExpectedBase
2069                  @ExpectedContainer
2070                  @Foo(0)
2071                  class SubClass extends SuperClass { }
2072                  */
2073 
2074                 //@Inherited only works for classes, no switch cases for method, field, package
2075                 if (srcType == SrcType.CLASS) {
2076                     //Contents for SuperClass
2077                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
2078                             + "@Foo(3)" ;
2079                     replaceVal = commonStmts + "\n" + anno;
2080                     String superClassContents = srcType.getTemplate()
2081                             .replace("#CN", SUPERCLASS)
2082                             .replace("#REPLACE", replaceVal);
2083 
2084                     //Contents for SubClass that extends SuperClass
2085                     anno = Helper.ContentVars.BASEANNO.getVal();
2086                     replaceVal = expectedVals + "\n" + anno;
2087                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
2088                             .replace("#CN", className)
2089                             .replace("#SN", SUPERCLASS)
2090                             .replace("#REPLACE", replaceVal);
2091 
2092                     contents = superClassContents + subClassContents;
2093                     srcFileObj = Helper.getFile(className, contents);
2094                     files = Arrays.asList(srcFileObj);
2095                 }
2096                 return files;
2097             }
2098         };
2099 
2100          private String expectedBase, expectedContainer;
2101 
2102          private TestCase(String expectedBase, String expectedContainer) {
2103              this.expectedBase = expectedBase;
2104              this.expectedContainer = expectedContainer;
2105          }
2106 
2107          public String getExpectedBase() {
2108              return expectedBase;
2109          }
2110 
2111          public String getExpectedContainer() {
2112              return expectedContainer;
2113          }
2114 
2115          // Each enum element should override this method
2116          public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
2117                  String className) {
2118              return null;
2119          }
2120     }
2121 
2122     /*
2123      * Each srctype has its template defined used for test src generation
2124      * Primary src types: class, method, field, package define
2125      *                    getExpectedBase() and getExpectedContainer()
2126      */
2127     enum SrcType {
2128 
2129         CLASS("\n#REPLACE\nclass #CN { } ") {
2130 
2131             @Override
2132             public ExpectedBase getExpectedBase(Class<?> c) {
2133                 return c.getAnnotation(ExpectedBase.class);
2134             }
2135 
2136             @Override
2137             public ExpectedContainer getExpectedContainer(Class<?> c) {
2138                 return c.getAnnotation(ExpectedContainer.class);
2139             }
2140         },
2141         METHOD("class #CN  {\n" + "   " + "#REPLACE\n" + "   void "
2142         + TESTMETHOD + "() {} \n" + "}\n") {
2143 
2144             @Override
2145             public ExpectedBase getExpectedBase(Class<?> c) {
2146                 ExpectedBase ret = null;
2147                 try {
2148                     ret = c.getDeclaredMethod(TESTMETHOD).getAnnotation(
2149                             ExpectedBase.class);
2150                 } catch (NoSuchMethodException nme) {
2151                     error("Could not get " + TESTMETHOD + " for className "
2152                             + c.getName() + " Exception:\n" + nme);
2153                 }
2154                 return ret;
2155             }
2156 
2157             @Override
2158             public ExpectedContainer getExpectedContainer(Class<?> c) {
2159                 ExpectedContainer ret = null;
2160                 try {
2161                     ret = c.getDeclaredMethod(TESTMETHOD).getAnnotation(
2162                             ExpectedContainer.class);
2163                 } catch (NoSuchMethodException nme) {
2164                     error("Could not get " + TESTMETHOD + " for className "
2165                             + c.getName() + " Exception:\n" + nme);
2166                 }
2167                 return ret;
2168 
2169             }
2170         },
2171         FIELD("class #CN  {\n" + "   " + "#REPLACE\n" + "   int " + TESTFIELD
2172         + " = 0; \n" + "}\n") {
2173 
2174             @Override
2175             public ExpectedBase getExpectedBase(Class<?> c) {
2176                 ExpectedBase ret = null;
2177                 try {
2178                     ret = c.getDeclaredField(TESTFIELD).getAnnotation(
2179                             ExpectedBase.class);
2180                 } catch (NoSuchFieldException nme) {
2181                     error("Could not get " + TESTFIELD + " for className "
2182                             + c.getName() + " Exception:\n" + nme);
2183                 }
2184                 return ret;
2185             }
2186 
2187             @Override
2188             public ExpectedContainer getExpectedContainer(Class<?> c) {
2189                 ExpectedContainer ret = null;
2190                 try {
2191                     ret = c.getDeclaredField(TESTFIELD).getAnnotation(
2192                             ExpectedContainer.class);
2193                 } catch (NoSuchFieldException nme) {
2194                     error("Could not get " + TESTFIELD + " for className "
2195                             + c.getName() + " Exception:\n" + nme);
2196                 }
2197                 return ret;
2198 
2199             }
2200         },
2201         PACKAGE("package " + TESTPKG + "; \n" + "class #CN {}") {
2202 
2203             @Override
2204             public ExpectedBase getExpectedBase(Class<?> c) {
2205                 return c.getPackage().getAnnotation(ExpectedBase.class);
2206             }
2207 
2208             @Override
2209             public ExpectedContainer getExpectedContainer(Class<?> c) {
2210                 return c.getPackage().getAnnotation(ExpectedContainer.class);
2211             }
2212         },
2213         PKGINFO("#REPLACE1\npackage " + TESTPKG + "; \n" + "#REPLACE2"),
2214         INTERFACE("#REPLACE\ninterface #IN { } "),
2215         INTERFACEIMPL("#REPLACE\nclass #CN implements #IN {}"),
2216         CLASSEXTENDS("#REPLACE\nclass #CN extends #SN {}");
2217         String template;
2218 
2219         private SrcType(String template) {
2220             this.template = template;
2221         }
2222 
2223         public String getTemplate() {
2224             return template;
2225         }
2226 
2227         // Elements should override
2228         public ExpectedBase getExpectedBase(Class<?> c) {
2229             return null;
2230         }
2231 
2232         public ExpectedContainer getExpectedContainer(Class<?> c) {
2233             return null;
2234         }
2235 
2236         /*
2237          * Returns only primary src types ;
2238          */
2239         public static SrcType[] getSrcTypes() {
2240             return new SrcType[]{CLASS, PACKAGE, METHOD, FIELD};
2241         }
2242     }
2243 
2244     /*
2245      * Each enum constant is one of the 6 methods from AnnotatedElement interface
2246      * that needs to be tested.
2247      * Each enum constant overrides these 4 methods:
2248      * - getActualAnnoBase(SrcType srcType, Class<?> c)
2249      * - getActualAnnoContainer(SrcType srcType, Class<?> c)
2250      * - getExpectedAnnoBase(SrcType srcType, Class<?> c)
2251      * - getExpectedAnnoContainer(SrcType srcType, Class<?> c)
2252      */
2253     enum TestMethod {
2254 
2255         GET_ANNO("getAnnotation") {
2256 
2257             @Override
2258             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
2259                 Annotation[] actualAnno = new Annotation[1];
2260                 switch (srcType) {
2261                     case CLASS:
2262                         actualAnno[0] = c.getAnnotation(srcType.getExpectedBase(c).value());
2263                         break;
2264                     case PACKAGE:
2265                         actualAnno[0] = c.getPackage().getAnnotation(
2266                                 srcType.getExpectedBase(c).value());
2267                         break;
2268                     case METHOD:
2269                         try {
2270                             actualAnno[0] = c.getDeclaredMethod(TESTMETHOD).getAnnotation(
2271                                     srcType.getExpectedBase(c).value());
2272                         } catch (NoSuchMethodException nme) {
2273                             error("Could not get " + TESTMETHOD
2274                                     + " for className = " + c.getName()
2275                                     + "Exception = " + nme);
2276                         }
2277                         break;
2278                     case FIELD:
2279                         try {
2280                             actualAnno[0] = c.getDeclaredField(TESTFIELD).getAnnotation(
2281                                     srcType.getExpectedBase(c).value());
2282                         } catch (NoSuchFieldException nfe) {
2283                             error("Could not get " + TESTFIELD
2284                                     + " for className = " + c.getName()
2285                                     + "Exception = " + nfe);
2286                         }
2287                         break;
2288                 }
2289                 return actualAnno;
2290             }
2291 
2292             @Override
2293             public Annotation[] getActualAnnoContainer(SrcType srcType,
2294                     Class<?> c) {
2295                 Annotation[] actualAnno = new Annotation[1];
2296                 switch (srcType) {
2297                     case CLASS:
2298                         actualAnno[0] = c.getAnnotation(srcType.getExpectedContainer(c).value());
2299                         break;
2300                     case PACKAGE:
2301                         actualAnno[0] = c.getPackage().getAnnotation(
2302                                 srcType.getExpectedContainer(c).value());
2303                         break;
2304                     case METHOD:
2305                         try {
2306                             actualAnno[0] = c.getDeclaredMethod(TESTMETHOD).getAnnotation(
2307                                     srcType.getExpectedContainer(c).value());
2308                         } catch (NoSuchMethodException nme) {
2309                             error("Could not get " + TESTMETHOD
2310                                     + " for className = " + c.getName()
2311                                     + "Exception = " + nme);
2312                         }
2313                         break;
2314                     case FIELD:
2315                         try {
2316                             actualAnno[0] = c.getDeclaredField(TESTFIELD).getAnnotation(
2317                                     srcType.getExpectedContainer(c).value());
2318                         } catch (NoSuchFieldException nfe) {
2319                             error("Could not get " + TESTFIELD
2320                                     + " for className = " + c.getName()
2321                                     + "Exception = " + nfe);
2322                         }
2323                         break;
2324                 }
2325                 return actualAnno;
2326             }
2327 
2328             @Override
2329             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
2330                 String[] expAnno = {srcType.getExpectedBase(c).getAnnotationVal()};
2331                 return expAnno;
2332             }
2333 
2334             @Override
2335             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
2336                 String[] expAnno = {srcType.getExpectedContainer(c).getAnnotationVal()};
2337                 return expAnno;
2338             }
2339         },
2340         GET_ANNOS("getAnnotations") {
2341 
2342             @Override
2343             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
2344                 Annotation[] actualAnnos = null;
2345                 switch (srcType) {
2346                     case CLASS:
2347                         actualAnnos = c.getAnnotations();
2348                         break;
2349                     case PACKAGE:
2350                         actualAnnos = c.getPackage().getAnnotations();
2351                         break;
2352                     case METHOD:
2353                         try {
2354                             actualAnnos = c.getDeclaredMethod(TESTMETHOD).getAnnotations();
2355                         } catch (NoSuchMethodException nme) {
2356                             error("Could not get " + TESTMETHOD
2357                                     + " for className = " + c.getName()
2358                                     + "Exception = " + nme);
2359                         }
2360                         break;
2361                     case FIELD:
2362                         try {
2363                             actualAnnos = c.getDeclaredField(TESTFIELD).getAnnotations();
2364                         } catch (NoSuchFieldException nfe) {
2365                             error("Could not get " + TESTFIELD
2366                                     + " for className = " + c.getName()
2367                                     + "Exception = " + nfe);
2368                         }
2369                         break;
2370                 }
2371                 return actualAnnos;
2372             }
2373 
2374             @Override
2375             public Annotation[] getActualAnnoContainer(SrcType srcType,
2376                     Class<?> c) {
2377                 Annotation[] actualAnnos = null;
2378                 switch (srcType) {
2379                     case CLASS:
2380                         actualAnnos = c.getAnnotations();
2381                         break;
2382                     case PACKAGE:
2383                         actualAnnos = c.getPackage().getAnnotations();
2384                         break;
2385                     case METHOD:
2386                         try {
2387                             actualAnnos = c.getDeclaredMethod(TESTMETHOD).getAnnotations();
2388                         } catch (NoSuchMethodException nme) {
2389                             error("Could not get " + TESTMETHOD
2390                                     + " for className = " + c.getName()
2391                                     + "Exception = " + nme);
2392                         }
2393                         break;
2394                     case FIELD:
2395                         try {
2396                             actualAnnos = c.getDeclaredField(TESTFIELD).getAnnotations();
2397                         } catch (NoSuchFieldException nfe) {
2398                             error("Could not get " + TESTFIELD
2399                                     + " for className = " + c.getName()
2400                                     + "Exception = " + nfe);
2401                         }
2402                         break;
2403                 }
2404                 return actualAnnos;
2405             }
2406 
2407             @Override
2408             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
2409                 return srcType.getExpectedBase(c).getAnnotationsVals();
2410             }
2411 
2412             @Override
2413             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
2414                 return srcType.getExpectedContainer(c).getAnnotationsVals();
2415             }
2416         },
2417         GET_DECL_ANNOS("getDeclaredAnnotations") {
2418 
2419             @Override
2420             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
2421                 Annotation[] actualDeclAnnos = null;
2422                 switch (srcType) {
2423                     case CLASS:
2424                         actualDeclAnnos = c.getDeclaredAnnotations();
2425                         break;
2426                     case PACKAGE:
2427                         actualDeclAnnos = c.getPackage().getDeclaredAnnotations();
2428                         break;
2429                     case METHOD:
2430                         try {
2431                             actualDeclAnnos = c.getDeclaredMethod(TESTMETHOD)
2432                                     .getDeclaredAnnotations();
2433                         } catch (NoSuchMethodException nme) {
2434                             error("Could not get " + TESTMETHOD
2435                                     + " for className = " + c.getName()
2436                                     + "Exception = " + nme);
2437                         }
2438                         break;
2439                     case FIELD:
2440                         try {
2441                             actualDeclAnnos = c.getDeclaredField(TESTFIELD)
2442                                     .getDeclaredAnnotations();
2443                         } catch (NoSuchFieldException nfe) {
2444                             error("Could not get " + TESTFIELD
2445                                     + " for className = " + c.getName()
2446                                     + "Exception = " + nfe);
2447                         }
2448                         break;
2449                 }
2450                 return actualDeclAnnos;
2451             }
2452 
2453             @Override
2454             public Annotation[] getActualAnnoContainer(SrcType srcType,
2455                     Class<?> c) {
2456                 Annotation[] actualDeclAnnos = null;
2457                 switch (srcType) {
2458                     case CLASS:
2459                         actualDeclAnnos = c.getDeclaredAnnotations();
2460                         break;
2461                     case PACKAGE:
2462                         actualDeclAnnos = c.getPackage().getDeclaredAnnotations();
2463                         break;
2464                     case METHOD:
2465                         try {
2466                             actualDeclAnnos = c.getDeclaredMethod(TESTMETHOD)
2467                                     .getDeclaredAnnotations();
2468                         } catch (NoSuchMethodException nme) {
2469                             error("Could not get " + TESTMETHOD
2470                                     + " for className = " + c.getName()
2471                                     + "Exception = " + nme);
2472                         }
2473                         break;
2474                     case FIELD:
2475                         try {
2476                             actualDeclAnnos = c.getDeclaredField(TESTFIELD)
2477                                     .getDeclaredAnnotations();
2478                         } catch (NoSuchFieldException nfe) {
2479                             error("Could not get " + TESTFIELD
2480                                     + " for className = " + c.getName()
2481                                     + "Exception = " + nfe);
2482                         }
2483                         break;
2484                 }
2485                 return actualDeclAnnos;
2486             }
2487 
2488             @Override
2489             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
2490                 return srcType.getExpectedBase(c).getDeclAnnosVals();
2491             }
2492 
2493             @Override
2494             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
2495                 return srcType.getExpectedContainer(c).getDeclAnnosVals();
2496             }
2497         },
2498         GET_DECL_ANNO("getDeclaredAnnotation") {
2499 
2500             @Override
2501             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
2502                 Annotation[] actualDeclAnno = new Annotation[1];
2503                 switch (srcType) {
2504                     case CLASS:
2505                         actualDeclAnno[0] = c.getDeclaredAnnotation(
2506                                 srcType.getExpectedBase(c).value());
2507                         break;
2508                     case PACKAGE:
2509                         actualDeclAnno[0] = c.getPackage().getDeclaredAnnotation(
2510                                 srcType.getExpectedBase(c).value());
2511                         break;
2512                     case METHOD:
2513                         try {
2514                             actualDeclAnno[0] = c.getDeclaredMethod(TESTMETHOD)
2515                                     .getDeclaredAnnotation(
2516                                         srcType.getExpectedBase(c).value());
2517                         } catch (NoSuchMethodException nme) {
2518                             error("Could not get " + TESTMETHOD
2519                                     + " for className = " + c.getName()
2520                                     + "Exception = " + nme);
2521                         }
2522                         break;
2523                     case FIELD:
2524                         try {
2525                             actualDeclAnno[0] = c.getDeclaredField(TESTFIELD)
2526                                     .getDeclaredAnnotation(
2527                                         srcType.getExpectedBase(c).value());
2528                         } catch (NoSuchFieldException nfe) {
2529                             error("Could not get " + TESTFIELD
2530                                     + " for className = " + c.getName()
2531                                     + "Exception = " + nfe);
2532                         }
2533                         break;
2534                 }
2535                 return actualDeclAnno;
2536             }
2537 
2538             @Override
2539             public Annotation[] getActualAnnoContainer(SrcType srcType,
2540                     Class<?> c) {
2541                 Annotation[] actualDeclAnno = new Annotation[1];
2542                 switch (srcType) {
2543                     case CLASS:
2544                         actualDeclAnno[0] = c.getDeclaredAnnotation(
2545                                 srcType.getExpectedContainer(c).value());
2546                         break;
2547                     case PACKAGE:
2548                         actualDeclAnno[0] = c.getPackage().getDeclaredAnnotation(
2549                                 srcType.getExpectedContainer(c).value());
2550                         break;
2551                     case METHOD:
2552                         try {
2553                             actualDeclAnno[0] = c.getDeclaredMethod(TESTMETHOD)
2554                                     .getDeclaredAnnotation(
2555                                         srcType.getExpectedContainer(c).value());
2556                         } catch (NoSuchMethodException nme) {
2557                             error("Could not get " + TESTMETHOD
2558                                     + " for className = " + c.getName()
2559                                     + "Exception = " + nme);
2560                         }
2561                         break;
2562                     case FIELD:
2563                         try {
2564                             actualDeclAnno[0] = c.getDeclaredField(TESTFIELD)
2565                                     .getDeclaredAnnotation(
2566                                         srcType.getExpectedContainer(c).value());
2567                         } catch (NoSuchFieldException nfe) {
2568                             error("Could not get " + TESTFIELD
2569                                     + " for className = " + c.getName()
2570                                     + "Exception = " + nfe);
2571                         }
2572                         break;
2573                 }
2574                 return actualDeclAnno;
2575             }
2576 
2577             @Override
2578             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
2579                 String[] expAnno = {srcType.getExpectedBase(c).getDeclAnnoVal()};
2580                 return expAnno;
2581             }
2582 
2583             @Override
2584             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
2585                 String[] expAnno = {srcType.getExpectedContainer(c).getDeclAnnoVal()};
2586                 return expAnno;
2587             }
2588         }, // new
2589         GET_ANNOS_ARG("getAnnotationsArg") {
2590 
2591             @Override
2592             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
2593                 Annotation[] actualAnnoArgs = null;
2594                 switch (srcType) {
2595                     case CLASS:
2596                         actualAnnoArgs = c.getAnnotationsByType(srcType.getExpectedBase(c).value());
2597                         break;
2598                     case PACKAGE:
2599                         actualAnnoArgs = c.getPackage().getAnnotationsByType(
2600                                 srcType.getExpectedBase(c).value());
2601                         break;
2602                     case METHOD:
2603                         try {
2604                             actualAnnoArgs = c.getDeclaredMethod(TESTMETHOD)
2605                                     .getAnnotationsByType(
2606                                         srcType.getExpectedBase(c).value());
2607                         } catch (NoSuchMethodException nme) {
2608                             error("Could not get " + TESTMETHOD
2609                                     + " for className = " + c.getName()
2610                                     + "Exception = " + nme);
2611                         }
2612                         break;
2613                     case FIELD:
2614                         try {
2615                             actualAnnoArgs = c.getDeclaredField(TESTFIELD)
2616                                     .getAnnotationsByType(
2617                                         srcType.getExpectedBase(c).value());
2618                         } catch (NoSuchFieldException nfe) {
2619                             error("Could not get " + TESTFIELD
2620                                     + " for className = " + c.getName()
2621                                     + "Exception = " + nfe);
2622                         }
2623                         break;
2624                 }
2625                 return actualAnnoArgs;
2626             }
2627 
2628             @Override
2629             public Annotation[] getActualAnnoContainer(SrcType srcType,
2630                     Class<?> c) {
2631                 Annotation[] actualAnnoArgs = null;
2632                 switch (srcType) {
2633                     case CLASS:
2634                         actualAnnoArgs = c.getAnnotationsByType(srcType.getExpectedContainer(c).value());
2635                         break;
2636                     case PACKAGE:
2637                         actualAnnoArgs = c.getPackage().getAnnotationsByType(
2638                                 srcType.getExpectedContainer(c).value());
2639                         break;
2640                     case METHOD:
2641                         try {
2642                             actualAnnoArgs = c.getDeclaredMethod(TESTMETHOD)
2643                                     .getAnnotationsByType(
2644                                         srcType.getExpectedContainer(c).value());
2645                         } catch (NoSuchMethodException nme) {
2646                             error("Could not get " + TESTMETHOD
2647                                     + " for className = " + c.getName()
2648                                     + "Exception = " + nme);
2649                         }
2650                         break;
2651                     case FIELD:
2652                         try {
2653                             actualAnnoArgs = c.getDeclaredField(TESTFIELD)
2654                                     .getAnnotationsByType(
2655                                         srcType.getExpectedContainer(c).value());
2656                         } catch (NoSuchFieldException nfe) {
2657                             error("Could not get " + TESTFIELD
2658                                     + " for className = " + c.getName()
2659                                     + "Exception = " + nfe);
2660                         }
2661                         break;
2662                 }
2663                 return actualAnnoArgs;
2664             }
2665 
2666             @Override
2667             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
2668                 return srcType.getExpectedBase(c).getAnnosArgs();
2669             }
2670 
2671             @Override
2672             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
2673                 return srcType.getExpectedContainer(c).getAnnosArgs();
2674             }
2675         }, // new
2676         GET_DECL_ANNOS_ARG("getDeclAnnosArg") {
2677 
2678             @Override
2679             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
2680                 Annotation[] actualDeclAnnosArgs = null;
2681                 switch (srcType) {
2682                     case CLASS:
2683                         actualDeclAnnosArgs = c.getDeclaredAnnotationsByType(
2684                                 srcType.getExpectedBase(c).value());
2685                         break;
2686                     case PACKAGE:
2687                         actualDeclAnnosArgs = c.getPackage().getDeclaredAnnotationsByType(
2688                                 srcType.getExpectedBase(c).value());
2689                         break;
2690                     case METHOD:
2691                         try {
2692                             actualDeclAnnosArgs = c.getDeclaredMethod(TESTMETHOD)
2693                                     .getDeclaredAnnotationsByType(
2694                                         srcType.getExpectedBase(c).value());
2695                         } catch (NoSuchMethodException nme) {
2696                             error("Could not get " + TESTMETHOD
2697                                     + " for className = " + c.getName()
2698                                     + "Exception = " + nme);
2699                         }
2700                         break;
2701                     case FIELD:
2702                         try {
2703                             actualDeclAnnosArgs = c.getDeclaredField(TESTFIELD)
2704                                     .getDeclaredAnnotationsByType(
2705                                         srcType.getExpectedBase(c).value());
2706                         } catch (NoSuchFieldException nfe) {
2707                             error("Could not get " + TESTFIELD
2708                                     + " for className = " + c.getName()
2709                                     + "Exception = " + nfe);
2710                         }
2711                         break;
2712                 }
2713                 return actualDeclAnnosArgs;
2714             }
2715 
2716             @Override
2717             public Annotation[] getActualAnnoContainer(SrcType srcType,
2718                     Class<?> c) {
2719                 Annotation[] actualDeclAnnosArgs = null;
2720                 switch (srcType) {
2721                     case CLASS:
2722                         actualDeclAnnosArgs = c.getDeclaredAnnotationsByType(
2723                                 srcType.getExpectedContainer(c).value());
2724                         break;
2725                     case PACKAGE:
2726                         actualDeclAnnosArgs = c.getPackage().getDeclaredAnnotationsByType(
2727                                 srcType.getExpectedContainer(c).value());
2728                         break;
2729                     case METHOD:
2730                         try {
2731                             actualDeclAnnosArgs = c.getDeclaredMethod(TESTMETHOD)
2732                                     .getDeclaredAnnotationsByType(
2733                                         srcType.getExpectedContainer(c).value());
2734                         } catch (NoSuchMethodException nme) {
2735                             error("Could not get " + TESTMETHOD
2736                                     + " for className = " + c.getName()
2737                                     + "Exception = " + nme);
2738                         }
2739                         break;
2740                     case FIELD:
2741                         try {
2742                             actualDeclAnnosArgs = c.getDeclaredField(TESTFIELD)
2743                                    .getDeclaredAnnotationsByType(
2744                                         srcType.getExpectedContainer(c).value());
2745                         } catch (NoSuchFieldException nfe) {
2746                             error("Could not get " + TESTFIELD
2747                                     + " for className = " + c.getName()
2748                                     + "Exception = " + nfe);
2749                         }
2750                         break;
2751                 }
2752                 return actualDeclAnnosArgs;
2753             }
2754 
2755             @Override
2756             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
2757                 return srcType.getExpectedBase(c).getDeclAnnosArgs();
2758             }
2759 
2760             @Override
2761             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
2762                 return srcType.getExpectedContainer(c).getDeclAnnosArgs();
2763             }
2764         }; // new
2765         String name;
2766 
2767         private TestMethod(String name) {
2768             this.name = name;
2769         }
2770 
2771         public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
2772             return null;
2773         }
2774 
2775         public Annotation[] getActualAnnoContainer(SrcType srcType, Class<?> c) {
2776             return null;
2777         }
2778 
2779         public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
2780             return null;
2781         }
2782 
2783         public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
2784             return null;
2785         }
2786     }
2787 
2788     /*
2789      * For a given srcType and class object, compare expectedBase and actualBase
2790      * annotations as well as expectedContainer and actualContainer annotations.
2791      *
2792      * Return true if both comparisons are true else return false.
2793      *
2794      */
2795     protected static void checkAnnoValues(SrcType srcType, Class<?> c) {
2796 
2797         // Load @ExpectedBase and @ExpectedContainer
2798         ExpectedBase eb = srcType.getExpectedBase(c);
2799         ExpectedContainer ec = srcType.getExpectedContainer(c);
2800         if (eb == null) {
2801             error("Did not find ExpectedBase Annotation, Test will exit");
2802             throw new RuntimeException();
2803         }
2804         if (ec == null) {
2805             error("Did not find ExpectedContainer Annotation, Test will exit");
2806             throw new RuntimeException();
2807         }
2808 
2809         for (TestMethod testMethod : TestMethod.values()) {
2810             debugPrint("---------------------------------------------");
2811             debugPrint("Test method = " + testMethod);
2812             boolean isBasePass = true;
2813             boolean isConPass = true;
2814             // ExpectedBase = Annotation, no annotation is defined, skip comparison
2815             if (!eb.value().getSimpleName().equalsIgnoreCase("Annotation")) {
2816                 isBasePass = compareAnnotations(
2817                         testMethod.getActualAnnoBase(srcType, c),
2818                         testMethod.getExpectedAnnoBase(srcType, c));
2819             }
2820 
2821             // ExpectedContainer = Annotation, no annotation is defined, skip comparison
2822             if (!ec.value().getSimpleName().equalsIgnoreCase("Annotation")) {
2823                 isConPass = compareAnnotations(
2824                         testMethod.getActualAnnoContainer(srcType, c),
2825                         testMethod.getExpectedAnnoContainer(srcType, c));
2826             }
2827             if (isBasePass && isConPass) {
2828                 debugPrint("Testcase passed for " + testMethod +
2829                         " for className = " + c.getName());
2830             } else {
2831                 debugPrint("Testcase failed for " + testMethod +
2832                         " for className = " + c.getName());
2833             }
2834         }
2835     }
2836 
2837     // Annotation comparison: Length should be same and all expected values
2838     // should be present in actualAnno[].
2839     private static boolean compareAnnotations(Annotation[] actualAnnos,
2840             String[] expectedAnnos) {
2841         boolean compOrder = false;
2842 
2843         // Length is different
2844         if (actualAnnos.length != expectedAnnos.length) {
2845             error("Length not same, Actual length = " + actualAnnos.length
2846                     + " Expected length = " + expectedAnnos.length);
2847             printArrContents(actualAnnos);
2848             printArrContents(expectedAnnos);
2849             return false;
2850         } else {
2851             int i = 0;
2852             // Length is same and 0
2853             if (actualAnnos.length == 0) {
2854                 // Expected/actual lengths already checked for
2855                 // equality; no more checks do to
2856                 return true;
2857             }
2858             // Expected annotation should be NULL
2859             if (actualAnnos[0] == null) {
2860                 if (expectedAnnos[0].equals("NULL")) {
2861                     debugPrint("Arr values are NULL as expected");
2862                     return true;
2863                 } else {
2864                     error("Array values are not NULL");
2865                     printArrContents(actualAnnos);
2866                     printArrContents(expectedAnnos);
2867                     return false;
2868                 }
2869             }
2870             // Lengths are same, compare array contents
2871             String[] actualArr = new String[actualAnnos.length];
2872             for (Annotation a : actualAnnos) {
2873                 if (a.annotationType().getSimpleName().contains("Expected"))
2874                 actualArr[i++] = a.annotationType().getSimpleName();
2875                  else if (a.annotationType().getName().contains(TESTPKG)) {
2876                     String replaced = a.toString().replaceAll(Pattern.quote("testpkg."),"");
2877                     actualArr[i++] = replaced;
2878                 } else
2879                     actualArr[i++] = a.toString();
2880             }
2881             List<String> actualList = new ArrayList<String>(Arrays.asList(actualArr));
2882             List<String> expectedList = new ArrayList<String>(Arrays.asList(expectedAnnos));
2883             if (!actualList.containsAll(expectedList)) {
2884                 error("Array values are not same");
2885                 printArrContents(actualAnnos);
2886                 printArrContents(expectedAnnos);
2887                 return false;
2888             } else {
2889                 debugPrint("Arr values are same as expected");
2890                 if (CHECKORDERING) {
2891                     debugPrint("Checking if annotation ordering is as expected..");
2892                     compOrder = compareOrdering(actualList, expectedList);
2893                     if (compOrder)
2894                         debugPrint("Arr values ordering is as expected");
2895                     else
2896                         error("Arr values ordering is not as expected! actual values: "
2897                             + actualList + " expected values: " + expectedList);
2898                 } else
2899                     compOrder = true;
2900             }
2901         }
2902         return compOrder;
2903     }
2904 
2905     // Annotation ordering comparison
2906     private static boolean compareOrdering(List<String> actualList, List<String> expectedList) {
2907         boolean order = true;
2908         // Discarding Expected* annotations before comparison of ordering
2909         actualList = iterateList(actualList);
2910         expectedList = iterateList(expectedList);
2911         // Length is different
2912         if (actualList.size() != expectedList.size()) {
2913             error("Length not same, Actual list length = " + actualList.size()
2914                     + " Expected list length = " + expectedList.size());
2915             return false;
2916         } else {
2917             if (actualList.isEmpty() && expectedList.isEmpty()) {
2918         return true;
2919     }
2920             boolean tmp = true;
2921             for (int i = 0; i < actualList.size(); i++) {
2922                 // Checking ordering
2923                 if (order) {
2924                     if (!actualList.get(i).equals(expectedList.get(i))) {
2925                         tmp = false;
2926                         debugPrint("Odering is false");
2927                         debugPrint("actualList values: " + actualList
2928                                 + " expectedList values: " + expectedList);
2929                     }
2930                 }
2931             }
2932             order = tmp;
2933         }
2934         return order;
2935     }
2936 
2937     private static List<String> iterateList(List<String> list) {
2938         Iterator<String> iter = list.iterator();
2939         while (iter.hasNext()) {
2940             String anno = iter.next();
2941             if (anno.contains("Expected")) {
2942                 iter.remove();
2943             }
2944         }
2945         return list;
2946     }
2947 
2948     private static void printArrContents(Annotation[] actualAnnos) {
2949         System.out.print("Actual Arr Values: ");
2950         for (Annotation a : actualAnnos) {
2951             if (a != null && a.annotationType() != null) {
2952                 System.out.print("[" + a.toString() + "]");
2953             } else {
2954                 System.out.println("[null]");
2955             }
2956         }
2957         System.out.println();
2958     }
2959 
2960     private static void printArrContents(String[] expectedAnnos) {
2961         System.out.print("Expected Arr Values: ");
2962         for (String s : expectedAnnos) {
2963             System.out.print("[" + s + "]");
2964         }
2965         System.out.println();
2966     }
2967 
2968     private ClassLoader getLoader() {
2969         return getClass().getClassLoader();
2970     }
2971 
2972     private static Class<?> loadClass(String className, ClassLoader parentClassLoader, File... destDirs) {
2973         try {
2974             List<URL> list = new ArrayList<>();
2975             for (File f : destDirs) {
2976                 list.add(new URL("file:" + f.toString().replace("\\", "/") + "/"));
2977             }
2978             return Class.forName(className, true, new URLClassLoader(
2979                     list.toArray(new URL[list.size()]), parentClassLoader));
2980         } catch (ClassNotFoundException | MalformedURLException e) {
2981             throw new RuntimeException("Error loading class " + className, e);
2982         }
2983     }
2984 
2985     private static void printTestSrc(Iterable<? extends JavaFileObject> files) {
2986         for (JavaFileObject f : files) {
2987             System.out.println("Test file " + f.getName() + ":");
2988             try {
2989                 System.out.println("" + f.getCharContent(true));
2990             } catch (IOException e) {
2991                 throw new RuntimeException(
2992                         "Exception when printing test src contents for class " +
2993                                 f.getName(), e);
2994             }
2995         }
2996 
2997     }
2998 
2999     public static StringBuilder getCommonStmts(boolean isRepeatable) {
3000         StringBuilder sb = new StringBuilder();
3001 
3002         sb.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
3003           .append(Helper.ContentVars.IMPORTSTMTS.getVal())
3004           .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
3005           .append(Helper.ContentVars.INHERITED.getVal());
3006         if(isRepeatable) {
3007             sb.append(Helper.ContentVars.REPEATABLE.getVal());
3008         }
3009         sb.append(Helper.ContentVars.BASE.getVal())
3010           .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
3011           .append(Helper.ContentVars.INHERITED.getVal())
3012           .append(Helper.ContentVars.CONTAINER.getVal());
3013         return sb;
3014     }
3015 
3016     private static int getNumErrors() {
3017         return errors;
3018     }
3019 
3020     private static void error(String msg) {
3021         System.out.println("error: " + msg);
3022         errors++;
3023     }
3024 
3025     private static void debugPrint(String string) {
3026         if(DEBUG)
3027             System.out.println(string);
3028     }
3029 }