View Javadoc
1   package de.fhdw.wtf.walker.tasks;
2   
3   import de.fhdw.wtf.common.ast.Attribute;
4   import de.fhdw.wtf.common.ast.Constructor;
5   import de.fhdw.wtf.common.ast.ConstructorOrOperation;
6   import de.fhdw.wtf.common.ast.Group;
7   import de.fhdw.wtf.common.ast.Model;
8   import de.fhdw.wtf.common.ast.Operation;
9   import de.fhdw.wtf.common.ast.type.ClassType;
10  import de.fhdw.wtf.common.ast.visitor.ConstructorOrOperationExceptionVisitor;
11  import de.fhdw.wtf.common.exception.walker.TaskException;
12  import de.fhdw.wtf.common.task.TaskExecutor;
13  import de.fhdw.wtf.walker.walker.SimpleWalkerTask;
14  
15  public class InheritanceOfThrownExceptionsCheck extends SimpleWalkerTask {
16  	
17  	public InheritanceOfThrownExceptionsCheck(final Model m, final TaskExecutor taskmanager) {
18  		super(m, taskmanager);
19  		// Auto-generated constructor stub
20  	}
21  	
22  	@Override
23  	public void handleClass(final ClassType c) throws TaskException {
24  		// Auto-generated method stub
25  		
26  	}
27  	
28  	@Override
29  	public void handleGroup(final Group g) throws TaskException {
30  		// Auto-generated method stub
31  		
32  	}
33  	
34  	@Override
35  	public void handleAttribute(final Attribute a, final ClassType owner) throws TaskException {
36  		// Auto-generated method stub
37  		
38  	}
39  	
40  	@Override
41  	public void handleConstructorOrOperation(final ConstructorOrOperation coo, final ClassType owner)
42  			throws TaskException {
43  		coo.accept(new ConstructorOrOperationExceptionVisitor<TaskException>() {
44  			
45  			@Override
46  			public void handleOperation(final Operation operation) throws TaskException {
47  				final java.util.Iterator<Operation> itr = operation.getOverridingOperations().iterator();
48  				while (itr.hasNext()) {
49  					final Operation op = itr.next();
50  					if (!op.getReturnType().isMoreOrEqualSpecialThan(operation.getReturnType())) {
51  						throw new TaskException("Wrong Inheritance in Thrown Exceptions! ");
52  					} else {
53  						// do nothing;
54  					}
55  				}
56  			}
57  			
58  			@Override
59  			public void handleConstructor(final Constructor constructor) throws TaskException {
60  				// Nothing to do here
61  				
62  			}
63  		});
64  		
65  	}
66  	
67  	@Override
68  	public void finalizeTask() throws TaskException {
69  		// TODO Auto-generated method stub
70  		
71  	}
72  	
73  	@Override
74  	public void beginTask() throws TaskException {
75  		// TODO Auto-generated method stub
76  		
77  	}
78  	
79  }