org.jobrunr.jobs.details.instructions.ANewArrayOperandInstruction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jobrunr Show documentation
Show all versions of jobrunr Show documentation
An easy way to perform background processing on the JVM. Backed by persistent storage. Open and free for commercial use.
package org.jobrunr.jobs.details.instructions;
import org.jobrunr.jobs.details.JobDetailsFinderContext;
import java.lang.reflect.Array;
import static org.jobrunr.jobs.details.JobDetailsGeneratorUtils.toFQClassName;
import static org.jobrunr.utils.reflection.ReflectionUtils.toClass;
public class ANewArrayOperandInstruction extends VisitTypeInstruction {
public ANewArrayOperandInstruction(JobDetailsFinderContext jobDetailsBuilder) {
super(jobDetailsBuilder);
}
@Override
public Object invokeInstruction() {
Integer arraySize = (Integer) jobDetailsBuilder.getStack().pollLast();
final Object[] result = (Object[]) Array.newInstance(toClass(toFQClassName(type)), arraySize);
for (int i = 0; i < arraySize; i++) {
jobDetailsBuilder.pollFirstInstruction().invokeInstruction(); // not interested in this (DUP)
jobDetailsBuilder.pollFirstInstruction().invokeInstruction(); // not interested in this (ICONST_ index in array)
final Object arrayItem = jobDetailsBuilder.pollFirstInstruction().invokeInstruction();
result[i] = arrayItem;
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy