[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Example of Switch mechanism



On Mon, 21 Dec 1998, James C. Corbett wrote:

> Does anyone have an example of the use of the switch mechanism, as
> implemented by the classes AbstractStmtSwitch, AbstractExprSwitch,
> etc.  ?

The idea behind the object-oriented switch is that we have an object of 
type, say, Stmt, but we don't know what type of Stmt it actually is; 
there is code that we want to run if it is an IfStmt, different code for 
a TableSwitchStmt, etc.

An example of this is in ca/mcgill/sable/soot/jimple/JasminClass.java at 
line 164.  You run the apply method on something that is StmtSwitch'd, 
and pass to the apply method a new TypeSwitch() which you define as an 
anonymous class.

pat