Skip to content

Method: handleGroup(Group)

1: package de.fhdw.wtf.walker.tasks;
2:
3: import java.util.ArrayList;
4: import java.util.Collection;
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.Name;
11: import de.fhdw.wtf.common.ast.type.ClassType;
12: import de.fhdw.wtf.common.exception.walker.DoubleGroupcomponentException;
13: import de.fhdw.wtf.common.exception.walker.TaskException;
14: import de.fhdw.wtf.common.task.TaskExecutor;
15: import de.fhdw.wtf.walker.walker.SimpleWalkerTask;
16:
17: /**
18: * This Task check the Classnames and Groupnames. If there are duplicate Name of Classes or Groups and Classes and
19: * Groups are named equal, this Checker will thrown an {@link DoubleGroupcomponentException} .
20: *
21: * This Checker must run before the {@link TypeReferencer}.
22: */
23: public final class DoubleGroupcomponentCheck extends SimpleWalkerTask {
24:         
25:         /**
26:          * List of already found groupcomponents.
27:          */
28:         private final Collection<Name> groupcomponents;
29:         
30:         /**
31:          * Constructor of {@link DoubleGroupcomponentCheck}.
32:          *
33:          * @param m
34:          * model
35:          * @param taskmanager
36:          * taskmanager
37:          */
38:         private DoubleGroupcomponentCheck(final Model m, final TaskExecutor taskmanager) {
39:                 super(m, taskmanager);
40:                 this.groupcomponents = new ArrayList<>();
41:         }
42:         
43:         /**
44:          * Creates a {@link DoubleGroupcomponentCheck}-Object.
45:          *
46:          * @param m
47:          * model
48:          * @param taskmanager
49:          * taskmanager
50:          * @return The {@link DoubleGroupcomponentCheck}-Object.
51:          */
52:         public static DoubleGroupcomponentCheck create(final Model m, final TaskExecutor taskmanager) {
53:                 return new DoubleGroupcomponentCheck(m, taskmanager);
54:         }
55:         
56:         @Override
57:         public void handleGroup(final Group g) throws TaskException {
58:•                if (this.groupcomponents.contains(g.getName())) {
59:                         throw DoubleGroupcomponentException.create(g.getName().toString());
60:                 }
61:                 this.groupcomponents.add(g.getName());
62:         }
63:         
64:         @Override
65:         public void handleClass(final ClassType c) throws TaskException {
66:                 if (this.groupcomponents.contains(c.getTypeName())) {
67:                         throw DoubleGroupcomponentException.create(c.getTypeName().toString());
68:                 }
69:                 this.groupcomponents.add(c.getTypeName());
70:         }
71:         
72:         @Override
73:         public void handleAttribute(final Attribute a, final ClassType owner) throws TaskException {
74:                 // Nothing to do here
75:         }
76:         
77:         @Override
78:         public void finalizeTask() throws TaskException {
79:                 // Nothing to do here
80:         }
81:         
82:         @Override
83:         public void beginTask() throws TaskException {
84:                 // Nothing to do here
85:         }
86:         
87:         @Override
88:         public void handleConstructorOrOperation(final ConstructorOrOperation coo, final ClassType owner)
89:                         throws TaskException {
90:                 // Nothing to do here
91:                 
92:         }
93: }