diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/textrender/AbstractTextRenderer.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/textrender/AbstractTextRenderer.java index 938c22f91..a98c22b0f 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/textrender/AbstractTextRenderer.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/textrender/AbstractTextRenderer.java @@ -5,7 +5,9 @@ */ package com.archimatetool.editor.ui.textrender; +import com.archimatetool.model.IArchimateConcept; import com.archimatetool.model.IArchimateModelObject; +import com.archimatetool.model.IArchimateRelationship; import com.archimatetool.model.IConnectable; import com.archimatetool.model.IDiagramModel; import com.archimatetool.model.IDiagramModelArchimateComponent; @@ -30,11 +32,11 @@ public abstract class AbstractTextRenderer implements ITextRenderer { * @return object itself or the underlying object */ protected IArchimateModelObject getActualObject(IArchimateModelObject object) { - if(object instanceof IDiagramModelArchimateComponent) { - return ((IDiagramModelArchimateComponent)object).getArchimateConcept(); + if(object instanceof IDiagramModelArchimateComponent dmo) { + return dmo.getArchimateConcept(); } - if(object instanceof IDiagramModelReference) { - return ((IDiagramModelReference)object).getReferencedModel(); + if(object instanceof IDiagramModelReference dmr) { + return dmr.getReferencedModel(); } return object; } @@ -61,18 +63,18 @@ protected IArchimateModelObject getObjectFromPrefix(IArchimateModelObject object } // View - object is an IDiagramModelComponent so return IDiagramModel - if(viewPrefix.equals(prefix) && object instanceof IDiagramModelComponent) { - return ((IDiagramModelComponent)object).getDiagramModel(); + if(viewPrefix.equals(prefix) && object instanceof IDiagramModelComponent dmc) { + return dmc.getDiagramModel(); } // Model Folder - if(modelFolderPrefix.equals(prefix) && actualObject.eContainer() instanceof IFolder) { // Has a folder parent - return (IFolder)actualObject.eContainer(); + if(modelFolderPrefix.equals(prefix) && actualObject.eContainer() instanceof IFolder folder) { // Has a folder parent + return folder; } // View Folder - if(viewFolderPrefix.equals(prefix) && object instanceof IDiagramModelComponent) { - IDiagramModel dm = ((IDiagramModelComponent)object).getDiagramModel(); + if(viewFolderPrefix.equals(prefix) && object instanceof IDiagramModelComponent dmc) { + IDiagramModel dm = dmc.getDiagramModel(); return dm != null ? (IArchimateModelObject)dm.eContainer() : null; // folder parent of IDiagramModel } @@ -83,38 +85,56 @@ protected IArchimateModelObject getObjectFromPrefix(IArchimateModelObject object } // Source of Connection - if(sourcePrefix.equals(prefix) && object instanceof IDiagramModelConnection) { - return getActualObject(((IDiagramModelConnection)object).getSource()); + if(sourcePrefix.equals(prefix) && object instanceof IDiagramModelConnection dmc) { + return getActualObject(dmc.getSource()); } // Target of Connection - if(targetPrefix.equals(prefix) && object instanceof IDiagramModelConnection) { - return getActualObject(((IDiagramModelConnection)object).getTarget()); + if(targetPrefix.equals(prefix) && object instanceof IDiagramModelConnection dmc) { + return getActualObject(dmc.getTarget()); } - // Linked Source object from a connection - if(prefix.endsWith(":source") && object instanceof IConnectable) { + // Linked Source object from a connection/relation + if(prefix.endsWith(":source") && object instanceof IConnectable connectable) { prefix = prefix.replace(":source", ""); - // Has at least one target connection that matches... - for(IDiagramModelConnection connection : ((IConnectable)object).getTargetConnections()) { - IArchimateModelObject actualConnection = getActualObject(connection); + // Has at least one source connection that matches... + for(IDiagramModelConnection connection : connectable.getTargetConnections()) { + IArchimateModelObject actualConnection = getActualObject(connection); // Could be "connection" or a relationship type if(actualConnection.eClass().getName().toLowerCase().contains(prefix)) { return getActualObject(connection.getSource()); } } + + // No connection, so has at least one source model relation that matches... + if(actualObject instanceof IArchimateConcept concept) { + for(IArchimateRelationship relationship : concept.getTargetRelationships()) { + if(relationship.eClass().getName().toLowerCase().contains(prefix)) { + return relationship.getSource(); + } + } + } } - // Linked Target object from a connection - else if(prefix.endsWith(":target") && object instanceof IConnectable) { + // Linked Target object from a connection/relation + else if(prefix.endsWith(":target") && object instanceof IConnectable connectable) { prefix = prefix.replace(":target", ""); - + // Has at least one target connection that matches... - for(IDiagramModelConnection connection : ((IConnectable)object).getSourceConnections()) { - IArchimateModelObject actualConnection = getActualObject(connection); + for(IDiagramModelConnection connection : connectable.getSourceConnections()) { + IArchimateModelObject actualConnection = getActualObject(connection); // Could be "connection" or a relationship type if(actualConnection.eClass().getName().toLowerCase().contains(prefix)) { return getActualObject(connection.getTarget()); } } + + // No connection, so has at least one target model relation that matches... + if(actualObject instanceof IArchimateConcept concept) { + for(IArchimateRelationship relationship : concept.getSourceRelationships()) { + if(relationship.eClass().getName().toLowerCase().contains(prefix)) { + return relationship.getTarget(); + } + } + } } return null; diff --git a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/DocumentationRendererTests.java b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/DocumentationRendererTests.java index ecfa10111..70b27f628 100644 --- a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/DocumentationRendererTests.java +++ b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/DocumentationRendererTests.java @@ -7,10 +7,12 @@ import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Test; import com.archimatetool.model.IArchimateFactory; import com.archimatetool.model.IArchimateModelObject; +import com.archimatetool.model.IConnectable; import com.archimatetool.model.IDiagramModelArchimateConnection; import com.archimatetool.model.IDiagramModelArchimateObject; import com.archimatetool.model.IDiagramModelGroup; @@ -28,8 +30,14 @@ public class DocumentationRendererTests extends AbstractTextRendererTests { private DocumentationRenderer renderer = new DocumentationRenderer(); - private IDiagramModelArchimateObject dmo = TextRendererTests.createDiagramModelObject(); - private IDiagramModelArchimateConnection dmc = TextRendererTests.createDiagramModelConnection(); + private IDiagramModelArchimateObject dmo; + private IDiagramModelArchimateConnection dmc; + + @Before + public void beforeEachTest() { + dmo = TextRendererTests.createDiagramModelObject(); + dmc = TextRendererTests.createDiagramModelConnection(); + } @Override protected DocumentationRenderer getRenderer() { @@ -109,10 +117,32 @@ public void render_ConnectedSourceDocumentation() { assertEquals("Source Documentation", result); } + @Test + public void render_ConnectedSourceDocumentation_No_DiagramModelComponent() { + IConnectable target = dmc.getTarget(); + + // remove dmc + dmc.disconnect(); + + String result = renderer.render(target, "$assignment:source{documentation}"); + assertEquals("Source Documentation", result); + } + @Test public void render_ConnectedTargetDocumentation() { String result = renderer.render(dmc.getSource(), "$assignment:target{documentation}"); assertEquals("Target Documentation", result); } + @Test + public void render_ConnectedTargetDocumentation_No_DiagramModelComponent() { + IConnectable source = dmc.getSource(); + + // remove dmc + dmc.disconnect(); + + String result = renderer.render(source, "$assignment:target{documentation}"); + assertEquals("Target Documentation", result); + } + } diff --git a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/NameRendererTests.java b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/NameRendererTests.java index be1d7c2a3..f54f3fc57 100644 --- a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/NameRendererTests.java +++ b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/NameRendererTests.java @@ -7,10 +7,12 @@ import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Test; import com.archimatetool.model.IArchimateFactory; import com.archimatetool.model.IArchimateModelObject; +import com.archimatetool.model.IConnectable; import com.archimatetool.model.IDiagramModelArchimateConnection; import com.archimatetool.model.IDiagramModelArchimateObject; import com.archimatetool.model.IDiagramModelGroup; @@ -28,8 +30,14 @@ public class NameRendererTests extends AbstractTextRendererTests { private NameRenderer renderer = new NameRenderer(); - private IDiagramModelArchimateObject dmo = TextRendererTests.createDiagramModelObject(); - private IDiagramModelArchimateConnection dmc = TextRendererTests.createDiagramModelConnection(); + private IDiagramModelArchimateObject dmo; + private IDiagramModelArchimateConnection dmc; + + @Before + public void beforeEachTest() { + dmo = TextRendererTests.createDiagramModelObject(); + dmc = TextRendererTests.createDiagramModelConnection(); + } @Override protected NameRenderer getRenderer() { @@ -103,10 +111,32 @@ public void render_ConnectedSourceName() { assertEquals("Source Concept", result); } + @Test + public void render_ConnectedSourceName_No_DiagramModelComponent() { + IConnectable target = dmc.getTarget(); + + // remove dmc + dmc.disconnect(); + + String result = renderer.render(target, "$assignment:source{name}"); + assertEquals("Source Concept", result); + } + @Test public void render_ConnectedTargetName() { String result = renderer.render(dmc.getSource(), "$assignment:target{name}"); assertEquals("Target Concept", result); } + @Test + public void render_ConnectedTargetName_No_DiagramModelComponent() { + IConnectable source = dmc.getSource(); + + // remove dmc + dmc.disconnect(); + + String result = renderer.render(source, "$assignment:target{name}"); + assertEquals("Target Concept", result); + } + } diff --git a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/TypeRendererTests.java b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/TypeRendererTests.java index 0546c94ec..48a417a84 100644 --- a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/TypeRendererTests.java +++ b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/textrender/TypeRendererTests.java @@ -7,10 +7,12 @@ import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Test; import com.archimatetool.model.IArchimateDiagramModel; import com.archimatetool.model.IArchimateFactory; +import com.archimatetool.model.IConnectable; import com.archimatetool.model.IDiagramModelArchimateConnection; import com.archimatetool.model.IDiagramModelArchimateObject; import com.archimatetool.model.IDiagramModelReference; @@ -27,8 +29,14 @@ public class TypeRendererTests extends AbstractTextRendererTests { private TypeRenderer renderer = new TypeRenderer(); - private IDiagramModelArchimateObject dmo = TextRendererTests.createDiagramModelObject(); - private IDiagramModelArchimateConnection dmc = TextRendererTests.createDiagramModelConnection(); + private IDiagramModelArchimateObject dmo; + private IDiagramModelArchimateConnection dmc; + + @Before + public void beforeEachTest() { + dmo = TextRendererTests.createDiagramModelObject(); + dmc = TextRendererTests.createDiagramModelConnection(); + } @Override protected TypeRenderer getRenderer() { @@ -93,17 +101,39 @@ public void render_ParentType() { } @Test - public void render_ConnectedSourceName() { + public void render_ConnectedSourceType() { String result = renderer.render(dmc.getTarget(), "$assignment:source{type}"); assertEquals("Business Actor", result); } @Test - public void render_ConnectedTargetName() { + public void render_ConnectedSourceType_No_DiagramModelComponent() { + IConnectable target = dmc.getTarget(); + + // remove dmc + dmc.disconnect(); + + String result = renderer.render(target, "$assignment:source{type}"); + assertEquals("Business Actor", result); + } + + @Test + public void render_ConnectedTargetType() { String result = renderer.render(dmc.getSource(), "$assignment:target{type}"); assertEquals("Business Role", result); } + @Test + public void render_ConnectedTargetType_No_DiagramModelComponent() { + IConnectable source = dmc.getSource(); + + // remove dmc + dmc.disconnect(); + + String result = renderer.render(source, "$assignment:target{type}"); + assertEquals("Business Role", result); + } + @Test public void render_ModelFolderName() { String result = renderer.render(dmo, "$mfolder{type}");