I am using Java and I log things like:
log.info("createArticle userId={} articleId={} title={} content={}", userId, articleId, title, content);
As you can see, when inputting this line into my IDE, I have to manually write down those characters like "userId={} ". Ideally, I hope I can simply type the userId, and Intellij IDEA will automatically help me fill out both "userId={} " (in the format string) and , userId (in the arguments list).
Question: How can I do that in IntelliJ IDEA? Or, is there any other ways to type such logging lines faster?
Thanks for any suggestions!
It is possible to implement it with Live Templates and groovyScript for one of the variables: take the second segment, split it by comma, concat in something like part=${part}:
groovyScript("_1.split(',').collect { it.trim() + '={}' }.join(' ')", B)
See video
Related
Hi (most probably Peter), I am having troubles to figure out how to make parametrization of my RUTA project.
First of all I have several scripts that make kind of chain:
Project Adjectives.ruta
Project Anatomy.ruta (contains "SCRIPT Adjectives;" and "Document{->CALL(Adjectives)};")
Project Anamnesis.ruta (contains "SCRIPT Anatomy;" and "Document{->CALL(Anatomy)};")
For the result I am calling this:
File specFile = new File("C:/.../.../pipelines/AnamnesisEngine.xml");
String path = new File(specFile.toURI()).getParentFile().getAbsolutePath();
AnalysisEngineDescription desc = null;
String[] VarNames = {"Name1", "Name2"};
String[] VarValues = {"Value1", "Value2"};
try {
desc = AnalysisEngineFactory.createEngineDescriptionFromPath(
specFile.getAbsolutePath(), RutaEngine.PARAM_SCRIPT_PATHS, path+"/script",
RutaEngine.PARAM_DESCRIPTOR_PATHS, path+"/descriptor",
RutaEngine.PARAM_RESOURCE_PATHS,path+"/resources",
RutaEngine.PARAM_VAR_NAMES, VarNames,
RutaEngine.PARAM_VAR_VALUES, VarValues); ..... End so on (Those parameters (VarNames and VarValues) are filled from query, but that is not so important right now)
Everything works fine and I am getting nice JSON output. But now I am having troubles with those parameters (VarNames, VarValues) and I can't figure this out.
When I make something like this in script Anamnesis.ruta
STRING Name1;
Anamnesis{->SETFEATURE("Lemma",Name1)};
Everything works perfectly and I can see in my output that lemma for Anamnesis annotation is set to Value1...
However I also need to work with those variables in projects Adjectives.ruta and Anatomy.ruta. I suspect that those projects are controlled by their own descriptors (AdjectivesEngine.xml and AnatomyEngine.xml). Is there way to set the parameters for those projects and use them while creating ae from AnamnesisEngine.xml?
When I try to add this to Anatomy.ruta (And again call AnamnesisEngine.xml)
STRING Name1;
Anatomy{->SETFEATURE("Lemma",Name1)};
There is no Lemma at all in the output. Which kind of makes sense but I was hoping that maybe that whole chain can be controlled by AnamnesisEngine.xml and those first two projects would be able to "find", assign and work with those variables... Well I was wrong...
Please what would be the best way to achieve this?
If somebody is ever interested, I managed to achieve this with "Aggregate Engine Type" - which let's you import other descriptors into it and propagates variables into them... Epic!
Is there any Intellij Idea hotkey or a plugin to quickly insert variable into string?
e.g. i have string
"My code is working, yay! Result is = ",
and i have to add construction "+variable +", resulting in
"My code is working, yay! Result is = "+ variable +"."
to properly insert a variable.
When i have to insert variables into 20+ string, its driving me nuts :)
tried to find solution on google or plugin repository, no result
PS: i know about soutv hotkey, but it cant help me since i have to change already existing strings in code
Added Live Template
Abbreviation: ++
Description: Insert variable into string
Expand with: Enter
Template text: "+ $EXPR$ +" (do not forget double quotes)
Edit Template Variable:
expression:variableOfType("") default Value: "expr"
settings screen
You type ++ in a string, press Enter, and template text is added, and you only need to choose a variable. Works like a charm.
Thanks for the idea, #Meo
I know I can use "code" in GitHub Flavored Markdown to highlight a code snippet. But I am not able to display line numbers for a snippet. Is there a way to do so?
```javascript
var s = "JavaScript syntax highlighting";
alert(s);
```
I want a line number to be put at the beginning of each line, like this:
1 var s = "JavaScript syntax highlighting";
2 alert(s);
As you may noticed in Markdown Cheatsheet, GitHub does not show line numbers in code blocks.
As a hack, you could save a pic of your code at https://carbon.now.sh and post it; they support line numbers as an option.
You can get something similar that you need using awk '{printf("% 4d %s\n", NR, $0)}' StartDsl.scala where StartDsl.scala is your source code file. Paste the result between
```scala
<your code here>
```
Although it is not available in GitHub as the question asks, I have discovered today if you add an = sign after the opening line, on some Markdown editors, it gives the desired result.
eg:
```javascript=
var s = "JavaScript syntax highlighting";
alert(s);
```
This works on Markdown editors such as HackMD
See your example on HackMD
So, you will need to help yourself by adding css to your html page. As a code goes into <pre> </pre> block in markdown.
You could apply your logic to this block to put line number against each line.
See https://codepen.io/heiswayi/pen/jyKYyg for reference.
I use RStudio with RMarkdown to render my Markdown (.md) files. It works great. Using the RMarkdown, the specification is made this way:
```{.javascript .numberLines .lineAnchors}
var s = "JavaScript syntax highlighting";
alert(s);
```
Yes, there are many markdown editors available and I'm not sure that this will work with all the editors, but RStudio/RMarkdown is a really great tool, which I use since a long time ago (IMHO).
Just add an = after the language you choose !
```java=
java code exemple:
int i = 5
```java=
Now here is the solution for adding line numbers in Markdown.
https://shd101wyy.github.io/markdown-preview-enhanced/#/markdown-basics?id=line-numbers
You can enable line number for a code block by adding line-numbers
class.
I use GWT I18N, which relies on annotations for messages with parameters.
Exemple :
#DefaultMessage("Here is a message <br/> with a param:{0}")
String messageToLocalize(String param);
In absence of a localized translation, the default message will be used.
I have some quite long strings to handle, which I would like to type in sevral lines for code readability (I don't speak about multiple lines for the rendered message).
I tried this :
#DefaultMessage("Here is a long \
message <br/> with a \
param:{0}")
String messageToLocalize(String param);
It fails (GWT PlugIn 4.2 and SDK 2.5.1) with an error "Invalid Escape Sequence".
Did I miss something ?
Is it a constraint on Java annotations or GWT ? (I am afraid so but couldn't find anything on that)
Is there a workaround ?
Thanks
Edit : Given first answers, the question must be rephrased : is it possible, and which character should I use to show continuation (if any) ?
The annotation processor obviously needs something to tell him.
I tried "\" because it is the char to use in property file ...
"+" does not work either.
Java doesn't support C-style string-lines representation, so you could not use such multi-line style neither in annotations declarations, neither in other places of code.
If you want multiply lines of single string, you have to do something like this:
#DefaultMessage("Here is a long " +
"message <br/> with a " +
"param:{0}")
As Andremoniy said, it must be cut using Java-style.
But otherwise, I recommend you to have a look at i18nCreator. It allows you to manage your i18n in properties files and have these Messages interfaces files automatically generated:
https://developers.google.com/web-toolkit/doc/latest/RefCommandLineTools#i18nCreator
(There is also a maven plugin: http://mojo.codehaus.org/gwt-maven-plugin/user-guide/i18n.html)
Try string concatenation that is done at compile time, so:
#DefaultMessage("Here is a long"+
"message <br/> with a " +
"param:{0}"")
well... i have a file containing tintin-script. Now i already managed to grab all actions and substitutions from it to show them properly ordered on a website using Ruby, which helps me to keep an overview.
Example TINTIN-script
#substitution {You tell {([a-zA-Z,\-\ ]*)}, %*$}
{<279>[<269> $sysdate[1]<279>, <269>$systime<279> |<219> Tell <279>] <269>to <219>%2<279> : <219>%3}
{4}
#substitution {{([a-zA-Z,\-\ ]*)} tells you, %*$}
{<279>[<269> $sysdate[1]<279>, <269>$systime<279> |<119> Tell <279>] <269>from <119>%2<279> : <119>%3}
{2}
#action {Your muscles suddenly relax, and your nimbleness is gone.}
{
#if {$sw_keepaon}
{
aon;
};
} {5}
#action {xxxxx}
{
#if {$sw_keepfamiliar}
{
familiar $familiar;
};
} {5}
To grab them in my Ruby-App i read my script-file into a varibable 'input' and then use the following pattern to scan the 'input'
pattern = /(?<braces>{([^{}]|\g<braces>)*}){0}^#(?<type>action|substitution)\s*(?<b1>\g<braces>)\s*(?<b2>\g<braces>)\s*(?<b3>\g<braces>)/im
input = ""
File.open("/home/igambin/lmud/lmud.tt") { |file| input = file.read }
input.scan(pattern) { |prio, type, pattern, code|
## here i usually create objects, but for simplicity only output now
puts "Type : #{type}"
puts "Pattern : #{pattern}"
puts "Priority: #{prio}"
puts "Code :\n#{code}"
puts
}
Now my idea was to use the netbeans platform to write a module to not only keep an overview but also to assist editing the tintin script file. So opening the file in an Editor-Window I still need to parse the tintin-file and have all 'actions' and 'substitutions' from the file grabbed and displayed in an eTable, in wich I could dbl-click on one item to open a modification-window.
I've setup the module and got everything ready so far, i just can't figure out how to translate the ruby-regex pattern i've written to a working java-regex-pattern. It seems named-group-capturing and especially the recursive application of these groups is not supported in Java. Without that I seem to be unable to find a working solution...
Here's the ruby pattern again...
pattern = /(?<braces>{([^{}]|\g<braces>)*}){0}^#(?<type>action|substitution)\s*(?<b1>\g<braces>)\s*(?<b2>\g<braces>)\s*(?<b3>\g<braces>)/im
Can anyone help me to create a java pattern that matches the same?
Many thanks in advance for tips/hints/ideas and especially for solutions or (close-to-solution comments)!
Your text format seems pretty simple; it's possible you don't really need recursive matching. This Java-compatible regex matches your sample data correctly, as far as I can tell:
(?s)#(substitution|action)\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(\d+)\}
Would that work for you? If you run Java 7, you can even name the groups. ;)
Can anyone help me to create a java pattern that matches the same?
No, no one can: Java's regex engine does not support recursive patterns (as Ruby 1.9 does).