Databases Reference
In-Depth Information
If one of those supertypes is contained in the slice, then the original supertype is
added to the slice. If this method adds any new entities to the work-list, the algo-
rithm is repeated from the start.
There are two special cases where this heuristic fails to include neces-
sary supertypes. The first is classes that either directly or indirectly implement
java.lang.Throwable . If a class is ever thrown, it must implement Throwable .
Ye t Throwable might never be explicitly mentioned in the code, as the requirement
is implicit in the throws statement. The second case is classes that implement
java.lang.Iterable . Enhanced for loops can implicitly require classes imple-
menting Iterable To solve both of these cases, Throwable and Iterable must be
explicitly added to the slice. This results in the heuristic always retaining the type
relationship.
A second difficulty introduced by the type hierarchy is due to abstract types
and implementation inheritance. Interfaces and abstract classes can both define
abstract methods which every non-abstract subtype is forced to implement. For
example, the interface java.lang.Iterable mentioned previously requires the
method iterator() to be implemented in every subtype. So if a class such as
ByteArrayOutputStream implements Closeable it must contain a method named
close with the proper signature in order to compile. Thus for a slice to compile, it
must include all the methods required by abstract declarations, whether or not they
are explicitly referenced within the slice.
Methods overriding non-required methods within the slice must also be added
in order to preserve correct functionality. So if ByteArrayOutputStream extends
OutputStream and both have a method named write if OutputStream 's write
method is in the slice then ByteArrayOutputStream 's write method must also be
included, whether it is explicitly referenced on not. Given the dynamic binding of
method calls in Java, it is not always clear statically if these methods are called. But
if a supertype's method is referenced, then it is possible that it is in fact a subtype's
overriding method that is actually being executed.
Once each type's type hierarchy has been examined, with the appropriate super-
types added to the slice, the next step is to ensure that all of the required methods are
present for that type. Our heuristic states that a method is required if it overrides a
supertype's method that is also in the slice. This ensures that all the requirements for
abstract supertypes are met, plus that all overriding methods are present that could
potentially be called while the type is upcast to a supertype.
Constructors and fields are not handled in this manner, as they cannot be required
by abstract types and are not dynamically bound.
11.6.3 Information Hiding
The separation between abstract types and their implementations in Java impacts
the selection of a seed declaration. If a seed declaration is chosen such that only the
abstract types are ever referenced, the slice does not include their implementations.
Search WWH ::




Custom Search