/** * Checks that the given string is a valid type descriptor. * * @param version the class version. * @param descriptor the string to be checked. * @param canBeVoid {@literal true} if {@code V} can be considered valid. */ static void checkDescriptor(final int version, final String descriptor, final boolean canBeVoid) { int endPos = checkDescriptor(version, descriptor, 0, canBeVoid); if (endPos != descriptor.length()) { throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor); } }
/** * Checks that the given string is a valid type descriptor. * * @param version the class version. * @param descriptor the string to be checked. * @param canBeVoid {@literal true} if {@code V} can be considered valid. */ static void checkDescriptor(final int version, final String descriptor, final boolean canBeVoid) { int endPos = checkDescriptor(version, descriptor, 0, canBeVoid); if (endPos != descriptor.length()) { throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor); } }
/** * Checks that the given string is a valid internal class name or array type descriptor. * * @param version the class version. * @param name the string to be checked. * @param message the message to use in case of error. */ static void checkInternalName(final int version, final String name, final String message) { if (name == null || name.length() == 0) { throw new IllegalArgumentException(INVALID + message + MUST_NOT_BE_NULL_OR_EMPTY); } if (name.charAt(0) == '[') { checkDescriptor(version, name, false); } else { checkInternalClassName(version, name, message); } }
@Override public void visitEnum(final String name, final String descriptor, final String value) { checkVisitEndNotCalled(); checkName(name); // Annotations can only appear in V1_5 or more classes. CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false); if (value == null) { throw new IllegalArgumentException("Invalid enum value"); } super.visitEnum(name, descriptor, value); }
@Override public void visitEnum(final String name, final String descriptor, final String value) { checkVisitEndNotCalled(); checkName(name); // Annotations can only appear in V1_5 or more classes. CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false); if (value == null) { throw new IllegalArgumentException("Invalid enum value"); } super.visitEnum(name, descriptor, value); }
@Override public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { checkState(); CheckMethodAdapter.checkDescriptor(version, descriptor, false); return new CheckAnnotationAdapter(super.visitAnnotation(descriptor, visible)); }
@Override public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { checkVisitEndNotCalled(); // Annotations can only appear in V1_5 or more classes. CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false); return new CheckAnnotationAdapter(super.visitAnnotation(descriptor, visible)); }
@Override public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { checkVisitEndNotCalled(); // Annotations can only appear in V1_5 or more classes. CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false); return new CheckAnnotationAdapter(super.visitAnnotation(descriptor, visible)); }
@Override public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { checkState(); CheckMethodAdapter.checkDescriptor(version, descriptor, false); return new CheckAnnotationAdapter(super.visitAnnotation(descriptor, visible)); }
@Override public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { checkVisitEndNotCalled(); checkDescriptor(version, descriptor, false); return new CheckAnnotationAdapter(super.visitAnnotation(descriptor, visible)); }
@Override public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { checkVisitEndNotCalled(); checkDescriptor(version, descriptor, false); return new CheckAnnotationAdapter(super.visitAnnotation(descriptor, visible)); }
@Override public void visitFieldInsn( final int opcode, final String owner, final String name, final String descriptor) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkOpcodeMethod(opcode, Method.VISIT_FIELD_INSN); checkInternalName(version, owner, "owner"); checkUnqualifiedName(version, name, "name"); checkDescriptor(version, descriptor, false); super.visitFieldInsn(opcode, owner, name, descriptor); ++insnCount; }
@Override public AnnotationVisitor visitTypeAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { checkVisitEndNotCalled(); int sort = new TypeReference(typeRef).getSort(); if (sort != TypeReference.FIELD) { throw new IllegalArgumentException( "Invalid type reference sort 0x" + Integer.toHexString(sort)); } CheckClassAdapter.checkTypeRef(typeRef); CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false); return new CheckAnnotationAdapter( super.visitTypeAnnotation(typeRef, typePath, descriptor, visible)); }
@Override public AnnotationVisitor visitAnnotation(final String name, final String descriptor) { checkVisitEndNotCalled(); checkName(name); // Annotations can only appear in V1_5 or more classes. CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false); return new CheckAnnotationAdapter(super.visitAnnotation(name, descriptor)); }
@Override public void visitFieldInsn( final int opcode, final String owner, final String name, final String descriptor) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkOpcodeMethod(opcode, Method.VISIT_FIELD_INSN); checkInternalName(version, owner, "owner"); checkUnqualifiedName(version, name, "name"); checkDescriptor(version, descriptor, false); super.visitFieldInsn(opcode, owner, name, descriptor); ++insnCount; }
@Override public AnnotationVisitor visitTypeAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { checkVisitEndNotCalled(); int sort = new TypeReference(typeRef).getSort(); if (sort != TypeReference.FIELD) { throw new IllegalArgumentException( "Invalid type reference sort 0x" + Integer.toHexString(sort)); } CheckClassAdapter.checkTypeRef(typeRef); CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false); return new CheckAnnotationAdapter( super.visitTypeAnnotation(typeRef, typePath, descriptor, visible)); }
@Override public AnnotationVisitor visitTypeAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { checkState(); int sort = new TypeReference(typeRef).getSort(); if (sort != TypeReference.CLASS_TYPE_PARAMETER && sort != TypeReference.CLASS_TYPE_PARAMETER_BOUND && sort != TypeReference.CLASS_EXTENDS) { throw new IllegalArgumentException( "Invalid type reference sort 0x" + Integer.toHexString(sort)); } checkTypeRef(typeRef); CheckMethodAdapter.checkDescriptor(version, descriptor, false); return new CheckAnnotationAdapter( super.visitTypeAnnotation(typeRef, typePath, descriptor, visible)); }
@Override public AnnotationVisitor visitAnnotation(final String name, final String descriptor) { checkVisitEndNotCalled(); checkName(name); // Annotations can only appear in V1_5 or more classes. CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false); return new CheckAnnotationAdapter(super.visitAnnotation(name, descriptor)); }
@Override public AnnotationVisitor visitTryCatchAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); int sort = new TypeReference(typeRef).getSort(); if (sort != TypeReference.EXCEPTION_PARAMETER) { throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort)); } CheckClassAdapter.checkTypeRef(typeRef); CheckMethodAdapter.checkDescriptor(version, descriptor, false); return new CheckAnnotationAdapter( super.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible)); }
@Override public AnnotationVisitor visitTryCatchAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); int sort = new TypeReference(typeRef).getSort(); if (sort != TypeReference.EXCEPTION_PARAMETER) { throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort)); } CheckClassAdapter.checkTypeRef(typeRef); CheckMethodAdapter.checkDescriptor(version, descriptor, false); return new CheckAnnotationAdapter( super.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible)); }