Example #1
0
  protected void markProgramMethodBody(ProgramClass programClass, ProgramMethod programMethod) {
    // Mark the name and descriptor.
    markConstant(programClass, programMethod.u2nameIndex);
    markConstant(programClass, programMethod.u2descriptorIndex);

    // Mark the attributes.
    programMethod.attributesAccept(programClass, this);

    // Mark the classes referenced in the descriptor string.
    programMethod.referencedClassesAccept(this);
  }
 public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod) {
   targetClass.hierarchyAccept(
       visitThisMember,
       visitSuperMembers,
       visitInterfaceMembers,
       visitOverridingMembers,
       new NamedMethodVisitor(
           programMethod.getName(programClass),
           programMethod.getDescriptor(programClass),
           memberVisitor));
 }
  public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod) {
    // Special cases: <clinit> and <init> are always kept unchanged.
    // We can ignore them here.
    String name = programMethod.getName(programClass);
    if (name.equals(ClassConstants.INTERNAL_METHOD_NAME_CLINIT)
        || name.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT)) {
      return;
    }

    String newName = MemberObfuscator.newMemberName(programMethod);
    if (newName != null) {
      ps.println(
          "    "
              + lineNumberRange(programClass, programMethod)
              + ClassUtil.externalFullMethodDescription(
                  programClass.getName(),
                  0,
                  programMethod.getName(programClass),
                  programMethod.getDescriptor(programClass))
              + " -> "
              + newName);
    }
  }
  public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod) {
    // Update the descriptor if it has any unused parameters.
    String descriptor = programMethod.getDescriptor(programClass);
    String newDescriptor = shrinkDescriptor(programMethod, descriptor);

    if (!descriptor.equals(newDescriptor)) {
      // Shrink the signature and parameter annotations.
      programMethod.attributesAccept(programClass, this);

      String name = programMethod.getName(programClass);
      String newName = name;

      // Append a code, if the method isn't a class instance initializer.
      if (!name.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT)) {
        newName +=
            ClassConstants.SPECIAL_MEMBER_SEPARATOR
                + Long.toHexString(Math.abs((descriptor).hashCode()));
      }

      if (DEBUG) {
        System.out.println("MethodDescriptorShrinker:");
        System.out.println("  Class file        = " + programClass.getName());
        System.out.println("  Method name       = " + name);
        System.out.println("                   -> " + newName);
        System.out.println("  Method descriptor = " + descriptor);
        System.out.println("                   -> " + newDescriptor);
      }

      ConstantPoolEditor constantPoolEditor = new ConstantPoolEditor(programClass);

      // Update the name, if necessary.
      if (!newName.equals(name)) {
        programMethod.u2nameIndex = constantPoolEditor.addUtf8Constant(newName);
      }

      // Update the referenced classes.
      programMethod.referencedClasses =
          shrinkReferencedClasses(programMethod, descriptor, programMethod.referencedClasses);

      // Finally, update the descriptor itself.
      programMethod.u2descriptorIndex = constantPoolEditor.addUtf8Constant(newDescriptor);

      // Visit the method, if required.
      if (extraMemberVisitor != null) {
        extraMemberVisitor.visitProgramMethod(programClass, programMethod);
      }
    }
  }
 public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod) {
   if (accepted(programMethod.getDescriptor(programClass))) {
     memberVisitor.visitProgramMethod(programClass, programMethod);
   }
 }