com.github.romanqed.jsm.bytecode.TableSwitchMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsm Show documentation
Show all versions of jsm Show documentation
A lightweight library that allows you to create fast finite state machine according to a given scheme.
The newest version!
package com.github.romanqed.jsm.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import java.util.Arrays;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
final class TableSwitchMap extends SwitchMap {
private final Function mapper;
private final int start;
private final int end;
TableSwitchMap(Function mapper, int start, int end) {
this.mapper = mapper;
this.start = start;
this.end = end;
}
@Override
void visitSwitch(MethodVisitor visitor, Consumer def, BiConsumer handler) {
var labels = new Label[body.size()];
Arrays.setAll(labels, e -> new Label());
var defaultLabel = new Label();
visitor.visitTableSwitchInsn(start, end, defaultLabel, labels);
for (var i = 0; i < labels.length; ++i) {
visitor.visitLabel(labels[i]);
var object = mapper.apply(start + i);
handler.accept(visitor, object);
}
visitor.visitLabel(defaultLabel);
def.accept(visitor);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy