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

import org.eclipse.papyrus.C_Cpp.NoCodeGen
import org.eclipse.papyrus.cpp.codegen.utils.CppGenUtils
import org.eclipse.uml2.uml.Classifier
import org.eclipse.uml2.uml.Element
import org.eclipse.uml2.uml.Enumeration
import org.eclipse.uml2.uml.Namespace
import org.eclipse.uml2.uml.Package
import org.eclipse.uml2.uml.PrimitiveType
import org.eclipse.uml2.uml.VisibilityKind
import org.eclipse.papyrus.codegen.base.GenUtils
import org.eclipse.uml2.uml.DataType
import org.eclipse.uml2.uml.UMLFactory

/**
 * @author Önder GÜRCAN (onder.gurcan@cea.fr)
 */
class CppClassTypeAndEnum {
	
	static def CppClassTypeAndEnum(Classifier clazz) '''
		«var publicStr = TypesAndEnumsForVisibility(clazz, VisibilityKind.PUBLIC_LITERAL).toString»
		«CppGenUtils.getSection(VisibilityKind.PUBLIC_LITERAL, publicStr)»
		«var protectedStr = TypesAndEnumsForVisibility(clazz, VisibilityKind.PROTECTED_LITERAL).toString»
		«CppGenUtils.getSection(VisibilityKind.PROTECTED_LITERAL, protectedStr)»
		«var privateStr = TypesAndEnumsForVisibility(clazz, VisibilityKind.PRIVATE_LITERAL).toString»
		«CppGenUtils.getSection(VisibilityKind.PRIVATE_LITERAL, privateStr)»
	'''
	
	static def CppClassTypeAndEnumPackage(Package pkg) {
		TypesAndEnumsForVisibility(pkg, VisibilityKind.get(VisibilityKind.PACKAGE))
		TypesAndEnumsForVisibility(pkg, VisibilityKind.get(VisibilityKind.PUBLIC))
	}

	static def TypesAndEnumsForVisibility(Namespace ne, VisibilityKind visibilityFilter) '''
		«FOR ownedElement : ne.ownedElements»
			«TypeAndEnumForVisibility(ownedElement, visibilityFilter)»
		«ENDFOR»
	'''

	static def TypeAndEnumForVisibility(Element element, VisibilityKind visibilityFilter) {
		if ((!GenUtils.hasStereotype(element, NoCodeGen)) && (element instanceof Classifier)) {
			var elementVisibility = (element as Classifier).visibility
			var value = elementVisibility.value
			if ((value == visibilityFilter.value)) {
				if (element instanceof Enumeration) {
					return CppEnumerations.CppEnumerationDefinition(element as Enumeration)
				} else if (element instanceof PrimitiveType) {
					return CppPrimitiveTypes.CppPrimitiveTypeDefinition(element as PrimitiveType)
				} else if (element instanceof DataType || element.eClass.equals(UMLFactory.eINSTANCE.getUMLPackage().getClass_())) {
					if (GenUtils.isTemplateBoundElement(element as Classifier)) {
						return CppInnerClassifiers.CppInnerBindDefinition(element as Classifier)
					} else {
						return CppInnerClassifiers.CppInnerClassDefinition(element as Classifier)
					}
					
				}
			}
		}
	}
}

Back to the top