proguard.classfile.visitor.MemberVisitor Java Examples

The following examples show how to use proguard.classfile.visitor.MemberVisitor. 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: ClassSpecificationVisitorFactory.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a ClassPoolVisitor to efficiently travel to the specified
 * classes and class members.
 *
 * @param classSpecifications the list of ClassSpecification instances,
 *                            defining of the classes and class members to
 *                            visit.
 * @param classVisitor        the ClassVisitor to be applied to matching
 *                            classes.
 * @param memberVisitor       the MemberVisitor to be applied to matching
 *                            class members.
 */
public static ClassPoolVisitor createClassPoolVisitor(List          classSpecifications,
                                                      ClassVisitor  classVisitor,
                                                      MemberVisitor memberVisitor)
{
    MultiClassPoolVisitor multiClassPoolVisitor = new MultiClassPoolVisitor();

    if (classSpecifications != null)
    {
        for (int index = 0; index < classSpecifications.size(); index++)
        {
            ClassSpecification classSpecification =
                (ClassSpecification)classSpecifications.get(index);

            multiClassPoolVisitor.addClassPoolVisitor(
                createClassPoolVisitor(classSpecification,
                                       classVisitor,
                                       memberVisitor));
        }
    }

    return multiClassPoolVisitor;
}
 
Example #2
Source File: ClassSpecificationVisitorFactory.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Adds elements to the given MultiClassVisitor, to apply the given
 * MemberVisitor to all class members that match the given List
 * of options (of the given type).
 */
private static void addMemberVisitors(List              memberSpecifications,
                                      boolean           isField,
                                      MultiClassVisitor multiClassVisitor,
                                      MemberVisitor     memberVisitor)
{
    if (memberSpecifications != null)
    {
        for (int index = 0; index < memberSpecifications.size(); index++)
        {
            MemberSpecification memberSpecification =
                (MemberSpecification)memberSpecifications.get(index);

            multiClassVisitor.addClassVisitor(
                createClassVisitor(memberSpecification,
                                   isField,
                                   memberVisitor));
        }
    }
}
 
Example #3
Source File: ProgramClass.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void methodsAccept(MemberVisitor memberVisitor)
{
    for (int index = 0; index < u2methodsCount; index++)
    {
        methods[index].accept(this, memberVisitor);
    }
}
 
Example #4
Source File: RefConstant.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the referenced class member accept the given visitor.
 */
public void referencedMemberAccept(MemberVisitor memberVisitor)
{
    if (referencedMember != null)
    {
        referencedMember.accept(referencedClass,
                                memberVisitor);
    }
}
 
Example #5
Source File: StringConstant.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the referenced member accept the given visitor.
 */
public void referencedMemberAccept(MemberVisitor memberVisitor)
{
    if (referencedMember != null)
    {
        referencedMember.accept(referencedClass, memberVisitor);
    }
}
 
Example #6
Source File: OptimizationInfoMemberFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    MemberVisitor visitor =
        MethodOptimizationInfo.getMethodOptimizationInfo(programMethod) instanceof ProgramMethodOptimizationInfo ?
            memberVisitor : otherMemberVisitor;

    if (visitor != null)
    {
        visitor.visitProgramMethod(programClass, programMethod);
    }
}
 
Example #7
Source File: OptimizationInfoMemberFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    MemberVisitor visitor =
        FieldOptimizationInfo.getFieldOptimizationInfo(programField) instanceof ProgramFieldOptimizationInfo ?
            memberVisitor : otherMemberVisitor;

    if (visitor != null)
    {
        visitor.visitProgramField(programClass, programField);
    }
}
 
Example #8
Source File: LibraryClass.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void fieldAccept(String name, String descriptor, MemberVisitor memberVisitor)
{
    Field field = findField(name, descriptor);
    if (field != null)
    {
        field.accept(this, memberVisitor);
    }
}
 
Example #9
Source File: LibraryClass.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void methodsAccept(MemberVisitor memberVisitor)
{
    for (int index = 0; index < methods.length; index++)
    {
        Method method = methods[index];
        if (method != null)
        {
            method.accept(this, memberVisitor);
        }
    }
}
 
Example #10
Source File: ShortestUsageMark.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given class visitor to this mark's member, if any.
 */
public void acceptMemberVisitor(MemberVisitor memberVisitor)
{
    if (clazz  != null &&
        member != null)
    {
        member.accept(clazz, memberVisitor);
    }
}
 
Example #11
Source File: ElementValue.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given visitor to the referenced method.
 */
public void referencedMethodAccept(MemberVisitor memberVisitor)
{
    if (referencedMethod != null)
    {
        referencedMethod.accept(referencedClass, memberVisitor);
    }
}
 
Example #12
Source File: EnclosingMethodAttribute.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the referenced class member accept the given visitor.
 */
public void referencedMethodAccept(MemberVisitor memberVisitor)
{
    if (referencedMethod != null)
    {
        referencedMethod.accept(referencedClass,
                                memberVisitor);
    }
}
 
Example #13
Source File: ProgramClass.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void fieldsAccept(MemberVisitor memberVisitor)
{
    for (int index = 0; index < u2fieldsCount; index++)
    {
        fields[index].accept(this, memberVisitor);
    }
}
 
Example #14
Source File: ElementValue.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given visitor to the referenced method.
 */
public void referencedMethodAccept(MemberVisitor memberVisitor)
{
    if (referencedMethod != null)
    {
        referencedMethod.accept(referencedClass, memberVisitor);
    }
}
 
Example #15
Source File: ClassSpecificationVisitorFactory.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a ClassVisitor to efficiently travel to the specified class
 * members.
 *
 * @param classSpecification the specifications of the class members to visit.
 * @param memberVisitor      the MemberVisitor to be applied to matching
 *                           class members.
 */
private static ClassVisitor createClassVisitor(ClassSpecification classSpecification,
                                               MemberVisitor      memberVisitor)
{
    MultiClassVisitor multiClassVisitor = new MultiClassVisitor();

    addMemberVisitors(classSpecification.fieldSpecifications,  true,  multiClassVisitor, memberVisitor);
    addMemberVisitors(classSpecification.methodSpecifications, false, multiClassVisitor, memberVisitor);

    // Mark the class member in this class and in super classes.
    return new ClassHierarchyTraveler(true, true, false, false,
                                      multiClassVisitor);
}
 
Example #16
Source File: ClassSpecificationVisitorFactory.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a ClassPoolVisitor to efficiently travel to the specified
 * classes and class members.
 *
 * @param keepClassSpecification the specifications of the class(es) and class
 *                          members to visit.
 * @param classVisitor      the ClassVisitor to be applied to matching
 *                          classes.
 * @param memberVisitor     the MemberVisitor to be applied to matching
 *                          class members.
 */
private static ClassPoolVisitor createClassPoolVisitor(KeepClassSpecification keepClassSpecification,
                                                       ClassVisitor      classVisitor,
                                                       MemberVisitor     memberVisitor)
{
    // Don't  visit the classes if not specified.
    if (!keepClassSpecification.markClasses &&
        !keepClassSpecification.markConditionally)
    {
        classVisitor = null;
    }

    // If specified, let the marker visit the class and its class
    // members conditionally.
    if (keepClassSpecification.markConditionally)
    {
        // Combine both visitors.
        ClassVisitor composedClassVisitor =
            createCombinedClassVisitor(keepClassSpecification,
                                       classVisitor,
                                       memberVisitor);

        // Replace the class visitor.
        classVisitor =
            createClassMemberTester(keepClassSpecification,
                                    composedClassVisitor);

        // Discard the member visitor, because it has already been included.
        memberVisitor = null;
    }

    return createClassPoolVisitor((ClassSpecification)keepClassSpecification,
                                  classVisitor,
                                  memberVisitor);
}
 
Example #17
Source File: MemberAdder.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Creates a new MemberAdder that will copy methods into the given target
     * class.
     * @param targetClass        the class to which all visited class members
     *                           will be added.
     * @param extraMemberVisitor an optional member visitor that visits each
     *                           new member right after it has been added. This
     *                           allows changing the visitor info, for instance.
     */
//     * @param addFields   specifies whether fields should be added, or fused
//     *                    with the present fields.
    public MemberAdder(ProgramClass  targetClass,
//                     boolean       addFields,
                       MemberVisitor extraMemberVisitor)
    {
        this.targetClass        = targetClass;
//      this.addFields          = addFields;
        this.extraMemberVisitor = extraMemberVisitor;

        constantAdder      = new ConstantAdder(targetClass);
        classEditor        = new ClassEditor(targetClass);
        constantPoolEditor = new ConstantPoolEditor(targetClass);
    }
 
Example #18
Source File: UsedMemberFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    MemberVisitor delegateVisitor = delegateVisitor(programField);
    if (delegateVisitor != null)
    {
        delegateVisitor.visitProgramField(programClass, programField);
    }
}
 
Example #19
Source File: ElementValue.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the given visitor to the referenced method.
 */
public void referencedMethodAccept(MemberVisitor memberVisitor)
{
    if (referencedMethod != null)
    {
        referencedMethod.accept(referencedClass, memberVisitor);
    }
}
 
Example #20
Source File: ClassSpecificationVisitorFactory.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a ClassPoolVisitor to efficiently travel to the specified
 * classes and class members.
 *
 * @param keepClassSpecifications the list of KeepClassSpecification
 *                                instances, defining of the classes and
 *                                class members to visit.
 * @param classVisitor            the ClassVisitor to be applied to matching
 *                                classes.
 * @param memberVisitor           the MemberVisitor to be applied to matching
 *                                class members.
 */
public static ClassPoolVisitor createClassPoolVisitor(List          keepClassSpecifications,
                                                      ClassVisitor  classVisitor,
                                                      MemberVisitor memberVisitor,
                                                      boolean       shrinking,
                                                      boolean       optimizing,
                                                      boolean       obfuscating)
{
    MultiClassPoolVisitor multiClassPoolVisitor = new MultiClassPoolVisitor();

    if (keepClassSpecifications != null)
    {
        for (int index = 0; index < keepClassSpecifications.size(); index++)
        {
            KeepClassSpecification keepClassSpecification =
                (KeepClassSpecification)keepClassSpecifications.get(index);

            if ((shrinking   && !keepClassSpecification.allowShrinking)    ||
                (optimizing  && !keepClassSpecification.allowOptimization) ||
                (obfuscating && !keepClassSpecification.allowObfuscation))
            {
                multiClassPoolVisitor.addClassPoolVisitor(
                    createClassPoolVisitor(keepClassSpecification,
                                           classVisitor,
                                           memberVisitor));
            }
        }
    }

    return multiClassPoolVisitor;
}
 
Example #21
Source File: UsedMemberFilter.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
public UsedMemberFilter(ClassUsageMarker classUsageMarker,
                        MemberVisitor    usedMemberFilter)
{
    this(classUsageMarker.getUsageMarker(), usedMemberFilter);
}
 
Example #22
Source File: ProgramMember.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
public void accept(Clazz clazz, MemberVisitor memberVisitor)
{
    accept((ProgramClass)clazz, memberVisitor);
}
 
Example #23
Source File: LibraryMember.java    From bazel with Apache License 2.0 4 votes vote down vote up
public void accept(Clazz clazz, MemberVisitor memberVisitor)
{
    accept((LibraryClass)clazz, memberVisitor);
}
 
Example #24
Source File: ProgramMethod.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void accept(ProgramClass programClass, MemberVisitor memberVisitor)
{
    memberVisitor.visitProgramMethod(programClass, this);
}
 
Example #25
Source File: AnnotationToMemberVisitor.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
public AnnotationToMemberVisitor(MemberVisitor memberVisitor)
{
    this.memberVisitor = memberVisitor;
}
 
Example #26
Source File: ProgramMember.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void accept(Clazz clazz, MemberVisitor memberVisitor)
{
    accept((ProgramClass)clazz, memberVisitor);
}
 
Example #27
Source File: VariableOptimizer.java    From proguard with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new VariableOptimizer with an extra visitor.
 * @param reuseThis                  specifies whether the 'this' variable
 *                                   can be reused. Many JVMs for JME and
 *                                   IBM's JVMs for JSE can't handle such
 *                                   reuse.
 * @param extraVariableMemberVisitor an optional extra visitor for all
 *                                   removed variables.
 */
public VariableOptimizer(boolean       reuseThis,
                         MemberVisitor extraVariableMemberVisitor)
{
    this.reuseThis                  = reuseThis;
    this.extraVariableMemberVisitor = extraVariableMemberVisitor;
}
 
Example #28
Source File: VariableOptimizer.java    From java-n-IDE-for-Android with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new VariableOptimizer with an extra visitor.
 * @param reuseThis                  specifies whether the 'this' variable
 *                                   can be reused. Many JVMs for JME and
 *                                   IBM's JVMs for JSE can't handle such
 *                                   reuse.
 * @param extraVariableMemberVisitor an optional extra visitor for all
 *                                   removed variables.
 */
public VariableOptimizer(boolean       reuseThis,
                         MemberVisitor extraVariableMemberVisitor)
{
    this.reuseThis                  = reuseThis;
    this.extraVariableMemberVisitor = extraVariableMemberVisitor;
}
 
Example #29
Source File: UsedMemberFilter.java    From proguard with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new UsedMemberFilter.
 * @param usageMarker   the usage marker that is used to mark the classes
 *                      and class members.
 * @param memberVisitor the member visitor to which the visiting will be
 *                      delegated.
 */
public UsedMemberFilter(UsageMarker   usageMarker,
                        MemberVisitor memberVisitor)
{
    this.usageMarker   = usageMarker;
    this.memberVisitor = memberVisitor;
}
 
Example #30
Source File: UsedMemberFilter.java    From proguard with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new UsedMemberFilter.
 *
 * @param usageMarker         the usage marker that is used to mark the classes
 *                            and class members.
 * @param usedMemberFilter    the member visitor to which the visiting of used members
 *                            will be delegated.
 * @param unusedMemberVisitor the member visitor to which the visiting of unused members
 *                            will bedelegated.
 */
public UsedMemberFilter(SimpleUsageMarker usageMarker,
                        MemberVisitor     usedMemberFilter,
                        MemberVisitor     unusedMemberVisitor)
{
    this.usageMarker         = usageMarker;
    this.usedMemberFilter    = usedMemberFilter;
    this.unusedMemberVisitor = unusedMemberVisitor;
}