Java Code Examples for proguard.optimize.KeepMarker#isKept()

The following examples show how to use proguard.optimize.KeepMarker#isKept() . 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: ClassFinalizer.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // If the class is not final/interface/abstract,
    // and it is not being kept,
    // and it doesn't have any subclasses,
    // then make it final.
    if ((programClass.u2accessFlags & (ClassConstants.ACC_FINAL     |
                                       ClassConstants.ACC_INTERFACE |
                                       ClassConstants.ACC_ABSTRACT)) == 0 &&
        !KeepMarker.isKept(programClass)                                           &&
        programClass.subClasses == null)
    {
        programClass.u2accessFlags |= ClassConstants.ACC_FINAL;

        // Visit the class, if required.
        if (extraClassVisitor != null)
        {
            extraClassVisitor.visitProgramClass(programClass);
        }
    }
}
 
Example 2
Source File: DescriptorKeepChecker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    if (!KeepMarker.isKept(programClass))
    {
        notePrinter.print(referencingClass.getName(),
                          programClass.getName(),
                          "Note: the configuration keeps the entry point '" +
                          ClassUtil.externalClassName(referencingClass.getName()) +
                          " { " +
                          (isField ?
                               ClassUtil.externalFullFieldDescription(0,
                                                                      referencingMember.getName(referencingClass),
                                                                      referencingMember.getDescriptor(referencingClass)) :
                               ClassUtil.externalFullMethodDescription(referencingClass.getName(),
                                                                       0,
                                                                       referencingMember.getName(referencingClass),
                                                                       referencingMember.getDescriptor(referencingClass))) +
                          "; }', but not the descriptor class '" +
                          ClassUtil.externalClassName(programClass.getName()) +
                          "'");
    }
}
 
Example 3
Source File: ClassFinalizer.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitProgramClass(ProgramClass programClass)
{
    // If the class is not final/interface/abstract,
    // and it is not being kept,
    // and it doesn't have any subclasses,
    // then make it final.
    if ((programClass.u2accessFlags & (AccessConstants.FINAL     |
                                       AccessConstants.INTERFACE |
                                       AccessConstants.ABSTRACT)) == 0 &&
        !KeepMarker.isKept(programClass)                               &&
        programClass.subClassCount == 0)
    {
        programClass.u2accessFlags |= AccessConstants.FINAL;

        // Visit the class, if required.
        if (extraClassVisitor != null)
        {
            extraClassVisitor.visitProgramClass(programClass);
        }
    }
}
 
Example 4
Source File: ClassFinalizer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // If the class is not final/interface/abstract,
    // and it is not being kept,
    // and it doesn't have any subclasses,
    // then make it final.
    if ((programClass.u2accessFlags & (ClassConstants.INTERNAL_ACC_FINAL     |
                                       ClassConstants.INTERNAL_ACC_INTERFACE |
                                       ClassConstants.INTERNAL_ACC_ABSTRACT)) == 0 &&
        !KeepMarker.isKept(programClass)                                           &&
        programClass.subClasses == null)
    {
        programClass.u2accessFlags |= ClassConstants.INTERNAL_ACC_FINAL;

        // Visit the class, if required.
        if (extraClassVisitor != null)
        {
            extraClassVisitor.visitProgramClass(programClass);
        }
    }
}
 
Example 5
Source File: ClassOptimizationInfoSetter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    if (!KeepMarker.isKept(programClass))
    {
        ClassOptimizationInfo.setClassOptimizationInfo(programClass);
    }
}
 
Example 6
Source File: MethodFinalizer.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    String name = programMethod.getName(programClass);

    // If the method is not already private/static/final/abstract,
    // and it is not a constructor,
    // and its class is final,
    //     or it is not being kept and it is not overridden,
    // then make it final.
    if ((programMethod.u2accessFlags & (ClassConstants.ACC_PRIVATE |
                                        ClassConstants.ACC_STATIC  |
                                        ClassConstants.ACC_FINAL   |
                                        ClassConstants.ACC_ABSTRACT)) == 0 &&
        !name.equals(ClassConstants.METHOD_NAME_INIT)                      &&
        ((programClass.u2accessFlags & ClassConstants.ACC_FINAL) != 0 ||
         (!KeepMarker.isKept(programMethod) &&
          (programClass.subClasses == null ||
           !memberFinder.isOverriden(programClass, programMethod)))))
    {
        programMethod.u2accessFlags |= ClassConstants.ACC_FINAL;

        // Visit the method, if required.
        if (extraMemberVisitor != null)
        {
            extraMemberVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 7
Source File: MemberOptimizationInfoSetter.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    if (!KeepMarker.isKept(programField))
    {
        FieldOptimizationInfo.setFieldOptimizationInfo(programClass,
                                                       programField);
    }
}
 
Example 8
Source File: MemberOptimizationInfoSetter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    if (!KeepMarker.isKept(programMethod))
    {
        MethodOptimizationInfo.setMethodOptimizationInfo(programClass,
                                                         programMethod);
    }
}
 
Example 9
Source File: MemberOptimizationInfoSetter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    if (!KeepMarker.isKept(programField))
    {
        FieldOptimizationInfo.setFieldOptimizationInfo(programClass,
                                                       programField);
    }
}
 
Example 10
Source File: MethodFinalizer.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)
{
    String name = programMethod.getName(programClass);

    // If the method is not already private/static/final/abstract,
    // and it is not a constructor,
    // and its class is final,
    //     or it is not being kept and it is not overridden,
    // then make it final.
    if ((programMethod.u2accessFlags & (ClassConstants.INTERNAL_ACC_PRIVATE |
                                        ClassConstants.INTERNAL_ACC_STATIC  |
                                        ClassConstants.INTERNAL_ACC_FINAL   |
                                        ClassConstants.INTERNAL_ACC_ABSTRACT)) == 0 &&
        !name.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT)                      &&
        ((programClass.u2accessFlags & ClassConstants.INTERNAL_ACC_FINAL) != 0 ||
         (!KeepMarker.isKept(programMethod) &&
          (programClass.subClasses == null ||
           !memberFinder.isOverriden(programClass, programMethod)))))
    {
        programMethod.u2accessFlags |= ClassConstants.INTERNAL_ACC_FINAL;

        // Visit the method, if required.
        if (extraMemberVisitor != null)
        {
            extraMemberVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 11
Source File: MethodFinalizer.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    String name = programMethod.getName(programClass);

    // If the method is not already private/static/final/abstract,
    // and it is not a constructor,
    // and its class is final,
    //     or it is not being kept and it is not overridden,
    // then make it final.
    if ((programMethod.u2accessFlags & (ClassConstants.ACC_PRIVATE |
                                        ClassConstants.ACC_STATIC  |
                                        ClassConstants.ACC_FINAL   |
                                        ClassConstants.ACC_ABSTRACT)) == 0 &&
        !name.equals(ClassConstants.METHOD_NAME_INIT)                      &&
        ((programClass.u2accessFlags & ClassConstants.ACC_FINAL) != 0 ||
         (!KeepMarker.isKept(programMethod) &&
          (programClass.subClasses == null ||
           !memberFinder.isOverriden(programClass, programMethod)))))
    {
        programMethod.u2accessFlags |= ClassConstants.ACC_FINAL;

        // Visit the method, if required.
        if (extraMemberVisitor != null)
        {
            extraMemberVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 12
Source File: ClassOptimizationInfoSetter.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    if (!KeepMarker.isKept(programClass))
    {
        ClassOptimizationInfo.setClassOptimizationInfo(programClass);
    }
}
 
Example 13
Source File: MemberOptimizationInfoSetter.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 (!KeepMarker.isKept(programField))
    {
        FieldOptimizationInfo.setFieldOptimizationInfo(programClass,
                                                       programField);
    }
}
 
Example 14
Source File: MethodFinalizer.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    String name = programMethod.getName(programClass);

    // If the method is not already private/static/final/abstract,
    // and it is not a constructor,
    // and its class is final,
    //     or it is not being kept and it is not overridden,
    // then make it final.
    if ((programMethod.u2accessFlags & (AccessConstants.PRIVATE |
                                        AccessConstants.STATIC  |
                                        AccessConstants.FINAL   |
                                        AccessConstants.ABSTRACT)) == 0 &&
        !name.equals(ClassConstants.METHOD_NAME_INIT)                      &&
        ((programClass.u2accessFlags & AccessConstants.FINAL) != 0 ||
         (!KeepMarker.isKept(programMethod) &&
          (programClass.subClassCount == 0 ||
           !memberFinder.isOverriden(programClass, programMethod)))))
    {
        programMethod.u2accessFlags |= AccessConstants.FINAL;

        // Visit the method, if required.
        if (extraMemberVisitor != null)
        {
            extraMemberVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 15
Source File: StoringInvocationUnit.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
private static void generalizeMethodReturnValue(Method method, Value value)
{
    if (!KeepMarker.isKept(method))
    {
        ProgramMethodOptimizationInfo.getProgramMethodOptimizationInfo(method).generalizeReturnValue(value);
    }
}
 
Example 16
Source File: StoringInvocationUnit.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
private static void generalizeMethodParameterValue(Method method, int parameterIndex, Value value)
{
    if (!KeepMarker.isKept(method))
    {
        ProgramMethodOptimizationInfo.getProgramMethodOptimizationInfo(method).generalizeParameterValue(parameterIndex, value);
    }
}
 
Example 17
Source File: StoringInvocationUnit.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
private static void generalizeFieldValue(Field field, Value value)
{
    if (!KeepMarker.isKept(field))
    {
        ProgramFieldOptimizationInfo.getProgramFieldOptimizationInfo(field).generalizeValue(value);
    }
}
 
Example 18
Source File: StoringInvocationUnit.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
private static void generalizeFieldClassValue(Field field, ReferenceValue value)
{
    if (!KeepMarker.isKept(field))
    {
        ProgramFieldOptimizationInfo.getProgramFieldOptimizationInfo(field).generalizeReferencedClass(value);
    }
}
 
Example 19
Source File: MethodInliner.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
    {
        int accessFlags = programMethod.getAccessFlags();

        if (// Don't inline methods that must be preserved.
            !KeepMarker.isKept(programMethod)                                                     &&

            // Only inline the method if it is private, static, or final.
            // This currently precludes default interface methods, because
            // they can't be final.
            (accessFlags & (ClassConstants.ACC_PRIVATE |
                            ClassConstants.ACC_STATIC  |
                            ClassConstants.ACC_FINAL)) != 0                                       &&

            // Only inline the method if it is not synchronized, etc.
            (accessFlags & (ClassConstants.ACC_SYNCHRONIZED |
                            ClassConstants.ACC_NATIVE       |
                            ClassConstants.ACC_ABSTRACT)) == 0                                    &&

            // Don't inline an <init> method, except in an <init> method in the
            // same class.
//            (!programMethod.getName(programClass).equals(ClassConstants.METHOD_NAME_INIT) ||
//             (programClass.equals(targetClass) &&
//              targetMethod.getName(targetClass).equals(ClassConstants.METHOD_NAME_INIT))) &&
            !programMethod.getName(programClass).equals(ClassConstants.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 a
            // dynamic method, or if it is in the same class.
            (!SuperInvocationMarker.invokesSuperMethods(programMethod) &&
             !DynamicInvocationMarker.invokesDynamically(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 always returns with an empty
            // stack.
            !NonEmptyStackReturnMarker.returnsWithNonEmptyStack(programMethod)                    &&

            // a subset of the initialized superclasses.
            ((accessFlags & ClassConstants.ACC_STATIC) == 0 ||
             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.METHOD_NAME_INIT))
        {
            uninitializedObjectCount--;
        }
    }
 
Example 20
Source File: SimpleEnumDescriptorSimplifier.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    // Update the descriptor if it has a simple enum class.
    String descriptor    = programField.getDescriptor(programClass);
    String newDescriptor = simplifyDescriptor(descriptor, programField.referencedClass);

    if (!descriptor.equals(newDescriptor))
    {
        String name    = programField.getName(programClass);
        String newName = name + TypeConstants.SPECIAL_MEMBER_SEPARATOR + Long.toHexString(Math.abs((descriptor).hashCode()));

        if (DEBUG)
        {
            System.out.println("SimpleEnumDescriptorSimplifier: ["+programClass.getName()+"."+name+" "+descriptor + "] -> ["+newName+" "+newDescriptor+"]");
        }

        ConstantPoolEditor constantPoolEditor =
            new ConstantPoolEditor(programClass);

        // Update the name.
        programField.u2nameIndex =
            constantPoolEditor.addUtf8Constant(newName);

        // Update the descriptor itself.
        programField.u2descriptorIndex =
            constantPoolEditor.addUtf8Constant(newDescriptor);

        // Clear the referenced class.
        programField.referencedClass = null;

        // Clear the enum flag.
        programField.u2accessFlags &= ~AccessConstants.ENUM;

        // Clear the field value.
        if (!KeepMarker.isKept(programField))
        {
            ProgramFieldOptimizationInfo.getProgramFieldOptimizationInfo(programField).resetValue(programClass, programField);
        }

        // Simplify the signature.
        programField.attributesAccept(programClass, this);
    }
}