public class Goto
extends java.lang.RuntimeException
Throw
able object.
when GOTOs reference a target that is outside the scope of the GOTO statement
(i.e. within an enclosing procedure which called the procedure containing
the GOTO statement) the Java code will bounce up (perhaps multiple) levels of
nested procedures to the location of that outer label.
Example, turn the following PL/I code:
A: PROC OPTIONS(MAIN); B: PROC; ... C: E=3; ... IF (...) THEN GOTO C; ... IF (...) THEN GOTO D; ... D: E = 2; ... IF (...) THEN GOTO E; END B; ... CALL B; ... E: E=4; ... END A;with scoped labels named "A:B:C" , "A:B:D" and "A:E" and generate code blocks roughly equivalent to:
public class A { public void a() { ... e: try { e = 4; catch (Goto exception) { exception.rethrowIfNotMe("A:E") } ... } // end a private void b() { ... c: while (true) { e=3; ... if (...) continue c; // backward GOTO C ... break c; } d: { ... if (...) break d; // forward GOTO D ... } e=2; ... if (...) throw new Goto("A:E"); // outer GOTO E } public void main(String [] args) { ... a(); ... } }
Constructor and Description |
---|
Goto()
Construct a Goto State
|
Goto(java.lang.String goToLabel)
Construct a Goto Exception
|
Modifier and Type | Method and Description |
---|---|
boolean |
isTarget(java.lang.String checkLabel)
isTarget - return true if you are here or if this is a new
Goto state (not looking for any target) and the parameter is
null indicating that this block should be executed once
|
java.lang.String |
label()
Return the label used to create this Goto
|
Goto |
rethrowIfNotFound()
Do nothing if the goto state is null meaning that
the GOTO label was found at some point by isTarget()
and executed at least one LabeledBlock within the GOTO
loop.
|
Goto |
rethrowIfNotMe(java.lang.String checkLabel)
Do nothing if the goto label matches
this object's label, otherwise throw the condition
|
public Goto(java.lang.String goToLabel)
public Goto()
public Goto rethrowIfNotMe(java.lang.String checkLabel) throws Goto
checkLabel
- - the label to check against this labelthis
- Goto if this is not at this levelGoto
public Goto rethrowIfNotFound()
this
- if this label was not found at this GOTO looppublic boolean isTarget(java.lang.String checkLabel)
checkLabel
- - the canonical name of the label to check,
may be nullpublic java.lang.String label()