Permalink
Browse files

[#89]: Relax input spec grammar by using Xtext options

Finished the checker for the MappingDSL

Task-Url: http://github.com/roberthilbrich/assist-public/issues/89
  • Loading branch information...
RobertHilbrich committed Oct 16, 2018
1 parent 278a400 commit 6203a51d1e03e2d90fd78d0033d35fac7d92189f
@@ -1,14 +1,12 @@
package ch.hilbri.assist.mapping.dsl.validation

import ch.hilbri.assist.model.AssistModel
import ch.hilbri.assist.model.Compartment
import ch.hilbri.assist.model.CustomProperty
import ch.hilbri.assist.model.FeatureRequirement
import ch.hilbri.assist.model.IntProperty
import ch.hilbri.assist.model.HardwareElement
import ch.hilbri.assist.model.ModelPackage
import ch.hilbri.assist.model.Property
import ch.hilbri.assist.model.StringProperty
import ch.hilbri.assist.model.SoftwareElement
import org.eclipse.xtext.validation.Check
import ch.hilbri.assist.model.HardwareElement

class MappingDSLValidator extends AbstractMappingDSLValidator {

@@ -25,28 +23,53 @@ class MappingDSLValidator extends AbstractMappingDSLValidator {
}
}

@Check
def checkProperties(AssistModel assistModel) {
val allProperties = assistModel.properties.filter[!(it instanceof CustomProperty)].toList
val propertiesList = allProperties.groupBy[class]
val multipleProperties = propertiesList.filter[className, properties | properties.size > 1]
for (classname : multipleProperties.keySet) {
for (property : multipleProperties.get(classname)) {
val propertyName = classname.name.split('\\.').last.split('Property').head
val propertyValue = multipleProperties.get(classname).head.stringValue
warning('''There are multiple definitions of the "«propertyName»" property in "Global" section. The value of the first definition ("«propertyValue»") will be used.''',
assistModel, ModelPackage.Literals::ASSIST_MODEL__PROPERTIES, allProperties.indexOf(property)
)
}
}
}

@Check
def checkProperties(HardwareElement hwElem) {
val allProperties = hwElem.properties
val allProperties = hwElem.properties.filter[!(it instanceof CustomProperty)].toList
val propertiesList = allProperties.groupBy[class]
val multipleProperties = propertiesList.filter[className, properties | properties.size > 1]
for (classname : multipleProperties.keySet) {
for (property : multipleProperties.get(classname)) {
val propertyName = classname.name.split('\\.').last.split('Property').head
val hwLevel = hwElem.class.name.split('\\.').last.split('Impl').head
val propertyValue = multipleProperties.get(classname).head.value
val propertyValue = multipleProperties.get(classname).head.stringValue
warning('''There are multiple definitions of the "«propertyName»" property in «hwLevel» "«hwElem.name»". The value of the first definition ("«propertyValue»") will be used.''',
hwElem, ModelPackage.Literals::HARDWARE_ELEMENT__PROPERTIES, allProperties.indexOf(property)
)
}
}
}

private def String getValue(Property property) {
if (property instanceof StringProperty)
return (property as StringProperty).value
if (property instanceof IntProperty)
return (property as IntProperty).value.toString
@Check
def checkProperties(SoftwareElement swElem) {
val allProperties = swElem.properties.filter[!(it instanceof CustomProperty)].toList
val propertiesList = allProperties.groupBy[class]
val multipleProperties = propertiesList.filter[className, properties | properties.size > 1]
for (classname : multipleProperties.keySet) {
for (property : multipleProperties.get(classname)) {
val propertyName = classname.name.split('\\.').last.split('Property').head
val hwLevel = swElem.class.name.split('\\.').last.split('Impl').head
val propertyValue = multipleProperties.get(classname).head.stringValue
warning('''There are multiple definitions of the "«propertyName»" property in «hwLevel» "«swElem.name»". The value of the first definition ("«propertyValue»") will be used.''',
swElem, ModelPackage.Literals::SOFTWARE_ELEMENT__PROPERTIES, allProperties.indexOf(property)
)
}
}
}

}
@@ -20,7 +20,21 @@ annotation "http://www.eclipse.org/emf/2002/GenModel" as GenModel
//
// PROPERTIES
//
class Property {}
class Property {
op String getStringValue() {
if (this instanceof StringProperty) return (this as StringProperty).value
else if (this instanceof IntProperty) return (this as IntProperty).value.toString
else if (this instanceof DesignAssuranceLevelProperty) return (this as DesignAssuranceLevelProperty).value.toString
else if (this instanceof CriticalityLevelProperty) return (this as CriticalityLevelProperty).value.toString
else if (this instanceof PeriodicityProperty) return (this as PeriodicityProperty).value.toString
else if (this instanceof ColorProperty) return (this as ColorProperty).value.toString
else if (this instanceof AssignedCoreProperty) return (this as AssignedCoreProperty).value.name
else if (this instanceof CustomIntProperty) return (this as CustomIntProperty).value.toString
else if (this instanceof CustomStringProperty) return (this as CustomStringProperty).value
else return null
}
}

class StringProperty extends Property { String value = "" }
class IntProperty extends Property { int value = "0" }
class SystemNameProperty extends StringProperty {}
Oops, something went wrong.

0 comments on commit 6203a51

Please sign in to comment.