Skip to content

Commit e090b74

Browse files
committed
Merge branch 'main' into 2.0.x
2 parents 86c502a + 3a2380a commit e090b74

File tree

15 files changed

+77
-116
lines changed

15 files changed

+77
-116
lines changed

core/sds-aspect-model-java-generator/src/main/resources/java-static-class-body-lib.vm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ static {
7575
);
7676
}
7777

78+
@Override
79+
public List<StaticProperty<?>> getAllProperties() {
80+
#if( $element.getExtends().isPresent() )
81+
#set( $extendedElement = $element.getExtends().get() )
82+
$codeGenerationConfig.getImportTracker().importExplicit( "${codeGenerationConfig.getPackageName()}.Meta${extendedElement.getName()}" )
83+
List<StaticProperty<?>> properties = getProperties();
84+
properties.addAll(Meta${extendedElement.getName()}.INSTANCE.getAllProperties());
85+
return properties;
86+
#else
87+
return getProperties();
88+
#end
89+
}
90+
7891
#if( !$element.getPreferredNames().isEmpty() )
7992
$codeGenerationConfig.getImportTracker().importExplicit( $LangString )
8093
$codeGenerationConfig.getImportTracker().importExplicit( $HashSet )

core/sds-aspect-model-java-generator/src/test/java/io/openmanufacturing/sds/aspectmodel/java/AspectModelJavaGeneratorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ public void testGenerateEqualsForAspectWithEntity( final KnownVersion metaModelV
831831
final TestAspect aspect = TestAspect.ASPECT_WITH_ENTITY;
832832
final GenerationResult result = TestContext.generateAspectCode().apply( getGenerators( aspect, metaModelVersion ) );
833833

834-
final PrimitiveType expectedReturnType = PrimitiveType.booleanType();
834+
final Optional<PrimitiveType> expectedReturnType = Optional.of( PrimitiveType.booleanType() );
835835
final boolean expectOverride = true;
836836
final int expectedNumberOfParameters = 1;
837837
List<String> expectedMethodBody = List.of(
@@ -863,7 +863,7 @@ public void testGenerateHashCodeForAspectWithEntity( final KnownVersion metaMode
863863
final TestAspect aspect = TestAspect.ASPECT_WITH_ENTITY;
864864
final GenerationResult result = TestContext.generateAspectCode().apply( getGenerators( aspect, metaModelVersion ) );
865865

866-
final PrimitiveType expectedReturnType = PrimitiveType.intType();
866+
final Optional<PrimitiveType> expectedReturnType = Optional.of( PrimitiveType.intType() );
867867
final boolean expectOverride = true;
868868
final int expectedNumberOfParameters = 0;
869869
List<String> expectedMethodBody = List.of( "returnObjects.hash(testProperty);" );
@@ -977,7 +977,7 @@ public void testGenerateEqualsForAspectWithAbstractEntity( final KnownVersion me
977977
final TestAspect aspect = TestAspect.ASPECT_WITH_ABSTRACT_ENTITY;
978978
final GenerationResult result = TestContext.generateAspectCode().apply( getGenerators( aspect, metaModelVersion ) );
979979

980-
final PrimitiveType expectedReturnType = PrimitiveType.booleanType();
980+
final Optional<PrimitiveType> expectedReturnType = Optional.of( PrimitiveType.booleanType() );
981981
final boolean expectOverride = true;
982982
final int expectedNumberOfParameters = 1;
983983
List<String> expectedMethodBody = List.of(
@@ -1023,7 +1023,7 @@ public void testGenerateHashCodeForAspectWithAbstractEntity( final KnownVersion
10231023
final TestAspect aspect = TestAspect.ASPECT_WITH_ABSTRACT_ENTITY;
10241024
final GenerationResult result = TestContext.generateAspectCode().apply( getGenerators( aspect, metaModelVersion ) );
10251025

1026-
final PrimitiveType expectedReturnType = PrimitiveType.intType();
1026+
final Optional<PrimitiveType> expectedReturnType = Optional.of( PrimitiveType.intType() );
10271027
final boolean expectOverride = true;
10281028
final int expectedNumberOfParameters = 0;
10291029
List<String> expectedMethodBody = List.of( "returnObjects.hash(testProperty);" );

core/sds-aspect-model-java-generator/src/test/java/io/openmanufacturing/sds/aspectmodel/java/GenerationResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void assertConstructorBody( final String className, final Set<String> expectedbo
184184
bodyStatements.stream().map( Node::toString ).collect( Collectors.joining() ) );
185185
}
186186

187-
void assertMethodBody( final String className, final String methodName, final boolean override, final PrimitiveType expectedReturnType,
187+
void assertMethodBody( final String className, final String methodName, final boolean override, final Optional<PrimitiveType> expectedReturnType,
188188
final int expectedNumberOfParameters, final List<String> expectedMethodBody ) {
189189
final Optional<MethodDeclaration> possibleMethodDeclaration = compilationUnits.get( className )
190190
.findAll( MethodDeclaration.class ).stream()
@@ -194,7 +194,7 @@ void assertMethodBody( final String className, final String methodName, final bo
194194

195195
final MethodDeclaration methodDeclaration = possibleMethodDeclaration.get();
196196
assertThat( methodDeclaration.isPublic() ).isTrue();
197-
assertThat( methodDeclaration.getType() ).isEqualTo( expectedReturnType );
197+
expectedReturnType.ifPresent(returnType -> assertThat( methodDeclaration.getType() ).isEqualTo( returnType ));
198198
assertThat( methodDeclaration.getParameters() ).hasSize( expectedNumberOfParameters );
199199
assertThat( methodDeclaration.getBody() ).isPresent();
200200
if ( override ) {

core/sds-aspect-model-java-generator/src/test/java/io/openmanufacturing/sds/aspectmodel/java/StaticMetaModelBaseAttributesTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public void testGeneratedMetaModelContainsRequiredMethods( final KnownVersion me
140140
.put( "getMetaModelVersion", "return KnownVersion." + KnownVersion.getLatest().toString() + ";" )
141141
.put( "getName", "return \"AspectWithBoolean\";" )
142142
.put( "getProperties", "return Arrays.asList(TEST_BOOLEAN);" )
143+
.put( "getAllProperties", "return getProperties();" )
143144
.put( "getPropertyType", "return Boolean.class;" )
144145
.build();
145146

@@ -176,6 +177,7 @@ public void testGeneratedMetaModelContainsOptionalMethods( final KnownVersion me
176177
.put( "getMetaModelVersion", "return KnownVersion." + KnownVersion.getLatest().toString() + ";" )
177178
.put( "getName", "return \"AspectWithAllBaseAttributes\";" )
178179
.put( "getProperties", "return Arrays.asList(TEST_BOOLEAN);" )
180+
.put( "getAllProperties", "return getProperties();" )
179181
.put( "getSee", "return Arrays.asList(\"http://example.com/omp\");" )
180182
.put( "getPreferredNames", getPreferredNamesBody )
181183
.put( "getDescriptions", getDescriptionsBody )
@@ -207,6 +209,7 @@ public void testGeneratedMetaModelContainsGetPreferredNamesMethod( final KnownVe
207209
.put( "getMetaModelVersion", "return KnownVersion." + KnownVersion.getLatest().toString() + ";" )
208210
.put( "getName", "return \"AspectWithPreferredNames\";" )
209211
.put( "getProperties", "return Arrays.asList(TEST_BOOLEAN);" )
212+
.put( "getAllProperties", "return getProperties();" )
210213
.put( "getPreferredNames", getPreferredNamesBody )
211214
.put( "getPropertyType", "return Boolean.class;" )
212215
.build();
@@ -236,6 +239,7 @@ public void testGeneratedMetaModelContainsGetDescriptionsMethod( final KnownVers
236239
.put( "getMetaModelVersion", "return KnownVersion." + KnownVersion.getLatest().toString() + ";" )
237240
.put( "getName", "return \"AspectWithDescriptions\";" )
238241
.put( "getProperties", "return Arrays.asList(TEST_BOOLEAN);" )
242+
.put( "getAllProperties", "return getProperties();" )
239243
.put( "getDescriptions", getDescriptionsBody )
240244
.put( "getPropertyType", "return Boolean.class;" )
241245
.build();
@@ -257,6 +261,7 @@ public void testGeneratedMetaModelContainsGetSeeMethod( final KnownVersion metaM
257261
.put( "getMetaModelVersion", "return KnownVersion." + KnownVersion.getLatest().toString() + ";" )
258262
.put( "getName", "return \"AspectWithPropertyWithSee\";" )
259263
.put( "getProperties", "return Arrays.asList(TEST_BOOLEAN);" )
264+
.put( "getAllProperties", "return getProperties();" )
260265
.put( "getPropertyType", "return Boolean.class;" )
261266
.build();
262267

core/sds-aspect-model-java-generator/src/test/java/io/openmanufacturing/sds/aspectmodel/java/StaticMetaModelJavaGeneratorTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public void testCodeGenerationSharedAspect( final TestSharedAspect testAspect )
7676
assertThatCode( () -> TestContext.generateStaticAspectCode().apply( getGenerators( testAspect, KnownVersion.getLatest() ) ) ).doesNotThrowAnyException();
7777
}
7878

79-
8079
@ParameterizedTest
8180
@MethodSource( value = "allVersions" )
8281
public void testGenerateStaticMetaModelWithOptionalProperties( final KnownVersion metaModelVersion ) throws IOException {
@@ -163,7 +162,7 @@ public void testGenerateStaticMetaModelWithMeasurementTwo( final KnownVersion me
163162
result.assertFields( "MetaAspectWithExtendedEntity",
164163
ImmutableMap.<String, Object> builder().put( "NAMESPACE", String.class ).put( "MODEL_ELEMENT_URN", String.class )
165164
.put( "CHARACTERISTIC_NAMESPACE", String.class ).put( "INSTANCE", "MetaAspectWithExtendedEntity" )
166-
.put( "TEST_PROPERTY", "StaticContainerProperty<TestEntity,java.util.LinkedHashSet<TestEntity>>").build(), new HashMap<>() );
165+
.put( "TEST_PROPERTY", "StaticContainerProperty<TestEntity,java.util.LinkedHashSet<TestEntity>>" ).build(), new HashMap<>() );
167166
}
168167

169168
@ParameterizedTest
@@ -234,6 +233,33 @@ ImmutableMap.<String, Object> builder().put( "NAMESPACE", String.class ).put( "M
234233
.build(), new HashMap<>() );
235234
}
236235

236+
@ParameterizedTest
237+
@MethodSource( value = "latestVersion" )
238+
public void testGenerateStaticMetaModelWithExtendedEntity( final KnownVersion metaModelVersion ) throws IOException {
239+
final TestSharedAspect aspect = TestSharedAspect.ASPECT_WITH_EXTENDED_ENTITY;
240+
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode().apply( getGenerators( aspect, metaModelVersion ) );
241+
result.assertNumberOfFiles( 8 );
242+
final String methodName = "getAllProperties";
243+
final boolean expectOverride = true;
244+
final int expectedNumberOfParameters = 0;
245+
final List<String> getAllPropertiesWithoutExtended = List.of( "returngetProperties();" );
246+
final List<String> getPropertiesMetaTestEntity = List.of(
247+
"List<StaticProperty<?>>properties=getProperties();",
248+
"properties.addAll(MetaParentTestEntity.INSTANCE.getAllProperties());",
249+
"returnproperties;" );
250+
final List<String> getPropertiesMetaParentTestEntity = List.of(
251+
"List<StaticProperty<?>>properties=getProperties();",
252+
"properties.addAll(MetaParentOfParentEntity.INSTANCE.getAllProperties());",
253+
"returnproperties;" );
254+
result.assertMethodBody( "MetaAspectWithExtendedEntity", methodName, expectOverride, Optional.empty(), expectedNumberOfParameters,
255+
getAllPropertiesWithoutExtended );
256+
result.assertMethodBody( "MetaParentTestEntity", methodName, expectOverride, Optional.empty(), expectedNumberOfParameters,
257+
getPropertiesMetaParentTestEntity );
258+
result.assertMethodBody( "MetaParentOfParentEntity", methodName, expectOverride, Optional.empty(), expectedNumberOfParameters,
259+
getAllPropertiesWithoutExtended );
260+
result.assertMethodBody( "MetaTestEntity", methodName, expectOverride, Optional.empty(), expectedNumberOfParameters, getPropertiesMetaTestEntity );
261+
}
262+
237263
@ParameterizedTest
238264
@MethodSource( value = "latestVersion" )
239265
public void testGenerateStaticMetaModelWithConstraints( final KnownVersion metaModelVersion ) throws IOException {

core/sds-aspect-static-meta-model-java/src/main/java/io/openmanufacturing/sds/staticmetamodel/PropertyContainer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2021 Robert Bosch Manufacturing Solutions GmbH
33
*
44
* See the AUTHORS file(s) distributed with this work for additional
5-
* information regarding authorship.
5+
* information regarding authorship.
66
*
77
* This Source Code Form is subject to the terms of the Mozilla Public
88
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -25,4 +25,10 @@ public interface PropertyContainer {
2525
*/
2626
@SuppressWarnings( "squid:S1452" )
2727
List<StaticProperty<?>> getProperties();
28+
29+
/**
30+
* @return a {@link List} of {@link StaticProperty}(ies) contained in this Meta Model element and the {@link StaticProperty}(ies) of the extended elements.
31+
*/
32+
@SuppressWarnings( "squid:S1452" )
33+
List<StaticProperty<?>> getAllProperties();
2834
}

core/sds-test-aspect-models/src/main/resources/valid/bamm_2_0_0/io.openmanufacturing.test.shared/1.0.0/AspectWithCollectionEntity.ttl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,5 @@
4646
bamm:description "This is a property for the test entity."@en ;
4747
bamm:characteristic bamm-c:Text .
4848

49-
:ParentTestEntity
50-
a bamm:AbstractEntity ;
51-
bamm:name "ParentTestEntity" ;
49+
:ParentTestEntity a bamm:AbstractEntity ;
5250
bamm:properties ( :testCollectionProperty ) .

core/sds-test-aspect-models/src/main/resources/valid/bamm_2_0_0/io.openmanufacturing.test.shared/1.0.0/AspectWithConstraintEntity.ttl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,5 @@
4646
bamm:description "This is a property for the test entity."@en ;
4747
bamm:characteristic bamm-c:Text .
4848

49-
:ParentTestEntity
50-
a bamm:AbstractEntity ;
51-
bamm:name "ParentTestEntity" ;
49+
:ParentTestEntity a bamm:AbstractEntity ;
5250
bamm:properties ( :stringRegexcProperty ) .

core/sds-test-aspect-models/src/main/resources/valid/bamm_2_0_0/io.openmanufacturing.test.shared/1.0.0/AspectWithEitherEntity.ttl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,5 @@
4646
bamm:description "This is a property for the test entity."@en ;
4747
bamm:characteristic bamm-c:Text .
4848

49-
:ParentTestEntity
50-
a bamm:AbstractEntity ;
51-
bamm:name "ParentTestEntity" ;
49+
:ParentTestEntity a bamm:AbstractEntity ;
5250
bamm:properties ( :testPropertyWithEither ) .

core/sds-test-aspect-models/src/main/resources/valid/bamm_2_0_0/io.openmanufacturing.test.shared/1.0.0/AspectWithExtendedEntity.ttl

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
#
1010
# SPDX-License-Identifier: MPL-2.0
1111

12-
@prefix : <urn:bamm:io.openmanufacturing.test.shared:1.0.0#> .
13-
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#> .
12+
@prefix : <urn:bamm:io.openmanufacturing.test.shared:1.0.0#> .
13+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#> .
1414
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:2.0.0#> .
1515
@prefix bamm-e: <urn:bamm:io.openmanufacturing:entity:2.0.0#> .
16-
@prefix unit: <urn:bamm:io.openmanufacturing:unit:2.0.0#> .
17-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16+
@prefix unit: <urn:bamm:io.openmanufacturing:unit:2.0.0#> .
17+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
1818

19-
:AspectWithExtendedEntity
20-
a bamm:Aspect ;
21-
bamm:name "AspectWithExtendedEntity" ;
19+
:AspectWithExtendedEntity a bamm:Aspect ;
2220
bamm:properties ( :testProperty ) ;
2321
bamm:operations ( ) .
2422

@@ -28,38 +26,25 @@
2826
bamm:see <http://example.com/omp> ;
2927
bamm:see <http://example.com/me> ;
3028
bamm:characteristic [ a bamm-c:SortedSet ;
31-
bamm:name "AspectWithExtendedEntity" ;
3229
bamm:dataType :TestEntity ] .
3330

34-
:TestEntity
35-
a bamm:Entity ;
36-
bamm:extends :ParentTestEntity ;
37-
bamm:name "TestEntity" ;
31+
:TestEntity a bamm:Entity ;
32+
bamm:extends :ParentTestEntity ;
3833
bamm:properties ( ) .
3934

40-
:ParentTestEntity
41-
a bamm:AbstractEntity ;
42-
bamm:extends :ParentOfParentEntity ;
43-
bamm:name "ParentTestEntity" ;
35+
:ParentTestEntity a bamm:AbstractEntity ;
36+
bamm:extends :ParentOfParentEntity ;
4437
bamm:properties ( :parentString ) .
4538

46-
:ParentOfParentEntity
47-
a bamm:AbstractEntity ;
48-
bamm:name "ParentOfParentEntity" ;
39+
:ParentOfParentEntity a bamm:AbstractEntity ;
4940
bamm:properties ( :booleanProperty ) .
5041

51-
:StringCode
52-
a bamm-c:Code ;
53-
bamm:name "StringCode" ;
42+
:StringCode a bamm-c:Code ;
5443
bamm:dataType xsd:string .
5544

56-
:parentString
57-
a bamm:Property ;
58-
bamm:name "parentString" ;
45+
:parentString a bamm:Property ;
5946
bamm:characteristic :StringCode .
6047

61-
:parentOfParentString
62-
a bamm:Property ;
63-
bamm:name "parentOfParentString" ;
48+
:parentOfParentString a bamm:Property ;
6449
bamm:characteristic :StringCode .
6550

0 commit comments

Comments
 (0)