/** * Creates a new annotation collector. * * @param descriptor The annotation descriptor. * @param typePath The type variable's type path. */ protected ForTypeVariable(String descriptor, TypePath typePath) { super(descriptor); this.typePath = typePath == null ? LazyTypeDescription.GenericTypeToken.EMPTY_TYPE_PATH : typePath.toString(); }
/** * {@inheritDoc} */ public AnnotationVisitor visit(String annotationTypeDescriptor, boolean visible, int typeReference, String typePath) { return methodVisitor.visitTypeAnnotation(typeReference, TypePath.fromString(typePath), annotationTypeDescriptor, visible); } }
/** * Returns a string representation of this type path. {@link #ARRAY_ELEMENT} steps are represented * with '[', {@link #INNER_TYPE} steps with '.', {@link #WILDCARD_BOUND} steps with '*' and {@link * #TYPE_ARGUMENT} steps with their type argument index in decimal form followed by ';'. */ @Override public String toString() { int length = getLength(); StringBuilder result = new StringBuilder(length * 2); for (int i = 0; i < length; ++i) { switch (getStep(i)) { case ARRAY_ELEMENT: result.append('['); break; case INNER_TYPE: result.append('.'); break; case WILDCARD_BOUND: result.append('*'); break; case TYPE_ARGUMENT: result.append(getStepArgument(i)).append(';'); break; default: throw new AssertionError(); } } return result.toString(); }
@Override public AnnotationVisitor visitTypeAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { // Create a ByteVector to hold a 'type_annotation' JVMS structure. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.20. ByteVector typeAnnotation = new ByteVector(); // Write target_type, target_info, and target_path. TypeReference.putTarget(typeRef, typeAnnotation); TypePath.put(typePath, typeAnnotation); // Write type_index and reserve space for num_element_value_pairs. typeAnnotation.putShort(symbolTable.addConstantUtf8(descriptor)).putShort(0); if (visible) { return lastRuntimeVisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastRuntimeVisibleTypeAnnotation); } else { return lastRuntimeInvisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastRuntimeInvisibleTypeAnnotation); } }
return new TypePath(output.data, 0);
@Override public AnnotationVisitor visitTypeAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { // Create a ByteVector to hold a 'type_annotation' JVMS structure. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.20. ByteVector typeAnnotation = new ByteVector(); // Write target_type, target_info, and target_path. TypeReference.putTarget(typeRef, typeAnnotation); TypePath.put(typePath, typeAnnotation); // Write type_index and reserve space for num_element_value_pairs. typeAnnotation.putShort(symbolTable.addConstantUtf8(descriptor)).putShort(0); if (visible) { return lastRuntimeVisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastRuntimeVisibleTypeAnnotation); } else { return lastRuntimeInvisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastRuntimeInvisibleTypeAnnotation); } }
pathLength == 0 ? null : new TypePath(b, currentOffset);
@Override public AnnotationVisitor visitTypeAnnotation(int i, TypePath tp, String string, boolean bln) { recordedCalls.add(List.of( "visitTypeAnnotation", i, tp.toString(), string, bln )); return super.visitTypeAnnotation(i, tp, string, bln); }
@Override public AnnotationVisitor visitTryCatchAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { // Create a ByteVector to hold a 'type_annotation' JVMS structure. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.20. ByteVector typeAnnotation = new ByteVector(); // Write target_type, target_info, and target_path. TypeReference.putTarget(typeRef, typeAnnotation); TypePath.put(typePath, typeAnnotation); // Write type_index and reserve space for num_element_value_pairs. typeAnnotation.putShort(symbolTable.addConstantUtf8(descriptor)).putShort(0); if (visible) { return lastCodeRuntimeVisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastCodeRuntimeVisibleTypeAnnotation); } else { return lastCodeRuntimeInvisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastCodeRuntimeInvisibleTypeAnnotation); } }
/** * {@inheritDoc} */ public AnnotationVisitor visit(String annotationTypeDescriptor, boolean visible, int typeReference, String typePath) { return classVisitor.visitTypeAnnotation(typeReference, TypePath.fromString(typePath), annotationTypeDescriptor, visible); } }
if ((targetType >>> 24) == TypeReference.EXCEPTION_PARAMETER) { TypePath path = pathLength == 0 ? null : new TypePath(b, currentOffset); currentOffset += 1 + 2 * pathLength;
@Override public AnnotationVisitor visitTryCatchAnnotation(int i, TypePath tp, String string, boolean bln) { recordedCalls.add(List.of( "visitTryCatchAnnotation", i, tp.toString(), string, bln )); return super.visitTryCatchAnnotation(i, tp, string, bln); }
@Override public final AnnotationVisitor visitTypeAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { // Create a ByteVector to hold a 'type_annotation' JVMS structure. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.20. ByteVector typeAnnotation = new ByteVector(); // Write target_type, target_info, and target_path. TypeReference.putTarget(typeRef, typeAnnotation); TypePath.put(typePath, typeAnnotation); // Write type_index and reserve space for num_element_value_pairs. typeAnnotation.putShort(symbolTable.addConstantUtf8(descriptor)).putShort(0); if (visible) { return lastRuntimeVisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastRuntimeVisibleTypeAnnotation); } else { return lastRuntimeInvisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastRuntimeInvisibleTypeAnnotation); } }
/** * {@inheritDoc} */ public AnnotationVisitor visit(String annotationTypeDescriptor, boolean visible, int typeReference, String typePath) { return fieldVisitor.visitTypeAnnotation(typeReference, TypePath.fromString(typePath), annotationTypeDescriptor, visible); } }
@Override public AnnotationVisitor visitInsnAnnotation(int i, TypePath tp, String string, boolean bln) { recordedCalls.add(List.of( "visitInsnAnnotation", i, tp.toString(), string, bln )); return super.visitInsnAnnotation(i, tp, string, bln); }
@Override public AnnotationVisitor visitInsnAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { // Create a ByteVector to hold a 'type_annotation' JVMS structure. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.20. ByteVector typeAnnotation = new ByteVector(); // Write target_type, target_info, and target_path. TypeReference.putTarget((typeRef & 0xFF0000FF) | (lastBytecodeOffset << 8), typeAnnotation); TypePath.put(typePath, typeAnnotation); // Write type_index and reserve space for num_element_value_pairs. typeAnnotation.putShort(symbolTable.addConstantUtf8(descriptor)).putShort(0); if (visible) { return lastCodeRuntimeVisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastCodeRuntimeVisibleTypeAnnotation); } else { return lastCodeRuntimeInvisibleTypeAnnotation = new AnnotationWriter(symbolTable, typeAnnotation, lastCodeRuntimeInvisibleTypeAnnotation); } }
/** * {@inheritDoc} */ public AnnotationVisitor visit(String annotationTypeDescriptor, boolean visible, int typeReference, String typePath) { return methodVisitor.visitTypeAnnotation(typeReference, TypePath.fromString(typePath), annotationTypeDescriptor, visible); } }
@Override public AnnotationVisitor visitLocalVariableAnnotation(int i, TypePath tp, Label[] labels, Label[] labels1, int[] ints, String string, boolean bln) { recordedCalls.add(List.of( "visitLocalVariableAnnotation", tp.toString(), listFromArray(labels).map(this::resolveLabel), listFromArray(labels1).map(this::resolveLabel), List.of(ints), string, bln )); return super.visitLocalVariableAnnotation(i, tp, labels, labels1, ints, string, bln); }
.putShort(index[i]); TypePath.put(typePath, typeAnnotation);