Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [XText] PostProcessing Question - Add operations with implementation
[XText] PostProcessing Question - Add operations with implementation [message #481140] Wed, 19 August 2009 13:43 Go to next message
Eclipse UserFriend
Hi everyone!

I'm thinking that I need a PostProcessing Definition in my Xtext Project.

In my grammar I have a Rule like this

Block:
'MyKeyword' myContent=STRING
;

The content of myContent can contain SubStructure(s) like

<Begin>ImportantContentPart<End>

After generating all the XText stuff based on my grammar definition, I
would like to have an operation called "getImportantConentPart". This
operation should be callable using an EObject of type "Block"
(myBlock.getImportantConentPart()).

Where can I find an example or a documentation to get this using the Xtend
post processing mechanism?

Any hints?

Thanks in advance, Helko
Re: [XText] PostProcessing Question - Add operations with implementation [message #481152 is a reply to message #481140] Wed, 19 August 2009 15:33 Go to previous messageGo to next message
Eclipse UserFriend
Hi Helko,

have you had a look at value converters? They allow to convert the
parsed information (the '<begin>something</end>' stuff) and extract the
important data directly. Only the value "something" will be set to the
attribute 'foo' in case of foo=TERMINAL_WITH_IMPORTANT_PART;

Adding logic to the body of an EOperation is a tough task. You could
google for the GenModel annotation for EOperations.
( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 1170.html)

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

Am 19.08.09 19:43, schrieb Helko Glathe:
> Hi everyone!
>
> I'm thinking that I need a PostProcessing Definition in my Xtext Project.
>
> In my grammar I have a Rule like this
>
> Block:
> 'MyKeyword' myContent=STRING
> ;
>
> The content of myContent can contain SubStructure(s) like
>
> <Begin>ImportantContentPart<End>
>
> After generating all the XText stuff based on my grammar definition, I
> would like to have an operation called "getImportantConentPart". This
> operation should be callable using an EObject of type "Block"
> (myBlock.getImportantConentPart()).
>
> Where can I find an example or a documentation to get this using the
> Xtend post processing mechanism?
>
> Any hints?
>
> Thanks in advance, Helko
>
Re: [XText] PostProcessing Question - Add operations with implementation [message #481163 is a reply to message #481152] Wed, 19 August 2009 17:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian.

The problem I've mentioned here is a little bit different to that of the
thread
http://www.eclipse.org/newsportal/article.php?id=1850&gr oup=eclipse.modeling.tmf#1850

The Problem here is that the attribute "myContent" can have further
content parts around the <begin>something</end> stuff.

E.g. "SomeText1<begin>something</end>SomeText2"

Parts such as SomeText1 and SomeText2 shall also be serialized back. But
defining converter methods it is not possible to remember SomeText1 and
SomeText2 because these parts will be rejected through the
internalToString converter methode.

So, I'm thinking that I need an additional operation for my "Block"
instead of a converter.

Regards, Helko

Sebastian Zarnekow wrote:

> Hi Helko,

> have you had a look at value converters? They allow to convert the
> parsed information (the '<begin>something</end>' stuff) and extract the
> important data directly. Only the value "something" will be set to the
> attribute 'foo' in case of foo=TERMINAL_WITH_IMPORTANT_PART;

> Adding logic to the body of an EOperation is a tough task. You could
> google for the GenModel annotation for EOperations.
> ( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 1170.html)

> Regards,
> Sebastian
Re: [XText] PostProcessing Question - Add operations with implementation [message #481165 is a reply to message #481163] Wed, 19 August 2009 17:46 Go to previous messageGo to next message
Eclipse UserFriend
Sorry. In the posting before I meant internalToValue instead of
internalToString

Helko
Re: [XText] PostProcessing Question - Add operations with implementation [message #481199 is a reply to message #481163] Thu, 20 August 2009 02:39 Go to previous messageGo to next message
Eclipse UserFriend
Hi Helko,

did the information about the Genmodel annotation for EOperations help
you with your usecase?

Regards,
Sebastian

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

Am 19.08.09 23:28, schrieb Helko Glathe:
> Hi Sebastian.
>
> The problem I've mentioned here is a little bit different to that of the
> thread
> http://www.eclipse.org/newsportal/article.php?id=1850&gr oup=eclipse.modeling.tmf#1850
>
>
> The Problem here is that the attribute "myContent" can have further
> content parts around the <begin>something</end> stuff.
>
> E.g. "SomeText1<begin>something</end>SomeText2"
>
> Parts such as SomeText1 and SomeText2 shall also be serialized back. But
> defining converter methods it is not possible to remember SomeText1 and
> SomeText2 because these parts will be rejected through the
> internalToString converter methode.
>
> So, I'm thinking that I need an additional operation for my "Block"
> instead of a converter.
>
> Regards, Helko
>
> Sebastian Zarnekow wrote:
>
>> Hi Helko,
>
>> have you had a look at value converters? They allow to convert the
>> parsed information (the '<begin>something</end>' stuff) and extract
>> the important data directly. Only the value "something" will be set to
>> the attribute 'foo' in case of foo=TERMINAL_WITH_IMPORTANT_PART;
>
>> Adding logic to the body of an EOperation is a tough task. You could
>> google for the GenModel annotation for EOperations.
>> ( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 1170.html)
>
>> Regards,
>> Sebastian
>
>
Re: [XText] PostProcessing Question - Add operations with implementation [message #481232 is a reply to message #481199] Thu, 20 August 2009 04:06 Go to previous messageGo to next message
Eclipse UserFriend
Dear Sebastian...

Your link to the Genmodel annotations discussion is interessting, but it
is not a discussion about annotation via Xtend.

In the Xtext User Guide there is a section "Customized Post Processing".

Considering the description there, I would need a Xtend *.ext File. In
this *.ext file it should be possible to define "add operations with
implementation using a body annotation."

So, I need something like an official documentation/tutorial to do this
with Xtend.

I have found an example here
http://jevopisdeveloperblog.blogspot.com/2009/07/user-report -migrate-from-oaw-xtext-to.html.
(see "Java Body Annotation in the Ecore Model")

I will try du adapt it. But I'm still searching for a docu/tut.

Regards, Helko



Sebastian Zarnekow wrote:

> Hi Helko,

> did the information about the Genmodel annotation for EOperations help
> you with your usecase?

> Regards,
> Sebastian
Re: [XText] PostProcessing Question - Add operations with implementation [message #481367 is a reply to message #481232] Thu, 20 August 2009 12:05 Go to previous message
Eclipse UserFriend
Hi

I've solved my problem using the post processor to define additional
helper methods for the generated Ecore Model Code.

Regards, Helko

ps:

Here is the content of my ext file:

import ecore;

process(xtext::GeneratedMetamodel this) :
ePackage.process()
;

process(EPackage this) :
eClassifiers.process()
;

process(EClassifier this) :
null
;

process(EClass this) :
if name=='Block' then eOperations.add(addOperation("getFMIdentifier",



'String fmIDSearchString = getAttributesFormatString();
String fmIDKeywordStart = "'+getBlockFMIdentifierKeywordStart()+'";
String fmIDKeywordEnd = "'+getBlockFMIdentifierKeywordEnd()+'";

if(fmIDSearchString == null) return null;

int indexOfFMIDStart = fmIDSearchString.indexOf(fmIDKeywordStart);
int indexOfFMIDEnd;

if (indexOfFMIDStart !=-1){
if(indexOfFMIDStart != fmIDSearchString.lastIndexOf(fmIDKeywordStart)){
//System.out.println("<FMID> scheint mehrfach vorzukommen!");
return null;
}
else{
indexOfFMIDEnd = fmIDSearchString.indexOf(fmIDKeywordEnd);
if(indexOfFMIDEnd != -1){
if(indexOfFMIDStart>indexOfFMIDEnd){
//System.out.println("</FMID> liegt scheinbar vor <FMID>!");
return null;
}
else{
if(indexOfFMIDEnd != fmIDSearchString.lastIndexOf(fmIDKeywordEnd)){
//System.out.println("</FMID> scheint mehrfach vorzukommen!");
return null;
}
else{
//System.out.println(fmIDSearchString.substring(indexOfFMIDS tart+6,
indexOfFMIDEnd));

try {
java.util.UUID.fromString(fmIDSearchString.substring(indexOf FMIDStart+fmIDKeywordStart.length(),
indexOfFMIDEnd));
} catch (Exception e) {
throw new java.lang.IllegalStateException("MalFormed MDL Block FM
Identifier:" +e.getMessage());
}
return
fmIDSearchString.substring(indexOfFMIDStart+fmIDKeywordStart .length(),
indexOfFMIDEnd);

}
}
}
else{
//System.out.println("</FMID> existiert nicht!");
return null;
}
}


}
else{
//System.out.println("<FMID> existiert nicht!");
return null;
}

'))

->

if name=='Block' then eOperations.add(addOperation("getCDMIdentifier",


'String cdmIDSearchString = getAttributesFormatString();
String cdmIDKeywordStart = "'+getBlockCDMIdentifierKeywordStart()+'";
String cdmIDKeywordEnd = "'+getBlockCDMIdentifierKeywordEnd()+'";

if(cdmIDSearchString == null) return null;

int indexOfCDMIDStart = cdmIDSearchString.indexOf(cdmIDKeywordStart);
int indexOfCDMIDEnd;

if (indexOfCDMIDStart !=-1){
if(indexOfCDMIDStart !=
cdmIDSearchString.lastIndexOf(cdmIDKeywordStart)){
//System.out.println("<CDMID> scheint mehrfach vorzukommen!");
return null;
}
else{
indexOfCDMIDEnd = cdmIDSearchString.indexOf(cdmIDKeywordEnd);
if(indexOfCDMIDEnd != -1){
if(indexOfCDMIDStart>indexOfCDMIDEnd){
//System.out.println("</CDMID> liegt scheinbar vor <CDMID>!");
return null;
}
else{
if(indexOfCDMIDEnd != cdmIDSearchString.lastIndexOf(cdmIDKeywordEnd)){
//System.out.println("</CDMID> scheint mehrfach vorzukommen!");
return null;
}
else{
//System.out.println(cdmIDSearchString.substring(indexOfCDMI DStart+6,
indexOfCDMIDEnd));

try {
java.util.UUID.fromString(cdmIDSearchString.substring(indexO fCDMIDStart+cdmIDKeywordStart.length(),
indexOfCDMIDEnd));
} catch (Exception e) {
throw new java.lang.IllegalStateException("MalFormed MDL Block CDM
Identifier:" +e.getMessage());
}
return
cdmIDSearchString.substring(indexOfCDMIDStart+cdmIDKeywordSt art.length(),
indexOfCDMIDEnd);

}
}
}
else{
//System.out.println("</CDMID> existiert nicht!");
return null;
}
}


}
else{
//System.out.println("<CDMID> existiert nicht!");
return null;
}

'))


;

create ecore::EOperation addOperation(ecore::EClassifier c, String
strName, String strBody):
setName(strName) ->
setEType(getEString()) ->
eAnnotations.add(addBodyAnnotation(strBody)) ->
((ecore::EClass)c).eOperations.add(this);


ecore::EDataType getEString():
JAVA de.***.xtext.MDLPostProcessorHelper.getEString();

String getBlockFMIdentifierKeywordStart():
JAVA
de.***.xtext.MDLPostProcessorHelper.getMdlBlockFmIdentifierK eywordStart();

String getBlockFMIdentifierKeywordEnd():
JAVA
de.***.xtext.MDLPostProcessorHelper.getMdlBlockFmIdentifierK eywordEnd();

String getBlockCDMIdentifierKeywordStart():
JAVA
de.***.xtext.MDLPostProcessorHelper.getMdlBlockCdmIdentifier KeywordStart();

String getBlockCDMIdentifierKeywordEnd():
JAVA
de.***.xtext.MDLPostProcessorHelper.getMdlBlockCdmIdentifier KeywordEnd();

create ecore::EOperation addOperation(ecore::EClassifier c, String
strName, ecore::EClassifier type,
List parameters,
String strBody):
setName(strName) ->
setEType(type) ->
parameters.collect(e|((List)e).setParameter(this)) ->
eAnnotations.add(addBodyAnnotation(strBody)) ->
((ecore::EClass)c).eOperations.add(this);

create ecore::EParameter setParameter(List parameter, ecore::EOperation
op):
setName((String)parameter.get(0)) ->
setEType((ecore::EClassifier) parameter.get(1)) ->
op.eParameters.add(this)
;

create ecore::EAnnotation addBodyAnnotation(ecore::EOperation op, String
strBody):
setSource("http://www.eclipse.org/emf/2002/GenModel") ->
this.createBody(strBody) ->
op.eAnnotations.add(this);

create ecore::EStringToStringMapEntry createBody(ecore::EAnnotation anno,
String strBody):
setKey("body") ->
setValue(strBody) ->
anno.details.add(this);
Previous Topic:Fast, normal and Expensive Java validator checks
Next Topic:Bracket matching
Goto Forum:
  


Current Time: Mon Jul 28 04:49:52 EDT 2025

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

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

Back to the top