Skip to content

Commit dadbe1c

Browse files
Modify traits management.
- Compute all traits to generate properties (attributes & accessors). - Only get traits from the class when writing the imports. This is to avoid redundancy in classes definition but still get all correct properties.
1 parent d6ebd19 commit dadbe1c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/src/main/java/ch/akuhn/fame/codegen/CodeGeneration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ private void acceptClass(MetaDescription metaDescription) throws IOException {
340340
}
341341
// Properties from my traits that are not in my own properties
342342
Set<PropertyDescription> propertyDescriptionSet = new HashSet<>();
343-
metaDescription.getTraits().stream()
343+
metaDescription.computeAllTraits().stream()
344344
.map(c -> c.getProperties().stream()
345345
.filter(traitProperty -> propertyDescriptions.stream().noneMatch(myProperty -> myProperty.getName().equals(traitProperty.getName())))
346346
.collect(Collectors.toList()))
@@ -365,7 +365,7 @@ private void acceptTrait(FM3Trait m) throws IOException {
365365
code.setTraits(m.getTraits().stream().map(FM3Type::getName).collect(Collectors.toList()));
366366
code.addImport(FameDescription.class);
367367
code.addImport(FamePackage.class);
368-
for (FM3Trait t : m.computeAllTraits()) {
368+
for (FM3Trait t : m.getTraits()) {
369369
code.addImport(packageName(t.getPackage()), t.getName());
370370
}
371371

lib/src/main/java/ch/akuhn/fame/fm3/FM3Type.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void setTraits(Collection<FM3Trait> traits) {
156156
}
157157
}
158158

159-
@FameProperty(name="traits", opposite = "owner")
159+
@FameProperty(name="traits", opposite = "users")
160160
public Collection<FM3Trait> getTraits() {
161161
return traits.values();
162162
}
@@ -174,11 +174,16 @@ public boolean isRoot() {
174174
}
175175

176176
public Set<FM3Trait> computeAllTraits() {
177-
Set<FM3Trait> traits = new HashSet<>();
178-
traits.addAll(getTraits());
179-
for (FM3Trait t : traits) {
180-
traits.addAll(t.computeAllTraits());
177+
Set<FM3Trait> computedTraits = new HashSet<>();
178+
computedTraits.addAll(getTraits());
179+
Set<FM3Trait> transitiveTraits = new HashSet<>();
180+
181+
for (FM3Trait t : computedTraits) {
182+
transitiveTraits.addAll(t.computeAllTraits());
181183
}
182-
return traits;
184+
185+
computedTraits.addAll(transitiveTraits);
186+
return computedTraits;
183187
}
188+
184189
}

0 commit comments

Comments
 (0)