Skip to content
Snippets Groups Projects
Commit 07d51831 authored by Sebastian Krings's avatar Sebastian Krings
Browse files

add unit pragma to constants

parent b5be35dd
No related branches found
No related tags found
No related merge requests found
......@@ -1269,5 +1269,11 @@
descriptionId="de.prob.ui.unitPragma">
</attributeReference>
</attributeRelation>
<attributeRelation
elementTypeId="org.eventb.core.constant">
<attributeReference
descriptionId="de.prob.ui.unitPragma">
</attributeReference>
</attributeRelation>
</extension>
</plugin>
......@@ -2,8 +2,10 @@ package de.prob.ui.pragmas;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eventb.core.IVariable;
import org.eventb.core.basis.Constant;
import org.eventb.internal.ui.eventbeditor.manipulation.IAttributeManipulation;
import org.rodinp.core.IAttributeType;
import org.rodinp.core.IInternalElement;
import org.rodinp.core.IRodinElement;
import org.rodinp.core.RodinCore;
import org.rodinp.core.RodinDBException;
......@@ -11,52 +13,56 @@ import org.rodinp.core.RodinDBException;
import de.prob.core.internal.Activator;
public class UnitPragma implements IAttributeManipulation {
public static IAttributeType.String ATTRIBUTE = RodinCore.getStringAttrType(Activator.PLUGIN_ID + ".unitPragma");
public static IAttributeType.String ATTRIBUTE = RodinCore
.getStringAttrType(Activator.PLUGIN_ID + ".unitPragma");
public UnitPragma() {
// empty constructor
}
private IVariable asVariable(IRodinElement element) {
assert element instanceof IVariable;
private IInternalElement asInternalElement(IRodinElement element) {
if (element instanceof IVariable) {
return (IVariable) element;
} else if (element instanceof Constant) {
return (Constant) element;
}
return null;
}
@Override
public String[] getPossibleValues(IRodinElement element, IProgressMonitor monitor) {
public String[] getPossibleValues(IRodinElement element,
IProgressMonitor monitor) {
return new String[] { "", "a", "b", "c" };
}
@Override
public String getValue(IRodinElement element, IProgressMonitor monitor)
throws RodinDBException {
return asVariable(element).getAttributeValue(ATTRIBUTE);
return asInternalElement(element).getAttributeValue(ATTRIBUTE);
}
@Override
public boolean hasValue(IRodinElement element, IProgressMonitor monitor)
throws RodinDBException {
return asVariable(element).hasAttribute(ATTRIBUTE);
return asInternalElement(element).hasAttribute(ATTRIBUTE);
}
@Override
public void removeAttribute(IRodinElement element, IProgressMonitor monitor)
throws RodinDBException {
asVariable(element).removeAttribute(ATTRIBUTE, monitor);
asInternalElement(element).removeAttribute(ATTRIBUTE, monitor);
}
@Override
public void setDefaultValue(IRodinElement element, IProgressMonitor monitor)
throws RodinDBException {
asVariable(element).setAttributeValue(ATTRIBUTE, "",
monitor);
asInternalElement(element).setAttributeValue(ATTRIBUTE, "", monitor);
}
@Override
public void setValue(IRodinElement element, String value, IProgressMonitor monitor)
throws RodinDBException {
asVariable(element).setAttributeValue(ATTRIBUTE, value,
monitor);
public void setValue(IRodinElement element, String value,
IProgressMonitor monitor) throws RodinDBException {
asInternalElement(element).setAttributeValue(ATTRIBUTE, value, monitor);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment