Пример #1
0
 private void castAndSetProperty(
     InvokeInstruction insn, String property, List<Instruction> instructions, Class<?> primitive) {
   Variable castVar = program.createVariable();
   InvokeInstruction castInvoke = new InvokeInstruction();
   castInvoke.setType(InvocationType.SPECIAL);
   String primitiveCapitalized = primitive.getName();
   primitiveCapitalized =
       Character.toUpperCase(primitiveCapitalized.charAt(0)) + primitiveCapitalized.substring(1);
   castInvoke.setMethod(
       new MethodReference(
           ResourceAccessor.class, "castFrom" + primitiveCapitalized, primitive, Object.class));
   castInvoke.getArguments().add(insn.getArguments().get(0));
   castInvoke.setReceiver(castVar);
   instructions.add(castInvoke);
   setProperty(insn, property, instructions, castVar);
 }
Пример #2
0
 private void setProperty(
     InvokeInstruction insn, String property, List<Instruction> instructions, Variable valueVar) {
   Variable nameVar = program.createVariable();
   StringConstantInstruction nameInsn = new StringConstantInstruction();
   nameInsn.setConstant(property);
   nameInsn.setReceiver(nameVar);
   instructions.add(nameInsn);
   InvokeInstruction accessorInvoke = new InvokeInstruction();
   accessorInvoke.setType(InvocationType.SPECIAL);
   accessorInvoke.setMethod(
       new MethodReference(
           ResourceAccessor.class, "put", Object.class, String.class, Object.class, void.class));
   accessorInvoke.getArguments().add(insn.getInstance());
   accessorInvoke.getArguments().add(nameVar);
   accessorInvoke.getArguments().add(valueVar);
   instructions.add(accessorInvoke);
 }
Пример #3
0
  private List<Instruction> transformKeys(InvokeInstruction insn) {
    Variable tmp = program.createVariable();

    InvokeInstruction keysInsn = new InvokeInstruction();
    keysInsn.setType(InvocationType.SPECIAL);
    keysInsn.setMethod(
        new MethodReference(ResourceAccessor.class, "keys", Object.class, Object.class));
    keysInsn.getArguments().add(insn.getInstance());
    keysInsn.setReceiver(tmp);

    InvokeInstruction transformInsn = new InvokeInstruction();
    transformInsn.setType(InvocationType.SPECIAL);
    transformInsn.setMethod(
        new MethodReference(ResourceAccessor.class, "keysToStrings", Object.class, String[].class));
    transformInsn.getArguments().add(tmp);
    transformInsn.setReceiver(insn.getReceiver());

    return Arrays.asList(keysInsn, transformInsn);
  }