Java Code Examples for proguard.classfile.util.ClassUtil#internalMethodDescriptor()

The following examples show how to use proguard.classfile.util.ClassUtil#internalMethodDescriptor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MappingKeeper.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void processMethodMapping(String className,
                                 int    firstLineNumber,
                                 int    lastLineNumber,
                                 String methodReturnType,
                                 String methodName,
                                 String methodArguments,
                                 String newMethodName)
{
    if (clazz != null)
    {
        // Find the method.
        String descriptor = ClassUtil.internalMethodDescriptor(methodReturnType,
                                                               ListUtil.commaSeparatedList(methodArguments));

        Method method = clazz.findMethod(methodName, descriptor);
        if (method != null)
        {
            // Print out a warning if the mapping conflicts with a name that
            // was set before.
            if (warningPrinter != null)
            {
                String currentNewName = MemberObfuscator.newMemberName(method);
                if (currentNewName != null &&
                    !currentNewName.equals(newMethodName))
                {
                    warningPrinter.print(ClassUtil.internalClassName(className),
                                         "Warning: " +
                                         className +
                                         ": method '" + methodReturnType + " " + methodName + ClassConstants.EXTERNAL_METHOD_ARGUMENTS_OPEN + methodArguments + ClassConstants.EXTERNAL_METHOD_ARGUMENTS_CLOSE +
                                         "' is not being kept as '" + currentNewName +
                                         "', but remapped to '" + newMethodName + "'");
                }
            }

            // Make sure the mapping name will be kept.
            MemberObfuscator.setFixedNewMemberName(method, newMethodName);
        }
    }
}
 
Example 2
Source File: MemberSpecificationElement.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds the contents of this class member specification element to the given
 * list.
 * @param memberSpecifications the class member specifications to be
 *                                  extended.
 * @param isMethod                  specifies whether this specification
 *                                  refers to a method.
 * @param isConstructor             specifies whether this specification
 *                                  refers to a constructor.
 */
public void appendTo(List    memberSpecifications,
                     boolean isMethod,
                     boolean isConstructor)
{
    // Get the referenced file set, or else this one.
    MemberSpecificationElement memberSpecificationElement = isReference() ?
        (MemberSpecificationElement)getCheckedRef(this.getClass(),
                                                  this.getClass().getName()) :
        this;

    // Create a new class member specification.
    String access     = memberSpecificationElement.access;
    String type       = memberSpecificationElement.type;
    String annotation = memberSpecificationElement.annotation;
    String name       = memberSpecificationElement.name;
    String parameters = memberSpecificationElement.parameters;
    String values     = memberSpecificationElement.values;

    // Perform some basic conversions and checks on the attributes.
    if (annotation != null)
    {
        annotation = ClassUtil.internalType(annotation);
    }

    if (isMethod)
    {
        if (isConstructor)
        {
            if (type != null)
            {
                throw new BuildException("Type attribute not allowed in constructor specification ["+type+"]");
            }

            if (parameters != null)
            {
                type = JavaTypeConstants.VOID;
            }

            if (values != null)
            {
                throw new BuildException("Values attribute not allowed in constructor specification ["+values+"]");
            }

            name = ClassConstants.METHOD_NAME_INIT;
        }
        else if ((type != null) ^ (parameters != null))
        {
            throw new BuildException("Type and parameters attributes must always be present in combination in method specification");
        }
    }
    else
    {
        if (parameters != null)
        {
            throw new BuildException("Parameters attribute not allowed in field specification ["+parameters+"]");
        }
    }

    if (values != null)
    {
        if (type == null)
        {
            throw new BuildException("Values attribute must be specified in combination with type attribute in class member specification ["+values+"]");
        }
    }

    List parameterList = ListUtil.commaSeparatedList(parameters);

    String descriptor =
        parameters != null ? ClassUtil.internalMethodDescriptor(type, parameterList) :
        type       != null ? ClassUtil.internalType(type)                            :
                             null;

    MemberSpecification memberSpecification = values != null ?
        new MemberValueSpecification(requiredAccessFlags(true, access),
                                     requiredAccessFlags(false, access),
                                     annotation,
                                     name,
                                     descriptor,
                                     parseValues(type,
                                                 ClassUtil.internalType(type),
                                                 values)) :
        new MemberSpecification(requiredAccessFlags(true,  access),
                                requiredAccessFlags(false, access),
                                annotation,
                                name,
                                descriptor);

    // Add it to the list.
    memberSpecifications.add(memberSpecification);
}
 
Example 3
Source File: ProGuardTask.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a specification of class members, based on the given parameters.
 */
private MemberSpecification createMemberSpecification(boolean isMethod,
                                                      boolean isConstructor,
                                                      boolean allowValues,
                                                      Map     classSpecificationArgs)
throws ParseException
{
    // Extract the arguments.
    String access            = (String)classSpecificationArgs.get("access");
    String type              = (String)classSpecificationArgs.get("type");
    String annotation        = (String)classSpecificationArgs.get("annotation");
    String name              = (String)classSpecificationArgs.get("name");
    String parameters        = (String)classSpecificationArgs.get("parameters");
    String values            = (String)classSpecificationArgs.get("value");

    // Perform some basic conversions and checks on the attributes.
    if (annotation != null)
    {
        annotation = ClassUtil.internalType(annotation);
    }

    if (isMethod)
    {
        if (isConstructor)
        {
            if (type != null)
            {
                throw new ParseException("Type attribute not allowed in constructor specification ["+type+"]");
            }

            if (parameters != null)
            {
                type = JavaTypeConstants.VOID;
            }

            if (values != null)
            {
                throw new ParseException("Values attribute not allowed in constructor specification ["+values+"]");
            }

            name = ClassConstants.METHOD_NAME_INIT;
        }
        else if ((type != null) ^ (parameters != null))
        {
            throw new ParseException("Type and parameters attributes must always be present in combination in method specification");
        }
    }
    else
    {
        if (parameters != null)
        {
            throw new ParseException("Parameters attribute not allowed in field specification ["+parameters+"]");
        }
    }

    if (values != null)
    {
        if (!allowValues)
        {
            throw new ParseException("Values attribute not allowed in this class specification ["+values+"]");
        }

        if (type == null)
        {
            throw new ParseException("Values attribute must be specified in combination with type attribute in class member specification ["+values+"]");
        }
    }

    List parameterList = ListUtil.commaSeparatedList(parameters);

    String descriptor =
        parameters != null ? ClassUtil.internalMethodDescriptor(type, parameterList) :
        type       != null ? ClassUtil.internalType(type)                            :
                             null;

    return values != null ?
        new MemberValueSpecification(requiredMemberAccessFlags(true,  access),
                                     requiredMemberAccessFlags(false, access),
                                     annotation,
                                     name,
                                     descriptor,
                                     parseValues(type,
                                                 ClassUtil.internalType(type),
                                                 values)) :
        new MemberSpecification(requiredMemberAccessFlags(true,  access),
                                requiredMemberAccessFlags(false, access),
                                annotation,
                                name,
                                descriptor);
}
 
Example 4
Source File: MemberSpecificationDialog.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the MemberSpecification currently represented in this dialog.
 */
public MemberSpecification getMemberSpecification()
{
    String annotationType = annotationTypeTextField.getText();
    String name           = nameTextField.getText();
    String type           = typeTextField.getText();
    String arguments      = argumentTypesTextField.getText();

    // Convert all class member specifications into the internal format.
    annotationType =
        annotationType.equals("") ||
        annotationType.equals("***") ? null : ClassUtil.internalType(annotationType);

    if (name.equals("") ||
        name.equals("*"))
    {
        name = null;
    }

    if (isField)
    {
        type =
            type.equals("") ||
            type.equals("***") ? null : ClassUtil.internalType(type);
    }
    else
    {
        if (type.equals(""))
        {
            type = JavaTypeConstants.VOID;
        }

        type =
            type     .equals("***") &&
            arguments.equals("...") ? null :
                ClassUtil.internalMethodDescriptor(type, ListUtil.commaSeparatedList(arguments));
    }

    MemberSpecification memberSpecification =
        new MemberSpecification(0, 0, annotationType, name, type);

    // Also get the access radio button settings.
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.PUBLIC,       publicRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.PRIVATE,      privateRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.PROTECTED,    protectedRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.STATIC,       staticRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.FINAL,        finalRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.SYNTHETIC,    syntheticRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.VOLATILE,     volatileRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.TRANSIENT,    transientRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.SYNCHRONIZED, synchronizedRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.NATIVE,       nativeRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.ABSTRACT,     abstractRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.STRICT,       strictRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.BRIDGE,       bridgeRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, AccessConstants.VARARGS,      varargsRadioButtons);

    return memberSpecification;
}
 
Example 5
Source File: ProGuardTask.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a specification of class members, based on the given parameters.
 */
private MemberSpecification createMemberSpecification(boolean isMethod,
                                                      boolean isConstructor,
                                                      Map     classSpecificationArgs)
throws ParseException
{
    // Extract the arguments.
    String access            = (String)classSpecificationArgs.get("access");
    String type              = (String)classSpecificationArgs.get("type");
    String annotation        = (String)classSpecificationArgs.get("annotation");
    String name              = (String)classSpecificationArgs.get("name");
    String parameters        = (String)classSpecificationArgs.get("parameters");

    // Perform some basic conversions and checks on the attributes.
    if (annotation != null)
    {
        annotation = ClassUtil.internalType(annotation);
    }

    if (isMethod)
    {
        if (isConstructor)
        {
            if (type != null)
            {
                throw new ParseException("Type attribute not allowed in constructor specification ["+type+"]");
            }

            if (parameters != null)
            {
                type = JavaConstants.TYPE_VOID;
            }

            name = ClassConstants.METHOD_NAME_INIT;
        }
        else if ((type != null) ^ (parameters != null))
        {
            throw new ParseException("Type and parameters attributes must always be present in combination in method specification");
        }
    }
    else
    {
        if (parameters != null)
        {
            throw new ParseException("Parameters attribute not allowed in field specification ["+parameters+"]");
        }
    }

    List parameterList = ListUtil.commaSeparatedList(parameters);

    String descriptor =
        parameters != null ? ClassUtil.internalMethodDescriptor(type, parameterList) :
        type       != null ? ClassUtil.internalType(type)                            :
                             null;

    return new MemberSpecification(requiredMemberAccessFlags(true,  access),
                                   requiredMemberAccessFlags(false, access),
                                   annotation,
                                   name,
                                   descriptor);
}
 
Example 6
Source File: MemberSpecificationElement.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds the contents of this class member specification element to the given
 * list.
 * @param memberSpecifications the class member specifications to be
 *                                  extended.
 * @param isMethod                  specifies whether this specification
 *                                  refers to a method.
 * @param isConstructor             specifies whether this specification
 *                                  refers to a constructor.
 */
public void appendTo(List    memberSpecifications,
                     boolean isMethod,
                     boolean isConstructor)
{
    // Get the referenced file set, or else this one.
    MemberSpecificationElement memberSpecificationElement = isReference() ?
        (MemberSpecificationElement)getCheckedRef(this.getClass(),
                                                  this.getClass().getName()) :
        this;

    // Create a new class member specification.
    String access     = memberSpecificationElement.access;
    String type       = memberSpecificationElement.type;
    String annotation = memberSpecificationElement.annotation;
    String name       = memberSpecificationElement.name;
    String parameters = memberSpecificationElement.parameters;

    // Perform some basic conversions and checks on the attributes.
    if (annotation != null)
    {
        annotation = ClassUtil.internalType(annotation);
    }

    if (isMethod)
    {
        if (isConstructor)
        {
            if (type != null)
            {
                throw new BuildException("Type attribute not allowed in constructor specification ["+type+"]");
            }

            if (parameters != null)
            {
                type = JavaConstants.TYPE_VOID;
            }

            name = ClassConstants.METHOD_NAME_INIT;
        }
        else if ((type != null) ^ (parameters != null))
        {
            throw new BuildException("Type and parameters attributes must always be present in combination in method specification");
        }
    }
    else
    {
        if (parameters != null)
        {
            throw new BuildException("Parameters attribute not allowed in field specification ["+parameters+"]");
        }
    }

    List parameterList = ListUtil.commaSeparatedList(parameters);

    String descriptor =
        parameters != null ? ClassUtil.internalMethodDescriptor(type, parameterList) :
        type       != null ? ClassUtil.internalType(type)                            :
                             null;

    MemberSpecification memberSpecification =
        new MemberSpecification(requiredAccessFlags(true,  access),
                                requiredAccessFlags(false, access),
                                annotation,
                                name,
                                descriptor);

    // Add it to the list.
    memberSpecifications.add(memberSpecification);
}
 
Example 7
Source File: ProGuardTask.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a specification of class members, based on the given parameters.
 */
private MemberSpecification createMemberSpecification(boolean isMethod,
                                                      boolean isConstructor,
                                                      Map     classSpecificationArgs)
throws ParseException
{
    // Extract the arguments.
    String access            = (String)classSpecificationArgs.get("access");
    String type              = (String)classSpecificationArgs.get("type");
    String annotation        = (String)classSpecificationArgs.get("annotation");
    String name              = (String)classSpecificationArgs.get("name");
    String parameters        = (String)classSpecificationArgs.get("parameters");

    // Perform some basic conversions and checks on the attributes.
    if (annotation != null)
    {
        annotation = ClassUtil.internalType(annotation);
    }

    if (isMethod)
    {
        if (isConstructor)
        {
            if (type != null)
            {
                throw new ParseException("Type attribute not allowed in constructor specification ["+type+"]");
            }

            if (parameters != null)
            {
                type = JavaConstants.TYPE_VOID;
            }

            name = ClassConstants.METHOD_NAME_INIT;
        }
        else if ((type != null) ^ (parameters != null))
        {
            throw new ParseException("Type and parameters attributes must always be present in combination in method specification");
        }
    }
    else
    {
        if (parameters != null)
        {
            throw new ParseException("Parameters attribute not allowed in field specification ["+parameters+"]");
        }
    }

    List parameterList = ListUtil.commaSeparatedList(parameters);

    String descriptor =
        parameters != null ? ClassUtil.internalMethodDescriptor(type, parameterList) :
        type       != null ? ClassUtil.internalType(type)                            :
                             null;

    return new MemberSpecification(requiredMemberAccessFlags(true,  access),
                                   requiredMemberAccessFlags(false, access),
                                   annotation,
                                   name,
                                   descriptor);
}
 
Example 8
Source File: MemberSpecificationElement.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Adds the contents of this class member specification element to the given
 * list.
 * @param memberSpecifications the class member specifications to be
 *                                  extended.
 * @param isMethod                  specifies whether this specification
 *                                  refers to a method.
 * @param isConstructor             specifies whether this specification
 *                                  refers to a constructor.
 */
public void appendTo(List    memberSpecifications,
                     boolean isMethod,
                     boolean isConstructor)
{
    // Get the referenced file set, or else this one.
    MemberSpecificationElement memberSpecificationElement = isReference() ?
        (MemberSpecificationElement)getCheckedRef(this.getClass(),
                                                  this.getClass().getName()) :
        this;

    // Create a new class member specification.
    String access     = memberSpecificationElement.access;
    String type       = memberSpecificationElement.type;
    String annotation = memberSpecificationElement.annotation;
    String name       = memberSpecificationElement.name;
    String parameters = memberSpecificationElement.parameters;

    // Perform some basic conversions and checks on the attributes.
    if (annotation != null)
    {
        annotation = ClassUtil.internalType(annotation);
    }

    if (isMethod)
    {
        if (isConstructor)
        {
            if (type != null)
            {
                throw new BuildException("Type attribute not allowed in constructor specification ["+type+"]");
            }

            if (parameters != null)
            {
                type = JavaConstants.TYPE_VOID;
            }

            name = ClassConstants.METHOD_NAME_INIT;
        }
        else if ((type != null) ^ (parameters != null))
        {
            throw new BuildException("Type and parameters attributes must always be present in combination in method specification");
        }
    }
    else
    {
        if (parameters != null)
        {
            throw new BuildException("Parameters attribute not allowed in field specification ["+parameters+"]");
        }
    }

    List parameterList = ListUtil.commaSeparatedList(parameters);

    String descriptor =
        parameters != null ? ClassUtil.internalMethodDescriptor(type, parameterList) :
        type       != null ? ClassUtil.internalType(type)                            :
                             null;

    MemberSpecification memberSpecification =
        new MemberSpecification(requiredAccessFlags(true,  access),
                                requiredAccessFlags(false, access),
                                annotation,
                                name,
                                descriptor);

    // Add it to the list.
    memberSpecifications.add(memberSpecification);
}
 
Example 9
Source File: MemberSpecificationDialog.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the MemberSpecification currently represented in this dialog.
 */
public MemberSpecification getMemberSpecification()
{
    String annotationType = annotationTypeTextField.getText();
    String name           = nameTextField.getText();
    String type           = typeTextField.getText();
    String arguments      = argumentTypesTextField.getText();

    // Convert all class member specifications into the internal format.
    annotationType =
        annotationType.equals("") ||
        annotationType.equals("***") ? null : ClassUtil.internalType(annotationType);

    if (name.equals("") ||
        name.equals("*"))
    {
        name = null;
    }

    if (isField)
    {
        type =
            type.equals("") ||
            type.equals("***") ? null : ClassUtil.internalType(type);
    }
    else
    {
        if (type.equals(""))
        {
            type = JavaConstants.TYPE_VOID;
        }

        type =
            type     .equals("***") &&
            arguments.equals("...") ? null :
                ClassUtil.internalMethodDescriptor(type, ListUtil.commaSeparatedList(arguments));
    }

    MemberSpecification memberSpecification =
        new MemberSpecification(0, 0, annotationType, name, type);

    // Also get the access radio button settings.
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_PUBLIC,       publicRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_PRIVATE,      privateRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_PROTECTED,    protectedRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_STATIC,       staticRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_FINAL,        finalRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_SYNTHETIC,    syntheticRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_VOLATILE,     volatileRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_TRANSIENT,    transientRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_SYNCHRONIZED, synchronizedRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_NATIVE,       nativeRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_ABSTRACT,     abstractRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_STRICT,       strictRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_BRIDGE,       bridgeRadioButtons);
    getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.ACC_VARARGS,      varargsRadioButtons);

    return memberSpecification;
}