Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 933b4a00407d6f31cb401243e8a2ccb047b93016 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************************
 * 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;

import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Package;
import Cpp.CppInclude;
import org.eclipse.papyrus.cpp.codegen.utils.GenUtils;
import org.eclipse.papyrus.cpp.codegen.jet.util.*;
import org.eclipse.papyrus.cpp.codegen.jet.doc.*;

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

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "#ifndef ";
  protected final String TEXT_2 = "_H" + NL + "#define ";
  protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************";
  protected final String TEXT_4 = NL + "              ";
  protected final String TEXT_5 = " interface header" + NL + " ************************************************************/" + NL;
  protected final String TEXT_6 = NL;
  protected final String TEXT_7 = NL;
  protected final String TEXT_8 = NL;
  protected final String TEXT_9 = NL;
  protected final String TEXT_10 = NL;
  protected final String TEXT_11 = NL;
  protected final String TEXT_12 = NL + "/************************************************************/";
  protected final String TEXT_13 = NL;
  protected final String TEXT_14 = NL + "class ";
  protected final String TEXT_15 = " ";
  protected final String TEXT_16 = "{" + NL + "" + NL + "/* Public declarations                                      */" + NL + "public:";
  protected final String TEXT_17 = NL;
  protected final String TEXT_18 = NL + NL + "};" + NL + "" + NL + "/************************************************************" + NL + "              End of ";
  protected final String TEXT_19 = " interface header" + NL + " ************************************************************/";
  protected final String TEXT_20 = NL;
  protected final String TEXT_21 = NL + NL + "#endif";
  protected final String TEXT_22 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
//////////////////////////////////////////////////////////////////////////////////////////
// Java preparation
//////////////////////////////////////////////////////////////////////////////////////////
	
	// Retrieve the class
	Interface currentInterface		= (Interface) argument;
	
	// Get the package name
	String interfaceName     = currentInterface.getName();
	String interfaceFULLNAME = GenUtils.getFullNameUC (currentInterface);
	
	// For interface documentation
	String iDoc		= "";
	
	// Retrieve enum doc
	CppElementDoc jDoc		= new CppElementDoc();
	iDoc					= jDoc.generate(currentInterface);
	
	// Include declaration "CppInclude"
	String headerDecl		= "";
	CppInclude cppInclude =  GenUtils.getApplication(currentInterface, CppInclude.class);
	if (cppInclude != null) {
		headerDecl =  "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL;
	}

	// Prepare owner package header include
	Package ownerPackage	= currentInterface.getPackage();
	String ownerInclude		= "";
	if (ownerPackage != null) {
		// Create an util template to prepare the declaration
		CppOwnerPackageIncludeDeclaration jetOwnerInclude		
							= new CppOwnerPackageIncludeDeclaration();
		// Execute the util template
		ownerInclude		= jetOwnerInclude.generate(ownerPackage);
	}
	
		
	// Prepare dependency includes
	CppInterfaceAllIncludesDeclaration jetInterfaceIncludes
									= new CppInterfaceAllIncludesDeclaration();
	String interfaceIncludes			= jetInterfaceIncludes.generate(argument);
	if (!interfaceIncludes.equals("")) {
		interfaceIncludes	= "/* Structural includes (inheritance, dependencies, ... */"+NL+interfaceIncludes;
	}
	
	// Prepare Methods declarations
	String publicOperations		= "";
	
	// Methods
	CppInterfacePublicOperationsDeclaration jetPublicInterfacePOp
								= new CppInterfacePublicOperationsDeclaration();
	publicOperations			= jetPublicInterfacePOp.generate(currentInterface);
	
		
	// Prepare inherited interfaces
	String inheritedDeclarations = "";
	CppInterfaceInheritedDeclarations jetInherited
									= new CppInterfaceInheritedDeclarations();
	inheritedDeclarations			= jetInherited.generate(currentInterface);
	
	
//////////////////////////////////////////////////////////////////////////////////////////
// The following part contains the template
//////////////////////////////////////////////////////////////////////////////////////////
    stringBuffer.append(TEXT_1);
    stringBuffer.append( interfaceFULLNAME );
    stringBuffer.append(TEXT_2);
    stringBuffer.append( interfaceFULLNAME );
    stringBuffer.append(TEXT_3);
    stringBuffer.append(TEXT_4);
    stringBuffer.append( interfaceName );
    stringBuffer.append(TEXT_5);
    stringBuffer.append(TEXT_6);
    stringBuffer.append( ownerInclude );
    stringBuffer.append(TEXT_7);
    stringBuffer.append(TEXT_8);
    stringBuffer.append( interfaceIncludes );
    stringBuffer.append(TEXT_9);
    stringBuffer.append(TEXT_10);
    stringBuffer.append( headerDecl );
    stringBuffer.append(TEXT_11);
    stringBuffer.append( GenUtils.openNS(currentInterface) );
    stringBuffer.append(TEXT_12);
    stringBuffer.append(TEXT_13);
    stringBuffer.append( iDoc );
    stringBuffer.append(TEXT_14);
    stringBuffer.append( interfaceName );
    stringBuffer.append(TEXT_15);
    stringBuffer.append( inheritedDeclarations );
    stringBuffer.append(TEXT_16);
    stringBuffer.append(TEXT_17);
    stringBuffer.append( publicOperations );
    stringBuffer.append(TEXT_18);
    stringBuffer.append( interfaceName );
    stringBuffer.append(TEXT_19);
    stringBuffer.append(TEXT_20);
    stringBuffer.append( GenUtils.closeNS(currentInterface) );
    stringBuffer.append(TEXT_21);
    stringBuffer.append(TEXT_22);
    return stringBuffer.toString();
  }
}

Back to the top