author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Thu, 30 Oct 2014 21:30:10 +0100 | |
changeset 409 | 40cabcdcd2be |
parent 266 | 47d5f1fe0b03 |
permissions | -rw-r--r-- |
jtulach@169 | 1 |
package org.apidesign.visitor; |
jtulach@169 | 2 |
|
jtulach@327 | 3 |
|
jtulach@327 | 4 |
// BEGIN: visitor.cleandefinitionofversion |
jtulach@169 | 5 |
public final class Language { |
jtulach@169 | 6 |
private Language() { } |
jtulach@169 | 7 |
|
jtulach@169 | 8 |
public static abstract class Expression { |
jtulach@169 | 9 |
Expression() {} |
jtulach@169 | 10 |
public abstract void visit(Visitor v); |
jtulach@169 | 11 |
} |
jtulach@169 | 12 |
public static final class Plus extends Expression { |
jtulach@169 | 13 |
private final Expression first; |
jtulach@169 | 14 |
private final Expression second; |
jtulach@169 | 15 |
|
jtulach@169 | 16 |
public Plus(Expression first, Expression second) { |
jtulach@169 | 17 |
this.first = first; |
jtulach@169 | 18 |
this.second = second; |
jtulach@169 | 19 |
} |
jtulach@169 | 20 |
public Expression getFirst() { return first; } |
jtulach@169 | 21 |
public Expression getSecond() { return second; } |
jtulach@169 | 22 |
@Override |
jtulach@170 | 23 |
public void visit(Visitor v) { |
jtulach@266 | 24 |
if (v instanceof Visitor10) { |
jtulach@266 | 25 |
((Visitor10)v).visitPlus(this); |
jtulach@170 | 26 |
} else { |
jtulach@170 | 27 |
v.visitUnknown(this); |
jtulach@170 | 28 |
} |
jtulach@170 | 29 |
} |
jtulach@169 | 30 |
} |
jtulach@169 | 31 |
public static final class Number extends Expression { |
jtulach@169 | 32 |
private final int value; |
jtulach@169 | 33 |
public Number(int value) { this.value = value; } |
jtulach@169 | 34 |
public int getValue() { return value; } |
jtulach@169 | 35 |
@Override |
jtulach@170 | 36 |
public void visit(Visitor v) { |
jtulach@266 | 37 |
if (v instanceof Visitor10) { |
jtulach@266 | 38 |
((Visitor10)v).visitNumber(this); |
jtulach@170 | 39 |
} else { |
jtulach@170 | 40 |
v.visitUnknown(this); |
jtulach@170 | 41 |
} |
jtulach@170 | 42 |
} |
jtulach@169 | 43 |
} |
jtulach@169 | 44 |
|
jtulach@169 | 45 |
public interface Visitor { |
jtulach@169 | 46 |
public void visitUnknown(Expression e); |
jtulach@170 | 47 |
} |
jtulach@170 | 48 |
|
jtulach@266 | 49 |
public interface Visitor10 extends Visitor { |
jtulach@169 | 50 |
public void visitPlus(Plus s); |
jtulach@169 | 51 |
public void visitNumber(Number n); |
jtulach@169 | 52 |
} |
jtulach@169 | 53 |
} |
jtulach@327 | 54 |
// END: visitor.cleandefinitionofversion |