Skip to content

Commit

Permalink
Fix class assembling scrambling order of members
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Oct 22, 2023
1 parent 23db2a0 commit b1b9464
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,33 @@

public class BlwReplaceClassBuilder implements ClassBuilder {

private final Map<Integer, BuilderShadow<Annotation>> visibleRuntimeAnnotations = new HashMap<>();
private final Map<Integer, BuilderShadow<Annotation>> invisibleRuntimeAnnotations = new HashMap<>();
public final Map<String, BlwReplaceMethodBuilder> methods = new HashMap<>();
public final Map<String, BlwReplaceFieldBuilder> fields = new HashMap<>();
private final Map<Integer, BuilderShadow<Annotation>> visibleRuntimeAnnotations = new LinkedHashMap<>();
private final Map<Integer, BuilderShadow<Annotation>> invisibleRuntimeAnnotations = new LinkedHashMap<>();
private final Map<String, BlwReplaceMethodBuilder> methods = new LinkedHashMap<>();
private final Map<String, BlwReplaceFieldBuilder> fields = new LinkedHashMap<>();
private List<InnerClass> innerClasses = List.of();
private InstanceType nestHost;
private String sourceFile, sourceDebug;
private int accessFlags;
private String signature;
private ConstantPool pool;
public InstanceType type;
private InstanceType type;
private InstanceType superClass;
private List<InstanceType> interfaces = List.of();
private JavaVersion version;

public InstanceType getType() {
return type;
}

public Map<String, BlwReplaceFieldBuilder> getFields() {
return fields;
}

public Map<String, BlwReplaceMethodBuilder> getMethods() {
return methods;
}

@Override
public ClassBuilder accessFlags(int accessFlags) {
this.accessFlags = accessFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public abstract class BlwReplaceMemberBuilder implements MemberBuilder {
private final Map<String, Reflectable<Annotation>> visibleRuntimeAnnotations = new HashMap<>();
private final Map<String, Reflectable<Annotation>> invisibleRuntimeAnnotations = new HashMap<>();
private final Map<String, Reflectable<Annotation>> visibleRuntimeAnnotations = new LinkedHashMap<>();
private final Map<String, Reflectable<Annotation>> invisibleRuntimeAnnotations = new LinkedHashMap<>();
protected String signature;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ASTMethodVisitor visitMethod(Modifiers modifiers, ASTIdentifier name, AST
.map(it -> BlwModifiers.modifier(it.content(), BlwModifiers.METHOD)).reduce(0, (a, b) -> a | b);
MethodType type = Types.methodType(descriptor.literal());
return new BlwMethodVisitor(
options.inheritanceChecker(), builder.type, type,
options.inheritanceChecker(), builder.getType(), type,
(accessFlags & AccessFlag.ACC_STATIC) == AccessFlag.ACC_STATIC,
builder.method(accessFlags, name.literal(), type)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public ASTAnnotationVisitor visitAnnotation(ASTIdentifier name) {
var path = options.annotationPath().split("\\.");
int index = Integer.parseInt(path[path.length - 1]);

InstanceType type = builder.type;
InstanceType type = builder.getType();

AnnotationBuilder.Nested<?> nested = switch (path.length) {
case 2 -> builder.visibleRuntimeAnnotation(type, index);
case 5 -> {
String member = path[3];
String descriptor = path[4];
yield switch (path[2]) {
case "field" -> builder.fields.get(member + descriptor).visibleRuntimeAnnotation(type, index);
case "method" -> builder.methods.get(member + descriptor).visibleRuntimeAnnotation(type, index);
case "field" -> builder.getFields().get(member + descriptor).visibleRuntimeAnnotation(type, index);
case "method" -> builder.getMethods().get(member + descriptor).visibleRuntimeAnnotation(type, index);
default -> throw new IllegalStateException("Unexpected value: " + path[2]);
};
}
Expand Down

0 comments on commit b1b9464

Please sign in to comment.