1) Moved net.sourceforge.phpeclipse.ui\src\net\sourceforge\phpdt back to net.sourcefo...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / ui / CodeGeneration.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.ui;
12
13 import net.sourceforge.phpdt.core.ICompilationUnit;
14 import net.sourceforge.phpdt.core.IMethod;
15 import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
16
17 import org.eclipse.core.runtime.CoreException;
18
19 /**
20  * Class that offers access to the templates contained in the 'code templates'
21  * preference page.
22  * 
23  * @since 2.1
24  */
25 public class CodeGeneration {
26
27         private CodeGeneration() {
28         }
29
30         /**
31          * Returns the content for a new compilation unit using the 'new Java file'
32          * code template.
33          * 
34          * @param cu
35          *            The compilation to create the source for. The compilation unit
36          *            does not need to exist.
37          * @param typeComment
38          *            The comment for the type to be created. Used when the code
39          *            template contains a <i>${typecomment}</i> variable. Can be
40          *            <code>null</code> if no comment should be added.
41          * @param typeContent
42          *            The code of the type, including type declaration and body.
43          * @param lineDelimiter
44          *            The line delimiter to be used.
45          * @return Returns the new content or <code>null</code> if the template is
46          *         undefined or empty.
47          * @throws CoreException
48          *             Thrown when the evaluation of the code template fails.
49          */
50 //      public static String getCompilationUnitContent(ICompilationUnit cu,
51 //                      String typeComment, String typeContent, String lineDelimiter)
52 //                      throws CoreException {
53 //              return StubUtility.getCompilationUnitContent(cu, typeComment,
54 //                              typeContent, lineDelimiter);
55 //      }
56
57         /**
58          * Returns the content for a new type comment using the 'type comment' code
59          * template. The returned content is unformatted and is not indented.
60          * 
61          * @param cu
62          *            The compilation where the type is contained. The compilation
63          *            unit does not need to exist.
64          * @param typeQualifiedName
65          *            The name of the type to which the comment is added. For inner
66          *            types the name must be qualified and include the outer types
67          *            names (dot separated). See
68          *            {@link net.sourceforge.phpdt.core.IType#getTypeQualifiedName(char)}.
69          * @param lineDelimiter
70          *            The line delimiter to be used.
71          * @return Returns the new content or <code>null</code> if the code
72          *         template is undefined or empty. The returned content is
73          *         unformatted and is not indented.
74          * @throws CoreException
75          *             Thrown when the evaluation of the code template fails.
76          */
77         public static String getTypeComment(ICompilationUnit cu,
78                         String typeQualifiedName, String lineDelimiter)
79                         throws CoreException {
80                 return StubUtility.getTypeComment(cu, typeQualifiedName, lineDelimiter);
81         }
82
83         /**
84          * Returns the content for a new field comment using the 'field comment'
85          * code template. The returned content is unformatted and is not indented.
86          * 
87          * @param cu
88          *            The compilation where the field is contained. The compilation
89          *            unit does not need to exist.
90          * @param typeName
91          *            The name of the field declared type.
92          * @param fieldName
93          *            The name of the field to which the comment is added.
94          * @param lineDelimiter
95          *            The line delimiter to be used.
96          * @return Returns the new content or <code>null</code> if the code
97          *         template is undefined or empty. The returned content is
98          *         unformatted and is not indented.
99          * @throws CoreException
100          *             Thrown when the evaluation of the code template fails.
101          * @since 3.0
102          */
103 //      public static String getFieldComment(ICompilationUnit cu, String typeName,
104 //                      String fieldName, String lineDelimiter) throws CoreException {
105 //              return StubUtility.getFieldComment(cu, typeName, fieldName,
106 //                              lineDelimiter);
107 //      }
108
109         /**
110          * Returns the comment for a method or constructor using the comment code
111          * templates (constructor / method / overriding method). <code>null</code>
112          * is returned if the template is empty.
113          * 
114          * @param cu
115          *            The compilation unit to which the method belongs. The
116          *            compilation unit does not need to exist.
117          * @param declaringTypeName
118          *            Name of the type to which the method belongs. For inner types
119          *            the name must be qualified and include the outer types names
120          *            (dot separated). See
121          *            {@link net.sourceforge.phpdt.core.IType#getTypeQualifiedName(char)}.
122          * @param decl
123          *            The MethodDeclaration AST node that will be added as new
124          *            method. The node does not need to exist in an AST (no parent
125          *            needed) and does not need to resolve. See
126          *            {@link net.sourceforge.phpdt.core.dom.AST#newMethodDeclaration()}
127          *            for how to create such a node.
128          * @param overridden
129          *            The binding of the method that will be overridden by the
130          *            created method or <code>null</code> if no method is
131          *            overridden.
132          * @param lineDelimiter
133          *            The line delimiter to be used.
134          * @return Returns the generated method comment or <code>null</code> if
135          *         the code template is empty. The returned content is unformatted
136          *         and not indented (formatting required).
137          * @throws CoreException
138          *             Thrown when the evaluation of the code template fails.
139          */
140         // public static String getMethodComment(ICompilationUnit cu, String
141         // declaringTypeName, MethodDeclaration decl, IMethodBinding overridden,
142         // String lineDelimiter) throws CoreException {
143         // return StubUtility.getMethodComment(cu, declaringTypeName, decl,
144         // overridden, lineDelimiter);
145         // }
146         /**
147          * Returns the comment for a method or constructor using the comment code
148          * templates (constructor / method / overriding method). <code>null</code>
149          * is returned if the template is empty.
150          * <p>
151          * The returned string is unformatted and not indented.
152          * <p>
153          * Exception types and return type are in signature notation. e.g. a source
154          * method declared as <code>public void foo(String text, int length)</code>
155          * would return the array <code>{"QString;","I"}</code> as parameter
156          * types. See {@link net.sourceforge.phpdt.core.Signature}.
157          * 
158          * @param cu
159          *            The compilation unit to which the method belongs. The
160          *            compilation unit does not need to exist.
161          * @param declaringTypeName
162          *            Name of the type to which the method belongs. For inner types
163          *            the name must be qualified and include the outer types names
164          *            (dot separated). See
165          *            {@link net.sourceforge.phpdt.core.IType#getTypeQualifiedName(char)}.
166          * @param methodName
167          *            Name of the method.
168          * @param paramNames
169          *            Names of the parameters for the method.
170          * @param excTypeSig
171          *            Thrown exceptions (Signature notation).
172          * @param retTypeSig
173          *            Return type (Signature notation) or <code>null</code> for
174          *            constructors.
175          * @param overridden
176          *            The method that will be overridden by the created method or
177          *            <code>null</code> for non-overriding methods. If not
178          *            <code>null</code>, the method must exist.
179          * @param lineDelimiter
180          *            The line delimiter to be used.
181          * @return Returns the constructed comment or <code>null</code> if the
182          *         comment code template is empty. The returned content is
183          *         unformatted and not indented (formatting required).
184          * @throws CoreException
185          *             Thrown when the evaluation of the code template fails.
186          */
187         public static String getMethodComment(ICompilationUnit cu,
188                         String declaringTypeName, String methodName, String[] paramNames,
189                         String[] excTypeSig, String retTypeSig, IMethod overridden,
190                         String lineDelimiter) throws CoreException {
191                 return StubUtility.getMethodComment(cu, declaringTypeName, methodName,
192                                 paramNames, excTypeSig, retTypeSig, overridden, lineDelimiter);
193         }
194
195         /**
196          * Returns the comment for a method or constructor using the comment code
197          * templates (constructor / method / overriding method). <code>null</code>
198          * is returned if the template is empty.
199          * <p>
200          * The returned string is unformatted and not indented.
201          * 
202          * @param method
203          *            The method to be documented. The method must exist.
204          * @param overridden
205          *            The method that will be overridden by the created method or
206          *            <code>null</code> for non-overriding methods. If not
207          *            <code>null</code>, the method must exist.
208          * @param lineDelimiter
209          *            The line delimiter to be used.
210          * @return Returns the constructed comment or <code>null</code> if the
211          *         comment code template is empty. The returned string is
212          *         unformatted and and has no indent (formatting required).
213          * @throws CoreException
214          *             Thrown when the evaluation of the code template fails.
215          */
216         public static String getMethodComment(IMethod method, IMethod overridden,
217                         String lineDelimiter) throws CoreException {
218                 return StubUtility.getMethodComment(method, overridden, lineDelimiter);
219         }
220
221         /**
222          * Returns the content of the body for a method or constructor using the
223          * method body templates. <code>null</code> is returned if the template is
224          * empty.
225          * <p>
226          * The returned string is unformatted and not indented.
227          * 
228          * @param cu
229          *            The compilation unit to which the method belongs. The
230          *            compilation unit does not need to exist.
231          * @param declaringTypeName
232          *            Name of the type to which the method belongs. For inner types
233          *            the name must be qualified and include the outer types names
234          *            (dot separated). See
235          *            {@link net.sourceforge.phpdt.core.IType#getTypeQualifiedName(char)}.
236          * @param methodName
237          *            Name of the method.
238          * @param isConstructor
239          *            Defines if the created body is for a constructor.
240          * @param bodyStatement
241          *            The code to be entered at the place of the variable
242          *            ${body_statement}.
243          * @param lineDelimiter
244          *            The line delimiter to be used.
245          * @return Returns the constructed body content or <code>null</code> if
246          *         the comment code template is empty. The returned string is
247          *         unformatted and and has no indent (formatting required).
248          * @throws CoreException
249          *             Thrown when the evaluation of the code template fails.
250          */
251 //      public static String getMethodBodyContent(ICompilationUnit cu,
252 //                      String declaringTypeName, String methodName, boolean isConstructor,
253 //                      String bodyStatement, String lineDelimiter) throws CoreException {
254 //              return StubUtility.getMethodBodyContent(isConstructor, cu
255 //                              .getJavaProject(), declaringTypeName, methodName,
256 //                              bodyStatement, lineDelimiter);
257 //      }
258
259         /**
260          * Returns the content of body for a getter method using the getter method
261          * body template. <code>null</code> is returned if the template is empty.
262          * <p>
263          * The returned string is unformatted and not indented.
264          * 
265          * @param cu
266          *            The compilation unit to which the method belongs. The
267          *            compilation unit does not need to exist.
268          * @param declaringTypeName
269          *            Name of the type to which the method belongs. For inner types
270          *            the name must be qualified and include the outer types names
271          *            (dot separated). See
272          *            {@link net.sourceforge.phpdt.core.IType#getTypeQualifiedName(char)}.
273          * @param methodName
274          *            The name of the getter method.
275          * @param fieldName
276          *            The name of the field to get in the getter method,
277          *            corresponding to the template variable for ${field}.
278          * @param lineDelimiter
279          *            The line delimiter to be used.
280          * @return Returns the constructed body content or <code>null</code> if
281          *         the comment code template is empty. The returned string is
282          *         unformatted and and has no indent (formatting required).
283          * @throws CoreException
284          *             Thrown when the evaluation of the code template fails.
285          * @since 3.0
286          */
287 //      public static String getGetterMethodBodyContent(ICompilationUnit cu,
288 //                      String declaringTypeName, String methodName, String fieldName,
289 //                      String lineDelimiter) throws CoreException {
290 //              return StubUtility.getGetterMethodBodyContent(cu.getJavaProject(),
291 //                              declaringTypeName, methodName, fieldName, lineDelimiter);
292 //      }
293
294         /**
295          * Returns the content of body for a setter method using the setter method
296          * body template. <code>null</code> is returned if the template is empty.
297          * <p>
298          * The returned string is unformatted and not indented.
299          * 
300          * @param cu
301          *            The compilation unit to which the method belongs. The
302          *            compilation unit does not need to exist.
303          * @param declaringTypeName
304          *            Name of the type to which the method belongs. For inner types
305          *            the name must be qualified and include the outer types names
306          *            (dot separated). See
307          *            {@link net.sourceforge.phpdt.core.IType#getTypeQualifiedName(char)}.
308          * @param methodName
309          *            The name of the setter method.
310          * @param fieldName
311          *            The name of the field to be set in the setter method,
312          *            corresponding to the template variable for ${field}.
313          * @param paramName
314          *            The name of the parameter passed to the setter method,
315          *            corresponding to the template variable for $(param).
316          * @param lineDelimiter
317          *            The line delimiter to be used.
318          * @return Returns the constructed body content or <code>null</code> if
319          *         the comment code template is empty. The returned string is
320          *         unformatted and and has no indent (formatting required).
321          * @throws CoreException
322          *             Thrown when the evaluation of the code template fails.
323          * @since 3.0
324          */
325 //      public static String getSetterMethodBodyContent(ICompilationUnit cu,
326 //                      String declaringTypeName, String methodName, String fieldName,
327 //                      String paramName, String lineDelimiter) throws CoreException {
328 //              return StubUtility.getSetterMethodBodyContent(cu.getJavaProject(),
329 //                              declaringTypeName, methodName, fieldName, paramName,
330 //                              lineDelimiter);
331 //      }
332
333         /**
334          * Returns the comment for a getter method using the getter comment
335          * template. <code>null</code> is returned if the template is empty.
336          * <p>
337          * The returned string is unformatted and not indented.
338          * 
339          * @param cu
340          *            The compilation unit to which the method belongs. The
341          *            compilation unit does not need to exist.
342          * @param declaringTypeName
343          *            Name of the type to which the method belongs. For inner types
344          *            the name must be qualified and include the outer types names
345          *            (dot separated). See
346          *            {@link net.sourceforge.phpdt.core.IType#getTypeQualifiedName(char)}.
347          * @param methodName
348          *            Name of the method.
349          * @param fieldName
350          *            Name of the field to get.
351          * @param fieldType
352          *            The type of the field to get.
353          * @param bareFieldName
354          *            The field name without prefix or suffix.
355          * @param lineDelimiter
356          *            The line delimiter to be used.
357          * @return Returns the generated getter comment or <code>null</code> if
358          *         the code template is empty. The returned content is not indented.
359          * @throws CoreException
360          *             Thrown when the evaluation of the code template fails.
361          * @since 3.0
362          */
363         public static String getGetterComment(ICompilationUnit cu,
364                         String declaringTypeName, String methodName, String fieldName,
365                         String fieldType, String bareFieldName, String lineDelimiter)
366                         throws CoreException {
367                 return StubUtility.getGetterComment(cu, declaringTypeName, methodName,
368                                 fieldName, fieldType, bareFieldName, lineDelimiter);
369         }
370
371         /**
372          * Returns the comment for a setter method using the setter method body
373          * template. <code>null</code> is returned if the template is empty.
374          * <p>
375          * The returned string is unformatted and not indented.
376          * 
377          * @param cu
378          *            The compilation unit to which the method belongs. The
379          *            compilation unit does not need to exist.
380          * @param declaringTypeName
381          *            Name of the type to which the method belongs. For inner types
382          *            the name must be qualified and include the outer types names
383          *            (dot separated). See
384          *            {@link net.sourceforge.phpdt.core.IType#getTypeQualifiedName(char)}.
385          * @param methodName
386          *            Name of the method.
387          * @param fieldName
388          *            Name of the field that is set.
389          * @param fieldType
390          *            The type of the field that is to set.
391          * @param paramName
392          *            The name of the parameter that used to set.
393          * @param bareFieldName
394          *            The field name without prefix or suffix.
395          * @param lineDelimiter
396          *            The line delimiter to be used.
397          * @return Returns the generated setter comment or <code>null</code> if
398          *         the code template is empty. The returned comment is not indented.
399          * @throws CoreException
400          *             Thrown when the evaluation of the code template fails.
401          * @since 3.0
402          */
403         public static String getSetterComment(ICompilationUnit cu,
404                         String declaringTypeName, String methodName, String fieldName,
405                         String fieldType, String paramName, String bareFieldName,
406                         String lineDelimiter) throws CoreException {
407                 return StubUtility.getSetterComment(cu, declaringTypeName, methodName,
408                                 fieldName, fieldType, paramName, bareFieldName, lineDelimiter);
409         }
410 }