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

require functionality now depends on the type

parent 2ab5b275
No related branches found
No related tags found
No related merge requests found
package org.rosi_project.model_sync.model_join.representation.core;
import amlanguage.Attribute;
import java.util.Objects;
import javax.annotation.Nonnull;
......
......@@ -11,7 +11,12 @@ class SSetter(struc: SStructuralFeature) extends SMethod(
name = s"set${struc.getName.firstLetterToUpperCase}",
result = PredefTypes.Unit,
params = Seq(SMethodParameter(struc.getName.head.toString, struc.getTypeElement)),
implementation = Seq(SMethodStatement(content = s"require(${struc.getName.head} != null)"),
SMethodStatement(content = s"${struc.getName} = ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))) {
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)))
}
}
......@@ -11,8 +11,13 @@ class SSetterAdd(struc: SStructuralFeature, inner: STypedElement) extends SMetho
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)))) {
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
......@@ -11,8 +11,13 @@ class SSetterRemove(struc: SStructuralFeature, inner: STypedElement) extends SMe
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)))) {
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
......@@ -13,18 +13,21 @@ object STypeRegistry {
private var registeredTypes: Map[STypedElement, EClass] = Map.empty
private val defaultTypes: Map[STypedElement, EClass] = Map(
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.Date -> null,
PredefTypes.Double -> null,
PredefTypes.Float -> null,
PredefTypes.Integer -> null,
PredefTypes.Object -> null,
PredefTypes.Long -> null,
PredefTypes.Short -> null,
PredefTypes.String -> null,
)
def getFromClass(cls: EClass): STypedElement = {
......@@ -36,7 +39,30 @@ object STypeRegistry {
null
}
registeredTypes ++= defaultTypes
registeredTypes ++= defaultTypesNull
registeredTypes ++= defaultTypesNotNull
/**
* 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.
......@@ -45,12 +71,9 @@ object STypeRegistry {
* @return `true` if it is a default type. Otherwise return false.
*/
def isDefaultType(name: String): Boolean = {
val existing: Option[STypedElement] = defaultTypes.keySet.find(existing => existing.getName == name)
if (existing.isEmpty) {
return false
} else {
return true
}
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.
......
......@@ -35,12 +35,12 @@ object PredefTypes {
/** `Double` */
val Double = SType("Double")
/** `String` */
val String = SType("String")
/** `Boolean` */
val Boolean = SType("Boolean")
/** `String` */
val String = SType("String")
/** `java.lang.Object` */
val Object = SType("Object")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment