Java Code Examples for proguard.classfile.visitor.ClassVisitor

The following examples show how to use proguard.classfile.visitor.ClassVisitor. These examples are extracted from open source projects. 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
/**
 * 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 Project: java-n-IDE-for-Android   Source File: SubroutineInliner.java    License: 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 Project: proguard   Source File: UsedClassFilter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitAnyClass(Clazz clazz)
{
    // Is the class marked?
    ClassVisitor classVisitor = simpleUsageMarker.isUsed(clazz) ?
        usedClassVisitor :
        unusedClassVisitor;

    if (classVisitor != null)
    {
        clazz.accept(classVisitor);
    }
}
 
Example 4
Source Project: proguard   Source File: JSR310Converter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new JSR310Converter instance.
 */
public JSR310Converter(ClassPool          programClassPool,
                       ClassPool          libraryClassPool,
                       WarningPrinter     warningPrinter,
                       ClassVisitor       modifiedClassVisitor,
                       InstructionVisitor extraInstructionVisitor)
{
    super(programClassPool,
          libraryClassPool,
          warningPrinter,
          modifiedClassVisitor,
          extraInstructionVisitor);

    TypeReplacement[] typeReplacements = new TypeReplacement[]
    {
        // java.time package has been added in Java 8
        replace("java/time/**", "org/threeten/bp/<1>"),
    };

    MethodReplacement[] methodReplacements = new MethodReplacement[]
    {
        // all classes in java.time.** are converted to
        // org.threeeten.bp.**.
        replace("java/time/**",        "**",  "**",
                "org/threeten/bp/<1>", "<1>", "<1>"),
    };

    setTypeReplacements(typeReplacements);
    setMethodReplacements(methodReplacements);
}
 
Example 5
Source Project: proguard   Source File: SimpleEnumFilter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
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 6
Source Project: proguard   Source File: EscapingClassFilter.java    License: 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 7
Source Project: proguard   Source File: ClassReader.java    License: GNU General Public License v2.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 8
Source Project: proguard   Source File: KeptClassFilter.java    License: 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 9
@Override
public void visitAnyClass(Clazz clazz)
{
    ClassVisitor delegateVisitor = selectVisitor(clazz);
    if (delegateVisitor != null)
    {
        clazz.accept(delegateVisitor);
    }
}
 
Example 10
Source Project: proguard   Source File: SimpleEnumFilter.java    License: 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 11
Source Project: bazel   Source File: ClassConstant.java    License: 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 12
/**
 * 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 13
/**
 * 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 14
Source Project: bazel   Source File: InvokeDynamicConstant.java    License: 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 15
Source Project: proguard   Source File: Annotation.java    License: 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 16
Source Project: java-n-IDE-for-Android   Source File: RefConstant.java    License: 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 17
Source Project: java-n-IDE-for-Android   Source File: ClassConstant.java    License: 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 18
Source Project: java-n-IDE-for-Android   Source File: LibraryClass.java    License: 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 19
Source Project: proguard   Source File: Annotation.java    License: 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 20
Source Project: java-n-IDE-for-Android   Source File: ClassPool.java    License: 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 21
Source Project: java-n-IDE-for-Android   Source File: ClassPool.java    License: 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 22
Source Project: java-n-IDE-for-Android   Source File: LibraryField.java    License: Apache License 2.0 5 votes vote down vote up
public void referencedClassesAccept(ClassVisitor classVisitor)
{
    if (referencedClass != null)
    {
        referencedClass.accept(classVisitor);
    }
}
 
Example 23
Source Project: java-n-IDE-for-Android   Source File: Annotation.java    License: 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 24
Source Project: java-n-IDE-for-Android   Source File: Annotation.java    License: 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
/**
 * 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 26
Source Project: bazel   Source File: SimpleEnumFilter.java    License: 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 27
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 28
Source Project: java-n-IDE-for-Android   Source File: SignatureAttribute.java    License: 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 29
/**
 * Lets the referenced class accept the given visitor.
 */
public void referencedClassAccept(ClassVisitor classVisitor)
{
    if (referencedClass != null)
    {
        referencedClass.accept(classVisitor);
    }
}
 
Example 30
Source Project: java-n-IDE-for-Android   Source File: LocalVariableInfo.java    License: 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);
    }
}