Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Add Bidirectional Reference Logic #105

Merged

Conversation

jcebel
Copy link
Contributor

@jcebel jcebel commented Jan 9, 2020

Resolves #38
Resolves jcebel#18

This need to be aligned with PR #99, as this one changes the logic of the labels.

@@ -128,6 +135,48 @@ public GEdge create(EReference eReference) {
.build();
}

private GEdge createBidirectionalEdge(EReference eReference, String source, String target) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we unify the code especially the big block of the GEdgeBuilder?

Copy link
Contributor

@CamilleLetavernier CamilleLetavernier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing for everyone; but labels on bi-directional references need to be inverted :) (The label for a Reference needs to be displayed next to the Type of the Reference; not its Owner)

image

image

@@ -150,4 +155,8 @@ public void remove(EObject eObject) {
}
semanticIndex.inverse().remove(eObject);
}

public Set<Integer> getBidirectionalReferences() {
return bidirectionalReferences;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashCodes shouldn't be used as IDs, as they're not guaranteed to be unique. Even if hashcode are used as a temporary solution, I would use a String-type Set, and a helper method to get a String-ID from an EReference (And there, you may use Integer.toString(ref.hashCode()), so it can easily be replaced later on with proper stable IDs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CamilleLetavernier The code has been adapted now - though it seems, that Github did not catch up with the squashed branches.

Is this now as it should be?


modelState.getIndex().getSemantic(elementId).ifPresent(element -> {
if(element instanceof EReference && ((EReference) element).getEOpposite() != null) {
EcoreUtil.remove(((EReference) element).getEOpposite());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, EcoreUtil.delete() should be preferred, as it will not only remove the object from the model, but also clean all references to that object (Preventing DanglingHref exceptions)

"No edge for label with id " + editLabelAction.getLabelId() + " found");
EReference reference_semantic = (EReference) getOrThrow(index.getSemantic(edge),
"No semantic element for labelContainer with id " + edge.getId() + " found");
String edgeId = editLabelAction.getLabelId().split("_")[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the labelID is created from multiple segments, I would recommend moving the split to a helper method (e.g. ReferenceUtil.getEdgeID(labelId)). It makes it easier to understand the code, and easier to modify

@jcebel jcebel force-pushed the 38-Bidirectional-Ref branch from c4bb258 to f2bddde Compare January 15, 2020 12:17
@jcebel jcebel force-pushed the 38-Bidirectional-Ref branch from f2bddde to 41ec151 Compare January 16, 2020 10:33
@jcebel jcebel force-pushed the 38-Bidirectional-Ref branch from 41ec151 to a07a292 Compare January 16, 2020 10:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add bidirectional references [8] Add bidirectional references
3 participants