When I press . (period) Eclipse tries to compile - eclipse

As the title states, every time I press . on the keyboard, I get a popup message saying "This compilation unit is not on the build path of a Java project.". Now keep in mind I'm not even trying to compile at this point, i'm just trying to type a . without the program trying to compile my unfinished code on me. Does anyone know how to fix this?

. is usually treated as an auto-activation character when it comes to invoking content assist, and providing content assist often involves trying to compile what it can from the potentially broken syntax in your source file.
Reference for the relevant Preference page if you want to disable or otherwise alter this behavior: http://help.eclipse.org/oxygen/topic/org.eclipse.jdt.doc.user/reference/preferences/java/editor/ref-preferences-content-assist.htm?cp=1_4_2_0_5_0
Really, though, you should tell it that the correct parent folder of your source file is a Source folder (what ever would make your package structure match the folder structure). The automatic background feedback that shortens your edit/compile/run loop is one of the main reasons to use an IDE instead of another text editor that happens to provide syntax coloring.

Related

What are keyboard shortcuts to find next and previous error in Netbeans 8.2 editor?

EDITED (see bottom)
Is there really, after so many years of unanswered questions such as mine, no keyboard shortcut to jump to the next or the previous error in Netbears 8.2?
This page says that the shortcuts are
Ctrl+./, Next/previous usage/compile error
Note the inclusion of the word usage. In no other "Next/Previous" shortcut is usage used. I wonder why it's here and if it points to the problem. It's not exactly a typo. What might it mean? Yeah, probably nothing.
Whatever, absolutely nothing that I have found shows how to accomplish this very important pair of tasks.
Using Tools > Options > Keymap shows that Ctrl+PERIOD and Ctrl+COMMA are how to do it. But it doesn't work.
Once Ctrl+PERIOD took me SOMEwhere, and doing it again took me to the next occurrence of it, etc., but those lines of code had no errors and it doesn't happen now.
I've clicked on the ellipsis on the line for Next Error and Previous Error and edited them to be Ctrl+BACKQUOTE and Alt+BACKQUOTE and I clicked on the ellipsis and defined alternative shortcuts to be Ctrl+CLOSE_BRACKET and Alt+CLOSE_BRACKET and I could NOT define Next error in Editor to ANYTHING.
NOTHING works.
So my question is WHY NOT? I use F2 and shift+F2 in Android Studio with every error I get! How can this NOT be possible in Netbeans 8.2?
I am reluctant to upgrade to Netbeans 11 for just this, especially not knowing if this problem persists.
======================
EDIT
After looking at what #Dmitry_M submitted, I took another whack at it with the above definitions, which cause:
Alt+1 to take me to Next Error, but ONLY after a fresh Build or Clean and Build Project, and it takes me to other lines (in xml, for one) that have no errors (that I know of; they're not flagged).
Alt+2 to take me to Previous Error unless I fixed it, in which case it takes me to that same line that HAD the previous error, just as Alt+1takes me to where the next errors USED to be and to the other places, too.
Next Error in Editor to do nothing.
This makes me wonder what Category actually means since Next Error in Editor says Source while the others that DO work say System.
My source files have more than a few "yellow warning" indicators, but unike Dmitry, the definitions don't find them.
If it finds the errors among other things, that's better than it was. But it only finds errors already listed in Output, and it requires build, and it finds other extraneous "errors". So I'll just look at Output. Keymap fails.
I'm discouraged with Netbeans 8.2.
I am using NetBeans 8.1
Next Error in Editor
The keymap moves a cursor to any hint or error that the editor shows. They are sometimes not compiler's errors. See it in action.
For example, the cursor moves to int i = 0; but there is no error there. There is just a hint that variable i is not used anywhere. And in the import statement: it's just a hint.
If you want to define a keymap for Next Error in Editor action try different key combinations. I use alt+1.
Previous Error/Next Error
The keymap only works for clean and build or build actions.
Probably, when just editing and saving NetBeans doesn't refresh errors list somewhere in the cache. It explains the behavior you experience: the cursor moves to a line where there are no errors. It simply moves to the line where an error was during the last build or clean and build action.
Se it in action just after clean and build. It works:
The cursor indeed moves only between "real" compilers' errors. But it only works after clean and build or build action. Probably it's a bug. There is a relevant bug but it was not resolved.
Also, in my case, Ctrl+PERIOD and Ctrl+COMMA were not working completely. Changed my keymaps to this one:

Compiling swift source files stuck

I have been working on my project when suddenly I have not compiled anymore, it stays waiting in Compile swift source files ... I cleaned the project, the folder, deleted the app and nothing. Is there any way to know what is happening?
Is there any way to know what is happening?
Yes. Go into the Report Navigator which is the one selected by the little speech bubble at the top right of the navigator pane. It will give you a list of all the actions you have performed like builds and tests and runs. The current build will be at the top of the pane. Click on it.
In the main editor you will see some buttons at the top and maybe some messages. Click the All Messages button and it will show you a tree view of the current build. The bottom line will be what the build system is doing now. If it is not changing (i.e. new lines appearing) the build is stuck.
Almost certainly the bottom line will be something like Compile SomeFile.swift. Assuming it is, you can now triage the problem. The Swift compiler usually gets stuck on inferring types for complicated expressions. The way to triage this is to comment out the entire file and then add lines back until the problem reappears. Make sure that you always add enough back so that the file compiles without error.
Obviously, the last line you added back will be the one causing the problem. Usually it's an expression that concatenates strings together with non strings that causes the problem.
The problem is in dictionary [String:Any] when I change the dictionary to [String:String] the problem is resolved . Is very strange..

Eclipse treating file as plain text

I've got a small homework project, and for whatever reason Eclipse has decided to stop highlighting syntax or allowing intellisense or goto definitions or anything in this Main.java file. I've tried rebooting it, and the computer, but had no luck.
The thing that really has me confused is that it's still compiling and running the code correctly (eg, changes I make in Main.java are compiled and run - it's not running old Main.class files), so it's still in the build path ... right?
Any ideas?
Right click on the file in the Package Explorer and choose the Open With menu. You will probably find that Text Editor is selected, choose Java Editor to open the file with the correct editor.
The Open With menu selection is remembered so you should get the Java Editor in future, but equally if you choose the plain text editor that is also remembered.
I suggest finding a way to reset any setting you might have set by accident. Not saying that you did it. But just to make sure, just try it out. If you customized the preferences already, you could make some kind of note of the settings, then change it. If that doesn't work, let me know. Good Luck!
Copy the text somewhere, delete the file, and then add a new class (of the same name) and paste the text back.

Creating an Eclipse plug-in to display content assist regardless of cursor location

I'm working on some reflection stuff using Java across XML files. The process would be made much faster and less prone to error if I could get content assist to behave like a tree in a small window off to the side, but more than by my current cursor location.
My question is can this really be done without reinventing the wheel too much? Essentially I want to display a list of classes, choose a class, then drill down a TreeView similar to the outline view Eclipse has for a current open file and at some point I click a button below and it generates the desired XML formatted text I would have typed manually, this is generated based on whatever in the tree I have highlighted.
I've designed and begun work on the front and back end, but the piece that keeps eluding me is harnessing Eclipse's content assist to gather a list of practically anything I could possibly call in a given project.
Can this be done? I've been combing Eclipse's documentation for a few days and fighting with the source download dying halfway repeatedly.
I am not 100% if that's it but I had an eclipse plugin with spider in it's name in mind, which does what you described.
Maybe it is this one: http://eclipse-plugins.2y.net/eclipse/plugin_details.jsp?id=202
Furthermore when writing Eclipse plugins, it is useful to press ctrl+shift+f1 (eclipse plugin spy) once having worked in the pde this should be possible.
It shows you info about all possible extensionpoints refering to your current view.

Bypassing Lock on Generated Code in NetBeans 6.5?

In NetBeans the GUI Builder generates code that is off limits to you from the editor.
I know you can switch to Design Mode and specify custom code and then enter edit in indirectly that way, but it's a pain to not be able to edit text that's 2 lines from your cursor.
Can I allow editing within those regions... I promise I'll be careful :)
Thanks.
Note: I don't want to lose code generation
If you open it in an external editor, there are two possibilities:
there is no guarantee that the changes you make will work (and not break anything) in the Netbeans UI Editor
The next time you edit the file in Netbeans it will be regenerated.
Either way, probably not what you want. The best thing to do would probably be to make the whole design up in the gui editor and when you are happy with it, delete the comments and continue on.
[sarcasm]
With the drag and drop gui editor, what could you possibly want to change by hand anyway?
[/sarcasm] ;)
If you open the .java files in Notepad or WordPad, you'll find pairs of comments that say
// GEN-BEGIN: <name of section>
...
// GEN-END: <name of section>
Delete those comments, and two things will happen.
You'll be able to edit anywhere in the file in NetBeans.
NetBeans will not be able to regenerate the file from the GUI editor.
So it can be done, but don't do it unless you really mean it.
EDIT: "Note: I don't want to lose code generation." Ok, let's see here.
You want to change what is generated.
You don't want to lose code generation.
You don't want to use the facilities NetBeans provides for adding custom code.
It sounds like you're wishing yourself trouble. :D
I had a same problem. I extended JPanel with my own panel class and I was not able to pack it with the rest of UI. First I searched the web and I found your question. I was not able to find elegant solution to this problem.
Therefore, I decided to create another java class and copy NetBeans created code into it. It worked like a charm.
I agree, it would be nice if we can modify existing code like in .NET.
I copy the initcomponents() method, create my own method newInitComponents() paste the generated code, and override what needs to be overridden before i distribute the code. That way when a change is made in the editor, you can still copy paste the code into your new method. You keep the functionality without costing you the ability to override where necessary. Just call newInitComponents() in your constructor rather than the original. This is not the most efficient way of doing things, but it does what you want.
You can also try moving the .form file in
(project name)\src\(name of JFrame/JPanel).form
NetBeans will now see it as a .java file.
If you did not edit anything necessary for the GUI editor, you can move the .form file back into the src folder.
Can you subclass the class and redefine the method where this code is? Of course then you'll have to maintain the method over time as you make changes to the GUI.
You can maybe also look into AspectJ. It will modify the byte-code at build time and make the changes you define. Not sure if this gives you enough control over what code to change.
If you use APT you can rewrite source code at compile time. This way you can overwrite the code that's there at the moment. You could keep the new code in the same Java file along with comments to explain what is going on. This tutorial makes it pretty easy to get started. Copy that code, get it working, then tweak it to your liking. To find out where in the code the annotated method is call getPosition() on the Declaration.
Go to design page and select any one of the fields. Right click on any selected field and choose Customizer Code , In Customizer Code change all default code to custom creation . Now you can edit your design code as you like...
Very simple... the crappy UTF-8 did not let me compile one JasperReport (everything done by GUI). So, I needed to change Project to iso-8859-1. Result? The project is messed up and some of the things to correct are in the blocked parts of the code. So, I really NEED to edit those automatically generated parts. When they are regenerated, they will be fine because the project is now iso-8859-1.
Step # 1 Close the project in NetBeans
Step # 2 Delete the .form file from the source directory of your project
Reopen the project and it will be editable now!