Java Code Examples for proguard.classfile.ClassPool#accept()

The following examples show how to use proguard.classfile.ClassPool#accept() . 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: SeedPrinter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints out the seeds for the classes in the given program class pool.
 * @param configuration the configuration containing the keep options.
 * @throws IOException if an IO error occurs while writing the configuration.
 */
public void write(Configuration configuration,
                  ClassPool     programClassPool,
                  ClassPool     libraryClassPool) throws IOException
{
    // Check if we have at least some keep commands.
    if (configuration.keep == null)
    {
        throw new IOException("You have to specify '-keep' options if you want to write out kept elements with '-printseeds'.");
    }

    // Clean up any old processing info.
    programClassPool.classesAccept(new ClassCleaner());
    libraryClassPool.classesAccept(new ClassCleaner());

    // Create a visitor for printing out the seeds. We're  printing out
    // the program elements that are preserved against shrinking,
    // optimization, or obfuscation.
    KeepMarker keepMarker = new KeepMarker();
    ClassPoolVisitor classPoolvisitor =
        new KeepClassSpecificationVisitorFactory(true, true, true)
            .createClassPoolVisitor(configuration.keep,
                                    keepMarker,
                                    keepMarker,
                                    keepMarker,
                                    null);

    // Mark the seeds.
    programClassPool.accept(classPoolvisitor);
    libraryClassPool.accept(classPoolvisitor);

    // Print out the seeds.
    SimpleClassPrinter printer = new SimpleClassPrinter(false, printWriter);
    programClassPool.classesAcceptAlphabetically(
        new MultiClassVisitor(
            new KeptClassFilter(printer),
            new AllMemberVisitor(new KeptMemberFilter(printer))
        ));
}
 
Example 2
Source File: SeedPrinter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Prints out the seeds for the classes in the given program class pool.
 * @param configuration the configuration containing the keep options.
 * @throws IOException if an IO error occurs while writing the configuration.
 */
public void write(Configuration configuration,
                  ClassPool programClassPool,
                  ClassPool libraryClassPool) throws IOException
{
    // Check if we have at least some keep commands.
    if (configuration.keep == null)
    {
        throw new IOException("You have to specify '-keep' options for the shrinking step.");
    }

    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());
    libraryClassPool.classesAccept(new ClassCleaner());

    // Create a visitor for printing out the seeds. We're  printing out
    // the program elements that are preserved against shrinking,
    // optimization, or obfuscation.
    KeepMarker keepMarker = new KeepMarker();
    ClassPoolVisitor classPoolvisitor =
        ClassSpecificationVisitorFactory.createClassPoolVisitor(configuration.keep,
                                                                keepMarker,
                                                                keepMarker,
                                                                true,
                                                                true,
                                                                true);
    // Mark the seeds.
    programClassPool.accept(classPoolvisitor);
    libraryClassPool.accept(classPoolvisitor);

    // Print out the seeds.
    SimpleClassPrinter printer = new SimpleClassPrinter(false, ps);
    programClassPool.classesAcceptAlphabetically(new MultiClassVisitor(
        new ClassVisitor[]
        {
            new KeptClassFilter(printer),
            new AllMemberVisitor(new KeptMemberFilter(printer))
        }));
}
 
Example 3
Source File: SeedPrinter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints out the seeds for the classes in the given program class pool.
 * @param configuration the configuration containing the keep options.
 * @throws IOException if an IO error occurs while writing the configuration.
 */
public void write(Configuration configuration,
                  ClassPool     programClassPool,
                  ClassPool     libraryClassPool) throws IOException
{
    // Check if we have at least some keep commands.
    if (configuration.keep == null)
    {
        throw new IOException("You have to specify '-keep' options for the shrinking step.");
    }

    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());
    libraryClassPool.classesAccept(new ClassCleaner());

    // Create a visitor for printing out the seeds. We're  printing out
    // the program elements that are preserved against shrinking,
    // optimization, or obfuscation.
    KeepMarker keepMarker = new KeepMarker();
    ClassPoolVisitor classPoolvisitor =
        ClassSpecificationVisitorFactory.createClassPoolVisitor(configuration.keep,
                                                                keepMarker,
                                                                keepMarker,
                                                                true,
                                                                true,
                                                                true);
    // Mark the seeds.
    programClassPool.accept(classPoolvisitor);
    libraryClassPool.accept(classPoolvisitor);

    // Print out the seeds.
    SimpleClassPrinter printer = new SimpleClassPrinter(false, ps);
    programClassPool.classesAcceptAlphabetically(new MultiClassVisitor(
        new ClassVisitor[]
        {
            new KeptClassFilter(printer),
            new AllMemberVisitor(new KeptMemberFilter(printer))
        }));
}
 
Example 4
Source File: SeedPrinter.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Prints out the seeds for the classes in the given program class pool.
 * @param configuration the configuration containing the keep options.
 * @throws IOException if an IO error occurs while writing the configuration.
 */
public void write(Configuration configuration,
                  ClassPool     programClassPool,
                  ClassPool     libraryClassPool) throws IOException
{
    // Check if we have at least some keep commands.
    if (configuration.keep == null)
    {
        throw new IOException("You have to specify '-keep' options for the shrinking step.");
    }

    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());
    libraryClassPool.classesAccept(new ClassCleaner());

    // Create a visitor for printing out the seeds. We're  printing out
    // the program elements that are preserved against shrinking,
    // optimization, or obfuscation.
    KeepMarker keepMarker = new KeepMarker();
    ClassPoolVisitor classPoolvisitor =
        ClassSpecificationVisitorFactory.createClassPoolVisitor(configuration.keep,
                                                                keepMarker,
                                                                keepMarker,
                                                                true,
                                                                true,
                                                                true);
    // Mark the seeds.
    programClassPool.accept(classPoolvisitor);
    libraryClassPool.accept(classPoolvisitor);

    // Print out the seeds.
    SimpleClassPrinter printer = new SimpleClassPrinter(false, ps);
    programClassPool.classesAcceptAlphabetically(new MultiClassVisitor(
        new ClassVisitor[]
        {
            new KeptClassFilter(printer),
            new AllMemberVisitor(new KeptMemberFilter(printer))
        }));
}
 
Example 5
Source File: GsonContext.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sets up the Gson context for the given program class pool.
 * Notes will be printed to the given printer if provided.
 *
 * @param programClassPool the program class pool
 * @param libraryClassPool the library class pool
 * @param warningPrinter   the optional warning printer to which notes
 *                         can be printed.
 */
public void setupFor(ClassPool      programClassPool,
                     ClassPool      libraryClassPool,
                     WarningPrinter warningPrinter)
{
    // Only apply remaining optimizations to classes that are not part of
    // Gson itself.
    ClassPool filteredClasses = new ClassPool();
    programClassPool.classesAccept(
        new ClassNameFilter("!com/google/gson/**",
                            new ClassPoolFiller(filteredClasses)));

    // Find all GsonBuilder invocations.
    gsonRuntimeSettings      = new GsonRuntimeSettings();
    GsonBuilderInvocationFinder gsonBuilderInvocationFinder =
        new GsonBuilderInvocationFinder(
            programClassPool,
            libraryClassPool,
            gsonRuntimeSettings,
            new ClassPoolFiller(gsonRuntimeSettings.instanceCreatorClassPool),
            new ClassPoolFiller(gsonRuntimeSettings.typeAdapterClassPool));

    filteredClasses.classesAccept(
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new AllInstructionVisitor(gsonBuilderInvocationFinder))));

    // Find all Gson invocations.
    gsonDomainClassPool = new ClassPool();
    GsonDomainClassFinder domainClassFinder  =
        new GsonDomainClassFinder(gsonRuntimeSettings,
                                  gsonDomainClassPool,
                                  warningPrinter);

    filteredClasses.accept(
        new AllClassVisitor(
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new AllInstructionVisitor(
        new MultiInstructionVisitor(
            new GsonSerializationInvocationFinder(programClassPool,
                                                  libraryClassPool,
                                                  domainClassFinder,
                                                  warningPrinter),
            new GsonDeserializationInvocationFinder(programClassPool,
                                                    libraryClassPool,
                                                    domainClassFinder,
                                                    warningPrinter)))))));
}