forked from quarkusio/gizmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstanceMethodCreatorImpl.java
41 lines (33 loc) · 1.38 KB
/
InstanceMethodCreatorImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package io.quarkus.gizmo2.impl;
import java.util.List;
import java.util.function.Consumer;
import io.github.dmlloyd.classfile.CodeBuilder;
import io.github.dmlloyd.classfile.extras.reflect.AccessFlag;
import io.quarkus.gizmo2.Expr;
import io.quarkus.gizmo2.creator.BlockCreator;
import io.quarkus.gizmo2.creator.InstanceMethodCreator;
public final class InstanceMethodCreatorImpl extends MethodCreatorImpl implements InstanceMethodCreator {
InstanceMethodCreatorImpl(final TypeCreatorImpl owner, final String name) {
super(owner, name, 0);
}
void doCode(final Consumer<BlockCreator> builder, final CodeBuilder cb, final List<ParamVarImpl> params) {
cb.localVariable(0, "this", owner.type(), cb.startLabel(), cb.endLabel());
super.doCode(builder, cb, params);
}
public void body(final Consumer<BlockCreator> builder) {
super.body(bc -> builder.accept(bc));
}
@Override
public Expr this_() {
return new ThisExpr(owner());
}
public void withFlag(final AccessFlag flag) {
switch (flag) {
case PUBLIC, PRIVATE, PROTECTED, SYNCHRONIZED, SYNTHETIC, BRIDGE, FINAL, VARARGS -> flags |= flag.mask();
default -> throw new IllegalArgumentException(flag.toString());
}
}
void accept(final Consumer<? super InstanceMethodCreatorImpl> builder) {
builder.accept(this);
}
}