Java Code Examples for proguard.classfile.attribute.visitor.AllAttributeVisitor

The following examples show how to use proguard.classfile.attribute.visitor.AllAttributeVisitor. 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
Source Project: proguard   Source File: Preverifier.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs preverification of the given program class pool.
 */
public void execute(ClassPool programClassPool)
{
    // Clean up any old processing info.
    programClassPool.classesAccept(new ClassCleaner());

    // Preverify all methods.
    // Classes for JME must be preverified.
    // Classes for JSE 6 may optionally be preverified.
    // Classes for JSE 7 or higher must be preverified.
    programClassPool.classesAccept(
        new ClassVersionFilter(configuration.microEdition ?
                                   VersionConstants.CLASS_VERSION_1_0 :
                                   VersionConstants.CLASS_VERSION_1_6,
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new CodePreverifier(configuration.microEdition)))));
}
 
Example 2
Source Project: proguard   Source File: SubroutineInliner.java    License: GNU General Public License v2.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 processing 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 &&
        !configuration.android)
    {
        inliner =
            new ClassVersionFilter(VersionConstants.CLASS_VERSION_1_6,
                                   inliner);
    }

    programClassPool.classesAccept(inliner);
}
 
Example 3
Source Project: java-n-IDE-for-Android   Source File: Preverifier.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Performs preverification of the given program class pool.
 */
public void execute(ClassPool programClassPool)
{
    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());

    // Preverify all methods.
    ClassVisitor preverifier =
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new CodePreverifier(configuration.microEdition)));

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

    programClassPool.classesAccept(preverifier);
}
 
Example 4
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 5
public FieldOptimizationInfo(Clazz clazz, Field field)
{
    int accessFlags = field.getAccessFlags();

    isWritten =
    isRead    = (accessFlags & ClassConstants.INTERNAL_ACC_VOLATILE) != 0;

    if ((accessFlags & ClassConstants.INTERNAL_ACC_STATIC) != 0)
    {
        // See if we can initialize the static field with a constant value.
        field.accept(clazz, new AllAttributeVisitor(this));
    }

    if ((accessFlags & ClassConstants.INTERNAL_ACC_FINAL) == 0 &&
        value == null)
    {
        // Otherwise initialize the non-final field with the default value.
        value = initialValue(field.getDescriptor(clazz));
    }
}
 
Example 6
Source Project: proguard   Source File: Preverifier.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs preverification of the given program class pool.
 */
public void execute(ClassPool programClassPool)
{
    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());

    // Preverify all methods.
    // Classes for JME must be preverified.
    // Classes for JSE 6 may optionally be preverified.
    // Classes for JSE 7 or higher must be preverified.
    programClassPool.classesAccept(
        new ClassVersionFilter(configuration.microEdition ?
                                   ClassConstants.CLASS_VERSION_1_0 :
                                   ClassConstants.CLASS_VERSION_1_6,
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new CodePreverifier(configuration.microEdition)))));
}
 
Example 7
Source Project: proguard   Source File: SubroutineInliner.java    License: GNU General Public License v2.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.CLASS_VERSION_1_6,
                                   inliner);
    }

    programClassPool.classesAccept(inliner);
}
 
Example 8
Source Project: bazel   Source File: Preverifier.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Performs preverification of the given program class pool.
 */
public void execute(ClassPool programClassPool)
{
    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());

    // Preverify all methods.
    // Classes for JME must be preverified.
    // Classes for JSE 6 may optionally be preverified.
    // Classes for JSE 7 or higher must be preverified.
    programClassPool.classesAccept(
        new ClassVersionFilter(configuration.microEdition ?
                                   ClassConstants.CLASS_VERSION_1_0 :
                                   ClassConstants.CLASS_VERSION_1_6,
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new CodePreverifier(configuration.microEdition)))));
}
 
Example 9
Source Project: bazel   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.CLASS_VERSION_1_6,
                                   inliner);
    }

    programClassPool.classesAccept(inliner);
}
 
Example 10
@Override
public void visitProgramClass(ProgramClass programClass)
{
    final Object mark = new Object();

    // Mark annotations when we are sure that they are not required
    // anymore by GSON.
    if (!gsonRuntimeSettings.setFieldNamingPolicy &&
        !gsonRuntimeSettings.setFieldNamingStrategy)
    {
        programClass.fieldsAccept(
            new AllAttributeVisitor(
            new AllAnnotationVisitor(
            new AnnotationTypeFilter(GsonClassConstants.ANNOTATION_TYPE_SERIALIZED_NAME,
            new ProcessingInfoSetter(mark)))));
    }

    programClass.fieldsAccept(
        new AllAttributeVisitor(
        new AllAnnotationVisitor(
        new AnnotationTypeFilter(GsonClassConstants.ANNOTATION_TYPE_EXPOSE,
        new ProcessingInfoSetter(mark)))));

    // Remove marked annotations.
    programClass.fieldsAccept(
        new AllAttributeVisitor(
        new MarkedAnnotationDeleter(mark)));

    // Unmark all annotations on fields.
    programClass.fieldsAccept(
        new AllAttributeVisitor(
        new AllAnnotationVisitor(
        new ProcessingInfoSetter(null))));
}
 
Example 11
Source Project: proguard   Source File: ProGuard.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Clears any JSE preverification information from the program classes.
 */
private void clearPreverification()
{
    programClassPool.classesAccept(
        new ClassVersionFilter(VersionConstants.CLASS_VERSION_1_6,
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new NamedAttributeDeleter(Attribute.STACK_MAP_TABLE)))));
}
 
Example 12
/**
 * Checks whether the referenced method is a .class method.
 */
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    String methodType = methodrefConstant.getType(clazz);

    // Do the method's class and type match?
    if (methodType.equals(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JAVAC) ||
        methodType.equals(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JIKES))
    {
        String methodName = methodrefConstant.getName(clazz);

        // Does the method's name match one of the special names?
        isClassForNameInvocation =
            methodName.equals(ClassConstants.INTERNAL_METHOD_NAME_DOT_CLASS_JAVAC) ||
            methodName.equals(ClassConstants.INTERNAL_METHOD_NAME_DOT_CLASS_JIKES);

        if (isClassForNameInvocation)
        {
            return;
        }

        String className = methodrefConstant.getClassName(clazz);

        // Note that we look for the class by name, since the referenced
        // class has not been initialized yet.
        Clazz referencedClass = programClassPool.getClass(className);
        if (referencedClass != null)
        {
            // Check if the code of the referenced method is .class code.
            // Note that we look for the method by name and type, since the
            // referenced method has not been initialized yet.
            referencedClass.methodAccept(methodName,
                                         methodType,
                                         new AllAttributeVisitor(this));
        }
    }
}
 
Example 13
Source Project: proguard   Source File: ProGuard.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Clears any JSE preverification information from the program classes.
 */
private void clearPreverification()
{
    programClassPool.classesAccept(
        new ClassVersionFilter(ClassConstants.CLASS_VERSION_1_6,
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new NamedAttributeDeleter(ClassConstants.ATTR_StackMapTable)))));
}
 
Example 14
Source Project: bazel   Source File: ProGuard.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Clears any JSE preverification information from the program classes.
 */
private void clearPreverification()
{
    programClassPool.classesAccept(
        new ClassVersionFilter(ClassConstants.CLASS_VERSION_1_6,
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new NamedAttributeDeleter(ClassConstants.ATTR_StackMapTable)))));
}
 
Example 15
Source Project: proguard   Source File: GsonContext.java    License: 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)))))));
}
 
Example 16
Source Project: proguard   Source File: ProGuard.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Trims the line number table attributes of all program classes.
 */
private void trimLineNumbers()
{
    programClassPool.classesAccept(new AllAttributeVisitor(true,
                                   new LineNumberTableAttributeTrimmer()));
}
 
Example 17
Source Project: proguard   Source File: ProGuard.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Trims the line number table attributes of all program classes.
 */
private void trimLineNumbers()
{
    programClassPool.classesAccept(new AllAttributeVisitor(true,
                                   new LineNumberTableAttributeTrimmer()));
}
 
Example 18
Source Project: bazel   Source File: ProGuard.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Trims the line number table attributes of all program classes.
 */
private void trimLineNumbers()
{
    programClassPool.classesAccept(new AllAttributeVisitor(true,
                                   new LineNumberTableAttributeTrimmer()));
}