diff options
| author | Laurent Fasani | 2015-06-15 15:30:45 +0000 |
|---|---|---|
| committer | Laurent Fasani | 2015-08-04 12:56:57 +0000 |
| commit | 5be107c34a8ba2e72d27203b92be004d748f28f5 (patch) | |
| tree | 9ca5211d1f180d5ef2c7ca5fddd28edb339c8efd | |
| parent | a0f13eb71060917cf8d340b793212ab1245ce461 (diff) | |
| download | org.eclipse.sirius-5be107c34a8ba2e72d27203b92be004d748f28f5.tar.gz org.eclipse.sirius-5be107c34a8ba2e72d27203b92be004d748f28f5.tar.xz org.eclipse.sirius-5be107c34a8ba2e72d27203b92be004d748f28f5.zip | |
[464269] Add completion variables for elementsToSelect interpreted expr
In completion:
- Add all variables under the tool
- Add variables from create operations
Add test cases
Bug: 464269
Change-Id: I2988aeb3492c2fef26b11dbaaf224ab3f218d99e
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
15 files changed, 478 insertions, 157 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/business/internal/diagramtype/SequenceToolInterpretedExpressionSwitch.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/business/internal/diagramtype/SequenceToolInterpretedExpressionSwitch.java index c40d19fa4f..819be959ad 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/business/internal/diagramtype/SequenceToolInterpretedExpressionSwitch.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/business/internal/diagramtype/SequenceToolInterpretedExpressionSwitch.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 THALES GLOBAL SERVICES. + * Copyright (c) 2012, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -151,6 +151,7 @@ public class SequenceToolInterpretedExpressionSwitch extends ToolSwitch<Option<C switch (getFeatureId(ToolPackage.eINSTANCE.getMessageCreationTool())) { case ToolPackage.MESSAGE_CREATION_TOOL__CONNECTION_START_PRECONDITION: case ToolPackage.MESSAGE_CREATION_TOOL__PRECONDITION: + case ToolPackage.MESSAGE_CREATION_TOOL__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: Collection<String> targets = Sets.newLinkedHashSet(); for (RepresentationElementMapping correspondingMapping : Iterables.concat(object.getEdgeMappings(), object.getExtraSourceMappings())) { @@ -175,6 +176,7 @@ public class SequenceToolInterpretedExpressionSwitch extends ToolSwitch<Option<C Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getReorderTool())) { case ToolPackage.REORDER_TOOL__PRECONDITION: + case ToolPackage.REORDER_TOOL__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: Collection<String> targets = Sets.newLinkedHashSet(); for (EventMapping correspondingMapping : object.getMappings()) { @@ -199,6 +201,7 @@ public class SequenceToolInterpretedExpressionSwitch extends ToolSwitch<Option<C Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getInstanceRoleReorderTool())) { case ToolPackage.INSTANCE_ROLE_REORDER_TOOL__PRECONDITION: + case ToolPackage.INSTANCE_ROLE_REORDER_TOOL__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: Collection<String> targets = Sets.newLinkedHashSet(); for (InstanceRoleMapping correspondingMapping : object.getMappings()) { diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramInterpretedExpressionQuery.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramInterpretedExpressionQuery.java index f40f173100..d4033f1ebd 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramInterpretedExpressionQuery.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramInterpretedExpressionQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -45,6 +45,7 @@ import org.eclipse.sirius.diagram.description.concern.ConcernPackage; import org.eclipse.sirius.diagram.description.filter.FilterPackage; import org.eclipse.sirius.diagram.description.style.StylePackage; import org.eclipse.sirius.diagram.description.tool.ContainerCreationDescription; +import org.eclipse.sirius.diagram.description.tool.CreateEdgeView; import org.eclipse.sirius.diagram.description.tool.CreateView; import org.eclipse.sirius.diagram.description.tool.DeleteElementDescription; import org.eclipse.sirius.diagram.description.tool.DirectEditLabel; @@ -56,6 +57,7 @@ import org.eclipse.sirius.ext.base.Options; import org.eclipse.sirius.viewpoint.description.RepresentationDescription; import org.eclipse.sirius.viewpoint.description.RepresentationElementMapping; import org.eclipse.sirius.viewpoint.description.tool.EditMaskVariables; +import org.eclipse.sirius.viewpoint.description.tool.ModelOperation; import org.eclipse.sirius.viewpoint.description.tool.OperationAction; import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; @@ -133,7 +135,7 @@ public class DiagramInterpretedExpressionQuery extends AbstractInterpretedExpres EditMaskVariables emv = ((DirectEditLabel) context).getMask(); appendEditMaskVariables(emv, definitions); } - // Add CreateViewn and CreateEdgeView Variable Name to available + // Add CreateView and CreateEdgeView Variable Name to available // variables if (context instanceof CreateView) { availableVariables.put(((CreateView) context).getVariableName(), VariableType.ANY_EOBJECT); @@ -166,14 +168,45 @@ public class DiagramInterpretedExpressionQuery extends AbstractInterpretedExpres Map<String, VariableType> availableVariables = super.getAvailableVariables(); - if (getToolContext().some()) { - EObject operationContext = getToolContext().get(); - if (operationContext instanceof EdgeCreationDescription) { - EdgeCreationDescription tool = (EdgeCreationDescription) operationContext; + /* + * [428757] tool variables are not displayed in autocompletion. This + * patch adds hard coded variables and hence is a temporary solution. + * The good way would be to put those metadata on the + * EdgeCreationDescription EClass in the diagram.ecore metamodel and to + * complete the AbstractInterpretedExpressionQuery to make it able to + * find specific variables for concrete types. + */ + if (target instanceof EdgeCreationDescription && ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__PRECONDITION.equals(feature)) { + availableVariables.put("diagram", VariableType.fromString("diagram.DDiagram")); + availableVariables.put("preSource", VariableType.fromString("ecore.EObject")); + availableVariables.put("preSourceView", VariableType.fromString(DIAGRAM_EDGE_TARGET_TYPE)); + availableVariables.put("preTarget", VariableType.fromString("ecore.EObject")); + availableVariables.put("preTargetView", VariableType.fromString(DIAGRAM_EDGE_TARGET_TYPE)); + } + + return availableVariables; + } + + @Override + protected void addVariableFromCreateOperation(ModelOperation modelOperation) { + super.addVariableFromCreateOperation(modelOperation); + + if (modelOperation instanceof CreateEdgeView) { + availableVariables.put(((CreateEdgeView) modelOperation).getVariableName(), VariableType.fromString("diagram.DEdge")); + } else if (modelOperation instanceof CreateView) { + availableVariables.put(((CreateView) modelOperation).getVariableName(), VariableType.fromString("viewpoint.DView")); + } + } + + @Override + protected void addVariablesFromToolContext(EObject toolContext) { + if (toolContext != null) { + if (toolContext instanceof EdgeCreationDescription) { + EdgeCreationDescription tool = (EdgeCreationDescription) toolContext; declareEdgeSourceTargets(availableVariables, tool.getEdgeMappings(), tool.getExtraSourceMappings(), tool.getExtraTargetMappings()); } - if (operationContext instanceof ReconnectEdgeDescription) { - ReconnectEdgeDescription tool = (ReconnectEdgeDescription) operationContext; + if (toolContext instanceof ReconnectEdgeDescription) { + ReconnectEdgeDescription tool = (ReconnectEdgeDescription) toolContext; declareEdgeSourceTargets(availableVariables, tool.getMappings(), Collections.<DiagramElementMapping> emptyList(), Collections.<DiagramElementMapping> emptyList()); availableVariables.put("otherEnd", VariableType.fromString(DIAGRAM_EDGE_TARGET_TYPE)); availableVariables.put("edgeView", VariableType.fromString(DIAGRAM_D_EDGE_TYPE)); @@ -185,8 +218,8 @@ public class DiagramInterpretedExpressionQuery extends AbstractInterpretedExpres refineVariableType(availableVariables, IInterpreterSiriusVariables.ELEMENT, possibleSources); } - if (operationContext instanceof NodeCreationDescription) { - NodeCreationDescription tool = (NodeCreationDescription) operationContext; + if (toolContext instanceof NodeCreationDescription) { + NodeCreationDescription tool = (NodeCreationDescription) toolContext; Collection<String> possibleSemanticTypes = Sets.newLinkedHashSet(); /* * gather types for the "container" variable. @@ -204,8 +237,8 @@ public class DiagramInterpretedExpressionQuery extends AbstractInterpretedExpres refineVariableType(availableVariables, IInterpreterSiriusVariables.CONTAINER_VIEW, possibleViewTypes); } - if (operationContext instanceof ContainerCreationDescription) { - ContainerCreationDescription tool = (ContainerCreationDescription) operationContext; + if (toolContext instanceof ContainerCreationDescription) { + ContainerCreationDescription tool = (ContainerCreationDescription) toolContext; Collection<String> possibleTypes = Sets.newLinkedHashSet(); /* * gather types for the "container" variable. @@ -221,8 +254,8 @@ public class DiagramInterpretedExpressionQuery extends AbstractInterpretedExpres refineVariableType(availableVariables, IInterpreterSiriusVariables.CONTAINER, possibleTypes); } - if (operationContext instanceof DeleteElementDescription) { - DeleteElementDescription tool = (DeleteElementDescription) operationContext; + if (toolContext instanceof DeleteElementDescription) { + DeleteElementDescription tool = (DeleteElementDescription) toolContext; Collection<String> possibleSemanticTypes = Sets.newLinkedHashSet(); Collection<String> possibleViewTypes = Sets.newLinkedHashSet(); Collection<String> possibleContainerViewTypes = Sets.newLinkedHashSet(); @@ -235,32 +268,13 @@ public class DiagramInterpretedExpressionQuery extends AbstractInterpretedExpres refineVariableType(availableVariables, "containerView", possibleContainerViewTypes); } - if (operationContext instanceof OperationAction) { - OperationAction tool = (OperationAction) operationContext; + if (toolContext instanceof OperationAction) { + OperationAction tool = (OperationAction) toolContext; if (new EObjectQuery(tool).getFirstAncestorOfType(DescriptionPackage.Literals.DIAGRAM_DESCRIPTION).some()) { availableVariables.put("diagram", VariableType.fromString(DIAGRAM_D_SEMANTIC_DIAGRAM)); } } - } - /* - * [428757] tool variables and not displayed in autocompletion This - * patch adds hard coded variables and hence is a temporary solution. - * The good way would be to put those metadata on the - * EdgeCreationDescription EClass in the diagram.ecore metamodel and to - * complete the AbstractInterpretedExpressionQuery to make it able to - * find specific variables for concrete types. - */ - if (target instanceof EdgeCreationDescription && ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__PRECONDITION.equals(feature)) { - availableVariables.put("diagram", VariableType.fromString("diagram.DDiagram")); - availableVariables.put("preSource", VariableType.fromString("ecore.EObject")); - availableVariables.put("preSourceView", VariableType.fromString(DIAGRAM_EDGE_TARGET_TYPE)); - availableVariables.put("preTarget", VariableType.fromString("ecore.EObject")); - availableVariables.put("preTargetView", VariableType.fromString(DIAGRAM_EDGE_TARGET_TYPE)); - - } - - return availableVariables; } private void refineVariableType(Map<String, VariableType> availableVariables, String variableName, Collection<String> foundTypes) { diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramToolInterpretedExpressionTargetSwitch.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramToolInterpretedExpressionTargetSwitch.java index 13989461f5..1d547393e7 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramToolInterpretedExpressionTargetSwitch.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/description/DiagramToolInterpretedExpressionTargetSwitch.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -157,6 +157,7 @@ public class DiagramToolInterpretedExpressionTargetSwitch extends ToolSwitch<Opt Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getRequestDescription())) { case ToolPackage.REQUEST_DESCRIPTION__PRECONDITION: + case ToolPackage.REQUEST_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -174,6 +175,7 @@ public class DiagramToolInterpretedExpressionTargetSwitch extends ToolSwitch<Opt Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getBehaviorTool())) { case ToolPackage.BEHAVIOR_TOOL__PRECONDITION: + case ToolPackage.BEHAVIOR_TOOL__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -230,6 +232,7 @@ public class DiagramToolInterpretedExpressionTargetSwitch extends ToolSwitch<Opt Option<Collection<String>> result = null; switch (getFeatureId(org.eclipse.sirius.viewpoint.description.tool.ToolPackage.eINSTANCE.getMappingBasedToolDescription())) { case org.eclipse.sirius.viewpoint.description.tool.ToolPackage.MAPPING_BASED_TOOL_DESCRIPTION__PRECONDITION: + case org.eclipse.sirius.viewpoint.description.tool.ToolPackage.MAPPING_BASED_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: Collection<String> targets = Sets.newLinkedHashSet(); for (RepresentationElementMapping correspondingMapping : new MappingBasedToolDescriptionQuery(tool).getMappings()) { diff --git a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/description/TableInterpretedExpressionQuery.java b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/description/TableInterpretedExpressionQuery.java index b79d632e66..7943656b4d 100644 --- a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/description/TableInterpretedExpressionQuery.java +++ b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/description/TableInterpretedExpressionQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -104,59 +104,57 @@ public class TableInterpretedExpressionQuery extends AbstractInterpretedExpressi @Override public Map<String, VariableType> getAvailableVariables() { - Map<String, VariableType> availableVariables = super.getAvailableVariables(); - - if (getToolContext().some()) { - EObject operationContext = getToolContext().get(); - if (operationContext instanceof CreateCellTool) { - CreateCellTool tool = (CreateCellTool) operationContext; - IntersectionMapping interMapping = tool.getMapping(); - if (interMapping != null) { - declareLineAndColumnSemantic(availableVariables, interMapping); - } - } else if (operationContext instanceof LabelEditTool) { - LabelEditTool tool = (LabelEditTool) operationContext; - if (tool.eContainer() instanceof IntersectionMapping) { - IntersectionMapping interMapping = (IntersectionMapping) tool.eContainer(); - declareLineAndColumnSemantic(availableVariables, interMapping); - } - } else if (operationContext instanceof CreateLineTool) { - CreateLineTool tool = (CreateLineTool) operationContext; + return super.getAvailableVariables(); + } - Set<String> possibleTypes = collectTypes(tool.eContainer()); + @Override + protected void addVariablesFromToolContext(EObject toolContext) { + if (toolContext instanceof CreateCellTool) { + CreateCellTool tool = (CreateCellTool) toolContext; + IntersectionMapping interMapping = tool.getMapping(); + if (interMapping != null) { + declareLineAndColumnSemantic(availableVariables, interMapping); + } + } else if (toolContext instanceof LabelEditTool) { + LabelEditTool tool = (LabelEditTool) toolContext; + if (tool.eContainer() instanceof IntersectionMapping) { + IntersectionMapping interMapping = (IntersectionMapping) tool.eContainer(); + declareLineAndColumnSemantic(availableVariables, interMapping); + } + } else if (toolContext instanceof CreateLineTool) { + CreateLineTool tool = (CreateLineTool) toolContext; - refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); - refineVariableType(availableVariables, IInterpreterSiriusTableVariables.CONTAINER, possibleTypes); + Set<String> possibleTypes = collectTypes(tool.eContainer()); - declareRootTableType(availableVariables, operationContext); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.CONTAINER, possibleTypes); - } else if (operationContext instanceof CreateColumnTool) { + declareRootTableType(availableVariables, toolContext); - CreateColumnTool tool = (CreateColumnTool) operationContext; - Set<String> possibleTypes = collectTypes(tool.eContainer()); - refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); - refineVariableType(availableVariables, IInterpreterSiriusTableVariables.CONTAINER, possibleTypes); - declareRootTableType(availableVariables, operationContext); + } else if (toolContext instanceof CreateColumnTool) { - } else if (operationContext instanceof DeleteLineTool) { - DeleteLineTool tool = (DeleteLineTool) operationContext; - LineMapping mapping = tool.getMapping(); - String domainClass = mapping.getDomainClass(); - if (!StringUtil.isEmpty(domainClass)) { - availableVariables.put(IInterpreterSiriusTableVariables.ELEMENT, VariableType.fromString(domainClass)); - } - declareRootTableType(availableVariables, operationContext); + CreateColumnTool tool = (CreateColumnTool) toolContext; + Set<String> possibleTypes = collectTypes(tool.eContainer()); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.CONTAINER, possibleTypes); + declareRootTableType(availableVariables, toolContext); - } else if (operationContext instanceof DeleteColumnTool) { - DeleteColumnTool tool = (DeleteColumnTool) operationContext; - ColumnMapping mapping = tool.getMapping(); - Set<String> possibleTypes = collectTypes(mapping); - refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); - declareRootTableType(availableVariables, operationContext); + } else if (toolContext instanceof DeleteLineTool) { + DeleteLineTool tool = (DeleteLineTool) toolContext; + LineMapping mapping = tool.getMapping(); + String domainClass = mapping.getDomainClass(); + if (!StringUtil.isEmpty(domainClass)) { + availableVariables.put(IInterpreterSiriusTableVariables.ELEMENT, VariableType.fromString(domainClass)); } + declareRootTableType(availableVariables, toolContext); + } else if (toolContext instanceof DeleteColumnTool) { + DeleteColumnTool tool = (DeleteColumnTool) toolContext; + ColumnMapping mapping = tool.getMapping(); + Set<String> possibleTypes = collectTypes(mapping); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); + declareRootTableType(availableVariables, toolContext); } - return availableVariables; } private void refineVariableType(Map<String, VariableType> availableVariables, String variableName, Collection<String> foundTypes) { diff --git a/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/AbstractInterpretedExpressionTestCase.java b/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/AbstractInterpretedExpressionTestCase.java index 8e060ff5b6..0f739ce380 100644 --- a/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/AbstractInterpretedExpressionTestCase.java +++ b/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/AbstractInterpretedExpressionTestCase.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, 2014 THALES GLOBAL SERVICES + * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,8 @@ package org.eclipse.sirius.tests.support.api; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import junit.framework.TestCase; @@ -21,8 +23,11 @@ import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EPackage; +import org.eclipse.sirius.common.tools.api.interpreter.VariableType; import org.eclipse.sirius.viewpoint.ViewpointPackage; import org.eclipse.sirius.viewpoint.description.DescriptionPackage; +import org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription; +import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; import org.junit.Assert; import com.google.common.base.Predicate; @@ -197,6 +202,10 @@ public abstract class AbstractInterpretedExpressionTestCase extends TestCase { }; Iterables.addAll(nonDocumented, Iterables.filter(interpretedExpressions, needsDocumentation)); + + // Exceptions + nonDocumented.remove(ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT); + Assert.assertTrue(getMessage(nonDocumented, AbstractInterpretedExpressionTestCase.VARIABLES), nonDocumented.isEmpty()); } @@ -236,4 +245,38 @@ public abstract class AbstractInterpretedExpressionTestCase extends TestCase { super.tearDown(); interpretedExpressions.clear(); } + + /** + * Assert variable existence. + * + * @param tool + * the tool owning the variable + * @param expectedVariable + * the expected variable + * @param variables + * the variables + */ + protected void assertVariableExistence(AbstractToolDescription tool, String expectedVariable, Set<String> variables) { + assertTrue("The interpreter context for " + tool.getName() + " should contains the variable " + expectedVariable, variables.contains(expectedVariable)); + } + + /** + * Assert variable existence and test type. + * + * @param tool + * the tool owning the variable + * @param expectedVariable + * the expected variable + * @param expectedType + * the expected type + * @param variables + * the variables + * @param variablesToType + * the variable types + */ + protected void assertVariableExistenceAndType(AbstractToolDescription tool, String expectedVariable, String expectedType, Set<String> variables, Map<String, VariableType> variablesToType) { + assertVariableExistence(tool, expectedVariable, variables); + assertEquals("The interpreter context for " + tool.eClass().getName() + " has a bad variable type for variable " + expectedVariable, VariableType.fromString(expectedType).toString(), + variablesToType.get(expectedVariable).toString()); + } } diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTableStandaloneTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTableStandaloneTests.java index d09d1f6527..8c8d17fab4 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTableStandaloneTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTableStandaloneTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,8 +14,8 @@ import junit.framework.Test; import junit.framework.TestSuite; import junit.textui.TestRunner; +import org.eclipse.sirius.tests.unit.api.vsm.interpreted.expression.variables.TableVariablesTest; import org.eclipse.sirius.tests.unit.table.unit.vsm.color.TableColorTest; -import org.eclipse.sirius.tests.unit.table.unit.vsm.interpreted.expression.variables.TableVariablesTest; public class AllTableStandaloneTests { diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/DiagramVariablesTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/DiagramVariablesTest.java index bb770c8ef4..45cf16e0ac 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/DiagramVariablesTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/DiagramVariablesTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,17 +10,33 @@ *******************************************************************************/ package org.eclipse.sirius.tests.unit.api.vsm.interpreted.expression.variables; +import java.util.Collection; +import java.util.Map; import java.util.Set; +import org.eclipse.emf.common.util.URI; +import org.eclipse.sirius.business.api.query.URIQuery; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreterContext; +import org.eclipse.sirius.common.tools.api.interpreter.VariableType; +import org.eclipse.sirius.common.tools.api.util.SiriusCrossReferenceAdapterImpl; import org.eclipse.sirius.diagram.DiagramPackage; import org.eclipse.sirius.diagram.description.DescriptionFactory; import org.eclipse.sirius.diagram.description.DiagramDescription; +import org.eclipse.sirius.diagram.description.NodeMapping; +import org.eclipse.sirius.diagram.description.tool.CreateEdgeView; +import org.eclipse.sirius.diagram.description.tool.CreateView; import org.eclipse.sirius.diagram.description.tool.EdgeCreationDescription; +import org.eclipse.sirius.diagram.description.tool.ReconnectEdgeDescription; import org.eclipse.sirius.diagram.description.tool.ToolFactory; import org.eclipse.sirius.diagram.description.tool.ToolSection; +import org.eclipse.sirius.table.business.internal.metamodel.TableToolVariables; +import org.eclipse.sirius.table.metamodel.table.description.TableCreationDescription; import org.eclipse.sirius.tests.support.api.AbstractInterpretedExpressionTestCase; import org.eclipse.sirius.tools.api.interpreter.context.SiriusInterpreterContextFactory; +import org.eclipse.sirius.tools.internal.resource.InMemoryResourceImpl; +import org.eclipse.sirius.viewpoint.description.tool.CreateInstance; +import org.eclipse.sirius.viewpoint.description.tool.InitEdgeCreationOperation; +import org.eclipse.sirius.viewpoint.description.tool.ToolEntry; import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; /** @@ -36,11 +52,12 @@ public class DiagramVariablesTest extends AbstractInterpretedExpressionTestCase super.setUp(); } - public void testInterpreterContextForAbstractVariable() { + public void testInterpreterContextForAbstractToolPreconditionVariables() { // Setup DiagramDescription diagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription(); ToolSection createToolSection = ToolFactory.eINSTANCE.createToolSection(); EdgeCreationDescription edgeCreationDescription = ToolFactory.eINSTANCE.createEdgeCreationDescription(); + edgeCreationDescription.setName("EdgeCreationDescription"); diagramDescription.setToolSection(createToolSection); createToolSection.getOwnedTools().add(edgeCreationDescription); @@ -48,15 +65,122 @@ public class DiagramVariablesTest extends AbstractInterpretedExpressionTestCase IInterpreterContext context = SiriusInterpreterContextFactory.createInterpreterContext(edgeCreationDescription, ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__PRECONDITION); // Check - Set<String> keySet = context.getVariables().keySet(); + Set<String> variables = context.getVariables().keySet(); - assertTrue("The interpreter context should contains the variable preSourceView", keySet.contains("preSourceView")); - assertTrue("The interpreter context should contains the variable preTargetView", keySet.contains("preTargetView")); - assertTrue("The interpreter context should contains the variable preSource", keySet.contains("preSource")); - assertTrue("The interpreter context should contains the variable preTarget", keySet.contains("preTarget")); - assertTrue("The interpreter context should contains the variable diagram", keySet.contains("diagram")); - assertTrue("The interpreter context should contains the variable container", keySet.contains("container")); + assertVariableExistence(edgeCreationDescription, "preSourceView", variables); + assertVariableExistence(edgeCreationDescription, "preTargetView", variables); + assertVariableExistence(edgeCreationDescription, "preSource", variables); + assertVariableExistence(edgeCreationDescription, "preTarget", variables); + assertVariableExistence(edgeCreationDescription, "diagram", variables); + assertVariableExistence(edgeCreationDescription, "container", variables); + } + + public void testInterpreterContextForAbstractToolElementsToSelectVariables() { + // 1 - Setup + // Need to create a resource with SiriusCrossReferenceAdapterImpl + // adapter on it because some code to test needs it + URI uri = URI.createURI(URIQuery.INMEMORY_URI_SCHEME + ":/" + "ProjectPipo/NotToBeSave.pipo"); + InMemoryResourceImpl resource = new InMemoryResourceImpl(uri); + resource.eAdapters().add(new SiriusCrossReferenceAdapterImpl()); + + DiagramDescription diagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription(); + resource.getContents().add(diagramDescription); + ToolSection createToolSection = ToolFactory.eINSTANCE.createToolSection(); + diagramDescription.setToolSection(createToolSection); + testEdgeCreationDescriptionWithCreateOperations(createToolSection.getOwnedTools()); + + testTableCreationDescription(diagramDescription, createToolSection.getOwnedTools()); + + testReconnectEdgeDescription(createToolSection.getOwnedTools()); + } + + private void testTableCreationDescription(DiagramDescription diagramDescription, Collection<ToolEntry> ownedTools) { + // 1 - Init data + TableCreationDescription tableCreationDescription = org.eclipse.sirius.table.metamodel.table.description.DescriptionFactory.eINSTANCE.createTableCreationDescription(); + tableCreationDescription.setName("TableCreationDescription"); + new TableToolVariables().doSwitch(tableCreationDescription); + ownedTools.add(tableCreationDescription); + + NodeMapping createNodeMapping = org.eclipse.sirius.diagram.description.DescriptionFactory.eINSTANCE.createNodeMapping(); + diagramDescription.setDefaultLayer(DescriptionFactory.eINSTANCE.createLayer()); + diagramDescription.getDefaultLayer().getNodeMappings().add(createNodeMapping); + createNodeMapping.setDomainClass("ecore.EClass"); + createNodeMapping.getDetailDescriptions().add(tableCreationDescription); + tableCreationDescription.getMappings().add(createNodeMapping); + + // 2 - Code to test + IInterpreterContext context = SiriusInterpreterContextFactory.createInterpreterContext(tableCreationDescription, ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT); + + // 3 - Test + Map<String, VariableType> variablesToType = context.getVariables(); + Set<String> variables = variablesToType.keySet(); + // check tool variables + assertVariableExistence(tableCreationDescription, "containerView", variables); + assertVariableExistence(tableCreationDescription, "tableName", variables); } + /** + * @param ownedTools + */ + private void testEdgeCreationDescriptionWithCreateOperations(Collection<ToolEntry> ownedTools) { + // 1 - Init data + org.eclipse.sirius.viewpoint.description.tool.ToolFactory vpToolFactory = org.eclipse.sirius.viewpoint.description.tool.ToolFactory.eINSTANCE; + EdgeCreationDescription edgeCreationDescription = ToolFactory.eINSTANCE.createEdgeCreationDescription(); + edgeCreationDescription.setName("EdgeCreationDescription"); + ownedTools.add(edgeCreationDescription); + InitEdgeCreationOperation createInitialOperation = vpToolFactory.createInitEdgeCreationOperation(); + CreateInstance createInstance = vpToolFactory.createCreateInstance(); + createInstance.setTypeName("EObject"); + CreateView createView = ToolFactory.eINSTANCE.createCreateView(); + CreateEdgeView createEdgeView = ToolFactory.eINSTANCE.createCreateEdgeView(); + createEdgeView.setVariableName("createdEdgeView"); + edgeCreationDescription.setInitialOperation(createInitialOperation); + createInitialOperation.setFirstModelOperations(createInstance); + createInstance.getSubModelOperations().add(createView); + createView.getSubModelOperations().add(createEdgeView); + + // 2 - Code to test + IInterpreterContext context = SiriusInterpreterContextFactory.createInterpreterContext(edgeCreationDescription, ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT); + + // 3 - Test + Map<String, VariableType> variablesToType = context.getVariables(); + Set<String> variables = variablesToType.keySet(); + + // check tool variables + assertVariableExistence(edgeCreationDescription, "sourceView", variables); + assertVariableExistence(edgeCreationDescription, "targetView", variables); + assertVariableExistence(edgeCreationDescription, "source", variables); + assertVariableExistence(edgeCreationDescription, "target", variables); + + // check variables from create operation + assertVariableExistenceAndType(edgeCreationDescription, "instance", "ecore.EObject", variables, variablesToType); + assertVariableExistenceAndType(edgeCreationDescription, "createdView", "viewpoint.DView", variables, variablesToType); + assertVariableExistenceAndType(edgeCreationDescription, "createdEdgeView", "diagram.DEdge", variables, variablesToType); + } + + private void testReconnectEdgeDescription(Collection<ToolEntry> ownedTools) { + // 1 - Init data + ReconnectEdgeDescription createReconnectEdgeDescription = ToolFactory.eINSTANCE.createReconnectEdgeDescription(); + createReconnectEdgeDescription.setName("ReconnectEdgeDescription"); + ownedTools.add(createReconnectEdgeDescription); + + // 2 - Code to test + IInterpreterContext context = SiriusInterpreterContextFactory.createInterpreterContext(createReconnectEdgeDescription, ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT); + + // 3 - Test + Map<String, VariableType> variablesToType = context.getVariables(); + Set<String> variables = variablesToType.keySet(); + + // check tool variables + assertVariableExistence(createReconnectEdgeDescription, "sourceView", variables); + assertVariableExistence(createReconnectEdgeDescription, "targetView", variables); + assertVariableExistence(createReconnectEdgeDescription, "source", variables); + assertVariableExistence(createReconnectEdgeDescription, "target", variables); + assertVariableExistence(createReconnectEdgeDescription, "element", variables); + + // check variables from create operation + assertVariableExistenceAndType(createReconnectEdgeDescription, "otherEnd", "diagram.EdgeTarget", variables, variablesToType); + assertVariableExistenceAndType(createReconnectEdgeDescription, "edgeView", "diagram.DEdge", variables, variablesToType); + } } diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/TableVariablesTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/TableVariablesTest.java new file mode 100644 index 0000000000..2e56b1e024 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/TableVariablesTest.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2015 THALES GLOBAL SERVICES. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.api.vsm.interpreted.expression.variables; + +import java.util.Map; +import java.util.Set; + +import org.eclipse.sirius.common.tools.api.interpreter.IInterpreterContext; +import org.eclipse.sirius.common.tools.api.interpreter.VariableType; +import org.eclipse.sirius.table.business.internal.metamodel.TableToolVariables; +import org.eclipse.sirius.table.metamodel.table.TablePackage; +import org.eclipse.sirius.table.metamodel.table.description.CreateLineTool; +import org.eclipse.sirius.table.metamodel.table.description.DescriptionFactory; +import org.eclipse.sirius.table.metamodel.table.description.LineMapping; +import org.eclipse.sirius.table.metamodel.table.description.TableDescription; +import org.eclipse.sirius.tests.support.api.AbstractInterpretedExpressionTestCase; +import org.eclipse.sirius.tools.api.interpreter.context.SiriusInterpreterContextFactory; +import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; + +/** + * Tests of interpreted expressions. + * + * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a> + */ +public class TableVariablesTest extends AbstractInterpretedExpressionTestCase { + + @Override + protected void setUp() throws Exception { + setBasePackage(TablePackage.eINSTANCE); + super.setUp(); + } + + public void testInterpreterContextForAbstractToolElementsToSelectVariables() { + // 1 - Setup + TableDescription tableDescription = DescriptionFactory.eINSTANCE.createEditionTableDescription(); + LineMapping lineMapping = DescriptionFactory.eINSTANCE.createLineMapping(); + lineMapping.setDomainClass("ecore.EClass"); + tableDescription.getOwnedLineMappings().add(lineMapping); + CreateLineTool createLineTool = DescriptionFactory.eINSTANCE.createCreateLineTool(); + createLineTool.setName("CreateLineTool"); + new TableToolVariables().doSwitch(createLineTool); + lineMapping.getCreate().add(createLineTool); + + // 2 - Code to test + IInterpreterContext context = SiriusInterpreterContextFactory.createInterpreterContext(createLineTool, ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT); + + // 3 - Test + Map<String, VariableType> variablesToType = context.getVariables(); + Set<String> variables = variablesToType.keySet(); + + // check tool variables + assertVariableExistenceAndType(createLineTool, "root", "ecore.EObject", variables, variablesToType); + assertVariableExistenceAndType(createLineTool, "element", "ecore.EClass", variables, variablesToType); + assertVariableExistenceAndType(createLineTool, "container", "ecore.EClass", variables, variablesToType); + } +} diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/TreeVariablesTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/TreeVariablesTest.java new file mode 100644 index 0000000000..655deba2cb --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/interpreted/expression/variables/TreeVariablesTest.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2015 THALES GLOBAL SERVICES. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.api.vsm.interpreted.expression.variables; + +import java.util.Map; +import java.util.Set; + +import org.eclipse.sirius.common.tools.api.interpreter.IInterpreterContext; +import org.eclipse.sirius.common.tools.api.interpreter.VariableType; +import org.eclipse.sirius.tests.support.api.AbstractInterpretedExpressionTestCase; +import org.eclipse.sirius.tools.api.interpreter.context.SiriusInterpreterContextFactory; +import org.eclipse.sirius.tree.TreePackage; +import org.eclipse.sirius.tree.business.internal.metamodel.TreeToolVariables; +import org.eclipse.sirius.tree.description.DescriptionFactory; +import org.eclipse.sirius.tree.description.TreeDescription; +import org.eclipse.sirius.tree.description.TreeItemCreationTool; +import org.eclipse.sirius.tree.description.TreeItemMapping; +import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; + +/** + * Tests of interpreted expressions. + * + * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a> + */ +public class TreeVariablesTest extends AbstractInterpretedExpressionTestCase { + + @Override + protected void setUp() throws Exception { + setBasePackage(TreePackage.eINSTANCE); + super.setUp(); + } + + public void testInterpreterContextForAbstractToolElementsToSelectVariables() { + // 1 - Setup + TreeDescription treeDescription = DescriptionFactory.eINSTANCE.createTreeDescription(); + TreeItemMapping treeItemMapping = DescriptionFactory.eINSTANCE.createTreeItemMapping(); + treeItemMapping.setDomainClass("ecore.EClass"); + treeDescription.getSubItemMappings().add(treeItemMapping); + TreeItemCreationTool treeItemCreationTool = DescriptionFactory.eINSTANCE.createTreeItemCreationTool(); + new TreeToolVariables().doSwitch(treeItemCreationTool); + treeItemMapping.getCreate().add(treeItemCreationTool); + + // 2 - Code to test + IInterpreterContext context = SiriusInterpreterContextFactory.createInterpreterContext(treeItemCreationTool, ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT); + + // 3 - Test + Map<String, VariableType> variablesToType = context.getVariables(); + Set<String> variables = variablesToType.keySet(); + + // check tool variables + assertVariableExistenceAndType(treeItemCreationTool, "container", "ecore.EObject", variables, variablesToType); + assertVariableExistenceAndType(treeItemCreationTool, "element", "ecore.EObject", variables, variablesToType); + assertVariableExistenceAndType(treeItemCreationTool, "root", "ecore.EObject", variables, variablesToType); + } +} diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/vsm/interpreted/expression/variables/TableVariablesTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/vsm/interpreted/expression/variables/TableVariablesTest.java deleted file mode 100644 index 9117073d98..0000000000 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/vsm/interpreted/expression/variables/TableVariablesTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.sirius.tests.unit.table.unit.vsm.interpreted.expression.variables; - -import org.eclipse.sirius.table.metamodel.table.TablePackage; -import org.eclipse.sirius.tests.support.api.AbstractInterpretedExpressionTestCase; - -/** - * Test documentation of interpreted expressions. - * - * @author mporhel - */ -public class TableVariablesTest extends AbstractInterpretedExpressionTestCase { - - @Override - protected void setUp() throws Exception { - setBasePackage(TablePackage.eINSTANCE); - super.setUp(); - } -} diff --git a/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/suite/tree/AllTreeStandaloneTests.java b/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/suite/tree/AllTreeStandaloneTests.java index 7b9fcdc390..8df578b98f 100644 --- a/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/suite/tree/AllTreeStandaloneTests.java +++ b/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/suite/tree/AllTreeStandaloneTests.java @@ -13,8 +13,9 @@ package org.eclipse.sirius.tests.suite.tree; import junit.framework.Test; import junit.framework.TestSuite; import junit.textui.TestRunner; + +import org.eclipse.sirius.tests.unit.api.vsm.interpreted.expression.variables.TreeVariablesTest; import org.eclipse.sirius.tests.unit.tree.vsm.color.TreeColorTest; -import org.eclipse.sirius.tests.unit.tree.vsm.interpreted.expression.TreeVariablesTest; /** * The designer main test standalone suite for the tree component. diff --git a/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/unit/tree/vsm/interpreted/expression/TreeVariablesTest.java b/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/unit/tree/vsm/interpreted/expression/TreeVariablesTest.java deleted file mode 100644 index c267e82890..0000000000 --- a/plugins/org.eclipse.sirius.tests.tree/src/org/eclipse/sirius/tests/unit/tree/vsm/interpreted/expression/TreeVariablesTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 THALES GLOBAL SERVICES. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.sirius.tests.unit.tree.vsm.interpreted.expression; - -import org.eclipse.sirius.tests.support.api.AbstractInterpretedExpressionTestCase; -import org.eclipse.sirius.tree.TreePackage; - -/** - * Test documentation of interpreted expressions. - * - * @author mporhel - */ -public class TreeVariablesTest extends AbstractInterpretedExpressionTestCase { - - @Override - protected void setUp() throws Exception { - setBasePackage(TreePackage.eINSTANCE); - super.setUp(); - } -} diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/description/TreeInterpretedExpressionTargetSwitch.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/description/TreeInterpretedExpressionTargetSwitch.java index f8c88a721e..6dd8664293 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/description/TreeInterpretedExpressionTargetSwitch.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/description/TreeInterpretedExpressionTargetSwitch.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -169,6 +169,7 @@ public class TreeInterpretedExpressionTargetSwitch extends DescriptionSwitch<Opt case DescriptionPackage.TREE_CREATION_DESCRIPTION__TITLE_EXPRESSION: case DescriptionPackage.TREE_CREATION_DESCRIPTION__BROWSE_EXPRESSION: case DescriptionPackage.TREE_CREATION_DESCRIPTION__PRECONDITION: + case DescriptionPackage.TREE_CREATION_DESCRIPTION__ELEMENTS_TO_SELECT: for (RepresentationElementMapping mapping : toolDescription.getMappings()) { Option<Collection<String>> mappingTypes = globalSwitch.doSwitch(mapping, false); if (mappingTypes.some()) { @@ -194,6 +195,7 @@ public class TreeInterpretedExpressionTargetSwitch extends DescriptionSwitch<Opt case DescriptionPackage.TREE_NAVIGATION_DESCRIPTION__BROWSE_EXPRESSION: case DescriptionPackage.TREE_NAVIGATION_DESCRIPTION__NAVIGATION_NAME_EXPRESSION: case DescriptionPackage.TREE_NAVIGATION_DESCRIPTION__PRECONDITION: + case DescriptionPackage.TREE_NAVIGATION_DESCRIPTION__ELEMENTS_TO_SELECT: for (RepresentationElementMapping mapping : toolDescription.getMappings()) { Option<Collection<String>> mappingTypes = globalSwitch.doSwitch(mapping, false); if (mappingTypes.some()) { diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/description/AbstractInterpretedExpressionQuery.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/description/AbstractInterpretedExpressionQuery.java index 3f77c8e455..2c4d64b3f2 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/description/AbstractInterpretedExpressionQuery.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/description/AbstractInterpretedExpressionQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 THALES GLOBAL SERVICES. + * Copyright (c) 2013, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EAnnotation; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; @@ -161,6 +162,7 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted * * @see org.eclipse.sirius.business.api.dialect.description.IInterpretedExpressionQuery#getTargetDomainClasses() */ + @Override public Option<Collection<String>> getTargetDomainClasses() { if (targetDomainClass == null) { /* @@ -191,6 +193,7 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted * * @see org.eclipse.sirius.business.api.dialect.description.IInterpretedExpressionQuery#getPackagesToImport() */ + @Override public Collection<EPackage> getPackagesToImport() { if (packagesToImport == null) { packagesToImport = Sets.newLinkedHashSet(); @@ -237,6 +240,7 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted * * @see org.eclipse.sirius.business.api.dialect.description.IInterpretedExpressionQuery#getDependencies() */ + @Override public Collection<String> getDependencies() { if (dependencies == null) { dependencies = Sets.newLinkedHashSet(); @@ -265,6 +269,7 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted * * @see org.eclipse.sirius.business.api.dialect.description.IInterpretedExpressionQuery#getAvailableVariables() */ + @Override public Map<String, VariableType> getAvailableVariables() { if (availableVariables == null) { availableVariables = Maps.newLinkedHashMap(); @@ -272,7 +277,7 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted Option<EObject> toolContext = getToolContext(); if (toolContext.some()) { EObject operationContext = toolContext.get(); - collectContextualVariableDefinitions(availableVariables, operationContext, target); + collectContextualVariableDefinitions(operationContext, target); if (operationContext instanceof ToolDescription) { /* * the containerView variable is accessible in any Model @@ -280,6 +285,7 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted */ availableVariables.put("containerView", VariableType.fromString("viewpoint.DSemanticDecorator")); } + addVariablesFromToolContext(operationContext); } collectLocalVariablesDefinitions(); if (this.target instanceof ToolDescription && feature == ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__PRECONDITION) { @@ -289,10 +295,54 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted */ availableVariables.put("containerView", VariableType.fromString("viewpoint.DSemanticDecorator")); } + + if (ToolPackage.Literals.ABSTRACT_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT.equals(feature)) { + collectContextualVariableDefinitions(target, target); + addVariablesFromToolContext(target); + addVariablesFromCreateOperation(target); + } + return availableVariables; } /** + * Add variables specific to each dialect and each tool. + * + * @param toolContext + * the tool from which to get the variables + */ + protected void addVariablesFromToolContext(EObject toolContext) { + } + + /** + * Add variables from create operations under the tool. + * + * @param toolContext + * the tool from which to get the create operation variables + */ + private void addVariablesFromCreateOperation(EObject toolContext) { + TreeIterator<EObject> eAllContents = toolContext.eAllContents(); + while (eAllContents.hasNext()) { + EObject eObject = eAllContents.next(); + if (eObject instanceof ModelOperation) { + addVariableFromCreateOperation((ModelOperation) eObject); + } + } + } + + /** + * Add variables for create operation. + * + * @param modelOperation + * the potential create operation from which to get the variable + */ + protected void addVariableFromCreateOperation(ModelOperation modelOperation) { + if (modelOperation instanceof CreateInstance) { + availableVariables.put(((CreateInstance) modelOperation).getVariableName(), VariableType.fromString(((CreateInstance) modelOperation).getTypeName())); + } + } + + /** * return the EObject which represents the top-level execution context. * * @return the EObject which represents the top-level execution context. @@ -371,7 +421,7 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted * shadowing, priority is given to the the value defined closest to * <code>bottom</code> (lexical scoping). */ - private void collectContextualVariableDefinitions(Map<String, VariableType> vars, EObject top, EObject bottom) { + private void collectContextualVariableDefinitions(EObject top, EObject bottom) { // A map with multiple values is not strictly required as we only use // one value, but it is useful when debugging to have all the // information. @@ -401,7 +451,7 @@ public abstract class AbstractInterpretedExpressionQuery implements IInterpreted // Merge all the definitions, by taking the one closest to // <code>bottom</code> when there are multiple ones. for (String var : definitions.keySet()) { - vars.put(var, ((List<VariableType>) definitions.get(var)).get(0)); + availableVariables.put(var, ((List<VariableType>) definitions.get(var)).get(0)); } } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/description/ToolInterpretedExpressionTargetSwitch.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/description/ToolInterpretedExpressionTargetSwitch.java index c0fff6a610..1bc7c77a6c 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/description/ToolInterpretedExpressionTargetSwitch.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/description/ToolInterpretedExpressionTargetSwitch.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -191,6 +191,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getMappingBasedToolDescription())) { case ToolPackage.MAPPING_BASED_TOOL_DESCRIPTION__PRECONDITION: + case ToolPackage.MAPPING_BASED_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: // Default case for MappingBasedToolDescription, if subclasses or // dialects did not return a specific result. @@ -207,6 +208,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getAbstractToolDescription())) { case ToolPackage.ABSTRACT_TOOL_DESCRIPTION__PRECONDITION: + case ToolPackage.ABSTRACT_TOOL_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: // Default case for AbstractToolDescription, if subclasses or // dialects did not return a specific result. @@ -223,6 +225,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getToolDescription())) { case ToolPackage.TOOL_DESCRIPTION__PRECONDITION: + case ToolPackage.TOOL_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -237,6 +240,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getOperationAction())) { case ToolPackage.OPERATION_ACTION__PRECONDITION: + case ToolPackage.OPERATION_ACTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -251,6 +255,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getPasteDescription())) { case ToolPackage.PASTE_DESCRIPTION__PRECONDITION: + case ToolPackage.PASTE_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: Collection<String> targets = Sets.newLinkedHashSet(); for (PasteTargetDescription container : object.getContainers()) { @@ -306,6 +311,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col case ToolPackage.PANE_BASED_SELECTION_WIZARD_DESCRIPTION__ROOT_EXPRESSION: case ToolPackage.PANE_BASED_SELECTION_WIZARD_DESCRIPTION__PRE_SELECTED_CANDIDATES_EXPRESSION: case ToolPackage.PANE_BASED_SELECTION_WIZARD_DESCRIPTION__PRECONDITION: + case ToolPackage.PANE_BASED_SELECTION_WIZARD_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -323,6 +329,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col case ToolPackage.SELECTION_WIZARD_DESCRIPTION__CHILDREN_EXPRESSION: case ToolPackage.SELECTION_WIZARD_DESCRIPTION__ROOT_EXPRESSION: case ToolPackage.SELECTION_WIZARD_DESCRIPTION__PRECONDITION: + case ToolPackage.SELECTION_WIZARD_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -337,6 +344,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getPopupMenu())) { case ToolPackage.POPUP_MENU__PRECONDITION: + case ToolPackage.POPUP_MENU__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -351,6 +359,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getExternalJavaAction())) { case ToolPackage.EXTERNAL_JAVA_ACTION__PRECONDITION: + case ToolPackage.EXTERNAL_JAVA_ACTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -365,6 +374,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col Option<Collection<String>> result = null; switch (getFeatureId(ToolPackage.eINSTANCE.getExternalJavaActionCall())) { case ToolPackage.EXTERNAL_JAVA_ACTION_CALL__PRECONDITION: + case ToolPackage.EXTERNAL_JAVA_ACTION_CALL__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: result = Options.newNone(); break; @@ -396,6 +406,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col case ToolPackage.REPRESENTATION_CREATION_DESCRIPTION__TITLE_EXPRESSION: case ToolPackage.REPRESENTATION_CREATION_DESCRIPTION__BROWSE_EXPRESSION: case ToolPackage.REPRESENTATION_CREATION_DESCRIPTION__PRECONDITION: + case ToolPackage.REPRESENTATION_CREATION_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: for (RepresentationElementMapping mapping : toolDescription.getMappings()) { IInterpretedExpressionQuery interpretedExpressionQuery = DialectManager.INSTANCE.createInterpretedExpressionQuery(mapping, null); @@ -420,6 +431,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col case ToolPackage.REPRESENTATION_NAVIGATION_DESCRIPTION__BROWSE_EXPRESSION: case ToolPackage.REPRESENTATION_NAVIGATION_DESCRIPTION__NAVIGATION_NAME_EXPRESSION: case ToolPackage.REPRESENTATION_NAVIGATION_DESCRIPTION__PRECONDITION: + case ToolPackage.REPRESENTATION_NAVIGATION_DESCRIPTION__ELEMENTS_TO_SELECT: case DO_NOT_CONSIDER_FEATURE: for (RepresentationElementMapping mapping : toolDescription.getMappings()) { IInterpretedExpressionQuery interpretedExpressionQuery = DialectManager.INSTANCE.createInterpretedExpressionQuery(mapping, null); @@ -473,7 +485,7 @@ public class ToolInterpretedExpressionTargetSwitch extends ToolSwitch<Option<Col } return result; } - + @Override public Option<Collection<String>> caseFor(For object) { Option<Collection<String>> result = null; |
