author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Thu, 30 Oct 2014 21:30:10 +0100 | |
changeset 409 | 40cabcdcd2be |
parent 170 | 206cdfeefeec |
permissions | -rw-r--r-- |
jtulach@169 | 1 |
package org.apidesign.visitor; |
jtulach@169 | 2 |
|
jtulach@169 | 3 |
public final class Language { |
jtulach@170 | 4 |
|
jtulach@170 | 5 |
private Language() { |
jtulach@170 | 6 |
} |
jtulach@170 | 7 |
|
jtulach@169 | 8 |
public static abstract class Expression { |
jtulach@170 | 9 |
|
jtulach@170 | 10 |
Expression() { |
jtulach@170 | 11 |
} |
jtulach@170 | 12 |
|
jtulach@169 | 13 |
public abstract void visit(Visitor v); |
jtulach@169 | 14 |
} |
jtulach@170 | 15 |
|
jtulach@169 | 16 |
public static final class Plus extends Expression { |
jtulach@170 | 17 |
|
jtulach@169 | 18 |
private final Expression first; |
jtulach@169 | 19 |
private final Expression second; |
jtulach@170 | 20 |
|
jtulach@169 | 21 |
public Plus(Expression first, Expression second) { |
jtulach@169 | 22 |
this.first = first; |
jtulach@169 | 23 |
this.second = second; |
jtulach@169 | 24 |
} |
jtulach@170 | 25 |
|
jtulach@170 | 26 |
public Expression getFirst() { |
jtulach@170 | 27 |
return first; |
jtulach@170 | 28 |
} |
jtulach@170 | 29 |
|
jtulach@170 | 30 |
public Expression getSecond() { |
jtulach@170 | 31 |
return second; |
jtulach@170 | 32 |
} |
jtulach@170 | 33 |
|
jtulach@169 | 34 |
@Override |
jtulach@170 | 35 |
public void visit(Visitor v) { |
jtulach@266 | 36 |
if (v instanceof Visitor10) { |
jtulach@266 | 37 |
((Visitor10) v).visitPlus(this); |
jtulach@170 | 38 |
} else { |
jtulach@170 | 39 |
v.visitUnknown(this); |
jtulach@170 | 40 |
} |
jtulach@170 | 41 |
} |
jtulach@169 | 42 |
} |
jtulach@170 | 43 |
|
jtulach@169 | 44 |
public static final class Number extends Expression { |
jtulach@170 | 45 |
|
jtulach@169 | 46 |
private final int value; |
jtulach@170 | 47 |
|
jtulach@170 | 48 |
public Number(int value) { |
jtulach@170 | 49 |
this.value = value; |
jtulach@170 | 50 |
} |
jtulach@170 | 51 |
|
jtulach@170 | 52 |
public int getValue() { |
jtulach@170 | 53 |
return value; |
jtulach@170 | 54 |
} |
jtulach@170 | 55 |
|
jtulach@169 | 56 |
@Override |
jtulach@170 | 57 |
public void visit(Visitor v) { |
jtulach@266 | 58 |
if (v instanceof Visitor10) { |
jtulach@266 | 59 |
((Visitor10) v).visitNumber(this); |
jtulach@170 | 60 |
} else { |
jtulach@170 | 61 |
v.visitUnknown(this); |
jtulach@170 | 62 |
} |
jtulach@170 | 63 |
} |
jtulach@169 | 64 |
} |
jtulach@170 | 65 |
|
jtulach@169 | 66 |
/** @since 2.0 */ |
jtulach@169 | 67 |
public static final class Minus extends Expression { |
jtulach@169 | 68 |
private final Expression first; |
jtulach@169 | 69 |
private final Expression second; |
jtulach@169 | 70 |
|
jtulach@169 | 71 |
public Minus(Expression first, Expression second) { |
jtulach@169 | 72 |
this.first = first; |
jtulach@169 | 73 |
this.second = second; |
jtulach@169 | 74 |
} |
jtulach@169 | 75 |
public Expression getFirst() { return first; } |
jtulach@169 | 76 |
public Expression getSecond() { return second; } |
jtulach@169 | 77 |
|
jtulach@169 | 78 |
// BEGIN: visitor.cleanversion.dispatch2 |
jtulach@169 | 79 |
public void visit(Visitor v) { |
jtulach@266 | 80 |
if (v instanceof Visitor20) { |
jtulach@266 | 81 |
((Visitor20)v).visitMinus(this); |
jtulach@169 | 82 |
} else { |
jtulach@169 | 83 |
v.visitUnknown(this); |
jtulach@169 | 84 |
} |
jtulach@169 | 85 |
} |
jtulach@169 | 86 |
// END: visitor.cleanversion.dispatch2 |
jtulach@169 | 87 |
} |
jtulach@169 | 88 |
|
jtulach@169 | 89 |
// BEGIN: visitor.cleanversion.v2 |
jtulach@169 | 90 |
public interface Visitor { |
jtulach@169 | 91 |
public void visitUnknown(Expression e); |
jtulach@170 | 92 |
} |
jtulach@266 | 93 |
public interface Visitor10 extends Visitor { |
jtulach@169 | 94 |
public void visitPlus(Plus s); |
jtulach@169 | 95 |
public void visitNumber(Number n); |
jtulach@169 | 96 |
} |
jtulach@169 | 97 |
/** @since 2.0 */ |
jtulach@266 | 98 |
public interface Visitor20 extends Visitor10 { |
jtulach@169 | 99 |
public void visitMinus(Minus s); |
jtulach@169 | 100 |
} |
jtulach@169 | 101 |
// END: visitor.cleanversion.v2 |
jtulach@169 | 102 |
} |