Package net.sf.rej.gui.editor.transfer

Examples of net.sf.rej.gui.editor.transfer.TransferrableMethod


              .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();

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


              this.classDef.getClassFile(), field.getFieldName(),
              field.getDescriptor(), new AccessFlags(field
                  .getAccessFlags()));
          ga.add(insertFieldAction);
        } else if (transferrable instanceof TransferrableMethod) {
          TransferrableMethod method = (TransferrableMethod) transferrable;
          int maxStack = 0;
          int maxLocals = 0;
          if (method.getMaxStack() != null) {
            maxStack = method.getMaxStack();
          }
          if (method.getMaxLocals() != null) {
            maxLocals = method.getMaxLocals();
          }
          // TODO: Attributes are not being copied
          InsertMethodAction insertMethodAction = new InsertMethodAction(
              this.classDef.getClassFile(), method
                  .getMethodName(), method.getDescriptor(),
              new AccessFlags(method.getAccessFlags()), maxStack,
              maxLocals, method.getExceptions());
          ga.add(insertMethodAction);
          InsertCodeToNewMethodAction ictnma = new InsertCodeToNewMethodAction(
              this.classDef.getClassFile(), insertMethodAction,
              method.getCode());
          ga.add(ictnma);
        } else {
          throw new AssertionError(
              "Invalid object in List of pasted data.");
        }
View Full Code Here

TOP

Related Classes of net.sf.rej.gui.editor.transfer.TransferrableMethod

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.