Skip to content

Commit

Permalink
misc: Remove AnnotationHolder use
Browse files Browse the repository at this point in the history
Annotation printing is handled without indexed lookups of "visible + invisible" anymore
  • Loading branch information
Col-E committed Oct 12, 2024
1 parent 7d48b18 commit 663bcb4
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ public void print(PrintContext<?> ctx) {
obj.end();
}

@Override
public AnnotationPrinter annotation(int index) {
return memberPrinter.printAnnotation(index);
}

@Override
public MethodPrinter method(String name, String descriptor) {
// find method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,4 @@ public void print(PrintContext<?> ctx) {
ctx.print("}");
}
}

@Override
public AnnotationPrinter annotation(int index) {
return memberPrinter.printAnnotation(index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,4 @@ public void print(PrintContext<?> ctx) {

obj.end();
}

@Override
public AnnotationPrinter annotation(int index) {
return memberPrinter.printAnnotation(index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import dev.xdark.blw.classfile.Signed;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public record MemberPrinter(
@Nullable Annotated annotated, @Nullable Signed signed, @Nullable Accessible accessible, Type type
) {
Expand Down Expand Up @@ -55,27 +53,6 @@ public PrintContext<?> printDeclaration(PrintContext<?> ctx) {
return ctx;
}

/**
* @param index Index into <i>all</i> annotations, where indices are based on the combined list of annotations.
* @return Printer for the annotation. {@code null} if the index does not point to a known annotation.
*/
public @Nullable AnnotationPrinter printAnnotation(int index) {
if (annotated != null) {
// First check visible annotations.
List<Annotation> visibleAnnos = annotated.visibleRuntimeAnnotations();
int runtimeAnnotationCount = visibleAnnos.size();
if (index < runtimeAnnotationCount)
return new JvmAnnotationPrinter(visibleAnnos.get(index), true);

// Next check invisible annotations, offsetting the index by the number of visible annotations.
List<Annotation> invisibleAnnos = annotated.invisibleRuntimeAnnotations();
int targetInvisibleIndex = index - runtimeAnnotationCount;
if (targetInvisibleIndex < invisibleAnnos.size())
return new JvmAnnotationPrinter(invisibleAnnos.get(targetInvisibleIndex), false);
}
return null;
}

enum Type {
CLASS,
FIELD,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.jetbrains.annotations.Nullable;

public interface ClassPrinter extends AnnotationHolder, Printer {
public interface ClassPrinter extends Printer {

@Nullable
MethodPrinter method(String name, String descriptor);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package me.darknet.assembler.printer;

public interface FieldPrinter extends AnnotationHolder, Printer {
public interface FieldPrinter extends Printer {

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package me.darknet.assembler.printer;

public interface MethodPrinter extends AnnotationHolder, Printer {
public interface MethodPrinter extends Printer {

}

0 comments on commit 663bcb4

Please sign in to comment.