IntelliJ File and Code Templates error - intellij-idea

This isn't specifically code-related, but about the templates of IntelliJ IDEA. In File -> Settings... -> File and Code Templates, it shows the templates of various file types that you can edit (when you create a file of that type, it provides the layout from the template, pretty simple). However, my problem is that it doesn't exactly follow my desired template. For example, let's take the Class type.
This is what I want:
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
public class ${NAME}
{
}
This is what I get:
package name
class name {
}
Why does IntelliJ IDEA ignore my moving of the block character onto the next line? How do I fix this? It's incredibly frustrating.

IntelliJ is deciding where to put the brace using your current code style.

Related

Intellij Idea does not detect and underline non-existing methods in the editor pane

In the idea editor and my java project , idea does not detect non-existing methods and underline in the editor pane, so i could not use alt + enter to generate new methods.
Example screenshot is below :
BTW : powersave mode is disabled, in the project setting sources are selected.
Project window is seen below:
I created demo maven project in idea, still the problem continues.
I created DemoNew Class.
public class DemoNew {
}
Then i created DemoImpl class:
public class DemoImpl {
public static void main(String[] args) {
DemoNew demoObject = new DemoNew();
demoObject.ssss(); // idea does not detect this non-existing method.
}
}
As seen above, idea does not detect the non existing ssss method in DemoNew class.
I uploaded demo project and my settings in intellij idea.
demo project and settings
After compiling project, still idea does not underline non-existing method with red color in the editor pane.
JetBrains Team answered the question
Looks like JDK uses wrong locale:
https://youtrack.jetbrains.com/issue/IDEA-190718 Please try to add
"-Dsun.locale.formatasdefault=true" option to JVM settings.
I added that parameters from intellij idea / help / edit custom vm options.
And parameters are seen below.
-Dsun.locale.formatasdefault=true
-Duser.language=en
-Duser.region=US
-Dfile.encoding=UTF8
I added last four items in the file.
That fixed the problem.

IntelliJ does not recognize kotlin file after deleting it and recreate with the same name

I am currently having a problem with IntelliJ. I am using Kotlin in my project. I have deleted a file (let's say test.kt), and now, I want to create a new file with the same name. IntelliJ does not recognize the kotlin syntaxe and show it as a text file.
When I have deleted I have unchecked "safe delete" and "Search in comment and strings"
Can anyone help me in this matter ?
Edit : I tried to delete .idea and .iml file, restart intelliJ. It does not change anything.
"Overrid File Type" to Kotlin would work.
Expanding on a comment:
Is test.kt listed in Preferences > Editor > File Types > Text, under the Registered Patterns? An entry there may override the default Kotlin filetype
I had a class, MyProxy.kt, that as the question implies was not being picked up as a Kotlin class in IntelliJ. I scrolled through my list of file associations and did not find anything that could match MyProxy.kt except for the Kotlin extension, *.kt (it is entirely possible I missed something.)
Most regex matching will apply the most specific rule, though. On the off chance my class was being picked up by another association, I explicitly declared it as a Kotlin file pattern. It is a little hacky, but it did work! My Kotlin file name patterns are now:
*.kt
*.kts
*.main.kts
MyProxy.kt
Note: IntelliJ did complain that *.kt would already catch MyProxy.kt, but I overrode it.
Ctrl+alt+s, Editor, File Types, under recognized filetypes,
Under Filetype auto-detected by file content...
remove Main.kt

IntelliJ type error when using Geb static content DSL with parameters

Whenever I use a static-content defined closure that takes parameters, IntelliJ will complain that the types do not match (even if I specify the type inside the closure).
For example, if I use this static content block:
static content = {
myModule { $('myModule').module(CustomModule) }
namedModule { String name -> $(".$name").module(CustomModule) }
}
Both of the above items can be used successfully in my tests, but if I was to use 'namedModule' in one of my tests as follows:
page.namedModule("moduleName").moduleMethod("blah blah blah")
IntelliJ will highlight the parameter "moduleName" in yellow with the error:
'namedModule' cannot be applied to '(java.lang.String)'
We are trying to refactor our tests in a way that means you can navigate through the code easier (e.g. avoiding any Geb/Groovy 'magic' that IntelliJ can't resolve), and this is one of the last remaining issues preventing this from being possible.
This is a known limitation to Geb support in IntelliJ. IntelliJ always treats content definitions as properties of pages and modules even though they can be parametrised. Given that Geb support in IntelliJ is open sourced we could probably add support for this.
In the mean time, as a workaround you can use methods for parametrised content instead of content definitions and IntelliJ will be able to understand these and be able to refactor them:
void namedModule(String name) {
$(".$name").module(CustomModule)
}
There are some caveats, though:
you will loose ability to use content definition options; if you need to use these for a content definition then I suggest creating a parameterised "private" content definition (for example with a _ at the beginning of the name) that you will only ever access from within the page or module
RequiredPageContentNotPresent will not be thrown even if the returned content is empty; to work around it you will either need to add manual verification to each such method or use a strategy outlined in the first bullet point with using "private" content definitions

IntelliJ Ultimate 14 find usages not working

I am using IntelliJ IDEA 14 Ultimate. When I search find usages, in find view, there is an info like "Searching for usages in project files" and doesn't return any result. Scope is "whole project".
I have also IntelliJ 14 Community Edition. When it tries find usages in Community Edition, it works.
Do you have any idea?
I had exactly the same problem, so for people looking for the quick answer, try
File -> Invalidate Caches / Restart
Thanks to user #yole and his comment.
If it doesn't solve by File -> Invalidate Caches / Restart
then make sure your 'src' folder is marked as 'Sources' in project structure.
If File -> Invalidate Caches / Restart is not working -> close the project, remove it from recent projects and then delete the .idea folder then open the project again.
In PhpStorm version 2019.1 on a Windows machine, if you hold AltGr key and hover on a function, it appears the popup 'Show usage of Method ...' but it's misleading since doesn't find the calls to that method from other files.
The correct way to show usages, is to hold the Ctrl button and click on the method name.
There are also other cases the "Find Usages" feature does not work. I can illustrate one very simple case.
Provider.java:
public class Provider {
private static final Provider instance = new Provider();
public static Provider getInstance() { return instance; }
public Integer getID() { return 0; }
}
User.java:
public class User {
private final Integer pID;
public User() { pID = Provider.getInstance().getID(); }
}
If you click on the getID() method in Provider.java and call "Find Usages", it finds the call in the User.java easily. But if you rename or remove the getInstance() method in Provider.java, then it won't find the getID() call in User.java anymore.
I assume that it happens because the line Provider.getInstance().getID() is marked with red (compilation error) and the "Find Usages" feature does not consider this failing code as a valid call of getID(). It means that, at least some compilation errors affect the "Find Usages" results.
I was curious enough to look into the list of bugs related to this feature on https://youtrack.jetbrains.com/issues?q=find%20usages and there I saw there are other cases and made my conclusion. To sum up, if you don't like to keep in mind all the conditions in which it works and want always full search I recommend using grep which finds always and everything.
IntelliJ IDEA 2022.2.1
After Invalidate Caches/Restart did not work, what did fix the problem was Mark Directory As -> Unmark As Sources Root, followed by Mark Directory As -> Sources Root on 'src/main/java'
Sometimes problem in your code format structure.
Try this -
Press ctrl+alt+shift+l and
Choose selected text
Code cleanup
then your problem is resolved
You can also temporarily force a "bad" source folder (ex: .../tmp), then switch back to the correct source folder (ex: src/main/java).
This, combined with cache cleaning as explained in the other posts solved the problem for one of my collegues.
You declare / undeclar source folder with a right click on the folder, then "Mark Directory as ...".
have u tried mark directory as -> Project Source and Header?I just work out it in CLion.

Eclipse custom text editor update syntax highlighting

I am writing an Eclipse plugin (Indigo/Juno) that contains a text editor for a custom text format. I am following the tutorial here: http://www.realsolve.co.uk/site/tech/jface-text.php
So far I have everything working. Eclipse will use my editor to edit files. I have partitioning, damaging, repairing, syntax highlighting all working.
I added a preferences page with color pickers to control syntax highlighting. It works mostly correct. If I update the colors, the editor uses them the next time I open or reopen a file.
How do I get an editor tab to update itself without opening a new one? The built-in JDT Java editor does this, but so far I have not been able to decipher how (it is a very large and complex editor).
I gather that I need to create a preferences listener (http://www.vogella.com/articles/EclipsePreferences/article.html). I have done this and can verify that my listener code is being invoked when I set a breakpoint in it.
The missing piece is the wiring between the listener and reinitializing the editor. I have tried reconstructing the partitioning logic, the color logic, the damager/repairer, etc. but nothing seems to work. It either does nothing I can see or at worst will corrupt the display until I scroll the current text out of view to repaint it... with the old colors.
Any ideas?
I think SourceViewer.invalidatePresentation() needs to be called.
It may be already late to you, but if you want you could use LiClipse for that (http://brainwy.github.io/liclipse/) -- one of its targets is easily doing an editor with syntax highlighting, basic code-completion, outline, etc targeting Eclipse.
No java skills are required to add a new language (mostly creating a new .liclipse -- which is a YAML -- file in the proper place and creating some basic rules to say how to partition your language -- i.e.: usually just separating code from comments from strings -- and specifying the keywords you have in the partition would already give you proper syntax highlighting).
If you download it, there are a number of examples at plugins\com.brainwy.liclipse.editor\languages and there's some basic documentation at http://brainwy.github.io/liclipse/supported_languages.html and http://brainwy.github.io/liclipse/scope_definition.html on how to do it.
For anyone coming across this as I did:
My solution involved adding the following lines into the Constructor of my Editor
Activator.getActivator().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
#Override
public void propertyChange(PropertyChangeEvent event) {
getSourceViewer().invalidateTextPresentation();
handlePreferenceStoreChanged(event);
}
});
and then creating a custom class that extended IToken. In the constructor I pass the String of the preference field and then in the 'getObject' method I create the TextAttribute: snippets below
public class MyToken extends Token implements IToken {
public MyToken(Object data) {
super(data);
}
#Override
public Object getData() {
String dataString = (String) super.getData();
return getAttributeFromColorName(dataString);
}
private TextAttribute getAttributeFromColorName(String preferenceField) {
Color color = new Color(Display.getCurrent(), StringConverter.asRGB(Activator.getActivator().getPreferenceStore().getString(preferenceField)));
return new TextAttribute(color);
}
}
When I generate my Rules I have all of my tokens as my custom class and this allowed me to change syntax color dynamically.
I also added an example for updating the coloring if the preference changes to https://www.vogella.com/tutorials/EclipseEditors/article.html#exercise-allow-user-to-customize-the-colors
This is using the Generic editor (currently the best approach to implement a customer editor) but it should be possible to adjust this to any Eclipse editor implementation.