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

The following examples show how to use proguard.classfile.util.ClassUtil#internalType() . 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: ClassSpecificationElement.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new class specification corresponding to the contents of this
 * class specification element.
 */
protected ClassSpecification createClassSpecification(ClassSpecificationElement classSpecificationElement)
{
    String access            = classSpecificationElement.access;
    String annotation        = classSpecificationElement.annotation;
    String type              = classSpecificationElement.type;
    String name              = classSpecificationElement.name;
    String extendsAnnotation = classSpecificationElement.extendsAnnotation;
    String extends_          = classSpecificationElement.extends_;

    // For backward compatibility, allow a single "*" wildcard to match
    // any class.
    if (name != null &&
        name.equals(ANY_CLASS_KEYWORD))
    {
        name = null;
    }

    ClassSpecification classSpecification =
        new ClassSpecification(null,
                               requiredAccessFlags(true,  access, type),
                               requiredAccessFlags(false, access, type),
                               annotation        != null ? ClassUtil.internalType(annotation)        : null,
                               name              != null ? ClassUtil.internalClassName(name)         : null,
                               extendsAnnotation != null ? ClassUtil.internalType(extendsAnnotation) : null,
                               extends_          != null ? ClassUtil.internalClassName(extends_)     : null);

    for (int index = 0; index < fieldSpecifications.size(); index++)
    {
        classSpecification.addField((MemberSpecification)fieldSpecifications.get(index));
    }

    for (int index = 0; index < methodSpecifications.size(); index++)
    {
        classSpecification.addMethod((MemberSpecification)methodSpecifications.get(index));
    }

    return classSpecification;
}
 
Example 2
Source File: ClassSpecificationDialog.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the ClassSpecification currently represented in this dialog.
 */
public ClassSpecification getClassSpecification()
{
    String comments              = commentsTextArea.getText();
    String annotationType        = annotationTypeTextField.getText();
    String className             = classNameTextField.getText();
    String extendsAnnotationType = extendsAnnotationTypeTextField.getText();
    String extendsClassName      = extendsClassNameTextField.getText();

    ClassSpecification classSpecification =
        new ClassSpecification(comments.equals("")              ? null : comments,
                               0,
                               0,
                               annotationType.equals("")        ? null : ClassUtil.internalType(annotationType),
                               className.equals("") ||
                               className.equals("*")            ? null : ClassUtil.internalClassName(className),
                               extendsAnnotationType.equals("") ? null : ClassUtil.internalType(extendsAnnotationType),
                               extendsClassName.equals("")      ? null : ClassUtil.internalClassName(extendsClassName));

    // Also get the access radio button settings.
    getClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_PUBLIC,      publicRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_FINAL,       finalRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_ABSTRACT,    abstractRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_INTERFACE,   interfaceRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_ANNOTATTION, annotationRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_ENUM,        enumRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_SYNTHETIC,   syntheticRadioButtons);

    // Get the keep class member option lists.
    classSpecification.fieldSpecifications  = memberSpecificationsPanel.getMemberSpecifications(true);
    classSpecification.methodSpecifications = memberSpecificationsPanel.getMemberSpecifications(false);

    return classSpecification;
}
 
Example 3
Source File: ClassSpecificationElement.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new class specification corresponding to the contents of this
 * class specification element.
 */
protected ClassSpecification createClassSpecification(ClassSpecificationElement classSpecificationElement)
{
    String access            = classSpecificationElement.access;
    String annotation        = classSpecificationElement.annotation;
    String type              = classSpecificationElement.type;
    String name              = classSpecificationElement.name;
    String extendsAnnotation = classSpecificationElement.extendsAnnotation;
    String extends_          = classSpecificationElement.extends_;

    // For backward compatibility, allow a single "*" wildcard to match
    // any class.
    if (name != null &&
        name.equals(ANY_CLASS_KEYWORD))
    {
        name = null;
    }

    ClassSpecification classSpecification =
        new ClassSpecification(null,
                               requiredAccessFlags(true,  access, type),
                               requiredAccessFlags(false, access, type),
                               annotation        != null ? ClassUtil.internalType(annotation)        : null,
                               name              != null ? ClassUtil.internalClassName(name)         : null,
                               extendsAnnotation != null ? ClassUtil.internalType(extendsAnnotation) : null,
                               extends_          != null ? ClassUtil.internalClassName(extends_)     : null);

    for (int index = 0; index < fieldSpecifications.size(); index++)
    {
        classSpecification.addField((MemberSpecification)fieldSpecifications.get(index));
    }

    for (int index = 0; index < methodSpecifications.size(); index++)
    {
        classSpecification.addMethod((MemberSpecification)methodSpecifications.get(index));
    }

    return classSpecification;
}
 
Example 4
Source File: ProGuardTask.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a specification of classes and class members, based on the
 * given parameters.
 */
private ClassSpecification createClassSpecification(Map     classSpecificationArgs,
                                                    Closure classMembersClosure)
throws ParseException
{
    // Extract the arguments.
    String access            = (String)classSpecificationArgs.get("access");
    String annotation        = (String)classSpecificationArgs.get("annotation");
    String type              = (String)classSpecificationArgs.get("type");
    String name              = (String)classSpecificationArgs.get("name");
    String extendsAnnotation = (String)classSpecificationArgs.get("extendsannotation");
    String extends_          = (String)classSpecificationArgs.get("extends");
    if (extends_ == null)
    {
        extends_             = (String)classSpecificationArgs.get("implements");
    }

    // Create the class specification.
    ClassSpecification classSpecification =
        new ClassSpecification(null,
                               requiredClassAccessFlags(true, access, type),
                               requiredClassAccessFlags(false, access, type),
                               annotation        != null ? ClassUtil.internalType(annotation)        : null,
                               name              != null ? ClassUtil.internalClassName(name)         : null,
                               extendsAnnotation != null ? ClassUtil.internalType(extendsAnnotation) : null,
                               extends_          != null ? ClassUtil.internalClassName(extends_)     : null);

    // Initialize the class specification with its closure.
    if (classMembersClosure != null)
    {
        // Temporarily remember the class specification, so we can add
        // class member specifications.
        this.classSpecification = classSpecification;
        classMembersClosure.call(classSpecification);
        this.classSpecification = null;
    }

    return classSpecification;
}
 
Example 5
Source File: ClassSpecificationElement.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new class specification corresponding to the contents of this
 * class specification element.
 */
protected ClassSpecification createClassSpecification(ClassSpecificationElement classSpecificationElement)
{
    String access            = classSpecificationElement.access;
    String annotation        = classSpecificationElement.annotation;
    String type              = classSpecificationElement.type;
    String name              = classSpecificationElement.name;
    String extendsAnnotation = classSpecificationElement.extendsAnnotation;
    String extends_          = classSpecificationElement.extends_;

    // For backward compatibility, allow a single "*" wildcard to match
    // any class.
    if (name != null &&
        name.equals(ANY_CLASS_KEYWORD))
    {
        name = null;
    }

    ClassSpecification classSpecification =
        new ClassSpecification(null,
                               requiredAccessFlags(true,  access, type),
                               requiredAccessFlags(false, access, type),
                               annotation        != null ? ClassUtil.internalType(annotation)        : null,
                               name              != null ? ClassUtil.internalClassName(name)         : null,
                               extendsAnnotation != null ? ClassUtil.internalType(extendsAnnotation) : null,
                               extends_          != null ? ClassUtil.internalClassName(extends_)     : null);

    for (int index = 0; index < fieldSpecifications.size(); index++)
    {
        classSpecification.addField((MemberSpecification)fieldSpecifications.get(index));
    }

    for (int index = 0; index < methodSpecifications.size(); index++)
    {
        classSpecification.addMethod((MemberSpecification)methodSpecifications.get(index));
    }

    return classSpecification;
}
 
Example 6
Source File: ProGuardTask.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a specification of classes and class members, based on the
 * given parameters.
 */
private ClassSpecification createClassSpecification(Map     classSpecificationArgs,
                                                    Closure classMembersClosure)
throws ParseException
{
    // Extract the arguments.
    String access            = (String)classSpecificationArgs.get("access");
    String annotation        = (String)classSpecificationArgs.get("annotation");
    String type              = (String)classSpecificationArgs.get("type");
    String name              = (String)classSpecificationArgs.get("name");
    String extendsAnnotation = (String)classSpecificationArgs.get("extendsannotation");
    String extends_          = (String)classSpecificationArgs.get("extends");
    if (extends_ == null)
    {
        extends_             = (String)classSpecificationArgs.get("implements");
    }

    // Create the class specification.
    ClassSpecification classSpecification =
        new ClassSpecification(null,
                               requiredClassAccessFlags(true, access, type),
                               requiredClassAccessFlags(false, access, type),
                               annotation        != null ? ClassUtil.internalType(annotation)        : null,
                               name              != null ? ClassUtil.internalClassName(name)         : null,
                               extendsAnnotation != null ? ClassUtil.internalType(extendsAnnotation) : null,
                               extends_          != null ? ClassUtil.internalClassName(extends_)     : null);

    // Initialize the class specification with its closure.
    if (classMembersClosure != null)
    {
        // Temporarily remember the class specification, so we can add
        // class member specifications.
        this.classSpecification = classSpecification;
        classMembersClosure.call(classSpecification);
        this.classSpecification = null;
    }

    return classSpecification;
}
 
Example 7
Source File: MappingKeeper.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void processFieldMapping(String className,
                                String fieldType,
                                String fieldName,
                                String newFieldName)
{
    if (clazz != null)
    {
        // Find the field.
        String name       = fieldName;
        String descriptor = ClassUtil.internalType(fieldType);

        Field field = clazz.findField(name, descriptor);
        if (field != null)
        {
            // Print out a warning if the mapping conflicts with a name that
            // was set before.
            if (warningPrinter != null)
            {
                String currentNewName = MemberObfuscator.newMemberName(field);
                if (currentNewName != null &&
                    !currentNewName.equals(newFieldName))
                {
                    warningPrinter.print(ClassUtil.internalClassName(className),
                                         "Warning: " +
                                         className +
                                         ": field '" + fieldType + " " + fieldName +
                                         "' is not being kept as '" + currentNewName +
                                         "', but remapped to '" + newFieldName + "'");
                }
            }

            // Make sure the mapping name will be kept.
            MemberObfuscator.setFixedNewMemberName(field, newFieldName);
        }
    }
}
 
Example 8
Source File: ClassSpecificationDialog.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the ClassSpecification currently represented in this dialog.
 */
public ClassSpecification getClassSpecification()
{
    String comments              = commentsTextArea.getText();
    String annotationType        = annotationTypeTextField.getText();
    String className             = classNameTextField.getText();
    String extendsAnnotationType = extendsAnnotationTypeTextField.getText();
    String extendsClassName      = extendsClassNameTextField.getText();

    ClassSpecification classSpecification =
        new ClassSpecification(comments.equals("")              ? null : comments,
                               0,
                               0,
                               annotationType.equals("")        ? null : ClassUtil.internalType(annotationType),
                               className.equals("") ||
                               className.equals("*")            ? null : ClassUtil.internalClassName(className),
                               extendsAnnotationType.equals("") ? null : ClassUtil.internalType(extendsAnnotationType),
                               extendsClassName.equals("")      ? null : ClassUtil.internalClassName(extendsClassName));

    // Also get the access radio button settings.
    getClassSpecificationRadioButtons(classSpecification, AccessConstants.PUBLIC,     publicRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, AccessConstants.FINAL,      finalRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, AccessConstants.ABSTRACT,   abstractRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, AccessConstants.INTERFACE,  interfaceRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, AccessConstants.ANNOTATION, annotationRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, AccessConstants.ENUM,       enumRadioButtons);
    getClassSpecificationRadioButtons(classSpecification, AccessConstants.SYNTHETIC,  syntheticRadioButtons);

    // Get the keep class member option lists.
    classSpecification.fieldSpecifications  = memberSpecificationsPanel.getMemberSpecifications(true);
    classSpecification.methodSpecifications = memberSpecificationsPanel.getMemberSpecifications(false);

    return classSpecification;
}
 
Example 9
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 10
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 11
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 12
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 13
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 14
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 15
Source File: ProGuardTask.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a specification of classes and class members, based on the
 * given parameters.
 */
private ClassSpecification createClassSpecification(boolean allowValues,
                                                    Map     classSpecificationArgs,
                                                    Closure classMembersClosure)
throws ParseException
{
    // Extract the arguments.
    String access            = (String)classSpecificationArgs.get("access");
    String annotation        = (String)classSpecificationArgs.get("annotation");
    String type              = (String)classSpecificationArgs.get("type");
    String name              = (String)classSpecificationArgs.get("name");
    String extendsAnnotation = (String)classSpecificationArgs.get("extendsannotation");
    String extends_          = (String)classSpecificationArgs.get("extends");
    if (extends_ == null)
    {
        extends_             = (String)classSpecificationArgs.get("implements");
    }

    // Create the class specification.
    ClassSpecification classSpecification =
        new ClassSpecification(null,
                               requiredClassAccessFlags(true, access, type),
                               requiredClassAccessFlags(false, access, type),
                               annotation        != null ? ClassUtil.internalType(annotation)        : null,
                               name              != null ? ClassUtil.internalClassName(name)         : null,
                               extendsAnnotation != null ? ClassUtil.internalType(extendsAnnotation) : null,
                               extends_          != null ? ClassUtil.internalClassName(extends_)     : null);

    // Initialize the class specification with its closure.
    if (classMembersClosure != null)
    {
        // Temporarily remember the class specification, so we can add
        // class member specifications.
        this.allowValues        = allowValues;
        this.classSpecification = classSpecification;
        classMembersClosure.call(classSpecification);
        this.allowValues        = false;
        this.classSpecification = null;
    }

    return classSpecification;
}
 
Example 16
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;
}
 
Example 17
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);
}