proguard.classfile.visitor.ClassVisitor Java Examples

The following examples show how to use proguard.classfile.visitor.ClassVisitor. 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: SubroutineInliner.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Performs subroutine inlining of the given program class pool.
 */
public void execute(ClassPool programClassPool)
{
    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());

    // Inline all subroutines.
    ClassVisitor inliner =
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new CodeSubroutineInliner()));

    // In Java Standard Edition, only class files from Java 6 or higher
    // should be preverified.
    if (!configuration.microEdition)
    {
        inliner =
            new ClassVersionFilter(ClassConstants.INTERNAL_CLASS_VERSION_1_6,
                                   Integer.MAX_VALUE,
                                   inliner);
    }

    programClassPool.classesAccept(inliner);
}
 
Example #3
Source File: InvokeDynamicConstant.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the Clazz objects referenced in the descriptor string
 * accept the given visitor.
 */
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        for (int index = 0; index < referencedClasses.length; index++)
        {
            if (referencedClasses[index] != null)
            {
                referencedClasses[index].accept(classVisitor);
            }
        }
    }
}
 
Example #4
Source File: ProgramMethod.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        for (int index = 0; index < referencedClasses.length; index++)
        {
            if (referencedClasses[index] != null)
            {
                referencedClasses[index].accept(classVisitor);
            }
        }
    }
}
 
Example #5
Source File: ClassReader.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new DataEntryClassFilter for reading the specified
 * Clazz objects.
 */
public ClassReader(boolean        isLibrary,
                   boolean        skipNonPublicLibraryClasses,
                   boolean        skipNonPublicLibraryClassMembers,
                   WarningPrinter warningPrinter,
                   ClassVisitor   classVisitor)
{
    this.isLibrary                        = isLibrary;
    this.skipNonPublicLibraryClasses      = skipNonPublicLibraryClasses;
    this.skipNonPublicLibraryClassMembers = skipNonPublicLibraryClassMembers;
    this.warningPrinter                   = warningPrinter;
    this.classVisitor                     = classVisitor;
}
 
Example #6
Source File: Annotation.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given visitor to all referenced classes.
 */
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        for (int index = 0; index < referencedClasses.length; index++)
        {
            Clazz referencedClass = referencedClasses[index];
            if (referencedClass != null)
            {
                referencedClass.accept(classVisitor);
            }
        }
    }
}
 
Example #7
Source File: ClassElementValue.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given visitor to all referenced classes.
 */
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        for (int index = 0; index < referencedClasses.length; index++)
        {
            Clazz referencedClass = referencedClasses[index];
            if (referencedClass != null)
            {
                referencedClass.accept(classVisitor);
            }
        }
    }
}
 
Example #8
Source File: EscapingClassFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitAnyClass(Clazz clazz)
{
    // Is the class marked to be escaping?
    ClassVisitor classVisitor = EscapingClassMarker.isClassEscaping(clazz) ?
        escapingClassVisitor :
        otherClassVisitor;

    if (classVisitor != null)
    {
        clazz.accept(classVisitor);
    }
}
 
Example #9
Source File: KeptClassFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitAnyClass(Clazz clazz)
{
    ClassVisitor delegateVisitor =
        KeepMarker.isKept(clazz) ? acceptedVisitor : rejectedVisitor;

    if (delegateVisitor != null)
    {
        clazz.accept(delegateVisitor);
    }
}
 
Example #10
Source File: LocalVariableInfo.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the referenced class accept the given visitor.
 */
public void referencedClassAccept(ClassVisitor classVisitor)
{
    if (referencedClass != null)
    {
        referencedClass.accept(classVisitor);
    }
}
 
Example #11
Source File: SimpleEnumFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Is the class marked as a simple enum?
    ClassVisitor classVisitor = SimpleEnumMarker.isSimpleEnum(programClass) ?
        simpleEnumClassVisitor : otherClassVisitor;

    if (classVisitor != null)
    {
        classVisitor.visitProgramClass(programClass);
    }
}
 
Example #12
Source File: ClassConstant.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the referenced class accept the given visitor.
 */
public void referencedClassAccept(ClassVisitor classVisitor)
{
    if (referencedClass != null)
    {
        referencedClass.accept(classVisitor);
    }
}
 
Example #13
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 #14
Source File: ClassSpecificationVisitorFactory.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a ClassVisitor that conditionally applies the given
 * ClassVisitor to all classes that contain the given class members.
 */
private static ClassVisitor createClassMemberTester(ClassSpecification classSpecification,
                                                    ClassVisitor       classVisitor)
{
    // Create a linked list of conditional visitors, for fields and for
    // methods.
    return createClassMemberTester(classSpecification.fieldSpecifications,
                                   true,
           createClassMemberTester(classSpecification.methodSpecifications,
                                   false,
                                   classVisitor));
}
 
Example #15
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 accept the given visitor.
 */
public void referencedClassAccept(ClassVisitor classVisitor)
{
    if (referencedClass != null)
    {
        referencedClass.accept(classVisitor);
    }
}
 
Example #16
Source File: SignatureAttribute.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the Clazz objects referenced in the signature string accept the
 * given visitor.
 */
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        for (int index = 0; index < referencedClasses.length; index++)
        {
            if (referencedClasses[index] != null)
            {
                referencedClasses[index].accept(classVisitor);
            }
        }
    }
}
 
Example #17
Source File: OriginalClassNameFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitAnyClass(Clazz clazz)
{
    ClassVisitor delegateVisitor = selectVisitor(clazz);
    if (delegateVisitor != null)
    {
        clazz.accept(delegateVisitor);
    }
}
 
Example #18
Source File: Annotation.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the given visitor to all referenced classes.
 */
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        for (int index = 0; index < referencedClasses.length; index++)
        {
            Clazz referencedClass = referencedClasses[index];
            if (referencedClass != null)
            {
                referencedClass.accept(classVisitor);
            }
        }
    }
}
 
Example #19
Source File: RetargetedClassFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Is the class marked to be retargeted?
    ClassVisitor classVisitor = ClassMerger.getTargetClass(programClass) != null ?
        retargetedClassVisitor : otherClassVisitor;

    if (classVisitor != null)
    {
        classVisitor.visitProgramClass(programClass);
    }
}
 
Example #20
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 accept the given visitor.
 */
public void referencedClassAccept(ClassVisitor classVisitor)
{
    if (referencedClass != null)
    {
        referencedClass.accept(classVisitor);
    }
}
 
Example #21
Source File: ClassConstant.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the referenced class accept the given visitor.
 */
public void referencedClassAccept(ClassVisitor classVisitor)
{
    if (referencedClass != null)
    {
        referencedClass.accept(classVisitor);
    }
}
 
Example #22
Source File: SimpleEnumFilter.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Is the class marked as a simple enum?
    ClassVisitor classVisitor = SimpleEnumMarker.isSimpleEnum(programClass) ?
        simpleEnumClassVisitor : otherClassVisitor;

    if (classVisitor != null)
    {
        classVisitor.visitProgramClass(programClass);
    }
}
 
Example #23
Source File: EnumConstantElementValue.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given visitor to all referenced classes.
 */
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        for (int index = 0; index < referencedClasses.length; index++)
        {
            Clazz referencedClass = referencedClasses[index];
            if (referencedClass != null)
            {
                referencedClass.accept(classVisitor);
            }
        }
    }
}
 
Example #24
Source File: Annotation.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given visitor to all referenced classes.
 */
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        for (int index = 0; index < referencedClasses.length; index++)
        {
            Clazz referencedClass = referencedClasses[index];
            if (referencedClass != null)
            {
                referencedClass.accept(classVisitor);
            }
        }
    }
}
 
Example #25
Source File: LibraryClass.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Lets the given class visitor visit the superclass, if it is known.
 * @param classVisitor the <code>ClassVisitor</code> that will visit the
 *                     superclass.
 */
public void superClassAccept(ClassVisitor classVisitor)
{
    if (superClass != null)
    {
        superClass.accept(classVisitor);
    }
}
 
Example #26
Source File: Annotation.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the given visitor to the first referenced class. This is the
 * main annotation class.
 */
public void referencedClassAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        Clazz referencedClass = referencedClasses[0];
        if (referencedClass != null)
        {
            referencedClass.accept(classVisitor);
        }
    }
}
 
Example #27
Source File: Annotation.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given visitor to the first referenced class. This is the
 * main annotation class.
 */
public void referencedClassAccept(ClassVisitor classVisitor)
{
    if (referencedClasses != null)
    {
        Clazz referencedClass = referencedClasses[0];
        if (referencedClass != null)
        {
            referencedClass.accept(classVisitor);
        }
    }
}
 
Example #28
Source File: ClassPool.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given ClassVisitor to all classes in the class pool,
 * in sorted order.
 */
public void classesAcceptAlphabetically(ClassVisitor classVisitor)
{
    // We're already using a tree map.
    //TreeMap sortedClasses = new TreeMap(classes);
    //Iterator iterator = sortedClasses.values().iterator();

    Iterator iterator = classes.values().iterator();
    while (iterator.hasNext())
    {
        Clazz clazz = (Clazz)iterator.next();
        clazz.accept(classVisitor);
    }
}
 
Example #29
Source File: ClassPool.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given ClassVisitor to the class with the given name,
 * if it is present in the class pool.
 */
public void classAccept(String className, ClassVisitor classVisitor)
{
    Clazz clazz = getClass(className);
    if (clazz != null)
    {
        clazz.accept(classVisitor);
    }
}
 
Example #30
Source File: LibraryField.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClass != null)
    {
        referencedClass.accept(classVisitor);
    }
}