diff --git a/org.eventb.texttools/META-INF/MANIFEST.MF b/org.eventb.texttools/META-INF/MANIFEST.MF index a0de626434281ec0d88b6c97ce69b6cc62082612..4d56e433bec0004b243699b0f94ae344082ebd41 100644 --- a/org.eventb.texttools/META-INF/MANIFEST.MF +++ b/org.eventb.texttools/META-INF/MANIFEST.MF @@ -15,11 +15,13 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,3.6.0)", org.eclipse.emf.compare.match;bundle-version="[1.0.0,2.0.0)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.eventb.texttools, +Export-Package: de.be4.eventb.core.parser.node, + org.eventb.texttools, org.eventb.texttools.formulas, org.eventb.texttools.merge, org.eventb.texttools.model.texttools, - org.eventb.texttools.prettyprint + org.eventb.texttools.prettyprint, + org.eventb.texttools.syntaxExtension Bundle-ClassPath: lib/aspectjrt.jar, lib/EventBParser.jar, . diff --git a/org.eventb.texttools/plugin.xml b/org.eventb.texttools/plugin.xml index 13948a526b0994f470a45b011f783b32239bbcf1..3ac6d0ab0b634c42f7a32624209841f59786bcbe 100644 --- a/org.eventb.texttools/plugin.xml +++ b/org.eventb.texttools/plugin.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <plugin> + <extension-point id="org.eventb.texttools.syntaxExtension" name="syntaxExtension" schema="schema/org.eventb.texttools.syntaxExtension.exsd"/> <extension point="org.rodinp.core.attributeTypes"> <attributeType @@ -13,6 +14,11 @@ kind="long" name="Text LastModified"> </attributeType> + <attributeType + id="syntax_extensions" + kind="string" + name="syntaxExtensions"> + </attributeType> </extension> <extension point="org.eclipse.emf.compare.match.engine"> diff --git a/org.eventb.texttools/schema/org.eventb.texttools.syntaxExtension.exsd b/org.eventb.texttools/schema/org.eventb.texttools.syntaxExtension.exsd new file mode 100644 index 0000000000000000000000000000000000000000..2863a58a87c2de04b1c60b7dd60b1b9b6bc50dd3 --- /dev/null +++ b/org.eventb.texttools/schema/org.eventb.texttools.syntaxExtension.exsd @@ -0,0 +1,123 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eventb.texttools" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eventb.texttools" id="org.eventb.texttools.syntaxExtension" name="syntaxExtension"/> + </appInfo> + <documentation> + [Enter description of this extension point.] + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence minOccurs="1" maxOccurs="unbounded"> + <element ref="syntaxExtension"/> + </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="syntaxExtension"> + <complexType> + <attribute name="name" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string" use="required"> + <annotation> + <documentation> + This is the id used in the <code>uses</code>-statements. + </documentation> + </annotation> + </attribute> + <attribute name="defaultKeyword" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="parserClass" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eventb.texttools.syntaxExtension.ISyntaxExtension"/> + </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/org.eventb.texttools/src/org/eventb/texttools/Parser.java b/org.eventb.texttools/src/org/eventb/texttools/Parser.java index 0513888e2a0688d09cf5a2ee839d751522c9c5ca..a5f2eca8d376541785896f95789a03650426de87 100644 --- a/org.eventb.texttools/src/org/eventb/texttools/Parser.java +++ b/org.eventb.texttools/src/org/eventb/texttools/Parser.java @@ -8,6 +8,7 @@ package org.eventb.texttools; import org.eclipse.jface.text.IDocument; import org.eventb.emf.core.EventBObject; +import org.eventb.texttools.extensions.ExtendedEventB; import org.eventb.texttools.internal.parsing.TransformationVisitor; import de.be4.eventb.core.parser.BException; @@ -21,9 +22,13 @@ import de.hhu.stups.sablecc.patch.SourcePositions; import de.hhu.stups.sablecc.patch.SourcecodeRange; public class Parser { + + private final Boolean allowSynatxExtensions = false; + private final EventBParser parser = new EventBParser(); private final TransformationVisitor transformer = new TransformationVisitor(); - + + /** * Parses the content of the given {@link IDocument}. * @@ -37,16 +42,33 @@ public class Parser { */ public <T extends EventBObject> T parse(final IDocument document) throws ParseException { + if (document == null) { throw new IllegalArgumentException( "Parser may not be called without input document"); } - final String input = document.get(); + + String input; + ExtendedEventB extendedEventB = null; + if (allowSynatxExtensions){ + extendedEventB = ExtendedEventB.createFromInput(document.get()); + input = extendedEventB.getPlainEventBCode(); + }else{ + input = document.get(); + } + try { final Start rootNode = parser.parse(input, false); - return transformer.<T>transform(rootNode, document); + T transform = transformer.<T>transform(rootNode, document); + + if (allowSynatxExtensions && extendedEventB != null){ + extendedEventB.assignElements((EventBObject)transform); + extendedEventB.runSyntaxExtensions(); + } + + return transform; } catch (final BException e) { final Exception cause = e.getCause(); diff --git a/org.eventb.texttools/src/org/eventb/texttools/PersistenceHelper.java b/org.eventb.texttools/src/org/eventb/texttools/PersistenceHelper.java index e1a16f87ee1196038dd4825cd3b111d19ae4b1b8..92260bdcbeb5446a6b3263603ec54dbc53791d77 100644 --- a/org.eventb.texttools/src/org/eventb/texttools/PersistenceHelper.java +++ b/org.eventb.texttools/src/org/eventb/texttools/PersistenceHelper.java @@ -31,6 +31,8 @@ import org.eventb.texttools.prettyprint.PrettyPrinter; public class PersistenceHelper { + public static final Boolean DEBUG = false; + public static IResource getIResource(final Resource resource) { final URI uri = resource.getURI(); if (uri.isPlatformResource()) { @@ -99,12 +101,35 @@ public class PersistenceHelper { } timeAttribute.setValue(timeStamp); } + + + public static void addUsesAnnotation(final EventBElement element, + final String usesStatements) { + final EMap<String, Attribute> attributes = element.getAttributes(); + Attribute usesAttribute = attributes.get(TextToolsPlugin.TYPE_USESEXTENSION.getId()); + if (usesAttribute == null) { + usesAttribute = CoreFactory.eINSTANCE.createAttribute(); + usesAttribute.setType(AttributeType.STRING); + attributes.put(TextToolsPlugin.TYPE_USESEXTENSION.getId(), + usesAttribute); + } + usesAttribute.setValue(usesStatements); + + } + private static void mergeComponents(final EventBNamedCommentedComponentElement oldVersion, final EventBNamedCommentedComponentElement newVersion, final IProgressMonitor monitor) { try { + long time0 = System.currentTimeMillis(); final ModelMerge merge = new ModelMerge(oldVersion, newVersion); + long time1 = System.currentTimeMillis(); merge.applyChanges(monitor); + long time2 = System.currentTimeMillis(); + if (DEBUG){ + System.out.println("new ModelMerge: " + (time1-time0)); + System.out.println("merge.applyChanges: " + (time2-time1)); + } } catch (final InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -115,7 +140,14 @@ public class PersistenceHelper { final EventBNamedCommentedComponentElement newVersion, final IProgressMonitor monitor) { final EventBNamedCommentedComponentElement component = getComponent(resource); if (component != null) { + // FIXME Hier stimmt die Reihenfolge noch + long start = System.currentTimeMillis(); mergeComponents(component, newVersion, monitor); + long end = System.currentTimeMillis(); + if (DEBUG){ + System.out.println("Time to merge components: " + (end-start)); + } + // Hier stimmt die Reihenfolge in component nicht mehr } else { resource.getContents().add(newVersion); } diff --git a/org.eventb.texttools/src/org/eventb/texttools/TextToolsPlugin.java b/org.eventb.texttools/src/org/eventb/texttools/TextToolsPlugin.java index 93e59682ad8d5882f2e8639c61dfcb4f28f1f018..066686a0314ae87c7b34d2bede65b9ad60a5e9e1 100644 --- a/org.eventb.texttools/src/org/eventb/texttools/TextToolsPlugin.java +++ b/org.eventb.texttools/src/org/eventb/texttools/TextToolsPlugin.java @@ -23,7 +23,9 @@ public class TextToolsPlugin extends Plugin { .getStringAttrType(PLUGIN_ID + ".text_representation"); public static final IAttributeType.Long TYPE_LASTMODIFIED = RodinCore .getLongAttrType(PLUGIN_ID + ".text_lastmodified"); - + public static final IAttributeType.String TYPE_USESEXTENSION = RodinCore + .getStringAttrType(PLUGIN_ID + ".syntax_extensions"); + // The shared instance private static TextToolsPlugin plugin; diff --git a/org.eventb.texttools/src/org/eventb/texttools/merge/ModelMerge.java b/org.eventb.texttools/src/org/eventb/texttools/merge/ModelMerge.java index 27852e6274324c37dcab75b2999b21c0fea311d9..afa99eb401e13938e598f1b3e5887845db7b53c5 100644 --- a/org.eventb.texttools/src/org/eventb/texttools/merge/ModelMerge.java +++ b/org.eventb.texttools/src/org/eventb/texttools/merge/ModelMerge.java @@ -113,23 +113,39 @@ public class ModelMerge { matchOptions.put(MatchOptions.OPTION_PROGRESS_MONITOR, subMonitor .newChild(1)); + + long timeStart = System.currentTimeMillis(); + final MatchModel matchModel = matchEngine.contentMatch(oldVersion, newVersion, matchOptions); - + + long timeMatch = System.currentTimeMillis(); + final DiffModel diff = getDiffModel(matchModel, subMonitor.newChild(2)); + + long timeDiff = System.currentTimeMillis(); + final EList<DiffElement> ownedElements = diff.getOwnedElements(); - + if (ownedElements.size() > 0) { // MergeService // .merge(new ArrayList<DiffElement>(ownedElements), false); - MergeService.merge(ownedElements, false); matchOptions.put(MatchOptions.OPTION_PROGRESS_MONITOR, subMonitor .newChild(1)); subMonitor.worked(1); } - + long timeMerge = System.currentTimeMillis(); + + if (PersistenceHelper.DEBUG){ + System.out.println("*** applyChanges() ****"); + System.out.println(" contentMatch: " + (timeMatch-timeStart)); + System.out.println(" getDiffModel: " + (timeDiff-timeMatch)); + System.out.println(" merge: " + (timeMerge-timeDiff)); + System.out.println(); + } + // cleanup tmp files EcoreUtil.remove(newVersion); if (tmpFileNew != null) { diff --git a/org.eventb.texttools/src/org/eventb/texttools/syntaxExtension/ISyntaxExtension.java b/org.eventb.texttools/src/org/eventb/texttools/syntaxExtension/ISyntaxExtension.java new file mode 100644 index 0000000000000000000000000000000000000000..dce14b0aa9a0b1a1ad9a410a1fbded2b5d54726d --- /dev/null +++ b/org.eventb.texttools/src/org/eventb/texttools/syntaxExtension/ISyntaxExtension.java @@ -0,0 +1,18 @@ +package org.eventb.texttools.syntaxExtension; + +import org.eventb.emf.core.EventBObject; + +public interface ISyntaxExtension { + + void setConcreteKeyword(String keyword, String extensionId); + + /** + * + * @param extensionId The extension-id this block is bound to + * @param text The text that has to be parsed + * @param root The Event-B root element i.e. machine or context + * @param element The surrounding Event-B element e.g. an event + */ + void parse(String extensionId, String text, EventBObject root, EventBObject element); + +}