Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext 2.0 Syntax Coloring(2) NodeUtil class not exists in Xtext 2.0)
Xtext 2.0 Syntax Coloring [message #708869] Wed, 03 August 2011 08:43 Go to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hello
I faced with a problem while I was trying to add syntax coloring feature for a type.

I have created a OurDefaultHighlightingConfiguration class (in com.example.mydsl.ui same packet with DslUIModel)which implements ISemanticHighlightingCalculator and overridden

following method

However, when I want to call NodeUtil, there is not such a NodeUtil class?
If you can help, I will appreciate

BR
Caner


@Override
	public void provideHighlightingFor(XtextResource resource,
			IHighlightedPositionAcceptor acceptor) {

/*
    if(resource==null)
      return;	
    
     Iterable<AbstractNode> allNode= NodeUtil.getAllContents(resource.getParseResult().getRootNode());

  
*/
}


[Updated on: Wed, 03 August 2011 20:26]

Report message to a moderator

Re: NodeUtil class not exists [message #708881 is a reply to message #708869] Wed, 03 August 2011 08:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
Hi,

this has changed in 2.0.0
http://www.eclipse.org/Xtext/documentation/2_0_0/213-migrating-from-1.0.php

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: NodeUtil class not exists [message #708906 is a reply to message #708881] Wed, 03 August 2011 09:17 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi again

I am already using Xtext 2.0 and I never used previous version.

Should I still do that migration stuff
BR
Caner
Re: NodeUtil class not exists [message #708907 is a reply to message #708906] Wed, 03 August 2011 09:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
Why then using NodeUtil wich is an Xtext 1.0.x only class?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: NodeUtil class not exists [message #708918 is a reply to message #708907] Wed, 03 August 2011 09:32 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 747
Registered: July 2009
Location: Dortmund, Germany
Senior Member

I think you just copied that from examples that were for Xtext 1.x. Use NodeModelUtils now.

~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: NodeUtil class not exists [message #708953 is a reply to message #708907] Wed, 03 August 2011 10:22 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Smile its not me its Xtext user Guide they didnt imply which version they support with this document

I have a old one 2008-2010,
thanx
Caner
Re: NodeUtil class not exists [message #708982 is a reply to message #708953] Wed, 03 August 2011 11:16 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi again
now I have the code as below, is there anything missing? I didnt understand why it not working

I have implemented these two classes

public class MyHighlightingConfiguration implements IHighlightingConfiguration {
	 
	  public final static String my_REF = "first reference"; 

	  public void configure(IHighlightingConfigurationAcceptor acceptor) {
	   acceptor.acceptDefaultHighlighting(my_REF, 
	      "first_reference", myReferenceTextStyle());
	  }
	  
	  public TextStyle myReferenceTextStyle() {
	    TextStyle textStyle = new TextStyle();
	    textStyle.setStyle(SWT.ITALIC);
	    textStyle.setColor(new RGB(127,0,85));
	    return textStyle;
	  }
	}



public class OurDefaultHighlightingConfiguration implements ISemanticHighlightingCalculator {
	
	public void provideHighlightingFor(XtextResource resource, 
		    IHighlightedPositionAcceptor acceptor) {
		  if (resource == null || resource.getParseResult() == null)
		    return;
		    
		  INode root = resource.getParseResult().getRootNode();
		  
                  //Writer is the target type for coloring
		
                   for (INode node : root.getAsTreeIterable()) {
		    if (node.getGrammarElement() instanceof Writer) {
		      acceptor.addPosition(node.getOffset(), node.getLength(), 
		        MyHighlightingConfiguration.my_REF);
		    }
		  }
		}
	
	
}



And I bind them in the DSLUIMODEL


public class DSLUiModule extends AbstractDSLModule {

	......

	 public Class<? extends OurDefaultHighlightingConfiguration> bindISemanticHighlightingCalculator(){
		 return OurDefaultHighlightingConfiguration.class;
	 }
	
	
	public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration () {
		    return MyHighlightingConfiguration.class;
		  }

          }


BR caner

[Updated on: Wed, 03 August 2011 11:16]

Report message to a moderator

Re: NodeUtil class not exists [message #709015 is a reply to message #708982] Wed, 03 August 2011 12:05 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I guess Writer is a type of the meta model and not a "grammar element" type. How about debugging? Check what node.getGrammarElement() actually returns.

Also you are not forced to iterate the parse tree. If you have simple access to the writers from the semantic model, iterate over them, use NodeModelUtils to navigate to te parse tree node in order to obtain offset and length.

Alex
Re: NodeUtil class not exists [message #709045 is a reply to message #709015] Wed, 03 August 2011 12:49 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi

yes, you are right Alex, the Writer is a type which has defined like this


import "http://www.eclipse.org/emf/2002/Ecore" as ecore

LibModel:
  (types+=Type)*;            

Type:
  LibComment1|NonEmpityLine;

  LibComment1: 
  	text=HASH_COMMENT
  	  ;  
 

 NonEmpityLine hidden (WS) : 

   	Writer=Writer  ':'  WritersBooks=WritersBooks':'  

		 
 Writer:
	Writer=Words
;


 Words hidden ():  	ID    ;
	
 




So How I need to call writer for coloring? can you give me an example how it supposed to be? Is there any link for a sample???
BR
Caner

[Updated on: Wed, 03 August 2011 13:22]

Report message to a moderator

Re: NodeUtil class not exists [message #709176 is a reply to message #709045] Wed, 03 August 2011 15:37 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

as I wrote in my last post! Either you filter out the right grammar element or you don't navigate over the parse tree but the semantic model. You get passed a resource. A resource has contents (in case of an XtextResource a single element). The content has a type, you should know the type (LibModel). You can walk over its contents, extract the Writers and use NodeModelUtils to navigate to the parse tree for extracting offset and length.

Alex

P.S.: Have you actually tried searching the web for ISemanticHighlightingCalculator?


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: NodeUtil class not exists [message #709280 is a reply to message #709176] Wed, 03 August 2011 18:27 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi

Thanx for explanation, The problem is with Xtext 2.0 , its new and therefore, there are not so much sample or tutorial and people didnt observe Xtext 2.0 in the blogs, thats why the documentation is weak

if there is something about xtext on the web 99% is xtext 1.x for instance there is not a link which used NodeModelUtils in a sample

BR
Caner

[Updated on: Wed, 03 August 2011 18:38]

Report message to a moderator

Re: NodeUtil class not exists [message #709293 is a reply to message #709280] Wed, 03 August 2011 18:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
this is why i pointed you to the migration guide

Quote:
Rewritten Node Model
To reduce memory consumption, the node model has been redesigned in Xtext 2.0. We no longer use EMF, but a chained list of compressed nodes instead.

The package org.eclipse.xtext.nodemodel now contains the relevant interfaces to program against. The new interfaces follow the naming convention of other types in the framework. They are called INode (src), ICompositeNode (src) and ILeafNode (src). That way, most of the migration will be done by prefixing the old names with an I and use the organize imports tool. Please make sure not to program against concrete or abstract classes.

If you used the node model a lot, you should have a closer look at the new APIs. The EObject API is no longer available on the nodes. Instead, you we offer a couple of Iterables for traversing the tree. Where appropriate, helper methods of the former ParseTreeUtil and NodeUtil have become members of the nodes, e.g. NodeUtil.getAllContents(AbstractNode) has become INode.getAsTreeIterable() (src) The remaining methods have been converted and moved to the new NodeModelUtils (src).


so you won't need any 2.0 specific code since you should be able to translate the 1.0 code to 2.0 code

Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: NodeUtil class not exists [message #709304 is a reply to message #709293] Wed, 03 August 2011 19:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
So with proper naming and binding the following might work

package org.xtext.example.mydsl.ui;

import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.xtext.example.mydsl.services.MyDslGrammarAccess;

import com.google.inject.Inject;

public class OurDefaultHighlightingCalculator implements ISemanticHighlightingCalculator {
	
	@Inject
	private MyDslGrammarAccess grammarAccess;
	
	public void provideHighlightingFor(XtextResource resource, 
		    IHighlightedPositionAcceptor acceptor) {
		if (resource == null || resource.getParseResult() == null)
		    return;
		    
		  INode root = resource.getParseResult().getRootNode();
		  
                  //Writer is the target type for coloring
		
                   for (INode node : root.getAsTreeIterable()) {
		    if (node.getGrammarElement() instanceof RuleCall && ((RuleCall)node.getGrammarElement()).getRule().equals(grammarAccess.getWriterRule())) {
		      acceptor.addPosition(node.getOffset(), node.getLength(), 
		        MyHighlightingConfiguration.my_REF);
		    }
		  }
		}
	
	
}


	public Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator(){
		 return OurDefaultHighlightingCalculator.class;
	 }
	
	
	public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration () {
		    return MyHighlightingConfiguration.class;
		  }


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: NodeUtil class not exists [message #709322 is a reply to message #709304] Wed, 03 August 2011 19:42 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Christian

Thank you so much for your sample and explanation With this block Xtext is really robust tool Smile even if 2.0 is just released.

BR
Re: NodeUtil class not exists [message #709336 is a reply to message #709322] Wed, 03 August 2011 20:13 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
By the way how should i implement the plugin installation site?
there is two different project com.example.mydsl and ..mydsl.ui
Should i implement for each one?
Re: NodeUtil class not exists [message #709342 is a reply to message #709336] Wed, 03 August 2011 20:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
Depends on if it happens that you may want to install only one (runtime)=> two features.
and please: new topics should go into a new topic


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: NodeUtil class not exists [message #713482 is a reply to message #709342] Mon, 08 August 2011 14:23 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Christian

Regarding syntax coloring;

If a type has a keyword/symbol , I am not able to implement syntax coloring for that type, for example i have a type which has "keyword" as a keyword
and try to create syntax coloring feature just like below, but it doesnt work. Do you have any advice for me please?

BR
caner

Grammar
LibModel:
  (types+=Type)*;            

Type:
  typeWithKey|NonEmpityLine;

typeWithKey: 'keyword' type=Words ;

Words hidden (): ID ;



public class OurDefaultHighlightingConfiguration implements
		ISemanticHighlightingCalculator {


	public void provideHighlightingFor(XtextResource resource, 
		    IHighlightedPositionAcceptor acceptor) {
		if (resource == null || resource.getParseResult() == null)
		    return;
		    
		  INode root = resource.getParseResult().getRootNode();
		 
    for (INode node : root.getAsTreeIterable()) {
		    if (node.getGrammarElement() instanceof 
RuleCall&& (RuleCall)node.getGrammarElement()).getRule().equals(grammarAccess.gettypeWithKeyRule())) {
		      acceptor.addPosition(node.getOffset(), node.getLength(), 
		        MyHighlightingConfiguration.typeWithKey_Ref);
		    }



public class MyHighlightingConfiguration implements IHighlightingConfiguration {

 public static String typeWithKey_Ref = "keyword";
--etc---

public void configure(IHighlightingConfigurationAcceptor acceptor) {
	
	    acceptor.acceptDefaultHighlighting(typeWithKey_Ref , 
			      "With Key", mytypeWithKeyTextStyle());
	    
  private TextStyle mytypeWithKeyTextStyle[code][/code]() {
		  TextStyle textStyle = new TextStyle();
		    textStyle.setStyle(SWT.ITALIC);
		    textStyle.setStyle(SWT.BOLD);
		    textStyle.setColor(new RGB(42, 0, 255));
		    return textStyle;
	
	
	}



and of course these classes have been binned in UIModule.java

[Updated on: Mon, 08 August 2011 14:25]

Report message to a moderator

Re: NodeUtil class not exists [message #713555 is a reply to message #713482] Mon, 08 August 2011 15:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
Hi,

are you talking about the highlighting of the keyword or of the rest?
btw in my case it is all blue

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 08 August 2011 16:05]

Report message to a moderator

Re: NodeUtil class not exists [message #713590 is a reply to message #713555] Mon, 08 August 2011 16:13 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi
Both of do not work Smile and rest seems more important
BR caner
Re: NodeUtil class not exists [message #713594 is a reply to message #713590] Mon, 08 August 2011 16:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
HI,

can you elaborate a bit more on the indended behaviour?
as i said before: works for me

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: NodeUtil class not exists [message #713608 is a reply to message #713594] Mon, 08 August 2011 16:42 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi
If I have a line like ;

keyword = something [Updated on 02. 02.2011 18:05]


My Id allows me to type like this, no error but also there is no coloring function, explicitly its black, and can not change the color from preferences

BR
Re: NodeUtil class not exists [message #713612 is a reply to message #713608] Mon, 08 August 2011 16:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
As i said before:

works with the stuff you posted. did you try to debug your stuff?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: NodeUtil class not exists [message #713619 is a reply to message #713612] Mon, 08 August 2011 17:03 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Thanx , I gonna observe it, and come back
BR
caner
Re: NodeUtil class not exists [message #713650 is a reply to message #713619] Mon, 08 August 2011 18:18 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi
I dont know what is wrong but it seems each method is alive

and entire line (ley word and ID are still black)

caner
Re: NodeUtil class not exists [message #713665 is a reply to message #713650] Mon, 08 August 2011 18:54 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
sry, without an reproducable example i cannot help. ~Christian

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: NodeUtil class not exists [message #713670 is a reply to message #713650] Mon, 08 August 2011 18:48 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
Do you actually open the editor for your language or is it a plain text
editor, e.g. does content assist work?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 08.08.11 20:18, Caner wrote:
> Hi
> I dont know what is wrong but it seems each method is alive
>
> and entire line (ley word and ID are still black)
>
> caner
Previous Topic:[Xtext 2.0] Reserved word 'is'?
Next Topic:Exact Xtext 2.0.1 git rev
Goto Forum:
  


Current Time: Fri Apr 23 15:39:36 GMT 2021

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

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

Back to the top