Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1bb92004f6ddef43aa45d9274d2301072f6dbcb6 (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
/*******************************************************************************
 * 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.Parameter;
import org.eclipse.uml2.uml.Classifier;
import Cpp.*;
import org.eclipse.papyrus.cpp.codegen.utils.Modifier;
import org.eclipse.papyrus.cpp.codegen.utils.GenUtils;

public class CppParameterWithoutDefaultValue
{
  protected static String nl;
  public static synchronized CppParameterWithoutDefaultValue create(String lineSeparator)
  {
    nl = lineSeparator;
    CppParameterWithoutDefaultValue result = new CppParameterWithoutDefaultValue();
    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 = ">";
  protected final String TEXT_3 = " ";
  protected final String TEXT_4 = " ";

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

	// Retrieve the Parameter
	Parameter currentParameter	= (Parameter) argument;

	String parameterName		= currentParameter.getName();

	String typeName			= "";
	Modifier modifier = new Modifier(currentParameter);
	
	// Prepare template parameter declaration without type
	String tparamWoType		= "";
	
	if (currentParameter.getType() == null) {
		typeName = "undefined";
	}
	else if (currentParameter.getType() instanceof Classifier) {
		Classifier classifier  = (Classifier) currentParameter.getType();
		tparamWoType = GenUtils.getTemplateParametersWoType(classifier);

		typeName = GenUtils.qualifiedName (currentParameter.getType());
	}
	else {
		typeName = GenUtils.qualifiedName (currentParameter.getType());
	}
	
//////////////////////////////////////////////////////////////////////////////////////////
// The following part contains the template
//////////////////////////////////////////////////////////////////////////////////////////
// Package visibility 
	if (!"".equals(tparamWoType)) {
	
//////////////////////////////////////////////////////////////////////////////////////////


    stringBuffer.append( modifier.isConst );
    stringBuffer.append( typeName );
    stringBuffer.append(TEXT_1);
    stringBuffer.append( tparamWoType );
    stringBuffer.append(TEXT_2);
    stringBuffer.append( modifier.ptr );
    stringBuffer.append( modifier.ref );
    stringBuffer.append(TEXT_3);
    stringBuffer.append( parameterName );
    stringBuffer.append( modifier.array );
    

//////////////////////////////////////////////////////////////////////////////////////////
	
	} else { // Default case

//////////////////////////////////////////////////////////////////////////////////////////


    stringBuffer.append( modifier.isConst );
    stringBuffer.append( typeName );
    stringBuffer.append( modifier.ptr );
    stringBuffer.append( modifier.ref );
    stringBuffer.append(TEXT_4);
    stringBuffer.append( parameterName );
    stringBuffer.append( modifier.array );
    


//////////////////////////////////////////////////////////////////////////////////////////
	}
//////////////////////////////////////////////////////////////////////////////////////////
    return stringBuffer.toString();
  }
}

Back to the top