コード例 #1
0
  /** Returns a shrunk descriptor or signature of the given method. */
  private String shrinkDescriptor(Method method, String descriptor) {
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    int parameterIndex =
        (method.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) != 0 ? 0 : 1;

    // Go over the parameters.
    InternalTypeEnumeration internalTypeEnumeration = new InternalTypeEnumeration(descriptor);

    StringBuffer newDescriptorBuffer = new StringBuffer();

    newDescriptorBuffer.append(internalTypeEnumeration.formalTypeParameters());
    newDescriptorBuffer.append(ClassConstants.INTERNAL_METHOD_ARGUMENTS_OPEN);

    while (internalTypeEnumeration.hasMoreTypes()) {
      String type = internalTypeEnumeration.nextType();
      if (ParameterUsageMarker.isParameterUsed(method, parameterIndex)) {
        newDescriptorBuffer.append(type);
      } else if (DEBUG) {
        System.out.println("  Deleting parameter #" + parameterIndex + " [" + type + "]");
      }

      parameterIndex += ClassUtil.isInternalCategory2Type(type) ? 2 : 1;
    }

    newDescriptorBuffer.append(ClassConstants.INTERNAL_METHOD_ARGUMENTS_CLOSE);
    newDescriptorBuffer.append(internalTypeEnumeration.returnType());

    return newDescriptorBuffer.toString();
  }
コード例 #2
0
  /** Shrinks the array of referenced classes of the given method. */
  private Clazz[] shrinkReferencedClasses(
      Method method, String descriptor, Clazz[] referencedClasses) {
    if (referencedClasses != null) {
      // All parameters of non-static methods are shifted by one in the local
      // variable frame.
      int parameterIndex =
          (method.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) != 0 ? 0 : 1;

      int referencedClassIndex = 0;
      int newReferencedClassIndex = 0;

      // Go over the parameters.
      InternalTypeEnumeration internalTypeEnumeration = new InternalTypeEnumeration(descriptor);

      // Also look at the formal type parameters.
      String type = internalTypeEnumeration.formalTypeParameters();
      int count = new DescriptorClassEnumeration(type).classCount();
      for (int counter = 0; counter < count; counter++) {
        referencedClasses[newReferencedClassIndex++] = referencedClasses[referencedClassIndex++];
      }

      while (internalTypeEnumeration.hasMoreTypes()) {
        // Consider the classes referenced by this parameter type.
        type = internalTypeEnumeration.nextType();
        count = new DescriptorClassEnumeration(type).classCount();

        if (ParameterUsageMarker.isParameterUsed(method, parameterIndex)) {
          // Copy the referenced classes.
          for (int counter = 0; counter < count; counter++) {
            referencedClasses[newReferencedClassIndex++] =
                referencedClasses[referencedClassIndex++];
          }
        } else {
          // Skip the referenced classes.
          referencedClassIndex += count;
        }

        parameterIndex += ClassUtil.isInternalCategory2Type(type) ? 2 : 1;
      }

      // Also look at the return value.
      type = internalTypeEnumeration.returnType();
      count = new DescriptorClassEnumeration(type).classCount();
      for (int counter = 0; counter < count; counter++) {
        referencedClasses[newReferencedClassIndex++] = referencedClasses[referencedClassIndex++];
      }

      // Clear the unused entries.
      while (newReferencedClassIndex < referencedClassIndex) {
        referencedClasses[newReferencedClassIndex++] = null;
      }
    }

    return referencedClasses;
  }