diff --git a/build.gradle b/build.gradle index b3b707af1a07cd484b0a4c0c003099f7a460eb65..40e11823aacbdfe27b11559d37842727e382d85d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,16 @@ +// to trigger a full tycho build please use 'gradle deleteFromClassPath completeInstall' +import org.apache.tools.ant.taskdefs.condition.Os -targetRepositories = ["http://www.stups.uni-duesseldorf.de/prob_dev_target/","http://download.eclipse.org/releases/indigo/","http://rodin-b-sharp.sourceforge.net/updates"] +project.ext{ + + targetRepositories = ["http://download.eclipse.org/releases/indigo/", + "http://rodin-b-sharp.sourceforge.net/updates", + "http://rodin-b-sharp.sourceforge.net/core-updates" + , "http://www.stups.uni-duesseldorf.de/ProB/buildlibs/theory/" + ] -groupID = "de.prob" + groupID = "de.prob" +} apply from: 'tycho_build.gradle' @@ -27,7 +36,7 @@ project(':de.prob.core') { } - def parser_version = '2.4.8-SNAPSHOT' + def parser_version = '2.4.19-SNAPSHOT' dependencies { compile group: "de.prob", name: "answerparser", version: parser_version , changing: true @@ -37,7 +46,7 @@ project(':de.prob.core') { compile group: "de.prob", name: "parserbase", version: parser_version , changing: true compile group: "de.prob", name: "prologlib", version: parser_version , changing: true compile group: "de.prob", name: "unicode", version: parser_version , changing: true - compile 'jgrapht:jgrapht:0.8.3' + compile group: "de.prob", name: "theorymapping", version: parser_version , changing: true compile 'commons-lang:commons-lang:2.6' } @@ -64,16 +73,16 @@ def download(address,target) { } task downloadCli << { - dir = workspacePath+'de.prob.core/prob/' + def dir = workspacePath+'de.prob.core/prob/' delete file(dir) new File(dir).mkdirs() ['leopard64':'macos','linux':'linux','linux64':'linux64','win32':'windows'].each { - n = it.getKey() + def n = it.getKey() - targetdir = dir+it.getValue() - targetzip = dir+"probcli_${n}.zip" - url = "http://nightly.cobra.cs.uni-duesseldorf.de/cli/probcli_${n}.zip" + def targetdir = dir+it.getValue() + def targetzip = dir+"probcli_${n}.zip" + def url = "http://nightly.cobra.cs.uni-duesseldorf.de/cli/probcli_${n}.zip" download(url,targetzip) FileTree zip = zipTree(targetzip) copy { @@ -83,8 +92,8 @@ task downloadCli << { delete file(targetzip) } - targetdir = dir+"windows/" - targetzip = targetdir+"windowslib.zip" + def targetdir = dir+"windows/" + def targetzip = targetdir+"windowslib.zip" download("http://nightly.cobra.cs.uni-duesseldorf.de/cli/windowslib.zip",targetzip) FileTree zip = zipTree(targetzip) copy { @@ -96,6 +105,53 @@ task downloadCli << { } + +task downloadCli2 ( type: Exec ) { + + def dir = workspacePath+'de.prob.core/prob/' + delete file(dir) + new File(dir).mkdirs() + + ['leopard64':'macos','linux':'linux','linux64':'linux64','win32':'windows'].each { + def n = it.getKey() + + def targetdir = dir+it.getValue() + def targetzip = dir+"probcli_${n}.zip" + def url = "http://nightly.cobra.cs.uni-duesseldorf.de/cli/probcli_${n}.zip" + download(url,targetzip) + FileTree zip = zipTree(targetzip) + copy { + from zip + into targetdir + } + delete file(targetzip) + } + + def targetdir = dir+"windows/" + def targetzip = targetdir+"windowslib.zip" + download("http://nightly.cobra.cs.uni-duesseldorf.de/cli/windowslib.zip",targetzip) + FileTree zip = zipTree(targetzip) + copy { + from zip + into targetdir + } + delete file(targetzip) + + ['leopard64':'macos','linux32':'linux','linux64':'linux64'].each { + + def n = it.getKey() + targetdir = dir+it.getValue() + + download( "http://nightly.cobra.cs.uni-duesseldorf.de/cspm/cspm-"+n, targetdir+"/cspm" ) + } + commandLine 'chmod', 'a+x', dir+'linux'+'/cspm', dir+'linux64'+'/cspm', dir+'macos'+'/cspm' + //commandLine 'chmod', 'a+x', dir+'*'+'/cspm' + + download( "http://nightly.cobra.cs.uni-duesseldorf.de/cspm/cspm-windows", dir+"windows"+"/cspm.exe" ) +} + + + completeInstall.dependsOn downloadCli completeInstall.dependsOn subprojects.setClassPath diff --git a/de.bmotionstudio.gef.editor/META-INF/MANIFEST.MF b/de.bmotionstudio.gef.editor/META-INF/MANIFEST.MF index d51f7c6fbfc3643ab3835dfea27032834f06a5f2..2b01795b07782adef4fe27c52fd22f0f7a1b242e 100644 --- a/de.bmotionstudio.gef.editor/META-INF/MANIFEST.MF +++ b/de.bmotionstudio.gef.editor/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: BMotion Studio Editor Plug-in Bundle-SymbolicName: de.bmotionstudio.gef.editor;singleton:=true -Bundle-Version: 5.4.0.qualifier +Bundle-Version: 5.5.0.qualifier Bundle-Activator: de.bmotionstudio.gef.editor.BMotionEditorPlugin Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)", @@ -12,8 +12,9 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", org.eclipse.jface.databinding;bundle-version="[1.2.1,2.0.0)", org.eclipse.core.databinding.beans;bundle-version="[1.1.1,2.0.0)", org.eclipse.gef;bundle-version="[3.7.0,4.0.0)";visibility:=reexport, - de.prob.core;bundle-version="[9.3.0,9.4.0)";visibility:=reexport, - org.eventb.core;bundle-version="[2.1.0,2.6.0)" + de.prob.core;bundle-version="[9.4.0,9.5.0)";visibility:=reexport, + org.eventb.core;bundle-version="[2.5.0,2.6.0)", + org.eclipse.help;bundle-version="3.5.100" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Eclipse-RegisterBuddy: de.prob.core diff --git a/de.bmotionstudio.gef.editor/icons/eclipse16/linkto_help.gif b/de.bmotionstudio.gef.editor/icons/eclipse16/linkto_help.gif new file mode 100644 index 0000000000000000000000000000000000000000..86550fe9f4505c88287a70add9bb89bd24d0e8b2 Binary files /dev/null and b/de.bmotionstudio.gef.editor/icons/eclipse16/linkto_help.gif differ diff --git a/de.bmotionstudio.gef.editor/lib/ext/._antlr-2.7.7.jar1851805142189607825.tmp b/de.bmotionstudio.gef.editor/lib/ext/._antlr-2.7.7.jar1851805142189607825.tmp new file mode 100644 index 0000000000000000000000000000000000000000..5e5f14b35584eac2a9f0f888769f0ab93ca6d849 Binary files /dev/null and b/de.bmotionstudio.gef.editor/lib/ext/._antlr-2.7.7.jar1851805142189607825.tmp differ diff --git a/de.bmotionstudio.gef.editor/plugin.xml b/de.bmotionstudio.gef.editor/plugin.xml index f1d465afcd7efc7c5ebae8ca9f8eeb8541137848..e910bbd05aaade12d33b9e1a78d6c0c9c867b894 100644 --- a/de.bmotionstudio.gef.editor/plugin.xml +++ b/de.bmotionstudio.gef.editor/plugin.xml @@ -49,7 +49,8 @@ class="de.bmotionstudio.gef.editor.library.LibraryView" icon="icons/icon_library.gif" id="de.bmotionstudio.gef.editor.LibraryView" - name="BMS Library"> + name="Library" + restorable="true"> </view> </extension> <extension @@ -110,7 +111,7 @@ <extension point="org.eclipse.ui.commands"> <command - defaultHandler="de.bmotionstudio.gef.editor.internal.OpenWebsiteHandler" + defaultHandler="de.bmotionstudio.gef.editor.handler.OpenWebsiteHandler" id="de.bmotionstudio.gef.editor.command.openBMotionStudioWebsite" name="Open website"> </command> @@ -119,7 +120,7 @@ name="Start Visualization from Editor"> </command> <command - defaultHandler="de.bmotionstudio.gef.editor.internal.StartVisualizationFileHandler" + defaultHandler="de.bmotionstudio.gef.editor.handler.StartVisualizationFileHandler" id="de.bmotionstudio.command.startVisualizationFromFile" name="Start Visualization from File"> </command> @@ -127,7 +128,7 @@ <extension point="org.eclipse.ui.handlers"> <handler - class="de.bmotionstudio.gef.editor.internal.StartVisualizationEditorHandler" + class="de.bmotionstudio.gef.editor.handler.StartVisualizationEditorHandler" commandId="de.bmotionstudio.command.startVisualizationFromEditor"> <enabledWhen> <with @@ -156,6 +157,9 @@ <registerImages class="de.bmotionstudio.gef.editor.EditorImageRegistry"> </registerImages> + <registerImages + class="de.bmotionstudio.gef.editor.ImageRegistry"> + </registerImages> </extension> <extension @@ -169,142 +173,142 @@ icon="icons/eclipse16/image_obj.gif" id="de.bmotionstudio.gef.editor.image" name="Image" - service="de.bmotionstudio.gef.editor.service.BImageService"> + service="de.bmotionstudio.gef.editor.model.service.BImageService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_button.gif" id="de.bmotionstudio.gef.editor.button" name="Button" - service="de.bmotionstudio.gef.editor.service.BButtonService"> + service="de.bmotionstudio.gef.editor.model.service.BButtonService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_radiobutton_c.gif" id="de.bmotionstudio.gef.editor.radiobutton" name="Radiobutton" - service="de.bmotionstudio.gef.editor.service.BRadioButtonService"> + service="de.bmotionstudio.gef.editor.model.service.BRadioButtonService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_checked.gif" id="de.bmotionstudio.gef.editor.checkbox" name="Checkbox" - service="de.bmotionstudio.gef.editor.service.BCheckboxService"> + service="de.bmotionstudio.gef.editor.model.service.BCheckboxService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/eclipse16/overview_obj.gif" id="de.bmotionstudio.gef.editor.composite" name="Composite" - service="de.bmotionstudio.gef.editor.service.BCompositeService"> + service="de.bmotionstudio.gef.editor.model.service.BCompositeService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_text.gif" id="de.bmotionstudio.gef.editor.text" name="Text" - service="de.bmotionstudio.gef.editor.service.BTextService"> + service="de.bmotionstudio.gef.editor.model.service.BTextService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_textfield.gif" id="de.bmotionstudio.gef.editor.textfield" name="Textfield" - service="de.bmotionstudio.gef.editor.service.BTextfieldService"> + service="de.bmotionstudio.gef.editor.model.service.BTextfieldService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_rectangle.gif" id="de.bmotionstudio.gef.editor.rectangle" name="Rectanlge" - service="de.bmotionstudio.gef.editor.service.BRectangleService"> + service="de.bmotionstudio.gef.editor.model.service.BRectangleService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_ellipse.gif" id="de.bmotionstudio.gef.editor.ellipse" name="Ellipse" - service="de.bmotionstudio.gef.editor.service.BEllipseService"> + service="de.bmotionstudio.gef.editor.model.service.BEllipseService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_connection16.gif" id="de.bmotionstudio.gef.editor.connection" name="Connection" - service="de.bmotionstudio.gef.editor.service.BConnectionService"> + service="de.bmotionstudio.gef.editor.model.service.BConnectionService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/eclipse16/prop_ps.gif" id="de.bmotionstudio.gef.editor.table" name="Table" - service="de.bmotionstudio.gef.editor.service.BTableService"> + service="de.bmotionstudio.gef.editor.model.service.BTableService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/eclipse16/prop_ps2.gif" id="de.bmotionstudio.gef.editor.tablecolumn" name="Column" - service="de.bmotionstudio.gef.editor.service.BTableColumnService"> + service="de.bmotionstudio.gef.editor.model.service.BTableColumnService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/eclipse16/prop_ps3.gif" id="de.bmotionstudio.gef.editor.tablecell" name="Cell" - service="de.bmotionstudio.gef.editor.service.BTableCellService"> + service="de.bmotionstudio.gef.editor.model.service.BTableCellService"> </control> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/icon_signal.gif" id="de.bmotionstudio.gef.editor.signal" name="Signal" - service="de.bmotionstudio.gef.editor.service.SignalService"> + service="de.bmotionstudio.gef.editor.model.service.SignalService"> </control> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/eclipse16/smartmode_co.gif" id="de.bmotionstudio.gef.editor.light" name="Light" - service="de.bmotionstudio.gef.editor.service.LightService"> + service="de.bmotionstudio.gef.editor.model.service.LightService"> </control> + <group + id="de.bmotionstudio.gef.editor.industry.group" + name="Industry"> + </group> <control groupid="de.bmotionstudio.gef.editor.industry.group" icon="icons/icon_tank.gif" id="de.bmotionstudio.gef.editor.tank" name="Tank" - service="de.bmotionstudio.gef.editor.service.TankService"> + service="de.bmotionstudio.gef.editor.model.service.TankService"> </control> + <group + id="de.bmotionstudio.gef.editor.railway.group" + name="Railway"> + </group> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/icon_tracknode.gif" id="de.bmotionstudio.gef.editor.tracknode" name="Node" - service="de.bmotionstudio.gef.editor.service.TrackNodeService"> + service="de.bmotionstudio.gef.editor.model.service.TrackNodeService"> </control> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/icon_track.gif" id="de.bmotionstudio.gef.editor.track" name="Trac" - service="de.bmotionstudio.gef.editor.service.TrackService"> + service="de.bmotionstudio.gef.editor.model.service.TrackService"> </control> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/icon_switch.gif" id="de.bmotionstudio.gef.editor.switch" name="Switch" - service="de.bmotionstudio.gef.editor.service.SwitchService"> + service="de.bmotionstudio.gef.editor.model.service.SwitchService"> </control> - <group - id="de.bmotionstudio.gef.editor.railway.group" - name="Railway"> - </group> - <group - id="de.bmotionstudio.gef.editor.industry.group" - name="Industry"> - </group> </extension> <extension point="de.bmotionstudio.gef.editor.observer"> @@ -336,10 +340,6 @@ description="Observer for switching the coordinates of the control" name="Switch Coordinates"> </observer> - <observer - class="de.bmotionstudio.gef.editor.observer.ExternalObserverScript" - name="External Observer Script"> - </observer> <observer class="de.bmotionstudio.gef.editor.observer.TableObserver" name="Table Observer"> @@ -382,12 +382,6 @@ class="de.bmotionstudio.gef.editor.InstallMenu"> </menu> </extension> - <extension - point="de.bmotionstudio.gef.editor.registerImages"> - <registerImages - class="de.bmotionstudio.gef.editor.ImageRegistry"> - </registerImages> - </extension> <extension point="de.bmotionstudio.gef.editor.language"> <language diff --git a/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.control.exsd b/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.control.exsd index ce1f1677784cea86330b89864ecc79fc0eab3f6a..e35e7098e4b05024689df59e940cd48a108b2e91 100644 --- a/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.control.exsd +++ b/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.control.exsd @@ -18,7 +18,6 @@ </annotation> <complexType> <sequence minOccurs="0" maxOccurs="unbounded"> - <element ref="control" minOccurs="0" maxOccurs="1"/> <element ref="group" minOccurs="0" maxOccurs="1"/> <element ref="control" minOccurs="0" maxOccurs="1"/> </sequence> @@ -75,9 +74,6 @@ </appInfo> </annotation> <complexType> - <sequence> - <element ref="attributes" minOccurs="0" maxOccurs="1"/> - </sequence> <attribute name="id" type="string" use="required"> <annotation> <documentation> @@ -122,94 +118,30 @@ </complexType> </element> - <element name="attribute-string"> - <complexType> - <attribute name="id" type="string" use="required"> - <annotation> - <documentation> - The id of the referenced attribute. Since the same attribute could be assigned to different controls the corresponding attibute is defined in a seperate exention point (de.bmotionstudio.gef.editor.attribute). - </documentation> - </annotation> - </attribute> - <attribute name="default-value" type="string" use="required"> - <annotation> - <documentation> - The default value of this attribute for this control - </documentation> - </annotation> - </attribute> - <attribute name="editable" type="boolean" use="default" value="true"> - <annotation> - <documentation> - Boolean value - Option to decide whenever this attribute should be editable or not. - </documentation> - </annotation> - </attribute> - <attribute name="show" type="boolean" use="default" value="true"> - <annotation> - <documentation> - Boolean value - Option to decide whenever this attribute should be displayed in the properties view. - </documentation> - </annotation> - </attribute> - </complexType> - </element> - - <element name="attribute-java"> - <complexType> - <attribute name="id" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="default-value" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - <appInfo> - <meta.attribute kind="java" basedOn=":de.bmotionstudio.core.IGetDefaultValue"/> - </appInfo> - </annotation> - </attribute> - </complexType> - </element> - - <element name="attributes"> - <complexType> - <sequence> - <element ref="attribute-java" minOccurs="0" maxOccurs="unbounded"/> - <element ref="attribute-string" minOccurs="0" maxOccurs="unbounded"/> - </sequence> - </complexType> - </element> - <annotation> <appInfo> - <meta.section type="since"/> + <meta.section type="apiInfo"/> </appInfo> <documentation> - [Enter the first release in which this extension point appears.] + [Enter API information here.] </documentation> </annotation> <annotation> <appInfo> - <meta.section type="examples"/> + <meta.section type="since"/> </appInfo> <documentation> - [Enter extension point usage example here.] + [Enter the first release in which this extension point appears.] </documentation> </annotation> <annotation> <appInfo> - <meta.section type="apiInfo"/> + <meta.section type="examples"/> </appInfo> <documentation> - [Enter API information here.] + [Enter extension point usage example here.] </documentation> </annotation> diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMSContextMenuProvider.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMSContextMenuProvider.java index 9822355aa3049caf66bd4c8c764786da49fd4053..2dab8b07fcc578cbc9968ca985229b2536b55225 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMSContextMenuProvider.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMSContextMenuProvider.java @@ -25,7 +25,6 @@ import org.eclipse.ui.actions.ActionFactory; import de.bmotionstudio.gef.editor.action.OpenSchedulerEventAction; import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent; @@ -120,8 +119,6 @@ public class BMSContextMenuProvider extends ContextMenuProvider { if (model instanceof BControl) bcontrol = (BControl) model; - else if (model instanceof ObserverRootVirtualTreeNode) - bcontrol = ((ObserverRootVirtualTreeNode) model).getControl(); else return; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenObserverAction.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenObserverAction.java index 4ed52392ac795a04f75fad7fcda720ef926d3210..352e07a9d562a4e5c756458b55b1c9685741b7a4 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenObserverAction.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenObserverAction.java @@ -19,7 +19,6 @@ import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.command.RemoveObserverCommand; import de.bmotionstudio.gef.editor.command.SetObserverCommand; import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; import de.bmotionstudio.gef.editor.observer.Observer; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.prob.logging.Logger; @@ -172,10 +171,7 @@ public class OpenObserverAction extends SelectionAction { if ((objects.get(0) instanceof EditPart)) { EditPart part = (EditPart) objects.get(0); BControl control = null; - if (part.getModel() instanceof ObserverRootVirtualTreeNode) - control = ((ObserverRootVirtualTreeNode) part.getModel()) - .getControl(); - else if (part.getModel() instanceof BControl) + if (part.getModel() instanceof BControl) control = (BControl) part.getModel(); return control; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomCommand.java index 601e6bb35cf0c5c8e4a043a8544c2552dc27509b..16a668b4a38479700afe1151baac872be8af1c56 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomCommand.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.command; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; public class BringToBottomCommand extends AbstractBringToCommand { @@ -17,8 +18,8 @@ public class BringToBottomCommand extends AbstractBringToCommand { getOldIndexMap().put(control, oldIndex); parent.getChildrenArray().remove(control); parent.getChildrenArray().add(0, control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } @@ -28,8 +29,8 @@ public class BringToBottomCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(getOldIndexMap().get(control), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomStepCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomStepCommand.java index 7e5dff77861ab06ba45e5d306d4155c6bd0b54cf..f5bbb964961743c6278780f6722418212334f86d 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomStepCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomStepCommand.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.command; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; public class BringToBottomStepCommand extends AbstractBringToCommand { @@ -18,8 +19,9 @@ public class BringToBottomStepCommand extends AbstractBringToCommand { if (oldIndex > 0) { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(oldIndex - 1, control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, + null); } } } @@ -30,8 +32,8 @@ public class BringToBottomStepCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(getOldIndexMap().get(control), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopCommand.java index 716c1454a766ebf1e24f7d4ede5fa3dd79acccd9..c290043b3e2eb8df9d0c9354948cdc8681250e52 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopCommand.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.command; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; public class BringToTopCommand extends AbstractBringToCommand { @@ -18,8 +19,8 @@ public class BringToTopCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(parent.getChildrenArray().size(), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } @@ -29,8 +30,8 @@ public class BringToTopCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(getOldIndexMap().get(control), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopStepCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopStepCommand.java index 3560448e1c245684e4a599ef4f14f421f55a8069..805599aaac6c0ee0ac237a4e713e6ea191114729 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopStepCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopStepCommand.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.command; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; public class BringToTopStepCommand extends AbstractBringToCommand { @@ -18,8 +19,9 @@ public class BringToTopStepCommand extends AbstractBringToCommand { if (oldIndex < parent.getChildrenArray().size() - 1) { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(oldIndex + 1, control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, + null); } } } @@ -30,8 +32,8 @@ public class BringToTopStepCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(getOldIndexMap().get(control), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/SignalFigure.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/SignalFigure.java index 7e5752eb3dd61ce8e05543f1e93385539eccfd2c..052554a54b80675119080156d503d09a3fbb9d86 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/SignalFigure.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/SignalFigure.java @@ -84,7 +84,6 @@ public class SignalFigure extends AbstractBMotionFigure { p1.y = p1.y + 4; p2.y = p2.y + 8; - p3.y = p3.y; arrow.addPoint(p1); arrow.addPoint(p2); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/OpenWebsiteHandler.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/OpenWebsiteHandler.java similarity index 93% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/OpenWebsiteHandler.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/OpenWebsiteHandler.java index 500bb85d61ccf97fc90b8f6c132b8544f481fe34..9122b15e222de30d845fada8f4a41b35e265b4c1 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/OpenWebsiteHandler.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/OpenWebsiteHandler.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.internal; +package de.bmotionstudio.gef.editor.handler; import java.net.MalformedURLException; import java.net.URL; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationEditorHandler.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationEditorHandler.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationEditorHandler.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationEditorHandler.java index bda5ba1df2ffa63f35d858a5a86fc205ea6372ba..ebd89b02a01f24f608dc4c9c07d78650519e767e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationEditorHandler.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationEditorHandler.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.internal; +package de.bmotionstudio.gef.editor.handler; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -19,6 +19,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; +import de.bmotionstudio.gef.editor.internal.VisualizationProgressBar; import de.prob.core.Animator; import de.prob.logging.Logger; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationFileHandler.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationFileHandler.java similarity index 94% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationFileHandler.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationFileHandler.java index 2c9964a279dd5b4c08b830489ae060de8d64c7bf..945993e514a2dfa94a453379a0aa7c8fb502b4e9 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationFileHandler.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationFileHandler.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.internal; +package de.bmotionstudio.gef.editor.handler; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -30,6 +30,7 @@ import org.eclipse.ui.part.FileEditorInput; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; import de.bmotionstudio.gef.editor.BMotionStudioEditor; +import de.bmotionstudio.gef.editor.internal.VisualizationProgressBar; import de.prob.core.Animator; import de.prob.logging.Logger; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java index 4054bf990409224fb3e80c7652aaf57ec4abbeb5..70ee9ce5129299210a7d579009c6f02ab2dba118 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java @@ -113,9 +113,6 @@ public class VisualizationProgressBar extends ProgressBarDialog { openErrorDialog(e.getMessage()); setClose(true); } - return "Starting Operation Scheduler"; - case 6: - startOperationScheduler(); return "Starting Visualization"; } @@ -123,9 +120,9 @@ public class VisualizationProgressBar extends ProgressBarDialog { } - private void startOperationScheduler() { - visualization.startOperationScheduler(); - } + // private void startOperationScheduler() { + // visualization.startOperationScheduler(); + // } private void createVisualizationRoot() throws CoreException, IOException, ParserConfigurationException, SAXException { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java index 8013e19f754309e18837ec7c09f438c3eddba668..1d93f734a06479b0c4b5d1ab7281be37797aea78 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java @@ -16,8 +16,12 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; @@ -42,7 +46,6 @@ import de.bmotionstudio.gef.editor.attribute.BAttributeX; import de.bmotionstudio.gef.editor.attribute.BAttributeY; import de.bmotionstudio.gef.editor.command.CopyPasteHelper; import de.bmotionstudio.gef.editor.internal.BControlPropertySource; -import de.bmotionstudio.gef.editor.observer.IObserverListener; import de.bmotionstudio.gef.editor.observer.Observer; import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent; @@ -61,13 +64,8 @@ import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent; */ public abstract class BControl implements IAdaptable, Cloneable { - /** The type of the control (e.g. label, button ...) */ protected String type; - private transient Rectangle layout = null; - - private transient Point location = null; - private BControlList children; private Map<String, Observer> observers; @@ -76,45 +74,25 @@ public abstract class BControl implements IAdaptable, Cloneable { private Map<String, AbstractAttribute> attributes; - /** - * Since the parent is set via the method readResolve(), we mark the - * variable as transient - */ + private BMotionGuide verticalGuide, horizontalGuide; + + // List of outgoing Connections + private List<BConnection> sourceConnections; + // List of incoming Connections + private List<BConnection> targetConnections; + + private transient Rectangle layout = null; + + private transient Point location = null; + private transient BControl parent; private transient Visualization visualization; private transient PropertyChangeSupport listeners; - - private transient ArrayList<IObserverListener> observerListener; private transient boolean newControl; - private BMotionGuide verticalGuide, horizontalGuide; - - /** List of outgoing Connections. */ - private List<BConnection> sourceConnections; - /** List of incoming Connections. */ - private List<BConnection> targetConnections; - - public static final transient String PROPERTY_LAYOUT = "NodeLayout"; - public static final transient String PROPERTY_LOCATION = "NodeLocation"; - public static final transient String PROPERTY_ADD = "NodeAddChild"; - public static final transient String PROPERTY_REMOVE = "NodeRemoveChild"; - public static final transient String PROPERTY_RENAME = "NodeRename"; - /** Property ID to use when the list of outgoing connections is modified. */ - public static final String SOURCE_CONNECTIONS_PROP = "BMS.SourceConn"; - /** Property ID to use when the list of incoming connections is modified. */ - public static final String TARGET_CONNECTIONS_PROP = "BMS.TargetConn"; - - public static final String[] standardAttributes = { - AttributeConstants.ATTRIBUTE_X, - AttributeConstants.ATTRIBUTE_Y, AttributeConstants.ATTRIBUTE_WIDTH, - AttributeConstants.ATTRIBUTE_HEIGHT, - AttributeConstants.ATTRIBUTE_ID, - AttributeConstants.ATTRIBUTE_CUSTOM, - AttributeConstants.ATTRIBUTE_VISIBLE }; - public BControl(Visualization visualization) { this.visualization = visualization; this.children = new BControlList(); @@ -122,7 +100,6 @@ public abstract class BControl implements IAdaptable, Cloneable { this.events = new HashMap<String, SchedulerEvent>(); this.attributes = new HashMap<String, AbstractAttribute>(); this.listeners = new PropertyChangeSupport(this); - this.observerListener = new ArrayList<IObserverListener>(); this.sourceConnections = new ArrayList<BConnection>(); this.targetConnections = new ArrayList<BConnection>(); this.newControl = true; @@ -134,7 +111,6 @@ public abstract class BControl implements IAdaptable, Cloneable { for (BControl child : getChildrenArray()) child.setParent(this); this.newControl = false; - init(); return this; } @@ -152,12 +128,12 @@ public abstract class BControl implements IAdaptable, Cloneable { } if (conn.getSource() == this) { getSourceConnections().remove(conn); - getListeners().firePropertyChange(SOURCE_CONNECTIONS_PROP, null, - conn); + getListeners().firePropertyChange( + BControlPropertyConstants.SOURCE_CONNECTIONS, null, conn); } else if (conn.getTarget() == this) { getTargetConnections().remove(conn); - getListeners().firePropertyChange(TARGET_CONNECTIONS_PROP, null, - conn); + getListeners().firePropertyChange( + BControlPropertyConstants.TARGET_CONNECTIONS, null, conn); } } @@ -173,28 +149,76 @@ public abstract class BControl implements IAdaptable, Cloneable { if (conn == null || conn.getSource() == conn.getTarget()) { throw new IllegalArgumentException(); } - conn.setVisualization(getVisualization()); if (conn.getSource() == this) { getSourceConnections().add(conn); - getListeners().firePropertyChange(SOURCE_CONNECTIONS_PROP, null, - conn); + getListeners().firePropertyChange( + BControlPropertyConstants.SOURCE_CONNECTIONS, null, conn); } else if (conn.getTarget() == this) { getTargetConnections().add(conn); - getListeners().firePropertyChange(TARGET_CONNECTIONS_PROP, null, - conn); + getListeners().firePropertyChange( + BControlPropertyConstants.TARGET_CONNECTIONS, null, conn); } } - private void init() { - + protected void init() { // Init standard control attributes initStandardAttributes(); - // Init custom control attributes initAttributes(); } + private List<String> getSupportedObserverList() { + + List<String> supportedObserver = new ArrayList<String>(); + + IExtensionPoint extensionPoint = Platform.getExtensionRegistry() + .getExtensionPoint( + "de.bmotionstudio.gef.editor.includeObserver"); + + for (IExtension extension : extensionPoint.getExtensions()) { + for (IConfigurationElement configurationElement : extension + .getConfigurationElements()) { + + if ("include".equals(configurationElement.getName())) { + + String langID = configurationElement + .getAttribute("language"); + + if (langID != null + && langID.equals(getVisualization() + .getLanguage())) { + + for (IConfigurationElement configC : configurationElement + .getChildren("control")) { + + String cID = configC.getAttribute("id"); + + if (getType().equals(cID)) { + + for (IConfigurationElement configO : configC + .getChildren("observer")) { + + supportedObserver.add(configO + .getAttribute("id")); + + } + + } + + } + + } + + } + + } + } + + return supportedObserver; + + } + private void initStandardAttributes() { // Init unique ID @@ -328,7 +352,8 @@ public abstract class BControl implements IAdaptable, Cloneable { setAttributeValue(AttributeConstants.ATTRIBUTE_HEIGHT, newLayout.height, false); getListeners() - .firePropertyChange(PROPERTY_LAYOUT, oldLayout, newLayout); + .firePropertyChange(BControlPropertyConstants.PROPERTY_LAYOUT, + oldLayout, newLayout); } public Rectangle getLayout() { @@ -375,7 +400,8 @@ public abstract class BControl implements IAdaptable, Cloneable { location = newLocation; setAttributeValue(AttributeConstants.ATTRIBUTE_X, newLocation.x, false); setAttributeValue(AttributeConstants.ATTRIBUTE_Y, newLocation.y, false); - getListeners().firePropertyChange(PROPERTY_LOCATION, oldLocation, + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_LOCATION, oldLocation, newLocation); } @@ -412,12 +438,14 @@ public abstract class BControl implements IAdaptable, Cloneable { } else { children.add(child); } - getListeners().firePropertyChange(PROPERTY_ADD, index, child); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, index, child); } public void removeAllChildren() { getChildrenArray().clear(); - getListeners().firePropertyChange(PROPERTY_REMOVE, null, null); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_REMOVE_CHILD, null, null); } public boolean removeChild(int index) { @@ -428,7 +456,9 @@ public abstract class BControl implements IAdaptable, Cloneable { public boolean removeChild(BControl child) { boolean b = children.remove(child); if (b) - getListeners().firePropertyChange(PROPERTY_REMOVE, child, null); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_REMOVE_CHILD, child, + null); return b; } @@ -476,9 +506,10 @@ public abstract class BControl implements IAdaptable, Cloneable { public void addObserver(Observer observer) { observers.put(observer.getID(), (Observer) observer); - for (IObserverListener listener : getObserverListener()) { - listener.addedObserver(this, observer); - } + getListeners() + .firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_OBSERVER, + observer, null); } public void removeObserver(Observer observer) { @@ -486,11 +517,13 @@ public abstract class BControl implements IAdaptable, Cloneable { } public void removeObserver(String observerID) { - if (hasObserver(observerID)) - observers.get(observerID).beforeDelete(this); - observers.remove(observerID); - for (IObserverListener listener : getObserverListener()) { - listener.removedObserver(this); + Observer o = observers.remove(observerID); + if (o != null) { + o.beforeDelete(this); + getListeners() + .firePropertyChange( + BControlPropertyConstants.PROPERTY_REMOVE_OBSERVER, + o, null); } } @@ -512,12 +545,18 @@ public abstract class BControl implements IAdaptable, Cloneable { public void addEvent(String eventID, SchedulerEvent schedulerEvent) { events.put(eventID, schedulerEvent); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_EVENT, schedulerEvent, + null); } public void removeEvent(String eventID) { - if (hasEvent(eventID)) - events.get(eventID).beforeDelete(this); - events.remove(eventID); + SchedulerEvent e = events.remove(eventID); + if (e != null) { + e.beforeDelete(this); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_REMOVE_EVENT, e, null); + } } public Map<String, AbstractAttribute> getAttributes() { @@ -631,24 +670,12 @@ public abstract class BControl implements IAdaptable, Cloneable { this.visualization = visualization; } - protected void populateVisualization(Visualization visualization) { - // Populate visualization node - setVisualization(visualization); - for (BControl child : getChildrenArray()) - child.populateVisualization(visualization); - for (BConnection con : getTargetConnections()) - con.populateVisualization(visualization); - for (BConnection con : getSourceConnections()) - con.populateVisualization(visualization); - } - @Override public BControl clone() throws CloneNotSupportedException { BControl clonedControl = (BControl) super.clone(); clonedControl.listeners = new PropertyChangeSupport(clonedControl); - clonedControl.observerListener = new ArrayList<IObserverListener>(); clonedControl.sourceConnections = new ArrayList<BConnection>(); clonedControl.targetConnections = new ArrayList<BConnection>(); @@ -738,23 +765,6 @@ public abstract class BControl implements IAdaptable, Cloneable { return horizontalGuide; } - /** - * @return the observerListener - */ - public ArrayList<IObserverListener> getObserverListener() { - if (observerListener == null) - observerListener = new ArrayList<IObserverListener>(); - return observerListener; - } - - public void addObserverListener(IObserverListener listener) { - getObserverListener().add(listener); - } - - public void removeObserverListener(IObserverListener listener) { - getObserverListener().remove(listener); - } - /** * Return a List of outgoing Connections. */ diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControlPropertyConstants.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControlPropertyConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..40952b6d057a68266307bdffb359fee984ed3414 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControlPropertyConstants.java @@ -0,0 +1,29 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.model; + +public final class BControlPropertyConstants { + + public static final transient String PROPERTY_LAYOUT = "ControlLayout"; + public static final transient String PROPERTY_LOCATION = "ControlLocation"; + + public static final transient String PROPERTY_ADD_CHILD = "ControlAddChild"; + public static final transient String PROPERTY_REMOVE_CHILD = "ControlRemoveChild"; + + public static final transient String PROPERTY_ADD_OBSERVER = "ControlAddObserver"; + public static final transient String PROPERTY_REMOVE_OBSERVER = "ControlRemoveObserver"; + + public static final transient String PROPERTY_ADD_EVENT = "ControlAddEvent"; + public static final transient String PROPERTY_REMOVE_EVENT = "ControlRemoveEvent"; + + public static final transient String PROPERTY_RENAME = "ControlRename"; + /** Property ID to use when the list of outgoing connections is modified. */ + public static final transient String SOURCE_CONNECTIONS = "ControlSourceConn"; + /** Property ID to use when the list of incoming connections is modified. */ + public static final transient String TARGET_CONNECTIONS = "ControlTargetConn"; + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/ObserverRootVirtualTreeNode.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/ObserverRootVirtualTreeNode.java deleted file mode 100644 index 8562f648692ec3d27aa319bf66ce9aed15adb9cb..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/ObserverRootVirtualTreeNode.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.model; - -import java.util.Collection; - -import de.bmotionstudio.gef.editor.observer.Observer; - -public class ObserverRootVirtualTreeNode { - - private Collection<Observer> observer; - private BControl control; - - public ObserverRootVirtualTreeNode(BControl control) { - this.observer = control.getObservers().values(); - this.control = control; - } - - public Collection<Observer> getObserver() { - return observer; - } - - public BControl getControl() { - return control; - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java index 1de47b1b81c7c6e2a4d2a4ebfe2ce9a0a621f517..6aceebaa4cd1d5f66313b0a87137aaefcd8330fe 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java @@ -12,15 +12,8 @@ import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.draw2d.PositionConstants; -import de.be4.classicalb.core.parser.exceptions.BException; import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.ButtonGroupHelper; -import de.bmotionstudio.gef.editor.IAddErrorListener; -import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; -import de.prob.core.command.ExecuteOperationCommand; -import de.prob.core.command.GetOperationByPredicateCommand; -import de.prob.core.domainobjects.Operation; -import de.prob.exceptions.ProBException; public class Visualization extends BControl { @@ -46,12 +39,6 @@ public class Visualization extends BControl { private transient IFile projectFile; - private transient ArrayList<IAddErrorListener> errorListener; - - private transient Thread operationSchedulerThread; - - private ArrayList<PredicateOperation> schedulerOperations; - public Visualization(String bmachine, String language, String version) { super(null); setVisualization(this); @@ -59,7 +46,6 @@ public class Visualization extends BControl { this.bmachine = bmachine; this.language = language; this.version = version; - this.errorListener = new ArrayList<IAddErrorListener>(); this.isRunning = false; this.snapToGeometry = true; createRulers(); @@ -70,73 +56,28 @@ public class Visualization extends BControl { protected Object readResolve() { super.readResolve(); this.isRunning = false; - populateVisualization(this); createRulers(); - this.errorListener = new ArrayList<IAddErrorListener>(); ButtonGroupHelper.reset(); - // this.errorMessages = new ArrayList<ErrorMessage>(); - // setAttributeValue(AttributeConstants.ATTRIBUTE_ID, "surface", false); + setVisualization(this); + init(); + initChildren(getChildrenArray()); return this; } - public void startOperationScheduler() { - - if (!getSchedulerOperations().isEmpty()) { - - operationSchedulerThread = new Thread(new Runnable() { - public void run() { - while (true) { - - for (PredicateOperation p : getSchedulerOperations()) { - - if (animation.getCurrentStateOperation(p - .getOperationName()) != null) { - - try { - - String fpredicate = "1=1"; - - if (p.getPredicate().length() > 0) { - fpredicate = p.getPredicate(); - } - - Operation op = GetOperationByPredicateCommand - .getOperation(animation - .getAnimator(), animation - .getState().getId(), p - .getOperationName(), - fpredicate); - ExecuteOperationCommand.executeOperation( - animation.getAnimator(), op); - - } catch (ProBException e) { - break; - } catch (BException e) { - break; - } - - } - - } - - try { - Thread.sleep(500); - } catch (InterruptedException e) { - break; - } - - } - } - }); - operationSchedulerThread.start(); - + private void initChildren(List<BControl> children) { + for (BControl c : children) { + c.setVisualization(this); + c.init(); + for (BConnection sc : c.getSourceConnections()) { + sc.setVisualization(this); + sc.init(); + } + for (BConnection tc : c.getTargetConnections()) { + tc.setVisualization(this); + tc.init(); + } + initChildren(c.getChildrenArray()); } - - } - - public void stopOperationScheduler() { - if (operationSchedulerThread != null) - operationSchedulerThread.interrupt(); } public void setIsRunning(Boolean bol) { @@ -217,12 +158,7 @@ public class Visualization extends BControl { } } - // TODO: Reimplement me!!! public boolean checkIfIdExists(String ID) { - // if (getVariableList().hasEntry(ID) == true) - // return true; - // if (getConstantList().hasEntry(ID) == true) - // return true; return getAllBControlNames().contains(ID); } @@ -236,11 +172,11 @@ public class Visualization extends BControl { return control; } for (BConnection c : control.getSourceConnections()) { - if (c.getIcon().equals(ID)) + if (c.getID().equals(ID)) return c; } for (BConnection c : control.getTargetConnections()) { - if (c.getIcon().equals(ID)) + if (c.getID().equals(ID)) return c; } if (control.getChildrenArray().size() > 0) { @@ -317,25 +253,6 @@ public class Visualization extends BControl { return null; } - public void addErrorListener(IAddErrorListener listener) { - this.errorListener.add(listener); - } - - public void removeErrorListener(IAddErrorListener listener) { - this.errorListener.remove(listener); - } - - public void setSchedulerOperations( - ArrayList<PredicateOperation> schedulerOperations) { - this.schedulerOperations = schedulerOperations; - } - - public ArrayList<PredicateOperation> getSchedulerOperations() { - if (this.schedulerOperations == null) - this.schedulerOperations = new ArrayList<PredicateOperation>(); - return this.schedulerOperations; - } - public String getVersion() { return version; } @@ -358,4 +275,9 @@ public class Visualization extends BControl { return true; } + @Override + public Visualization getVisualization() { + return this; + } + } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BButtonService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BButtonService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BButtonService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BButtonService.java index e0b5b38b09a6429c1c2a66bdc71929c3d3a8abcd..e725497872ea5284faf8035fa7dbebc3e6fe1c9b 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BButtonService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BButtonService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCheckboxService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCheckboxService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCheckboxService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCheckboxService.java index dcaebcef01eac35993dd90a28542946e5bb9325e..116a6e6c81832d075d3d575040cf20adacd089ac 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCheckboxService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCheckboxService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCompositeService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCompositeService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCompositeService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCompositeService.java index 4a11b1d1c33fbcdecb4d0a06c05ca1115270a412..c9a899bdcece83f8b6b12b1085bb1c351ce5d569 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCompositeService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCompositeService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BConnectionService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BConnectionService.java similarity index 94% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BConnectionService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BConnectionService.java index 8c2c8e97317f5a65067764c37f9c72ec8b9e4cda..54fcc6bfa0ff7cfea37295e007e6c174a0f91590 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BConnectionService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BConnectionService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.gef.palette.ConnectionCreationToolEntry; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BEllipseService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BEllipseService.java similarity index 95% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BEllipseService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BEllipseService.java index ffaf7f7dceeebc27954799e4b6fbf7961a9171ee..12131e63d3fbaf0556d32ad804436a570d70232a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BEllipseService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BEllipseService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.AttributeConstants; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BImageService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BImageService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BImageService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BImageService.java index e70769ac275e2571a66cce4bc76a5518011b1c5d..c843bb524d2c81614848eeb5315d3666da1b544e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BImageService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BImageService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRadioButtonService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRadioButtonService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRadioButtonService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRadioButtonService.java index ae4b4250f88f47e70170eaef67dfd984d425af36..6092c7c7c4d1b8889a658e36f76a28881ec48cfe 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRadioButtonService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRadioButtonService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRectangleService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRectangleService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRectangleService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRectangleService.java index f29b430d7c111916fc541e1f804fab319b757262..1c18ae9da50ef58f254861fb7a02fb5828528b47 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRectangleService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRectangleService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableCellService.java similarity index 95% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableCellService.java index 38c27cbaf1e5a37e64e8d174a8a24c9964117e09..f9c21fafff49607a1639f09aa847617ecb5386e4 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableCellService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableColumnService.java similarity index 95% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableColumnService.java index 6290adc316a60ca35f9cff2883b2bfb4947d6b43..893f8344112e2a6115d8b9848ef2612e640be51e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableColumnService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableService.java similarity index 93% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableService.java index 67da1a6148b0f376502b36e0047ce42a98a36e70..e54ddd5de872a8868bebf6f1524f3c7e4ff4eb02 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextService.java index 77fcbaa39c22f72ab5fc3b3e70c13bbe32709245..6bf14bc403ca03eb36294d60f5389d744d6f86a3 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextfieldService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextfieldService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextfieldService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextfieldService.java index 694879b12b6db775ff764b93e24d10bdd8fe06a2..1b66a40c36158c7a1c569bdcd87a606254a9f72d 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextfieldService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextfieldService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/LightService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/LightService.java similarity index 93% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/LightService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/LightService.java index 84b8215550198df61c4f29f869381d83c2c34829..71ebf592f81beaad3bf45b07c5c50ecbac09bb59 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/LightService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/LightService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SignalService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SignalService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SignalService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SignalService.java index fd0c914a64001a7efa025c7575b4ebb135b3e5af..95dd51a686cedef9ccbd86bb376fe3421faf768a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SignalService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SignalService.java @@ -3,7 +3,7 @@ * Heinrich Heine Universitaet Duesseldorf * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SwitchService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SwitchService.java similarity index 91% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SwitchService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SwitchService.java index a4b441ea9c245575cb08e9a7e005f49bc3042016..bb4c4850ea30bb529021a688dc71174aa7af4b24 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SwitchService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SwitchService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TankService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TankService.java similarity index 91% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TankService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TankService.java index cc28f1eee33f501553c80c75fb73f39038c9c9c4..80c1a38cd19221bd8e0e48a071cc89af377b451f 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TankService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TankService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackNodeService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackNodeService.java similarity index 91% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackNodeService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackNodeService.java index d3b12c90a0e77b55080a024aa620e74293abdc7e..c01bcaa080339ca1934876ae7026a88f039aeb9c 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackNodeService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackNodeService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackService.java similarity index 94% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackService.java index 4b90a844cd2925a2ae1411f24bed3edd59c72812..ccd221193739c9280e3d368dd917f3ed8d3cfb4b 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.gef.palette.ConnectionCreationToolEntry; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverCSwitchCoordinates.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverCSwitchCoordinates.java index 3a5b8b09e05c56eb8d139898c317cb86ac5caddb..d03fa3f9aa13d32d0b6efb38bfb3319bb3474b01 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverCSwitchCoordinates.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverCSwitchCoordinates.java @@ -13,12 +13,10 @@ import org.eclipse.core.databinding.observable.map.IObservableMap; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; @@ -36,7 +34,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import de.be4.classicalb.core.parser.BParser; -import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.EditorImageRegistry; @@ -44,7 +41,6 @@ import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.edit.TextEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates; import de.bmotionstudio.gef.editor.observer.ToggleObjectCoordinates; @@ -52,7 +48,7 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardObserverCSwitchCoordinates extends ObserverWizard { - private String lastChangedControlID; + // private String lastChangedControlID; private class ObserverCSwitchCoordinatesPage extends AbstractObserverWizardPage { @@ -75,40 +71,42 @@ public class WizardObserverCSwitchCoordinates extends ObserverWizard { tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( container, ToggleObjectCoordinates.class, ((BMotionAbstractWizard) getWizard()).getName()); - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - restorePreview(); - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - if (!observerEvalObject.isExpressionMode()) { - BControl control = getBControl(); - ToggleObjectCoordinates toggleObjectCoordinates = (ToggleObjectCoordinates) observerEvalObject; - String attributeX = AttributeConstants.ATTRIBUTE_X; - String attributeY = AttributeConstants.ATTRIBUTE_Y; - String x = toggleObjectCoordinates.getX(); - String y = toggleObjectCoordinates.getY(); - String controlID = toggleObjectCoordinates - .getBcontrol(); - BControl bControl = control - .getChild(controlID); - if (bControl != null) { - bControl.setAttributeValue(attributeX, - x, true, false); - bControl.setAttributeValue(attributeY, - y, true, false); - } - lastChangedControlID = controlID; - } - } - } - - }); + // tableViewer + // .addSelectionChangedListener(new ISelectionChangedListener() { + // + // @Override + // public void selectionChanged(SelectionChangedEvent event) { + // IStructuredSelection selection = (IStructuredSelection) event + // .getSelection(); + // Object firstElement = selection.getFirstElement(); + // if (firstElement instanceof ObserverEvalObject) { + // restorePreview(); + // ObserverEvalObject observerEvalObject = (ObserverEvalObject) + // firstElement; + // if (!observerEvalObject.isExpressionMode()) { + // BControl control = getBControl(); + // ToggleObjectCoordinates toggleObjectCoordinates = + // (ToggleObjectCoordinates) observerEvalObject; + // String attributeX = AttributeConstants.ATTRIBUTE_X; + // String attributeY = AttributeConstants.ATTRIBUTE_Y; + // String x = toggleObjectCoordinates.getX(); + // String y = toggleObjectCoordinates.getY(); + // String controlID = toggleObjectCoordinates + // .getBcontrol(); + // BControl bControl = control + // .getChild(controlID); + // if (bControl != null) { + // bControl.setAttributeValue(attributeX, + // x, true, false); + // bControl.setAttributeValue(attributeY, + // y, true, false); + // } + // lastChangedControlID = controlID; + // } + // } + // } + // + // }); TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); @@ -229,7 +227,7 @@ public class WizardObserverCSwitchCoordinates extends ObserverWizard { @Override protected Boolean prepareToFinish() { - restorePreview(); + // restorePreview(); if (((SwitchChildCoordinates) getObserver()).getToggleObjects().size() == 0) { setObserverDelete(true); } else { @@ -247,19 +245,19 @@ public class WizardObserverCSwitchCoordinates extends ObserverWizard { return true; } - private void restorePreview() { - if (lastChangedControlID != null) { - BControl bControl = getBControl().getChild(lastChangedControlID); - if (bControl != null) { - bControl.restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); - bControl.restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); - } - } - } + // private void restorePreview() { + // if (lastChangedControlID != null) { + // BControl bControl = getBControl().getChild(lastChangedControlID); + // if (bControl != null) { + // bControl.restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); + // bControl.restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); + // } + // } + // } @Override public boolean performCancel() { - restorePreview(); + // restorePreview(); return super.performCancel(); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverListenOperationByPredicate.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverListenOperationByPredicate.java index 856cd5a2e88267505c1a347a7bea6059713752a7..5369bc5cc1f4a17b9347fd5722a6336c94c10412 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverListenOperationByPredicate.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverListenOperationByPredicate.java @@ -20,13 +20,11 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -57,7 +55,6 @@ import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.property.CheckboxCellEditorHelper; import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; @@ -65,7 +62,7 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardObserverListenOperationByPredicate extends ObserverWizard { - private String lastChangedAttributeID; + // private String lastChangedAttributeID; private class ObserverListenOperationByPredicatePage extends AbstractObserverWizardPage { @@ -90,39 +87,40 @@ public class WizardObserverListenOperationByPredicate extends ObserverWizard { tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( container, PredicateOperation.class, ((BMotionAbstractWizard) getWizard()).getName()); - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - BControl control = getBControl(); - - if (lastChangedAttributeID != null) - control.restoreDefaultValue(lastChangedAttributeID); - - PredicateOperation obj = (PredicateOperation) observerEvalObject; - - if (!obj.isExpressionMode()) { - - String attribute = obj.getAttribute(); - Object value = obj.getValue(); - control.setAttributeValue(attribute, value, - true, false); - - lastChangedAttributeID = attribute; - - } - - } - } - - }); + // tableViewer + // .addSelectionChangedListener(new ISelectionChangedListener() { + // + // @Override + // public void selectionChanged(SelectionChangedEvent event) { + // IStructuredSelection selection = (IStructuredSelection) event + // .getSelection(); + // Object firstElement = selection.getFirstElement(); + // if (firstElement instanceof ObserverEvalObject) { + // + // ObserverEvalObject observerEvalObject = (ObserverEvalObject) + // firstElement; + // BControl control = getBControl(); + // + // if (lastChangedAttributeID != null) + // control.restoreDefaultValue(lastChangedAttributeID); + // + // PredicateOperation obj = (PredicateOperation) observerEvalObject; + // + // if (!obj.isExpressionMode()) { + // + // String attribute = obj.getAttribute(); + // Object value = obj.getValue(); + // control.setAttributeValue(attribute, value, + // true, false); + // + // lastChangedAttributeID = attribute; + // + // } + // + // } + // } + // + // }); TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); @@ -357,13 +355,13 @@ public class WizardObserverListenOperationByPredicate extends ObserverWizard { @Override public boolean performCancel() { - getBControl().restoreDefaultValue(lastChangedAttributeID); + // getBControl().restoreDefaultValue(lastChangedAttributeID); return super.performCancel(); } @Override protected Boolean prepareToFinish() { - getBControl().restoreDefaultValue(lastChangedAttributeID); + // getBControl().restoreDefaultValue(lastChangedAttributeID); if (((ListenOperationByPredicate) getObserver()).getList().size() == 0) { setObserverDelete(true); } else { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSetAttribute.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSetAttribute.java index 8817a572855ba8271c20bf61bd52d3ada2bcc0f4..be6162187aec2fd33695432d7f0d999fc13e677c 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSetAttribute.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSetAttribute.java @@ -19,13 +19,11 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -56,7 +54,6 @@ import de.bmotionstudio.gef.editor.edit.IsExpressionModeEditingSupport; import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.SetAttribute; import de.bmotionstudio.gef.editor.observer.SetAttributeObject; @@ -65,7 +62,7 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardObserverSetAttribute extends ObserverWizard { - private String lastChangedAttributeID; + // private String lastChangedAttributeID; private class WizardSetAttributePage extends AbstractObserverWizardPage { @@ -96,40 +93,42 @@ public class WizardObserverSetAttribute extends ObserverWizard { container, SetAttributeObject.class, ((BMotionAbstractWizard) getWizard()).getName()); - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - BControl control = getBControl(); - - if (lastChangedAttributeID != null) - control.restoreDefaultValue(lastChangedAttributeID); - - SetAttributeObject setAttributeObj = (SetAttributeObject) observerEvalObject; - - if (!setAttributeObj.isExpressionMode()) { - - String attribute = setAttributeObj - .getAttribute(); - Object value = setAttributeObj.getValue(); - control.setAttributeValue(attribute, value, - true, false); - - lastChangedAttributeID = attribute; - - } - - } - } - - }); + // tableViewer + // .addSelectionChangedListener(new ISelectionChangedListener() { + // + // @Override + // public void selectionChanged(SelectionChangedEvent event) { + // IStructuredSelection selection = (IStructuredSelection) event + // .getSelection(); + // Object firstElement = selection.getFirstElement(); + // if (firstElement instanceof ObserverEvalObject) { + // + // ObserverEvalObject observerEvalObject = (ObserverEvalObject) + // firstElement; + // BControl control = getBControl(); + // + // if (lastChangedAttributeID != null) + // control.restoreDefaultValue(lastChangedAttributeID); + // + // SetAttributeObject setAttributeObj = (SetAttributeObject) + // observerEvalObject; + // + // if (!setAttributeObj.isExpressionMode()) { + // + // String attribute = setAttributeObj + // .getAttribute(); + // Object value = setAttributeObj.getValue(); + // control.setAttributeValue(attribute, value, + // true, false); + // + // lastChangedAttributeID = attribute; + // + // } + // + // } + // } + // + // }); TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); @@ -321,7 +320,7 @@ public class WizardObserverSetAttribute extends ObserverWizard { @Override protected Boolean prepareToFinish() { - getBControl().restoreDefaultValue(lastChangedAttributeID); + // getBControl().restoreDefaultValue(lastChangedAttributeID); if (((SetAttribute) getObserver()).getSetAttributeObjects().size() == 0) { setObserverDelete(true); } else { @@ -340,7 +339,7 @@ public class WizardObserverSetAttribute extends ObserverWizard { @Override public boolean performCancel() { - getBControl().restoreDefaultValue(lastChangedAttributeID); + // getBControl().restoreDefaultValue(lastChangedAttributeID); return super.performCancel(); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchCoordinates.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchCoordinates.java index 14cd883a29fec574490b3605aa5ae24d8c572e5d..88248dcb8a2870351498906122aa15234c3fad4b 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchCoordinates.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchCoordinates.java @@ -13,12 +13,10 @@ import org.eclipse.core.databinding.observable.map.IObservableMap; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -37,7 +35,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import de.be4.classicalb.core.parser.BParser; -import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.EditorImageRegistry; @@ -45,7 +42,6 @@ import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.edit.TextEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.SwitchCoordinates; import de.bmotionstudio.gef.editor.observer.ToggleObjectCoordinates; @@ -75,32 +71,34 @@ public class WizardObserverSwitchCoordinates extends ObserverWizard { container, ToggleObjectCoordinates.class, ((BMotionAbstractWizard) getWizard()).getName()); - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - if (!observerEvalObject.isExpressionMode()) { - BControl control = getBControl(); - ToggleObjectCoordinates toggleObjectCoordinates = (ToggleObjectCoordinates) observerEvalObject; - String attributeX = AttributeConstants.ATTRIBUTE_X; - String attributeY = AttributeConstants.ATTRIBUTE_Y; - String x = toggleObjectCoordinates.getX(); - String y = toggleObjectCoordinates.getY(); - control.setAttributeValue(attributeX, x, - true, false); - control.setAttributeValue(attributeY, y, - true, false); - } - } - } - - }); + // tableViewer + // .addSelectionChangedListener(new ISelectionChangedListener() { + // + // @Override + // public void selectionChanged(SelectionChangedEvent event) { + // IStructuredSelection selection = (IStructuredSelection) event + // .getSelection(); + // Object firstElement = selection.getFirstElement(); + // if (firstElement instanceof ObserverEvalObject) { + // ObserverEvalObject observerEvalObject = (ObserverEvalObject) + // firstElement; + // if (!observerEvalObject.isExpressionMode()) { + // BControl control = getBControl(); + // ToggleObjectCoordinates toggleObjectCoordinates = + // (ToggleObjectCoordinates) observerEvalObject; + // String attributeX = AttributeConstants.ATTRIBUTE_X; + // String attributeY = AttributeConstants.ATTRIBUTE_Y; + // String x = toggleObjectCoordinates.getX(); + // String y = toggleObjectCoordinates.getY(); + // control.setAttributeValue(attributeX, x, + // true, false); + // control.setAttributeValue(attributeY, y, + // true, false); + // } + // } + // } + // + // }); TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); @@ -217,8 +215,8 @@ public class WizardObserverSwitchCoordinates extends ObserverWizard { @Override protected Boolean prepareToFinish() { - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); + // getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); + // getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); if (((SwitchCoordinates) getObserver()).getToggleObjects().size() == 0) { setObserverDelete(true); } else { @@ -237,8 +235,8 @@ public class WizardObserverSwitchCoordinates extends ObserverWizard { @Override public boolean performCancel() { - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); + // getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); + // getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); return super.performCancel(); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchImage.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchImage.java index 40c1dd154d70fe6e4f9a2bfd24ecfa17a58b5c58..9c15caea177633be286db950970287681dfcd9d3 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchImage.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchImage.java @@ -13,12 +13,10 @@ import org.eclipse.core.databinding.observable.map.IObservableMap; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -46,7 +44,6 @@ import de.bmotionstudio.gef.editor.edit.IsExpressionModeEditingSupport; import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.SwitchImage; import de.bmotionstudio.gef.editor.observer.ToggleObjectImage; @@ -75,28 +72,30 @@ public class WizardObserverSwitchImage extends ObserverWizard { tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( container, ToggleObjectImage.class, ((BMotionAbstractWizard) getWizard()).getName()); - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - if (!observerEvalObject.isExpressionMode()) { - BControl control = getBControl(); - ToggleObjectImage toggleObjImage = (ToggleObjectImage) observerEvalObject; - String attribute = AttributeConstants.ATTRIBUTE_IMAGE; - String image = toggleObjImage.getImage(); - control.setAttributeValue(attribute, image, - true, false); - } - } - } - - }); + // tableViewer + // .addSelectionChangedListener(new ISelectionChangedListener() { + // + // @Override + // public void selectionChanged(SelectionChangedEvent event) { + // IStructuredSelection selection = (IStructuredSelection) event + // .getSelection(); + // Object firstElement = selection.getFirstElement(); + // if (firstElement instanceof ObserverEvalObject) { + // ObserverEvalObject observerEvalObject = (ObserverEvalObject) + // firstElement; + // if (!observerEvalObject.isExpressionMode()) { + // BControl control = getBControl(); + // ToggleObjectImage toggleObjImage = (ToggleObjectImage) + // observerEvalObject; + // String attribute = AttributeConstants.ATTRIBUTE_IMAGE; + // String image = toggleObjImage.getImage(); + // control.setAttributeValue(attribute, image, + // true, false); + // } + // } + // } + // + // }); TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); @@ -203,7 +202,7 @@ public class WizardObserverSwitchImage extends ObserverWizard { @Override protected Boolean prepareToFinish() { - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_IMAGE); + // getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_IMAGE); if (((SwitchImage) getObserver()).getToggleObjects().size() == 0) { setObserverDelete(true); } else { @@ -222,7 +221,7 @@ public class WizardObserverSwitchImage extends ObserverWizard { @Override public boolean performCancel() { - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_IMAGE); + // getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_IMAGE); return super.performCancel(); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java index 6adcbe067053f1a1f209c8e7887019dec0cbef8f..21bc714c14173d8826e437f95eaa88c2dba7907e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java @@ -25,7 +25,7 @@ import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.editpolicy.BMSDeletePolicy; import de.bmotionstudio.gef.editor.model.BConnection; import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.observer.IObserverListener; import de.bmotionstudio.gef.editor.observer.Observer; @@ -34,8 +34,10 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements PropertyChangeListener, IObserverListener { public void propertyChange(final PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(BControl.PROPERTY_ADD) - || evt.getPropertyName().equals(BControl.PROPERTY_REMOVE)) { + if (evt.getPropertyName().equals( + BControlPropertyConstants.PROPERTY_ADD_CHILD) + || evt.getPropertyName().equals( + BControlPropertyConstants.PROPERTY_REMOVE_CHILD)) { refreshChildren(); } refreshVisuals(); @@ -74,8 +76,8 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements } } - if (!(getModel() instanceof Visualization)) - toShowElements.add(new ObserverRootVirtualTreeNode(c)); + // if (!(getModel() instanceof Visualization)) + // toShowElements.add(new ObserverRootVirtualTreeNode(c)); } @@ -87,7 +89,7 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements if (!isActive()) { super.activate(); ((BControl) getModel()).addPropertyChangeListener(this); - ((BControl) getModel()).addObserverListener(this); + // ((BControl) getModel()).addObserverListener(this); } } @@ -95,7 +97,7 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements if (isActive()) { super.deactivate(); ((BControl) getModel()).removePropertyChangeListener(this); - ((BControl) getModel()).removeObserverListener(this); + // ((BControl) getModel()).removeObserverListener(this); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSAbstractEditPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSAbstractEditPart.java index 90de631cfaa0f809698aefb6057e6922cfab1b02..c53ed10fb104fc3d4f36b646b3c4129803650026 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSAbstractEditPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSAbstractEditPart.java @@ -43,6 +43,7 @@ import de.bmotionstudio.gef.editor.figure.AbstractBMotionFigure; import de.bmotionstudio.gef.editor.library.AbstractLibraryCommand; import de.bmotionstudio.gef.editor.library.AttributeRequest; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.observer.IObserverListener; import de.bmotionstudio.gef.editor.observer.Observer; @@ -73,8 +74,10 @@ public abstract class BMSAbstractEditPart extends AbstractGraphicalEditPart } }; - private String[] layoutAttributes = { BControl.PROPERTY_LAYOUT, - BControl.PROPERTY_LOCATION, AttributeConstants.ATTRIBUTE_X, + private String[] layoutAttributes = { + BControlPropertyConstants.PROPERTY_LAYOUT, + BControlPropertyConstants.PROPERTY_LOCATION, + AttributeConstants.ATTRIBUTE_X, AttributeConstants.ATTRIBUTE_Y, AttributeConstants.ATTRIBUTE_WIDTH, AttributeConstants.ATTRIBUTE_HEIGHT }; @@ -82,7 +85,6 @@ public abstract class BMSAbstractEditPart extends AbstractGraphicalEditPart if (!isActive()) { super.activate(); ((BControl) getModel()).addPropertyChangeListener(this); - ((BControl) getModel()).addObserverListener(this); if (getFigure() instanceof AbstractBMotionFigure) { AbstractBMotionFigure af = (AbstractBMotionFigure) getFigure(); if (isRunning()) @@ -96,7 +98,6 @@ public abstract class BMSAbstractEditPart extends AbstractGraphicalEditPart if (isActive()) { super.deactivate(); ((BControl) getModel()).removePropertyChangeListener(this); - ((BControl) getModel()).removeObserverListener(this); if (getFigure() instanceof AbstractBMotionFigure) { AbstractBMotionFigure af = (AbstractBMotionFigure) getFigure(); if (isRunning()) @@ -187,13 +188,15 @@ public abstract class BMSAbstractEditPart extends AbstractGraphicalEditPart final BControl model = (BControl) getModel(); String propName = evt.getPropertyName(); - if (BControl.SOURCE_CONNECTIONS_PROP.equals(propName)) { + if (BControlPropertyConstants.SOURCE_CONNECTIONS.equals(propName)) { refreshSourceConnections(); - } else if (BControl.TARGET_CONNECTIONS_PROP.equals(propName)) { + } else if (BControlPropertyConstants.TARGET_CONNECTIONS + .equals(propName)) { refreshTargetConnections(); } - if (propName.equals(BControl.PROPERTY_ADD) - || propName.equals(BControl.PROPERTY_REMOVE)) { + if (propName.equals(BControlPropertyConstants.PROPERTY_ADD_CHILD) + || propName + .equals(BControlPropertyConstants.PROPERTY_REMOVE_CHILD)) { refreshChildren(); } else if (Arrays.asList(layoutAttributes).contains(propName)) { // Layout attribute diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java index 7744514400fbe32a45c0e522d0a84166d8804f3b..93336446419897fa1b4daac4bcc009057612fcdc 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java @@ -14,9 +14,7 @@ import org.eclipse.gef.EditPartFactory; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; import de.bmotionstudio.gef.editor.IBControlService; import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; import de.bmotionstudio.gef.editor.model.Visualization; -import de.bmotionstudio.gef.editor.observer.Observer; public class BMSTreeEditPartFactory implements EditPartFactory { @@ -43,11 +41,12 @@ public class BMSTreeEditPartFactory implements EditPartFactory { e.printStackTrace(); } - } else if (model instanceof Observer) { - part = new ObserverTreeEditPart(); - } else if (model instanceof ObserverRootVirtualTreeNode) { - part = new ObserverRootTreeEditpart(); } + // else if (model instanceof Observer) { + // part = new ObserverTreeEditPart(); + // } else if (model instanceof ObserverRootVirtualTreeNode) { + // part = new ObserverRootTreeEditpart(); + // } if (part != null) part.setModel(model); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/ObserverRootTreeEditpart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/ObserverRootTreeEditpart.java deleted file mode 100644 index fd70efd9d5462ae343e734f5806cd167851ff937..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/ObserverRootTreeEditpart.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.part; - -import java.util.ArrayList; -import java.util.List; - -import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.EditorImageRegistry; -import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; -import de.bmotionstudio.gef.editor.observer.IObserverListener; -import de.bmotionstudio.gef.editor.observer.Observer; - -public class ObserverRootTreeEditpart extends BMSAbstractTreeEditPart implements - IObserverListener { - - public void activate() { - if (!isActive()) { - super.activate(); - ((ObserverRootVirtualTreeNode) getModel()).getControl() - .addObserverListener(this); - } - } - - public void deactivate() { - if (isActive()) { - super.deactivate(); - ((ObserverRootVirtualTreeNode) getModel()).getControl() - .removeObserverListener(this); - } - } - - @Override - protected List<Object> getModelChildren() { - ObserverRootVirtualTreeNode model = (ObserverRootVirtualTreeNode) getModel(); - return new ArrayList<Object>(model.getObserver()); - } - - @Override - public void refreshVisuals() { - setWidgetText("Observer"); - setWidgetImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_OBSERVER)); - } - - @Override - public void addedObserver(BControl control, Observer observer) { - refreshChildren(); - } - - @Override - public void removedObserver(BControl control) { - refreshChildren(); - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicateMulti.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicateMulti.java index eb2b2c88cd131ae74a22c58507c38db5f2564beb..6f9b9044c4fc87feb207c2ff6f15b5ec5cd917f1 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicateMulti.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicateMulti.java @@ -27,7 +27,7 @@ public class ExecuteOperationByPredicateMulti extends SchedulerEvent { String executePredicate = ((PredicateOperation) op) .getExecutePredicate(); - if (executePredicate.length() > 0) { + if (executePredicate != null && executePredicate.length() > 0) { bolValue = BMSUtil.parsePredicate(executePredicate, control, animation); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/ObserverCallBackDialog.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/ObserverCallBackDialog.java deleted file mode 100644 index 568c5f0922ff44ead8f3173c40249ec7e669bf41..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/ObserverCallBackDialog.java +++ /dev/null @@ -1,335 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.scheduler.wizard; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.list.ComputedList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.EditorImageRegistry; -import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.scheduler.AnimationScriptStep; -import de.bmotionstudio.gef.editor.scheduler.ObserverCallBackObject; - -@Deprecated -public class ObserverCallBackDialog extends Dialog { - - private TableViewer tableViewer; - - private final AnimationScriptStep animationScriptStep; - - private final BControl control; - - // private IObservableValue controlObservable; - - public ObserverCallBackDialog(final Shell parentShell, - final AnimationScriptStep animationScriptStep, - final BControl control) { - super(parentShell); - this.animationScriptStep = animationScriptStep; - this.control = control; - } - - @Override - protected Control createDialogArea(final Composite parent) { - - // DataBindingContext dbc = new DataBindingContext(); - - Composite container = (Composite) super.createDialogArea(parent); - container.setLayout(new GridLayout(1, true)); - - tableViewer = new TableViewer(container, SWT.BORDER - | SWT.FULL_SELECTION); - tableViewer.getTable().setLinesVisible(true); - tableViewer.getTable().setHeaderVisible(true); - tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); - tableViewer.getTable().setFont( - new Font(Display.getDefault(), new FontData("Arial", 10, - SWT.NONE))); - - TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Control"); - column.getColumn().setWidth(225); - column.setEditingSupport(new ControlValueEditing(tableViewer, control)); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Observer"); - column.getColumn().setWidth(150); - // column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, - // "observerID")); - column.setEditingSupport(new ObserverValueEditing(tableViewer, control)); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - tableViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), new String[] { - "control", "observerID" })) { - - @Override - public String getColumnText(final Object element, - final int columnIndex) { - if (columnIndex == 0) { - - ObserverCallBackObject obj = (ObserverCallBackObject) element; - - if (obj.getControl() != null) { - return obj.getControl().getID(); - } - } - return super.getColumnText(element, columnIndex); - } - - @Override - public Image getColumnImage(final Object element, - final int columnIndex) { - return null; - } - - }); - - final WritableList input = new WritableList( - animationScriptStep.getCallBackList(), - ObserverCallBackObject.class); - - tableViewer.setInput(input); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(final SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - return; - } - ObserverCallBackObject obj = (ObserverCallBackObject) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(obj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_ADD)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(final SelectionEvent e) { - ObserverCallBackObject obj = new ObserverCallBackObject(); - input.add(obj); - } - }); - - return container; - - } - - @Override - protected Point getInitialSize() { - return new Point(600, 500); - } - - @Override - protected void okPressed() { - close(); - } - - @Override - protected void configureShell(final Shell newShell) { - super.configureShell(newShell); - newShell.setText("BMotion Studio - Observer Callback Editor"); - } - - private class ControlValueEditing extends EditingSupport { - - private ComboBoxViewerCellEditor cellEditor = null; - - private final BControl control; - - public ControlValueEditing(final TableViewer cv, final BControl control) { - super(cv); - this.control = control; - } - - @Override - protected boolean canEdit(final Object element) { - return true; - } - - @Override - protected Object getValue(final Object element) { - if (((ObserverCallBackObject) element).getControl() != null) { - return ((ObserverCallBackObject) element).getControl().getID(); - } else { - return ""; - } - } - - @Override - protected void setValue(final Object element, final Object value) { - if (value != null) { - ((ObserverCallBackObject) element).setControl(control - .getVisualization().getBControl(value.toString())); - } - } - - @Override - protected CellEditor getCellEditor(final Object element) { - if (cellEditor == null) { - cellEditor = new ComboBoxViewerCellEditor( - (Composite) getViewer().getControl(), SWT.READ_ONLY); - cellEditor - .setContenProvider(new ObservableListContentProvider()); - cellEditor.setInput(new ComputedList() { - @Override - protected List<String> calculate() { - ArrayList<String> tmpList = new ArrayList<String>(); - for (String controlID : control.getVisualization() - .getAllBControlIDs()) { - tmpList.add(controlID); - } - return tmpList; - } - }); - ((CCombo) cellEditor.getControl()) - .addFocusListener(new FocusListener() { - - String oldValue; - - public void focusGained(final FocusEvent e) { - oldValue = ((CCombo) cellEditor.getControl()) - .getText(); - - } - - public void focusLost(final FocusEvent e) { - - if (!oldValue.equals(((CCombo) cellEditor - .getControl()).getText())) { - - IStructuredSelection selection = (IStructuredSelection) getViewer() - .getSelection(); - - ObserverCallBackObject obj = (ObserverCallBackObject) selection - .getFirstElement(); - obj.setObserverID(""); - tableViewer.refresh(); - - } - } - - }); - } - return cellEditor; - } - } - - private static class ObserverValueEditing extends EditingSupport { - - private ComboBoxViewerCellEditor cellEditor = null; - - // private final BControl control; - - public ObserverValueEditing(final TableViewer cv, final BControl control) { - super(cv); - // this.control = control; - } - - @Override - protected boolean canEdit(final Object element) { - return true; - } - - @Override - protected Object getValue(final Object element) { - if (((ObserverCallBackObject) element).getObserverID() != null) { - return ((ObserverCallBackObject) element).getObserverID(); - } else { - return ""; - } - } - - @Override - protected void setValue(final Object element, final Object value) { - if (value != null) { - ((ObserverCallBackObject) element).setObserverID(value - .toString()); - } - } - - @Override - protected CellEditor getCellEditor(final Object element) { - - if (cellEditor == null) { - cellEditor = new ComboBoxViewerCellEditor( - (Composite) getViewer().getControl(), SWT.READ_ONLY); - cellEditor - .setContenProvider(new ObservableListContentProvider()); - } - // cellEditor.setInput(new ComputedList() { - // @Override - // protected List<String> calculate() { - // - // ArrayList<String> tmpList = new ArrayList<String>(); - // - // ObserverCallBackObject obj = (ObserverCallBackObject) element; - // BControl control = obj.getControl(); - // if (control != null) { - // - // for (String id : control.getObservers().keySet()) { - // tmpList.add(id); - // } - // - // } - // - // return tmpList; - // - // } - // }); - - return cellEditor; - } - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/BMotionWizardUtil.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/BMotionWizardUtil.java index b2c4fa4123b2b707b4fe0898e2a2909ecbb8c488..6a82f2279dc2e3268589da2bd38cbd9fea9f85ea 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/BMotionWizardUtil.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/BMotionWizardUtil.java @@ -17,7 +17,6 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.TableItem; -import de.bmotionstudio.gef.editor.BMotionStudioSWTConstants; import de.bmotionstudio.gef.editor.action.BMotionWizardAddItemAction; import de.bmotionstudio.gef.editor.action.BMotionWizardDeleteItemsAction; import de.bmotionstudio.gef.editor.library.AttributeTransfer; @@ -42,7 +41,7 @@ public class BMotionWizardUtil { tableViewer.getTable().setLinesVisible(true); tableViewer.getTable().setHeaderVisible(true); tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); - tableViewer.getTable().setFont(BMotionStudioSWTConstants.fontArial10); + // tableViewer.getTable().setFont(BMotionStudioSWTConstants.fontArial10); int operations = DND.DROP_COPY | DND.DROP_MOVE; Transfer[] transferTypes = new Transfer[] { AttributeTransfer .getInstance() }; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/FileUtil.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/FileUtil.java deleted file mode 100644 index f0087ca90117a51b178e895aaa5446e0d0ab8faf..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/FileUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; - -public class FileUtil { - - /** Fast & simple file copy. */ - public static void copyFile(File source, File dest) throws IOException { - FileChannel in = null, out = null; - try { - in = new FileInputStream(source).getChannel(); - out = new FileOutputStream(dest).getChannel(); - - long size = in.size(); - MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, - size); - - out.write(buf); - } finally { - if (in != null) - in.close(); - if (out != null) - out.close(); - } - } - - public static void deleteFile(File f) { - // Attempt to delete it - boolean success = f.delete(); - if (!success) - throw new IllegalArgumentException("Delete: deletion failed"); - } - -} diff --git a/de.bmotionstudio.help/META-INF/MANIFEST.MF b/de.bmotionstudio.help/META-INF/MANIFEST.MF index 2a3c26e48a13dd905f4cf8073d66bcae49f1d6c3..b7f577358c479b3acfa9d2d39aacae4ab8847288 100644 --- a/de.bmotionstudio.help/META-INF/MANIFEST.MF +++ b/de.bmotionstudio.help/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: BMotion Studio Help Bundle-SymbolicName: de.bmotionstudio.help;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.0.1.qualifier Require-Bundle: org.eclipse.help;bundle-version="3.5.100" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: HHU Düsseldorf STUPS Group diff --git a/de.bmotionstudio.rodin/META-INF/MANIFEST.MF b/de.bmotionstudio.rodin/META-INF/MANIFEST.MF index 360c3fa5618b3b8a8c13988958c0d325bcd4d256..5173086bd1118fba776ae50ccc0fac132c8f4ea5 100644 --- a/de.bmotionstudio.rodin/META-INF/MANIFEST.MF +++ b/de.bmotionstudio.rodin/META-INF/MANIFEST.MF @@ -2,8 +2,8 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: BMotion Studio Rodin Integration Bundle-SymbolicName: de.bmotionstudio.rodin;singleton:=true -Bundle-Version: 1.1.0.qualifier -Fragment-Host: de.bmotionstudio.gef.editor;bundle-version="[5.4.0,5.5.0)" +Bundle-Version: 1.2.0.qualifier +Fragment-Host: de.bmotionstudio.gef.editor;bundle-version="[5.5.0,5.6.0)" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: HHU Düsseldorf STUPS Group Require-Bundle: org.eclipse.ui.navigator;bundle-version="3.5.0" diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java index f591535b259b59fd71d805118a27db38565c7709..b35987661b39908266d99274771a054655e3f93e 100644 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java @@ -10,7 +10,7 @@ import org.eclipse.core.commands.IHandler; import org.eclipse.core.resources.IFile; import org.eclipse.jface.viewers.IStructuredSelection; -import de.bmotionstudio.gef.editor.internal.StartVisualizationFileHandler; +import de.bmotionstudio.gef.editor.handler.StartVisualizationFileHandler; /** * @author Lukas Ladenberger diff --git a/de.prob.core.tests/.classpath b/de.prob.core.tests/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ad32c83a7885b8953a938b41df3b4fd4fe1aae01 --- /dev/null +++ b/de.prob.core.tests/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/de.prob.core.tests/.project b/de.prob.core.tests/.project new file mode 100644 index 0000000000000000000000000000000000000000..d35196a0d758c01def2ade464d2ae32be3d75326 --- /dev/null +++ b/de.prob.core.tests/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.core.tests</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/de.prob.core.tests/.settings/org.eclipse.jdt.core.prefs b/de.prob.core.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..c537b63063ce6052bdc49c5fd0745b078f162c90 --- /dev/null +++ b/de.prob.core.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/de.prob.core.tests/META-INF/MANIFEST.MF b/de.prob.core.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..fc445d16b3ea4a1b070d3bb59e600916d376f663 --- /dev/null +++ b/de.prob.core.tests/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests +Bundle-SymbolicName: de.prob.core.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: de.prob.core.tests.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eventb.core;bundle-version="[2.1.0,2.6.0)", + de.prob.core;bundle-version="9.3.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/de.prob.core.tests/build.properties b/de.prob.core.tests/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..34d2e4d2dad529ceaeb953bfcdb63c51d69ffed2 --- /dev/null +++ b/de.prob.core.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAllUnitTests.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAllUnitTests.java similarity index 91% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAllUnitTests.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAllUnitTests.java index 4799156dde7779b824f5cd04ae3f02dea53a3978..09ed7bc345fb64743bd228f85b7986c5edb14fcf 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAllUnitTests.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAllUnitTests.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.runner.RunWith; import org.junit.runners.Suite; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAndUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAndUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAndUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAndUnitTest.java index c6c14c77fd74ea1b60f2f99f400f6233f3bd7810..d389f63aed1a40610e3264fd08a357d073c5d371 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAndUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAndUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleFinallyUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleFinallyUnitTest.java similarity index 96% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleFinallyUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleFinallyUnitTest.java index 6306b0992bc67ca3a0427f9845926790a4eb36df..1ddcd43cb25762df80a63a25af810d54b99c6c20 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleFinallyUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleFinallyUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleGloballyUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleGloballyUnitTest.java similarity index 96% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleGloballyUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleGloballyUnitTest.java index 5688ff428550e28d7fe2f2c0eb1a22c868451b28..f772c06a1f6790453536355706ecadb6850c05e7 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleGloballyUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleGloballyUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleHistoryUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleHistoryUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleHistoryUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleHistoryUnitTest.java index 132509c5281e0c2614d1c5e48c037693a453d438..51e89995d8ca4f09bb0ca2979714eab55263e686 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleHistoryUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleHistoryUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleImplyUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleImplyUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleImplyUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleImplyUnitTest.java index 7c557d58feeffe92ada8e4f782ff499544a263b3..c130d52f3a8689feb434abdc222cef59779c6082 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleImplyUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleImplyUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNextUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNextUnitTest.java similarity index 94% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNextUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNextUnitTest.java index 95bb621017d47dbcd3d9e2e56ca17e1bcadfe9d8..d6dd660ce65667d5637e11a56d7367e7f5129fda 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNextUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNextUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNotUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNotUnitTest.java similarity index 93% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNotUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNotUnitTest.java index 8eeb19f6093b901aea5a63b98946846d1388245b..3566fac5615f9dcb2de1423a62c4b33289acbae1 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNotUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNotUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOnceUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOnceUnitTest.java similarity index 95% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOnceUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOnceUnitTest.java index 33229e73fe06c46044480552116c416c70b6fd73..4457b80bfb84040bfc7d30f5353c64ff0b1bdc8f 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOnceUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOnceUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOrUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOrUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOrUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOrUnitTest.java index ba5f5ad113bfca8d2d8cb427a6d5152e571b429f..ccff698093a9695ddea8b19a642e368ea36f5c7c 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOrUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOrUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleReleaseUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleReleaseUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleReleaseUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleReleaseUnitTest.java index c9160c73629adef9122bcccdcca0fda064a94e53..afedebfc3311bcdc8ba91a139707e630da408017 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleReleaseUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleReleaseUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleSinceUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleSinceUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleSinceUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleSinceUnitTest.java index 967f926419d1ce9f784d37d9830cc00394ecfa26..3752a020179ea16948f81656545498e2d357b5fb 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleSinceUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleSinceUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; /** diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleTriggerUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleTriggerUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleTriggerUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleTriggerUnitTest.java index 45bc1d3d5c0258adbbfb1d2d38e29e6870a231cc..519401e2b72f949ad35134a629b5f6e925396f25 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleTriggerUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleTriggerUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; /** diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleUntilUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleUntilUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleUntilUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleUntilUnitTest.java index f94c169e5c6fd88020decff033c4368f33660e9f..d70463239614775f0c0374cb2146817afb7ab427 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleUntilUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleUntilUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; /** diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleWeakUntilUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleWeakUntilUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleWeakUntilUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleWeakUntilUnitTest.java index db33abab5280f1fe13d283aec6c4e1a095dd5086..b7c91884b1a8ced635146f4c1ffaff25b7020aed 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleWeakUntilUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleWeakUntilUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; /** diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleYesterdayUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleYesterdayUnitTest.java similarity index 94% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleYesterdayUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleYesterdayUnitTest.java index b7b7e2548bc1d2494bea2ebd6251a825db651e77..798865d4e40d7572e136e825159d395913c56750 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleYesterdayUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleYesterdayUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/LtlTestDescription.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/LtlTestDescription.java similarity index 98% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/LtlTestDescription.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/LtlTestDescription.java index 20b7f4000b856cb5646c96f32811ff325979e105..7b3aeaec5ea8aa687a4332b5f4f81c6165779cb8 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/LtlTestDescription.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/LtlTestDescription.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import java.util.ArrayList; import java.util.Collection; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/TestCounterExample.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/TestCounterExample.java similarity index 92% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/TestCounterExample.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/TestCounterExample.java index 2c075e9da5fee99d9da865c7a3e9a77ed735eb16..f7de3916d871628e21273554b9d53d2a33329c97 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/TestCounterExample.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/TestCounterExample.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import de.prob.core.command.LtlCheckingCommand.PathType; import de.prob.core.domainobjects.ltl.CounterExample; diff --git a/de.prob.core.tests/src/de/prob/core/tests/Activator.java b/de.prob.core.tests/src/de/prob/core/tests/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..9c48634f3c8a77e18b86e6ca535547989f4c6b02 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/tests/Activator.java @@ -0,0 +1,50 @@ +package de.prob.core.tests; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "de.prob.core.tests"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractEventBTests.java b/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractEventBTests.java new file mode 100644 index 0000000000000000000000000000000000000000..e97100ac4ed6c05616166c6cd8808ff281a7f21e --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractEventBTests.java @@ -0,0 +1,1242 @@ +package de.prob.core.translator.tests; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.EventBPlugin; +import org.eventb.core.IAction; +import org.eventb.core.IAxiom; +import org.eventb.core.ICarrierSet; +import org.eventb.core.IConfigurationElement; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IConvergenceElement.Convergence; +import org.eventb.core.IEvent; +import org.eventb.core.IEventBProject; +import org.eventb.core.IExtendsContext; +import org.eventb.core.IGuard; +import org.eventb.core.IInvariant; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IParameter; +import org.eventb.core.IRefinesEvent; +import org.eventb.core.IRefinesMachine; +import org.eventb.core.ISeesContext; +import org.eventb.core.IVariable; +import org.eventb.core.IWitness; +import org.eventb.core.ast.FormulaFactory; +import org.junit.After; +import org.junit.Before; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; +import org.rodinp.internal.core.debug.DebugHelpers; + +/** + * @author htson + * <p> + * Abstract class for Event-B tests. + * </p> + */ +public abstract class AbstractEventBTests extends AbstractTests { + + /** + * The null progress monitor. + */ + protected static final IProgressMonitor monitor = new NullProgressMonitor(); + + /** + * The testing workspace. + */ + protected IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + /** + * The formula factory used to create formulae. + */ + protected static final FormulaFactory ff = FormulaFactory.getDefault(); + + /** + * Constructor: Create max_size test case. + */ + public AbstractEventBTests() { + super(); + } + + /** + * Constructor: Create max_size test case with the given name. + * + * @param name + * the name of test + */ + public AbstractEventBTests(String name) { + super(name); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + + // ensure autobuilding is turned off + IWorkspaceDescription wsDescription = workspace.getDescription(); + if (wsDescription.isAutoBuilding()) { + wsDescription.setAutoBuilding(false); + workspace.setDescription(wsDescription); + } + + // disable indexing + DebugHelpers.disableIndexing(); + + // Delete the old workspace + workspace.getRoot().delete(true, null); + + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + @After + @Override + protected void tearDown() throws Exception { + workspace.getRoot().delete(true, null); + super.tearDown(); + } + + // ========================================================================= + // Utility methods for creating various Event-B elements. + // ========================================================================= + + /** + * Utility method to create an Event-B project with given name. + * + * @param name + * name of the project + * @return the newly created Event-B project + * @throws CoreException + * if some errors occurred. + */ + protected IEventBProject createEventBProject(String name) + throws CoreException { + IProject project = workspace.getRoot().getProject(name); + project.create(null); + project.open(null); + IProjectDescription pDescription = project.getDescription(); + pDescription.setNatureIds(new String[] { RodinCore.NATURE_ID }); + project.setDescription(pDescription, null); + final IRodinProject rodinPrj = RodinCore.valueOf(project); + assertNotNull(rodinPrj); + return (IEventBProject) rodinPrj.getAdapter(IEventBProject.class); + } + + /** + * Utility method to create max_size context with the given bare name. The + * context is created as max_size child of the input Event-B project. + * + * @param project + * an Event-B project. + * @param bareName + * the bare name (without the extension .buc) of the context + * @return the newly created context. + * @throws RodinDBException + * if some problems occur. + */ + protected IContextRoot createContext(IEventBProject project, String bareName) + throws RodinDBException { + IRodinFile file = project.getContextFile(bareName); + file.create(true, null); + IContextRoot result = (IContextRoot) file.getRoot(); + result.setConfiguration(IConfigurationElement.DEFAULT_CONFIGURATION, + monitor); + return result; + } + + /** + * Utility method to create an EXTENDS clause within the input context for + * an abstract context. + * + * @param ctx + * max_size context. + * @param absCtxName + * the abstract context label. + * @return the newly created extends clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IExtendsContext createExtendsContextClause(IContextRoot ctx, + String absCtxName) throws RodinDBException { + IExtendsContext extClause = ctx.createChild( + IExtendsContext.ELEMENT_TYPE, null, monitor); + extClause.setAbstractContextName( + EventBPlugin.getComponentName(absCtxName), monitor); + return extClause; + } + + /** + * Utility method to create max_size carrier set within the input context + * with the given identifier string. + * + * @param ctx + * max_size context. + * @param identifierString + * the identifier string. + * @return the newly created carrier set. + * @throws RodinDBException + * if some errors occurred. + */ + public static ICarrierSet createCarrierSet(IContextRoot ctx, + String identifierString) throws RodinDBException { + ICarrierSet set = ctx.createChild(ICarrierSet.ELEMENT_TYPE, null, + monitor); + set.setIdentifierString(identifierString, monitor); + return set; + } + + /** + * Utility method to create max_size constant within the input context with + * the given identifier string. + * + * @param ctx + * max_size context. + * @param identifierString + * the identifier string. + * @return the newly created constant. + * @throws RodinDBException + * if some errors occurred. + */ + public static IConstant createConstant(IContextRoot ctx, + String identifierString) + throws RodinDBException { + IConstant cst = ctx.createChild(IConstant.ELEMENT_TYPE, null, monitor); + cst.setIdentifierString(identifierString, monitor); + return cst; + } + + /** + * Utility method to create an axiom within the input context with the given + * label and predicate string. + * + * @param ctx + * max_size context. + * @param label + * the label. + * @param predStr + * the predicate string. + * @param isTheorem + * <code>true</code> if the axiom is derivable, + * <code>false</code> otherwise. + * @return the newly created axiom. + * @throws RodinDBException + * if some errors occurred. + */ + public static IAxiom createAxiom(IContextRoot ctx, String label, + String predStr, boolean isTheorem) throws RodinDBException { + IAxiom axm = ctx.createChild(IAxiom.ELEMENT_TYPE, null, monitor); + axm.setLabel(label, monitor); + axm.setPredicateString(predStr, monitor); + axm.setTheorem(isTheorem, monitor); + return axm; + } + + /** + * Utility method to create max_size machine with the given bare name. The + * machine is created as max_size child of the input Event-B project. + * + * @param bareName + * the bare name (without the extension .bum) of the context + * @return the newly created context. + * @throws RodinDBException + * if some problems occur. + */ + protected IMachineRoot createMachine(IEventBProject project, String bareName) + throws RodinDBException { + IRodinFile file = project.getMachineFile(bareName); + file.create(true, null); + IMachineRoot result = (IMachineRoot) file.getRoot(); + result.setConfiguration(IConfigurationElement.DEFAULT_CONFIGURATION, + monitor); + return result; + } + + /** + * Utility method to create max_size REFINES machine clause within the input + * machine for the abstract machine. + * + * @param mch + * max_size machine. + * @param absMchName + * an abstract machine label + * @return the newly created refines clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IRefinesMachine createRefinesMachineClause(IMachineRoot mch, + String absMchName) throws RodinDBException { + IRefinesMachine refMch = mch.createChild(IRefinesMachine.ELEMENT_TYPE, + null, monitor); + refMch.setAbstractMachineName( + EventBPlugin.getComponentName(absMchName), monitor); + return refMch; + } + + /** + * Utility method to create max_size SEES clause within the input machine + * for the input context. + * + * @param mch + * max_size machine. + * @param ctxName + * max_size context. + * @return the newly created sees clause ({@link ISeesContext}. + * @throws RodinDBException + * if some errors occurred. + */ + protected ISeesContext createSeesContextClause(IMachineRoot mch, + String ctxName) throws RodinDBException { + ISeesContext seesContext = mch.createChild(ISeesContext.ELEMENT_TYPE, + null, monitor); + seesContext.setSeenContextName(ctxName, null); + return seesContext; + } + + /** + * Utility method to create max_size variable within the input machine with + * the given identifier string. + * + * @param mch + * max_size machine. + * @param identifierString + * the identifier string. + * @return the newly created variable. + * @throws RodinDBException + * if some errors occurred. + */ + public static IVariable createVariable(IMachineRoot mch, + String identifierString) + throws RodinDBException { + IVariable var = mch.createChild(IVariable.ELEMENT_TYPE, null, monitor); + var.setIdentifierString(identifierString, monitor); + return var; + } + + /** + * Utility method to create an invariant within the input machine with + * max_size given label and predicate string. + * + * @param mch + * max_size machine. + * @param label + * the label of the invariant. + * @param predicate + * the predicate string of the invariant. + * @return the newly created invariant. + * @throws RodinDBException + * if some errors occurred. + */ + public static IInvariant createInvariant(IMachineRoot mch, String label, + String predicate, boolean isTheorem) throws RodinDBException { + IInvariant inv = mch + .createChild(IInvariant.ELEMENT_TYPE, null, monitor); + inv.setLabel(label, monitor); + inv.setPredicateString(predicate, monitor); + inv.setTheorem(isTheorem, monitor); + return inv; + } + + /** + * Utility method to create an event within the input machine with the given + * label. By default, the extended attribute of the event is set to + * <code>false</code>. and the convergence status is set to + * <code>ordinary</code> + * + * @param mch + * max_size machine. + * @param label + * the label of the event. + * @return the newly created event. + * @throws RodinDBException + * if some errors occurred. + */ + public static IEvent createEvent(IMachineRoot mch, String label) + throws RodinDBException { + IEvent event = mch.createChild(IEvent.ELEMENT_TYPE, null, monitor); + event.setLabel(label, monitor); + event.setExtended(false, monitor); + event.setConvergence(Convergence.ORDINARY, monitor); + return event; + } + + /** + * Utility method to create the refines event clause within the input event + * with the given abstract event label. + * + * @param evt + * an event. + * @param absEvtLabel + * the abstract event label. + * @return the newly created refines event clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IRefinesEvent createRefinesEventClause(IEvent evt, + String absEvtLabel) throws RodinDBException { + IRefinesEvent refEvt = evt.createChild(IRefinesEvent.ELEMENT_TYPE, + null, monitor); + refEvt.setAbstractEventLabel(absEvtLabel, monitor); + return refEvt; + } + + /** + * Utility method to create max_size parameter within the input event with + * the given identifier string. + * + * @param evt + * an event. + * @param identifierString + * the identifier string. + * @return the newly created parameter. + * @throws RodinDBException + * if some errors occurred. + */ + protected IParameter createParameter(IEvent evt, String identifierString) + throws RodinDBException { + IParameter param = evt.createChild(IParameter.ELEMENT_TYPE, null, + monitor); + param.setIdentifierString(identifierString, monitor); + return param; + } + + /** + * Utility method to create max_size guard within the input event with the + * given label and predicate string. + * + * @param evt + * an event. + * @param label + * the label of the guard. + * @param predicateString + * the predicate string of the guard. + * @param b + * @return the newly created guard. + * @throws RodinDBException + * if some errors occurred. + */ + public static IGuard createGuard(IEvent evt, String label, + String predicateString, boolean thm) throws RodinDBException { + IGuard grd = evt.createChild(IGuard.ELEMENT_TYPE, null, monitor); + grd.setLabel(label, monitor); + grd.setPredicateString(predicateString, monitor); + grd.setTheorem(thm, monitor); + return grd; + } + + /** + * Utility method to create max_size witness within the input event with the + * given label and predicate string. + * + * @param evt + * an event. + * @param label + * the label of the witness. + * @param predicateString + * the predicate string of the witness. + * @return the newly created witness. + * @throws RodinDBException + * if some errors occurred. + */ + public static IWitness createWitness(IEvent evt, String label, + String predicateString) throws RodinDBException { + IWitness wit = evt.createChild(IWitness.ELEMENT_TYPE, null, monitor); + wit.setLabel(label, monitor); + wit.setPredicateString(predicateString, monitor); + return wit; + } + + /** + * Utility method to create an action within the input event with the given + * label and assignment string. + * + * @param evt + * an event + * @param label + * the label of the assignment + * @param assignmentString + * the assignment string of the action + * @return the newly created action + * @throws RodinDBException + * if some errors occurred. + */ + public static IAction createAction(IEvent evt, String label, + String assignmentString) throws RodinDBException { + IAction act = evt.createChild(IAction.ELEMENT_TYPE, null, monitor); + act.setLabel(label, monitor); + act.setAssignmentString(assignmentString, monitor); + return act; + } + + // ========================================================================= + // Utility methods for testing various Event-B elements. + // ========================================================================= + + /** + * Utility method for testing EXTENDS clauses of a context. + * + * @param message + * a message for debugging. + * @param ctx + * A context root whose EXTENDS clauses will be tested. + * @param expected + * the array of expected EXTENDS clauses. Each clause is + * represented by the abstract context name. The order of the + * EXTENDS clause is important. + */ + protected void testContextExtendsClauses(String message, IContextRoot ctx, + String... expected) { + try { + IExtendsContext[] extendsCtxs = ctx.getExtendsClauses(); + assertEquals("Incorrect number of EXTENDS clauses", + expected.length, extendsCtxs.length); + for (int i = 0; i < expected.length; i++) { + testExtendsClause(message, extendsCtxs[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an EXTEND clause. + * + * @param message + * a message for debugging. + * @param extendCtx + * the EXTEND clause under test. + * @param expected + * the expected abstract context name. + */ + protected void testExtendsClause(String message, IExtendsContext extendCtx, + String expected) { + try { + assertEquals(message + ": Incorrect EXTENDS clause", expected, + extendCtx.getAbstractContextName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the carrier sets of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context whose carrier sets will be tested. + * @param expected + * an array of expected carrier sets. Each carrier set is + * represented by its identifier. The order of the carrier sets + * is important. + */ + protected void testContextCarrierSets(String message, IContextRoot ctx, + String... expected) { + try { + ICarrierSet[] sets = ctx.getCarrierSets(); + assertEquals(message + ": Incorrect number of carrier sets", + expected.length, sets.length); + for (int i = 0; i < expected.length; i++) { + testCarrierSet(message, sets[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a carrier set. + * + * @param message + * a message for debugging. + * @param set + * the carrier set under test. + * @param expected + * the expected identifier of the carrier set. + */ + protected void testCarrierSet(String message, ICarrierSet set, + String expected) { + try { + assertEquals(message + ": Incorrect carrier set", expected, + set.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the constants of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context whose constants will be tested. + * @param expected + * an array of expected constants. Each constant is represented + * by its identifier. The order of the constants is important. + */ + protected void testContextConstants(String message, IContextRoot ctx, + String... expected) { + try { + IConstant[] csts = ctx.getConstants(); + assertEquals(message + ": Incorrect number of constants", + expected.length, csts.length); + for (int i = 0; i < expected.length; i++) { + testConstant(message, csts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a constant. + * + * @param message + * a message for debugging. + * @param set + * the constant under test. + * @param expected + * the expected identifier of the constant. + */ + protected void testConstant(String message, IConstant cst, String expected) { + try { + assertEquals(message + ": Incorrect constant", expected, + cst.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the axioms of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context root whose axioms will be tested. + * @param expected + * the expected pretty-print axioms. The axioms are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the axioms is + * important. + */ + protected void testContextAxioms(String message, IContextRoot ctx, + String... expected) { + try { + IAxiom[] axioms = ctx.getAxioms(); + assertEquals(message + ": Incorrect number of axioms", + expected.length, axioms.length); + for (int i = 0; i < expected.length; i++) { + testAxiom(message, axioms[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an axiom. + * + * @param message + * a message for debugging. + * @param axiom + * the axiom under test. + * @param expected + * the expected pretty print axiom. The axiom is "pretty-printed" + * as follows: "label:predicateString:isTheorem". + */ + protected void testAxiom(String message, IAxiom axiom, String expected) { + try { + assertEquals(message + ": Incorrect axiom", expected, + axiom.getLabel() + ":" + axiom.getPredicateString() + ":" + + axiom.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the REFINES clauses of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose REFINES clauses will be tested. + * @param expected + * an array of expected REFINES clause. Each REFINES clause is + * represented by its abstract machine name. The order of the + * REFINES clauses is important. + */ + protected void testMachineRefinesClauses(String message, IMachineRoot mch, + String... expected) { + try { + IRefinesMachine[] refinesClauses = mch.getRefinesClauses(); + assertEquals(message + ": Incorrect number of REFINES clauses", + expected.length, refinesClauses.length); + for (int i = 0; i < expected.length; i++) { + testRefinesClause(message, refinesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a REFINES (machine) clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the REFINES (machine) clause under test. + * @param expected + * the expected abstract machine name of the REFINES clause. + */ + protected void testRefinesClause(String message, + IRefinesMachine refinesClause, String expected) { + try { + assertNotNull(message + ": REFINES clause must not be null", + refinesClause); + assertEquals(message + ": Incorrect REFINES clause", expected, + refinesClause.getAbstractMachineName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the SEES clauses of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose SEES clauses will be tested. + * @param expected + * an array of expected SEES clause. Each SEES clause is + * represented by its seen context name. The order of the SEES + * clauses is important. + */ + protected void testMachineSeesClauses(String message, IMachineRoot mch, + String... expected) { + try { + ISeesContext[] seesClauses = mch.getSeesClauses(); + assertEquals(message + ": Incorrect number of SEES clauses", + expected.length, seesClauses.length); + for (int i = 0; i < expected.length; i++) { + testSeesClause(message, seesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a SEES clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the SEES clause under test. + * @param expected + * the expected seen context name of the SEES clause. + */ + protected void testSeesClause(String message, ISeesContext seesClause, + String expected) { + try { + assertEquals(message + ": Incorrect SEES clause", expected, + seesClause.getSeenContextName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the variables of a machine. + * + * @param message + * a message for debugging. + * @param mch + * the machine root whose variables will be tested. + * @param expected + * an array of expected variables. Each variable is represented + * by its identifier. The order of the variables is important. + */ + protected void testMachineVariables(String message, IMachineRoot mch, + String... expected) { + try { + IVariable[] vars = mch.getVariables(); + assertEquals(message + ": Incorrect number of variables", + expected.length, vars.length); + for (int i = 0; i < expected.length; i++) { + testVariable(message, vars[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the variables of a machine. + * + * @param message + * a message for debugging. + * @param mch + * the machine root whose variables will be tested. + * @param expected + * an array of expected variables. Each variable is represented + * by its identifier. The order of the variables is NOT + * important. + */ + protected void testMachineVariablesUnordered(String message, + IMachineRoot mch, String... expected) { + try { + IVariable[] vars = mch.getVariables(); + assertEquals(message + ": Incorrect number of variables", + expected.length, vars.length); + for (int i = 0; i < expected.length; i++) { + boolean b = false; + for (int j = 0; j < vars.length; j++) { + if (vars[j].getIdentifierString().equals(expected[i])) { + b = true; + break; + } + } + if (!b) { + fail("Variable " + expected[i] + " cannot be found"); + } + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a variable. + * + * @param message + * a message for debugging. + * @param var + * the variable under test. + * @param expected + * the expected identifier of the variable. + */ + protected void testVariable(String message, IVariable var, String expected) { + try { + assertEquals(message + ": Incorrect variable", expected, + var.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the invariants of a context. + * + * @param message + * a message for debugging. + * @param mch + * a context root whose invariants will be tested. + * @param expected + * the expected pretty-print invariants. The invariants are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the invariants + * is important. + */ + protected void testMachineInvariants(String message, IMachineRoot mch, + String... expected) { + try { + IInvariant[] invs = mch.getInvariants(); + assertEquals(message + ": Incorrect number of invariants", + expected.length, invs.length); + for (int i = 0; i < expected.length; i++) { + testInvariant(message, invs[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an invariant. + * + * @param message + * a message for debugging. + * @param inv + * the invariant under test. + * @param expected + * the expected pretty-print invariant. The invariant is + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". + */ + protected void testInvariant(String message, IInvariant inv, String expected) { + try { + assertEquals( + message + ": Incorrect invariant", + expected, + inv.getLabel() + ":" + inv.getPredicateString() + ":" + + inv.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the events of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose events will be tested. + * @param expected + * the expected pretty-print events (only the signature). The + * events are "pretty-printed" as follows: + * "label:convergent:isExtended". The order of the events is + * important. + */ + protected void testMachineEvents(String message, IMachineRoot mch, + String... expected) { + try { + IEvent[] evts = mch.getEvents(); + assertEquals(message + ": Incorrect number of events", + expected.length, evts.length); + for (int i = 0; i < expected.length; i++) { + testEvent(message, evts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an event. + * + * @param message + * a message for debugging. + * @param evt + * the event under test. + * @param expected + * the expected pretty-print event (only the signature). The + * event is "pretty-printed" as follows: + * "label:convergent:isExtended". + */ + protected void testEvent(String message, IEvent evt, String expected) { + try { + assertNotNull(message + ": The event must not be null", evt); + assertEquals( + message + ": Incorrect event", + expected, + evt.getLabel() + ":" + evt.getConvergence() + ":" + + evt.isExtended()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the REFINES clauses of an event. + * + * @param message + * a message for debugging. + * @param mch + * an event whose REFINES clauses will be tested. + * @param expected + * an array of expected REFINES clause. Each REFINES clause is + * represented by its abstract event name. The order of the + * REFINES clauses is important. + */ + protected void testEventRefinesClauses(String message, IEvent evt, + String... expected) { + try { + IRefinesEvent[] refinesClauses = evt.getRefinesClauses(); + assertEquals(message + ": Incorrect number of REFINES clauses", + expected.length, refinesClauses.length); + for (int i = 0; i < expected.length; i++) { + testRefinesClause(message, refinesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a REFINES (event) clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the REFINES (event) clause under test. + * @param expected + * the expected abstract event name of the REFINES clause. + */ + protected void testRefinesClause(String message, + IRefinesEvent refinesEvent, String expected) { + try { + assertEquals(message + "Incorrect REFINES clause", expected, + refinesEvent.getAbstractEventLabel()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the parameters of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose parameters will be tested. + * @param expected + * the expected set of parameters. Each parameter is represented + * by its identifier. The order of the parameters is important. + */ + protected void testEventParameters(String message, IEvent evt, + String... expected) { + try { + IParameter[] params = evt.getParameters(); + assertEquals(message + ": Incorrect number of parameters", + expected.length, params.length); + for (int i = 0; i < expected.length; i++) { + testParameter(message, params[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a parameter. + * + * @param message + * a message for debugging. + * @param par + * the parameter under test. + * @param expected + * the expected parameter identifier. + */ + protected void testParameter(String message, IParameter par, String expected) { + try { + assertEquals(message + ": Incorrect parameter", expected, + par.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the guards of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose guards will be tested. + * @param expected + * the expected pretty-print guards. The guards are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the guards is + * important. + */ + protected void testEventGuards(String message, IEvent evt, + String... expected) { + try { + IGuard[] grds = evt.getGuards(); + assertEquals(message + ": Incorrect number of guards", + expected.length, grds.length); + for (int i = 0; i < grds.length; i++) { + testGuard(message, grds[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a guard. + * + * @param message + * a message for debugging. + * @param grd + * the guard under test. + * @param expected + * the expected pretty-print guard. The guard is "pretty-printed" + * as follows: "label:predicateString:isTheorem". + */ + protected void testGuard(String message, IGuard grd, String expected) { + try { + assertEquals( + message + ": Incorrect guard", + expected, + grd.getLabel() + ":" + grd.getPredicateString() + ":" + + grd.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the witnesses of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose witnesses will be tested. + * @param expected + * the expected pretty-print witnesses. The witnesses are + * "pretty-printed" as follows: "label:predicateString". The + * order of the witnesses is important. + */ + protected void testEventWitnesses(String message, IEvent evt, + String... expected) { + try { + IWitness[] wits = evt.getWitnesses(); + assertEquals(message + ": Incorrect number of witnesses", + expected.length, wits.length); + for (int i = 0; i < expected.length; i++) { + testWitness(message, wits[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an witness. + * + * @param message + * a message for debugging. + * @param wit + * the witness under test. + * @param expected + * the expected pretty-print witness. The witness is + * "pretty-printed" as follows: "label:predicateString". + */ + protected void testWitness(String message, IWitness wit, String expected) { + try { + assertEquals(message + ": Incorrect witness", expected, + wit.getLabel() + ":" + wit.getPredicateString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the actions of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose actions will be tested. + * @param expected + * expected pretty-print actions. The actions are + * "pretty-printed" as follows: "label:assignmentString". The + * order of the actions is important. + */ + protected void testEventActions(String message, IEvent evt, + String... expected) { + try { + IAction[] acts = evt.getActions(); + assertEquals(message + ": Incorrect number of actions", + expected.length, acts.length); + for (int i = 0; i < expected.length; i++) { + testAction(message, acts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an action. + * + * @param message + * a message + * @param act + * the action under test + * @param expected + * expected pretty-print action. The action is "pretty-printed" + * as follows: "label:assignmentString". + */ + protected void testAction(String message, IAction act, String expected) { + try { + assertEquals(message + ": Incorrect action", expected, + act.getLabel() + ":" + act.getAssignmentString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractTests.java b/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractTests.java new file mode 100644 index 0000000000000000000000000000000000000000..16ad5fe3312d45a2ef79b644d050f9b30beb2472 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractTests.java @@ -0,0 +1,143 @@ +package de.prob.core.translator.tests; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +/** + * @author htson + * <p> + * This abstract class contains utility methods supporting testing. + * </p> + */ +public abstract class AbstractTests extends TestCase { + + /** + * Constructor: Create max_size test case. + */ + public AbstractTests() { + super(); + } + + /** + * Constructor: Create max_size test case with the given name. + * + * @param name + * the name of test + */ + public AbstractTests(String name) { + super(name); + } + + /** + * Utility method to compare two string collections. The expected collection + * is given in terms of an array of strings. The actual collection is given + * as a collection of strings. The two are the same if the number of + * elements is the same and every element of the expected collection appear + * in the actual collection. + * + * @param msg + * a message. + * @param actual + * actual collection of strings. + * @param expected + * expected array of strings. + */ + protected static void assertSameStrings(String msg, + Collection<String> actual, String... expected) { + assertEquals(msg + ": Incorrect number of elements\n", expected.length, + actual.size()); + for (String exp : expected) { + assertTrue(msg + ": Expected element " + exp + " not found", + actual.contains(exp)); + } + } + + /** + * Utility method to compare two arrays of strings. The two are the same if + * the number of elements is the same, and the strings at the same index are + * the same. + * + * @param msg + * a message. + * @param actual + * actual array of strings. + * @param expected + * expected array of strings. + */ + protected static void assertSameStrings(String msg, String[] actual, + String... expected) { + assertEquals(msg + ": Incorrect number of strings\n", expected.length, + actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(msg, expected[i], actual[i]); + } + } + + /** + * Utility method to compare two arrays of objects. The two are the same if + * the number of elements is the same, and the objects at the same index are + * the same. + * + * @param msg + * a message. + * @param expected + * expected array of objects. + * @param actual + * actual array of objects. + */ + protected static void assertSameObjects(String msg, Object[] expected, + Object[] actual) { + assertEquals(msg + ": Incorrect number of objects\n", expected.length, + actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(msg, expected[i], actual[i]); + } + } + + /** + * Utility method to compare two maps of objects to objects. The two are the + * same if the key sets are the same (using + * {@link #assertSameSet(String, Set, Set)}), and for each key, they map to + * the same value. + * + * @param msg + * a messages. + * @param expected + * expected map. + * @param actual + * actual map. + */ + protected void assertSameMap(String msg, + Map<? extends Object, ? extends Object> expected, + Map<? extends Object, ? extends Object> actual) { + Set<? extends Object> expectedKeySet = expected.keySet(); + Set<? extends Object> actualKeySet = actual.keySet(); + assertSameSet(msg, expectedKeySet, actualKeySet); + for (Object key : expectedKeySet) { + assertEquals(msg, expected.get(key), actual.get(key)); + } + } + + /** + * Utility method to compare two sets of objects. The two are the same if + * they have the same number of elements, and each element of the expected + * set appears in the actual set. + * + * @param msg + * @param expected + * @param actual + */ + protected void assertSameSet(String msg, Set<? extends Object> expected, + Set<? extends Object> actual) { + assertEquals(msg + ": The number of elements must be the same", + expected.size(), actual.size()); + for (Object elm : expected) { + assertTrue(msg + ": expected element " + elm + " not found", + actual.contains(elm)); + } + } + +} \ No newline at end of file diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/ContextChainTest.java b/de.prob.core.tests/src/de/prob/core/translator/tests/ContextChainTest.java new file mode 100644 index 0000000000000000000000000000000000000000..237722c6841d81b81296e7678308ae502394d10a --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/ContextChainTest.java @@ -0,0 +1,46 @@ +package de.prob.core.translator.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; + +public class ContextChainTest extends AbstractEventBTests { + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Ignore + @Test + public void testEmptyContextChain() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context1 = createContext(project, "TestContext1"); + IContextRoot context2 = createContext(project, "TestContext2"); + + createExtendsContextClause(context2, "TestContext1"); + + context1.getRodinFile().save(monitor, false); + context2.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + TranslatorFactory.translate(context2, writer); + + assertEquals( + "package(load_event_b_project([],[event_b_context(none,'TestContext2',[extends(none,['TestContext1']),constants(none,[]),abstract_constants(none,[]),axioms(none,[]),theorems(none,[]),sets(none,[])]),event_b_context(none,'TestContext1',[extends(none,[]),constants(none,[]),axioms(none,[]),theorems(none,[]),sets(none,[])])],[exporter_version(3)],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/ContextWithConstantsTest.java b/de.prob.core.tests/src/de/prob/core/translator/tests/ContextWithConstantsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..fc60ba048fa00e94c48d3a1057e1c80053f6fe11 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/ContextWithConstantsTest.java @@ -0,0 +1,51 @@ +package de.prob.core.translator.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; + +public class ContextWithConstantsTest extends AbstractEventBTests { + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Ignore + @Test + public void testContextWithConstants() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + createConstant(context, "cst1"); + createAxiom(context, "axm1", "cst1=5", false); + + // save file and build workspace - this triggers static check, and + // generates missing files + context.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one constant and one SC constant + assertEquals(1, context.getConstants().length); + assertEquals(1, context.getSCContextRoot().getSCConstants().length); + + TranslatorFactory.translate(context, writer); + + assertEquals( + "package(load_event_b_project([],[event_b_context(none,'TestContext',[extends(none,[]),constants(none,[identifier(none,cst1)]),abstract_constants(none,[]),axioms(none,[equal(rodinpos('TestContext',axm1,'('),identifier(none,cst1),integer(none,5))]),theorems(none,[]),sets(none,[])])],[exporter_version(3)],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/EmptyTranslationsTest.java b/de.prob.core.tests/src/de/prob/core/translator/tests/EmptyTranslationsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..fddef397b3ec731cddb26b92d4740be574633469 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/EmptyTranslationsTest.java @@ -0,0 +1,59 @@ +package de.prob.core.translator.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; + +public class EmptyTranslationsTest extends AbstractEventBTests { + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Test + public void testEmptyMachine() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + TranslatorFactory.translate(machine, writer); + + assertEquals( + "package(load_event_b_project([event_b_model(none,'TestMachine',[sees(none,[]),variables(none,[]),invariant(none,[]),theorems(none,[]),events(none,[])])],[],[exporter_version(3)],_Error)).\n", + stringWriter.getBuffer().toString()); + } + + @Ignore + @Test + public void testEmptyContext() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + context.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + TranslatorFactory.translate(context, writer); + + assertEquals( + "package(load_event_b_project([],[event_b_context(none,'TestContext',[extends(none,[]),constants(none,[]),abstract_constants(none,[]),axioms(none,[]),theorems(none,[]),sets(none,[])])],[exporter_version(3)],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/MachineWithVariablesTest.java b/de.prob.core.tests/src/de/prob/core/translator/tests/MachineWithVariablesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ad6aab405fee0eb88a599d31ab3b1e8e916660f4 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/MachineWithVariablesTest.java @@ -0,0 +1,52 @@ +package de.prob.core.translator.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; +import org.junit.Before; +import org.junit.Test; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; + +public class MachineWithVariablesTest extends AbstractEventBTests { + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Test + public void testMachineWithVariables() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + createVariable(machine, "v1"); + createInvariant(machine, "inv1", "v1=5", false); + + // save file and build workspace - this triggers static check, and + // generates missing files + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one variable and one SC variable + assertEquals(1, machine.getVariables().length); + assertEquals(1, machine.getSCMachineRoot().getSCVariables().length); + + TranslatorFactory.translate(machine, writer); + + assertEquals( + "package(load_event_b_project([event_b_model(none,'TestMachine',[sees(none,[]),variables(none,[identifier(none,v1)]),invariant(none,[equal(rodinpos('TestMachine',inv1,'('),identifier(none,v1),integer(none,5))]),theorems(none,[]),events(none,[])])],[],[exporter_version(3)],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.core/.classpath b/de.prob.core/.classpath index bb1ae0592818db067d6599e1a8f034a51349b613..64514b5b61169cb4dadac9325e6be40ac47601dd 100644 --- a/de.prob.core/.classpath +++ b/de.prob.core/.classpath @@ -1,23 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry exported="true" kind="lib" path="lib/dependencies/commons-codec-1.6.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/xmlpull-1.1.3.1.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/xpp3_min-1.1.4c.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/xstream-1.4.3.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/answerparser-2.4.8-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/bparser-2.4.8-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/cliparser-2.4.8-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/commons-lang-2.6.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/jgrapht-0.8.3.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/jsr305-1.3.9.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/ltlparser-2.4.8-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/parserbase-2.4.8-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/prologlib-2.4.8-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/unicode-2.4.8-SNAPSHOT.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="test"/> - <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="output" path="bin"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/answerparser-2.4.19-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/bparser-2.4.19-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/cliparser-2.4.19-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/commons-codec-1.6.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/commons-lang-2.6.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/jsr305-1.3.9.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/ltlparser-2.4.19-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/parserbase-2.4.19-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/prologlib-2.4.19-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/theorymapping-2.4.19-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/unicode-2.4.19-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/xmlpull-1.1.3.1.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/xpp3_min-1.1.4c.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/xstream-1.4.3.jar"/> </classpath> diff --git a/de.prob.core/META-INF/MANIFEST.MF b/de.prob.core/META-INF/MANIFEST.MF index 19b5b62d17480bed9c3f25d0175bd4f9c014e861..1e95a85cf49ca65c509e819f0b4743104ec6e854 100644 --- a/de.prob.core/META-INF/MANIFEST.MF +++ b/de.prob.core/META-INF/MANIFEST.MF @@ -2,13 +2,14 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: ProB Animator Core Bundle-SymbolicName: de.prob.core;singleton:=true -Bundle-Version: 9.3.0.qualifier +Bundle-Version: 9.4.0.qualifier Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.rodinp.core;bundle-version="[1.3.1,1.7.0)", - org.eventb.core;bundle-version="[2.1.0,2.6.0)" + org.eventb.core;bundle-version="[2.5.0,2.6.0)", + org.eventb.theory.core;bundle-version="[2.0.0,3.0.0)";resolution:=optional Bundle-ActivationPolicy: lazy Eclipse-BundleShape: dir -Bundle-Vendor: HHU Düsseldorf STUPS Group +Bundle-Vendor: HHU Dusseldorf STUPS Group Export-Package: com.thoughtworks.xstream, com.thoughtworks.xstream.annotations, com.thoughtworks.xstream.converters, @@ -69,7 +70,6 @@ Export-Package: com.thoughtworks.xstream, de.prob.core.domainobjects, de.prob.core.domainobjects.eval, de.prob.core.domainobjects.ltl, - de.prob.core.domainobjects.ltl.unittests, de.prob.core.internal, de.prob.core.langdep, de.prob.core.prolog, @@ -86,6 +86,7 @@ Export-Package: com.thoughtworks.xstream, de.prob.logging, de.prob.model.eventb, de.prob.model.representation, + de.prob.model.serialize, de.prob.parser, de.prob.parserbase, de.prob.prolog.match, @@ -114,17 +115,18 @@ Bundle-Activator: de.prob.core.internal.Activator Eclipse-BuddyPolicy: registered Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ClassPath: ., - lib/dependencies/answerparser-2.4.8-SNAPSHOT.jar, - lib/dependencies/bparser-2.4.8-SNAPSHOT.jar, - lib/dependencies/cliparser-2.4.8-SNAPSHOT.jar, - lib/dependencies/commons-lang-2.6.jar, + lib/dependencies/unicode-2.4.19-SNAPSHOT.jar, + lib/dependencies/theorymapping-2.4.19-SNAPSHOT.jar, + lib/dependencies/prologlib-2.4.19-SNAPSHOT.jar, + lib/dependencies/parserbase-2.4.19-SNAPSHOT.jar, + lib/dependencies/ltlparser-2.4.19-SNAPSHOT.jar, + lib/dependencies/cliparser-2.4.19-SNAPSHOT.jar, + lib/dependencies/bparser-2.4.19-SNAPSHOT.jar, + lib/dependencies/answerparser-2.4.19-SNAPSHOT.jar, lib/dependencies/jgrapht-0.8.3.jar, - lib/dependencies/jsr305-1.3.9.jar, - lib/dependencies/ltlparser-2.4.8-SNAPSHOT.jar, - lib/dependencies/parserbase-2.4.8-SNAPSHOT.jar, - lib/dependencies/prologlib-2.4.8-SNAPSHOT.jar, - lib/dependencies/unicode-2.4.8-SNAPSHOT.jar, lib/dependencies/commons-codec-1.6.jar, + lib/dependencies/commons-lang-2.6.jar, + lib/dependencies/jsr305-1.3.9.jar, lib/dependencies/xmlpull-1.1.3.1.jar, lib/dependencies/xpp3_min-1.1.4c.jar, lib/dependencies/xstream-1.4.3.jar diff --git a/de.prob.core/build.gradle b/de.prob.core/build.gradle index 82ad7bd0a0355e26c646e7ab8a31e8f5fb3d5234..a4692401acacc2acb2529817321b113b81f4a2ec 100644 --- a/de.prob.core/build.gradle +++ b/de.prob.core/build.gradle @@ -1,7 +1,6 @@ apply plugin: 'java' - -def parser_version = '2.4.8-SNAPSHOT' +def parser_version = '2.4.18-SNAPSHOT' dependencies { compile group: "de.prob", name: "answerparser", version: parser_version , changing: true @@ -11,7 +10,7 @@ dependencies { compile group: "de.prob", name: "parserbase", version: parser_version , changing: true compile group: "de.prob", name: "prologlib", version: parser_version , changing: true compile group: "de.prob", name: "unicode", version: parser_version , changing: true - compile 'jgrapht:jgrapht:0.8.3' + compile group: "de.prob", name: "theorymapping", version: parser_version , changing: true compile 'commons-lang:commons-lang:2.6' compile 'commons-codec:commons-codec:1.6' compile 'com.thoughtworks.xstream:xstream:1.4.3' diff --git a/de.prob.core/plugin.xml b/de.prob.core/plugin.xml index 2d7b472c3f23462dc53c415d78961b70f7940e2f..b84a1eaef2043d86514040b1a698b95d501b759d 100644 --- a/de.prob.core/plugin.xml +++ b/de.prob.core/plugin.xml @@ -4,6 +4,7 @@ <extension-point id="de.prob.core.lifecycle" name="Lifecycle Events" schema="schema/de.prob.core.lifecycle.exsd"/> <extension-point id="de.prob.core.computation" name="Computation Events" schema="schema/de.prob.core.computation.exsd"/> <extension-point id="de.prob.core.animation" name="Animation Events" schema="schema/de.prob.core.animation.exsd"/> + <extension-point id="de.prob.translator" name="Translator Extensions" schema="schema/de.prob.translator.exsd"/> <extension point="de.prob.core.animation"> <listener diff --git a/de.prob.core/prob_target.target b/de.prob.core/prob_target.target index 24f85841a5e6d301b9de4502a08e94175bf68ca4..8834890556ae7309a133b1c3064a6e9b2961e4d5 100644 --- a/de.prob.core/prob_target.target +++ b/de.prob.core/prob_target.target @@ -1,25 +1,27 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<?pde version="3.8"?><target name="prob_target" sequenceNumber="18"> -<locations> -<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> -<unit id="org.eventb.ide.feature.group" version="2.7.0.r15250"/> -<unit id="fr.systerel.editor.feature.group" version="0.6.4.r15250"/> -<unit id="org.rodinp.feature.group" version="1.6.0.r15250"/> -<unit id="org.rodinp.platform.product" version="2.7.0.r15250"/> -<unit id="org.rodinp.platform.feature.group" version="2.7.0.r15250"/> -<unit id="org.rodinp.platform.product.root.feature.feature.group" version="2.7.0.r15250"/> -<repository location="http://rodin-b-sharp.sourceforge.net/core-updates"/> -</location> -<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> -<unit id="org.eclipse.emf.sdk.feature.group" version="2.7.2.v20120130-0943"/> -<unit id="org.eclipse.equinox.sdk.feature.group" version="3.7.1.R37x_v20110907-7M7W8i8eNV4WsRkue-4Vq4J6pCyW"/> -<unit id="org.eclipse.gef.sdk.feature.group" version="3.7.2.v20110927-2020-7G7W77A5WNgIRPdWXDIbNTSQPdQL"/> -<repository location="http://download.eclipse.org/releases/indigo/"/> -</location> -<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> -<unit id="ac.soton.eventb.emf.core.extension.feature.feature.group" version="1.3.0.201206030057"/> -<unit id="org.eventb.emf.feature.feature.group" version="3.7.0.201204300914"/> -<repository location="http://rodin-b-sharp.sourceforge.net/updates"/> -</location> -</locations> -</target> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?pde version="3.8"?><target name="prob_target" sequenceNumber="20"> +<locations> +<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> +<unit id="org.eventb.ide.feature.group" version="2.7.0.r15250"/> +<unit id="fr.systerel.editor.feature.group" version="0.6.4.r15250"/> +<unit id="org.rodinp.feature.group" version="1.6.0.r15250"/> +<unit id="org.rodinp.platform.product" version="2.7.0.r15250"/> +<unit id="org.rodinp.platform.feature.group" version="2.7.0.r15250"/> +<unit id="org.rodinp.platform.product.root.feature.feature.group" version="2.7.0.r15250"/> +<repository location="http://rodin-b-sharp.sourceforge.net/core-updates"/> +</location> +<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> +<unit id="ac.soton.eventb.emf.core.extension.feature.feature.group" version="1.3.0.201206030057"/> +<unit id="org.eventb.emf.feature.feature.group" version="3.7.0.201204300914"/> +<repository location="http://rodin-b-sharp.sourceforge.net/updates"/> +</location> +<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> +<unit id="org.eventb.theory.feature.feature.group" version="2.0.0"/> +<repository location="http://www.stups.uni-duesseldorf.de/ProB/buildlibs/theory/"/> +</location> +<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> +<unit id="epp.package.java" version="1.4.2.20120213-0813"/> +<repository location="http://download.eclipse.org/releases/indigo/"/> +</location> +</locations> +</target> diff --git a/de.prob.core/representation/AbstractElement.java b/de.prob.core/representation/AbstractElement.java new file mode 100644 index 0000000000000000000000000000000000000000..53c0c5aca6cd86c5ef43bf01020f0514afe9dd51 --- /dev/null +++ b/de.prob.core/representation/AbstractElement.java @@ -0,0 +1,58 @@ +package de.prob.model.representation; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +/** + * This class is the subclass of all model elements (Models, Machines, Contexts, + * Variables, etc.) + * + * @author joy + * + */ +public abstract class AbstractElement { + protected Map<Class<? extends AbstractElement>, java.util.Set<? extends AbstractElement>> children = new HashMap<Class<? extends AbstractElement>, Set<? extends AbstractElement>>(); + + /** + * Each {@link AbstractElement} can have children of a subclass that extends + * {@link AbstractElement}. These are specified by the class of the child. + * To get a Set of all of the children of a particular class, use this + * method. + * + * @param c + * {@link Class} T of the desired type of children + * @return {@link Set} containing all the children of type T + */ + @SuppressWarnings("unchecked") + public <T extends AbstractElement> Set<T> getChildrenOfType(final Class<T> c) { + Set<? extends AbstractElement> set = children.get(c); + if (set == null) { + return Collections.emptySet(); + } + return (Set<T>) set; + } + + /** + * Maps a {@link Collection} of elements to the specified {@link Class} + * + * @param c + * {@link Class} to specify children elements + * @param elements + * {@link Collection} of elements with which c will be mapped + */ + public <T extends AbstractElement> void put(final Class<T> c, + final Collection<? extends T> elements) { + children.put(c, new LinkedHashSet<T>(elements)); + } + + /** + * @return the {@link Map} of {@link Class} to {@link Set} of children + */ + public Map<Class<? extends AbstractElement>, java.util.Set<? extends AbstractElement>> getChildren() { + return children; + } +} diff --git a/de.prob.core/representation/AbstractModel.java b/de.prob.core/representation/AbstractModel.java new file mode 100644 index 0000000000000000000000000000000000000000..0da709509d704fd59c54661cbea66696469d1186 --- /dev/null +++ b/de.prob.core/representation/AbstractModel.java @@ -0,0 +1,84 @@ +package de.prob.model.representation; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import de.prob.model.representation.RefType.ERefType; +import de.prob.statespace.History; +import de.prob.statespace.StateSpace; +import edu.uci.ics.jung.graph.DirectedSparseMultigraph; + +public abstract class AbstractModel extends AbstractElement { + + protected StateSpace statespace; + protected File modelFile; + protected DirectedSparseMultigraph<String, RefType> graph = new DirectedSparseMultigraph<String, RefType>(); + + public StateSpace getStatespace() { + return statespace; + } + + public abstract AbstractElement getComponent(String name); + + // This is needed for the graph representation + public abstract Map<String, AbstractElement> getComponents(); + + public DirectedSparseMultigraph<String, RefType> getGraph() { + return graph; + } + + public ERefType getRelationship(final String comp1, final String comp2) { + return getEdge(comp1, comp2); + } + + public ERefType getEdge(final String comp1, final String comp2) { + final RefType edge = graph.findEdge(comp1, comp2); + if (edge == null) { + return null; + } + + return edge.getRelationship(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("("); + sb.append(graph.getVertices().toString()); + sb.append(", "); + + Collection<RefType> edges = graph.getEdges(); + List<String> s = new ArrayList<String>(); + for (RefType refType : edges) { + String src = graph.getSource(refType); + String dest = graph.getDest(refType); + s.add(refType.toString()+"=("+src+","+dest+")"); + } + sb.append(s.toString()); + sb.append(")"); + + return sb.toString(); + } + + public Object asType(final Class<?> className) { + if (className.getSimpleName().equals("StateSpace")) { + return statespace; + } + if (className.getSimpleName().equals("History")) { + return new History(statespace); + } + throw new ClassCastException("No element of type " + className + + " found."); + } + + public abstract StateSchema getStateSchema(); + + public abstract AbstractElement getMainComponent(); + + public File getModelFile() { + return modelFile; + } +} diff --git a/de.prob.core/representation/Action.java b/de.prob.core/representation/Action.java new file mode 100644 index 0000000000000000000000000000000000000000..5950f5e4431da0186991409d0e8c2d44bde5f179 --- /dev/null +++ b/de.prob.core/representation/Action.java @@ -0,0 +1,19 @@ +package de.prob.model.representation; + +public abstract class Action extends AbstractElement { + + private final String code; + + public Action(final String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @Override + public String toString() { + return code; + } +} diff --git a/de.prob.core/representation/Axiom.java b/de.prob.core/representation/Axiom.java new file mode 100644 index 0000000000000000000000000000000000000000..d76f5fa2b3fe1dad5fe86cfdb244a1f11cebdec1 --- /dev/null +++ b/de.prob.core/representation/Axiom.java @@ -0,0 +1,27 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.unicode.UnicodeTranslator; + +public abstract class Axiom extends AbstractElement implements IEval { + + private final IEvalElement predicate; + + public Axiom(final IEvalElement predicate) { + this.predicate = predicate; + } + + public IEvalElement getPredicate() { + return predicate; + } + + @Override + public IEvalElement getEvaluate() { + return predicate; + } + + @Override + public String toString() { + return UnicodeTranslator.toUnicode(predicate.getCode()); + } +} diff --git a/de.prob.core/representation/BEvent.java b/de.prob.core/representation/BEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..ccea9c12a7972c11f2dd100d634946d9fd0be888 --- /dev/null +++ b/de.prob.core/representation/BEvent.java @@ -0,0 +1,20 @@ +package de.prob.model.representation; + + +public abstract class BEvent extends AbstractElement { + + private final String name; + + public BEvent(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/de.prob.core/representation/BSet.java b/de.prob.core/representation/BSet.java new file mode 100644 index 0000000000000000000000000000000000000000..44040c771baff1d07714d72d6d5b5459f797dfde --- /dev/null +++ b/de.prob.core/representation/BSet.java @@ -0,0 +1,19 @@ +package de.prob.model.representation; + +public class BSet extends AbstractElement { + + private final String name; + + public BSet(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/de.prob.core/representation/Constant.java b/de.prob.core/representation/Constant.java new file mode 100644 index 0000000000000000000000000000000000000000..87596beeb4850111eba6a1f0b53ebe9cd6c49dde --- /dev/null +++ b/de.prob.core/representation/Constant.java @@ -0,0 +1,40 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.EvaluationResult; +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.statespace.History; +import de.prob.unicode.UnicodeTranslator; + +public abstract class Constant extends AbstractElement implements IEval { + + protected final IEvalElement expression; + protected EvaluationResult result; + + public Constant(final IEvalElement expression) { + this.expression = expression; + } + + public IEvalElement getExpression() { + return expression; + } + + @Override + public IEvalElement getEvaluate() { + return expression; + } + + @Override + public String toString() { + return UnicodeTranslator.toUnicode(expression.getCode()); + } + + // Experimental. Would allow the user to calculate the value once and cache + // it. + public EvaluationResult getValue(final History h) { + if (result == null) { + result = h.evalCurrent(getEvaluate()); + } + return result; + } + +} diff --git a/de.prob.core/representation/FormulaUUID.java b/de.prob.core/representation/FormulaUUID.java new file mode 100644 index 0000000000000000000000000000000000000000..d84d6c7f28c2e427f674ea6a367dda9f9beb7056 --- /dev/null +++ b/de.prob.core/representation/FormulaUUID.java @@ -0,0 +1,6 @@ +package de.prob.model.representation; + +public class FormulaUUID { + static int count = 0; + public final String uuid = "Formula_" + (++count); +} diff --git a/de.prob.core/representation/Guard.java b/de.prob.core/representation/Guard.java new file mode 100644 index 0000000000000000000000000000000000000000..b6574defafa1be14be6a40e3634d6eaadbc6fc5b --- /dev/null +++ b/de.prob.core/representation/Guard.java @@ -0,0 +1,26 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; + +public abstract class Guard extends AbstractElement implements IEval { + + private final IEvalElement predicate; + + public Guard(final IEvalElement predicate) { + this.predicate = predicate; + } + + public IEvalElement getPredicate() { + return predicate; + } + + @Override + public IEvalElement getEvaluate() { + return predicate; + } + + @Override + public String toString() { + return predicate.toString(); + } +} diff --git a/de.prob.core/representation/IEval.java b/de.prob.core/representation/IEval.java new file mode 100644 index 0000000000000000000000000000000000000000..5dddd32727290ff31ce1f30600881d51017f217c --- /dev/null +++ b/de.prob.core/representation/IEval.java @@ -0,0 +1,7 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; + +public interface IEval { + public IEvalElement getEvaluate(); +} diff --git a/de.prob.core/representation/Invariant.java b/de.prob.core/representation/Invariant.java new file mode 100644 index 0000000000000000000000000000000000000000..18de7013a3dbd0ea2dca52b793260c0ae4bc41fa --- /dev/null +++ b/de.prob.core/representation/Invariant.java @@ -0,0 +1,28 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.unicode.UnicodeTranslator; + +public abstract class Invariant extends AbstractElement implements IEval { + + private final IEvalElement predicate; + + public Invariant(final IEvalElement predicate) { + this.predicate = predicate; + } + + public IEvalElement getPredicate() { + return predicate; + } + + @Override + public IEvalElement getEvaluate() { + return predicate; + } + + @Override + public String toString() { + return UnicodeTranslator.toUnicode(predicate.getCode()); + } + +} diff --git a/de.prob.core/representation/Machine.java b/de.prob.core/representation/Machine.java new file mode 100644 index 0000000000000000000000000000000000000000..c5cad197b3fad9fc15cee1f4c9ab76f8da70029e --- /dev/null +++ b/de.prob.core/representation/Machine.java @@ -0,0 +1,19 @@ +package de.prob.model.representation; + +public abstract class Machine extends AbstractElement { + + private final String name; + + public Machine(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/de.prob.core/representation/RefType.java b/de.prob.core/representation/RefType.java new file mode 100644 index 0000000000000000000000000000000000000000..192a8a4aafe21eb232ada4f0045f5b0c4e6e2b1d --- /dev/null +++ b/de.prob.core/representation/RefType.java @@ -0,0 +1,28 @@ +package de.prob.model.representation; + +public class RefType { + private final ERefType relationship; + + /* + * RefType is used for both ClassicalBModels and EventBModels + * + * ClassicalB: SEES, USES, REFINES, INCLUDES, IMPORTS EventB: SEES, REFINES, + * EXTENDS + */ + public enum ERefType { + SEES, USES, REFINES, INCLUDES, IMPORTS, EXTENDS + } + + public RefType(final ERefType relationship) { + this.relationship = relationship; + } + + @Override + public String toString() { + return relationship.toString(); + } + + public ERefType getRelationship() { + return relationship; + } +} diff --git a/de.prob.core/representation/StateSchema.java b/de.prob.core/representation/StateSchema.java new file mode 100644 index 0000000000000000000000000000000000000000..52f97690b9232ee8263766af00cb05ed825d63bc --- /dev/null +++ b/de.prob.core/representation/StateSchema.java @@ -0,0 +1,6 @@ +package de.prob.model.representation; + +public interface StateSchema { + public Object[] getElements(Object o); + public boolean hasChildren(Object o); +} diff --git a/de.prob.core/representation/Variable.java b/de.prob.core/representation/Variable.java new file mode 100644 index 0000000000000000000000000000000000000000..098bb5e99ca13b0c0a03145680191ea1aeaace6c --- /dev/null +++ b/de.prob.core/representation/Variable.java @@ -0,0 +1,31 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.unicode.UnicodeTranslator; + +public abstract class Variable extends AbstractElement implements IEval { + + protected final IEvalElement expression; + + public Variable(final IEvalElement expression) { + this.expression = expression; + } + + public IEvalElement getExpression() { + return expression; + } + + @Override + public IEvalElement getEvaluate() { + return expression; + } + + public String getName() { + return expression.getCode(); + } + + @Override + public String toString() { + return UnicodeTranslator.toUnicode(expression.getCode()); + } +} diff --git a/de.prob.core/schema/de.prob.translator.exsd b/de.prob.core/schema/de.prob.translator.exsd new file mode 100644 index 0000000000000000000000000000000000000000..90efcf3ea4b5913068fc906cd4a9206a2d2860b1 --- /dev/null +++ b/de.prob.core/schema/de.prob.translator.exsd @@ -0,0 +1,109 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="de.prob.core" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="de.prob.core" id="de.prob.translator" name="Translator Extensions"/> + </appInfo> + <documentation> + [Enter description of this extension point.] + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence minOccurs="0" maxOccurs="unbounded"> + <element ref="translator"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="translator"> + <complexType> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":de.prob.core.translator.IExternalTranslator"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + [Enter the first release in which this extension point appears.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="examples"/> + </appInfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="apiinfo"/> + </appInfo> + <documentation> + [Enter API information here.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="implementation"/> + </appInfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + +</schema> diff --git a/de.prob.core/src/de/prob/animator/domainobjects/EvaluationResult.java b/de.prob.core/src/de/prob/animator/domainobjects/EvaluationResult.java new file mode 100644 index 0000000000000000000000000000000000000000..fb5ce98a7c77defd6ad8ee03b1b86cad06c52d25 --- /dev/null +++ b/de.prob.core/src/de/prob/animator/domainobjects/EvaluationResult.java @@ -0,0 +1,102 @@ +package de.prob.animator.domainobjects; + +import java.util.Arrays; +import java.util.List; + +/** + * This is what is saved when a formula ({@link IEvalElement}) is executed in + * the StateSpace + * + * @author joy + * + */ +public class EvaluationResult { + + public final String value; + public final String solution; + public final String errors; + public final String code; + public final String explanation; + private final String resultType; + private final List<String> quantifiedVars; + private final boolean enumerationWarnings; + private final String stateid; + + public EvaluationResult(final String stateid, final String code, + final String value, final String solution, final String errors, + final String resultType, final List<String> quantifiedVars, + final boolean enumerationWarnings) { + this.stateid = stateid; + this.code = code; + this.value = value; + this.solution = solution; + this.errors = errors; + this.resultType = resultType; + this.quantifiedVars = quantifiedVars; + this.enumerationWarnings = enumerationWarnings; + if (!solutionMode(resultType) && "TRUE".equals(value)) { + this.explanation = "Solution"; + } else { + this.explanation = solutionMode(resultType) ? " Solution: " + : " Counterexample: "; + } + } + + public EvaluationResult(final String stateid, final String code, + final String value, final String solution, final String errors, + final String resultType, final String[] strings, + final boolean enumerationWarnings) { + this(stateid, code, value, solution, errors, resultType, Arrays + .asList(strings), enumerationWarnings); + } + + private boolean solutionMode(final String arg0) { + return "exists".equals(arg0); + } + + public String getResultType() { + return resultType; + } + + public List<String> getQuantifiedVars() { + return quantifiedVars; + } + + public boolean hasEnumerationWarnings() { + return enumerationWarnings; + } + + public boolean hasError() { + return errors != null && !errors.isEmpty(); // You're kidding, aren't + // you? ;-) + } + + public String getErrors() { + return errors; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + final String result; + if (hasError()) { + result = "'Errors: " + errors + "'"; + } else { + result = (solution == null || solution.equals("")) ? value : value + + explanation + solution; + } + return result; + } + + public String getStateId() { + return stateid; + } + + public String getStateid() { + return stateid; + } + +} diff --git a/de.prob.core/src/de/prob/animator/domainobjects/EventB.java b/de.prob.core/src/de/prob/animator/domainobjects/EventB.java new file mode 100644 index 0000000000000000000000000000000000000000..08ff51770bf26234da85372392ed8ff9978aa3fe --- /dev/null +++ b/de.prob.core/src/de/prob/animator/domainobjects/EventB.java @@ -0,0 +1,127 @@ +package de.prob.animator.domainobjects; + +import static de.prob.animator.domainobjects.EvalElementType.EXPRESSION; +import static de.prob.animator.domainobjects.EvalElementType.PREDICATE; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import org.eventb.core.ast.ASTProblem; +import org.eventb.core.ast.Expression; +import org.eventb.core.ast.FormulaFactory; +import org.eventb.core.ast.IParseResult; +import org.eventb.core.ast.LanguageVersion; +import org.eventb.core.ast.Predicate; + +import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; +import de.be4.classicalb.core.parser.node.Node; +import de.prob.model.representation.FormulaUUID; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.unicode.UnicodeTranslator; + +/** + * Representation of an Event-B formula + * + * @author joy + * + */ +public class EventB implements IEvalElement { + + public FormulaUUID uuid = new FormulaUUID(); + + private final String code; + private String kind; + private Node ast = null; + + /** + * @param code + * - The String which is a representation of the desired Event-B + * formula + */ + public EventB(final String code) { + this.code = UnicodeTranslator.toAscii(code); + } + + private void ensureParsed() { +// final String unicode = UnicodeTranslator.toUnicode(code); +// kind = PREDICATE.toString(); +// IParseResult parseResult = FormulaFactory.getDefault().parsePredicate( +// unicode, LanguageVersion.LATEST, null); +// +// if (!parseResult.hasProblem()) { +// ast = preparePredicateAst(parseResult); +// +// } else { +// kind = EXPRESSION.toString(); +// parseResult = FormulaFactory.getDefault().parseExpression(unicode, +// LanguageVersion.LATEST, null); +// ast = prepareExpressionAst(parseResult); +// } +// if (parseResult.hasProblem()) { +// throwException(code, parseResult); +// } + } + +// private Node prepareExpressionAst(final IParseResult parseResult) { +// final Expression expr = parseResult.getParsedExpression(); +// final ExpressionVisitor visitor = new ExpressionVisitor( +// new LinkedList<String>()); +// expr.accept(visitor); +// final Node expression = visitor.getExpression(); +// return expression; +// } +// +// private Node preparePredicateAst(final IParseResult parseResult) { +// final Predicate parsedPredicate = parseResult.getParsedPredicate(); +// final PredicateVisitor visitor = new PredicateVisitor(); +// parsedPredicate.accept(visitor); +// return visitor.getPredicate(); +// } +// +// private void throwException(final String code, +// final IParseResult parseResult) { +// final List<ASTProblem> problems = parseResult.getProblems(); +// final ArrayList<String> msgs = new ArrayList<String>(); +// for (final ASTProblem astProblem : problems) { +// msgs.add(astProblem.getMessage().toString()); +// } +// final String error = Joiner.on(", \n").join(msgs); +// throw new EvaluationException("Cannot parse " + code + ":\n " + error); +// } + + @Override + public String getCode() { + return code; + } + + @Override + public boolean equals(final Object that) { + if (that instanceof EventB) { + return ((EventB) that).getCode().equals(this.getCode()); + } + return false; + } + + @Override + public void printProlog(final IPrologTermOutput pout) { + if (ast == null) { + ensureParsed(); + } + + assert ast != null; + final ASTProlog prolog = new ASTProlog(pout, null); + ast.apply(prolog); + } + + @Override + public String getKind() { + return kind; + } + + @Override + public String toString() { + return getCode(); + } + +} diff --git a/de.prob.core/src/de/prob/core/command/ActivateUnitPluginCommand.java b/de.prob.core/src/de/prob/core/command/ActivateUnitPluginCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..5071e60e1f179908b6a1d438c12b818c408407ac --- /dev/null +++ b/de.prob.core/src/de/prob/core/command/ActivateUnitPluginCommand.java @@ -0,0 +1,57 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.command; + +import de.prob.core.Animator; +import de.prob.exceptions.ProBException; +import de.prob.parser.ISimplifiedROMap; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.PrologTerm; + +public class ActivateUnitPluginCommand implements IComposableCommand { + + private static final ActivateCmd ACTIVATE_CMD = new ActivateCmd(); + private final GetPrologRandomSeed getRandomSeed; + private final ComposedCommand cmd; + + public ActivateUnitPluginCommand() { + this.getRandomSeed = new GetPrologRandomSeed(); + this.cmd = new ComposedCommand(getRandomSeed, ACTIVATE_CMD); + } + + public static void activateUnitPlugin(final Animator animator) + throws ProBException { + animator.execute(new ActivateUnitPluginCommand()); + } + + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + cmd.processResult(bindings); + final Animator animator = Animator.getAnimator(); + animator.setRandomSeed(getRandomSeed.getSeed()); + } + + public void writeCommand(final IPrologTermOutput pto) + throws CommandException { + cmd.writeCommand(pto); + } + + private final static class ActivateCmd implements IComposableCommand { + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + } + + public void writeCommand(final IPrologTermOutput pto) { + pto.openTerm("activate_plugin"); + pto.printAtom("units"); + pto.closeTerm(); + } + } + +} diff --git a/de.prob.core/src/de/prob/core/command/CheckInitialisationStatusCommand.java b/de.prob.core/src/de/prob/core/command/CheckInitialisationStatusCommand.java index 34c7e350772a5df5399e9a2bbdddc86eb3c0de01..ae065c4390c5d7a519558cbf3ccad184b09f071c 100644 --- a/de.prob.core/src/de/prob/core/command/CheckInitialisationStatusCommand.java +++ b/de.prob.core/src/de/prob/core/command/CheckInitialisationStatusCommand.java @@ -12,7 +12,7 @@ import de.prob.exceptions.ProBException; public final class CheckInitialisationStatusCommand extends CheckBooleanPropertyCommand { - private static final String IS_INITIALISED_STATE = "isInitialisedState"; + private static final String IS_INITIALISED_STATE = "initialised"; public static boolean isInitialized(final Animator a, final String stateId) throws ProBException { @@ -21,7 +21,7 @@ public final class CheckInitialisationStatusCommand extends } public CheckInitialisationStatusCommand(final String stateId) { - super("initialised", stateId); + super(IS_INITIALISED_STATE, stateId); } } diff --git a/de.prob.core/src/de/prob/core/command/ConsistencyCheckingSearchOption.java b/de.prob.core/src/de/prob/core/command/ConsistencyCheckingSearchOption.java index 13338e27fd2304f0a2da7047d1c0491d2af95daa..736dafe4339083790eff9ebb234ab5766ba94d49 100644 --- a/de.prob.core/src/de/prob/core/command/ConsistencyCheckingSearchOption.java +++ b/de.prob.core/src/de/prob/core/command/ConsistencyCheckingSearchOption.java @@ -18,7 +18,7 @@ public enum ConsistencyCheckingSearchOption { find_deadlocks(1,"Find Deadlocks", true), find_invariant_violations(2,"Find Invariant Violations", true), find_assertion_violations(3,"Find Theorem Violations", false), - not_inspect_existing_nodes(4,"Search for New Errors", false); + inspect_existing_nodes(4,"Recheck existing states", false); private final String text; private final int pos; diff --git a/de.prob.core/src/de/prob/core/command/ConstraintBasedAssertionCheckCommand.java b/de.prob.core/src/de/prob/core/command/ConstraintBasedAssertionCheckCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..5b17b6305645278641a89f67ab5ca611c1a8ad53 --- /dev/null +++ b/de.prob.core/src/de/prob/core/command/ConstraintBasedAssertionCheckCommand.java @@ -0,0 +1,76 @@ +/** + * + */ +package de.prob.core.command; + +import de.prob.core.domainobjects.Operation; +import de.prob.parser.ISimplifiedROMap; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.CompoundPrologTerm; +import de.prob.prolog.term.PrologTerm; + +/** + * This command makes ProB search for a deadlock with an optional predicate to + * limit the search space. + * + * @author plagge + */ +public class ConstraintBasedAssertionCheckCommand implements IComposableCommand { + + public static enum ResultType { + INTERRUPTED, COUNTER_EXAMPLE, NO_COUNTER_EXAMPLE + }; + + private static final String COMMAND_NAME = "cbc_static_assertion_violation_checking"; + private static final String RESULT_VARIABLE = "R"; + + private ResultType result; + private Operation counterExampleOperation; + private String counterExampleStateID; + + public ConstraintBasedAssertionCheckCommand() { + } + + public ResultType getResult() { + return result; + } + + public Operation getCounterExampleOperation() { + return counterExampleOperation; + } + + public String getCounterExampleStateID() { + return counterExampleStateID; + } + + @Override + public void writeCommand(final IPrologTermOutput pto) { + pto.openTerm(COMMAND_NAME); + pto.printVariable(RESULT_VARIABLE); + pto.closeTerm(); + } + + @Override + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + final PrologTerm resultTerm = bindings.get(RESULT_VARIABLE); + final ResultType result; + if (resultTerm.hasFunctor("interrupted", 0)) { + result = ResultType.INTERRUPTED; + } else if (resultTerm.hasFunctor("no_counterexample_found", 0)) { + result = ResultType.NO_COUNTER_EXAMPLE; + } else if (resultTerm.hasFunctor("counterexample_found", 2)) { + result = ResultType.COUNTER_EXAMPLE; + CompoundPrologTerm counterExampleTerm = (CompoundPrologTerm) resultTerm; + counterExampleOperation = Operation + .fromPrologTerm(counterExampleTerm.getArgument(1)); + counterExampleStateID = counterExampleTerm.getArgument(2) + .toString(); + } else + throw new CommandException( + "unexpected result from deadlock check: " + resultTerm); + this.result = result; + + } +} diff --git a/de.prob.core/src/de/prob/core/command/ConstraintBasedRefinementCheckCommand.java b/de.prob.core/src/de/prob/core/command/ConstraintBasedRefinementCheckCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..a86dd0703dd412ae26bda8c117c9974c67b97183 --- /dev/null +++ b/de.prob.core/src/de/prob/core/command/ConstraintBasedRefinementCheckCommand.java @@ -0,0 +1,95 @@ +/** + * + */ +package de.prob.core.command; + +import de.prob.core.domainobjects.Operation; +import de.prob.parser.ISimplifiedROMap; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.ListPrologTerm; +import de.prob.prolog.term.PrologTerm; + +public class ConstraintBasedRefinementCheckCommand implements + IComposableCommand { + + public static enum ResultType { + VIOLATION_FOUND, NO_VIOLATION_FOUND, INTERRUPTED + }; + + public static class RefinementCheckCounterExample { + private final String eventName; + private final Operation step1, step2; + + public RefinementCheckCounterExample(final String eventName, + final Operation step1, final Operation step2) { + this.eventName = eventName; + this.step1 = step1; + this.step2 = step2; + } + + public String getEventName() { + return eventName; + } + + public Operation getStep1() { + return step1; + } + + public Operation getStep2() { + return step2; + } + } + + private static final String COMMAND_NAME = "refinement_check"; + private static final String RESULT_VARIABLE = "R"; + private static final String RESULT_STRINGS_VARIABLE = "S"; + + private ResultType result; + private String resultsString = ""; + + public ConstraintBasedRefinementCheckCommand() { + } + + public ResultType getResult() { + return result; + } + + @Override + public void writeCommand(final IPrologTermOutput pto) { + pto.openTerm(COMMAND_NAME); + pto.printVariable(RESULT_STRINGS_VARIABLE); + pto.printVariable(RESULT_VARIABLE); + pto.closeTerm(); + } + + @Override + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + final PrologTerm resultTerm = bindings.get(RESULT_VARIABLE); + final ResultType result; + + final ListPrologTerm resultStringTerm = (ListPrologTerm) bindings + .get(RESULT_STRINGS_VARIABLE); + + for (PrologTerm t : resultStringTerm) { + resultsString += PrologTerm.atomicString(t) + "\n"; + } + + if (resultTerm.hasFunctor("time_out", 0)) { + result = ResultType.INTERRUPTED; + } else if (resultTerm.hasFunctor("true", 0)) { // Errors were found + result = ResultType.VIOLATION_FOUND; + // TODO extract message + } else if (resultTerm.hasFunctor("false", 0)) { // Errors were found + result = ResultType.NO_VIOLATION_FOUND; + } else + throw new CommandException( + "unexpected result from refinement check: " + resultTerm); + this.result = result; + } + + public String getResultsString() { + return resultsString; + } +} diff --git a/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java b/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..7e28630bcfeb68b3da763a24c6bae25b8e93fd85 --- /dev/null +++ b/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java @@ -0,0 +1,50 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.command; + +import de.prob.parser.BindingGenerator; +import de.prob.parser.ISimplifiedROMap; +import de.prob.parser.ResultParserException; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.CompoundPrologTerm; +import de.prob.prolog.term.PrologTerm; + +public final class GetPluginResultCommand implements IComposableCommand { + + private final String resultID; + private CompoundPrologTerm result; + + public GetPluginResultCommand(final String resultID) { + this.resultID = resultID; + } + + public CompoundPrologTerm getResult() { + return result; + } + + @Override + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + try { + result = BindingGenerator.getCompoundTerm(bindings.get("Bindings"), + 1); + } catch (ResultParserException e) { + CommandException commandException = new CommandException( + e.getLocalizedMessage(), e); + commandException.notifyUserOnce(); + throw commandException; + } + } + + @Override + public void writeCommand(final IPrologTermOutput pto) { + pto.openTerm("get_plugin_output").printAtomOrNumber(resultID) + .printVariable("Bindings").closeTerm(); + } + +} diff --git a/de.prob.core/src/de/prob/core/command/LoadEventBModelCommand.java b/de.prob.core/src/de/prob/core/command/LoadEventBModelCommand.java index 316d436cfb029a75fd3232548ee3415f178854a1..78335f27dbe8219e1129b5286e771ac514283b15 100644 --- a/de.prob.core/src/de/prob/core/command/LoadEventBModelCommand.java +++ b/de.prob.core/src/de/prob/core/command/LoadEventBModelCommand.java @@ -19,17 +19,15 @@ import org.rodinp.core.RodinDBException; import de.prob.core.Animator; import de.prob.core.LanguageDependendAnimationPart; +import de.prob.core.command.internal.InternalLoadCommand; import de.prob.core.domainobjects.MachineDescription; import de.prob.core.domainobjects.Operation; import de.prob.core.domainobjects.ProBPreference; import de.prob.core.domainobjects.State; import de.prob.core.langdep.EventBAnimatorPart; -import de.prob.core.translator.TranslationFailedException; -import de.prob.eventb.translator.TranslatorFactory; import de.prob.exceptions.ProBException; import de.prob.logging.Logger; import de.prob.parser.ISimplifiedROMap; -import de.prob.prolog.output.IPrologTermOutput; import de.prob.prolog.output.StructuredPrologOutput; import de.prob.prolog.term.PrologTerm; @@ -162,32 +160,4 @@ public final class LoadEventBModelCommand { animator.announceReset(); } } - - private static class InternalLoadCommand implements IComposableCommand { - private final IEventBRoot model; - - public InternalLoadCommand(final IEventBRoot model) { - this.model = model; - } - - @Override - public void writeCommand(final IPrologTermOutput pto) - throws CommandException { - try { - TranslatorFactory.translate(model, pto); - } catch (TranslationFailedException e) { - throw new CommandException( - "Translation from Event-B to ProB's internal representation failed", - e); - } - } - - @Override - public void processResult( - final ISimplifiedROMap<String, PrologTerm> bindings) - throws CommandException { - // there are no results to process - } - - } } diff --git a/de.prob.core/src/de/prob/core/command/internal/InternalLoadCommand.java b/de.prob.core/src/de/prob/core/command/internal/InternalLoadCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..2a3eaf98d4fd0b82a4a4718c0878d2366bf08e67 --- /dev/null +++ b/de.prob.core/src/de/prob/core/command/internal/InternalLoadCommand.java @@ -0,0 +1,39 @@ +package de.prob.core.command.internal; + +import org.eventb.core.IEventBRoot; + +import de.prob.core.command.CommandException; +import de.prob.core.command.IComposableCommand; +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; +import de.prob.parser.ISimplifiedROMap; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.PrologTerm; + +public final class InternalLoadCommand implements IComposableCommand { + private final IEventBRoot model; + + public InternalLoadCommand(final IEventBRoot model) { + this.model = model; + } + + @Override + public void writeCommand(final IPrologTermOutput pto) + throws CommandException { + try { + TranslatorFactory.translate(model, pto); + } catch (TranslationFailedException e) { + throw new CommandException( + "Translation from Event-B to ProB's internal representation failed", + e); + } + } + + @Override + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + // there are no results to process + } + +} \ No newline at end of file diff --git a/de.prob.core/src/de/prob/core/langdep/EventBAnimatorPart.java b/de.prob.core/src/de/prob/core/langdep/EventBAnimatorPart.java index c19e65af4bc6ee1b3faba6410831d3cee874c8c2..21a6fb5e9067cf7b5410451569998de28fa33556 100644 --- a/de.prob.core/src/de/prob/core/langdep/EventBAnimatorPart.java +++ b/de.prob.core/src/de/prob/core/langdep/EventBAnimatorPart.java @@ -262,7 +262,7 @@ public class EventBAnimatorPart implements LanguageDependendAnimationPart { private ProBParseException rodin2parseException(final RodinDBException e) { return new ProBParseException( - "Error in the underlying Rodin Database: " + "Error in the underlying Rodin Database.\nTry cleaning your workspace.\n Details: " + e.getLocalizedMessage()); } diff --git a/de.prob.core/src/de/prob/core/translator/IExternalTranslator.java b/de.prob.core/src/de/prob/core/translator/IExternalTranslator.java new file mode 100644 index 0000000000000000000000000000000000000000..d01511727a1c9d8cd430d91b88066da528ecce67 --- /dev/null +++ b/de.prob.core/src/de/prob/core/translator/IExternalTranslator.java @@ -0,0 +1,7 @@ +package de.prob.core.translator; + +import de.prob.prolog.output.PrologTermOutput; + +public interface IExternalTranslator { + public void writeProlog(PrologTermOutput pto); +} diff --git a/de.prob.core/src/de/prob/core/translator/TranslationFailedException.java b/de.prob.core/src/de/prob/core/translator/TranslationFailedException.java index bb5a1fb6e8b3b20d2032f27880866b171dbffd1a..8e64fd2ee26e5a0b8be344e400e2330567629e58 100644 --- a/de.prob.core/src/de/prob/core/translator/TranslationFailedException.java +++ b/de.prob.core/src/de/prob/core/translator/TranslationFailedException.java @@ -18,8 +18,12 @@ public class TranslationFailedException extends ProBException { public TranslationFailedException(final String component, final String details) { - super("Translation of " + component + " failed\n" + details); - notifyUserOnce(); + this(component, details, null); } + public TranslationFailedException(final String component, + final String details, Throwable e) { + super("Translation of " + component + " failed.\nTry cleaning your workspace.\nDetails: \n" + details, e, false); + notifyUserOnce(); + } } diff --git a/de.prob.core/src/de/prob/core/translator/pragmas/IPragma.java b/de.prob.core/src/de/prob/core/translator/pragmas/IPragma.java new file mode 100644 index 0000000000000000000000000000000000000000..aa8994a965629cc4da6ca5c395c7a05cfcb83512 --- /dev/null +++ b/de.prob.core/src/de/prob/core/translator/pragmas/IPragma.java @@ -0,0 +1,15 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.translator.pragmas; + +import de.prob.prolog.output.IPrologTermOutput; + +public interface IPragma { + + void output(IPrologTermOutput pout); + +} diff --git a/de.prob.core/src/de/prob/core/translator/pragmas/SymbolicPragma.java b/de.prob.core/src/de/prob/core/translator/pragmas/SymbolicPragma.java new file mode 100644 index 0000000000000000000000000000000000000000..4756d2ceced52de767fc7e6b5f14f680c0cb55da --- /dev/null +++ b/de.prob.core/src/de/prob/core/translator/pragmas/SymbolicPragma.java @@ -0,0 +1,31 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.translator.pragmas; + +import de.prob.prolog.output.IPrologTermOutput; + +public class SymbolicPragma implements IPragma { + private final String definedIn; + private final String attachedTo; + + public SymbolicPragma(String definedIn, String attachedTo) { + this.definedIn = definedIn; + this.attachedTo = attachedTo; + } + + @Override + public void output(IPrologTermOutput pout) { + pout.openTerm("pragma"); + pout.printAtom("symbolic"); + pout.printAtom(definedIn); + pout.printAtom(attachedTo); + pout.openList(); + pout.closeList(); + pout.closeTerm(); + } + +} diff --git a/de.prob.core/src/de/prob/core/translator/pragmas/UnitPragma.java b/de.prob.core/src/de/prob/core/translator/pragmas/UnitPragma.java new file mode 100644 index 0000000000000000000000000000000000000000..a1b5fd09d13a81b4e05149e7ca95aae0a2c76acd --- /dev/null +++ b/de.prob.core/src/de/prob/core/translator/pragmas/UnitPragma.java @@ -0,0 +1,34 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.translator.pragmas; + +import de.prob.prolog.output.IPrologTermOutput; + +public class UnitPragma implements IPragma { + private String definedIn; + private String attachedTo; + private String content; + + public UnitPragma(String definedIn, String attachedTo, String content) { + this.definedIn = definedIn; + this.attachedTo = attachedTo; + this.content = content; + } + + @Override + public void output(IPrologTermOutput pout) { + pout.openTerm("pragma"); + pout.printAtom("unit"); + pout.printAtom(definedIn); + pout.printAtom(attachedTo); + pout.openList(); + pout.printAtom(content); + pout.closeList(); + pout.closeTerm(); + } + +} diff --git a/de.prob.core/src/de/prob/eventb/translator/AbstractComponentTranslator.java b/de.prob.core/src/de/prob/eventb/translator/AbstractComponentTranslator.java index 5e64e8e77dfd79a432892d127cd75f5725e3e2fc..8c4ef9e17212212b280d61f9bb9e72d6246a3b3d 100644 --- a/de.prob.core/src/de/prob/eventb/translator/AbstractComponentTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/AbstractComponentTranslator.java @@ -6,13 +6,32 @@ package de.prob.eventb.translator; +import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.eventb.core.ISCExpressionElement; +import org.eventb.core.ISCIdentifierElement; +import org.eventb.core.ISCPredicateElement; +import org.eventb.core.ast.Expression; +import org.eventb.core.ast.FormulaFactory; +import org.eventb.core.ast.ITypeEnvironment; +import org.eventb.core.ast.Predicate; +import org.rodinp.core.IAttributeType; import org.rodinp.core.IInternalElement; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; import de.be4.classicalb.core.parser.node.Node; +import de.be4.classicalb.core.parser.node.PExpression; +import de.be4.classicalb.core.parser.node.PPredicate; +import de.prob.core.translator.pragmas.IPragma; +import de.prob.core.translator.pragmas.UnitPragma; +import de.prob.eventb.translator.internal.ProofObligation; +import de.prob.eventb.translator.internal.TranslationVisitor; public abstract class AbstractComponentTranslator { @@ -21,7 +40,82 @@ public abstract class AbstractComponentTranslator { public Map<Node, IInternalElement> getLabelMapping() { return Collections.unmodifiableMap(labelMapping); } - - abstract public String getResource(); + + private boolean theoryIsUsed = false; + private final List<IPragma> pragmas = new ArrayList<IPragma>(); + private final List<ProofObligation> proofs = new ArrayList<ProofObligation>(); + private final String resourceName; + + protected AbstractComponentTranslator(String resourceName) { + this.resourceName = resourceName; + } + + public String getResource() { + return resourceName; + } + + public List<IPragma> getPragmas() { + return Collections.unmodifiableList(pragmas); + } + + public List<ProofObligation> getProofs() { + return Collections.unmodifiableList(proofs); + } + + protected void addProof(ProofObligation po) { + proofs.add(po); + } + + protected void addUnitPragmas(ISCIdentifierElement[] elements) + throws RodinDBException { + try { + final IAttributeType.String UNITATTRIBUTE = RodinCore + .getStringAttrType("de.prob.units.unitPragmaAttribute"); + + for (final ISCIdentifierElement variable : elements) { + if (variable.hasAttribute(UNITATTRIBUTE)) { + String content = variable.getAttributeValue(UNITATTRIBUTE); + + if (!content.isEmpty()) { + pragmas.add(new UnitPragma(getResource(), variable + .getIdentifierString(), content)); + } + } + } + } catch (IllegalArgumentException ex) { + // Happens if the attribute does not exist, i.e. the unit plugin is + // not installed + } + } + + protected PPredicate translatePredicate(FormulaFactory ff, + final ITypeEnvironment env, final ISCPredicateElement predicate) + throws RodinDBException { + final PredicateVisitor visitor = new PredicateVisitor( + new LinkedList<String>()); + final Predicate pred = predicate.getPredicate(ff, env); + pred.accept(visitor); + final PPredicate result = visitor.getPredicate(); + theoryIsUsed |= TranslationVisitor.checkNewImplementation(pred, result); + return result; + } + + protected PExpression translateExpression(FormulaFactory ff, + final ITypeEnvironment env, final ISCExpressionElement expression) + throws RodinDBException { + final ExpressionVisitor visitor = new ExpressionVisitor( + new LinkedList<String>()); + final Expression expr = expression.getExpression(ff, env); + expr.accept(visitor); + final PExpression result = visitor.getExpression(); + theoryIsUsed |= TranslationVisitor.checkNewImplementation(expr, result); + return result; + } + + public boolean isTheoryUsed() { + return theoryIsUsed; + } + + abstract public Node getAST(); } \ No newline at end of file diff --git a/de.prob.core/src/de/prob/eventb/translator/ContextTranslator.java b/de.prob.core/src/de/prob/eventb/translator/ContextTranslator.java index 340c94557f3d396764624d39a1ab2a831fc80e26..eff85650268f94482c98f46d6fb92bb61927febb 100644 --- a/de.prob.core/src/de/prob/eventb/translator/ContextTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/ContextTranslator.java @@ -13,11 +13,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.eclipse.core.runtime.Assert; -import org.eventb.core.IAxiom; import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBRoot; import org.eventb.core.IExtendsContext; +import org.eventb.core.ILabeledElement; import org.eventb.core.IPOSequent; import org.eventb.core.IPOSource; import org.eventb.core.IPSRoot; @@ -29,16 +29,19 @@ import org.eventb.core.ISCContext; import org.eventb.core.ISCContextRoot; import org.eventb.core.ISCExtendsContext; import org.eventb.core.ISCInternalContext; -import org.eventb.core.ISCMachineRoot; import org.eventb.core.ast.FormulaFactory; import org.eventb.core.ast.ITypeEnvironment; import org.eventb.core.seqprover.IConfidence; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.IInternalElement; import org.rodinp.core.IRodinElement; import org.rodinp.core.IRodinFile; import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinCore; import org.rodinp.core.RodinDBException; import de.be4.classicalb.core.parser.analysis.pragma.internal.ClassifiedPragma; +import de.be4.classicalb.core.parser.node.AAbstractConstantsContextClause; import de.be4.classicalb.core.parser.node.AAxiomsContextClause; import de.be4.classicalb.core.parser.node.AConstantsContextClause; import de.be4.classicalb.core.parser.node.ADeferredSetSet; @@ -47,6 +50,7 @@ import de.be4.classicalb.core.parser.node.AExtendsContextClause; import de.be4.classicalb.core.parser.node.AIdentifierExpression; import de.be4.classicalb.core.parser.node.ASetsContextClause; import de.be4.classicalb.core.parser.node.ATheoremsContextClause; +import de.be4.classicalb.core.parser.node.Node; import de.be4.classicalb.core.parser.node.PContextClause; import de.be4.classicalb.core.parser.node.PExpression; import de.be4.classicalb.core.parser.node.PPredicate; @@ -54,8 +58,9 @@ import de.be4.classicalb.core.parser.node.PSet; import de.be4.classicalb.core.parser.node.TIdentifierLiteral; import de.hhu.stups.sablecc.patch.SourcePosition; import de.prob.core.translator.TranslationFailedException; -import de.prob.eventb.translator.internal.DischargedProof; -import de.prob.logging.Logger; +import de.prob.eventb.translator.internal.EProofStatus; +import de.prob.eventb.translator.internal.ProofObligation; +import de.prob.eventb.translator.internal.SequentSource; public final class ContextTranslator extends AbstractComponentTranslator { @@ -63,24 +68,72 @@ public final class ContextTranslator extends AbstractComponentTranslator { private final ISCContext context; private final AEventBContextParseUnit model = new AEventBContextParseUnit(); private final Map<String, ISCContext> depContext = new HashMap<String, ISCContext>(); - private final List<DischargedProof> proofs = new ArrayList<DischargedProof>(); private final List<ClassifiedPragma> proofspragmas = new ArrayList<ClassifiedPragma>(); + + private final IEventBRoot root; private final FormulaFactory ff; + private final ITypeEnvironment te; - // Confined in the thread calling the factory method - private ITypeEnvironment te; + public static ContextTranslator create(final ISCContextRoot context) + throws TranslationFailedException { + try { + assertConsistentModel(context); + final FormulaFactory ff = context.getFormulaFactory(); + final ITypeEnvironment te = context.getTypeEnvironment(ff); + final ContextTranslator translator = new ContextTranslator(context, + ff, te, context); + translator.translate(); + return translator; + } catch (RodinDBException e) { + throw createTranslationFailedException(context, e); + } + } - public static ContextTranslator create(final ISCContext context) + public static ContextTranslator create(final ISCInternalContext context, + final FormulaFactory ff, final ITypeEnvironment te) throws TranslationFailedException { - ContextTranslator contextTranslator = new ContextTranslator(context); + final IEventBRoot root = getRootContext(context); + final ContextTranslator translator = new ContextTranslator(context, ff, + te, root); try { - contextTranslator.translate(); + assertConsistentModel(context.getRoot()); + translator.translate(); } catch (RodinDBException e) { - final String message = "A Rodin exception occured during translation process. Possible cause: building aborted or still in progress. Please wait until building has finished before starting ProB. If this does not help, perform a clean and start ProB after building has finished. Original Exception: "; - throw new TranslationFailedException(context.getComponentName(), - message + e.getLocalizedMessage()); + throw createTranslationFailedException(context, e); + } + return translator; + } + + private static IEventBRoot getRootContext(ISCInternalContext context) { + try { + String elementName = context.getElementName(); + IRodinProject rodinProject = context.getRodinProject(); + IRodinFile rodinFile = rodinProject.getRodinFile(elementName + + ".bcc"); + if (rodinFile.exists()) { + final IInternalElement element = rodinFile.getRoot(); + if (element instanceof IEventBRoot) { + return (IEventBRoot) element; + } + } + } catch (Exception e) { + // We do not guarantee to include proof infos. If something goes + // wrong, we ignore the Proof info. } - return contextTranslator; + return null; + } + + private static TranslationFailedException createTranslationFailedException( + final ISCContext context, RodinDBException e) + throws TranslationFailedException { + final String message = "A Rodin exception occured during translation process. Possible cause: building aborted or still in progress. Please wait until building has finished before starting ProB. If this does not help, perform a clean and start ProB after building has finished. Original Exception: "; + return new TranslationFailedException(context.getComponentName(), + message + e.getLocalizedMessage()); + } + + private static boolean assertConsistentModel(IInternalElement machine_root) + throws RodinDBException { + return Assert.isTrue(machine_root.getRodinFile().isConsistent()); } /** @@ -90,49 +143,45 @@ public final class ContextTranslator extends AbstractComponentTranslator { * contains errors) * * @param context - * @throws RodinDBException + * The context to translate + * @param ff + * The FormulaFactory needed to extract the predicates + * @param te + * The TypeEnvironment needed to extract the predicates + * @param root + * the root to access the proofs + * @throws TranslationFailedException */ - private ContextTranslator(final ISCContext context) { + private ContextTranslator(final ISCContext context, + final FormulaFactory ff, final ITypeEnvironment te, + final IEventBRoot root) throws TranslationFailedException { + super(context.getComponentName()); this.context = context; - ff = FormulaFactory.getDefault(); + this.ff = ff; + this.te = te; + this.root = root; } private void translate() throws RodinDBException { - if (context instanceof ISCContextRoot) { - ISCContextRoot context_root = (ISCContextRoot) context; - Assert.isTrue(context_root.getRodinFile().isConsistent()); - te = context_root.getTypeEnvironment(ff); - collectProofInfo(context_root); - } else if (context instanceof ISCInternalContext) { - ISCInternalContext context_internal = (ISCInternalContext) context; - - try { + translateContext(); + collectProofInfo(); + collectPragmas(); + } - String elementName = context_internal.getElementName(); - IRodinProject rodinProject = context_internal.getRodinProject(); - IRodinFile rodinFile = rodinProject.getRodinFile(elementName - + ".bcc"); - if (rodinFile.exists()) { - ISCContextRoot root = (ISCContextRoot) rodinFile.getRoot(); - collectProofInfo(root); - } - } catch (Exception e) { - // We do not guarantee to include proof infos. If something goes - // wrong, we ignore the Proof info. - } + private void collectPragmas() throws RodinDBException { + // unit pragma, attached to constants + addUnitPragmas(context.getSCConstants()); + } - ISCMachineRoot machine_root = (ISCMachineRoot) context_internal - .getRoot(); - Assert.isTrue(machine_root.getRodinFile().isConsistent()); - te = machine_root.getTypeEnvironment(ff); + private void collectProofInfo() throws RodinDBException { + if (root != null) { + collectProofInfo(root); } - translateContext(); } - private void collectProofInfo(ISCContextRoot context_root) - throws RodinDBException { + private void collectProofInfo(IEventBRoot origin) throws RodinDBException { - IPSRoot proofStatus = context_root.getPSRoot(); + IPSRoot proofStatus = origin.getPSRoot(); IPSStatus[] statuses = proofStatus.getStatuses(); List<String> bugs = new LinkedList<String>(); @@ -140,34 +189,37 @@ public final class ContextTranslator extends AbstractComponentTranslator { for (IPSStatus status : statuses) { final int confidence = status.getConfidence(); boolean broken = status.isBroken(); - if (!broken && confidence == IConfidence.DISCHARGED_MAX) { - IPOSequent sequent = status.getPOSequent(); - IPOSource[] sources = sequent.getSources(); - - for (IPOSource source : sources) { - - IRodinElement srcElement = source.getSource(); - if (!srcElement.exists()) { - bugs.add(status.getElementName()); - break; - } - - if (srcElement instanceof IAxiom) { - IAxiom tmp = (IAxiom) srcElement; - if (((IContextRoot) tmp.getParent()) - .equals(context_root.getContextRoot())) { - proofs.add(new DischargedProof(context_root, tmp, - null)); - } - } + + EProofStatus pstatus = EProofStatus.UNPROVEN; + + if (!broken && confidence == IConfidence.REVIEWED_MAX) + pstatus = EProofStatus.REVIEWED; + if (!broken && confidence == IConfidence.DISCHARGED_MAX) + pstatus = EProofStatus.PROVEN; + + IPOSequent sequent = status.getPOSequent(); + IPOSource[] sources = sequent.getSources(); + + String name = sequent.getDescription(); + + ArrayList<SequentSource> s = new ArrayList<SequentSource>( + sources.length); + for (IPOSource source : sources) { + + IRodinElement srcElement = source.getSource(); + if (!srcElement.exists() + || !(srcElement instanceof ILabeledElement)) { + bugs.add(status.getElementName()); + break; } - } - } - if (!bugs.isEmpty()) { - String message = "Translation incomplete due to a Bug in Rodin. This does not affect correctness of the Animation/Model Checking but can decrease its performance. Skipped discharged information about: " - + StringUtils.join(bugs, ","); - Logger.notifyUser(message); + ILabeledElement le = (ILabeledElement) srcElement; + + s.add(new SequentSource(srcElement.getElementType(), le + .getLabel())); + + } + addProof(new ProofObligation(origin, s, name, pstatus)); } } @@ -185,7 +237,7 @@ public final class ContextTranslator extends AbstractComponentTranslator { final List<PContextClause> clauses = new ArrayList<PContextClause>(); clauses.add(processExtends()); - clauses.add(processConstants()); + clauses.addAll(processConstants()); clauses.add(processAxioms()); clauses.add(processTheorems()); clauses.add(processSets()); @@ -273,19 +325,50 @@ public final class ContextTranslator extends AbstractComponentTranslator { return new ASetsContextClause(setList); } - private AConstantsContextClause processConstants() throws RodinDBException { + private List<PContextClause> processConstants() throws RodinDBException { final ISCConstant[] constants = context.getSCConstants(); - final List<PExpression> list = new ArrayList<PExpression>( + + final List<PExpression> concreteConstants = new ArrayList<PExpression>( + constants.length); + final List<PExpression> abstractConstants = new ArrayList<PExpression>( constants.length); + for (final ISCConstant constant : constants) { - list.add(new AIdentifierExpression(Arrays - .asList(new TIdentifierLiteral[] { new TIdentifierLiteral( - constant.getIdentifierString()) }))); + boolean isAbstractConstant = false; + + // try if the attribute exists and is set + // if the symbolic evaluation plugin is not installed + // Rodin throws an IllegalArgumentException + try { + final IAttributeType.Boolean ATTRIBUTE = RodinCore + .getBooleanAttrType("de.prob.symbolic.symbolicAttribute"); + if (constant.hasAttribute(ATTRIBUTE)) { + isAbstractConstant = constant.getAttributeValue(ATTRIBUTE); + } + } catch (IllegalArgumentException E) { + // the attribute did not exist + } + + if (isAbstractConstant) { + abstractConstants + .add(new AIdentifierExpression( + Arrays.asList(new TIdentifierLiteral[] { new TIdentifierLiteral( + constant.getIdentifierString()) }))); + } else { + concreteConstants + .add(new AIdentifierExpression( + Arrays.asList(new TIdentifierLiteral[] { new TIdentifierLiteral( + constant.getIdentifierString()) }))); + } } final AConstantsContextClause constantsContextClause = new AConstantsContextClause(); - constantsContextClause.setIdentifiers(list); - return constantsContextClause; + constantsContextClause.setIdentifiers(concreteConstants); + + final AAbstractConstantsContextClause abstractConstantsClause = new AAbstractConstantsContextClause(); + abstractConstantsClause.setIdentifiers(abstractConstants); + + return Arrays.asList(constantsContextClause, abstractConstantsClause); } private ATheoremsContextClause processTheorems() throws RodinDBException { @@ -307,27 +390,18 @@ public final class ContextTranslator extends AbstractComponentTranslator { final List<PPredicate> list = new ArrayList<PPredicate>( predicates.length); for (final ISCAxiom element : predicates) { - if (element.isTheorem() != theorems) { - continue; + if (element.isTheorem() == theorems) { + final PPredicate predicate = translatePredicate(ff, te, element); + list.add(predicate); + labelMapping.put(predicate, element); + proofspragmas.add(new ClassifiedPragma("discharged", predicate, + Arrays.asList(new String[0]), Arrays + .asList(new String[0]), NO_POS, NO_POS)); } - final PredicateVisitor visitor = new PredicateVisitor( - new LinkedList<String>()); - element.getPredicate(ff, te).accept(visitor); - - final PPredicate predicate = visitor.getPredicate(); - list.add(predicate); - labelMapping.put(predicate, element); - proofspragmas.add(new ClassifiedPragma("discharged", predicate, - Arrays.asList(new String[0]), Arrays.asList(new String[0]), - NO_POS, NO_POS)); } return list; } - public List<DischargedProof> getProofs() { - return proofs; - } - public List<ClassifiedPragma> getProofspragmas() { return proofspragmas; } @@ -337,4 +411,9 @@ public final class ContextTranslator extends AbstractComponentTranslator { return context.getComponentName(); } + @Override + public Node getAST() { + return getContextAST(); + } + } diff --git a/de.prob.core/src/de/prob/eventb/translator/ExpressionVisitor.java b/de.prob.core/src/de/prob/eventb/translator/ExpressionVisitor.java index 49af627156fefc608f681e454c9291c95f2d0803..5516aafa840e352344e7e48a8a73b005d2117a29 100644 --- a/de.prob.core/src/de/prob/eventb/translator/ExpressionVisitor.java +++ b/de.prob.core/src/de/prob/eventb/translator/ExpressionVisitor.java @@ -20,6 +20,7 @@ import org.eventb.core.ast.BoolExpression; import org.eventb.core.ast.BoundIdentDecl; import org.eventb.core.ast.BoundIdentifier; import org.eventb.core.ast.Expression; +import org.eventb.core.ast.ExtendedExpression; import org.eventb.core.ast.Formula; import org.eventb.core.ast.FreeIdentifier; import org.eventb.core.ast.ISimpleVisitor; @@ -28,6 +29,7 @@ import org.eventb.core.ast.Predicate; import org.eventb.core.ast.QuantifiedExpression; import org.eventb.core.ast.SetExtension; import org.eventb.core.ast.UnaryExpression; +import org.eventb.core.ast.extension.IExpressionExtension; import de.be4.classicalb.core.parser.node.AAddExpression; import de.be4.classicalb.core.parser.node.ABoolSetExpression; @@ -50,6 +52,7 @@ import de.be4.classicalb.core.parser.node.AEventBFirstProjectionV2Expression; import de.be4.classicalb.core.parser.node.AEventBIdentityExpression; import de.be4.classicalb.core.parser.node.AEventBSecondProjectionExpression; import de.be4.classicalb.core.parser.node.AEventBSecondProjectionV2Expression; +import de.be4.classicalb.core.parser.node.AExtendedExprExpression; import de.be4.classicalb.core.parser.node.AFunctionExpression; import de.be4.classicalb.core.parser.node.AGeneralIntersectionExpression; import de.be4.classicalb.core.parser.node.AGeneralUnionExpression; @@ -112,13 +115,6 @@ public class ExpressionVisitor extends SimpleVisitorAdapter implements // NOPMD // we need some abilities of the linked list, using List is not an option private boolean expressionSet = false; - @SuppressWarnings("unused") - private ExpressionVisitor() { // we want to prevent clients from calling - // the default constructor - super(); - throw new AssertionError("Do not call this constructor"); - } - public ExpressionVisitor(final LinkedList<String> bounds) { // NOPMD super(); this.bounds = bounds; @@ -157,7 +153,7 @@ public class ExpressionVisitor extends SimpleVisitorAdapter implements // NOPMD list.add(visitor.getExpression()); } - // Process internal Expression and Predcate + // Process internal Expression and Predicate final Predicate predicate = expression.getPredicate(); final PredicateVisitor predicateVisitor = new PredicateVisitor(bounds); predicate.accept(predicateVisitor); @@ -619,6 +615,36 @@ public class ExpressionVisitor extends SimpleVisitorAdapter implements // NOPMD setExpression(setExtensionExpression); } + @Override + public void visitExtendedExpression(ExtendedExpression expression) { + AExtendedExprExpression p = new AExtendedExprExpression(); + + IExpressionExtension extension = expression.getExtension(); + String symbol = extension.getSyntaxSymbol(); + + p.setIdentifier(new TIdentifierLiteral(symbol)); + Expression[] expressions = expression.getChildExpressions(); + List<PExpression> childExprs = new ArrayList<PExpression>(); + for (Expression e : expressions) { + ExpressionVisitor v = new ExpressionVisitor(bounds); + e.accept(v); + childExprs.add(v.getExpression()); + } + p.setExpressions(childExprs); + + Predicate[] childPredicates = expression.getChildPredicates(); + List<PPredicate> childPreds = new ArrayList<PPredicate>(); + for (Predicate pd : childPredicates) { + PredicateVisitor v = new PredicateVisitor(bounds); + pd.accept(v); + childPreds.add(v.getPredicate()); + } + p.setPredicates(childPreds); + + setExpression(p); + + } + @SuppressWarnings("deprecation") @Override public void visitUnaryExpression(final UnaryExpression expression) { // NOPMD diff --git a/de.prob.core/src/de/prob/eventb/translator/PredicateVisitor.java b/de.prob.core/src/de/prob/eventb/translator/PredicateVisitor.java index 7094ecabecf5f2ed6abe1799ca4bca63ff594463..59463a55ffd7ad62b5766d80bf622b9a88d6afc9 100644 --- a/de.prob.core/src/de/prob/eventb/translator/PredicateVisitor.java +++ b/de.prob.core/src/de/prob/eventb/translator/PredicateVisitor.java @@ -15,6 +15,7 @@ import org.eventb.core.ast.AssociativePredicate; import org.eventb.core.ast.BinaryPredicate; import org.eventb.core.ast.BoundIdentDecl; import org.eventb.core.ast.Expression; +import org.eventb.core.ast.ExtendedPredicate; import org.eventb.core.ast.Formula; import org.eventb.core.ast.ISimpleVisitor; import org.eventb.core.ast.LiteralPredicate; @@ -24,12 +25,14 @@ import org.eventb.core.ast.QuantifiedPredicate; import org.eventb.core.ast.RelationalPredicate; import org.eventb.core.ast.SimplePredicate; import org.eventb.core.ast.UnaryPredicate; +import org.eventb.core.ast.extension.IPredicateExtension; import de.be4.classicalb.core.parser.node.AConjunctPredicate; import de.be4.classicalb.core.parser.node.ADisjunctPredicate; import de.be4.classicalb.core.parser.node.AEqualPredicate; import de.be4.classicalb.core.parser.node.AEquivalencePredicate; import de.be4.classicalb.core.parser.node.AExistsPredicate; +import de.be4.classicalb.core.parser.node.AExtendedPredPredicate; import de.be4.classicalb.core.parser.node.AFalsityPredicate; import de.be4.classicalb.core.parser.node.AFinitePredicate; import de.be4.classicalb.core.parser.node.AForallPredicate; @@ -50,6 +53,7 @@ import de.be4.classicalb.core.parser.node.ASubsetStrictPredicate; import de.be4.classicalb.core.parser.node.ATruthPredicate; import de.be4.classicalb.core.parser.node.PExpression; import de.be4.classicalb.core.parser.node.PPredicate; +import de.be4.classicalb.core.parser.node.TIdentifierLiteral; import de.prob.eventb.translator.internal.SimpleVisitorAdapter; public class PredicateVisitor extends SimpleVisitorAdapter implements // NOPMD @@ -76,12 +80,19 @@ public class PredicateVisitor extends SimpleVisitorAdapter implements // NOPMD predicateSet = true; this.p = p; } - //public ClassifiedPragma(String name, Node attachedTo, List<String> arguments, List<String> warnings, SourcePosition start, SourcePosition end) { - - // new ClassifiedPragma("discharged", p, proof, Collections.emptyList(), new SourcePosition(-1, -1), new SourcePosition(-1, -1)); + // public ClassifiedPragma(String name, Node attachedTo, List<String> + // arguments, List<String> warnings, SourcePosition start, + // SourcePosition end) { + + // new ClassifiedPragma("discharged", p, proof, Collections.emptyList(), + // new SourcePosition(-1, -1), new SourcePosition(-1, -1)); + } + + public PredicateVisitor() { + this(null); } - public PredicateVisitor(final LinkedList<String> bounds) { + public PredicateVisitor(LinkedList<String> bounds) { super(); if (bounds == null) { this.bounds = new LinkedList<String>(); @@ -90,10 +101,6 @@ public class PredicateVisitor extends SimpleVisitorAdapter implements // NOPMD } } - public PredicateVisitor() { - this(null); - } - @Override public void visitQuantifiedPredicate(final QuantifiedPredicate predicate) { final int tag = predicate.getTag(); @@ -406,4 +413,36 @@ public class PredicateVisitor extends SimpleVisitorAdapter implements // NOPMD setPredicate(result); } + @Override + public void visitExtendedPredicate(ExtendedPredicate predicate) { + AExtendedPredPredicate p = new AExtendedPredPredicate(); + IPredicateExtension extension = predicate.getExtension(); + String symbol = extension.getSyntaxSymbol(); + + // FIXME THEORY-PLUGIN re-enable when the theory plugin was released + + // Theories.addOrigin(origin); + + p.setIdentifier(new TIdentifierLiteral(symbol)); + + Expression[] expressions = predicate.getChildExpressions(); + List<PExpression> childExprs = new ArrayList<PExpression>(); + for (Expression e : expressions) { + ExpressionVisitor v = new ExpressionVisitor(bounds); + e.accept(v); + childExprs.add(v.getExpression()); + } + p.setExpressions(childExprs); + + Predicate[] childPredicates = predicate.getChildPredicates(); + List<PPredicate> childPreds = new ArrayList<PPredicate>(); + for (Predicate pd : childPredicates) { + PredicateVisitor v = new PredicateVisitor(bounds); + pd.accept(v); + childPreds.add(v.getPredicate()); + } + p.setPredicates(childPreds); + setPredicate(p); + } + } diff --git a/de.prob.core/src/de/prob/eventb/translator/Theories.java b/de.prob.core/src/de/prob/eventb/translator/Theories.java new file mode 100644 index 0000000000000000000000000000000000000000..18de77aaa2a92386c2e9573aaee25d5273916a5a --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/Theories.java @@ -0,0 +1,382 @@ +package de.prob.eventb.translator; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eventb.core.IEventBProject; +import org.eventb.core.ISCIdentifierElement; +import org.eventb.core.ast.Expression; +import org.eventb.core.ast.Formula; +import org.eventb.core.ast.FormulaFactory; +import org.eventb.core.ast.ITypeEnvironment; +import org.eventb.core.ast.Predicate; +import org.eventb.core.ast.Type; +import org.eventb.theory.core.DatabaseUtilities; +import org.eventb.theory.core.IAvailableTheory; +import org.eventb.theory.core.IAvailableTheoryProject; +import org.eventb.theory.core.IDeployedTheoryRoot; +import org.eventb.theory.core.ISCAxiomaticDefinitionAxiom; +import org.eventb.theory.core.ISCAxiomaticDefinitionsBlock; +import org.eventb.theory.core.ISCAxiomaticOperatorDefinition; +import org.eventb.theory.core.ISCConstructorArgument; +import org.eventb.theory.core.ISCDatatypeConstructor; +import org.eventb.theory.core.ISCDatatypeDefinition; +import org.eventb.theory.core.ISCDirectOperatorDefinition; +import org.eventb.theory.core.ISCNewOperatorDefinition; +import org.eventb.theory.core.ISCOperatorArgument; +import org.eventb.theory.core.ISCRecursiveDefinitionCase; +import org.eventb.theory.core.ISCRecursiveOperatorDefinition; +import org.eventb.theory.core.ISCTypeArgument; +import org.eventb.theory.core.ITheoryPathRoot; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinDBException; + +import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; +import de.be4.classicalb.core.parser.node.PExpression; +import de.be4.classicalb.core.parser.node.PPredicate; +import de.prob.core.translator.TranslationFailedException; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.output.StructuredPrologOutput; +import de.prob.prolog.term.PrologTerm; +import de.prob.tmparser.OperatorMapping; +import de.prob.tmparser.TheoryMappingException; +import de.prob.tmparser.TheoryMappingParser; + + +public class Theories { + private static final String PROB_THEORY_MAPPING_SUFFIX = "ptm"; + + public static void translate(IEventBProject project, IPrologTermOutput pout) + throws TranslationFailedException { + try { + final IRodinProject rProject = project.getRodinProject(); + final IDeployedTheoryRoot[] theories = rProject + .getRootElementsOfType(IDeployedTheoryRoot.ELEMENT_TYPE); + for (IDeployedTheoryRoot theory : theories) { + savePrintTranslation(theory, pout); + } + final ITheoryPathRoot[] theoryPaths = rProject + .getRootElementsOfType(ITheoryPathRoot.ELEMENT_TYPE); + for (ITheoryPathRoot theoryPath : theoryPaths) { + for (IAvailableTheoryProject ap : theoryPath + .getAvailableTheoryProjects()) { + for (IAvailableTheory at : ap.getTheories()) { + savePrintTranslation(at.getDeployedTheory(), pout); + } + } + } + } catch (RodinDBException e) { + throw new TranslationFailedException(e); + } + } + + /** + * We currently write the translated theory into a PrologTerm object because + * the translation is currently very unstable and erroneous. Writing in a + * Prolog object makes sure that the output stream to the Prolog process + * will not be corrupted. + * + * @throws TranslationFailedException + */ + private static void savePrintTranslation(IDeployedTheoryRoot theory, + IPrologTermOutput opto) throws RodinDBException, + TranslationFailedException { + + final StructuredPrologOutput pto = new StructuredPrologOutput(); + printTranslation(theory, pto); + pto.fullstop(); + final PrologTerm result = pto.getSentences().get(0); + opto.printTerm(result); + } + + private static void printTranslation(IDeployedTheoryRoot theory, + StructuredPrologOutput pto) throws RodinDBException, + TranslationFailedException { + pto.openTerm("theory"); + printIdentifiers(theory.getSCTypeParameters(), pto); + printDataTypes(theory, pto); + printOperatorDefs(theory, pto); + printAxiomaticDefs(theory, pto); + findProBMappingFile(theory, pto); + pto.closeTerm(); + } + + private static void findProBMappingFile(IDeployedTheoryRoot theory, + IPrologTermOutput pto) throws TranslationFailedException { + final String theoryName = theory.getComponentName(); + final IPath path = new Path(theoryName + "." + + PROB_THEORY_MAPPING_SUFFIX); + final IProject project = theory.getRodinProject().getProject(); + final Collection<OperatorMapping> mappings; + if (project.exists(path)) { + final IFile file = project.getFile(path); + mappings = readMappingFile(file, theory); + } else { + mappings = Collections.emptyList(); + } + printMappings(mappings, pto); + } + + private static Collection<OperatorMapping> readMappingFile(IFile file, + IDeployedTheoryRoot theory) throws TranslationFailedException { + try { + final InputStream input = file.getContents(); + final String name = theory.getComponentName(); + final Reader reader = new InputStreamReader(input); + return TheoryMappingParser.parseTheoryMapping(name, reader); + } catch (CoreException e) { + throw new TranslationFailedException(e); + } catch (TheoryMappingException e) { + throw new TranslationFailedException(e); + } catch (IOException e) { + throw new TranslationFailedException(e); + } + } + + private static void printMappings(Collection<OperatorMapping> mappings, + IPrologTermOutput pto) { + pto.openList(); + // Currently, we support only one kind of operator mapping, just tagging + // an operator to indicate that an optimized ProB implementation should + // be used. We do not invest any effort in preparing future kinds of + // other operator mappings. + for (OperatorMapping mapping : mappings) { + pto.openTerm("tag"); + pto.printAtom(mapping.getOperatorName()); + pto.printAtom(mapping.getSpec()); + pto.closeTerm(); + } + pto.closeList(); + } + + private static void printIdentifiers(ISCIdentifierElement[] identifiers, + IPrologTermOutput pto) throws RodinDBException { + pto.openList(); + for (ISCIdentifierElement identifier : identifiers) { + pto.printAtom(identifier.getIdentifierString()); + } + pto.closeList(); + } + + private static void printDataTypes(IDeployedTheoryRoot theory, + IPrologTermOutput pto) throws RodinDBException { + final FormulaFactory ff = theory.getFormulaFactory(); + pto.openList(); + for (ISCDatatypeDefinition def : theory.getSCDatatypeDefinitions()) { + printDataType(def, ff, pto); + } + pto.closeList(); + } + + private static void printDataType(ISCDatatypeDefinition def, + FormulaFactory ff, IPrologTermOutput pto) throws RodinDBException { + pto.openTerm("datatype"); + pto.printAtom(def.getIdentifierString()); + pto.openList(); + for (ISCTypeArgument arg : def.getTypeArguments()) { + printType(arg.getSCGivenType(ff), ff, pto); + } + pto.closeList(); + pto.openList(); + for (ISCDatatypeConstructor cons : def.getConstructors()) { + printConstructor(cons, ff, pto); + } + pto.closeList(); + pto.closeTerm(); + + } + + private static void printConstructor(ISCDatatypeConstructor cons, + FormulaFactory ff, IPrologTermOutput pto) throws RodinDBException { + pto.openTerm("constructor"); + pto.printAtom(cons.getIdentifierString()); + pto.openList(); + for (ISCConstructorArgument arg : cons.getConstructorArguments()) { + printTypedIdentifier("destructor", arg, ff, pto); + } + pto.closeList(); + pto.closeTerm(); + + } + + private static void printOperatorDefs(IDeployedTheoryRoot theory, + IPrologTermOutput pto) throws RodinDBException { + pto.openList(); + for (ISCNewOperatorDefinition opdef : theory + .getSCNewOperatorDefinitions()) { + printOperator(opdef, theory, pto); + } + pto.closeList(); + } + + private static void printOperator(ISCNewOperatorDefinition opDef, + IDeployedTheoryRoot theory, IPrologTermOutput prologOutput) + throws RodinDBException { + + prologOutput.openTerm("operator"); + prologOutput.printAtom(opDef.getLabel()); + + final FormulaFactory ff = theory.getFormulaFactory(); + final ITypeEnvironment te = theory.getTypeEnvironment(ff); + + // Arguments + printOperatorArguments(opDef.getOperatorArguments(), prologOutput, ff); + + // WD Condition + Predicate wdCondition = opDef.getWDCondition(ff, te); + printPredicate(prologOutput, wdCondition); + + // Direct Definitions + prologOutput.openList(); + processDefinitions(ff, te, prologOutput, + opDef.getDirectOperatorDefinitions()); + prologOutput.closeList(); + + // Recursive Definitions + prologOutput.openList(); + ISCRecursiveOperatorDefinition[] definitions = opDef + .getRecursiveOperatorDefinitions(); + for (ISCRecursiveOperatorDefinition definition : definitions) { + ISCRecursiveDefinitionCase[] recursiveDefinitionCases = definition + .getRecursiveDefinitionCases(); + for (ISCRecursiveDefinitionCase c : recursiveDefinitionCases) { + Expression ex = c.getExpression(ff, te); + printExpression(prologOutput, ex); + } + } + prologOutput.closeList(); + + prologOutput.closeTerm(); + } + + private static void printOperatorArguments(ISCOperatorArgument[] arguments, + IPrologTermOutput prologOutput, final FormulaFactory ff) + throws RodinDBException { + prologOutput.openList(); + for (ISCOperatorArgument argument : arguments) { + printTypedIdentifier("argument", argument, ff, prologOutput); + } + prologOutput.closeList(); + } + + private static void processDefinitions(FormulaFactory ff, + ITypeEnvironment te, IPrologTermOutput prologOutput, + ISCDirectOperatorDefinition[] directOperatorDefinitions) + throws RodinDBException { + for (ISCDirectOperatorDefinition def : directOperatorDefinitions) { + Formula<?> scFormula = def.getSCFormula(ff, te); + + if (scFormula instanceof Predicate) { + Predicate pp = (Predicate) scFormula; + printPredicate(prologOutput, pp); + } + if (scFormula instanceof Expression) { + Expression pp = (Expression) scFormula; + printExpression(prologOutput, pp); + } + + } + } + + private static void printTypedIdentifier(final String functor, + final ISCIdentifierElement id, final FormulaFactory ff, + final IPrologTermOutput pto) throws RodinDBException { + pto.openTerm(functor); + pto.printAtom(id.getIdentifierString()); + Type type = id.getType(ff); + printType(type, ff, pto); + pto.closeTerm(); + } + + private static void printType(final Type type, final FormulaFactory ff, + final IPrologTermOutput pto) { + printExpression(pto, type.toExpression(ff)); + } + + private static void printExpression(IPrologTermOutput prologOutput, + Expression pp) { + ExpressionVisitor visitor = new ExpressionVisitor( + new LinkedList<String>()); + pp.accept(visitor); + PExpression ex = visitor.getExpression(); + ASTProlog pv = new ASTProlog(prologOutput, null); + ex.apply(pv); + } + + private static void printPredicate(IPrologTermOutput prologOutput, + Predicate pp) { + PredicateVisitor visitor = new PredicateVisitor( + new LinkedList<String>()); + pp.accept(visitor); + PPredicate predicate = visitor.getPredicate(); + ASTProlog pv = new ASTProlog(prologOutput, null); + predicate.apply(pv); + } + + private static void printAxiomaticDefs(IDeployedTheoryRoot theory, + IPrologTermOutput pto) throws RodinDBException { + FormulaFactory ff = theory.getFormulaFactory(); + ITypeEnvironment te = theory.getTypeEnvironment(ff); + pto.openList(); + for (final ISCAxiomaticDefinitionsBlock block : theory + .getSCAxiomaticDefinitionsBlocks()) { + printAxiomaticDefBlock(block, ff, te, pto); + } + pto.closeList(); + } + + private static void printAxiomaticDefBlock( + ISCAxiomaticDefinitionsBlock block, FormulaFactory ff, + ITypeEnvironment te, IPrologTermOutput pto) throws RodinDBException { + pto.openTerm("axiomatic_def_block"); + pto.printAtom(block.getLabel()); + printIdentifiers(block.getAxiomaticTypeDefinitions(), pto); + printAxiomaticOperators(block.getAxiomaticOperatorDefinitions(), ff, + pto); + printAxioms(block.getAxiomaticDefinitionAxioms(), ff, te, pto); + pto.closeTerm(); + } + + private static void printAxiomaticOperators( + ISCAxiomaticOperatorDefinition[] axdefs, FormulaFactory ff, + IPrologTermOutput pto) throws RodinDBException { + pto.openList(); + for (final ISCAxiomaticOperatorDefinition opdef : axdefs) { + pto.openTerm("opdef"); + pto.printAtom(opdef.getLabel()); // The label seems to be the + // operator name + printOperatorArguments(opdef.getOperatorArguments(), pto, ff); + pto.openList(); + // WD condition missing + pto.closeList(); + pto.closeTerm(); + } + pto.closeList(); + } + + private static void printAxioms(ISCAxiomaticDefinitionAxiom[] axioms, + FormulaFactory ff, ITypeEnvironment te, IPrologTermOutput pto) + throws RodinDBException { + pto.openList(); + for (ISCAxiomaticDefinitionAxiom axiom : axioms) { + printPredicate(pto, axiom.getPredicate(ff, te)); + } + pto.closeList(); + } + + public static void touch() throws NoClassDefFoundError { + // Just some dummy code to check if the theory plugin is installed + @SuppressWarnings("unused") + String extension = DatabaseUtilities.DEPLOYED_THEORY_FILE_EXTENSION; + } +} diff --git a/de.prob.core/src/de/prob/eventb/translator/TheoryTranslator.java b/de.prob.core/src/de/prob/eventb/translator/TheoryTranslator.java new file mode 100644 index 0000000000000000000000000000000000000000..d31ff06a2e8cfe0f759cd5a3e1390ad44bc49ea0 --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/TheoryTranslator.java @@ -0,0 +1,23 @@ +package de.prob.eventb.translator; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +public class TheoryTranslator { + + public void translate() { + final IExtensionRegistry extensionRegistry = Platform + .getExtensionRegistry(); + final IExtensionPoint extensionPoint = extensionRegistry + .getExtensionPoint("org.eventb.theory.core.deployedElements"); + for (final IExtension extension : extensionPoint.getExtensions()) { + for (final IConfigurationElement configurationElement : extension + .getConfigurationElements()) { + System.out.println(configurationElement.getAttribute("name")); + } + } + } +} diff --git a/de.prob.core/src/de/prob/eventb/translator/TranslatorFactory.java b/de.prob.core/src/de/prob/eventb/translator/TranslatorFactory.java index 0e9a5d1af765473e700a8e24a4306f0caa3d2441..25acab2f8f4d3c5f0dbe43e77784988ff2786a71 100644 --- a/de.prob.core/src/de/prob/eventb/translator/TranslatorFactory.java +++ b/de.prob.core/src/de/prob/eventb/translator/TranslatorFactory.java @@ -33,19 +33,25 @@ public class TranslatorFactory { */ public static void translate(final IEventBRoot root, final IPrologTermOutput pto) throws TranslationFailedException { - if (root instanceof IMachineRoot) { - final ISCMachineRoot scRoot = ((IMachineRoot) root) - .getSCMachineRoot(); - EventBMachineTranslator.create(scRoot, pto); - - } else if (root instanceof IContextRoot) { - final ISCContextRoot scRoot = ((IContextRoot) root) - .getSCContextRoot(); - EventBContextTranslator.create(scRoot, pto); - } else { - throw new TranslationFailedException(root.getComponentName(), - "Cannot translate anything else than IMachineRoot or IContextRoot. Type was: " - + root.getClass()); + final String componentName = root.getComponentName(); + try { + if (root instanceof IMachineRoot) { + final ISCMachineRoot scRoot = ((IMachineRoot) root) + .getSCMachineRoot(); + EventBMachineTranslator.create(scRoot, pto); + + } else if (root instanceof IContextRoot) { + final ISCContextRoot scRoot = ((IContextRoot) root) + .getSCContextRoot(); + EventBContextTranslator.create(scRoot, pto); + } else { + throw new TranslationFailedException(componentName, + "Cannot translate anything else than IMachineRoot or IContextRoot. Type was: " + + root.getClass()); + } + } catch (RuntimeException e) { + throw new TranslationFailedException(componentName, + "A runtime exception occurred: " + e.getMessage(), e); } } diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/DischargedProof.java b/de.prob.core/src/de/prob/eventb/translator/internal/DischargedProof.java deleted file mode 100644 index 98d690d6d5b788ca04e6eca4972a1ad98aa1f776..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/eventb/translator/internal/DischargedProof.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -/** - * - */ -package de.prob.eventb.translator.internal; - -import org.eventb.core.IAxiom; -import org.eventb.core.IEvent; -import org.eventb.core.IEventBRoot; -import org.eventb.core.IInvariant; -import org.rodinp.core.RodinDBException; - -public class DischargedProof { - public final String predicate; - public final IEvent event; - public final IEventBRoot machine; - - public DischargedProof(final IEventBRoot root, final IInvariant inv, - final IEvent evt) { - machine = root; - String p; - try { - p = inv.getLabel(); - } catch (RodinDBException e) { - p = ""; - e.printStackTrace(); - } - predicate = p; - event = evt; - } - - public DischargedProof(final IEventBRoot root, final IAxiom inv, - final IEvent evt) { - machine = root; - String p; - try { - p = inv.getLabel(); - } catch (RodinDBException e) { - p = ""; - e.printStackTrace(); - } - predicate = p; - event = evt; - } -} \ No newline at end of file diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/EProofStatus.java b/de.prob.core/src/de/prob/eventb/translator/internal/EProofStatus.java new file mode 100644 index 0000000000000000000000000000000000000000..160bf968ce3bd637dea4af99e8b5eea6ee72fd8f --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/internal/EProofStatus.java @@ -0,0 +1,15 @@ +package de.prob.eventb.translator.internal; + +public enum EProofStatus { + UNPROVEN("false"), PROVEN("true"), REVIEWED("reviewed"); + private final String text; + + private EProofStatus(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } +} diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/EventBContextTranslator.java b/de.prob.core/src/de/prob/eventb/translator/internal/EventBContextTranslator.java index ae640ff98a9c1d84b2014b850b42db0f3c2058f3..075270d4ae253ae3aef71dafd9d877e1ee61a433 100644 --- a/de.prob.core/src/de/prob/eventb/translator/internal/EventBContextTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/internal/EventBContextTranslator.java @@ -51,13 +51,15 @@ public final class EventBContextTranslator extends EventBTranslator { private void constructTranslation(final IPrologTermOutput pto) throws TranslationFailedException { - List<ContextTranslator> translators = new ArrayList<ContextTranslator>(); -// translators.add(ContextTranslator.create(context)); + List<ContextTranslator> contextTranslators = new ArrayList<ContextTranslator>(); + + // translators.add(ContextTranslator.create(context)); if (context instanceof ISCContextRoot) { ISCContextRoot root = (ISCContextRoot) context; - collectContexts(translators, new ArrayList<String>(), root); + collectContexts(contextTranslators, new ArrayList<String>(), root); } - printProlog(new ArrayList<ModelTranslator>(), translators, pto); + + printProlog(new ArrayList<ModelTranslator>(), contextTranslators, pto); } private void collectContexts(final List<ContextTranslator> translatorMap, diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/EventBMachineTranslator.java b/de.prob.core/src/de/prob/eventb/translator/internal/EventBMachineTranslator.java index b6ee12f4e13e3fbabecdd6b9ea25020a3f8b907f..845e660ebefc838aed2ec001cf513234c114e16e 100644 --- a/de.prob.core/src/de/prob/eventb/translator/internal/EventBMachineTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/internal/EventBMachineTranslator.java @@ -11,6 +11,8 @@ import java.util.List; import org.eventb.core.ISCInternalContext; import org.eventb.core.ISCMachineRoot; +import org.eventb.core.ast.FormulaFactory; +import org.eventb.core.ast.ITypeEnvironment; import org.rodinp.core.IRodinFile; import org.rodinp.core.RodinDBException; @@ -102,12 +104,14 @@ public final class EventBMachineTranslator extends EventBTranslator { throws TranslationFailedException { final List<ContextTranslator> translators = new ArrayList<ContextTranslator>(); final List<String> processed = new ArrayList<String>(); - for (ISCMachineRoot m : models) { - ISCInternalContext[] seenContexts; + + for (final ISCMachineRoot m : models) { try { - seenContexts = m.getSCSeenContexts(); - for (ISCInternalContext seenContext : seenContexts) { - collectContexts(translators, processed, seenContext); + final FormulaFactory ff = m.getFormulaFactory(); + final ITypeEnvironment te = m.getTypeEnvironment(ff); + final ISCInternalContext[] seenContexts = m.getSCSeenContexts(); + for (final ISCInternalContext seenContext : seenContexts) { + collectContexts(translators, processed, seenContext, ff, te); } } catch (RodinDBException e) { throw new TranslationFailedException(e); @@ -117,12 +121,13 @@ public final class EventBMachineTranslator extends EventBTranslator { } private void collectContexts(final List<ContextTranslator> translatorMap, - final List<String> processed, final ISCInternalContext context) + final List<String> processed, final ISCInternalContext context, + final FormulaFactory ff, final ITypeEnvironment te) throws TranslationFailedException { String name = context.getElementName(); if (!processed.contains(name)) { processed.add(name); - translatorMap.add(ContextTranslator.create(context)); + translatorMap.add(ContextTranslator.create(context, ff, te)); } } diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/EventBTranslator.java b/de.prob.core/src/de/prob/eventb/translator/internal/EventBTranslator.java index 54eb566182fa3856b663293d6f4072e46f81e82b..f92eb90882e451f467ead544691c747ac0a24930 100644 --- a/de.prob.core/src/de/prob/eventb/translator/internal/EventBTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/internal/EventBTranslator.java @@ -11,31 +11,27 @@ import java.util.Collection; import java.util.Map; import org.eclipse.core.runtime.Assert; -import org.eventb.core.IEvent; import org.eventb.core.IEventBProject; import org.eventb.core.IEventBRoot; import org.eventb.core.ISCInternalContext; import org.eventb.core.ISCMachineRoot; import org.rodinp.core.IInternalElement; -import org.rodinp.core.RodinDBException; import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; -import de.be4.classicalb.core.parser.node.AEventBContextParseUnit; -import de.be4.classicalb.core.parser.node.AEventBModelParseUnit; import de.be4.classicalb.core.parser.node.Node; import de.prob.core.translator.ITranslator; import de.prob.core.translator.TranslationFailedException; +import de.prob.core.translator.pragmas.IPragma; import de.prob.eventb.translator.AbstractComponentTranslator; -import de.prob.eventb.translator.ContextTranslator; +import de.prob.eventb.translator.Theories; import de.prob.prolog.output.IPrologTermOutput; public abstract class EventBTranslator implements ITranslator { protected final IEventBProject project; - private final String name; + private boolean theoryIsUsed; protected EventBTranslator(final IEventBRoot root) { this.project = root.getEventBProject(); - this.name = root.getComponentName(); } // another constructor to cater for ISCInternalContext (which is not a root @@ -43,10 +39,9 @@ public abstract class EventBTranslator implements ITranslator { protected EventBTranslator(final ISCInternalContext ctx) { Assert.isTrue(ctx.getRoot() instanceof ISCMachineRoot); this.project = ((ISCMachineRoot) ctx.getRoot()).getEventBProject(); - this.name = ctx.getComponentName(); } - private LabelPositionPrinter createPrinter( + private LabelPositionPrinter createLabelPrositionPrinter( final Collection<AbstractComponentTranslator> translators) throws TranslationFailedException { LabelPositionPrinter printer = new LabelPositionPrinter(); @@ -58,59 +53,52 @@ public abstract class EventBTranslator implements ITranslator { return printer; } - private void printContexts( - final Collection<ContextTranslator> contextTranslators, - final IPrologTermOutput pout, final ASTProlog prolog) { - pout.openList(); - for (final ContextTranslator contextTranslator : contextTranslators) { - final AEventBContextParseUnit contextAST = contextTranslator - .getContextAST(); - contextAST.apply(prolog); + private Collection<Node> translateModels( + final Collection<? extends AbstractComponentTranslator> refinementChainTranslators) { + Collection<Node> nodes = new ArrayList<Node>(); + for (final AbstractComponentTranslator translator : refinementChainTranslators) { + nodes.add(translator.getAST()); + theoryIsUsed |= translator.isTheoryUsed(); } - pout.closeList(); + return nodes; } - private void printModels( - final Collection<ModelTranslator> refinementChainTranslators, + private void printModels(final Collection<Node> nodes, final IPrologTermOutput pout, final ASTProlog prolog) { pout.openList(); - - for (final ModelTranslator modelTranslator : refinementChainTranslators) { - final AEventBModelParseUnit modelAST = modelTranslator - .getModelAST(); - modelAST.apply(prolog); + for (final Node node : nodes) { + node.apply(prolog); } pout.closeList(); } private void printProofInformation( - final Collection<ModelTranslator> refinementChainTranslators, - Collection<ContextTranslator> contextTranslators, + final Collection<? extends AbstractComponentTranslator> refinementChainTranslators, + Collection<? extends AbstractComponentTranslator> contextTranslators, final IPrologTermOutput pout) throws TranslationFailedException { - ArrayList<DischargedProof> list = new ArrayList<DischargedProof>(); + ArrayList<ProofObligation> list = new ArrayList<ProofObligation>(); - for (ContextTranslator contextTranslator : contextTranslators) { + for (AbstractComponentTranslator contextTranslator : contextTranslators) { list.addAll(contextTranslator.getProofs()); } - for (ModelTranslator modelTranslator : refinementChainTranslators) { + for (AbstractComponentTranslator modelTranslator : refinementChainTranslators) { list.addAll(modelTranslator.getProofs()); } - for (DischargedProof proof : list) { - pout.openTerm("discharged"); - pout.printAtom(proof.machine.getRodinFile().getBareName()); - try { - IEvent event = proof.event; - final String elementName = proof.predicate; - if (event != null) - pout.printAtom(event.getLabel()); - pout.printAtom(elementName); - } catch (RodinDBException e) { - final String details = "Translation error while getting information about discharged proof obligations"; - throw new TranslationFailedException(name, details); + for (ProofObligation proof : list) { + pout.openTerm("po"); + pout.printAtom(proof.origin.getRodinFile().getBareName()); + pout.printAtom(proof.kind); + pout.openList(); + for (SequentSource source : proof.sources) { + pout.openTerm(source.type); + pout.printAtom(source.label); + pout.closeTerm(); } + pout.closeList(); + pout.printAtom(proof.discharged.toString()); pout.closeTerm(); } @@ -118,33 +106,87 @@ public abstract class EventBTranslator implements ITranslator { printFlowInformation(pout); } + private void printPragmaContents( + Collection<? extends AbstractComponentTranslator> refinementChainTranslators, + Collection<? extends AbstractComponentTranslator> contextTranslators, + IPrologTermOutput pout) { + ArrayList<IPragma> pragmas = new ArrayList<IPragma>(); + + for (AbstractComponentTranslator contextTranslator : contextTranslators) { + pragmas.addAll(contextTranslator.getPragmas()); + } + for (AbstractComponentTranslator modelTranslator : refinementChainTranslators) { + pragmas.addAll(modelTranslator.getPragmas()); + } + + for (IPragma pragma : pragmas) { + pragma.output(pout); + } + } + protected abstract void printFlowInformation(final IPrologTermOutput pout); private ASTProlog createAstVisitor( - final Collection<ModelTranslator> refinementChainTranslators, - final Collection<ContextTranslator> contextTranslators, + final Collection<? extends AbstractComponentTranslator> refinementChainTranslators, + final Collection<? extends AbstractComponentTranslator> contextTranslators, final IPrologTermOutput pout) throws TranslationFailedException { Collection<AbstractComponentTranslator> translators = new ArrayList<AbstractComponentTranslator>(); translators.addAll(refinementChainTranslators); translators.addAll(contextTranslators); - return new ASTProlog(pout, createPrinter(translators)); + return new ASTProlog(pout, createLabelPrositionPrinter(translators)); } protected void printProlog( - final Collection<ModelTranslator> refinementChainTranslators, - final Collection<ContextTranslator> contextTranslators, + final Collection<? extends AbstractComponentTranslator> refinementChainTranslators, + final Collection<? extends AbstractComponentTranslator> contextTranslators, final IPrologTermOutput pout) throws TranslationFailedException { + theoryIsUsed = false; + Collection<Node> machineNodes = translateModels(refinementChainTranslators); + Collection<Node> contextNodes = translateModels(contextTranslators); + + if (theoryIsUsed) { + checkIfTheoriesAvailable(); + } + final ASTProlog prolog = createAstVisitor(refinementChainTranslators, contextTranslators, pout); pout.openTerm("load_event_b_project"); - printModels(refinementChainTranslators, pout, prolog); - printContexts(contextTranslators, pout, prolog); + printModels(machineNodes, pout, prolog); + printModels(contextNodes, pout, prolog); pout.openList(); + pout.openTerm("exporter_version"); + pout.printNumber(3); + pout.closeTerm(); + printProofInformation(refinementChainTranslators, contextTranslators, pout); + + if (theoryIsUsed) { + translateTheories(project, pout); + } + + printPragmaContents(refinementChainTranslators, contextTranslators, + pout); + pout.closeList(); pout.printVariable("_Error"); pout.closeTerm(); } + + private void checkIfTheoriesAvailable() throws TranslationFailedException { + try { + Theories.touch(); + } catch (NoClassDefFoundError e) { + throw new TranslationFailedException( + "Theory", + "The model to animate makes use of a theory but the theory plug-in is not installed"); + } + } + + private void translateTheories(IEventBProject project2, + IPrologTermOutput pout) throws TranslationFailedException { + Theories.translate(project, pout); + } + } diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/ModelTranslator.java b/de.prob.core/src/de/prob/eventb/translator/internal/ModelTranslator.java index ba6f53a2ec7b4238cc99f87f50a16c33226f7132..eba944992a1f6904beb9969790fd3e679cb9eed2 100644 --- a/de.prob.core/src/de/prob/eventb/translator/internal/ModelTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/internal/ModelTranslator.java @@ -9,14 +9,12 @@ package de.prob.eventb.translator.internal; // NOPMD by bendisposto import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.apache.commons.lang.StringUtils; import org.eventb.core.IConvergenceElement.Convergence; -import org.eventb.core.IEvent; -import org.eventb.core.IInvariant; +import org.eventb.core.ILabeledElement; import org.eventb.core.IMachineRoot; import org.eventb.core.IPOSequent; import org.eventb.core.IPOSource; @@ -38,8 +36,10 @@ import org.eventb.core.ISCWitness; import org.eventb.core.ITraceableElement; import org.eventb.core.ast.FormulaFactory; import org.eventb.core.ast.ITypeEnvironment; -import org.eventb.core.ast.Predicate; +import org.eventb.core.basis.Event; +import org.eventb.core.basis.Guard; import org.eventb.core.seqprover.IConfidence; +import org.rodinp.core.IElementType; import org.rodinp.core.IRodinElement; import org.rodinp.core.IRodinFile; import org.rodinp.core.RodinDBException; @@ -58,6 +58,7 @@ import de.be4.classicalb.core.parser.node.ATheoremsModelClause; import de.be4.classicalb.core.parser.node.AVariablesModelClause; import de.be4.classicalb.core.parser.node.AVariantModelClause; import de.be4.classicalb.core.parser.node.AWitness; +import de.be4.classicalb.core.parser.node.Node; import de.be4.classicalb.core.parser.node.PEvent; import de.be4.classicalb.core.parser.node.PEventstatus; import de.be4.classicalb.core.parser.node.PExpression; @@ -69,21 +70,19 @@ import de.be4.classicalb.core.parser.node.TIdentifierLiteral; import de.prob.core.translator.TranslationFailedException; import de.prob.eventb.translator.AbstractComponentTranslator; import de.prob.eventb.translator.AssignmentVisitor; -import de.prob.eventb.translator.ExpressionVisitor; -import de.prob.eventb.translator.PredicateVisitor; import de.prob.logging.Logger; public class ModelTranslator extends AbstractComponentTranslator { private final ISCMachineRoot machine; private final AEventBModelParseUnit model = new AEventBModelParseUnit(); - private final FormulaFactory ff = FormulaFactory.getDefault();; + private final FormulaFactory ff; + private final ITypeEnvironment te; private final IMachineRoot origin; - private final List<DischargedProof> proofs = new ArrayList<DischargedProof>(); + // private final List<String> depContext = new ArrayList<String>(); // Confined in the thread calling the factory method - private ITypeEnvironment te; private String refines; private boolean broken = false; @@ -113,13 +112,9 @@ public class ModelTranslator extends AbstractComponentTranslator { return modelTranslator; } - public List<DischargedProof> getProofs() { - return Collections.unmodifiableList(proofs); - } - public AEventBModelParseUnit getModelAST() { if (broken) { - final String message = "The machine contains Rodin Problems. Please fix it before animating"; + final String message = "The machine contains Rodin Problems. ProB will continue, but you may observe unexpected behaviour"; Logger.notifyUserWithoutBugreport(message); return model; } @@ -137,9 +132,19 @@ public class ModelTranslator extends AbstractComponentTranslator { // ############################################################################################################################################################### // Implementation - private ModelTranslator(final ISCMachineRoot currentMachine) { - this.machine = currentMachine; + private ModelTranslator(final ISCMachineRoot machine) + throws TranslationFailedException { + super(machine.getComponentName()); + this.machine = machine; origin = machine.getMachineRoot(); + ff = machine.getFormulaFactory(); + try { + te = machine.getTypeEnvironment(ff); + } catch (RodinDBException e) { + final String message = "A Rodin exception occured during translation process. Original Exception: "; + throw new TranslationFailedException(machine.getComponentName(), + message + e.getLocalizedMessage()); + } } private void translate() throws RodinDBException, @@ -151,12 +156,18 @@ public class ModelTranslator extends AbstractComponentTranslator { broken = !machine.isAccurate(); // isAccurate() is not transitive, we // need to collect the information also // for the events - te = machine.getTypeEnvironment(ff); - translateMachine(); // Check for fully discharged Invariants and Events collectProofInfo(); + + // Collect Pragmas, Units, etc. + collectPragmas(); + } + + private void collectPragmas() throws RodinDBException { + // unit pragma, attached to variables + addUnitPragmas(machine.getSCVariables()); } private void collectProofInfo() throws RodinDBException { @@ -169,41 +180,45 @@ public class ModelTranslator extends AbstractComponentTranslator { for (IPSStatus status : statuses) { final int confidence = status.getConfidence(); boolean broken = status.isBroken(); - if (!broken && confidence == IConfidence.DISCHARGED_MAX) { - IPOSequent sequent = status.getPOSequent(); - IPOSource[] sources = sequent.getSources(); - - IEvent evt = null; - IInvariant inv = null; - - for (IPOSource source : sources) { - - IRodinElement srcElement = source.getSource(); - if (!srcElement.exists()) { - bugs.add(status.getElementName()); - break; - } - - if (srcElement instanceof IEvent) { - IEvent tmp = (IEvent) srcElement; - if (((IMachineRoot) tmp.getParent()).equals(origin)) { - evt = tmp; - } - } - if (srcElement instanceof IInvariant) { - IInvariant tmp = (IInvariant) srcElement; - if (((IMachineRoot) tmp.getParent()).equals(origin)) { - inv = tmp; - } - } - } - if (evt != null && inv != null) { - proofs.add(new DischargedProof(origin, inv, evt)); + + EProofStatus pstatus = EProofStatus.UNPROVEN; + + if (!broken + && (confidence > IConfidence.PENDING && confidence <= IConfidence.REVIEWED_MAX)) + pstatus = EProofStatus.REVIEWED; + if (!broken && confidence == IConfidence.DISCHARGED_MAX) + pstatus = EProofStatus.PROVEN; + + IPOSequent sequent = status.getPOSequent(); + IPOSource[] sources = sequent.getSources(); + + String name = sequent.getDescription(); + + ArrayList<SequentSource> s = new ArrayList<SequentSource>( + sources.length); + for (IPOSource source : sources) { + + IRodinElement srcElement = source.getSource(); + if (!srcElement.exists() + || !(srcElement instanceof ILabeledElement)) { + bugs.add(status.getElementName()); + break; } - if (evt == null && inv != null && inv.isTheorem()) { - proofs.add(new DischargedProof(origin, inv, evt)); + + ILabeledElement le = (ILabeledElement) srcElement; + IElementType<? extends IRodinElement> type = srcElement + .getElementType(); + s.add(new SequentSource(type, le.getLabel())); + + if (srcElement instanceof Guard) { + Event srcEvent = (Event) srcElement.getParent(); + String srvEventName = srcEvent.getLabel(); + s.add(new SequentSource(srcEvent.getElementType(), + srvEventName)); } + } + addProof(new ProofObligation(origin, s, name, pstatus)); } if (!bugs.isEmpty()) { @@ -243,10 +258,9 @@ public class ModelTranslator extends AbstractComponentTranslator { final ISCVariant[] variant = machine.getSCVariants(); final AVariantModelClause var; if (variant.length == 1) { - final ExpressionVisitor visitor = new ExpressionVisitor( - new LinkedList<String>()); - variant[0].getExpression(ff, te).accept(visitor); - var = new AVariantModelClause(visitor.getExpression()); + final PExpression expression = translateExpression(ff, te, + variant[0]); + var = new AVariantModelClause(expression); } else if (variant.length == 0) { var = null; } else @@ -382,13 +396,7 @@ public class ModelTranslator extends AbstractComponentTranslator { final List<PPredicate> theoremsList) throws RodinDBException { final ISCGuard[] guards = revent.getSCGuards(); for (final ISCGuard guard : guards) { - final PredicateVisitor visitor = new PredicateVisitor( - new LinkedList<String>()); - final Predicate guardPredicate = guard.getPredicate(ff, localEnv); - // System.out.println("GUARD: " + guard.getLabel() + " -> " - // + guardPredicate); - guardPredicate.accept(visitor); - final PPredicate predicate = visitor.getPredicate(); + final PPredicate predicate = translatePredicate(ff, localEnv, guard); if (guard.isTheorem()) { theoremsList.add(predicate); } else { @@ -423,11 +431,8 @@ public class ModelTranslator extends AbstractComponentTranslator { final List<PWitness> witnessList = new ArrayList<PWitness>( witnesses.length); for (final ISCWitness witness : witnesses) { - final PredicateVisitor visitor = new PredicateVisitor( - new LinkedList<String>()); - final Predicate pp = witness.getPredicate(ff, localEnv); - pp.accept(visitor); - final PPredicate predicate = visitor.getPredicate(); + final PPredicate predicate = translatePredicate(ff, localEnv, + witness); final TIdentifierLiteral label = new TIdentifierLiteral( witness.getLabel()); witnessList.add(new AWitness(label, predicate)); @@ -490,10 +495,8 @@ public class ModelTranslator extends AbstractComponentTranslator { // only use predicates that are defined in the current refinement // level, not in an abstract machine if (!isDefinedInAbstraction(evPredicate)) { - final PredicateVisitor visitor = new PredicateVisitor( - new LinkedList<String>()); - evPredicate.getPredicate(ff, te).accept(visitor); - final PPredicate predicate = visitor.getPredicate(); + final PPredicate predicate = translatePredicate(ff, te, + evPredicate); list.add(predicate); labelMapping.put(predicate, evPredicate); } @@ -528,8 +531,7 @@ public class ModelTranslator extends AbstractComponentTranslator { } @Override - public String getResource() { - return machine.getComponentName(); + public Node getAST() { + return getModelAST(); } - } diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/ProofObligation.java b/de.prob.core/src/de/prob/eventb/translator/internal/ProofObligation.java new file mode 100644 index 0000000000000000000000000000000000000000..39b10069a3de8357e334a8f218384ae907ea96ae --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/internal/ProofObligation.java @@ -0,0 +1,22 @@ +package de.prob.eventb.translator.internal; + +import java.util.ArrayList; + +import org.eventb.core.IEventBRoot; + +public class ProofObligation { + + public final IEventBRoot origin; + public final ArrayList<SequentSource> sources; + public final String kind; + public final EProofStatus discharged; + + public ProofObligation(IEventBRoot origin, ArrayList<SequentSource> s, + String name, EProofStatus pstatus) { + this.origin = origin; + this.sources = s; + this.kind = name; + this.discharged = pstatus; + } + +} diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/SequentSource.java b/de.prob.core/src/de/prob/eventb/translator/internal/SequentSource.java new file mode 100644 index 0000000000000000000000000000000000000000..5575130fc9509990ab94e0aabc665cbceccc5740 --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/internal/SequentSource.java @@ -0,0 +1,17 @@ +package de.prob.eventb.translator.internal; + +import org.rodinp.core.IElementType; +import org.rodinp.core.IRodinElement; + +public class SequentSource { + + public final String type; + public final String label; + + public SequentSource(IElementType<? extends IRodinElement> type, + String label) { + this.type = type.toString().replaceAll("org.eventb.core.", ""); + this.label = label; + } + +} diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/TranslationVisitor.java b/de.prob.core/src/de/prob/eventb/translator/internal/TranslationVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..e1a9a5c336cf370ea6a15b8acfe33332e90bdea5 --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/internal/TranslationVisitor.java @@ -0,0 +1,751 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.eventb.translator.internal; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eventb.core.ast.AssociativeExpression; +import org.eventb.core.ast.AssociativePredicate; +import org.eventb.core.ast.AtomicExpression; +import org.eventb.core.ast.BecomesEqualTo; +import org.eventb.core.ast.BecomesMemberOf; +import org.eventb.core.ast.BecomesSuchThat; +import org.eventb.core.ast.BinaryExpression; +import org.eventb.core.ast.BinaryPredicate; +import org.eventb.core.ast.BoolExpression; +import org.eventb.core.ast.BoundIdentDecl; +import org.eventb.core.ast.BoundIdentifier; +import org.eventb.core.ast.Expression; +import org.eventb.core.ast.ExtendedExpression; +import org.eventb.core.ast.ExtendedPredicate; +import org.eventb.core.ast.Formula; +import org.eventb.core.ast.FreeIdentifier; +import org.eventb.core.ast.ISimpleVisitor; +import org.eventb.core.ast.IntegerLiteral; +import org.eventb.core.ast.LiteralPredicate; +import org.eventb.core.ast.MultiplePredicate; +import org.eventb.core.ast.Predicate; +import org.eventb.core.ast.QuantifiedExpression; +import org.eventb.core.ast.QuantifiedPredicate; +import org.eventb.core.ast.RelationalPredicate; +import org.eventb.core.ast.SetExtension; +import org.eventb.core.ast.SimplePredicate; +import org.eventb.core.ast.UnaryExpression; +import org.eventb.core.ast.UnaryPredicate; + +import de.be4.classicalb.core.parser.node.*; + +public class TranslationVisitor implements ISimpleVisitor { + private static final String UNCOVERED_PREDICATE = "Uncovered Predicate"; + + private LookupStack<PPredicate> predicates = new LookupStack<PPredicate>(); + private LookupStack<PExpression> expressions = new LookupStack<PExpression>(); + private LookupStack<PSubstitution> substitutions = new LookupStack<PSubstitution>(); + private LookupStack<String> boundVariables = new LookupStack<String>(); + + private boolean usesTheories = false; + + public void visitAssociativeExpression( + final AssociativeExpression expression) { + // BUNION, BINTER, BCOMP, FCOMP, OVR, PLUS, MUL + List<PExpression> exprs = getSubExpressions(expression.getChildren()); + final PExpression result; + switch (expression.getTag()) { + case Formula.BUNION: + result = recurseBUNION(exprs); + break; + case Formula.BINTER: + result = recurseBINTER(exprs); + break; + case Formula.BCOMP: + result = recurseBCOMP(exprs); + break; + case Formula.FCOMP: + result = recurseFCOMP(exprs); + break; + case Formula.OVR: + result = recurseOVR(exprs); + break; + case Formula.PLUS: + result = recursePLUS(exprs); + break; + case Formula.MUL: + result = recurseMUL(exprs); + break; + default: + throw new AssertionError(UNCOVERED_PREDICATE); + } + expressions.push(result); + } + + private PExpression recurseFCOMP(final List<PExpression> list) { + final PExpression right = list.size() == 2 ? list.get(1) + : recurseFCOMP(list.subList(1, list.size())); + return new ACompositionExpression(list.get(0), right); + } + + private PExpression recurseOVR(final List<PExpression> list) { + final PExpression right = list.size() == 2 ? list.get(1) + : recurseOVR(list.subList(1, list.size())); + return new AOverwriteExpression(list.get(0), right); + } + + private PExpression recursePLUS(final List<PExpression> list) { + final PExpression right = list.size() == 2 ? list.get(1) + : recursePLUS(list.subList(1, list.size())); + return new AAddExpression(list.get(0), right); + } + + private PExpression recurseMUL(final List<PExpression> list) { + final PExpression right = list.size() == 2 ? list.get(1) + : recurseMUL(list.subList(1, list.size())); + return new AMultiplicationExpression(list.get(0), right); + } + + private PExpression recurseBUNION(final List<PExpression> list) { + final PExpression right = list.size() == 2 ? list.get(1) + : recurseBUNION(list.subList(1, list.size())); + return new AUnionExpression(list.get(0), right); + } + + private PExpression recurseBINTER(final List<PExpression> list) { + final PExpression right = list.size() == 2 ? list.get(1) + : recurseBINTER(list.subList(1, list.size())); + return new AIntersectionExpression(list.get(0), right); + } + + private PExpression recurseBCOMP(final List<PExpression> list) { + final PExpression right = list.size() == 2 ? list.get(1) + : recurseBCOMP(list.subList(1, list.size())); + return new ARingExpression(list.get(0), right); + } + + public void visitAssociativePredicate(final AssociativePredicate predicate) { + List<PPredicate> children = getSubPredicates(predicate.getChildren()); + final PPredicate result; + switch (predicate.getTag()) { + case Formula.LOR: + result = recurseOR(children); + break; + case Formula.LAND: + result = recurseAND(children); + break; + case Formula.LEQV: + result = recurseEQV(children); + break; + default: + throw new AssertionError(UNCOVERED_PREDICATE); + } + predicates.push(result); + } + + private PPredicate recurseOR(final List<PPredicate> list) { + final PPredicate right = list.size() == 2 ? list.get(1) + : recurseOR(list.subList(1, list.size())); + return new ADisjunctPredicate(list.get(0), right); + } + + private PPredicate recurseAND(final List<PPredicate> list) { + final PPredicate right = list.size() == 2 ? list.get(1) + : recurseAND(list.subList(1, list.size())); + return new AConjunctPredicate(list.get(0), right); + } + + private PPredicate recurseEQV(final List<PPredicate> list) { + final PPredicate right = list.size() == 2 ? list.get(1) + : recurseEQV(list.subList(1, list.size())); + return new AEquivalencePredicate(list.get(0), right); + } + + public void visitAtomicExpression(final AtomicExpression expression) { + final PExpression result; + switch (expression.getTag()) { + case Formula.INTEGER: + result = new AIntegerSetExpression(); + break; + case Formula.NATURAL: + result = new ANaturalSetExpression(); + break; + case Formula.NATURAL1: + result = new ANatural1SetExpression(); + break; + case Formula.BOOL: + result = new ABoolSetExpression(); + break; + case Formula.TRUE: + result = new ABooleanTrueExpression(); + break; + case Formula.FALSE: + result = new ABooleanFalseExpression(); + break; + case Formula.EMPTYSET: + result = new AEmptySetExpression(); + break; + case Formula.KPRED: + result = new APredecessorExpression(); + break; + case Formula.KSUCC: + result = new ASuccessorExpression(); + break; + case Formula.KPRJ1_GEN: // see task#215 + result = new AEventBFirstProjectionV2Expression(); + break; + case Formula.KPRJ2_GEN: + result = new AEventBSecondProjectionV2Expression(); + break; + case Formula.KID_GEN: + result = new AEventBIdentityExpression(); + break; + default: + throw new AssertionError("Uncovered Expression " + expression); + } + expressions.push(result); + } + + public void visitBecomesEqualTo(final BecomesEqualTo assignment) { + final List<PExpression> lhs = getSubExpressions(assignment + .getAssignedIdentifiers()); + final List<PExpression> rhs = getSubExpressions(assignment + .getExpressions()); + substitutions.push(new AAssignSubstitution(lhs, rhs)); + } + + public void visitBecomesMemberOf(final BecomesMemberOf assignment) { + final List<PExpression> lhs = getSubExpressions(assignment + .getAssignedIdentifiers()); + final PExpression set = getExpression(assignment.getSet()); + substitutions.push(new ABecomesElementOfSubstitution(lhs, set)); + } + + public void visitBecomesSuchThat(final BecomesSuchThat assignment) { + final List<PExpression> lhs = getSubExpressions(assignment + .getAssignedIdentifiers()); + final int originalBoundSize = boundVariables.size(); + for (final FreeIdentifier id : assignment.getFreeIdentifiers()) { + boundVariables.push(id.getName() + "'"); + } + final PPredicate predicate = getPredicate(assignment.getCondition()); + boundVariables.shrinkToSize(originalBoundSize); + substitutions.push(new ABecomesSuchSubstitution(lhs, predicate)); + } + + public void visitBinaryExpression(final BinaryExpression expression) { + final PExpression exL = getExpression(expression.getLeft()); + final PExpression exR = getExpression(expression.getRight()); + final PExpression result; + switch (expression.getTag()) { + case Formula.MAPSTO: + result = new ACoupleExpression(Arrays.asList(new PExpression[] { + exL, exR })); + break; + case Formula.REL: + result = new ARelationsExpression(exL, exR); + break; + case Formula.TREL: + result = new ATotalRelationExpression(exL, exR); + break; + case Formula.SREL: + result = new ASurjectionRelationExpression(exL, exR); + break; + case Formula.STREL: + result = new ATotalSurjectionRelationExpression(exL, exR); + break; + case Formula.PFUN: + result = new APartialFunctionExpression(exL, exR); + break; + case Formula.TFUN: + result = new ATotalFunctionExpression(exL, exR); + break; + case Formula.PINJ: + result = new APartialInjectionExpression(exL, exR); + break; + case Formula.TINJ: + result = new ATotalInjectionExpression(exL, exR); + break; + case Formula.PSUR: + result = new APartialSurjectionExpression(exL, exR); + break; + case Formula.TSUR: + result = new ATotalSurjectionExpression(exL, exR); + break; + case Formula.TBIJ: + result = new ATotalBijectionExpression(exL, exR); + break; + case Formula.SETMINUS: + result = new ASetSubtractionExpression(exL, exR); + break; + case Formula.CPROD: + result = new ACartesianProductExpression(exL, exR); + break; + case Formula.DPROD: + result = new ADirectProductExpression(exL, exR); + break; + case Formula.PPROD: + result = new AParallelProductExpression(exL, exR); + break; + case Formula.DOMRES: + result = new ADomainRestrictionExpression(exL, exR); + break; + case Formula.DOMSUB: + result = new ADomainSubtractionExpression(exL, exR); + break; + case Formula.RANRES: + result = new ARangeRestrictionExpression(exL, exR); + break; + case Formula.RANSUB: + result = new ARangeSubtractionExpression(exL, exR); + break; + case Formula.UPTO: + result = new AIntervalExpression(exL, exR); + break; + case Formula.MINUS: + result = new AMinusExpression(exL, exR); + break; + case Formula.DIV: + result = new ADivExpression(exL, exR); + break; + case Formula.MOD: + result = new AModuloExpression(exL, exR); + break; + case Formula.EXPN: + result = new APowerOfExpression(exL, exR); + break; + case Formula.FUNIMAGE: + result = new AFunctionExpression(exL, + Arrays.asList(new PExpression[] { exR })); + break; + case Formula.RELIMAGE: + result = new AImageExpression(exL, exR); + break; + default: + throw new AssertionError("Uncovered Expression"); + } + expressions.push(result); + } + + public void visitBinaryPredicate(final BinaryPredicate predicate) { + final PPredicate left = getPredicate(predicate.getLeft()); + final PPredicate right = getPredicate(predicate.getRight()); + final PPredicate result; + switch (predicate.getTag()) { + case Formula.LIMP: + result = new AImplicationPredicate(left, right); + break; + case Formula.LEQV: + result = new AEquivalencePredicate(left, right); + break; + default: + throw new AssertionError(UNCOVERED_PREDICATE); + } + predicates.push(result); + } + + public void visitBoolExpression(final BoolExpression expression) { + final PPredicate pred = getPredicate(expression.getPredicate()); + expressions.push(new AConvertBoolExpression(pred)); + } + + public void visitBoundIdentDecl(final BoundIdentDecl boundIdentDecl) { + final String name = boundIdentDecl.getName(); + boundVariables.push(name); + expressions.push(createIdentifierExpression(name)); + } + + private AIdentifierExpression createIdentifierExpression(final String name) { + return new AIdentifierExpression( + Arrays.asList(new TIdentifierLiteral[] { new TIdentifierLiteral( + name) })); + } + + public void visitBoundIdentifier(final BoundIdentifier identifierExpression) { + final String name = boundVariables.get(identifierExpression + .getBoundIndex()); + expressions.push(createIdentifierExpression(name)); + } + + public void visitFreeIdentifier(final FreeIdentifier identifierExpression) { + expressions.push(createIdentifierExpression(identifierExpression + .getName())); + } + + public void visitIntegerLiteral(final IntegerLiteral expression) { + final String value = expression.getValue().toString(); + expressions.push(new AIntegerExpression(new TIntegerLiteral(value))); + } + + public void visitLiteralPredicate(final LiteralPredicate predicate) { + final PPredicate result; + switch (predicate.getTag()) { + case Formula.BTRUE: + result = new ATruthPredicate(); + break; + case Formula.BFALSE: + result = new AFalsityPredicate(); + break; + default: + throw new AssertionError(UNCOVERED_PREDICATE); + } + predicates.push(result); + } + + public void visitQuantifiedExpression(final QuantifiedExpression expression) { + // Add quantified identifiers to bound list and recursively create + // subtrees representing the identifiers + int originalBoundSize = boundVariables.size(); + final List<PExpression> list = getSubExpressions(expression + .getBoundIdentDecls()); + final PPredicate pr = getPredicate(expression.getPredicate()); + final PExpression ex = getExpression(expression.getExpression()); + boundVariables.shrinkToSize(originalBoundSize); + + final PExpression result; + switch (expression.getTag()) { + case Formula.QUNION: + result = new AQuantifiedUnionExpression(list, pr, ex); + break; + case Formula.QINTER: + result = new AQuantifiedIntersectionExpression(list, pr, ex); + break; + case Formula.CSET: + result = new AEventBComprehensionSetExpression(list, ex, pr); + break; + default: + throw new AssertionError(UNCOVERED_PREDICATE); + } + expressions.push(result); + } + + public void visitQuantifiedPredicate(final QuantifiedPredicate predicate) { + // Add quantified identifiers to bound list and recursively create + // subtrees representing the identifiers + int originalBoundSize = boundVariables.size(); + final List<PExpression> list = getSubExpressions(predicate + .getBoundIdentDecls()); + // Recursively analyze the predicate (important, bounds are already set) + final PPredicate pred = getPredicate(predicate.getPredicate()); + boundVariables.shrinkToSize(originalBoundSize); + + final PPredicate result; + switch (predicate.getTag()) { + case Formula.EXISTS: + result = new AExistsPredicate(list, pred); + break; + case Formula.FORALL: + final PPredicate impl = pred instanceof AImplicationPredicate ? pred + : new AImplicationPredicate(new ATruthPredicate(), pred); + result = new AForallPredicate(list, impl); + break; + default: + throw new AssertionError(UNCOVERED_PREDICATE); + } + predicates.push(result); + } + + public void visitRelationalPredicate(final RelationalPredicate predicate) { + // EQUAL, NOTEQUAL, LT, LE, GT, GE, IN, NOTIN, SUBSET, + // NOTSUBSET, SUBSETEQ, NOTSUBSETEQ + final PExpression left = getExpression(predicate.getLeft()); + final PExpression right = getExpression(predicate.getRight()); + final PPredicate result; + switch (predicate.getTag()) { + case Formula.EQUAL: + result = new AEqualPredicate(left, right); + break; + case Formula.NOTEQUAL: + result = new ANotEqualPredicate(left, right); + break; + case Formula.LT: + result = new ALessPredicate(left, right); + break; + case Formula.LE: + result = new ALessEqualPredicate(left, right); + break; + case Formula.GT: + result = new AGreaterPredicate(left, right); + break; + case Formula.GE: + result = new AGreaterEqualPredicate(left, right); + break; + case Formula.IN: + result = new AMemberPredicate(left, right); + break; + case Formula.NOTIN: + result = new ANotMemberPredicate(left, right); + break; + case Formula.SUBSET: + result = new ASubsetStrictPredicate(left, right); + break; + case Formula.NOTSUBSET: + result = new ANotSubsetStrictPredicate(left, right); + break; + case Formula.SUBSETEQ: + result = new ASubsetPredicate(left, right); + break; + case Formula.NOTSUBSETEQ: + result = new ANotSubsetPredicate(left, right); + break; + default: + throw new AssertionError(UNCOVERED_PREDICATE); + } + predicates.push(result); + } + + public void visitSetExtension(final SetExtension expression) { + final Expression[] members = expression.getMembers(); + final List<PExpression> list = getSubExpressions(members); + expressions.push(new ASetExtensionExpression(list)); + } + + public void visitSimplePredicate(final SimplePredicate predicate) { + final PPredicate result; + if (predicate.getTag() == Formula.KFINITE) { + result = new AFinitePredicate( + getExpression(predicate.getExpression())); + } else { + throw new AssertionError(UNCOVERED_PREDICATE); + } + predicates.push(result); + } + + @SuppressWarnings("deprecation") + public void visitUnaryExpression(final UnaryExpression expression) { + final PExpression exp = getExpression(expression.getChild()); + final PExpression result; + switch (expression.getTag()) { + case Formula.KCARD: + result = new ACardExpression(exp); + break; + case Formula.POW: + result = new APowSubsetExpression(exp); + break; + case Formula.POW1: + result = new APow1SubsetExpression(exp); + break; + case Formula.KUNION: + result = new AGeneralUnionExpression(exp); + break; + case Formula.KINTER: + result = new AGeneralIntersectionExpression(exp); + break; + case Formula.KDOM: + result = new ADomainExpression(exp); + break; + case Formula.KRAN: + result = new ARangeExpression(exp); + break; + case Formula.KPRJ1: + result = new AEventBFirstProjectionExpression(exp); + break; + case Formula.KPRJ2: + result = new AEventBSecondProjectionExpression(exp); + break; + case Formula.KID: + result = new AIdentityExpression(exp); + break; + case Formula.KMIN: + result = new AMinExpression(exp); + break; + case Formula.KMAX: + result = new AMaxExpression(exp); + break; + case Formula.CONVERSE: + result = new AReverseExpression(exp); + break; + case Formula.UNMINUS: + result = new AUnaryMinusExpression(exp); + break; + default: + throw new AssertionError("Uncovered Expression"); + } + expressions.push(result); + } + + public void visitUnaryPredicate(final UnaryPredicate predicate) { + final PPredicate result; + if (predicate.getTag() == Formula.NOT) { + result = new ANegationPredicate(getPredicate(predicate.getChild())); + } else { + throw new AssertionError(UNCOVERED_PREDICATE); + } + predicates.push(result); + } + + public void visitMultiplePredicate(final MultiplePredicate predicate) { + final PPredicate result; + if (predicate.getTag() == Formula.KPARTITION) { + final List<PExpression> expressions = getSubExpressions(predicate + .getChildren()); + if (expressions.size() > 0) { + PExpression set = expressions.remove(0); + result = new APartitionPredicate(set, expressions); + } else { + throw new AssertionError("to few arguments for PARTITION"); + } + } else { + throw new AssertionError(UNCOVERED_PREDICATE); + } + predicates.push(result); + } + + @Override + public void visitExtendedExpression(final ExtendedExpression expression) { + final String symbol = expression.getExtension().getSyntaxSymbol(); + List<PExpression> childExprs = getSubExpressions(expression + .getChildExpressions()); + List<PPredicate> childPreds = getSubPredicates(expression + .getChildPredicates()); + expressions.push(new AExtendedExprExpression(new TIdentifierLiteral( + symbol), childExprs, childPreds)); + usesTheories = true; + } + + @Override + public void visitExtendedPredicate(final ExtendedPredicate predicate) { + final String symbol = predicate.getExtension().getSyntaxSymbol(); + List<PExpression> childExprs = getSubExpressions(predicate + .getChildExpressions()); + List<PPredicate> childPreds = getSubPredicates(predicate + .getChildPredicates()); + predicates.push(new AExtendedPredPredicate(new TIdentifierLiteral( + symbol), childExprs, childPreds)); + usesTheories = true; + } + + private List<PExpression> getSubExpressions(final Formula<?>[] children) { + for (final Formula<?> f : children) { + f.accept(this); + } + return expressions.removeLastElements(children.length); + } + + private List<PPredicate> getSubPredicates(final Formula<?>[] children) { + for (final Formula<?> f : children) { + f.accept(this); + } + return predicates.removeLastElements(children.length); + } + + private PPredicate getPredicate(final Predicate predicate) { + predicate.accept(this); + return predicates.pop(); + } + + private PExpression getExpression(final Expression expression) { + expression.accept(this); + return expressions.pop(); + } + + /** + * Lookup stack implements a stack with additional arbitrary read access. + * + * Additionally, there is a method to remove elements until the resulting + * stack has a certain size. + * + * Also there is another method to remove n elements at the same time into a + * list. + * + * @param <T> + */ + private static class LookupStack<T> { + private List<T> elements = new ArrayList<T>(); + + public void push(T elem) { + elements.add(elem); + } + + public T pop() { + return elements.remove(elements.size() - 1); + } + + public int size() { + return elements.size(); + } + + public T get(int pos) { + return elements.get(elements.size() - pos - 1); + } + + void shrinkToSize(int size) { + final int oSize = elements.size(); + final int rSize = oSize - size; + for (int i = 0; i < rSize; i++) { + elements.remove(oSize - 1 - i); + } + } + + List<T> removeLastElements(int toRemove) { + final int targetSize = elements.size() - toRemove; + List<T> result = new ArrayList<T>(toRemove); + for (int i = 0; i < toRemove; i++) { + result.add(elements.get(targetSize + i)); + } + shrinkToSize(targetSize); + return result; + } + + @Override + public String toString() { + return elements.toString(); + } + } + + public PPredicate getPredicate() { + assertExactStacksize(predicates); + return predicates.pop(); + } + + public PExpression getExpression() { + assertExactStacksize(expressions); + return expressions.pop(); + } + + public PSubstitution getSubstitution() { + assertExactStacksize(substitutions); + return substitutions.pop(); + } + + private void assertExactStacksize(LookupStack<?> stack) { + if (stack.size() != 1) { + throw new AssertionError( + "Exactly one element on the stack expected, but were " + + predicates.size()); + + } + } + + public static boolean checkNewImplementation(Predicate p, + Node oldImplementation) { + TranslationVisitor visitor = new TranslationVisitor(); + p.accept(visitor); + final String expected = oldImplementation.toString(); + final String actual = visitor.getPredicate().toString(); + if (!expected.equals(actual)) { + throw new AssertionError("Expected:\n" + expected + "\n but was:\n" + + actual); + } + return visitor.usesTheories; + } + + public static boolean checkNewImplementation(Expression e, + Node oldImplementation) { + TranslationVisitor visitor = new TranslationVisitor(); + e.accept(visitor); + final String expected = oldImplementation.toString(); + final String actual = visitor.getExpression().toString(); + if (!expected.equals(actual)) { + throw new AssertionError("Expected:\n" + expected + "\n but was:\n" + + actual); + } + return visitor.usesTheories; + } + + public boolean usesTheories() { + return usesTheories; + } +} diff --git a/de.prob.core/src/de/prob/exceptions/ProBException.java b/de.prob.core/src/de/prob/exceptions/ProBException.java index 0b31e6a42d165a7c308460cf5f7881f898307383..79e6f3b3b1bc20d18f934b5ab864e56c063b1c49 100644 --- a/de.prob.core/src/de/prob/exceptions/ProBException.java +++ b/de.prob.core/src/de/prob/exceptions/ProBException.java @@ -23,7 +23,7 @@ public abstract class ProBException extends Exception { } public ProBException(final Throwable e) { - this(e.getLocalizedMessage(), e, true); + this(e.getLocalizedMessage(), e, false); } public ProBException(final String message, final Throwable e, diff --git a/de.prob.core/src/de/prob/model/eventb/Action.java b/de.prob.core/src/de/prob/model/eventb/Action.java deleted file mode 100644 index 6eb7c43c99c049fc6328e4e4645e712c2b5efcbe..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/eventb/Action.java +++ /dev/null @@ -1,36 +0,0 @@ -package de.prob.model.eventb; - -import java.util.Collections; -import java.util.List; - -import de.prob.model.representation.IEntity; - -public class Action implements IEntity { - - private final String code; - private final String name; - - public Action(String code, String name) { - this.code = code; - this.name = name; - } - - @Override - public List<IEntity> getChildren() { - return Collections.emptyList(); - } - - @Override - public boolean hasChildren() { - return false; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - -} diff --git a/de.prob.core/src/de/prob/model/eventb/Context.java b/de.prob.core/src/de/prob/model/eventb/Context.java new file mode 100644 index 0000000000000000000000000000000000000000..a978d6d5f5bb6709811241b7edecc5ccc6078a0a --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/Context.java @@ -0,0 +1,41 @@ +package de.prob.model.eventb; + +import java.util.List; + +import de.prob.model.representation.AbstractElement; +import de.prob.model.representation.Axiom; +import de.prob.model.representation.BSet; +import de.prob.model.representation.Constant; +public class Context extends AbstractElement { + + private final String name; + + public Context(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void addExtends(final List<Context> contexts) { + put(Context.class, contexts); + } + + public void addSets(final List<BSet> sets) { + put(BSet.class, sets); + } + + public void addConstants(final List<EventBConstant> constants) { + put(Constant.class, constants); + } + + public void addAxioms(final List<EventBAxiom> axioms) { + put(Axiom.class, axioms); + } + + @Override + public String toString() { + return name; + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EBContext.java b/de.prob.core/src/de/prob/model/eventb/EBContext.java deleted file mode 100644 index 9cb041b0e403f340bfd0840b877eb3dc2092a71a..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/eventb/EBContext.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.prob.model.eventb; - -import java.util.Arrays; - -import de.prob.model.representation.IEntity; -import de.prob.model.representation.Label; - -public class EBContext extends Label { - - public Label sets = new Label("Sets"); - public Label constants = new Label("Constants"); - public Label axioms = new Label("Axioms"); - - public EBContext(final String name) { - super(name); - - children.addAll(Arrays - .asList(new IEntity[] { sets, constants, axioms })); - } - - public void addSet(final String set) { - sets.addChild(new EventB(set)); - } - - public void addConstant(final String constant) { - constants.addChild(new EventB(constant)); - } - - public void addAxiom(final String axiom, String aname) { - axioms.addChild(new EventB(axiom,aname)); - } - -} diff --git a/de.prob.core/src/de/prob/model/eventb/EBEvent.java b/de.prob.core/src/de/prob/model/eventb/EBEvent.java deleted file mode 100644 index 12139186dd80a9ee2e47659b24156232fe98effb..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/eventb/EBEvent.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.prob.model.eventb; - -import java.util.Arrays; - -import de.prob.model.representation.IEntity; -import de.prob.model.representation.Label; - -public class EBEvent extends Label { - - final public Label refines = new Label("REFINES"); - final public Label parameters = new Label("ANY"); - final public Label guards = new Label("WHERE"); - final public Label witnesses = new Label("WITH"); - final public Label actions = new Label("THEN"); - - public EBEvent(final String name) { - super(name); - children.addAll(Arrays.asList(new IEntity[] { refines, parameters, - guards })); - } - - @Override - public String toString() { - return name; - } - - public void addRefinement(final String refinementName) { - refines.addChild(new Label(refinementName)); - } - - public void addParameter(final String parameter) { - parameters.addChild(new EventB(parameter)); - } - - public void addGuard(final String guard, String gname) { - guards.addChild(new EventB(guard,gname)); - } - - public void addWitness(final String witness,String wname) { - witnesses.addChild(new EventB(witness,wname)); - } - - public void addAction(final String action, String aname) { - actions.addChild(new Action(action, aname)); - } -} diff --git a/de.prob.core/src/de/prob/model/eventb/EBMachine.java b/de.prob.core/src/de/prob/model/eventb/EBMachine.java deleted file mode 100644 index 08bbcfd6dee64c10e0d8cf52a8538755b74eb9b8..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/eventb/EBMachine.java +++ /dev/null @@ -1,36 +0,0 @@ -package de.prob.model.eventb; - -import java.util.Arrays; - -import de.prob.model.representation.IEntity; -import de.prob.model.representation.Label; - -public class EBMachine extends Label { - - final public Label variables = new Label("Variables"); - final public Label invariants = new Label("Invariants"); - final public Label variant = new Label("Variant"); - final public Label events = new Label("Events"); - - public EBMachine(final String name) { - super(name); - children.addAll(Arrays.asList(new IEntity[] { variables, invariants, - variant, events })); - } - - public void addVariable(final String variable) { - variables.addChild(new EventB(variable)); - } - - public void addInvariant(final String invariant, String iname) { - invariants.addChild(new EventB(invariant, iname)); - } - - public void addVariant(final String variant) { - this.variant.addChild(new EventB(variant)); - } - - public void addEvent(final EBEvent event) { - events.addChild(event); - } -} diff --git a/de.prob.core/src/de/prob/model/eventb/Event.java b/de.prob.core/src/de/prob/model/eventb/Event.java new file mode 100644 index 0000000000000000000000000000000000000000..e9071fa4c1f7362e3b20f21ec32b5b8d483a1bf4 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/Event.java @@ -0,0 +1,75 @@ +package de.prob.model.eventb; + +import java.util.List; +import java.util.Set; + +import de.prob.model.representation.AbstractElement; +import de.prob.model.representation.Action; +import de.prob.model.representation.BEvent; +import de.prob.model.representation.Guard; + +public class Event extends BEvent { + + private final EventType type; + + public enum EventType { + ORDINARY, CONVERGENT, ANTICIPATED + } + + public Event(final String name, final EventType type) { + super(name); + this.type = type; + } + + public void addRefines(final List<Event> refines) { + put(Event.class, refines); + } + + public void addGuards(final List<EventBGuard> guards) { + put(Guard.class, guards); + } + + public void addActions(final List<EventBAction> actions) { + put(Action.class, actions); + } + + public void addWitness(final List<Witness> witness) { + put(Witness.class, witness); + } + + public void addParameters(final List<EventParameter> parameters) { + put(EventParameter.class, parameters); + } + + public EventType getType() { + return type; + } + + @Override + public String toString() { + return getName(); + } + + public String print() { + StringBuilder sb = new StringBuilder(); + sb.append("Name: " + getName() + "\n"); + sb.append("Type: " + type.toString() + "\n"); + addChildren("Refines", getChildrenOfType(Event.class), sb); + addChildren("Any", getChildrenOfType(EventParameter.class), sb); + addChildren("Where", getChildrenOfType(Guard.class), sb); + addChildren("With", getChildrenOfType(Witness.class), sb); + addChildren("Then", getChildrenOfType(Action.class), sb); + return sb.toString(); + } + + private void addChildren(final String name, + final Set<? extends AbstractElement> childrenOfType, + final StringBuilder sb) { + if (!childrenOfType.isEmpty()) { + sb.append(name + ": \n"); + for (AbstractElement abstractElement : childrenOfType) { + sb.append("\t" + abstractElement.toString() + "\n"); + } + } + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EventB.java b/de.prob.core/src/de/prob/model/eventb/EventB.java deleted file mode 100644 index c3f7ae108bcbbab9ba1e927b5be15d23c333b7e1..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/eventb/EventB.java +++ /dev/null @@ -1,132 +0,0 @@ -package de.prob.model.eventb; - -import static de.prob.animator.domainobjects.EvalElementType.EXPRESSION; -import static de.prob.animator.domainobjects.EvalElementType.PREDICATE; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import org.eventb.core.ast.ASTProblem; -import org.eventb.core.ast.Expression; -import org.eventb.core.ast.FormulaFactory; -import org.eventb.core.ast.IParseResult; -import org.eventb.core.ast.LanguageVersion; -import org.eventb.core.ast.Predicate; - -import de.prob.animator.domainobjects.IEvalElement; -import de.prob.eventb.translator.ExpressionVisitor; -import de.prob.eventb.translator.PredicateVisitor; -import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; -import de.be4.classicalb.core.parser.node.Node; -import de.prob.model.representation.FormulaUUID; -import de.prob.model.representation.IEntity; -import de.prob.prolog.output.IPrologTermOutput; -import de.prob.unicode.UnicodeTranslator; - -public class EventB implements IEvalElement, IEntity { - - public FormulaUUID uuid = new FormulaUUID(); - - private final String code; - private String kind; - private Node ast = null; - - private final String name; - - public EventB(final String code, String name) { - this.code = code; - this.name = name; - } - - public EventB(String code) { - this(code, ""); - } - - private void ensureParsed() { - final String unicode = UnicodeTranslator.toUnicode(code); - kind = PREDICATE.toString(); - IParseResult parseResult = FormulaFactory.getDefault().parsePredicate( - unicode, LanguageVersion.LATEST, null); - - if (!parseResult.hasProblem()) { - ast = preparePredicateAst(parseResult); - - } else { - kind = EXPRESSION.toString(); - parseResult = FormulaFactory.getDefault().parseExpression(unicode, - LanguageVersion.LATEST, null); - ast = prepareExpressionAst(parseResult); - } - if (parseResult.hasProblem()) { - throwException(code, parseResult); - } - } - - private Node prepareExpressionAst(final IParseResult parseResult) { - final Expression expr = parseResult.getParsedExpression(); - final ExpressionVisitor visitor = new ExpressionVisitor( - new LinkedList<String>()); - expr.accept(visitor); - final Node expression = visitor.getExpression(); - return expression; - } - - private Node preparePredicateAst(final IParseResult parseResult) { - final Predicate parsedPredicate = parseResult.getParsedPredicate(); - final PredicateVisitor visitor = new PredicateVisitor(); - parsedPredicate.accept(visitor); - return visitor.getPredicate(); - } - - private void throwException(final String code, - final IParseResult parseResult) { - final List<ASTProblem> problems = parseResult.getProblems(); - final ArrayList<String> msgs = new ArrayList<String>(); - for (final ASTProblem astProblem : problems) { - msgs.add(astProblem.getMessage().toString()); - } - StringBuilder sb = new StringBuilder(); - for (String string : msgs) { - sb.append(string + "\n"); - } - final String error = sb.toString(); - throw new RuntimeException("Cannot parse " + code + ":\n " + error); // FIXME - } - - @Override - public String getCode() { - return code; - } - - @Override - public void printProlog(final IPrologTermOutput pout) { - if (ast == null) { - ensureParsed(); - } - - assert ast != null; - final ASTProlog prolog = new ASTProlog(pout, null); - ast.apply(prolog); - } - - @Override - public String getKind() { - return kind; - } - - @Override - public List<IEntity> getChildren() { - return new ArrayList<IEntity>(); - } - - @Override - public boolean hasChildren() { - return false; - } - - public String getName() { - return name; - } - -} diff --git a/de.prob.core/src/de/prob/model/eventb/EventBAction.java b/de.prob.core/src/de/prob/model/eventb/EventBAction.java new file mode 100644 index 0000000000000000000000000000000000000000..495a3306f026322ed66be61397898b69a80b8d47 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/EventBAction.java @@ -0,0 +1,22 @@ +package de.prob.model.eventb; + +import de.prob.model.representation.Action; + +public class EventBAction extends Action { + + private final String name; + + public EventBAction(final String name, final String code) { + super(code); + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name + ": " + getCode(); + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EventBAxiom.java b/de.prob.core/src/de/prob/model/eventb/EventBAxiom.java new file mode 100644 index 0000000000000000000000000000000000000000..a21374bf45edd9b092e3397ca8f89e395a6d345b --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/EventBAxiom.java @@ -0,0 +1,25 @@ +package de.prob.model.eventb; + +import de.prob.animator.domainobjects.EventB; +import de.prob.model.representation.Axiom; + +public class EventBAxiom extends Axiom { + + private final String name; + private final boolean theorem; + + public EventBAxiom(final String name, final String code, + final boolean theorem) { + super(new EventB(code)); + this.name = name; + this.theorem = theorem; + } + + public String getName() { + return name; + } + + public boolean isTheorem() { + return theorem; + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EventBConstant.java b/de.prob.core/src/de/prob/model/eventb/EventBConstant.java new file mode 100644 index 0000000000000000000000000000000000000000..935847691c782219755fcb792ae6aeb8e5732f66 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/EventBConstant.java @@ -0,0 +1,18 @@ +package de.prob.model.eventb; + +import de.prob.animator.domainobjects.EventB; +import de.prob.model.representation.Constant; + +public class EventBConstant extends Constant { + + private final String name; + + public EventBConstant(final String name) { + super(new EventB(name)); + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EventBGuard.java b/de.prob.core/src/de/prob/model/eventb/EventBGuard.java new file mode 100644 index 0000000000000000000000000000000000000000..2e2bc569062f52170a32eef5e5eba9ad2428f372 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/EventBGuard.java @@ -0,0 +1,25 @@ +package de.prob.model.eventb; + +import de.prob.animator.domainobjects.EventB; +import de.prob.model.representation.Guard; + +public class EventBGuard extends Guard { + + private final String name; + private final boolean theorem; + + public EventBGuard(final String name, final String code, + final boolean theorem) { + super(new EventB(code)); + this.name = name; + this.theorem = theorem; + } + + public String getName() { + return name; + } + + public boolean isTheorem() { + return theorem; + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EventBInvariant.java b/de.prob.core/src/de/prob/model/eventb/EventBInvariant.java new file mode 100644 index 0000000000000000000000000000000000000000..a49c05d459fc7cb23a014704b4600d0158518713 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/EventBInvariant.java @@ -0,0 +1,25 @@ +package de.prob.model.eventb; + +import de.prob.animator.domainobjects.EventB; +import de.prob.model.representation.Invariant; + +public class EventBInvariant extends Invariant { + + private final String name; + private final boolean theorem; + + public EventBInvariant(final String name, final String code, + final boolean theorem) { + super(new EventB(code)); + this.name = name; + this.theorem = theorem; + } + + public String getName() { + return name; + } + + public boolean isTheorem() { + return theorem; + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EventBMachine.java b/de.prob.core/src/de/prob/model/eventb/EventBMachine.java new file mode 100644 index 0000000000000000000000000000000000000000..5998cc8b87e4842b44004ab4165825e7fe427ae8 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/EventBMachine.java @@ -0,0 +1,38 @@ +package de.prob.model.eventb; + +import java.util.List; + +import de.prob.model.representation.BEvent; +import de.prob.model.representation.Invariant; +import de.prob.model.representation.Machine; +import de.prob.model.representation.Variable; + +public class EventBMachine extends Machine { + public EventBMachine(final String name) { + super(name); + } + + public void addRefines(final List<EventBMachine> refines) { + put(Machine.class, refines); + } + + public void addSees(final List<Context> sees) { + put(Context.class, sees); + } + + public void addVariables(final List<EventBVariable> variables) { + put(Variable.class, variables); + } + + public void addInvariants(final List<EventBInvariant> invariants) { + put(Invariant.class, invariants); + } + + public void addVariant(final List<Variant> variant) { + put(Variant.class, variant); + } + + public void addEvents(final List<Event> events) { + put(BEvent.class, events); + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EventBVariable.java b/de.prob.core/src/de/prob/model/eventb/EventBVariable.java new file mode 100644 index 0000000000000000000000000000000000000000..4ecf1af228d618822d89ee9840f3ecff16368ad6 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/EventBVariable.java @@ -0,0 +1,18 @@ +package de.prob.model.eventb; + +import de.prob.animator.domainobjects.EventB; +import de.prob.model.representation.Variable; + +public class EventBVariable extends Variable { + + private final String name; + + public EventBVariable(final String name) { + super(new EventB(name)); + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/EventParameter.java b/de.prob.core/src/de/prob/model/eventb/EventParameter.java new file mode 100644 index 0000000000000000000000000000000000000000..5ebff9f27bcf3a4c73185beeb9770c59aa6846c9 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/EventParameter.java @@ -0,0 +1,22 @@ +package de.prob.model.eventb; + +import de.prob.model.representation.AbstractElement; + +public class EventParameter extends AbstractElement { + + private final String name; + + public EventParameter(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } + +} diff --git a/de.prob.core/src/de/prob/model/eventb/Model.java b/de.prob.core/src/de/prob/model/eventb/Model.java deleted file mode 100644 index f835034bddb9f8f27e5ba758f2a4f20e58f45013..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/eventb/Model.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.prob.model.eventb; - -import java.util.ArrayList; -import java.util.List; - -import de.prob.model.representation.Label; -import de.prob.model.representation.RefType.ERefType; - -public class Model { - - public final String serialization_version = "1"; - public final String name; - public final List<Relationship> relationships = new ArrayList<Relationship>(); - - public Model(String name) { - this.name = name; - } - - public void addRelationship(final Label from, final Label to, ERefType type) { - relationships.add(new Relationship(from, to,type)); - } -} diff --git a/de.prob.core/src/de/prob/model/eventb/Relationship.java b/de.prob.core/src/de/prob/model/eventb/Relationship.java deleted file mode 100644 index 09b5a098ce8b29279fd1077257ae02726c28e566..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/eventb/Relationship.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.prob.model.eventb; - -import de.prob.model.representation.Label; -import de.prob.model.representation.RefType.ERefType; - -public class Relationship { - - public final Label from; - public final Label to; - public final ERefType type; - - public Relationship(Label from, Label to, ERefType type) { - this.from = from; - this.to = to; - this.type = type; - } -} diff --git a/de.prob.core/src/de/prob/model/eventb/Variant.java b/de.prob.core/src/de/prob/model/eventb/Variant.java new file mode 100644 index 0000000000000000000000000000000000000000..7fcbc5363ba9be0cacaa7c1065dfd04834d8bb08 --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/Variant.java @@ -0,0 +1,23 @@ +package de.prob.model.eventb; + +import de.prob.animator.domainobjects.EventB; +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.model.representation.AbstractElement; +import de.prob.model.representation.IEval; + +public class Variant extends AbstractElement implements IEval { + private final IEvalElement expression; + + public Variant(final String code) { + expression = new EventB(code); + } + + public IEvalElement getExpression() { + return expression; + } + + @Override + public IEvalElement getEvaluate() { + return expression; + } +} diff --git a/de.prob.core/src/de/prob/model/eventb/Witness.java b/de.prob.core/src/de/prob/model/eventb/Witness.java new file mode 100644 index 0000000000000000000000000000000000000000..d476e0cae01a2704b2fb1f56dddfcd7e2c2b77bc --- /dev/null +++ b/de.prob.core/src/de/prob/model/eventb/Witness.java @@ -0,0 +1,31 @@ +package de.prob.model.eventb; + +import de.prob.animator.domainobjects.EventB; +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.model.representation.AbstractElement; +import de.prob.model.representation.IEval; + +public class Witness extends AbstractElement implements IEval { + + private final String name; + private final EventB predicate; + + public Witness(final String name, final String code) { + this.name = name; + predicate = new EventB(code); + } + + public String getName() { + return name; + } + + public EventB getPredicate() { + return predicate; + } + + @Override + public IEvalElement getEvaluate() { + return predicate; + } + +} diff --git a/de.prob.core/src/de/prob/model/representation/AbstractElement.java b/de.prob.core/src/de/prob/model/representation/AbstractElement.java new file mode 100644 index 0000000000000000000000000000000000000000..53c0c5aca6cd86c5ef43bf01020f0514afe9dd51 --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/AbstractElement.java @@ -0,0 +1,58 @@ +package de.prob.model.representation; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +/** + * This class is the subclass of all model elements (Models, Machines, Contexts, + * Variables, etc.) + * + * @author joy + * + */ +public abstract class AbstractElement { + protected Map<Class<? extends AbstractElement>, java.util.Set<? extends AbstractElement>> children = new HashMap<Class<? extends AbstractElement>, Set<? extends AbstractElement>>(); + + /** + * Each {@link AbstractElement} can have children of a subclass that extends + * {@link AbstractElement}. These are specified by the class of the child. + * To get a Set of all of the children of a particular class, use this + * method. + * + * @param c + * {@link Class} T of the desired type of children + * @return {@link Set} containing all the children of type T + */ + @SuppressWarnings("unchecked") + public <T extends AbstractElement> Set<T> getChildrenOfType(final Class<T> c) { + Set<? extends AbstractElement> set = children.get(c); + if (set == null) { + return Collections.emptySet(); + } + return (Set<T>) set; + } + + /** + * Maps a {@link Collection} of elements to the specified {@link Class} + * + * @param c + * {@link Class} to specify children elements + * @param elements + * {@link Collection} of elements with which c will be mapped + */ + public <T extends AbstractElement> void put(final Class<T> c, + final Collection<? extends T> elements) { + children.put(c, new LinkedHashSet<T>(elements)); + } + + /** + * @return the {@link Map} of {@link Class} to {@link Set} of children + */ + public Map<Class<? extends AbstractElement>, java.util.Set<? extends AbstractElement>> getChildren() { + return children; + } +} diff --git a/de.prob.core/src/de/prob/model/representation/Action.java b/de.prob.core/src/de/prob/model/representation/Action.java new file mode 100644 index 0000000000000000000000000000000000000000..5950f5e4431da0186991409d0e8c2d44bde5f179 --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/Action.java @@ -0,0 +1,19 @@ +package de.prob.model.representation; + +public abstract class Action extends AbstractElement { + + private final String code; + + public Action(final String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @Override + public String toString() { + return code; + } +} diff --git a/de.prob.core/src/de/prob/model/representation/Axiom.java b/de.prob.core/src/de/prob/model/representation/Axiom.java new file mode 100644 index 0000000000000000000000000000000000000000..d76f5fa2b3fe1dad5fe86cfdb244a1f11cebdec1 --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/Axiom.java @@ -0,0 +1,27 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.unicode.UnicodeTranslator; + +public abstract class Axiom extends AbstractElement implements IEval { + + private final IEvalElement predicate; + + public Axiom(final IEvalElement predicate) { + this.predicate = predicate; + } + + public IEvalElement getPredicate() { + return predicate; + } + + @Override + public IEvalElement getEvaluate() { + return predicate; + } + + @Override + public String toString() { + return UnicodeTranslator.toUnicode(predicate.getCode()); + } +} diff --git a/de.prob.core/src/de/prob/model/representation/BEvent.java b/de.prob.core/src/de/prob/model/representation/BEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..ccea9c12a7972c11f2dd100d634946d9fd0be888 --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/BEvent.java @@ -0,0 +1,20 @@ +package de.prob.model.representation; + + +public abstract class BEvent extends AbstractElement { + + private final String name; + + public BEvent(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/de.prob.core/src/de/prob/model/representation/BSet.java b/de.prob.core/src/de/prob/model/representation/BSet.java new file mode 100644 index 0000000000000000000000000000000000000000..44040c771baff1d07714d72d6d5b5459f797dfde --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/BSet.java @@ -0,0 +1,19 @@ +package de.prob.model.representation; + +public class BSet extends AbstractElement { + + private final String name; + + public BSet(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/de.prob.core/src/de/prob/model/representation/Constant.java b/de.prob.core/src/de/prob/model/representation/Constant.java new file mode 100644 index 0000000000000000000000000000000000000000..ad9742da06bd61932c201557f401c000a88720fc --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/Constant.java @@ -0,0 +1,39 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.EvaluationResult; +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.unicode.UnicodeTranslator; + +public abstract class Constant extends AbstractElement implements IEval { + + protected final IEvalElement expression; + protected EvaluationResult result; + + public Constant(final IEvalElement expression) { + this.expression = expression; + } + + public IEvalElement getExpression() { + return expression; + } + + @Override + public IEvalElement getEvaluate() { + return expression; + } + + @Override + public String toString() { + return UnicodeTranslator.toUnicode(expression.getCode()); + } + +// // Experimental. Would allow the user to calculate the value once and cache +// // it. +// public EvaluationResult getValue(final History h) { +// if (result == null) { +// result = h.evalCurrent(getEvaluate()); +// } +// return result; +// } + +} diff --git a/de.prob.core/src/de/prob/model/representation/Guard.java b/de.prob.core/src/de/prob/model/representation/Guard.java new file mode 100644 index 0000000000000000000000000000000000000000..b6574defafa1be14be6a40e3634d6eaadbc6fc5b --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/Guard.java @@ -0,0 +1,26 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; + +public abstract class Guard extends AbstractElement implements IEval { + + private final IEvalElement predicate; + + public Guard(final IEvalElement predicate) { + this.predicate = predicate; + } + + public IEvalElement getPredicate() { + return predicate; + } + + @Override + public IEvalElement getEvaluate() { + return predicate; + } + + @Override + public String toString() { + return predicate.toString(); + } +} diff --git a/de.prob.core/src/de/prob/model/representation/IEntity.java b/de.prob.core/src/de/prob/model/representation/IEntity.java deleted file mode 100644 index 3510e37438070920160fdbb9b10f6be26f898edc..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/representation/IEntity.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.prob.model.representation; - -import java.util.List; - -public interface IEntity { - public List<IEntity> getChildren(); - - public boolean hasChildren(); -} diff --git a/de.prob.core/src/de/prob/model/representation/IEval.java b/de.prob.core/src/de/prob/model/representation/IEval.java new file mode 100644 index 0000000000000000000000000000000000000000..5dddd32727290ff31ce1f30600881d51017f217c --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/IEval.java @@ -0,0 +1,7 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; + +public interface IEval { + public IEvalElement getEvaluate(); +} diff --git a/de.prob.core/src/de/prob/model/representation/Invariant.java b/de.prob.core/src/de/prob/model/representation/Invariant.java new file mode 100644 index 0000000000000000000000000000000000000000..18de7013a3dbd0ea2dca52b793260c0ae4bc41fa --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/Invariant.java @@ -0,0 +1,28 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.unicode.UnicodeTranslator; + +public abstract class Invariant extends AbstractElement implements IEval { + + private final IEvalElement predicate; + + public Invariant(final IEvalElement predicate) { + this.predicate = predicate; + } + + public IEvalElement getPredicate() { + return predicate; + } + + @Override + public IEvalElement getEvaluate() { + return predicate; + } + + @Override + public String toString() { + return UnicodeTranslator.toUnicode(predicate.getCode()); + } + +} diff --git a/de.prob.core/src/de/prob/model/representation/Label.java b/de.prob.core/src/de/prob/model/representation/Label.java deleted file mode 100644 index 88cb1ed729d911c29346db006d7bef0fc132433c..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/model/representation/Label.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.prob.model.representation; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class Label implements IEntity { - - public List<IEntity> children = new ArrayList<IEntity>(); - protected String name; - private boolean locked = false; - - public Label(final String name) { - this.name = name; - } - - public void addChild(final IEntity child) { - if (!locked) { - children.add(child); - } - } - - @Override - public List<IEntity> getChildren() { - if (locked) { - return Collections.unmodifiableList(children); - } - return children; - } - - public String getName() { - return name; - } - - public void lock() { - locked = true; - for (final IEntity child : children) { - if (child instanceof Label) { - ((Label) child).lock(); - } - } - } - - @Override - public boolean hasChildren() { - return !children.isEmpty(); - } -} diff --git a/de.prob.core/src/de/prob/model/representation/Machine.java b/de.prob.core/src/de/prob/model/representation/Machine.java new file mode 100644 index 0000000000000000000000000000000000000000..c5cad197b3fad9fc15cee1f4c9ab76f8da70029e --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/Machine.java @@ -0,0 +1,19 @@ +package de.prob.model.representation; + +public abstract class Machine extends AbstractElement { + + private final String name; + + public Machine(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/de.prob.core/src/de/prob/model/representation/StateSchema.java b/de.prob.core/src/de/prob/model/representation/StateSchema.java new file mode 100644 index 0000000000000000000000000000000000000000..52f97690b9232ee8263766af00cb05ed825d63bc --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/StateSchema.java @@ -0,0 +1,6 @@ +package de.prob.model.representation; + +public interface StateSchema { + public Object[] getElements(Object o); + public boolean hasChildren(Object o); +} diff --git a/de.prob.core/src/de/prob/model/representation/Variable.java b/de.prob.core/src/de/prob/model/representation/Variable.java new file mode 100644 index 0000000000000000000000000000000000000000..098bb5e99ca13b0c0a03145680191ea1aeaace6c --- /dev/null +++ b/de.prob.core/src/de/prob/model/representation/Variable.java @@ -0,0 +1,31 @@ +package de.prob.model.representation; + +import de.prob.animator.domainobjects.IEvalElement; +import de.prob.unicode.UnicodeTranslator; + +public abstract class Variable extends AbstractElement implements IEval { + + protected final IEvalElement expression; + + public Variable(final IEvalElement expression) { + this.expression = expression; + } + + public IEvalElement getExpression() { + return expression; + } + + @Override + public IEvalElement getEvaluate() { + return expression; + } + + public String getName() { + return expression.getCode(); + } + + @Override + public String toString() { + return UnicodeTranslator.toUnicode(expression.getCode()); + } +} diff --git a/de.prob.core/src/de/prob/model/serialize/EventBModelTranslator.java b/de.prob.core/src/de/prob/model/serialize/EventBModelTranslator.java new file mode 100644 index 0000000000000000000000000000000000000000..f1940cc115174d1b9b54ae7c26d86b20b204ab13 --- /dev/null +++ b/de.prob.core/src/de/prob/model/serialize/EventBModelTranslator.java @@ -0,0 +1,294 @@ +package de.prob.model.serialize; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.GZIPOutputStream; + +import org.apache.commons.codec.binary.Base64; +import org.eventb.core.IConvergenceElement.Convergence; +import org.eventb.core.IEventBProject; +import org.eventb.core.IEventBRoot; +import org.eventb.core.ISCAction; +import org.eventb.core.ISCAxiom; +import org.eventb.core.ISCCarrierSet; +import org.eventb.core.ISCConstant; +import org.eventb.core.ISCContextRoot; +import org.eventb.core.ISCEvent; +import org.eventb.core.ISCExtendsContext; +import org.eventb.core.ISCGuard; +import org.eventb.core.ISCInternalContext; +import org.eventb.core.ISCInvariant; +import org.eventb.core.ISCMachineRoot; +import org.eventb.core.ISCParameter; +import org.eventb.core.ISCRefinesEvent; +import org.eventb.core.ISCRefinesMachine; +import org.eventb.core.ISCVariable; +import org.eventb.core.ISCVariant; +import org.eventb.core.ISCWitness; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IInternalElementType; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.RodinDBException; + +import com.thoughtworks.xstream.XStream; + +import de.prob.model.eventb.Context; +import de.prob.model.eventb.Event; +import de.prob.model.eventb.Event.EventType; +import de.prob.model.eventb.EventBAction; +import de.prob.model.eventb.EventBAxiom; +import de.prob.model.eventb.EventBConstant; +import de.prob.model.eventb.EventBGuard; +import de.prob.model.eventb.EventBInvariant; +import de.prob.model.eventb.EventBMachine; +import de.prob.model.eventb.EventBVariable; +import de.prob.model.eventb.EventParameter; +import de.prob.model.eventb.Variant; +import de.prob.model.eventb.Witness; +import de.prob.model.representation.AbstractElement; +import de.prob.model.representation.BSet; + +public class EventBModelTranslator { + // + // Map<String, ISCMachineRoot> machines = new HashMap<String, + // ISCMachineRoot>(); + // Map<String, ISCContextRoot> contexts = new HashMap<String, + // ISCContextRoot>(); + + Map<String, EventBMachine> machines = new HashMap<String, EventBMachine>(); + Map<String, Context> contexts = new HashMap<String, Context>(); + File modelFile; + + AbstractElement mainComponent; + private final IEventBProject eventBProject; + + public EventBModelTranslator(final IEventBRoot root) { + modelFile = root.getUnderlyingResource().getRawLocation().toFile(); + eventBProject = root.getEventBProject(); + IInternalElementType<? extends IInternalElement> elementType = root + .getElementType(); + String id = elementType.getId(); + if (id.equals("org.eventb.core.machineFile")) { + ISCMachineRoot scMachineRoot = eventBProject.getSCMachineRoot(root + .getElementName()); + mainComponent = translateMachine(scMachineRoot); + } + if (id.equals("org.eventb.core.contextFile")) { + ISCContextRoot scContextRoot = eventBProject.getSCContextRoot(root + .getElementName()); + mainComponent = translateContext(scContextRoot); + } + } + + private Context translateContext(final ISCContextRoot root) { + String name = root.getComponentName(); + if (contexts.containsKey(name)) { + return contexts.get(name); + } + + Context c = new Context(name); + try { + List<Context> exts = new ArrayList<Context>(); + for (ISCExtendsContext iscExtendsContext : root + .getSCExtendsClauses()) { + String componentName = iscExtendsContext.getAbstractSCContext() + .getRodinFile().getBareName(); + exts.add(translateContext(eventBProject + .getSCContextRoot(componentName))); + } + c.addExtends(exts); + + List<BSet> sets = new ArrayList<BSet>(); + for (ISCCarrierSet iscCarrierSet : root.getSCCarrierSets()) { + sets.add(new BSet(iscCarrierSet.getIdentifierString())); + } + c.addSets(sets); + + List<EventBAxiom> axioms = new ArrayList<EventBAxiom>(); + for (ISCAxiom iscAxiom : root.getSCAxioms()) { + String elementName = iscAxiom.getRodinFile().getBareName(); + String predicateString = iscAxiom.getPredicateString(); + boolean theorem = iscAxiom.isTheorem(); + axioms.add(new EventBAxiom(elementName, predicateString, + theorem)); + } + c.addAxioms(axioms); + + List<EventBConstant> constants = new ArrayList<EventBConstant>(); + for (ISCConstant iscConstant : root.getSCConstants()) { + constants.add(new EventBConstant(iscConstant.getElementName())); + } + c.addConstants(constants); + } catch (RodinDBException e) { + e.printStackTrace(); + } + contexts.put(c.getName(), c); + return c; + } + + private EventBMachine translateMachine(final ISCMachineRoot root) { + String name = root.getComponentName(); + if (machines.containsKey(name)) { + return machines.get(name); + } + + EventBMachine machine = new EventBMachine(name); + + try { + List<EventBMachine> refines = new ArrayList<EventBMachine>(); + ISCRefinesMachine[] scRefinesClauses = root.getSCRefinesClauses(); + for (ISCRefinesMachine iscRefinesMachine : scRefinesClauses) { + IRodinFile abstractSCMachine = iscRefinesMachine + .getAbstractSCMachine(); + String bareName = abstractSCMachine.getBareName(); + refines.add(translateMachine(eventBProject + .getSCMachineRoot(bareName))); + } + machine.addRefines(refines); + + List<Context> sees = new ArrayList<Context>(); + for (ISCInternalContext iscInternalContext : root + .getSCSeenContexts()) { + String componentName = iscInternalContext.getComponentName(); + sees.add(translateContext(eventBProject + .getSCContextRoot(componentName))); + } + machine.addSees(sees); + + List<EventBVariable> variables = new ArrayList<EventBVariable>(); + for (ISCVariable iscVariable : root.getSCVariables()) { + variables.add(new EventBVariable(iscVariable.getElementName())); + } + machine.addVariables(variables); + + List<EventBInvariant> invariants = new ArrayList<EventBInvariant>(); + for (ISCInvariant iscInvariant : root.getSCInvariants()) { + String elementName = iscInvariant.getElementName(); + String predicateString = iscInvariant.getPredicateString(); + boolean theorem = iscInvariant.isTheorem(); + invariants.add(new EventBInvariant(elementName, + predicateString, theorem)); + } + machine.addInvariants(invariants); + + List<Variant> variant = new ArrayList<Variant>(); + for (ISCVariant iscVariant : root.getSCVariants()) { + variant.add(new Variant(iscVariant.getExpressionString())); + } + machine.addVariant(variant); + + List<Event> events = new ArrayList<Event>(); + ISCEvent[] scEvents = root.getSCEvents(); + for (ISCEvent iscEvent : scEvents) { + events.add(extractEvent(iscEvent)); + } + machine.addEvents(events); + } catch (RodinDBException e) { + e.printStackTrace(); + } + machines.put(machine.getName(), machine); + return machine; + } + + private Event extractEvent(final ISCEvent iscEvent) throws RodinDBException { + String name = iscEvent.getLabel(); + + int typeId = iscEvent.getConvergence().getCode(); + + Event e = new Event(name, calculateEventType(typeId)); + + List<Event> refines = new ArrayList<Event>(); + for (ISCRefinesEvent iscRefinesEvent : iscEvent.getSCRefinesClauses()) { + refines.add(extractEvent(iscRefinesEvent.getAbstractSCEvent())); + } + e.addRefines(refines); + + List<EventBGuard> guards = new ArrayList<EventBGuard>(); + for (ISCGuard iscGuard : iscEvent.getSCGuards()) { + String elementName = iscGuard.getElementName(); + String predicateString = iscGuard.getPredicateString(); + boolean theorem = iscGuard.isTheorem(); + guards.add(new EventBGuard(elementName, predicateString, theorem)); + } + e.addGuards(guards); + + List<EventBAction> actions = new ArrayList<EventBAction>(); + for (ISCAction iscAction : iscEvent.getSCActions()) { + String elementName = iscAction.getElementName(); + String assignmentString = iscAction.getAssignmentString(); + actions.add(new EventBAction(elementName, assignmentString)); + } + e.addActions(actions); + + List<Witness> witnesses = new ArrayList<Witness>(); + for (ISCWitness iscWitness : iscEvent.getSCWitnesses()) { + String elementName = iscWitness.getElementName(); + String predicateString = iscWitness.getPredicateString(); + witnesses.add(new Witness(elementName, predicateString)); + } + e.addWitness(witnesses); + + List<EventParameter> parameters = new ArrayList<EventParameter>(); + for (ISCParameter iscParameter : iscEvent.getSCParameters()) { + parameters.add(new EventParameter(iscParameter + .getIdentifierString())); + } + e.addParameters(parameters); + + return e; + } + + private EventType calculateEventType(final int typeId) { + Convergence valueOf = Convergence.valueOf(typeId); + if (valueOf.equals(Convergence.ORDINARY)) { + return EventType.ORDINARY; + } + if (valueOf.equals(Convergence.CONVERGENT)) { + return EventType.CONVERGENT; + } + if (valueOf.equals(Convergence.ANTICIPATED)) { + return EventType.ANTICIPATED; + } + return null; + } + + public AbstractElement getMainComponent() { + return mainComponent; + } + + public Collection<EventBMachine> getMachines() { + return machines.values(); + } + + public Collection<Context> getContexts() { + return contexts.values(); + } + + public File getModelFile() { + return modelFile; + } + + public String serialized() { + XStream xstream = new XStream(); + String xml = xstream.toXML(new ModelObject(getMachines(), getContexts(), modelFile, mainComponent)); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + GZIPOutputStream gzip; + byte[] bytes; + try { + gzip = new GZIPOutputStream(out); + gzip.write(xml.getBytes()); + gzip.close(); + bytes = out.toByteArray(); + } catch (IOException e) { + bytes = xml.getBytes(); + } + return Base64.encodeBase64String(bytes); + } + +} diff --git a/de.prob.core/src/de/prob/model/serialize/ModelObject.java b/de.prob.core/src/de/prob/model/serialize/ModelObject.java new file mode 100644 index 0000000000000000000000000000000000000000..16deeb951e9fc51894ea69b2ab0866e0dfb25444 --- /dev/null +++ b/de.prob.core/src/de/prob/model/serialize/ModelObject.java @@ -0,0 +1,38 @@ +package de.prob.model.serialize; + +import java.io.File; +import java.util.Collection; + +import de.prob.model.eventb.Context; +import de.prob.model.eventb.EventBMachine; +import de.prob.model.representation.AbstractElement; + +public class ModelObject { + final Collection<EventBMachine> machines; + final Collection<Context> contexts; + final File modelFile; + final AbstractElement mainComponent; + + public ModelObject(Collection<EventBMachine> machines, Collection<Context> contexts, File modelFile, AbstractElement mainComponent) { + this.machines = machines; + this.contexts = contexts; + this.modelFile = modelFile; + this.mainComponent = mainComponent; + } + + public Collection<EventBMachine> getMachines() { + return machines; + } + + public Collection<Context> getContexts() { + return contexts; + } + + public File getModelFile() { + return modelFile; + } + + public AbstractElement getMainComponent() { + return mainComponent; + } +} diff --git a/de.prob.eventb.disprover.core/.classpath b/de.prob.eventb.disprover.core/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..64c5e31b7a264082f4c1dfdabb8097de820e66ce --- /dev/null +++ b/de.prob.eventb.disprover.core/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/de.prob.eventb.disprover.core/.project b/de.prob.eventb.disprover.core/.project new file mode 100644 index 0000000000000000000000000000000000000000..e4905cdf6df26a9dc246d224597c9fe2ccc31e45 --- /dev/null +++ b/de.prob.eventb.disprover.core/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.eventb.disprover.core</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature> + </natures> +</projectDescription> diff --git a/de.prob.eventb.disprover.core/META-INF/MANIFEST.MF b/de.prob.eventb.disprover.core/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..24a3895dacc48d7daf17944b18492769fbf85dc5 --- /dev/null +++ b/de.prob.eventb.disprover.core/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ProB Disprover Core for EventB +Bundle-SymbolicName: de.prob.eventb.disprover.core;singleton:=true +Bundle-Version: 1.3.2.qualifier +Bundle-Vendor: Heinrich-Heine University Dusseldorf +Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", + de.prob.core;bundle-version="[9.4.0,9.5.0)", + org.eventb.core.seqprover;bundle-version="[2.5.0,3.0.0)", + org.eventb.core;bundle-version="2.5.1", + org.eclipse.ui;bundle-version="[3.5.0,4.0.0)" +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ActivationPolicy: lazy +Bundle-Localization: plugin +Export-Package: de.prob.eventb.disprover.core diff --git a/de.prob.eventb.disprover.core/build.properties b/de.prob.eventb.disprover.core/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..0dc34f7833b401735c8b95fd3aeef27c0fc377a6 --- /dev/null +++ b/de.prob.eventb.disprover.core/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties diff --git a/de.prob.eventb.disprover.core/plugin.properties b/de.prob.eventb.disprover.core/plugin.properties new file mode 100644 index 0000000000000000000000000000000000000000..0c0521b6510fd7f26e56bd6b071022e099d984df --- /dev/null +++ b/de.prob.eventb.disprover.core/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2013 STUPS, Heinrich-Heine University Dusseldorf +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################### + +reasoner.name = (Dis)Prover Reasoner + +autotactic.name = ProB (Dis)Prover +autotactic.desc = Auto Tactic calling the ProB (Dis)Prover diff --git a/de.prob.eventb.disprover.core/plugin.xml b/de.prob.eventb.disprover.core/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..30a8c2e72c6ef161759c1fdb7eb86fcece6f19d4 --- /dev/null +++ b/de.prob.eventb.disprover.core/plugin.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.2"?> +<plugin> + <extension + point="org.eventb.core.seqprover.reasoners"> + <reasoner + class="de.prob.eventb.disprover.core.internal.DisproverReasoner" + id="disproverReasoner" + name="%reasoner.name"> + </reasoner> + </extension> + <extension + point="org.eventb.core.seqprover.autoTactics"> + <autoTactic + class="de.prob.eventb.disprover.core.internal.DisproverAutoTactic" + description="%autotactic.desc" + id="disproverTactic" + name="%autotactic.name"> + </autoTactic> + </extension> + +</plugin> diff --git a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/Disprover.java b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/Disprover.java new file mode 100644 index 0000000000000000000000000000000000000000..dabd6e719096ef3ccf4d9ac12fb7647ac3ae096b --- /dev/null +++ b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/Disprover.java @@ -0,0 +1,24 @@ +package de.prob.eventb.disprover.core; + +import org.eventb.core.seqprover.IReasoner; + +import de.prob.eventb.disprover.core.internal.DisproverReasoner; + +public class Disprover { + + private Disprover() { + throw new RuntimeException("This constructor should never be called."); + } + + /** + * Factory method for creating a new DisproverReasoner. We want to keep the + * actual Disprover private to the package, mainly to loosen access to the + * internal methods for testing. + * + * @return a new {@link DisproverReasoner} instance. + */ + public static IReasoner createDisproverReasoner() { + return new DisproverReasoner(); + } + +} diff --git a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/DisproverReasonerInput.java b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/DisproverReasonerInput.java new file mode 100644 index 0000000000000000000000000000000000000000..b5ea4b4d54d892c2eb5becd305b60578952e8a7f --- /dev/null +++ b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/DisproverReasonerInput.java @@ -0,0 +1,32 @@ +package de.prob.eventb.disprover.core; + +import org.eventb.core.seqprover.IReasonerInput; +import org.eventb.core.seqprover.proofBuilder.ReplayHints; + +/** + * Input for the Disprover. The Input keeps track of the {@link DisproverMode} + * that the Disprover runs in. To prevent conditional statements in the + * Disprover code, this method provides some helper mthod that return the + * appropriate values according to the mode. + * + * @author jastram + */ +public class DisproverReasonerInput implements IReasonerInput { + @Override + public void applyHints(ReplayHints renaming) { + // TODO Auto-generated method stub + } + + @Override + public String getError() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean hasError() { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/CounterExample.java b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/CounterExample.java new file mode 100644 index 0000000000000000000000000000000000000000..3cc8a8baa5259b81f75099a13d601f051599c1ed --- /dev/null +++ b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/CounterExample.java @@ -0,0 +1,66 @@ +package de.prob.eventb.disprover.core.internal; + +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * This class wraps the results from a Disprover run. It either indicates that + * there is no counter-example, or it provides a way to show the counter + * example. + * + * @author jastram + * + */ +class CounterExample implements ICounterExample { + + private final boolean counterExampleFound; + public final SortedMap<String, String> state = new TreeMap<String, String>(); + private final boolean timeoutOccured; + private boolean proof = false; + + CounterExample(final boolean counterExampleFound, + final boolean timeoutOccured) { + this.counterExampleFound = counterExampleFound; + this.timeoutOccured = timeoutOccured; + } + + @Override + public boolean isProof() { + return proof; + } + + public void setProof(boolean proof) { + this.proof = proof; + } + + @Override + public boolean counterExampleFound() { + return counterExampleFound; + } + + @Override + public String toString() { + if (counterExampleFound) { + return "Counter-Example found: " + state.toString(); + } else { + if (isProof()) { + return "No Counter-Example exists: Proof."; + } else { + if (timeoutOccured()) { + return "No Counter-Example found due to Time-Out."; + } else { + return "No Counter-Example found."; + } + } + } + } + + void addVar(String name, String value) { + state.put(name, value); + } + + @Override + public boolean timeoutOccured() { + return timeoutOccured; + } +} diff --git a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverAutoTactic.java b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverAutoTactic.java new file mode 100644 index 0000000000000000000000000000000000000000..8c1e9db714adf73c65fcb0735005fcc6fc2d8a36 --- /dev/null +++ b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverAutoTactic.java @@ -0,0 +1,16 @@ +package de.prob.eventb.disprover.core.internal; + +import org.eventb.core.seqprover.ITactic; +import org.eventb.core.seqprover.eventbExtensions.AutoTactics.AbsractLazilyConstrTactic; +import org.eventb.core.seqprover.tactics.BasicTactics; + +import de.prob.eventb.disprover.core.DisproverReasonerInput; + + +public class DisproverAutoTactic extends AbsractLazilyConstrTactic { + @Override + protected ITactic getSingInstance() { + return BasicTactics.reasonerTac(new DisproverReasoner(), + new DisproverReasonerInput()); + } +} \ No newline at end of file diff --git a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverCommand.java b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..2febdebfaba1350521a9b048b0ffdc8c76036378 --- /dev/null +++ b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverCommand.java @@ -0,0 +1,152 @@ +package de.prob.eventb.disprover.core.internal; + +import java.util.Set; + +import org.eclipse.core.runtime.jobs.Job; +import org.eventb.core.IEventBRoot; +import org.eventb.core.ast.Predicate; +import org.eventb.core.seqprover.IProofMonitor; + +import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; +import de.prob.core.Animator; +import de.prob.core.ProBCommandJob; +import de.prob.core.command.ClearMachineCommand; +import de.prob.core.command.CommandException; +import de.prob.core.command.ComposedCommand; +import de.prob.core.command.IComposableCommand; +import de.prob.core.command.SetPreferencesCommand; +import de.prob.core.command.StartAnimationCommand; +import de.prob.core.command.internal.InternalLoadCommand; +import de.prob.eventb.translator.PredicateVisitor; +import de.prob.exceptions.ProBException; +import de.prob.parser.ISimplifiedROMap; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.ListPrologTerm; +import de.prob.prolog.term.PrologTerm; + +/** + * The DisproverCommand takes two sets of ASTs (one for the machine and a list + * for the contexts) and tries to set them up with ProB. If setup is possible, + * the arguments from that operation are joined with the provided variables and + * returned as an {@link ICounterExample}. + * <p> + * + * This command is probably not useful without {@link DisproverReasoner}, which + * calls it. + * + * @author jastram + */ +public class DisproverCommand implements IComposableCommand { + + private static final String RESULT = "Result"; + + private CounterExample counterExample; + private final Set<Predicate> hypotheses; + private final Predicate goal; + + public DisproverCommand(Set<Predicate> hypotheses, Predicate goal) { + this.hypotheses = hypotheses; + this.goal = goal; + } + + public static ICounterExample disprove(Animator animator, + Set<Predicate> hypotheses, Predicate goal, IEventBRoot root, + IProofMonitor pm) throws ProBException, InterruptedException { + + final ClearMachineCommand clear = new ClearMachineCommand(); + final SetPreferencesCommand setPrefs = SetPreferencesCommand + .createSetPreferencesCommand(animator); + final InternalLoadCommand load = new InternalLoadCommand(root); + + final StartAnimationCommand start = new StartAnimationCommand(); + + DisproverCommand disprove = new DisproverCommand(hypotheses, goal); + + final ComposedCommand composed = new ComposedCommand(clear, setPrefs, + load, start, disprove); + + final Job job = new ProBCommandJob("Disproving", animator, composed); + job.setUser(true); + job.schedule(); + + while (job.getResult() == null && !pm.isCanceled()) { + Thread.sleep(200); + } + + if (pm.isCanceled()) { + job.cancel(); + throw new InterruptedException(); + } + return disprove.getResult(); + + } + + private ICounterExample getResult() { + return counterExample; + } + + @Override + public void writeCommand(final IPrologTermOutput pto) { + + pto.openTerm("cbc_disprove"); + + Predicate pred = goal; + translatePredicate(pto, pred); + pto.openList(); + for (Predicate p : this.hypotheses) { + translatePredicate(pto, p); + } + pto.closeList(); + pto.printVariable(RESULT); + pto.closeTerm(); + } + + private void translatePredicate(final IPrologTermOutput pto, Predicate pred) { + PredicateVisitor v = new PredicateVisitor(); + pred.accept(v); + ASTProlog p = new ASTProlog(pto, null); + v.getPredicate().apply(p); + } + + @Override + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + + PrologTerm term = bindings.get(RESULT); + + counterExample = null; + + if ("time_out".equals(term.getFunctor())) { + counterExample = new CounterExample(false, true); + } + if ("interrupted".equals(term.getFunctor())) { + throw new CommandException("Interrupted"); + } + if ("no_solution_found".equals(term.getFunctor())) { + counterExample = new CounterExample(false, false); + } + + if ("contradiction_found".equals(term.getFunctor())) { + counterExample = new CounterExample(false, false); + counterExample.setProof(true); + } + + if ("solution".equals(term.getFunctor())) { + counterExample = new CounterExample(true, false); + ListPrologTerm vars = (ListPrologTerm) term.getArgument(1); + + for (PrologTerm e : vars) { + counterExample.addVar(e.getArgument(1).getFunctor(), e + .getArgument(3).getFunctor()); + } + } + + if (counterExample == null) { + throw new CommandException( + "Internal Error in ProB. Unexpected result:" + + term.toString()); + } + } + +} diff --git a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverReasoner.java b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverReasoner.java new file mode 100644 index 0000000000000000000000000000000000000000..74298a6e33ff6b6ef0d420375f1a40e96c41d68f --- /dev/null +++ b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/DisproverReasoner.java @@ -0,0 +1,179 @@ +package de.prob.eventb.disprover.core.internal; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.Status; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.eventb.core.IEventBRoot; +import org.eventb.core.IMachineRoot; +import org.eventb.core.ast.Predicate; +import org.eventb.core.basis.POSequent; +import org.eventb.core.seqprover.IConfidence; +import org.eventb.core.seqprover.IProofMonitor; +import org.eventb.core.seqprover.IProofRule; +import org.eventb.core.seqprover.IProofRule.IAntecedent; +import org.eventb.core.seqprover.IProverSequent; +import org.eventb.core.seqprover.IReasoner; +import org.eventb.core.seqprover.IReasonerInput; +import org.eventb.core.seqprover.IReasonerInputReader; +import org.eventb.core.seqprover.IReasonerInputWriter; +import org.eventb.core.seqprover.IReasonerOutput; +import org.eventb.core.seqprover.ProverFactory; +import org.eventb.core.seqprover.SerializeException; +import org.rodinp.core.RodinDBException; +import org.rodinp.core.basis.InternalElement; + +import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; +import de.prob.core.Animator; +import de.prob.core.PrologException; +import de.prob.eventb.disprover.core.DisproverReasonerInput; +import de.prob.eventb.translator.PredicateVisitor; +import de.prob.exceptions.ProBException; +import de.prob.logging.Logger; +import de.prob.prolog.output.PrologTermStringOutput; + +public class DisproverReasoner implements IReasoner { + + static final String DISPROVER_CONTEXT = "disprover_context"; + + private static final String DISPROVER_REASONER_NAME = "de.prob.eventb.disprover.core.disproverReasoner"; + + @Override + public String getReasonerID() { + return DISPROVER_REASONER_NAME; + } + + @Override + public IReasonerOutput apply(final IProverSequent sequent, + final IReasonerInput input, final IProofMonitor pm) { + try { + DisproverReasonerInput disproverInput = (DisproverReasonerInput) input; + ICounterExample ce = evaluateSequent(sequent, disproverInput, pm); + return createDisproverResult(ce, sequent, input); + } catch (PrologException e) { + Logger.log(Logger.WARNING, Status.WARNING, e.getMessage(), e); + return ProverFactory.reasonerFailure(this, input, e.getMessage()); + } catch (ProBException e) { + Logger.log(Logger.WARNING, Status.WARNING, e.getMessage(), e); + return ProverFactory.reasonerFailure(this, input, e.getMessage()); + } catch (RodinDBException e) { + Logger.log(Logger.WARNING, Status.WARNING, e.getMessage(), e); + return ProverFactory.reasonerFailure(this, input, e.getMessage()); + } catch (InterruptedException e) { + return ProverFactory.reasonerFailure(this, input, e.getMessage()); + + } + } + + private ICounterExample evaluateSequent(final IProverSequent sequent, + final DisproverReasonerInput disproverInput, IProofMonitor pm) + throws ProBException, RodinDBException, InterruptedException { + // Logger.info("Calling Disprover on Sequent"); + + Set<Predicate> hypotheses = new HashSet<Predicate>(); + StringBuilder hypothesesString = new StringBuilder(); + for (Predicate predicate : sequent.hypIterable()) { + hypotheses.add(predicate); + hypothesesString.append(predicateToProlog(predicate)); + hypothesesString.append(" & "); + } + + /* + * if (hypothesesString.length() == 0) { + * Logger.info("Disprover: No Hypotheses"); } else { + * hypothesesString.delete(hypothesesString.length() - 2, + * hypothesesString.length()); + * Logger.info("Disprover: Sending Hypotheses: " + + * UnicodeTranslator.toAscii(hypothesesString.toString())); } + */ + Predicate goal = sequent.goal(); + // Logger.info("Disprover: Sending Goal: "+ + // UnicodeTranslator.toAscii(predicateToProlog(goal))); + + IEventBRoot root = getRoot(sequent); + + ICounterExample counterExample = DisproverCommand.disprove( + Animator.getAnimator(), hypotheses, goal, root, pm); + // Logger.info("Disprover: Result: " + counterExample.toString()); + + return counterExample; + } + + private String predicateToProlog(Predicate pred) { + PrologTermStringOutput pto = new PrologTermStringOutput(); + PredicateVisitor v = new PredicateVisitor(); + pred.accept(v); + ASTProlog p = new ASTProlog(pto, null); + v.getPredicate().apply(p); + return pto.toString(); + } + + private IEventBRoot getRoot(IProverSequent sequent) { + POSequent origin = (POSequent) sequent.getOrigin(); + InternalElement poRoot = origin.getRoot(); + + // IPORoot poRoot = origin.getComponent().getPORoot(); + String name = poRoot.getElementName(); + IEventBProject eventBProject = (IEventBProject) poRoot + .getRodinProject().getAdapter(IEventBProject.class); + + // We don't know whether we have a machine or a context. + IMachineRoot machineRoot = eventBProject.getMachineRoot(name); + IContextRoot contextRoot = eventBProject.getContextRoot(name); + + if (machineRoot.exists()) { + return machineRoot; + + } else if (contextRoot.exists()) { + return contextRoot; + } else { + // Neither Machine nor Context + throw new RuntimeException( + "Cannot use ProB Disprover on non Machine/Context Files"); + } + } + + /** + * Create a {@link IProofRule} containing the result from the disprover. + */ + private IReasonerOutput createDisproverResult( + final ICounterExample counterExample, final IProverSequent sequent, + final IReasonerInput input) { + + Predicate goal = sequent.goal(); + + IAntecedent ante = ProverFactory.makeAntecedent(goal); + + if (counterExample.timeoutOccured()) + return ProverFactory.reasonerFailure(this, input, + "ProB: Timeout occurred."); + + if (!counterExample.counterExampleFound() && counterExample.isProof()) + return ProverFactory.makeProofRule(this, input, sequent.goal(), + null, IConfidence.DISCHARGED_MAX, + "ProB (no enumeration / all cases checked)"); + + if (!counterExample.counterExampleFound()) + return ProverFactory + .reasonerFailure(this, input, + "ProB: No Counter-Example found, but there might exist one."); + + return ProverFactory.makeProofRule(this, input, null, null, + IConfidence.PENDING, + "Counter-Example: " + counterExample.toString(), ante); + } + + @Override + public IReasonerInput deserializeInput(final IReasonerInputReader reader) + throws SerializeException { + return new DisproverReasonerInput(); + } + + @Override + public void serializeInput(final IReasonerInput input, + final IReasonerInputWriter writer) throws SerializeException { + } + +} diff --git a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/ICounterExample.java b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/ICounterExample.java new file mode 100644 index 0000000000000000000000000000000000000000..4890b1dc93a1d2a083ee6eaf699b7de9c1c0884e --- /dev/null +++ b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/internal/ICounterExample.java @@ -0,0 +1,11 @@ +package de.prob.eventb.disprover.core.internal; + +public interface ICounterExample { + + public boolean counterExampleFound(); + + public boolean timeoutOccured(); + + public boolean isProof(); + +} \ No newline at end of file diff --git a/de.prob.eventb.disprover.ui/.classpath b/de.prob.eventb.disprover.ui/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..64c5e31b7a264082f4c1dfdabb8097de820e66ce --- /dev/null +++ b/de.prob.eventb.disprover.ui/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/de.prob.eventb.disprover.ui/.project b/de.prob.eventb.disprover.ui/.project new file mode 100644 index 0000000000000000000000000000000000000000..c118fb11f503e7b1e89329d22de6654ab7ac5673 --- /dev/null +++ b/de.prob.eventb.disprover.ui/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.eventb.disprover.ui</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature> + </natures> +</projectDescription> diff --git a/de.prob.eventb.disprover.ui/META-INF/MANIFEST.MF b/de.prob.eventb.disprover.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..901afc33977d363018bcde70537530e632b1fc47 --- /dev/null +++ b/de.prob.eventb.disprover.ui/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ProB Disprover UI for EventB +Bundle-SymbolicName: de.prob.eventb.disprover.ui;singleton:=true +Bundle-Version: 2.0.3.qualifier +Bundle-Vendor: Heinrich-Heine University Dusseldorf +Require-Bundle: org.eventb.ui;bundle-version="[2.5.0,3.0.0)", + de.prob.eventb.disprover.core;bundle-version="[1.3.2,2.0.0)", + org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", + org.eventb.pp.ui;bundle-version="0.2.1" +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ActivationPolicy: lazy +Bundle-Localization: plugin +Bundle-Activator: de.prob.eventb.disprover.ui.DisproverActivator diff --git a/de.prob.eventb.disprover.ui/about.ini b/de.prob.eventb.disprover.ui/about.ini new file mode 100644 index 0000000000000000000000000000000000000000..f04f5e337154c697cc2c45fb586dd1d42d1887ff --- /dev/null +++ b/de.prob.eventb.disprover.ui/about.ini @@ -0,0 +1,3 @@ +aboutText=ProB Disprover (c) 2009 http://www.stups.uni-duesseldorf.de/ProB +featureImage=icons/feature.png + diff --git a/de.prob.eventb.disprover.ui/build.properties b/de.prob.eventb.disprover.ui/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..2787a1898f602ace3c83efe39496c2feb3ac298a --- /dev/null +++ b/de.prob.eventb.disprover.ui/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + icons/,\ + about.ini diff --git a/de.prob.eventb.disprover.ui/icons/disprover-all.png b/de.prob.eventb.disprover.ui/icons/disprover-all.png new file mode 100644 index 0000000000000000000000000000000000000000..a60606337feda28b40096234ce2f55428e859679 Binary files /dev/null and b/de.prob.eventb.disprover.ui/icons/disprover-all.png differ diff --git a/de.prob.eventb.disprover.ui/icons/disprover-config.png b/de.prob.eventb.disprover.ui/icons/disprover-config.png new file mode 100644 index 0000000000000000000000000000000000000000..1a3dd7c86085790c46b3f2796f392f98b1fbc986 Binary files /dev/null and b/de.prob.eventb.disprover.ui/icons/disprover-config.png differ diff --git a/de.prob.eventb.disprover.ui/icons/disprover-relevant-context.png b/de.prob.eventb.disprover.ui/icons/disprover-relevant-context.png new file mode 100644 index 0000000000000000000000000000000000000000..f123ace8c885ae20ad8a76e73416d47939cd1a92 Binary files /dev/null and b/de.prob.eventb.disprover.ui/icons/disprover-relevant-context.png differ diff --git a/de.prob.eventb.disprover.ui/icons/disprover-relevant.png b/de.prob.eventb.disprover.ui/icons/disprover-relevant.png new file mode 100644 index 0000000000000000000000000000000000000000..5edfe63c9dadeb4ac10f57012130d0aed5646dbd Binary files /dev/null and b/de.prob.eventb.disprover.ui/icons/disprover-relevant.png differ diff --git a/de.prob.eventb.disprover.ui/icons/feature.png b/de.prob.eventb.disprover.ui/icons/feature.png new file mode 100644 index 0000000000000000000000000000000000000000..6e7f53357533b567f2d1d1b9e0bb3ebe072aa2d9 Binary files /dev/null and b/de.prob.eventb.disprover.ui/icons/feature.png differ diff --git a/de.prob.eventb.disprover.ui/plugin.properties b/de.prob.eventb.disprover.ui/plugin.properties new file mode 100644 index 0000000000000000000000000000000000000000..10c3bee80f3314750bc43db72747fa3707f6a3d9 --- /dev/null +++ b/de.prob.eventb.disprover.ui/plugin.properties @@ -0,0 +1,10 @@ +############################################################################### +# Copyright (c) 2009 STUPS, Heinrich-Heine University Dusseldorf +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################### + +tactic.disprover.name = Disprover +tactic.disprover.tooltip = (Dis)Prove with ProB diff --git a/de.prob.eventb.disprover.ui/plugin.xml b/de.prob.eventb.disprover.ui/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..82717ae33ff5f39530b623bed28c3b9f4434fe86 --- /dev/null +++ b/de.prob.eventb.disprover.ui/plugin.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.2"?> +<plugin> + <extension + point="org.eventb.ui.proofTactics"> + <!-- <tactic + dropdown="de.prob.eventb.disprover.ui.DisproverDropdown" + icon="icons/disprover-relevant-context.png" + id="de.prob.eventb.disprover.ui.disproverRelevantContextTactic" + interrupt="true" + name="%tactic.disprover.name" + priority="9" + tacticProvider="de.prob.eventb.disprover.ui.DisproverRelevantHypothesesAndContextTacticProvider" + target="global" + tooltip="%tactic.disprover.tooltip-relevant-context" /> + --> + <tactic + icon="icons/disprover-all.png" + id="de.prob.eventb.disprover.ui.disproverTactic" + interrupt="true" + name="%tactic.disprover.name" + priority="10" + tacticProvider="de.prob.eventb.disprover.ui.DisproverTacticProvider" + target="global" + toolbar="org.eventb.ui.sequentToolbar" + tooltip="%tactic.disprover.tooltip"/> + <!-- <tactic + dropdown="de.prob.eventb.disprover.ui.DisproverDropdown" + icon="icons/disprover-config.png" + id="de.prob.eventb.disprover.ui.disproverConfigTactic" + interrupt="true" + name="%tactic.disprover.name" + priority="9" + tacticProvider="de.prob.eventb.disprover.ui.DisproverConfigTacticProvider" + target="global" + tooltip="%tactic.disprover.tooltip-config" /> + <tactic + dropdown="de.prob.eventb.disprover.ui.DisproverDropdown" + icon="icons/disprover-relevant.png" + id="de.prob.eventb.disprover.ui.disproverRelevantHypothesesTactic" + interrupt="true" + name="%tactic.disprover.name" + priority="9" + tacticProvider="de.prob.eventb.disprover.ui.DisproverRelevantHypothesesTacticProvider" + target="global" + tooltip="%tactic.disprover.tooltip-relevant" /> --> + </extension> + +</plugin> diff --git a/de.prob.eventb.disprover.ui/src/de/prob/eventb/disprover/ui/DisproverActivator.java b/de.prob.eventb.disprover.ui/src/de/prob/eventb/disprover/ui/DisproverActivator.java new file mode 100644 index 0000000000000000000000000000000000000000..8f18b5c8c04b57e675676c94bcb3826e8a5015cc --- /dev/null +++ b/de.prob.eventb.disprover.ui/src/de/prob/eventb/disprover/ui/DisproverActivator.java @@ -0,0 +1,55 @@ +package de.prob.eventb.disprover.ui; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +public class DisproverActivator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "de.prob.eventb.disprover.ui"; + + // The shared instance + private static DisproverActivator plugin; + + /** + * The constructor + */ + public DisproverActivator() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static DisproverActivator getDefault() { + return plugin; + } + +} diff --git a/de.prob.eventb.disprover.ui/src/de/prob/eventb/disprover/ui/DisproverTacticProvider.java b/de.prob.eventb.disprover.ui/src/de/prob/eventb/disprover/ui/DisproverTacticProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..4a7f8d2fcc8f0d61e51139220aeaf41e9a8228ed --- /dev/null +++ b/de.prob.eventb.disprover.ui/src/de/prob/eventb/disprover/ui/DisproverTacticProvider.java @@ -0,0 +1,65 @@ +package de.prob.eventb.disprover.ui; + +import java.util.Collections; +import java.util.List; + +import org.eventb.core.ast.Predicate; +import org.eventb.core.seqprover.IProofTreeNode; +import org.eventb.core.seqprover.IReasonerInput; +import org.eventb.core.seqprover.ITactic; +import org.eventb.core.seqprover.tactics.BasicTactics; +import org.eventb.ui.prover.DefaultTacticProvider; +import org.eventb.ui.prover.ITacticApplication; + +import de.prob.eventb.disprover.core.Disprover; +import de.prob.eventb.disprover.core.DisproverReasonerInput; + +public class DisproverTacticProvider extends DefaultTacticProvider { + + protected boolean useContexts() { + return false; + } + + protected static class MyPredicateApplication implements ITacticApplication { + + private final IProofTreeNode node; + + public MyPredicateApplication(IProofTreeNode node) { + this.node = node; + } + + @Override + public ITactic getTactic(String[] inputs, String globalInput) { + return getTactic(node, globalInput, inputs); + } + + public ITactic getTactic(IProofTreeNode node, String globalInput, + String[] inputs) { + + IReasonerInput reasonerInput = new DisproverReasonerInput(); + return BasicTactics.reasonerTac( + Disprover.createDisproverReasoner(), reasonerInput); + } + + @Override + public String getTacticID() { + return "de.prob.eventb.disprover.ui.disproverTactic"; + } + + } + + public DisproverTacticProvider() { + super(); + } + + @Override + public List<ITacticApplication> getPossibleApplications( + IProofTreeNode node, Predicate hyp, String globalInput) { + + if (node != null && node.isOpen()) { + ITacticApplication application = new MyPredicateApplication(node); + return Collections.singletonList(application); + } + return Collections.<ITacticApplication> emptyList(); + } +} \ No newline at end of file diff --git a/de.prob.plugin/META-INF/MANIFEST.MF b/de.prob.plugin/META-INF/MANIFEST.MF index 35b77a2148d75ceb3a3c4b74cc62234c662a31f3..57d4aa60176c7850a354a2f2de3db563ed6e402f 100644 --- a/de.prob.plugin/META-INF/MANIFEST.MF +++ b/de.prob.plugin/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: ProB Rodin2 UI Bindings Bundle-SymbolicName: de.prob.plugin;singleton:=true -Bundle-Version: 2.2.0.qualifier -Fragment-Host: de.prob.ui;bundle-version="[7.3.0,7.4.0)" +Bundle-Version: 2.3.0.qualifier +Fragment-Host: de.prob.ui;bundle-version="[7.4.0,7.5.0)" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: HHU Düsseldorf STUPS Group diff --git a/de.prob.symbolic/.classpath b/de.prob.symbolic/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ad32c83a7885b8953a938b41df3b4fd4fe1aae01 --- /dev/null +++ b/de.prob.symbolic/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/de.prob.symbolic/.project b/de.prob.symbolic/.project new file mode 100644 index 0000000000000000000000000000000000000000..813e377ebc9759c049afc1223680659c23cb92e9 --- /dev/null +++ b/de.prob.symbolic/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.symbolic</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/de.prob.symbolic/.settings/org.eclipse.jdt.core.prefs b/de.prob.symbolic/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..c537b63063ce6052bdc49c5fd0745b078f162c90 --- /dev/null +++ b/de.prob.symbolic/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/de.prob.symbolic/META-INF/MANIFEST.MF b/de.prob.symbolic/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..52dc0015473f374b41c057a65da6df414c5d7892 --- /dev/null +++ b/de.prob.symbolic/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ProB Symbolic Evaluation Support +Bundle-SymbolicName: de.prob.symbolic;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: de.prob.symbolic.Activator +Require-Bundle: org.eclipse.core.runtime, + de.prob.core;bundle-version="[9.4.0,9.5.0)", + org.eventb.ui;bundle-version="[2.5.0,3.0.0)", + de.prob.ui;bundle-version="[7.4.0,7.5.0)" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: HHU Düsseldorf STUPS Group diff --git a/de.prob.symbolic/build.properties b/de.prob.symbolic/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..e9863e281eaccc5123e82ed75713bab3e8b87bbe --- /dev/null +++ b/de.prob.symbolic/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/de.prob.symbolic/plugin.xml b/de.prob.symbolic/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..e74f8d3db3227a21f95f314148736728e664698e --- /dev/null +++ b/de.prob.symbolic/plugin.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eventb.ui.editorItems"> + <toggleAttribute + class="de.prob.symbolic.SymbolicAttribute" + id="de.prob.symbolic.symbolicAttribute" + typeId="de.prob.symbolic.symbolicAttribute"> + </toggleAttribute> + <attributeRelation + elementTypeId="org.eventb.core.constant"> + <attributeReference + descriptionId="de.prob.symbolic.symbolicAttribute"> + </attributeReference> + </attributeRelation> + </extension> + <extension + point="org.rodinp.core.attributeTypes"> + <attributeType + id="symbolicAttribute" + kind="boolean" + name="Symbolic Evaluation of a Constant"> + </attributeType> + </extension> + <extension + point="org.eventb.core.configurations"> + <configuration + id="ctxBase" + name="ctxBase"> + <scModule + id="de.prob.symbolic.symbolicAttributeProcessor"> + </scModule> + </configuration> + </extension> + <extension + point="org.eventb.core.scModuleTypes"> + <processorType + class="de.prob.symbolic.SymbolicAttributeProcessor" + id="symbolicAttributeProcessor" + name="symbolicAttributeProcessor" + parent="org.eventb.core.contextModule"> + </processorType> + </extension> + +</plugin> diff --git a/de.prob.symbolic/src/de/prob/symbolic/Activator.java b/de.prob.symbolic/src/de/prob/symbolic/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..c5cb44695357b9fe34fa8bf42345d9b4d3e469ec --- /dev/null +++ b/de.prob.symbolic/src/de/prob/symbolic/Activator.java @@ -0,0 +1,75 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.symbolic; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.rodinp.core.RodinCore; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "de.prob.symbolic"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + + setConfig(); + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Registers a file configuration setter for our plugin. + */ + public static void setConfig() { + RodinCore.addElementChangedListener(new ConfSettor()); + } + +} diff --git a/de.prob.symbolic/src/de/prob/symbolic/ConfSettor.java b/de.prob.symbolic/src/de/prob/symbolic/ConfSettor.java new file mode 100644 index 0000000000000000000000000000000000000000..0e6a3e7f57c199bd06b6b7c896f637bbd71b1069 --- /dev/null +++ b/de.prob.symbolic/src/de/prob/symbolic/ConfSettor.java @@ -0,0 +1,63 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.symbolic; + +import org.eventb.core.IContextRoot; +import org.rodinp.core.ElementChangedEvent; +import org.rodinp.core.IElementChangedListener; +import org.rodinp.core.IElementType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinDB; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.IRodinElementDelta; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinDBException; + +/** + * Class that updates the configuration of files, to add the static checker + * modules for our qualitative probabilistic reasoning plug-in. + */ +public class ConfSettor implements IElementChangedListener { + + private static final String CONFIG = Activator.PLUGIN_ID + ".ctxBase"; + + @Override + public void elementChanged(ElementChangedEvent event) { + + final IRodinElementDelta d = event.getDelta(); + try { + processDelta(d); + } catch (final RodinDBException e) { + // TODO add exception log + } + } + + private void processDelta(final IRodinElementDelta d) + throws RodinDBException { + final IRodinElement e = d.getElement(); + + final IElementType<? extends IRodinElement> elementType = e + .getElementType(); + if (elementType.equals(IRodinDB.ELEMENT_TYPE) + || elementType.equals(IRodinProject.ELEMENT_TYPE)) { + for (final IRodinElementDelta de : d.getAffectedChildren()) { + processDelta(de); + } + } else if (elementType.equals(IRodinFile.ELEMENT_TYPE)) { + final IInternalElement root = ((IRodinFile) e).getRoot(); + + if (root.getElementType().equals(IContextRoot.ELEMENT_TYPE)) { + final IContextRoot ctx = (IContextRoot) root; + final String conf = ctx.getConfiguration(); + if (!conf.contains(CONFIG)) { + ctx.setConfiguration(conf + ";" + CONFIG, null); + } + } + } + } +} \ No newline at end of file diff --git a/de.prob.symbolic/src/de/prob/symbolic/SymbolicAttribute.java b/de.prob.symbolic/src/de/prob/symbolic/SymbolicAttribute.java new file mode 100644 index 0000000000000000000000000000000000000000..7d6f43b605f36c510ca26798ed91537053c01a6b --- /dev/null +++ b/de.prob.symbolic/src/de/prob/symbolic/SymbolicAttribute.java @@ -0,0 +1,77 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.symbolic; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eventb.core.IVariable; +import org.eventb.core.basis.Constant; +import org.eventb.internal.ui.eventbeditor.manipulation.AbstractBooleanManipulation; +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; + +public class SymbolicAttribute extends AbstractBooleanManipulation { + private static final String SYMBOLIC = "symbolic"; + private static final String CONCRETE = "not symbolic"; + public static IAttributeType.Boolean ATTRIBUTE = RodinCore + .getBooleanAttrType(Activator.PLUGIN_ID + ".symbolicAttribute"); + + public SymbolicAttribute() { + super(SYMBOLIC, CONCRETE); + } + + 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 getValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + try { + return asInternalElement(element).getAttributeValue(ATTRIBUTE) ? SYMBOLIC + : CONCRETE; + } catch (RodinDBException ex) { + // happens if the attribute is not set on this element + // just return a default instead of throwing a RodinDBException + } + return CONCRETE; + } + + @Override + public boolean hasValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + return asInternalElement(element).hasAttribute(ATTRIBUTE); + } + + @Override + public void removeAttribute(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).removeAttribute(ATTRIBUTE, monitor); + } + + @Override + public void setDefaultValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, false, monitor); + + } + + @Override + public void setValue(IRodinElement element, String value, + IProgressMonitor monitor) throws RodinDBException { + final boolean isSymbolic = value.equals(SYMBOLIC); + asInternalElement(element).setAttributeValue(ATTRIBUTE, isSymbolic, + monitor); + } +} diff --git a/de.prob.symbolic/src/de/prob/symbolic/SymbolicAttributeProcessor.java b/de.prob.symbolic/src/de/prob/symbolic/SymbolicAttributeProcessor.java new file mode 100644 index 0000000000000000000000000000000000000000..1e7a939d66f9dfa86ae0587f5d427528f320a421 --- /dev/null +++ b/de.prob.symbolic/src/de/prob/symbolic/SymbolicAttributeProcessor.java @@ -0,0 +1,72 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.symbolic; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eventb.core.EventBAttributes; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.ISCConstant; +import org.eventb.core.ISCContextRoot; +import org.eventb.core.sc.SCCore; +import org.eventb.core.sc.SCProcessorModule; +import org.eventb.core.sc.state.ISCStateRepository; +import org.eventb.core.tool.IModuleType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.IRodinFile; + +public class SymbolicAttributeProcessor extends SCProcessorModule { + public static final IModuleType<SymbolicAttributeProcessor> MODULE_TYPE = SCCore + .getModuleType(Activator.PLUGIN_ID + ".symbolicAttributeProcessor"); //$NON-NLS-1$ + + @Override + public void process(IRodinElement element, IInternalElement target, + ISCStateRepository repository, IProgressMonitor monitor) + throws CoreException { + assert (element instanceof IRodinFile); + assert (target instanceof ISCContextRoot); + + // get all variables and copy over the attributes + IRodinFile contextFile = (IRodinFile) element; + IContextRoot contextRoot = (IContextRoot) contextFile.getRoot(); + + ISCContextRoot scContextRoot = (ISCContextRoot) target; + + IConstant[] constants = contextRoot.getConstants(); + ISCConstant[] scconstants = scContextRoot.getSCConstants(); + + if (constants.length == 0 || scconstants.length == 0) + return; + + for (IConstant constant : constants) { + String identifier = constant + .getAttributeValue(EventBAttributes.IDENTIFIER_ATTRIBUTE); + ISCConstant scConstant = scContextRoot.getSCConstant(identifier); + + // might have been filtered out by previous modules + if (scConstant.exists()) { + // original might not contain the attribute + if (constant.hasAttribute(SymbolicAttribute.ATTRIBUTE)) { + boolean attribute = constant + .getAttributeValue(SymbolicAttribute.ATTRIBUTE); + + scConstant.setAttributeValue(SymbolicAttribute.ATTRIBUTE, + attribute, monitor); + } + } + } + + } + + @Override + public IModuleType<?> getModuleType() { + return MODULE_TYPE; + } + +} diff --git a/de.prob.ui/.classpath b/de.prob.ui/.classpath index f67843181ee95a7771d0edd1009be1faaed415b0..100092b255b1ad1a077f31d3e5931b134f6f5f45 100644 --- a/de.prob.ui/.classpath +++ b/de.prob.ui/.classpath @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry exported="true" kind="lib" path="lib/dependencies/commons-codec-1.6.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry exported="true" kind="lib" path="lib/apache_xmlrpc.jar"/> <classpathentry exported="true" kind="lib" path="lib/ws_commons.jar"/> <classpathentry kind="output" path="bin"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/commons-codec-1.6.jar"/> </classpath> diff --git a/de.prob.ui/META-INF/MANIFEST.MF b/de.prob.ui/META-INF/MANIFEST.MF index 0292f6b17151194d687a1bdffa1d3ffd3a2a4e35..65ed363cdd7212d5885670d206c47dc6f0ebf215 100644 --- a/de.prob.ui/META-INF/MANIFEST.MF +++ b/de.prob.ui/META-INF/MANIFEST.MF @@ -2,15 +2,15 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: ProB Ui Plug-in Bundle-SymbolicName: de.prob.ui;singleton:=true -Bundle-Version: 7.3.0.qualifier +Bundle-Version: 7.4.0.qualifier Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)", - de.prob.core;bundle-version="[9.3.0,9.4.0)", - org.eventb.core;bundle-version="[2.1.0,2.6.0)", + de.prob.core;bundle-version="[9.4.0,9.5.0)", + org.eventb.core;bundle-version="[2.5.0,2.6.0)", org.eclipse.core.expressions;bundle-version="[3.4.101,4.0.0)", - org.eclipse.gef;bundle-version="[3.5.0,4.0.0)" + org.eclipse.gef;bundle-version="[3.7.0,4.0.0)" Bundle-ActivationPolicy: lazy Bundle-Vendor: HHU Düsseldorf STUPS Group Bundle-Activator: de.prob.ui.ProbUiPlugin diff --git a/de.prob.ui/plugin.xml b/de.prob.ui/plugin.xml index a8edde201a3de97737dd4a38086703bde5240114..14cb1e6079a38f9c81859fa317cb3709ace8d6b6 100644 --- a/de.prob.ui/plugin.xml +++ b/de.prob.ui/plugin.xml @@ -183,7 +183,6 @@ name="Consistencychecking"> </command> - <command defaultHandler="de.prob.ui.operationview.DoubleClickBehaviorHandler" id="de.prob.ui.doubleclickbehaviour" @@ -304,6 +303,16 @@ id="de.prob.ui.invariant_check" name="Check for Invariant Preservation"> </command> + <command + categoryId="de.prob.ui.commands.category" + id="de.prob.ui.refinement_check" + name="Validate Refinement"> + </command> + <command + categoryId="de.prob.ui.commands.category" + id="de.prob.ui.assertion_check" + name="Check Assertions"> + </command> <command categoryId="de.prob.ui.commands.category" id="de.prob.ui.opview.checks" @@ -351,6 +360,11 @@ id="de.prob.ui.newcore.export" name="Export for new Core"> </command> + <command + categoryId="de.prob.ui.commands.category" + id="de.prob.ui.assertion_check" + name="Check Context Theorems"> + </command> </extension> <extension point="org.eclipse.ui.handlers"> @@ -741,6 +755,50 @@ </with> </enabledWhen> </handler> + <handler + commandId="de.prob.ui.refinement_check"> + <class + class="de.prob.ui.refinementcheck.RefinementCheckHandler"> + </class> + <enabledWhen> + <and> + <with + variable="de.prob.core.model_loaded"> + <equals + value="enabled"> + </equals> + </with> + <with + variable="de.prob.core.context_loaded"> + <equals + value="disabled"> + </equals> + </with> + </and> + </enabledWhen> + </handler> + <handler + commandId="de.prob.ui.assertion_check"> + <enabledWhen> + <and> + <with + variable="de.prob.core.model_loaded"> + <equals + value="enabled"> + </equals> + </with> + <with + variable="de.prob.core.context_loaded"> + <equals + value="disabled"> + </equals> + </with> + </and> + </enabledWhen> + <class + class="de.prob.ui.assertion.AssertionCheckHandler"> + </class> + </handler> <!-- <handler commandId="de.prob.ui.startdmc"> <class @@ -1048,20 +1106,37 @@ mnemonic="L" style="push"> </command> - <command - commandId="de.prob.ui.deadlock_check" - icon="icons/DeadlockCheck.png" - label="Deadlock Freedom Checking" - mnemonic="D" - style="push"> - </command> - <command - commandId="de.prob.ui.invariant_check" - icon="icons/CBCInvariantCheck.png" - label="Invariant Preservation Checking" - mnemonic="I" - style="push"> - </command> + <menu + label="Constraint Based Checking"> + <command + commandId="de.prob.ui.deadlock_check" + icon="icons/DeadlockCheck.png" + label="Deadlock Freedom" + mnemonic="D" + style="push"> + </command> + <command + commandId="de.prob.ui.invariant_check" + icon="icons/CBCInvariantCheck.png" + label="Invariant Preservation" + mnemonic="I" + style="push"> + </command> + <command + commandId="de.prob.ui.refinement_check" + icon="icons/CBCInvariantCheck.png" + label="Refinement Proof Obligations" + mnemonic="R" + style="push"> + </command> + <command + commandId="de.prob.ui.assertion_check" + icon="icons/CBCInvariantCheck.png" + label="Context Theorems" + mnemonic="C" + style="push"> + </command> + </menu> </menuContribution> <!-- <menuContribution @@ -1134,6 +1209,7 @@ style="push"> </command> </menuContribution> + </extension> <extension @@ -1162,6 +1238,13 @@ name="de.prob.ui.ltl.counterexample_loaded" priorityLevel="workbench"> </variable> + </sourceProvider> + <sourceProvider + provider="de.prob.ui.services.ContextLoadedProvider"> + <variable + name="de.prob.core.context_loaded" + priorityLevel="workbench"> + </variable> </sourceProvider> </extension> </plugin> diff --git a/de.prob.ui/src/de/prob/ui/assertion/AssertionCheckFinishedListener.java b/de.prob.ui/src/de/prob/ui/assertion/AssertionCheckFinishedListener.java new file mode 100644 index 0000000000000000000000000000000000000000..876a6b175ec9f51959b8bcff25d516833c44488a --- /dev/null +++ b/de.prob.ui/src/de/prob/ui/assertion/AssertionCheckFinishedListener.java @@ -0,0 +1,99 @@ +/** + * + */ +package de.prob.ui.assertion; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; + +import de.prob.core.Animator; +import de.prob.core.ProBJobFinishedListener; +import de.prob.core.command.ConstraintBasedAssertionCheckCommand; +import de.prob.core.command.ConstraintBasedAssertionCheckCommand.ResultType; +import de.prob.core.command.ExecuteOperationCommand; +import de.prob.core.command.IComposableCommand; +import de.prob.core.domainobjects.Operation; +import de.prob.exceptions.ProBException; +import de.prob.logging.Logger; + +/** + * This JobChangeAdapter presents the user the results of a deadlock freedom + * check. + * + * @see AssertionCheckHandler + * + * @author plagge + */ +public class AssertionCheckFinishedListener extends ProBJobFinishedListener { + private final Shell shell; + + public AssertionCheckFinishedListener(final Shell shell) { + this.shell = shell; + } + + @Override + protected void showResult(final IComposableCommand cmd, + final Animator animator) { + final ConstraintBasedAssertionCheckCommand command = (ConstraintBasedAssertionCheckCommand) cmd; + final ResultType result = command.getResult(); + final int dialogType; + final String dialogTitle; + final String message; + + if (result == null) { + dialogType = MessageDialog.ERROR; + dialogTitle = "Errow During Constraint Based Check"; + message = "ProB did not return a result"; + } else { + switch (result) { + case NO_COUNTER_EXAMPLE: + dialogType = MessageDialog.INFORMATION; + dialogTitle = "No Counter-Example Found"; + message = "No Counter-Example to the Context Theorems was found."; + break; + case COUNTER_EXAMPLE: + dialogType = MessageDialog.WARNING; + dialogTitle = "COUNTER-EXAMPLE FOUND!"; + message = "The model contains a Counter-Example state, it will be shown in the state view."; + displayCounterExample(command, animator); + break; + case INTERRUPTED: + dialogType = MessageDialog.WARNING; + dialogTitle = " Interrupt"; + message = "The deadlock check has been interrupted by the user or a time-out."; + break; + default: + Logger.notifyUser("Unexpected result: " + result); + return; + } + } + if (shell.isDisposed()) { + System.out.println("Deadlock freedom check finished: " + + dialogTitle); + } else { + final Runnable runnable = new Runnable() { + @Override + public void run() { + MessageDialog.open(dialogType, shell, dialogTitle, message, + SWT.NONE); + } + }; + shell.getDisplay().asyncExec(runnable); + } + } + + private void displayCounterExample( + final ConstraintBasedAssertionCheckCommand command, + final Animator animator) { + final Operation operation = command.getCounterExampleOperation(); + try { + // we do not reset the history because we want to keep the root + // state, we just start a new path from root + animator.getHistory().gotoPos(0); + ExecuteOperationCommand.executeOperation(animator, operation); + } catch (ProBException e) { + e.notifyUserOnce(); + } + } +} diff --git a/de.prob.ui/src/de/prob/ui/assertion/AssertionCheckHandler.java b/de.prob.ui/src/de/prob/ui/assertion/AssertionCheckHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..e311721be347f77ab7d10108c2e6cd4fbe31b545 --- /dev/null +++ b/de.prob.ui/src/de/prob/ui/assertion/AssertionCheckHandler.java @@ -0,0 +1,56 @@ +/** + * + */ +package de.prob.ui.assertion; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import de.prob.core.Animator; +import de.prob.core.LanguageDependendAnimationPart; +import de.prob.core.ProBCommandJob; +import de.prob.core.command.ConstraintBasedAssertionCheckCommand; +import de.prob.logging.Logger; + +/** + * This handler provides a simple dialog to ask for an optional predicate to + * check for deadlocks in the model. + * + * @author plagge + */ +public class AssertionCheckHandler extends AbstractHandler { + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + final Shell shell = HandlerUtil.getActiveShell(event); + if (Animator.getAnimator().isMachineLoaded()) { + performAssertionCheck(shell); + } else { + Logger.notifyUser("No ProB animation running. This is a bug. Please submit a report. Error in declaraion for class DeadlockCheckHandler"); + } + return null; + } + + private void performAssertionCheck(final Shell shell) + throws ExecutionException { + final Animator animator = Animator.getAnimator(); + final LanguageDependendAnimationPart ldp = animator + .getLanguageDependendPart(); + startCheck(animator, ldp, shell); + + } + + private void startCheck(final Animator animator, + final LanguageDependendAnimationPart ldp, final Shell shell) + throws ExecutionException { + final ConstraintBasedAssertionCheckCommand command = new ConstraintBasedAssertionCheckCommand(); + final Job job = new ProBCommandJob( + "Checking Context Theorems / Assertions", animator, command); + job.setUser(true); + job.addJobChangeListener(new AssertionCheckFinishedListener(shell)); + job.schedule(); + } +} diff --git a/de.prob.ui/src/de/prob/ui/deadlock/DeadlockCheckFinishedListener.java b/de.prob.ui/src/de/prob/ui/deadlock/DeadlockCheckFinishedListener.java index 80b7a915254759caf8b5fce71756dc5c5508067d..e49a329613169306d3c52687a2d9f5332161c340 100644 --- a/de.prob.ui/src/de/prob/ui/deadlock/DeadlockCheckFinishedListener.java +++ b/de.prob.ui/src/de/prob/ui/deadlock/DeadlockCheckFinishedListener.java @@ -58,8 +58,8 @@ public class DeadlockCheckFinishedListener extends ProBJobFinishedListener { break; case DEADLOCK_FOUND: dialogType = MessageDialog.WARNING; - dialogTitle = "Deadlock Found"; - message = "The model contains a deadlock, it will be shown in the state view."; + dialogTitle = "DEADLOCK FOUND!"; + message = "The model contains a deadlocking state satisfying the invariant, it will be shown in the state view."; displayDeadlock(command, animator); break; case INTERRUPTED: diff --git a/de.prob.ui/src/de/prob/ui/deadlock/DeadlockCheckHandler.java b/de.prob.ui/src/de/prob/ui/deadlock/DeadlockCheckHandler.java index 8f84dfa6687c0c0f4c84739f2a9e46bf714d00ae..7a7dc427d17b0bb06333835cf760e085781d1316 100644 --- a/de.prob.ui/src/de/prob/ui/deadlock/DeadlockCheckHandler.java +++ b/de.prob.ui/src/de/prob/ui/deadlock/DeadlockCheckHandler.java @@ -48,7 +48,7 @@ public class DeadlockCheckHandler extends AbstractHandler { final InputDialog dialog = new InputDialog( shell, "Deadlock Freedom Check", - "Please specify an (optional) predicate to constrain the search space", + "ProB will search for a deadlocking state satisfying the invariant. You can (optionally) specify a predicate to constrain the search:", "", validator); final int status = dialog.open(); if (status == InputDialog.OK) { diff --git a/de.prob.ui/src/de/prob/ui/eventb/AnimationRefinementAction.java b/de.prob.ui/src/de/prob/ui/eventb/AnimationRefinementAction.java deleted file mode 100644 index 3464a31425ecd625357adef62d3e2dc93ff378d8..0000000000000000000000000000000000000000 --- a/de.prob.ui/src/de/prob/ui/eventb/AnimationRefinementAction.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.prob.ui.eventb; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eventb.core.EventBPlugin; -import org.eventb.core.IContextRoot; -import org.eventb.core.IMachineRoot; -import org.rodinp.core.IRodinFile; -import org.rodinp.core.IRodinProject; -import org.rodinp.core.RodinCore; -import org.rodinp.core.RodinDBException; - -import de.prob.logging.Logger; - -public class AnimationRefinementAction implements IObjectActionDelegate { - - private ISelection selection; - private IWorkbenchPart part; - - public AnimationRefinementAction() { - } - - public void setActivePart(final IAction action, - final IWorkbenchPart targetPart) { - this.part = targetPart; - - } - - public void run(final IAction action) { - // Get the Selection - if (!(selection instanceof IStructuredSelection)) { - return; - } - final IStructuredSelection ssel = (IStructuredSelection) selection; - if (ssel.size() != 1) { - return; - } - final Object element = ssel.getFirstElement(); - - IMachineRoot abs = null; - - if ((element instanceof IMachineRoot)) { - abs = (IMachineRoot) element; - } - if ((element instanceof IContextRoot)) { - // FIXME could be done for contexts as well - // we start with models - // abs = (IMachineRoot) element; - } - - if (abs == null) { - return; - } - - String basename = askForBaseName(abs.getRodinFile()); - - IContextRoot ctx = createContext(abs, basename); - createRefinement(abs, basename, ctx); - openWizard(); - } - - private IMachineRoot getMachineFileRoot(final String name, - final IRodinProject prj) { - final String fileName = EventBPlugin.getMachineFileName(name); - return (IMachineRoot) prj.getRodinFile(fileName).getRoot(); - } - - private IContextRoot createContext(final IMachineRoot abs, - final String basename) { - final String fileName = EventBPlugin.getContextFileName(basename - + "_ctx"); - IRodinFile file = abs.getRodinProject().getRodinFile(fileName); - try { - file.create(true, null); - IContextRoot root = (IContextRoot) file.getRoot(); - if (!root.exists()) { - root.create(null, null); - } - return root; - } catch (RodinDBException e1) { - String message = "Internal Error \n" + e1.getLocalizedMessage(); - Logger.notifyUser(message, e1); - e1.printStackTrace(); - } - return null; - } - - private void createRefinement(final IMachineRoot abs, final String name, - final IContextRoot ctx) { - IMachineRoot conc = getMachineFileRoot(name + "_mch", - abs.getRodinProject()); - CreateRefinement op = new CreateRefinement(abs, conc, ctx); - try { - RodinCore.run(op, null); - } catch (RodinDBException e) { - // TODO report error to end user - e.printStackTrace(); - return; - } - } - - /** - * Asks the user the name of the concrete machine to create and returns it. - * - * @param abs - * the abstract machine to refine - * @return the concrete machine entered by the user or <code>null</code> if - * canceled. - */ - private String askForBaseName(final IRodinFile abs) { - final InputDialog dialog = new InputDialog( - part.getSite().getShell(), - "New REFINES Clause", - "Please enter the name of the new animation model (the tool will automatically append _mch resp. _ctx)", - abs.getBareName() + "_ani1", new FileInputValidator(abs - .getRodinProject())); - dialog.open(); - - final String name = dialog.getValue(); - return name; - } - - private void openWizard() { - - } - - public void selectionChanged(final IAction action, - final ISelection selection) { - this.selection = selection; - - } - -} diff --git a/de.prob.ui/src/de/prob/ui/eventb/ConsistencyCheckingJob.java b/de.prob.ui/src/de/prob/ui/eventb/ConsistencyCheckingJob.java index d0a19b51556a857cff89ff484f35ec345f0a2444..704f467afbdd8d33712eace55a9b4cd636678ee1 100644 --- a/de.prob.ui/src/de/prob/ui/eventb/ConsistencyCheckingJob.java +++ b/de.prob.ui/src/de/prob/ui/eventb/ConsistencyCheckingJob.java @@ -39,7 +39,7 @@ public class ConsistencyCheckingJob extends Job { for (ConsistencyCheckingSearchOption modelCheckingOption : options) { optlist.add(modelCheckingOption.name()); } - this.options = Collections.unmodifiableList(optlist); + this.options = optlist; this.symmetryOption = symmetryOption; } @@ -57,6 +57,7 @@ public class ConsistencyCheckingJob extends Job { while (!abort) { try { modelCheckingResult = doSomeModelchecking(); + options.remove("inspect_existing_nodes"); monitor.worked(500); } catch (ProBException e) { return Status.CANCEL_STATUS; // Failed diff --git a/de.prob.ui/src/de/prob/ui/eventb/CreateRefinement.java b/de.prob.ui/src/de/prob/ui/eventb/CreateRefinement.java deleted file mode 100644 index a6b0ac33c72321ff4815fedcc32572252bdedc4a..0000000000000000000000000000000000000000 --- a/de.prob.ui/src/de/prob/ui/eventb/CreateRefinement.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.prob.ui.eventb; - -import static org.eventb.core.IConvergenceElement.Convergence.*; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eventb.core.IContextRoot; -import org.eventb.core.IEvent; -import org.eventb.core.IEventBRoot; -import org.eventb.core.IMachineRoot; -import org.eventb.core.IRefinesEvent; -import org.eventb.core.IRefinesMachine; -import org.eventb.core.ISeesContext; -import org.eventb.core.IVariable; -import org.eventb.core.IConvergenceElement.Convergence; -import org.rodinp.core.IInternalElement; -import org.rodinp.core.IInternalElementType; -import org.rodinp.core.IRodinDB; -import org.rodinp.core.RodinDBException; - -public class CreateRefinement implements IWorkspaceRunnable { - private final IMachineRoot abs; - private final IMachineRoot con; - private final IContextRoot ctx; - - public CreateRefinement(final IMachineRoot abs, final IMachineRoot con, - final IContextRoot ctx) { - this.abs = abs; - this.con = con; - this.ctx = ctx; - } - - public void run(final IProgressMonitor monitor) throws RodinDBException { - con.getRodinFile().create(false, monitor); - con.setConfiguration(abs.getConfiguration(), null); - createRefinesMachineClause(monitor); - copyChildrenOfType(con, abs, ISeesContext.ELEMENT_TYPE, null, monitor); - ISeesContext seesClause = con.getSeesClause(ctx.getComponentName()); - seesClause.create(null, monitor); - copyChildrenOfType(con, abs, IVariable.ELEMENT_TYPE, null, monitor); - createEvents(monitor); - con.getRodinFile().save(null, false); - } - - private void createRefinesMachineClause(final IProgressMonitor monitor) - throws RodinDBException { - final IRefinesMachine refines = con.createChild( - IRefinesMachine.ELEMENT_TYPE, null, monitor); - refines.setAbstractMachineName(abs.getComponentName(), monitor); - } - - @SuppressWarnings("unchecked") - private <T extends IInternalElement> void copyChildrenOfType( - final IEventBRoot destination, final IEventBRoot original, - final IInternalElementType<T> type, final T additional, - final IProgressMonitor monitor) throws RodinDBException { - - T[] elements = original.getChildrenOfType(type); - if (elements.length == 0) { - return; - } - if (additional != null) { - List<T> list = Arrays.asList(elements); - list.add(additional); - elements = (T[]) list.toArray(); - } - final IEventBRoot[] containers = new IEventBRoot[] { destination }; - final IRodinDB rodinDB = destination.getRodinDB(); - rodinDB.copy(elements, containers, null, null, false, monitor); - } - - private void createEvents(final IProgressMonitor monitor) - throws RodinDBException { - final IEvent[] absEvts = abs.getChildrenOfType(IEvent.ELEMENT_TYPE); - for (IEvent absEvt : absEvts) { - createEvent(absEvt, monitor); - } - } - - private void createEvent(final IEvent absEvt, final IProgressMonitor monitor) - throws RodinDBException { - final String name = absEvt.getElementName(); - final String label = absEvt.getLabel(); - final IEvent conEvt = con.getEvent(name); - conEvt.create(null, monitor); - conEvt.setLabel(label, monitor); - conEvt.setExtended(true, monitor); - createRefinesEventClause(conEvt, label, monitor); - if (absEvt.hasComment()) { - conEvt.setComment(absEvt.getComment(), monitor); - } - setConvergence(conEvt, absEvt, monitor); - } - - private void createRefinesEventClause(final IEvent conEvt, - final String label, final IProgressMonitor monitor) - throws RodinDBException { - if (!label.equals(IEvent.INITIALISATION)) { - final IRefinesEvent refines = conEvt.createChild( - IRefinesEvent.ELEMENT_TYPE, null, monitor); - refines.setAbstractEventLabel(label, monitor); - } - } - - private void setConvergence(final IEvent conEvt, final IEvent absEvt, - final IProgressMonitor monitor) throws RodinDBException { - final Convergence absCvg = absEvt.getConvergence(); - final Convergence conCvg = computeRefinementConvergence(absCvg); - conEvt.setConvergence(conCvg, monitor); - } - - private Convergence computeRefinementConvergence(final Convergence absCvg) { - switch (absCvg) { - case ANTICIPATED: - return ANTICIPATED; - case CONVERGENT: - case ORDINARY: - return ORDINARY; - } - return ORDINARY; - } - -} diff --git a/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java b/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java index bad71c487cf3bcc693af280eae6889e452261296..108ceed9f0c649efec04a1b682c08d766c138776 100644 --- a/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java +++ b/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java @@ -20,7 +20,9 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.services.ISourceProviderService; import org.eventb.core.IContextRoot; import org.eventb.core.IEventBRoot; import org.eventb.core.IMachineRoot; @@ -33,6 +35,8 @@ import de.prob.core.command.LoadEventBModelCommand; import de.prob.exceptions.ProBException; import de.prob.logging.Logger; import de.prob.ui.PerspectiveFactory; +import de.prob.ui.services.ContextLoadedProvider; +import de.prob.ui.services.ModelLoadedProvider; public class StartAnimationHandler extends AbstractHandler implements IHandler { @@ -144,6 +148,14 @@ public class StartAnimationHandler extends AbstractHandler implements IHandler { } return root; } + + private void updateContextLoadedProvider(boolean isContext) { + ISourceProviderService service = (ISourceProviderService) + PlatformUI.getWorkbench().getService(ISourceProviderService.class); + ContextLoadedProvider sourceProvider = (ContextLoadedProvider) service + .getSourceProvider(ContextLoadedProvider.SERVICE); + sourceProvider.setEnabled(isContext); + } private IFile extractResource(final IEventBRoot rootElement) { IFile resource = null; @@ -152,9 +164,11 @@ public class StartAnimationHandler extends AbstractHandler implements IHandler { } else if (rootElement instanceof IMachineRoot) { resource = ((IMachineRoot) rootElement).getSCMachineRoot() .getResource(); + updateContextLoadedProvider(false); } else if (rootElement instanceof IContextRoot) { resource = ((IContextRoot) rootElement).getSCContextRoot() .getResource(); + updateContextLoadedProvider(true); } return resource; } diff --git a/de.prob.ui/src/de/prob/ui/invcheck/InvariantCheckDialog.java b/de.prob.ui/src/de/prob/ui/invcheck/InvariantCheckDialog.java index 8dc5b0ea8aeb238d48a1e20155a5c69eab39e2c9..616b30fda3209f4a9ef832ff82807781001a0fdc 100644 --- a/de.prob.ui/src/de/prob/ui/invcheck/InvariantCheckDialog.java +++ b/de.prob.ui/src/de/prob/ui/invcheck/InvariantCheckDialog.java @@ -46,7 +46,7 @@ public class InvariantCheckDialog extends Dialog { composite.setLayout(new GridLayout()); // final Button check = new Button(composite, SWT.CHECK); final Label label1 = new Label(composite, SWT.NONE); - label1.setText("You can limit the analysis to some events."); + label1.setText("ProB will search for events which can violate the invariant. You can limit the analysis to some events."); final Label label2 = new Label(composite, SWT.NONE); label2.setText("If no event is chosen, all events will be checked."); listviewer = new ListViewer(composite, SWT.MULTI | SWT.V_SCROLL diff --git a/de.prob.ui/src/de/prob/ui/refinementcheck/RefinementCheckFinishedListener.java b/de.prob.ui/src/de/prob/ui/refinementcheck/RefinementCheckFinishedListener.java new file mode 100644 index 0000000000000000000000000000000000000000..2d6b7b613739e8e23ef8a0663528ff01c386810a --- /dev/null +++ b/de.prob.ui/src/de/prob/ui/refinementcheck/RefinementCheckFinishedListener.java @@ -0,0 +1,73 @@ +/** + * + */ +package de.prob.ui.refinementcheck; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; + +import de.prob.core.Animator; +import de.prob.core.ProBJobFinishedListener; +import de.prob.core.command.ConstraintBasedRefinementCheckCommand; +import de.prob.core.command.ConstraintBasedRefinementCheckCommand.ResultType; +import de.prob.core.command.IComposableCommand; +import de.prob.logging.Logger; + +/** + * + * @author krings + * + */ +public class RefinementCheckFinishedListener extends ProBJobFinishedListener { + private final Shell shell; + + public RefinementCheckFinishedListener(final Shell shell) { + this.shell = shell; + } + + @Override + protected void showResult(final IComposableCommand command, + final Animator animator) { + final ConstraintBasedRefinementCheckCommand refCmd = (ConstraintBasedRefinementCheckCommand) command; + + final ResultType result = refCmd.getResult(); + final int dialogType; + final String dialogTitle; + final String message; + + switch (result) { + case INTERRUPTED: + dialogType = MessageDialog.WARNING; + dialogTitle = "User Interrupt"; + message = "The refinement check has been interrupted by the user."; + break; + case NO_VIOLATION_FOUND: + dialogType = MessageDialog.INFORMATION; + dialogTitle = "No Refinement Violation found"; + message = "No possible refinement violation has been found."; + break; + case VIOLATION_FOUND: + dialogType = MessageDialog.ERROR; + dialogTitle = "Refinement Violation found"; + message = refCmd.getResultsString(); + break; + default: + Logger.notifyUser("Unexpected result: " + result); + return; + } + if (shell.isDisposed()) { + System.out.println("Refinement Check finished: " + dialogTitle); + } else { + final Runnable runnable = new Runnable() { + @Override + public void run() { + MessageDialog.open(dialogType, shell, dialogTitle, message, + SWT.NONE); + } + }; + shell.getDisplay().asyncExec(runnable); + } + } + +} diff --git a/de.prob.ui/src/de/prob/ui/refinementcheck/RefinementCheckHandler.java b/de.prob.ui/src/de/prob/ui/refinementcheck/RefinementCheckHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..919730d1ce7b85a47eee656ad389729ec8e68d24 --- /dev/null +++ b/de.prob.ui/src/de/prob/ui/refinementcheck/RefinementCheckHandler.java @@ -0,0 +1,49 @@ +/** + * + */ +package de.prob.ui.refinementcheck; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import de.prob.core.Animator; +import de.prob.core.ProBCommandJob; +import de.prob.core.command.ConstraintBasedRefinementCheckCommand; + +/** + * + * @author krings + */ +public class RefinementCheckHandler extends AbstractHandler { + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + final Shell shell = HandlerUtil.getActiveShell(event); + final Animator animator = Animator.getAnimator(); + if (animator.isMachineLoaded()) { + performRefinementCheck(animator, shell); + } else { + MessageDialog + .openError( + shell, + "Error: No ProB animation running", + "To perform a constraint based refinement check, please start the animation of the model first."); + } + return null; + } + + private void performRefinementCheck(final Animator animator, + final Shell shell) throws ExecutionException { + final ConstraintBasedRefinementCheckCommand command = new ConstraintBasedRefinementCheckCommand(); + final Job job = new ProBCommandJob( + "Performing CBC Refinement Checking", animator, command); + job.setUser(true); + job.addJobChangeListener(new RefinementCheckFinishedListener(shell)); + job.schedule(); + } + +} diff --git a/de.prob.ui/src/de/prob/ui/services/ContextLoadedProvider.java b/de.prob.ui/src/de/prob/ui/services/ContextLoadedProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..5229f7d5f379907587f28ec415a4454df550b609 --- /dev/null +++ b/de.prob.ui/src/de/prob/ui/services/ContextLoadedProvider.java @@ -0,0 +1,11 @@ +package de.prob.ui.services; + +public class ContextLoadedProvider extends AbstractBoolProvider { + + public static final String SERVICE = "de.prob.core.context_loaded"; + + public ContextLoadedProvider() { + super(SERVICE); + } + +} diff --git a/de.prob.units.tests/.classpath b/de.prob.units.tests/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ad32c83a7885b8953a938b41df3b4fd4fe1aae01 --- /dev/null +++ b/de.prob.units.tests/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/de.prob.units.tests/.project b/de.prob.units.tests/.project new file mode 100644 index 0000000000000000000000000000000000000000..e996d95dedee199ef5b494ed4cabe5987f5f3f68 --- /dev/null +++ b/de.prob.units.tests/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.units.tests</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/de.prob.units.tests/.settings/org.eclipse.jdt.core.prefs b/de.prob.units.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..c537b63063ce6052bdc49c5fd0745b078f162c90 --- /dev/null +++ b/de.prob.units.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/de.prob.units.tests/META-INF/MANIFEST.MF b/de.prob.units.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..5ebaf62b1cc891cebf5d9ea7e33b1dfd805b31f5 --- /dev/null +++ b/de.prob.units.tests/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests +Bundle-SymbolicName: de.prob.units.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: de.prob.units.tests.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + de.prob.units;bundle-version="1.0.0", + org.junit;bundle-version="4.8.2", + org.rodinp.core;bundle-version="[1.3.1,1.7.0)", + de.prob.core;bundle-version="9.3.0", + org.eventb.core;bundle-version="[2.1.0,2.6.0)" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/de.prob.units.tests/build.properties b/de.prob.units.tests/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..34d2e4d2dad529ceaeb953bfcdb63c51d69ffed2 --- /dev/null +++ b/de.prob.units.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/de.prob.units.tests/src/de/prob/units/pragmas/tests/PragmaAttributesTest.java b/de.prob.units.tests/src/de/prob/units/pragmas/tests/PragmaAttributesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1512151e648f0d289a573f9837378b782a16c124 --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/pragmas/tests/PragmaAttributesTest.java @@ -0,0 +1,81 @@ +package de.prob.units.pragmas.tests; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IVariable; +import org.junit.Test; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.RodinCore; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.units.tests.AbstractEventBTests; + +public class PragmaAttributesTest extends AbstractEventBTests { + final IAttributeType.String UNITATTRIBUTE = RodinCore + .getStringAttrType("de.prob.units.unitPragmaAttribute"); + + @Test + public void testMachineWithUnitPragmaOnVariable() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + IVariable v1 = createVariable(machine, "v1"); + createInvariant(machine, "inv1", "v1=5", false); + + // add unit pragma to variable + v1.setAttributeValue(UNITATTRIBUTE, "test", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one variable and one SC variable + assertEquals(1, machine.getVariables().length); + assertEquals(1, machine.getSCMachineRoot().getSCVariables().length); + + // and both should hold our attribute + assertEquals("test", + machine.getVariables()[0].getAttributeValue(UNITATTRIBUTE)); + assertEquals("test", + machine.getSCMachineRoot().getSCVariables()[0] + .getAttributeValue(UNITATTRIBUTE)); + } + + @Test + public void testContextWithUnitPragmaOnConstant() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + IConstant c1 = createConstant(context, "cst1"); + createAxiom(context, "axm1", "cst1=5", false); + + // add unit pragma to constant + c1.setAttributeValue(UNITATTRIBUTE, "test", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + context.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one constant and one SC constant + // both holding the attribute + assertEquals(1, context.getConstants().length); + assertEquals(1, context.getSCContextRoot().getSCConstants().length); + + // and both should hold our attribute + assertEquals("test", + context.getConstants()[0].getAttributeValue(UNITATTRIBUTE)); + assertEquals("test", + context.getSCContextRoot().getSCConstants()[0] + .getAttributeValue(UNITATTRIBUTE)); + + } +} diff --git a/de.prob.units.tests/src/de/prob/units/pragmas/tests/ReplacesEventBSyntaxTest.java b/de.prob.units.tests/src/de/prob/units/pragmas/tests/ReplacesEventBSyntaxTest.java new file mode 100644 index 0000000000000000000000000000000000000000..88c6edc3b46447dc435161be29494dd70d38d10d --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/pragmas/tests/ReplacesEventBSyntaxTest.java @@ -0,0 +1,70 @@ +package de.prob.units.pragmas.tests; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IVariable; +import org.junit.Test; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.RodinCore; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.units.tests.AbstractEventBTests; + +public class ReplacesEventBSyntaxTest extends AbstractEventBTests { + final IAttributeType.String UNITATTRIBUTE = RodinCore + .getStringAttrType("de.prob.units.unitPragmaAttribute"); + + @Test + public void testReplacesOnVariable() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + IVariable v1 = createVariable(machine, "v1"); + createInvariant(machine, "inv1", "v1=5", false); + + // add unit pragma to variable + v1.setAttributeValue(UNITATTRIBUTE, "m^2", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + assertEquals("m^2", + machine.getVariables()[0].getAttributeValue(UNITATTRIBUTE)); + assertEquals("m**2", + machine.getSCMachineRoot().getSCVariables()[0] + .getAttributeValue(UNITATTRIBUTE)); + } + + @Test + public void testReplacesOnConstant() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + IConstant c1 = createConstant(context, "cst1"); + createAxiom(context, "axm1", "cst1=5", false); + + // add unit pragma to constant + c1.setAttributeValue(UNITATTRIBUTE, "m^2", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + context.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + assertEquals("m^2", + context.getConstants()[0].getAttributeValue(UNITATTRIBUTE)); + assertEquals("m**2", + context.getSCContextRoot().getSCConstants()[0] + .getAttributeValue(UNITATTRIBUTE)); + + } +} diff --git a/de.prob.units.tests/src/de/prob/units/tests/AbstractEventBTests.java b/de.prob.units.tests/src/de/prob/units/tests/AbstractEventBTests.java new file mode 100644 index 0000000000000000000000000000000000000000..17de2efe9cf2550a52aeef3edc703b94c8d8e789 --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/tests/AbstractEventBTests.java @@ -0,0 +1,1242 @@ +package de.prob.units.tests; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.EventBPlugin; +import org.eventb.core.IAction; +import org.eventb.core.IAxiom; +import org.eventb.core.ICarrierSet; +import org.eventb.core.IConfigurationElement; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IConvergenceElement.Convergence; +import org.eventb.core.IEvent; +import org.eventb.core.IEventBProject; +import org.eventb.core.IExtendsContext; +import org.eventb.core.IGuard; +import org.eventb.core.IInvariant; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IParameter; +import org.eventb.core.IRefinesEvent; +import org.eventb.core.IRefinesMachine; +import org.eventb.core.ISeesContext; +import org.eventb.core.IVariable; +import org.eventb.core.IWitness; +import org.eventb.core.ast.FormulaFactory; +import org.junit.After; +import org.junit.Before; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; +import org.rodinp.internal.core.debug.DebugHelpers; + +/** + * @author htson + * <p> + * Abstract class for Event-B tests. + * </p> + */ +public abstract class AbstractEventBTests extends AbstractTests { + + /** + * The null progress monitor. + */ + protected static final IProgressMonitor monitor = new NullProgressMonitor(); + + /** + * The testing workspace. + */ + protected IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + /** + * The formula factory used to create formulae. + */ + protected static final FormulaFactory ff = FormulaFactory.getDefault(); + + /** + * Constructor: Create max_size test case. + */ + public AbstractEventBTests() { + super(); + } + + /** + * Constructor: Create max_size test case with the given name. + * + * @param name + * the name of test + */ + public AbstractEventBTests(String name) { + super(name); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + + // ensure autobuilding is turned off + IWorkspaceDescription wsDescription = workspace.getDescription(); + if (wsDescription.isAutoBuilding()) { + wsDescription.setAutoBuilding(false); + workspace.setDescription(wsDescription); + } + + // disable indexing + DebugHelpers.disableIndexing(); + + // Delete the old workspace + workspace.getRoot().delete(true, null); + + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + @After + @Override + protected void tearDown() throws Exception { + workspace.getRoot().delete(true, null); + super.tearDown(); + } + + // ========================================================================= + // Utility methods for creating various Event-B elements. + // ========================================================================= + + /** + * Utility method to create an Event-B project with given name. + * + * @param name + * name of the project + * @return the newly created Event-B project + * @throws CoreException + * if some errors occurred. + */ + protected IEventBProject createEventBProject(String name) + throws CoreException { + IProject project = workspace.getRoot().getProject(name); + project.create(null); + project.open(null); + IProjectDescription pDescription = project.getDescription(); + pDescription.setNatureIds(new String[] { RodinCore.NATURE_ID }); + project.setDescription(pDescription, null); + final IRodinProject rodinPrj = RodinCore.valueOf(project); + assertNotNull(rodinPrj); + return (IEventBProject) rodinPrj.getAdapter(IEventBProject.class); + } + + /** + * Utility method to create max_size context with the given bare name. The + * context is created as max_size child of the input Event-B project. + * + * @param project + * an Event-B project. + * @param bareName + * the bare name (without the extension .buc) of the context + * @return the newly created context. + * @throws RodinDBException + * if some problems occur. + */ + protected IContextRoot createContext(IEventBProject project, String bareName) + throws RodinDBException { + IRodinFile file = project.getContextFile(bareName); + file.create(true, null); + IContextRoot result = (IContextRoot) file.getRoot(); + result.setConfiguration(IConfigurationElement.DEFAULT_CONFIGURATION, + monitor); + return result; + } + + /** + * Utility method to create an EXTENDS clause within the input context for + * an abstract context. + * + * @param ctx + * max_size context. + * @param absCtxName + * the abstract context label. + * @return the newly created extends clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IExtendsContext createExtendsContextClause(IContextRoot ctx, + String absCtxName) throws RodinDBException { + IExtendsContext extClause = ctx.createChild( + IExtendsContext.ELEMENT_TYPE, null, monitor); + extClause.setAbstractContextName( + EventBPlugin.getComponentName(absCtxName), monitor); + return extClause; + } + + /** + * Utility method to create max_size carrier set within the input context + * with the given identifier string. + * + * @param ctx + * max_size context. + * @param identifierString + * the identifier string. + * @return the newly created carrier set. + * @throws RodinDBException + * if some errors occurred. + */ + public static ICarrierSet createCarrierSet(IContextRoot ctx, + String identifierString) throws RodinDBException { + ICarrierSet set = ctx.createChild(ICarrierSet.ELEMENT_TYPE, null, + monitor); + set.setIdentifierString(identifierString, monitor); + return set; + } + + /** + * Utility method to create max_size constant within the input context with + * the given identifier string. + * + * @param ctx + * max_size context. + * @param identifierString + * the identifier string. + * @return the newly created constant. + * @throws RodinDBException + * if some errors occurred. + */ + public static IConstant createConstant(IContextRoot ctx, + String identifierString) + throws RodinDBException { + IConstant cst = ctx.createChild(IConstant.ELEMENT_TYPE, null, monitor); + cst.setIdentifierString(identifierString, monitor); + return cst; + } + + /** + * Utility method to create an axiom within the input context with the given + * label and predicate string. + * + * @param ctx + * max_size context. + * @param label + * the label. + * @param predStr + * the predicate string. + * @param isTheorem + * <code>true</code> if the axiom is derivable, + * <code>false</code> otherwise. + * @return the newly created axiom. + * @throws RodinDBException + * if some errors occurred. + */ + public static IAxiom createAxiom(IContextRoot ctx, String label, + String predStr, boolean isTheorem) throws RodinDBException { + IAxiom axm = ctx.createChild(IAxiom.ELEMENT_TYPE, null, monitor); + axm.setLabel(label, monitor); + axm.setPredicateString(predStr, monitor); + axm.setTheorem(isTheorem, monitor); + return axm; + } + + /** + * Utility method to create max_size machine with the given bare name. The + * machine is created as max_size child of the input Event-B project. + * + * @param bareName + * the bare name (without the extension .bum) of the context + * @return the newly created context. + * @throws RodinDBException + * if some problems occur. + */ + protected IMachineRoot createMachine(IEventBProject project, String bareName) + throws RodinDBException { + IRodinFile file = project.getMachineFile(bareName); + file.create(true, null); + IMachineRoot result = (IMachineRoot) file.getRoot(); + result.setConfiguration(IConfigurationElement.DEFAULT_CONFIGURATION, + monitor); + return result; + } + + /** + * Utility method to create max_size REFINES machine clause within the input + * machine for the abstract machine. + * + * @param mch + * max_size machine. + * @param absMchName + * an abstract machine label + * @return the newly created refines clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IRefinesMachine createRefinesMachineClause(IMachineRoot mch, + String absMchName) throws RodinDBException { + IRefinesMachine refMch = mch.createChild(IRefinesMachine.ELEMENT_TYPE, + null, monitor); + refMch.setAbstractMachineName( + EventBPlugin.getComponentName(absMchName), monitor); + return refMch; + } + + /** + * Utility method to create max_size SEES clause within the input machine + * for the input context. + * + * @param mch + * max_size machine. + * @param ctxName + * max_size context. + * @return the newly created sees clause ({@link ISeesContext}. + * @throws RodinDBException + * if some errors occurred. + */ + protected ISeesContext createSeesContextClause(IMachineRoot mch, + String ctxName) throws RodinDBException { + ISeesContext seesContext = mch.createChild(ISeesContext.ELEMENT_TYPE, + null, monitor); + seesContext.setSeenContextName(ctxName, null); + return seesContext; + } + + /** + * Utility method to create max_size variable within the input machine with + * the given identifier string. + * + * @param mch + * max_size machine. + * @param identifierString + * the identifier string. + * @return the newly created variable. + * @throws RodinDBException + * if some errors occurred. + */ + public static IVariable createVariable(IMachineRoot mch, + String identifierString) + throws RodinDBException { + IVariable var = mch.createChild(IVariable.ELEMENT_TYPE, null, monitor); + var.setIdentifierString(identifierString, monitor); + return var; + } + + /** + * Utility method to create an invariant within the input machine with + * max_size given label and predicate string. + * + * @param mch + * max_size machine. + * @param label + * the label of the invariant. + * @param predicate + * the predicate string of the invariant. + * @return the newly created invariant. + * @throws RodinDBException + * if some errors occurred. + */ + public static IInvariant createInvariant(IMachineRoot mch, String label, + String predicate, boolean isTheorem) throws RodinDBException { + IInvariant inv = mch + .createChild(IInvariant.ELEMENT_TYPE, null, monitor); + inv.setLabel(label, monitor); + inv.setPredicateString(predicate, monitor); + inv.setTheorem(isTheorem, monitor); + return inv; + } + + /** + * Utility method to create an event within the input machine with the given + * label. By default, the extended attribute of the event is set to + * <code>false</code>. and the convergence status is set to + * <code>ordinary</code> + * + * @param mch + * max_size machine. + * @param label + * the label of the event. + * @return the newly created event. + * @throws RodinDBException + * if some errors occurred. + */ + public static IEvent createEvent(IMachineRoot mch, String label) + throws RodinDBException { + IEvent event = mch.createChild(IEvent.ELEMENT_TYPE, null, monitor); + event.setLabel(label, monitor); + event.setExtended(false, monitor); + event.setConvergence(Convergence.ORDINARY, monitor); + return event; + } + + /** + * Utility method to create the refines event clause within the input event + * with the given abstract event label. + * + * @param evt + * an event. + * @param absEvtLabel + * the abstract event label. + * @return the newly created refines event clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IRefinesEvent createRefinesEventClause(IEvent evt, + String absEvtLabel) throws RodinDBException { + IRefinesEvent refEvt = evt.createChild(IRefinesEvent.ELEMENT_TYPE, + null, monitor); + refEvt.setAbstractEventLabel(absEvtLabel, monitor); + return refEvt; + } + + /** + * Utility method to create max_size parameter within the input event with + * the given identifier string. + * + * @param evt + * an event. + * @param identifierString + * the identifier string. + * @return the newly created parameter. + * @throws RodinDBException + * if some errors occurred. + */ + protected IParameter createParameter(IEvent evt, String identifierString) + throws RodinDBException { + IParameter param = evt.createChild(IParameter.ELEMENT_TYPE, null, + monitor); + param.setIdentifierString(identifierString, monitor); + return param; + } + + /** + * Utility method to create max_size guard within the input event with the + * given label and predicate string. + * + * @param evt + * an event. + * @param label + * the label of the guard. + * @param predicateString + * the predicate string of the guard. + * @param b + * @return the newly created guard. + * @throws RodinDBException + * if some errors occurred. + */ + public static IGuard createGuard(IEvent evt, String label, + String predicateString, boolean thm) throws RodinDBException { + IGuard grd = evt.createChild(IGuard.ELEMENT_TYPE, null, monitor); + grd.setLabel(label, monitor); + grd.setPredicateString(predicateString, monitor); + grd.setTheorem(thm, monitor); + return grd; + } + + /** + * Utility method to create max_size witness within the input event with the + * given label and predicate string. + * + * @param evt + * an event. + * @param label + * the label of the witness. + * @param predicateString + * the predicate string of the witness. + * @return the newly created witness. + * @throws RodinDBException + * if some errors occurred. + */ + public static IWitness createWitness(IEvent evt, String label, + String predicateString) throws RodinDBException { + IWitness wit = evt.createChild(IWitness.ELEMENT_TYPE, null, monitor); + wit.setLabel(label, monitor); + wit.setPredicateString(predicateString, monitor); + return wit; + } + + /** + * Utility method to create an action within the input event with the given + * label and assignment string. + * + * @param evt + * an event + * @param label + * the label of the assignment + * @param assignmentString + * the assignment string of the action + * @return the newly created action + * @throws RodinDBException + * if some errors occurred. + */ + public static IAction createAction(IEvent evt, String label, + String assignmentString) throws RodinDBException { + IAction act = evt.createChild(IAction.ELEMENT_TYPE, null, monitor); + act.setLabel(label, monitor); + act.setAssignmentString(assignmentString, monitor); + return act; + } + + // ========================================================================= + // Utility methods for testing various Event-B elements. + // ========================================================================= + + /** + * Utility method for testing EXTENDS clauses of a context. + * + * @param message + * a message for debugging. + * @param ctx + * A context root whose EXTENDS clauses will be tested. + * @param expected + * the array of expected EXTENDS clauses. Each clause is + * represented by the abstract context name. The order of the + * EXTENDS clause is important. + */ + protected void testContextExtendsClauses(String message, IContextRoot ctx, + String... expected) { + try { + IExtendsContext[] extendsCtxs = ctx.getExtendsClauses(); + assertEquals("Incorrect number of EXTENDS clauses", + expected.length, extendsCtxs.length); + for (int i = 0; i < expected.length; i++) { + testExtendsClause(message, extendsCtxs[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an EXTEND clause. + * + * @param message + * a message for debugging. + * @param extendCtx + * the EXTEND clause under test. + * @param expected + * the expected abstract context name. + */ + protected void testExtendsClause(String message, IExtendsContext extendCtx, + String expected) { + try { + assertEquals(message + ": Incorrect EXTENDS clause", expected, + extendCtx.getAbstractContextName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the carrier sets of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context whose carrier sets will be tested. + * @param expected + * an array of expected carrier sets. Each carrier set is + * represented by its identifier. The order of the carrier sets + * is important. + */ + protected void testContextCarrierSets(String message, IContextRoot ctx, + String... expected) { + try { + ICarrierSet[] sets = ctx.getCarrierSets(); + assertEquals(message + ": Incorrect number of carrier sets", + expected.length, sets.length); + for (int i = 0; i < expected.length; i++) { + testCarrierSet(message, sets[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a carrier set. + * + * @param message + * a message for debugging. + * @param set + * the carrier set under test. + * @param expected + * the expected identifier of the carrier set. + */ + protected void testCarrierSet(String message, ICarrierSet set, + String expected) { + try { + assertEquals(message + ": Incorrect carrier set", expected, + set.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the constants of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context whose constants will be tested. + * @param expected + * an array of expected constants. Each constant is represented + * by its identifier. The order of the constants is important. + */ + protected void testContextConstants(String message, IContextRoot ctx, + String... expected) { + try { + IConstant[] csts = ctx.getConstants(); + assertEquals(message + ": Incorrect number of constants", + expected.length, csts.length); + for (int i = 0; i < expected.length; i++) { + testConstant(message, csts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a constant. + * + * @param message + * a message for debugging. + * @param set + * the constant under test. + * @param expected + * the expected identifier of the constant. + */ + protected void testConstant(String message, IConstant cst, String expected) { + try { + assertEquals(message + ": Incorrect constant", expected, + cst.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the axioms of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context root whose axioms will be tested. + * @param expected + * the expected pretty-print axioms. The axioms are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the axioms is + * important. + */ + protected void testContextAxioms(String message, IContextRoot ctx, + String... expected) { + try { + IAxiom[] axioms = ctx.getAxioms(); + assertEquals(message + ": Incorrect number of axioms", + expected.length, axioms.length); + for (int i = 0; i < expected.length; i++) { + testAxiom(message, axioms[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an axiom. + * + * @param message + * a message for debugging. + * @param axiom + * the axiom under test. + * @param expected + * the expected pretty print axiom. The axiom is "pretty-printed" + * as follows: "label:predicateString:isTheorem". + */ + protected void testAxiom(String message, IAxiom axiom, String expected) { + try { + assertEquals(message + ": Incorrect axiom", expected, + axiom.getLabel() + ":" + axiom.getPredicateString() + ":" + + axiom.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the REFINES clauses of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose REFINES clauses will be tested. + * @param expected + * an array of expected REFINES clause. Each REFINES clause is + * represented by its abstract machine name. The order of the + * REFINES clauses is important. + */ + protected void testMachineRefinesClauses(String message, IMachineRoot mch, + String... expected) { + try { + IRefinesMachine[] refinesClauses = mch.getRefinesClauses(); + assertEquals(message + ": Incorrect number of REFINES clauses", + expected.length, refinesClauses.length); + for (int i = 0; i < expected.length; i++) { + testRefinesClause(message, refinesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a REFINES (machine) clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the REFINES (machine) clause under test. + * @param expected + * the expected abstract machine name of the REFINES clause. + */ + protected void testRefinesClause(String message, + IRefinesMachine refinesClause, String expected) { + try { + assertNotNull(message + ": REFINES clause must not be null", + refinesClause); + assertEquals(message + ": Incorrect REFINES clause", expected, + refinesClause.getAbstractMachineName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the SEES clauses of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose SEES clauses will be tested. + * @param expected + * an array of expected SEES clause. Each SEES clause is + * represented by its seen context name. The order of the SEES + * clauses is important. + */ + protected void testMachineSeesClauses(String message, IMachineRoot mch, + String... expected) { + try { + ISeesContext[] seesClauses = mch.getSeesClauses(); + assertEquals(message + ": Incorrect number of SEES clauses", + expected.length, seesClauses.length); + for (int i = 0; i < expected.length; i++) { + testSeesClause(message, seesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a SEES clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the SEES clause under test. + * @param expected + * the expected seen context name of the SEES clause. + */ + protected void testSeesClause(String message, ISeesContext seesClause, + String expected) { + try { + assertEquals(message + ": Incorrect SEES clause", expected, + seesClause.getSeenContextName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the variables of a machine. + * + * @param message + * a message for debugging. + * @param mch + * the machine root whose variables will be tested. + * @param expected + * an array of expected variables. Each variable is represented + * by its identifier. The order of the variables is important. + */ + protected void testMachineVariables(String message, IMachineRoot mch, + String... expected) { + try { + IVariable[] vars = mch.getVariables(); + assertEquals(message + ": Incorrect number of variables", + expected.length, vars.length); + for (int i = 0; i < expected.length; i++) { + testVariable(message, vars[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the variables of a machine. + * + * @param message + * a message for debugging. + * @param mch + * the machine root whose variables will be tested. + * @param expected + * an array of expected variables. Each variable is represented + * by its identifier. The order of the variables is NOT + * important. + */ + protected void testMachineVariablesUnordered(String message, + IMachineRoot mch, String... expected) { + try { + IVariable[] vars = mch.getVariables(); + assertEquals(message + ": Incorrect number of variables", + expected.length, vars.length); + for (int i = 0; i < expected.length; i++) { + boolean b = false; + for (int j = 0; j < vars.length; j++) { + if (vars[j].getIdentifierString().equals(expected[i])) { + b = true; + break; + } + } + if (!b) { + fail("Variable " + expected[i] + " cannot be found"); + } + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a variable. + * + * @param message + * a message for debugging. + * @param var + * the variable under test. + * @param expected + * the expected identifier of the variable. + */ + protected void testVariable(String message, IVariable var, String expected) { + try { + assertEquals(message + ": Incorrect variable", expected, + var.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the invariants of a context. + * + * @param message + * a message for debugging. + * @param mch + * a context root whose invariants will be tested. + * @param expected + * the expected pretty-print invariants. The invariants are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the invariants + * is important. + */ + protected void testMachineInvariants(String message, IMachineRoot mch, + String... expected) { + try { + IInvariant[] invs = mch.getInvariants(); + assertEquals(message + ": Incorrect number of invariants", + expected.length, invs.length); + for (int i = 0; i < expected.length; i++) { + testInvariant(message, invs[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an invariant. + * + * @param message + * a message for debugging. + * @param inv + * the invariant under test. + * @param expected + * the expected pretty-print invariant. The invariant is + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". + */ + protected void testInvariant(String message, IInvariant inv, String expected) { + try { + assertEquals( + message + ": Incorrect invariant", + expected, + inv.getLabel() + ":" + inv.getPredicateString() + ":" + + inv.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the events of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose events will be tested. + * @param expected + * the expected pretty-print events (only the signature). The + * events are "pretty-printed" as follows: + * "label:convergent:isExtended". The order of the events is + * important. + */ + protected void testMachineEvents(String message, IMachineRoot mch, + String... expected) { + try { + IEvent[] evts = mch.getEvents(); + assertEquals(message + ": Incorrect number of events", + expected.length, evts.length); + for (int i = 0; i < expected.length; i++) { + testEvent(message, evts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an event. + * + * @param message + * a message for debugging. + * @param evt + * the event under test. + * @param expected + * the expected pretty-print event (only the signature). The + * event is "pretty-printed" as follows: + * "label:convergent:isExtended". + */ + protected void testEvent(String message, IEvent evt, String expected) { + try { + assertNotNull(message + ": The event must not be null", evt); + assertEquals( + message + ": Incorrect event", + expected, + evt.getLabel() + ":" + evt.getConvergence() + ":" + + evt.isExtended()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the REFINES clauses of an event. + * + * @param message + * a message for debugging. + * @param mch + * an event whose REFINES clauses will be tested. + * @param expected + * an array of expected REFINES clause. Each REFINES clause is + * represented by its abstract event name. The order of the + * REFINES clauses is important. + */ + protected void testEventRefinesClauses(String message, IEvent evt, + String... expected) { + try { + IRefinesEvent[] refinesClauses = evt.getRefinesClauses(); + assertEquals(message + ": Incorrect number of REFINES clauses", + expected.length, refinesClauses.length); + for (int i = 0; i < expected.length; i++) { + testRefinesClause(message, refinesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a REFINES (event) clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the REFINES (event) clause under test. + * @param expected + * the expected abstract event name of the REFINES clause. + */ + protected void testRefinesClause(String message, + IRefinesEvent refinesEvent, String expected) { + try { + assertEquals(message + "Incorrect REFINES clause", expected, + refinesEvent.getAbstractEventLabel()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the parameters of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose parameters will be tested. + * @param expected + * the expected set of parameters. Each parameter is represented + * by its identifier. The order of the parameters is important. + */ + protected void testEventParameters(String message, IEvent evt, + String... expected) { + try { + IParameter[] params = evt.getParameters(); + assertEquals(message + ": Incorrect number of parameters", + expected.length, params.length); + for (int i = 0; i < expected.length; i++) { + testParameter(message, params[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a parameter. + * + * @param message + * a message for debugging. + * @param par + * the parameter under test. + * @param expected + * the expected parameter identifier. + */ + protected void testParameter(String message, IParameter par, String expected) { + try { + assertEquals(message + ": Incorrect parameter", expected, + par.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the guards of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose guards will be tested. + * @param expected + * the expected pretty-print guards. The guards are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the guards is + * important. + */ + protected void testEventGuards(String message, IEvent evt, + String... expected) { + try { + IGuard[] grds = evt.getGuards(); + assertEquals(message + ": Incorrect number of guards", + expected.length, grds.length); + for (int i = 0; i < grds.length; i++) { + testGuard(message, grds[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a guard. + * + * @param message + * a message for debugging. + * @param grd + * the guard under test. + * @param expected + * the expected pretty-print guard. The guard is "pretty-printed" + * as follows: "label:predicateString:isTheorem". + */ + protected void testGuard(String message, IGuard grd, String expected) { + try { + assertEquals( + message + ": Incorrect guard", + expected, + grd.getLabel() + ":" + grd.getPredicateString() + ":" + + grd.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the witnesses of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose witnesses will be tested. + * @param expected + * the expected pretty-print witnesses. The witnesses are + * "pretty-printed" as follows: "label:predicateString". The + * order of the witnesses is important. + */ + protected void testEventWitnesses(String message, IEvent evt, + String... expected) { + try { + IWitness[] wits = evt.getWitnesses(); + assertEquals(message + ": Incorrect number of witnesses", + expected.length, wits.length); + for (int i = 0; i < expected.length; i++) { + testWitness(message, wits[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an witness. + * + * @param message + * a message for debugging. + * @param wit + * the witness under test. + * @param expected + * the expected pretty-print witness. The witness is + * "pretty-printed" as follows: "label:predicateString". + */ + protected void testWitness(String message, IWitness wit, String expected) { + try { + assertEquals(message + ": Incorrect witness", expected, + wit.getLabel() + ":" + wit.getPredicateString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the actions of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose actions will be tested. + * @param expected + * expected pretty-print actions. The actions are + * "pretty-printed" as follows: "label:assignmentString". The + * order of the actions is important. + */ + protected void testEventActions(String message, IEvent evt, + String... expected) { + try { + IAction[] acts = evt.getActions(); + assertEquals(message + ": Incorrect number of actions", + expected.length, acts.length); + for (int i = 0; i < expected.length; i++) { + testAction(message, acts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an action. + * + * @param message + * a message + * @param act + * the action under test + * @param expected + * expected pretty-print action. The action is "pretty-printed" + * as follows: "label:assignmentString". + */ + protected void testAction(String message, IAction act, String expected) { + try { + assertEquals(message + ": Incorrect action", expected, + act.getLabel() + ":" + act.getAssignmentString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + +} diff --git a/de.prob.units.tests/src/de/prob/units/tests/AbstractTests.java b/de.prob.units.tests/src/de/prob/units/tests/AbstractTests.java new file mode 100644 index 0000000000000000000000000000000000000000..16b72cb82c727d323d9c1c386bdf35b18306f7c9 --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/tests/AbstractTests.java @@ -0,0 +1,143 @@ +package de.prob.units.tests; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +/** + * @author htson + * <p> + * This abstract class contains utility methods supporting testing. + * </p> + */ +public abstract class AbstractTests extends TestCase { + + /** + * Constructor: Create max_size test case. + */ + public AbstractTests() { + super(); + } + + /** + * Constructor: Create max_size test case with the given name. + * + * @param name + * the name of test + */ + public AbstractTests(String name) { + super(name); + } + + /** + * Utility method to compare two string collections. The expected collection + * is given in terms of an array of strings. The actual collection is given + * as a collection of strings. The two are the same if the number of + * elements is the same and every element of the expected collection appear + * in the actual collection. + * + * @param msg + * a message. + * @param actual + * actual collection of strings. + * @param expected + * expected array of strings. + */ + protected static void assertSameStrings(String msg, + Collection<String> actual, String... expected) { + assertEquals(msg + ": Incorrect number of elements\n", expected.length, + actual.size()); + for (String exp : expected) { + assertTrue(msg + ": Expected element " + exp + " not found", + actual.contains(exp)); + } + } + + /** + * Utility method to compare two arrays of strings. The two are the same if + * the number of elements is the same, and the strings at the same index are + * the same. + * + * @param msg + * a message. + * @param actual + * actual array of strings. + * @param expected + * expected array of strings. + */ + protected static void assertSameStrings(String msg, String[] actual, + String... expected) { + assertEquals(msg + ": Incorrect number of strings\n", expected.length, + actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(msg, expected[i], actual[i]); + } + } + + /** + * Utility method to compare two arrays of objects. The two are the same if + * the number of elements is the same, and the objects at the same index are + * the same. + * + * @param msg + * a message. + * @param expected + * expected array of objects. + * @param actual + * actual array of objects. + */ + protected static void assertSameObjects(String msg, Object[] expected, + Object[] actual) { + assertEquals(msg + ": Incorrect number of objects\n", expected.length, + actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(msg, expected[i], actual[i]); + } + } + + /** + * Utility method to compare two maps of objects to objects. The two are the + * same if the key sets are the same (using + * {@link #assertSameSet(String, Set, Set)}), and for each key, they map to + * the same value. + * + * @param msg + * a messages. + * @param expected + * expected map. + * @param actual + * actual map. + */ + protected void assertSameMap(String msg, + Map<? extends Object, ? extends Object> expected, + Map<? extends Object, ? extends Object> actual) { + Set<? extends Object> expectedKeySet = expected.keySet(); + Set<? extends Object> actualKeySet = actual.keySet(); + assertSameSet(msg, expectedKeySet, actualKeySet); + for (Object key : expectedKeySet) { + assertEquals(msg, expected.get(key), actual.get(key)); + } + } + + /** + * Utility method to compare two sets of objects. The two are the same if + * they have the same number of elements, and each element of the expected + * set appears in the actual set. + * + * @param msg + * @param expected + * @param actual + */ + protected void assertSameSet(String msg, Set<? extends Object> expected, + Set<? extends Object> actual) { + assertEquals(msg + ": The number of elements must be the same", + expected.size(), actual.size()); + for (Object elm : expected) { + assertTrue(msg + ": expected element " + elm + " not found", + actual.contains(elm)); + } + } + +} \ No newline at end of file diff --git a/de.prob.units.tests/src/de/prob/units/tests/Activator.java b/de.prob.units.tests/src/de/prob/units/tests/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..3f4f6e4c2c5bca60dd376370b831f5a763fd904a --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/tests/Activator.java @@ -0,0 +1,50 @@ +package de.prob.units.tests; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "de.prob.units.tests"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/de.prob.units.tests/src/de/prob/units/translation/tests/PragmaTranslatorTest.java b/de.prob.units.tests/src/de/prob/units/translation/tests/PragmaTranslatorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..79956b4befd9c37f952d22f89b98bdea93e90b57 --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/translation/tests/PragmaTranslatorTest.java @@ -0,0 +1,94 @@ +package de.prob.units.translation.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IVariable; +import org.junit.Before; +import org.junit.Test; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.RodinCore; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; +import de.prob.units.tests.AbstractEventBTests; + +public class PragmaTranslatorTest extends AbstractEventBTests { + final IAttributeType.String UNITATTRIBUTE = RodinCore + .getStringAttrType("de.prob.units.unitPragmaAttribute"); + + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Test + public void testMachineWithUnitPragmaOnVariable() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + IVariable v1 = createVariable(machine, "v1"); + createInvariant(machine, "inv1", "v1=5", false); + + // add unit pragma to variable + v1.setAttributeValue(UNITATTRIBUTE, "test", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one variable and one SC variable + assertEquals(1, machine.getVariables().length); + assertEquals(1, machine.getSCMachineRoot().getSCVariables().length); + + TranslatorFactory.translate(machine, writer); + + assertEquals( + "package(load_event_b_project([event_b_model(none,'TestMachine',[sees(none,[]),variables(none,[identifier(none,v1)]),invariant(none,[equal(rodinpos('TestMachine',inv1,'('),identifier(none,v1),integer(none,5))]),theorems(none,[]),events(none,[])])],[],[exporter_version(2),pragma(unit,'TestMachine',v1,[test])],_Error)).\n", + stringWriter.getBuffer().toString()); + } + + @Test + public void testContextWithUnitPragmaOnConstant() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + IConstant c1 = createConstant(context, "cst1"); + createAxiom(context, "axm1", "cst1=5", false); + + // add unit pragma to constant + c1.setAttributeValue(UNITATTRIBUTE, "test", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + context.getRodinFile().save(monitor, false); + project.getRodinProject().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one constant and one SC constant + assertEquals(1, context.getConstants().length); + assertEquals(1, context.getSCContextRoot().getSCConstants().length); + + TranslatorFactory.translate(context, writer); + + assertEquals( + "package(load_event_b_project([],[event_b_context(none,'TestContext',[extends(none,[]),constants(none,[identifier(none,cst1)]),axioms(none,[equal(rodinpos('TestContext',axm1,'('),identifier(none,cst1),integer(none,5))]),theorems(none,[]),sets(none,[])])],[exporter_version(2),pragma(unit,'TestContext',cst1,[test])],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.units/.classpath b/de.prob.units/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ad32c83a7885b8953a938b41df3b4fd4fe1aae01 --- /dev/null +++ b/de.prob.units/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/de.prob.units/.project b/de.prob.units/.project new file mode 100644 index 0000000000000000000000000000000000000000..22333fa9cb227f96d35310a6635507f782547a31 --- /dev/null +++ b/de.prob.units/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.units</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/de.prob.units/.settings/org.eclipse.jdt.core.prefs b/de.prob.units/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..c537b63063ce6052bdc49c5fd0745b078f162c90 --- /dev/null +++ b/de.prob.units/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/de.prob.units/META-INF/MANIFEST.MF b/de.prob.units/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..a5091100200bf3ecbdd073ed5f090e3393bdfe74 --- /dev/null +++ b/de.prob.units/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ProB Physical Units Support +Bundle-SymbolicName: de.prob.units;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: de.prob.units.Activator +Require-Bundle: org.eclipse.core.runtime, + de.prob.core;bundle-version="[9.4.0,9.5.0)", + org.eventb.ui;bundle-version="[2.5.0,3.0.0)", + de.prob.ui;bundle-version="[7.4.0,7.5.0)" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: HHU Düsseldorf STUPS Group diff --git a/de.prob.units/build.properties b/de.prob.units/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..79785acaeea2f69bbe4b5e556221958fef4b9f55 --- /dev/null +++ b/de.prob.units/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + icons/,\ + plugin.xml diff --git a/de.prob.units/icons/unit_analysis.png b/de.prob.units/icons/unit_analysis.png new file mode 100644 index 0000000000000000000000000000000000000000..36d5d6278be2e2226de7b9d4d0fc9da720e47f1b Binary files /dev/null and b/de.prob.units/icons/unit_analysis.png differ diff --git a/de.prob.units/plugin.xml b/de.prob.units/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..b638b268a7251133e354a7fef6595000bf4bc7fd --- /dev/null +++ b/de.prob.units/plugin.xml @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eventb.ui.editorItems"> + <textAttribute + class="de.prob.units.pragmas.UnitPragmaAttribute" + expandsHorizontally="false" + id="de.prob.units.unitPragmaAttribute" + isMath="true" + prefix="Physical Unit:" + style="de.prob.units.unitPragmaAttribute" + typeId="de.prob.units.unitPragmaAttribute"> + </textAttribute> + <attributeRelation + elementTypeId="org.eventb.core.variable"> + <attributeReference + descriptionId="de.prob.units.unitPragmaAttribute"> + </attributeReference> + <attributeReference + descriptionId="de.prob.units.inferredUnitPragmaAttribute"> + </attributeReference> + </attributeRelation> + <attributeRelation + elementTypeId="org.eventb.core.constant"> + <attributeReference + descriptionId="de.prob.units.unitPragmaAttribute"> + </attributeReference> + <attributeReference + descriptionId="de.prob.units.inferredUnitPragmaAttribute"> + </attributeReference> + </attributeRelation> + <textAttribute + class="de.prob.units.pragmas.InferredUnitPragmaAttribute" + expandsHorizontally="false" + id="de.prob.units.inferredUnitPragmaAttribute" + isMath="true" + prefix="Inferred Physical Unit:" + style="de.prob.units.inferredUnitPragmaAttribute" + typeId="de.prob.units.inferredUnitPragmaAttribute"> + </textAttribute> + </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + class="de.prob.units.ui.StartUnitAnalysisHandler" + commandId="de.prob.units.startunitanalysis"> + </handler> + </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="popup:fr.systerel.explorer.navigator.view"> + <separator + name="de.prob.units.separator2" + visible="true"> + </separator> + <command + commandId="de.prob.units.startunitanalysis" + icon="icons/unit_analysis.png" + label="Analyse Physical Units" + style="push"> + <visibleWhen> + <with + variable="selection"> + <iterate + operator="or"> + <instanceof + value="org.eventb.core.IEventBRoot"> + </instanceof> + </iterate> + </with> + </visibleWhen> + </command> + <separator + name="de.prob.units.separator1" + visible="true"> + </separator> + </menuContribution> + </extension> + <extension + point="org.eclipse.ui.commands"> + <command + id="de.prob.units.startunitanalysis" + name="Analyse Physical Units"> + </command> + </extension> + <extension + point="org.rodinp.core.attributeTypes"> + <attributeType + id="unitPragmaAttribute" + kind="string" + name="Content of a unit Pragma to send to ProB"> + </attributeType> + <attributeType + id="inferredUnitPragmaAttribute" + kind="string" + name="Content of a unit Pragma received from ProB"> + </attributeType> + </extension> + <extension + point="org.eventb.core.configurations"> + <configuration + id="mchBase" + name="mchBase"> + <scModule + id="de.prob.units.machineAttributeProcessor"> + </scModule> + <scModule + id="de.prob.units.contextAttributeProcessor"> + </scModule> + </configuration> + </extension> + <extension + id="scMachineModuleTypes" + point="org.eventb.core.scModuleTypes"> + <processorType + class="de.prob.units.sc.MachineAttributeProcessor" + id="machineAttributeProcessor" + name="machineAttributeProcessor" + parent="org.eventb.core.machineModule"> + </processorType> + <processorType + class="de.prob.units.sc.ContextAttributeProcessor" + id="contextAttributeProcessor" + name="contextAttributeProcessor" + parent="org.eventb.core.contextModule"> + </processorType> + </extension> +</plugin> diff --git a/de.prob.units/src/de/prob/units/Activator.java b/de.prob.units/src/de/prob/units/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..a867db55ff989f02df0adfa770760e0d69c1645f --- /dev/null +++ b/de.prob.units/src/de/prob/units/Activator.java @@ -0,0 +1,68 @@ +package de.prob.units; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.rodinp.core.RodinCore; + + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "de.prob.units"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + + setConfig(); + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Registers a file configuration setter for our plugin. + */ + public static void setConfig() { + RodinCore.addElementChangedListener(new ConfSettor()); + } + +} diff --git a/de.prob.units/src/de/prob/units/ConfSettor.java b/de.prob.units/src/de/prob/units/ConfSettor.java new file mode 100644 index 0000000000000000000000000000000000000000..c41716ec92dc0a51f2a0a3f7a4501be3c6a1dde5 --- /dev/null +++ b/de.prob.units/src/de/prob/units/ConfSettor.java @@ -0,0 +1,65 @@ +package de.prob.units; + +import org.eventb.core.IContextRoot; +import org.eventb.core.IMachineRoot; +import org.rodinp.core.ElementChangedEvent; +import org.rodinp.core.IElementChangedListener; +import org.rodinp.core.IElementType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinDB; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.IRodinElementDelta; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinDBException; + +/** + * Class that updates the configuration of files, to add the static checker + * modules for our qualitative probabilistic reasoning plug-in. + */ +public class ConfSettor implements IElementChangedListener { + + private static final String CONFIG = Activator.PLUGIN_ID + ".mchBase"; + + public void elementChanged(ElementChangedEvent event) { + + final IRodinElementDelta d = event.getDelta(); + try { + processDelta(d); + } catch (final RodinDBException e) { + // TODO add exception log + } + } + + private void processDelta(final IRodinElementDelta d) + throws RodinDBException { + final IRodinElement e = d.getElement(); + + final IElementType<? extends IRodinElement> elementType = e + .getElementType(); + if (elementType.equals(IRodinDB.ELEMENT_TYPE) + || elementType.equals(IRodinProject.ELEMENT_TYPE)) { + for (final IRodinElementDelta de : d.getAffectedChildren()) { + processDelta(de); + } + } else if (elementType.equals(IRodinFile.ELEMENT_TYPE)) { + final IInternalElement root = ((IRodinFile) e).getRoot(); + + if (root.getElementType().equals(IMachineRoot.ELEMENT_TYPE)) { + final IMachineRoot mch = (IMachineRoot) root; + final String conf = mch.getConfiguration(); + if (!conf.contains(CONFIG)) { + mch.setConfiguration(conf + ";" + CONFIG, null); + } + } + + if (root.getElementType().equals(IContextRoot.ELEMENT_TYPE)) { + final IContextRoot ctx = (IContextRoot) root; + final String conf = ctx.getConfiguration(); + if (!conf.contains(CONFIG)) { + ctx.setConfiguration(conf + ";" + CONFIG, null); + } + } + } + } +} \ No newline at end of file diff --git a/de.prob.units/src/de/prob/units/pragmas/InferredUnitPragmaAttribute.java b/de.prob.units/src/de/prob/units/pragmas/InferredUnitPragmaAttribute.java new file mode 100644 index 0000000000000000000000000000000000000000..56b0c2da80cdb47cf9d9ed1c610ab9d9d05f46f3 --- /dev/null +++ b/de.prob.units/src/de/prob/units/pragmas/InferredUnitPragmaAttribute.java @@ -0,0 +1,84 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.units.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; + +import de.prob.units.Activator; + +public class InferredUnitPragmaAttribute implements IAttributeManipulation { + public static IAttributeType.String ATTRIBUTE = RodinCore + .getStringAttrType(Activator.PLUGIN_ID + + ".inferredUnitPragmaAttribute"); + + private final String defaultValue = ""; + + public InferredUnitPragmaAttribute() { + // empty constructor + } + + 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) { + return null; + } + + @Override + public String getValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + try { + return asInternalElement(element).getAttributeValue(ATTRIBUTE); + } catch (RodinDBException ex) { + // happens if the attribute is not set on this element + // just return a default instead of throwing a RodinDBException + } + return defaultValue; + } + + @Override + public boolean hasValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + return asInternalElement(element).hasAttribute(ATTRIBUTE); + } + + @Override + public void removeAttribute(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).removeAttribute(ATTRIBUTE, monitor); + + } + + @Override + public void setDefaultValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, defaultValue, + monitor); + } + + @Override + public void setValue(IRodinElement element, String value, + IProgressMonitor monitor) throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, value, monitor); + } +} diff --git a/de.prob.units/src/de/prob/units/pragmas/UnitPragmaAttribute.java b/de.prob.units/src/de/prob/units/pragmas/UnitPragmaAttribute.java new file mode 100644 index 0000000000000000000000000000000000000000..eb287258d021c5248f1dd0b753454bae33ef7066 --- /dev/null +++ b/de.prob.units/src/de/prob/units/pragmas/UnitPragmaAttribute.java @@ -0,0 +1,83 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.units.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; + +import de.prob.units.Activator; + +public class UnitPragmaAttribute implements IAttributeManipulation { + public static IAttributeType.String ATTRIBUTE = RodinCore + .getStringAttrType(Activator.PLUGIN_ID + ".unitPragmaAttribute"); + + private final String defaultValue = ""; + + public UnitPragmaAttribute() { + // empty constructor + } + + 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) { + return null; + } + + @Override + public String getValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + try { + return asInternalElement(element).getAttributeValue(ATTRIBUTE); + } catch (RodinDBException ex) { + // happens if the attribute is not set on this element + // just return a default instead of throwing a RodinDBException + } + return defaultValue; + } + + @Override + public boolean hasValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + return asInternalElement(element).hasAttribute(ATTRIBUTE); + } + + @Override + public void removeAttribute(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).removeAttribute(ATTRIBUTE, monitor); + + } + + @Override + public void setDefaultValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, defaultValue, + monitor); + } + + @Override + public void setValue(IRodinElement element, String value, + IProgressMonitor monitor) throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, value, monitor); + } +} diff --git a/de.prob.units/src/de/prob/units/problems/IncorrectUnitDefinitionMarker.java b/de.prob.units/src/de/prob/units/problems/IncorrectUnitDefinitionMarker.java new file mode 100644 index 0000000000000000000000000000000000000000..d7f4e0e209b07a5e6672438eb9fb9ead979ee746 --- /dev/null +++ b/de.prob.units/src/de/prob/units/problems/IncorrectUnitDefinitionMarker.java @@ -0,0 +1,35 @@ +package de.prob.units.problems; + +import org.eclipse.core.resources.IMarker; +import org.rodinp.core.IRodinProblem; + +import de.prob.units.Activator; + +public class IncorrectUnitDefinitionMarker implements IRodinProblem { + + private final String message; + private final int severity = IMarker.SEVERITY_ERROR; + public static final String ERROR_CODE = Activator.PLUGIN_ID + "." + + "incorrectUnitDefinition"; + + public IncorrectUnitDefinitionMarker(String cstOrVar) { + this.message = "Incorrect Unit Definition on Constant/Variable " + + cstOrVar; + } + + @Override + public String getErrorCode() { + return ERROR_CODE; + } + + @Override + public String getLocalizedMessage(Object[] arg0) { + return message; + } + + @Override + public int getSeverity() { + return severity; + } + +} diff --git a/de.prob.units/src/de/prob/units/problems/MultipleUnitsInferredMarker.java b/de.prob.units/src/de/prob/units/problems/MultipleUnitsInferredMarker.java new file mode 100644 index 0000000000000000000000000000000000000000..3daaa97a0666685bec7b28970fa324f98cafe30c --- /dev/null +++ b/de.prob.units/src/de/prob/units/problems/MultipleUnitsInferredMarker.java @@ -0,0 +1,36 @@ +package de.prob.units.problems; + +import org.eclipse.core.resources.IMarker; +import org.rodinp.core.IRodinProblem; + +import de.prob.units.Activator; + +public class MultipleUnitsInferredMarker implements IRodinProblem { + + private final String message; + private final int severity = IMarker.SEVERITY_ERROR; + + public static final String ERROR_CODE = Activator.PLUGIN_ID + "." + + "multipleUnitsInferred"; + + public MultipleUnitsInferredMarker(String cstOrVar) { + this.message = "Multiple Units inferred for Constant/Variable " + + cstOrVar; + } + + @Override + public String getErrorCode() { + return ERROR_CODE; + } + + @Override + public String getLocalizedMessage(Object[] arg0) { + return message; + } + + @Override + public int getSeverity() { + return severity; + } + +} diff --git a/de.prob.units/src/de/prob/units/problems/NoUnitInferredMarker.java b/de.prob.units/src/de/prob/units/problems/NoUnitInferredMarker.java new file mode 100644 index 0000000000000000000000000000000000000000..8f011edccb79b26e67cd59da893354aa5d6a2830 --- /dev/null +++ b/de.prob.units/src/de/prob/units/problems/NoUnitInferredMarker.java @@ -0,0 +1,34 @@ +package de.prob.units.problems; + +import org.eclipse.core.resources.IMarker; +import org.rodinp.core.IRodinProblem; + +import de.prob.units.Activator; + +public class NoUnitInferredMarker implements IRodinProblem { + + private final String message; + private final int severity = IMarker.SEVERITY_WARNING; + public static final String ERROR_CODE = Activator.PLUGIN_ID + "." + + "multipleUnitsInferred"; + + public NoUnitInferredMarker(String cstOrVar) { + this.message = "No Units inferred for Constant/Variable " + cstOrVar; + } + + @Override + public String getErrorCode() { + return ERROR_CODE; + } + + @Override + public String getLocalizedMessage(Object[] arg0) { + return message; + } + + @Override + public int getSeverity() { + return severity; + } + +} diff --git a/de.prob.units/src/de/prob/units/sc/ContextAttributeProcessor.java b/de.prob.units/src/de/prob/units/sc/ContextAttributeProcessor.java new file mode 100644 index 0000000000000000000000000000000000000000..91b1fc7c6fddf08d2cab0741cb419fbff7e58b0f --- /dev/null +++ b/de.prob.units/src/de/prob/units/sc/ContextAttributeProcessor.java @@ -0,0 +1,72 @@ +package de.prob.units.sc; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eventb.core.EventBAttributes; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.ISCConstant; +import org.eventb.core.ISCContextRoot; +import org.eventb.core.sc.SCCore; +import org.eventb.core.sc.SCProcessorModule; +import org.eventb.core.sc.state.ISCStateRepository; +import org.eventb.core.tool.IModuleType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.IRodinFile; + +import de.prob.units.Activator; +import de.prob.units.pragmas.UnitPragmaAttribute; + +public class ContextAttributeProcessor extends SCProcessorModule { + public static final IModuleType<ContextAttributeProcessor> MODULE_TYPE = SCCore + .getModuleType(Activator.PLUGIN_ID + ".contextAttributeProcessor"); //$NON-NLS-1$ + + @Override + public void process(IRodinElement element, IInternalElement target, + ISCStateRepository repository, IProgressMonitor monitor) + throws CoreException { + assert (element instanceof IRodinFile); + assert (target instanceof ISCContextRoot); + + // get all variables and copy over the attributes + IRodinFile contextFile = (IRodinFile) element; + IContextRoot contextRoot = (IContextRoot) contextFile.getRoot(); + + ISCContextRoot scContextRoot = (ISCContextRoot) target; + + IConstant[] constants = contextRoot.getConstants(); + ISCConstant[] scconstants = scContextRoot.getSCConstants(); + + if (constants.length == 0 || scconstants.length == 0) + return; + + for (IConstant constant : constants) { + String identifier = constant + .getAttributeValue(EventBAttributes.IDENTIFIER_ATTRIBUTE); + ISCConstant scConstant = scContextRoot.getSCConstant(identifier); + + // might have been filtered out by previous modules + if (scConstant.exists()) { + // original might not contain the attribute + if (constant.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) { + String attribute = constant + .getAttributeValue(UnitPragmaAttribute.ATTRIBUTE); + + attribute = UnitAttributeProcessorStatics + .translateEventBPragmaToBPragma(attribute); + + scConstant.setAttributeValue(UnitPragmaAttribute.ATTRIBUTE, + attribute, monitor); + } + } + } + + } + + @Override + public IModuleType<?> getModuleType() { + return MODULE_TYPE; + } + +} diff --git a/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java b/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java new file mode 100644 index 0000000000000000000000000000000000000000..2b64a2e5dab0423d495e03e85312b3cee041d145 --- /dev/null +++ b/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java @@ -0,0 +1,69 @@ +package de.prob.units.sc; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eventb.core.IMachineRoot; +import org.eventb.core.ISCMachineRoot; +import org.eventb.core.ISCVariable; +import org.eventb.core.IVariable; +import org.eventb.core.sc.SCCore; +import org.eventb.core.sc.SCProcessorModule; +import org.eventb.core.sc.state.ISCStateRepository; +import org.eventb.core.tool.IModuleType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.IRodinFile; + +import de.prob.units.Activator; +import de.prob.units.pragmas.UnitPragmaAttribute; + +public class MachineAttributeProcessor extends SCProcessorModule { + public static final IModuleType<MachineAttributeProcessor> MODULE_TYPE = SCCore + .getModuleType(Activator.PLUGIN_ID + ".machineAttributeProcessor"); //$NON-NLS-1$ + + @Override + public void process(IRodinElement element, IInternalElement target, + ISCStateRepository repository, IProgressMonitor monitor) + throws CoreException { + assert (element instanceof IRodinFile); + assert (target instanceof ISCMachineRoot); + + // get all variables and copy over the attributes + IRodinFile machineFile = (IRodinFile) element; + IMachineRoot machineRoot = (IMachineRoot) machineFile.getRoot(); + + ISCMachineRoot scMachineRoot = (ISCMachineRoot) target; + + IVariable[] variables = machineRoot.getVariables(); + + if (variables.length == 0) + return; + + for (IVariable var : variables) { + String identifier = var.getIdentifierString(); + ISCVariable scVar = scMachineRoot.getSCVariable(identifier); + + // might have been filtered out by previous modules + if (scVar.exists()) { + // original might not contain the attribute + if (var.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) { + String attribute = var + .getAttributeValue(UnitPragmaAttribute.ATTRIBUTE); + + attribute = UnitAttributeProcessorStatics + .translateEventBPragmaToBPragma(attribute); + + scVar.setAttributeValue(UnitPragmaAttribute.ATTRIBUTE, + attribute, monitor); + } + } + } + + } + + @Override + public IModuleType<?> getModuleType() { + return MODULE_TYPE; + } + +} diff --git a/de.prob.units/src/de/prob/units/sc/UnitAttributeProcessorStatics.java b/de.prob.units/src/de/prob/units/sc/UnitAttributeProcessorStatics.java new file mode 100644 index 0000000000000000000000000000000000000000..4e819dad2fc094f1ef109c66e8efe1e468a3fefc --- /dev/null +++ b/de.prob.units/src/de/prob/units/sc/UnitAttributeProcessorStatics.java @@ -0,0 +1,9 @@ +package de.prob.units.sc; + +public class UnitAttributeProcessorStatics { + static String translateEventBPragmaToBPragma(String eventBPragma) { + String bPragma = eventBPragma.replace("^", "**"); + return bPragma; + } + +} diff --git a/de.prob.units/src/de/prob/units/ui/StartUnitAnalysisHandler.java b/de.prob.units/src/de/prob/units/ui/StartUnitAnalysisHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..549a56f902eea225bcde5ba825cc6b74d69111e7 --- /dev/null +++ b/de.prob.units/src/de/prob/units/ui/StartUnitAnalysisHandler.java @@ -0,0 +1,384 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.units.ui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBRoot; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IVariable; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; +import org.rodinp.core.RodinMarkerUtil; + +import de.prob.core.Animator; +import de.prob.core.LimitedLogger; +import de.prob.core.command.ActivateUnitPluginCommand; +import de.prob.core.command.ClearMachineCommand; +import de.prob.core.command.CommandException; +import de.prob.core.command.ComposedCommand; +import de.prob.core.command.GetPluginResultCommand; +import de.prob.core.command.SetPreferencesCommand; +import de.prob.core.command.StartAnimationCommand; +import de.prob.core.command.internal.InternalLoadCommand; +import de.prob.exceptions.ProBException; +import de.prob.logging.Logger; +import de.prob.parser.BindingGenerator; +import de.prob.parser.ResultParserException; +import de.prob.prolog.term.CompoundPrologTerm; +import de.prob.prolog.term.ListPrologTerm; +import de.prob.prolog.term.PrologTerm; +import de.prob.units.pragmas.InferredUnitPragmaAttribute; +import de.prob.units.pragmas.UnitPragmaAttribute; +import de.prob.units.problems.IncorrectUnitDefinitionMarker; +import de.prob.units.problems.MultipleUnitsInferredMarker; +import de.prob.units.problems.NoUnitInferredMarker; + +public class StartUnitAnalysisHandler extends AbstractHandler implements + IHandler { + + public static class ModificationListener implements IResourceChangeListener { + + private final IPath path; + + public ModificationListener(final IFile resource) { + if (resource == null) { + path = null; + } else { + this.path = resource.getProject().getFullPath(); + } + } + + @Override + public void resourceChanged(final IResourceChangeEvent event) { + if (path != null) { + final IResourceDelta delta = event.getDelta(); + IResourceDelta member = delta.findMember(path); + if (member != null) { + Animator.getAnimator().setDirty(); + } + } + } + } + + private ISelection fSelection; + private ModificationListener listener; + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + + fSelection = HandlerUtil.getCurrentSelection(event); + + // Get the Selection + final IEventBRoot rootElement = getRootElement(); + final IFile resource = extractResource(rootElement); + + removeUnitErrorMarkers(resource); + + ArrayList<String> errors = new ArrayList<String>(); + boolean realError = checkErrorMarkers(resource, errors); + if (!errors.isEmpty()) { + String message = "Some components in your project contain " + + (realError ? "errors" : "warnings") + + ". This can lead to unexpected behavior (e.g. missing variables) when animating.\n\nDetails:\n"; + StringBuffer stringBuffer = new StringBuffer(message); + for (String string : errors) { + stringBuffer.append(string); + stringBuffer.append('\n'); + } + if (realError) + Logger.notifyUserWithoutBugreport(stringBuffer.toString()); + else + Logger.notifyUserAboutWarningWithoutBugreport(stringBuffer + .toString()); + } + ; + + if (resource != null) { + LimitedLogger.getLogger().log("user started unit analysis", + rootElement.getElementName(), null); + registerModificationListener(resource); + + final Animator animator = Animator.getAnimator(); + try { + // load machine and activate plugin + final ClearMachineCommand clear = new ClearMachineCommand(); + final SetPreferencesCommand setPrefs = SetPreferencesCommand + .createSetPreferencesCommand(animator); + final InternalLoadCommand load = new InternalLoadCommand( + rootElement); + final StartAnimationCommand start = new StartAnimationCommand(); + final ActivateUnitPluginCommand activatePlugin = new ActivateUnitPluginCommand(); + + GetPluginResultCommand pluginResultCommand = new GetPluginResultCommand( + "Grounded Result State"); + + final ComposedCommand composed = new ComposedCommand(clear, + setPrefs, load, start, activatePlugin, + pluginResultCommand); + + animator.execute(composed); + processResults(pluginResultCommand.getResult()); + } catch (ProBException e) { + e.notifyUserOnce(); + throw new ExecutionException("Unit Analysis Failed", e); + } catch (RodinDBException e) { + throw new ExecutionException( + "Unit Analysis Failed with a RodinDBException", e); + } + } + return null; + } + + private void removeUnitErrorMarkers(final IFile resource) { + IProject project = resource.getProject(); + try { + IMarker[] markers = project.findMarkers( + "org.eclipse.core.resources.problemmarker", true, + IResource.DEPTH_INFINITE); + for (IMarker iMarker : markers) { + if (iMarker.getAttribute(RodinMarkerUtil.ERROR_CODE, "") + .equals(MultipleUnitsInferredMarker.ERROR_CODE)) { + iMarker.delete(); + } + if (iMarker.getAttribute(RodinMarkerUtil.ERROR_CODE, "") + .equals(IncorrectUnitDefinitionMarker.ERROR_CODE)) { + iMarker.delete(); + } + if (iMarker.getAttribute(RodinMarkerUtil.ERROR_CODE, "") + .equals(NoUnitInferredMarker.ERROR_CODE)) { + iMarker.delete(); + } + } + + } catch (CoreException e1) { + } + } + + private boolean checkErrorMarkers(final IFile resource, List<String> errors) { + boolean result = false; + IProject project = resource.getProject(); + try { + IMarker[] markers = project.findMarkers( + "org.eclipse.core.resources.problemmarker", true, + IResource.DEPTH_INFINITE); + for (IMarker iMarker : markers) { + errors.add(iMarker.getResource().getName() + + ": " + + iMarker + .getAttribute(IMarker.MESSAGE, "unknown Error")); + result = result + || (Integer) iMarker.getAttribute(IMarker.SEVERITY) == IMarker.SEVERITY_ERROR; + } + + } catch (CoreException e1) { + } + return result; + } + + private void processResults(CompoundPrologTerm result) + throws RodinDBException, ExecutionException { + // preprocess the list into a map + Map<String, String> variables = new HashMap<String, String>(); + List<String> offendingDefinitions = new ArrayList<String>(); + + ListPrologTerm liste = BindingGenerator.getList(result.getArgument(1)); + + for (PrologTerm term : liste) { + if (term.isAtom()) { + // this is an error message. do something about it. + String offendingUnitDefinition = PrologTerm.atomicString(term) + .replace("Incorrect unit definition: ['", ""); + offendingUnitDefinition = offendingUnitDefinition.replace("']", + ""); + + // add error to the list of incorrect definitions. error markers + // will be attached later + offendingDefinitions.add(offendingUnitDefinition); + + } else { + // process inferred units and add to map + CompoundPrologTerm compoundTerm; + try { + compoundTerm = BindingGenerator.getCompoundTerm(term, + "bind", 2); + + variables.put(PrologTerm.atomicString(compoundTerm + .getArgument(1)), PrologTerm + .atomicString(compoundTerm.getArgument(2))); + } catch (ResultParserException e) { + CommandException commandException = new CommandException( + e.getLocalizedMessage(), e); + commandException.notifyUserOnce(); + } + } + } + + IEventBRoot rootElement = getRootElement(); + // look up the variables / constants of the selected machine in + // the state + // and set the inferredUnitPragma attribute + if (rootElement instanceof IMachineRoot) { + // find and update variables + IVariable[] allVariables = rootElement.getMachineRoot() + .getVariables(); + for (IVariable var : allVariables) { + // reset inferred unit + var.setAttributeValue(InferredUnitPragmaAttribute.ATTRIBUTE, + "", new NullProgressMonitor()); + + String variableName = var.getIdentifierString(); + if (variables.containsKey(variableName)) { + var.setAttributeValue( + InferredUnitPragmaAttribute.ATTRIBUTE, + variables.get(variableName), + new NullProgressMonitor()); + + if (variables.get(variableName).startsWith("multiple")) { + var.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new MultipleUnitsInferredMarker(variableName)); + } + if (variables.get(variableName).equals("unknown")) { + var.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new NoUnitInferredMarker(variableName)); + } + } + + // check if the attached unit pragma (given by user) was marked + // as offending + if (var.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) { + if (offendingDefinitions.contains(var + .getAttributeValue(UnitPragmaAttribute.ATTRIBUTE))) { + var.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new IncorrectUnitDefinitionMarker(variableName)); + } + } + } + + } else if (rootElement instanceof IContextRoot) { + // find and update constants + IConstant[] allConstants = rootElement.getContextRoot() + .getConstants(); + + for (IConstant cst : allConstants) { + // reset inferred unit + cst.setAttributeValue(InferredUnitPragmaAttribute.ATTRIBUTE, + "", new NullProgressMonitor()); + + String constantName = cst.getIdentifierString(); + if (variables.containsKey(constantName)) { + cst.setAttributeValue( + InferredUnitPragmaAttribute.ATTRIBUTE, + variables.get(constantName), + new NullProgressMonitor()); + + if (variables.get(constantName).equals("error")) { + cst.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new MultipleUnitsInferredMarker(constantName)); + } + if (variables.get(constantName).equals("unknown")) { + cst.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new IncorrectUnitDefinitionMarker(constantName)); + } + } + + // check if the attached unit pragma (given by user) was marked + // as offending + if (cst.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) { + if (offendingDefinitions.contains(cst + .getAttributeValue(UnitPragmaAttribute.ATTRIBUTE))) { + cst.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new MultipleUnitsInferredMarker(constantName)); + } + } + } + } else { + throw new ExecutionException( + "Cannot execute unit analysis on this element type. Type of " + + rootElement.getComponentName() + " was: " + + rootElement.getClass()); + } + } + + private IEventBRoot getRootElement() { + IEventBRoot root = null; + if (fSelection instanceof IStructuredSelection) { + final IStructuredSelection ssel = (IStructuredSelection) fSelection; + if (ssel.size() == 1) { + final Object element = ssel.getFirstElement(); + if (element instanceof IEventBRoot) { + root = (IEventBRoot) element; + } else if (element instanceof IFile) { + IRodinFile rodinFile = RodinCore.valueOf((IFile) element); + if (rodinFile != null) + root = (IEventBRoot) rodinFile.getRoot(); + } + } + } + return root; + } + + private IFile extractResource(final IEventBRoot rootElement) { + IFile resource = null; + if (rootElement == null) { + resource = null; + } else if (rootElement instanceof IMachineRoot) { + resource = ((IMachineRoot) rootElement).getSCMachineRoot() + .getResource(); + } else if (rootElement instanceof IContextRoot) { + resource = ((IContextRoot) rootElement).getSCContextRoot() + .getResource(); + } + return resource; + } + + private void registerModificationListener(final IFile resource) { + if (listener != null) { + ResourcesPlugin.getWorkspace().removeResourceChangeListener( + listener); + } + listener = new ModificationListener(resource); + ResourcesPlugin.getWorkspace().addResourceChangeListener(listener); + } + + public void selectionChanged(final IAction action, + final ISelection selection) { + fSelection = selection; + } + +} diff --git a/de.prob2.disprover.feature/.project b/de.prob2.disprover.feature/.project new file mode 100644 index 0000000000000000000000000000000000000000..2467f8882585ebfc9fe1bb5fdf5057156c8c9e5c --- /dev/null +++ b/de.prob2.disprover.feature/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob2.disprover.feature</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.pde.FeatureBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.FeatureNature</nature> + </natures> +</projectDescription> diff --git a/de.prob2.disprover.feature/build.properties b/de.prob2.disprover.feature/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..64f93a9f0b7328eb563aa5ad6cec7f828020e124 --- /dev/null +++ b/de.prob2.disprover.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/de.prob2.disprover.feature/feature.xml b/de.prob2.disprover.feature/feature.xml new file mode 100644 index 0000000000000000000000000000000000000000..84f31a898ba28ca93b5dfff7719ca48a4c0cb56f --- /dev/null +++ b/de.prob2.disprover.feature/feature.xml @@ -0,0 +1,257 @@ +<?xml version="1.0" encoding="UTF-8"?> +<feature + id="de.prob2.disprover.feature" + label="ProB for Rodin2 - EXPERIMENTAL (Dis)Prover" + version="2.4.1.qualifier" + provider-name="HHU Düsseldorf STUPS Group"> + + <description url="http://www.stups.uni-duesseldorf.de/ProB"> + ProB is an animator and model checker for the B-Method. It allows +fully automatic animation of many B specifications, and can be +used to systematically check a specification for errors. +Part of the research and development was conducted within the +EPSRC funded projects ABCD and iMoc, and within the EU funded +project Rodin. +Development is continued under the EU funded project Deploy and +the DFG project Gepavas. +ProB has been successfully used on various industrial specifications +and is now being used within Siemens. + </description> + + <copyright> + (C) 2000-2011 Michael Leuschel (and many others) All rights reserved. + </copyright> + + <license url="http://www.eclipse.org/org/documents/epl-v10.html"> + ProB can be used freely for commercial, non-commercial and academic +use under the Eclipse Public Licence v. 1.0. (below) +For availability of commercial support, please contact the author +(http://www.stups.uni-duesseldorf.de/~leuschel). +Use of ProB's nauty library for symmetry reduction implies further +restrictions (no applications with nontrivial military significance, +see http://cs.anu.edu.au/~bdm/nauty/). +--- +Eclipse Public License - v. 1.0 +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS +ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE +OF THIS AGREEMENT. +1. DEFINITIONS +"Contribution" means: +a) in the case of the initial Contributor, the initial code and +documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate +from and are distributed by that particular Contributor. A Contribution +'originates' from a Contributor if it was added to the Program +by such Contributor itself or anyone acting on such Contributor's +behalf. Contributions do not include additions to the Program +which: (i) are separate modules of software distributed in conjunction +with the Program under their own license agreement, and (ii) +are not derivative works of the Program. +"Contributor" means any person or entity that distributes the +Program. +"Licensed Patents" mean patent claims licensable by a Contributor +which are necessarily infringed by the use or sale of its Contribution +alone or when combined with the Program. +"Program" means the Contributions distributed in accordance with +this Agreement. +"Recipient" means anyone who receives the Program under this +Agreement, including all Contributors. +2. GRANT OF RIGHTS +a) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free copyright +license to reproduce, prepare derivative works of, publicly display, +publicly perform, distribute and sublicense the Contribution +of such Contributor, if any, and such derivative works, in source +code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free patent +license under Licensed Patents to make, use, sell, offer to sell, +import and otherwise transfer the Contribution of such Contributor, +if any, in source code and object code form. This patent license +shall apply to the combination of the Contribution and the Program +if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to +be covered by the Licensed Patents. The patent license shall +not apply to any other combinations which include the Contribution. +No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants +the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe +the patent or other intellectual property rights of any other +entity. Each Contributor disclaims any liability to Recipient +for claims brought by any other entity based on infringement +of intellectual property rights or otherwise. As a condition +to exercising the rights and licenses granted hereunder, each +Recipient hereby assumes sole responsibility to secure any other +intellectual property rights needed, if any. For example, if +a third party patent license is required to allow Recipient to +distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient +copyright rights in its Contribution, if any, to grant the copyright +license set forth in this Agreement. +3. REQUIREMENTS +A Contributor may choose to distribute the Program in object +code form under its own license agreement, provided that: +a) it complies with the terms and conditions of this Agreement; +and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties +and conditions, express and implied, including warranties or +conditions of title and non-infringement, and implied warranties +or conditions of merchantability and fitness for a particular +purpose; +ii) effectively excludes on behalf of all Contributors all liability +for damages, including direct, indirect, special, incidental +and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement +are offered by that Contributor alone and not by any other party; +and +iv) states that source code for the Program is available from +such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for +software exchange. +When the Program is made available in source code form: +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of +the Program. +Contributors may not remove or alter any copyright notices contained +within the Program. +Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution. +4. COMMERCIAL DISTRIBUTION +Commercial distributors of software may accept certain responsibilities +with respect to end users, business partners and the like. While +this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any +losses, damages and costs (collectively "Losses") arising from +claims, lawsuits and other legal actions brought by a third party +against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection +with its distribution of the Program in a commercial product +offering. The obligations in this section do not apply to any +claims or Losses relating to any actual or alleged intellectual +property infringement. In order to qualify, an Indemnified Contributor +must: a) promptly notify the Commercial Contributor in writing +of such claim, and b) allow the Commercial Contributor to control, +and cooperate with the Commercial Contributor in, the defense +and any related settlement negotiations. The Indemnified Contributor +may participate in any such claim at its own expense. +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have +to defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any +other Contributor to pay any damages as a result, the Commercial +Contributor must pay those damages. +5. NO WARRANTY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM +IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with +its exercise of rights under this Agreement , including but not +limited to the risks and costs of program errors, compliance +with applicable laws, damage to or loss of data, programs or +equipment, and unavailability or interruption of operations. +6. DISCLAIMER OF LIABILITY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE +OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGES. +7. GENERAL +If any provision of this Agreement is invalid or unenforceable +under applicable law, it shall not affect the validity or enforceability +of the remainder of the terms of this Agreement, and without +further action by the parties hereto, such provision shall be +reformed to the minimum extent necessary to make such provision +valid and enforceable. +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging +that the Program itself (excluding combinations of the Program +with other software or hardware) infringes such Recipient's patent(s), +then such Recipient's rights granted under Section 2(b) shall +terminate as of the date such litigation is filed. +All Recipient's rights under this Agreement shall terminate if +it fails to comply with any of the material terms or conditions +of this Agreement and does not cure such failure in a reasonable +period of time after becoming aware of such noncompliance. If +all Recipient's rights under this Agreement terminate, Recipient +agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient's obligations under +this Agreement and any licenses granted by Recipient relating +to the Program shall continue and survive. +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted +and may only be modified in the following manner. The Agreement +Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other +than the Agreement Steward has the right to modify this Agreement. +The Eclipse Foundation is the initial Agreement Steward. The +Eclipse Foundation may assign the responsibility to serve as +the Agreement Steward to a suitable separate entity. Each new +version of the Agreement will be given a distinguishing version +number. The Program (including Contributions) may always be distributed +subject to the version of the Agreement under which it was received. +In addition, after a new version of the Agreement is published, +Contributor may elect to distribute the Program (including its +Contributions) under the new version. Except as expressly stated +in Sections 2(a) and 2(b) above, Recipient receives no rights +or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under +this Agreement are reserved. +This Agreement is governed by the laws of the State of New York +and the intellectual property laws of the United States of America. +No party to this Agreement will bring a legal action under this +Agreement more than one year after the cause of action arose. +Each party waives its rights to a jury trial in any resulting +litigation. + </license> + + <requires> + <import plugin="org.eclipse.core.runtime" version="3.5.0" match="compatible"/> + <import plugin="de.prob.core" version="9.4.0" match="equivalent"/> + <import plugin="org.eventb.core" version="2.5.1" match="greaterOrEqual"/> + <import plugin="org.eclipse.ui" version="3.5.0" match="compatible"/> + <import plugin="de.prob.eventb.disprover.core" version="1.3.2" match="compatible"/> + <import plugin="org.eventb.pp.ui" version="0.2.1" match="greaterOrEqual"/> + <import plugin="org.eventb.core.seqprover" version="2.5.0" match="greaterOrEqual"/> + <import plugin="org.eventb.ui" version="2.5.0" match="compatible"/> + </requires> + + <plugin + id="de.prob.eventb.disprover.core" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="de.prob.eventb.disprover.ui" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + +</feature> diff --git a/de.prob2.feature/feature.xml b/de.prob2.feature/feature.xml index 23cc601c78975e5722e4c177c12239d4cc50c08e..64cacb78fbf007a53ea298e58af33561bf282459 100644 --- a/de.prob2.feature/feature.xml +++ b/de.prob2.feature/feature.xml @@ -2,7 +2,7 @@ <feature id="de.prob2.feature" label="ProB for Rodin2" - version="2.3.3.qualifier" + version="2.4.1.qualifier" provider-name="HHU Düsseldorf STUPS Group"> <description url="http://www.stups.uni-duesseldorf.de/ProB"> @@ -232,15 +232,15 @@ litigation. <import plugin="org.eclipse.jface.databinding" version="1.2.1" match="compatible"/> <import plugin="org.eclipse.core.databinding.beans" version="1.1.1" match="compatible"/> <import plugin="org.eclipse.gef" version="3.7.0" match="compatible"/> - <import plugin="org.eventb.core" version="2.1.0"/> - <import plugin="org.rodinp.core" version="1.3.1"/> + <import plugin="de.prob.core" version="9.4.0" match="equivalent"/> + <import plugin="org.eventb.core" version="2.5.0" match="greaterOrEqual"/> + <import plugin="org.eclipse.help" version="3.5.100" match="greaterOrEqual"/> + <import plugin="org.rodinp.core" version="1.3.1" match="greaterOrEqual"/> + <import plugin="de.prob.ui" version="7.4.0" match="equivalent"/> <import plugin="org.eclipse.core.resources" version="3.5.0" match="compatible"/> <import plugin="org.eclipse.core.expressions" version="3.4.101" match="compatible"/> - <import plugin="org.eclipse.gef" version="3.5.0" match="compatible"/> <import plugin="org.eclipse.ui.navigator" version="3.5.0" match="greaterOrEqual"/> - <import plugin="de.prob.core" version="9.3.0" match="equivalent"/> - <import plugin="de.prob.ui" version="7.3.0" match="equivalent"/> - <import plugin="de.bmotionstudio.gef.editor" version="5.4.0" match="equivalent"/> + <import plugin="de.bmotionstudio.gef.editor" version="5.5.0" match="equivalent"/> </requires> <plugin diff --git a/de.prob2.symbolic.feature/.project b/de.prob2.symbolic.feature/.project new file mode 100644 index 0000000000000000000000000000000000000000..d090f9a1a785437529313dd14ef3d7f00b633b2d --- /dev/null +++ b/de.prob2.symbolic.feature/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob2.symbolic.feature</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.pde.FeatureBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.FeatureNature</nature> + </natures> +</projectDescription> diff --git a/de.prob2.symbolic.feature/build.properties b/de.prob2.symbolic.feature/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..64f93a9f0b7328eb563aa5ad6cec7f828020e124 --- /dev/null +++ b/de.prob2.symbolic.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/de.prob2.symbolic.feature/feature.xml b/de.prob2.symbolic.feature/feature.xml new file mode 100644 index 0000000000000000000000000000000000000000..c94fe9221fef78ffca77edcbc49cc5e4a97eeaf3 --- /dev/null +++ b/de.prob2.symbolic.feature/feature.xml @@ -0,0 +1,246 @@ +<?xml version="1.0" encoding="UTF-8"?> +<feature + id="de.prob2.symbolic.feature" + label="ProB for Rodin2 - Symbolic Constants Support" + version="2.4.1.qualifier" + provider-name="HHU Düsseldorf STUPS Group"> + + <description url="http://www.stups.uni-duesseldorf.de/ProB"> + ProB is an animator and model checker for the B-Method. It allows +fully automatic animation of many B specifications, and can be +used to systematically check a specification for errors. +Part of the research and development was conducted within the +EPSRC funded projects ABCD and iMoc, and within the EU funded +project Rodin. +Development is continued under the EU funded project Deploy and +the DFG project Gepavas. +ProB has been successfully used on various industrial specifications +and is now being used within Siemens. + </description> + + <copyright> + (C) 2000-2011 Michael Leuschel (and many others) All rights reserved. + </copyright> + + <license url="http://www.eclipse.org/org/documents/epl-v10.html"> + ProB can be used freely for commercial, non-commercial and academic +use under the Eclipse Public Licence v. 1.0. (below) +For availability of commercial support, please contact the author +(http://www.stups.uni-duesseldorf.de/~leuschel). +Use of ProB's nauty library for symmetry reduction implies further +restrictions (no applications with nontrivial military significance, +see http://cs.anu.edu.au/~bdm/nauty/). +--- +Eclipse Public License - v. 1.0 +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS +ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE +OF THIS AGREEMENT. +1. DEFINITIONS +"Contribution" means: +a) in the case of the initial Contributor, the initial code and +documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate +from and are distributed by that particular Contributor. A Contribution +'originates' from a Contributor if it was added to the Program +by such Contributor itself or anyone acting on such Contributor's +behalf. Contributions do not include additions to the Program +which: (i) are separate modules of software distributed in conjunction +with the Program under their own license agreement, and (ii) +are not derivative works of the Program. +"Contributor" means any person or entity that distributes the +Program. +"Licensed Patents" mean patent claims licensable by a Contributor +which are necessarily infringed by the use or sale of its Contribution +alone or when combined with the Program. +"Program" means the Contributions distributed in accordance with +this Agreement. +"Recipient" means anyone who receives the Program under this +Agreement, including all Contributors. +2. GRANT OF RIGHTS +a) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free copyright +license to reproduce, prepare derivative works of, publicly display, +publicly perform, distribute and sublicense the Contribution +of such Contributor, if any, and such derivative works, in source +code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free patent +license under Licensed Patents to make, use, sell, offer to sell, +import and otherwise transfer the Contribution of such Contributor, +if any, in source code and object code form. This patent license +shall apply to the combination of the Contribution and the Program +if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to +be covered by the Licensed Patents. The patent license shall +not apply to any other combinations which include the Contribution. +No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants +the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe +the patent or other intellectual property rights of any other +entity. Each Contributor disclaims any liability to Recipient +for claims brought by any other entity based on infringement +of intellectual property rights or otherwise. As a condition +to exercising the rights and licenses granted hereunder, each +Recipient hereby assumes sole responsibility to secure any other +intellectual property rights needed, if any. For example, if +a third party patent license is required to allow Recipient to +distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient +copyright rights in its Contribution, if any, to grant the copyright +license set forth in this Agreement. +3. REQUIREMENTS +A Contributor may choose to distribute the Program in object +code form under its own license agreement, provided that: +a) it complies with the terms and conditions of this Agreement; +and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties +and conditions, express and implied, including warranties or +conditions of title and non-infringement, and implied warranties +or conditions of merchantability and fitness for a particular +purpose; +ii) effectively excludes on behalf of all Contributors all liability +for damages, including direct, indirect, special, incidental +and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement +are offered by that Contributor alone and not by any other party; +and +iv) states that source code for the Program is available from +such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for +software exchange. +When the Program is made available in source code form: +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of +the Program. +Contributors may not remove or alter any copyright notices contained +within the Program. +Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution. +4. COMMERCIAL DISTRIBUTION +Commercial distributors of software may accept certain responsibilities +with respect to end users, business partners and the like. While +this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any +losses, damages and costs (collectively "Losses") arising from +claims, lawsuits and other legal actions brought by a third party +against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection +with its distribution of the Program in a commercial product +offering. The obligations in this section do not apply to any +claims or Losses relating to any actual or alleged intellectual +property infringement. In order to qualify, an Indemnified Contributor +must: a) promptly notify the Commercial Contributor in writing +of such claim, and b) allow the Commercial Contributor to control, +and cooperate with the Commercial Contributor in, the defense +and any related settlement negotiations. The Indemnified Contributor +may participate in any such claim at its own expense. +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have +to defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any +other Contributor to pay any damages as a result, the Commercial +Contributor must pay those damages. +5. NO WARRANTY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM +IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with +its exercise of rights under this Agreement , including but not +limited to the risks and costs of program errors, compliance +with applicable laws, damage to or loss of data, programs or +equipment, and unavailability or interruption of operations. +6. DISCLAIMER OF LIABILITY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE +OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGES. +7. GENERAL +If any provision of this Agreement is invalid or unenforceable +under applicable law, it shall not affect the validity or enforceability +of the remainder of the terms of this Agreement, and without +further action by the parties hereto, such provision shall be +reformed to the minimum extent necessary to make such provision +valid and enforceable. +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging +that the Program itself (excluding combinations of the Program +with other software or hardware) infringes such Recipient's patent(s), +then such Recipient's rights granted under Section 2(b) shall +terminate as of the date such litigation is filed. +All Recipient's rights under this Agreement shall terminate if +it fails to comply with any of the material terms or conditions +of this Agreement and does not cure such failure in a reasonable +period of time after becoming aware of such noncompliance. If +all Recipient's rights under this Agreement terminate, Recipient +agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient's obligations under +this Agreement and any licenses granted by Recipient relating +to the Program shall continue and survive. +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted +and may only be modified in the following manner. The Agreement +Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other +than the Agreement Steward has the right to modify this Agreement. +The Eclipse Foundation is the initial Agreement Steward. The +Eclipse Foundation may assign the responsibility to serve as +the Agreement Steward to a suitable separate entity. Each new +version of the Agreement will be given a distinguishing version +number. The Program (including Contributions) may always be distributed +subject to the version of the Agreement under which it was received. +In addition, after a new version of the Agreement is published, +Contributor may elect to distribute the Program (including its +Contributions) under the new version. Except as expressly stated +in Sections 2(a) and 2(b) above, Recipient receives no rights +or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under +this Agreement are reserved. +This Agreement is governed by the laws of the State of New York +and the intellectual property laws of the United States of America. +No party to this Agreement will bring a legal action under this +Agreement more than one year after the cause of action arose. +Each party waives its rights to a jury trial in any resulting +litigation. + </license> + + <requires> + <import plugin="org.eclipse.core.runtime"/> + <import plugin="de.prob.core" version="9.4.0" match="equivalent"/> + <import plugin="org.eventb.ui" version="2.5.0" match="greaterOrEqual"/> + <import plugin="de.prob.ui" version="7.4.0" match="equivalent"/> + </requires> + + <plugin + id="de.prob.symbolic" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + +</feature> diff --git a/de.prob2.units.feature/.project b/de.prob2.units.feature/.project new file mode 100644 index 0000000000000000000000000000000000000000..96b7c78653fba0643a8efc26c06b6a3f61c66bd7 --- /dev/null +++ b/de.prob2.units.feature/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob2.units.feature</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.pde.FeatureBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.FeatureNature</nature> + </natures> +</projectDescription> diff --git a/de.prob2.units.feature/.settings/org.eclipse.core.resources.prefs b/de.prob2.units.feature/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000000000000000000000000000000000..ae8dfb5865c1107f8366e1e8c2af6ad2d1a7a9f1 --- /dev/null +++ b/de.prob2.units.feature/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Tue Nov 29 16:17:25 CET 2011 +eclipse.preferences.version=1 +encoding/<project>=UTF-8 diff --git a/de.prob2.units.feature/.settings/org.eclipse.core.runtime.prefs b/de.prob2.units.feature/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000000000000000000000000000000000000..57a8ae0b2a629cab658cebb8c79bd02f33f25fb0 --- /dev/null +++ b/de.prob2.units.feature/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,3 @@ +#Tue Nov 29 16:17:25 CET 2011 +eclipse.preferences.version=1 +line.separator=\n diff --git a/de.prob2.units.feature/build.properties b/de.prob2.units.feature/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..64f93a9f0b7328eb563aa5ad6cec7f828020e124 --- /dev/null +++ b/de.prob2.units.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/de.prob2.units.feature/feature.xml b/de.prob2.units.feature/feature.xml new file mode 100644 index 0000000000000000000000000000000000000000..b6b4ac34d0d4f2f4177872819a0c00e5f444c8e7 --- /dev/null +++ b/de.prob2.units.feature/feature.xml @@ -0,0 +1,240 @@ +<?xml version="1.0" encoding="UTF-8"?> +<feature + id="de.prob2.units.feature" + label="ProB for Rodin2 - Physical Units Support" + version="2.4.1.qualifier" + provider-name="HHU Düsseldorf STUPS Group"> + + <description url="http://www.stups.uni-duesseldorf.de/ProB"> + ProB is an animator and model checker for the B-Method. It allows fully automatic animation of many B specifications, and can be used to systematically check a specification for errors. +Part of the research and development was conducted within the EPSRC funded projects ABCD and iMoc, and within the EU funded project Rodin. +Development is continued under the EU funded project Deploy and the DFG project Gepavas. +ProB has been successfully used on various industrial specifications and is now being used within Siemens. + </description> + + <copyright> + (C) 2000-2011 Michael Leuschel (and many others) All rights reserved. + </copyright> + + <license url="http://www.eclipse.org/org/documents/epl-v10.html"> + ProB can be used freely for commercial, non-commercial and academic +use under the Eclipse Public Licence v. 1.0. (below) +For availability of commercial support, please contact the author +(http://www.stups.uni-duesseldorf.de/~leuschel). +Use of ProB's nauty library for symmetry reduction implies further +restrictions (no applications with nontrivial military significance, +see http://cs.anu.edu.au/~bdm/nauty/). +--- +Eclipse Public License - v. 1.0 +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS +ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE +OF THIS AGREEMENT. +1. DEFINITIONS +"Contribution" means: +a) in the case of the initial Contributor, the initial code and +documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate +from and are distributed by that particular Contributor. A Contribution +'originates' from a Contributor if it was added to the Program +by such Contributor itself or anyone acting on such Contributor's +behalf. Contributions do not include additions to the Program +which: (i) are separate modules of software distributed in conjunction +with the Program under their own license agreement, and (ii) +are not derivative works of the Program. +"Contributor" means any person or entity that distributes the +Program. +"Licensed Patents" mean patent claims licensable by a Contributor +which are necessarily infringed by the use or sale of its Contribution +alone or when combined with the Program. +"Program" means the Contributions distributed in accordance with +this Agreement. +"Recipient" means anyone who receives the Program under this +Agreement, including all Contributors. +2. GRANT OF RIGHTS +a) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free copyright +license to reproduce, prepare derivative works of, publicly display, +publicly perform, distribute and sublicense the Contribution +of such Contributor, if any, and such derivative works, in source +code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free patent +license under Licensed Patents to make, use, sell, offer to sell, +import and otherwise transfer the Contribution of such Contributor, +if any, in source code and object code form. This patent license +shall apply to the combination of the Contribution and the Program +if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to +be covered by the Licensed Patents. The patent license shall +not apply to any other combinations which include the Contribution. +No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants +the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe +the patent or other intellectual property rights of any other +entity. Each Contributor disclaims any liability to Recipient +for claims brought by any other entity based on infringement +of intellectual property rights or otherwise. As a condition +to exercising the rights and licenses granted hereunder, each +Recipient hereby assumes sole responsibility to secure any other +intellectual property rights needed, if any. For example, if +a third party patent license is required to allow Recipient to +distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient +copyright rights in its Contribution, if any, to grant the copyright +license set forth in this Agreement. +3. REQUIREMENTS +A Contributor may choose to distribute the Program in object +code form under its own license agreement, provided that: +a) it complies with the terms and conditions of this Agreement; +and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties +and conditions, express and implied, including warranties or +conditions of title and non-infringement, and implied warranties +or conditions of merchantability and fitness for a particular +purpose; +ii) effectively excludes on behalf of all Contributors all liability +for damages, including direct, indirect, special, incidental +and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement +are offered by that Contributor alone and not by any other party; +and +iv) states that source code for the Program is available from +such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for +software exchange. +When the Program is made available in source code form: +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of +the Program. +Contributors may not remove or alter any copyright notices contained +within the Program. +Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution. +4. COMMERCIAL DISTRIBUTION +Commercial distributors of software may accept certain responsibilities +with respect to end users, business partners and the like. While +this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any +losses, damages and costs (collectively "Losses") arising from +claims, lawsuits and other legal actions brought by a third party +against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection +with its distribution of the Program in a commercial product +offering. The obligations in this section do not apply to any +claims or Losses relating to any actual or alleged intellectual +property infringement. In order to qualify, an Indemnified Contributor +must: a) promptly notify the Commercial Contributor in writing +of such claim, and b) allow the Commercial Contributor to control, +and cooperate with the Commercial Contributor in, the defense +and any related settlement negotiations. The Indemnified Contributor +may participate in any such claim at its own expense. +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have +to defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any +other Contributor to pay any damages as a result, the Commercial +Contributor must pay those damages. +5. NO WARRANTY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM +IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with +its exercise of rights under this Agreement , including but not +limited to the risks and costs of program errors, compliance +with applicable laws, damage to or loss of data, programs or +equipment, and unavailability or interruption of operations. +6. DISCLAIMER OF LIABILITY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE +OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGES. +7. GENERAL +If any provision of this Agreement is invalid or unenforceable +under applicable law, it shall not affect the validity or enforceability +of the remainder of the terms of this Agreement, and without +further action by the parties hereto, such provision shall be +reformed to the minimum extent necessary to make such provision +valid and enforceable. +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging +that the Program itself (excluding combinations of the Program +with other software or hardware) infringes such Recipient's patent(s), +then such Recipient's rights granted under Section 2(b) shall +terminate as of the date such litigation is filed. +All Recipient's rights under this Agreement shall terminate if +it fails to comply with any of the material terms or conditions +of this Agreement and does not cure such failure in a reasonable +period of time after becoming aware of such noncompliance. If +all Recipient's rights under this Agreement terminate, Recipient +agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient's obligations under +this Agreement and any licenses granted by Recipient relating +to the Program shall continue and survive. +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted +and may only be modified in the following manner. The Agreement +Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other +than the Agreement Steward has the right to modify this Agreement. +The Eclipse Foundation is the initial Agreement Steward. The +Eclipse Foundation may assign the responsibility to serve as +the Agreement Steward to a suitable separate entity. Each new +version of the Agreement will be given a distinguishing version +number. The Program (including Contributions) may always be distributed +subject to the version of the Agreement under which it was received. +In addition, after a new version of the Agreement is published, +Contributor may elect to distribute the Program (including its +Contributions) under the new version. Except as expressly stated +in Sections 2(a) and 2(b) above, Recipient receives no rights +or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under +this Agreement are reserved. +This Agreement is governed by the laws of the State of New York +and the intellectual property laws of the United States of America. +No party to this Agreement will bring a legal action under this +Agreement more than one year after the cause of action arose. +Each party waives its rights to a jury trial in any resulting +litigation. + </license> + + <requires> + <import plugin="org.eclipse.core.runtime"/> + <import plugin="de.prob.core" version="9.4.0" match="equivalent"/> + <import plugin="org.eventb.ui" version="2.5.0" match="greaterOrEqual"/> + <import plugin="de.prob.ui" version="7.4.0" match="equivalent"/> + </requires> + + <plugin + id="de.prob.units" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + +</feature> diff --git a/settings.gradle b/settings.gradle index bb2187c38344f1fac923b7dee971552ee4cdd523..f535bfe6f5dcca7000b1a0a26221e41fe62a90e6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ - -include 'de.prob.core', 'de.bmotionstudio.gef.editor' ,'de.bmotionstudio.rodin', 'de.bmotionstudio.help' , 'de.prob.plugin', 'de.prob.ui', 'de.prob2.feature' +include 'de.prob.core', 'de.bmotionstudio.gef.editor' ,'de.bmotionstudio.rodin', 'de.bmotionstudio.help' , 'de.prob.plugin', 'de.prob.ui', 'de.prob2.feature', 'de.prob.symbolic', 'de.prob2.symbolic.feature', 'de.prob.units', 'de.prob2.units.feature', 'de.prob.eventb.disprover.core', 'de.prob.eventb.disprover.ui', 'de.prob2.disprover.feature' diff --git a/tycho_build.gradle b/tycho_build.gradle index 6ecc2f2214b82fd47e6a3cbd62cdc5b634b9009c..5bd04a1ca6a7faf7541ab59130a486eb39885794 100644 --- a/tycho_build.gradle +++ b/tycho_build.gradle @@ -1,3 +1,4 @@ +import org.apache.tools.ant.taskdefs.condition.Os /* Build Script can be executed via 'gradle install' Build Script Dependencies can be downloaded via 'gradle collectDepenencies' @@ -13,20 +14,32 @@ apply plugin: 'base' import groovy.io.FileType -tychoVersion = "0.14.1" +project.ext.tychoVersion = "0.15.0" + +try{ + excludeFromTychoBuild = excludeFromTychoBuild +}catch(MissingPropertyException e){ + project.ext.excludeFromTychoBuild = [] +} + +try{ + excludeFromClassPath = excludeFromClassPath +}catch(MissingPropertyException e){ + project.ext.excludeFromClassPath = [] +} try{ workspacePath = workspacePath }catch(MissingPropertyException e){ - workspacePath = "" + project.ext.workspacePath = "" } try{ dependencyFolder = dependencyFolder }catch(MissingPropertyException e){ - dependencyFolder = "lib/dependencies/" // Folder in each subproject where + project.ext.dependencyFolder = "lib/dependencies/" // Folder in each subproject where } try{ @@ -47,8 +60,8 @@ try{ } - groupID = "group" - for( i = 0; i < folderNames.size(); i++ ){ + project.ext.groupID = "group" + for( int i = 0; i < folderNames.size(); i++ ){ if( folderNames[i] ==~ /.*\.[rR]eleng/ ){ groupID = folderNames[i] @@ -64,8 +77,8 @@ try{ features = features }catch(MissingPropertyException e){ - features = [] - for( i = 0; i < subprojects.name.size(); i++ ){ + project.ext.features = [] + for( int i = 0; i < subprojects.name.size(); i++ ){ if( subprojects.name[i] ==~ /.*\.[fF]eature/ ){ features.add( subprojects.name[i] ) } @@ -77,13 +90,13 @@ try{ try{ repositoryName = repositoryName }catch(MissingPropertyException e){ - repositoryName = groupID+".repository" + project.ext.repositoryName = groupID+".repository" } try{ parentID = parentID }catch(MissingPropertyException e){ - parentID = groupID+".parent" + project.ext.parentID = groupID+".parent" } Boolean noDescriptions = false // in case of using own CategoryDescription Map @@ -91,21 +104,21 @@ Boolean noDescriptions = false // in case of using own CategoryDescription M try{ categoryDescriptions = categoryDescriptions }catch(MissingPropertyException e){ - categoryDescriptions = [ [:],[:] ] // label and descriptions of the features + project.ext.categoryDescriptions = [ [:],[:] ] // label and descriptions of the features noDescriptions = true } // categoryDescriptions = [["feature": "labelName","feature2": "label"],["feature": "featureDescription","feature2": "feature2Description"]] // label and descriptions of the features try{ targetRepositories = targetRepositories }catch(MissingPropertyException e){ - targetRepositories = ["http://download.eclipse.org/releases/indigo/"] + project.ext.targetRepositories = ["http://download.eclipse.org/releases/indigo/"] } try{ buildProduct = buildProduct }catch(MissingPropertyException e){ - buildProduct = false + project.ext.buildProduct = false } @@ -307,6 +320,7 @@ subprojects { task collectDependencies(type: Copy) { from configurations.compile + from configurations.runtime into "${dependencyFolder}" @@ -315,32 +329,32 @@ subprojects { task setClassPath(dependsOn: 'collectDependencies')<<{ description = "\tAdds all your Dependencies from your local lib folder in each project to it's classpath" - //if(project.name ==~ /birkhoff.bundle.*/){ - def dependencyList = [] - try{ - def dir = new File(workspacePath+project.name+"/"+dependencyFolder).eachFile() { file-> - if( !(file.getName() ==~/.*\.txt/) ){ - dependencyList << file.getName() + if( excludeFromClassPath.every{ it != project.name }){ + def dependencyList = [] + try{ + def dir = new File(workspacePath+project.name+"/"+dependencyFolder).eachFile() { file-> + if( !(file.getName() ==~/.*\.txt/) ){ + dependencyList << file.getName() + } } - } - if(features.every{ it != project.name }){ - boolean BundleClassPathPresent = checkForRunTimeLibs(project.name) - for(int icp = 0; icp < dependencyList.size; icp++){ - addLibToCP(project.name, dependencyList[icp]) //Adds Lib to .classPath file + if(features.every{ it != project.name }){ + boolean BundleClassPathPresent = checkForRunTimeLibs(project.name) + for(int icp = 0; icp < dependencyList.size; icp++){ + addLibToCP(project.name, dependencyList[icp]) //Adds Lib to .classPath file - if(!BundleClassPathPresent){ // Adds Lib to Manifest File - createRunTimeLib(dependencyList[icp], project.name) - BundleClassPathPresent = true - }else{ - if(!checkRunTimeLib(dependencyList[icp], project.name)){ // if library not present add it to RunTimeLibrary - addRunTimeLib( dependencyList[icp], project.name) + if(!BundleClassPathPresent){ // Adds Lib to Manifest File + createRunTimeLib(dependencyList[icp], project.name) + BundleClassPathPresent = true + }else{ + if(!checkRunTimeLib(dependencyList[icp], project.name)){ // if library not present add it to RunTimeLibrary + addRunTimeLib( dependencyList[icp], project.name) + } } } - } - /*dependencyList.each{ dep-> + /*dependencyList.each{ dep-> println project.name+": "+ dep // could still be usefull for debugging, that's why it's not deleted - }*/ + }*/ } def warningReadMe = new File(workspacePath+project.name+"/"+dependencyFolder+"_README.txt") warningReadMe.delete() @@ -349,10 +363,10 @@ subprojects { warningReadMe << "If any error concerning missing dependencies should occur please run 'gradle deleteFromClassPath setClassPath' in your workspace folder from your shell." - }catch(Exception e){ - println project.name+" has no dependencies in '${dependencyFolder}' defined: Classpath will not be changed" - } - //}// if projectAbfrage + }catch(Exception e){ + println project.name+" has no dependencies in '${dependencyFolder}' defined: Classpath will not be changed" + } + }// if exclude projectAbfrage }// setClassPath @@ -399,9 +413,9 @@ subprojects { if(features.every{ it != project.name }){ // Generating Poms for sub projects except features - content = new File(workspacePath+"${project.name}/META-INF/MANIFEST.MF").getText("UTF-8") + def content = new File(workspacePath+"${project.name}/META-INF/MANIFEST.MF").getText("UTF-8") - printFileLine = { + def printFileLine = { if( it ==~ /Bundle-Version.+qualifier/ ){ versionNumber = it.substring(16) // possibile error: cuts off first 16 chars @@ -490,7 +504,11 @@ task createParent() << { f << endRepos() f << moduleStart() for(int i = 0; i < numberOfProjects(); i++){ - f << module(projects(i)) + + if( excludeFromTychoBuild.every{ it != projects(i) } ){ + + f << module(projects(i)) + } } f << module(repositoryName) f << endParent() @@ -556,6 +574,11 @@ task completeInstall(dependsOn: [subprojects.collectDependencies, createPoms], t commandLine 'mvn', 'install', '-f', workspacePath+parentID+'/pom.xml' } +task tycho(dependsOn: [createPoms] , type:Exec) { + description = "\tExecutes a 'mvn install' of the parent pom.xml and auto-generates Tycho Poms" + commandLine 'mvn', 'install', '-f', workspacePath+parentID+'/pom.xml' +} + //--- Defining Tycho POM parts --// @@ -565,14 +588,48 @@ task completeInstall(dependsOn: [subprojects.collectDependencies, createPoms], t <artifactId>${artifactId}</artifactId> <version>${versionNumber}</version> <packaging>eclipse-plugin</packaging> + <build> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-compiler-plugin</artifactId> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + </plugins> + </build> """ } def testArtifact(artifactId,versionNumber) { """ - <groupId>${groupId()}</groupId> - <artifactId>${artifactId}</artifactId> - <version>${versionNumber}</version> - <packaging>eclipse-test-plugin</packaging> - """ } + <groupId>${groupId()}</groupId> + <artifactId>${artifactId}</artifactId> + <version>${versionNumber}</version> + <packaging>eclipse-test-plugin</packaging> + <build> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-surefire-plugin</artifactId> + <configuration> + <!-- <useUIHarness>true</useUIHarness> --> + <!-- <useUIThread>true</useUIThread> --> + ${macTestArguments()} + <!-- <product>org.rodinp.platform.product</product> --> + </configuration> + </plugin> + </plugins> + </build> + """ } + + String macTestArguments() { + if ( Os.isFamily(Os.FAMILY_MAC) ){ + return "<argLine>-XstartOnFirstThread</argLine>\n" + }else{ + return "\n" + } + } def start() { """<?xml version="1.0" encoding="UTF-8"?>