How to use variable value in live templates in Intellij IDEA? - intellij-idea

I want to create live template for setter.
I've created this template
How can I use value of par variable to generate value of var variable? Basically, I want to avoid redundancy here and put name of variable only once and other one will be generated automatically by some algorithm.
UPDATE
I want to clarify a little bit what I want to achieve.
Suppose I want to create setter with name setTime which has parameter time.
public void setTime(long time)
{
// ...
}
I don't want to type "time" twice - capitalized and non-capitalized. I want to type just parameter name so method name will be generated automatically.
UPDATE (Answer)
Turned out that variable order is important. This is final result of what I want

You can use the soutv as an example, notice how it defines a copy of a variable:
It's also possible to define custom expression for live templates via plugins or Groovy code:
How can i add custom expression functions for Live templates in Intellij.

Related

Azure DevOps Access Custom Field From Script

I have a required custom field on any ticket created (Bug, Tasks, PBI).
I have a pipeline that creates tickets automatically, but the values that are used to create these tickets doesn't have a value for my custom field. I want to set this custom field by adding an entry to the pipeline variables, but I don't know the variable name of the custom field.
How can I find the variable name of the custom field so I can access it?
I found out how to determine your custom variable name.
ADO has a bunch of APIs. The following will give you all the details of a specific work type. For my case I needed the "bug" work type.
/*
Api to display work type fields in JSON format
Replace {} with correct values
*/
https://dev.azure.com/{orginization}/{project}/_apis/wit/workitemtypes/{type}/fields?api-version=6.0
The resulting JSON will give you a whole list of variables. Here is what the System Variable and a Custom Variable look like.
The referenceName is the variable name you would use in your scripts, etc.
TL;DR -
Take your field name and remove all spacing and then put Custom. in front of it.
Custom.FieldNameWithNoSpace

Telosys does not generate column definition (i.e. for CHAR-columns)

When using Telosys to generate entities with the java7-persistence-commons-jpa-T300 templates the column annotation never includes columnDefinition when generating the #Column annotation in JpaRecord-classes. That forces database schemageneration with hbm2ddl always to generate VARCHAR columns.
But when the origin database column is an CHAR-column the generated record-class should also generate columnDefinition... i.e.: #Column(columnDefinition = "CHAR(xx)", name = "VVT_NR", nullable = false, length = 20)
Is there a way to force telosys to generate the columnDefinition (with correct length for xx of course)?
The JPA function "$jpa.fieldAnnotations()”
used in the mentioned template is a shortcut to generate the "classical" JPA annotations for a given field and indeed it doesn’t generated all the “#Column” optional elements (for example “table”, “insertable”, “updatable” and “columnDefinition” are not generated)
In version 3 there's no way to force the generator to produce the "columnDefinition".
But if you really want to generate the “columnDefinition” you can create a specific function or a specific macro.
To create a Velocity macro see :
http://www.telosys.org/templates-doc/velocity/macro.html
http://people.apache.org/~henning/docbook/html/ch07.html
To create a specific function see this other question :
Is it possible in a Telosys template to call a function created specifically?
For a specific function you can reuse the "$jpa" class source code :
https://github.com/telosys-tools-bricks/telosys-tools-generator/blob/master/src/main/java/org/telosys/tools/generator/context/Jpa.java

How to apply more than one function to a passed in live template variable?

I'm trying to build a Python Unit Test File Template in PyCharm. The overall result I want to achieve is:
A user creates a new file with my template, say "widget_builder.py"
Inside the template I want to create the class name by taking the file name "widget_builder" and turning it into "WidgetBuilderTests"
It looks like I need to use a Live Template to manipulate the file template variable $FILE_NAME$?
How can I create a Live Template that given a passed in variable (in this case $FILE_NAME$), applies both the underscoresToCamelCase and capitalize functions to it?
If I declare the Template text as:
$CLASS_NAME$
...and then edit variables, how can I reference a passed in variable of '$FILE_NAME$'?
I'd imagine it to look something like this, but I just can't get it to work:
I'm sure there must be a way to do this, but I just can't quite wrap my head round it.
Is this possible? Thanks!
EDIT
I've got a bit further. If I define the template as this:
If I then use it, this happens:
So the end result of $CLASS_NAME$ (WidgetBuilder) on the left is what I want, but I don't want $FILE_NAME$ (widget_builder) to be there once I hit return.
So your problem here is that $FILE_NAME$ is not a native variable in the live templates, merely an arbitrary name. What you actually want to be using is another function: fileNameWithoutExtension().
So your template would look something like:

Can I use e.parameter in conjunction with a global variable to retrieve an external variable in Google Apps Scripts?

I realize the question is confusing. I'm trying to reference many widgets that were created in the main loop of my script from a secondary function using e.parameter.
Instead of referencing each e.parameter separately, by its name, I'd like to be able to make one reference to e.parameter and have the parameter name portion be a globally defined variable.
As in:
e.parameter.some_id
Would be the same as:
var test=[]
test[0]='some_id'
e.parameter.(test[0])
Or some other syntax. I'm trying to reference the parameters in a loop, and using the array means I can increment a for loop counter instead doing if tests for each parameter individually.
I'm certain there's an easier way to do this, but I'm still new to java.
Use e.parameter[test[0]] . It is not java but JavaScript

How do I use Team Build Properties in MSBuild?

I have a simple tfs-2010 build definition using the default process template. In it I defined the Build Number Format using $(BuildID) to define part of the computed field. This works and I can see what BuildID's value is.
Now I try to pass the BuildID property to MSBuild as an argument:
/p:SomeProperty=$(BuildID)
However when I look at the build log I see SomeProperty literally equals $(BuildID) rather then the value of BuildID.
What am I missing?
Update for clarity: What I'm asking is how to reference as a Build Process Parameter in the Build Definition. For example Build Number Format has a default expression of $(BuildDefinitionName)_$(Date:yyyyMMdd)$(Rev:.r)
You need to use a VB.NET expression. For example:
String.Format("/p:SomeProperty={0}", BuildDetail.BuildNumber)
The Build Number tokens, e.g. $(BuildDefinitionName), are specific to the Build Number Format process parameter. They aren't tokens that you can use anywhere else in the build process. Most are available in the BuildDetail object or from the environment. The Build Id is a bit of a special case, however. It comes from the identity column of the builds table and isn't directly exposed in our public API. You could extract it from the BuildNumber, like this:
BuildDetail.BuildNumber.Substring(BuildDetail.BuildNumber.LastIndexOf('/') + 1)
Note that you would need to do this in the XAML directly rather than putting a VB expression into the build process parameter editor GUI. That's because those values just get passed through as literal strings.