Skip to content

Commit

Permalink
Fixed RosettaEcoreUtils (finos#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCockx authored Sep 9, 2024
1 parent 2753bb1 commit 64c4d0e
Showing 1 changed file with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.regnosys.rosetta.rosetta.expression.OneOfOperation
import com.regnosys.rosetta.rosetta.simple.Annotated
import com.regnosys.rosetta.rosetta.simple.Attribute
import com.regnosys.rosetta.rosetta.simple.Condition
import com.regnosys.rosetta.rosetta.simple.Data
import com.regnosys.rosetta.rosetta.simple.Function
import com.regnosys.rosetta.types.RAttribute
import com.regnosys.rosetta.types.RDataType
Expand All @@ -31,6 +32,7 @@ import com.regnosys.rosetta.rosetta.RosettaFactory
import com.regnosys.rosetta.scoping.RosettaScopeProvider
import com.regnosys.rosetta.rosetta.simple.SimpleFactory
import com.regnosys.rosetta.types.RObjectFactory
import java.util.LinkedHashSet

@Singleton // see `metaFieldsCache`
class RosettaEcoreUtil {
Expand Down Expand Up @@ -63,6 +65,33 @@ class RosettaEcoreUtil {
}
}

@Deprecated // Use RDataType#getAllSuperTypes instead
def List<Data> getAllSuperTypes(Data data) {
val reversedResult = newLinkedHashSet
doGetAllSuperTypes(data, reversedResult);
reversedResult.toList.reverse
}
private def void doGetAllSuperTypes(Data current, LinkedHashSet<Data> superTypes) {
if (superTypes.add(current)) {
val s = current.getSuperType();
if (s !== null) {
doGetAllSuperTypes(s, superTypes);
}
}
}

@Deprecated // Use RDataType#getAllAttributes instead
def Iterable<Attribute> getAllAttributes(Data data) {
return data.allSuperTypes.flatMap[attributes]
}

@Deprecated // Use RDataType#getAllNonOverridenAttributes instead
def Collection<Attribute> getAllNonOverridenAttributes(Data data) {
val result = newLinkedHashMap
data.allAttributes.forEach[result.put(name, it)]
return result.values();
}

@Deprecated // TODO: move to REnumType, similar to RDataType
def Set<RosettaEnumeration> getAllSuperEnumerations(RosettaEnumeration e) {
doGetSuperEnumerations(e, newLinkedHashSet)
Expand Down Expand Up @@ -147,8 +176,13 @@ class RosettaEcoreUtil {
}

@Deprecated
def String conditionName(Condition cond, RDataType data) {
return cond.conditionName(data.name, data.EObject.conditions)
def String conditionName(Condition cond, RDataType t) {
conditionName(cond, t.EObject)
}

@Deprecated
def String conditionName(Condition cond, Data data) {
return cond.conditionName(data.name, data.conditions)
}

@Deprecated
Expand Down

0 comments on commit 64c4d0e

Please sign in to comment.