Skip to content

Commit a5df14d

Browse files
committed
Fix tests and update logic
1 parent 26f6217 commit a5df14d

File tree

9 files changed

+36
-18
lines changed

9 files changed

+36
-18
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/Instantiator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected Value buildValue( final RDFNode node, final Optional<Resource> charact
180180
}
181181

182182
if ( !resource.hasProperty( RDF.type, SammNs.SAMM.Value() ) ) {
183-
return new DefaultScalarValue( null, resource.getURI(), new DefaultScalar( type.toString() ) );
183+
return new DefaultScalarValue( buildBaseAttributes( resource ), resource.getURI(), new DefaultScalar( type.toString() ) );
184184
}
185185

186186
if ( resource.hasProperty( RDF.type, SammNs.SAMM.Value() ) ) {

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/ValueInstantiator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public Optional<ScalarValue> buildScalarValue( final String lexicalRepresentatio
5151
return SammXsdType.ALL_TYPES.stream()
5252
.filter( type -> type.getURI().equals( datatypeUri ) )
5353
.map( type -> type.parse( lexicalRepresentation ) )
54-
.<ScalarValue> map( value -> new DefaultScalarValue( null, value, new DefaultScalar( datatypeUri ) ) )
54+
.<ScalarValue> map( value -> new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), value, new DefaultScalar( datatypeUri ) ) )
5555
.findAny();
5656
}
5757

5858
public ScalarValue buildLanguageString( final String lexicalRepresentation, final String languageTag ) {
5959
final LangString langString = new LangString( lexicalRepresentation, Locale.forLanguageTag( languageTag ) );
6060
final Scalar type = new DefaultScalar( RDF.langString.getURI() );
61-
return new DefaultScalarValue( null, langString, type );
61+
return new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), langString, type );
6262
}
6363
}

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/instantiator/PropertyInstantiator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private ScalarValue buildScalarValue( final RDFNode node, final Type expectedTyp
114114
return new DefaultScalarValue( buildBaseAttributes( resource ), valueOpt.get(), new DefaultScalar( expectedType.toString() ) );
115115
}
116116

117-
return new DefaultScalarValue( null, resource.getURI(), new DefaultScalar( expectedType.toString() ) );
117+
return new DefaultScalarValue( buildBaseAttributes( resource ), resource.getURI(), new DefaultScalar( expectedType.toString() ) );
118118
}
119119

120120
throw new AspectLoadingException( "Unexpected RDF node type: " + node );

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/instantiator/RangeConstraintInstantiator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public RangeConstraint apply( final Resource rangeConstraint ) {
4242

4343
final Optional<ScalarValue> minValue = optionalAttributeValue( rangeConstraint, SammNs.SAMMC.minValue() )
4444
.map( Statement::getLiteral )
45-
.map( literal -> new DefaultScalarValue( null, literal.getValue(), new DefaultScalar( literal.getDatatypeURI() ) ) );
45+
.map( literal -> new DefaultScalarValue( buildBaseAttributes( rangeConstraint ), literal.getValue(), new DefaultScalar( literal.getDatatypeURI() ) ) );
4646
final Optional<ScalarValue> maxValue = optionalAttributeValue( rangeConstraint, SammNs.SAMMC.maxValue() )
4747
.map( Statement::getLiteral )
48-
.map( literal -> new DefaultScalarValue( null, literal.getValue(), new DefaultScalar( literal.getDatatypeURI() ) ) );
48+
.map( literal -> new DefaultScalarValue( buildBaseAttributes( rangeConstraint ), literal.getValue(), new DefaultScalar( literal.getDatatypeURI() ) ) );
4949
final BoundDefinition lowerBoundDefinition = getBoundDefinitionForRangeValue( minValue,
5050
SammNs.SAMMC.lowerBoundDefinition(), rangeConstraint, BoundDefinition.AT_LEAST );
5151
final BoundDefinition upperBoundDefinition = getBoundDefinitionForRangeValue( maxValue,

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/metamodel/builder/SammBuilder.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,25 +1371,41 @@ public static <T extends EntityInstanceBuilder<T>> EntityInstanceBuilder<T> enti
13711371
}
13721372

13731373
public static ScalarValue value( final String stringValue ) {
1374-
return new DefaultScalarValue( null, stringValue, xsd.string );
1374+
return new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), stringValue, xsd.string );
13751375
}
13761376

13771377
public static ScalarValue value( final boolean booleanValue ) {
1378-
return new DefaultScalarValue( null, booleanValue, xsd.boolean_ );
1378+
return new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), booleanValue, xsd.boolean_ );
13791379
}
13801380

13811381
public static ScalarValue value( final float floatValue ) {
1382-
return new DefaultScalarValue( null, floatValue, xsd.float_ );
1382+
return new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), floatValue, xsd.float_ );
13831383
}
13841384

13851385
public static ScalarValue value( final double doubleValue ) {
1386-
return new DefaultScalarValue( null, doubleValue, xsd.double_ );
1386+
return new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), doubleValue, xsd.double_ );
13871387
}
13881388

13891389
/* Intentionally no value(int) method here, because an int value could imply different XSD types */
13901390

13911391
public static ScalarValue value( final Object value, final Scalar type ) {
1392-
return new DefaultScalarValue( null, value, dataTypeByUri( type.getUrn() ) );
1392+
MetaModelBaseAttributes metaModelBaseAttributes;
1393+
1394+
if ( value instanceof ScalarValue scalarValue ) {
1395+
metaModelBaseAttributes = MetaModelBaseAttributes.builder()
1396+
.withUrn( scalarValue.urn() )
1397+
.withPreferredNames( scalarValue.getPreferredNames() )
1398+
.withDescriptions( scalarValue.getDescriptions() )
1399+
.withSee( scalarValue.getSee() )
1400+
.isAnonymous( scalarValue.isAnonymous() )
1401+
.withSourceFile( scalarValue.getSourceFile() )
1402+
.build();
1403+
} else {
1404+
metaModelBaseAttributes = MetaModelBaseAttributes.builder()
1405+
.isAnonymous( false )
1406+
.build();
1407+
}
1408+
return new DefaultScalarValue( metaModelBaseAttributes, value, dataTypeByUri( type.getUrn() ) );
13931409
}
13941410

13951411
public static <T> java.util.List<ScalarValue> values( final Scalar type, final T... values ) {

core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/json/AspectModelJsonPayloadGeneratorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,10 @@ Trait createTraitWithRangeConstraint( final Type dataType, final BoundDefinition
789789
.withUrn( TestModel.TEST_NAMESPACE + "TestConstraint" ).build();
790790
final Optional<ScalarValue> minValue = BoundDefinition.OPEN.equals( boundKind )
791791
? Optional.empty()
792-
: Optional.of( new DefaultScalarValue( null, randomRange.getLeft(), new DefaultScalar( dataType.getUrn() ) ) );
792+
: Optional.of( new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), randomRange.getLeft(), new DefaultScalar( dataType.getUrn() ) ) );
793793
final Optional<ScalarValue> maxValue = BoundDefinition.OPEN.equals( boundKind )
794794
? Optional.empty()
795-
: Optional.of( new DefaultScalarValue( null, randomRange.getRight(), new DefaultScalar( dataType.getUrn() ) ) );
795+
: Optional.of( new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), randomRange.getRight(), new DefaultScalar( dataType.getUrn() ) ) );
796796
final RangeConstraint rangeConstraint = new DefaultRangeConstraint( constraintAttibutes, minValue, maxValue, boundKind,
797797
getMatchingUpperBound( boundKind ) );
798798
final MetaModelBaseAttributes traitAttributes = MetaModelBaseAttributes.builder().withUrn( TestModel.TEST_NAMESPACE + "TestTrait" )

core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticMetaModelVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ public String visitBase( final ModelElement modelElement, final StaticCodeGenera
111111
public String visitScalarValue( final ScalarValue value, final StaticCodeGenerationContext context ) {
112112
context.getCodeGenerationConfig().importTracker().importExplicit( DefaultScalarValue.class );
113113
final ValueExpressionVisitor.Context valueContext = new ValueExpressionVisitor.Context( context.getCodeGenerationConfig(), false );
114+
final String metaModelAttributes = ( !value.getSee().isEmpty() && !value.getPreferredNames().isEmpty() ) ? "getMetaModelBaseAttributes( value, context )" : null;
114115
return "new DefaultScalarValue("
116+
+ metaModelAttributes + ","
115117
// Object value
116118
+ value.accept( valueExpressionVisitor, valueContext ) + ","
117119
// Scalar type

core/esmf-aspect-model-java-generator/src/test-shared/java/org/eclipse/esmf/test/shared/arbitraries/SammArbitraries.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ default Arbitrary<? extends Type> anyType() {
254254
}
255255

256256
private Value buildScalarValue( final Object value, final Scalar type ) {
257-
return new DefaultScalarValue( null, value, type );
257+
return new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), value, type );
258258
}
259259

260260
@Provide

core/esmf-aspect-model-java-generator/src/test/java/org/eclipse/esmf/aspectmodel/java/StaticMetaModelJavaGeneratorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ void testCharacteristicInstantiationForEnums() throws IOException {
446446
new DefaultEnumeration(MetaModelBaseAttributes.builder().withUrn(AspectModelUrn.fromUrn(NAMESPACE + "TestEnumeration")).build(), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer"), new ArrayList<Value>() {
447447
448448
{
449-
add(new DefaultScalarValue(new BigInteger("1"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
450-
add(new DefaultScalarValue(new BigInteger("2"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
451-
add(new DefaultScalarValue(new BigInteger("3"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
449+
add(new DefaultScalarValue(null, new BigInteger("1"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
450+
add(new DefaultScalarValue(null, new BigInteger("2"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
451+
add(new DefaultScalarValue(null, new BigInteger("3"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
452452
}
453453
})""";
454454

@@ -518,7 +518,7 @@ void testCharacteristicInstantiationForPropertyWithExampleValue() throws IOExcep
518518

519519
result.assertMetaModelBaseAttributesForProperties( "MetaAspectWithCollection", expectedBaseAttributes );
520520

521-
final String expectedExampleValue = "Optional.of(new DefaultScalarValue(\"Example Value\", new DefaultScalar(\"http://www.w3"
521+
final String expectedExampleValue = "Optional.of(null, new DefaultScalarValue(\"Example Value\", new DefaultScalar(\"http://www.w3"
522522
+ ".org/2001/XMLSchema#string\")))";
523523

524524
result.assertConstructorArgumentForProperties(

0 commit comments

Comments
 (0)