01: package spoon.jdiet;
02:
03: import java.util.Collection;
04: import java.util.Hashtable;
05: import java.util.Map;
06: import java.util.Vector;
07:
08: import spoon.processing.AbstractProcessor;
09: import spoon.reflect.declaration.CtMethod;
10: import spoon.reflect.factory.TypeFactory;
11: import spoon.reflect.reference.CtTypeReference;
12:
13: /**
14: * This processor replaces method return types with a J2ME compliant equivalent
15: * type.
16: *
17: * @author Lionel Seinturier <Lionel.Seinturier@lifl.fr>
18: */
19: public class MethodProcessor extends AbstractProcessor<CtMethod> {
20:
21: public void process(CtMethod meth) {
22:
23: TypeFactory tf = getFactory().Type();
24: CtTypeReference ctr = meth.getType();
25:
26: if (!ctr.isPrimitif()) {
27:
28: // Transform Collection into Vector
29: if (ctr.isSubtypeOf(tf.createReference(Collection.class))) {
30: meth.setType(tf.createReference(Vector.class));
31: }
32:
33: // Transform Map into Hashtable
34: else if (ctr.isSubtypeOf(tf.createReference(Map.class))) {
35: meth.setType(tf.createReference(Hashtable.class));
36: }
37: }
38: }
39:
40: }
|