Skip to content

Commit

Permalink
WIP3: annotation storing
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed Jun 4, 2024
1 parent 3becd75 commit eb79b21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
23 changes: 14 additions & 9 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package java.lang;

import java.io.ByteArrayInputStream;
import java.lang.annotation.Annotation;
import java.lang.classfile.Attributes;
import java.lang.classfile.ClassFile;
Expand Down Expand Up @@ -2425,15 +2426,19 @@ private Deconstructor<?>[] getDeclaredDeconstructors0(Class<?>[] params) {
List<String> parameterNameList = mp.parameters().stream().map(p -> p.name().get().stringValue()).toList();

// binding annotations
// RuntimeVisibleAnnotations_attribute {
// u2 attribute_name_index;
// u4 attribute_length;
// u2 num_annotations;
// annotation annotations[num_annotations];
//}
RuntimeVisibleParameterAnnotationsAttribute rvpa = pa.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElse(null);
ByteBuffer joined = null;
ByteBuffer assembled = null; // reference: ClassFileParser::assemble_annotations
if (rvpa != null) {
byte rvpaBytes[] = ((BoundAttribute) rvpa).contents();
int rvpa_length = ((BoundAttribute) rvpa).payloadLen();
joined = ByteBuffer.allocate(rvpaBytes.length + 4 + 4);
joined.putInt(1); // one attribute
joined.put(rvpaBytes);
joined.putInt(rvpa_length);
byte rvpaBytes[] = ((BoundAttribute) rvpa).contents(); // returns the full attribute
int rvpa_length = ((BoundAttribute) rvpa).payloadLen(); // already comes after the subtraction with 4
assembled = ByteBuffer.wrap(rvpaBytes, 4, rvpa_length + 4);
// todo
}

ArrayList<DeconstructorElement> deconstructorElements = new ArrayList<>();
Expand All @@ -2444,8 +2449,8 @@ private Deconstructor<?>[] getDeclaredDeconstructors0(Class<?>[] params) {
parameterNameList.get(i),
bindingClass,
signatures.get(i),
rvpa == null ? null : joined.array(), // TODO: annotations of deconstructor element
null // TODO: type annotations of deconstructor element
rvpa == null ? null : assembled.array(), // TODO: annotations of deconstructor element
null // TODO: type annotations of deconstructor element
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @test
* @summary SimpleDeconstructorsTest
* @enablePreview
* @compile --enable-preview --source ${jdk.version} -parameters SimpleDeconstructorsTest.java
* @run main/othervm --enable-preview SimpleDeconstructorsTest
*/

Expand Down

0 comments on commit eb79b21

Please sign in to comment.