Skip to content
Snippets Groups Projects
Commit e2311567 authored by Chrissi's avatar Chrissi
Browse files

Merge branch 'develop'

parents 0cf8f28c f0cedcbe
Branches
Tags
No related merge requests found
Showing
with 448 additions and 82 deletions
package org.rosi_project.model_sync.generator.acr_model
class SEnum (_name: String, _sPackage: String, val enums: Set[String]) extends STypedElement(_name, _sPackage, SClassType.normalClass) {
override def getDeepName: String = _name + ".Value"
override def accept(visitor: SModelVisitor): Unit = {
//pass never change an incoming enum
}
}
\ No newline at end of file
...@@ -7,10 +7,10 @@ import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExte ...@@ -7,10 +7,10 @@ import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExte
* *
* @author Rico Bergmann * @author Rico Bergmann
*/ */
class SGetter(attr: SAttribute) extends SMethod( class SGetter(struc: SStructuralFeature) extends SMethod(
name = s"get${attr.name.firstLetterToUpperCase}", name = s"get${struc.getName.firstLetterToUpperCase}",
result = attr.attrType, result = struc.getTypeElement,
params = Seq.empty, params = Seq.empty,
implementation = Seq(SMethodStatement(content = attr.name, usedTypes = Set(attr.attrType)))) { implementation = Seq(SMethodStatement(content = struc.getName, usedTypes = Set(struc.getTypeElement)))) {
} }
package org.rosi_project.model_sync.generator.acr_model
import java.util.Objects
class SInnerClass(_name: String,
_sPackage: String = "",
_sClassType: SClassType.Value = SClassType.normalClass,
val externalClass: SClass) extends SClass(_name, _sPackage, _sClassType) {
Objects.requireNonNull(externalClass, "External class may not be null")
override def getDeepName: String = externalClass.getName + "#" + _name
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model
import java.util.Objects
class SInnerViewNaturalClass(_name: String,
_sPackage: String = "",
_sClassType: SClassType.Value = SClassType.normalClass,
_externalClass: SClass,
val sumSource: SClass) extends SInnerClass(_name, _sPackage, _sClassType, _externalClass) {
Objects.requireNonNull(sumSource, "SUM Source class may not be null")
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model
import java.util.Objects
class SInnerViewRelationalClass(_name: String,
_sPackage: String = "",
_sClassType: SClassType.Value = SClassType.normalClass,
_externalClass: SClass,
val sumSource: SRelationalCompartmentClass,
val viewSource: SInnerViewNaturalClass,
val viewTarget: SInnerViewNaturalClass) extends SInnerClass(_name, _sPackage, _sClassType, _externalClass) {
Objects.requireNonNull(sumSource, "SUM Source class may not be null")
Objects.requireNonNull(viewSource, "View Source class may not be null")
Objects.requireNonNull(viewTarget, "View Target class may not be null")
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model
import org.rosi_project.model_management.sum.join.RsumJoinType
class SJoinClass(_name: String,
_sPackage: String,
val base: SClass,
val other: SClass,
val joinType: RsumJoinType.Value,
val joinAttributes: Set[SStructuralFeature],
val innerAttributes: Set[SStructuralFeature],
val joinObject: SClass) extends SClass(_name, _sPackage) {
override def getRootClassWithNameAndPackage(n: String, p: String): SClass = {
val bparent = base.getRootClassWithNameAndPackage(n, p)
val oparent = other.getRootClassWithNameAndPackage(n, p)
if (bparent != null) {
return bparent
}
oparent
}
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model package org.rosi_project.model_sync.generator.acr_model
import java.util.Objects import java.util.Objects
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
// TODO use a simple DSL to represent the method body? // TODO use a simple DSL to represent the method body?
...@@ -8,18 +9,26 @@ import java.util.Objects ...@@ -8,18 +9,26 @@ import java.util.Objects
* *
* @author Rico Bergmann * @author Rico Bergmann
*/ */
class SMethod(val name: String, class SMethod(name: String,
val result: STypedElement, val result: STypedElement,
val params: Seq[SMethodParameter], val params: Seq[SMethodParameter],
var implementation: Seq[SMethodStatement], var implementation: Seq[SMethodStatement],
var overrides: Boolean = false) var overrides: Boolean = false)
extends SModelElement { extends SNamedModelElement(name) {
private var visibility = MethodVisibility.publicVis
def setVisibility(v: MethodVisibility.Value): Unit = {
visibility = v
}
def getVisibility: MethodVisibility.Value = visibility;
/** Provides the return-type as a `String`. /** Provides the return-type as a `String`.
* *
* @return the type. Will never be `null` nor empty. * @return the type. Will never be `null` nor empty.
*/ */
def getResultType: String = result.getName def getResultType: String = result.getDeepName
/** Replaces the current body of `this` method. /** Replaces the current body of `this` method.
* *
...@@ -48,10 +57,10 @@ class SMethod(val name: String, ...@@ -48,10 +57,10 @@ class SMethod(val name: String,
def getUsedTypes: Set[STypedElement] = { def getUsedTypes: Set[STypedElement] = {
val resultType = result match { val resultType = result match {
case GenericSType(_, _, typeParam) => Seq(result, typeParam) case GenericSType(_, _, typeParam) => Seq(result, typeParam)
case SType.Unit => Seq.empty case PredefTypes.Unit => Seq.empty
case _ => Seq(result) case _ => Seq(result)
} }
val paramTypes = params.map(_.paramType) val paramTypes = params.map(_.getType)
val implementationTypes = implementation.map(_.usedTypes).fold(Set.empty)((s1, s2) => s1 ++ s2) val implementationTypes = implementation.map(_.usedTypes).fold(Set.empty)((s1, s2) => s1 ++ s2)
(resultType ++ paramTypes).toSet ++ implementationTypes (resultType ++ paramTypes).toSet ++ implementationTypes
} }
...@@ -63,17 +72,17 @@ class SMethod(val name: String, ...@@ -63,17 +72,17 @@ class SMethod(val name: String,
override def equals(other: Any): Boolean = other match { override def equals(other: Any): Boolean = other match {
case that: SMethod => case that: SMethod =>
(that canEqual this) && (that canEqual this) &&
name == that.name && getName == that.getName &&
result == that.result && result == that.result &&
params == that.params params == that.params
case _ => false case _ => false
} }
override def hashCode(): Int = { override def hashCode(): Int = {
val state = Seq(name, result, params) val state = Seq(getName, result, params)
state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b) state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b)
} }
override def toString: String = s"$name(${params.map(_.name).mkString(", ")}): $getResultType" override def toString: String = s"$getName(${params.map(_.getName).mkString(", ")}): ${result.getName}"
} }
...@@ -4,14 +4,32 @@ package org.rosi_project.model_sync.generator.acr_model ...@@ -4,14 +4,32 @@ package org.rosi_project.model_sync.generator.acr_model
* *
* @author Rico Bergmann * @author Rico Bergmann
*/ */
case class SMethodParameter(name: String, paramType: STypedElement) { case class SMethodParameter(private val name: String, private val paramType: STypedElement) {
/** Provides the type of `this` parameter as a `String`. /** Provides the type of `this` parameter as a `String`.
* *
* @return the type. Will never be `null` nor empty. * @return the type. Will never be `null` nor empty.
*/ */
def getType: String = paramType.getName def getTypeName: String = paramType.getName
override def toString: String = s"$name: $getType" /** Provides the deep type name of `this` parameter as a `String`.
*
* @return the type. Will never be `null` nor empty.
*/
def getDeepTypeName: String = paramType.getDeepName
/** Provides the type of `this` parameter as a `STypedElement`.
*
* @return the type. Will never be `null` nor empty.
*/
def getType: STypedElement = paramType
/** Provides the name of `this` parameter as a `String`.
*
* @return the name. Will never be `null` nor empty.
*/
def getName: String = name
override def toString: String = s"$getName: $getTypeName"
} }
...@@ -12,7 +12,7 @@ package org.rosi_project.model_sync.generator.acr_model ...@@ -12,7 +12,7 @@ package org.rosi_project.model_sync.generator.acr_model
* *
* @author Rico Bergmann * @author Rico Bergmann
*/ */
case class SMethodStatement(content: String, usedTypes: Set[STypedElement] = Set.empty) { case class SMethodStatement(private val content: String, usedTypes: Set[STypedElement] = Set.empty) {
/** The actual statement as a `String`. /** The actual statement as a `String`.
* *
......
...@@ -5,18 +5,81 @@ package org.rosi_project.model_sync.generator.acr_model ...@@ -5,18 +5,81 @@ package org.rosi_project.model_sync.generator.acr_model
* *
* @author Rico Bergmann * @author Rico Bergmann
*/ */
trait SModel extends SModelElement { abstract class SModel(private val name: String, private val sourceName: String, private val nsUri: String) extends SModelElement {
/** Provides all the classes in `this` model. /** Get NsURI from the model. */
*/ def getNsURI: String = nsUri
/** Get source name from the model. */
def getSourceName: String = sourceName
/** Get the name from the model. */
def getName: String = name
/** Provides all the classes in `this` model. */
def getAllClasses: Set[SClass] def getAllClasses: Set[SClass]
/** Provides all model classes in `this` model. */
def getModelClasses: Set[SClass]
/** Provides all model enums in `this` model. */
def getModelEnums: Set[SEnum]
/** Provides all provider classes in `this` model. */
def getProviderClasses: Set[SClass]
/** Provides all relational compartments in `this` model. */
def getRelationalCompartments: Set[SClass]
/** Provides all view compartments in `this` model. */
def getViewCompartments: Set[SClass]
/** Provides all join classes in `this` model. */
def getJoinClasses: Set[SClass]
/** Extends the model by a new provder class.
*
* @param mClass the class to add. May never `null`.
*/
def addProviderClass(mClass: SClass): Unit
/** Extends the model by a new relational compartment.
*
* @param mClass the class to add. May never `null`.
*/
def addRelationalCompartment(mClass: SClass): Unit
/** Extends the model by a new view compartment.
*
* @param mClass the class to add. May never `null`.
*/
def addViewCompartment(mClass: SClass): Unit
/** Extends the model by a new class. /** Extends the model by a new class.
* *
* @param mClass the class to add. May never `null`. * @param mClass the class to add. May never `null`.
*/ */
def addModelClass(mClass: SClass): Unit def addModelClass(mClass: SClass): Unit
/** Extends the model by a new join class.
*
* @param mClass the class to add. May never `null`.
*/
def addJoinClass(mClass: SClass): Unit
/** Extends the model by a new enum.
*
* @param mEnum the enum to add. May never `null`.
*/
def addModelEnums(mEnum: SEnum): Unit
/**
* Add another model to this on and return this one.
*/
def addOtherModel(model: SModel): SModel
override def toString: String = s"SModel: classes=$getAllClasses" override def toString: String = s"SModel: classes=$getAllClasses"
} }
...@@ -29,6 +29,13 @@ trait SModelVisitor { ...@@ -29,6 +29,13 @@ trait SModelVisitor {
*/ */
def visit(sAttr: SAttribute): Unit def visit(sAttr: SAttribute): Unit
/** Runs the algorithm as appropriate for a reference of a model class.
*
* @param sRef the reference to run the algorithm on. Whether it may be `null` is implementation
* specific.
*/
def visit(sRef: SReference): Unit
/** Runs the algorithm as appropriate for a method of a model class. /** Runs the algorithm as appropriate for a method of a model class.
* *
* @param sMethod the method to run the algorithm on. Whether it may be `null` is implementation * @param sMethod the method to run the algorithm on. Whether it may be `null` is implementation
......
package org.rosi_project.model_sync.generator.acr_model
/** Representation of named element like class, types, attributes and references.
*
* @author Christopher Werner
*/
abstract class SNamedModelElement (name: String) extends SModelElement {
/** The name of 'this' element.
*
* @return the name. Will never be `null` nor empty.
*/
def getName: String = name
/** The deep name with external class name + # + this class name.
* If there is no external class then only the name is returned.
*
* @return the name. Will never be `null` nor empty.
*/
def getDeepName: String = name
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model
/** Representation of class reference. This abstraction is a simplification of an actual scala
* reference: it is impossible to distinguish between ''final'' and ''non-final'' fields. Instead,
* all attributes will be treated mutable.
*
* @author Christopher Werner
*/
case class SReference(_name: String, /*val stype: STypedElement,*/ _ttype: STypedElement, upperBound: Int, lowerBound: Int, containment: Boolean = false, var oppositeRef: SReference = null) extends SStructuralFeature (_name, _ttype) {
def hasOpposite: Boolean = oppositeRef != null
def getImportant: SReference = {
//return if one is containment
if (containment) {
return this
}
if (oppositeRef.containment) {
return oppositeRef
}
//return if one has bigger lowerBound
if (lowerBound > oppositeRef.lowerBound) {
return this
}
if (lowerBound < oppositeRef.lowerBound) {
return oppositeRef
}
//return if one has smaller upperBound but bigger than -1
if (upperBound > -1 && oppositeRef.upperBound > -1 && upperBound > oppositeRef.upperBound) {
return oppositeRef
}
this
}
def getMinimalConnection: SReference = {
if (lowerBound == 0 && upperBound == 1) {
return this
}
if (hasOpposite && oppositeRef.lowerBound == 0 && oppositeRef.upperBound == 1) {
return oppositeRef
}
if (lowerBound == 1 && upperBound == 1) {
return this
}
if (hasOpposite && oppositeRef.lowerBound == 1 && oppositeRef.upperBound == 1) {
return oppositeRef
}
return null
}
override def accept(visitor: SModelVisitor): Unit = visitor.visit(this)
override def toString: String = s"$getName: ${getTypeElement.getName} $containment $lowerBound $upperBound"
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model
import java.util.Objects
class SRelationalCompartmentClass(_name: String,
_sPackage: String = "",
_sClassType: SClassType.Value = SClassType.normalClass,
val connectedRef: SReference,
val sClass: STypedElement,
val tClass: STypedElement) extends SClass(_name, _sPackage, _sClassType) {
Objects.requireNonNull(connectedRef, "Connected Reference may not be null")
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model package org.rosi_project.model_sync.generator.acr_model
import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExtended import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExtended
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
/** Simple representation of a setter method. /** Simple representation of a setter method.
* *
* @author Rico Bergmann * @author Rico Bergmann
*/ */
class SSetter(attr: SAttribute) extends SMethod( class SSetter(struc: SStructuralFeature) extends SMethod(
name = s"set${attr.name.firstLetterToUpperCase}", name = s"set${struc.getName.firstLetterToUpperCase}",
result = SType.Unit, result = PredefTypes.Unit,
params = Seq(SMethodParameter(attr.name.head.toString, attr.attrType)), params = Seq(SMethodParameter(struc.getName.head.toString, struc.getTypeElement)),
implementation = Seq(SMethodStatement(content = s"${attr.name} = ${attr.name.head}", usedTypes = Set(attr.attrType)))) { implementation = Seq(SMethodStatement(content = s"${struc.getName} = ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))) {
/*if (!STypeRegistry.isDefaultNotNullType(struc.getTypeElement.getName)) {
implementation = Seq(SMethodStatement(content = s"require(${struc.getName.head} != null)"),
SMethodStatement(content = s"${struc.getName} = ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))
} else {
implementation = Seq(SMethodStatement(content = s"${struc.getName} = ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))
} */
} }
package org.rosi_project.model_sync.generator.acr_model
import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExtended
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
/** Add an element to a Set of elements.
*
* @author Christopher Werner
*/
class SSetterAdd(struc: SStructuralFeature, inner: STypedElement) extends SMethod(
name = s"add${struc.getName.firstLetterToUpperCase}",
result = PredefTypes.Unit,
params = Seq(SMethodParameter(struc.getName.head.toString, inner)),
implementation = Seq(SMethodStatement(content = s"${struc.getName} += ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))) {
if (!STypeRegistry.isDefaultNotNullType(struc.getTypeElement.getName)) {
implementation = Seq(SMethodStatement(content = s"require(${struc.getName.head} != null)"),
SMethodStatement(content = s"require(!${struc.getName}.contains(${struc.getName.head}))"),
SMethodStatement(content = s"${struc.getName} += ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))
} else {
implementation = Seq(SMethodStatement(content = s"${struc.getName} += ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))
}
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model
import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExtended
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
/** Remove an element from a Set of elements.
*
* @author Christopher Werner
*/
class SSetterRemove(struc: SStructuralFeature, inner: STypedElement) extends SMethod(
name = s"remove${struc.getName.firstLetterToUpperCase}",
result = PredefTypes.Unit,
params = Seq(SMethodParameter(struc.getName.head.toString, inner)),
implementation = Seq(SMethodStatement(content = s"${struc.getName} -= ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))) {
if (!STypeRegistry.isDefaultNotNullType(struc.getTypeElement.getName)) {
implementation = Seq(SMethodStatement(content = s"require(${struc.getName.head} != null)"),
SMethodStatement(content = s"require(${struc.getName}.contains(${struc.getName.head}))"),
SMethodStatement(content = s"${struc.getName} -= ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))
} else {
implementation = Seq(SMethodStatement(content = s"${struc.getName} -= ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))
}
}
\ No newline at end of file
package org.rosi_project.model_sync.generator.acr_model
/** Representation of structural features like attributes and references.
*
* @author Christopher Werner
*/
abstract class SStructuralFeature (_name: String, private val sType: STypedElement) extends SNamedModelElement(_name) {
var isFinal: Boolean = false
private var visibility = MethodVisibility.publicVis
def setVisibility(v: MethodVisibility.Value): Unit = {
visibility = v
}
def getVisibility: MethodVisibility.Value = visibility;
/** The type of 'this' structural feature.
*
* @return
*/
def getTypeElement: STypedElement = sType
}
\ No newline at end of file
...@@ -11,30 +11,9 @@ package org.rosi_project.model_sync.generator.acr_model ...@@ -11,30 +11,9 @@ package org.rosi_project.model_sync.generator.acr_model
* @see [[SClass]] * @see [[SClass]]
* @author Rico Bergmann * @author Rico Bergmann
*/ */
case class SType(name: String, sPackage: String = "") extends STypedElement { case class SType(_name: String, _sPackage: String = "", _sClassType: SClassType.Value = SClassType.normalTrait) extends STypedElement (_name, _sPackage, _sClassType) {
override def getName: String = name
override def getPackage: String = sPackage
override def accept(visitor: SModelVisitor): Unit = visitor.visit(this) override def accept(visitor: SModelVisitor): Unit = visitor.visit(this)
} override def toString: String = s"ST: $getName($sPackage, $isInterface)"
/** The companion defines frequently used types.
*/
object SType {
/** The empty type.
*/
val Unit = SType("Unit")
/** Wrapper for `AnyRef`.
*/
val AnyRef = SType("AnyRef")
/** Wrapper for `String`.
*/
val String = SType("String")
} }
package org.rosi_project.model_sync.generator.acr_model package org.rosi_project.model_sync.generator.acr_model
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
import org.eclipse.emf.ecore.EClass
import org.rosi_project.model_sync.generator.acr_model.types.PredefEcoreTypes
/** Repository to keep track of all types and classes of model. It ensures that all attributes, /** Repository to keep track of all types and classes of model. It ensures that all attributes,
* methods, etc. reference the same type instances and thus prevent duplication and conflicting * methods, etc. reference the same type instances and thus prevent duplication and conflicting
* states. The registry should be treated as "''single point of truth''". * states. The registry should be treated as "''single point of truth''".
...@@ -8,19 +12,87 @@ package org.rosi_project.model_sync.generator.acr_model ...@@ -8,19 +12,87 @@ package org.rosi_project.model_sync.generator.acr_model
*/ */
object STypeRegistry { object STypeRegistry {
private var registeredTypes: Set[STypedElement] = Set() private var registeredTypes: Map[STypedElement, EClass] = Map.empty
private val defaultTypesNull: Map[STypedElement, EClass] = Map(
PredefTypes.Date -> null,
PredefTypes.Object -> null,
PredefTypes.String -> null,
)
private val defaultTypesNotNull: Map[STypedElement, EClass] = Map(
PredefTypes.Boolean -> null,
PredefTypes.Byte -> null,
PredefTypes.Char -> null,
PredefTypes.Double -> null,
PredefTypes.Float -> null,
PredefTypes.Integer -> null,
PredefTypes.Long -> null,
PredefTypes.Short -> null,
)
/*private val ecoreTypes: Map[STypedElement, EClass] = Map(
PredefEcoreTypes.EcoreObject -> null,
PredefEcoreTypes.EcoreStructuralFeature -> null,
)*/
def getFromClass(cls: EClass): STypedElement = {
registeredTypes.foreach(r => {
if (r._2 == cls) {
return r._1
}
})
null
}
registeredTypes ++= defaultTypesNull
registeredTypes ++= defaultTypesNotNull
//registeredTypes ++= ecoreTypes
registerDefaultTypes() /**
* Return true if this name comes from a standard null type.
*
* @param name the name that must be proven.
* @return `true` if it is a default type. Otherwise return false.
*/
def isDefaultNullType(name: String): Boolean = {
val existingNull: Option[STypedElement] = defaultTypesNull.keySet.find(existing => existing.getName == name)
return !existingNull.isEmpty
}
/**
* Return true if this name comes from a standard not null type.
*
* @param name the name that must be proven.
* @return `true` if it is a default type. Otherwise return false.
*/
def isDefaultNotNullType(name: String): Boolean = {
val existingNotNull: Option[STypedElement] = defaultTypesNotNull.keySet.find(existing => existing.getName == name)
return !existingNotNull.isEmpty
}
/**
* Return true if this name comes from a standard type.
*
* @param name the name that must be proven.
* @return `true` if it is a default type. Otherwise return false.
*/
def isDefaultType(name: String): Boolean = {
val existingNotNull: Option[STypedElement] = defaultTypesNotNull.keySet.find(existing => existing.getName == name)
val existingNull: Option[STypedElement] = defaultTypesNull.keySet.find(existing => existing.getName == name)
return !existingNotNull.isEmpty || !existingNull.isEmpty
}
/** Registers a type if it is not already known. /** Registers a type if it is not already known.
* *
* @param theType the new type. May never be `null`. * @param theType the new type. May never be `null`.
* @return `theType` if it was indeed unknown before. Otherwise the currently registered type. * @return `theType` if it was indeed unknown before. Otherwise the currently registered type.
*/ */
def addType(theType: STypedElement): STypedElement = { def addType(theType: STypedElement, cls: EClass): STypedElement = {
val existing: Option[STypedElement] = registeredTypes.find(existing => existing.getName == theType.getName && existing.getPackage == theType.getPackage) val existing: Option[STypedElement] = registeredTypes.keySet.find(existing => existing.getName == theType.getName && existing.getPackage == theType.getPackage)
if (existing.isEmpty) { if (existing.isEmpty) {
registeredTypes += theType registeredTypes = registeredTypes + (theType -> cls)
//registeredTypes += theType
theType theType
} else { } else {
existing.get existing.get
...@@ -34,35 +106,12 @@ object STypeRegistry { ...@@ -34,35 +106,12 @@ object STypeRegistry {
* @return the type if it was found * @return the type if it was found
*/ */
def query(name: String, sPackage: String): Option[STypedElement] = { def query(name: String, sPackage: String): Option[STypedElement] = {
registeredTypes.find(t => t.getName == name && t.getPackage == sPackage) registeredTypes.keySet.find(t => t.getName == name && t.getPackage == sPackage)
}
/** Searches for a type based on its name. It may reside in any package.
*
* @param name the type's name
* @return the type if it was found
*/
def queryForName(name: String): Option[STypedElement] = {
registeredTypes.find(_.getName == name)
} }
/** Provides all types that are currently in the repository. /** Provides all types that are currently in the repository.
*/ */
def allTypes: Set[STypedElement] = registeredTypes def allTypes: Set[STypedElement] = registeredTypes.keySet
private def registerDefaultTypes(): Unit = {
registeredTypes ++= Seq(
SType("Boolean"),
SType("Byte"),
SType("Short"),
SType("Integer"),
SType("Long"),
SType("Float"),
SType("Double"),
SType("String"),
)
}
override def toString: String = s"Registry: $registeredTypes" override def toString: String = s"Registry: $registeredTypes"
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment