proguard.classfile
package using the visitor pattern.See: Description
Interface | Description |
---|---|
ClassPoolVisitor |
This interface specifies the methods for a visitor of
ClassPool instances. |
ClassVisitor |
This interface specifies the methods for a visitor of
Clazz instances. |
MemberVisitor |
This interface specifies the methods for a visitor of
ProgramMember instances and LibraryMember
instances. |
ParallelAllClassVisitor.ClassVisitorFactory |
A factory for
ClassVisitor objects. |
ParameterVisitor |
This interface specifies the methods for a visitor of method parameters or
field types (which can be considered parameters when storing values).
|
Class | Description |
---|---|
AllClassVisitor |
This
ClassPoolVisitor lets a given ClassVisitor visit all Clazz
instances of the class pools it visits. |
AllFieldVisitor | |
AllMemberVisitor |
This
ClassVisitor lets a given MemberVisitor visit all Member
instances of the classes it visits. |
AllMethodVisitor | |
BottomClassFilter |
This
ClassVisitor delegates its visits to one of two other given
ClassVisitor instances, depending on whether they have any
subclasses or not. |
ClassAccessFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , but only when the visited class
has the proper access flags. |
ClassCleaner |
This
ClassVisitor removes all processing information of the
classes it visits. |
ClassCollector |
This
ClassVisitor collects the classes that it visits in the
given collection. |
ClassCounter |
This
ClassVisitor counts the number of classes that has been visited. |
ClassFeatureNameCollector |
This
ClassVisitor collects the feature names of the classes
that it visits in the given collection. |
ClassHierarchyTraveler |
This
ClassVisitor lets a given ClassVisitor
optionally travel to the visited class, its superclass, its interfaces, and
its subclasses. |
ClassNameCollector |
This
ClassVisitor collects the names of the classes that it
visits in the given collection. |
ClassNameFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , but only when the visited class has a name that
matches a given regular expression. |
ClassPoolClassVisitor |
This
ClassPoolVisitor and ClassVisitor remembers the ClassPool instances
that it visits and applies the given ClassPoolVisitor to the most
recently remembered one, every time it visits a Clazz instance. |
ClassPoolFiller |
This
ClassVisitor collects all the classes it visits in a given
class pool. |
ClassPoolRemover |
This
ClassVisitor removes all the classes it visits from a given
class pool. |
ClassPresenceFilter |
This
ClassVisitor delegates its visits to one of two
ClassVisitor instances, depending on whether the name of
the visited class file is present in a given ClassPool or not. |
ClassPrinter |
This
ClassVisitor prints out the complete internal
structure of the classes it visits. |
ClassProcessingFlagFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , but only when the visited class
has the proper processing flags. |
ClassProcessingInfoFilter |
Delegates all class visits to another given visitor, depending on if the given predicate passes or not.
|
ClassVersionFilter |
This
ClassVisitor delegates its visits to program classes to
another given ClassVisitor , but only when the class version
number of the visited program class lies in a given range. |
ClassVersionSetter |
This
ClassVisitor sets the version number of the program classes
that it visits. |
ConcreteClassDownTraveler |
This
ClassVisitor lets a given ClassVisitor
travel to the first concrete subclasses down in its hierarchy of abstract
classes and concrete classes. |
ConstantProcessingFlagFilter |
This
ConstantVisitor delegates its visits to another given ConstantVisitor ,
but only when the visited constant has the proper processing flags. |
ConstructorMethodFilter |
This
MemberVisitor delegates its visits to one of three delegates, depending on whether the visited method is:
- a constructor
- a constructor that calls a super constructor
- or another method. |
CounterConditionalClassVisitor |
This ClassVisitor delegates to a given class visitor, and then, if the given predicate succeeds
with the given
Counter before and after values, also to a second given class visitor. |
DotClassClassVisitor |
This
InstructionVisitor lets a given ClassVisitor visit all
classes involved in any .class constructs that it visits. |
DynamicReturnedClassVisitor |
This
ConstantVisitor lets a given ClassVisitor visit all the referenced
classes that are returned by the dynamic constants and invoke dynamic
constants that it visits. |
ExceptClassesFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , except for classes are in a given list. |
ExceptClassFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , except for one given class. |
ExceptionCounter |
This
ExceptionInfoVisitor counts the number of exceptions that has been visited. |
ExceptionExcludedOffsetFilter |
This
ExceptionInfoVisitor delegates its visits to another given
ExceptionInfoVisitor , but only when the visited exception
does not cover the instruction at the given offset. |
ExceptionHandlerConstantVisitor |
This
ExceptionInfoVisitor lets a given
ConstantVisitor visit all catch class constants of exceptions
that it visits. |
ExceptionHandlerFilter |
This
ExceptionInfoVisitor delegates its visits to another given
ExceptionInfoVisitor , but only when the visited exception
targets an instruction in the given range of offsets. |
ExceptionOffsetFilter |
This
ExceptionInfoVisitor delegates its visits to another given
ExceptionInfoVisitor , but only when the visited exception
covers the instruction at the given offset. |
ExceptionRangeFilter |
This
ExceptionInfoVisitor delegates its visits to another given
ExceptionInfoVisitor , but only when the visited exception
overlaps with the given instruction range. |
FilteredClassVisitor |
This
ClassPoolVisitor lets a given ClassVisitor visit all matching Clazz
instances of the class pools it visits. |
FunctionalInterfaceFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , but only for functional interfaces, that
is, interface classes that have exactly one abstract method. |
ImplementedClassConstantFilter |
This
ConstantVisitor delegates its visits to class constants
to another given ConstantVisitor , except for classes that
extend or implement a given class. |
ImplementedClassFilter |
This
ClassVisitor delegates its visits to one of two given
ClassVisitor s, depending on whether the visited classes
extend/implement a given class or not. |
ImplementingClassConstantFilter |
This
ConstantVisitor delegates its visits to class constants
to another given ConstantVisitor , except for classes that
are extended or implemented by a given class. |
InitializerMethodFilter |
This
MemberVisitor delegates its visits to one of two other given
MemberVisitor instances, depending on whether the visited method
is a static initializer or instance initializer, or not. |
LibraryClassFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , but only when visiting library classes. |
LibraryMemberFilter |
This
MemberVisitor delegates its visits to another given
MemberVisitor , but only when visiting members of library
classes. |
LineNumberFinder |
Retrieves the lineNumber for a given offset from a codeattribute.
|
MemberAccessFilter |
This
MemberVisitor delegates its visits to another given
MemberVisitor , but only when the visited member has the proper
access flags. |
MemberAccessFlagCleaner |
This
ClassVisitor and MemberVisitor clears the specified
access flags of the classes and class members that its visits. |
MemberAccessFlagSetter |
This
MemberVisitor sets the specified access flags of the
program class members that it visits. |
MemberAccessSetter |
This
MemberVisitor sets the access part of the access flags of
the program class members that its visits to a given value. |
MemberClassAccessFilter |
This
MemberVisitor delegates its visits to another given
MemberVisitor , but only when the visited member is accessible
from the given referencing class. |
MemberCollectionFilter |
This MemberVisitor delegates its visits to one of two other visitors,
depending on whether the member is present in the given member collection or not.
|
MemberCollector |
This
MemberVisitor collects dot-separated classname.membername.descriptor
strings of the class members that it visits. |
MemberCounter |
This
MemberVisitor counts the number of class members that have been visited. |
MemberDescriptorFilter |
This
MemberVisitor delegates its visits to another given
MemberVisitor , but only when the visited member
has a descriptor that matches a given regular expression. |
MemberDescriptorReferencedClassVisitor |
This
MemberVisitor lets a given ClassVisitor visit all the classes
referenced by the descriptors of the class members that it visits. |
MemberNameFilter |
This
MemberVisitor delegates its visits to another given
MemberVisitor , but only when the visited member
has a name that matches a given regular expression. |
MemberProcessingFlagFilter |
This
MemberVisitor delegates its visits to another given
MemberVisitor , but only when the visited member has the proper
processing flags. |
MemberToClassVisitor |
This
MemberVisitor delegates all visits to a given ClassVisitor . |
MethodCollector |
This
MemberVisitor collects the methods that it visits in the
given collection. |
MethodCounter |
This
MemberVisitor counts the number of methods that have been visited. |
MethodFilter |
This
MemberVisitor delegates its visits to one of two other given
MemberVisitor instances, depending on whether the visited method
is a method or a field. |
MethodImplementationFilter |
This
MemberVisitor delegates its visits to methods to
another given MemberVisitor , but only when the visited
method may have implementations. |
MethodImplementationTraveler |
This
MemberVisitor lets a given MemberVisitor
travel to all concrete and abstract implementations of the visited methods
in their class hierarchies. |
MultiClassPoolVisitor |
This
ClassPoolVisitor delegates all visits to each ClassPoolVisitor
in a given list. |
MultiClassVisitor |
This
ClassVisitor delegates all visits to each ClassVisitor
in a given list. |
MultiConstantVisitor |
This
ConstantVisitor delegates all visits to each ConstantVisitor in a given list. |
MultiMemberVisitor |
This
MemberVisitor delegates all visits to each MemberVisitor
in a given list. |
NamedClassVisitor |
This
ClassPoolVisitor lets a given ClassVisitor visit
Clazz instances with a given name, in the class pools that it
visits. |
NamedFieldVisitor |
This class visits
ProgramMember instances referring to fields, identified by
a name and descriptor pair. |
NamedMethodVisitor |
This class visits
ProgramMember instances referring to methods, identified by
a name and descriptor pair. |
ParallelAllClassVisitor |
This
ClassPoolVisitor will visit all Clazz instances of the class pool
in a parallel way. |
ProcessingInfoSetter |
This visitor sets a fixed info object on all the
Processable
instances that it visits. |
ProgramClassFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , but only when visiting program classes. |
ProgramMemberFilter |
This
MemberVisitor delegates its visits to another given
MemberVisitor , but only when visiting members of program
classes. |
ReferencedClassVisitor | |
ReferencedMemberVisitor |
This
ConstantVisitor and ElementValueVisitor lets a given MemberVisitor
visit all the referenced class members of the elements that it visits. |
ReturnClassExtractor |
Returns the last referenced class of referencedClasses from the program-/ librarymethod.
|
SignatureAttributeReferencedClassVisitor |
This
AttributeVisitor lets a given ClassVisitor visit all the
classes referenced by the type descriptors of the signatures that it visits. |
SimilarMemberVisitor |
This
MemberVisitor lets a given MemberVisitor
visit all members that have the same name and type as the visited methods
in the class hierarchy of the members' classes or of a given target class. |
SimpleClassPrinter |
This
ClassVisitor and MemberVisitor
prints out the class names of the classes it visits, and the full class
member descriptions of the class members it visits. |
SingleTimeClassVisitor |
This
ClassVisitor delegates all visits to a given ClassVisitor , although
only once to the same class in a row. |
SubclassFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , except for classes that have a given class as
direct subclass. |
SubclassTraveler |
This
ClassVisitor lets a given ClassVisitor
travel to direct subclasses of the visited class. |
UniqueClassFilter |
This
ClassVisitor delegates its visits to another given
ClassVisitor , but at most a single time. |
VariableClassVisitor |
This
ClassVisitor delegates all method calls to a ClassVisitor
that can be changed at any time. |
VariableMemberVisitor |
This
MemberVisitor delegates all method calls to a MemberVisitor
that can be changed at any time. |
proguard.classfile
package using the visitor pattern.
Cfr., for instance, "Design Patterns, Elements of Reusable OO Software", by
Gamma, Helm, Johnson, and Vlissider.
Why the visitor pattern? Class files frequently contain lists of elements of
various mixed types: class items, constant pool entries, attributes,...
These lists and types are largely fixed; they won't change much in future
releases of the Java class file specifications. On the other hand, the kinds
of operations that we may wish to perform on the class files may change and
expand. We want to separate the objects and the operations performed upon them.
This is a good place to use the visitor pattern.
Visitor interfaces avoid having to do series of instanceof
tests
on the elements of a list, followed by type casts and the proper operations.
Every list element is a processable. When its accept
method
is called by a visitor, it calls its corresponding visitX
method
in the visitor, passing itself as an argument. This technique is called
double-dispatch.
As already mentioned, the main advantage is avoiding lots of
instanceof
tests and type casts. Also, implementing a visitor
interface ensures you're handling all possible processable types. Each
type has its own method, which you simply have to implement.
A disadvantage is that the visitor methods always get the same names, specified
by the visitor interface. These names aren't descriptive at all, making code
harder to read. It's the visitor classes that describe the operations now.
Also, the visitor methods always have the same parameters and return values, as
specified by the visitor interfaces. Passing additional parameters is done by
means of extra fields in the visitor, which is somewhat of a kludge.
Because objects (the processables) and the operations performed upon them
(the visitors) are now separated, it becomes harder to associate some state
with the objects. For convenience, we always provide an extra visitor
info field in processables, in which visitors can put any temporary
information they want.