blob: 605818a9a5d3e04a8b18f6f34c9299dc85e7b4bb (
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
|
/*****************************************************************************
* Copyright (c) 2014, 2015 Christian W. Damus and others.
*
* 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:
* Christian W. Damus - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.profile.types.generator
import java.util.List
import javax.inject.Inject
import javax.inject.Singleton
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.EObject
import org.eclipse.papyrus.infra.types.ElementTypeConfiguration
import org.eclipse.papyrus.infra.types.ElementTypesConfigurationsFactory
import org.eclipse.papyrus.infra.types.SpecializationTypeConfiguration
import org.eclipse.papyrus.uml.types.core.matchers.stereotype.StereotypeApplicationMatcherFactory
import org.eclipse.uml2.uml.Stereotype
import static extension org.eclipse.emf.common.util.URI.decode
/**
* Transformation rule for generating a {@link SpecializationTypeConfiguration} from a UML metaclass {@link Extension}.
*/
@Singleton
class ElementTypeRule {
static extension ElementTypesConfigurationsFactory elementtypesconfigurationsFactory = ElementTypesConfigurationsFactory.
eINSTANCE
static extension StereotypeApplicationMatcherFactory stereotypeApplicationMatcherConfigurationFactory = StereotypeApplicationMatcherFactory.
eINSTANCE
@Inject extension UMLElementTypes
@Inject extension Identifiers
def create createSpecializationTypeConfiguration toElementType(ImpliedExtension umlExtension,
ElementTypeConfiguration supertype) {
// Basics
identifier = umlExtension.toElementTypeID(supertype)
if (hasSemanticSupertype(supertype)) {
// Add the base semantic type in addition to the parent visual type
val baseType = createSpecializationTypeConfiguration();
val baseTypeId = umlExtension.toElementTypeID(umlExtension.metaclass.elementTypeConfiguration);
baseType.identifier = baseTypeId;
baseType.specializedTypes.add(umlExtension.metaclass.elementTypeConfiguration)
baseType.hint = umlExtension.metaclass.elementTypeConfiguration.hint
baseType.name = umlExtension.toElementTypeName(umlExtension.metaclass.elementTypeConfiguration)
// Icon
var icon = umlExtension.stereotype.iconEntry
baseType.iconEntry = if(icon != null) icon else umlExtension.metaclass.iconEntry
val addedBaseType = ConfigurationSetRule.addElementType(baseType)
specializedTypes.add(addedBaseType)
}
specializedTypes.add(supertype)
hint = supertype.hint
name = umlExtension.toElementTypeName(supertype)
// Icon
var icon = umlExtension.stereotype.iconEntry
iconEntry = if(icon != null) icon else umlExtension.metaclass.iconEntry
// Add stereotype matcher, if it isn't inherited from a semantic supertype
if (!hasSemanticSupertype(supertype)) {
matcherConfiguration = umlExtension.toMatcherConfiguration(supertype)
}
}
private def create createStereotypeApplicationMatcherConfiguration toMatcherConfiguration(ImpliedExtension umlExtension,
ElementTypeConfiguration supertype) {
stereotypesQualifiedNames.add(umlExtension.stereotype.qualifiedName)
}
private def getIconEntry(Stereotype stereotype) {
val image = stereotype.icons.findFirst[!location.nullOrEmpty]
if (image != null) {
val uri = URI.createURI(image.location, true)
if (uri != null) {
createIconEntry => [
if (uri.platform) {
// Explicit platform-scheme URI
bundleId = uri.segment(1)
iconPath = "/" + uri.segmentsList.drop(2).join("/", [decode])
} else if (uri.relative) {
// Bundle-relative path. Infer the bundle ID from the containing project
bundleId = stereotype.containingProject.name
iconPath = "/" + uri.toString.decode
} else {
// Absolute URI: use as is; don't decode it
iconPath = uri.toString
}
]
}
}
}
private def containingProject(EObject object) {
ResourcesPlugin.workspace.root.getProject(object.eResource.URI.segment(2))
}
}
|