Java Reference
In-Depth Information
class ThrowsVisitor extends NodeVisitor
/
This extends the class definition of Figure 9.4
/
procedure
gather
T
hrows
( n )
call
visit
C
hildren
( n )
ans ←∅
foreach c n . getChildren() do ans ans c . throwsSet
n . throwsSet ans
end
procedure
( Trying tn )
call tn . catches . accept( this )
call tn . final . accept( this )
currentCatchList ← get
visit
32
C
atch
L
ist
()
call
( tn . catches )
call tn . tryBody . accept( this )
call
update
C
atch
L
ist
set
C
atch
L
ist
( currentCatchList )
call
( tn . tryBody . throwsSet , tn . catches )
tn . throwsSet ← filter
process
C
atch
( tryBody . throwsSet , tn . catches )
tn . throwsSet tn . throwsSet tn . catches . throwsSet tn . final . throwsSet
C
atches
end
procedure
visit
(Catching cn )
33
call
gather
T
hrows
( cn )
end
procedure
visit
(Throwing tn )
34
call
( tn )
thrownType tn . thrownVal . type
tn . throwsSet tn . thrownVal . throwsSet thrownType
if
visit
C
hildren
assignable
( RuntimeException , thrownType ) or
assignable
( Error , thrownType )
then return
else
throwTargets ← get
C
atch
L
ist
()
∪get
D
ecl
T
hrows
L
ist
()
f ilteredTargets ← filter
T
hrows
( throwTargets , thrownType )
if
size
( throwTargets )
= size
( f ilteredTargets )
then
call
error
(” Type thrown not f ound in enclosing catch or declared throws list ”)
end
procedure
visit
(Calling cn )
35
call gather
( cn )
if cn . calledMethod null
then
cn . throwsSet cn . throwsSet cn . calledMethod . declaredThrowsList
T
hrows
end
end
Figure 9.28: Throws Analysis Visitors (Part 2)
 
Search WWH ::




Custom Search