Limit text field completion to a specific set of segments within Intellij Plugin - intellij-plugin

I was able to get code completion to work for a text field in my plugin based on the answer here: Text Field with Standard PsiElement Auto Completion in IntelliJ Plugin
But that's only a part of the problem. In my field I need to express plain text plus Java expressions e.g.:
This is plain text and here's a Java expression {myJavaObject.myMethod()} here's more text and a variable {var}
This is a pretty standard concept in Java. I'd like completion and syntax highlighting to only apply within the curly braces. Is this possible? If so how would one go about implementing this?

Related

JetBrains IDEs live templates - place multiple carets

In IntelliJ live templates one can use $END$ to specify where the cursor should be placed once the template is expanded.
Is there a way to place multiple carets? Specifying multiple $END$ locations doesn't work. I sometimes need to type the same text into several places for what can be an auto-generated piece and that would be a nice expansion of functionality.
Currently as a solution I use "surround templates" where I can first type some text and then use $SELECTION variable.

Intellij Plugin Completion exits on dot?

What I wanna achieve?
When the Completion list shows up, my code will map all the language files located in .neon files and show them as auto complete text.
What I have done?
I restricted the completion to only show up when your caret is in between double quotes or single quotes
Issue
When I start typing it works as expected
But as soon as I type the dot character it miss behaves
I need the completion list to look up my whole string I wrote, not only those after the dot character
As a really bad workaround is to don't write the dot character
Can it be done somehow?
Okay, i got it. This is a default behavior of intelliJ where i was testing it.
After opening and testing the plugin in a proper intelliJ Ultimate instance. It works by default. I don't know why the sandboxed version has porblems with it.

IntelliJ constants.getProperty() autocomplete field

I have a large constants.properties file.
When reading properties from it with constants.getProperty("PROPERTY_NAME") I often have to copy/paste the property names which is rather long.
I see that IntelliJ is able to detect when properties are used inside the code, is it be possible to have auto-completion of property names when I type the name in getProperty()?
Yes, IntelliJ IDEA provides the completion for the Java Properties, use Ctrl+Space to get the hints:

Intellij - Numbers in `Intention Actions` window

I was wondering. Is it possible to add number shortcut to corresponding actions inside Intention Actions window? Like with String Manipulations plugin:
For example in this case:
I would love to press Alt+Enter and then 3 to Create object buzz - I know for a lot of cases I can use shortcut for example ctrl+alt+v for a variable extraction but not for all.
I was looking for this kind of plugin but without a result

Where is the live templates for Java in Intellij-IDEA?

I could not find the live templates for Java! Who can tell me how to set? Thanks.
They're inside all the nodes that are not specific to another language than Java: iterations, output, plain, surround, etc.
As JB Nizet wrote there is not a special node for Java (but you can create one). If you want your own Live Template for Java created do the following.
Open Settings window (File -> Settings)
Click on Editor -> Live Templates
Choose Template Group in which you want to add your Live Template
(you can create your own Template Group if you wish)
Click on + icon and choose Live Template
Specify the Abbreviation, Description and Template text.
Do not forget to define the context (in your case Java)
Example
Here is an example of how to create your own TODO text
Open the Setting window with Live Templates editor (as specified above).
Click on + icon and select Template Group.
Name this group Java.
Click on + icon again and select Live Template.
Specify your Live Template and DEFINE CONTEXT.
In my case writing mtodo and pressing enter will result in:
// TODO myName
You can even use variables. Write in your Template text e.g. $DATE$ and $TIME$
// TODO myName $DATE$ $TIME$
Click on Edit variables button and assign to each variable (defined by dollar sign) and expression (predefined function).
Now mtodo will result in
// TODO myName 13.10.2015 15:39
Predefined functions could be found here. The example was created using IntelliJ IDEA 15 EAP.
For those of you who have taken Postfix completion for Live templates, it is worth mentioning they are different. from not-choosing pretty good answers from #JB Niznet and #vitfo, I guess that's the case for OP writer. The document, here, says:
Postfix code completion is similar to live templates, it transforms the current expression without selecting it. For example, you can type .if after an expression to invoke the corresponding postfix completion and wrap the expression with an if statement.
You can check out a list of postfix completions:
Open the Preferences window
Click on Editor -> General -> Postfix completion
By default, there is no JAVA group in this setting page.
However, these default settings distribute on each feature group. For example, iterations:
IntelliJ IDEA 2019.2.4 (Ultimate Edition)