Commit 55a7d8d8 authored by Faezeh KHORRAM's avatar Faezeh KHORRAM 💬
Browse files

catch exception

parent b24828e9
......@@ -45,11 +45,13 @@ class ModelEObjectCreator {
}
var EObject newEObject = rootEPackage.EFactoryInstance.create(eobjectType)
//assign the value of its attributes
setEObjectFeatures(TDLObject, newEObject, eobjectType)
return newEObject
if (setEObjectFeatures(TDLObject, newEObject, eobjectType)){
return newEObject
}
return null
}
def void setEObjectFeatures(DataInstanceUse TDLObject, EObject newEObject, EClass eobjectType){
def boolean setEObjectFeatures(DataInstanceUse TDLObject, EObject newEObject, EClass eobjectType){
if (TDLObject.dataInstance instanceof StructuredDataInstance &&
(TDLObject.dataInstance as StructuredDataInstance).memberAssignment.size>0){//check the member assignments
val StructuredDataInstance dataInstance = TDLObject.dataInstance as StructuredDataInstance
......@@ -57,7 +59,7 @@ class ModelEObjectCreator {
val eStructuralFeature = eobjectType.getEStructuralFeature(getValidName(memberAssignment.member.name))
if (eStructuralFeature !== null){
val memberValue = memberAssignment.memberSpec
setFeatureValue(newEObject, eStructuralFeature, getTdlValues(memberValue))
return setFeatureValue(newEObject, eStructuralFeature, getTdlValues(memberValue))
}
}
}
......@@ -66,7 +68,7 @@ class ModelEObjectCreator {
val eStructuralFeature = eobjectType.getEStructuralFeature(getValidName(parameterBinding.parameter.name))
if (eStructuralFeature !== null){
val parameterValue = parameterBinding.dataUse
setFeatureValue(newEObject, eStructuralFeature, getTdlValues(parameterValue))
return setFeatureValue(newEObject, eStructuralFeature, getTdlValues(parameterValue))
}
}
}
......@@ -88,9 +90,9 @@ class ModelEObjectCreator {
return tdlValues
}
def void setFeatureValue (EObject newEObject, EStructuralFeature feature, List<DataUse> featureTdlValues){
def boolean setFeatureValue (EObject newEObject, EStructuralFeature feature, List<DataUse> featureTdlValues){
if (featureTdlValues.size == 0){
setEObjectFeatureValue (newEObject, feature, feature.defaultValue)
return setEObjectFeatureValue (newEObject, feature, feature.defaultValue)
}
//all the values must be from the same type:
//(1) if they are dataInstanceUse, it means they are references to EObjects of the model under test
......@@ -106,9 +108,9 @@ class ModelEObjectCreator {
}
if (!featureValues.empty){
if (feature.isMany){//the feature value is a list of eobjects
setEObjectFeatureValue (newEObject, feature, featureValues)
return setEObjectFeatureValue (newEObject, feature, featureValues)
}else{//the feature value is only one eobject
setEObjectFeatureValue (newEObject, feature, featureValues.get(0))
return setEObjectFeatureValue (newEObject, feature, featureValues.get(0))
}
}
}
......@@ -117,45 +119,44 @@ class ModelEObjectCreator {
if (feature.EType.name.equals("EIntegerObject") || feature.EType.name.equals("EInt")){
if (!feature.isMany){//a single integer must be set as the value
var featureValue = getLiteralValue(featureTdlValues.get(0) as LiteralValueUse)
Integer.parseInt(featureValue)
setEObjectFeatureValue (newEObject, feature, Integer.parseInt(featureValue))
return setEObjectFeatureValue (newEObject, feature, Integer.parseInt(featureValue))
}else{//a list of integers must be set as the value
var List<Integer> featureValues = new ArrayList
for (DataUse tdlValue : featureTdlValues){
var featureValue = getLiteralValue(tdlValue as LiteralValueUse)
featureValues.add(Integer.parseInt(featureValue))
}
setEObjectFeatureValue (newEObject, feature, featureValues)
return setEObjectFeatureValue (newEObject, feature, featureValues)
}
} else if (feature.EType.name.equals("EBooleanObject") || feature.EType.name.equals("EBoolean")){//TODO: must be tested
if (!feature.isMany){//a single boolean must be set as the value
var featureValue = getLiteralValue(featureTdlValues.get(0) as LiteralValueUse)
setEObjectFeatureValue (newEObject, feature, Boolean.parseBoolean(featureValue))
return setEObjectFeatureValue (newEObject, feature, Boolean.parseBoolean(featureValue))
}else{//a list of booleans must be set as the value
var List<Boolean> featureValues = new ArrayList
for (DataUse tdlValue : featureTdlValues){
var featureValue = getLiteralValue(tdlValue as LiteralValueUse)
featureValues.add(Boolean.parseBoolean(featureValue))
}
setEObjectFeatureValue (newEObject, feature, featureValues)
return setEObjectFeatureValue (newEObject, feature, featureValues)
}
} else {
if (!feature.isMany){//a single string must be set as the value
var featureValue = getLiteralValue(featureTdlValues.get(0) as LiteralValueUse)
setEObjectFeatureValue (newEObject, feature, featureValue)
return setEObjectFeatureValue (newEObject, feature, featureValue)
}else{//a list of strings must be set as the value
var List<String> featureValues = new ArrayList
for (DataUse tdlValue : featureTdlValues){
var featureValue = getLiteralValue(tdlValue as LiteralValueUse)
featureValues.add(featureValue)
}
setEObjectFeatureValue (newEObject, feature, featureValues)
return setEObjectFeatureValue (newEObject, feature, featureValues)
}
}
}
}
def setEObjectFeatureValue(EObject object, EStructuralFeature feature, Object value) {
def boolean setEObjectFeatureValue(EObject object, EStructuralFeature feature, Object value) {
try{
val TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(object);
domain.getCommandStack().execute(new RecordingCommand(domain) {
......@@ -163,16 +164,20 @@ class ModelEObjectCreator {
object.eSet(feature, value)
}
});
}catch(IllegalArgumentException e){
println("New value cannot be set for the " + feature.name + " property of the MUT")
}catch(NullPointerException e){
try{
object.eSet(feature, value)
}
catch(IllegalStateException e2){
e2.printStackTrace
}
return true
}catch(IllegalArgumentException e){
println("IllegalArgumentException: New value cannot be set for the " + feature.name + " property of the MUT")
return false
}catch(NullPointerException e){
try{
object.eSet(feature, value)
return true
}
catch(IllegalStateException e2){
println("IllegalStateException: New value cannot be set for the " + feature.name + " property of the MUT")
return false
}
}
}
def String getLiteralValue(LiteralValueUse literalValue){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment