Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem:Hierarchical Presentation of Referential Syntax in the Outline.(The correct hierarchical structure is not obtained in the outline after using referential syntax.)
Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861432] Thu, 12 October 2023 11:53 Go to next message
Eclipse UserFriend
Hi, everyone. I have a question regarding the outline presentation in DSL files, and I hope you can provide me with some suggestions. Below is my grammar:

Modele:
modeles+=(ModelePackage)*
;
ModelePackage:
A | B | C
;
A:
'A' name=ID
;
B:
'B' name=ID ref=[A]
;
C:
'C' name=ID ref=[B]
;

As you can see in the grammar, I'm using references to models B and C. Then, I've included an example of my DSL file:

A a1
A a2
B b a1
C c b

In the grammar definition, because I'm referencing A within B and C within B, I would like the DSL file's outline to display 'b' as a child of 'a1' and 'c' as a child of 'b',like this:

Model:
a1
-b
-c
a2

but the current result shows all elements in a single column without the correct containment relationships, like this:

Model:
a1
a2
b
c

I prefer to achieve the correct outline presentation by making changes to the grammar itself, without resorting to Java code in the OutlineTreeProvider. I'd appreciate any suggestions and insights you can offer, thanks!
Re: Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861437 is a reply to message #1861432] Thu, 12 October 2023 13:07 Go to previous messageGo to next message
Eclipse UserFriend
i have very serve doubts this can be done purely with grammar.
maybe you can make use of IDerivedStateComputer to achive non flat ast

https://xtextcasts.org/episodes/18-model-optimization
Re: Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861486 is a reply to message #1861437] Mon, 16 October 2023 07:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
Thanks for your response.
I shall proceed to attempt it as per your guidance.
Re: Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861575 is a reply to message #1861437] Thu, 19 October 2023 14:01 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
Based on the method you provided last time, I attempted to rewrite the code in the DefaultOutlineTreeProvider to achieve the correct hierarchy in the outline. However, I'm encountering some issues with the code implementation and would like to seek your advice.

Here is my grammar:
Modele:
modeles+=(ModelePackage)*
;
ModelePackage:
A | B | C
;
A:
	'A' name=ID 
;
B:
	'B' name=ID 'To' ref=[A]
;
C:
	'C' name=ID 'To' ref=[B]
;


And here's the code I've rewritten:
public class MyDslOutlineTreeProvider extends DefaultOutlineTreeProvider {
	@Override
	public void _createChildren(IOutlineNode parentNode, EObject modelElement) {
		if (modelElement instanceof B) {
			A parentB = ((B) modelElement).getRef();
			if (parentB != null) {
				EObject nodeA=parentB;
				IOutlineNode parent=findOutlineNode(parentNode, nodeA);
				if (parent != null) {
					createEObjectNode(parent, modelElement);
				}
			}
		} else if (modelElement instanceof C) {
			B parentC = ((C) modelElement).getRef();
			if (parentC != null) {
				EObject nodeB=parentC;
				IOutlineNode parent=findOutlineNode(parentNode, nodeB);
				if (parent != null) {
					createEObjectNode(parent, modelElement);
				}
			}
		} else {
			 super._createChildren(parentNode, modelElement);
		}
	
	}


	private IOutlineNode findOutlineNode(IOutlineNode node,EObject element) {
		for(IOutlineNode child : node.getChildren()) {
			if (child.getText().equals(element.eGet(EcorePackage.Literals.ENAMED_ELEMENT__NAME))){
				return child;
			}
		}
		return null;
	}
}


In the code, my idea was to locate the position of the referenced parent element in the outline and then add the child elements under the parent, displaying the appropriate containment relationships. However, with the code I've written, the outline's hierarchy structure hasn't changed, and all elements are listed in the same column.

I would greatly appreciate your assistance in addressing this matter. Thank you!
Re: Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861595 is a reply to message #1861575] Fri, 20 October 2023 14:16 Go to previous messageGo to next message
Eclipse UserFriend
i dont understand why you search nodes in the outline. i would expect you to change the provider to create the nodes in the correct structure

public class MyDslOutlineTreeProvider extends DefaultOutlineTreeProvider {
	
	@Override
	protected void _createChildren(DocumentRootNode parentNode, EObject modelElement) {
		if (modelElement instanceof Modele) {
			EObjectNode modeleNode = createEObjectNode(parentNode, modelElement);
			for (ModelePackage p : ((Modele) modelElement).getModeles()) {
				if (p instanceof A) {
					EObjectNode aNode = createEObjectNode(modeleNode, p);
					for (ModelePackage px : ((Modele) modelElement).getModeles()) {
						if (px instanceof B) {
							if (((B) px).getRef() == p) {
								EObjectNode bNode = createEObjectNode(aNode, px);
								for (ModelePackage pxx : ((Modele) modelElement).getModeles()) {
									if (pxx instanceof C) {
										if (((C) pxx).getRef() == px) {
											 createEObjectNode(bNode, pxx);
										}
									}
								}
							}
						}
					}
				}
			}
			
		} else {
			super._createChildren(parentNode, modelElement);
		}
	}

}

[Updated on: Fri, 20 October 2023 14:59] by Moderator

Report message to a moderator

Re: Problem:Hierarchical Presentation of Referential Syntax in the Outline. [message #1861615 is a reply to message #1861595] Mon, 23 October 2023 08:54 Go to previous message
Eclipse UserFriend
Thank you very much Christian, it is working as expected.
I will ensure to write my code correctly by understanding your approach.
Previous Topic: Xtext 2.33.0.M2 is out
Next Topic:How to customize the scope of a reference
Goto Forum:
  


Current Time: Mon Feb 10 10:10:14 GMT 2025

Powered by FUDForum. Page generated in 0.03281 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top