@Override
  public void parseSelf(AttributeInfo attributeInfo, List<ConstantPoolInfo> cp_info)
      throws Exception {
    super.parseSelf(attributeInfo, cp_info);

    byte[] info = attributeInfo.getInfo();
    int[] index = new int[] {0};
    setNum_parameters(TransformUtil.subBytes(info, index, 1)[0]);

    int num_param = TransformUtil.bytesToInt(new byte[] {getNum_parameters()});
    if (num_param > 0) {
      List<Parameter> parameters = new ArrayList<Parameter>();
      for (int i = 0; i < num_param; i++) {
        Parameter parameter = new Parameter();
        parameter.setNum_annotations(TransformUtil.subBytes(info, index, 2));

        int num_anno = TransformUtil.bytesToInt(parameter.getNum_annotations());
        if (num_anno > 0) {
          List<Annotation> annotations = new ArrayList<Annotation>();
          for (int j = 0; j < num_anno; j++) {
            Annotation annotation = new Annotation(cp_info);
            annotation.parseSelf(info, index);
            annotations.add(annotation);
          }
          parameter.setAnnotations(annotations);
        }
        setParameters(parameters);
      }
    }
  }
 private void mergeDataObjects(DataObjectInfo keep, DataObjectInfo merge) {
   for (AttributeInfo attr : merge.getAttributeDefs()) {
     if (keep.getAttributeDef(attr.getAttrName()) == null) {
       attr.setParentDataObject(keep);
       keep.addAttribute(attr);
     }
   }
   if (keep.getFindAllMethod() == null) {
     keep.setFindAllMethod(merge.getFindAllMethod());
   }
   if (keep.getFindMethod() == null) {
     keep.setFindMethod(merge.getFindMethod());
   }
   if (keep.getGetCanonicalMethod() == null) {
     keep.setGetCanonicalMethod(merge.getGetCanonicalMethod());
   }
   if (keep.getCreateMethod() == null) {
     keep.setCreateMethod(merge.getCreateMethod());
   }
   if (keep.getUpdateMethod() == null) {
     keep.setUpdateMethod(merge.getUpdateMethod());
   }
   if (keep.getMergeMethod() == null) {
     keep.setMergeMethod(merge.getMergeMethod());
   }
   if (keep.getDeleteMethod() == null) {
     keep.setDeleteMethod(merge.getDeleteMethod());
   }
   // move child accessors to "keep" data object"
   for (AccessorInfo accessor : merge.getAllChildren()) {
     if (keep.findChildAccessor(accessor.getChildAccessorName()) == null) {
       accessor.setParentDataObject(keep);
       keep.addChild(accessor);
     }
   }
   // loop over all other data objects, and check if they have a child accessor with the "merge"
   // data object as child. If so, move the pointer from "merge" to "keep" data object
   // NOTE: we should not loop over getSelectedDataObjectInfo, would cause infinite loop
   // as this method is called from getSelectedDataObjectInfos
   for (DataObjectInfo doi : this.getDataObjectInfos()) {
     for (AccessorInfo accessor : doi.getAllChildren()) {
       if (accessor.getChildDataObject() == merge) {
         accessor.setChildDataObject(keep);
         // if there is a child accessor method, we also need to add that "find-in=parent method to
         // "keep" doi!
         if (accessor.getChildAccessorMethod() != null) {
           keep.addFindAllInParentMethod(accessor.getChildAccessorMethod());
         }
       }
     }
     // also check the parameterValueProvider objects for methods
     for (DCMethod method : doi.getAllMethods()) {
       if (merge == method.getParameterValueProviderDataObject()) {
         method.setParameterValueProviderDataObject(keep);
       }
     }
   }
 }
Beispiel #3
0
 public AttributeInfo getAtrribute(String name) {
   NOTNULL(name);
   for (AttributeInfo a : attributes()) {
     if (a.name().equals(name)) {
       return a;
     }
   }
   return null;
 }
Beispiel #4
0
 private void registerConstants(ConstantPool pool) {
   classname = pool.register(classname);
   superclass = pool.register(superclass);
   interfaces = Helper.register(interfaces, pool);
   for (FieldInfo f : iterable(fields)) {
     f.registerConstants(pool);
   }
   for (MethodInfo m : iterable(methods)) {
     m.registerConstants(pool);
   }
   for (AttributeInfo a : iterable(attributes)) {
     a.registerConstants(pool);
   }
   pool.rebuild();
 }
Beispiel #5
0
  private AttributeInfo parseAttribute() throws IOException {
    AttributeInfo result = new AttributeInfo();

    int nameIndex = in.readUnsignedShort();
    if (nameIndex != -1) {
      result.setName(toUTF8(nameIndex));
    }

    int attributeLength = in.readInt();
    byte[] value = new byte[attributeLength];
    for (int b = 0; b < attributeLength; b++) {
      value[b] = in.readByte();
    }

    result.setValue(value);
    return result;
  }
Beispiel #6
0
 private void read(DataInputStream in) throws IOException {
   accessFlags = in.readUnsignedShort();
   name = in.readUnsignedShort();
   descriptor = in.readUnsignedShort();
   int n = in.readUnsignedShort();
   attribute = new LinkedList();
   for (int i = 0; i < n; ++i) attribute.add(AttributeInfo.read(constPool, in));
 }
Beispiel #7
0
 void write(DataOutputStream out) throws IOException {
   out.writeShort(accessFlags);
   out.writeShort(name);
   out.writeShort(descriptor);
   if (attribute == null) out.writeShort(0);
   else {
     out.writeShort(attribute.size());
     AttributeInfo.writeAll(attribute, out);
   }
 }
Beispiel #8
0
  void prune(ConstPool cp) {
    LinkedList newAttributes = new LinkedList();
    AttributeInfo invisibleAnnotations = getAttribute(AnnotationsAttribute.invisibleTag);
    if (invisibleAnnotations != null) {
      invisibleAnnotations = invisibleAnnotations.copy(cp, null);
      newAttributes.add(invisibleAnnotations);
    }

    AttributeInfo visibleAnnotations = getAttribute(AnnotationsAttribute.visibleTag);
    if (visibleAnnotations != null) {
      visibleAnnotations = visibleAnnotations.copy(cp, null);
      newAttributes.add(visibleAnnotations);
    }

    AttributeInfo signature = getAttribute(SignatureAttribute.tag);
    if (signature != null) {
      signature = signature.copy(cp, null);
      newAttributes.add(signature);
    }

    int index = getConstantValue();
    if (index != 0) {
      index = constPool.copy(index, cp, null);
      newAttributes.add(new ConstantAttribute(cp, index));
    }

    attribute = newAttributes;
    name = cp.addUtf8Info(getName());
    descriptor = cp.addUtf8Info(getDescriptor());
    constPool = cp;
  }
  static void printAttributes(List<AttributeInfo> list, PrintWriter out, char kind) {
    if (list == null) {
      return;
    }

    int n = list.size();
    for (int i = 0; i < n; ++i) {
      AttributeInfo ai = list.get(i);
      if (ai instanceof CodeAttribute) {
        CodeAttribute ca = (CodeAttribute) ai;
        out.println("attribute: " + ai.getName() + ": " + ai.getClass().getName());
        out.println(
            "max stack "
                + ca.getMaxStack()
                + ", max locals "
                + ca.getMaxLocals()
                + ", "
                + ca.getExceptionTable().size()
                + " catch blocks");
        out.println("<code attribute begin>");
        printAttributes(ca.getAttributes(), out, kind);
        out.println("<code attribute end>");
      } else if (ai instanceof org.hotswap.agent.javassist.bytecode.AnnotationsAttribute) {
        out.println("annnotation: " + ai.toString());
      } else if (ai instanceof org.hotswap.agent.javassist.bytecode.ParameterAnnotationsAttribute) {
        out.println("parameter annnotations: " + ai.toString());
      } else if (ai instanceof org.hotswap.agent.javassist.bytecode.StackMapTable) {
        out.println("<stack map table begin>");
        org.hotswap.agent.javassist.bytecode.StackMapTable.Printer.print(
            (org.hotswap.agent.javassist.bytecode.StackMapTable) ai, out);
        out.println("<stack map table end>");
      } else if (ai instanceof org.hotswap.agent.javassist.bytecode.StackMap) {
        out.println("<stack map begin>");
        ((org.hotswap.agent.javassist.bytecode.StackMap) ai).print(out);
        out.println("<stack map end>");
      } else if (ai instanceof org.hotswap.agent.javassist.bytecode.SignatureAttribute) {
        org.hotswap.agent.javassist.bytecode.SignatureAttribute sa =
            (org.hotswap.agent.javassist.bytecode.SignatureAttribute) ai;
        String sig = sa.getSignature();
        out.println("signature: " + sig);
        try {
          String s;
          if (kind == 'c') {
            s =
                org.hotswap.agent.javassist.bytecode.SignatureAttribute.toClassSignature(sig)
                    .toString();
          } else if (kind == 'm') {
            s =
                org.hotswap.agent.javassist.bytecode.SignatureAttribute.toMethodSignature(sig)
                    .toString();
          } else {
            s =
                org.hotswap.agent.javassist.bytecode.SignatureAttribute.toFieldSignature(sig)
                    .toString();
          }

          out.println("           " + s);
        } catch (org.hotswap.agent.javassist.bytecode.BadBytecode e) {
          out.println("           syntax error");
        }
      } else {
        out.println(
            "attribute: "
                + ai.getName()
                + " ("
                + ai.get().length
                + " byte): "
                + ai.getClass().getName());
      }
    }
  }
Beispiel #10
0
 /**
  * Copies all constant pool items to a given new constant pool and replaces the original items
  * with the new ones. This is used for garbage collecting the items of removed fields and methods.
  *
  * @param cp the destination
  */
 void compact(ConstPool cp) {
   name = cp.addUtf8Info(getName());
   descriptor = cp.addUtf8Info(getDescriptor());
   attribute = AttributeInfo.copyAll(attribute, cp);
   constPool = cp;
 }
Beispiel #11
0
  /**
   * Appends an attribute. If there is already an attribute with the same name, the new one
   * substitutes for it.
   *
   * @see #getAttributes()
   */
  public void addAttribute(AttributeInfo info) {
    if (attribute == null) attribute = new LinkedList();

    AttributeInfo.remove(attribute, info.getName());
    attribute.add(info);
  }
Beispiel #12
0
 /**
  * Returns the attribute with the specified name. It returns null if the specified attribute is
  * not found.
  *
  * @param name attribute name
  * @see #getAttributes()
  */
 public AttributeInfo getAttribute(String name) {
   return AttributeInfo.lookup(attribute, name);
 }
  /**
   * @return
   * @throws BasicException
   */
  @Override
  public Object createValue() throws BasicException {
    AttributeInfo att = (AttributeInfo) attmodel.getSelectedItem();

    return att == null ? null : att.getId();
  }