View Javadoc

1   /*
2    * Copyright (c) 2001-2005,
3    * RedVerst Group, ISP RAS http://www.ispras.ru
4    * All rights reserved.
5    *
6    * Redistribution and use in source and binary forms, with or without
7    * modification, are permitted provided that the following conditions are met:
8    *
9    * 1. Redistributions of source code must retain the above copyright notice, this
10   *    list of conditions and the following disclaimer.
11   *
12   * 2. Redistributions in binary form must reproduce the above copyright notice,
13   *    this list of conditions and the following disclaimer in the documentation
14   *    and/or other materials provided with the distribution.
15   *
16   * 3. The names "ATP", "TreeDL", "RedVerst", "ISP RAS"
17   *    may not be used to endorse or promote products derived from this software
18   *    without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24   * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27   * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   */
31  
32  package com.unitesk.atp.treedl;
33  
34  import com.unitesk.atp.treedl.TDL.*;
35  import com.unitesk.atp.tool.PluginClass;
36  
37  /***
38   * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
39   * @version $Id: CSharpInterfaceFactoryGenerator.java,v 1.2 2005/11/20 21:26:55 all-x Exp $
40   */
41  public class CSharpInterfaceFactoryGenerator
42      extends CSharpTextGenerator
43      implements TDL_Visitor
44  {
45      /***
46       * {@inheritDoc}
47       */
48      public String getVersion()
49      {
50          return PluginClass.getRevision( "$Revision: 1.2 $" ) + "-alpha";
51      }
52  
53      public void visitModule( Module node )
54      {
55          setFunction( "PredefinedTypeName", new PredefinedTypeNameFunction() );
56  
57          generateHeader();
58  
59          int indexOfLastDot = getOutClassName().lastIndexOf( '.' );
60          if( indexOfLastDot != -1 )
61          {
62              txt( "namespace " + getOutClassName().substring( 0, indexOfLastDot ) ); nl();
63              block_nl();
64          }
65  
66          if( node.getOptHeader() != null )
67          {
68              txt( "//-----------------------------------------------------------------------------" ); nl();
69              txt( "// tree header" ); nl();
70              txt( "${optHeader}" ); nl();
71              txt( "//-----------------------------------------------------------------------------" ); nl();
72              nl();
73          }
74  
75          String outShortClassName = getOutClassName().substring( indexOfLastDot + 1 );
76  
77          txt( "public interface " + outShortClassName ); nl();
78          block();
79          list( "memberIndex", 0, node.sizeOptMemberList(), "${optMemberList[memberIndex]}", null );
80          unblock_nl();
81  
82          if( node.getName().sizeIdList() > 1 )
83          {
84              txt( "}" ); nl();
85          }
86      }
87  
88      public void visitNodeTypeDecl( NodeTypeDecl node )
89      {
90          if( node.isAbstract() ) return;
91          
92          nl();
93          txt( "${parent.name}.${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     }
127 
128     public void visitConstTypeDecl( ConstTypeDecl node )
129     {
130     }
131 
132     public void visitOperationDecl( OperationDecl node )
133     {
134     }
135 
136     public void visitBaseModule( BaseModule node ) 
137     {
138         throw new UnsupportedOperationException();
139     }
140 
141     public void visitConstructorCodeMember( ConstructorCodeMember node )
142     {
143         throw new UnsupportedOperationException();
144     }
145     
146     public void visitBodyCodeMember( BodyCodeMember node )
147     {
148         throw new UnsupportedOperationException();
149     }
150 
151     public void visitField( Field node ) 
152     {
153         throw new UnsupportedOperationException();
154     }
155 
156     public void visitNonVirtualParameterDecl( NonVirtualParameterDecl node ) 
157     {
158         throw new UnsupportedOperationException();
159     }
160 
161     public void visitVirtualParameterDecl( VirtualParameterDecl node ) 
162     {
163         throw new UnsupportedOperationException();
164     }
165 
166     public void visitCase( Case node ) 
167     {
168         throw new UnsupportedOperationException();
169     }
170 
171     public void visitCaseSignature( CaseSignature node ) 
172     {
173         throw new UnsupportedOperationException();
174     }
175 
176     public void visitParameter( Parameter node ) 
177     {
178         throw new UnsupportedOperationException();
179     }
180 }