Package net.sf.rej.java.constantpool

Examples of net.sf.rej.java.constantpool.ConstantPool


        cf.validateMagic(this.magic);

        cf.setMinorVersion(this.minorVersion);
        cf.setMajorVersion(this.majorVersion);

        ConstantPool pool = new ConstantPool();
        pool.init(1);
        cf.setPool(pool);

        cf.setAccessFlags(this.flags.getValue());
        cf.setThisClass(pool.optionalAddClassRef(fullClassName));
        if (superClass != null) {
          cf.setSuperClass(pool.optionalAddClassRef(superClass));
        } else {
          cf.setSuperClass(0); // 0 signals no super class
        }

        cf.setInterfaces(new ArrayList<Interface>());
View Full Code Here


    public Field createField(ByteParser parser, ConstantPool pool) {
        return new Field(parser, pool);
    }

    public Field createField(ClassFile cf, AccessFlags accessFlags, int nameIndex, int descIndex) {
        ConstantPool cp = cf.getPool();
        Field field = new Field(cp);
        field.setAccessFlags(accessFlags);
        field.setNameIndex(nameIndex);
        field.setDescriptorIndex(descIndex);
        return field;
View Full Code Here

        ProjectIterator.iterate(this.openProject, iterator);
  }

    public Imports getImports(ClassFile cf) {
    Imports imports = new Imports(cf.getPackageName());
    ConstantPool pool = cf.getPool();

    for (int i = 0; i < pool.size(); i++) {
      ConstantPoolInfo cpi = pool.get(i);
      if (cpi != null) {
        if (cpi.getType() == ConstantPoolInfo.CLASS) {
          // there can be array definitions here, too
          JavaType cls = new JavaType(cpi.getValue());
          imports.addType(cls.getType());
View Full Code Here

                    "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);
      }
    }

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

      String superClass = null;
      if (!"java.lang.Object".equals(rt.name())) {
        superClass = rt.getSuperClassName();
      }
      ClassFile cf = factory.createClass(rt.name(), superClass);
      ConstantPool cp = cf.getPool();
      FieldFactory fieldFactory = new FieldFactory();
      for (IField field : rt.visibleFields()) {
        AccessFlags flags = new AccessFlags(field.modifiers());
        Field fieldToAdd = fieldFactory.createField(cf, flags, cp.optionalAddUtf8(field.name()), cp.optionalAddUtf8(field.signature()));
        cf.add(fieldToAdd);
      }
     
      MethodFactory methodFactory = new MethodFactory();
      for (IMethod method : rt.visibleMethods()) {
        AccessFlags flags = new AccessFlags(method.modifiers());
        net.sf.rej.java.Method methodToAdd = methodFactory.createMethod(cf, flags, cp.optionalAddUtf8(method.name()), cp.optionalAddUtf8(method.signature()), cp.optionalAddUtf8("Code"), 0, 0, cp.optionalAddUtf8("Exceptions"), new ArrayList<ExceptionDescriptor>());
        cf.add(methodToAdd);
      }

      SystemFacade.getInstance().setStatus("Class definition pulled from VM: " + sf.location().declaringType().name());
      Event event = new Event(EventType.CLASS_OPEN);
View Full Code Here

TOP

Related Classes of net.sf.rej.java.constantpool.ConstantPool

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.