Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8d3c4b1f90d77debfbf957420e35f1288161b7a3 (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
package org.eclipse.papyrus.cpp.codegen.xtend

/*******************************************************************************
 * Copyright (c) 2014 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/
 
 import org.eclipse.uml2.uml.NamedElement
import org.eclipse.papyrus.C_Cpp.Include
import org.eclipse.uml2.uml.util.UMLUtil
import org.eclipse.papyrus.codegen.base.GenUtils

/**
 * @author Önder GÜRCAN (onder.gurcan@cea.fr)
 */
class CppIncludeUtil {
	static def includeDirective(String path) {
		if ((path != null) && (path.length > 0))
			return '''#include ''' + '"' + path + '"'
	}
	
	static def declareDirective(String path) {
		if ((path != null) && (path.length > 0)) {
			return path
		}	
	}

	static def CppIncludeHeader(NamedElement ne) {
		if (GenUtils.hasStereotype(ne, Include)) {
			UMLUtil.getStereotypeApplication(ne, Include)
			var header = UMLUtil.getStereotypeApplication(ne, Include).header
			if ((header != null) && (header.length > 0)) {
				var includeHeader = constIncludeHeaderStart + GenUtils.cleanCR(header) + '\n' +
					constIncludeHeaderEnd
				return includeHeader
			}
		}
	}

	static def constIncludeHeaderStart() '''
		// Include from Include stereotype (header)
	'''

	static def constIncludeHeaderEnd() '''
		// End of Include stereotype (header)
	'''
	
	static def CppIncludePreBody(NamedElement ne) {
		if (GenUtils.hasStereotype(ne, Include)) {
			var String preBody = UMLUtil.getStereotypeApplication(ne, Include).preBody
			if ((preBody != null) && (preBody.length > 0)) {
				var includePreBody = constIncludePreBodyStart + GenUtils.cleanCR(preBody) + '\n' +
					constIncludePreBodyEnd
				return includePreBody
			}
		}
	}
	
	static def constIncludePreBodyStart() '''
		// Include from Include stereotype (pre-body)
	'''

	static def constIncludePreBodyEnd() '''
		// End of Include stereotype (pre-body)
	'''
	
	static def CppIncludeBody(NamedElement ne) {
		if (GenUtils.hasStereotype(ne, Include)) {
			var String body = UMLUtil.getStereotypeApplication(ne, Include).body
			if ((body != null) && (body.length > 0)) {
				var includeBody = constIncludeBodyStart + GenUtils.cleanCR(body) + '\n' +
					constIncludeBodyEnd
				return includeBody
			}
		}
	}
	
	static def constIncludeBodyStart() '''
		// Include from Include declaration (body)
	'''

	static def constIncludeBodyEnd() '''
		// End of Include declaration (body)
	'''

}

Back to the top