Skip to content

Commit 950d4f6

Browse files
committed
Issue #16 - Added nested profiles to computed set of applied profiles.
- Also corrected error in InternalElementReferenceImpl.getMembers.
1 parent 69e7f2e commit 950d4f6

File tree

7 files changed

+59
-10
lines changed

7 files changed

+59
-10
lines changed
655 Bytes
Binary file not shown.
655 Bytes
Binary file not shown.

org.modeldriven.alf/src/org/modeldriven/alf/execution/AlfBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public abstract class AlfBase {
2626

27-
public static final String ALF_VERSION = "1.0.4/dev-01";
27+
public static final String ALF_VERSION = "1.0.4/dev-02";
2828

2929
protected boolean isVerbose = false;
3030

org.modeldriven.alf/src/org/modeldriven/alf/syntax/common/impl/InternalElementReferenceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public List<ElementReference> getOwnedMembers() {
367367
@Override
368368
public List<ElementReference> getMembers() {
369369
List<ElementReference> members = new ArrayList<ElementReference>();
370-
if (this.isClassifier()) {
370+
if (this.isNamespace()) {
371371
for (Member member: ((NamespaceDefinition)this.getSelf().getElement()).getMember()) {
372372
members.add(member.getImpl().getReferent());
373373
}

org.modeldriven.alf/src/org/modeldriven/alf/syntax/units/impl/NamespaceDefinitionImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*******************************************************************************
32
* Copyright 2011-2016 Data Access Technologies, Inc. (Model Driven Solutions)
43
*
@@ -280,7 +279,7 @@ public ElementReference resolveStereotype(QualifiedName name) {
280279
// If the stereotype name is qualified, then there must be an
281280
// applied profile that is named by the qualification of
282281
// the stereotype and that contains a stereotype of that name.
283-
// NOTE: This means that if the stereotype not directly owned by
282+
// NOTE: This means that if the stereotype is not directly owned by
284283
// the profile, then the names of any subpackages in which it is
285284
// nested are NOT to be included in the qualification when
286285
// naming the stereotype.
@@ -319,6 +318,8 @@ private static ElementReference findStereotype(String name, ElementReference pac
319318
return null;
320319
}
321320

321+
// NOTE: This is overridden in PackageDefinitionImpl, since profiles can only be
322+
// applied to packages.
322323
public Collection<ElementReference> getAllAppliedProfiles() {
323324
NamespaceDefinition outerScope = this.getOuterScope();
324325
return outerScope == null? new ArrayList<ElementReference>():

org.modeldriven.alf/src/org/modeldriven/alf/syntax/units/impl/PackageDefinitionImpl.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*******************************************************************************
32
* Copyright 2011-2016 Data Access Technologies, Inc. (Model Driven Solutions)
43
* All rights reserved worldwide. This program and the accompanying materials
@@ -31,6 +30,8 @@ public class PackageDefinitionImpl extends NamespaceDefinitionImpl {
3130
// NOTE: A collection of element references is used here to allow
3231
// for the (non-standard) possibility of profiles defined using Alf.
3332
private Collection<ElementReference> appliedProfile = null; // DERIVED
33+
34+
private Collection<ElementReference> allAppliedProfiles = null;
3435

3536
public PackageDefinitionImpl(PackageDefinition self) {
3637
super(self);
@@ -165,10 +166,31 @@ public List<Member> getPublicMembers(Collection<ElementReference> excluded) {
165166
}
166167

167168
@Override
168-
public Collection<ElementReference> getAllAppliedProfiles() {
169-
Collection<ElementReference> appliedProfiles = super.getAllAppliedProfiles();
170-
appliedProfiles.addAll(this.getAppliedProfileReference());
171-
return appliedProfiles;
169+
public Collection<ElementReference> getAllAppliedProfiles() {
170+
if (this.allAppliedProfiles == null) {
171+
this.allAppliedProfiles = super.getAllAppliedProfiles();
172+
Collection<ElementReference> appliedProfiles = this.getAppliedProfileReference();
173+
this.allAppliedProfiles.addAll(appliedProfiles);
174+
175+
// NOTE: Nested profiles are added here, because, according to the UML spec,
176+
// "Applying a Profile means recursively applying all its nested and imported Profiles."
177+
for (ElementReference profile: appliedProfiles) {
178+
this.allAppliedProfiles.addAll(getNestedProfiles(profile));
179+
}
180+
}
181+
return this.allAppliedProfiles;
182+
}
183+
184+
// NOTE: By searching members, not just owned members, this also returns any imported profiles.
185+
public static Collection<ElementReference> getNestedProfiles(ElementReference profile) {
186+
Collection<ElementReference> nestedProfiles = new ArrayList<ElementReference>();
187+
for (ElementReference member: profile.getImpl().getMembers()) {
188+
if (member.getImpl().isProfile()) {
189+
nestedProfiles.add(member);
190+
nestedProfiles.addAll(getNestedProfiles(member));
191+
}
192+
}
193+
return nestedProfiles;
172194
}
173195

174196
@Override

org.modeldriven.alf/tests/Units_Profile.alf

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,29 @@ package Units_Profile {
1414
public tag3: String[0..1];
1515
}
1616

17+
@stereotype(Property)
18+
public class S3 {
19+
}
20+
21+
@profile
22+
public package NestedProfile {
23+
24+
@stereotype(Property)
25+
public class S3 {
26+
}
27+
28+
@stereotype(Property)
29+
public class S4 {
30+
}
31+
32+
}
33+
1734
}
1835

1936
@apply(Profile)
2037
public package P {
2138

22-
@Profile::S1
39+
@S1
2340
public class A {
2441

2542
@StandardProfile::Create
@@ -31,6 +48,15 @@ package Units_Profile {
3148
@Profile::S2(tag1=>-3, tag2=>true, tag3=>"blah")
3249
private y: Boolean;
3350

51+
@Profile::S3
52+
private z: Boolean;
53+
54+
@Profile::NestedProfile::S3
55+
private a: Integer;
56+
57+
@S4
58+
private b: Integer;
59+
3460
}
3561

3662
}

0 commit comments

Comments
 (0)