Commit 5a11aee2 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub

fix(validation) message id expression validation (#635)

Close BS-16879
parent 78a2453b
......@@ -31,6 +31,7 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EcoreUtil.CrossReferencer;
import org.eclipse.gmf.runtime.notation.Edge;
public class RemoveDanglingReferences {
......@@ -53,6 +54,10 @@ public class RemoveDanglingReferences {
(((Connection) eObject).getTarget() == null || ((Connection) eObject).getSource() == null)) {
toRemove.add(eObject);
}
if (eObject instanceof Edge &&
(((Edge) eObject).getTarget() == null || ((Edge) eObject).getSource() == null)) {
toRemove.add(eObject);
}
});
toRemove.forEach(EcoreUtil::remove);
}
......
......@@ -77,6 +77,7 @@ import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.util.NotationAdapterFactory;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Image;
......@@ -441,6 +442,8 @@ public class DiagramRepositoryStore extends
}
//Sanitize model
new RemoveDanglingReferences(diagram).execute();
diagram.eResource().getContents().stream().filter(Diagram.class::isInstance).findFirst()
.ifPresent(d -> new RemoveDanglingReferences(d).execute());
updateConfigurationId(diagramResource, diagram);
return new FileInputStream(new File(diagramResource.getURI()
.toFileString()));
......
......@@ -56,8 +56,9 @@ public class MessageIdExpressionProvider implements IExpressionProvider {
for (int i = 0; i < throwMessageContent.getExpressions().size(); i++) {
ListExpression row = throwMessageContent.getExpressions().get(i);
Expression id = row.getExpressions().get(0);
Expression value = row.getExpressions().get(1);
if (id != null && id.getName() != null) {
messageContentIds.add(createExpression(id.getName()));
messageContentIds.add(createExpression(id.getName(), value.getReturnType()));
}
}
return messageContentIds;
......@@ -66,12 +67,12 @@ public class MessageIdExpressionProvider implements IExpressionProvider {
return Collections.emptySet();
}
private Expression createExpression(String id) {
private Expression createExpression(String name, String returnType) {
Expression exp = ExpressionFactory.eINSTANCE.createExpression();
exp.setType(getExpressionType());
exp.setContent(id);
exp.setName(id);
exp.setReturnType(String.class.getName());
exp.setContent(name);
exp.setName(name);
exp.setReturnType(returnType);
return exp;
}
......
......@@ -73,9 +73,6 @@ public class ExpressionLabelProvider extends LabelProvider implements IExpressio
@Override
public String getDescription(final Expression expression) {
if (ExpressionConstants.MESSAGE_ID_TYPE.equals(expression.getType())) {
return "";
}
return expression.getReturnType();
}
......
Markdown is supported
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