Example usage for org.objectweb.asm.commons InstructionAdapter newarray

List of usage examples for org.objectweb.asm.commons InstructionAdapter newarray

Introduction

In this page you can find the example usage for org.objectweb.asm.commons InstructionAdapter newarray.

Prototype

public void newarray(final Type type) 

Source Link

Document

Generates the instruction to create and push on the stack an array of the given type.

Usage

From source file:com.github.jasmo.obfuscate.ScrambleStrings.java

License:Open Source License

private void createStaticConstructor(ClassNode owner) throws UnsupportedEncodingException {
    MethodNode original = BytecodeHelper.getMethod(owner, "<clinit>", "()V");
    MethodVisitor mv = owner.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
    // generate instructions
    InstructionAdapter builder = new InstructionAdapter(mv);
    builder.iconst(stringList.size());/*from ww  w . j a  v a  2  s.c  o m*/
    builder.newarray(Type.getType(String.class));
    for (int i = 0; i < stringList.size(); i++) {
        builder.dup();
        builder.iconst(i);
        builder.aconst(Base64.getEncoder().encodeToString(stringList.get(i).getBytes("UTF-8")));
        builder.astore(InstructionAdapter.OBJECT_TYPE);
    }
    builder.putstatic(unscrambleClass.name, FIELD_NAME, "[Ljava/lang/String;");
    // merge with original if it exists
    if (original != null) {
        // original should already end with RETURN
        owner.methods.remove(original);
        original.instructions.accept(builder);
    } else {
        builder.areturn(Type.VOID_TYPE);
    }
}

From source file:com.google.devtools.build.android.resources.IntArrayFieldInitializer.java

License:Open Source License

@Override
public int writeCLInit(InstructionAdapter insts, String className) {
    insts.iconst(values.size());/*from  w  ww .  j av  a 2s  . com*/
    insts.newarray(Type.INT_TYPE);
    int curIndex = 0;
    for (Integer value : values) {
        insts.dup();
        insts.iconst(curIndex);
        insts.iconst(value);
        insts.astore(Type.INT_TYPE);
        ++curIndex;
    }
    insts.putstatic(className, fieldName, DESC);
    // Needs up to 4 stack slots for: the array ref for the putstatic, the dup of the array ref
    // for the store, the index, and the value to store.
    return 4;
}