Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2021-05-27 19:59:40 +0000
committerVincent Lorenzo2021-06-04 07:53:34 +0000
commitc737a5a6f68f9709428cf6cb3a44928c19cb3e80 (patch)
tree08ae2462d1288b98a582fbc5fb3ed9e719a2ea26
parent37d6502cf8742f5e65a48de98ee36a5ab45430da (diff)
downloadorg.eclipse.papyrus-c737a5a6f68f9709428cf6cb3a44928c19cb3e80.tar.gz
org.eclipse.papyrus-c737a5a6f68f9709428cf6cb3a44928c19cb3e80.tar.xz
org.eclipse.papyrus-c737a5a6f68f9709428cf6cb3a44928c19cb3e80.zip
Bug 573788: [Toolsmiths] Generic representation clean-up advice
- create a generic representation (view) deletion advice that works with any user-defined representation kind - add a context menu action to the Architecture Model that adds this advice to an architecture context - add a custom toolsmiths validation warning for architecture contexts that do not reference, inherit, or get by extension this new advice, unless the context is an extension of other contexts Change-Id: I58ce20d7d9654d5c5204a7a01c505d143a0328af Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/advice/DeleteNatTableContextAdvice.java21
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.properties11
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.xml44
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/AddRecommendedElementTypesConfigurationsHandler.java126
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/Messages.java5
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/messages.properties2
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/model/representations.elementtypesconfigurations4
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/plugin.xml7
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/internal/policy/advice/RepresentationDependencyAdvice.java57
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/META-INF/MANIFEST.MF3
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/constants/ArchitecturePluginValidationConstants.java7
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureCustomValidator.java48
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureDependencies.java2
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/Messages.java3
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/messages.properties5
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/ArchitectureMarkerResolutionGenerator.java19
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF3
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/CustomModelChecker.java17
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/internal/utils/ArchitectureIndex.java74
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/CommonMarkerResolutionUtils.java56
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/SimpleModelEditMarkerResolution.java120
-rw-r--r--tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/.classpath12
-rw-r--r--tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/internal/policy/advice/tests/RepresentationDependencyAdviceTest.java116
-rw-r--r--tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java14
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/.classpath12
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/META-INF/MANIFEST.MF6
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice-extension.architecture33
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice.architecture32
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-representationsAdviceByExtension.architecture35
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-representationsAdviceInherited.architecture35
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.architecture1
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/tests/ModelQuickFixTests.java141
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/AllTests.java2
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/ArchitectureModelBuilderTest.java59
36 files changed, 1094 insertions, 42 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/advice/DeleteNatTableContextAdvice.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/advice/DeleteNatTableContextAdvice.java
index 71dff434a09..aa5f4698009 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/advice/DeleteNatTableContextAdvice.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/advice/DeleteNatTableContextAdvice.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 2021 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,10 +10,12 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 573788
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.advice;
import java.util.Collection;
+import java.util.Optional;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -23,12 +25,9 @@ import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.papyrus.infra.nattable.messages.Messages;
import org.eclipse.papyrus.infra.nattable.model.nattable.NattablePackage;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
/**
* Destroy the NatTable
@@ -39,13 +38,6 @@ import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
*/
public class DeleteNatTableContextAdvice extends AbstractEditHelperAdvice {
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeDestroyDependentsCommand(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest)
- *
- * @param request
- * @return
- */
@Override
protected ICommand getBeforeDestroyDependentsCommand(DestroyDependentsRequest request) {
final EObject objectToDestroy = request.getElementToDestroy();
@@ -61,13 +53,12 @@ public class DeleteNatTableContextAdvice extends AbstractEditHelperAdvice {
final EObject currentEObject = currentSetting.getEObject();
final EStructuralFeature currentfeature = currentSetting.getEStructuralFeature();
if (currentEObject instanceof Table && currentfeature == NattablePackage.eINSTANCE.getTable_Context()) {
- final DestroyElementRequest request2 = new DestroyElementRequest(currentEObject, false);
- final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(currentEObject);
- cmd.add(provider.getEditCommand(request2));
+ Optional.ofNullable(request.getDestroyDependentCommand(currentEObject))
+ .ifPresent(cmd::add);
}
}
if (!cmd.isEmpty()) {
- return cmd;
+ return cmd.reduce();
}
}
return null;
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.properties b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.properties
index 2d336b82cfe..cc5b9a13a9c 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.properties
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.properties
@@ -1,4 +1,4 @@
-# Copyright (c) 2016 CEA LIST.
+# Copyright (c) 2016, 2021 CEA LIST, Christian W. Damus, and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -9,7 +9,7 @@
#
# Contributors:
# Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
-#
+# Christian W. Damus - bug 573788
#
pluginName = Architecture UI
@@ -77,3 +77,10 @@ _UI_RuntimeVersion_label = &Runtime Version
_UI_Resolve_All_menu_item = Resolve All
_UI_Resolve_All_simple_description = Resolves all reference from selected objects
+
+contextsPage.name = Architecture Contexts
+Switch_Architecture_Context.command = Change Architecture Context
+addTypes.description = Select from the recommended Element Types Set Configurations to add to an architecture context.
+addTypes.name = Add Recommended Element Types Configurations
+Switch_Architecture_Context.mnemonic = C
+addTypes.label = Add Recommended Element Types Configurations
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.xml b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.xml
index 562f2ccc6e8..a388b4d053e 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.xml
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/plugin.xml
@@ -2,7 +2,7 @@
<?eclipse version="3.0"?>
<!--
- Copyright (c) 2016 CEA LIST.
+ Copyright (c) 2016, 2021 CEA LIST, Christian W. Damus, and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
@@ -13,7 +13,7 @@
Contributors:
Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
-
+ Christian W. Damus - bug 573788
-->
@@ -50,7 +50,7 @@
category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
class="org.eclipse.papyrus.infra.ui.architecture.preferences.ArchitectureContextPreferencePage"
id="org.eclipse.papyrus.infra.ui.architecture.preferences.ArchitecturesPreferencePage"
- name="Architecture Contexts">
+ name="%contextsPage.name">
</page>
</extension>
@@ -59,8 +59,30 @@
<command
defaultHandler="org.eclipse.papyrus.infra.ui.architecture.handlers.ChangeArchitectureContextHandler"
id="org.eclipse.papyrus.infra.ui.architecture.commands.ChangeArchitectureContext"
- name="Change Architecture Context">
+ name="%Switch_Architecture_Context.command">
</command>
+ <command
+ description="%addTypes.description"
+ id="org.eclipse.papyrus.infra.ui.architecture.addRecommendedElementTypesConfigurations"
+ name="%addTypes.name">
+ </command>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ commandId="org.eclipse.papyrus.infra.ui.architecture.addRecommendedElementTypesConfigurations"
+ class="org.eclipse.papyrus.infra.ui.architecture.handlers.AddRecommendedElementTypesConfigurationsHandler">
+ <activeWhen>
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <instanceof
+ value="org.eclipse.papyrus.infra.core.architecture.ArchitectureContext">
+ </instanceof>
+ </iterate>
+ </activeWhen>
+ </handler>
</extension>
<extension
@@ -73,7 +95,7 @@
icon="icons/full/obj16/ArchitectureContext.gif"
id="org.eclipse.papyrus.infra.ui.architecture.commands.ChangeArchitectureContext"
label="%Switch_Architecture_Context"
- mnemonic="C"
+ mnemonic="%Switch_Architecture_Context.mnemonic"
style="push">
<visibleWhen
checkEnabled="false">
@@ -99,6 +121,18 @@
</dynamic>
</menu>
</menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.infra.ui.architecture.ArchitectureEditorID?after=additions">
+ <command
+ commandId="org.eclipse.papyrus.infra.ui.architecture.addRecommendedElementTypesConfigurations"
+ id="org.eclipse.papyrus.infra.ui.architecture.addRecommendedElementTypesConfigurations"
+ label="%addTypes.label"
+ style="push">
+ <visibleWhen
+ checkEnabled="true"/>
+ </command>
+ </menuContribution>
</extension>
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/AddRecommendedElementTypesConfigurationsHandler.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/AddRecommendedElementTypesConfigurationsHandler.java
new file mode 100644
index 00000000000..7dbc42a2723
--- /dev/null
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/AddRecommendedElementTypesConfigurationsHandler.java
@@ -0,0 +1,126 @@
+/*****************************************************************************
+ * Copyright (c) 2021 Christian W. Damus, CEA LIST, and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.architecture.handlers;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.core.architecture.ArchitectureContext;
+import org.eclipse.papyrus.infra.core.architecture.ArchitecturePackage;
+import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration;
+import org.eclipse.papyrus.infra.types.ElementTypesConfigurationsPackage;
+import org.eclipse.papyrus.infra.ui.architecture.messages.Messages;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Handler of the <em>Add Recommended Element Types Configurations</em> command.
+ */
+public class AddRecommendedElementTypesConfigurationsHandler extends AbstractHandler {
+
+ private static final URI REPRESENTATIONS_ADVICE_URI = URI.createURI("pathmap://PAPYRUS_VIEWPOINTS_POLICY/representations/advice", true); //$NON-NLS-1$
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
+ List<ArchitectureContext> contexts = getArchitectureContexts(selection);
+ if (!contexts.isEmpty()) {
+ EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(contexts.get(0));
+ if (domain != null) {
+ Shell parent = HandlerUtil.getActiveShell(event);
+ domain.getCommandStack().execute(getAddElementTypeSetConfigurationsCommand(parent, domain, contexts));
+ }
+ }
+ return null;
+ }
+
+ private List<ArchitectureContext> getArchitectureContexts(IStructuredSelection selection) {
+ return ((List<?>) selection.toList()).stream()
+ .filter(ArchitectureContext.class::isInstance)
+ .map(ArchitectureContext.class::cast)
+ .collect(Collectors.toList());
+ }
+
+ private Command getAddElementTypeSetConfigurationsCommand(Shell parent, EditingDomain domain, Collection<? extends ArchitectureContext> contexts) {
+ Collection<? extends ElementTypeSetConfiguration> recommendedSets = getRecommendedElementTypesConfigurations(domain);
+
+ AdapterFactory adapterFactory;
+ if (domain instanceof AdapterFactoryEditingDomain) {
+ adapterFactory = ((AdapterFactoryEditingDomain) domain).getAdapterFactory();
+ } else {
+ adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ }
+
+ ILabelProvider labels = new AdapterFactoryLabelProvider(adapterFactory);
+ Collection<?> selectedSets;
+
+ try {
+ FeatureEditorDialog dialog = new FeatureEditorDialog(parent, labels, Messages.AddRecommendedElementTypesConfigurationsHandler_1, ElementTypesConfigurationsPackage.Literals.ELEMENT_TYPE_SET_CONFIGURATION, List.of(), Messages.AddRecommendedElementTypesConfigurationsHandler_2,
+ List.copyOf(recommendedSets), true, true, true);
+ if (dialog.open() == Window.OK) {
+ selectedSets = dialog.getResult();
+ } else {
+ selectedSets = List.of();
+ }
+ } finally {
+ if (!(domain instanceof AdapterFactoryEditingDomain)) {
+ // We created an adapter factory, so we must dispose it
+ ((ComposedAdapterFactory) adapterFactory).dispose();
+ }
+ labels.dispose();
+ }
+
+ return contexts.stream().map(ctx -> getAddElementTypeSetConfigurationsCommand(domain, ctx, selectedSets))
+ .filter(Objects::nonNull)
+ .reduce(Command::chain)
+ .orElse(UnexecutableCommand.INSTANCE);
+ }
+
+ private Collection<ElementTypeSetConfiguration> getRecommendedElementTypesConfigurations(EditingDomain domain) {
+ // TODO: This should be a pluggable registry of recommended Element Types Configurations
+ Resource resource = domain.getResourceSet().getResource(REPRESENTATIONS_ADVICE_URI, true);
+ return (resource == null) ? List.of() : EcoreUtil.<ElementTypeSetConfiguration> getObjectsByType(resource.getContents(), ElementTypesConfigurationsPackage.Literals.ELEMENT_TYPE_SET_CONFIGURATION);
+ }
+
+ private Command getAddElementTypeSetConfigurationsCommand(EditingDomain domain, ArchitectureContext context, Collection<?> recommendedSets) {
+ Set<?> toAdd = new HashSet<>(recommendedSets);
+ toAdd.removeAll(context.getElementTypes());
+ return toAdd.isEmpty() ? null : AddCommand.create(domain, context, ArchitecturePackage.Literals.ARCHITECTURE_CONTEXT__ELEMENT_TYPES, toAdd);
+ }
+
+}
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/Messages.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/Messages.java
index c81e517480f..58c26dbb5ae 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/Messages.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/Messages.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2019 CEA LIST and others.
+ * Copyright (c) 2019, 2021 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 573788
*
*****************************************************************************/
@@ -22,6 +23,8 @@ import org.eclipse.osgi.util.NLS;
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.ui.architecture.messages.messages"; //$NON-NLS-1$
+ public static String AddRecommendedElementTypesConfigurationsHandler_1;
+ public static String AddRecommendedElementTypesConfigurationsHandler_2;
public static String ArchitecturePageAddValidator_diagleTitle;
public static String ArchitecturePageAddValidator_dialogLabel;
public static String ChangeArchitectureContextHandler_dialogLabel;
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/messages.properties b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/messages.properties
index 25c948987c7..b214857d552 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/messages.properties
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/messages.properties
@@ -1,3 +1,5 @@
+AddRecommendedElementTypesConfigurationsHandler_1=Selected Contexts
+AddRecommendedElementTypesConfigurationsHandler_2=Recommended Element Type Set Configurations
ArchitecturePageAddValidator_diagleTitle=Enable viewpoint for diagram(s)/table(s)
ArchitecturePageAddValidator_dialogLabel=The current diagram(s)/table(s) you want to open is not managed by the current viewpoint(s).\nSwitch the architecture context and/or viewpoints to get the one containing the diagram(s)/table(s) you want to open:
ChangeArchitectureContextHandler_dialogLabel=Switch the architecture context and/or viewpoints applied to the Papyrus model:
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
index 11fd8b515cd..33dc1e176ca 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
@@ -2,6 +2,7 @@ Manifest-Version: 1.0
Export-Package: org.eclipse.papyrus.infra.viewpoints.configuration,
org.eclipse.papyrus.infra.viewpoints.configuration.impl,
org.eclipse.papyrus.infra.viewpoints.configuration.util,
+ org.eclipse.papyrus.infra.viewpoints.internal.policy.advice;x-internal:=true,
org.eclipse.papyrus.infra.viewpoints.policy,
org.eclipse.papyrus.infra.viewpoints.policy.providers,
org.eclipse.papyrus.infra.viewpoints.policy.query,
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/model/representations.elementtypesconfigurations b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/model/representations.elementtypesconfigurations
new file mode 100644
index 00000000000..a95893408fd
--- /dev/null
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/model/representations.elementtypesconfigurations
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<elementtypesconfigurations:ElementTypeSetConfiguration xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:elementtypesconfigurations="http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2" xmi:id="_A5utQL5PEeuDXfdzV8a7zA" description="Advice bindings for manipulation of Representations." identifier="org.eclipse.papyrus.infra.viewpoints.policy.representations" name="Representations Advice" metamodelNsURI="http://www.eclipse.org/papyrus/infra/core/architecture">
+ <adviceBindingsConfigurations xmi:type="elementtypesconfigurations:AdviceBindingConfiguration" xmi:id="_OEsSsL5PEeuDXfdzV8a7zA" description="Automatic updates of representations owned by or in the context of a model object being edited." identifier="org.eclipse.papyrus.infra.viewpoints.internal.policy.advice.representationDependencyAdvice" inheritance="all" editHelperAdviceClassName="org.eclipse.papyrus.infra.viewpoints.internal.policy.advice.RepresentationDependencyAdvice"/>
+</elementtypesconfigurations:ElementTypeSetConfiguration>
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/plugin.xml b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/plugin.xml
index 3d2a4d243fd..2255722df36 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/plugin.xml
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/plugin.xml
@@ -55,5 +55,12 @@
class="org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationPackage"
genModel="model/configuration.genmodel"/>
</extension>
+ <extension
+ point="org.eclipse.emf.ecore.uri_mapping">
+ <mapping
+ source="pathmap://PAPYRUS_VIEWPOINTS_POLICY/representations/advice"
+ target="model/representations.elementtypesconfigurations">
+ </mapping>
+ </extension>
</plugin>
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/internal/policy/advice/RepresentationDependencyAdvice.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/internal/policy/advice/RepresentationDependencyAdvice.java
new file mode 100644
index 00000000000..02ec4962d5b
--- /dev/null
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/internal/policy/advice/RepresentationDependencyAdvice.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2021 Christian W. Damus, CEA LIST, and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.viewpoints.internal.policy.advice;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
+import org.eclipse.papyrus.infra.core.architecture.RepresentationKind;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+
+/**
+ * Advice that updates {@linkplain RepresentationKind representations} that are owned
+ * by or in the context of some {@link EObject} being edited in a Papyrus model.
+ * Currently this implements advice for
+ * <ul>
+ * <li>{@linkplain #getBeforeDestroyDependentsCommand(DestroyDependentsRequest) destroy-dependents request} on the owner/context object
+ * to delete the representation</li>
+ * </ul>
+ */
+public class RepresentationDependencyAdvice extends AbstractEditHelperAdvice {
+
+ @Override
+ protected ICommand getBeforeDestroyDependentsCommand(DestroyDependentsRequest request) {
+ Collection<EObject> representationsToDelete = new HashSet<>();
+
+ for (EStructuralFeature.Setting setting : EMFHelper.getUsages(request.getElementToDestroy())) {
+ EObject owner = setting.getEObject();
+ ViewPrototype prototype = ViewPrototype.get(owner);
+ if (prototype != null && !prototype.isUnavailable()) {
+ // This is a representation of the object being deleted. Delete it, also
+ representationsToDelete.add(owner);
+ }
+ }
+
+ return representationsToDelete.isEmpty() ? null : request.getDestroyDependentsCommand(representationsToDelete);
+ }
+
+}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/META-INF/MANIFEST.MF b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/META-INF/MANIFEST.MF
index 931c6e17f5b..5b3f2e6c5fe 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/META-INF/MANIFEST.MF
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/META-INF/MANIFEST.MF
@@ -20,7 +20,8 @@ Require-Bundle:
org.eclipse.ui.ide;bundle-version="[3.18.0,4.0.0)",
org.eclipse.papyrus.toolsmiths.plugin.builder;bundle-version="[1.1.0,2.0.0)",
org.eclipse.papyrus.infra.core;bundle-version="[4.1.0,5.0.0)",
- org.eclipse.papyrus.infra.emf;bundle-version="[4.0.0,5.0.0)"
+ org.eclipse.papyrus.infra.emf;bundle-version="[4.0.0,5.0.0)",
+ org.eclipse.emf.edit;bundle-version="[2.16.0,3.0.0)"
Export-Package:
org.eclipse.papyrus.toolsmiths.validation.architecture,
org.eclipse.papyrus.toolsmiths.validation.architecture.checkers,
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/constants/ArchitecturePluginValidationConstants.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/constants/ArchitecturePluginValidationConstants.java
index b5f61beafac..01ec98c44fc 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/constants/ArchitecturePluginValidationConstants.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/constants/ArchitecturePluginValidationConstants.java
@@ -10,12 +10,13 @@
*
* Contributors:
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 570097
+ * Christian W. Damus - bugs 570097, 573788
*
*****************************************************************************/
package org.eclipse.papyrus.toolsmiths.validation.architecture.constants;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.toolsmiths.validation.common.checkers.CommonProblemConstants;
/**
@@ -41,6 +42,10 @@ public class ArchitecturePluginValidationConstants {
/** Problem IDs for the markers generated by architecture plug-in validation. */
public static final int PROBLEM_ID_BASE = CommonProblemConstants.MAX_PROBLEM_ID + 0x01;
public static final int MISSING_ARCHITECTURE_MODEL_EXTENSION_ID = PROBLEM_ID_BASE + 0x00;
+ public static final int MISSING_REPRESENTATIONS_ADVICE_ID = PROBLEM_ID_BASE + 0x01;
public static final int MAX_PROBLEM_ID = PROBLEM_ID_BASE + 0x3f;
+ /** The URI of the <em>Element Types Configurations</em> model that has the Representations Advice. */
+ public static final URI REPRESENTATIONS_ADVICE_URI = URI.createURI("pathmap://PAPYRUS_VIEWPOINTS_POLICY/representations/advice", true); //$NON-NLS-1$
+
}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureCustomValidator.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureCustomValidator.java
index aa8df738a0f..77567166dab 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureCustomValidator.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureCustomValidator.java
@@ -25,10 +25,14 @@ import java.util.stream.Collectors;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.infra.core.architecture.ADElement;
import org.eclipse.papyrus.infra.core.architecture.ArchitectureContext;
import org.eclipse.papyrus.infra.core.architecture.ArchitectureDomain;
@@ -38,10 +42,13 @@ import org.eclipse.papyrus.infra.core.architecture.Concern;
import org.eclipse.papyrus.infra.core.architecture.RepresentationKind;
import org.eclipse.papyrus.infra.core.architecture.Stakeholder;
import org.eclipse.papyrus.infra.core.architecture.util.ArchitectureSwitch;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration;
import org.eclipse.papyrus.infra.types.core.extensionpoints.IElementTypeSetExtensionPoint;
+import org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants;
import org.eclipse.papyrus.toolsmiths.validation.architecture.internal.messages.Messages;
import org.eclipse.papyrus.toolsmiths.validation.common.checkers.CustomModelChecker;
+import org.eclipse.papyrus.toolsmiths.validation.common.checkers.IPluginChecker2;
import org.eclipse.papyrus.toolsmiths.validation.common.internal.utils.ArchitectureIndex;
import org.eclipse.pde.core.plugin.IPluginElement;
@@ -70,6 +77,9 @@ public class ArchitectureCustomValidator extends CustomModelChecker.SwitchValida
if (architecture.getId() != null) { // Missing ID is reported separately
architecture.getElementTypes().forEach(typeSet -> validateElementTypesContextID(architecture, typeSet, diagnostics, context));
}
+ if (!architecture.isExtension()) {
+ validateContextHasRepresentationsAdvice(architecture, diagnostics, context);
+ }
}
private void validateElementTypesContextID(ArchitectureContext architecture, ElementTypeSetConfiguration typeSet, DiagnosticChain diagnostics, Map<Object, Object> context) {
@@ -151,6 +161,44 @@ public class ArchitectureCustomValidator extends CustomModelChecker.SwitchValida
return ArchitectureIndex.getInstance().isReferenced(context, ArchitecturePackage.Literals.ARCHITECTURE_CONTEXT__EXTENDED_CONTEXTS);
}
+ /**
+ * Check whether an {@code architecture} references the <em>Element Types Configurations</em> model that provides the
+ * representations advice, whether itself, or by inheritance or extension.
+ */
+ void validateContextHasRepresentationsAdvice(ArchitectureContext architecture, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ boolean hasAdvice = hasRepresentationsAdvice(architecture);
+ if (!hasAdvice && architecture.getGeneralContext() != null) {
+ // Does not need to be recursive because extension content is not inherited
+ hasAdvice = architecture.allGeneralContexts().stream().anyMatch(this::hasRepresentationsAdvice);
+ }
+ if (!hasAdvice && hasExtensions(architecture)) {
+ hasAdvice = ArchitectureIndex.getInstance().getAllExtensions(architecture).stream().anyMatch(this::hasOrInheritsRepresentationsAdvice);
+ }
+
+ if (!hasAdvice) {
+ diagnostics.add(createDiagnostic(Diagnostic.WARNING, architecture, ArchitecturePackage.Literals.ARCHITECTURE_CONTEXT__ELEMENT_TYPES,
+ format(Messages.ArchitectureCustomValidator_0, context, architecture),
+ IPluginChecker2.problem(ArchitecturePluginValidationConstants.MISSING_REPRESENTATIONS_ADVICE_ID)));
+ }
+ }
+
+ private boolean hasOrInheritsRepresentationsAdvice(ArchitectureContext architecture) {
+ boolean result = hasRepresentationsAdvice(architecture);
+ if (!result && architecture.getGeneralContext() != null) {
+ result = architecture.allGeneralContexts().stream().anyMatch(this::hasRepresentationsAdvice);
+ }
+ return result;
+ }
+
+ private boolean hasRepresentationsAdvice(ArchitectureContext architecture) {
+ URIConverter converter = EMFHelper.getResourceSet(architecture).getURIConverter();
+ URI normalized = converter.normalize(ArchitecturePluginValidationConstants.REPRESENTATIONS_ADVICE_URI);
+
+ @SuppressWarnings("unchecked")
+ EList<? extends EObject> representations = (EList<? extends EObject>) architecture.eGet(ArchitecturePackage.Literals.ARCHITECTURE_CONTEXT__ELEMENT_TYPES, false);
+ return representations.stream().map(EcoreUtil::getURI).map(URI::trimFragment).map(converter::normalize).anyMatch(normalized::equals);
+ }
+
//
// Nested types
//
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureDependencies.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureDependencies.java
index 6ad1c950150..e6eca97cd14 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureDependencies.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/checkers/ArchitectureDependencies.java
@@ -94,7 +94,7 @@ class ArchitectureDependencies {
bundleName = Optional.empty();
}
- return URI.createURI(String.format("bundleclass://%s/%s", bundleName.orElse(hostBundle), className));
+ return URI.createURI(String.format("bundleclass://%s/%s", bundleName.orElse(hostBundle), className)); //$NON-NLS-1$
}
}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/Messages.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/Messages.java
index 68c4375484c..3b9aba8615b 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/Messages.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/Messages.java
@@ -22,6 +22,7 @@ import org.eclipse.osgi.util.NLS;
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.papyrus.toolsmiths.validation.architecture.internal.messages.messages"; //$NON-NLS-1$
+ public static String ArchitectureCustomValidator_0;
public static String ArchitectureCustomValidator_2;
public static String ArchitectureCustomValidator_3;
public static String ArchitectureCustomValidator_4;
@@ -29,6 +30,8 @@ public class Messages extends NLS {
public static String ArchitecturePluginChecker_1;
public static String MissingArchitectureExtension_0;
public static String MissingArchitectureExtension_1;
+ public static String MissingRepresentationsAdvice_0;
+ public static String MissingRepresentationsAdvice_1;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/messages.properties b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/messages.properties
index 8b3bebe222b..15987b1439d 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/messages.properties
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/messages/messages.properties
@@ -10,10 +10,11 @@
#
# Contributors:
# CEA LIST - Initial API and implementation
-# Christian W. Damus - bugs 570097, 542945, 570486
+# Christian W. Damus - bugs 570097, 542945, 570486, 573788
#
##################################################################################
+ArchitectureCustomValidator_0=Context should have the Representations Advice: {0}.
ArchitectureCustomValidator_2=''{0}'' is registered to a different context.
ArchitectureCustomValidator_3=No viewpoint includes ''{0}'', so it is not accessible.
ArchitectureCustomValidator_4={0} will be merged implicitly with another registered under the same qualified name. \
@@ -22,3 +23,5 @@ ArchitecturePluginChecker_0=Validate Architecture plug-in
ArchitecturePluginChecker_1=Prepare plug-in validation
MissingArchitectureExtension_0=Register architecture model
MissingArchitectureExtension_1=Add a plug-in extension registering the architecture model
+MissingRepresentationsAdvice_0=Add Representations Advice
+MissingRepresentationsAdvice_1=Add a reference to the Element Types Configurations model that defined the representations advice.
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/ArchitectureMarkerResolutionGenerator.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/ArchitectureMarkerResolutionGenerator.java
index 06a2f781919..0ba87cbeec8 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/ArchitectureMarkerResolutionGenerator.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.architecture/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/ArchitectureMarkerResolutionGenerator.java
@@ -20,16 +20,27 @@ import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.A
import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants.ELEM_MODEL;
import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants.MAX_PROBLEM_ID;
import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants.MISSING_ARCHITECTURE_MODEL_EXTENSION_ID;
+import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants.MISSING_REPRESENTATIONS_ADVICE_ID;
import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants.PROBLEM_ID_BASE;
+import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants.REPRESENTATIONS_ADVICE_URI;
import static org.eclipse.papyrus.toolsmiths.validation.common.quickfix.CommonMarkerResolutionUtils.getModelPath;
import static org.eclipse.papyrus.toolsmiths.validation.common.quickfix.SimpleMissingExtensionMarkerResolution.optionalAttribute;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.core.architecture.ArchitectureContext;
+import org.eclipse.papyrus.infra.core.architecture.ArchitecturePackage;
+import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration;
+import org.eclipse.papyrus.infra.types.ElementTypesConfigurationsPackage;
import org.eclipse.papyrus.toolsmiths.validation.architecture.internal.messages.Messages;
import org.eclipse.papyrus.toolsmiths.validation.common.quickfix.CommonMarkerResolutionGenerator;
import org.eclipse.papyrus.toolsmiths.validation.common.quickfix.SimpleMissingExtensionMarkerResolution;
+import org.eclipse.papyrus.toolsmiths.validation.common.quickfix.SimpleModelEditMarkerResolution;
import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.uml2.common.util.UML2Util;
/**
* Resolution generator for markers created by the validation of <em>Architecture Description</em> models.
@@ -53,6 +64,9 @@ public class ArchitectureMarkerResolutionGenerator extends CommonMarkerResolutio
Messages.MissingArchitectureExtension_0, Messages.MissingArchitectureExtension_1,
ARCHITECTURE_EXTENSION_POINT_IDENTIFIER, ELEM_MODEL,
optionalAttribute(ATTR_PATH, m -> getModelPath(m).map(IPath::toPortableString))));
+ case MISSING_REPRESENTATIONS_ADVICE_ID:
+ return only(SimpleModelEditMarkerResolution.create(problemID, Messages.MissingRepresentationsAdvice_0, Messages.MissingRepresentationsAdvice_1,
+ ArchitectureContext.class, this::getAddRepresentationsAdviceCommand));
default:
return noResolutions();
}
@@ -64,4 +78,9 @@ public class ArchitectureMarkerResolutionGenerator extends CommonMarkerResolutio
|| matchProblemID(marker, PROBLEM_ID_BASE, MAX_PROBLEM_ID);
}
+ private Command getAddRepresentationsAdviceCommand(EditingDomain domain, ArchitectureContext context) {
+ ElementTypeSetConfiguration set = UML2Util.load(domain.getResourceSet(), REPRESENTATIONS_ADVICE_URI, ElementTypesConfigurationsPackage.Literals.ELEMENT_TYPE_SET_CONFIGURATION);
+ return AddCommand.create(domain, context, ArchitecturePackage.Literals.ARCHITECTURE_CONTEXT__ELEMENT_TYPES, set);
+ }
+
}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF
index 4f4c31cf116..b11ce9feb2e 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF
@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.emf.transaction;bundle-version="[1.9.0,2.0.0)",
org.eclipse.papyrus.emf;bundle-version="[2.0.0,3.0.0)",
org.eclipse.ui.ide;bundle-version="[3.18.0,4.0.0)",
org.eclipse.papyrus.eclipse.project.editors;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.pde.ui;bundle-version="[3.12.100,4.0.0)"
+ org.eclipse.pde.ui;bundle-version="[3.12.100,4.0.0)",
+ org.eclipse.emf.edit;bundle-version="[2.16.0,3.0.0)"
Export-Package: org.eclipse.papyrus.toolsmiths.validation.common,
org.eclipse.papyrus.toolsmiths.validation.common.checkers,
org.eclipse.papyrus.toolsmiths.validation.common.internal.utils;x-friends:="org.eclipse.papyrus.toolsmiths.validation.elementtypes,org.eclipse.papyrus.toolsmiths.validation.architecture,org.eclipse.papyrus.toolsmiths.validation.profile",
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/CustomModelChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/CustomModelChecker.java
index 76e5bf3cc54..ba20d93c23d 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/CustomModelChecker.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/CustomModelChecker.java
@@ -51,6 +51,8 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.toolsmiths.validation.common.Activator;
import org.eclipse.papyrus.toolsmiths.validation.common.internal.messages.Messages;
+import com.google.common.collect.Lists;
+
/**
* <p>
* A configurable model checker that recursively walks the model to evaluate custom
@@ -378,6 +380,21 @@ public class CustomModelChecker extends AbstractPluginChecker {
return result;
}
+ protected Diagnostic createDiagnostic(int severity, EObject eObject, String message, MarkerAttribute attr1, MarkerAttribute... moreAttrs) {
+ return createDiagnostic(severity, eObject, null, 0, message, attr1, moreAttrs);
+ }
+
+ protected Diagnostic createDiagnostic(int severity, EObject eObject, EStructuralFeature feature, String message, MarkerAttribute attr1, MarkerAttribute... moreAttrs) {
+ return createDiagnostic(severity, eObject, feature, 0, message, attr1, moreAttrs);
+ }
+
+ protected Diagnostic createDiagnostic(int severity, EObject eObject, EStructuralFeature feature, int code, String message, MarkerAttribute attr1, MarkerAttribute... moreAttrs) {
+ List<Object> data = diagnosticData(eObject, feature);
+ data.addAll(Lists.asList(attr1, moreAttrs));
+
+ return new BasicDiagnostic(severity, source, code, message, data.toArray());
+ }
+
protected boolean isValidatorFor(EPackage ePackage) {
return nsURI.equals(ePackage.getNsURI());
}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/internal/utils/ArchitectureIndex.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/internal/utils/ArchitectureIndex.java
index a18c8dc4411..0a1eded8873 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/internal/utils/ArchitectureIndex.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/internal/utils/ArchitectureIndex.java
@@ -15,11 +15,15 @@
package org.eclipse.papyrus.toolsmiths.validation.common.internal.utils;
+import java.util.ArrayDeque;
import java.util.Collection;
import java.util.EnumMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
+import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -41,9 +45,11 @@ import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager;
import org.eclipse.papyrus.infra.core.architecture.ADElement;
+import org.eclipse.papyrus.infra.core.architecture.ArchitectureContext;
import org.eclipse.papyrus.infra.core.architecture.ArchitectureDomain;
import org.eclipse.papyrus.infra.core.architecture.ArchitecturePackage;
import org.eclipse.papyrus.infra.core.utils.JobExecutorService;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.emf.utils.InternalCrossReferencer;
import org.eclipse.papyrus.toolsmiths.validation.common.Activator;
@@ -413,6 +419,43 @@ public class ArchitectureIndex {
return result.build();
}
+ public Collection<ArchitectureContext> getAllExtensions(ArchitectureContext context) {
+ try {
+ return getAllExtensionsAsync(context).get();
+ } catch (InterruptedException | ExecutionException e) {
+ Activator.log.error("Error querying Architecture Context models.", e); //$NON-NLS-1$
+ return List.of();
+ }
+ }
+
+ public CompletableFuture<Collection<ArchitectureContext>> getAllExtensionsAsync(ArchitectureContext context) {
+ return getInternalCrossReferences().thenApply(xrefs -> {
+ Collection<ArchitectureContext> result = new LinkedHashSet<>();
+ Queue<ArchitectureContext> queue = new ArrayDeque<>(getExtensions(context, xrefs));
+
+ for (ArchitectureContext next = queue.poll(); next != null; next = queue.poll()) {
+ if (result.add(next)) {
+ queue.addAll(getExtensions(next, xrefs));
+ }
+ }
+
+ return result;
+ });
+ }
+
+ private Collection<ArchitectureContext> getExtensions(ArchitectureContext context, Multimap<EObject, EStructuralFeature.Setting> xrefs) {
+ UserSpaceMapping mapping = new UserSpaceMapping(context);
+
+ return xrefs.get(mapping.toIndexSpace(context)).stream()
+ .filter(setting -> setting.getEStructuralFeature() == ArchitecturePackage.Literals.ARCHITECTURE_CONTEXT__EXTENDED_CONTEXTS)
+ .map(EStructuralFeature.Setting::getEObject)
+ .map(ArchitectureContext.class::cast)
+ .distinct()
+ .map(mapping::toUserSpace)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ }
+
//
// Nested types
//
@@ -464,4 +507,35 @@ public class ArchitectureIndex {
}
+ /**
+ * A bijection of objects in user space and index space, being the resource set of the client
+ * component and the resource set of the index, respectively.
+ */
+ private final class UserSpaceMapping {
+ private final ResourceSet userContext;
+ private final ResourceSet indexContext;
+
+ UserSpaceMapping(EObject userContext) {
+ super();
+
+ this.userContext = EMFHelper.getResourceSet(userContext);
+ this.indexContext = domainManager.getRegisteredArchitectureDomains().stream()
+ .map(EMFHelper::getResourceSet)
+ .filter(Objects::nonNull)
+ .findAny()
+ .orElse(null);
+ }
+
+ @SuppressWarnings("unchecked")
+ <T extends EObject> T toUserSpace(T indexObject) {
+ return (T) userContext.getEObject(EcoreUtil.getURI(indexObject), true);
+ }
+
+ @SuppressWarnings("unchecked")
+ <T extends EObject> T toIndexSpace(T userObject) {
+ return (indexContext == null) ? null : (T) indexContext.getEObject(EcoreUtil.getURI(userObject), true);
+ }
+
+ }
+
}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/CommonMarkerResolutionUtils.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/CommonMarkerResolutionUtils.java
index c07cc68bb0b..5c0d5fc1dfb 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/CommonMarkerResolutionUtils.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/CommonMarkerResolutionUtils.java
@@ -10,19 +10,34 @@
*
* Contributors:
* Christian W. Damus - Initial API and implementation
- * Christian W. Damus - bug 570097
+ * Christian W. Damus - bugs 570097, 573788
*
*****************************************************************************/
package org.eclipse.papyrus.toolsmiths.validation.common.quickfix;
import java.util.Optional;
+import java.util.stream.Stream;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.papyrus.toolsmiths.validation.common.checkers.CommonProblemConstants;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
/**
* Helper class with utility methods used by {@linkplain IMarkerResolution marker resolutions}.
@@ -39,4 +54,43 @@ public final class CommonMarkerResolutionUtils {
return Optional.ofNullable(marker.getAttribute(CommonProblemConstants.MODEL_PATH, null)).map(Path::new);
}
+ /** Get the object of the given {@code type} from an editing {@code domain}, identified by the URI in the {@code marker}. */
+ public static <T extends EObject> Optional<T> getModelObject(IMarker marker, Class<T> type, EditingDomain domain) {
+ String targetURI = marker.getAttribute(EValidator.URI_ATTRIBUTE, null);
+ return Optional.ofNullable(targetURI).map(uri -> URI.createURI(uri, true))
+ .map(uri -> domain.getResourceSet().getEObject(uri, true))
+ .filter(type::isInstance)
+ .map(type::cast);
+ }
+
+ /** Get the editing domain from an editor that is currently open on the resource of a {@code marker}, if any. */
+ public static Optional<EditingDomain> getOpenEditingDomain(IMarker marker) {
+ IResource resource = marker.getResource();
+ if (!(resource instanceof IFile) || !PlatformUI.isWorkbenchRunning()) {
+ return Optional.empty();
+ }
+
+ IEditorInput editorInput = new FileEditorInput((IFile) resource);
+
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ return Stream.of(windows).map(IWorkbenchWindow::getActivePage)
+ .flatMap(page -> Stream.of(page.findEditors(editorInput, null, IWorkbenchPage.MATCH_INPUT)))
+ .map(CommonMarkerResolutionUtils::getEditingDomain)
+ .findAny();
+ }
+
+ private static EditingDomain getEditingDomain(IEditorReference editorRef) {
+ EditingDomain result = null;
+
+ IEditorPart editor = editorRef.getEditor(true);
+ if (editor instanceof IEditingDomainProvider) {
+ result = ((IEditingDomainProvider) editor).getEditingDomain();
+ }
+ if (result == null && editor != null) {
+ result = editor.getAdapter(EditingDomain.class);
+ }
+
+ return result;
+ }
+
}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/SimpleModelEditMarkerResolution.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/SimpleModelEditMarkerResolution.java
new file mode 100644
index 00000000000..e81d0348701
--- /dev/null
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/quickfix/SimpleModelEditMarkerResolution.java
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * Copyright (c) 2021 Christian W. Damus, CEA LIST, and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.toolsmiths.validation.common.quickfix;
+
+import java.io.IOException;
+import java.util.Optional;
+import java.util.function.BiFunction;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.emf.common.command.BasicCommandStack;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.toolsmiths.validation.common.Activator;
+
+/**
+ * A marker resolution that resolves a problem by means of an EMF {@link Command}
+ * that edits the model.
+ *
+ * @param <T>
+ * the model object class on which I resolve the problem
+ */
+public class SimpleModelEditMarkerResolution<T extends EObject> extends AbstractPapyrusWorkbenchMarkerResolution {
+
+ private final String label;
+ private final String description;
+
+ private final Class<T> type;
+ private final BiFunction<? super EditingDomain, ? super T, ? extends Command> commandFunction;
+
+ protected SimpleModelEditMarkerResolution(int problemID, String label, String description, Class<T> type, BiFunction<? super EditingDomain, ? super T, ? extends Command> commandFunction) {
+ super(problemID);
+
+ this.label = label;
+ this.description = description;
+ this.type = type;
+ this.commandFunction = commandFunction;
+ }
+
+ /**
+ * Create a new marker resolution that edits the model.
+ *
+ * @param <T>
+ * the kind of object to edit
+ * @param problemID
+ * my marker resolution problem ID
+ * @param label
+ * a label to present to the user for the marker resolution
+ * @param description
+ * a description of the marker resolution to present to the user
+ * @param type
+ * the type of object to edit to resolve the marker
+ * @param commandFunction
+ * a function that creates a command to edit the object. It will receive an editing domain either from
+ * an existing open editor or created on-the-fly for an off-line edit, plus the object loaded in that domain to edit
+ *
+ * @return the marker resolution
+ */
+ public static <T extends EObject> SimpleModelEditMarkerResolution<T> create(int problemID, String label, String description, Class<T> type, BiFunction<? super EditingDomain, ? super T, ? extends Command> commandFunction) {
+ return new SimpleModelEditMarkerResolution<>(problemID, label, description, type, commandFunction);
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public void run(IMarker marker) {
+ Optional<EditingDomain> openDomain = CommonMarkerResolutionUtils.getOpenEditingDomain(marker);
+ EditingDomain domain = openDomain.orElseGet(() -> new AdapterFactoryEditingDomain(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE), new BasicCommandStack()));
+
+ try {
+ CommonMarkerResolutionUtils.getModelObject(marker, type, domain).ifPresent(object -> {
+ Command command = commandFunction.apply(domain, object);
+ if (command != null) {
+ domain.getCommandStack().execute(command);
+ }
+ });
+ } finally {
+ if (openDomain.isEmpty()) {
+ // We created a domain. Save the changes and unload it
+ ResourceSet rset = domain.getResourceSet();
+ if (!rset.getResources().isEmpty()) {
+ try {
+ rset.getResources().get(0).save(null);
+ } catch (IOException e) {
+ Activator.log.error("Failed to save marker resolution.", e); //$NON-NLS-1$
+ }
+ }
+
+ EMFHelper.unload(domain.getResourceSet());
+ ((ComposedAdapterFactory) ((AdapterFactoryEditingDomain) domain).getAdapterFactory()).dispose();
+ }
+ }
+ }
+
+}
diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/.classpath b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/.classpath
index e801ebfb468..c2a9d38066d 100644
--- a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/.classpath
+++ b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/.classpath
@@ -1,7 +1,15 @@
<?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-11"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
+ <attributes>
+ <attribute name="module" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/papyrus/infra/viewpoints/internal/**"/>
+ </accessrules>
+ </classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF
index 4eb30d2f565..1623cf6cbc1 100644
--- a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF
@@ -1,5 +1,6 @@
Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.infra.viewpoints.policy.tests
+Export-Package: org.eclipse.papyrus.infra.viewpoints.internal.policy.advice.tests;x-internal:=true,
+ org.eclipse.papyrus.infra.viewpoints.policy.tests
Require-Bundle: org.eclipse.emf.databinding;bundle-version="[1.5.0,2.0.0)",
org.eclipse.emf.edit.ui;bundle-version="[2.18.0,3.0.0)",
org.eclipse.gmf.runtime.emf.type.core;bundle-version="[1.9.0,2.0.0)",
diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/internal/policy/advice/tests/RepresentationDependencyAdviceTest.java b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/internal/policy/advice/tests/RepresentationDependencyAdviceTest.java
new file mode 100644
index 00000000000..f39fde0865d
--- /dev/null
+++ b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/internal/policy/advice/tests/RepresentationDependencyAdviceTest.java
@@ -0,0 +1,116 @@
+/*****************************************************************************
+ * Copyright (c) 2021 Christian W. Damus, CEA LIST, and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.viewpoints.internal.policy.advice.tests;
+
+import static org.eclipse.papyrus.junit.matchers.MoreMatchers.lessThan;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.viewpoints.internal.policy.advice.RepresentationDependencyAdvice;
+import org.eclipse.papyrus.infra.viewpoints.policy.NotationUtils;
+import org.eclipse.papyrus.junit.utils.rules.ModelSetFixture;
+import org.eclipse.papyrus.junit.utils.rules.PluginResource;
+import org.eclipse.papyrus.junit.utils.rules.ServiceRegistryModelSetFixture;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.util.UMLUtil;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Test cases for the {@link RepresentationDependencyAdviceTest} class.
+ */
+@PluginResource("/resources/owned-views.di")
+public class RepresentationDependencyAdviceTest {
+
+ private static final String STATE_MACHINE = "model::Class1::StateMachine1"; //$NON-NLS-1$
+
+ @Rule
+ public final ModelSetFixture modelSet = new ServiceRegistryModelSetFixture();
+
+ public RepresentationDependencyAdviceTest() {
+ super();
+ }
+
+ @Test
+ public void destroyDependentOwnedView() {
+ NamedElement stateMachine = getElement(STATE_MACHINE);
+ EObject diagram = getDiagram();
+
+ DestroyDependentsRequest request = destroyDependents(stateMachine);
+ process(request);
+
+ assertThat("Owned diagram not deleted by the advice.", diagram.eResource(), nullValue());
+ }
+
+ @Test
+ @PluginResource("/resources/unowned-views.di")
+ public void destroyDependentUnownedView() {
+ NamedElement stateMachine = getElement(STATE_MACHINE);
+ EObject diagram = getDiagram();
+
+ DestroyDependentsRequest request = destroyDependents(stateMachine);
+ process(request);
+
+ assertThat("Unowned diagram not deleted by the advice.", diagram.eResource(), nullValue());
+ }
+
+ //
+ // Test framework
+ //
+
+ NamedElement getElement(String qualifiedName) {
+ return UMLUtil.findNamedElements(modelSet.getModelResource(), STATE_MACHINE).iterator().next();
+ }
+
+ EObject getDiagram() {
+ return getDiagram(0);
+ }
+
+ EObject getDiagram(int index) {
+ Iterator<EObject> notations = NotationUtils.getNotationRoots(modelSet.getRoot());
+ for (int i = 0; i < index; i++) {
+ notations.next();
+ }
+ return notations.next();
+ }
+
+ DestroyDependentsRequest destroyDependents(EObject object) {
+ return new DestroyDependentsRequest(modelSet.getEditingDomain(), object, false);
+ }
+
+ void process(IEditCommandRequest request) {
+ IEditHelperAdvice advice = new RepresentationDependencyAdvice();
+ ICommand before = advice.getBeforeEditCommand(request);
+ ICommand after = advice.getAfterEditCommand(request);
+
+ ICommand composed = CompositeCommand.compose(before, after);
+
+ if (composed != null && composed.canExecute()) {
+ IStatus status = modelSet.execute(composed);
+ assertThat("Command execution failed.", status.getSeverity(), lessThan(IStatus.ERROR));
+ }
+ }
+
+}
diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java
index 20c42c4c553..5e15c7b763a 100644
--- a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java
+++ b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java
@@ -1,6 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2016 Christian W. Damus and others.
- *
+ * Copyright (c) 2016, 2021 Christian W. Damus, CEA LIST, and others.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -10,11 +10,12 @@
*
* Contributors:
* Christian W. Damus - Initial API and implementation
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.infra.viewpoints.policy.tests;
+import org.eclipse.papyrus.infra.viewpoints.internal.policy.advice.tests.RepresentationDependencyAdviceTest;
import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite;
import org.eclipse.papyrus.junit.framework.runner.Headless;
import org.junit.runner.RunWith;
@@ -25,9 +26,10 @@ import org.junit.runners.Suite.SuiteClasses;
*/
@RunWith(ClassificationSuite.class)
@SuiteClasses({
- ViewPrototypeTest.class,
- PolicyCheckerTest.class
- })
+ ViewPrototypeTest.class,
+ PolicyCheckerTest.class,
+ RepresentationDependencyAdviceTest.class,
+})
@Headless
public class AllTests {
}
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/.classpath b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/.classpath
index e801ebfb468..a1bdb036c0f 100644
--- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/.classpath
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/.classpath
@@ -1,7 +1,15 @@
<?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-11"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
+ <attributes>
+ <attribute name="module" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/papyrus/toolsmiths/validation/architecture/internal/**"/>
+ </accessrules>
+ </classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/META-INF/MANIFEST.MF
index da69b436fb5..c6f70900c74 100644
--- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/META-INF/MANIFEST.MF
@@ -17,8 +17,10 @@ Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="[2.18.0,3.0.0)",
org.eclipse.papyrus.toolsmiths.validation.common;bundle-version="[2.0.0,3.0.0)",
org.eclipse.uml2.uml;bundle-version="[5.5.0,6.0.0)",
org.eclipse.papyrus.toolsmiths.validation.common.tests;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.papyrus.uml.diagram.clazz;bundle-version="[4.0.0,5.0.0)"
-Export-Package: org.eclipse.papyrus.toolsmiths.validation.architecture.tests
+ org.eclipse.papyrus.uml.diagram.clazz;bundle-version="[4.0.0,5.0.0)",
+ org.eclipse.ui.ide;bundle-version="[3.18.0,4.0.0)"
+Export-Package: org.eclipse.papyrus.toolsmiths.validation.architecture.internal.quickfix.tests;x-internal:=true,
+ org.eclipse.papyrus.toolsmiths.validation.architecture.tests
Automatic-Module-Name: org.eclipse.papyrus.toolsmiths.validation.architecture.tests
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice-extension.architecture b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice-extension.architecture
new file mode 100644
index 00000000000..9000e02f280
--- /dev/null
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice-extension.architecture
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<architecture:ArchitectureDomain xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:architecture="http://www.eclipse.org/papyrus/infra/core/architecture" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:elementtypesconfigurations="http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2" xmlns:gmfdiagrepresentation="http://www.eclipse.org/papyrus/infra/gmfdiag/representation" xmlns:paletteconfiguration="http://www.eclipse.org/papyrus/diagram/paletteconfiguration/0.8" xmlns:representation="http://www.eclipse.org/papyrus/infra/core/architecture/representation" xmi:id="_W0vj0FG2EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstore" name="BookStore" description="Example architecture domain for testing: a book store modeling language." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png">
+ <stakeholders xmi:type="architecture:Stakeholder" xmi:id="_zYz54FG5EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookvendor" name="Book Vendor" description="A seeler of books, in a bookstore." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g"/>
+ <concerns xmi:type="architecture:Concern" xmi:id="_95r3oFG5EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookselling" name="Book Selling" description="The concern of selling books, in a book store." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png"/>
+ <contexts xmi:type="architecture:ArchitectureDescriptionLanguage" xmi:id="_Ty_tQFG6EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstorelang.extension" name="BookStore Extension" icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" defaultViewpoints="_fnEJgFHAEeuwtJo37XL9OQ" extensionPrefix="bookstore" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateBookstoreModelCommand">
+ <viewpoints xmi:type="architecture:ArchitectureViewpoint" xmi:id="_fnEJgFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstoremanagement" name="BookStore Management" description="The viewpoint of the book store manager who needs to track inventory." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g" representationKinds="_u1T1UFHAEeuwtJo37XL9OQ"/>
+ <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.elementtypesconfigurations#_c0DGsGBhEemoFuWBTUmJOQ"/>
+ <extendedContexts xmi:type="architecture:ArchitectureDescriptionLanguage" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice.architecture#_Ty_tQFG6EeuXzM4mqVly4g"/>
+ <representationKinds xmi:type="gmfdiagrepresentation:PapyrusDiagram" xmi:id="_u1T1UFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.inventory" name="InventoryDiagram" description="Book store inventory diagram." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" concerns="_95r3oFG5EeuXzM4mqVly4g" grayedIcon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore_d.png" implementationID="org.eclipse.papyrus.toolsmiths.validation.architecture.example.InventoryDiagram" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateInventoryDiagramCommand">
+ <modelRules xmi:type="representation:ModelRule" xmi:id="__8BXQFHDEeuwtJo37XL9OQ" permit="true" elementMultiplicity="1" multiplicity="-1">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cBFG7EeuXzM4mqVly4g"/>
+ </modelRules>
+ <owningRules xmi:type="representation:OwningRule" xmi:id="_GnAokFHEEeuwtJo37XL9OQ" permit="true" multiplicity="-1">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cBFG7EeuXzM4mqVly4g"/>
+ </owningRules>
+ <childRules xmi:type="gmfdiagrepresentation:ChildRule" xmi:id="_LyaWcFHEEeuwtJo37XL9OQ" permit="true">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cDFG7EeuXzM4mqVly4g"/>
+ <origin xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </childRules>
+ <childRules xmi:type="gmfdiagrepresentation:ChildRule" xmi:id="_TjwL0FHEEeuwtJo37XL9OQ" permit="true">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cCFG7EeuXzM4mqVly4g"/>
+ <origin xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </childRules>
+ <palettes xmi:type="paletteconfiguration:PaletteConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.paletteconfiguration#/"/>
+ </representationKinds>
+ <metamodel xmi:type="ecore:EPackage" href="http://www.eclipse.org/uml2/5.0.0/UML#/"/>
+ <profiles xmi:type="ecore:EPackage" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cAVG7EeuXzM4mqVly4g"/>
+ </contexts>
+</architecture:ArchitectureDomain>
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice.architecture b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice.architecture
new file mode 100644
index 00000000000..a00a218ab17
--- /dev/null
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-noRepresentationsAdvice.architecture
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<architecture:ArchitectureDomain xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:architecture="http://www.eclipse.org/papyrus/infra/core/architecture" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:elementtypesconfigurations="http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2" xmlns:gmfdiagrepresentation="http://www.eclipse.org/papyrus/infra/gmfdiag/representation" xmlns:paletteconfiguration="http://www.eclipse.org/papyrus/diagram/paletteconfiguration/0.8" xmlns:representation="http://www.eclipse.org/papyrus/infra/core/architecture/representation" xmi:id="_W0vj0FG2EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstore" name="BookStore" description="Example architecture domain for testing: a book store modeling language." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png">
+ <stakeholders xmi:type="architecture:Stakeholder" xmi:id="_zYz54FG5EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookvendor" name="Book Vendor" description="A seeler of books, in a bookstore." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g"/>
+ <concerns xmi:type="architecture:Concern" xmi:id="_95r3oFG5EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookselling" name="Book Selling" description="The concern of selling books, in a book store." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png"/>
+ <contexts xmi:type="architecture:ArchitectureDescriptionLanguage" xmi:id="_Ty_tQFG6EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstorelang" name="BookStore" icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" defaultViewpoints="_fnEJgFHAEeuwtJo37XL9OQ" extensionPrefix="bookstore" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateBookstoreModelCommand">
+ <viewpoints xmi:type="architecture:ArchitectureViewpoint" xmi:id="_fnEJgFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstoremanagement" name="BookStore Management" description="The viewpoint of the book store manager who needs to track inventory." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g" representationKinds="_u1T1UFHAEeuwtJo37XL9OQ"/>
+ <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.elementtypesconfigurations#_c0DGsGBhEemoFuWBTUmJOQ"/>
+ <representationKinds xmi:type="gmfdiagrepresentation:PapyrusDiagram" xmi:id="_u1T1UFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.inventory" name="InventoryDiagram" description="Book store inventory diagram." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" concerns="_95r3oFG5EeuXzM4mqVly4g" grayedIcon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore_d.png" implementationID="org.eclipse.papyrus.toolsmiths.validation.architecture.example.InventoryDiagram" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateInventoryDiagramCommand">
+ <modelRules xmi:type="representation:ModelRule" xmi:id="__8BXQFHDEeuwtJo37XL9OQ" permit="true" elementMultiplicity="1" multiplicity="-1">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cBFG7EeuXzM4mqVly4g"/>
+ </modelRules>
+ <owningRules xmi:type="representation:OwningRule" xmi:id="_GnAokFHEEeuwtJo37XL9OQ" permit="true" multiplicity="-1">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cBFG7EeuXzM4mqVly4g"/>
+ </owningRules>
+ <childRules xmi:type="gmfdiagrepresentation:ChildRule" xmi:id="_LyaWcFHEEeuwtJo37XL9OQ" permit="true">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cDFG7EeuXzM4mqVly4g"/>
+ <origin xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </childRules>
+ <childRules xmi:type="gmfdiagrepresentation:ChildRule" xmi:id="_TjwL0FHEEeuwtJo37XL9OQ" permit="true">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cCFG7EeuXzM4mqVly4g"/>
+ <origin xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </childRules>
+ <palettes xmi:type="paletteconfiguration:PaletteConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.paletteconfiguration#/"/>
+ </representationKinds>
+ <metamodel xmi:type="ecore:EPackage" href="http://www.eclipse.org/uml2/5.0.0/UML#/"/>
+ <profiles xmi:type="ecore:EPackage" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cAVG7EeuXzM4mqVly4g"/>
+ </contexts>
+</architecture:ArchitectureDomain>
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-representationsAdviceByExtension.architecture b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-representationsAdviceByExtension.architecture
new file mode 100644
index 00000000000..c0b7c8e709e
--- /dev/null
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-representationsAdviceByExtension.architecture
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<architecture:ArchitectureDomain xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:architecture="http://www.eclipse.org/papyrus/infra/core/architecture" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:elementtypesconfigurations="http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2" xmlns:gmfdiagrepresentation="http://www.eclipse.org/papyrus/infra/gmfdiag/representation" xmlns:paletteconfiguration="http://www.eclipse.org/papyrus/diagram/paletteconfiguration/0.8" xmlns:representation="http://www.eclipse.org/papyrus/infra/core/architecture/representation" xmi:id="_W0vj0FG2EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstore" name="BookStore" description="Example architecture domain for testing: a book store modeling language." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png">
+ <stakeholders xmi:type="architecture:Stakeholder" xmi:id="_zYz54FG5EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookvendor" name="Book Vendor" description="A seeler of books, in a bookstore." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g"/>
+ <concerns xmi:type="architecture:Concern" xmi:id="_95r3oFG5EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookselling" name="Book Selling" description="The concern of selling books, in a book store." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png"/>
+ <contexts xmi:type="architecture:ArchitectureDescriptionLanguage" xmi:id="_Ty_tQFG6EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstorelang" name="BookStore" icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" defaultViewpoints="_fnEJgFHAEeuwtJo37XL9OQ" extensionPrefix="bookstore" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateBookstoreModelCommand">
+ <viewpoints xmi:type="architecture:ArchitectureViewpoint" xmi:id="_fnEJgFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstoremanagement" name="BookStore Management" description="The viewpoint of the book store manager who needs to track inventory." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g" representationKinds="_u1T1UFHAEeuwtJo37XL9OQ"/>
+ <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.elementtypesconfigurations#_c0DGsGBhEemoFuWBTUmJOQ"/>
+ <representationKinds xmi:type="gmfdiagrepresentation:PapyrusDiagram" xmi:id="_u1T1UFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.inventory" name="InventoryDiagram" description="Book store inventory diagram." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" concerns="_95r3oFG5EeuXzM4mqVly4g" grayedIcon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore_d.png" implementationID="org.eclipse.papyrus.toolsmiths.validation.architecture.example.InventoryDiagram" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateInventoryDiagramCommand">
+ <modelRules xmi:type="representation:ModelRule" xmi:id="__8BXQFHDEeuwtJo37XL9OQ" permit="true" elementMultiplicity="1" multiplicity="-1">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cBFG7EeuXzM4mqVly4g"/>
+ </modelRules>
+ <owningRules xmi:type="representation:OwningRule" xmi:id="_GnAokFHEEeuwtJo37XL9OQ" permit="true" multiplicity="-1">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cBFG7EeuXzM4mqVly4g"/>
+ </owningRules>
+ <childRules xmi:type="gmfdiagrepresentation:ChildRule" xmi:id="_LyaWcFHEEeuwtJo37XL9OQ" permit="true">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cDFG7EeuXzM4mqVly4g"/>
+ <origin xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </childRules>
+ <childRules xmi:type="gmfdiagrepresentation:ChildRule" xmi:id="_TjwL0FHEEeuwtJo37XL9OQ" permit="true">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cCFG7EeuXzM4mqVly4g"/>
+ <origin xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </childRules>
+ <palettes xmi:type="paletteconfiguration:PaletteConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.paletteconfiguration#/"/>
+ </representationKinds>
+ <metamodel xmi:type="ecore:EPackage" href="http://www.eclipse.org/uml2/5.0.0/UML#/"/>
+ <profiles xmi:type="ecore:EPackage" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cAVG7EeuXzM4mqVly4g"/>
+ </contexts>
+ <contexts xmi:type="architecture:ArchitectureDescriptionLanguage" xmi:id="_6rbE8L8fEeuhfp4rJgXr8w" name="Extension" extendedContexts="_Ty_tQFG6EeuXzM4mqVly4g">
+ <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="pathmap://PAPYRUS_VIEWPOINTS_POLICY/representations/advice#_A5utQL5PEeuDXfdzV8a7zA"/>
+ </contexts>
+</architecture:ArchitectureDomain>
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-representationsAdviceInherited.architecture b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-representationsAdviceInherited.architecture
new file mode 100644
index 00000000000..8e71202fd0c
--- /dev/null
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/bug573788-models/BookStore-representationsAdviceInherited.architecture
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<architecture:ArchitectureDomain xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:architecture="http://www.eclipse.org/papyrus/infra/core/architecture" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:elementtypesconfigurations="http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2" xmlns:gmfdiagrepresentation="http://www.eclipse.org/papyrus/infra/gmfdiag/representation" xmlns:paletteconfiguration="http://www.eclipse.org/papyrus/diagram/paletteconfiguration/0.8" xmlns:representation="http://www.eclipse.org/papyrus/infra/core/architecture/representation" xmi:id="_W0vj0FG2EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstore" name="BookStore" description="Example architecture domain for testing: a book store modeling language." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png">
+ <stakeholders xmi:type="architecture:Stakeholder" xmi:id="_zYz54FG5EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookvendor" name="Book Vendor" description="A seeler of books, in a bookstore." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g"/>
+ <concerns xmi:type="architecture:Concern" xmi:id="_95r3oFG5EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookselling" name="Book Selling" description="The concern of selling books, in a book store." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png"/>
+ <contexts xmi:type="architecture:ArchitectureDescriptionLanguage" xmi:id="_Ty_tQFG6EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstorelang" name="BookStore" icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" defaultViewpoints="_fnEJgFHAEeuwtJo37XL9OQ" extensionPrefix="bookstore" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateBookstoreModelCommand" generalContext="_ZtaEYL8iEeuhfp4rJgXr8w">
+ <viewpoints xmi:type="architecture:ArchitectureViewpoint" xmi:id="_fnEJgFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstoremanagement" name="BookStore Management" description="The viewpoint of the book store manager who needs to track inventory." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g" representationKinds="_u1T1UFHAEeuwtJo37XL9OQ"/>
+ <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.elementtypesconfigurations#_c0DGsGBhEemoFuWBTUmJOQ"/>
+ <representationKinds xmi:type="gmfdiagrepresentation:PapyrusDiagram" xmi:id="_u1T1UFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.inventory" name="InventoryDiagram" description="Book store inventory diagram." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" concerns="_95r3oFG5EeuXzM4mqVly4g" grayedIcon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore_d.png" implementationID="org.eclipse.papyrus.toolsmiths.validation.architecture.example.InventoryDiagram" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateInventoryDiagramCommand">
+ <modelRules xmi:type="representation:ModelRule" xmi:id="__8BXQFHDEeuwtJo37XL9OQ" permit="true" elementMultiplicity="1" multiplicity="-1">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cBFG7EeuXzM4mqVly4g"/>
+ </modelRules>
+ <owningRules xmi:type="representation:OwningRule" xmi:id="_GnAokFHEEeuwtJo37XL9OQ" permit="true" multiplicity="-1">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cBFG7EeuXzM4mqVly4g"/>
+ </owningRules>
+ <childRules xmi:type="gmfdiagrepresentation:ChildRule" xmi:id="_LyaWcFHEEeuwtJo37XL9OQ" permit="true">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cDFG7EeuXzM4mqVly4g"/>
+ <origin xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </childRules>
+ <childRules xmi:type="gmfdiagrepresentation:ChildRule" xmi:id="_TjwL0FHEEeuwtJo37XL9OQ" permit="true">
+ <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <stereotypes xmi:type="ecore:EClass" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cCFG7EeuXzM4mqVly4g"/>
+ <origin xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </childRules>
+ <palettes xmi:type="paletteconfiguration:PaletteConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.paletteconfiguration#/"/>
+ </representationKinds>
+ <metamodel xmi:type="ecore:EPackage" href="http://www.eclipse.org/uml2/5.0.0/UML#/"/>
+ <profiles xmi:type="ecore:EPackage" href="http://www.eclipse.org/Papyrus/test/toolsmiths/architecturebuilder/BookStore#_e24cAVG7EeuXzM4mqVly4g"/>
+ </contexts>
+ <contexts xmi:type="architecture:ArchitectureDescriptionLanguage" xmi:id="_ZtaEYL8iEeuhfp4rJgXr8w" name="General">
+ <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="pathmap://PAPYRUS_VIEWPOINTS_POLICY/representations/advice#_A5utQL5PEeuDXfdzV8a7zA"/>
+ </contexts>
+</architecture:ArchitectureDomain>
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.architecture b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.architecture
index a00a218ab17..e90bb918b97 100644
--- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.architecture
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/resources/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.architecture
@@ -5,6 +5,7 @@
<contexts xmi:type="architecture:ArchitectureDescriptionLanguage" xmi:id="_Ty_tQFG6EeuXzM4mqVly4g" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstorelang" name="BookStore" icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" defaultViewpoints="_fnEJgFHAEeuwtJo37XL9OQ" extensionPrefix="bookstore" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateBookstoreModelCommand">
<viewpoints xmi:type="architecture:ArchitectureViewpoint" xmi:id="_fnEJgFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.bookstoremanagement" name="BookStore Management" description="The viewpoint of the book store manager who needs to track inventory." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/book_vendor.png" concerns="_95r3oFG5EeuXzM4mqVly4g" representationKinds="_u1T1UFHAEeuwtJo37XL9OQ"/>
<elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/resources/BookStore.elementtypesconfigurations#_c0DGsGBhEemoFuWBTUmJOQ"/>
+ <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="pathmap://PAPYRUS_VIEWPOINTS_POLICY/representations/advice#_A5utQL5PEeuDXfdzV8a7zA"/>
<representationKinds xmi:type="gmfdiagrepresentation:PapyrusDiagram" xmi:id="_u1T1UFHAEeuwtJo37XL9OQ" id="org.eclipse.papyrus.toolsmiths.validation.architecture.example.inventory" name="InventoryDiagram" description="Book store inventory diagram." icon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore.png" concerns="_95r3oFG5EeuXzM4mqVly4g" grayedIcon="platform:/plugin/org.eclipse.papyrus.toolsmiths.validation.architecture.example/icons/full/obj16/bookstore_d.png" implementationID="org.eclipse.papyrus.toolsmiths.validation.architecture.example.InventoryDiagram" creationCommandClass="org.eclipse.papyrus.toolsmiths.validation.architecture.example.internal.commands.CreateInventoryDiagramCommand">
<modelRules xmi:type="representation:ModelRule" xmi:id="__8BXQFHDEeuwtJo37XL9OQ" permit="true" elementMultiplicity="1" multiplicity="-1">
<element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/tests/ModelQuickFixTests.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/tests/ModelQuickFixTests.java
new file mode 100644
index 00000000000..a5bc8bde0ec
--- /dev/null
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/internal/quickfix/tests/ModelQuickFixTests.java
@@ -0,0 +1,141 @@
+/*****************************************************************************
+ * Copyright (c) 2021 Christian W. Damus, CEA LIST, and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.toolsmiths.validation.architecture.internal.quickfix.tests;
+
+import static org.eclipse.papyrus.junit.matchers.MoreMatchers.greaterThanOrEqual;
+import static org.eclipse.papyrus.junit.matchers.MoreMatchers.isEmpty;
+import static org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants.ARCHITECTURE_PLUGIN_VALIDATION_MARKER_TYPE;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.papyrus.toolsmiths.validation.architecture.constants.ArchitecturePluginValidationConstants;
+import org.eclipse.papyrus.toolsmiths.validation.architecture.internal.quickfix.ArchitectureMarkerResolutionGenerator;
+import org.eclipse.papyrus.toolsmiths.validation.common.checkers.IPluginChecker2;
+import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.Build;
+import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.MarkerType;
+import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.OverlayFile;
+import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProject;
+import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProjectFixture;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Specific tests for the <em>Architecture Model</em> quick fixes.
+ */
+@TestProject("org.eclipse.papyrus.toolsmiths.validation.architecture.example")
+@MarkerType(ARCHITECTURE_PLUGIN_VALIDATION_MARKER_TYPE)
+@Build
+public class ModelQuickFixTests {
+
+ private static final String MODEL_PATH = "resources/BookStore.architecture"; //$NON-NLS-1$
+
+ private List<IMarker> modelMarkers;
+ private List<Map<String, Object>> fixedMarkers = new ArrayList<>();
+
+ /**
+ * The project fixture to manage easily the project.
+ */
+ @Rule
+ public final TestProjectFixture fixture = new TestProjectFixture();
+
+ public ModelQuickFixTests() {
+ super();
+ }
+
+ /**
+ * Test the marker resolution for the Representations Advice warning.
+ *
+ * @see <a href="https://eclip.se/573788">bug 573788</a>
+ */
+ @OverlayFile(value = "bug573788-models/BookStore-noRepresentationsAdvice.architecture", path = MODEL_PATH)
+ @Test
+ public void representationsAdviceFix() {
+ fix(ArchitecturePluginValidationConstants.MISSING_REPRESENTATIONS_ADVICE_ID);
+ }
+
+ //
+ // Test framework
+ //
+
+ @Before
+ public void initMarkers() {
+ modelMarkers = fixture.getMarkers(MODEL_PATH);
+ }
+
+ @After
+ public void verifyFixes() {
+ if (!fixedMarkers.isEmpty()) {
+ fixture.build();
+
+ Set<Map<String, Object>> newMarkerAttributes = getMarkerAttributes(fixture.getMarkers(MODEL_PATH));
+ Set<Map<String, Object>> unfixed = new HashSet<>(fixedMarkers);
+ unfixed.retainAll(newMarkerAttributes);
+
+ assertThat("Some problem(s) not fixed", unfixed, isEmpty());
+ }
+ }
+
+ Map<String, Object> getAttributes(IMarker marker) {
+ try {
+ return marker.getAttributes();
+ } catch (CoreException e) {
+ throw new AssertionError("Failed to extract marker attributes.", e);
+ }
+ }
+
+ Set<Map<String, Object>> getMarkerAttributes(Collection<? extends IMarker> markers) {
+ return markers.stream()
+ .map(this::getAttributes)
+ .collect(Collectors.toSet());
+ }
+
+ void fix(int problemID) {
+ IMarker marker = getFixableMarker(problemID);
+ Map<String, Object> attributes = getAttributes(marker);
+
+ IMarkerResolutionGenerator2 generator = new ArchitectureMarkerResolutionGenerator();
+ assertThat("No quick fix available for problem " + problemID, generator.hasResolutions(marker), is(true));
+ IMarkerResolution[] fixes = generator.getResolutions(marker);
+ assertThat("No quick fix provided by generator", fixes.length, greaterThanOrEqual(1));
+ fixes[0].run(marker);
+
+ fixedMarkers.add(attributes);
+ }
+
+ IMarker getFixableMarker(int problemID) {
+ IPluginChecker2.MarkerAttribute attr = IPluginChecker2.problem(problemID);
+ IMarker result = modelMarkers.stream().filter(m -> m.getAttribute(attr.getName(), -1) == problemID)
+ .findAny().orElse(null);
+ assertThat("Fixable problem marker not found: " + problemID, result, notNullValue());
+ return result;
+ }
+
+}
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/AllTests.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/AllTests.java
index 24ba11e90b6..82cab4c6833 100644
--- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/AllTests.java
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/AllTests.java
@@ -14,6 +14,7 @@
*****************************************************************************/
package org.eclipse.papyrus.toolsmiths.validation.architecture.tests;
+import org.eclipse.papyrus.toolsmiths.validation.architecture.internal.quickfix.tests.ModelQuickFixTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -28,6 +29,7 @@ import org.junit.runners.Suite.SuiteClasses;
ArchitectureModelBuilderTest.class,
ArchitectureDependenciesBuilderTest.class,
ArchitectureBuildPropertiesBuilderTest.class,
+ ModelQuickFixTests.class,
})
public class AllTests {
// Everything is specified in annotations
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/ArchitectureModelBuilderTest.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/ArchitectureModelBuilderTest.java
index 48cee2452ed..9244de73858 100644
--- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/ArchitectureModelBuilderTest.java
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.architecture.tests/src/org/eclipse/papyrus/toolsmiths/validation/architecture/tests/ArchitectureModelBuilderTest.java
@@ -231,6 +231,65 @@ public class ArchitectureModelBuilderTest extends AbstractPapyrusTest {
assertThat(modelMarkers, not(hasItem(isMarkerMessage(containsString("will be merged implicitly"))))); //$NON-NLS-1$
}
+
+ /**
+ * Test that validation reports a warning for an architecture context that does not
+ * reference the <em>Element Types Set Configuration</em> defining the representations advice.
+ *
+ * @see <a href="https://eclip.se/573788">bug 573788</a>
+ */
+ @OverlayFile(value = "bug573788-models/BookStore-noRepresentationsAdvice.architecture", path = "resources/BookStore.architecture")
+ @Test
+ public void representationsAdviceNotIncluded() {
+ List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$
+
+ assertThat(modelMarkers, hasItem(both(isMarkerSeverity(IMarker.SEVERITY_WARNING)).and(
+ isMarkerMessage(containsString("Representations Advice")))));
+ }
+
+ /**
+ * Test that validation does not report a warning for an architecture context that does not
+ * have the <em>Element Types Set Configuration</em> defining the representations advice
+ * by any mechanism when the context in question is an extension context.
+ *
+ * @see <a href="https://eclip.se/573788">bug 573788</a>
+ */
+ @OverlayFile(value = "bug573788-models/BookStore-noRepresentationsAdvice-extension.architecture", path = "resources/BookStore.architecture")
+ @Test
+ public void representationsAdviceNotIncluded_extension() {
+ List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$
+
+ assertThat(modelMarkers, not(hasItem(isMarkerMessage(containsString("Representations Advice"))))); //$NON-NLS-1$
+ }
+
+ /**
+ * Test that validation does not report a warning for an architecture context that inherits a
+ * reference the <em>Element Types Set Configuration</em> defining the representations advice.
+ *
+ * @see <a href="https://eclip.se/573788">bug 573788</a>
+ */
+ @OverlayFile(value = "bug573788-models/BookStore-representationsAdviceInherited.architecture", path = "resources/BookStore.architecture")
+ @Test
+ public void representationsAdvice_inherited() {
+ List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$
+
+ assertThat(modelMarkers, not(hasItem(isMarkerMessage(containsString("Representations Advice"))))); //$NON-NLS-1$
+ }
+
+ /**
+ * Test that validation reports a warning for an architecture context that has a
+ * reference to the <em>Element Types Set Configuration</em> defining the representations
+ * advice contributed by an extension.
+ *
+ * @see <a href="https://eclip.se/573788">bug 573788</a>
+ */
+ @OverlayFile(value = "bug573788-models/BookStore-representationsAdviceByExtension.architecture", path = "resources/BookStore.architecture")
+ @Test
+ public void representationsAdvice_byExtension() {
+ List<IMarker> modelMarkers = fixture.getMarkers("resources/BookStore.architecture"); //$NON-NLS-1$
+
+ assertThat(modelMarkers, not(hasItem(isMarkerMessage(containsString("Representations Advice"))))); //$NON-NLS-1$
+ }
}
}

Back to the top