Ejemplo n.º 1
0
  public BaseClassData(Class<?> cls) {
    className = cls.getName();
    internalName = Descriptor.toJvmName(cls.getName());
    this.loader = cls.getClassLoader();
    replaceable = false;
    if (cls.getSuperclass() != null) {
      superClassName = cls.getSuperclass().getName();
    } else {
      superClassName = null;
    }
    Set<MethodData> meths = new HashSet<MethodData>();
    for (Method m : cls.getDeclaredMethods()) {
      MemberType type = MemberType.NORMAL;
      final String descriptor = DescriptorUtils.getDescriptor(m);
      if ((descriptor.equals(Constants.ADDED_METHOD_DESCRIPTOR)
              && m.getName().equals(Constants.ADDED_METHOD_NAME))
          || (descriptor.equals(Constants.ADDED_STATIC_METHOD_DESCRIPTOR)
              && m.getName().equals(Constants.ADDED_STATIC_METHOD_NAME))) {
        type = MemberType.ADDED_SYSTEM;
      }
      MethodData md =
          new MethodData(m.getName(), descriptor, cls.getName(), type, m.getModifiers(), false);
      meths.add(md);
    }
    for (Constructor<?> c : cls.getDeclaredConstructors()) {
      MemberType type = MemberType.NORMAL;
      final String descriptor = DescriptorUtils.getDescriptor(c);
      if (descriptor.equals(Constants.ADDED_CONSTRUCTOR_DESCRIPTOR)) {
        type = MemberType.ADDED_SYSTEM;
      }
      MethodData md =
          new MethodData("<init>", descriptor, cls.getName(), type, c.getModifiers(), false);
      meths.add(md);
    }

    this.methods = Collections.unmodifiableSet(meths);
    Set<FieldData> fieldData = new HashSet<FieldData>();
    for (Field m : cls.getDeclaredFields()) {
      fieldData.add(new FieldData(m));
    }
    this.fields = Collections.unmodifiableSet(fieldData);
  }
Ejemplo n.º 2
0
  public BaseClassData(ClassFile file, ClassLoader loader, boolean replaceable) {
    className = file.getName();
    this.replaceable = replaceable;
    internalName = Descriptor.toJvmName(file.getName());
    this.loader = loader;
    superClassName = file.getSuperclass();
    boolean finalMethod = false;
    Set<MethodData> meths = new HashSet<MethodData>();
    for (Object o : file.getMethods()) {
      String methodClassName = className;
      MethodInfo m = (MethodInfo) o;
      MemberType type = MemberType.NORMAL;
      if ((m.getDescriptor().equals(Constants.ADDED_METHOD_DESCRIPTOR)
              && m.getName().equals(Constants.ADDED_METHOD_NAME))
          || (m.getDescriptor().equals(Constants.ADDED_STATIC_METHOD_DESCRIPTOR)
              && m.getName().equals(Constants.ADDED_STATIC_METHOD_NAME))
          || (m.getDescriptor().equals(Constants.ADDED_CONSTRUCTOR_DESCRIPTOR))) {
        type = MemberType.ADDED_SYSTEM;
      } else if (m.getAttribute(Constants.FINAL_METHOD_ATTRIBUTE) != null) {
        finalMethod = true;
      }

      MethodData md =
          new MethodData(
              m.getName(),
              m.getDescriptor(),
              methodClassName,
              type,
              m.getAccessFlags(),
              finalMethod);
      meths.add(md);
    }
    this.methods = Collections.unmodifiableSet(meths);
    Set<FieldData> fieldData = new HashSet<FieldData>();
    for (Object o : file.getFields()) {
      FieldInfo m = (FieldInfo) o;
      MemberType mt = MemberType.NORMAL;
      fieldData.add(new FieldData(m, mt, className, m.getAccessFlags()));
    }
    this.fields = Collections.unmodifiableSet(fieldData);
  }
 public MethodAdapter(MethodVisitor mv, boolean add, CtClass target) {
   super(mv);
   addSynchronized = add;
   this.target = target;
   targetOwner = Descriptor.toJvmName(target.getName());
 }