Java Code Examples for proguard.classfile.util.ClassUtil

The following examples show how to use proguard.classfile.util.ClassUtil. These examples are extracted from open source projects. 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 Project: proguard   Source File: OutputWriter.java    License: 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 2
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 3
Source Project: proguard   Source File: SimpleClassPrinter.java    License: 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 Project: java-n-IDE-for-Android   Source File: ClassObfuscator.java    License: 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 5
Source Project: proguard   Source File: KotlinModuleFixer.java    License: 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 6
@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 7
Source Project: bazel   Source File: ConfigurationWriter.java    License: 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 8
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 9
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 10
Source Project: java-n-IDE-for-Android   Source File: ValueFactory.java    License: 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 11
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 12
Source Project: proguard   Source File: ChangedCodePrinter.java    License: 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 13
Source Project: bazel   Source File: ValueFactory.java    License: 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 14
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: 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 15
Source Project: bazel   Source File: OutputWriter.java    License: 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 16
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: 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 17
Source Project: proguard   Source File: SimpleClassPrinter.java    License: 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 18
/**
 * 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 19
Source Project: java-n-IDE-for-Android   Source File: MappingPrinter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    String name    = programClass.getName();
    String newName = ClassObfuscator.newClassName(programClass);

    ps.println(ClassUtil.externalClassName(name) +
               " -> " +
               ClassUtil.externalClassName(newName) +
               ":");

    // Print out the class members.
    programClass.fieldsAccept(this);
    programClass.methodsAccept(this);
}
 
Example 20
Source Project: proguard   Source File: TypedReferenceValue.java    License: 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 21
Source Project: bazel   Source File: ClassSpecificationDialog.java    License: 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 22
/**
 * 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 23
Source Project: bazel   Source File: MemberSpecificationDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the MemberSpecification to be represented in this dialog.
 */
public void setMemberSpecification(MemberSpecification memberSpecification)
{
    String annotationType = memberSpecification.annotationType;
    String name           = memberSpecification.name;
    String descriptor     = memberSpecification.descriptor;

    // Set the class name text fields.
    annotationTypeTextField.setText(annotationType == null ? "" : ClassUtil.externalType(annotationType));

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

    // Set the class name text fields.
    nameTextField.setText(name == null ? "*" : name);

    if (isField)
    {
        typeTextField         .setText(descriptor == null ? "***" : ClassUtil.externalType(descriptor));
    }
    else
    {
        typeTextField         .setText(descriptor == null ? "***" : ClassUtil.externalMethodReturnType(descriptor));
        argumentTypesTextField.setText(descriptor == null ? "..." : ClassUtil.externalMethodArguments(descriptor));
    }
}
 
Example 24
Source Project: bazel   Source File: ProGuardTask.java    License: 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 25
Source Project: proguard   Source File: KotlinModuleFixer.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void addFileFacadesToModule(KotlinModule                              kotlinModule,
                                           Map<String, KotlinFileFacadeKindMetadata> fileFacadesToMove)
{
    fileFacadesToMove.forEach((fileFacadeName, referencedFileFacade) ->
        kotlinModule.modulePackagesAccept((__, modulePackage) -> {
            if (modulePackage.fqName.equals(ClassUtil.internalPackageName(fileFacadeName)))
            {
                modulePackage.fileFacadeNames      .add(fileFacadeName);
                modulePackage.referencedFileFacades.add(referencedFileFacade);
            }
        }));
}
 
Example 26
Source Project: proguard   Source File: SimpleClassPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitLibraryClass(LibraryClass libraryClass)
{
    ps.println(ClassUtil.externalFullClassDescription(
                   printAccessModifiers ?
                       libraryClass.getAccessFlags() :
                       0,
                   libraryClass.getName()));
}
 
Example 27
Source Project: proguard   Source File: ProGuardTask.java    License: 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 28
Source Project: bazel   Source File: SimpleClassPrinter.java    License: Apache License 2.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)));
}
 
Example 29
Source Project: bazel   Source File: ConfigurationWriter.java    License: Apache License 2.0 5 votes vote down vote up
private void writeFieldSpecification(List memberSpecifications)
{
    if (memberSpecifications != null)
    {
        for (int index = 0; index < memberSpecifications.size(); index++)
        {
            MemberSpecification memberSpecification =
                (MemberSpecification)memberSpecifications.get(index);

            writer.print("    ");

            // Write out the required annotation, if any.
            if (memberSpecification.annotationType != null)
            {
                writer.print(ConfigurationConstants.ANNOTATION_KEYWORD);
                writer.println(ClassUtil.externalType(memberSpecification.annotationType));
                writer.print("    ");
            }

            // Write out the field access flags.
            writer.print(ClassUtil.externalFieldAccessFlags(memberSpecification.requiredUnsetAccessFlags,
                                                            ConfigurationConstants.NEGATOR_KEYWORD));

            writer.print(ClassUtil.externalFieldAccessFlags(memberSpecification.requiredSetAccessFlags));

            // Write out the field name and descriptor.
            String name       = memberSpecification.name;
            String descriptor = memberSpecification.descriptor;

            writer.print(descriptor == null ? name == null ?
                ConfigurationConstants.ANY_FIELD_KEYWORD             :
                ConfigurationConstants.ANY_TYPE_KEYWORD + ' ' + name :
                ClassUtil.externalFullFieldDescription(0,
                                                       name == null ? ConfigurationConstants.ANY_CLASS_MEMBER_KEYWORD : name,
                                                       descriptor));

            writer.println(ConfigurationConstants.SEPARATOR_KEYWORD);
        }
    }
}
 
Example 30
Source Project: proguard   Source File: SimpleClassPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    ps.println(ClassUtil.externalFullClassDescription(
                   printAccessModifiers ?
                       programClass.getAccessFlags() :
                       0,
                   programClass.getName()));
}