1 package de.fhdw.wtf.walker.tasks;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
6 import de.fhdw.wtf.common.ast.Attribute;
7 import de.fhdw.wtf.common.ast.ConstructorOrOperation;
8 import de.fhdw.wtf.common.ast.Group;
9 import de.fhdw.wtf.common.ast.Model;
10 import de.fhdw.wtf.common.ast.type.AtomicType;
11 import de.fhdw.wtf.common.ast.type.BaseType;
12 import de.fhdw.wtf.common.ast.type.ClassType;
13 import de.fhdw.wtf.common.ast.type.CompositeType;
14 import de.fhdw.wtf.common.ast.type.Type;
15 import de.fhdw.wtf.common.ast.type.TypeProxy;
16 import de.fhdw.wtf.common.ast.visitor.AtomicTypeVisitorException;
17 import de.fhdw.wtf.common.ast.visitor.TypeVisitorException;
18 import de.fhdw.wtf.common.exception.ast.ASTException;
19 import de.fhdw.wtf.common.exception.walker.DoubleAttributenameException;
20 import de.fhdw.wtf.common.exception.walker.TaskException;
21 import de.fhdw.wtf.common.task.TaskExecutor;
22 import de.fhdw.wtf.walker.walker.HelperUtils;
23 import de.fhdw.wtf.walker.walker.SimpleWalkerTask;
24
25
26
27
28
29
30
31 public final class DoubleAttributenameCheck extends SimpleWalkerTask {
32
33
34
35
36
37
38
39
40
41 private DoubleAttributenameCheck(final Model m, final TaskExecutor taskmanager) {
42 super(m, taskmanager);
43 }
44
45
46
47
48
49
50
51
52
53
54 public static DoubleAttributenameCheck create(final Model model, final TaskExecutor taskmanager) {
55 return new DoubleAttributenameCheck(model, taskmanager);
56 }
57
58 @Override
59 public void handleClass(final ClassType c) throws TaskException {
60 this.checkAttributeNames(c);
61 }
62
63 @Override
64 public void handleGroup(final Group g) throws TaskException {
65
66 }
67
68 @Override
69 public void handleAttribute(final Attribute a, final ClassType owner) throws TaskException {
70
71 }
72
73
74
75
76
77
78
79
80
81 private void checkAttributeNames(final ClassType clss) throws DoubleAttributenameException {
82 this.checkAttributeNames(clss, new HashSet<String>());
83 }
84
85
86
87
88
89
90
91
92
93
94
95 void checkAttributeNames(final ClassType clss, final Set<String> attrNamen) throws DoubleAttributenameException {
96 for (final Attribute currentAttr : clss.getAttributes()) {
97 if (!attrNamen.add(currentAttr.getName())) {
98 throw DoubleAttributenameException.create(currentAttr);
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 }
150
151 @Override
152 public void finalizeTask() throws TaskException {
153
154 }
155
156 @Override
157 public void beginTask() throws TaskException {
158
159 }
160
161 @Override
162 public void handleConstructorOrOperation(final ConstructorOrOperation coo, final ClassType owner)
163 throws TaskException {
164
165
166 }
167 }