author | Jaroslav Tulach <jtulach@netbeans.org> |
Sun, 06 Oct 2013 22:05:14 +0200 | |
changeset 407 | e1439046d96e |
parent 177 | 67d6dceb1002 |
permissions | -rw-r--r-- |
jtulach@176 | 1 |
package org.apidesign.visitor; |
jtulach@176 | 2 |
|
jtulach@176 | 3 |
public final class Language { |
jtulach@176 | 4 |
private Language() { } |
jtulach@176 | 5 |
|
jtulach@176 | 6 |
public interface Expression { |
jtulach@176 | 7 |
public abstract void visit(Visitor v); |
jtulach@176 | 8 |
} |
jtulach@176 | 9 |
public interface Plus extends Expression { |
jtulach@176 | 10 |
public Expression getFirst(); |
jtulach@176 | 11 |
public Expression getSecond(); |
jtulach@176 | 12 |
} |
jtulach@176 | 13 |
public interface Number extends Expression { |
jtulach@176 | 14 |
public int getValue(); |
jtulach@176 | 15 |
} |
jtulach@176 | 16 |
// BEGIN: visitor.clientprovider.v2 |
jtulach@176 | 17 |
/** @since 2.0 */ |
jtulach@176 | 18 |
public interface Minus extends Expression { |
jtulach@176 | 19 |
public Expression getFirst(); |
jtulach@176 | 20 |
public Expression getSecond(); |
jtulach@176 | 21 |
} |
jtulach@176 | 22 |
|
jtulach@176 | 23 |
public static abstract class Visitor { |
jtulach@176 | 24 |
Visitor() {} |
jtulach@176 | 25 |
/** @since 2.0 */ |
jtulach@266 | 26 |
public static Visitor create(Version20 v) { |
jtulach@266 | 27 |
return create20(v); |
jtulach@176 | 28 |
} |
jtulach@176 | 29 |
|
jtulach@176 | 30 |
/** @since 2.0 */ |
jtulach@266 | 31 |
public interface Version20 extends Version10 { |
jtulach@176 | 32 |
public void visitMinus(Minus m); |
jtulach@176 | 33 |
} |
jtulach@176 | 34 |
|
jtulach@176 | 35 |
|
jtulach@176 | 36 |
/** @since 2.0 */ |
jtulach@176 | 37 |
public abstract void dispatchNumber(Number n); |
jtulach@176 | 38 |
// FINISH: visitor.clientprovider.v2 |
jtulach@176 | 39 |
|
jtulach@266 | 40 |
public static Visitor create(Version10 v) { |
jtulach@266 | 41 |
return create10(v); |
jtulach@176 | 42 |
} |
jtulach@176 | 43 |
|
jtulach@266 | 44 |
public interface Version10 { |
jtulach@176 | 45 |
public boolean visitUnknown(Expression e); |
jtulach@176 | 46 |
public void visitPlus(Plus s); |
jtulach@176 | 47 |
public void visitNumber(Number n); |
jtulach@176 | 48 |
} |
jtulach@176 | 49 |
|
jtulach@176 | 50 |
public abstract void dispatchPlus(Plus p); |
jtulach@176 | 51 |
public abstract void dispatchMinus(Minus m); |
jtulach@176 | 52 |
} |
jtulach@176 | 53 |
|
jtulach@266 | 54 |
static Visitor create10(final Visitor.Version10 v) { |
jtulach@176 | 55 |
return new Visitor() { |
jtulach@176 | 56 |
@Override |
jtulach@176 | 57 |
public void dispatchPlus(Plus p) { |
jtulach@176 | 58 |
v.visitPlus(p); |
jtulach@176 | 59 |
} |
jtulach@176 | 60 |
|
jtulach@176 | 61 |
@Override |
jtulach@176 | 62 |
public void dispatchNumber(Number n) { |
jtulach@176 | 63 |
v.visitNumber(n); |
jtulach@176 | 64 |
} |
jtulach@176 | 65 |
|
jtulach@176 | 66 |
@Override |
jtulach@176 | 67 |
public void dispatchMinus(Minus m) { |
jtulach@176 | 68 |
if (v.visitUnknown(m)) { |
jtulach@176 | 69 |
m.getFirst().visit(this); |
jtulach@176 | 70 |
m.getSecond().visit(this); |
jtulach@176 | 71 |
} |
jtulach@176 | 72 |
} |
jtulach@176 | 73 |
}; |
jtulach@176 | 74 |
} |
jtulach@266 | 75 |
static Visitor create20(final Visitor.Version20 v) { |
jtulach@176 | 76 |
return new Visitor() { |
jtulach@176 | 77 |
@Override |
jtulach@176 | 78 |
public void dispatchPlus(Plus p) { |
jtulach@176 | 79 |
v.visitPlus(p); |
jtulach@176 | 80 |
} |
jtulach@176 | 81 |
|
jtulach@176 | 82 |
@Override |
jtulach@176 | 83 |
public void dispatchNumber(Number n) { |
jtulach@176 | 84 |
v.visitNumber(n); |
jtulach@176 | 85 |
} |
jtulach@176 | 86 |
|
jtulach@176 | 87 |
@Override |
jtulach@176 | 88 |
public void dispatchMinus(Minus m) { |
jtulach@176 | 89 |
v.visitMinus(m); |
jtulach@176 | 90 |
} |
jtulach@176 | 91 |
}; |
jtulach@176 | 92 |
} |
jtulach@176 | 93 |
} |