How do I auto generate an arbitrary number (Long) for use in a Live Template in IntelliJ?
Example:
public static final long uid = $randomLong$;
where randomLong is replaced with a random long value. I have tried adding the following as an expression for the variable on the live template definition but nothing is generated when the template outputs.
new Random().nextLong()
What I am trying to achieve is very similar to what the IDEA code inspector generates for the Serialization version UID field but with a live template.
Please try adding groovyScript("new Random().nextLong()") as the variable expression instead.
Related
How to solve an example in a string?
Let's say we have val example : String = "3+5"
So how do I solve this example? Or if val example : String = "3*5/3"
Two ways to achieve it:
Keval - 3rd party dependency
You can either use Keval.eval("(3+4)(2/8 * 5) % PI") or as an extension function on String, "(3+4)(2/8 * 5) % PI".keval(). This will return the calculated value as Double. For your example, "3*5/3".keval().
To use it, add implementation("com.notkamui.libs:keval:0.8.0") in dependencies in app level build.gradle file and sync gradle. Then, use it in any file as mentioned in the above para, put the cursor on the line and press Alt + Enter (or hover for suggestions) to import the necessary imports.
Look into its Readme.md on the provided link for more usage and implementation details.
Custom String parsing using BODMAS rule
You can split the string using the BODMAS rule, parse the split array as int/double, if it throws exception, it means the substring is an expression too, again split it using BODMAS, parse and perform the calculation.
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
I'm currently running some performance tests and am having issues converting a string I have extracted from JSON into an int.
The problem I'm having is that I need this number which has been extracted as both an int and a string, its currently only a string and I don't see how I can create another variable where the number is an int.
Here is the JSON extractor I'm using
How can I have another variable which is an int?
By default JMeter stores values into JMeter Variables in String form, if you need to save it in Integer form as well you can do it using i.e. __groovy() function like:
${__groovy(vars.putObject('Fixture_ID_INT'\, vars.get('Fixture_ID') as int),)}
and access it where required like:
${__groovy(vars.getObject('Fixture_ID_INT'),)}
Demo:
More information: Apache Groovy - Why and How You Should Use It
you can use the below code
Integer.parseInt(vars.get("urs"));
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.
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.