live templates method format question

Answered

There're something format question when I add a method live templates

 

1.the script:

groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {if(i == 0){result+='* @param ' + params[i] + ((i < params.size() - 1) ? '\\n\\b' : '')}else{result+=' * @param ' + params[i] + ((i < params.size() - 1) ? '\\n\\b' : '')}}; return result", methodParameters())

 

 

2.step1:

when I use my template generate annotation, it will focus on the date:

 

3.step2

when I enter the keyboard "enter", it focus on time, and show the format question:

 

 

4. I paste the annotation to the textmate, I found it auto add <BS> to the annotation, but it doesn't show in idea.

 

 

So, I ask for your help

How can I make wipe "<BS>" in the script?

Thank you very much

0
14 comments

ask for another question:

I add the Duser.name in idea.vmoptions

 

but it still show me my mac user name "design", not the Duser.name "Jiandong.Li"

 

0

>How can I make wipe "<BS>" in the script?

I'm not aware of any way to wipe it when the template is applied, but what about removing `\\b` from your grrovy script?

>but it still show me my mac user name "design", not the Duser.name "Jiandong.Li"

Please make sure to use Help | Edit custom VM options... to modify the options; also, you have to re-start the IDE after changing

-Duser.name

to get it recognized

0

Elena Pogorelova

Your solution is so good.

<BS> and user name is fix by your solution.

But the retract question is still. 

 

 

another question:

where is the exception?

 

could you show your live templates about method comment so that I can study from you?

thank you very much.

 

0

>But the retract question is still. 

Looks like the code created with groovyScript is not formatted on expanding the template, unlike the code produced by other expression. You can reformat the code manually once the template expansion is completed

>where is the exception?

Can you provide the full definition of your live template?

0

 

template text:

 

**
* @Description:
* @Author: Jiandong.Li
* @Date: $date$ $time$
* @throws: $exception$
$params$
* @return: $return$
* @user: $user$
*/

 

 

 

 

script:

groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+='* @param ' + params[i] + ((i < params.size() - 1) ? '\\n ' : '')}; return result", methodParameters())

 

 

------------------

 

 

I think your live template is neat and orderly, could you show me to study?

thank you.

 

0

Unfortunately there are no template macros that would return method throws clause; expressionType() won't work here - it returns a type of expression passed as argument, not the name of exception class

 

>I think your live template is neat and orderly, could you show me to study?

I don't have any:)

0

Do you mean Idea can't add a "exception" pattern by template macros ? So the @throws: ________ is empty.

 

but why Idea default can auto generate like this?

I want to write the exception in my template like this, do you know how to do it?

 

 

0

>Do you mean Idea can't add a "exception" pattern by template macros

yes, exactly

 

>but why Idea default can auto generate like this?

sure it has methods for generating this stuff, but these methods are not exposed through live template macros

0

Thank you very much Elena 

So I advise Idea developer group can make this function more better.

 

0

I found sth:

1.

If do like it can fix pattern like * position question

 

now it is normal and needn't I press the "enter":

 

 

2.

methodParameters() will print method params [req, requestionMap]

 

 

so do you know where is "methodParameters()" detail describe in document? maybe I can find the which maybe call "exceptionParameters" in that document.

 

0

methodParameters() is described in https://www.jetbrains.com/help/idea/2018.3/settings-live-templates.html#predefined_functions:

methodParameters()

Returns the list of parameters of the method in which the template is expanded

You were already using it in your groovyscript, BTW:

groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+='* @param ' + params[i] + ((i < params.size() - 1) ? '\\n ' : '')}; return result", methodParameters())

>maybe I can find the which maybe call "exceptionParameters" in that document.

As I wrote, there is no template macro for method exception clause

0

I see, Thank you ^_^

0

 i have the same question 

how can i get the exceptionType?

0

How do you intend to use this in the live template?
Please leave your comments in https://youtrack.jetbrains.com/issue/IDEA-256288

0

Please sign in to leave a comment.