All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jobrunr.jobs.details.instructions.ANewArrayOperandInstruction Maven / Gradle / Ivy

Go to download

An easy way to perform background processing on the JVM. Backed by persistent storage. Open and free for commercial use.

There is a newer version: 7.4.0
Show newest version
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