Information Technology Reference
In-Depth Information
tactic
eliminateTypeTests
(
X,
''
bool
isX
()
{
result
:=
self is
X
}
”)
;
tactic
eliminateNew
(
X
)
;
law
changeSuperfromEmptyToImmediateSuperclass
(
immedSubs
(
X
)
,
super
(
X
)
,→
)
;
law
classElimination
(
X,→
)
;
end
The auxiliary tactic
moveUpF ields
pulls up the fields declared in
X
to the im-
mediate superclass. If the target superclass has any other subclass declaring the
moved field, the tactic moves two or more fields with the same name to the
superclass in one step; if it is not the case, the single field is moved to the super-
class, with Law
move field to superclass
[22]. Next,
X
's methods are pulled up as
well, with the auxiliary tactic
moveUpMethods
. In this case, the synchronizer
must deal with two cases: redefined and non-redefined methods:
-
The redefined methods are removed from
X
and the corresponding method
body in the superclass is modified with an
if
command that adds the body
of the moved method, using Law
move redefined method to superclass
.Also
within the tactic,
super
method calls are eliminated by inlining from
object
to
X
, top-down in the hierarchy (Law
eliminate super
[22]); for this, all private
fields in this hierarchy are first made public;
-
The non-redefined methods must be copied to other subclasses of
B
,with
an empty body, so no type errors occur with the new method in
B
.
After removing its fields and methods,
X
is replaced by its superclass on decla-
rations over the program, with
changeDeclarationsT ypetoSuper
;inthistactic,
Law
change field type
and analogous laws are applied. Next, In the main tactic,
casts to
X
are removed with another law (
eliminate casts of expressions
). Consec-
utively,
eliminateT ypeT ests
removes type tests involving
X
, with the following
steps:
1. A boolean method
isX
is declared within
B
and its subclasses. This method
is a surrogate for the type tests that are going to be eliminated.
The method body returns the value of testing
self
with
X
and subclasses (in
this example,
Z
);
class
B
{
..
bool
isX()
{
result
:=
self is
X
∨
self is
Z
}}
2. Every occurrence of
x
is
X
must be replaced by a special statement, a
parameterized command
[18]. A parameterized command of the form
test:= (
result
:= x
is
X)
is then be replaced by a method call to
isX
.
For avoiding null pointer errors, we introduce an
if
statement for ensuring
that the expression being tested is not null;
if
(x=
null
)
then
test:= false
else
test:= x.isX()
3. Additional changes are performed for backing up the
isX
test. Field
type
is
introduced and initializations to this field are added to
X
's constructor and
every constructor in
X
's subclasses;
Search WWH ::
Custom Search