Skip to content

Commit

Permalink
170: getEObjectRepr non-recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed May 26, 2020
1 parent 0b8a082 commit 0c69b53
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions edelta.parent/edelta.lib/src/edelta/lib/EdeltaLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,23 @@ public EEnumLiteral newEEnumLiteral(String name, Consumer<EEnumLiteral> initiali
* @return
*/
public String getEObjectRepr(EObject e) {
return getEObjectReprInternal(e, new HashSet<>());
}

private String getEObjectReprInternal(EObject e, Set<EObject> seen) {
if (e == null)
return "";
String info = e.toString();
if (e instanceof ENamedElement) {
info = ((ENamedElement) e).getName();
Set<EObject> seen = new HashSet<>();
StringBuilder builder = new StringBuilder();
EObject current = e;
while (current != null) {
if (builder.length() > 0)
builder.insert(0, ".");
if (current instanceof ENamedElement) {
builder.insert(0, ((ENamedElement) current).getName());
} else {
builder.insert(0, current.toString());
}
if (seen.contains(current))
break;
seen.add(current);
current = current.eContainer();
}
if (seen.contains(e))
return info;
seen.add(e);
return e.eContainer() != null ?
getEObjectReprInternal(e.eContainer(), seen) + "." + info :
info;
return builder.toString();
}

public void addEStructuralFeature(EClass eClass, EStructuralFeature eStructuralFeature) {
Expand Down

0 comments on commit 0c69b53

Please sign in to comment.