1.1 --- a/test/lib/annotations/annotations/classfile/ClassfileInspector.java Wed Dec 10 14:35:58 2014 -0800 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,1733 +0,0 @@ 1.4 -/* 1.5 - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 - * 1.8 - * This code is free software; you can redistribute it and/or modify it 1.9 - * under the terms of the GNU General Public License version 2 only, as 1.10 - * published by the Free Software Foundation. 1.11 - * 1.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 - * version 2 for more details (a copy is included in the LICENSE file that 1.16 - * accompanied this code). 1.17 - * 1.18 - * You should have received a copy of the GNU General Public License version 1.19 - * 2 along with this work; if not, write to the Free Software Foundation, 1.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 - * 1.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 - * or visit www.oracle.com if you need additional information or have any 1.24 - * questions. 1.25 - */ 1.26 - 1.27 -package annotations.classfile; 1.28 - 1.29 -import java.io.*; 1.30 -import java.net.URL; 1.31 -import java.util.List; 1.32 - 1.33 -import com.sun.tools.classfile.*; 1.34 - 1.35 -/** 1.36 - * A class providing utilities for writing tests that inspect class 1.37 - * files directly, looking for specific type annotations. 1.38 - * 1.39 - * Note: this framework does not currently handle repeating 1.40 - * annotations. 1.41 - */ 1.42 -public class ClassfileInspector { 1.43 - 1.44 - /** 1.45 - * A group of expected annotations to be found in a given class. 1.46 - * If the class name is null, then the template will be applied to 1.47 - * every class. 1.48 - */ 1.49 - public static class Expected { 1.50 - /** 1.51 - * The name of the class. If {@code null} this template will 1.52 - * apply to every class; otherwise, it will only be applied to 1.53 - * the named class. 1.54 - */ 1.55 - public final String classname; 1.56 - 1.57 - /** 1.58 - * The expected class annotations. These will be checked 1.59 - * against the class' attributes. 1.60 - */ 1.61 - public final ExpectedAnnotation[] classAnnos; 1.62 - 1.63 - /** 1.64 - * The expected method annotations. These will be checked 1.65 - * against all methods in the class. 1.66 - */ 1.67 - public final ExpectedMethodAnnotation[] methodAnnos; 1.68 - 1.69 - /** 1.70 - * The expected method parameter annotations. These will be checked 1.71 - * against all methods in the class. 1.72 - */ 1.73 - public final ExpectedParameterAnnotation[] methodParamAnnos; 1.74 - 1.75 - /** 1.76 - * The expected field type annotations. These will be checked 1.77 - * against all fields in the class. 1.78 - */ 1.79 - public final ExpectedFieldAnnotation[] fieldAnnos; 1.80 - 1.81 - /** 1.82 - * The expected class type annotations. These will be checked 1.83 - * against the class' attributes. 1.84 - */ 1.85 - public final ExpectedTypeAnnotation[] classTypeAnnos; 1.86 - 1.87 - /** 1.88 - * The expected method type annotations. These will be checked 1.89 - * against all methods in the class. 1.90 - */ 1.91 - public final ExpectedMethodTypeAnnotation[] methodTypeAnnos; 1.92 - 1.93 - /** 1.94 - * The expected field type annotations. These will be checked 1.95 - * against all fields in the class. 1.96 - */ 1.97 - public final ExpectedFieldTypeAnnotation[] fieldTypeAnnos; 1.98 - 1.99 - /** 1.100 - * Create an {@code Expected} from all components. 1.101 - * 1.102 - * @param classname The name of the class to match, or {@code 1.103 - * null} for all classes. 1.104 - * @param classAnnos The expected class annotations. 1.105 - * @param methodAnnos The expected method annotations. 1.106 - * @param methodParamAnnos The expected method parameter annotations. 1.107 - * @param fieldAnnos The expected field annotations. 1.108 - * @param classTypeAnnos The expected class type annotations. 1.109 - * @param methodTypeAnnos The expected method type annotations. 1.110 - * @param fieldTypeAnnos The expected field type annotations. 1.111 - */ 1.112 - public Expected(String classname, 1.113 - ExpectedAnnotation[] classAnnos, 1.114 - ExpectedMethodAnnotation[] methodAnnos, 1.115 - ExpectedParameterAnnotation[] methodParamAnnos, 1.116 - ExpectedFieldAnnotation[] fieldAnnos, 1.117 - ExpectedTypeAnnotation[] classTypeAnnos, 1.118 - ExpectedMethodTypeAnnotation[] methodTypeAnnos, 1.119 - ExpectedFieldTypeAnnotation[] fieldTypeAnnos) { 1.120 - this.classname = classname; 1.121 - this.classAnnos = classAnnos; 1.122 - this.methodAnnos = methodAnnos; 1.123 - this.methodParamAnnos = methodParamAnnos; 1.124 - this.fieldAnnos = fieldAnnos; 1.125 - this.classTypeAnnos = classTypeAnnos; 1.126 - this.methodTypeAnnos = methodTypeAnnos; 1.127 - this.fieldTypeAnnos = fieldTypeAnnos; 1.128 - } 1.129 - 1.130 - /** 1.131 - * Create an {@code Expected} from regular annotation components. 1.132 - * 1.133 - * @param classname The name of the class to match, or {@code 1.134 - * null} for all classes. 1.135 - * @param classAnnos The expected class annotations. 1.136 - * @param methodAnnos The expected method annotations. 1.137 - * @param methodParamAnnos The expected method parameter annotations. 1.138 - * @param fieldAnnos The expected field annotations. 1.139 - */ 1.140 - public Expected(String classname, 1.141 - ExpectedAnnotation[] classAnnos, 1.142 - ExpectedMethodAnnotation[] methodAnnos, 1.143 - ExpectedParameterAnnotation[] methodParamAnnos, 1.144 - ExpectedFieldAnnotation[] fieldAnnos) { 1.145 - this(classname, classAnnos, methodAnnos, methodParamAnnos, 1.146 - fieldAnnos, null, null, null); 1.147 - } 1.148 - 1.149 - /** 1.150 - * Create an {@code Expected} from type annotation components. 1.151 - * 1.152 - * @param classname The name of the class to match, or {@code 1.153 - * null} for all classes. 1.154 - * @param classTypeAnnos The expected class type annotations. 1.155 - * @param methodTypeAnnos The expected method type annotations. 1.156 - * @param fieldTypeAnnos The expected field type annotations. 1.157 - */ 1.158 - public Expected(String classname, 1.159 - ExpectedTypeAnnotation[] classTypeAnnos, 1.160 - ExpectedMethodTypeAnnotation[] methodTypeAnnos, 1.161 - ExpectedFieldTypeAnnotation[] fieldTypeAnnos) { 1.162 - this(classname, null, null, null, null, 1.163 - classTypeAnnos, methodTypeAnnos, fieldTypeAnnos); 1.164 - } 1.165 - 1.166 - public String toString() { 1.167 - final StringBuilder sb = new StringBuilder(); 1.168 - final String newline = System.lineSeparator(); 1.169 - sb.append("Expected on class ").append(classname); 1.170 - if (null != classAnnos) { 1.171 - sb.append(newline).append("Class annotations:").append(newline); 1.172 - for(ExpectedAnnotation anno : classAnnos) { 1.173 - sb.append(anno).append(newline); 1.174 - } 1.175 - } 1.176 - if (null != methodAnnos) { 1.177 - sb.append(newline).append("Method annotations:").append(newline); 1.178 - for(ExpectedAnnotation anno : methodAnnos) { 1.179 - sb.append(anno).append(newline); 1.180 - } 1.181 - } 1.182 - if (null != methodParamAnnos) { 1.183 - sb.append(newline).append("Method param annotations:").append(newline); 1.184 - for(ExpectedAnnotation anno : methodParamAnnos) { 1.185 - sb.append(anno).append(newline); 1.186 - } 1.187 - } 1.188 - if (null != fieldAnnos) { 1.189 - sb.append(newline).append("Field annotations:").append(newline); 1.190 - for(ExpectedAnnotation anno : fieldAnnos) { 1.191 - sb.append(anno).append(newline); 1.192 - } 1.193 - } 1.194 - if (null != classTypeAnnos) { 1.195 - sb.append(newline).append("Class type annotations:").append(newline); 1.196 - for(ExpectedAnnotation anno : classTypeAnnos) { 1.197 - sb.append(anno).append(newline); 1.198 - } 1.199 - } 1.200 - if (null != methodTypeAnnos) { 1.201 - sb.append(newline).append("Method type annotations:").append(newline); 1.202 - for(ExpectedAnnotation anno : methodTypeAnnos) { 1.203 - sb.append(anno).append(newline); 1.204 - } 1.205 - } 1.206 - if (null != fieldTypeAnnos) { 1.207 - sb.append(newline).append("Field type annotations:").append(newline); 1.208 - for(ExpectedAnnotation anno : fieldTypeAnnos) { 1.209 - sb.append(anno).append(newline); 1.210 - } 1.211 - } 1.212 - return sb.toString(); 1.213 - } 1.214 - 1.215 - /** 1.216 - * See if this template applies to a class. 1.217 - * 1.218 - * @param classname The classname to check. 1.219 - * @return Whether or not this template should apply. 1.220 - */ 1.221 - public boolean matchClassName(String classname) { 1.222 - return this.classname == null || this.classname.equals(classname); 1.223 - } 1.224 - 1.225 - /** 1.226 - * After applying the template to all classes, check to see if 1.227 - * any of the expected annotations weren't matched. 1.228 - * 1.229 - * @return The number of missed matches. 1.230 - */ 1.231 - public int check() { 1.232 - int count = 0; 1.233 - if (classAnnos != null) { 1.234 - for(ExpectedAnnotation expected : classAnnos) { 1.235 - if (!expected.check()) { 1.236 - count++; 1.237 - } 1.238 - } 1.239 - } 1.240 - if (methodAnnos != null) { 1.241 - for(ExpectedAnnotation expected : methodAnnos) { 1.242 - if (!expected.check()) { 1.243 - count++; 1.244 - } 1.245 - } 1.246 - } 1.247 - if (methodParamAnnos != null) { 1.248 - for(ExpectedAnnotation expected : methodParamAnnos) { 1.249 - if (!expected.check()) { 1.250 - count++; 1.251 - } 1.252 - } 1.253 - } 1.254 - if (fieldAnnos != null) { 1.255 - for(ExpectedAnnotation expected : fieldAnnos) { 1.256 - if (!expected.check()) { 1.257 - count++; 1.258 - } 1.259 - } 1.260 - } 1.261 - if (classTypeAnnos != null) { 1.262 - for(ExpectedAnnotation expected : classTypeAnnos) { 1.263 - if (!expected.check()) { 1.264 - count++; 1.265 - } 1.266 - } 1.267 - } 1.268 - if (methodTypeAnnos != null) { 1.269 - for(ExpectedAnnotation expected : methodTypeAnnos) { 1.270 - if (!expected.check()) { 1.271 - count++; 1.272 - } 1.273 - } 1.274 - } 1.275 - if (fieldTypeAnnos != null) { 1.276 - for(ExpectedAnnotation expected : fieldTypeAnnos) { 1.277 - if (!expected.check()) { 1.278 - count++; 1.279 - } 1.280 - } 1.281 - } 1.282 - return count; 1.283 - } 1.284 - } 1.285 - 1.286 - /** 1.287 - * An expected annotation. This is both a superclass for 1.288 - * method, field, and type annotations, as well as a class for 1.289 - * annotations on a class. 1.290 - */ 1.291 - public static class ExpectedAnnotation { 1.292 - protected int count = 0; 1.293 - protected final String expectedName; 1.294 - protected final int expectedCount; 1.295 - protected final boolean visibility; 1.296 - 1.297 - /** 1.298 - * Create an {@code ExpectedAnnotation} from its 1.299 - * components. It is usually a better idea to use a {@code 1.300 - * Builder} to do this. 1.301 - * 1.302 - * @param expectedName The expected annotation name. 1.303 - * @param visibility Whether this annotation should be runtime-visible. 1.304 - * @param expectedCount The number of annotations that should 1.305 - * be seen. If 0, this asserts that the 1.306 - * described annotation is not present. 1.307 - */ 1.308 - public ExpectedAnnotation(String expectedName, 1.309 - boolean visibility, 1.310 - int expectedCount) { 1.311 - this.expectedName = expectedName; 1.312 - this.visibility = visibility; 1.313 - this.expectedCount = expectedCount; 1.314 - } 1.315 - 1.316 - public String toString() { 1.317 - final StringBuilder sb = new StringBuilder(); 1.318 - sb.append("Expected "); 1.319 - sb.append(expectedCount); 1.320 - sb.append(" annotation "); 1.321 - sb.append(expectedName); 1.322 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 1.323 - return sb.toString(); 1.324 - } 1.325 - 1.326 - /** 1.327 - * See if this template matches the given visibility. 1.328 - * 1.329 - * @param Whether or not the annotation is visible at runtime. 1.330 - * @return Whether or not this template matches the visibility. 1.331 - */ 1.332 - public boolean matchVisibility(boolean visibility) { 1.333 - return this.visibility == visibility; 1.334 - } 1.335 - 1.336 - /** 1.337 - * Attempty to match this template against an annotation. If 1.338 - * it does match, then the match count for the template will 1.339 - * be incremented. Otherwise, nothing will be done. 1.340 - * 1.341 - * @param anno The annotation to attempt to match. 1.342 - */ 1.343 - public void matchAnnotation(ConstantPool cpool, 1.344 - Annotation anno) { 1.345 - if (checkMatch(cpool, anno)) { 1.346 - count++; 1.347 - } 1.348 - } 1.349 - 1.350 - /** 1.351 - * Indicate whether an annotation matches this expected 1.352 - * annotation. 1.353 - * 1.354 - * @param ConstantPool The constant pool to use. 1.355 - * @param anno The annotation to check. 1.356 - * @return Whether the annotation matches. 1.357 - */ 1.358 - protected boolean checkMatch(ConstantPool cpool, 1.359 - Annotation anno) { 1.360 - try { 1.361 - return cpool.getUTF8Info(anno.type_index).value.equals("L" + expectedName + ";"); 1.362 - } catch(Exception e) { 1.363 - return false; 1.364 - } 1.365 - } 1.366 - 1.367 - /** 1.368 - * After all matching, check to see if the expected number of 1.369 - * matches equals the actual number. If not, then print a 1.370 - * failure message and return {@code false}. 1.371 - * 1.372 - * @return Whether or not the expected number of matched 1.373 - * equals the actual number. 1.374 - */ 1.375 - public boolean check() { 1.376 - if (count != expectedCount) { 1.377 - System.err.println(this + ", but saw " + count); 1.378 - return false; 1.379 - } else { 1.380 - return true; 1.381 - } 1.382 - } 1.383 - } 1.384 - 1.385 - /** 1.386 - * An annotation found on a method. 1.387 - */ 1.388 - public static class ExpectedMethodAnnotation extends ExpectedAnnotation { 1.389 - protected final String methodname; 1.390 - 1.391 - /** 1.392 - * Create an {@code ExpectedMethodAnnotation} from its 1.393 - * components. It is usually a better idea to use a {@code 1.394 - * Builder} to do this. 1.395 - * 1.396 - * @param methodname The expected method name. 1.397 - * @param expectedName The expected annotation name. 1.398 - * @param visibility Whether this annotation should be runtime-visible. 1.399 - * @param expectedCount The number of annotations that should be seen. 1.400 - */ 1.401 - public ExpectedMethodAnnotation(String methodname, 1.402 - String expectedName, 1.403 - boolean visibility, 1.404 - int expectedCount) { 1.405 - super(expectedName, visibility, expectedCount); 1.406 - this.methodname = methodname; 1.407 - } 1.408 - 1.409 - public String toString() { 1.410 - final StringBuilder sb = new StringBuilder(); 1.411 - sb.append("Expected "); 1.412 - sb.append(expectedCount); 1.413 - sb.append(" annotation "); 1.414 - sb.append(expectedName); 1.415 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 1.416 - sb.append(" on method "); 1.417 - sb.append(methodname); 1.418 - return sb.toString(); 1.419 - } 1.420 - 1.421 - /** 1.422 - * See if this template applies to a method. 1.423 - * 1.424 - * @param methodname The method name to check. 1.425 - * @return Whether or not this template should apply. 1.426 - */ 1.427 - public boolean matchMethodName(String methodname) { 1.428 - return this.methodname.equals(methodname); 1.429 - } 1.430 - 1.431 - } 1.432 - 1.433 - /** 1.434 - * An annotation found on a method parameter. 1.435 - */ 1.436 - public static class ExpectedParameterAnnotation 1.437 - extends ExpectedMethodAnnotation { 1.438 - protected final int index; 1.439 - 1.440 - /** 1.441 - * Create an {@code ExpectedParameterAnnotation} from its 1.442 - * components. It is usually a better idea to use a {@code 1.443 - * Builder} to do this. 1.444 - * 1.445 - * @param methodname The expected method name. 1.446 - * @param index The parameter index. 1.447 - * @param expectedName The expected annotation name. 1.448 - * @param visibility Whether this annotation should be runtime-visible. 1.449 - * @param expectedCount The number of annotations that should be seen. 1.450 - */ 1.451 - public ExpectedParameterAnnotation(String methodname, 1.452 - int index, 1.453 - String expectedName, 1.454 - boolean visibility, 1.455 - int expectedCount) { 1.456 - super(methodname, expectedName, visibility, expectedCount); 1.457 - this.index = index; 1.458 - } 1.459 - 1.460 - public String toString() { 1.461 - final StringBuilder sb = new StringBuilder(); 1.462 - sb.append("Expected "); 1.463 - sb.append(expectedCount); 1.464 - sb.append(" annotation "); 1.465 - sb.append(expectedName); 1.466 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 1.467 - sb.append(" on method "); 1.468 - sb.append(methodname); 1.469 - sb.append(" parameter " + index); 1.470 - return sb.toString(); 1.471 - } 1.472 - 1.473 - } 1.474 - 1.475 - /** 1.476 - * An annotation found on a field. 1.477 - */ 1.478 - public static class ExpectedFieldAnnotation extends ExpectedAnnotation { 1.479 - private final String fieldname; 1.480 - 1.481 - /** 1.482 - * Create an {@code ExpectedFieldAnnotation} from its 1.483 - * components. It is usually a better idea to use a {@code 1.484 - * Builder} to do this. 1.485 - * 1.486 - * @param fieldname The expected field name. 1.487 - * @param expectedName The expected annotation name. 1.488 - * @param visibility Whether this annotation should be runtime-visible. 1.489 - * @param expectedCount The number of annotations that should be seen. 1.490 - */ 1.491 - public ExpectedFieldAnnotation(String fieldname, 1.492 - String expectedName, 1.493 - boolean visibility, 1.494 - int expectedCount) { 1.495 - super(expectedName, visibility, expectedCount); 1.496 - this.fieldname = fieldname; 1.497 - } 1.498 - 1.499 - public String toString() { 1.500 - final StringBuilder sb = new StringBuilder(); 1.501 - sb.append("Expected ").append(expectedCount) 1.502 - .append(" annotation ").append(expectedName) 1.503 - .append(visibility ? ", runtime visibile " : ", runtime invisibile ") 1.504 - .append(" on field ").append(fieldname); 1.505 - return sb.toString(); 1.506 - } 1.507 - 1.508 - /** 1.509 - * See if this template applies to a field. 1.510 - * 1.511 - * @param fieldname The field name to check. 1.512 - * @return Whether or not this template should apply. 1.513 - */ 1.514 - public boolean matchFieldName(String fieldname) { 1.515 - return this.fieldname.equals(fieldname); 1.516 - } 1.517 - 1.518 - } 1.519 - 1.520 - /** 1.521 - * An expected type annotation. This is both a superclass for 1.522 - * method and field type annotations, as well as a class for type 1.523 - * annotations on a class. 1.524 - */ 1.525 - public static class ExpectedTypeAnnotation extends ExpectedAnnotation { 1.526 - protected final TypeAnnotation.TargetType targetType; 1.527 - protected final int bound_index; 1.528 - protected final int parameter_index; 1.529 - protected final int type_index; 1.530 - protected final int exception_index; 1.531 - protected final TypeAnnotation.Position.TypePathEntry[] typePath; 1.532 - 1.533 - /** 1.534 - * Create an {@code ExpectedTypeAnnotation} from its 1.535 - * components. It is usually a better idea to use a {@code 1.536 - * Builder} to do this. 1.537 - * 1.538 - * @param expectedName The expected annotation name. 1.539 - * @param visibility Whether this annotation should be runtime-visible. 1.540 - * @param expectedCount The number of annotations that should 1.541 - * be seen. If 0, this asserts that the 1.542 - * described annotation is not present. 1.543 - * @param targetType The expected target type. 1.544 - * @param bound_index The expected bound index, or {@code Integer.MIN_VALUE}. 1.545 - * @param parameter_index The expected parameter index, or 1.546 - * {@code Integer.MIN_VALUE}. 1.547 - * @param type_index The expected type index, or {@code Integer.MIN_VALUE}. 1.548 - * @param exception_index The expected exception index, or 1.549 - * {@code Integer.MIN_VALUE}. 1.550 - * @param typePath The expected type path. 1.551 - */ 1.552 - public ExpectedTypeAnnotation(String expectedName, 1.553 - boolean visibility, 1.554 - int expectedCount, 1.555 - TypeAnnotation.TargetType targetType, 1.556 - int bound_index, 1.557 - int parameter_index, 1.558 - int type_index, 1.559 - int exception_index, 1.560 - TypeAnnotation.Position.TypePathEntry... typePath) { 1.561 - super(expectedName, visibility, expectedCount); 1.562 - this.targetType = targetType; 1.563 - this.bound_index = bound_index; 1.564 - this.parameter_index = parameter_index; 1.565 - this.type_index = type_index; 1.566 - this.exception_index = exception_index; 1.567 - this.typePath = typePath; 1.568 - } 1.569 - 1.570 - public String toString() { 1.571 - final StringBuilder sb = new StringBuilder(); 1.572 - sb.append("Expected "); 1.573 - sb.append(expectedCount); 1.574 - sb.append(" annotation "); 1.575 - sb.append(expectedName); 1.576 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 1.577 - sb.append(targetType); 1.578 - sb.append(", bound_index = "); 1.579 - sb.append(bound_index); 1.580 - sb.append(", parameter_index = "); 1.581 - sb.append(parameter_index); 1.582 - sb.append(", type_index = "); 1.583 - sb.append(type_index); 1.584 - sb.append(", exception_index = "); 1.585 - sb.append(exception_index); 1.586 - sb.append(", type_path = ["); 1.587 - for(int i = 0; i < typePath.length; i++) { 1.588 - if (i != 0) { 1.589 - sb.append(", "); 1.590 - } 1.591 - sb.append(typePath[i]); 1.592 - } 1.593 - sb.append("]"); 1.594 - return sb.toString(); 1.595 - } 1.596 - 1.597 - @Override 1.598 - public void matchAnnotation(ConstantPool cpool, 1.599 - Annotation anno) {} 1.600 - 1.601 - public void matchAnnotation(TypeAnnotation anno) { 1.602 - if (checkMatch(anno)) { 1.603 - count++; 1.604 - } 1.605 - } 1.606 - 1.607 - public boolean checkMatch(TypeAnnotation anno) { 1.608 - boolean matches = checkMatch(anno.constant_pool, anno.annotation); 1.609 - 1.610 - matches = matches && anno.position.type == targetType; 1.611 - matches = matches && anno.position.bound_index == bound_index; 1.612 - matches = matches && anno.position.parameter_index == parameter_index; 1.613 - matches = matches && anno.position.type_index == type_index; 1.614 - matches = matches && anno.position.exception_index == exception_index; 1.615 - matches = matches && anno.position.location.size() == typePath.length; 1.616 - 1.617 - if (matches) { 1.618 - int i = 0; 1.619 - for(TypeAnnotation.Position.TypePathEntry entry : 1.620 - anno.position.location) { 1.621 - matches = matches && typePath[i++].equals(entry); 1.622 - } 1.623 - } 1.624 - 1.625 - return matches; 1.626 - } 1.627 - 1.628 - /** 1.629 - * A builder class for creating {@code 1.630 - * ExpectedTypeAnnotation}s in a more convenient fashion. The 1.631 - * constructor for {@code ExpectedTypeAnnotation} takes a 1.632 - * large number of parameters (by necessity). This class 1.633 - * allows users to construct a {@code ExpectedTypeAnnotation}s 1.634 - * using only the ones they need. 1.635 - */ 1.636 - public static class Builder { 1.637 - protected final String expectedName; 1.638 - protected final boolean visibility; 1.639 - protected final int expectedCount; 1.640 - protected final TypeAnnotation.TargetType targetType; 1.641 - protected int bound_index = Integer.MIN_VALUE; 1.642 - protected int parameter_index = Integer.MIN_VALUE; 1.643 - protected int type_index = Integer.MIN_VALUE; 1.644 - protected int exception_index = Integer.MIN_VALUE; 1.645 - protected TypeAnnotation.Position.TypePathEntry[] typePath = 1.646 - new TypeAnnotation.Position.TypePathEntry[0]; 1.647 - 1.648 - /** 1.649 - * Create a {@code Builder} from the mandatory parameters. 1.650 - * 1.651 - * @param expectedName The expected annotation name. 1.652 - * @param targetType The expected target type. 1.653 - * @param visibility Whether this annotation should be runtime-visible. 1.654 - * @param expectedCount The number of annotations that should be seen. 1.655 - */ 1.656 - public Builder(String expectedName, 1.657 - TypeAnnotation.TargetType targetType, 1.658 - boolean visibility, 1.659 - int expectedCount) { 1.660 - this.expectedName = expectedName; 1.661 - this.visibility = visibility; 1.662 - this.expectedCount = expectedCount; 1.663 - this.targetType = targetType; 1.664 - } 1.665 - 1.666 - /** 1.667 - * Create an {@code ExpectedTypeAnnotation} from all 1.668 - * parameters that have been provided. The default values 1.669 - * will be used for those that have not. 1.670 - * 1.671 - * @return The cretaed {@code ExpectedTypeAnnotation}. 1.672 - */ 1.673 - public ExpectedTypeAnnotation build() { 1.674 - return new ExpectedTypeAnnotation(expectedName, visibility, 1.675 - expectedCount, targetType, 1.676 - bound_index, parameter_index, 1.677 - type_index, exception_index, 1.678 - typePath); 1.679 - } 1.680 - 1.681 - /** 1.682 - * Provide a bound index parameter. 1.683 - * 1.684 - * @param bound_index The bound_index value. 1.685 - */ 1.686 - public Builder setBoundIndex(int bound_index) { 1.687 - this.bound_index = bound_index; 1.688 - return this; 1.689 - } 1.690 - 1.691 - /** 1.692 - * Provide a parameter index parameter. 1.693 - * 1.694 - * @param bound_index The parameter_index value. 1.695 - */ 1.696 - public Builder setParameterIndex(int parameter_index) { 1.697 - this.parameter_index = parameter_index; 1.698 - return this; 1.699 - } 1.700 - 1.701 - /** 1.702 - * Provide a type index parameter. 1.703 - * 1.704 - * @param type_index The type_index value. 1.705 - */ 1.706 - public Builder setTypeIndex(int type_index) { 1.707 - this.type_index = type_index; 1.708 - return this; 1.709 - } 1.710 - 1.711 - /** 1.712 - * Provide an exception index parameter. 1.713 - * 1.714 - * @param exception_index The exception_index value. 1.715 - */ 1.716 - public Builder setExceptionIndex(int exception_index) { 1.717 - this.exception_index = exception_index; 1.718 - return this; 1.719 - } 1.720 - 1.721 - /** 1.722 - * Provide a type path parameter. 1.723 - * 1.724 - * @param typePath The type path value. 1.725 - */ 1.726 - public Builder setTypePath(TypeAnnotation.Position.TypePathEntry[] typePath) { 1.727 - this.typePath = typePath; 1.728 - return this; 1.729 - } 1.730 - } 1.731 - } 1.732 - 1.733 - /** 1.734 - * A type annotation found on a method. 1.735 - */ 1.736 - public static class ExpectedMethodTypeAnnotation extends ExpectedTypeAnnotation { 1.737 - private final String methodname; 1.738 - 1.739 - /** 1.740 - * Create an {@code ExpectedMethodTypeAnnotation} from its 1.741 - * components. It is usually a better idea to use a {@code 1.742 - * Builder} to do this. 1.743 - * 1.744 - * @param methodname The expected method name. 1.745 - * @param expectedName The expected annotation name. 1.746 - * @param visibility Whether this annotation should be runtime-visible. 1.747 - * @param expectedCount The number of annotations that should be seen. 1.748 - * @param targetType The expected target type. 1.749 - * @param bound_index The expected bound index, or {@code Integer.MIN_VALUE}. 1.750 - * @param parameter_index The expected parameter index, or 1.751 - * {@code Integer.MIN_VALUE}. 1.752 - * @param type_index The expected type index, or {@code Integer.MIN_VALUE}. 1.753 - * @param exception_index The expected exception index, or 1.754 - * {@code Integer.MIN_VALUE}. 1.755 - * @param typePath The expected type path. 1.756 - */ 1.757 - public ExpectedMethodTypeAnnotation(String methodname, 1.758 - String expectedName, 1.759 - boolean visibility, 1.760 - int expectedCount, 1.761 - TypeAnnotation.TargetType targetType, 1.762 - int bound_index, 1.763 - int parameter_index, 1.764 - int type_index, 1.765 - int exception_index, 1.766 - TypeAnnotation.Position.TypePathEntry... typePath) { 1.767 - super(expectedName, visibility, expectedCount, targetType, bound_index, 1.768 - parameter_index, type_index, exception_index, typePath); 1.769 - this.methodname = methodname; 1.770 - } 1.771 - 1.772 - public String toString() { 1.773 - final StringBuilder sb = new StringBuilder(); 1.774 - sb.append("Expected "); 1.775 - sb.append(expectedCount); 1.776 - sb.append(" annotation "); 1.777 - sb.append(expectedName); 1.778 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 1.779 - sb.append(targetType); 1.780 - sb.append(", bound_index = "); 1.781 - sb.append(bound_index); 1.782 - sb.append(", parameter_index = "); 1.783 - sb.append(parameter_index); 1.784 - sb.append(", type_index = "); 1.785 - sb.append(type_index); 1.786 - sb.append(", exception_index = "); 1.787 - sb.append(exception_index); 1.788 - sb.append(", type_path = ["); 1.789 - for(int i = 0; i < typePath.length; i++) { 1.790 - if (i != 0) { 1.791 - sb.append(", "); 1.792 - } 1.793 - sb.append(typePath[i]); 1.794 - } 1.795 - sb.append("]"); 1.796 - sb.append(" on method "); 1.797 - sb.append(methodname); 1.798 - return sb.toString(); 1.799 - } 1.800 - 1.801 - /** 1.802 - * See if this template applies to a method. 1.803 - * 1.804 - * @param methodname The method name to check. 1.805 - * @return Whether or not this template should apply. 1.806 - */ 1.807 - public boolean matchMethodName(String methodname) { 1.808 - return this.methodname.equals(methodname); 1.809 - } 1.810 - 1.811 - /** 1.812 - * A builder class for creating {@code 1.813 - * ExpectedMethodTypeAnnotation}s in a more convenient fashion. The 1.814 - * constructor for {@code ExpectedMethodTypeAnnotation} takes a 1.815 - * large number of parameters (by necessity). This class 1.816 - * allows users to construct a {@code ExpectedMethodTypeAnnotation}s 1.817 - * using only the ones they need. 1.818 - */ 1.819 - public static class Builder extends ExpectedTypeAnnotation.Builder { 1.820 - protected final String methodname; 1.821 - 1.822 - /** 1.823 - * Create a {@code Builder} from the mandatory parameters. 1.824 - * 1.825 - * @param methodname The expected method name. 1.826 - * @param expectedName The expected annotation name. 1.827 - * @param targetType The expected target type. 1.828 - * @param visibility Whether this annotation should be runtime-visible. 1.829 - * @param expectedCount The number of annotations that should be seen. 1.830 - */ 1.831 - public Builder(String methodname, 1.832 - String expectedName, 1.833 - TypeAnnotation.TargetType targetType, 1.834 - boolean visibility, 1.835 - int expectedCount) { 1.836 - super(expectedName, targetType, visibility, expectedCount); 1.837 - this.methodname = methodname; 1.838 - } 1.839 - 1.840 - /** 1.841 - * Create an {@code ExpectedMethodTypeAnnotation} from all 1.842 - * parameters that have been provided. The default values 1.843 - * will be used for those that have not. 1.844 - * 1.845 - * @return The cretaed {@code ExpectedMethodTypeAnnotation}. 1.846 - */ 1.847 - public ExpectedMethodTypeAnnotation build() { 1.848 - return new ExpectedMethodTypeAnnotation(methodname, expectedName, 1.849 - visibility, expectedCount, 1.850 - targetType, bound_index, 1.851 - parameter_index, type_index, 1.852 - exception_index, typePath); 1.853 - } 1.854 - } 1.855 - } 1.856 - 1.857 - /** 1.858 - * A type annotation found on a field. 1.859 - */ 1.860 - public static class ExpectedFieldTypeAnnotation extends ExpectedTypeAnnotation { 1.861 - private final String fieldname; 1.862 - 1.863 - /** 1.864 - * Create an {@code ExpectedFieldTypeAnnotation} from its 1.865 - * components. It is usually a better idea to use a {@code 1.866 - * Builder} to do this. 1.867 - * 1.868 - * @param fieldname The expected field name. 1.869 - * @param expectedName The expected annotation name. 1.870 - * @param visibility Whether this annotation should be runtime-visible. 1.871 - * @param expectedCount The number of annotations that should be seen. 1.872 - * @param targetType The expected target type. 1.873 - * @param bound_index The expected bound index, or {@code Integer.MIN_VALUE}. 1.874 - * @param parameter_index The expected parameter index, or 1.875 - * {@code Integer.MIN_VALUE}. 1.876 - * @param type_index The expected type index, or {@code Integer.MIN_VALUE}. 1.877 - * @param exception_index The expected exception index, or 1.878 - * {@code Integer.MIN_VALUE}. 1.879 - * @param typePath The expected type path. 1.880 - */ 1.881 - public ExpectedFieldTypeAnnotation(String fieldname, 1.882 - String expectedName, 1.883 - boolean visibility, 1.884 - int expectedCount, 1.885 - TypeAnnotation.TargetType targetType, 1.886 - int bound_index, 1.887 - int parameter_index, 1.888 - int type_index, 1.889 - int exception_index, 1.890 - TypeAnnotation.Position.TypePathEntry... typePath) { 1.891 - super(expectedName, visibility, expectedCount, targetType, bound_index, 1.892 - parameter_index, type_index, exception_index, typePath); 1.893 - this.fieldname = fieldname; 1.894 - } 1.895 - 1.896 - public String toString() { 1.897 - final StringBuilder sb = new StringBuilder(); 1.898 - sb.append("Expected ").append(expectedCount) 1.899 - .append(" annotation ").append(expectedName) 1.900 - .append(visibility ? ", runtime visibile " : ", runtime invisibile ") 1.901 - .append(targetType) 1.902 - .append(", bound_index = ").append(bound_index) 1.903 - .append(", parameter_index = ").append(parameter_index) 1.904 - .append(", type_index = ").append(type_index) 1.905 - .append(", exception_index = ").append(exception_index) 1.906 - .append(", type_path = ["); 1.907 - 1.908 - for(int i = 0; i < typePath.length; i++) { 1.909 - if (i != 0) { 1.910 - sb.append(", "); 1.911 - } 1.912 - sb.append(typePath[i]); 1.913 - } 1.914 - sb.append("]") 1.915 - .append(" on field ").append(fieldname); 1.916 - return sb.toString(); 1.917 - } 1.918 - 1.919 - /** 1.920 - * See if this template applies to a field. 1.921 - * 1.922 - * @param fieldname The field name to check. 1.923 - * @return Whether or not this template should apply. 1.924 - */ 1.925 - public boolean matchFieldName(String fieldname) { 1.926 - return this.fieldname.equals(fieldname); 1.927 - } 1.928 - 1.929 - /** 1.930 - * A builder class for creating {@code 1.931 - * ExpectedFieldTypeAnnotation}s in a more convenient fashion. The 1.932 - * constructor for {@code ExpectedFieldTypeAnnotation} takes a 1.933 - * large number of parameters (by necessity). This class 1.934 - * allows users to construct a {@code ExpectedFieldTypeAnnotation}s 1.935 - * using only the ones they need. 1.936 - */ 1.937 - public static class Builder extends ExpectedTypeAnnotation.Builder { 1.938 - protected final String fieldname; 1.939 - 1.940 - /** 1.941 - * Create a {@code Builder} from the mandatory parameters. 1.942 - * 1.943 - * @param fieldname The expected field name. 1.944 - * @param expectedName The expected annotation name. 1.945 - * @param targetType The expected target type. 1.946 - * @param visibility Whether this annotation should be runtime-visible. 1.947 - * @param expectedCount The number of annotations that should be seen. 1.948 - */ 1.949 - public Builder(String fieldname, 1.950 - String expectedName, 1.951 - TypeAnnotation.TargetType targetType, 1.952 - boolean visibility, 1.953 - int expectedCount) { 1.954 - super(expectedName, targetType, visibility, expectedCount); 1.955 - this.fieldname = fieldname; 1.956 - } 1.957 - 1.958 - /** 1.959 - * Create an {@code ExpectedFieldTypeAnnotation} from all 1.960 - * parameters that have been provided. The default values 1.961 - * will be used for those that have not. 1.962 - * 1.963 - * @return The cretaed {@code ExpectedFieldTypeAnnotation}. 1.964 - */ 1.965 - public ExpectedFieldTypeAnnotation build() { 1.966 - return new ExpectedFieldTypeAnnotation(fieldname, expectedName, 1.967 - visibility, expectedCount, 1.968 - targetType, bound_index, 1.969 - parameter_index, type_index, 1.970 - exception_index, typePath); 1.971 - } 1.972 - } 1.973 - } 1.974 - 1.975 - private void matchClassAnnotation(ClassFile classfile, 1.976 - ExpectedAnnotation expected) 1.977 - throws ConstantPoolException { 1.978 - for(Attribute attr : classfile.attributes) { 1.979 - attr.accept(annoMatcher(classfile.constant_pool), expected); 1.980 - } 1.981 - } 1.982 - 1.983 - private void matchMethodAnnotation(ClassFile classfile, 1.984 - ExpectedMethodAnnotation expected) 1.985 - throws ConstantPoolException { 1.986 - for(Method meth : classfile.methods) { 1.987 - if (expected.matchMethodName(meth.getName(classfile.constant_pool))) { 1.988 - for(Attribute attr : meth.attributes) { 1.989 - attr.accept(annoMatcher(classfile.constant_pool), expected); 1.990 - } 1.991 - } 1.992 - } 1.993 - } 1.994 - 1.995 - private void matchParameterAnnotation(ClassFile classfile, 1.996 - ExpectedParameterAnnotation expected) 1.997 - throws ConstantPoolException { 1.998 - for(Method meth : classfile.methods) { 1.999 - if (expected.matchMethodName(meth.getName(classfile.constant_pool))) { 1.1000 - for(Attribute attr : meth.attributes) { 1.1001 - attr.accept(paramMatcher(classfile.constant_pool), expected); 1.1002 - } 1.1003 - } 1.1004 - } 1.1005 - } 1.1006 - 1.1007 - private void matchFieldAnnotation(ClassFile classfile, 1.1008 - ExpectedFieldAnnotation expected) 1.1009 - throws ConstantPoolException { 1.1010 - for(Field field : classfile.fields) { 1.1011 - if (expected.matchFieldName(field.getName(classfile.constant_pool))) { 1.1012 - for(Attribute attr : field.attributes) { 1.1013 - attr.accept(annoMatcher(classfile.constant_pool), expected); 1.1014 - } 1.1015 - } 1.1016 - } 1.1017 - } 1.1018 - 1.1019 - private void matchClassTypeAnnotation(ClassFile classfile, 1.1020 - ExpectedTypeAnnotation expected) 1.1021 - throws ConstantPoolException { 1.1022 - for(Attribute attr : classfile.attributes) { 1.1023 - attr.accept(typeAnnoMatcher, expected); 1.1024 - } 1.1025 - } 1.1026 - 1.1027 - private void matchMethodTypeAnnotation(ClassFile classfile, 1.1028 - ExpectedMethodTypeAnnotation expected) 1.1029 - throws ConstantPoolException { 1.1030 - for(Method meth : classfile.methods) { 1.1031 - if (expected.matchMethodName(meth.getName(classfile.constant_pool))) { 1.1032 - for(Attribute attr : meth.attributes) { 1.1033 - attr.accept(typeAnnoMatcher, expected); 1.1034 - } 1.1035 - } 1.1036 - } 1.1037 - } 1.1038 - 1.1039 - private void matchFieldTypeAnnotation(ClassFile classfile, 1.1040 - ExpectedFieldTypeAnnotation expected) 1.1041 - throws ConstantPoolException { 1.1042 - for(Field field : classfile.fields) { 1.1043 - if (expected.matchFieldName(field.getName(classfile.constant_pool))) { 1.1044 - for(Attribute attr : field.attributes) { 1.1045 - attr.accept(typeAnnoMatcher, expected); 1.1046 - } 1.1047 - } 1.1048 - } 1.1049 - } 1.1050 - 1.1051 - private void matchClassAnnotations(ClassFile classfile, 1.1052 - ExpectedAnnotation[] expected) 1.1053 - throws ConstantPoolException { 1.1054 - for(ExpectedAnnotation one : expected) { 1.1055 - matchClassAnnotation(classfile, one); 1.1056 - } 1.1057 - } 1.1058 - 1.1059 - private void matchMethodAnnotations(ClassFile classfile, 1.1060 - ExpectedMethodAnnotation[] expected) 1.1061 - throws ConstantPoolException { 1.1062 - for(ExpectedMethodAnnotation one : expected) { 1.1063 - matchMethodAnnotation(classfile, one); 1.1064 - } 1.1065 - } 1.1066 - 1.1067 - private void matchParameterAnnotations(ClassFile classfile, 1.1068 - ExpectedParameterAnnotation[] expected) 1.1069 - throws ConstantPoolException { 1.1070 - for(ExpectedParameterAnnotation one : expected) { 1.1071 - matchParameterAnnotation(classfile, one); 1.1072 - } 1.1073 - } 1.1074 - 1.1075 - private void matchFieldAnnotations(ClassFile classfile, 1.1076 - ExpectedFieldAnnotation[] expected) 1.1077 - throws ConstantPoolException { 1.1078 - for(ExpectedFieldAnnotation one : expected) { 1.1079 - matchFieldAnnotation(classfile, one); 1.1080 - } 1.1081 - } 1.1082 - 1.1083 - private void matchClassTypeAnnotations(ClassFile classfile, 1.1084 - ExpectedTypeAnnotation[] expected) 1.1085 - throws ConstantPoolException { 1.1086 - for(ExpectedTypeAnnotation one : expected) { 1.1087 - matchClassTypeAnnotation(classfile, one); 1.1088 - } 1.1089 - } 1.1090 - 1.1091 - private void matchMethodTypeAnnotations(ClassFile classfile, 1.1092 - ExpectedMethodTypeAnnotation[] expected) 1.1093 - throws ConstantPoolException { 1.1094 - for(ExpectedMethodTypeAnnotation one : expected) { 1.1095 - matchMethodTypeAnnotation(classfile, one); 1.1096 - } 1.1097 - } 1.1098 - 1.1099 - private void matchFieldTypeAnnotations(ClassFile classfile, 1.1100 - ExpectedFieldTypeAnnotation[] expected) 1.1101 - throws ConstantPoolException { 1.1102 - for(ExpectedFieldTypeAnnotation one : expected) { 1.1103 - matchFieldTypeAnnotation(classfile, one); 1.1104 - } 1.1105 - } 1.1106 - 1.1107 - /** 1.1108 - * Run a template on a single {@code ClassFile}. 1.1109 - * 1.1110 - * @param classfile The {@code ClassFile} on which to run tests. 1.1111 - * @param expected The expected annotation template. 1.1112 - */ 1.1113 - public void run(ClassFile classfile, 1.1114 - Expected... expected) 1.1115 - throws ConstantPoolException { 1.1116 - run(new ClassFile[] { classfile }, expected); 1.1117 - } 1.1118 - 1.1119 - /** 1.1120 - * Run a template on multiple {@code ClassFile}s. 1.1121 - * 1.1122 - * @param classfile The {@code ClassFile}s on which to run tests. 1.1123 - * @param expected The expected annotation template. 1.1124 - */ 1.1125 - public void run(ClassFile[] classfiles, 1.1126 - Expected... expected) 1.1127 - throws ConstantPoolException { 1.1128 - for(ClassFile classfile : classfiles) { 1.1129 - for(Expected one : expected) { 1.1130 - if (one.matchClassName(classfile.getName())) { 1.1131 - if (one.classAnnos != null) 1.1132 - matchClassAnnotations(classfile, one.classAnnos); 1.1133 - if (one.methodAnnos != null) 1.1134 - matchMethodAnnotations(classfile, one.methodAnnos); 1.1135 - if (one.methodParamAnnos != null) 1.1136 - matchParameterAnnotations(classfile, one.methodParamAnnos); 1.1137 - if (one.fieldAnnos != null) 1.1138 - matchFieldAnnotations(classfile, one.fieldAnnos); 1.1139 - if (one.classTypeAnnos != null) 1.1140 - matchClassTypeAnnotations(classfile, one.classTypeAnnos); 1.1141 - if (one.methodTypeAnnos != null) 1.1142 - matchMethodTypeAnnotations(classfile, one.methodTypeAnnos); 1.1143 - if (one.fieldTypeAnnos != null) 1.1144 - matchFieldTypeAnnotations(classfile, one.fieldTypeAnnos); 1.1145 - } 1.1146 - } 1.1147 - } 1.1148 - int count = 0; 1.1149 - for (Expected one : expected) { 1.1150 - count += one.check(); 1.1151 - } 1.1152 - 1.1153 - if (count != 0) { 1.1154 - throw new RuntimeException(count + " errors occurred in test"); 1.1155 - } 1.1156 - } 1.1157 - 1.1158 - /** 1.1159 - * Get a {@code ClassFile} from its file name. 1.1160 - * 1.1161 - * @param name The class' file name. 1.1162 - * @param host A class in the same package. 1.1163 - * @return The {@code ClassFile} 1.1164 - */ 1.1165 - public static ClassFile getClassFile(String name, 1.1166 - Class<?> host) 1.1167 - throws IOException, ConstantPoolException { 1.1168 - final URL url = host.getResource(name); 1.1169 - final InputStream in = url.openStream(); 1.1170 - try { 1.1171 - return ClassFile.read(in); 1.1172 - } finally { 1.1173 - in.close(); 1.1174 - } 1.1175 - } 1.1176 - 1.1177 - private static final Attribute.Visitor<Void, ExpectedTypeAnnotation> typeAnnoMatcher = 1.1178 - new Attribute.Visitor<Void, ExpectedTypeAnnotation>() { 1.1179 - 1.1180 - @Override 1.1181 - public Void visitBootstrapMethods(BootstrapMethods_attribute attr, 1.1182 - ExpectedTypeAnnotation expected) { 1.1183 - return null; 1.1184 - } 1.1185 - 1.1186 - @Override 1.1187 - public Void visitDefault(DefaultAttribute attr, 1.1188 - ExpectedTypeAnnotation expected) { 1.1189 - return null; 1.1190 - } 1.1191 - 1.1192 - @Override 1.1193 - public Void visitAnnotationDefault(AnnotationDefault_attribute attr, 1.1194 - ExpectedTypeAnnotation expected) { 1.1195 - return null; 1.1196 - } 1.1197 - 1.1198 - @Override 1.1199 - public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, 1.1200 - ExpectedTypeAnnotation expected) { 1.1201 - return null; 1.1202 - } 1.1203 - 1.1204 - @Override 1.1205 - public Void visitCode(Code_attribute attr, 1.1206 - ExpectedTypeAnnotation expected) { 1.1207 - return null; 1.1208 - } 1.1209 - 1.1210 - @Override 1.1211 - public Void visitCompilationID(CompilationID_attribute attr, 1.1212 - ExpectedTypeAnnotation expected) { 1.1213 - return null; 1.1214 - } 1.1215 - 1.1216 - @Override 1.1217 - public Void visitConstantValue(ConstantValue_attribute attr, 1.1218 - ExpectedTypeAnnotation expected) { 1.1219 - return null; 1.1220 - } 1.1221 - 1.1222 - @Override 1.1223 - public Void visitDeprecated(Deprecated_attribute attr, 1.1224 - ExpectedTypeAnnotation expected) { 1.1225 - return null; 1.1226 - } 1.1227 - 1.1228 - @Override 1.1229 - public Void visitEnclosingMethod(EnclosingMethod_attribute attr, 1.1230 - ExpectedTypeAnnotation expected) { 1.1231 - return null; 1.1232 - } 1.1233 - 1.1234 - @Override 1.1235 - public Void visitExceptions(Exceptions_attribute attr, 1.1236 - ExpectedTypeAnnotation expected) { 1.1237 - return null; 1.1238 - } 1.1239 - 1.1240 - @Override 1.1241 - public Void visitInnerClasses(InnerClasses_attribute attr, 1.1242 - ExpectedTypeAnnotation expected) { 1.1243 - return null; 1.1244 - } 1.1245 - 1.1246 - @Override 1.1247 - public Void visitLineNumberTable(LineNumberTable_attribute attr, 1.1248 - ExpectedTypeAnnotation expected) { 1.1249 - return null; 1.1250 - } 1.1251 - 1.1252 - @Override 1.1253 - public Void visitLocalVariableTable(LocalVariableTable_attribute attr, 1.1254 - ExpectedTypeAnnotation expected) { 1.1255 - return null; 1.1256 - } 1.1257 - 1.1258 - @Override 1.1259 - public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, 1.1260 - ExpectedTypeAnnotation expected) { 1.1261 - return null; 1.1262 - } 1.1263 - 1.1264 - @Override 1.1265 - public Void visitMethodParameters(MethodParameters_attribute attr, 1.1266 - ExpectedTypeAnnotation expected) { 1.1267 - return null; 1.1268 - } 1.1269 - 1.1270 - @Override 1.1271 - public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, 1.1272 - ExpectedTypeAnnotation expected) { 1.1273 - return null; 1.1274 - } 1.1275 - 1.1276 - @Override 1.1277 - public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, 1.1278 - ExpectedTypeAnnotation expected) { 1.1279 - return null; 1.1280 - } 1.1281 - 1.1282 - @Override 1.1283 - public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, 1.1284 - ExpectedTypeAnnotation expected) { 1.1285 - return null; 1.1286 - } 1.1287 - 1.1288 - @Override 1.1289 - public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, 1.1290 - ExpectedTypeAnnotation expected) { 1.1291 - return null; 1.1292 - } 1.1293 - 1.1294 - @Override 1.1295 - public Void visitSignature(Signature_attribute attr, 1.1296 - ExpectedTypeAnnotation expected) { 1.1297 - return null; 1.1298 - } 1.1299 - 1.1300 - @Override 1.1301 - public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, 1.1302 - ExpectedTypeAnnotation expected) { 1.1303 - return null; 1.1304 - } 1.1305 - 1.1306 - @Override 1.1307 - public Void visitSourceFile(SourceFile_attribute attr, 1.1308 - ExpectedTypeAnnotation expected) { 1.1309 - return null; 1.1310 - } 1.1311 - 1.1312 - @Override 1.1313 - public Void visitSourceID(SourceID_attribute attr, 1.1314 - ExpectedTypeAnnotation expected) { 1.1315 - return null; 1.1316 - } 1.1317 - 1.1318 - @Override 1.1319 - public Void visitStackMap(StackMap_attribute attr, 1.1320 - ExpectedTypeAnnotation expected) { 1.1321 - return null; 1.1322 - } 1.1323 - 1.1324 - @Override 1.1325 - public Void visitStackMapTable(StackMapTable_attribute attr, 1.1326 - ExpectedTypeAnnotation expected) { 1.1327 - return null; 1.1328 - } 1.1329 - 1.1330 - @Override 1.1331 - public Void visitSynthetic(Synthetic_attribute attr, 1.1332 - ExpectedTypeAnnotation expected) { 1.1333 - return null; 1.1334 - } 1.1335 - 1.1336 - @Override 1.1337 - public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, 1.1338 - ExpectedTypeAnnotation expected) { 1.1339 - if (expected.matchVisibility(true)) { 1.1340 - for(TypeAnnotation anno : attr.annotations) { 1.1341 - expected.matchAnnotation(anno); 1.1342 - } 1.1343 - } 1.1344 - 1.1345 - return null; 1.1346 - } 1.1347 - 1.1348 - @Override 1.1349 - public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, 1.1350 - ExpectedTypeAnnotation expected) { 1.1351 - if (expected.matchVisibility(false)) { 1.1352 - for(TypeAnnotation anno : attr.annotations) { 1.1353 - expected.matchAnnotation(anno); 1.1354 - } 1.1355 - } 1.1356 - 1.1357 - return null; 1.1358 - } 1.1359 - }; 1.1360 - 1.1361 - private static Attribute.Visitor<Void, ExpectedAnnotation> annoMatcher(ConstantPool cpool) { 1.1362 - return new Attribute.Visitor<Void, ExpectedAnnotation>() { 1.1363 - 1.1364 - @Override 1.1365 - public Void visitBootstrapMethods(BootstrapMethods_attribute attr, 1.1366 - ExpectedAnnotation expected) { 1.1367 - return null; 1.1368 - } 1.1369 - 1.1370 - @Override 1.1371 - public Void visitDefault(DefaultAttribute attr, 1.1372 - ExpectedAnnotation expected) { 1.1373 - return null; 1.1374 - } 1.1375 - 1.1376 - @Override 1.1377 - public Void visitAnnotationDefault(AnnotationDefault_attribute attr, 1.1378 - ExpectedAnnotation expected) { 1.1379 - return null; 1.1380 - } 1.1381 - 1.1382 - @Override 1.1383 - public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, 1.1384 - ExpectedAnnotation expected) { 1.1385 - return null; 1.1386 - } 1.1387 - 1.1388 - @Override 1.1389 - public Void visitCode(Code_attribute attr, 1.1390 - ExpectedAnnotation expected) { 1.1391 - return null; 1.1392 - } 1.1393 - 1.1394 - @Override 1.1395 - public Void visitCompilationID(CompilationID_attribute attr, 1.1396 - ExpectedAnnotation expected) { 1.1397 - return null; 1.1398 - } 1.1399 - 1.1400 - @Override 1.1401 - public Void visitConstantValue(ConstantValue_attribute attr, 1.1402 - ExpectedAnnotation expected) { 1.1403 - return null; 1.1404 - } 1.1405 - 1.1406 - @Override 1.1407 - public Void visitDeprecated(Deprecated_attribute attr, 1.1408 - ExpectedAnnotation expected) { 1.1409 - return null; 1.1410 - } 1.1411 - 1.1412 - @Override 1.1413 - public Void visitEnclosingMethod(EnclosingMethod_attribute attr, 1.1414 - ExpectedAnnotation expected) { 1.1415 - return null; 1.1416 - } 1.1417 - 1.1418 - @Override 1.1419 - public Void visitExceptions(Exceptions_attribute attr, 1.1420 - ExpectedAnnotation expected) { 1.1421 - return null; 1.1422 - } 1.1423 - 1.1424 - @Override 1.1425 - public Void visitInnerClasses(InnerClasses_attribute attr, 1.1426 - ExpectedAnnotation expected) { 1.1427 - return null; 1.1428 - } 1.1429 - 1.1430 - @Override 1.1431 - public Void visitLineNumberTable(LineNumberTable_attribute attr, 1.1432 - ExpectedAnnotation expected) { 1.1433 - return null; 1.1434 - } 1.1435 - 1.1436 - @Override 1.1437 - public Void visitLocalVariableTable(LocalVariableTable_attribute attr, 1.1438 - ExpectedAnnotation expected) { 1.1439 - return null; 1.1440 - } 1.1441 - 1.1442 - @Override 1.1443 - public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, 1.1444 - ExpectedAnnotation expected) { 1.1445 - return null; 1.1446 - } 1.1447 - 1.1448 - @Override 1.1449 - public Void visitMethodParameters(MethodParameters_attribute attr, 1.1450 - ExpectedAnnotation expected) { 1.1451 - return null; 1.1452 - } 1.1453 - 1.1454 - @Override 1.1455 - public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, 1.1456 - ExpectedAnnotation expected) { 1.1457 - return null; 1.1458 - } 1.1459 - 1.1460 - @Override 1.1461 - public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, 1.1462 - ExpectedAnnotation expected) { 1.1463 - return null; 1.1464 - } 1.1465 - 1.1466 - @Override 1.1467 - public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, 1.1468 - ExpectedAnnotation expected) { 1.1469 - return null; 1.1470 - } 1.1471 - 1.1472 - @Override 1.1473 - public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, 1.1474 - ExpectedAnnotation expected) { 1.1475 - return null; 1.1476 - } 1.1477 - 1.1478 - @Override 1.1479 - public Void visitSignature(Signature_attribute attr, 1.1480 - ExpectedAnnotation expected) { 1.1481 - return null; 1.1482 - } 1.1483 - 1.1484 - @Override 1.1485 - public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, 1.1486 - ExpectedAnnotation expected) { 1.1487 - return null; 1.1488 - } 1.1489 - 1.1490 - @Override 1.1491 - public Void visitSourceFile(SourceFile_attribute attr, 1.1492 - ExpectedAnnotation expected) { 1.1493 - return null; 1.1494 - } 1.1495 - 1.1496 - @Override 1.1497 - public Void visitSourceID(SourceID_attribute attr, 1.1498 - ExpectedAnnotation expected) { 1.1499 - return null; 1.1500 - } 1.1501 - 1.1502 - @Override 1.1503 - public Void visitStackMap(StackMap_attribute attr, 1.1504 - ExpectedAnnotation expected) { 1.1505 - return null; 1.1506 - } 1.1507 - 1.1508 - @Override 1.1509 - public Void visitStackMapTable(StackMapTable_attribute attr, 1.1510 - ExpectedAnnotation expected) { 1.1511 - return null; 1.1512 - } 1.1513 - 1.1514 - @Override 1.1515 - public Void visitSynthetic(Synthetic_attribute attr, 1.1516 - ExpectedAnnotation expected) { 1.1517 - return null; 1.1518 - } 1.1519 - 1.1520 - @Override 1.1521 - public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, 1.1522 - ExpectedAnnotation expected) { 1.1523 - if (expected.matchVisibility(true)) { 1.1524 - for(Annotation anno : attr.annotations) { 1.1525 - expected.matchAnnotation(cpool, anno); 1.1526 - } 1.1527 - } 1.1528 - 1.1529 - return null; 1.1530 - } 1.1531 - 1.1532 - @Override 1.1533 - public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, 1.1534 - ExpectedAnnotation expected) { 1.1535 - if (expected.matchVisibility(false)) { 1.1536 - for(Annotation anno : attr.annotations) { 1.1537 - expected.matchAnnotation(cpool, anno); 1.1538 - } 1.1539 - } 1.1540 - 1.1541 - return null; 1.1542 - } 1.1543 - }; 1.1544 - } 1.1545 - 1.1546 - private static Attribute.Visitor<Void, ExpectedParameterAnnotation> paramMatcher(ConstantPool cpool) { 1.1547 - return new Attribute.Visitor<Void, ExpectedParameterAnnotation>() { 1.1548 - 1.1549 - @Override 1.1550 - public Void visitBootstrapMethods(BootstrapMethods_attribute attr, 1.1551 - ExpectedParameterAnnotation expected) { 1.1552 - return null; 1.1553 - } 1.1554 - 1.1555 - @Override 1.1556 - public Void visitDefault(DefaultAttribute attr, 1.1557 - ExpectedParameterAnnotation expected) { 1.1558 - return null; 1.1559 - } 1.1560 - 1.1561 - @Override 1.1562 - public Void visitAnnotationDefault(AnnotationDefault_attribute attr, 1.1563 - ExpectedParameterAnnotation expected) { 1.1564 - return null; 1.1565 - } 1.1566 - 1.1567 - @Override 1.1568 - public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, 1.1569 - ExpectedParameterAnnotation expected) { 1.1570 - return null; 1.1571 - } 1.1572 - 1.1573 - @Override 1.1574 - public Void visitCode(Code_attribute attr, 1.1575 - ExpectedParameterAnnotation expected) { 1.1576 - return null; 1.1577 - } 1.1578 - 1.1579 - @Override 1.1580 - public Void visitCompilationID(CompilationID_attribute attr, 1.1581 - ExpectedParameterAnnotation expected) { 1.1582 - return null; 1.1583 - } 1.1584 - 1.1585 - @Override 1.1586 - public Void visitConstantValue(ConstantValue_attribute attr, 1.1587 - ExpectedParameterAnnotation expected) { 1.1588 - return null; 1.1589 - } 1.1590 - 1.1591 - @Override 1.1592 - public Void visitDeprecated(Deprecated_attribute attr, 1.1593 - ExpectedParameterAnnotation expected) { 1.1594 - return null; 1.1595 - } 1.1596 - 1.1597 - @Override 1.1598 - public Void visitEnclosingMethod(EnclosingMethod_attribute attr, 1.1599 - ExpectedParameterAnnotation expected) { 1.1600 - return null; 1.1601 - } 1.1602 - 1.1603 - @Override 1.1604 - public Void visitExceptions(Exceptions_attribute attr, 1.1605 - ExpectedParameterAnnotation expected) { 1.1606 - return null; 1.1607 - } 1.1608 - 1.1609 - @Override 1.1610 - public Void visitInnerClasses(InnerClasses_attribute attr, 1.1611 - ExpectedParameterAnnotation expected) { 1.1612 - return null; 1.1613 - } 1.1614 - 1.1615 - @Override 1.1616 - public Void visitLineNumberTable(LineNumberTable_attribute attr, 1.1617 - ExpectedParameterAnnotation expected) { 1.1618 - return null; 1.1619 - } 1.1620 - 1.1621 - @Override 1.1622 - public Void visitLocalVariableTable(LocalVariableTable_attribute attr, 1.1623 - ExpectedParameterAnnotation expected) { 1.1624 - return null; 1.1625 - } 1.1626 - 1.1627 - @Override 1.1628 - public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, 1.1629 - ExpectedParameterAnnotation expected) { 1.1630 - return null; 1.1631 - } 1.1632 - 1.1633 - @Override 1.1634 - public Void visitMethodParameters(MethodParameters_attribute attr, 1.1635 - ExpectedParameterAnnotation expected) { 1.1636 - return null; 1.1637 - } 1.1638 - 1.1639 - @Override 1.1640 - public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, 1.1641 - ExpectedParameterAnnotation expected) { 1.1642 - return null; 1.1643 - } 1.1644 - 1.1645 - @Override 1.1646 - public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, 1.1647 - ExpectedParameterAnnotation expected) { 1.1648 - return null; 1.1649 - } 1.1650 - 1.1651 - @Override 1.1652 - public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, 1.1653 - ExpectedParameterAnnotation expected) { 1.1654 - return null; 1.1655 - } 1.1656 - 1.1657 - @Override 1.1658 - public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, 1.1659 - ExpectedParameterAnnotation expected) { 1.1660 - return null; 1.1661 - } 1.1662 - 1.1663 - @Override 1.1664 - public Void visitSignature(Signature_attribute attr, 1.1665 - ExpectedParameterAnnotation expected) { 1.1666 - return null; 1.1667 - } 1.1668 - 1.1669 - @Override 1.1670 - public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, 1.1671 - ExpectedParameterAnnotation expected) { 1.1672 - return null; 1.1673 - } 1.1674 - 1.1675 - @Override 1.1676 - public Void visitSourceFile(SourceFile_attribute attr, 1.1677 - ExpectedParameterAnnotation expected) { 1.1678 - return null; 1.1679 - } 1.1680 - 1.1681 - @Override 1.1682 - public Void visitSourceID(SourceID_attribute attr, 1.1683 - ExpectedParameterAnnotation expected) { 1.1684 - return null; 1.1685 - } 1.1686 - 1.1687 - @Override 1.1688 - public Void visitStackMap(StackMap_attribute attr, 1.1689 - ExpectedParameterAnnotation expected) { 1.1690 - return null; 1.1691 - } 1.1692 - 1.1693 - @Override 1.1694 - public Void visitStackMapTable(StackMapTable_attribute attr, 1.1695 - ExpectedParameterAnnotation expected) { 1.1696 - return null; 1.1697 - } 1.1698 - 1.1699 - @Override 1.1700 - public Void visitSynthetic(Synthetic_attribute attr, 1.1701 - ExpectedParameterAnnotation expected) { 1.1702 - return null; 1.1703 - } 1.1704 - 1.1705 - @Override 1.1706 - public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, 1.1707 - ExpectedParameterAnnotation expected) { 1.1708 - if (expected.matchVisibility(true)) { 1.1709 - if (expected.index < attr.parameter_annotations.length) { 1.1710 - for(Annotation anno : 1.1711 - attr.parameter_annotations[expected.index]) { 1.1712 - expected.matchAnnotation(cpool, anno); 1.1713 - } 1.1714 - } 1.1715 - } 1.1716 - 1.1717 - return null; 1.1718 - } 1.1719 - 1.1720 - @Override 1.1721 - public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, 1.1722 - ExpectedParameterAnnotation expected) { 1.1723 - if (expected.matchVisibility(false)) { 1.1724 - if (expected.index < attr.parameter_annotations.length) { 1.1725 - for(Annotation anno : 1.1726 - attr.parameter_annotations[expected.index]) { 1.1727 - expected.matchAnnotation(cpool, anno); 1.1728 - } 1.1729 - } 1.1730 - } 1.1731 - 1.1732 - return null; 1.1733 - } 1.1734 - }; 1.1735 - } 1.1736 -}