Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 28ff6878080421fa897b85c557cd051c89a3656b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are property of the CEA, their use is subject to specific agreement 
 * with the CEA.
 * 
 * Contributors:
 *    CEA List - initial API and implementation
 *******************************************************************************/

package org.eclipse.papyrus.cpp.codegen.jet.util;

import org.eclipse.uml2.uml.*;
import org.eclipse.papyrus.cpp.codegen.jet.doc.*;
import Cpp.*;
import org.eclipse.papyrus.cpp.codegen.StdStereo;
import org.eclipse.papyrus.cpp.codegen.utils.GenUtils;

public class CppOperationDeclaration
{
  protected static String nl;
  public static synchronized CppOperationDeclaration create(String lineSeparator)
  {
    nl = lineSeparator;
    CppOperationDeclaration result = new CppOperationDeclaration();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = NL;
  protected final String TEXT_3 = NL + "\t";
  protected final String TEXT_4 = "(";
  protected final String TEXT_5 = ")";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
//////////////////////////////////////////////////////////////////////////////////////////
// Java preparation
//////////////////////////////////////////////////////////////////////////////////////////

	// Retrieve the Operation
	Operation currentOperation	= (Operation) argument;
		
	String operationName		= currentOperation.getName();

	String opParameters			= "";
	
	String returnTypeName		= "void";
	String pVirtualSuffix		= "";
	String prefix				= "";
	String constOp				= "";

	
	String opDoc = "";
	
	// Doc for the template
	CppOperationDoc jDoc		= new CppOperationDoc();
	opDoc						= GenUtils.indent (jDoc.generate(currentOperation), "\t");
	
	// Prepare return type
	CppOperationReturnType jetRT = new CppOperationReturnType();
	returnTypeName	= jetRT.generate(currentOperation);	
	if (!returnTypeName.equals ("")) {
		returnTypeName += " ";
	}
	
	boolean isInterface = currentOperation.getOwner () instanceof Interface;
		
	// Static attribute
	if (currentOperation.isStatic()) {
		prefix				= prefix+"static"+" ";
	}
	
	// Inline attribute
	if (GenUtils.hasStereotype(currentOperation, CppInline.class)) {
		prefix				= prefix+"inline"+" ";
	}		
		
	// Creator / Destructor: use function within StdStereo
	if (StdStereo.isApplied(currentOperation, StdStereo.create)) {
		returnTypeName		= "";
	}
	if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) {
		returnTypeName		= "";
		operationName		= "~"+operationName;
	}
	
	// Const attribute on operation
	if (GenUtils.hasStereotype(currentOperation, CppConst.class)) {
		constOp				= " const";
	}	
	
	// Virtual attribute on operation
	if (GenUtils.hasStereotype(currentOperation, CppVirtual.class)) {
		prefix				= "virtual "+prefix;
	}	
	
	// Pure Virtual attribute on operation
	if (isInterface || currentOperation.isAbstract ()) {
		prefix				= "virtual "+prefix;
		pVirtualSuffix		= " = 0";
	}
	
	// Friend attribute on operation
	if (GenUtils.hasStereotype(currentOperation, CppFriend.class)) {
		prefix				= "friend "+prefix;
	}	
	
	// Prepare parameters
	CppOperationParameters	jetParams	= new CppOperationParameters();
	opParameters						= jetParams.generate(currentOperation);	
	
//////////////////////////////////////////////////////////////////////////////////////////
// The following part contains the template only if current operation is not main
//	else nothing is return...
//////////////////////////////////////////////////////////////////////////////////////////

if (!operationName.equals("main")) { 

//////////////////////////////////////////////////////////////////////////////////////////
    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    stringBuffer.append( opDoc );
    stringBuffer.append(TEXT_3);
    stringBuffer.append( prefix );
    stringBuffer.append( returnTypeName );
    stringBuffer.append( operationName );
    stringBuffer.append(TEXT_4);
    stringBuffer.append( opParameters );
    stringBuffer.append(TEXT_5);
    stringBuffer.append( constOp );
    stringBuffer.append( pVirtualSuffix );
    //////////////////////////////////////////////////////////////////////////////////////////
} // else nothing done
//////////////////////////////////////////////////////////////////////////////////////////
    return stringBuffer.toString();
  }
}

Back to the top