Package net.sf.rej.util

Examples of net.sf.rej.util.Range


  public void sync(ConstantPoolInfo cpi) {
    if (cpi == null) {
      this.hexEditor.getHexEditor().getSelectionModel().clearSelection();     
    } else {
      Range range = this.offsets.get(cpi);
      this.hexEditor.getHexEditor().getSelectionModel().setSelectedInverval(range.getOffset(), range.getOffset() + range.getSize());     
    }
    this.hexEditor.repaint();
    this.hexEditor.getHexEditor().ensureSelectionIsVisible();
  }
View Full Code Here


      return this.offsets.get(ClassFile.OffsetTag.METHOD_DATA);
    } else if (node instanceof MethodNode) {
      MethodNode mNode = (MethodNode) node;
      return this.offsets.get(mNode.getMethod());
    } else if (node instanceof MethodAccessFlagsNode) {
      Range parentRange = getRange((StructureNode)node.getParent());
      MethodAccessFlagsNode mafNode = (MethodAccessFlagsNode) node;
      Method method = mafNode.getMethod();
      Range afRange = method.getOffsetMap().get(Method.OffsetTag.ACCESS_FLAGS);
      return afRange.offsetBy(parentRange.getOffset());
    } else if (node instanceof MethodNameNode) {
      Range parentRange = getRange((StructureNode)node.getParent());
      MethodNameNode mafNode = (MethodNameNode) node;
      Method method = mafNode.getMethod();
      Range afRange = method.getOffsetMap().get(Method.OffsetTag.METHOD_NAME);
      return afRange.offsetBy(parentRange.getOffset());
    } else if (node instanceof MethodDescriptorNode) {     
      Range parentRange = getRange((StructureNode)node.getParent());
      MethodDescriptorNode mafNode = (MethodDescriptorNode) node;
      Method method = mafNode.getMethod();
      Range afRange = method.getOffsetMap().get(Method.OffsetTag.METHOD_DESCRIPTOR);
      return afRange.offsetBy(parentRange.getOffset());
    } else if (node instanceof AttributeNode) {
      AttributeNode aNode = (AttributeNode) node;
      AttributesNode an = (AttributesNode) aNode.getParent();
      Range range = getRange(an);
      Map<Object, Range> map = an.getAttributesObject().getOffsetMap(range.getOffset());
      return map.get(aNode.getAttributeObject());
    } else if (node instanceof AttributesNode) {
      StructureNode parent = (StructureNode) node.getParent();
      if (parent instanceof ClassFileNode) {
        return this.offsets.get(ClassFile.OffsetTag.ATTRIBUTES);
      } else if (parent instanceof MethodNode) {
        MethodNode mNode = (MethodNode) parent;
        Range parentRange = getRange(parent);
        Map<Object, Range> map = mNode.getMethod().getOffsetMap();
        return map.get(Method.OffsetTag.ATTRIBUTES).offsetBy(parentRange.getOffset());
      } else if (parent instanceof FieldNode) {
        FieldNode fNode = (FieldNode) parent;
        Range parentRange = getRange(parent);
        Map<Object, Range> map = fNode.getField().getOffsetMap();
        return map.get(Field.OffsetTag.ATTRIBUTES).offsetBy(parentRange.getOffset());
      } else if (parent instanceof AttributeNode) {
        // code attribute attributes
        AttributeNode aNode = (AttributeNode) parent;
        CodeAttribute cAttr = (CodeAttribute) aNode.getAttributeObject();
        Range range = cAttr.getOffsetMap().get(CodeAttribute.OffsetTag.ATTRIBUTES);
        Range parentRange = getRange(parent);
        return range.offsetBy(parentRange.getOffset());
      }
      return null;
    } else {
      return null;
    }   
View Full Code Here

    }   
  }

  public void sync(StructureNode node) {
   
    Range range = getRange(node);
    if (range == null) {
      this.hexEditor.getHexEditor().getSelectionModel().clearSelection();
    } else {
      this.hexEditor.getHexEditor().getSelectionModel().setSelectedInverval(range.getOffset(), range.getOffset() + range.getSize());
    }
    this.hexEditor.repaint();
    this.hexEditor.getHexEditor().ensureSelectionIsVisible();
  }
View Full Code Here

     * @return a map of element offsets in class file data.
     */
    public Map<Object, Range> getOffsetMap() {
      Map<Object, Range> map = new HashMap<Object, Range>();
      int offset = 6; // 6 bytes of Attribute serialization data.
      map.put(OffsetTag.MAX_STACK, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.MAX_LOCALS, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.CODE_LENGTH, new Range(offset, 4));
      offset += 4;
      int codeLength = this.code.getData().length;
      map.put(OffsetTag.CODE, new Range(offset, codeLength));
      offset += codeLength;
      int exceptionsLength = this.exceptions.getData().length;
      map.put(OffsetTag.EXCEPTIONS, new Range(offset, exceptionsLength));
      offset += exceptionsLength;
      map.put(OffsetTag.ATTRIBUTES, new Range(offset, this.attributes.getData().length));
     
      // each attribute
      map.putAll(this.attributes.getOffsetMap(offset));

      return map;
View Full Code Here

    if (er == null) {
      this.hexEditor.getHexEditor().getSelectionModel().clearSelection();
    } else {
      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();
        // "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);         
View Full Code Here

      Map<Object, Range> map = new HashMap<Object, Range>();
      int offset = initialOffset;
      offset += 2;
        for (Attribute attr : this.attributes) {
          int size = attr.getData().length;
          map.put(attr, new Range(offset, size));
          offset += size;
        }

      return map;
    }
View Full Code Here

        this.model.setColumnIdentifiers(HEADERS);
      }
    }
    if (event.getType() == EventType.CLASS_OPEN || event.getType() == EventType.CLASS_UPDATE || event.getType() == EventType.CLASS_REPARSE) {
      if (this.cf != null) {
        Range constantPoolRange = this.cf.getOffsetMap().get(ClassFile.OffsetTag.CONSTANT_POOL);
        this.offsets = this.cf.getPool().getOffsetMap(constantPoolRange.getOffset());
        if (this.sync != null) {
          this.sync.setOffsets(this.offsets);
        }
      }
     
View Full Code Here

     * @return a map of element offsets in class file data.
     */
    public Map<Object, Range> getOffsetMap() {
      Map<Object, Range> map = new HashMap<Object, Range>();
      int offset = 0;
      map.put(OffsetTag.ACCESS_FLAGS, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.METHOD_NAME, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.METHOD_DESCRIPTOR, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.ATTRIBUTES, new Range(offset, this.attributes.getData().length));
      // each attribute
     
      map.putAll(this.attributes.getOffsetMap(offset));

      return map;
View Full Code Here

     * @return a map of element offsets in class file data.
     */
    public Map<Object, Range> getOffsetMap() {
      Map<Object, Range> map = new HashMap<Object, Range>();
      int offset = 0;
      map.put(OffsetTag.ACCESS_FLAGS, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.FIELD_NAME, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.FIELD_DESCRIPTOR, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.ATTRIBUTES, new Range(offset, this.attributes.getData().length));
      // each attribute
     
      map.putAll(this.attributes.getOffsetMap(offset));

      return map;
View Full Code Here

     * @return a map of element offsets in class file data.
     */
    public Map<Object, Range> getOffsetMap() {
      Map<Object, Range> map = new HashMap<Object, Range>();
      int offset = 0;
      map.put(OffsetTag.MAGIC, new Range(offset, 4));
      offset += 4;
      map.put(OffsetTag.VERSION, new Range(offset, 4));
      map.put(OffsetTag.MINOR_VERSION, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.MAJOR_VERSION, new Range(offset, 2));
      offset += 2;
      int poolSize = this.pool.getData().length;
      map.put(OffsetTag.CONSTANT_POOL, new Range(offset, poolSize));
      // TODO: offsets for each pool item?
      offset += poolSize;
      map.put(OffsetTag.ACCESS_FLAGS, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.THIS_CLASS, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.SUPER_CLASS, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.INTERFACE_COUNT, new Range(offset, 2));
      offset += 2;
      map.put(OffsetTag.INTERFACE_DATA, new Range(offset, this.interfaces.size()*2));
      {
        for (Interface anInterface : this.interfaces) {
          map.put(anInterface, new Range(offset, 2));
          offset += 2;
        }
      }
      map.put(OffsetTag.FIELD_COUNT, new Range(offset, 2));
      offset += 2;
      int fieldDataTotalSize = 0;
      Range fieldDataOffset = new Range(offset, 0);
      map.put(OffsetTag.FIELD_DATA, fieldDataOffset);
        for (Field field : this.fields) {
          int fieldSize = field.getData().length;
          map.put(field, new Range(offset, fieldSize));
          offset += fieldSize;
          fieldDataTotalSize += fieldSize;
        }
        fieldDataOffset.setSize(fieldDataTotalSize);
       
      map.put(OffsetTag.METHOD_COUNT, new Range(offset, 2));
      offset += 2;
      int methodDataTotalSize = 0;
      Range methodDataOffset = new Range(offset, 0);
      map.put(OffsetTag.METHOD_DATA, methodDataOffset);
        for (Method method : this.methods) {
          int methodSize = method.getData().length;
          map.put(method, new Range(offset, methodSize));
          offset += methodSize;
          methodDataTotalSize += methodSize;
        }
        methodDataOffset.setSize(methodDataTotalSize);
       
      map.put(OffsetTag.ATTRIBUTES, new Range(offset, this.attributes.getData().length));
      return map;
    }
View Full Code Here

TOP

Related Classes of net.sf.rej.util.Range

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.