Java Code Examples for proguard.classfile.Clazz#hierarchyAccept()

The following examples show how to use proguard.classfile.Clazz#hierarchyAccept() . 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: MemberFinder.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether the given method is overridden anywhere down the class
 * hierarchy.
 */
public boolean isOverriden(Clazz  clazz,
                           Method method)
{
    String name       = method.getName(clazz);
    String descriptor = method.getDescriptor(clazz);

    // Go looking for the method down the class hierarchy.
    try
    {
        this.clazz  = null;
        this.member = null;

        clazz.hierarchyAccept(false, false, false, true,
            new NamedMethodVisitor(name, descriptor,
            new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE, this)));
    }
    catch (MemberFoundException ex)
    {
        // We've found an overriding method.
        return true;
    }

    return false;
}
 
Example 2
Source File: MemberFinder.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether the given field is shadowed anywhere down the class
 * hierarchy.
 */
public boolean isShadowed(Clazz clazz,
                          Field field)
{
    String name       = field.getName(clazz);
    String descriptor = field.getDescriptor(clazz);

    // Go looking for the field down the class hierarchy.
    try
    {
        this.clazz  = null;
        this.member = null;
        clazz.hierarchyAccept(false, false, false, true,
            new NamedFieldVisitor(name, descriptor,
            new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE, this)));
    }
    catch (MemberFoundException ex)
    {
        // We've found a shadowing field.
        return true;
    }

    return false;
}
 
Example 3
Source File: MemberFinder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the class member with the given name and descriptor in the given
 * class or its hierarchy.
 */
public Member findMember(Clazz   referencingClass,
                         Clazz   clazz,
                         String  name,
                         String  descriptor,
                         boolean isField)
{
    // Organize a search in the hierarchy of superclasses and interfaces.
    // The class member may be in a different class, if the code was
    // compiled with "-target 1.2" or higher (the default in JDK 1.4).
    try
    {
        this.clazz  = null;
        this.member = null;
        clazz.hierarchyAccept(true, true, true, false, isField ?
            (ClassVisitor)new NamedFieldVisitor(name, descriptor,
                          new MemberClassAccessFilter(referencingClass, this)) :
            (ClassVisitor)new NamedMethodVisitor(name, descriptor,
                          new MemberClassAccessFilter(referencingClass, this)));
    }
    catch (MemberFoundException ex)
    {
        // We've found the member we were looking for.
    }

    return member;
}
 
Example 4
Source File: MethodLinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitAnyClass(Clazz clazz)
{
    // Collect all non-private members in this class hierarchy.
    clazz.hierarchyAccept(true, true, true, false,
        new AllMethodVisitor(
        new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE,
        this)));

    // Clean up for the next class hierarchy.
    memberMap.clear();
}
 
Example 5
Source File: SideEffectInstructionChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the set of superclasses and interfaces that are initialized.
 */
private Set initializedSuperClasses(Clazz clazz)
{
    Set set = new HashSet();

    // Visit all superclasses and interfaces, collecting the ones that have
    // static initializers.
    clazz.hierarchyAccept(true, true, true, false,
                          new StaticInitializerContainingClassFilter(
                          new ClassCollector(set)));

    return set;
}
 
Example 6
Source File: ClassMerger.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the set of superclasses and interfaces that are initialized.
 */
private Set initializedSuperClasses(Clazz clazz)
{
    Set set = new HashSet();

    // Visit all superclasses and interfaces, collecting the ones that have
    // static initializers.
    clazz.hierarchyAccept(true, true, true, false,
                          new StaticInitializerContainingClassFilter(
                          new ClassCollector(set)));

    return set;
}
 
Example 7
Source File: ClassMerger.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the set of superclasses and interfaces that are used in
 * 'instanceof' tests.
 */
private Set instanceofedSuperClasses(Clazz clazz)
{
    Set set = new HashSet();

    // Visit all superclasses and interfaces, collecting the ones that are
    // used in an 'instanceof' test.
    clazz.hierarchyAccept(true, true, true, false,
                          new InstanceofClassFilter(
                          new ClassCollector(set)));

    return set;
}
 
Example 8
Source File: ClassMerger.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the set of superclasses that are caught as exceptions.
 */
private Set caughtSuperClasses(Clazz clazz)
{
    Set set = new HashSet();

    // Visit all superclasses, collecting the ones that are caught.
    clazz.hierarchyAccept(true, true, false, false,
                          new CaughtClassFilter(
                          new ClassCollector(set)));

    return set;
}
 
Example 9
Source File: ClassMerger.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the given class or its subclasses shadow any methods in
 * the given target class.
 */
private boolean shadowsAnyMethods(Clazz clazz, Clazz targetClass)
{
    MemberCounter counter = new MemberCounter();

    // Visit all private methods, counting the ones that are shadowing
    // non-private methods in the class hierarchy of the target class.
    clazz.hierarchyAccept(true, false, false, true,
                          new AllMethodVisitor(
                          new MemberAccessFilter(ClassConstants.INTERNAL_ACC_PRIVATE, 0,
                          new MemberNameFilter(new NotMatcher(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_INIT)),
                          new SimilarMemberVisitor(targetClass, true, true, true, false,
                          new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE,
                          counter))))));

    // Visit all static methods, counting the ones that are shadowing
    // non-private methods in the class hierarchy of the target class.
    clazz.hierarchyAccept(true, false, false, true,
                          new AllMethodVisitor(
                          new MemberAccessFilter(ClassConstants.INTERNAL_ACC_STATIC, 0,
                          new MemberNameFilter(new NotMatcher(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_CLINIT)),
                          new SimilarMemberVisitor(targetClass, true, true, true, false,
                          new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE,
                          counter))))));

    return counter.getCount() > 0;
}
 
Example 10
Source File: MethodInliner.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the set of superclasses and interfaces that are initialized.
 */
private Set initializedSuperClasses(Clazz clazz)
{
    Set set = new HashSet();

    // Visit all superclasses and interfaces, collecting the ones that have
    // static initializers.
    clazz.hierarchyAccept(true, true, true, false,
                          new StaticInitializerContainingClassFilter(
                          new ClassCollector(set)));

    return set;
}