|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
proguard.classfile package using
the visitor pattern.
See:
Description
| Interface Summary | |
|---|---|
| ClassPoolVisitor | This interface specifies the methods for a visitor of
ClassPool objects. |
| ClassVisitor | This interface specifies the methods for a visitor of
Clazz objects. |
| MemberVisitor | This interface specifies the methods for a visitor of
ProgramMember objects and LibraryMember
objects. |
| Class Summary | |
|---|---|
| AllClassVisitor | This ClassPoolVisitor lets a given ClassVisitor visit all Clazz objects of the class pools it visits. |
| AllFieldVisitor | This ClassVisitor lets a given MemberVisitor visit all FieldMember objects of the classes it visits. |
| AllMemberVisitor | This ClassVisitor lets a given MemberVisitor visit all Member objects of the classes it visits. |
| AllMethodVisitor | This ClassVisitor lets a given MemberVisitor visit all MethodMember objects of the classes it visits. |
| BottomClassFilter | This ClassVisitor delegates its visits to another given
ClassVisitor, but only when visiting classes that don't
have any subclasses. |
| 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 visitor 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. |
| ClassForNameClassVisitor | This ConstantVisitor lets a given ClassVisitor visit all
constant classes involved in any Class.forName constructs that
it visits. |
| ClassHierarchyTraveler | This ClassVisitor lets a given ClassVisitor
optionally travel to the visited class, its superclass, its interfaces, and
its subclasses. |
| 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. |
| ClassPoolFiller | This ClassVisitor collects all the classes it visits in 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. |
| 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. |
| DotClassClassVisitor | This InstructionVisitor lets a given ClassVisitor visit all
classes involved in any .class constructs 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. |
| 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 another given
ClassVisitor, except for classes that extend or implement
a given class. |
| 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. |
| 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. |
| MemberAccessFilter | This MemberVisitor delegates its visits to another given
MemberVisitor, but only when the visited member has the proper
access flags. |
| MemberClassAccessFilter | This MemberVisitor delegates its visits to another given
MemberVisitor, but only when the visited member is accessible
from the given referencing class. |
| MemberCollector | This MemberVisitor collects the concatenated name/descriptor strings of class members that have been visited. |
| 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. |
| 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. |
| MemberToClassVisitor | This MemberVisitor delegates all visits to a given ClassVisitor. |
| 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. |
| MultiMemberVisitor | This MemberVisitor delegates all visits to each MemberVisitor in a given list. |
| NamedClassVisitor | This class visits Clazz objects with the given name. |
| NamedFieldVisitor | This class visits ProgramMember objects referring to fields, identified by a name and descriptor pair. |
| NamedMethodVisitor | This class visits ProgramMember objects referring to methods, identified by a name and descriptor pair. |
| 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 | This ClassVisitor, MemberVisitor, ConstantVisitor, AttributeVisitor, etc. |
| ReferencedMemberVisitor | This ConstantVisitor and ElementValueVisitor lets a given MemberVisitor visit all the referenced class members of the elements 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 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. |
| 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. |
| 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. |
This package contains interfaces and classes for processing class files from
the package using
the visitor pattern. Cfr., for instance, "Design Patterns, Elements of
Reusable OO Software", by Gamma, Helm, Johnson, and Vlissider.
proguard.classfile
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 visitor accepter. 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 visitor accepter 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 visitor accepters) 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 visitor accepters, in which visitors can put any temporary information they want.
|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||