Skip to content

Commit

Permalink
Make ChainedClassBuilder and ChainedMethodBuilder compliant with docu…
Browse files Browse the repository at this point in the history
…mentation of ClassFileTransform.andThen
  • Loading branch information
mpfaff committed Apr 19, 2024
1 parent 21b77a9 commit 972d023
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@

public final class ChainedClassBuilder
implements ClassBuilder, Consumer<ClassElement> {
private final ClassBuilder downstream;
private final DirectClassBuilder terminal;
private final Consumer<ClassElement> consumer;

public ChainedClassBuilder(ClassBuilder downstream,
Consumer<ClassElement> consumer) {
this.downstream = downstream;
this.consumer = consumer;
this.terminal = switch (downstream) {
case ChainedClassBuilder cb -> cb.terminal;
Expand All @@ -60,7 +58,7 @@ public Optional<ClassModel> original() {

@Override
public ClassBuilder withField(Utf8Entry name, Utf8Entry descriptor, Consumer<? super FieldBuilder> handler) {
return downstream.with(new BufferedFieldBuilder(terminal.constantPool, terminal.context,
return consumer.accept(new BufferedFieldBuilder(terminal.constantPool, terminal.context,
name, descriptor, null)
.run(handler)
.toModel());
Expand All @@ -72,13 +70,13 @@ public ClassBuilder transformField(FieldModel field, FieldTransform transform) {
field.fieldName(), field.fieldType(),
field);
builder.transform(field, transform);
return downstream.with(builder.toModel());
return consumer.accept(builder.toModel());
}

@Override
public ClassBuilder withMethod(Utf8Entry name, Utf8Entry descriptor, int flags,
Consumer<? super MethodBuilder> handler) {
return downstream.with(new BufferedMethodBuilder(terminal.constantPool, terminal.context,
return consumer.accept(new BufferedMethodBuilder(terminal.constantPool, terminal.context,
name, descriptor, null)
.run(handler)
.toModel());
Expand All @@ -89,7 +87,7 @@ public ClassBuilder transformMethod(MethodModel method, MethodTransform transfor
BufferedMethodBuilder builder = new BufferedMethodBuilder(terminal.constantPool, terminal.context,
method.methodName(), method.methodType(), method);
builder.transform(method, transform);
return downstream.with(builder.toModel());
return consumer.accept(builder.toModel());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
import java.lang.classfile.constantpool.ConstantPoolBuilder;

public final class ChainedMethodBuilder implements MethodBuilder {
final MethodBuilder downstream;
final TerminalMethodBuilder terminal;
final Consumer<MethodElement> consumer;

public ChainedMethodBuilder(MethodBuilder downstream,
Consumer<MethodElement> consumer) {
this.downstream = downstream;
this.consumer = consumer;
this.terminal = switch (downstream) {
case ChainedMethodBuilder cb -> cb.terminal;
Expand All @@ -58,7 +56,7 @@ public MethodBuilder with(MethodElement element) {

@Override
public MethodBuilder withCode(Consumer<? super CodeBuilder> handler) {
return downstream.with(terminal.bufferedCodeBuilder(null)
return consumer.accept(terminal.bufferedCodeBuilder(null)
.run(handler)
.toModel());
}
Expand All @@ -67,7 +65,7 @@ public MethodBuilder withCode(Consumer<? super CodeBuilder> handler) {
public MethodBuilder transformCode(CodeModel code, CodeTransform transform) {
BufferedCodeBuilder builder = terminal.bufferedCodeBuilder(code);
builder.transform(code, transform);
return downstream.with(builder.toModel());
return consumer.accept(builder.toModel());
}

@Override
Expand Down

0 comments on commit 972d023

Please sign in to comment.