Eclipseplugins
pAMethod.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.MethodInfo;
9 import com.openedge.core.metadata.Mode;
10 import com.openedge.core.reflect.IParameter;
11 import com.proalpha.pds.templates.helper.TemplatesUtils;
12 import com.proalpha.pds.templates.helper.ReturnTypeAnayzer;
13 
14 public class pAMethod implements ITemplateGenerator
15  {
16  protected static String nl;
17  public static synchronized pAMethod create(String lineSeparator)
18  {
19  nl = lineSeparator;
20  pAMethod result = new pAMethod();
21  nl = null;
22  return result;
23  }
24 
25  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
26  protected final String TEXT_1 = " ";
27  protected final String TEXT_2 = NL + " METHOD";
28  protected final String TEXT_3 = " ";
29  protected final String TEXT_4 = NL + " ( ";
30  protected final String TEXT_5 = " )";
31  protected final String TEXT_6 = ":";
32  protected final String TEXT_7 = ".";
33  protected final String TEXT_8 = NL + " /* Description -----------------------------------------------------------*/" + NL + " /* */" + NL + " /* */" + NL + " /* */" + NL + " /* Notes -----------------------------------------------------------------*/" + NL + " /* */" + NL + " /* */" + NL + " /* */" + NL + " /* Parameters ------------------------------------------------------------*/" + NL + " /* */" + NL + " /* <none> */" + NL + " /* */" + NL + " /* Examples --------------------------------------------------------------*/" + NL + " /* */" + NL + " /* */" + NL + " /* */" + NL + " /*------------------------------------------------------------------------*/" + NL + " ";
34  protected final String TEXT_9 = NL + " /* Variables -------------------------------------------------------------*/";
35  protected final String TEXT_10 = NL + " ";
36  protected final String TEXT_11 = NL + " /*------------------------------------------------------------------------*/";
37  protected final String TEXT_12 = NL + NL + " /* Buffers ---------------------------------------------------------------*/" + NL + "" + NL + " /*------------------------------------------------------------------------*/" + NL + " /* Processing */" + NL + " /*------------------------------------------------------------------------*/" + NL;
38  protected final String TEXT_13 = NL + " END METHOD. /* ";
39  protected final String TEXT_14 = " */";
40  protected final String TEXT_15 = NL;
41 
42 /* (non-javadoc)
43  * @see ITemplateGenerator#generate(Object)
44  */
45 public String generate(ITemplateArgs argument) throws TemplateGenerationException
46  {
47  final StringBuffer stringBuffer = new StringBuffer();
48 
49  MethodInfo methodInfo = (MethodInfo) argument.getObj("methodinfo");
50  boolean generateBody = ((Boolean) argument.getObj("generatebody")).booleanValue();
51 
52  StringBuffer paramsBuf = new StringBuffer();
53  String returnType = methodInfo.getReturnType();
54  String returnTypePreFix = ReturnTypeAnayzer.getPrefixForDataType(returnType);
55  String returnValue = returnTypePreFix + "ReturnValue";
56 
57  IParameter[] parameter = methodInfo.getParameters();
58  for (int i = 0; i < parameter.length; i++) {
59  paramsBuf.append(TemplatesUtils.generateParameter(parameter[i], NL));
60  if(i < parameter.length - 1){
61  paramsBuf.append(",");
62  paramsBuf.append(NL);
63  }
64  }
65 
66  stringBuffer.append(TEXT_1);
67  stringBuffer.append(OETemplateUtil.generateAnnotations(methodInfo.getAnnotations(), NL));
68  stringBuffer.append(TEXT_2);
69  stringBuffer.append( methodInfo.isOverride() ? " override " :"");
70  stringBuffer.append(TEXT_3);
71  stringBuffer.append(Mode.ACESSORS[methodInfo.getMode()]);
72  stringBuffer.append(methodInfo.isStatic() ? " static ":"");
73  stringBuffer.append(methodInfo.isFinal() ? " final ":"");
74  stringBuffer.append(TEXT_3);
75  stringBuffer.append( returnType );
76  stringBuffer.append(TEXT_3);
77  stringBuffer.append( methodInfo.getName() );
78  stringBuffer.append(TEXT_4);
79  stringBuffer.append( paramsBuf.toString() );
80  stringBuffer.append(TEXT_5);
81  if(generateBody){
82  stringBuffer.append(TEXT_6);
83  } else {
84  stringBuffer.append(TEXT_7);
85  }
86  stringBuffer.append(TEXT_8);
87  if(generateBody){
88  stringBuffer.append(TEXT_9);
89  if (!returnType.equalsIgnoreCase("void")){
90  stringBuffer.append(TEXT_10);
91  stringBuffer.append(TemplatesUtils.generateReturnVariableComment(returnType, returnValue, NL));
92  } else {
93  }
94  stringBuffer.append(TEXT_11);
95  if (!returnType.equalsIgnoreCase("void")){
96  stringBuffer.append(TEXT_10);
97  stringBuffer.append("");
98  stringBuffer.append(TEXT_10);
99  stringBuffer.append(TemplatesUtils.generateReturnVariable(returnType, returnValue, NL, methodInfo.getExtent()));
100  }
101  stringBuffer.append(TEXT_12);
102  if (methodInfo.isOverride() && returnType.equalsIgnoreCase("void")){
103  stringBuffer.append(TEXT_10);
104  stringBuffer.append(returnValue +" = ");
105  stringBuffer.append("super:" + methodInfo.getName() + "()." );
106  }
107  if (!returnType.equalsIgnoreCase("void")){
108  stringBuffer.append(TEXT_10);
109  stringBuffer.append(TemplatesUtils.generateReturnStatement(returnType, returnValue, NL));
110  }
111  if (methodInfo.isGenerateCatch()){
112  stringBuffer.append(TEXT_10);
113  stringBuffer.append(OETemplateUtil.generateCatchBlock(NL));
114  }
115  if (methodInfo.isGenerateFinally()){
116  stringBuffer.append(TEXT_10);
117  stringBuffer.append(OETemplateUtil.generateFinallyBlock(NL));
118  }
119  stringBuffer.append(TEXT_13);
120  stringBuffer.append( methodInfo.getName() );
121  stringBuffer.append(TEXT_14);
122  }
123  stringBuffer.append(TEXT_10);
124  stringBuffer.append(TEXT_15);
125  stringBuffer.append( NL );
126  stringBuffer.append(TEXT_3);
127  return stringBuffer.toString();
128  }
129 }