1 | // |
2 | // (c) Copyright, Moebius Solutions, 2002 |
3 | // |
4 | // All Rights Reserved |
5 | // |
6 | // This material may be reproduced by or for the U. S. Government |
7 | // pursuant to the copyright license under the clause at |
8 | // DFARS 252.227-7013 (OCT 1988). |
9 | // |
10 | /* |
11 | * $Id: JavaForwardVisitor.java,v 1.3 2004/08/24 20:33:41 hastings Exp $ |
12 | */ |
13 | package com.moesol.generator; |
14 | |
15 | import java.io.*; |
16 | import java.lang.reflect.*; |
17 | import java.util.Comparator; |
18 | import java.util.Iterator; |
19 | import java.util.TreeSet; |
20 | |
21 | import com.moesol.generator.core.*; |
22 | import com.moesol.generator.printer.*; |
23 | import com.moesol.generator.visitor.*; |
24 | |
25 | public class JavaForwardVisitor |
26 | implements ReflectVisitor, ParamTypeVisitor |
27 | { |
28 | public JavaForwardVisitor(Writer out, TranslationContext ctx) { |
29 | m_out = out; |
30 | m_ctx = ctx; |
31 | } |
32 | public void visitField(final Class c, final Field field) throws ApplyException { |
33 | m_forwards.add(field.getType()); |
34 | } |
35 | public void visitMethod(Class a_class, Method method) throws ApplyException { |
36 | VisitClass.visitParamTypes(method, this); |
37 | m_forwards.add(method.getReturnType()); |
38 | } |
39 | public void visitConstructor(Class c, Constructor ctor) throws ApplyException { |
40 | VisitClass.visitParamTypes(ctor, this); |
41 | } |
42 | |
43 | public void visitParamType(Class c, int nparam, Class paramType) throws ApplyException { |
44 | m_forwards.add(paramType); |
45 | } |
46 | public void visitParamSeparator(Class c) throws ApplyException { |
47 | } |
48 | public void visitDone() throws ApplyException { |
49 | Iterator i = m_forwards.iterator(); |
50 | while (i.hasNext()) { |
51 | printForward( (Class) i.next() ); |
52 | } |
53 | } |
54 | |
55 | protected void printForward(Class type) throws ApplyException { |
56 | try { |
57 | CniFwdTypePrinter.getInstance().print(type, m_out); |
58 | } catch (IOException e) { |
59 | throw new ApplyException(e); |
60 | } |
61 | } |
62 | |
63 | private Writer m_out; |
64 | private TranslationContext m_ctx; |
65 | private static class ClassCompareator implements Comparator { |
66 | public int compare(Object o1, Object o2) { |
67 | Class left = (Class)o1; |
68 | Class right = (Class)o2; |
69 | return left.getName().compareTo(right.getName()); |
70 | } |
71 | } |
72 | private TreeSet m_forwards = new TreeSet(new ClassCompareator()); |
73 | } |