proguard.classfile.util.ClassUtil Java Examples

The following examples show how to use proguard.classfile.util.ClassUtil. 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: SimpleClassPrinter.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    ps.println(ClassUtil.externalFullClassDescription(
                   printAccessModifiers ?
                       programClass.getAccessFlags() :
                       0,
                   programClass.getName()) +
               ": " +
               ClassUtil.externalFullMethodDescription(
                   programClass.getName(),
                   printAccessModifiers ?
                       programMethod.getAccessFlags() :
                       0,
                   programMethod.getName(programClass),
                   programMethod.getDescriptor(programClass)));
}
 
Example #2
Source File: ClassObfuscator.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Does this class still need a new name?
    newClassName = newClassName(programClass);
    if (newClassName == null)
    {
        // Make sure the outer class has a name, if it exists. The name will
        // be stored as the new class name, as a side effect, so we'll be
        // able to use it as a prefix.
        programClass.attributesAccept(this);

        // Figure out a package prefix. The package prefix may actually be
        // the an outer class prefix, if any, or it may be the fixed base
        // package, if classes are to be repackaged.
        String newPackagePrefix = newClassName != null ?
            newClassName + ClassConstants.INTERNAL_INNER_CLASS_SEPARATOR :
            newPackagePrefix(ClassUtil.internalPackagePrefix(programClass.getName()));

        // Come up with a new class name, numeric or ordinary.
        newClassName = newClassName != null && numericClassName ?
            generateUniqueNumericClassName(newPackagePrefix) :
            generateUniqueClassName(newPackagePrefix);

        setNewClassName(programClass, newClassName);
    }
}
 
Example #3
Source File: SimpleClassPrinter.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
{
    ps.println(ClassUtil.externalFullClassDescription(
                   printAccessModifiers ?
                       libraryClass.getAccessFlags() :
                       0,
                   libraryClass.getName()) +
               ": " +
               ClassUtil.externalFullMethodDescription(
                   libraryClass.getName(),
                   printAccessModifiers ?
                       libraryMethod.getAccessFlags() :
                       0,
                   libraryMethod.getName(libraryClass),
                   libraryMethod.getDescriptor(libraryClass)));
}
 
Example #4
Source File: MemberReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Check if this class entry is an array type.
    if (ClassUtil.isInternalArrayType(classConstant.getName(clazz)))
    {
        isInterfaceMethod = false;
    }
    else
    {
        // Check if this class entry refers to an interface class.
        Clazz referencedClass = classConstant.referencedClass;
        if (referencedClass != null)
        {
            isInterfaceMethod = (referencedClass.getAccessFlags() & ClassConstants.INTERNAL_ACC_INTERFACE) != 0;
        }
    }
}
 
Example #5
Source File: OutputWriter.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a map of old package prefixes to new package prefixes, based on
 * the given class pool.
 */
private static Map createPackagePrefixMap(ClassPool classPool)
{
    Map packagePrefixMap = new HashMap();

    Iterator iterator = classPool.classNames();
    while (iterator.hasNext())
    {
        String className     = (String)iterator.next();
        String packagePrefix = ClassUtil.internalPackagePrefix(className);

        String mappedNewPackagePrefix = (String)packagePrefixMap.get(packagePrefix);
        if (mappedNewPackagePrefix == null ||
            !mappedNewPackagePrefix.equals(packagePrefix))
        {
            String newClassName     = classPool.getClass(className).getName();
            String newPackagePrefix = ClassUtil.internalPackagePrefix(newClassName);

            packagePrefixMap.put(packagePrefix, newPackagePrefix);
        }
    }

    return packagePrefixMap;
}
 
Example #6
Source File: KotlinModuleFixer.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
private static void createNewModulePackages(KotlinModule                                 kotlinModule,
                                            List<String>                                 existingPackageNames,
                                            Map<String, KotlinFileFacadeKindMetadata>    fileFacadesToMove,
                                            Map<String, KotlinMultiFilePartKindMetadata> multiFilePartsToMove)
{
    // Create a new package in the module for each of the classes packages
    // if they're not an already existing package.

    Stream.concat(fileFacadesToMove   .keySet().stream(),
                  multiFilePartsToMove.keySet().stream())
        .map(ClassUtil::internalPackageName)
        .distinct()
        .filter(packageName -> !existingPackageNames.contains(packageName))
        .map(   packageName -> new KotlinModulePackage(packageName, new ArrayList<>(), new HashMap<>()))
        .forEach(kotlinModule.modulePackages::add);
}
 
Example #7
Source File: KotlinAliasReferenceFixer.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitAnyType(Clazz clazz, KotlinTypeMetadata kotlinTypeMetadata)
{
    if (kotlinTypeMetadata.aliasName != null)
    {
        String newName;

        if (kotlinTypeMetadata.referencedTypeAlias.referencedDeclarationContainer.k == KotlinConstants.METADATA_KIND_CLASS)
        {
            // Type alias declared within a class.
            // Inner classes in Kotlin metadata have a '.' separator instead of the standard '$'.
            newName = ((KotlinClassKindMetadata)kotlinTypeMetadata.referencedTypeAlias.referencedDeclarationContainer).className + "." +
                      kotlinTypeMetadata.referencedTypeAlias.name;
        }
        else
        {
            // Top-level alias declaration.
            // Package is that of the file facade (which is a declaration container).
            newName =
                ClassUtil.internalPackagePrefix(kotlinTypeMetadata.referencedTypeAlias.referencedDeclarationContainer.ownerClassName) +
                kotlinTypeMetadata.referencedTypeAlias.name;
        }

        kotlinTypeMetadata.aliasName = newName;
    }
}
 
Example #8
Source File: ConfigurationWriter.java    From bazel with Apache License 2.0 6 votes vote down vote up
private void writeOption(String  optionName,
                         String  arguments,
                         boolean replaceInternalClassNames)
{
    if (arguments != null)
    {
        if (replaceInternalClassNames)
        {
            arguments = ClassUtil.externalClassName(arguments);
        }

        writer.print(optionName);
        writer.print(' ');
        writer.println(quotedString(arguments));
    }
}
 
Example #9
Source File: VariableSizeUpdater.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // The minimum variable size is determined by the arguments.
        codeAttribute.u2maxLocals =
            ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz),
                                                  method.getAccessFlags());

        if (DEBUG)
        {
            System.out.println("VariableSizeUpdater: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz));
            System.out.println("  Max locals: "+codeAttribute.u2maxLocals+" <- parameters");
        }

        // Go over all instructions.
        codeAttribute.instructionsAccept(clazz, method, this);

        // Remove the unused variables of the attributes.
        variableCleaner.visitCodeAttribute(clazz, method, codeAttribute);
    }
 
Example #10
Source File: BasicInvocationUnit.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitAnyMethodrefConstant(Clazz clazz, RefConstant methodrefConstant)
{
    String type = methodrefConstant.getType(clazz);

    // Count the number of parameters.
    int parameterCount = ClassUtil.internalMethodParameterCount(type);
    if (!isStatic)
    {
        parameterCount++;
    }

    // Pop the parameters and the class reference, in reverse order.
    for (int parameterIndex = parameterCount-1; parameterIndex >= 0; parameterIndex--)
    {
        setMethodParameterValue(clazz, methodrefConstant, parameterIndex, stack.pop());
    }

    // Push the return value, if applicable.
    String returnType = ClassUtil.internalMethodReturnType(type);
    if (returnType.charAt(0) != ClassConstants.INTERNAL_TYPE_VOID)
    {
        stack.push(getMethodReturnValue(clazz, methodrefConstant, returnType));
    }
}
 
Example #11
Source File: ValueFactory.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new Value of the given type.
 * The type must be a fully specified internal type for primitives, classes,
 * or arrays.
 */
public Value createValue(String type, Clazz referencedClass, boolean mayBeNull)
{
    switch (type.charAt(0))
    {
        case ClassConstants.INTERNAL_TYPE_VOID:    return null;
        case ClassConstants.INTERNAL_TYPE_BOOLEAN:
        case ClassConstants.INTERNAL_TYPE_BYTE:
        case ClassConstants.INTERNAL_TYPE_CHAR:
        case ClassConstants.INTERNAL_TYPE_SHORT:
        case ClassConstants.INTERNAL_TYPE_INT:     return createIntegerValue();
        case ClassConstants.INTERNAL_TYPE_LONG:    return createLongValue();
        case ClassConstants.INTERNAL_TYPE_FLOAT:   return createFloatValue();
        case ClassConstants.INTERNAL_TYPE_DOUBLE:  return createDoubleValue();
        default:                                   return createReferenceValue(ClassUtil.isInternalArrayType(type) ?
                                                                                   type :
                                                                                   ClassUtil.internalClassNameFromClassType(type),
                                                                               referencedClass,
                                                                               mayBeNull);
    }
}
 
Example #12
Source File: ConstantParameterFilter.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    int firstParameterIndex =
        (programMethod.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) != 0 ?
            0 : 1;

    int parameterCount =
        ClassUtil.internalMethodParameterCount(programMethod.getDescriptor(programClass));

    for (int index = firstParameterIndex; index < parameterCount; index++)
    {
        Value value = StoringInvocationUnit.getMethodParameterValue(programMethod, index);
        if (value != null &&
            value.isParticular())
        {
            constantParameterVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example #13
Source File: ChangedCodePrinter.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
private void printChangedCode(Clazz         clazz,
                              Method        method,
                              CodeAttribute codeAttribute,
                              byte[]        oldCode)
{
    System.out.println("Class "+ClassUtil.externalClassName(clazz.getName()));
    System.out.println("Method "+ClassUtil.externalFullMethodDescription(clazz.getName(),
                                                                         0,
                                                                         method.getName(clazz),
                                                                         method.getDescriptor(clazz)));

    for (int index = 0; index < codeAttribute.u4codeLength; index++)
    {
        System.out.println(
            (oldCode[index] == codeAttribute.code[index]? "  -- ":"  => ")+
            index+": "+
            Integer.toHexString(0x100|oldCode[index]           &0xff).substring(1)+" "+
            Integer.toHexString(0x100|codeAttribute.code[index]&0xff).substring(1));
    }
}
 
Example #14
Source File: ValueFactory.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new Value of the given type.
 * The type must be a fully specified internal type for primitives, classes,
 * or arrays.
 */
public Value createValue(String type, Clazz referencedClass, boolean mayBeNull)
{
    switch (type.charAt(0))
    {
        case ClassConstants.TYPE_VOID:    return null;
        case ClassConstants.TYPE_BOOLEAN:
        case ClassConstants.TYPE_BYTE:
        case ClassConstants.TYPE_CHAR:
        case ClassConstants.TYPE_SHORT:
        case ClassConstants.TYPE_INT:     return createIntegerValue();
        case ClassConstants.TYPE_LONG:    return createLongValue();
        case ClassConstants.TYPE_FLOAT:   return createFloatValue();
        case ClassConstants.TYPE_DOUBLE:  return createDoubleValue();
        default:                          return createReferenceValue(ClassUtil.isInternalArrayType(type) ?
                                                                          type :
                                                                          ClassUtil.internalClassNameFromClassType(type),
                                                                      referencedClass,
                                                                      mayBeNull);
    }
}
 
Example #15
Source File: ClassPrinter.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    println(visitorInfo(programField) + " " +
            "Field:        " +
            programField.getName(programClass) + " " +
            programField.getDescriptor(programClass));

    indent();
    println("Access flags: 0x" + Integer.toHexString(programField.u2accessFlags));
    println("  = " +
            ClassUtil.externalFullFieldDescription(programField.u2accessFlags,
                                                   programField.getName(programClass),
                                                   programField.getDescriptor(programClass)));

    visitMember(programClass, programField);
    outdent();
}
 
Example #16
Source File: OutputWriter.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a map of old package prefixes to new package prefixes, based on
 * the given class pool.
 */
private static Map createPackagePrefixMap(ClassPool classPool)
{
    Map packagePrefixMap = new HashMap();

    Iterator iterator = classPool.classNames();
    while (iterator.hasNext())
    {
        String className     = (String)iterator.next();
        String packagePrefix = ClassUtil.internalPackagePrefix(className);

        String mappedNewPackagePrefix = (String)packagePrefixMap.get(packagePrefix);
        if (mappedNewPackagePrefix == null ||
            !mappedNewPackagePrefix.equals(packagePrefix))
        {
            String newClassName     = classPool.getClass(className).getName();
            String newPackagePrefix = ClassUtil.internalPackagePrefix(newClassName);

            packagePrefixMap.put(packagePrefix, newPackagePrefix);
        }
    }

    return packagePrefixMap;
}
 
Example #17
Source File: ClassPrinter.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
{
    println(visitorInfo(libraryMethod) + " " +
            "Method:       " +
            libraryMethod.getName(libraryClass) + " " +
            libraryMethod.getDescriptor(libraryClass));

    indent();
    println("Access flags: 0x" + Integer.toHexString(libraryMethod.u2accessFlags));
    println("  = " +
            ClassUtil.externalFullMethodDescription(libraryClass.getName(),
                                                    libraryMethod.u2accessFlags,
                                                    libraryMethod.getName(libraryClass),
                                                    libraryMethod.getDescriptor(libraryClass)));
    outdent();
}
 
Example #18
Source File: ProgramClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
{
    // Read the parameter annotations.
    parameterAnnotationsAttribute.u2parametersCount           = dataInput.readUnsignedByte();

    // The java compilers of JDK 1.5, JDK 1.6, and Eclipse all count the
    // number of parameters of constructors of non-static inner classes
    // incorrectly. Fix it right here.
    int parameterStart = 0;
    if (method.getName(clazz).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT))
    {
        int realParametersCount = ClassUtil.internalMethodParameterCount(method.getDescriptor(clazz));
        parameterStart = realParametersCount - parameterAnnotationsAttribute.u2parametersCount;
        parameterAnnotationsAttribute.u2parametersCount = realParametersCount;
    }

    parameterAnnotationsAttribute.u2parameterAnnotationsCount = new int[parameterAnnotationsAttribute.u2parametersCount];
    parameterAnnotationsAttribute.parameterAnnotations        = new Annotation[parameterAnnotationsAttribute.u2parametersCount][];

    for (int parameterIndex = parameterStart; parameterIndex < parameterAnnotationsAttribute.u2parametersCount; parameterIndex++)
    {
        // Read the parameter annotations of the given parameter.
        int u2annotationsCount = dataInput.readUnsignedShort();

        Annotation[] annotations = new Annotation[u2annotationsCount];

        for (int index = 0; index < u2annotationsCount; index++)
        {
            Annotation annotation = new Annotation();
            this.visitAnnotation(clazz, annotation);
            annotations[index] = annotation;
        }

        parameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex] = u2annotationsCount;
        parameterAnnotationsAttribute.parameterAnnotations[parameterIndex]        = annotations;
    }
}
 
Example #19
Source File: ShortestUsagePrinter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
{
    // Print the name of this method.
    String name = libraryMethod.getName(libraryClass);
    String type = libraryMethod.getDescriptor(libraryClass);

    ps.println(ClassUtil.externalClassName(libraryClass.getName()) +
               (verbose ?
                    ": " + ClassUtil.externalFullMethodDescription(libraryClass.getName(), 0, name, type):
                    "."  + name));

    // Print the reason for keeping this method.
    ps.println("  is a library method.\n");
}
 
Example #20
Source File: ShortestUsagePrinter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
{
    // Print the name of this field.
    String name = libraryField.getName(libraryClass);
    String type = libraryField.getDescriptor(libraryClass);

    ps.println(ClassUtil.externalClassName(libraryClass.getName()) +
               (verbose ?
                    ": " + ClassUtil.externalFullFieldDescription(0, name, type):
                    "."  + name));

    // Print the reason for keeping this field.
    ps.println("  is a library field.\n");
}
 
Example #21
Source File: TypedReferenceValue.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public ReferenceValue referenceArrayLoad(IntegerValue indexValue, ValueFactory valueFactory)
{
    return
        type == null                         ? ValueFactory.REFERENCE_VALUE_NULL                        :
        !ClassUtil.isInternalArrayType(type) ? ValueFactory.REFERENCE_VALUE_JAVA_LANG_OBJECT_MAYBE_NULL :
                                               valueFactory.createValue(type.substring(1),
                                                                        referencedClass,
                                                                        true).referenceValue();
}
 
Example #22
Source File: ProGuardGUI.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Looks in the given list for keep specifications that match the given
 * template. Returns a comma-separated string of class names from
 * matching keep specifications, and removes the matching keep
 * specifications as a side effect.
 */
private String findMatchingKeepSpecifications(KeepClassSpecification keepClassSpecificationTemplate,
                                              List              keepSpecifications)
{
    if (keepSpecifications == null)
    {
        return null;
    }

    StringBuffer buffer = null;

    for (int index = 0; index < keepSpecifications.size(); index++)
    {
        KeepClassSpecification listedKeepClassSpecification =
            (KeepClassSpecification)keepSpecifications.get(index);
        String className = listedKeepClassSpecification.className;
        keepClassSpecificationTemplate.className = className;
        if (keepClassSpecificationTemplate.equals(listedKeepClassSpecification))
        {
            if (buffer == null)
            {
                buffer = new StringBuffer();
            }
            else
            {
                buffer.append(',');
            }
            buffer.append(className == null ? "*" : ClassUtil.externalClassName(className));

            // Remove the matching option as a side effect.
            keepSpecifications.remove(index--);
        }
    }

    return buffer == null ? null : buffer.toString();
}
 
Example #23
Source File: ShortestUsagePrinter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitLibraryClass(LibraryClass libraryClass)
{
    // Print the name of this class.
    ps.println(ClassUtil.externalClassName(libraryClass.getName()));

    // Print the reason for keeping this class.
    ps.println("  is a library class.\n");
}
 
Example #24
Source File: ShortestUsagePrinter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Print the name of this class.
    ps.println(ClassUtil.externalClassName(programClass.getName()));

    // Print the reason for keeping this class.
    printReason(programClass);
}
 
Example #25
Source File: ClassSpecificationDialog.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the ClassSpecification to be represented in this dialog.
 */
public void setClassSpecification(ClassSpecification classSpecification)
{
    String comments              = classSpecification.comments;
    String annotationType        = classSpecification.annotationType;
    String className             = classSpecification.className;
    String extendsAnnotationType = classSpecification.extendsAnnotationType;
    String extendsClassName      = classSpecification.extendsClassName;
    List   keepFieldOptions      = classSpecification.fieldSpecifications;
    List   keepMethodOptions     = classSpecification.methodSpecifications;

    // Set the comments text area.
    commentsTextArea.setText(comments == null ? "" : comments);

    // Set the access radio buttons.
    setClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_PUBLIC,      publicRadioButtons);
    setClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_FINAL,       finalRadioButtons);
    setClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_ABSTRACT,    abstractRadioButtons);
    setClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_INTERFACE,   interfaceRadioButtons);
    setClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_ANNOTATTION, annotationRadioButtons);
    setClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_ENUM,        enumRadioButtons);
    setClassSpecificationRadioButtons(classSpecification, ClassConstants.ACC_SYNTHETIC,   syntheticRadioButtons);

    // Set the class and annotation text fields.
    annotationTypeTextField       .setText(annotationType        == null ? ""  : ClassUtil.externalType(annotationType));
    classNameTextField            .setText(className             == null ? "*" : ClassUtil.externalClassName(className));
    extendsAnnotationTypeTextField.setText(extendsAnnotationType == null ? ""  : ClassUtil.externalType(extendsAnnotationType));
    extendsClassNameTextField     .setText(extendsClassName      == null ? ""  : ClassUtil.externalClassName(extendsClassName));

    // Set the keep class member option list.
    memberSpecificationsPanel.setMemberSpecifications(keepFieldOptions, keepMethodOptions);
}
 
Example #26
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 #27
Source File: KeepClassMemberChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the given class specifications try to keep class members
 * without actually specifying any, printing notes if necessary. Returns
 * the number of notes printed.
 */
public void checkClassSpecifications(List keepClassSpecifications)
{
    if (keepClassSpecifications != null)
    {
        for (int index = 0; index < keepClassSpecifications.size(); index++)
        {
            KeepClassSpecification keepClassSpecification =
                (KeepClassSpecification)keepClassSpecifications.get(index);

            if (!keepClassSpecification.markClasses                      &&
                (keepClassSpecification.fieldSpecifications  == null ||
                 keepClassSpecification.fieldSpecifications.size() == 0) &&
                (keepClassSpecification.methodSpecifications == null ||
                 keepClassSpecification.methodSpecifications.size() == 0))
            {
                String className = keepClassSpecification.className;

                if (notePrinter.accepts(className))
                {
                    notePrinter.print(className,
                                      "Note: the configuration doesn't specify which class members to keep for class '" +
                                      ClassUtil.externalClassName(className) + "'");
                }
            }
        }
    }
}
 
Example #28
Source File: ClassSpecificationDialog.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a suitable label summarizing the given class specification at
 * some given index.
 */
public String label(ClassSpecification classSpecification, int index)
{
    return
        classSpecification                       == null ? msg("none")                                                                                                        :
        classSpecification.comments              != null ? classSpecification.comments.trim()                                                                                 :
        classSpecification.className             != null ? (msg("class") + ' ' + ClassUtil.externalClassName(classSpecification.className))                                   :
        classSpecification.annotationType        != null ? (msg("classesAnnotatedWith") + ' ' + ClassUtil.externalType(classSpecification.annotationType))                    :
        classSpecification.extendsClassName      != null ? (msg("extensionsOf") + ' ' + ClassUtil.externalClassName(classSpecification.extendsClassName))                     :
        classSpecification.extendsAnnotationType != null ? (msg("extensionsOfClassesAnnotatedWith") + ' ' + ClassUtil.externalType(classSpecification.extendsAnnotationType)) :
        index                                    >= 0    ? (msg("specificationNumber") + index)                                                                               :
                                                           msg("specification");
}
 
Example #29
Source File: ProGuardTask.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the given filter to the given list, creating a new list if
 * necessary. External class names are converted to internal class names,
 * if requested.
 */
private List extendFilter(List    filter,
                          String  filterString,
                          boolean convertExternalClassNames)
{
    if (filter == null)
    {
        filter = new ArrayList();
    }

    if (filterString == null)
    {
        // Clear the filter to keep all names.
        filter.clear();
    }
    else
    {
        if (convertExternalClassNames)
        {
            filterString = ClassUtil.internalClassName(filterString);
        }

        // Append the filter.
        filter.addAll(ListUtil.commaSeparatedList(filterString));
    }

    return filter;
}
 
Example #30
Source File: SimpleClassPrinter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
{
    ps.println(ClassUtil.externalFullClassDescription(
                   printAccessModifiers ?
                       libraryClass.getAccessFlags() :
                       0,
                   libraryClass.getName()) +
               ": " +
               ClassUtil.externalFullFieldDescription(
                   printAccessModifiers ?
                       libraryField.getAccessFlags() :
                       0,
                   libraryField.getName(libraryClass),
                   libraryField.getDescriptor(libraryClass)));
}