Java Code Examples for proguard.classfile.ProgramClass#equals()

The following examples show how to use proguard.classfile.ProgramClass#equals() . 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: AccessFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramMember(ProgramClass programClass, ProgramMember programMember)
{
    int currentAccessFlags = programMember.getAccessFlags();
    int currentAccessLevel = AccessUtil.accessLevel(currentAccessFlags);

    // Compute the required access level.
    int requiredAccessLevel =
        programClass.equals(referencingClass)         ? AccessUtil.PRIVATE         :
        inSamePackage(programClass, referencingClass) ? AccessUtil.PACKAGE_VISIBLE :
        referencedClass.extends_(referencingClass) &&
        referencingClass.extends_(programClass)       ? AccessUtil.PROTECTED       :
                                                        AccessUtil.PUBLIC;

    // Fix the class member access flags if necessary.
    if (currentAccessLevel < requiredAccessLevel)
    {
        programMember.u2accessFlags =
            AccessUtil.replaceAccessFlags(currentAccessFlags,
                                          AccessUtil.accessFlags(requiredAccessLevel));
    }
}
 
Example 2
Source File: ExceptClassFilter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    if (!programClass.equals(exceptClass))
    {
        classVisitor.visitProgramClass(programClass);
    }
}
 
Example 3
Source File: MemberToClassVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    if (!programClass.equals(lastVisitedClass))
    {
        classVisitor.visitProgramClass(programClass);

        lastVisitedClass = programClass;
    }
}
 
Example 4
Source File: MemberToClassVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    if (!programClass.equals(lastVisitedClass))
    {
        classVisitor.visitProgramClass(programClass);

        lastVisitedClass = programClass;
    }
}
 
Example 5
Source File: SideEffectInstructionChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    hasSideEffects =
        (ReadWriteFieldMarker.isRead(programField) &&
         ReadWriteFieldMarker.isWritten(programField))                                ||
        ((programField.getAccessFlags() & ClassConstants.INTERNAL_ACC_VOLATILE) != 0) ||
        (!programClass.equals(referencingClass) &&
         !initializedSuperClasses(referencingClass).containsAll(initializedSuperClasses(programClass)));
}
 
Example 6
Source File: SideEffectInstructionChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // Note that side effects already include synchronization of some
    // implementation of the method.
    hasSideEffects =
        !NoSideEffectMethodMarker.hasNoSideEffects(programMethod) &&
        (SideEffectMethodMarker.hasSideEffects(programMethod) ||
         (!programClass.equals(referencingClass) &&
          !initializedSuperClasses(referencingClass).containsAll(initializedSuperClasses(programClass))));
}
 
Example 7
Source File: TargetClassChanger.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Change the references of the constant pool.
    programClass.constantPoolEntriesAccept(this);

    // Change the references of the class members.
    programClass.fieldsAccept(this);
    programClass.methodsAccept(this);

    // Change the references of the attributes.
    programClass.attributesAccept(this);

    // Is the class itself being retargeted?
    Clazz targetClass = ClassMerger.getTargetClass(programClass);
    if (targetClass != null)
    {
        // Restore the class name. We have to add a new class entry
        // to avoid an existing entry with the same name being reused. The
        // names have to be fixed later, based on their referenced classes.
        programClass.u2thisClass =
            addNewClassConstant(programClass,
                                programClass.getName(),
                                programClass);

        // This class will loose all its interfaces.
        programClass.u2interfacesCount = 0;

        // This class will loose all its subclasses.
        programClass.subClasses = null;
    }
    else
    {
        // Remove interface classes that are pointing to this class.
        int newInterfacesCount = 0;
        for (int index = 0; index < programClass.u2interfacesCount; index++)
        {
            Clazz interfaceClass = programClass.getInterface(index);
            if (!programClass.equals(interfaceClass))
            {
                programClass.u2interfaces[newInterfacesCount++] =
                    programClass.u2interfaces[index];
            }
        }
        programClass.u2interfacesCount = newInterfacesCount;

        // Update the subclasses of the superclass and interfaces of the
        // target class.
        ConstantVisitor subclassAdder =
            new ReferencedClassVisitor(
            new SubclassFilter(programClass,
            new SubclassAdder(programClass)));

        programClass.superClassConstantAccept(subclassAdder);
        programClass.interfaceConstantsAccept(subclassAdder);

        // TODO: Maybe restore private method references.
    }
}
 
Example 8
Source File: MethodInliner.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
    {
        int accessFlags = programMethod.getAccessFlags();

        if (// Only inline the method if it is private, static, or final.
            (accessFlags & (ClassConstants.INTERNAL_ACC_PRIVATE |
                            ClassConstants.INTERNAL_ACC_STATIC  |
                            ClassConstants.INTERNAL_ACC_FINAL)) != 0                              &&

            // Only inline the method if it is not synchronized, etc.
            (accessFlags & (ClassConstants.INTERNAL_ACC_SYNCHRONIZED |
                            ClassConstants.INTERNAL_ACC_NATIVE       |
                            ClassConstants.INTERNAL_ACC_INTERFACE    |
                            ClassConstants.INTERNAL_ACC_ABSTRACT)) == 0                           &&

            // Don't inline an <init> method, except in an <init> method in the
            // same class.
//            (!programMethod.getName(programClass).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT) ||
//             (programClass.equals(targetClass) &&
//              targetMethod.getName(targetClass).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT))) &&
            !programMethod.getName(programClass).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT) &&

            // Don't inline a method into itself.
            (!programMethod.equals(targetMethod) ||
             !programClass.equals(targetClass))                                                   &&

            // Only inline the method if it isn't recursing.
            !inliningMethods.contains(programMethod)                                              &&

            // Only inline the method if its target class has at least the
            // same version number as the source class, in order to avoid
            // introducing incompatible constructs.
            targetClass.u4version >= programClass.u4version                                       &&

            // Only inline the method if it doesn't invoke a super method, or if
            // it is in the same class.
            (!SuperInvocationMarker.invokesSuperMethods(programMethod) ||
             programClass.equals(targetClass))                                                    &&

            // Only inline the method if it doesn't branch backward while there
            // are uninitialized objects.
            (!BackwardBranchMarker.branchesBackward(programMethod) ||
             uninitializedObjectCount == 0)                                                       &&

            // Only inline if the code access of the inlined method allows it.
            (allowAccessModification ||
             ((!AccessMethodMarker.accessesPrivateCode(programMethod) ||
               programClass.equals(targetClass)) &&

              (!AccessMethodMarker.accessesPackageCode(programMethod) ||
               ClassUtil.internalPackageName(programClass.getName()).equals(
               ClassUtil.internalPackageName(targetClass.getName())))))                           &&

//               (!AccessMethodMarker.accessesProtectedCode(programMethod) ||
//                targetClass.extends_(programClass) ||
//                targetClass.implements_(programClass)) ||
            (!AccessMethodMarker.accessesProtectedCode(programMethod) ||
             programClass.equals(targetClass))                                                    &&

            // Only inline the method if it doesn't catch exceptions, or if it
            // is invoked with an empty stack.
            (!CatchExceptionMarker.catchesExceptions(programMethod) ||
             emptyInvokingStack)                                                                  &&

            // Only inline the method if it comes from the a class with at most
            // a subset of the initialized superclasses.
            (programClass.equals(targetClass) ||
             initializedSuperClasses(targetClass).containsAll(initializedSuperClasses(programClass))))
        {                                                                                                   boolean oldInlining = inlining;
            inlining = true;
            inliningMethods.push(programMethod);

            // Inline the method body.
            programMethod.attributesAccept(programClass, this);

            // Update the optimization information of the target method.
            MethodOptimizationInfo info =
                MethodOptimizationInfo.getMethodOptimizationInfo(targetMethod);
            if (info != null)
            {
                info.merge(MethodOptimizationInfo.getMethodOptimizationInfo(programMethod));
            }

            inlining = oldInlining;
            inliningMethods.pop();
        }
        else if (programMethod.getName(programClass).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT))
        {
            uninitializedObjectCount--;
        }
    }