Skip to content

Commit

Permalink
Use ASM9 Opcodes, add missing non-void overrides
Browse files Browse the repository at this point in the history
This fixes support for Records; would previously throw `java.lang.UnsupportedOperationException: Records requires ASM8`
  • Loading branch information
jpenilla committed May 13, 2021
1 parent d5ef1e6 commit 1671623
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@

import java.util.HashSet;
import java.util.Set;
import java.io.File;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.ModuleVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.RecordComponentVisitor;
import org.objectweb.asm.TypePath;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper;

/**
* interal - do not use
* internal - do not use
*/

public final class DependenciesClassAdapter extends ClassRemapper {

private static final int OPCODES = Opcodes.ASM9;

private static final EmptyVisitor ev = new EmptyVisitor();

public DependenciesClassAdapter() {
Expand All @@ -57,7 +60,7 @@ public String map(String pClassName) {

static class EmptyVisitor extends ClassVisitor {

private static final AnnotationVisitor av = new AnnotationVisitor(Opcodes.ASM7) {
private static final AnnotationVisitor av = new AnnotationVisitor(OPCODES) {
@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
return this;
Expand All @@ -69,7 +72,7 @@ public AnnotationVisitor visitArray(String name) {
}
};

private static final MethodVisitor mv = new MethodVisitor( Opcodes.ASM6) {
private static final MethodVisitor mv = new MethodVisitor(OPCODES) {
@Override
public AnnotationVisitor visitAnnotationDefault() {
return av;
Expand Down Expand Up @@ -112,7 +115,7 @@ public AnnotationVisitor visitTypeAnnotation( int typeRef, TypePath typePath, St
}
};

private static final FieldVisitor fieldVisitor = new FieldVisitor( Opcodes.ASM7 ) {
private static final FieldVisitor fieldVisitor = new FieldVisitor(OPCODES) {
@Override
public AnnotationVisitor visitAnnotation( String desc, boolean visible ) {
return av;
Expand All @@ -124,8 +127,23 @@ public AnnotationVisitor visitTypeAnnotation( int typeRef, TypePath typePath, St
}
};

private static final ModuleVisitor moduleVisitor = new ModuleVisitor(OPCODES) {
};

private static final RecordComponentVisitor recordComponentVisitor = new RecordComponentVisitor(OPCODES) {
@Override
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
return av;
}

@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
return av;
}
};

public EmptyVisitor() {
super(Opcodes.ASM7);
super(OPCODES);
}

@Override
Expand All @@ -148,5 +166,15 @@ public AnnotationVisitor visitTypeAnnotation( int typeRef, TypePath typePath, St
boolean visible ) {
return av;
}

@Override
public ModuleVisitor visitModule(String name, int access, String version) {
return moduleVisitor;
}

@Override
public RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature) {
return recordComponentVisitor;
}
}
}

0 comments on commit 1671623

Please sign in to comment.