diff options
author | 2021-08-03 18:42:39 +0900 | |
---|---|---|
committer | 2021-08-06 19:32:38 +0900 | |
commit | be4f78978faba3d3ceb88df02a7f93a2e09ff1e0 (patch) | |
tree | 1f3f1a96251ac4f655c8a96fc33d5d4ee779cd06 /rba.tool.editor/src/rba/tool/editor/linking/RBAModelLinker.xtend | |
parent | 71ca7c6cab863767ef30c8bd05b2bbfda8731cb5 (diff) |
Initial commit
Bug-AGL: SPEC-4033
Signed-off-by: Kenji Hosokawa <khosokawa@jp.adit-jv.com>
Diffstat (limited to 'rba.tool.editor/src/rba/tool/editor/linking/RBAModelLinker.xtend')
-rw-r--r-- | rba.tool.editor/src/rba/tool/editor/linking/RBAModelLinker.xtend | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/rba.tool.editor/src/rba/tool/editor/linking/RBAModelLinker.xtend b/rba.tool.editor/src/rba/tool/editor/linking/RBAModelLinker.xtend new file mode 100644 index 0000000..2ceaf15 --- /dev/null +++ b/rba.tool.editor/src/rba/tool/editor/linking/RBAModelLinker.xtend @@ -0,0 +1,87 @@ +package rba.tool.editor.linking + +import java.util.ArrayList +import java.util.Iterator +import java.util.List +import javax.inject.Inject +import org.eclipse.emf.common.util.AbstractTreeIterator +import org.eclipse.emf.common.util.URI +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.EReference +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.ecore.util.EcoreUtil +import org.eclipse.xtext.EcoreUtil2 +import org.eclipse.xtext.linking.impl.DefaultLinkingService +import org.eclipse.xtext.linking.lazy.LazyLinker +import org.eclipse.xtext.nodemodel.INode +import rba.core.ObjectReference +import rba.tool.editor.rbaEditorModel.MemberFeatureReference +import rba.tool.editor.util.RBAModelEditorToolUtil + +class RBAModelLinker extends LazyLinker { + + @Inject extension DefaultLinkingService linkingService + + override protected clearReference(EObject obj, EReference ref) { + if(RBAModelEditorToolUtil.isSkippedSyntax(obj, ref)) { + return; + } + super.clearReference(obj, ref); + } + + override protected createProxy(EObject obj, INode node, EReference eRef) { + val EObject result = getLinkedObject(obj, node, eRef); + if(eRef.EOpposite !== null && (result !== null && result.eClass.EAllSuperTypes.contains(eRef.EReferenceType))) { + val Resource objResource = obj.eResource(); + val Resource rslResource = result.eResource(); + if(!equals(objResource.URI, rslResource.URI)) { + return result; + } + } + + return super.createProxy(obj, node, eRef); + } + + override protected getAllLinkableContents(EObject model) { + val AbstractTreeIterator<EObject> result = new AbstractTreeIterator<EObject>(model) { + override public Iterator<EObject> getChildren(Object object) { + val List<EObject> contents = new ArrayList<EObject>(); + if(object instanceof MemberFeatureReference) { + // do nothing + } else { + val temp = (object as EObject).eContents(); + for (eObject : temp) { + if(eObject instanceof MemberFeatureReference) { + contents.addAll(EcoreUtil2.getAllContentsOfType(eObject, ObjectReference)); + } + contents.add(eObject); + } + } + return contents.iterator(); + } + }; + + return result; + } + + def private EObject getLinkedObject(EObject obj, INode node, EReference eRef) { + val linkedObjects = linkingService.getLinkedObjects(obj, eRef, node); + if(linkedObjects.size == 1) { + val linkedObject = linkedObjects.get(0); + if(linkedObject.eIsProxy) { + return EcoreUtil.resolve(linkedObject, obj.eResource); + } else { + return linkedObject; + } + } + return null; + } + + def private boolean equals(URI uri1, URI uri2) { + if(uri1 === null || uri2 === null) { + return false; + } + + return uri1.equals(uri2); + } +} |