Eclipseplugins
pAConstructor.java
1 package com.proalpha.pds.templates.jet.openEdge;
2 
3 import com.openedge.pdt.core.template.ITemplateGenerator;
4 import com.openedge.pdt.core.template.TemplateGenerationException;
5 import com.openedge.pdt.text.template.OETemplateUtil;
6 import com.openedge.pdt.core.template.ITemplateArgs;
7 
8 import com.openedge.core.metadata.Constructor;
9 import com.openedge.core.metadata.Mode;
10 import com.openedge.core.reflect.IParameter;
11 import com.proalpha.pds.templates.helper.TemplatesUtils;
12 
13 public class pAConstructor implements ITemplateGenerator
14  {
15  protected static String nl;
16  public static synchronized pAConstructor create(String lineSeparator)
17  {
18  nl = lineSeparator;
19  pAConstructor result = new pAConstructor();
20  nl = null;
21  return result;
22  }
23 
24  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
25  protected final String TEXT_1 = " ";
26  protected final String TEXT_2 = "\t" + NL + " CONSTRUCTOR ";
27  protected final String TEXT_3 = " ";
28  protected final String TEXT_4 = " ( ";
29  protected final String TEXT_5 = " ):" + NL + " /* Description -----------------------------------------------------------*/" + NL + " /* */" + NL + " /* */" + NL + " /* */" + NL + " /* Notes -----------------------------------------------------------------*/" + NL + " /* */" + NL + " /* */" + NL + " /* */" + NL + " /* Parameters ------------------------------------------------------------*/" + NL + " /* */" + NL + " /* <none> */" + NL + " /* */" + NL + " /* Examples --------------------------------------------------------------*/" + NL + " /* */" + NL + " /* */" + NL + " /* */" + NL + " /*------------------------------------------------------------------------*/" + NL + "" + NL + " /* Variables -------------------------------------------------------------*/" + NL + " /*------------------------------------------------------------------------*/" + NL + "" + NL + " /* Buffers ---------------------------------------------------------------*/" + NL + "" + NL + " /*------------------------------------------------------------------------*/" + NL + " /* Processing */" + NL + " /*------------------------------------------------------------------------*/";
30  protected final String TEXT_6 = NL + " ";
31  protected final String TEXT_7 = NL + " END CONSTRUCTOR. /* ";
32  protected final String TEXT_8 = " */ " + NL;
33 
34 /* (non-javadoc)
35  * @see ITemplateGenerator#generate(Object)
36  */
37 public String generate(ITemplateArgs argument) throws TemplateGenerationException
38  {
39  final StringBuffer stringBuffer = new StringBuffer();
40 
41  Constructor constructorInfo = (Constructor) argument.getObj("constructorinfo");
42  boolean addsuper = constructorInfo.isCallSuper();
43  StringBuffer paramsBuf = new StringBuffer();
44  StringBuffer superBuf = new StringBuffer();
45  IParameter[] parameter = constructorInfo.getParameters();
46  for (int i = 0; i < parameter.length; i++) {
47  paramsBuf.append(TemplatesUtils.generateParameter(parameter[i], NL));
48  superBuf.append(parameter[i].getMode()+" "+parameter[i].getName());
49  if(i < parameter.length - 1){
50  paramsBuf.append(",");
51  paramsBuf.append(NL);
52  superBuf.append(", ");
53  }
54  }
55 
56  stringBuffer.append(TEXT_1);
57  stringBuffer.append(OETemplateUtil.generateAnnotations(constructorInfo.getAnnotations(), NL));
58  stringBuffer.append(TEXT_2);
59  stringBuffer.append( constructorInfo.isStatic()? "static" : Mode.ACESSORS[constructorInfo.getMode()]);
60  stringBuffer.append(TEXT_3);
61  stringBuffer.append( constructorInfo.getName() );
62  stringBuffer.append(TEXT_4);
63  stringBuffer.append( paramsBuf.toString() );
64  stringBuffer.append(TEXT_5);
65  stringBuffer.append(TEXT_6);
66  stringBuffer.append(addsuper ? "super (" + superBuf.toString() + ")." : "" );
67  stringBuffer.append(TEXT_6);
68  stringBuffer.append(constructorInfo.getMethodCode());
69  stringBuffer.append(constructorInfo.isInsertCatch() ? OETemplateUtil.generateCatchBlock(NL) : "" );
70  stringBuffer.append(constructorInfo.isInsertFinally()? OETemplateUtil.generateFinallyBlock(NL) : "");
71  stringBuffer.append(TEXT_7);
72  stringBuffer.append( constructorInfo.getName() );
73  stringBuffer.append(TEXT_8);
74 
75  return stringBuffer.toString();
76  }
77 }