proguard.classfile.visitor |
This package contains interfaces and classes for processing class files from
the {@link proguard.classfile 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 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.
|
Java Source File Name | Type | Comment |
AllClassVisitor.java | Class | This ClassPoolVisitor lets a given ClassVisitor visit all Clazz
objects of the class pools it visits. |
AllFieldVisitor.java | Class | This ClassVisitor lets a given MemberVisitor visit all FieldMember
objects of the classes it visits. |
AllMemberVisitor.java | Class | This ClassVisitor lets a given MemberVisitor visit all Member
objects of the classes it visits. |
AllMethodVisitor.java | Class | This ClassVisitor lets a given MemberVisitor visit all MethodMember
objects of the classes it visits. |
BottomClassFilter.java | Class | This ClassVisitor delegates its visits to another given
ClassVisitor , but only when visiting classes that don't
have any subclasses. |
ClassAccessFilter.java | Class | This ClassVisitor delegates its visits to another given
ClassVisitor , but only when the visited class
has the proper access flags. |
ClassCleaner.java | Class | This ClassVisitor removes all visitor information of the
classes it visits. |
ClassCollector.java | Class | This ClassVisitor collects the classes that it visits in the
given collection. |
ClassCounter.java | Class | This ClassVisitor counts the number of classes that has been visited. |
ClassForNameClassVisitor.java | Class | This ConstantVisitor lets a given ClassVisitor visit all
constant classes involved in any Class.forName constructs that
it visits. |
ClassHierarchyTraveler.java | Class | This ClassVisitor lets a given ClassVisitor
optionally travel to the visited class, its superclass, its interfaces, and
its subclasses. |
ClassMemberVisitor.java | Class | This MemberVisitor delegates all visits to a given ClassVisitor. |
ClassNameFilter.java | Class | 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.java | Class | This ClassVisitor collects all the classes it visits in a given
class pool. |
ClassPoolVisitor.java | Interface | This interface specifies the methods for a visitor of
ClassPool objects. |
ClassPresenceFilter.java | Class | 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.java | Class | This ClassVisitor prints out the complete internal
structure of the classes it visits. |
ClassVersionFilter.java | Class | 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.java | Class | This ClassVisitor sets the version number of the program classes
that it visits. |
ClassVisitor.java | Interface | This interface specifies the methods for a visitor of
Clazz objects. |
ConcreteClassDownTraveler.java | Class | This ClassVisitor lets a given ClassVisitor
travel to the first concrete subclasses down in its hierarchy of abstract
classes and concrete classes. |
DotClassClassVisitor.java | Class | This InstructionVisitor lets a given ClassVisitor visit all
classes involved in any .class constructs that it visits. |
ExceptionCounter.java | Class | This ExceptionInfoVisitor counts the number of exceptions that has been visited. |
ExceptionExcludedOffsetFilter.java | Class | This ExceptionInfoVisitor delegates its visits to another given
ExceptionInfoVisitor , but only when the visited exception
does not cover the instruction at the given offset. |
ExceptionOffsetFilter.java | Class | This ExceptionInfoVisitor delegates its visits to another given
ExceptionInfoVisitor , but only when the visited exception
covers the instruction at the given offset. |
ExceptionRangeFilter.java | Class | This ExceptionInfoVisitor delegates its visits to another given
ExceptionInfoVisitor , but only when the visited exception
overlaps with the given instruction range. |
LibraryClassFilter.java | Class | This ClassVisitor delegates its visits to another given
ClassVisitor , but only when visiting library classes. |
LibraryMemberFilter.java | Class | This MemberVisitor delegates its visits to another given
MemberVisitor , but only when visiting members of library
classes. |
MemberAccessFilter.java | Class | This MemberVisitor delegates its visits to another given
MemberVisitor , but only when the visited member has the proper
access flags. |
MemberClassAccessFilter.java | Class | This MemberVisitor delegates its visits to another given
MemberVisitor , but only when the visited member is accessible
from the given referencing class. |
MemberCounter.java | Class | This MemberVisitor counts the number of class members that has been visited. |
MemberDescriptorFilter.java | Class | 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.java | Class | 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.java | Class | This MemberVisitor delegates all visits to a given ClassVisitor. |
MemberVisitor.java | Interface | This interface specifies the methods for a visitor of
ProgramMember objects and LibraryMember
objects. |
MethodImplementationFilter.java | Class | This MemberVisitor delegates its visits to methods to
another given MemberVisitor , but only when the visited
method may have implementations. |
MethodImplementationTraveler.java | Class | This MemberVisitor lets a given MemberVisitor
travel to all concrete implementations of the visited methods in their class
hierarchies. |
MultiClassPoolVisitor.java | Class | This ClassPoolVisitor delegates all visits to each ClassPoolVisitor
in a given list. |
MultiClassVisitor.java | Class | This ClassVisitor delegates all visits to each ClassVisitor
in a given list. |
MultiMemberVisitor.java | Class | This MemberVisitor delegates all visits to each MemberVisitor
in a given list. |
NamedClassVisitor.java | Class | This class visits Clazz objects with the given name. |
NamedFieldVisitor.java | Class | This class visits ProgramMember objects referring to fields, identified by
a name and descriptor pair. |
NamedMethodVisitor.java | Class | This class visits ProgramMember objects referring to methods, identified by
a name and descriptor pair. |
ProgramClassFilter.java | Class | This ClassVisitor delegates its visits to another given
ClassVisitor , but only when visiting program classes. |
ProgramMemberFilter.java | Class | This MemberVisitor delegates its visits to another given
MemberVisitor , but only when visiting members of program
classes. |
ReferencedClassVisitor.java | Class | This ClassVisitor, MemberVisitor, ConstantVisitor, AttributeVisitor, etc. |
ReferencedMemberVisitor.java | Class | This ConstantVisitor and ElementValueVisitor lets a given MemberVisitor
visit all the referenced class members of the elements that it visits. |
SimpleClassPrinter.java | Class | 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. |
VariableClassVisitor.java | Class | This ClassVisitor delegates all method calls to a ClassVisitor
that can be changed at any time. |
VariableMemberVisitor.java | Class | This MemberVisitor delegates all method calls to a MemberVisitor
that can be changed at any time. |