@Test public void testNoAnnotationsOnClass() throws IOException { assertFalse(filter.accept(getByteCodeInputStream(ClassWithoutAnnotations.class))); }
@SuppressWarnings("unused") public boolean accept(InputStream classFileStream) throws IOException { DataInputStream in = new DataInputStream(classFileStream); int magic = in.readInt(); if (magic != CLASS_FILE_MAGIC) { if (log.isDebugEnabled()) { log.debug("Magic not found! Not a valid class file!"); } return false; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); if (major < 49) { if (log.isTraceEnabled()) { log.trace("Not a JDK5 class! It cannot contain annotations!"); } return false; } int constantPoolEntries = in.readUnsignedShort() - 1; for (int i = 0; i < constantPoolEntries; i++) { int tag = in.readUnsignedByte(); switch (tag) { case CONSTANT_Class: in.readUnsignedShort(); break; case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_String: in.readUnsignedShort(); break; case CONSTANT_Integer: case CONSTANT_Float: in.readInt(); break; case CONSTANT_Long: case CONSTANT_Double: in.readLong(); i++; break; case CONSTANT_NameAndType: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_Utf8: String str = in.readUTF(); if (containsFieldDescriptor(str)) { if (log.isTraceEnabled()) { log.trace("Found interesting annotation reference in constant pool: " + str); } return true; } break; case CONSTANT_MethodHandle: in.readByte(); in.readShort(); break; case CONSTANT_MethodType: in.readShort(); break; case CONSTANT_InvokeDynamic: in.readShort(); in.readShort(); break; default: if (log.isDebugEnabled()) { log.debug("Unknown constant pool tag found: " + tag); } return true; } } return false; }
ByteCodeFilter { @SuppressWarnings("unused") public boolean accept(InputStream classFileStream) throws IOException { DataInputStream in = new DataInputStream(classFileStream); int magic = in.readInt(); if (magic != CLASS_FILE_MAGIC) { if (log.isDebugEnabled()) { log.debug("Magic not found! Not a valid class file!"); } return false; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); if (major < 49) { if (log.isTraceEnabled()) { log.trace("Not a JDK5 class! It cannot contain annotations!"); } return false; } int constantPoolEntries = in.readUnsignedShort() - 1; for (int i = 0; i < constantPoolEntries; i++) { int tag = in.readUnsignedByte(); switch (tag) { case CONSTANT_Class: in.readUnsignedShort(); break; case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_String: in.readUnsignedShort(); break; case CONSTANT_Integer: case CONSTANT_Float: in.readInt(); break; case CONSTANT_Long: case CONSTANT_Double: in.readLong(); i++; break; case CONSTANT_NameAndType: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_Utf8: String str = in.readUTF(); if (containsFieldDescriptor(str)) { if (log.isTraceEnabled()) { log.trace("Found interesting annotation reference in constant pool: " + str); } return true; } break; case CONSTANT_MethodHandle: in.readByte(); in.readShort(); break; case CONSTANT_MethodType: in.readShort(); break; case CONSTANT_InvokeDynamic: in.readShort(); in.readShort(); break; default: if (log.isDebugEnabled()) { log.debug("Unknown constant pool tag found: " + tag); } return true; } } return false; } }
ByteCodeFilter { @SuppressWarnings("unused") public boolean accept(InputStream classFileStream) throws IOException { DataInputStream in = new DataInputStream(classFileStream); int magic = in.readInt(); if (magic != CLASS_FILE_MAGIC) { if (log.isDebugEnabled()) { log.debug("Magic not found! Not a valid class file!"); } return false; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); if (major < 49) { if (log.isTraceEnabled()) { log.trace("Not a JDK5 class! It cannot contain annotations!"); } return false; } int constantPoolEntries = in.readUnsignedShort() - 1; for (int i = 0; i < constantPoolEntries; i++) { int tag = in.readUnsignedByte(); switch (tag) { case CONSTANT_Class: in.readUnsignedShort(); break; case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_String: in.readUnsignedShort(); break; case CONSTANT_Integer: case CONSTANT_Float: in.readInt(); break; case CONSTANT_Long: case CONSTANT_Double: in.readLong(); i++; break; case CONSTANT_NameAndType: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_Utf8: String str = in.readUTF(); if (containsFieldDescriptor(str)) { if (log.isTraceEnabled()) { log.trace("Found interesting annotation reference in constant pool: " + str); } return true; } break; case CONSTANT_MethodHandle: in.readByte(); in.readShort(); break; case CONSTANT_MethodType: in.readShort(); break; case CONSTANT_InvokeDynamic: in.readShort(); in.readShort(); break; default: if (log.isDebugEnabled()) { log.debug("Unknown constant pool tag found: " + tag); } return true; } } return false; } ByteCodeFilter(Set<Class<? extends Annotation>> types); }
ByteCodeFilter { @SuppressWarnings("unused") public boolean accept(InputStream classFileStream) throws IOException { DataInputStream in = new DataInputStream(classFileStream); int magic = in.readInt(); if (magic != CLASS_FILE_MAGIC) { if (log.isDebugEnabled()) { log.debug("Magic not found! Not a valid class file!"); } return false; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); if (major < 49) { if (log.isTraceEnabled()) { log.trace("Not a JDK5 class! It cannot contain annotations!"); } return false; } int constantPoolEntries = in.readUnsignedShort() - 1; for (int i = 0; i < constantPoolEntries; i++) { int tag = in.readUnsignedByte(); switch (tag) { case CONSTANT_Class: in.readUnsignedShort(); break; case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_String: in.readUnsignedShort(); break; case CONSTANT_Integer: case CONSTANT_Float: in.readInt(); break; case CONSTANT_Long: case CONSTANT_Double: in.readLong(); i++; break; case CONSTANT_NameAndType: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_Utf8: String str = in.readUTF(); if (containsFieldDescriptor(str)) { if (log.isTraceEnabled()) { log.trace("Found interesting annotation reference in constant pool: " + str); } return true; } break; case CONSTANT_MethodHandle: in.readByte(); in.readShort(); break; case CONSTANT_MethodType: in.readShort(); break; case CONSTANT_InvokeDynamic: in.readShort(); in.readShort(); break; default: if (log.isDebugEnabled()) { log.debug("Unknown constant pool tag found: " + tag); } return true; } } return false; } ByteCodeFilter(Set<Class<? extends Annotation>> types); @SuppressWarnings("unused") boolean accept(InputStream classFileStream); @Override String toString(); }
ByteCodeFilter { @SuppressWarnings("unused") public boolean accept(InputStream classFileStream) throws IOException { DataInputStream in = new DataInputStream(classFileStream); int magic = in.readInt(); if (magic != CLASS_FILE_MAGIC) { if (log.isDebugEnabled()) { log.debug("Magic not found! Not a valid class file!"); } return false; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); if (major < 49) { if (log.isTraceEnabled()) { log.trace("Not a JDK5 class! It cannot contain annotations!"); } return false; } int constantPoolEntries = in.readUnsignedShort() - 1; for (int i = 0; i < constantPoolEntries; i++) { int tag = in.readUnsignedByte(); switch (tag) { case CONSTANT_Class: in.readUnsignedShort(); break; case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_String: in.readUnsignedShort(); break; case CONSTANT_Integer: case CONSTANT_Float: in.readInt(); break; case CONSTANT_Long: case CONSTANT_Double: in.readLong(); i++; break; case CONSTANT_NameAndType: in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_Utf8: String str = in.readUTF(); if (containsFieldDescriptor(str)) { if (log.isTraceEnabled()) { log.trace("Found interesting annotation reference in constant pool: " + str); } return true; } break; case CONSTANT_MethodHandle: in.readByte(); in.readShort(); break; case CONSTANT_MethodType: in.readShort(); break; case CONSTANT_InvokeDynamic: in.readShort(); in.readShort(); break; default: if (log.isDebugEnabled()) { log.debug("Unknown constant pool tag found: " + tag); } return true; } } return false; } ByteCodeFilter(Set<Class<? extends Annotation>> types); @SuppressWarnings("unused") boolean accept(InputStream classFileStream); @Override String toString();  }