diff --git a/crates/noxis-classfile/src/format/parse/attrs.rs b/crates/noxis-classfile/src/format/parse/attrs.rs index c99a392..66cad3d 100644 --- a/crates/noxis-classfile/src/format/parse/attrs.rs +++ b/crates/noxis-classfile/src/format/parse/attrs.rs @@ -123,6 +123,36 @@ pub(super) fn convert(attr: &RtAttr, pool: &ConstantPool<'_>) -> Result>()?, ) } + RtAttr::RuntimeVisibleParameterAnnotations { + parameter_annotations, + .. + } => Attribute::RuntimeVisibleParameterAnnotations( + parameter_annotations + .iter() + .map(|param| { + param + .annotations + .iter() + .map(|anno| annotation(pool, anno)) + .collect::>() + }) + .collect::>()?, + ), + RtAttr::RuntimeInvisibleParameterAnnotations { + parameter_annotations, + .. + } => Attribute::RuntimeInvisibleParameterAnnotations( + parameter_annotations + .iter() + .map(|param| { + param + .annotations + .iter() + .map(|anno| annotation(pool, anno)) + .collect::>() + }) + .collect::>()?, + ), other => raw(other)?, }) } diff --git a/crates/noxis-classfile/src/format/write/attrs.rs b/crates/noxis-classfile/src/format/write/attrs.rs index 246dc15..a450715 100644 --- a/crates/noxis-classfile/src/format/write/attrs.rs +++ b/crates/noxis-classfile/src/format/write/attrs.rs @@ -193,6 +193,38 @@ pub(super) fn convert(attr: &Attribute, pool: &mut Pool) -> Result>()?, }, + Attribute::RuntimeVisibleParameterAnnotations(params) => { + RtAttr::RuntimeVisibleParameterAnnotations { + name_index: pool.utf8("RuntimeVisibleParameterAnnotations")?, + parameter_annotations: params + .iter() + .map(|param| { + Ok(ristretto_classfile::attributes::ParameterAnnotation { + annotations: param + .iter() + .map(|anno| annotation(anno, pool)) + .collect::>()?, + }) + }) + .collect::>()?, + } + } + Attribute::RuntimeInvisibleParameterAnnotations(params) => { + RtAttr::RuntimeInvisibleParameterAnnotations { + name_index: pool.utf8("RuntimeInvisibleParameterAnnotations")?, + parameter_annotations: params + .iter() + .map(|param| { + Ok(ristretto_classfile::attributes::ParameterAnnotation { + annotations: param + .iter() + .map(|anno| annotation(anno, pool)) + .collect::>()?, + }) + }) + .collect::>()?, + } + } Attribute::Raw { name, data } => RtAttr::Unknown { name_index: pool.utf8(name)?, info: data.clone(), diff --git a/crates/noxis-classfile/src/model/mod.rs b/crates/noxis-classfile/src/model/mod.rs index 4f5548b..ecedd92 100644 --- a/crates/noxis-classfile/src/model/mod.rs +++ b/crates/noxis-classfile/src/model/mod.rs @@ -48,6 +48,12 @@ pub enum Attribute { RuntimeVisibleAnnotations(Vec), /// `RuntimeInvisibleAnnotations` (JVMS §4.7.17): CLASS-retention ones. RuntimeInvisibleAnnotations(Vec), + /// `RuntimeVisibleParameterAnnotations` (JVMS §4.7.18): per-parameter + /// annotations. Parsed like the class-level ones - raw pool indices go + /// stale when the pool is rebuilt. + RuntimeVisibleParameterAnnotations(Vec>), + /// `RuntimeInvisibleParameterAnnotations` (JVMS §4.7.19). + RuntimeInvisibleParameterAnnotations(Vec>), /// Everything else: name + raw `info` bytes (careful with pool indices). Raw { name: String, diff --git a/crates/noxis-passes/src/rename/rewrite/annotations.rs b/crates/noxis-passes/src/rename/rewrite/annotations.rs index d5bcefc..4ee45df 100644 --- a/crates/noxis-passes/src/rename/rewrite/annotations.rs +++ b/crates/noxis-passes/src/rename/rewrite/annotations.rs @@ -12,6 +12,13 @@ pub(super) fn rewrite_annotations(annotations: &mut [Annotation], maps: &RenameM } } +/// Per-parameter annotation lists (`RuntimeVisibleParameterAnnotations`). +pub(super) fn rewrite_parameter_annotations(params: &mut [Vec], maps: &RenameMaps) { + for param in params.iter_mut() { + rewrite_annotations(param, maps); + } +} + fn rewrite_annotation(anno: &mut Annotation, maps: &RenameMaps) { anno.descriptor = rewrite_descriptor(&anno.descriptor, &maps.classes); for (_, value) in anno.elements.iter_mut() { diff --git a/crates/noxis-passes/src/rename/rewrite/mod.rs b/crates/noxis-passes/src/rename/rewrite/mod.rs index 933ca76..d6a95ee 100644 --- a/crates/noxis-passes/src/rename/rewrite/mod.rs +++ b/crates/noxis-passes/src/rename/rewrite/mod.rs @@ -3,7 +3,7 @@ mod annotations; mod code; -use annotations::rewrite_annotations; +use annotations::{rewrite_annotations, rewrite_parameter_annotations}; use noxis_classfile::{Attribute, ClassFile, Const, StackMapFrame, VerificationType}; use noxis_core::{Config, Context}; @@ -147,6 +147,10 @@ fn rewrite_attributes( | Attribute::RuntimeInvisibleAnnotations(annos) => { rewrite_annotations(annos, maps); } + Attribute::RuntimeVisibleParameterAnnotations(params) + | Attribute::RuntimeInvisibleParameterAnnotations(params) => { + rewrite_parameter_annotations(params, maps); + } Attribute::BootstrapMethods(methods) => { for bsm in methods.iter_mut() { rewrite_method_ref(&mut bsm.owner, &mut bsm.name, &mut bsm.descriptor, maps);