Suggest code corrections in Idea - java

I've recently moved from Eclipse to Intellij IDEA for java development,
I have some code as shown in the screenshot, and as you can see there is no package called test2, Eclipse used to give suggestion if I want to create/move such a package, what is the IDEA equivalent shortcut for that option ?

Context specific actions can be brought up by alt+enter while having your cursor on the underlined part.
May I also suggest ctrl+shift+a. This brings up a search field for all kinds of menu items and settings.
Edit
Two more tips I always give IntelliJ newcomers:
Regularily check out Help/Productivity Guide. It tells you which features you don't use yet.
Install the Key promoter plugin. It tells you which shortcuts you could have used when you use an IntelliJ-Feature.

Related

Netbeans refuses to auto suggest known classes for imports

I just discovered that my NetBeans suddenly stops importing classes that are found in the Java API but can still import classes from my external libraries. Take a look at the image below:
As you can see, List and ArrayList are classes from the java.util package but the usual suggestions for importing them are not shown here, instead it is asking me to create class. I know that I can type import java.util.List; on the top of the code but life was better before! Please I need help thanks.
I had the same problem a couple minutes ago... Terrible. The same problem has been reported here:
Bug 235712
The solution which I've found there was sufficient - simply delete the Netbeans cache...
In order to do this, go to Help ==> About . Then go to the directory with cache and delete all you find in the "index" catalog.
After restarting the NB, everything was cool.
Today I came across the same problem. It happens that it actually is very easy to exclude a class from code completion if you click in the wrong place while working.
To solve it (netbeans 8.2) go to
Tools - Options -> Editor tab
Then select Code Completion Tab
In the drop Down select JAVA (in my case it was Java)
You will find a box bellow titled Package/Classes
In the EXCLUDE tab you probably will find the packages marked to be excluded from code completion. Just remove the ones you want back.
Check under Preferences->Editor->Code Completion to make sure auto complete is on, though by your screen shot I assume that it is.
Also try Preferences->Editor->Formatting and set your Language to Java
In my case, NetBeans was refusing to suggest Scanner. As it turned out, all I had to do was remove java.util.Scanner from Options » Editor » Code Completion » Packages/classes: » Exclude. Then the autocompletion for Scanner returned.

How to write an eclipse content assist?

I want to write a plugin which will give me content assist support and work in JSF. I want it to work like the sample below :
I'll type "p:button action="#{
Then I'll press "Ctrl+Shift+Space" (for example)
It'll read the classes in my project and show them as a list in a pop-up window
Then I'll select one class. It'll be like below
h:button action="#{MyClass
When I type "." , It'll read the methods in my selected class and show them as a list in a pop-up window.
Then I'll select a method
Finally, It'll end like this "h:button action="#{MyClass.MyMethod}
Do you have any idea, how can i do this? Any suggestions?
One place to look for an example of content assist is to look at XText which already has this feature for DSL-like languages.
See the XText sources in its Git repository: by looking work the log message 'assist', you will have a list of commits all related to content assist implementation, like the XbaseProposalProvider.java class.
The following are both screenshots from the Web Page Editor which comes with the Java EE edition of Eclipse.
You can install it by adding the following mirror to your Eclipse repository. Change the name depending on what version you use. For Helios it is http://download.eclipse.org/webtools/repository/helios.

Being in Debug View, and after program termination, switch back to Java View in Eclipse

I am looking for a way to come back to the standard Java View in Eclipse after the application I'm debugging is over.
Is it possible to accomplish that? That is the default behaviour in some other IDEs (Visual Studio, for instance) and I'd prefer to have it that way. It's so boring to have to go an manually switch the view again to the initial one :(
Thanks
Eclipse is a generic platform where you can have a dozen type of different launch configurations, so a good and usable 'generic' implementation of this feature is not trivial.
However, there is an open bug report for this feature, which has some activity recently so there is a chance that this feature will be included after Eclipse 3.7.
I wrote a plugin that does what you want. Here's the update site:
http://backtojava.s3-website-us-east-1.amazonaws.com/
I didn't categorize the feature, so when you look for it, unselect the "Group items by category" checkbox.
And here's the project on Eclipse Labs I made to host the source:
https://hg.codespot.com/a/eclipselabs.org/backtojava
I haven't checked the Feature project in; just the plugin.
I personally have never seen such a feature. I also wouldn't consider such a feature desirable. Rare would be the occasion where I would be in debug mode for only a single run. Typically, the editing window provided in the debug mode is sufficient for any edits I would make during a debugging session.
Do you have to use Eclipse? There are other Java IDEs, for example in Intellij IDEA you can set the debug window 'unpinned', so it hides when you click on the editor. Personally I would find that behaviour annoying but it might work for you.

.NET pop-up box terminology along with Java

I need to know a couple things.
What is the terminology for the pop-up box shown in this Image? (Not the text, but the actual box itself) This is with Visual Studios.
alt text http://www.freeimagehosting.net/uploads/16060e2a55.png
I need to do a project in Java and I heard that Eclipse has this pop-up box, but I cant seem to find it. Does anyone know where this option is? I was hoping maybe finding out the terminology of the box will help me find the option easier.
Is there a better IDE for java than Eclipse with this box included?
Thank you for the help.
This is IntelliSense, it's activated automatically, but can be invoked manually using Ctrl+Space.
Yes, Eclipse does have this as well. Press Ctrl+Space to bring it up (I don't think Eclipse does it manually - it's been a couple of months since I last used Eclispe so I may be wrong).
You might want to look into IntelliJ IDEA or Netbeans (the former over the latter). IMHO, Eclipse is the most powerful and represents best value for money :-)

AutoIndent in Eclipse possible?

I have been wracking my brain trying to figure this out. For the first time I used jEdit the other day and I was pleasantly surprised that it auto indented my code (meaning that I'd put in the following code:
int method () {
_ //<-- and it put me here automatically
I've tried to get the same thing working with eclipse but with no success. I got into the code formatter but I don't see how to make that happen.
Is it possible to do this? Also while I'm here, is there a such thing as a eclipse plugin that will allow you to search the methods and classes of the standard java library?
Thanks
Personally all I use for this is the format options Window->preferences under Java->Code Style ->Formatter.
I once took the time to tweek how I like my code to look like when I work and exported the whole thing. After that I just code without too much bother on what it looks like. When I find the code looks messy by pressing the combination ctrl+shift+f and the whole class becomes pretty again, comments and all.
After a while it pretty much became a reflex...
code code code
ctrl-s, ctrl-b (cause I disable auto build sometimes), ctrl-shift-f
code some more etc...
Once I got used to this I never really cared how it presented the code as i was typing because I knew it would look all pretty as soon as the loop/if/switch/method etc is finished
My clean eclipse install does this by default.
Have you changed any options? Make sure the file you are editing has the .java file extension. The preference options that control the typing automations are under Java -> Editor -> Typing in the Window -> Preferences menu.
Also, I find that the auto-indenting, and most of the other auto-complete functions of eclipse do not function well if the file I am editing has errors in it which prevent compilation. Make sure that your curly-braces are matched correctly, this is the main one that I've noticed blocks auto-indent.
Regarding searching through the standard Java libraries, use the Search -> Java.. menu option, and check the JRE libraries checkbox, then search away. You can also use the Hierarchy view to see how the classes relate. Also, in the Package and Project views you can expand the JRE System Library, and then expand rt.jar which holds pretty much all the standard Java pacakges.
Eclipse has always done this for me by default.
One really cool thing about eclipse is that you can search preference pages. Just right click and go to prefrences. Go to the "Window" menu, and click "Prefrences". Then at the top of the tree view there's a text box that says "type filter text". Replace that with "indent" and it should bring up the page where the indent option is.
Make sure that eclipse recognizes your file as a java file, that you're using the Java distribution, the latest version, etc.
Iv been trying to work around the eclipse indenting and other supposed features for years, and it seems that the bottom line is this ...
It only works for the programming style of the authors, so to use it you need to modify your style to comply.
This would be OK except that the authors of eclipse have some very strange ideas about common shortcut keys.
One horrid example is the search features, eg when did Ctrl+K become "Find Next occurrence" and why doesnt F3 or n work?
That all being said I use eclipse because if you have the time to wait around while it starts up - or never close it - and you can modify everything youve learned about using an editor - why why why - then it will certainly increase your efficiency.
Please note that there is a preference setting for indenting, it can be set for a project, a workspace, or globally, but no matter how you set it eclipse will still chuck tab characters in where you dont want them.
In fact its indent crazy, like it wants to indent everything, even if its already indented.
Like I said Iv been using it for years and it STILL drives me nuts with its random behavior.
Follow these steps for Eclipse:
Select all text: ctrl+A
Correct indentation: ctrl+I
You should check:
Hidden features/tricks for Eclipse?
What is your favorite hot-key in Eclipse?

Categories