Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding comments using the JvmModelInferrer(Prepend toField/toClass/... with some generated comment)
Adding comments using the JvmModelInferrer [message #865377] Mon, 30 April 2012 11:20 Go to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 149
Registered: March 2010
Senior Member
Hello,

I am using the JvmModelInferrer to generate java code from my xtext grammar. Since I'm a quite new user (<2w) for the library, I'm stuck looking for the API to generate comments from the model inferrer. For example, the code below:

// this is a reference to a message part
val fieldType = typereferences.getTypeForName(member.refTo.fullyQualifiedName.toString, element)
if (fieldType != null) {
	// How do I do something like this:
	// elementClass.addSingleLineComment("This is field " + member.name)
	elementClass.members += member.toField(member.name, fieldType
		) [
			makePublic
		]
}


...or maybe something like this exists?:

// this is a reference to a message part
val fieldType = typereferences.getTypeForName(member.refTo.fullyQualifiedName.toString, element)
if (fieldType != null) {
	// How do I do something like this:
	// elementClass.addSingleLineComment("This is field " + member.name)
	newMemberField = member.toField(member.name, fieldType
		) [
			makePublic
		]
	newMemberField.addComment("this will appear before this field")
	elementClass.members += newMemberField
}

Re: Adding comments using the JvmModelInferrer [message #865394 is a reply to message #865377] Mon, 30 April 2012 11:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i do not know if it is possible to do this single line comment stuff at all. why do you think this should be possible?
why dont you simply use the std documentation adapter?

members += f.toField(f.name, f.type) [
    documentation = "Das ist ein Test"
]


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding comments using the JvmModelInferrer [message #865428 is a reply to message #865394] Mon, 30 April 2012 11:50 Go to previous messageGo to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 149
Registered: March 2010
Senior Member
First of all, thank you for your response. It is helpful in the sense that I should "stop looking for something that doesn't exist" so it's good to know.

Regarding why I want to do that: I am aware of the documentation tag, but this is provided by the user of my grammar and I don't want to override it. The comment I want to add is *not* intended to be javadoc but more like a "source beautifier" for developers reading the generated code.

The example below should clarify what I mean to do. My grammar allows one to write the following in my DSL:

protocol my.protocol specification {
	part Header {
		/** user javadoc here - PRESERVE THIS */
		type	: ByteField
		len	: ByteField
	}
	part CommonParts {
		// ... some fields here
	}
	message SomeMessage {
		injectFieldsFrom  Header
		oneField	: ShortField
		anotherField	: ByteField
		commonFields asReferenceTo CommonParts
	}
}


The intent is to be able to produce code like this:

package my.protocol;

class SomeMessage  {
	// START --- copied from my.protocol.Header
	/** user javadoc here - PRESERVE THIS */
	byte type;

	byte len;
	// END --- copied from my.protocol.Header

	short oneField;

//...
}


Any javadoc in the original
Re: Adding comments using the JvmModelInferrer [message #865445 is a reply to message #865428] Mon, 30 April 2012 12:01 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i guess you wont get this for free.
you have to come up with a own/customized JvmTypesBuilder and JvmModelGenerator
e.g. by adding a SingleLineDocumentationAdaperBefore and a SingleLineDocumentationAdaperAfter in the inferrer
and query it in the generator like it is done for the javaDoc

or maybe do not use jvm modell inferrer for this generation at all.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 30 April 2012 12:01]

Report message to a moderator

Previous Topic:failure on XVariableDeclaration resolution in XBaseInterpreter
Next Topic:[SOLVED] Referencing Java methods by annotation
Goto Forum:
  


Current Time: Thu Apr 18 14:53:49 GMT 2024

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

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

Back to the top