(&mut self, attribute: &Attribute, cp: &ConstantPool)
| 121 | } |
| 122 | |
| 123 | fn write_attribute(&mut self, attribute: &Attribute, cp: &ConstantPool) -> Result<usize, Error> { |
| 124 | match attribute { |
| 125 | &Attribute::RawAttribute { name_index: ref n_idx, info: ref bytes } => self.write_u16(n_idx.idx as u16).and(self.write_u32(bytes.len() as u32)).and(self.write_n(bytes)), |
| 126 | &Attribute::ConstantValue(ref idx) => self.write_u16(cp.get_utf8_index("ConstantValue") as u16).and(self.write_u32(2)).and(self.write_u16(idx.idx as u16)), |
| 127 | &Attribute::Code { max_stack, max_locals, ref code, ref exception_table, ref attributes } => { |
| 128 | let mut target: Vec<u8> = vec![]; |
| 129 | |
| 130 | { |
| 131 | let mut code_writer = ClassWriter::new(&mut target); |
| 132 | |
| 133 | let _ = code_writer.write_u16(max_stack) |
| 134 | .and(code_writer.write_u16(max_locals)) |
| 135 | .and(code_writer.write_instructions(code)) |
| 136 | .and(code_writer.write_exception_handlers(exception_table)) |
| 137 | .and(code_writer.write_attributes(attributes, cp)); |
| 138 | } |
| 139 | |
| 140 | self.write_u16(cp.get_utf8_index("Code") as u16) |
| 141 | .and(self.write_u32(target.len() as u32)) |
| 142 | .and(self.write_n(&target)) |
| 143 | }, |
| 144 | &Attribute::StackMapTable(ref table) => self.write_stack_map_table(table, cp), |
| 145 | &Attribute::Exceptions(ref table) => self.write_u16(cp.get_utf8_index("Exceptions") as u16).and(self.write_u32(2 + (table.len() as u32) * 2)).and(self.write_u16(table.len() as u16)).and(table.iter().fold(Ok(0), |_, x| self.write_u16(x.idx as u16))), |
| 146 | &Attribute::InnerClasses(ref table) => self.write_u16(cp.get_utf8_index("InnerClasses") as u16).and(self.write_u32(2 + (table.len() as u32) * 8)).and(self.write_u16(table.len() as u16)).and(table.iter().fold(Ok(0), |_, x| { |
| 147 | self.write_u16(x.inner_class_info_index.idx as u16) |
| 148 | .and(self.write_u16(x.outer_class_info_index.idx as u16)) |
| 149 | .and(self.write_u16(x.inner_name_index.idx as u16)) |
| 150 | .and(self.write_u16(x.access_flags.flags)) |
| 151 | })), |
| 152 | &Attribute::EnclosingMethod { ref class_index, ref method_index } => self.write_u16(cp.get_utf8_index("EnclosingMethod") as u16).and(self.write_u32(4)).and(self.write_u16(class_index.idx as u16)).and(self.write_u16(method_index.idx as u16)), |
| 153 | &Attribute::Synthetic => self.write_u16(cp.get_utf8_index("Synthetic") as u16).and(self.write_u32(0)), |
| 154 | &Attribute::Signature(ref idx) => self.write_u16(cp.get_utf8_index("Signature") as u16).and(self.write_u32(2)).and(self.write_u16(idx.idx as u16)), |
| 155 | &Attribute::SourceFile(ref idx) => self.write_u16(cp.get_utf8_index("SourceFile") as u16).and(self.write_u32(2)).and(self.write_u16(idx.idx as u16)), |
| 156 | &Attribute::SourceDebugExtension(ref vec) => self.write_u16(cp.get_utf8_index("SourceDebugExtension") as u16).and(self.write_u32(vec.len() as u32)).and(self.write_n(vec)), |
| 157 | &Attribute::LineNumberTable(ref table) => self.write_u16(cp.get_utf8_index("LineNumberTable") as u16).and(self.write_u32(2 + table.len() as u32 * 4)).and(self.write_u16(table.len() as u16)).and(table.iter().fold(Ok(0), |_, x| { |
| 158 | self.write_u16(x.start_pc).and(self.write_u16(x.line_number)) |
| 159 | })), |
| 160 | &Attribute::LocalVariableTable(ref table) => self.write_u16(cp.get_utf8_index("LocalVariableTable") as u16).and(self.write_u32(2 + table.len() as u32 * 10)).and(self.write_u16(table.len() as u16)).and(table.iter().fold(Ok(0), |_, x| { |
| 161 | self.write_u16(x.start_pc) |
| 162 | .and(self.write_u16(x.length)) |
| 163 | .and(self.write_u16(x.name_index.idx as u16)) |
| 164 | .and(self.write_u16(x.descriptor_index.idx as u16)) |
| 165 | .and(self.write_u16(x.index)) |
| 166 | })), |
| 167 | &Attribute::LocalVariableTypeTable(ref table) => self.write_u16(cp.get_utf8_index("LocalVariableTypeTable") as u16).and(self.write_u32(2 + table.len() as u32 * 10)).and(self.write_u16(table.len() as u16)).and(table.iter().fold(Ok(0), |_, x| { |
| 168 | self.write_u16(x.start_pc) |
| 169 | .and(self.write_u16(x.length)) |
| 170 | .and(self.write_u16(x.name_index.idx as u16)) |
| 171 | .and(self.write_u16(x.signature_index.idx as u16)) |
| 172 | .and(self.write_u16(x.index)) |
| 173 | })), |
| 174 | &Attribute::Deprecated => self.write_u16(cp.get_utf8_index("Deprecated") as u16).and(self.write_u32(0)), |
| 175 | &Attribute::RuntimeVisibleAnnotations(ref table) => { |
| 176 | self.write_u16(cp.get_utf8_index("RuntimeVisibleAnnotations") as u16) |
| 177 | // attribute_length |
| 178 | .and(self.write_u32(table.iter().fold(2, |acc, x| acc + x.len() as u32))) |
| 179 | // num_annotations |
| 180 | .and(self.write_u16(table.len() as u16)) |
no test coverage detected