![]() We select the option Remove unnecessary braces in GString from the intentions to make this work: In Groovy we can leave out the curly braces for dotted expression or the expression is a single value. When we select the option IDEA will turn the statement into a GString with the variable value replaced as an expression:Īlso when we already have a GString value in our code we can remove unnecessary braces. Now we see the option Convert to GString: We can select one of the elements of the concatenation and open the Show Intentions Action. We can also apply the conversion the other way around:Īnother useful intention, especially when we copy-past some Java code in our Groovy source files, is to convert a String concatenation with the + operator to a GString value. When we select Convert to String IntelliJ IDEA changed our value assignment: We see that we can change our String value to dollar slashy, regular expression, multiline or plain String syntax: We type convert to shorten the list with only conversion options. We use our shortcut key to open the suggested intentions. In the following screenshot we see our variable s with a value. But we want to change it to a single quoted String value, so to make it explicit the value cannot be a GString implementation. We used the double quoted syntax to do so, like in Java. Suppose we have assigned a String value to a variable in our code. IDEA will show the action with the shortcut key for us. Alternatively we can press the Shift key twice and type in Show intentions. We need to check our shortcut keys to see the assigned shortcut. To see the possible intentions in IDEA we must select the Show Intentions Action. The intentions shown here work in the free Community Edition as well in the paid Ultimate Edition. ![]() We will look at some of the intentions that deal with String values in this blog post. The Groovy plugin has some nice intentions for us that we can use to optimise and refactor our code. The best IDE to use when developing Groovy code is IntelliJ IDEA. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |