Fri, 03 May 2013 09:56:56 -0700
8012728: Normalize @ignore comments on langtools tests
Reviewed-by: vromero, mcimadamore
jfranck@1560 | 1 | /* |
jfranck@1560 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
jfranck@1560 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jfranck@1560 | 4 | * |
jfranck@1560 | 5 | * This code is free software; you can redistribute it and/or modify it |
jfranck@1560 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jfranck@1560 | 7 | * published by the Free Software Foundation. |
jfranck@1560 | 8 | * |
jfranck@1560 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jfranck@1560 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jfranck@1560 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jfranck@1560 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jfranck@1560 | 13 | * accompanied this code). |
jfranck@1560 | 14 | * |
jfranck@1560 | 15 | * You should have received a copy of the GNU General Public License version |
jfranck@1560 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jfranck@1560 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jfranck@1560 | 18 | * |
jfranck@1560 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jfranck@1560 | 20 | * or visit www.oracle.com if you need additional information or have any |
jfranck@1560 | 21 | * questions. |
jfranck@1560 | 22 | */ |
jfranck@1560 | 23 | |
jfranck@1560 | 24 | import java.lang.annotation.Annotation; |
jfranck@1560 | 25 | import java.util.Arrays; |
jfranck@1560 | 26 | import java.util.EnumSet; |
jfranck@1560 | 27 | import java.util.List; |
jfranck@1560 | 28 | import java.util.Set; |
jfranck@1560 | 29 | import javax.annotation.processing.*; |
jfranck@1560 | 30 | import javax.lang.model.element.*; |
jfranck@1560 | 31 | import javax.lang.model.type.MirroredTypeException; |
jfranck@1560 | 32 | import javax.lang.model.type.TypeMirror; |
jfranck@1560 | 33 | import javax.lang.model.util.Elements; |
jfranck@1560 | 34 | |
jfranck@1560 | 35 | public class ElementRepAnnoTester extends JavacTestingAbstractProcessor { |
jfranck@1560 | 36 | // All methods to test. |
jfranck@1560 | 37 | final EnumSet<TestMethod> ALL_TEST_METHODS = EnumSet.allOf(TestMethod.class); |
jfranck@1560 | 38 | int count = 0; |
jfranck@1560 | 39 | int error = 0; |
jfranck@1560 | 40 | |
jfranck@1560 | 41 | public boolean process(Set<? extends TypeElement> annotations, |
jfranck@1560 | 42 | RoundEnvironment roundEnv) { |
jfranck@1560 | 43 | if (!roundEnv.processingOver()) { |
jfranck@1560 | 44 | List<String> superClass = Arrays.asList("A", "B", "C", "D", "E", |
jfranck@1560 | 45 | "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"); |
jfranck@1560 | 46 | // Go through all test classes |
jfranck@1560 | 47 | for (Element element : roundEnv.getRootElements()) { |
jfranck@1560 | 48 | // For now, no testing super classes (TODO) |
jfranck@1560 | 49 | if (element.getKind() == ElementKind.CLASS |
jfranck@1560 | 50 | && !superClass.contains(element.getSimpleName().toString())) { |
jfranck@1560 | 51 | // Compare expected and actual values from methods. |
jfranck@1560 | 52 | checkAnnoValues(element, ALL_TEST_METHODS); |
jfranck@1560 | 53 | // Now, look for enclosed elements in test classes. |
jfranck@1560 | 54 | for (Element elements : element.getEnclosedElements()) { |
jfranck@1560 | 55 | // Look for Methods annotations. |
jfranck@1560 | 56 | if (elements.getKind() == ElementKind.METHOD |
jfranck@1560 | 57 | && elements.getSimpleName().toString().equals("testMethod")) { |
jfranck@1560 | 58 | checkAnnoValues(elements, ALL_TEST_METHODS); |
jfranck@1560 | 59 | } |
jfranck@1560 | 60 | // Look for Field annotations. |
jfranck@1560 | 61 | if (elements.getKind() == ElementKind.FIELD |
jfranck@1560 | 62 | && elements.getSimpleName().toString().equals("testField")) { |
jfranck@1560 | 63 | checkAnnoValues(elements, ALL_TEST_METHODS); |
jfranck@1560 | 64 | } |
jfranck@1560 | 65 | } |
jfranck@1560 | 66 | } |
jfranck@1560 | 67 | } |
jfranck@1560 | 68 | |
jfranck@1560 | 69 | if (error != 0) { |
jfranck@1560 | 70 | System.out.println("Total tests : " + count); |
jfranck@1560 | 71 | System.out.println("Total test failures : " + error); |
jfranck@1560 | 72 | throw new RuntimeException(); |
jfranck@1560 | 73 | } else { |
jfranck@1560 | 74 | System.out.println("ALL TESTS PASSED. " + count); |
jfranck@1560 | 75 | } |
jfranck@1560 | 76 | } |
jfranck@1560 | 77 | return true; |
jfranck@1560 | 78 | } |
jfranck@1560 | 79 | |
jfranck@1560 | 80 | enum TestMethod { |
jfranck@1560 | 81 | getAnnotation, |
jfranck@1560 | 82 | getAnnotationsByType, |
jfranck@1560 | 83 | getAllAnnotationMirrors, |
jfranck@1560 | 84 | getAnnotationMirrors |
jfranck@1560 | 85 | } |
jfranck@1560 | 86 | |
jfranck@1560 | 87 | protected void checkAnnoValues(Element element, EnumSet<TestMethod> testMethods) { |
jfranck@1560 | 88 | boolean baseAnnoPresent = false; |
jfranck@1560 | 89 | boolean conAnnoPresent = false; |
jfranck@1560 | 90 | ExpectedBase eb = null; |
jfranck@1560 | 91 | ExpectedContainer ec = null; |
jfranck@1560 | 92 | // Getting the expected values to compare with. |
jfranck@1560 | 93 | eb = element.getAnnotation(ExpectedBase.class); |
jfranck@1560 | 94 | ec = element.getAnnotation(ExpectedContainer.class); |
jfranck@1560 | 95 | |
jfranck@1560 | 96 | if (eb == null) { |
jfranck@1560 | 97 | System.out.println("Did not find ExpectedBase Annotation in " |
jfranck@1560 | 98 | + element.getSimpleName().toString() + ", Test will exit"); |
jfranck@1560 | 99 | throw new RuntimeException(); |
jfranck@1560 | 100 | } |
jfranck@1560 | 101 | if (ec == null) { |
jfranck@1560 | 102 | System.out.println("Did not find ExpectedContainer Annotation in " |
jfranck@1560 | 103 | + element.getSimpleName().toString() + " Test will exit"); |
jfranck@1560 | 104 | throw new RuntimeException(); |
jfranck@1560 | 105 | } |
jfranck@1560 | 106 | // Look if all test cases have ExpectedBase and ExpectedContainer values(). |
jfranck@1560 | 107 | TypeMirror valueBase = null; |
jfranck@1560 | 108 | TypeMirror valueCon = null; |
jfranck@1560 | 109 | |
jfranck@1560 | 110 | try { |
jfranck@1560 | 111 | eb.value(); |
jfranck@1560 | 112 | } catch (MirroredTypeException mte) { |
jfranck@1560 | 113 | valueBase = mte.getTypeMirror(); |
jfranck@1560 | 114 | } |
jfranck@1560 | 115 | |
jfranck@1560 | 116 | try { |
jfranck@1560 | 117 | ec.value(); |
jfranck@1560 | 118 | } catch (MirroredTypeException mte1) { |
jfranck@1560 | 119 | valueCon = mte1.getTypeMirror(); |
jfranck@1560 | 120 | } |
jfranck@1560 | 121 | |
jfranck@1560 | 122 | String expectedBaseAnno = valueBase.toString(); |
jfranck@1560 | 123 | String expectedConAnno = valueCon.toString(); |
jfranck@1560 | 124 | |
jfranck@1560 | 125 | if (!expectedBaseAnno.equals("java.lang.annotation.Annotation")) { |
jfranck@1560 | 126 | baseAnnoPresent = true; |
jfranck@1560 | 127 | } |
jfranck@1560 | 128 | if (!expectedConAnno.equalsIgnoreCase("java.lang.annotation.Annotation")) { |
jfranck@1560 | 129 | conAnnoPresent = true; |
jfranck@1560 | 130 | } |
jfranck@1560 | 131 | |
jfranck@1560 | 132 | // Look into TestMethod and compare method's output with expected values. |
jfranck@1560 | 133 | for (TestMethod testMethod : testMethods) { |
jfranck@1560 | 134 | boolean isBasePass = true; |
jfranck@1560 | 135 | boolean isConPass = true; |
jfranck@1560 | 136 | |
jfranck@1560 | 137 | switch (testMethod) { |
jfranck@1560 | 138 | case getAnnotation: |
jfranck@1560 | 139 | if (baseAnnoPresent) { |
jfranck@1560 | 140 | count++; |
jfranck@1560 | 141 | Annotation actualAnno = getAnnotationBase(element); |
jfranck@1560 | 142 | String expectedAnno = eb.getAnnotation(); |
jfranck@1560 | 143 | isBasePass = compareAnnotation(actualAnno, expectedAnno); |
jfranck@1560 | 144 | } |
jfranck@1560 | 145 | if (conAnnoPresent) { |
jfranck@1560 | 146 | count++; |
jfranck@1560 | 147 | Annotation actualAnno = getAnnotationContainer(element); |
jfranck@1560 | 148 | String expectedAnno = ec.getAnnotation(); |
jfranck@1560 | 149 | isConPass = compareAnnotation(actualAnno, expectedAnno); |
jfranck@1560 | 150 | } |
jfranck@1560 | 151 | if (!isBasePass || !isConPass) { |
jfranck@1560 | 152 | System.out.println("FAIL in " + element.getSimpleName() |
jfranck@1560 | 153 | + "-" + element.getKind() |
jfranck@1560 | 154 | + " method: getAnnotation(class <T>)"); |
jfranck@1560 | 155 | error++; |
jfranck@1560 | 156 | } |
jfranck@1560 | 157 | break; |
jfranck@1560 | 158 | |
jfranck@1560 | 159 | case getAnnotationMirrors: |
jfranck@1560 | 160 | if (baseAnnoPresent) { |
jfranck@1560 | 161 | count++; |
jfranck@1560 | 162 | List<? extends AnnotationMirror> actualDeclAnnos = |
jfranck@1560 | 163 | element.getAnnotationMirrors(); |
jfranck@1560 | 164 | String[] expectedAnnos = eb.getAnnotationMirrors(); |
jfranck@1560 | 165 | isBasePass = compareArrVals(actualDeclAnnos, expectedAnnos); |
jfranck@1560 | 166 | } |
jfranck@1560 | 167 | if (conAnnoPresent) { |
jfranck@1560 | 168 | isConPass = true; |
jfranck@1560 | 169 | } |
jfranck@1560 | 170 | if (!isBasePass || !isConPass) { |
jfranck@1560 | 171 | System.out.println("FAIL in " + element.getSimpleName() |
jfranck@1560 | 172 | + "-" + element.getKind() |
jfranck@1560 | 173 | + " method: getAnnotationMirrors()"); |
jfranck@1560 | 174 | error++; |
jfranck@1560 | 175 | } |
jfranck@1560 | 176 | break; |
jfranck@1560 | 177 | |
jfranck@1560 | 178 | case getAnnotationsByType: |
jfranck@1560 | 179 | if (baseAnnoPresent) { |
jfranck@1560 | 180 | count++; |
jfranck@1560 | 181 | Annotation[] actualAnnosArgs = getAnnotationsBase(element); |
jfranck@1560 | 182 | String[] expectedAnnos = eb.getAnnotationsByType(); |
jfranck@1560 | 183 | isBasePass = compareArrVals(actualAnnosArgs, expectedAnnos); |
jfranck@1560 | 184 | } |
jfranck@1560 | 185 | if (conAnnoPresent) { |
jfranck@1560 | 186 | count++; |
jfranck@1560 | 187 | Annotation[] actualAnnosArgs = getAnnotationsContainer(element); |
jfranck@1560 | 188 | String[] expectedAnnos = ec.getAnnotationsByType(); |
jfranck@1560 | 189 | isConPass = compareArrVals(actualAnnosArgs, expectedAnnos); |
jfranck@1560 | 190 | } |
jfranck@1560 | 191 | if (!isBasePass || !isConPass) { |
jfranck@1560 | 192 | System.out.println("FAIL in " + element.getSimpleName() |
jfranck@1560 | 193 | + "-" + element.getKind() |
jfranck@1560 | 194 | + " method: getAnnotationsByType(class <T>)"); |
jfranck@1560 | 195 | error++; |
jfranck@1560 | 196 | } |
jfranck@1560 | 197 | break; |
jfranck@1560 | 198 | |
jfranck@1560 | 199 | case getAllAnnotationMirrors: |
jfranck@1560 | 200 | if (baseAnnoPresent) { |
jfranck@1560 | 201 | count++; |
jfranck@1560 | 202 | Elements elements = processingEnv.getElementUtils(); |
jfranck@1560 | 203 | List<? extends AnnotationMirror> actualAnnosMirrors = |
jfranck@1560 | 204 | elements.getAllAnnotationMirrors(element); |
jfranck@1560 | 205 | String[] expectedAnnos = eb.getAllAnnotationMirrors(); |
jfranck@1560 | 206 | isBasePass = compareArrVals(actualAnnosMirrors, expectedAnnos); |
jfranck@1560 | 207 | } |
jfranck@1560 | 208 | if (conAnnoPresent) { |
jfranck@1560 | 209 | isConPass = true; |
jfranck@1560 | 210 | } |
jfranck@1560 | 211 | if (!isBasePass || !isConPass) { |
jfranck@1560 | 212 | System.out.println("FAIL in " + element.getSimpleName() |
jfranck@1560 | 213 | + "-" + element.getKind() |
jfranck@1560 | 214 | + " method: getAllAnnotationMirrors(e)"); |
jfranck@1560 | 215 | error++; |
jfranck@1560 | 216 | } |
jfranck@1560 | 217 | break; |
jfranck@1560 | 218 | } |
jfranck@1560 | 219 | } |
jfranck@1560 | 220 | } |
jfranck@1560 | 221 | // Sort tests to be run with different anno processors. |
jfranck@1560 | 222 | final List<String> singularAnno = Arrays.asList( |
jfranck@1560 | 223 | "SingularBasicTest" |
jfranck@1560 | 224 | ); |
jfranck@1560 | 225 | final List<String> singularInheritedAnno = Arrays.asList( |
jfranck@1560 | 226 | "SingularInheritedATest" |
jfranck@1560 | 227 | ); |
jfranck@1560 | 228 | final List<String> repeatableAnno = Arrays.asList( |
jfranck@1560 | 229 | "RepeatableBasicTest", |
jfranck@1560 | 230 | "MixRepeatableAndOfficialContainerBasicTest", |
jfranck@1560 | 231 | "OfficialContainerBasicTest", |
jfranck@1560 | 232 | "RepeatableOfficialContainerBasicTest" |
jfranck@1560 | 233 | ); |
jfranck@1560 | 234 | final List<String> repeatableInheritedAnno = Arrays.asList( |
jfranck@1560 | 235 | "RepeatableInheritedTest", |
jfranck@1560 | 236 | "RepeatableOverrideATest", |
jfranck@1560 | 237 | "RepeatableOverrideBTest", |
jfranck@1560 | 238 | "OfficialContainerInheritedTest", |
jfranck@1560 | 239 | "MixRepeatableAndOfficialContainerInheritedA1Test", |
jfranck@1560 | 240 | "MixRepeatableAndOfficialContainerInheritedB1Test", |
jfranck@1560 | 241 | "MixRepeatableAndOfficialContainerInheritedA2Test", |
jfranck@1560 | 242 | "MixRepeatableAndOfficialContainerInheritedB2Test" |
jfranck@1560 | 243 | ); |
jfranck@1560 | 244 | final List<String> repeatableContainerInheritedAnno = Arrays.asList( |
jfranck@1560 | 245 | "RepeatableOfficialContainerInheritedTest" |
jfranck@1560 | 246 | ); |
jfranck@1560 | 247 | final List<String> unofficialAnno = Arrays.asList( |
jfranck@1560 | 248 | "UnofficialContainerBasicTest", |
jfranck@1560 | 249 | "MixSingularAndUnofficialContainerBasicTest" |
jfranck@1560 | 250 | ); |
jfranck@1560 | 251 | final List<String> unofficialInheritedAnno = Arrays.asList( |
jfranck@1560 | 252 | "UnofficialContainerInheritedTest", |
jfranck@1560 | 253 | "SingularInheritedBTest", |
jfranck@1560 | 254 | "MixSingularAndUnofficialContainerInheritedA1Test", |
jfranck@1560 | 255 | "MixSingularAndUnofficialContainerInheritedB1Test", |
jfranck@1560 | 256 | "MixSingularAndUnofficialContainerInheritedA2Test", |
jfranck@1560 | 257 | "MixSingularAndUnofficialContainerInheritedB2Test" |
jfranck@1560 | 258 | ); |
jfranck@1560 | 259 | // Respective container annotation for the different test cases to test. |
jfranck@1560 | 260 | final List<String> repeatableAnnoContainer = repeatableAnno; |
jfranck@1560 | 261 | final List<String> repeatableInheritedAnnoContainer = repeatableInheritedAnno; |
jfranck@1560 | 262 | final List<String> repeatableContainerInheritedAnnoContainer = |
jfranck@1560 | 263 | repeatableContainerInheritedAnno; |
jfranck@1560 | 264 | final List<String> unofficialAnnoContainer = unofficialAnno; |
jfranck@1560 | 265 | final List<String> unofficialInheritedAnnoContainer = unofficialInheritedAnno; |
jfranck@1560 | 266 | |
jfranck@1560 | 267 | // Variables to verify if all test cases have been run. |
jfranck@1560 | 268 | private Annotation specialAnno = new Annotation() { |
jfranck@1560 | 269 | @Override |
jfranck@1560 | 270 | public Class annotationType() { |
jfranck@1560 | 271 | return null; |
jfranck@1560 | 272 | } |
jfranck@1560 | 273 | }; |
jfranck@1560 | 274 | private Annotation[] specialAnnoArray = new Annotation[1]; |
jfranck@1560 | 275 | private List<AnnotationMirror> specialAnnoMirrors = |
jfranck@1560 | 276 | new java.util.ArrayList<AnnotationMirror>(2); |
jfranck@1560 | 277 | |
jfranck@1560 | 278 | private Annotation getAnnotationBase(Element e) { |
jfranck@1560 | 279 | Annotation actualAnno = specialAnno; |
jfranck@1560 | 280 | |
jfranck@1560 | 281 | if (singularAnno.contains( |
jfranck@1560 | 282 | e.getEnclosingElement().toString()) |
jfranck@1560 | 283 | || singularAnno.contains( |
jfranck@1560 | 284 | e.getSimpleName().toString()) |
jfranck@1560 | 285 | || unofficialAnno.contains( |
jfranck@1560 | 286 | e.getEnclosingElement().toString()) |
jfranck@1560 | 287 | || unofficialAnno.contains( |
jfranck@1560 | 288 | e.getSimpleName().toString())) { |
jfranck@1560 | 289 | actualAnno = e.getAnnotation(Foo.class); |
jfranck@1560 | 290 | } |
jfranck@1560 | 291 | if (singularInheritedAnno.contains( |
jfranck@1560 | 292 | e.getEnclosingElement().toString()) |
jfranck@1560 | 293 | || singularInheritedAnno.contains( |
jfranck@1560 | 294 | e.getSimpleName().toString()) |
jfranck@1560 | 295 | || unofficialInheritedAnno.contains( |
jfranck@1560 | 296 | e.getEnclosingElement().toString()) |
jfranck@1560 | 297 | || unofficialInheritedAnno.contains( |
jfranck@1560 | 298 | e.getSimpleName().toString())) { |
jfranck@1560 | 299 | actualAnno = e.getAnnotation(FooInherited.class); |
jfranck@1560 | 300 | } |
jfranck@1560 | 301 | if (repeatableAnno.contains( |
jfranck@1560 | 302 | e.getEnclosingElement().toString()) |
jfranck@1560 | 303 | || repeatableAnno.contains( |
jfranck@1560 | 304 | e.getSimpleName().toString())) { |
jfranck@1560 | 305 | actualAnno = e.getAnnotation(Bar.class); |
jfranck@1560 | 306 | } |
jfranck@1560 | 307 | if (repeatableInheritedAnno.contains( |
jfranck@1560 | 308 | e.getEnclosingElement().toString()) |
jfranck@1560 | 309 | || repeatableInheritedAnno.contains( |
jfranck@1560 | 310 | e.getSimpleName().toString())) { |
jfranck@1560 | 311 | actualAnno = e.getAnnotation(BarInherited.class); |
jfranck@1560 | 312 | } |
jfranck@1560 | 313 | if (repeatableContainerInheritedAnno.contains( |
jfranck@1560 | 314 | e.getEnclosingElement().toString()) |
jfranck@1560 | 315 | || repeatableContainerInheritedAnno.contains( |
jfranck@1560 | 316 | e.getSimpleName().toString())) { |
jfranck@1560 | 317 | actualAnno = e.getAnnotation(BarInheritedContainer.class); |
jfranck@1560 | 318 | } |
jfranck@1560 | 319 | return actualAnno; |
jfranck@1560 | 320 | } |
jfranck@1560 | 321 | |
jfranck@1560 | 322 | private Annotation getAnnotationContainer(Element e) { |
jfranck@1560 | 323 | Annotation actualAnno = specialAnno; |
jfranck@1560 | 324 | |
jfranck@1560 | 325 | if (repeatableAnnoContainer.contains( |
jfranck@1560 | 326 | e.getEnclosingElement().toString()) |
jfranck@1560 | 327 | || repeatableAnnoContainer.contains( |
jfranck@1560 | 328 | e.getSimpleName().toString())) { |
jfranck@1560 | 329 | actualAnno = e.getAnnotation(BarContainer.class); |
jfranck@1560 | 330 | } |
jfranck@1560 | 331 | if (repeatableInheritedAnnoContainer.contains( |
jfranck@1560 | 332 | e.getEnclosingElement().toString()) |
jfranck@1560 | 333 | || repeatableInheritedAnnoContainer.contains( |
jfranck@1560 | 334 | e.getSimpleName().toString())) { |
jfranck@1560 | 335 | actualAnno = e.getAnnotation(BarInheritedContainer.class); |
jfranck@1560 | 336 | } |
jfranck@1560 | 337 | if (repeatableContainerInheritedAnnoContainer.contains( |
jfranck@1560 | 338 | e.getEnclosingElement().toString()) |
jfranck@1560 | 339 | || repeatableContainerInheritedAnnoContainer.contains( |
jfranck@1560 | 340 | e.getSimpleName().toString())) { |
jfranck@1560 | 341 | actualAnno = e.getAnnotation(BarInheritedContainerContainer.class); |
jfranck@1560 | 342 | } |
jfranck@1560 | 343 | if (unofficialAnnoContainer.contains( |
jfranck@1560 | 344 | e.getEnclosingElement().toString()) |
jfranck@1560 | 345 | || unofficialAnnoContainer.contains( |
jfranck@1560 | 346 | e.getSimpleName().toString())) { |
jfranck@1560 | 347 | actualAnno = e.getAnnotation(UnofficialContainer.class); |
jfranck@1560 | 348 | } |
jfranck@1560 | 349 | if (unofficialInheritedAnnoContainer.contains( |
jfranck@1560 | 350 | e.getEnclosingElement().toString()) |
jfranck@1560 | 351 | || unofficialInheritedAnnoContainer.contains( |
jfranck@1560 | 352 | e.getSimpleName().toString())) { |
jfranck@1560 | 353 | actualAnno = e.getAnnotation(UnofficialInheritedContainer.class); |
jfranck@1560 | 354 | } |
jfranck@1560 | 355 | return actualAnno; |
jfranck@1560 | 356 | } |
jfranck@1560 | 357 | |
jfranck@1560 | 358 | private Annotation[] getAnnotationsBase(Element e) { |
jfranck@1560 | 359 | Annotation[] actualAnnosArgs = specialAnnoArray; |
jfranck@1560 | 360 | |
jfranck@1560 | 361 | if (singularAnno.contains( |
jfranck@1560 | 362 | e.getEnclosingElement().toString()) |
jfranck@1560 | 363 | || singularAnno.contains( |
jfranck@1560 | 364 | e.getSimpleName().toString()) |
jfranck@1560 | 365 | || unofficialAnno.contains( |
jfranck@1560 | 366 | e.getEnclosingElement().toString()) |
jfranck@1560 | 367 | || unofficialAnno.contains( |
jfranck@1560 | 368 | e.getSimpleName().toString())) { |
jfranck@1564 | 369 | actualAnnosArgs = e.getAnnotationsByType(Foo.class); |
jfranck@1560 | 370 | } |
jfranck@1560 | 371 | if (singularInheritedAnno.contains( |
jfranck@1560 | 372 | e.getEnclosingElement().toString()) |
jfranck@1560 | 373 | || singularInheritedAnno.contains( |
jfranck@1560 | 374 | e.getSimpleName().toString()) |
jfranck@1560 | 375 | || unofficialInheritedAnno.contains( |
jfranck@1560 | 376 | e.getEnclosingElement().toString()) |
jfranck@1560 | 377 | || unofficialInheritedAnno.contains( |
jfranck@1560 | 378 | e.getSimpleName().toString())) { |
jfranck@1564 | 379 | actualAnnosArgs = e.getAnnotationsByType(FooInherited.class); |
jfranck@1560 | 380 | } |
jfranck@1560 | 381 | if (repeatableAnno.contains( |
jfranck@1560 | 382 | e.getEnclosingElement().toString()) |
jfranck@1560 | 383 | || repeatableAnno.contains( |
jfranck@1560 | 384 | e.getSimpleName().toString())) { |
jfranck@1564 | 385 | actualAnnosArgs = e.getAnnotationsByType(Bar.class); |
jfranck@1560 | 386 | } |
jfranck@1560 | 387 | if (repeatableInheritedAnno.contains( |
jfranck@1560 | 388 | e.getEnclosingElement().toString()) |
jfranck@1560 | 389 | || repeatableInheritedAnno.contains( |
jfranck@1560 | 390 | e.getSimpleName().toString())) { |
jfranck@1564 | 391 | actualAnnosArgs = e.getAnnotationsByType(BarInherited.class); |
jfranck@1560 | 392 | } |
jfranck@1560 | 393 | if (repeatableContainerInheritedAnno.contains( |
jfranck@1560 | 394 | e.getEnclosingElement().toString()) |
jfranck@1560 | 395 | || repeatableContainerInheritedAnno.contains( |
jfranck@1560 | 396 | e.getSimpleName().toString())) { |
jfranck@1564 | 397 | actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainer.class); |
jfranck@1560 | 398 | } |
jfranck@1560 | 399 | return actualAnnosArgs; |
jfranck@1560 | 400 | } |
jfranck@1560 | 401 | |
jfranck@1560 | 402 | private Annotation[] getAnnotationsContainer(Element e) { |
jfranck@1560 | 403 | Annotation[] actualAnnosArgs = specialAnnoArray; |
jfranck@1560 | 404 | |
jfranck@1560 | 405 | if (repeatableAnnoContainer.contains( |
jfranck@1560 | 406 | e.getEnclosingElement().toString()) |
jfranck@1560 | 407 | || repeatableAnnoContainer.contains( |
jfranck@1560 | 408 | e.getSimpleName().toString())) { |
jfranck@1564 | 409 | actualAnnosArgs = e.getAnnotationsByType(BarContainer.class); |
jfranck@1560 | 410 | } |
jfranck@1560 | 411 | if (repeatableInheritedAnnoContainer.contains( |
jfranck@1560 | 412 | e.getEnclosingElement().toString()) |
jfranck@1560 | 413 | || repeatableInheritedAnnoContainer.contains( |
jfranck@1560 | 414 | e.getSimpleName().toString())) { |
jfranck@1564 | 415 | actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainer.class); |
jfranck@1560 | 416 | } |
jfranck@1560 | 417 | if (repeatableContainerInheritedAnnoContainer.contains( |
jfranck@1560 | 418 | e.getEnclosingElement().toString()) |
jfranck@1560 | 419 | || repeatableContainerInheritedAnnoContainer.contains( |
jfranck@1560 | 420 | e.getSimpleName().toString())) { |
jfranck@1564 | 421 | actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainerContainer.class); |
jfranck@1560 | 422 | } |
jfranck@1560 | 423 | if (unofficialAnnoContainer.contains( |
jfranck@1560 | 424 | e.getEnclosingElement().toString()) |
jfranck@1560 | 425 | || unofficialAnnoContainer.contains( |
jfranck@1560 | 426 | e.getSimpleName().toString())) { |
jfranck@1564 | 427 | actualAnnosArgs = e.getAnnotationsByType(UnofficialContainer.class); |
jfranck@1560 | 428 | } |
jfranck@1560 | 429 | if (unofficialInheritedAnnoContainer.contains( |
jfranck@1560 | 430 | e.getEnclosingElement().toString()) |
jfranck@1560 | 431 | || unofficialInheritedAnnoContainer.contains( |
jfranck@1560 | 432 | e.getSimpleName().toString())) { |
jfranck@1564 | 433 | actualAnnosArgs = e.getAnnotationsByType(UnofficialInheritedContainer.class); |
jfranck@1560 | 434 | } |
jfranck@1560 | 435 | return actualAnnosArgs; |
jfranck@1560 | 436 | } |
jfranck@1560 | 437 | |
jfranck@1560 | 438 | // Array comparison: Length should be same and all expected values |
jfranck@1560 | 439 | // should be present in actualAnnos[]. |
jfranck@1560 | 440 | private boolean compareArrVals(Annotation[] actualAnnos, String[] expectedAnnos) { |
jfranck@1560 | 441 | // Look if test case was run. |
jfranck@1560 | 442 | if (actualAnnos == specialAnnoArray) { |
jfranck@1560 | 443 | return false; // no testcase matches |
jfranck@1560 | 444 | } |
jfranck@1560 | 445 | if (actualAnnos.length != expectedAnnos.length) { |
jfranck@1560 | 446 | System.out.println("Length not same. " |
jfranck@1560 | 447 | + " actualAnnos length = " + actualAnnos.length |
jfranck@1560 | 448 | + " expectedAnnos length = " + expectedAnnos.length); |
jfranck@1560 | 449 | printArrContents(actualAnnos); |
jfranck@1560 | 450 | printArrContents(expectedAnnos); |
jfranck@1560 | 451 | return false; |
jfranck@1560 | 452 | } else { |
jfranck@1560 | 453 | int i = 0; |
jfranck@1560 | 454 | String[] actualArr = new String[actualAnnos.length]; |
jfranck@1560 | 455 | for (Annotation a : actualAnnos) { |
jfranck@1560 | 456 | actualArr[i++] = a.toString(); |
jfranck@1560 | 457 | } |
jfranck@1560 | 458 | List<String> actualList = Arrays.asList(actualArr); |
jfranck@1560 | 459 | List<String> expectedList = Arrays.asList(expectedAnnos); |
jfranck@1560 | 460 | |
jfranck@1560 | 461 | if (!actualList.containsAll(expectedList)) { |
jfranck@1560 | 462 | System.out.println("Array values are not same"); |
jfranck@1560 | 463 | printArrContents(actualAnnos); |
jfranck@1560 | 464 | printArrContents(expectedAnnos); |
jfranck@1560 | 465 | return false; |
jfranck@1560 | 466 | } |
jfranck@1560 | 467 | } |
jfranck@1560 | 468 | return true; |
jfranck@1560 | 469 | } |
jfranck@1560 | 470 | |
jfranck@1560 | 471 | // Array comparison: Length should be same and all expected values |
jfranck@1560 | 472 | // should be present in actualAnnos List<?>. |
jfranck@1560 | 473 | private boolean compareArrVals(List<? extends AnnotationMirror> actualAnnos, |
jfranck@1560 | 474 | String[] expectedAnnos) { |
jfranck@1560 | 475 | // Look if test case was run. |
jfranck@1560 | 476 | if (actualAnnos == specialAnnoMirrors) { |
jfranck@1560 | 477 | return false; //no testcase run |
jfranck@1560 | 478 | } |
jfranck@1560 | 479 | if (actualAnnos.size() != expectedAnnos.length) { |
jfranck@1560 | 480 | System.out.println("Length not same. " |
jfranck@1560 | 481 | + " actualAnnos length = " + actualAnnos.size() |
jfranck@1560 | 482 | + " expectedAnnos length = " + expectedAnnos.length); |
jfranck@1560 | 483 | printArrContents(actualAnnos); |
jfranck@1560 | 484 | printArrContents(expectedAnnos); |
jfranck@1560 | 485 | return false; |
jfranck@1560 | 486 | } else { |
jfranck@1560 | 487 | int i = 0; |
jfranck@1560 | 488 | String[] actualArr = new String[actualAnnos.size()]; |
jfranck@1560 | 489 | String annoTypeName = ""; |
jfranck@1560 | 490 | for (AnnotationMirror annotationMirror : actualAnnos) { |
jfranck@1560 | 491 | if (annotationMirror.getAnnotationType().toString().contains("Expected")) { |
jfranck@1560 | 492 | annoTypeName = annotationMirror.getAnnotationType().toString(); |
jfranck@1560 | 493 | } else { |
jfranck@1560 | 494 | annoTypeName = annotationMirror.toString(); |
jfranck@1560 | 495 | } |
jfranck@1560 | 496 | actualArr[i++] = annoTypeName; |
jfranck@1560 | 497 | } |
jfranck@1560 | 498 | List<String> actualList = Arrays.asList(actualArr); |
jfranck@1560 | 499 | List<String> expectedList = Arrays.asList(expectedAnnos); |
jfranck@1560 | 500 | |
jfranck@1560 | 501 | if (!actualList.containsAll(expectedList)) { |
jfranck@1560 | 502 | System.out.println("Array values are not same"); |
jfranck@1560 | 503 | printArrContents(actualAnnos); |
jfranck@1560 | 504 | printArrContents(expectedAnnos); |
jfranck@1560 | 505 | return false; |
jfranck@1560 | 506 | } |
jfranck@1560 | 507 | } |
jfranck@1560 | 508 | return true; |
jfranck@1560 | 509 | } |
jfranck@1560 | 510 | |
jfranck@1560 | 511 | private void printArrContents(Annotation[] actualAnnos) { |
jfranck@1560 | 512 | for (Annotation a : actualAnnos) { |
jfranck@1560 | 513 | System.out.println("actualAnnos values = " + a); |
jfranck@1560 | 514 | } |
jfranck@1560 | 515 | } |
jfranck@1560 | 516 | |
jfranck@1560 | 517 | private void printArrContents(String[] expectedAnnos) { |
jfranck@1560 | 518 | for (String s : expectedAnnos) { |
jfranck@1560 | 519 | System.out.println("expectedAnnos values = " + s); |
jfranck@1560 | 520 | } |
jfranck@1560 | 521 | } |
jfranck@1560 | 522 | |
jfranck@1560 | 523 | private void printArrContents(List<? extends AnnotationMirror> actualAnnos) { |
jfranck@1560 | 524 | for (AnnotationMirror annotationMirror : actualAnnos) { |
jfranck@1560 | 525 | System.out.println("actualAnnos values = " + annotationMirror); |
jfranck@1560 | 526 | } |
jfranck@1560 | 527 | } |
jfranck@1560 | 528 | |
jfranck@1560 | 529 | private boolean compareAnnotation(Annotation actualAnno, String expectedAnno) { |
jfranck@1560 | 530 | //String actualAnnoName = ""; |
jfranck@1560 | 531 | boolean isSame = true; |
jfranck@1560 | 532 | // Look if test case was run. |
jfranck@1560 | 533 | if (actualAnno == specialAnno) { |
jfranck@1560 | 534 | return false; //no testcase run |
jfranck@1560 | 535 | } |
jfranck@1560 | 536 | if (actualAnno != null) { |
jfranck@1560 | 537 | if (!actualAnno.toString().equalsIgnoreCase(expectedAnno)) { |
jfranck@1560 | 538 | System.out.println("Anno did not match. " |
jfranck@1560 | 539 | + " expectedAnno = " + expectedAnno |
jfranck@1560 | 540 | + " actualAnno = " + actualAnno); |
jfranck@1560 | 541 | isSame = false; |
jfranck@1560 | 542 | } else { |
jfranck@1560 | 543 | isSame = true; |
jfranck@1560 | 544 | } |
jfranck@1560 | 545 | } else { |
jfranck@1560 | 546 | if (expectedAnno.compareToIgnoreCase("null") == 0) { |
jfranck@1560 | 547 | isSame = true; |
jfranck@1560 | 548 | } else { |
jfranck@1560 | 549 | System.out.println("Actual anno is null"); |
jfranck@1560 | 550 | isSame = false; |
jfranck@1560 | 551 | } |
jfranck@1560 | 552 | } |
jfranck@1560 | 553 | return isSame; |
jfranck@1560 | 554 | } |
jfranck@1560 | 555 | } |