Java Code Examples for proguard.classfile.ClassConstants#INTERNAL_ACC_PRIVATE

The following examples show how to use proguard.classfile.ClassConstants#INTERNAL_ACC_PRIVATE . 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: AccessMethodMarker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitAnyMember(Clazz clazz, Member member)
{
    int accessFlags = member.getAccessFlags();

    if      ((accessFlags & ClassConstants.INTERNAL_ACC_PRIVATE)   != 0)
    {
        setAccessesPrivateCode(invokingMethod);
    }
    else if ((accessFlags & ClassConstants.INTERNAL_ACC_PROTECTED) != 0)
    {
        setAccessesProtectedCode(invokingMethod);
    }
    else if ((accessFlags & ClassConstants.INTERNAL_ACC_PUBLIC)    == 0)
    {
        setAccessesPackageCode(invokingMethod);
    }
}
 
Example 2
Source File: UsageMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Marks the hierarchy of implementing or overriding methods corresponding
 * to the given method, if any.
 */
protected void markMethodHierarchy(Clazz clazz, Method method)
{
    if ((method.getAccessFlags() &
         (ClassConstants.INTERNAL_ACC_PRIVATE |
          ClassConstants.INTERNAL_ACC_STATIC)) == 0)
    {
        clazz.accept(new ConcreteClassDownTraveler(
                     new ClassHierarchyTraveler(true, true, false, true,
                     new NamedMethodVisitor(method.getName(clazz),
                                            method.getDescriptor(clazz),
                     new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE | ClassConstants.INTERNAL_ACC_STATIC | ClassConstants.INTERNAL_ACC_ABSTRACT,
                     this)))));
    }
}
 
Example 3
Source File: MethodImplementationTraveler.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private boolean isSpecial(Clazz clazz, Method method)
{
    return (method.getAccessFlags() &
            (ClassConstants.INTERNAL_ACC_PRIVATE |
             ClassConstants.INTERNAL_ACC_STATIC)) != 0 ||
           method.getName(clazz).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT);
}
 
Example 4
Source File: AccessUtil.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the corresponding access level of the given access flags.
 * @param accessFlags the internal access flags.
 * @return the corresponding access level: <code>PRIVATE</code>,
 *         <code>PACKAGE_VISIBLE</code>, <code>PROTECTED</code>, or
 *         <code>PUBLIC</code>.
 */
public static int accessLevel(int accessFlags)
{
    switch (accessFlags & ACCESS_MASK)
    {
        case ClassConstants.INTERNAL_ACC_PRIVATE:   return PRIVATE;
        default:                                    return PACKAGE_VISIBLE;
        case ClassConstants.INTERNAL_ACC_PROTECTED: return PROTECTED;
        case ClassConstants.INTERNAL_ACC_PUBLIC:    return PUBLIC;
    }
}
 
Example 5
Source File: AccessUtil.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the corresponding access flags of the given access level.
 * @param accessLevel the access level: <code>PRIVATE</code>,
 *                    <code>PACKAGE_VISIBLE</code>, <code>PROTECTED</code>,
 *                    or <code>PUBLIC</code>.
 * @return the corresponding internal access flags,  the internal access
 *         flags as a logical bit mask of <code>INTERNAL_ACC_PRIVATE</code>,
 *         <code>INTERNAL_ACC_PROTECTED</code>, and
 *         <code>INTERNAL_ACC_PUBLIC</code>.
 */
public static int accessFlags(int accessLevel)
{
    switch (accessLevel)
    {
        case PRIVATE:   return ClassConstants.INTERNAL_ACC_PRIVATE;
        default:        return 0;
        case PROTECTED: return ClassConstants.INTERNAL_ACC_PROTECTED;
        case PUBLIC:    return ClassConstants.INTERNAL_ACC_PUBLIC;
    }
}
 
Example 6
Source File: AccessUtil.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the access part of the given access flags.
 * @param accessFlags the internal access flags.
 * @param accessFlags the new internal access flags.
 */
public static int replaceAccessFlags(int accessFlags, int newAccessFlags)
{
    // A private class member should not be explicitly final.
    if (newAccessFlags == ClassConstants.INTERNAL_ACC_PRIVATE)
    {
        accessFlags &= ~ClassConstants.INTERNAL_ACC_FINAL;
    }

    return (accessFlags    & ~ACCESS_MASK) |
           (newAccessFlags &  ACCESS_MASK);
}
 
Example 7
Source File: PackageVisibleMemberContainingClassMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitAnyMember(Clazz clazz, Member member)
{
    if ((member.getAccessFlags() &
         (ClassConstants.INTERNAL_ACC_PRIVATE |
          ClassConstants.INTERNAL_ACC_PUBLIC)) == 0)
    {
        setPackageVisibleMembers(clazz);
    }
}
 
Example 8
Source File: PackageVisibleMemberInvokingClassMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitAnyMember(Clazz clazz, Member member)
{
    if ((member.getAccessFlags() &
         (ClassConstants.INTERNAL_ACC_PUBLIC |
          ClassConstants.INTERNAL_ACC_PRIVATE)) == 0)
    {
        setInvokesPackageVisibleMembers(referencingClass);
    }
}
 
Example 9
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 10
Source File: ClassUtil.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Converts internal class access flags into an external access description.
 * @param accessFlags the class access flags.
 * @param prefix      a prefix that is added to each access modifier.
 * @return the external class access description,
 *         e.g. "<code>public final </code>".
 */
public static String externalClassAccessFlags(int accessFlags, String prefix)
{
    if (accessFlags == 0)
    {
        return EMPTY_STRING;
    }

    StringBuffer string = new StringBuffer(50);

    if ((accessFlags & ClassConstants.INTERNAL_ACC_PUBLIC) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PUBLIC).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_PRIVATE) != 0)
    {
        // Only in InnerClasses attributes.
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PRIVATE).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_PROTECTED) != 0)
    {
        // Only in InnerClasses attributes.
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PROTECTED).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_STATIC) != 0)
    {
        // Only in InnerClasses attributes.
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_STATIC).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_FINAL) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_FINAL).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_ANNOTATTION) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_ANNOTATION);
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_INTERFACE) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_INTERFACE).append(' ');
    }
    else if ((accessFlags & ClassConstants.INTERNAL_ACC_ENUM) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_ENUM).append(' ');
    }
    else if ((accessFlags & ClassConstants.INTERNAL_ACC_ABSTRACT) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_ABSTRACT).append(' ');
    }
    else if ((accessFlags & ClassConstants.INTERNAL_ACC_SYNTHETIC) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_SYNTHETIC).append(' ');
    }

    return string.toString();
}
 
Example 11
Source File: ClassUtil.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Converts internal field access flags into an external access description.
 * @param accessFlags the field access flags.
 * @param prefix      a prefix that is added to each access modifier.
 * @return the external field access description,
 *         e.g. "<code>public volatile </code>".
 */
public static String externalFieldAccessFlags(int accessFlags, String prefix)
{
    if (accessFlags == 0)
    {
        return EMPTY_STRING;
    }

    StringBuffer string = new StringBuffer(50);

    if ((accessFlags & ClassConstants.INTERNAL_ACC_PUBLIC) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PUBLIC).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_PRIVATE) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PRIVATE).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_PROTECTED) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PROTECTED).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_STATIC) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_STATIC).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_FINAL) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_FINAL).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_VOLATILE) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_VOLATILE).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_TRANSIENT) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_TRANSIENT).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_SYNTHETIC) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_SYNTHETIC).append(' ');
    }

    return string.toString();
}
 
Example 12
Source File: ClassUtil.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Converts internal method access flags into an external access description.
 * @param accessFlags the method access flags.
 * @param prefix      a prefix that is added to each access modifier.
 * @return the external method access description,
 *                    e.g. "public synchronized ".
 */
public static String externalMethodAccessFlags(int accessFlags, String prefix)
{
    if (accessFlags == 0)
    {
        return EMPTY_STRING;
    }

    StringBuffer string = new StringBuffer(50);

    if ((accessFlags & ClassConstants.INTERNAL_ACC_PUBLIC) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PUBLIC).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_PRIVATE) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PRIVATE).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_PROTECTED) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_PROTECTED).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_STATIC) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_STATIC).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_FINAL) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_FINAL).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_SYNCHRONIZED) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_SYNCHRONIZED).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_BRIDGE) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_BRIDGE).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_VARARGS) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_VARARGS).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_NATIVE) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_NATIVE).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_ABSTRACT) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_ABSTRACT).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_STRICT) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_STRICT).append(' ');
    }
    if ((accessFlags & ClassConstants.INTERNAL_ACC_SYNTHETIC) != 0)
    {
        string.append(prefix).append(ClassConstants.EXTERNAL_ACC_SYNTHETIC).append(' ');
    }

    return string.toString();
}
 
Example 13
Source File: MemberAdder.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
    {
        String name        = programField.getName(programClass);
        String descriptor  = programField.getDescriptor(programClass);
        int    accessFlags = programField.getAccessFlags();

        // Does the target class already have such a field?
        ProgramField targetField = (ProgramField)targetClass.findField(name, descriptor);
        if (targetField != null)
        {
            // Is the field private or static?
            int targetAccessFlags = targetField.getAccessFlags();
            if ((targetAccessFlags &
                 (ClassConstants.INTERNAL_ACC_PRIVATE |
                  ClassConstants.INTERNAL_ACC_STATIC)) != 0)
            {
                if (DEBUG)
                {
                    System.out.println("MemberAdder: renaming field ["+targetClass+"."+targetField.getName(targetClass)+" "+targetField.getDescriptor(targetClass)+"]");
                }

                // Rename the private or static field.
                targetField.u2nameIndex =
                    constantPoolEditor.addUtf8Constant(newUniqueMemberName(name, targetClass.getName()));
            }
//            else
//            {
//                // Keep the non-private and non-static field, but update its
//                // contents, in order to keep any references to it valid.
//                if (DEBUG)
//                {
//                    System.out.println("MemberAdder: updating field ["+programClass+"."+programField.getName(programClass)+" "+programField.getDescriptor(programClass)+"] into ["+targetClass.getName()+"]");
//                }
//
//                // Combine the access flags.
//                targetField.u2accessFlags = accessFlags | targetAccessFlags;
//
//                // Add and replace any attributes.
//                programField.attributesAccept(programClass,
//                                              new AttributeAdder(targetClass,
//                                                                 targetField,
//                                                                 true));
//
//                // Don't add a new field.
//                return;
//            }
        }

        if (DEBUG)
        {
            System.out.println("MemberAdder: copying field ["+programClass+"."+programField.getName(programClass)+" "+programField.getDescriptor(programClass)+"] into ["+targetClass.getName()+"]");
        }

        // Create a copy of the field.
        ProgramField newProgramField =
            new ProgramField(accessFlags,
                             constantAdder.addConstant(programClass, programField.u2nameIndex),
                             constantAdder.addConstant(programClass, programField.u2descriptorIndex),
                             0,
                             programField.u2attributesCount > 0 ?
                                 new Attribute[programField.u2attributesCount] :
                                 EMPTY_ATTRIBUTES,
                             programField.referencedClass);

        // Link to its visitor info.
        newProgramField.setVisitorInfo(programField);

        // Copy its attributes.
        programField.attributesAccept(programClass,
                                      new AttributeAdder(targetClass,
                                                         newProgramField,
                                                         false));

        // Add the completed field.
        classEditor.addField(newProgramField);
    }
 
Example 14
Source File: TailRecursionSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
        int accessFlags = method.getAccessFlags();

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

            // Only check 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)
        {
//            codeAttributeComposer.DEBUG = DEBUG =
//                clazz.getName().equals("abc/Def") &&
//                method.getName(clazz).equals("abc");

            targetMethod = method;
            inlinedAny   = false;
            codeAttributeComposer.reset();

            // The code may expand, due to expanding constant and variable
            // instructions.
            codeAttributeComposer.beginCodeFragment(codeAttribute.u4codeLength);

            // Copy the instructions.
            codeAttribute.instructionsAccept(clazz, method, this);

            // Update the code attribute if any code has been inlined.
            if (inlinedAny)
            {
                // Copy the exceptions.
                codeAttribute.exceptionsAccept(clazz, method, this);

                // Append a label just after the code.
                codeAttributeComposer.appendLabel(codeAttribute.u4codeLength);

                codeAttributeComposer.endCodeFragment();

                codeAttributeComposer.visitCodeAttribute(clazz, method, codeAttribute);
            }
        }
    }
 
Example 15
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--;
        }
    }