Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCockx authored Oct 2, 2024
1 parent caea5e2 commit 842f63f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,21 @@ class MetaFieldGenerator {
if (ctx.cancelIndicator.canceled) {
return
}
val refs = nsc.value.filter(Data).flatMap[buildRDataType.ownAttributes].filter [
metaAnnotations.exists[name == "reference" || name == "address"]
].toSet
val attributesWithMeta = nsc.value.filter(Data).flatMap[buildRDataType.ownAttributes].filter[!metaAnnotations.empty]

for (ref : refs) {
val targetModel = ref.RType.namespace
for (attr : attributesWithMeta) {
val targetModel = attr.RType.namespace
val targetPackage = new RootPackage(targetModel)
val metaJt = ref.toForcedMetaItemJavaType
val metaJt = attr.toForcedMetaItemJavaType

if (ctx.cancelIndicator.canceled) {
return
}
fsa.generateFile('''«metaJt.canonicalName.withForwardSlashes».java''',
referenceWithMeta(targetPackage, metaJt, ref.RType))
}



//find all the metaed types
val metas = nsc.value.filter(Data).flatMap[buildRDataType.ownAttributes].filter[
!metaAnnotations.exists[name=="reference" || name=="address"]
].toSet

for (meta:metas) {
val targetModel = meta.RType.namespace
val targetPackage = new RootPackage(targetModel)
val metaJt = meta.toForcedMetaItemJavaType

if (ctx.cancelIndicator.canceled) {
return
if (attr.hasReferenceOrAddressMetadata) {
fsa.generateFile('''«metaJt.canonicalName.withForwardSlashes».java''', referenceWithMeta(targetPackage, metaJt, attr.RType))
} else {
fsa.generateFile('''«metaJt.canonicalName.withForwardSlashes».java''', fieldWithMeta(targetPackage, metaJt, attr.RType))
}
fsa.generateFile('''«metaJt.canonicalName.withForwardSlashes».java''', fieldWithMeta(targetPackage, metaJt, meta.RType))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.regnosys.rosetta.issues

import com.regnosys.rosetta.tests.RosettaInjectorProvider
import com.regnosys.rosetta.tests.util.CodeGeneratorTestHelper
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

import javax.inject.Inject

import static org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeAll
import java.util.Map
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle

// Regression test for https://github.com/finos/rune-dsl/issues/844
@ExtendWith(InjectionExtension)
@InjectWith(RosettaInjectorProvider)
@TestInstance(Lifecycle.PER_CLASS)
class Issue844 {

@Inject extension CodeGeneratorTestHelper

Map<String, String> code

@BeforeAll
def void setup() {
code = '''
type Foo:
foo Foo (0..1)
'''.generateCode
}

@Test
def void shouldNotGenerateFieldWithMeta() {
assertFalse(code.containsKey("com.rosetta.test.model.metafields.FieldWithMetaFoo"))
}

@Test
def void shouldNotGenerateReferenceWithMeta() {
assertFalse(code.containsKey("com.rosetta.test.model.metafields.ReferenceWithMetaFoo"))
}
}

0 comments on commit 842f63f

Please sign in to comment.