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