1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package com.unitesk.atp.treedl;
33
34 import com.unitesk.atp.tool.PluginClass;
35 import com.unitesk.atp.treedl.TDL.*;
36
37 /***
38 * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
39 * @version $Id: Java5NullFactoryGenerator.java,v 1.4 2005/11/20 20:20:13 all-x Exp $
40 */
41 public class Java5NullFactoryGenerator
42 extends Java5InterfaceFactoryGenerator
43 {
44 /***
45 * {@inheritDoc}
46 */
47 public String getVersion()
48 {
49 return PluginClass.getRevision( "$Revision: 1.4 $" ) + "-beta";
50 }
51
52 public void visitModule( Module node )
53 {
54 setFunction( "PredefinedTypeName", new PredefinedTypeNameFunction() );
55
56 generateHeader();
57
58 int indexOfLastDot = getOutClassName().lastIndexOf( '.' );
59 if( indexOfLastDot != -1 )
60 {
61 txt( "package " + getOutClassName().substring( 0, indexOfLastDot ) + ";" ); nl();
62 nl();
63 }
64 if( node.getOptHeader() != null )
65 {
66 txt( "//-----------------------------------------------------------------------------" ); nl();
67 txt( "// tree header" ); nl();
68 txt( "${optHeader}" ); nl();
69 txt( "//-----------------------------------------------------------------------------" ); nl();
70 nl();
71 }
72 txt( "import ${name}.*;" ); nl();
73 nl();
74
75 String outShortClassName = getOutClassName().substring( indexOfLastDot + 1 );
76
77 txt( "public class " + outShortClassName + " implements " );
78 String[] implementedInterfaceList = getImplementedInterfaceList();
79 Object oldImplementedInterfaceList
80 = setVariable( "implementedInterfaceList", implementedInterfaceList );
81 list( "i", 0, implementedInterfaceList.length, "${.implementedInterfaceList[i]}", ", " ); nl();
82 setVariable( "implementedInterfaceList", oldImplementedInterfaceList );
83 block();
84 list( "i", 0, node.sizeOptMemberList(), "${optMemberList[i]}", null ); nl();
85 unblock_nl();
86 }
87
88 public void visitNodeTypeDecl( NodeTypeDecl node )
89 {
90 if( node.isAbstract() ) return;
91
92 nl();
93 txt( "public ${name} create${name}" );
94 int constructorParametersCount = 0;
95 for( int i = 0; i < node.sizeFullFieldList(); i++ )
96 {
97 Field field = node.getFullFieldList( i );
98
99 if( TDL_Module.isConstructorParameter( field ) )
100 {
101 pushNode( field );
102
103 nl();
104 txtif( constructorParametersCount == 0, "(", "," );
105 txt( " ${type} ${name}" );
106 constructorParametersCount++;
107
108 popNode();
109 }
110 }
111
112 switch( constructorParametersCount )
113 {
114 case 0:
115 txt( "()" );
116 break;
117 case 1:
118 txt( " )" );
119 break;
120 default:
121 nl();
122 txt( ")" );
123 break;
124 }
125 nl();
126 block_nl();
127 txt( "return null;"); nl();
128 unblock_nl();
129 }
130 }