Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Oomph » How to display $Author$ in code template
How to display $Author$ in code template [message #1713784] Fri, 06 November 2015 16:06 Go to next message
Thanh Liem PHAN is currently offline Thanh Liem PHANFriend
Messages: 8
Registered: November 2015
Junior Member
Hi all,

I am trying to create a code template for the comment. The comment is something like that:
/**
 * @author $Author$
 * @version $Version$
*/


The "$Author$" and "$Version$" are important because the SVN server will use this info later. Here the problem is the $ sign. I tried to escaped it with $$ like below:

<setupTask
            xsi:type="setup:PreferenceTask"
            key="/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_code_templates"
            value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?>&#xD;&#xA;&lt;templates>&#xD;&#xA;&lt;template autoinsert=&quot;true&quot; context=&quot;typecomment_context&quot; deleted=&quot;false&quot; description=&quot;Comment for created types&quot; enabled=&quot;true&quot; id=&quot;org.eclipse.jdt.ui.text.codetemplates.typecomment&quot; name=&quot;typecomment&quot;>/**&#xD;&#xA; * @author [b]$$Author$$ [/b]&#xD;&#xA; * @version [b]$$Revision$$[/b]&#xD;&#xA; */&lt;/template>&#xD;&#xA;&lt;/templates>"/>


And of course, it did not work, oomph will interpret the appearance of $$ as the existence of a variable, which need to be followed by {var.name}. So something like $${var.name} is always ok.

Does someone have the same problem or any idea?
Thanks for your help.
Re: How to display $Author$ in code template [message #1713822 is a reply to message #1713784] Fri, 06 November 2015 17:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
A $ by itself shouldn't cause a problem. Only ${...} will be recognized
as a variable, and only $$ is recognized as an escape to produce $ in
the final result. E.g., one could specify $${...} if you need ${...} in
the final result. Did you try leaving the $Author$ just as it is? I
don't see how $$ causes a problem either though. Are you saying you are
prompted for variable values because of this?


On 06/11/2015 5:37 PM, Thanh Liem PHAN wrote:
> Hi all,
>
> I am trying to create a code template for the comment. The comment is
> something like that:
> /**
> * @author $Author$
> * @version $Version$
> */
>
> The "$Author$" and "$Version$" are important because the SVN server
> will use this info later. Here the problem is the $ sign. I tried to
> escaped it with $$ like below:
>
> <setupTask
> xsi:type="setup:PreferenceTask"
> key="/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_code_templates"
> value="<?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <templates>
> <template autoinsert="true" context="typecomment_context"
> deleted="false" description="Comment for created types" enabled="true"
> id="org.eclipse.jdt.ui.text.codetemplates.typecomment"
> name="typecomment">/**
> * @author $$Author$$
> * @version $$Revision$$
> */</template>
> </templates>"/>
>
> And of course, it did not work, oomph will interpret the appearance of
> $$ as the existence of a variable, which need to be followed by
> {var.name}. So something like $${var.name} is always ok.
>
> Does someone have the same problem or any idea?
> Thanks for your help.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to display $Author$ in code template [message #1713845 is a reply to message #1713822] Fri, 06 November 2015 23:58 Go to previous messageGo to next message
Thanh Liem PHAN is currently offline Thanh Liem PHANFriend
Messages: 8
Registered: November 2015
Junior Member
Of course, if I use "Author" only, it's ok.
index.php/fa/23858/0/

Then I tried with both $Author$, and $$Author$$. They don't work.
The comment showed in the eclipse target platform is always the default one.
index.php/fa/23859/0/

It seems that if oomph detect an error or a problem in the <template>...</template>, it will replace by the default one.
Re: How to display $Author$ in code template [message #1713847 is a reply to message #1713845] Sat, 07 November 2015 03:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
I'm currently working on better support for recording and applying
preferences where lists and blobs of XML are involved so I tried this
scenario. JDT itself complains if you specify $Author$ and insists you
use $$Author$$. If you try to record this change, the recorder escapes
this to be $$$$Author$$$$ in the recorded value:

<?xml version="1.0" encoding="UTF-8"
standalone="no"?><templates><template autoinsert="false"
context="typecomment_context" deleted="false" description="Comment for
created types" enabled="true"
id="org.eclipse.jdt.ui.text.codetemplates.typecomment"
name="typecomment">/**
* @author $$$$Author$$$$
* @version $$$$Version$$$$
*
*/</template></templates>

So yes, $$ is special in values where Oomph variables are expanded; it
expands to $. So if you want $$ in the expanded final value, it must be
represented as $$$$.

On 07/11/2015 12:58 AM, Thanh Liem PHAN wrote:
> Of course, if I use "Author" only, it's ok.
>
>
> Then I tried with both $Author$, and $$Author$$. They don't work.
> The comment showed in the eclipse target platform is always the default one.
>
>
> It seems that if oomph detect an error or a problem in the <template>...</template>, it will replace by the default one.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to display $Author$ in code template [message #1713859 is a reply to message #1713847] Sat, 07 November 2015 09:23 Go to previous messageGo to next message
Thanh Liem PHAN is currently offline Thanh Liem PHANFriend
Messages: 8
Registered: November 2015
Junior Member
No, I just want $Author$ and not $$Author$$ in the comment.
So if I understand well, using $$Author$$ in code could generate $Author$ in the final comment.
But what I received by using $$Author$$ is always the default comment of OOMPH.
So maybe there is a bug here? Does the newest version of OOMPH support this?
Re: How to display $Author$ in code template [message #1713867 is a reply to message #1713859] Sat, 07 November 2015 10:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comments below.

On 07/11/2015 10:23 AM, Thanh Liem PHAN wrote:
> No, I just want $Author$ and not $$Author$$ in the comment.
Yes, but to achieve that you need $$Author$$ in the template, because
JDT complains and wants you to escape the $ by using two.
> So if I understand well, using $$Author$$ in code could generate
> $Author$ in the final comment.
It's not clear by "in code", but yes, the template must have $$Author$$
to generate $Author$ in the code.
> But what I received by using $$Author$$ is always the default comment
> of OOMPH.
I have no idea what you mean by a default comment. But in the recorded
preference task you must also escape the $$ so in the preference task
you need $$$$Author$$$$. That should generate the correct template
value, of $$Author$$ which should produce the correct code result of
$Author$ in the generated code.
> So maybe there is a bug here?
Did you try $$$$Author$$$$ in your preference task?
> Does the newest version of OOMPH support this?
Which version are you using?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to display $Author$ in code template [message #1713966 is a reply to message #1713867] Mon, 09 November 2015 08:40 Go to previous message
Thanh Liem PHAN is currently offline Thanh Liem PHANFriend
Messages: 8
Registered: November 2015
Junior Member
Ah, it works with $$$$Author$$$$.
So, it requires 2 times to escape the $ sign.

$$$$Author$$$$ (in script.setup)
==> will be $$Author$$ in Preferences/Code Templates
==> will be $Author$ in the generated comment in Java code.

Thanks for your help Ed Merks.


Previous Topic:register project catalog via start parameter
Next Topic:Build configuration with Oomph
Goto Forum:
  


Current Time: Thu Apr 25 01:31:15 GMT 2024

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

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

Back to the top