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

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


        }
      }

      Attributes attr = method.getAttributes();
      CodeAttribute codeAttr = attr.getCode();
      MethodDefRow mdr = new MethodDefRow(cf, method, true,
          codeAttr != null);
      if (!deprecatedAnnotationAdded && method.isDeprecated()) {
        DeprecatedAnnotationDefRow ddr = new DeprecatedAnnotationDefRow();
        this.rows.add(ddr);
      }
      this.rows.add(mdr);
      this.classDef.addMethod(mdr);
      LineNumberTableAttribute lnAttr = null;
      LocalVariableTableAttribute lvs = null;
      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);
            mdr.addCodeRow(lr);
          } else {
            int lineNumber = -1;

            if (lnAttr != null) {
              lineNumber = lnAttr.getLineNumber(dc.getPosition());
            }
            if (lvs != null) {
              List locals = lvs
                  .getLocalVariable(dc.getPosition());
              for (int k = 0; k < locals.size(); k++) {
                LocalVariable lv = (LocalVariable) locals
                    .get(k);
                LocalVariableDefRow lvdr = new LocalVariableDefRow(
                    lv, mdr);
                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);

            dc.incrementPosition(instruction);
          }

        }

        this.rows.add(new MethodDefRow(cf, method, false, true));
      }
      this.rows.add(new BlankRow());
    }

    this.rows.add(new ClassDefRow(cf, false));
View Full Code Here


      }
      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;
              }
            }
          }
          throw new AssertionError(
              "Position of method in link not found: "
                  + link.dump());
        }
      }
      throw new AssertionError("Method in link not found: " + link.dump());
    }
    case Link.ANCHOR_METHOD_DEF: {
      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())) {
          int index = this.rows.indexOf(mdr);
          this.list.setSelectedIndex(index);
          this.list.ensureIndexIsVisible(index);
          break switchLabel;
        }
      }
      throw new AssertionError("Method in link not found: " + link.dump());

    }
    case Link.ANCHOR_METHOD_LV: {
      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())) {
          java.util.List lvRows = mdr.getLocalVariables();
          for (int j = 0; j < lvRows.size(); j++) {
            LocalVariableDefRow lvdr = (LocalVariableDefRow) lvRows
                .get(j);
            if (lvdr.getLocalVariable().getSignatureLine().equals(
                link.getLv().getSignatureLine())) {
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();
          dc.setPosition(pc);
          pc += cr.getInstruction().getSize(dc);
View Full Code Here

    if (o instanceof CodeRow) {
      CodeRow cr = (CodeRow) o;
      modifyInstruction(cr.getPosition(), cr.getInstruction(), cr.getDecompilationContext().getLocalVariableTable());
      this.list.repaint();
    } else if (o instanceof MethodDefRow) {
      MethodDefRow mdr = (MethodDefRow) o;
      Method method = mdr.getMethod();
      CodeAttribute code = method.getAttributes().getCode();
      int flags = method.getAccessFlags();
      if (!AccessFlags.isNative(flags) && !AccessFlags.isAbstract(flags)) {
        this.methodEditor.invoke(method.getName(), method
            .getDescriptor(), method.getAccessFlags(), Integer.valueOf(
            code.getMaxStackSize()), Integer.valueOf(code
            .getMaxLocals()), method.getExceptions());
      } else {
        this.methodEditor.invoke(method.getName(), method
            .getDescriptor(), method.getAccessFlags(), null, null,
            method.getExceptions());
      }

      if (!this.methodEditor.wasCancelled()) {
        AccessFlags af = this.methodEditor.getAccessFlags();
        String name = this.methodEditor.getMethodName();
        Descriptor desc = this.methodEditor.getDescriptor();
        int maxStack = this.methodEditor.getMaxStack();
        int maxLocals = this.methodEditor.getMaxLocals();

        EditorFacade.getInstance().modifyMethod(
            mdr.getClassFile().getPool(), mdr.getMethod(), name,
            desc, af, maxStack, maxLocals,
            methodEditor.getExceptions());
      }

    } else if (o instanceof FieldDefRow) {
View Full Code Here

    List<EditorRow> code = new ArrayList<EditorRow>();
    int rows[] = this.list.getSelectedIndices();
    for (int row : rows) {
      Object obj = this.model.elementAt(row);
      if (obj instanceof MethodDefRow) {
        MethodDefRow mdr = (MethodDefRow) obj;
        if (!mdr.isClosing()) {
          Method method = mdr.getMethod();
          List<String> exceptionNames = new ArrayList<String>();
          for (ExceptionDescriptor ex : method
              .getExceptions()) {
            exceptionNames.add(ex.getName());
          }
          // TODO: Attributes are not being copied

          TransferrableMethod transferrable = new TransferrableMethod();
          transferrable.setMethodName(method.getName());
          transferrable.setDescriptor(method.getDescriptor());
          transferrable.setAccessFlags(method.getAccessFlags());
          CodeAttribute ca = method.getAttributes().getCode();
          if (ca != null) {
            transferrable.setMaxStack(ca.getMaxStackSize());
            transferrable.setMaxLocals(ca.getMaxLocals());
            List<Instruction> list = new ArrayList<Instruction>();
            for (EditorRow er : mdr.getCodeRows()) {
              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 : mdr.getCodeRows()) {
              if (er instanceof LabelRow)
                continue;
              CodeRow cr = (CodeRow) er;

              Instruction inst = cr.getInstruction();
View Full Code Here

        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
          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

 
  public void setExecutionRow(String methodName, Descriptor desc, Integer pc) {
    clearExecutionRow();
    List methods = this.classDef.getMethods();
    for (int i = 0; i < methods.size(); i++) {
      MethodDefRow mdr = (MethodDefRow) methods.get(i);
      if (mdr.getMethod().getName().equals(methodName)
       && mdr.getMethod().getDescriptor().equals(desc)) {
        if (pc == null) {
          // Method row
          this.executionRow = mdr;
          mdr.setExecutionRow(true);
          int index = this.rows.indexOf(mdr);
          this.list.ensureIndexIsVisible(index);
          repaint();         
          return;
        }
       
        // 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;
View Full Code Here

      if (er instanceof FieldDefRow) {
        FieldDefRow fdr = (FieldDefRow) er;
        Range offset = this.offsets.get(fdr.getField());
        this.hexEditor.getHexEditor().getSelectionModel().setSelectedInverval(offset.getOffset(), offset.getOffset() + offset.getSize());
      } 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();
View Full Code Here

          list.add(er);
        }
      } else if (er instanceof FieldDefRow) {
        list.add(er);
      } else if (er instanceof MethodDefRow) {
        MethodDefRow mdr = (MethodDefRow) er;
        if (!mdr.isClosing()) {
          list.add(er);
        }
      }
    }
   
View Full Code Here

    if (!deprecatedAnnotationAdded && method.isDeprecated()) {
      DeprecatedAnnotationDefRow ddr = new DeprecatedAnnotationDefRow();
      list.add(ddr);
    }

    MethodDefRow mdr = new MethodDefRow(cf, method, true, method.getAttributes().getCode() != null);
    list.add(mdr);

    Attributes attr = method.getAttributes();
    CodeAttribute codeAttr = attr.getCode();

    LineNumberTableAttribute lnAttr = null;
    LocalVariableTableAttribute lvs = null;
    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) {
          LabelRow lr = new LabelRow((Label) instruction, mdr);
          lr.setParentCode(code);
          list.add(lr);
          mdr.addCodeRow(lr);
        } else {
          int lineNumber = -1;

          if (lnAttr != null) {
            lineNumber = lnAttr.getLineNumber(dc.getPosition());
          }
          if (lvs != null) {
            List locals = lvs
                .getLocalVariable(dc.getPosition());
            for (int k = 0; k < locals.size(); k++) {
              LocalVariable lv = (LocalVariable) locals
                  .get(k);
              LocalVariableDefRow lvdr = new LocalVariableDefRow(
                  lv, mdr);
              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);

          dc.incrementPosition(instruction);
        }

      }

      list.add(new MethodDefRow(cf, method, false, true));
    }

    return list;
  }
View Full Code Here

TOP

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

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.