blob: e4f18d52ecf51da87ff86d34d29d6df443db6aca (
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
|
/*******************************************************************************
* Copyright (c) 2006 - 2012 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.utils;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.UniqueEList;
import org.eclipse.papyrus.codegen.base.GenUtils;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Interface;
/**
* A set of utility functions related to classes.
*
* @author ansgar (ansgar.radermacher@cea.fr)
*
*/
public class ClassUtils {
/**
* Calculate the list of classifiers that needs to be included
*
* @param currentClass
* @return
*/
public static EList<Classifier> includedClassifiers(Classifier currentClass) {
// Retrieve package used by current package (dependencies)
// use a unique list to avoid duplicates
EList<Classifier> usedClasses = new UniqueEList<Classifier>();
// class attributes dependencies
usedClasses.addAll(GenUtils.getOwnedAttributeTypes(currentClass));
// operation parameters dependencies
usedClasses.addAll(GenUtils.getTypesViaOperations(currentClass));
// realized interface dependencies
if (currentClass instanceof Class) {
Class clazz = (Class) currentClass;
EList<Interface> implementedInterfaces = clazz.getImplementedInterfaces();
usedClasses.addAll(implementedInterfaces);
}
// dependencies and associations
usedClasses.addAll(GenUtils.getTypesViaRelationshipsNoDeps(currentClass));
// template parameters are declared locally (if owned) and do not correspond to a file
// that can be included
usedClasses.removeAll(GenUtils.getTemplateParameteredElements(currentClass));
return usedClasses;
}
}
|