Thu, 11 Dec 2014 13:38:51 -0800
Merge
test/lib/annotations/annotations/classfile/ClassfileInspector.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/annotations/SyntheticParameters.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/annotations/typeAnnotations/classfile/SyntheticParameters.java | file | annotate | diff | comparison | revisions |
1.1 --- a/THIRD_PARTY_README Wed Dec 10 14:35:58 2014 -0800 1.2 +++ b/THIRD_PARTY_README Thu Dec 11 13:38:51 2014 -0800 1.3 @@ -3385,7 +3385,7 @@ 1.4 included with JRE 8, JDK 8, and OpenJDK 8. 1.5 1.6 Apache Commons Math 3.2 1.7 - Apache Derby 10.10.1.3 1.8 + Apache Derby 10.11.1.2 1.9 Apache Jakarta BCEL 5.1 1.10 Apache Jakarta Regexp 1.4 1.11 Apache Santuario XML Security for Java 1.5.4
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Dec 10 14:35:58 2014 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Dec 11 13:38:51 2014 -0800 2.3 @@ -2716,10 +2716,9 @@ 2.4 syms.intType, tree.sym); 2.5 ordParam.mods.flags |= SYNTHETIC; ordParam.sym.flags_field |= SYNTHETIC; 2.6 2.7 + tree.params = tree.params.prepend(ordParam).prepend(nameParam); 2.8 + 2.9 MethodSymbol m = tree.sym; 2.10 - tree.params = tree.params.prepend(ordParam).prepend(nameParam); 2.11 - incrementParamTypeAnnoIndexes(m, 2); 2.12 - 2.13 m.extraParams = m.extraParams.prepend(ordParam.sym); 2.14 m.extraParams = m.extraParams.prepend(nameParam.sym); 2.15 Type olderasure = m.erasure(types); 2.16 @@ -2742,17 +2741,6 @@ 2.17 } 2.18 } 2.19 //where 2.20 - private void incrementParamTypeAnnoIndexes(MethodSymbol m, 2.21 - int amount) { 2.22 - for (final Attribute.TypeCompound anno : m.getRawTypeAttributes()) { 2.23 - // Increment the parameter_index of any existing formal 2.24 - // parameter annotations. 2.25 - if (anno.position.type == TargetType.METHOD_FORMAL_PARAMETER) { 2.26 - anno.position.parameter_index += amount; 2.27 - } 2.28 - } 2.29 - } 2.30 - 2.31 private void visitMethodDefInternal(JCMethodDecl tree) { 2.32 if (tree.name == names.init && 2.33 (currentClass.isInner() || currentClass.isLocal())) { 2.34 @@ -2783,10 +2771,8 @@ 2.35 // Add this$n (if needed) in front of and free variables behind 2.36 // constructor parameter list. 2.37 tree.params = tree.params.appendList(fvdefs); 2.38 - if (currentClass.hasOuterInstance()) { 2.39 + if (currentClass.hasOuterInstance()) 2.40 tree.params = tree.params.prepend(otdef); 2.41 - incrementParamTypeAnnoIndexes(m, 1); 2.42 - } 2.43 2.44 // If this is an initial constructor, i.e., it does not start with 2.45 // this(...), insert initializers for this$n and proxies
3.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Wed Dec 10 14:35:58 2014 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Thu Dec 11 13:38:51 2014 -0800 3.3 @@ -670,27 +670,6 @@ 3.4 } 3.5 3.6 3.7 - private void writeParamAnnotations(List<VarSymbol> params, 3.8 - RetentionPolicy retention) { 3.9 - for (VarSymbol s : params) { 3.10 - ListBuffer<Attribute.Compound> buf = new ListBuffer<>(); 3.11 - for (Attribute.Compound a : s.getRawAttributes()) 3.12 - if (types.getRetention(a) == retention) 3.13 - buf.append(a); 3.14 - databuf.appendChar(buf.length()); 3.15 - for (Attribute.Compound a : buf) 3.16 - writeCompoundAttribute(a); 3.17 - } 3.18 - 3.19 - } 3.20 - 3.21 - private void writeParamAnnotations(MethodSymbol m, 3.22 - RetentionPolicy retention) { 3.23 - databuf.appendByte(m.params.length() + m.extraParams.length()); 3.24 - writeParamAnnotations(m.extraParams, retention); 3.25 - writeParamAnnotations(m.params, retention); 3.26 - } 3.27 - 3.28 /** Write method parameter annotations; 3.29 * return number of attributes written. 3.30 */ 3.31 @@ -713,13 +692,31 @@ 3.32 int attrCount = 0; 3.33 if (hasVisible) { 3.34 int attrIndex = writeAttr(names.RuntimeVisibleParameterAnnotations); 3.35 - writeParamAnnotations(m, RetentionPolicy.RUNTIME); 3.36 + databuf.appendByte(m.params.length()); 3.37 + for (VarSymbol s : m.params) { 3.38 + ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>(); 3.39 + for (Attribute.Compound a : s.getRawAttributes()) 3.40 + if (types.getRetention(a) == RetentionPolicy.RUNTIME) 3.41 + buf.append(a); 3.42 + databuf.appendChar(buf.length()); 3.43 + for (Attribute.Compound a : buf) 3.44 + writeCompoundAttribute(a); 3.45 + } 3.46 endAttr(attrIndex); 3.47 attrCount++; 3.48 } 3.49 if (hasInvisible) { 3.50 int attrIndex = writeAttr(names.RuntimeInvisibleParameterAnnotations); 3.51 - writeParamAnnotations(m, RetentionPolicy.CLASS); 3.52 + databuf.appendByte(m.params.length()); 3.53 + for (VarSymbol s : m.params) { 3.54 + ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>(); 3.55 + for (Attribute.Compound a : s.getRawAttributes()) 3.56 + if (types.getRetention(a) == RetentionPolicy.CLASS) 3.57 + buf.append(a); 3.58 + databuf.appendChar(buf.length()); 3.59 + for (Attribute.Compound a : buf) 3.60 + writeCompoundAttribute(a); 3.61 + } 3.62 endAttr(attrIndex); 3.63 attrCount++; 3.64 }
4.1 --- a/test/lib/annotations/annotations/classfile/ClassfileInspector.java Wed Dec 10 14:35:58 2014 -0800 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,1733 +0,0 @@ 4.4 -/* 4.5 - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 4.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 - * 4.8 - * This code is free software; you can redistribute it and/or modify it 4.9 - * under the terms of the GNU General Public License version 2 only, as 4.10 - * published by the Free Software Foundation. 4.11 - * 4.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 - * version 2 for more details (a copy is included in the LICENSE file that 4.16 - * accompanied this code). 4.17 - * 4.18 - * You should have received a copy of the GNU General Public License version 4.19 - * 2 along with this work; if not, write to the Free Software Foundation, 4.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 - * 4.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 - * or visit www.oracle.com if you need additional information or have any 4.24 - * questions. 4.25 - */ 4.26 - 4.27 -package annotations.classfile; 4.28 - 4.29 -import java.io.*; 4.30 -import java.net.URL; 4.31 -import java.util.List; 4.32 - 4.33 -import com.sun.tools.classfile.*; 4.34 - 4.35 -/** 4.36 - * A class providing utilities for writing tests that inspect class 4.37 - * files directly, looking for specific type annotations. 4.38 - * 4.39 - * Note: this framework does not currently handle repeating 4.40 - * annotations. 4.41 - */ 4.42 -public class ClassfileInspector { 4.43 - 4.44 - /** 4.45 - * A group of expected annotations to be found in a given class. 4.46 - * If the class name is null, then the template will be applied to 4.47 - * every class. 4.48 - */ 4.49 - public static class Expected { 4.50 - /** 4.51 - * The name of the class. If {@code null} this template will 4.52 - * apply to every class; otherwise, it will only be applied to 4.53 - * the named class. 4.54 - */ 4.55 - public final String classname; 4.56 - 4.57 - /** 4.58 - * The expected class annotations. These will be checked 4.59 - * against the class' attributes. 4.60 - */ 4.61 - public final ExpectedAnnotation[] classAnnos; 4.62 - 4.63 - /** 4.64 - * The expected method annotations. These will be checked 4.65 - * against all methods in the class. 4.66 - */ 4.67 - public final ExpectedMethodAnnotation[] methodAnnos; 4.68 - 4.69 - /** 4.70 - * The expected method parameter annotations. These will be checked 4.71 - * against all methods in the class. 4.72 - */ 4.73 - public final ExpectedParameterAnnotation[] methodParamAnnos; 4.74 - 4.75 - /** 4.76 - * The expected field type annotations. These will be checked 4.77 - * against all fields in the class. 4.78 - */ 4.79 - public final ExpectedFieldAnnotation[] fieldAnnos; 4.80 - 4.81 - /** 4.82 - * The expected class type annotations. These will be checked 4.83 - * against the class' attributes. 4.84 - */ 4.85 - public final ExpectedTypeAnnotation[] classTypeAnnos; 4.86 - 4.87 - /** 4.88 - * The expected method type annotations. These will be checked 4.89 - * against all methods in the class. 4.90 - */ 4.91 - public final ExpectedMethodTypeAnnotation[] methodTypeAnnos; 4.92 - 4.93 - /** 4.94 - * The expected field type annotations. These will be checked 4.95 - * against all fields in the class. 4.96 - */ 4.97 - public final ExpectedFieldTypeAnnotation[] fieldTypeAnnos; 4.98 - 4.99 - /** 4.100 - * Create an {@code Expected} from all components. 4.101 - * 4.102 - * @param classname The name of the class to match, or {@code 4.103 - * null} for all classes. 4.104 - * @param classAnnos The expected class annotations. 4.105 - * @param methodAnnos The expected method annotations. 4.106 - * @param methodParamAnnos The expected method parameter annotations. 4.107 - * @param fieldAnnos The expected field annotations. 4.108 - * @param classTypeAnnos The expected class type annotations. 4.109 - * @param methodTypeAnnos The expected method type annotations. 4.110 - * @param fieldTypeAnnos The expected field type annotations. 4.111 - */ 4.112 - public Expected(String classname, 4.113 - ExpectedAnnotation[] classAnnos, 4.114 - ExpectedMethodAnnotation[] methodAnnos, 4.115 - ExpectedParameterAnnotation[] methodParamAnnos, 4.116 - ExpectedFieldAnnotation[] fieldAnnos, 4.117 - ExpectedTypeAnnotation[] classTypeAnnos, 4.118 - ExpectedMethodTypeAnnotation[] methodTypeAnnos, 4.119 - ExpectedFieldTypeAnnotation[] fieldTypeAnnos) { 4.120 - this.classname = classname; 4.121 - this.classAnnos = classAnnos; 4.122 - this.methodAnnos = methodAnnos; 4.123 - this.methodParamAnnos = methodParamAnnos; 4.124 - this.fieldAnnos = fieldAnnos; 4.125 - this.classTypeAnnos = classTypeAnnos; 4.126 - this.methodTypeAnnos = methodTypeAnnos; 4.127 - this.fieldTypeAnnos = fieldTypeAnnos; 4.128 - } 4.129 - 4.130 - /** 4.131 - * Create an {@code Expected} from regular annotation components. 4.132 - * 4.133 - * @param classname The name of the class to match, or {@code 4.134 - * null} for all classes. 4.135 - * @param classAnnos The expected class annotations. 4.136 - * @param methodAnnos The expected method annotations. 4.137 - * @param methodParamAnnos The expected method parameter annotations. 4.138 - * @param fieldAnnos The expected field annotations. 4.139 - */ 4.140 - public Expected(String classname, 4.141 - ExpectedAnnotation[] classAnnos, 4.142 - ExpectedMethodAnnotation[] methodAnnos, 4.143 - ExpectedParameterAnnotation[] methodParamAnnos, 4.144 - ExpectedFieldAnnotation[] fieldAnnos) { 4.145 - this(classname, classAnnos, methodAnnos, methodParamAnnos, 4.146 - fieldAnnos, null, null, null); 4.147 - } 4.148 - 4.149 - /** 4.150 - * Create an {@code Expected} from type annotation components. 4.151 - * 4.152 - * @param classname The name of the class to match, or {@code 4.153 - * null} for all classes. 4.154 - * @param classTypeAnnos The expected class type annotations. 4.155 - * @param methodTypeAnnos The expected method type annotations. 4.156 - * @param fieldTypeAnnos The expected field type annotations. 4.157 - */ 4.158 - public Expected(String classname, 4.159 - ExpectedTypeAnnotation[] classTypeAnnos, 4.160 - ExpectedMethodTypeAnnotation[] methodTypeAnnos, 4.161 - ExpectedFieldTypeAnnotation[] fieldTypeAnnos) { 4.162 - this(classname, null, null, null, null, 4.163 - classTypeAnnos, methodTypeAnnos, fieldTypeAnnos); 4.164 - } 4.165 - 4.166 - public String toString() { 4.167 - final StringBuilder sb = new StringBuilder(); 4.168 - final String newline = System.lineSeparator(); 4.169 - sb.append("Expected on class ").append(classname); 4.170 - if (null != classAnnos) { 4.171 - sb.append(newline).append("Class annotations:").append(newline); 4.172 - for(ExpectedAnnotation anno : classAnnos) { 4.173 - sb.append(anno).append(newline); 4.174 - } 4.175 - } 4.176 - if (null != methodAnnos) { 4.177 - sb.append(newline).append("Method annotations:").append(newline); 4.178 - for(ExpectedAnnotation anno : methodAnnos) { 4.179 - sb.append(anno).append(newline); 4.180 - } 4.181 - } 4.182 - if (null != methodParamAnnos) { 4.183 - sb.append(newline).append("Method param annotations:").append(newline); 4.184 - for(ExpectedAnnotation anno : methodParamAnnos) { 4.185 - sb.append(anno).append(newline); 4.186 - } 4.187 - } 4.188 - if (null != fieldAnnos) { 4.189 - sb.append(newline).append("Field annotations:").append(newline); 4.190 - for(ExpectedAnnotation anno : fieldAnnos) { 4.191 - sb.append(anno).append(newline); 4.192 - } 4.193 - } 4.194 - if (null != classTypeAnnos) { 4.195 - sb.append(newline).append("Class type annotations:").append(newline); 4.196 - for(ExpectedAnnotation anno : classTypeAnnos) { 4.197 - sb.append(anno).append(newline); 4.198 - } 4.199 - } 4.200 - if (null != methodTypeAnnos) { 4.201 - sb.append(newline).append("Method type annotations:").append(newline); 4.202 - for(ExpectedAnnotation anno : methodTypeAnnos) { 4.203 - sb.append(anno).append(newline); 4.204 - } 4.205 - } 4.206 - if (null != fieldTypeAnnos) { 4.207 - sb.append(newline).append("Field type annotations:").append(newline); 4.208 - for(ExpectedAnnotation anno : fieldTypeAnnos) { 4.209 - sb.append(anno).append(newline); 4.210 - } 4.211 - } 4.212 - return sb.toString(); 4.213 - } 4.214 - 4.215 - /** 4.216 - * See if this template applies to a class. 4.217 - * 4.218 - * @param classname The classname to check. 4.219 - * @return Whether or not this template should apply. 4.220 - */ 4.221 - public boolean matchClassName(String classname) { 4.222 - return this.classname == null || this.classname.equals(classname); 4.223 - } 4.224 - 4.225 - /** 4.226 - * After applying the template to all classes, check to see if 4.227 - * any of the expected annotations weren't matched. 4.228 - * 4.229 - * @return The number of missed matches. 4.230 - */ 4.231 - public int check() { 4.232 - int count = 0; 4.233 - if (classAnnos != null) { 4.234 - for(ExpectedAnnotation expected : classAnnos) { 4.235 - if (!expected.check()) { 4.236 - count++; 4.237 - } 4.238 - } 4.239 - } 4.240 - if (methodAnnos != null) { 4.241 - for(ExpectedAnnotation expected : methodAnnos) { 4.242 - if (!expected.check()) { 4.243 - count++; 4.244 - } 4.245 - } 4.246 - } 4.247 - if (methodParamAnnos != null) { 4.248 - for(ExpectedAnnotation expected : methodParamAnnos) { 4.249 - if (!expected.check()) { 4.250 - count++; 4.251 - } 4.252 - } 4.253 - } 4.254 - if (fieldAnnos != null) { 4.255 - for(ExpectedAnnotation expected : fieldAnnos) { 4.256 - if (!expected.check()) { 4.257 - count++; 4.258 - } 4.259 - } 4.260 - } 4.261 - if (classTypeAnnos != null) { 4.262 - for(ExpectedAnnotation expected : classTypeAnnos) { 4.263 - if (!expected.check()) { 4.264 - count++; 4.265 - } 4.266 - } 4.267 - } 4.268 - if (methodTypeAnnos != null) { 4.269 - for(ExpectedAnnotation expected : methodTypeAnnos) { 4.270 - if (!expected.check()) { 4.271 - count++; 4.272 - } 4.273 - } 4.274 - } 4.275 - if (fieldTypeAnnos != null) { 4.276 - for(ExpectedAnnotation expected : fieldTypeAnnos) { 4.277 - if (!expected.check()) { 4.278 - count++; 4.279 - } 4.280 - } 4.281 - } 4.282 - return count; 4.283 - } 4.284 - } 4.285 - 4.286 - /** 4.287 - * An expected annotation. This is both a superclass for 4.288 - * method, field, and type annotations, as well as a class for 4.289 - * annotations on a class. 4.290 - */ 4.291 - public static class ExpectedAnnotation { 4.292 - protected int count = 0; 4.293 - protected final String expectedName; 4.294 - protected final int expectedCount; 4.295 - protected final boolean visibility; 4.296 - 4.297 - /** 4.298 - * Create an {@code ExpectedAnnotation} from its 4.299 - * components. It is usually a better idea to use a {@code 4.300 - * Builder} to do this. 4.301 - * 4.302 - * @param expectedName The expected annotation name. 4.303 - * @param visibility Whether this annotation should be runtime-visible. 4.304 - * @param expectedCount The number of annotations that should 4.305 - * be seen. If 0, this asserts that the 4.306 - * described annotation is not present. 4.307 - */ 4.308 - public ExpectedAnnotation(String expectedName, 4.309 - boolean visibility, 4.310 - int expectedCount) { 4.311 - this.expectedName = expectedName; 4.312 - this.visibility = visibility; 4.313 - this.expectedCount = expectedCount; 4.314 - } 4.315 - 4.316 - public String toString() { 4.317 - final StringBuilder sb = new StringBuilder(); 4.318 - sb.append("Expected "); 4.319 - sb.append(expectedCount); 4.320 - sb.append(" annotation "); 4.321 - sb.append(expectedName); 4.322 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 4.323 - return sb.toString(); 4.324 - } 4.325 - 4.326 - /** 4.327 - * See if this template matches the given visibility. 4.328 - * 4.329 - * @param Whether or not the annotation is visible at runtime. 4.330 - * @return Whether or not this template matches the visibility. 4.331 - */ 4.332 - public boolean matchVisibility(boolean visibility) { 4.333 - return this.visibility == visibility; 4.334 - } 4.335 - 4.336 - /** 4.337 - * Attempty to match this template against an annotation. If 4.338 - * it does match, then the match count for the template will 4.339 - * be incremented. Otherwise, nothing will be done. 4.340 - * 4.341 - * @param anno The annotation to attempt to match. 4.342 - */ 4.343 - public void matchAnnotation(ConstantPool cpool, 4.344 - Annotation anno) { 4.345 - if (checkMatch(cpool, anno)) { 4.346 - count++; 4.347 - } 4.348 - } 4.349 - 4.350 - /** 4.351 - * Indicate whether an annotation matches this expected 4.352 - * annotation. 4.353 - * 4.354 - * @param ConstantPool The constant pool to use. 4.355 - * @param anno The annotation to check. 4.356 - * @return Whether the annotation matches. 4.357 - */ 4.358 - protected boolean checkMatch(ConstantPool cpool, 4.359 - Annotation anno) { 4.360 - try { 4.361 - return cpool.getUTF8Info(anno.type_index).value.equals("L" + expectedName + ";"); 4.362 - } catch(Exception e) { 4.363 - return false; 4.364 - } 4.365 - } 4.366 - 4.367 - /** 4.368 - * After all matching, check to see if the expected number of 4.369 - * matches equals the actual number. If not, then print a 4.370 - * failure message and return {@code false}. 4.371 - * 4.372 - * @return Whether or not the expected number of matched 4.373 - * equals the actual number. 4.374 - */ 4.375 - public boolean check() { 4.376 - if (count != expectedCount) { 4.377 - System.err.println(this + ", but saw " + count); 4.378 - return false; 4.379 - } else { 4.380 - return true; 4.381 - } 4.382 - } 4.383 - } 4.384 - 4.385 - /** 4.386 - * An annotation found on a method. 4.387 - */ 4.388 - public static class ExpectedMethodAnnotation extends ExpectedAnnotation { 4.389 - protected final String methodname; 4.390 - 4.391 - /** 4.392 - * Create an {@code ExpectedMethodAnnotation} from its 4.393 - * components. It is usually a better idea to use a {@code 4.394 - * Builder} to do this. 4.395 - * 4.396 - * @param methodname The expected method name. 4.397 - * @param expectedName The expected annotation name. 4.398 - * @param visibility Whether this annotation should be runtime-visible. 4.399 - * @param expectedCount The number of annotations that should be seen. 4.400 - */ 4.401 - public ExpectedMethodAnnotation(String methodname, 4.402 - String expectedName, 4.403 - boolean visibility, 4.404 - int expectedCount) { 4.405 - super(expectedName, visibility, expectedCount); 4.406 - this.methodname = methodname; 4.407 - } 4.408 - 4.409 - public String toString() { 4.410 - final StringBuilder sb = new StringBuilder(); 4.411 - sb.append("Expected "); 4.412 - sb.append(expectedCount); 4.413 - sb.append(" annotation "); 4.414 - sb.append(expectedName); 4.415 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 4.416 - sb.append(" on method "); 4.417 - sb.append(methodname); 4.418 - return sb.toString(); 4.419 - } 4.420 - 4.421 - /** 4.422 - * See if this template applies to a method. 4.423 - * 4.424 - * @param methodname The method name to check. 4.425 - * @return Whether or not this template should apply. 4.426 - */ 4.427 - public boolean matchMethodName(String methodname) { 4.428 - return this.methodname.equals(methodname); 4.429 - } 4.430 - 4.431 - } 4.432 - 4.433 - /** 4.434 - * An annotation found on a method parameter. 4.435 - */ 4.436 - public static class ExpectedParameterAnnotation 4.437 - extends ExpectedMethodAnnotation { 4.438 - protected final int index; 4.439 - 4.440 - /** 4.441 - * Create an {@code ExpectedParameterAnnotation} from its 4.442 - * components. It is usually a better idea to use a {@code 4.443 - * Builder} to do this. 4.444 - * 4.445 - * @param methodname The expected method name. 4.446 - * @param index The parameter index. 4.447 - * @param expectedName The expected annotation name. 4.448 - * @param visibility Whether this annotation should be runtime-visible. 4.449 - * @param expectedCount The number of annotations that should be seen. 4.450 - */ 4.451 - public ExpectedParameterAnnotation(String methodname, 4.452 - int index, 4.453 - String expectedName, 4.454 - boolean visibility, 4.455 - int expectedCount) { 4.456 - super(methodname, expectedName, visibility, expectedCount); 4.457 - this.index = index; 4.458 - } 4.459 - 4.460 - public String toString() { 4.461 - final StringBuilder sb = new StringBuilder(); 4.462 - sb.append("Expected "); 4.463 - sb.append(expectedCount); 4.464 - sb.append(" annotation "); 4.465 - sb.append(expectedName); 4.466 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 4.467 - sb.append(" on method "); 4.468 - sb.append(methodname); 4.469 - sb.append(" parameter " + index); 4.470 - return sb.toString(); 4.471 - } 4.472 - 4.473 - } 4.474 - 4.475 - /** 4.476 - * An annotation found on a field. 4.477 - */ 4.478 - public static class ExpectedFieldAnnotation extends ExpectedAnnotation { 4.479 - private final String fieldname; 4.480 - 4.481 - /** 4.482 - * Create an {@code ExpectedFieldAnnotation} from its 4.483 - * components. It is usually a better idea to use a {@code 4.484 - * Builder} to do this. 4.485 - * 4.486 - * @param fieldname The expected field name. 4.487 - * @param expectedName The expected annotation name. 4.488 - * @param visibility Whether this annotation should be runtime-visible. 4.489 - * @param expectedCount The number of annotations that should be seen. 4.490 - */ 4.491 - public ExpectedFieldAnnotation(String fieldname, 4.492 - String expectedName, 4.493 - boolean visibility, 4.494 - int expectedCount) { 4.495 - super(expectedName, visibility, expectedCount); 4.496 - this.fieldname = fieldname; 4.497 - } 4.498 - 4.499 - public String toString() { 4.500 - final StringBuilder sb = new StringBuilder(); 4.501 - sb.append("Expected ").append(expectedCount) 4.502 - .append(" annotation ").append(expectedName) 4.503 - .append(visibility ? ", runtime visibile " : ", runtime invisibile ") 4.504 - .append(" on field ").append(fieldname); 4.505 - return sb.toString(); 4.506 - } 4.507 - 4.508 - /** 4.509 - * See if this template applies to a field. 4.510 - * 4.511 - * @param fieldname The field name to check. 4.512 - * @return Whether or not this template should apply. 4.513 - */ 4.514 - public boolean matchFieldName(String fieldname) { 4.515 - return this.fieldname.equals(fieldname); 4.516 - } 4.517 - 4.518 - } 4.519 - 4.520 - /** 4.521 - * An expected type annotation. This is both a superclass for 4.522 - * method and field type annotations, as well as a class for type 4.523 - * annotations on a class. 4.524 - */ 4.525 - public static class ExpectedTypeAnnotation extends ExpectedAnnotation { 4.526 - protected final TypeAnnotation.TargetType targetType; 4.527 - protected final int bound_index; 4.528 - protected final int parameter_index; 4.529 - protected final int type_index; 4.530 - protected final int exception_index; 4.531 - protected final TypeAnnotation.Position.TypePathEntry[] typePath; 4.532 - 4.533 - /** 4.534 - * Create an {@code ExpectedTypeAnnotation} from its 4.535 - * components. It is usually a better idea to use a {@code 4.536 - * Builder} to do this. 4.537 - * 4.538 - * @param expectedName The expected annotation name. 4.539 - * @param visibility Whether this annotation should be runtime-visible. 4.540 - * @param expectedCount The number of annotations that should 4.541 - * be seen. If 0, this asserts that the 4.542 - * described annotation is not present. 4.543 - * @param targetType The expected target type. 4.544 - * @param bound_index The expected bound index, or {@code Integer.MIN_VALUE}. 4.545 - * @param parameter_index The expected parameter index, or 4.546 - * {@code Integer.MIN_VALUE}. 4.547 - * @param type_index The expected type index, or {@code Integer.MIN_VALUE}. 4.548 - * @param exception_index The expected exception index, or 4.549 - * {@code Integer.MIN_VALUE}. 4.550 - * @param typePath The expected type path. 4.551 - */ 4.552 - public ExpectedTypeAnnotation(String expectedName, 4.553 - boolean visibility, 4.554 - int expectedCount, 4.555 - TypeAnnotation.TargetType targetType, 4.556 - int bound_index, 4.557 - int parameter_index, 4.558 - int type_index, 4.559 - int exception_index, 4.560 - TypeAnnotation.Position.TypePathEntry... typePath) { 4.561 - super(expectedName, visibility, expectedCount); 4.562 - this.targetType = targetType; 4.563 - this.bound_index = bound_index; 4.564 - this.parameter_index = parameter_index; 4.565 - this.type_index = type_index; 4.566 - this.exception_index = exception_index; 4.567 - this.typePath = typePath; 4.568 - } 4.569 - 4.570 - public String toString() { 4.571 - final StringBuilder sb = new StringBuilder(); 4.572 - sb.append("Expected "); 4.573 - sb.append(expectedCount); 4.574 - sb.append(" annotation "); 4.575 - sb.append(expectedName); 4.576 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 4.577 - sb.append(targetType); 4.578 - sb.append(", bound_index = "); 4.579 - sb.append(bound_index); 4.580 - sb.append(", parameter_index = "); 4.581 - sb.append(parameter_index); 4.582 - sb.append(", type_index = "); 4.583 - sb.append(type_index); 4.584 - sb.append(", exception_index = "); 4.585 - sb.append(exception_index); 4.586 - sb.append(", type_path = ["); 4.587 - for(int i = 0; i < typePath.length; i++) { 4.588 - if (i != 0) { 4.589 - sb.append(", "); 4.590 - } 4.591 - sb.append(typePath[i]); 4.592 - } 4.593 - sb.append("]"); 4.594 - return sb.toString(); 4.595 - } 4.596 - 4.597 - @Override 4.598 - public void matchAnnotation(ConstantPool cpool, 4.599 - Annotation anno) {} 4.600 - 4.601 - public void matchAnnotation(TypeAnnotation anno) { 4.602 - if (checkMatch(anno)) { 4.603 - count++; 4.604 - } 4.605 - } 4.606 - 4.607 - public boolean checkMatch(TypeAnnotation anno) { 4.608 - boolean matches = checkMatch(anno.constant_pool, anno.annotation); 4.609 - 4.610 - matches = matches && anno.position.type == targetType; 4.611 - matches = matches && anno.position.bound_index == bound_index; 4.612 - matches = matches && anno.position.parameter_index == parameter_index; 4.613 - matches = matches && anno.position.type_index == type_index; 4.614 - matches = matches && anno.position.exception_index == exception_index; 4.615 - matches = matches && anno.position.location.size() == typePath.length; 4.616 - 4.617 - if (matches) { 4.618 - int i = 0; 4.619 - for(TypeAnnotation.Position.TypePathEntry entry : 4.620 - anno.position.location) { 4.621 - matches = matches && typePath[i++].equals(entry); 4.622 - } 4.623 - } 4.624 - 4.625 - return matches; 4.626 - } 4.627 - 4.628 - /** 4.629 - * A builder class for creating {@code 4.630 - * ExpectedTypeAnnotation}s in a more convenient fashion. The 4.631 - * constructor for {@code ExpectedTypeAnnotation} takes a 4.632 - * large number of parameters (by necessity). This class 4.633 - * allows users to construct a {@code ExpectedTypeAnnotation}s 4.634 - * using only the ones they need. 4.635 - */ 4.636 - public static class Builder { 4.637 - protected final String expectedName; 4.638 - protected final boolean visibility; 4.639 - protected final int expectedCount; 4.640 - protected final TypeAnnotation.TargetType targetType; 4.641 - protected int bound_index = Integer.MIN_VALUE; 4.642 - protected int parameter_index = Integer.MIN_VALUE; 4.643 - protected int type_index = Integer.MIN_VALUE; 4.644 - protected int exception_index = Integer.MIN_VALUE; 4.645 - protected TypeAnnotation.Position.TypePathEntry[] typePath = 4.646 - new TypeAnnotation.Position.TypePathEntry[0]; 4.647 - 4.648 - /** 4.649 - * Create a {@code Builder} from the mandatory parameters. 4.650 - * 4.651 - * @param expectedName The expected annotation name. 4.652 - * @param targetType The expected target type. 4.653 - * @param visibility Whether this annotation should be runtime-visible. 4.654 - * @param expectedCount The number of annotations that should be seen. 4.655 - */ 4.656 - public Builder(String expectedName, 4.657 - TypeAnnotation.TargetType targetType, 4.658 - boolean visibility, 4.659 - int expectedCount) { 4.660 - this.expectedName = expectedName; 4.661 - this.visibility = visibility; 4.662 - this.expectedCount = expectedCount; 4.663 - this.targetType = targetType; 4.664 - } 4.665 - 4.666 - /** 4.667 - * Create an {@code ExpectedTypeAnnotation} from all 4.668 - * parameters that have been provided. The default values 4.669 - * will be used for those that have not. 4.670 - * 4.671 - * @return The cretaed {@code ExpectedTypeAnnotation}. 4.672 - */ 4.673 - public ExpectedTypeAnnotation build() { 4.674 - return new ExpectedTypeAnnotation(expectedName, visibility, 4.675 - expectedCount, targetType, 4.676 - bound_index, parameter_index, 4.677 - type_index, exception_index, 4.678 - typePath); 4.679 - } 4.680 - 4.681 - /** 4.682 - * Provide a bound index parameter. 4.683 - * 4.684 - * @param bound_index The bound_index value. 4.685 - */ 4.686 - public Builder setBoundIndex(int bound_index) { 4.687 - this.bound_index = bound_index; 4.688 - return this; 4.689 - } 4.690 - 4.691 - /** 4.692 - * Provide a parameter index parameter. 4.693 - * 4.694 - * @param bound_index The parameter_index value. 4.695 - */ 4.696 - public Builder setParameterIndex(int parameter_index) { 4.697 - this.parameter_index = parameter_index; 4.698 - return this; 4.699 - } 4.700 - 4.701 - /** 4.702 - * Provide a type index parameter. 4.703 - * 4.704 - * @param type_index The type_index value. 4.705 - */ 4.706 - public Builder setTypeIndex(int type_index) { 4.707 - this.type_index = type_index; 4.708 - return this; 4.709 - } 4.710 - 4.711 - /** 4.712 - * Provide an exception index parameter. 4.713 - * 4.714 - * @param exception_index The exception_index value. 4.715 - */ 4.716 - public Builder setExceptionIndex(int exception_index) { 4.717 - this.exception_index = exception_index; 4.718 - return this; 4.719 - } 4.720 - 4.721 - /** 4.722 - * Provide a type path parameter. 4.723 - * 4.724 - * @param typePath The type path value. 4.725 - */ 4.726 - public Builder setTypePath(TypeAnnotation.Position.TypePathEntry[] typePath) { 4.727 - this.typePath = typePath; 4.728 - return this; 4.729 - } 4.730 - } 4.731 - } 4.732 - 4.733 - /** 4.734 - * A type annotation found on a method. 4.735 - */ 4.736 - public static class ExpectedMethodTypeAnnotation extends ExpectedTypeAnnotation { 4.737 - private final String methodname; 4.738 - 4.739 - /** 4.740 - * Create an {@code ExpectedMethodTypeAnnotation} from its 4.741 - * components. It is usually a better idea to use a {@code 4.742 - * Builder} to do this. 4.743 - * 4.744 - * @param methodname The expected method name. 4.745 - * @param expectedName The expected annotation name. 4.746 - * @param visibility Whether this annotation should be runtime-visible. 4.747 - * @param expectedCount The number of annotations that should be seen. 4.748 - * @param targetType The expected target type. 4.749 - * @param bound_index The expected bound index, or {@code Integer.MIN_VALUE}. 4.750 - * @param parameter_index The expected parameter index, or 4.751 - * {@code Integer.MIN_VALUE}. 4.752 - * @param type_index The expected type index, or {@code Integer.MIN_VALUE}. 4.753 - * @param exception_index The expected exception index, or 4.754 - * {@code Integer.MIN_VALUE}. 4.755 - * @param typePath The expected type path. 4.756 - */ 4.757 - public ExpectedMethodTypeAnnotation(String methodname, 4.758 - String expectedName, 4.759 - boolean visibility, 4.760 - int expectedCount, 4.761 - TypeAnnotation.TargetType targetType, 4.762 - int bound_index, 4.763 - int parameter_index, 4.764 - int type_index, 4.765 - int exception_index, 4.766 - TypeAnnotation.Position.TypePathEntry... typePath) { 4.767 - super(expectedName, visibility, expectedCount, targetType, bound_index, 4.768 - parameter_index, type_index, exception_index, typePath); 4.769 - this.methodname = methodname; 4.770 - } 4.771 - 4.772 - public String toString() { 4.773 - final StringBuilder sb = new StringBuilder(); 4.774 - sb.append("Expected "); 4.775 - sb.append(expectedCount); 4.776 - sb.append(" annotation "); 4.777 - sb.append(expectedName); 4.778 - sb.append(visibility ? ", runtime visibile " : ", runtime invisibile "); 4.779 - sb.append(targetType); 4.780 - sb.append(", bound_index = "); 4.781 - sb.append(bound_index); 4.782 - sb.append(", parameter_index = "); 4.783 - sb.append(parameter_index); 4.784 - sb.append(", type_index = "); 4.785 - sb.append(type_index); 4.786 - sb.append(", exception_index = "); 4.787 - sb.append(exception_index); 4.788 - sb.append(", type_path = ["); 4.789 - for(int i = 0; i < typePath.length; i++) { 4.790 - if (i != 0) { 4.791 - sb.append(", "); 4.792 - } 4.793 - sb.append(typePath[i]); 4.794 - } 4.795 - sb.append("]"); 4.796 - sb.append(" on method "); 4.797 - sb.append(methodname); 4.798 - return sb.toString(); 4.799 - } 4.800 - 4.801 - /** 4.802 - * See if this template applies to a method. 4.803 - * 4.804 - * @param methodname The method name to check. 4.805 - * @return Whether or not this template should apply. 4.806 - */ 4.807 - public boolean matchMethodName(String methodname) { 4.808 - return this.methodname.equals(methodname); 4.809 - } 4.810 - 4.811 - /** 4.812 - * A builder class for creating {@code 4.813 - * ExpectedMethodTypeAnnotation}s in a more convenient fashion. The 4.814 - * constructor for {@code ExpectedMethodTypeAnnotation} takes a 4.815 - * large number of parameters (by necessity). This class 4.816 - * allows users to construct a {@code ExpectedMethodTypeAnnotation}s 4.817 - * using only the ones they need. 4.818 - */ 4.819 - public static class Builder extends ExpectedTypeAnnotation.Builder { 4.820 - protected final String methodname; 4.821 - 4.822 - /** 4.823 - * Create a {@code Builder} from the mandatory parameters. 4.824 - * 4.825 - * @param methodname The expected method name. 4.826 - * @param expectedName The expected annotation name. 4.827 - * @param targetType The expected target type. 4.828 - * @param visibility Whether this annotation should be runtime-visible. 4.829 - * @param expectedCount The number of annotations that should be seen. 4.830 - */ 4.831 - public Builder(String methodname, 4.832 - String expectedName, 4.833 - TypeAnnotation.TargetType targetType, 4.834 - boolean visibility, 4.835 - int expectedCount) { 4.836 - super(expectedName, targetType, visibility, expectedCount); 4.837 - this.methodname = methodname; 4.838 - } 4.839 - 4.840 - /** 4.841 - * Create an {@code ExpectedMethodTypeAnnotation} from all 4.842 - * parameters that have been provided. The default values 4.843 - * will be used for those that have not. 4.844 - * 4.845 - * @return The cretaed {@code ExpectedMethodTypeAnnotation}. 4.846 - */ 4.847 - public ExpectedMethodTypeAnnotation build() { 4.848 - return new ExpectedMethodTypeAnnotation(methodname, expectedName, 4.849 - visibility, expectedCount, 4.850 - targetType, bound_index, 4.851 - parameter_index, type_index, 4.852 - exception_index, typePath); 4.853 - } 4.854 - } 4.855 - } 4.856 - 4.857 - /** 4.858 - * A type annotation found on a field. 4.859 - */ 4.860 - public static class ExpectedFieldTypeAnnotation extends ExpectedTypeAnnotation { 4.861 - private final String fieldname; 4.862 - 4.863 - /** 4.864 - * Create an {@code ExpectedFieldTypeAnnotation} from its 4.865 - * components. It is usually a better idea to use a {@code 4.866 - * Builder} to do this. 4.867 - * 4.868 - * @param fieldname The expected field name. 4.869 - * @param expectedName The expected annotation name. 4.870 - * @param visibility Whether this annotation should be runtime-visible. 4.871 - * @param expectedCount The number of annotations that should be seen. 4.872 - * @param targetType The expected target type. 4.873 - * @param bound_index The expected bound index, or {@code Integer.MIN_VALUE}. 4.874 - * @param parameter_index The expected parameter index, or 4.875 - * {@code Integer.MIN_VALUE}. 4.876 - * @param type_index The expected type index, or {@code Integer.MIN_VALUE}. 4.877 - * @param exception_index The expected exception index, or 4.878 - * {@code Integer.MIN_VALUE}. 4.879 - * @param typePath The expected type path. 4.880 - */ 4.881 - public ExpectedFieldTypeAnnotation(String fieldname, 4.882 - String expectedName, 4.883 - boolean visibility, 4.884 - int expectedCount, 4.885 - TypeAnnotation.TargetType targetType, 4.886 - int bound_index, 4.887 - int parameter_index, 4.888 - int type_index, 4.889 - int exception_index, 4.890 - TypeAnnotation.Position.TypePathEntry... typePath) { 4.891 - super(expectedName, visibility, expectedCount, targetType, bound_index, 4.892 - parameter_index, type_index, exception_index, typePath); 4.893 - this.fieldname = fieldname; 4.894 - } 4.895 - 4.896 - public String toString() { 4.897 - final StringBuilder sb = new StringBuilder(); 4.898 - sb.append("Expected ").append(expectedCount) 4.899 - .append(" annotation ").append(expectedName) 4.900 - .append(visibility ? ", runtime visibile " : ", runtime invisibile ") 4.901 - .append(targetType) 4.902 - .append(", bound_index = ").append(bound_index) 4.903 - .append(", parameter_index = ").append(parameter_index) 4.904 - .append(", type_index = ").append(type_index) 4.905 - .append(", exception_index = ").append(exception_index) 4.906 - .append(", type_path = ["); 4.907 - 4.908 - for(int i = 0; i < typePath.length; i++) { 4.909 - if (i != 0) { 4.910 - sb.append(", "); 4.911 - } 4.912 - sb.append(typePath[i]); 4.913 - } 4.914 - sb.append("]") 4.915 - .append(" on field ").append(fieldname); 4.916 - return sb.toString(); 4.917 - } 4.918 - 4.919 - /** 4.920 - * See if this template applies to a field. 4.921 - * 4.922 - * @param fieldname The field name to check. 4.923 - * @return Whether or not this template should apply. 4.924 - */ 4.925 - public boolean matchFieldName(String fieldname) { 4.926 - return this.fieldname.equals(fieldname); 4.927 - } 4.928 - 4.929 - /** 4.930 - * A builder class for creating {@code 4.931 - * ExpectedFieldTypeAnnotation}s in a more convenient fashion. The 4.932 - * constructor for {@code ExpectedFieldTypeAnnotation} takes a 4.933 - * large number of parameters (by necessity). This class 4.934 - * allows users to construct a {@code ExpectedFieldTypeAnnotation}s 4.935 - * using only the ones they need. 4.936 - */ 4.937 - public static class Builder extends ExpectedTypeAnnotation.Builder { 4.938 - protected final String fieldname; 4.939 - 4.940 - /** 4.941 - * Create a {@code Builder} from the mandatory parameters. 4.942 - * 4.943 - * @param fieldname The expected field name. 4.944 - * @param expectedName The expected annotation name. 4.945 - * @param targetType The expected target type. 4.946 - * @param visibility Whether this annotation should be runtime-visible. 4.947 - * @param expectedCount The number of annotations that should be seen. 4.948 - */ 4.949 - public Builder(String fieldname, 4.950 - String expectedName, 4.951 - TypeAnnotation.TargetType targetType, 4.952 - boolean visibility, 4.953 - int expectedCount) { 4.954 - super(expectedName, targetType, visibility, expectedCount); 4.955 - this.fieldname = fieldname; 4.956 - } 4.957 - 4.958 - /** 4.959 - * Create an {@code ExpectedFieldTypeAnnotation} from all 4.960 - * parameters that have been provided. The default values 4.961 - * will be used for those that have not. 4.962 - * 4.963 - * @return The cretaed {@code ExpectedFieldTypeAnnotation}. 4.964 - */ 4.965 - public ExpectedFieldTypeAnnotation build() { 4.966 - return new ExpectedFieldTypeAnnotation(fieldname, expectedName, 4.967 - visibility, expectedCount, 4.968 - targetType, bound_index, 4.969 - parameter_index, type_index, 4.970 - exception_index, typePath); 4.971 - } 4.972 - } 4.973 - } 4.974 - 4.975 - private void matchClassAnnotation(ClassFile classfile, 4.976 - ExpectedAnnotation expected) 4.977 - throws ConstantPoolException { 4.978 - for(Attribute attr : classfile.attributes) { 4.979 - attr.accept(annoMatcher(classfile.constant_pool), expected); 4.980 - } 4.981 - } 4.982 - 4.983 - private void matchMethodAnnotation(ClassFile classfile, 4.984 - ExpectedMethodAnnotation expected) 4.985 - throws ConstantPoolException { 4.986 - for(Method meth : classfile.methods) { 4.987 - if (expected.matchMethodName(meth.getName(classfile.constant_pool))) { 4.988 - for(Attribute attr : meth.attributes) { 4.989 - attr.accept(annoMatcher(classfile.constant_pool), expected); 4.990 - } 4.991 - } 4.992 - } 4.993 - } 4.994 - 4.995 - private void matchParameterAnnotation(ClassFile classfile, 4.996 - ExpectedParameterAnnotation expected) 4.997 - throws ConstantPoolException { 4.998 - for(Method meth : classfile.methods) { 4.999 - if (expected.matchMethodName(meth.getName(classfile.constant_pool))) { 4.1000 - for(Attribute attr : meth.attributes) { 4.1001 - attr.accept(paramMatcher(classfile.constant_pool), expected); 4.1002 - } 4.1003 - } 4.1004 - } 4.1005 - } 4.1006 - 4.1007 - private void matchFieldAnnotation(ClassFile classfile, 4.1008 - ExpectedFieldAnnotation expected) 4.1009 - throws ConstantPoolException { 4.1010 - for(Field field : classfile.fields) { 4.1011 - if (expected.matchFieldName(field.getName(classfile.constant_pool))) { 4.1012 - for(Attribute attr : field.attributes) { 4.1013 - attr.accept(annoMatcher(classfile.constant_pool), expected); 4.1014 - } 4.1015 - } 4.1016 - } 4.1017 - } 4.1018 - 4.1019 - private void matchClassTypeAnnotation(ClassFile classfile, 4.1020 - ExpectedTypeAnnotation expected) 4.1021 - throws ConstantPoolException { 4.1022 - for(Attribute attr : classfile.attributes) { 4.1023 - attr.accept(typeAnnoMatcher, expected); 4.1024 - } 4.1025 - } 4.1026 - 4.1027 - private void matchMethodTypeAnnotation(ClassFile classfile, 4.1028 - ExpectedMethodTypeAnnotation expected) 4.1029 - throws ConstantPoolException { 4.1030 - for(Method meth : classfile.methods) { 4.1031 - if (expected.matchMethodName(meth.getName(classfile.constant_pool))) { 4.1032 - for(Attribute attr : meth.attributes) { 4.1033 - attr.accept(typeAnnoMatcher, expected); 4.1034 - } 4.1035 - } 4.1036 - } 4.1037 - } 4.1038 - 4.1039 - private void matchFieldTypeAnnotation(ClassFile classfile, 4.1040 - ExpectedFieldTypeAnnotation expected) 4.1041 - throws ConstantPoolException { 4.1042 - for(Field field : classfile.fields) { 4.1043 - if (expected.matchFieldName(field.getName(classfile.constant_pool))) { 4.1044 - for(Attribute attr : field.attributes) { 4.1045 - attr.accept(typeAnnoMatcher, expected); 4.1046 - } 4.1047 - } 4.1048 - } 4.1049 - } 4.1050 - 4.1051 - private void matchClassAnnotations(ClassFile classfile, 4.1052 - ExpectedAnnotation[] expected) 4.1053 - throws ConstantPoolException { 4.1054 - for(ExpectedAnnotation one : expected) { 4.1055 - matchClassAnnotation(classfile, one); 4.1056 - } 4.1057 - } 4.1058 - 4.1059 - private void matchMethodAnnotations(ClassFile classfile, 4.1060 - ExpectedMethodAnnotation[] expected) 4.1061 - throws ConstantPoolException { 4.1062 - for(ExpectedMethodAnnotation one : expected) { 4.1063 - matchMethodAnnotation(classfile, one); 4.1064 - } 4.1065 - } 4.1066 - 4.1067 - private void matchParameterAnnotations(ClassFile classfile, 4.1068 - ExpectedParameterAnnotation[] expected) 4.1069 - throws ConstantPoolException { 4.1070 - for(ExpectedParameterAnnotation one : expected) { 4.1071 - matchParameterAnnotation(classfile, one); 4.1072 - } 4.1073 - } 4.1074 - 4.1075 - private void matchFieldAnnotations(ClassFile classfile, 4.1076 - ExpectedFieldAnnotation[] expected) 4.1077 - throws ConstantPoolException { 4.1078 - for(ExpectedFieldAnnotation one : expected) { 4.1079 - matchFieldAnnotation(classfile, one); 4.1080 - } 4.1081 - } 4.1082 - 4.1083 - private void matchClassTypeAnnotations(ClassFile classfile, 4.1084 - ExpectedTypeAnnotation[] expected) 4.1085 - throws ConstantPoolException { 4.1086 - for(ExpectedTypeAnnotation one : expected) { 4.1087 - matchClassTypeAnnotation(classfile, one); 4.1088 - } 4.1089 - } 4.1090 - 4.1091 - private void matchMethodTypeAnnotations(ClassFile classfile, 4.1092 - ExpectedMethodTypeAnnotation[] expected) 4.1093 - throws ConstantPoolException { 4.1094 - for(ExpectedMethodTypeAnnotation one : expected) { 4.1095 - matchMethodTypeAnnotation(classfile, one); 4.1096 - } 4.1097 - } 4.1098 - 4.1099 - private void matchFieldTypeAnnotations(ClassFile classfile, 4.1100 - ExpectedFieldTypeAnnotation[] expected) 4.1101 - throws ConstantPoolException { 4.1102 - for(ExpectedFieldTypeAnnotation one : expected) { 4.1103 - matchFieldTypeAnnotation(classfile, one); 4.1104 - } 4.1105 - } 4.1106 - 4.1107 - /** 4.1108 - * Run a template on a single {@code ClassFile}. 4.1109 - * 4.1110 - * @param classfile The {@code ClassFile} on which to run tests. 4.1111 - * @param expected The expected annotation template. 4.1112 - */ 4.1113 - public void run(ClassFile classfile, 4.1114 - Expected... expected) 4.1115 - throws ConstantPoolException { 4.1116 - run(new ClassFile[] { classfile }, expected); 4.1117 - } 4.1118 - 4.1119 - /** 4.1120 - * Run a template on multiple {@code ClassFile}s. 4.1121 - * 4.1122 - * @param classfile The {@code ClassFile}s on which to run tests. 4.1123 - * @param expected The expected annotation template. 4.1124 - */ 4.1125 - public void run(ClassFile[] classfiles, 4.1126 - Expected... expected) 4.1127 - throws ConstantPoolException { 4.1128 - for(ClassFile classfile : classfiles) { 4.1129 - for(Expected one : expected) { 4.1130 - if (one.matchClassName(classfile.getName())) { 4.1131 - if (one.classAnnos != null) 4.1132 - matchClassAnnotations(classfile, one.classAnnos); 4.1133 - if (one.methodAnnos != null) 4.1134 - matchMethodAnnotations(classfile, one.methodAnnos); 4.1135 - if (one.methodParamAnnos != null) 4.1136 - matchParameterAnnotations(classfile, one.methodParamAnnos); 4.1137 - if (one.fieldAnnos != null) 4.1138 - matchFieldAnnotations(classfile, one.fieldAnnos); 4.1139 - if (one.classTypeAnnos != null) 4.1140 - matchClassTypeAnnotations(classfile, one.classTypeAnnos); 4.1141 - if (one.methodTypeAnnos != null) 4.1142 - matchMethodTypeAnnotations(classfile, one.methodTypeAnnos); 4.1143 - if (one.fieldTypeAnnos != null) 4.1144 - matchFieldTypeAnnotations(classfile, one.fieldTypeAnnos); 4.1145 - } 4.1146 - } 4.1147 - } 4.1148 - int count = 0; 4.1149 - for (Expected one : expected) { 4.1150 - count += one.check(); 4.1151 - } 4.1152 - 4.1153 - if (count != 0) { 4.1154 - throw new RuntimeException(count + " errors occurred in test"); 4.1155 - } 4.1156 - } 4.1157 - 4.1158 - /** 4.1159 - * Get a {@code ClassFile} from its file name. 4.1160 - * 4.1161 - * @param name The class' file name. 4.1162 - * @param host A class in the same package. 4.1163 - * @return The {@code ClassFile} 4.1164 - */ 4.1165 - public static ClassFile getClassFile(String name, 4.1166 - Class<?> host) 4.1167 - throws IOException, ConstantPoolException { 4.1168 - final URL url = host.getResource(name); 4.1169 - final InputStream in = url.openStream(); 4.1170 - try { 4.1171 - return ClassFile.read(in); 4.1172 - } finally { 4.1173 - in.close(); 4.1174 - } 4.1175 - } 4.1176 - 4.1177 - private static final Attribute.Visitor<Void, ExpectedTypeAnnotation> typeAnnoMatcher = 4.1178 - new Attribute.Visitor<Void, ExpectedTypeAnnotation>() { 4.1179 - 4.1180 - @Override 4.1181 - public Void visitBootstrapMethods(BootstrapMethods_attribute attr, 4.1182 - ExpectedTypeAnnotation expected) { 4.1183 - return null; 4.1184 - } 4.1185 - 4.1186 - @Override 4.1187 - public Void visitDefault(DefaultAttribute attr, 4.1188 - ExpectedTypeAnnotation expected) { 4.1189 - return null; 4.1190 - } 4.1191 - 4.1192 - @Override 4.1193 - public Void visitAnnotationDefault(AnnotationDefault_attribute attr, 4.1194 - ExpectedTypeAnnotation expected) { 4.1195 - return null; 4.1196 - } 4.1197 - 4.1198 - @Override 4.1199 - public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, 4.1200 - ExpectedTypeAnnotation expected) { 4.1201 - return null; 4.1202 - } 4.1203 - 4.1204 - @Override 4.1205 - public Void visitCode(Code_attribute attr, 4.1206 - ExpectedTypeAnnotation expected) { 4.1207 - return null; 4.1208 - } 4.1209 - 4.1210 - @Override 4.1211 - public Void visitCompilationID(CompilationID_attribute attr, 4.1212 - ExpectedTypeAnnotation expected) { 4.1213 - return null; 4.1214 - } 4.1215 - 4.1216 - @Override 4.1217 - public Void visitConstantValue(ConstantValue_attribute attr, 4.1218 - ExpectedTypeAnnotation expected) { 4.1219 - return null; 4.1220 - } 4.1221 - 4.1222 - @Override 4.1223 - public Void visitDeprecated(Deprecated_attribute attr, 4.1224 - ExpectedTypeAnnotation expected) { 4.1225 - return null; 4.1226 - } 4.1227 - 4.1228 - @Override 4.1229 - public Void visitEnclosingMethod(EnclosingMethod_attribute attr, 4.1230 - ExpectedTypeAnnotation expected) { 4.1231 - return null; 4.1232 - } 4.1233 - 4.1234 - @Override 4.1235 - public Void visitExceptions(Exceptions_attribute attr, 4.1236 - ExpectedTypeAnnotation expected) { 4.1237 - return null; 4.1238 - } 4.1239 - 4.1240 - @Override 4.1241 - public Void visitInnerClasses(InnerClasses_attribute attr, 4.1242 - ExpectedTypeAnnotation expected) { 4.1243 - return null; 4.1244 - } 4.1245 - 4.1246 - @Override 4.1247 - public Void visitLineNumberTable(LineNumberTable_attribute attr, 4.1248 - ExpectedTypeAnnotation expected) { 4.1249 - return null; 4.1250 - } 4.1251 - 4.1252 - @Override 4.1253 - public Void visitLocalVariableTable(LocalVariableTable_attribute attr, 4.1254 - ExpectedTypeAnnotation expected) { 4.1255 - return null; 4.1256 - } 4.1257 - 4.1258 - @Override 4.1259 - public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, 4.1260 - ExpectedTypeAnnotation expected) { 4.1261 - return null; 4.1262 - } 4.1263 - 4.1264 - @Override 4.1265 - public Void visitMethodParameters(MethodParameters_attribute attr, 4.1266 - ExpectedTypeAnnotation expected) { 4.1267 - return null; 4.1268 - } 4.1269 - 4.1270 - @Override 4.1271 - public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, 4.1272 - ExpectedTypeAnnotation expected) { 4.1273 - return null; 4.1274 - } 4.1275 - 4.1276 - @Override 4.1277 - public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, 4.1278 - ExpectedTypeAnnotation expected) { 4.1279 - return null; 4.1280 - } 4.1281 - 4.1282 - @Override 4.1283 - public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, 4.1284 - ExpectedTypeAnnotation expected) { 4.1285 - return null; 4.1286 - } 4.1287 - 4.1288 - @Override 4.1289 - public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, 4.1290 - ExpectedTypeAnnotation expected) { 4.1291 - return null; 4.1292 - } 4.1293 - 4.1294 - @Override 4.1295 - public Void visitSignature(Signature_attribute attr, 4.1296 - ExpectedTypeAnnotation expected) { 4.1297 - return null; 4.1298 - } 4.1299 - 4.1300 - @Override 4.1301 - public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, 4.1302 - ExpectedTypeAnnotation expected) { 4.1303 - return null; 4.1304 - } 4.1305 - 4.1306 - @Override 4.1307 - public Void visitSourceFile(SourceFile_attribute attr, 4.1308 - ExpectedTypeAnnotation expected) { 4.1309 - return null; 4.1310 - } 4.1311 - 4.1312 - @Override 4.1313 - public Void visitSourceID(SourceID_attribute attr, 4.1314 - ExpectedTypeAnnotation expected) { 4.1315 - return null; 4.1316 - } 4.1317 - 4.1318 - @Override 4.1319 - public Void visitStackMap(StackMap_attribute attr, 4.1320 - ExpectedTypeAnnotation expected) { 4.1321 - return null; 4.1322 - } 4.1323 - 4.1324 - @Override 4.1325 - public Void visitStackMapTable(StackMapTable_attribute attr, 4.1326 - ExpectedTypeAnnotation expected) { 4.1327 - return null; 4.1328 - } 4.1329 - 4.1330 - @Override 4.1331 - public Void visitSynthetic(Synthetic_attribute attr, 4.1332 - ExpectedTypeAnnotation expected) { 4.1333 - return null; 4.1334 - } 4.1335 - 4.1336 - @Override 4.1337 - public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, 4.1338 - ExpectedTypeAnnotation expected) { 4.1339 - if (expected.matchVisibility(true)) { 4.1340 - for(TypeAnnotation anno : attr.annotations) { 4.1341 - expected.matchAnnotation(anno); 4.1342 - } 4.1343 - } 4.1344 - 4.1345 - return null; 4.1346 - } 4.1347 - 4.1348 - @Override 4.1349 - public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, 4.1350 - ExpectedTypeAnnotation expected) { 4.1351 - if (expected.matchVisibility(false)) { 4.1352 - for(TypeAnnotation anno : attr.annotations) { 4.1353 - expected.matchAnnotation(anno); 4.1354 - } 4.1355 - } 4.1356 - 4.1357 - return null; 4.1358 - } 4.1359 - }; 4.1360 - 4.1361 - private static Attribute.Visitor<Void, ExpectedAnnotation> annoMatcher(ConstantPool cpool) { 4.1362 - return new Attribute.Visitor<Void, ExpectedAnnotation>() { 4.1363 - 4.1364 - @Override 4.1365 - public Void visitBootstrapMethods(BootstrapMethods_attribute attr, 4.1366 - ExpectedAnnotation expected) { 4.1367 - return null; 4.1368 - } 4.1369 - 4.1370 - @Override 4.1371 - public Void visitDefault(DefaultAttribute attr, 4.1372 - ExpectedAnnotation expected) { 4.1373 - return null; 4.1374 - } 4.1375 - 4.1376 - @Override 4.1377 - public Void visitAnnotationDefault(AnnotationDefault_attribute attr, 4.1378 - ExpectedAnnotation expected) { 4.1379 - return null; 4.1380 - } 4.1381 - 4.1382 - @Override 4.1383 - public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, 4.1384 - ExpectedAnnotation expected) { 4.1385 - return null; 4.1386 - } 4.1387 - 4.1388 - @Override 4.1389 - public Void visitCode(Code_attribute attr, 4.1390 - ExpectedAnnotation expected) { 4.1391 - return null; 4.1392 - } 4.1393 - 4.1394 - @Override 4.1395 - public Void visitCompilationID(CompilationID_attribute attr, 4.1396 - ExpectedAnnotation expected) { 4.1397 - return null; 4.1398 - } 4.1399 - 4.1400 - @Override 4.1401 - public Void visitConstantValue(ConstantValue_attribute attr, 4.1402 - ExpectedAnnotation expected) { 4.1403 - return null; 4.1404 - } 4.1405 - 4.1406 - @Override 4.1407 - public Void visitDeprecated(Deprecated_attribute attr, 4.1408 - ExpectedAnnotation expected) { 4.1409 - return null; 4.1410 - } 4.1411 - 4.1412 - @Override 4.1413 - public Void visitEnclosingMethod(EnclosingMethod_attribute attr, 4.1414 - ExpectedAnnotation expected) { 4.1415 - return null; 4.1416 - } 4.1417 - 4.1418 - @Override 4.1419 - public Void visitExceptions(Exceptions_attribute attr, 4.1420 - ExpectedAnnotation expected) { 4.1421 - return null; 4.1422 - } 4.1423 - 4.1424 - @Override 4.1425 - public Void visitInnerClasses(InnerClasses_attribute attr, 4.1426 - ExpectedAnnotation expected) { 4.1427 - return null; 4.1428 - } 4.1429 - 4.1430 - @Override 4.1431 - public Void visitLineNumberTable(LineNumberTable_attribute attr, 4.1432 - ExpectedAnnotation expected) { 4.1433 - return null; 4.1434 - } 4.1435 - 4.1436 - @Override 4.1437 - public Void visitLocalVariableTable(LocalVariableTable_attribute attr, 4.1438 - ExpectedAnnotation expected) { 4.1439 - return null; 4.1440 - } 4.1441 - 4.1442 - @Override 4.1443 - public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, 4.1444 - ExpectedAnnotation expected) { 4.1445 - return null; 4.1446 - } 4.1447 - 4.1448 - @Override 4.1449 - public Void visitMethodParameters(MethodParameters_attribute attr, 4.1450 - ExpectedAnnotation expected) { 4.1451 - return null; 4.1452 - } 4.1453 - 4.1454 - @Override 4.1455 - public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, 4.1456 - ExpectedAnnotation expected) { 4.1457 - return null; 4.1458 - } 4.1459 - 4.1460 - @Override 4.1461 - public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, 4.1462 - ExpectedAnnotation expected) { 4.1463 - return null; 4.1464 - } 4.1465 - 4.1466 - @Override 4.1467 - public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, 4.1468 - ExpectedAnnotation expected) { 4.1469 - return null; 4.1470 - } 4.1471 - 4.1472 - @Override 4.1473 - public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, 4.1474 - ExpectedAnnotation expected) { 4.1475 - return null; 4.1476 - } 4.1477 - 4.1478 - @Override 4.1479 - public Void visitSignature(Signature_attribute attr, 4.1480 - ExpectedAnnotation expected) { 4.1481 - return null; 4.1482 - } 4.1483 - 4.1484 - @Override 4.1485 - public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, 4.1486 - ExpectedAnnotation expected) { 4.1487 - return null; 4.1488 - } 4.1489 - 4.1490 - @Override 4.1491 - public Void visitSourceFile(SourceFile_attribute attr, 4.1492 - ExpectedAnnotation expected) { 4.1493 - return null; 4.1494 - } 4.1495 - 4.1496 - @Override 4.1497 - public Void visitSourceID(SourceID_attribute attr, 4.1498 - ExpectedAnnotation expected) { 4.1499 - return null; 4.1500 - } 4.1501 - 4.1502 - @Override 4.1503 - public Void visitStackMap(StackMap_attribute attr, 4.1504 - ExpectedAnnotation expected) { 4.1505 - return null; 4.1506 - } 4.1507 - 4.1508 - @Override 4.1509 - public Void visitStackMapTable(StackMapTable_attribute attr, 4.1510 - ExpectedAnnotation expected) { 4.1511 - return null; 4.1512 - } 4.1513 - 4.1514 - @Override 4.1515 - public Void visitSynthetic(Synthetic_attribute attr, 4.1516 - ExpectedAnnotation expected) { 4.1517 - return null; 4.1518 - } 4.1519 - 4.1520 - @Override 4.1521 - public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, 4.1522 - ExpectedAnnotation expected) { 4.1523 - if (expected.matchVisibility(true)) { 4.1524 - for(Annotation anno : attr.annotations) { 4.1525 - expected.matchAnnotation(cpool, anno); 4.1526 - } 4.1527 - } 4.1528 - 4.1529 - return null; 4.1530 - } 4.1531 - 4.1532 - @Override 4.1533 - public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, 4.1534 - ExpectedAnnotation expected) { 4.1535 - if (expected.matchVisibility(false)) { 4.1536 - for(Annotation anno : attr.annotations) { 4.1537 - expected.matchAnnotation(cpool, anno); 4.1538 - } 4.1539 - } 4.1540 - 4.1541 - return null; 4.1542 - } 4.1543 - }; 4.1544 - } 4.1545 - 4.1546 - private static Attribute.Visitor<Void, ExpectedParameterAnnotation> paramMatcher(ConstantPool cpool) { 4.1547 - return new Attribute.Visitor<Void, ExpectedParameterAnnotation>() { 4.1548 - 4.1549 - @Override 4.1550 - public Void visitBootstrapMethods(BootstrapMethods_attribute attr, 4.1551 - ExpectedParameterAnnotation expected) { 4.1552 - return null; 4.1553 - } 4.1554 - 4.1555 - @Override 4.1556 - public Void visitDefault(DefaultAttribute attr, 4.1557 - ExpectedParameterAnnotation expected) { 4.1558 - return null; 4.1559 - } 4.1560 - 4.1561 - @Override 4.1562 - public Void visitAnnotationDefault(AnnotationDefault_attribute attr, 4.1563 - ExpectedParameterAnnotation expected) { 4.1564 - return null; 4.1565 - } 4.1566 - 4.1567 - @Override 4.1568 - public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, 4.1569 - ExpectedParameterAnnotation expected) { 4.1570 - return null; 4.1571 - } 4.1572 - 4.1573 - @Override 4.1574 - public Void visitCode(Code_attribute attr, 4.1575 - ExpectedParameterAnnotation expected) { 4.1576 - return null; 4.1577 - } 4.1578 - 4.1579 - @Override 4.1580 - public Void visitCompilationID(CompilationID_attribute attr, 4.1581 - ExpectedParameterAnnotation expected) { 4.1582 - return null; 4.1583 - } 4.1584 - 4.1585 - @Override 4.1586 - public Void visitConstantValue(ConstantValue_attribute attr, 4.1587 - ExpectedParameterAnnotation expected) { 4.1588 - return null; 4.1589 - } 4.1590 - 4.1591 - @Override 4.1592 - public Void visitDeprecated(Deprecated_attribute attr, 4.1593 - ExpectedParameterAnnotation expected) { 4.1594 - return null; 4.1595 - } 4.1596 - 4.1597 - @Override 4.1598 - public Void visitEnclosingMethod(EnclosingMethod_attribute attr, 4.1599 - ExpectedParameterAnnotation expected) { 4.1600 - return null; 4.1601 - } 4.1602 - 4.1603 - @Override 4.1604 - public Void visitExceptions(Exceptions_attribute attr, 4.1605 - ExpectedParameterAnnotation expected) { 4.1606 - return null; 4.1607 - } 4.1608 - 4.1609 - @Override 4.1610 - public Void visitInnerClasses(InnerClasses_attribute attr, 4.1611 - ExpectedParameterAnnotation expected) { 4.1612 - return null; 4.1613 - } 4.1614 - 4.1615 - @Override 4.1616 - public Void visitLineNumberTable(LineNumberTable_attribute attr, 4.1617 - ExpectedParameterAnnotation expected) { 4.1618 - return null; 4.1619 - } 4.1620 - 4.1621 - @Override 4.1622 - public Void visitLocalVariableTable(LocalVariableTable_attribute attr, 4.1623 - ExpectedParameterAnnotation expected) { 4.1624 - return null; 4.1625 - } 4.1626 - 4.1627 - @Override 4.1628 - public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, 4.1629 - ExpectedParameterAnnotation expected) { 4.1630 - return null; 4.1631 - } 4.1632 - 4.1633 - @Override 4.1634 - public Void visitMethodParameters(MethodParameters_attribute attr, 4.1635 - ExpectedParameterAnnotation expected) { 4.1636 - return null; 4.1637 - } 4.1638 - 4.1639 - @Override 4.1640 - public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, 4.1641 - ExpectedParameterAnnotation expected) { 4.1642 - return null; 4.1643 - } 4.1644 - 4.1645 - @Override 4.1646 - public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, 4.1647 - ExpectedParameterAnnotation expected) { 4.1648 - return null; 4.1649 - } 4.1650 - 4.1651 - @Override 4.1652 - public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, 4.1653 - ExpectedParameterAnnotation expected) { 4.1654 - return null; 4.1655 - } 4.1656 - 4.1657 - @Override 4.1658 - public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, 4.1659 - ExpectedParameterAnnotation expected) { 4.1660 - return null; 4.1661 - } 4.1662 - 4.1663 - @Override 4.1664 - public Void visitSignature(Signature_attribute attr, 4.1665 - ExpectedParameterAnnotation expected) { 4.1666 - return null; 4.1667 - } 4.1668 - 4.1669 - @Override 4.1670 - public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, 4.1671 - ExpectedParameterAnnotation expected) { 4.1672 - return null; 4.1673 - } 4.1674 - 4.1675 - @Override 4.1676 - public Void visitSourceFile(SourceFile_attribute attr, 4.1677 - ExpectedParameterAnnotation expected) { 4.1678 - return null; 4.1679 - } 4.1680 - 4.1681 - @Override 4.1682 - public Void visitSourceID(SourceID_attribute attr, 4.1683 - ExpectedParameterAnnotation expected) { 4.1684 - return null; 4.1685 - } 4.1686 - 4.1687 - @Override 4.1688 - public Void visitStackMap(StackMap_attribute attr, 4.1689 - ExpectedParameterAnnotation expected) { 4.1690 - return null; 4.1691 - } 4.1692 - 4.1693 - @Override 4.1694 - public Void visitStackMapTable(StackMapTable_attribute attr, 4.1695 - ExpectedParameterAnnotation expected) { 4.1696 - return null; 4.1697 - } 4.1698 - 4.1699 - @Override 4.1700 - public Void visitSynthetic(Synthetic_attribute attr, 4.1701 - ExpectedParameterAnnotation expected) { 4.1702 - return null; 4.1703 - } 4.1704 - 4.1705 - @Override 4.1706 - public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, 4.1707 - ExpectedParameterAnnotation expected) { 4.1708 - if (expected.matchVisibility(true)) { 4.1709 - if (expected.index < attr.parameter_annotations.length) { 4.1710 - for(Annotation anno : 4.1711 - attr.parameter_annotations[expected.index]) { 4.1712 - expected.matchAnnotation(cpool, anno); 4.1713 - } 4.1714 - } 4.1715 - } 4.1716 - 4.1717 - return null; 4.1718 - } 4.1719 - 4.1720 - @Override 4.1721 - public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, 4.1722 - ExpectedParameterAnnotation expected) { 4.1723 - if (expected.matchVisibility(false)) { 4.1724 - if (expected.index < attr.parameter_annotations.length) { 4.1725 - for(Annotation anno : 4.1726 - attr.parameter_annotations[expected.index]) { 4.1727 - expected.matchAnnotation(cpool, anno); 4.1728 - } 4.1729 - } 4.1730 - } 4.1731 - 4.1732 - return null; 4.1733 - } 4.1734 - }; 4.1735 - } 4.1736 -}
5.1 --- a/test/tools/javac/annotations/SyntheticParameters.java Wed Dec 10 14:35:58 2014 -0800 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,198 +0,0 @@ 5.4 -/* 5.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 5.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 - * 5.8 - * This code is free software; you can redistribute it and/or modify it 5.9 - * under the terms of the GNU General Public License version 2 only, as 5.10 - * published by the Free Software Foundation. 5.11 - * 5.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 - * version 2 for more details (a copy is included in the LICENSE file that 5.16 - * accompanied this code). 5.17 - * 5.18 - * You should have received a copy of the GNU General Public License version 5.19 - * 2 along with this work; if not, write to the Free Software Foundation, 5.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 - * 5.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 - * or visit www.oracle.com if you need additional information or have any 5.24 - * questions. 5.25 - */ 5.26 - 5.27 -/* 5.28 - * @test SyntheticParameters 5.29 - * @bug 8065132 5.30 - * @summary Test generation of annotations on inner class parameters. 5.31 - * @library /lib/annotations/ 5.32 - * @run main SyntheticParameters 5.33 - */ 5.34 - 5.35 -import annotations.classfile.ClassfileInspector; 5.36 - 5.37 -import java.io.*; 5.38 -import java.lang.annotation.*; 5.39 - 5.40 -import com.sun.tools.classfile.*; 5.41 - 5.42 -public class SyntheticParameters extends ClassfileInspector { 5.43 - 5.44 - private static final String Inner_class = "SyntheticParameters$Inner.class"; 5.45 - private static final String Foo_class = "SyntheticParameters$Foo.class"; 5.46 - private static final Expected Inner_expected = 5.47 - new Expected("SyntheticParameters$Inner", 5.48 - null, 5.49 - null, 5.50 - new ExpectedParameterAnnotation[] { 5.51 - (ExpectedParameterAnnotation) 5.52 - // Assert there is no annotation on the 5.53 - // this$0 parameter. 5.54 - new ExpectedParameterAnnotation( 5.55 - "<init>", 5.56 - 0, 5.57 - "A", 5.58 - true, 5.59 - 0), 5.60 - (ExpectedParameterAnnotation) 5.61 - // Assert there is an annotation on the 5.62 - // first parameter. 5.63 - new ExpectedParameterAnnotation( 5.64 - "<init>", 5.65 - 1, 5.66 - "A", 5.67 - true, 5.68 - 1), 5.69 - (ExpectedParameterAnnotation) 5.70 - new ExpectedParameterAnnotation( 5.71 - "foo", 5.72 - 0, 5.73 - "A", 5.74 - true, 5.75 - 1), 5.76 - (ExpectedParameterAnnotation) 5.77 - new ExpectedParameterAnnotation( 5.78 - "foo", 5.79 - 1, 5.80 - "A", 5.81 - true, 5.82 - 0), 5.83 - (ExpectedParameterAnnotation) 5.84 - // Assert there is no annotation on the 5.85 - // this$0 parameter. 5.86 - new ExpectedParameterAnnotation( 5.87 - "<init>", 5.88 - 0, 5.89 - "B", 5.90 - false, 5.91 - 0), 5.92 - (ExpectedParameterAnnotation) 5.93 - // Assert there is an annotation on the 5.94 - // first parameter. 5.95 - new ExpectedParameterAnnotation( 5.96 - "<init>", 5.97 - 1, 5.98 - "B", 5.99 - false, 5.100 - 1), 5.101 - (ExpectedParameterAnnotation) 5.102 - new ExpectedParameterAnnotation( 5.103 - "foo", 5.104 - 0, 5.105 - "B", 5.106 - false, 5.107 - 1), 5.108 - (ExpectedParameterAnnotation) 5.109 - new ExpectedParameterAnnotation( 5.110 - "foo", 5.111 - 1, 5.112 - "B", 5.113 - false, 5.114 - 0) 5.115 - }, 5.116 - null); 5.117 - private static final Expected Foo_expected = 5.118 - new Expected("SyntheticParameters$Foo", 5.119 - null, 5.120 - null, 5.121 - new ExpectedParameterAnnotation[] { 5.122 - (ExpectedParameterAnnotation) 5.123 - // Assert there is no annotation on the 5.124 - // $enum$name parameter. 5.125 - new ExpectedParameterAnnotation( 5.126 - "<init>", 5.127 - 0, 5.128 - "A", 5.129 - true, 5.130 - 0), 5.131 - (ExpectedParameterAnnotation) 5.132 - // Assert there is no annotation on the 5.133 - // $enum$ordinal parameter. 5.134 - new ExpectedParameterAnnotation( 5.135 - "<init>", 5.136 - 1, 5.137 - "A", 5.138 - true, 5.139 - 0), 5.140 - (ExpectedParameterAnnotation) 5.141 - // Assert there is an annotation on the 5.142 - // first parameter. 5.143 - new ExpectedParameterAnnotation( 5.144 - "<init>", 5.145 - 2, 5.146 - "A", 5.147 - true, 5.148 - 1), 5.149 - (ExpectedParameterAnnotation) 5.150 - // Assert there is no annotation on the 5.151 - // $enum$name parameter. 5.152 - new ExpectedParameterAnnotation( 5.153 - "<init>", 5.154 - 0, 5.155 - "B", 5.156 - false, 5.157 - 0), 5.158 - (ExpectedParameterAnnotation) 5.159 - // Assert there is no annotation on the 5.160 - // $enum$ordinal parameter. 5.161 - new ExpectedParameterAnnotation( 5.162 - "<init>", 5.163 - 1, 5.164 - "B", 5.165 - false, 5.166 - 0), 5.167 - (ExpectedParameterAnnotation) 5.168 - // Assert there is an annotation on the 5.169 - // first parameter. 5.170 - new ExpectedParameterAnnotation( 5.171 - "<init>", 5.172 - 2, 5.173 - "B", 5.174 - false, 5.175 - 1) 5.176 - }, 5.177 - null); 5.178 - 5.179 - public static void main(String... args) throws Exception { 5.180 - new SyntheticParameters().run( 5.181 - new ClassFile[] { getClassFile(Inner_class, Inner.class), 5.182 - getClassFile(Foo_class, Foo.class) }, 5.183 - new Expected[] { Inner_expected, Foo_expected }); 5.184 - } 5.185 - 5.186 - public class Inner { 5.187 - public Inner(@A @B int a) {} 5.188 - public void foo(@A @B int a, int b) {} 5.189 - } 5.190 - 5.191 - public static enum Foo { 5.192 - ONE(null); 5.193 - Foo(@A @B Object a) {} 5.194 - } 5.195 -} 5.196 - 5.197 -@Retention(RetentionPolicy.RUNTIME) 5.198 -@interface A {} 5.199 - 5.200 -@Retention(RetentionPolicy.CLASS) 5.201 -@interface B {}
6.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/SyntheticParameters.java Wed Dec 10 14:35:58 2014 -0800 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,133 +0,0 @@ 6.4 -/* 6.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 6.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 - * 6.8 - * This code is free software; you can redistribute it and/or modify it 6.9 - * under the terms of the GNU General Public License version 2 only, as 6.10 - * published by the Free Software Foundation. 6.11 - * 6.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 - * version 2 for more details (a copy is included in the LICENSE file that 6.16 - * accompanied this code). 6.17 - * 6.18 - * You should have received a copy of the GNU General Public License version 6.19 - * 2 along with this work; if not, write to the Free Software Foundation, 6.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 - * 6.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 - * or visit www.oracle.com if you need additional information or have any 6.24 - * questions. 6.25 - */ 6.26 - 6.27 -/* 6.28 - * @test SyntheticParameters 6.29 - * @summary Test generation of annotations on inner class parameters. 6.30 - * @library /lib/annotations/ 6.31 - * @run main SyntheticParameters 6.32 - */ 6.33 - 6.34 -import annotations.classfile.ClassfileInspector; 6.35 - 6.36 -import java.io.*; 6.37 -import java.lang.annotation.*; 6.38 - 6.39 -import com.sun.tools.classfile.*; 6.40 - 6.41 -public class SyntheticParameters extends ClassfileInspector { 6.42 - 6.43 - private static final String Inner_class = "SyntheticParameters$Inner.class"; 6.44 - private static final String Foo_class = "SyntheticParameters$Foo.class"; 6.45 - private static final Expected Inner_expected = 6.46 - new Expected("SyntheticParameters$Inner", 6.47 - null, 6.48 - new ExpectedMethodTypeAnnotation[] { 6.49 - (ExpectedMethodTypeAnnotation) 6.50 - // Assert there is no annotation on the 6.51 - // this$0 parameter. 6.52 - new ExpectedMethodTypeAnnotation.Builder( 6.53 - "<init>", 6.54 - "A", 6.55 - TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 6.56 - false, 6.57 - 0).setParameterIndex(0).build(), 6.58 - (ExpectedMethodTypeAnnotation) 6.59 - // Assert there is an annotation on the 6.60 - // first parameter. 6.61 - new ExpectedMethodTypeAnnotation.Builder( 6.62 - "<init>", 6.63 - "A", 6.64 - TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 6.65 - false, 6.66 - 1).setParameterIndex(1).build(), 6.67 - (ExpectedMethodTypeAnnotation) 6.68 - new ExpectedMethodTypeAnnotation.Builder( 6.69 - "foo", 6.70 - "A", 6.71 - TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 6.72 - false, 6.73 - 1).setParameterIndex(0).build(), 6.74 - (ExpectedMethodTypeAnnotation) 6.75 - new ExpectedMethodTypeAnnotation.Builder( 6.76 - "foo", 6.77 - "A", 6.78 - TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 6.79 - false, 6.80 - 0).setParameterIndex(1).build() 6.81 - }, 6.82 - null); 6.83 - private static final Expected Foo_expected = 6.84 - new Expected("SyntheticParameters$Foo", 6.85 - null, 6.86 - new ExpectedMethodTypeAnnotation[] { 6.87 - (ExpectedMethodTypeAnnotation) 6.88 - // Assert there is no annotation on the 6.89 - // $enum$name parameter. 6.90 - new ExpectedMethodTypeAnnotation.Builder( 6.91 - "<init>", 6.92 - "A", 6.93 - TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 6.94 - false, 6.95 - 0).setParameterIndex(0).build(), 6.96 - (ExpectedMethodTypeAnnotation) 6.97 - // Assert there is no annotation on the 6.98 - // $enum$ordinal parameter. 6.99 - new ExpectedMethodTypeAnnotation.Builder( 6.100 - "<init>", 6.101 - "A", 6.102 - TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 6.103 - false, 6.104 - 0).setParameterIndex(1).build(), 6.105 - (ExpectedMethodTypeAnnotation) 6.106 - // Assert there is an annotation on the 6.107 - // first parameter. 6.108 - new ExpectedMethodTypeAnnotation.Builder( 6.109 - "<init>", 6.110 - "A", 6.111 - TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 6.112 - false, 6.113 - 1).setParameterIndex(2).build() 6.114 - }, 6.115 - null); 6.116 - 6.117 - public static void main(String... args) throws Exception { 6.118 - new SyntheticParameters().run( 6.119 - new ClassFile[] { getClassFile(Inner_class, Inner.class), 6.120 - getClassFile(Foo_class, Foo.class) }, 6.121 - new Expected[] { Inner_expected, Foo_expected }); 6.122 - } 6.123 - 6.124 - public class Inner { 6.125 - public Inner(@A int a) {} 6.126 - public void foo(@A int a, int b) {} 6.127 - } 6.128 - 6.129 - public static enum Foo { 6.130 - ONE(null); 6.131 - Foo(@A Object a) {} 6.132 - } 6.133 -} 6.134 - 6.135 -@Target({ElementType.TYPE_USE}) 6.136 -@interface A {}
7.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java Wed Dec 10 14:35:58 2014 -0800 7.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java Thu Dec 11 13:38:51 2014 -0800 7.3 @@ -46,7 +46,7 @@ 7.4 @TADescriptions({ 7.5 @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}), 7.6 @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}), 7.7 - @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) 7.8 + @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 7.9 }) 7.10 @TestClass("Test$Inner") 7.11 public String innerClass() { 7.12 @@ -61,7 +61,7 @@ 7.13 @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}), 7.14 @TADescription(annotation = "TC", type = METHOD_RECEIVER), 7.15 @TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}), 7.16 - @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) 7.17 + @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 7.18 }) 7.19 @TestClass("Test$Inner") 7.20 public String innerClass2() { 7.21 @@ -77,7 +77,7 @@ 7.22 @TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}), 7.23 @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}), 7.24 @TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}), 7.25 - @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) 7.26 + @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 7.27 }) 7.28 @TestClass("Outer$Middle$Inner") 7.29 public String innerClass3() {