Package net.sf.rej.java

Examples of net.sf.rej.java.Code


    public CodeAttribute(int nameIndex, ConstantPool cp, int maxStack, int maxLocals) {
        super(nameIndex, cp);
        this.maxStack = maxStack;
        this.maxLocals = maxLocals;
        this.code = new Code(cp);
        this.exceptions = new Exceptions();
        this.attributes = new Attributes();
    }
View Full Code Here


        this.maxLocals = parser.getShortAsInt();
        int codeLength = (int) parser.getInt();
        byte[] codeData = parser.getBytes(codeLength);
        ByteParser newParser = new ByteArrayByteParser(codeData);
        newParser.setBigEndian(true);
        this.code = new Code(newParser, pool);
        this.exceptions = new Exceptions(parser, pool);
        this.attributes = new Attributes(parser, pool);
        LineNumberTableAttribute lnAttr = this.attributes.getLineNumberTable();
        if (lnAttr != null) {
          lnAttr.setCode(this.code);
View Full Code Here

    if (codeAttr != null) {
      if (codeAttr.getAttributes() != null) {
        lnAttr = codeAttr.getAttributes().getLineNumberTable();
        lvs = codeAttr.getAttributes().getLocalVariableTable();
      }
      Code code = codeAttr.getCode();
      DecompilationContext dc = code.createDecompilationContext();
      List instructions = code.getInstructions();
      dc.setPosition(0);
      for (int j = 0; j < instructions.size(); j++) {
        Instruction instruction = (Instruction) instructions.get(j);

        if (instruction instanceof Label) {
View Full Code Here

      if (codeAttrB.getAttributes() != null) {
        lnAttrB = codeAttrB.getAttributes().getLineNumberTable();
        lvsB = codeAttrB.getAttributes().getLocalVariableTable();
      }

      Code codeA = codeAttrA.getCode();
      Code codeB = codeAttrB.getCode();
     
      DecompilationContext dcA = codeA.createDecompilationContext();
      DecompilationContext dcB = codeB.createDecompilationContext();
     
      List<Instruction> instructionsA = codeA.getInstructions();
      List<Instruction> instructionsB = codeB.getInstructions();
      dcA.setPosition(0);
      dcB.setPosition(0);
     
      List<EditorRow> methodRowsA = getMethodRows(instructionsA, codeA, mdrA, lnAttrA, lvsA, dcA, cfA);
      List<EditorRow> methodRowsB = getMethodRows(instructionsB, codeB, mdrB, lnAttrB, lvsB, dcB, cfB);
View Full Code Here

              agent.processLocalVariable(ic, lv);
            }
          }

          // method code
          Code code = null;
          if (ca != null)
            code = ca.getCode();
          if (code != null) {
            DecompilationContext dc = code
                .createDecompilationContext();
            ic.setDc(dc);
            dc.setPosition(0);
            List<Instruction> instructions = code.getInstructions();
            for (Instruction instruction : instructions) {
              agent.processInstruction(ic, instruction);
              dc.incrementPosition(instruction);
            }
          }
View Full Code Here

      if (codeAttr != null) {
        if (codeAttr.getAttributes() != null) {
          lnAttr = codeAttr.getAttributes().getLineNumberTable();
          lvs = codeAttr.getAttributes().getLocalVariableTable();
        }
        Code code = codeAttr.getCode();
        DecompilationContext dc = code.createDecompilationContext();
        dc.setPosition(0);
        for (Instruction instruction : code.getInstructions()) {

          if (instruction instanceof Label) {
            LabelRow lr = new LabelRow((Label) instruction, mdr);
            lr.setParentCode(code);
            this.rows.add(lr);
View Full Code Here

  public void insertInstruction() {
    Object row = this.list.getSelectedValue();
    if (row instanceof MethodDefRow) {
      MethodDefRow mdr = (MethodDefRow) row;
      Code code = null;
      LocalVariableTableAttribute lvAttr = null;
      if (mdr.getMethod().getAttributes().getCode() != null) {
        code = mdr.getMethod().getAttributes().getCode().getCode();
        lvAttr = mdr.getMethod().getAttributes().getCode().getAttributes().getLocalVariableTable();
      }
      int pc = 0;
      if (code != null && mdr.isClosing() && mdr.getCodeRows().size() > 0) {
        DecompilationContext dc = code.createDecompilationContext();
        EditorRow er = mdr.getCodeRows().get(
            mdr.getCodeRows().size() - 1);
        if (er instanceof CodeRow) {
          CodeRow cr = (CodeRow) er;
          pc = cr.getPosition();
View Full Code Here

                        + er.getClass());
              }
            }

            ConstantPool newPool = new ConstantPool();
            Code codeBlock = new Code(newPool);
            InstructionCopier instructionCopier = new InstructionCopier();
            for (EditorRow er : mdr.getCodeRows()) {
              if (er instanceof LabelRow)
                continue;
              CodeRow cr = (CodeRow) er;

              Instruction inst = cr.getInstruction();

              Instruction copy = instructionCopier
                  .copyInstruction(inst, cr
                      .getDecompilationContext()
                      .getConstantPool(), newPool);
             
              if (copy == null) {
                throw new AssertionError("Copied instruction is null for instruction: " + inst);
              }
              int index = list.indexOf(inst);
              list.set(index, copy);
              List<Label> labels = inst.getLabels();
              List<Label> copyLabels = copy.getLabels();
              for (int i = 0; i < labels.size(); i++) {
                if (copyLabels.get(i) == null) {
                  throw new AssertionError("Copied label is null for instruction: " + inst + " : " + copyLabels);
                }
                Label label = labels.get(i);
                int labelIndex = list.indexOf(label);
                if (labelIndex != -1) {
                  list.set(labelIndex, copyLabels.get(i));
                } else {
                  list.add(copyLabels.get(i));
                }
              }

            }
            codeBlock.add(0, list);
            transferrable.setCode(codeBlock);
          }
          transferrable.setExceptions(exceptionNames);
          transferables.add(transferrable);
        }

      } else if (obj instanceof FieldDefRow) {
        FieldDefRow fdr = (FieldDefRow) obj;
        Field field = fdr.getField();
        // TODO: Attributes are not being copied

        TransferrableField transferrable = new TransferrableField();
        transferrable.setFieldName(field.getName());
        transferrable.setDescriptor(field.getDescriptor());
        transferrable.setAccessFlags(field.getAccessFlags());
        transferables.add(transferrable);
      } else if (obj instanceof CodeRow || obj instanceof LabelRow) {
        code.add((EditorRow) obj);
      }
    }

    if (!transferables.isEmpty()) {
      return transferables;
    } else {
      List<Instruction> list = new ArrayList<Instruction>();
      for (EditorRow er : code) {
        if (er instanceof CodeRow) {
          list.add(((CodeRow) er).getInstruction());
        } else if (er instanceof LabelRow) {
          list.add(((LabelRow) er).getLabel());
        } else {
          throw new AssertionError(
              "Object of invalid class (not CodeRow and not LabelRow) in list: "
                  + er.getClass());
        }
      }

      ConstantPool newPool = new ConstantPool();
      Code codeBlock = new Code(newPool);
      InstructionCopier instructionCopier = new InstructionCopier();
      for (EditorRow er : code) {
        if (er instanceof LabelRow)
          continue;
        CodeRow cr = (CodeRow) er;
        Instruction inst = cr.getInstruction();

        Instruction copy = instructionCopier.copyInstruction(inst, cr
            .getDecompilationContext().getConstantPool(), newPool);
        int index = list.indexOf(inst);
        list.set(index, copy);
        List<Label> labels = inst.getLabels();
        List<Label> copyLabels = copy.getLabels();
        for (int i = 0; i < labels.size(); i++) {
          Label label = labels.get(i);
          int labelIndex = list.indexOf(label);
          if (labelIndex != -1) {
            list.set(labelIndex, copyLabels.get(i));
          } else {
            list.add(copyLabels.get(i));
          }
        }

      }
      codeBlock.add(0, list);

      return codeBlock;
    }
  }
View Full Code Here

        MethodDefRow mdr = (MethodDefRow) row;
        if (mdr.isClosing()) {
          // at the end of the code block
          CodeAttribute ca = mdr.getMethod().getAttributes()
              .getCode();
          Code code = ca.getCode();
          InsertCodeAction ica = new InsertCodeAction(this.classDef
              .getClassFile(), code, code.getMaxPC(), (Code) data);
          SystemFacade.getInstance().performAction(ica);
        } else {
          // at the beginning of the code block
          CodeAttribute ca = mdr.getMethod().getAttributes()
              .getCode();
          Code code = ca.getCode();
          InsertCodeAction ica = new InsertCodeAction(this.classDef
              .getClassFile(), code, 0, (Code) data);
          SystemFacade.getInstance().performAction(ica);
        }
      }
View Full Code Here

TOP

Related Classes of net.sf.rej.java.Code

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.