diff options
author | Jeremie Tatibouet | 2015-03-24 13:15:15 +0000 |
---|---|---|
committer | Camille Letavernier | 2015-03-24 13:19:29 +0000 |
commit | 246b5ad5b70a9d974448ec9c2dfd8fdfe10553e2 (patch) | |
tree | 3fafa30290597619ed71bc13fafad1eb8d5f5bb1 /extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text | |
parent | def2c21b7ea8a1529fa6b06a96dd1a30ddc4f6da (diff) | |
download | org.eclipse.papyrus-246b5ad5b70a9d974448ec9c2dfd8fdfe10553e2.tar.gz org.eclipse.papyrus-246b5ad5b70a9d974448ec9c2dfd8fdfe10553e2.tar.xz org.eclipse.papyrus-246b5ad5b70a9d974448ec9c2dfd8fdfe10553e2.zip |
462954: [ALF] Integrate the new ALF grammar & tooling
https://bugs.eclipse.org/bugs/show_bug.cgi?id=462954
- Squash the committers/cletavernie/alf-integration branch
Also-by: Ed Seidewitz <ed-s@modeldriven.com>
Also-by: Arnaud Cuccuru <arnaud.cuccuru@cea.fr>
Signed-off-by: Jeremie Tatibouet <jeremie.tatibouet@cea.fr>
Diffstat (limited to 'extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text')
23 files changed, 1349 insertions, 0 deletions
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.classpath b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.classpath new file mode 100644 index 00000000000..b1dabee3829 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.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.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.project b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.project new file mode 100644 index 00000000000..116c74ef06e --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.uml.alf.text</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/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.settings/org.eclipse.jdt.core.prefs b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..11f6e462df7 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/.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.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/META-INF/MANIFEST.MF b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..2d00c973c03 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: org.eclipse.papyrus.uml.alf.text +Bundle-SymbolicName: org.eclipse.papyrus.uml.alf.text +Bundle-Version: 1.1.0.qualifier +Bundle-Activator: org.eclipse.papyrus.uml.alf.text.ActivatorText +Bundle-Vendor: %providerName +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.uml2.uml, + org.eclipse.papyrus.uml.alf, + org.eclipse.papyrus.uml.alf.libraries, + org.eclipse.compare, + org.eclipse.gmf.runtime.common.core, + org.eclipse.swt, + org.eclipse.compare.core, + org.eclipse.papyrus.infra.core.log +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.papyrus.uml.alf.text.generation, + org.eclipse.papyrus.uml.alf.text.merge.manual, + org.eclipse.papyrus.uml.alf.text.representation, + org.eclipse.papyrus.uml.alf.text.representation.util diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/about.html b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/about.html new file mode 100644 index 00000000000..209103075a7 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>November 14, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
\ No newline at end of file diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/build.properties b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/build.properties new file mode 100644 index 00000000000..785a40c0ec7 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/build.properties @@ -0,0 +1,6 @@ +source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html
+src.includes = about.html
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/pom.xml b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/pom.xml new file mode 100644 index 00000000000..a1e4f5b5532 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/pom.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.papyrus</artifactId> + <groupId>org.eclipse.papyrus</groupId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../../../../releng/top-pom-extras.xml</relativePath> + </parent> + <artifactId>org.eclipse.papyrus.uml.alf.text</artifactId> + <groupId>org.eclipse.papyrus</groupId> + <version>1.1.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> +</project>
\ No newline at end of file diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/ActivatorText.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/ActivatorText.java new file mode 100644 index 00000000000..c9089ee5ab1 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/ActivatorText.java @@ -0,0 +1,67 @@ +package org.eclipse.papyrus.uml.alf.text;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.papyrus.uml.alf.AlfRuntimeModule;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ActivatorText extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.alf.text"; //$NON-NLS-1$
+
+ // The shared instance
+ private static ActivatorText plugin;
+
+ private Injector injector;
+
+ public static LogHelper logger;
+
+ /**
+ * The constructor
+ */
+ public ActivatorText() {
+ }
+
+ /*
+ * (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;
+ this.injector = Guice.createInjector(new AlfRuntimeModule());
+ logger = new LogHelper(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);
+ logger = null;
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static ActivatorText getDefault() {
+ return plugin;
+ }
+
+ public Injector getInjector() {
+ return this.injector;
+ }
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/generation/DefaultEditStringRetrievalStrategy.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/generation/DefaultEditStringRetrievalStrategy.java new file mode 100644 index 00000000000..85ad34e43bb --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/generation/DefaultEditStringRetrievalStrategy.java @@ -0,0 +1,121 @@ +package org.eclipse.papyrus.uml.alf.text.generation;
+
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST);
+ *****************************************************************************/
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.uml.alf.Member;
+import org.eclipse.papyrus.uml.alf.PropertyDefinition;
+import org.eclipse.papyrus.uml.alf.text.ActivatorText;
+import org.eclipse.papyrus.uml.alf.text.representation.AlfTextualRepresentation;
+import org.eclipse.papyrus.uml.alf.text.representation.util.RepresentationParser;
+import org.eclipse.papyrus.uml.alf.text.representation.util.RepresentationParsingError;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.xtext.resource.SaveOptions;
+import org.eclipse.xtext.serializer.ISerializer;
+
+public class DefaultEditStringRetrievalStrategy extends EditStringRetrievalStrategy {
+
+ /**
+ * The serializer associated to the ALF grammar
+ */
+ private ISerializer serializer;
+
+ public DefaultEditStringRetrievalStrategy() {
+ this.serializer = ActivatorText.getDefault().getInjector().getInstance(ISerializer.class);
+ }
+
+ /**
+ * Return the textual representation associated to a given model element
+ *
+ * @param element
+ * - the element for which the textual representation is computed
+ * @return generated - the textual representation computed for this element
+ */
+ public String getGeneratedEditString(Element element) {
+ String generated = "";
+ Resource alfModel = this.getAlfModel((NamedElement) element);
+ if (this.serializer != null) {
+ EObject serializationTarget = null;
+ if (element instanceof Property) {
+ serializationTarget = this.getPropertyDefinition((Property) element, alfModel);
+ } else {
+ serializationTarget = alfModel.getContents().get(0);
+ }
+ generated = this.serializer.serialize(serializationTarget, SaveOptions.newBuilder().noValidation().getOptions());
+ }
+ return generated;
+ }
+
+ /**
+ * When opened the editor retrieve the based string on which the user is going to work.
+ * There are two possibilities:
+ * 1 - The element already has a textual representation associated. Then the return string is the registered representation
+ * 2 - The element does not have an associated textual representation. Then the return string is the one dynamically calculated
+ *
+ * @param element
+ * - the element for which the textual representation is computed
+ * @return registered - the textual representation computed for this element
+ */
+ public String getEditString(Element element) {
+ AlfTextualRepresentation registeredRep = null;
+ /* 1. Parse the representation associated to model element */
+ try {
+ registeredRep = RepresentationParser.getInstance().
+ parse((NamedElement) element);
+ } catch (RepresentationParsingError e) {
+ e.printStackTrace();
+ }
+ /* 2. If the representation is in detached state (i.e. there is no model element owning it) then rely on the issued from a snapshot */
+ if (registeredRep != null && registeredRep.isDetached()) {
+ AlfTextualRepresentation generatedRep = null;
+ try {
+ generatedRep = RepresentationParser.getInstance().
+ getSnapshot((NamedElement) element);
+ } catch (RepresentationParsingError e) {
+ e.printStackTrace();
+ }
+ if (generatedRep != null) {
+ registeredRep.setText(generatedRep.getContent());
+ }
+ }
+ return registeredRep.getContent();
+ }
+
+
+ private EObject getPropertyDefinition(Property property, Resource alfModelResource) {
+ EObject memberDefinition = null;
+ Iterator<EObject> contentIterator = alfModelResource.getAllContents();
+ boolean found = false;
+ while (contentIterator.hasNext() && !found) {
+ EObject currentObject = contentIterator.next();
+ if (currentObject instanceof Member) {
+ Member member = (Member) currentObject;
+ if (member.getVisibility().equals(property.getVisibility().toString())
+ && member.getDefinition() instanceof PropertyDefinition) {
+ PropertyDefinition definition = (PropertyDefinition) member.getDefinition();
+ if (definition.getName().equals(property.getName())) {
+ found = (definition.getTypePart().isIsAny() && property.getType() == null)
+ || definition.getTypePart().getTypeName().toString().equals(property.getType().toString());
+ memberDefinition = member;
+ }
+ }
+ }
+ }
+ return memberDefinition;
+ }
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/generation/EditStringRetrievalStrategy.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/generation/EditStringRetrievalStrategy.java new file mode 100644 index 00000000000..752469be8e5 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/generation/EditStringRetrievalStrategy.java @@ -0,0 +1,47 @@ +/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.generation;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.uml.alf.MappingError;
+import org.eclipse.papyrus.uml.alf.UMLMapper;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+
+public abstract class EditStringRetrievalStrategy {
+
+ /**
+ * Provide a resource containing the ALF model corresponding to the given UML element
+ *
+ * @param UMLelement
+ * - the element from which the ALF model is computed
+ * @return alfModelResource - the resource containing the ALF model
+ */
+ protected Resource getAlfModel(NamedElement UMLelement) {
+ UMLMapper mapper = new UMLMapper();
+ Resource alfModelResource = null;
+ try {
+ if (UMLelement instanceof Property) {
+ alfModelResource = mapper.map(((Property) UMLelement).getNamespace());
+ } else {
+ alfModelResource = mapper.map(UMLelement);
+ }
+ } catch (MappingError e) {
+ e.printStackTrace();
+ }
+ return alfModelResource;
+ }
+
+ public abstract String getEditString(Element element);
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/merge/manual/AlfCompareEditor.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/merge/manual/AlfCompareEditor.java new file mode 100644 index 00000000000..9388f4f7de1 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/merge/manual/AlfCompareEditor.java @@ -0,0 +1,46 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.merge.manual;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.papyrus.uml.alf.text.representation.AlfTextualRepresentation;
+
+public class AlfCompareEditor extends CompareEditorInput {
+
+ protected final AlfTextualRepresentation registeredRep;
+
+ protected final AlfTextualRepresentation generatedRep;
+
+ public AlfCompareEditor(AlfTextualRepresentation registeredTextualRepresentation,
+ AlfTextualRepresentation generatedTextualRepresentation) {
+ super(new CompareConfiguration());
+ this.registeredRep = registeredTextualRepresentation;
+ this.generatedRep = generatedTextualRepresentation;
+ }
+
+ @Override
+ protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public void saveChanges(IProgressMonitor monitor) throws CoreException {
+ super.saveChanges(monitor);
+ }
+
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/merge/manual/MergeActionDialog.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/merge/manual/MergeActionDialog.java new file mode 100644 index 00000000000..66d79baa526 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/merge/manual/MergeActionDialog.java @@ -0,0 +1,137 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.merge.manual;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+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.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.NamedElement;
+
+public class MergeActionDialog extends TitleAreaDialog {
+
+ protected NamedElement modelElement;
+
+ protected final int WIDTH = 590;
+
+ protected final int HEIGHT = 280;
+
+ private List<Button> checkboxes;
+
+ private int returnCode;
+
+ private final String REBASE_MSG = "Abandon the modifications you previously saved for this element";
+ private final String MERGE_MSG = "Merge your ongoing modifications with the current state of this element [under construction]";
+ private final String RECONCILE_MSG = "Try to automatically reconcile your ongoing modifications with the current state of this element (risky)";
+
+ public static final int REBASE = 0;
+ public static final int MERGE = 1;
+ public static final int RECONCILE = 2;
+
+ public MergeActionDialog(Shell parent, NamedElement modelElement) {
+ super(parent);
+ this.returnCode = 0;
+ this.modelElement = modelElement;
+ this.checkboxes = new ArrayList<Button>();
+ }
+
+ public void create() {
+ super.create();
+ this.setTitle("Warning");
+ String value = "You have ongoing changes this model element: ";
+ value += this.modelElement.getName() == null ? "<unknown>" : this.modelElement.getName();
+ value += " (" + this.modelElement.eClass().getInstanceTypeName() + ")";
+ this.setMessage(value, IMessageProvider.WARNING);
+ this.getShell().setText("Potential conflict(s) detected");
+ this.getShell().setSize(WIDTH, HEIGHT);
+ Rectangle parentShellBounds = this.getParentShell().getBounds();
+ this.getShell().setLocation((parentShellBounds.width - WIDTH) / 2 + parentShellBounds.x,
+ (parentShellBounds.height - HEIGHT) / 2 + parentShellBounds.y);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite container = new Composite(area, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ container.setLayoutData(data);
+ container.setLayout(layout);
+ this.createActionGroup(container);
+ return area;
+ }
+
+ private void createActionGroup(Composite parent) {
+ Group actionsGroup = new Group(parent, SWT.NONE);
+ actionsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ RowLayout layout = new RowLayout();
+ layout.type = SWT.VERTICAL;
+ layout.spacing = 12;
+ actionsGroup.setLayout(layout);
+ this.checkboxes.add(this.createAction(actionsGroup, true, REBASE_MSG));
+ Button merge = this.createAction(actionsGroup, false, MERGE_MSG);
+ merge.setEnabled(false);
+ this.checkboxes.add(merge);
+ this.checkboxes.add(this.createAction(actionsGroup, false, RECONCILE_MSG));
+ this.returnCode = REBASE;
+ }
+
+ private Button createAction(Composite parent, final boolean checked, final String message) {
+ Button checkbox = new Button(parent, SWT.CHECK);
+ checkbox.setSelection(checked);
+ checkbox.setText(message);
+ checkbox.addSelectionListener(new CheckboxSelectionListener());
+ return checkbox;
+ }
+
+ @Override
+ public int getReturnCode() {
+ if (super.getReturnCode() != 0) {
+ this.returnCode = super.getReturnCode();
+ }
+ return this.returnCode;
+ }
+
+ private class CheckboxSelectionListener extends SelectionAdapter {
+
+ public void widgetSelected(SelectionEvent e) {
+ for (Button checkbox : MergeActionDialog.this.checkboxes) {
+ if (checkbox == e.getSource()) {
+ checkbox.setSelection(true);
+ if (checkbox.getText().equals(REBASE_MSG)) {
+ MergeActionDialog.this.returnCode = REBASE;
+ } else if (checkbox.getText().equals(MERGE_MSG)) {
+ MergeActionDialog.this.returnCode = MERGE;
+ } else {
+ MergeActionDialog.this.returnCode = RECONCILE;
+ }
+ } else {
+ checkbox.setSelection(false);
+ }
+ }
+ }
+ }
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/AlfTextualRepresentation.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/AlfTextualRepresentation.java new file mode 100644 index 00000000000..16f0c0992c7 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/AlfTextualRepresentation.java @@ -0,0 +1,187 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.compare.IModificationDate;
+import org.eclipse.compare.rangedifferencer.IRangeComparator;
+import org.eclipse.compare.rangedifferencer.RangeDifference;
+import org.eclipse.compare.rangedifferencer.RangeDifferencer;
+import org.eclipse.papyrus.uml.alf.libraries.helper.BackupState;
+import org.eclipse.papyrus.uml.alf.libraries.helper.BackupState.EditionStatus;
+import org.eclipse.papyrus.uml.alf.text.representation.compare.LineComparator;
+import org.eclipse.papyrus.uml.alf.text.representation.compare.LineDifference;
+import org.eclipse.papyrus.uml.alf.text.representation.compare.StringUtil;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.uml2.uml.NamedElement;
+
+public class AlfTextualRepresentation extends TextualRepresentation
+ implements IAlfTextualRepresentation, IModificationDate {
+
+ protected BackupState editionState;
+
+ public AlfTextualRepresentation(NamedElement owner) {
+ super(owner);
+ this.editionState = new BackupState();
+ }
+
+ public boolean isSaved() {
+ return this.editionState.status.equals(EditionStatus.SAVED);
+ }
+
+ public boolean isMerged() {
+ return this.editionState.status.equals(EditionStatus.MERGED);
+ }
+
+ public void setEditionState(BackupState state) {
+ this.editionState.timestamp = state.timestamp;
+ this.editionState.status = state.status;
+ }
+
+ public BackupState getEditionState() {
+ return this.editionState;
+ }
+
+ public EditionStatus getStatus() {
+ if (this.editionState != null) {
+ return this.editionState.status;
+ }
+ return null;
+ }
+
+ public long getModificationDate() {
+ return this.editionState.timestamp.getTime();
+ }
+
+ /**
+ * Two representations are considered as different since the set of differences is not empty
+ */
+ public boolean isDifferent(AlfTextualRepresentation representation) {
+ return !this.compare(representation).isEmpty();
+ }
+
+ /**
+ * Returns the set of differences found between two representations
+ */
+ public List<LineDifference> compare(AlfTextualRepresentation representation) {
+ /* 1. Build comparator for each representation */
+ IRangeComparator left = this.getRangeComparator();
+ IRangeComparator right = representation.getRangeComparator();
+ /* 2. Perform the differencing */
+ RangeDifference[] differences = RangeDifferencer.findDifferences(left, right);
+ /* 3. Build the result list */
+ List<LineDifference> results = new ArrayList<LineDifference>();
+ for (RangeDifference difference : differences) {
+ results.add(new LineDifference(difference, this, representation, left, right));
+ }
+ return results;
+ }
+
+ public boolean merge(AlfTextualRepresentation representation) {
+ // TODO
+ return true;
+ }
+
+ /**
+ * Heuristic to reconcile to different textual representation of the same model element.
+ * If possible changes in <code>representation</code> are propagated into the current textual representation.
+ * There is no guarantee that the reconciliation phase does not introduce loss of data.
+ *
+ * @return this - the current textual representation
+ */
+ public AlfTextualRepresentation reconcile(AlfTextualRepresentation representation) {
+ StringBuilder builder = new StringBuilder(this.text);
+ int offset = 0;
+ /* 1. Compute the list of differences */
+ Iterator<LineDifference> differenceIterator = this.compare(representation).iterator();
+ /* 2. Try to reconcile differences */
+ while (differenceIterator.hasNext()) {
+
+ /* 2.1. Retrieve the current difference and extract the position of the region to change (left) */
+ LineDifference difference = differenceIterator.next();
+ Point leftFragmentPosition = difference.getLeftFragmentPosition();
+
+ /* 2.2. Split the regions impacted by the difference into lines */
+ StringBuilder leftHandSideBuilder = new StringBuilder();
+ String[] leftLines = difference.getLeftState().split(StringUtil.EOL);
+ String[] rightLines = difference.getRightState().split(StringUtil.EOL);
+ int maxLineCount = Math.max(leftLines.length, rightLines.length);
+
+ /*
+ * 2.3. Integrate changes from left to right. In case where left hand side and right side
+ * have different sizes:
+ * A. right > left -> remaining lines in the right are preserved
+ * B. left > right -> remaining lines are integrated to the right
+ */
+ for (int i = 0; i < maxLineCount; i++) {
+
+ /* 2.3.1 Both sides have a definition of the same line */
+ if (i < leftLines.length && i < rightLines.length) {
+ if (!StringUtil.isNegligible(rightLines[i])) {
+ leftHandSideBuilder.append(rightLines[i] + StringUtil.EOL);
+ } else {
+ leftHandSideBuilder.append(leftLines[i] + StringUtil.EOL);
+ }
+ } else {
+ /* 2.3.2. The left side is larger than the right hand side */
+ if (i < leftLines.length) {
+ leftHandSideBuilder.append(leftLines[i] + StringUtil.EOL);
+ } else {
+ leftHandSideBuilder.append(rightLines[i] + StringUtil.EOL);
+ }
+ }
+ }
+
+ /* 2.4. Apply the change in the original representation */
+ builder.delete(leftFragmentPosition.x + offset, leftFragmentPosition.y + offset);
+ builder.insert(leftFragmentPosition.x + offset, leftHandSideBuilder);
+ offset += leftHandSideBuilder.length() - difference.getLeftState().length();
+ }
+
+ /* 3. Delete the EOF separator added previously at the end and replace text of the current representation */
+ if (builder.charAt(builder.length() - 1) == StringUtil.CHAR_EOL) {
+ builder.deleteCharAt(builder.length());
+ }
+ this.setText(builder.toString());
+ return this;
+ }
+
+ /**
+ * Rebase the current ALF representation onto the representation provided as parameter
+ * A rebase can only work if two representation concerns the same model element
+ *
+ * @return this - the current textual representation
+ */
+ public AlfTextualRepresentation rebase(AlfTextualRepresentation representation) {
+ if (this.getOwner() == representation.getOwner()) {
+ BackupState state = new BackupState();
+ state.status = representation.getStatus();
+ state.timestamp = new Timestamp(representation.getModificationDate());
+ this.setEditionState(state);
+ this.setText(representation.getContent());
+ }
+ return this;
+ }
+
+ /**
+ * Provide the comparator to be used to compare two textual representation
+ */
+ protected IRangeComparator getRangeComparator() {
+ return new LineComparator(this.text);
+ }
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/IAlfTextualRepresentation.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/IAlfTextualRepresentation.java new file mode 100644 index 00000000000..234607fe31c --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/IAlfTextualRepresentation.java @@ -0,0 +1,31 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation;
+
+import java.util.List;
+
+import org.eclipse.papyrus.uml.alf.text.representation.compare.LineDifference;
+
+public interface IAlfTextualRepresentation {
+
+ public boolean isDifferent(AlfTextualRepresentation representation);
+
+ public List<LineDifference> compare(AlfTextualRepresentation representation);
+
+ public boolean merge(AlfTextualRepresentation representation);
+
+ public AlfTextualRepresentation reconcile(AlfTextualRepresentation representation);
+
+ public AlfTextualRepresentation rebase(AlfTextualRepresentation representation);
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/TextualRepresentation.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/TextualRepresentation.java new file mode 100644 index 00000000000..b634c83ec9a --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/TextualRepresentation.java @@ -0,0 +1,98 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation;
+
+import java.io.InputStream;
+
+import org.eclipse.compare.IStreamContentAccessor;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.rangedifferencer.IRangeComparator;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.xtext.util.StringInputStream;
+
+public abstract class TextualRepresentation
+ implements IStreamContentAccessor, ITypedElement {
+
+ protected NamedElement owner;
+
+ protected Comment source;
+
+ protected String text;
+
+ public TextualRepresentation() {
+ }
+
+ public TextualRepresentation(NamedElement owner) {
+ this.owner = owner;
+ }
+
+ public Comment getSource() {
+ return this.source;
+ }
+
+ public void setSource(Comment source) {
+ this.source = source;
+ }
+
+ public NamedElement getOwner() {
+ return this.owner;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getContent() {
+ return this.text;
+ }
+
+ public String getName() {
+ if (this.getOwner() != null) {
+ return this.getOwner().getName();
+ }
+ return null;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public String getType() {
+ return ITypedElement.TEXT_TYPE;
+ }
+
+ public InputStream getContents() throws CoreException {
+ return new StringInputStream(this.text);
+ }
+
+ /**
+ * Be detached means the textual representation is not attached to a particular comment
+ *
+ * @return true if no source exists false otherwise
+ */
+ public boolean isDetached() {
+ return this.source == null;
+ }
+
+ /**
+ * Obtain a comparator from the textual representation in order to let the text
+ * be compared using range differencing strategy to another textual representation
+ *
+ * @return
+ */
+ protected abstract IRangeComparator getRangeComparator();
+
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/IAdvancedDifference.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/IAdvancedDifference.java new file mode 100644 index 00000000000..0a289fa903d --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/IAdvancedDifference.java @@ -0,0 +1,41 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation.compare;
+
+import org.eclipse.swt.graphics.Point;
+
+public interface IAdvancedDifference {
+
+ /**
+ * Provide the start index and the end index of the region concerned by the modification (at the left)
+ */
+ Point getLeftFragmentPosition();
+
+ /**
+ * Provide the start index and the end index of the region concerned by the modification (at the right)
+ */
+ Point getRightFragmentPosition();
+
+ /**
+ * Returns the region of the left hand side representation concerned by the difference
+ */
+ String getLeftState();
+
+ /**
+ * Returns the region of the right hand side representation concerned by the difference
+ */
+ String getRightState();
+
+
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/LineComparator.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/LineComparator.java new file mode 100644 index 00000000000..9647b1a854e --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/LineComparator.java @@ -0,0 +1,53 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation.compare;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.rangedifferencer.IRangeComparator;
+
+public class LineComparator implements IRangeComparator {
+
+ private List<String> lines;
+
+ public LineComparator(final String content) {
+ this.lines = new ArrayList<String>();
+ for (String line : content.split("\n")) {
+ lines.add(line);
+ }
+ }
+
+ public String getLine(int index) {
+ return this.lines.get(index);
+ }
+
+ @Override
+ public int getRangeCount() {
+ return this.lines.size();
+ }
+
+ @Override
+ public boolean rangesEqual(int thisIndex, IRangeComparator other, int otherIndex) {
+ String l1 = this.lines.get(thisIndex);
+ String l2 = ((LineComparator) other).lines.get(otherIndex);
+ return l1.equals(l2);
+ }
+
+ @Override
+ public boolean skipRangeComparison(int length, int maxLength, IRangeComparator other) {
+ return false;
+ }
+
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/LineDifference.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/LineDifference.java new file mode 100644 index 00000000000..d3c7952b405 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/LineDifference.java @@ -0,0 +1,102 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation.compare;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.contentmergeviewer.ITokenComparator;
+import org.eclipse.compare.contentmergeviewer.TokenComparator;
+import org.eclipse.compare.rangedifferencer.IRangeComparator;
+import org.eclipse.compare.rangedifferencer.RangeDifference;
+import org.eclipse.compare.rangedifferencer.RangeDifferencer;
+import org.eclipse.papyrus.uml.alf.text.representation.AlfTextualRepresentation;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * This class represent a difference between regions of two representations
+ */
+public class LineDifference extends RegionDifference implements IAdvancedDifference {
+
+ public LineDifference(RangeDifference d, AlfTextualRepresentation leftR,
+ AlfTextualRepresentation rightR, IRangeComparator leftC, IRangeComparator rightC) {
+ super(d, leftR, rightR, leftC, rightC);
+ }
+
+ public String getLeftState() {
+ Point position = this.getLeftFragmentPosition();
+ return this.leftR.getContent().substring(position.x, position.y);
+ }
+
+ public String getRightState() {
+ Point position = this.getRightFragmentPosition();
+ return this.rightR.getContent().substring(position.x, position.y);
+ }
+
+ public Point getLeftFragmentPosition() {
+ String[] leftLines = this.leftR.getContent().split(StringUtil.EOL);
+ int startIndex = 0;
+ for (int i = 0; i < this.leftStart; i++) {
+ startIndex += leftLines[i].length() + 1;
+ }
+ int endIndex = startIndex;
+ for (int i = this.leftStart; i < this.leftEnd(); i++) {
+ if (this.leftEnd() == leftLines.length) {
+ endIndex += leftLines[i].length();
+ } else {
+ endIndex += leftLines[i].length() + 1;
+ }
+ }
+ return new Point(startIndex, endIndex);
+ }
+
+ public Point getRightFragmentPosition() {
+ String[] rightLines = this.rightR.getContent().split(StringUtil.EOL);
+ int startIndex = 0;
+ for (int i = 0; i < this.rightStart; i++) {
+ startIndex += rightLines[i].length() + 1;
+ }
+ int endIndex = startIndex;
+ for (int i = this.rightStart; i < this.rightEnd(); i++) {
+ if (this.rightEnd() == rightLines.length) {
+ endIndex += rightLines[i].length();
+ } else {
+ endIndex += rightLines[i].length() + 1;
+ }
+ }
+ return new Point(startIndex, endIndex);
+ }
+
+ /**
+ * return all the differences between tokens present in the left line and
+ * those present at the right line
+ *
+ * @return tokenDifferences - the list of differences
+ */
+ public List<TokenDifference> getChildren() {
+ ITokenComparator leftTokenComparator = new TokenComparator(this.getLeftState());
+ ITokenComparator rightTokenComparator = new TokenComparator(this.getRightState());
+ AlfTextualRepresentation leftRepresentation = new AlfTextualRepresentation(null);
+ leftRepresentation.setText(this.getLeftState());
+ AlfTextualRepresentation rightRepresentation = new AlfTextualRepresentation(null);
+ leftRepresentation.setText(this.getRightState());
+ RangeDifference[] differences = RangeDifferencer.findDifferences(leftTokenComparator, rightTokenComparator);
+ List<TokenDifference> tokenDifferences = new ArrayList<TokenDifference>();
+ for (RangeDifference difference : differences) {
+ tokenDifferences.add(new TokenDifference(difference, leftRepresentation, rightRepresentation, leftTokenComparator, rightTokenComparator));
+ }
+ return tokenDifferences;
+ }
+
+}
\ No newline at end of file diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/RegionDifference.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/RegionDifference.java new file mode 100644 index 00000000000..7d6d101033b --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/RegionDifference.java @@ -0,0 +1,77 @@ +package org.eclipse.papyrus.uml.alf.text.representation.compare;
+
+import org.eclipse.compare.rangedifferencer.IRangeComparator;
+import org.eclipse.compare.rangedifferencer.RangeDifference;
+import org.eclipse.papyrus.uml.alf.text.representation.AlfTextualRepresentation;
+
+public abstract class RegionDifference extends RangeDifference implements IAdvancedDifference {
+
+ /**
+ * The left hand side comparator
+ */
+ protected IRangeComparator leftC;
+
+ /**
+ * The right hand side comparator
+ */
+ protected IRangeComparator rightC;
+
+ /**
+ * The left side representation
+ */
+ protected AlfTextualRepresentation leftR;
+
+ /**
+ * The right side representation
+ */
+ protected AlfTextualRepresentation rightR;
+
+ protected RegionDifference(RangeDifference d, AlfTextualRepresentation leftR,
+ AlfTextualRepresentation rightR, IRangeComparator leftC, IRangeComparator rightC) {
+ this(d.kind(), d.rightStart(), d.rightLength(), d.leftStart(),
+ d.leftLength(), d.ancestorStart(), d.ancestorLength());
+ this.leftC = leftC;
+ this.rightC = rightC;
+ this.leftR = leftR;
+ this.rightR = rightR;
+ }
+
+ public RegionDifference(int kind, int rightStart, int rightLength, int leftStart, int leftLength,
+ int ancestorStart, int ancestorLength) {
+ super(kind, rightStart, rightLength, leftStart, leftLength, ancestorStart, ancestorLength);
+ }
+
+ /**
+ * Return true if the current difference represents a deletion. Typically a deletion means
+ * a member in the right state disappeared in the left state
+ */
+ public boolean isDeletion() {
+ return !StringUtil.isNegligible(this.getLeftState()) && StringUtil.isNegligible(this.getRightState());
+ }
+
+ /**
+ * Return true if the current difference represents an addition. An addition is the exact reverse
+ * of a deletion (i.e. we have a member in the left that does exists in the right states).
+ */
+ public boolean isAddition() {
+ return StringUtil.isNegligible(this.getLeftState()) && !StringUtil.isNegligible(this.getRightState());
+ }
+
+ /**
+ * Return true if the current difference represents a change. A change is an update of a member
+ * existing in the right state
+ */
+ public boolean isChange() {
+ return !StringUtil.isNegligible(this.getLeftState()) && !StringUtil.isNegligible(this.getRightState());
+ }
+
+ public String toString() {
+ String serialization = "\n=======================DIFF=======================\n";
+ serialization += this.getLeftState();
+ serialization += "\n==================================================\n";
+ serialization += this.getRightState();
+ serialization += "\n=====================END DIFF=====================\n";
+ return serialization;
+ }
+
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/StringUtil.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/StringUtil.java new file mode 100644 index 00000000000..e3120567d8d --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/StringUtil.java @@ -0,0 +1,44 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation.compare;
+
+public class StringUtil {
+
+ public static final char CHAR_EOL = '\n';
+ public static final String EOL = "\n";
+
+ /**
+ * Return true if the given string is not negligible to be used in a comparison
+ *
+ * @param str
+ * - the assessed string
+ * @return negligible
+ */
+ public static final boolean isNegligible(String str) {
+ boolean negligible = true;
+ if (!str.isEmpty()) {
+ int i = 0;
+ while (negligible && i < str.length()) {
+ if (str.charAt(i) != '\n'
+ && str.charAt(i) != '\r'
+ && str.charAt(i) != ' '
+ && str.charAt(i) != '\t') {
+ negligible = false;
+ }
+ i++;
+ }
+ }
+ return negligible;
+ }
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/TokenDifference.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/TokenDifference.java new file mode 100644 index 00000000000..f1ffebdd9de --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/compare/TokenDifference.java @@ -0,0 +1,62 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation.compare;
+
+import org.eclipse.compare.contentmergeviewer.ITokenComparator;
+import org.eclipse.compare.rangedifferencer.IRangeComparator;
+import org.eclipse.compare.rangedifferencer.RangeDifference;
+import org.eclipse.papyrus.uml.alf.text.representation.AlfTextualRepresentation;
+import org.eclipse.swt.graphics.Point;
+
+public class TokenDifference extends RegionDifference implements IAdvancedDifference {
+
+ public TokenDifference(RangeDifference d, AlfTextualRepresentation leftR,
+ AlfTextualRepresentation rightR, IRangeComparator leftC, IRangeComparator rightC) {
+ super(d, leftR, rightR, leftC, rightC);
+ }
+
+ public String getLeftState() {
+ String result = "";
+ int startIndex = ((ITokenComparator) this.leftC).getTokenStart(this.leftStart);
+ int endIndex = 0;
+ for (int i = this.leftStart; i <= this.leftEnd(); i++) {
+ endIndex += ((ITokenComparator) this.leftC).getTokenLength(i);
+ }
+ result = this.leftR.getContent().substring(startIndex, startIndex + endIndex);
+ return result;
+ }
+
+ @Override
+ public String getRightState() {
+ String result = "";
+ int endIndex = 0;
+ int startIndex = ((ITokenComparator) this.rightC).getTokenStart(this.rightStart);
+ for (int i = this.rightStart; i <= this.rightEnd(); i++) {
+ endIndex += ((ITokenComparator) this.rightC).getTokenLength(i);
+ }
+ result = this.rightR.getContent().substring(startIndex, startIndex + endIndex);
+ return result;
+ }
+
+ public Point getLeftFragmentPosition() {
+ return new Point(((ITokenComparator) this.leftC).getTokenStart(this.leftStart),
+ ((ITokenComparator) this.leftC).getTokenStart(this.leftEnd()) + ((ITokenComparator) this.leftC).getTokenLength(this.leftEnd()));
+ }
+
+ public Point getRightFragmentPosition() {
+ return new Point(((ITokenComparator) this.rightC).getTokenStart(this.rightStart),
+ ((ITokenComparator) this.rightC).getTokenStart(this.rightEnd()) + ((ITokenComparator) this.rightC).getTokenLength(this.rightEnd()));
+ }
+
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/util/RepresentationParser.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/util/RepresentationParser.java new file mode 100644 index 00000000000..5aab9dfecd9 --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/util/RepresentationParser.java @@ -0,0 +1,98 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * Jeremie Tatibouet
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation.util;
+
+import java.sql.Timestamp;
+import java.util.Calendar;
+
+import org.eclipse.papyrus.uml.alf.libraries.helper.AlfUtil;
+import org.eclipse.papyrus.uml.alf.libraries.helper.BackupState;
+import org.eclipse.papyrus.uml.alf.libraries.helper.BackupUtil;
+import org.eclipse.papyrus.uml.alf.libraries.helper.BackupState.EditionStatus;
+import org.eclipse.papyrus.uml.alf.text.generation.DefaultEditStringRetrievalStrategy;
+import org.eclipse.papyrus.uml.alf.text.representation.AlfTextualRepresentation;
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class RepresentationParser {
+
+ private static RepresentationParser parser;
+
+ private BackupUtil helperBackup;
+
+ private AlfUtil helperAlf;
+
+ private RepresentationParser() {
+ this.helperBackup = BackupUtil.getInstance();
+ this.helperAlf = AlfUtil.getInstance();
+ }
+
+ public static RepresentationParser getInstance() {
+ if (parser == null) {
+ parser = new RepresentationParser();
+ }
+ return parser;
+ }
+
+ /**
+ * Load the textual representation attached to a model element which is a NamedElement
+ *
+ * @param modelElement
+ * @return representation
+ * @throws RepresentationParsingError
+ */
+ public AlfTextualRepresentation parse(NamedElement modelElement) throws RepresentationParsingError {
+ if (modelElement == null) {
+ throw new RepresentationParsingError(
+ "The model element for which the representation is calculated cannot be null");
+ }
+ AlfTextualRepresentation representation = new AlfTextualRepresentation(modelElement);
+ Comment comment = helperAlf.getTextualRepresentationComment(modelElement);
+ if (comment != null) {
+ representation.setSource(comment);
+ representation.setText(comment.getBody());
+ if (helperBackup.isBackup(comment)) {
+ Stereotype backup = helperBackup.getBackuStereotype(modelElement);
+ if (backup != null) {
+ representation.setEditionState(helperBackup.getBackupState(comment));
+ }
+ }
+ } else {
+ representation.setText(new DefaultEditStringRetrievalStrategy().getGeneratedEditString(modelElement));
+ }
+ return representation;
+ }
+
+ /**
+ * Capture the textual representation of a model element. It does not returns an already registered representation
+ * associated to this element. It captures the current state of a model element.
+ *
+ * @param modelElement
+ * @return representation
+ * @throws RepresentationParsingError
+ */
+ public AlfTextualRepresentation getSnapshot(NamedElement modelElement) throws RepresentationParsingError {
+ if (modelElement == null) {
+ throw new RepresentationParsingError(
+ "The model element for which the representation is calculated cannot be null");
+ }
+ AlfTextualRepresentation representation = new AlfTextualRepresentation(modelElement);
+ representation.setText(new DefaultEditStringRetrievalStrategy().getGeneratedEditString(modelElement));
+ representation.setEditionState(new BackupState(
+ new Timestamp(Calendar.getInstance().getTimeInMillis()),
+ EditionStatus.MERGED));
+ return representation;
+ }
+}
diff --git a/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/util/RepresentationParsingError.java b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/util/RepresentationParsingError.java new file mode 100644 index 00000000000..fbc6e82baef --- /dev/null +++ b/extraplugins/alf/core/org.eclipse.papyrus.uml.alf.text/src/org/eclipse/papyrus/uml/alf/text/representation/util/RepresentationParsingError.java @@ -0,0 +1,25 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Contributors:
+ * J�r�mie Tatibouet (CEA LIST)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.alf.text.representation.util;
+
+@SuppressWarnings("serial")
+public class RepresentationParsingError extends Exception {
+
+ public RepresentationParsingError() {
+ }
+
+ public RepresentationParsingError(String arg0) {
+ super(arg0);
+ }
+}
|