Eclipseplugins
pAInternalFunction.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.proalpha.pds.templates.helper.ReturnTypeAnayzer;
9 import org.eclipse.ui.PlatformUI;
10 import com.proalpha.pds.templates.helper.TemplatesUtils;
11 
12 public class pAInternalFunction implements ITemplateGenerator
13  {
14  protected static String nl;
15  public static synchronized pAInternalFunction create(String lineSeparator)
16  {
17  nl = lineSeparator;
19  nl = null;
20  return result;
21  }
22 
23  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
24  protected final String TEXT_1 = "&IF DEFINED(EXCLUDE-";
25  protected final String TEXT_2 = ") = 0 &THEN" + NL + "" + NL + "&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION ";
26  protected final String TEXT_3 = " Method-Library";
27  protected final String TEXT_4 = NL + "function ";
28  protected final String TEXT_5 = " returns ";
29  protected final String TEXT_6 = " ";
30  protected final String TEXT_7 = NL + " ( ):" + NL + "/* Description ---------------------------------------------------------------*/" + NL + "/* */" + NL + "/* */" + NL + "/* */" + NL + "/* Notes ---------------------------------------------------------------------*/" + NL + "/* */" + NL + "/* */" + NL + "/* */" + NL + "/* Parameters ----------------------------------------------------------------*/" + NL + "/* */" + NL + "/* <none> */" + NL + "/* */" + NL + "/* Examples ------------------------------------------------------------------*/" + NL + "/* */" + NL + "/* */" + NL + "/* */" + NL + "/*----------------------------------------------------------------------------*/" + NL;
31  protected final String TEXT_8 = NL + "/* Variables -----------------------------------------------------------------*/" + NL + "/* ";
32  protected final String TEXT_9 = "ReturnValue function return value */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "" + NL + "define variable ";
33  protected final String TEXT_10 = "ReturnValue as ";
34  protected final String TEXT_11 = " no-undo.";
35  protected final String TEXT_12 = NL + NL + "/* Buffers -------------------------------------------------------------------*/" + NL + "" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* Processing */" + NL + "/*----------------------------------------------------------------------------*/";
36  protected final String TEXT_13 = "\t\t" + NL + "" + NL + "return ";
37  protected final String TEXT_14 = "ReturnValue." + NL + "" + NL + "end function. /* ";
38  protected final String TEXT_15 = " */" + NL;
39  protected final String TEXT_16 = NL + "/* _UIB-CODE-BLOCK-END */" + NL + "&ANALYZE-RESUME" + NL + "" + NL + "&ENDIF";
40  protected final String TEXT_17 = 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  String fileName = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput().getName();
50  boolean isUserExitInclude = TemplatesUtils.isFileUserExitInclude(fileName);
51 
52  String functionName = argument.get("functionname");
53  boolean isPrivate = argument.get("private").equalsIgnoreCase("true");
54  String returnType = argument.get("returntype");
55  String returnTypePreFix = ReturnTypeAnayzer.getPrefixForDataType(returnType.toLowerCase());
56 
57  boolean generateCatch = Boolean.valueOf(argument.get("generateCatch"));
58  boolean generateFinally = Boolean.valueOf(argument.get("generateFinally"));
59 
60  if(!isUserExitInclude) {
61  stringBuffer.append(TEXT_1);
62  stringBuffer.append( functionName );
63  stringBuffer.append(TEXT_2);
64  stringBuffer.append( functionName );
65  stringBuffer.append(TEXT_3);
66  };
67  stringBuffer.append(TEXT_4);
68  stringBuffer.append( functionName );
69  stringBuffer.append(TEXT_5);
70  stringBuffer.append( returnType );
71  stringBuffer.append(TEXT_6);
72  stringBuffer.append( isPrivate ? "private" : "" );
73  stringBuffer.append(TEXT_7);
74  if (!returnType.equals("VOID")) {
75  stringBuffer.append(TEXT_8);
76  stringBuffer.append( returnTypePreFix );
77  stringBuffer.append(TEXT_9);
78  stringBuffer.append( returnTypePreFix );
79  stringBuffer.append(TEXT_10);
80  stringBuffer.append( returnType );
81  stringBuffer.append(TEXT_11);
82  };
83  stringBuffer.append(TEXT_12);
84  stringBuffer.append(generateCatch ? OETemplateUtil.generateCatchBlock(NL) : "");
85  stringBuffer.append(generateFinally ? OETemplateUtil.generateFinallyBlock(NL) : "");
86  stringBuffer.append(TEXT_13);
87  stringBuffer.append( returnTypePreFix );
88  stringBuffer.append(TEXT_14);
89  stringBuffer.append( functionName );
90  stringBuffer.append(TEXT_15);
91  if(!isUserExitInclude) {
92  stringBuffer.append(TEXT_16);
93  };
94  stringBuffer.append(TEXT_17);
95  return stringBuffer.toString();
96  }
97 }
static Boolean isFileUserExitInclude(String fileName)