blob: c27ae9c3a1919203d85527b38dea415fb72fdbba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
package ca.ubc.cs.spl.aspectPatterns.patternLibrary;
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This file is part of the design patterns project at UBC
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* either https://www.mozilla.org/MPL/ or https://aspectj.org/MPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is ca.ubc.cs.spl.aspectPatterns.
*
* For more details and the latest version of this code, please see:
* https://www.cs.ubc.ca/labs/spl/projects/aodps.html
*
* Contributor(s):
*/
/**
* Implements the abstracted Visitor design pattern.<p>
*
* Intent: <i>Represents an operation to be performed on the elements of an
* object structure. Visitor lets you define a new operation without changing
* the classes of the elements on which it operates</i><p>
*
* Note that this implementation only deals with two different kind of nodes:
* terminal and non-terminal nodes. In cases where the aggregate structure
* contains more types of nodes, this aspect cannot be used without
* modifications. <p>
*
* Note further that whenever the aggregate structure is unimportant, the
* additional functionality can be added in a much sipmler using
* AspectJ's open classes mechanism (i.e., by using inter-type declarations
* to implement the desired functionality).
*
* @author Jan Hannemann
* @author Gregor Kiczales
* @version 1.1, 02/17/04
*/
public abstract aspect VisitorProtocol {
/**
* Defines the <i>Element</i> role. The inerface is public so that
* <i>ConcreteVisitor</i>s can use the type.
*/
public interface VisitableNode {}
/**
* Defines a <i>ConcreteElement</i> role for non-terminal nodes in
* a binary tree structure. The interface is protected as it is only used
* by concrete subaspects.
*/
protected interface Node extends VisitableNode {}
/**
* Defines a <i>ConcreteElement</i> role for terminal nodes in
* a tree structure. The inerface is protected as it is only used
* by concrete subaspects.
*/
protected interface Leaf extends VisitableNode {}
/**
* This interface is implemented by <i>ConcreteVisitor</i>s.
*/
public interface Visitor {
/**
* Defines a method signature for visiting regular nodes.
*
* @param node the regular node to visit
*/
public void visitNode(VisitableNode node);
/**
* Defines a method signature for visiting leaf nodes.
*
* @param node the leaf node to visit
*/
public void visitLeaf(VisitableNode node);
/**
* Defines a method signature for returning the visitor's results
*
* @param node a string containig the visitor's results
*/
public String report();
}
/**
* Declares <code>accept(..)</code> for visitable nodes
*
* @param visitor the visitor that is to be accepted
*/
public void VisitableNode.accept(Visitor visitor) {}
/**
* Declares <code>accept(..)</code> for regular nodes
*
* @param visitor the visitor that is to be accepted
*/
public void Node.accept(Visitor visitor) {
visitor.visitNode(this);
}
/**
* Declares <code>accept(..)</code> for leaf nodes
*
* @param visitor the visitor that is to be accepted
*/
public void Leaf.accept(Visitor visitor) {
visitor.visitLeaf(this);
}
}
|