Package net.sf.rej.gui.editor.row

Examples of net.sf.rej.gui.editor.row.CodeRow


            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();
View Full Code Here


      }

      Object row = this.list.getSelectedValue();
      if (row instanceof CodeRow) {
        // before selected instruction
        CodeRow cr = (CodeRow) row;
        int pos = cr.getPosition();
        InsertCodeAction ica = new InsertCodeAction(this.classDef
            .getClassFile(), cr.getParentCode(), pos, (Code) data);
        SystemFacade.getInstance().performAction(ica);
      } else if (row instanceof MethodDefRow) {
        MethodDefRow mdr = (MethodDefRow) row;
        if (mdr.isClosing()) {
          // at the end of the code block
View Full Code Here

        }
       
        // Code row
        for (EditorRow er : mdr.getCodeRows()) {
          if (er instanceof CodeRow) {
            CodeRow cr = (CodeRow) er;
            if (cr.getPosition() == pc.intValue()) {
              final int index = this.rows.indexOf(cr);
              this.executionRow = cr;
              cr.setExecutionRow(true);
              // Workaround for a problem where ensureIndexIsVisible
              // is not working for some reason even though this
              // method is always called from the event thread
              SwingUtilities.invokeLater(new Runnable() {
                public void run() {
View Full Code Here

              list.add(lvdr);
              mdr.addLocalVariable(lvdr);
            }
          }

          CodeRow cd = new CodeRow(cf, mdr, instruction);
          cd.setPosition(dc.getPosition());
          cd.setDecompilationContext(dc);
          cd.setParentCode(code);

          if (lineNumber != -1) {
            cd.setLineNumber(lineNumber);
          }

          list.add(cd);
          mdr.addCodeRow(cd);
View Full Code Here

            list.add(lvdr);
            mdr.addLocalVariable(lvdr);
          }
        }

        CodeRow cd = new CodeRow(cf, mdr, instruction);
        cd.setPosition(dc.getPosition());
        cd.setDecompilationContext(dc);
        cd.setParentCode(code);

        if (lineNumber != -1) {
          cd.setLineNumber(lineNumber);
        }

        list.add(cd);
        mdr.addCodeRow(cd);
View Full Code Here

    } else if (erA instanceof LabelRow) {
      LabelRow lrA = (LabelRow) erA;
      LabelRow lrB = (LabelRow) erB;
      return lrA.getLabel().getId().equals(lrB.getLabel().getId());
    } else if (erA instanceof CodeRow) {
      CodeRow crA = (CodeRow) erA;
      CodeRow crB = (CodeRow) erB;
      Instruction instA = crA.getInstruction();
      Instruction instB = crB.getInstruction();
      boolean opCodesEqual = (instA.getOpcode() == instB.getOpcode());
      if (!opCodesEqual) return false;
           
      return instA.getParameters().getString(crA.getDecompilationContext()).equals(instB.getParameters().getString(crB.getDecompilationContext()));
    } else {
      throw new AssertionError("Invalid object type: " + erA.getClass());
    }
  }
View Full Code Here

      } else if (er instanceof MethodDefRow) {
        MethodDefRow mdr = (MethodDefRow) er;
        Range offset = this.offsets.get(mdr.getMethod());
        this.hexEditor.getHexEditor().getSelectionModel().setSelectedInverval(offset.getOffset(), offset.getOffset() + offset.getSize());         
      } else if (er instanceof CodeRow) {
        CodeRow cr = (CodeRow) er;
        Method m = cr.getEnclosingMethodDef().getMethod();
        CodeAttribute ca = m.getAttributes().getCode();
        // "cache" method offset maps
        Map<Object, Range> methodOffsetMap = this.methodOffsets.get(m);
        if (methodOffsetMap == null) {
          methodOffsetMap = m.getOffsetMap();
          this.methodOffsets.put(m, methodOffsetMap);
        }
        Range range = methodOffsetMap.get(ca);
        int offset = this.offsets.get(m).getOffset() +  range.getOffset() + 14 + cr.getPosition();
        DecompilationContext dc = ca.getCode().createDecompilationContext();
        dc.setPosition(cr.getPosition());
        int size = cr.getInstruction().getSize(dc);
       
        this.hexEditor.getHexEditor().getSelectionModel().setSelectedInverval(offset, offset + size);         
      } else {
        this.hexEditor.getHexEditor().getSelectionModel().clearSelection();
      }
View Full Code Here

                this.rows.add(lvdr);
                mdr.addLocalVariable(lvdr);
              }
            }

            CodeRow cd = new CodeRow(cf, mdr, instruction);
            cd.setPosition(dc.getPosition());
            cd.setDecompilationContext(dc);
            cd.setParentCode(code);
            cd.setBreakpoint(EditorFacade.getInstance()
                .getBreakpoint(cf.getFullClassName(),
                    method.getName(),
                    method.getDescriptor(),
                    dc.getPosition()));

            if (lineNumber != -1) {
              cd.setLineNumber(lineNumber);
            }

            this.rows.add(cd);
            mdr.addCodeRow(cd);
View Full Code Here

    switch (link.getAnchor()) {
    case Link.ANCHOR_SOURCE_LINE_NUMBER: {
      for (int i = 0; i < this.rows.size(); i++) {
        Object obj = this.rows.get(i);
        if (obj instanceof CodeRow) {
          CodeRow cr = (CodeRow) obj;
          if (cr.getLineNumber() == link.getPosition()) {
            int index = this.rows.indexOf(cr);
            this.list.setSelectedIndex(index);
            this.list.ensureIndexIsVisible(index);
            break;
          }
        }
      }
      break;
    }
    case Link.ANCHOR_PC_OFFSET: {
      Object row = this.list.getSelectedValue();
      MethodDefRow mdr = null;
      if (row instanceof CodeRow) {
        CodeRow cr = (CodeRow) row;
        mdr = cr.getEnclosingMethodDef();
      } else if (row instanceof LabelRow) {
        LabelRow lr = (LabelRow) row;
        mdr = lr.getEnclosingMethodDef();
      } else if (row instanceof LocalVariableDefRow) {
        LocalVariableDefRow lvdr = (LocalVariableDefRow) row;
        mdr = lvdr.getEnclosingMethodDef();
      } else if (row instanceof MethodDefRow) {
        mdr = (MethodDefRow) row;
      }

      if (mdr != null) {
        List codeRows = mdr.getCodeRows();
        for (int i = 0; i < codeRows.size(); i++) {
          if (codeRows.get(i) instanceof LabelRow)
            continue;

          CodeRow cr = (CodeRow) codeRows.get(i);
          if (cr.getPosition() >= link.getPosition()) {
            int index = this.rows.indexOf(cr);
            this.list.setSelectedIndex(index);
            this.list.ensureIndexIsVisible(index);
            break;
          }
        }
      }
      break;
    }
    case Link.ANCHOR_CLASS_DEF: {
      int index = this.rows.indexOf(this.classDef);
      this.list.setSelectedIndex(index);
      break;
    }
    case Link.ANCHOR_FIELD_DEF: {
      List fields = this.classDef.getFields();
      for (int i = 0; i < fields.size(); i++) {
        FieldDefRow fdr = (FieldDefRow) fields.get(i);
        if (fdr.getField().getSignatureLine().equals(
            link.getField().getSignatureLine())) {
          int index = this.rows.indexOf(fdr);
          this.list.setSelectedIndex(index);
          this.list.ensureIndexIsVisible(index);
          break switchLabel;
        }
      }
      throw new AssertionError("Field in link not found: " + link.dump());
    }
    case Link.ANCHOR_METHOD_CODE: {
      List methods = this.classDef.getMethods();
      for (int i = 0; i < methods.size(); i++) {
        MethodDefRow mdr = (MethodDefRow) methods.get(i);
        if (mdr.getMethod().getSignatureLine().equals(
            link.getMethod().getSignatureLine())) {
          for (EditorRow er : mdr.getCodeRows()) {
            if (er instanceof CodeRow) {
              CodeRow cr = (CodeRow) er;
              if (cr.getPosition() == link.getPosition()) {
                int index = this.rows.indexOf(cr);
                this.list.setSelectedIndex(index);
                this.list.ensureIndexIsVisible(index);
                break switchLabel;
              }
View Full Code Here

      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();
          dc.setPosition(pc);
          pc += cr.getInstruction().getSize(dc);
        }
      }
     
      insertInstruction(mdr, pc, lvAttr, code);
    }
View Full Code Here

TOP

Related Classes of net.sf.rej.gui.editor.row.CodeRow

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.