How can I format an entire source tree in Eclipse 3.4 (Ganymede)? - eclipse

The obvious thing to do would be to:
Right-click on the folder that you wish to format.
Source > Format
Expected results:
- All java code in the directory and subdirectories are formatted (using the project specific formatting settings)
Actual results:
- None of the java is formatted.
While we're at it, how can we do a batch clean up operation in Eclipse?
From editor, I Right-click > Source > Clean Up, but I can only do one file at a time.

I faced the same issue. I had to switch to packaged Explorer to use the formatter. Under Navigator it does not work. Hope this help.

As mentioned in this thread, this (format all Java source files within a folder) should work since eclipse3.0.
Do you see some kind of error message in the "errors view" ?

I did exactly as you suggested you would like to do, and it did exactly what you suggested was expected. I selected Source | Format for a directory in my src tree and it reformatted all the units within.
EDIT: ...with 3.4.1 Ganymede.

If your code isn't checked out from source control or isn't writable, doing a group operation like this won't check them out or make them writable.

I have the same problem using SpringSource Tool Suite 2.5.1
I am using the package explorer
The project is in a SVN repository that is checked out
In the progress dialog I can see that only the XML files are modified
When I press Ctrl+Shift+F into a file, it gets reformatted (therefore is writable) but when after a reverse I do a right-click Source > Format on its folder nothing happens
I know it's been 2 years but I was wondering if #LES2 has found a workaround to correct this
EDIT :
Okay, despite I was really in the package explorer as written before, my java code was interpreted only as text files. I re-ran the full repository check-out of my project and a package-tree (squares for packages instead of folders) appeared giving me the ability to mass-format even Java files.

Related

Version 8.2 difficulties

I upgraded to version 8.2 and my projects list disappeared. When I pointed to the folder where my java files are located, Netbeans cannot find a project file. However, in the folder reside my 2 java files and a form file.
Admittedly, I do lack a bit of Netbeans experience, and for the life of me, I cannot figure out how to import these files into a project - and be able to work with the form. Can anyone give me a pointer on how to resurrect my project?
Edited at recommendation:
When I selected "Open Project" and entered the path to where my files are located "/Users/robertbray/Documents/Robert/NetBeans/numberaddition/" In the "Project Folder" pane, nothing appears, as if the project does not exist. So, playing around this evening, I used the "Open File" method and entered the path "/Users/robertbray/Documents/Robert/NetBeans/numberaddition", now I am able to see my source files (NumberAdditionUI.java, NumberAdditionUI.form, and GraphPanel2.java) and I can open them, including the form (design). However, I cannot determine how to convert this to a project file so I can build and run the code - these options are greyed out.
Since I had the original source files, I created a new project, then moved (and renamed) the original java class/form files into the "/src" directory. Of course I had to do some changes in the java files with the new name. As s test, I modified the form and rebuilt the project. Working as expected. Many thanks to #skomisa!

How do I make Javadoc files show in Eclipse Package Explorer?

I'm using the Android Developer Tools wrapper of Eclipse, and the EGit git plugin for Eclipse. I'm having a problem where I'm generating Javadoc, but I can't find it in the package explorer.
I go to Project->Generate Javadoc.
I'm using C:\Program Files\Java\jdk1.7.0_51\bin\javadoc.exe as my Javadoc command, and I select the package I want to generate Javadoc for.
I select the standard doclet with the following destination, where ReverseSentence is my package.
C:\Users\myname\workspace\ReverseSentence\doc
I check "open generated index file in browser", and generate the javadoc. It generates the Javadoc with no errors, and the index shows up in the main section of eclipse. However, the files don't show up in the package explorer.
I searched in the workspace through opening up the folder, and inside workspace\ReverseSentence there is a folder doc, which contains the proper Javadoc. However it isn't showing up in the package explorer.
How do I make it show up in the package explorer? When I used the regular version of Eclipse in the past (not the android developer tools wrapper), the Javadocs showed up there automatically.
What I've tried:
refreshing the project
closing and restarting eclipse
generating the Javadoc with an older version of the Javadoc command, which was what I was using in the other version of eclipse last time it worked (jdk1.6.0_43)
deleting the doc folder, recreating it, then trying to generate the javadoc in it (it generated in it but did not show up)
unchecking the filters which hide some things in the package explorer, (as shown how to do here: How can I get Eclipse to show .* files?)
I think that the problem is the destination folder/directory for your Javadoc files once they are generated. I encountered this same problem and discovered (finally) that the Javadocs were getting sent to a different folder than my package files were in. They went to the workspace folder I thought held all of my code also, but the code was going into a different repository. Maybe try looking for your code's location and then seeing if the generated Javadocs are landing somewhere else when they are generated. If this is the case, then the fix is to regenerate and send to the code's directory. This way, Package Explorer should be able to find and display them. Hope this helps!
Did you try by refreshing the workspace or re-opening the eclipse !?
Check the filters in the settings of the explorer. If something does not show up, usually the filter hides it. The filter can be accessed in the drop down menu of Package Explorer.

How can I get Eclipse to index an entire C/C++ source tree that contains multiple "make projects"?

I'm having trouble getting Eclipse to index my source code. I'm using Eclipse Helios on Windows XP at the moment.
I have a directory called src. Within it, I have a bunch of dirs, something like this:
src
-include (common headers)
-lib
-libIO (source code for this library)
-libGUI (source code for this library)
-pgms
-pgm1 (source code and headers for this pgm)
-pgm2 (source code and headers for this pgm)
Each leaf has its own Makefile. There is no top-level Makefile in src. pgm1 can and does include files from include and lib/libIO and lib/libGUI.
Basically, I want Eclipse to index my entire src directory, without having to set up a C/C++ project for every leaf in my tree. I can't seem to find a way to make this happen.
Here's my symptoms; what I'm trying to solve for:
When editing source in the pgm1 dir, it references functions that are declared in my include dir header files and defined in source files found in lib/libIO.
However, when I press F3 to get to the declaration of a function, Eclipse says "Could not find symbol 'X' in index". I can't seem to get Eclipse to find either the header declaration or the source definition for the method under my cursor (like the Java module does perfectly). Is this possible?
I had exactly same issue as OP but for some reason the menus in Eclipse I was using (Helios Service Release 2) were not "Go to Properties -> C/C++ General -> Paths and Symbols -> Source Location.".
The way I fixed the issue was :
in C/C++ view, right-click on top project name;
in the menu, select New->C++ Project;
in the window that appears, select Convert to and then select C++ project;
click OK to close the window.
Eclipse will start indexing right away. Depending on the size of source tree it may take a while but you will have the indexing working finally after that.
I faced similar situation. I solved it in this way: right-click the project in project View-->select Index-->rebuild.
I managed to solve this thanks to comments here.... I ended up recreating my project. I used the Import method to download a project from CVS, and told it to use the New Project wizard to do so. When I got the New Project dialog, I told it this was a C++ Project, and the indexing now works fine.
I still wish I could index files without having to attach a specific project type to it, but at least I found an answer.
Thanks for the help all.
Exit Eclipse. In workspace go to ".metadata/.plugins/org.eclipse.cdt.core" and delete everything in there.
in the project explorer panel, right click the project you want to re-index, then select index, then select the action you want
Indexing of files and variables under different flags is always complicated when we have a huge project, lot of files and more importantly lot of different build options. I prefer playing around with the Indexer option to help me browse the entire code.
You can find it : Project Properties>C/C++ General/Indexer.
You can choose "Enable project specific settings"
Then it's up to you to choose the options you want for your project.
For a particular build we can choose "Use active build configuration" so that only the files and MACROS are considered which are used by the build script.
Or Index all source files in the entire project.
I am using Eclipse Neon 3, here's the solution that worked for me :
go to File
New
Convert to C/C++ Autotools project
then select your project and finish.
It can take some time to finish indexing, it depends on your project size.
I have experienced problems with the indexer of Eclipse Luna when there was an unresolved friend declaration in the class declaration - it seems then that the indexer skipped indexing the rest of that class, and all references to it was shown as unresolved by the indexer.
Solution: removed the unresolved friend declaration (in my case, it was legacy code that was no longer needed).
Please try the following (my project is set up differently, so I am not sure this will work for you).
Go to Properties -> C/C++ General -> Paths and Symbols -> Source Location.
Do you see your source folder there?
I observe this behavior:
When I add a source folder and then exclude it from build, it disappears from the above list. After that the folder is no longer indexed. Re-adding it to "Source Location" solves the problem: the folder is now indexed; remains excluded from build (as intended); is visible among source locations.
I believe it is a bug -- excluding a source folder from build should not remove it from source locations list.
In Coocox IDE (Eclipse + gcc) the problem is resolved by going from file menu
Edit > Preferences > C/C++ / Indexer > Build configuration for Indexer set to Active build configuration and the rebuild the project (Ctrl R).
If the project is already converted to C/C++ and still the index is not working you can right click on the project and Index and rebuild. The project will start indexing right away.
I am using
Eclipse IDE for C/C++ Linux Developers
Version: Helios Service Release 2
Build id: 20110218-0911
I followed the suggestions above and in addition I had to mark all referenced projects (with in the work space) using project properties->Project references
The following has worked for me in Eclipse Neon:
New Project -> C/C++ -> Makefile project with existing code -> Next. Then Navigate to the code and finish the project creation. Indexing starts automatically.

How to format all Java files in an Eclipse project at one time?

I have an old Eclipse project and the code is not well formatted. I'd like to format all the .java files according to the settings in Eclipse. I don't want to edit every individual file with Ctrl+Shift+F. Is there a way to format all my files? Perhaps an Eclipse plugin?
Right click on the project root and select Source -> Format. This should work for at least version 3.8.1. and above.
If the above does not work, you're probably using an older Eclipse-version. In such case you can select your Source Folders by clicking on them while holding down CTRL, then select Source -> Format from the right-click -menu. Works with package-folders and class files also, in case you don't want to format the entire project.
I also had the Java Perspective ON and this was still not working. My eclipse was only formatting css and Html files, but not JAVA ones.
Then, I located this answer that explains this:
You must add Java Facet to the project to allow Java classes to be detected by Eclipse formatter
Then, you should check on PROJECT-PROPERTIES-PROJECT FACETS and activate the Java facet for the project:
And by right-clicking on top of the PACKAGE-EXPLORER you will find the SOURCE - FORMAT option, and it will format Java files too.
Be careful, check it´s package explorer, not Project Explorer (click
Window-Show View-PackageExplorer)
This is the purpose of
Source ->Clean Up...
selecting the appropriate options.
In older versions of Eclipse (Indigo) it works from Package Explorer (not Navigator). Right click the package you wish to format then choose Source -> Format. It will format all classes in that package and its sub-packages.
In Eclipse Mars.1 Release (4.5.1) version and above, just press
Right click on the code typing area
Src > Source > Format.
If you want to format individual java / xml file just do Ctrl+Shift+f

Eclipse autocomplete not working in some Java files

I have noticed that autocomplete is not working in some of java files in Eclipse.
Also, the files where autocomplete is not working, display a hollow "J" as the icon for the Java file. The files where autocomplete is working, icon for java file is a filled "J"
I am wondering if someone can point out what went wrong all of suddent, why the change in icons and why autocomplete and syntax highlighting is turned-off in the files with a hollow "J" icon?
Thanks.
update
Basically, I was doing what VonC has suggested but Eclipse was not refreshing that it why I was thinking that VonC's suggestion isn't working, after doing a refresh, the problem resolved.
Since this question is highly ranked on Google, I will add a solution to fix general auto complete issue, not for 'hollow J' ones.
Try Window (Windows/Linux) or Eclipse (OS X) -> Preferences -> Java -> Editor -> Content Assist -> Restore Defaults
also
Content Assist -> Advanced -> Restore Defaults
some answers (restore defaults) above do not work for some adt bundle installs as of jan '13.
in those cases, go to
Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced
and tick on the JAVA PROPOSAL options.
In this following picture, MyClass.java has a hollow J, because it is explicitly excluded from the sources to build:
Could you go to the properties of the project, "Java Build Path" Section, "Source" tab and see if some exclusion filter has been set ?
It is usual for instance to define:
**/Test*.java
to exclude at first building any unit-test class (when you have a large set of sources and do not want to be presented with Test classes during auto-completion, or do not want them considered during source searches).
Those with a hollow J aren't part of the build path of the project, so they can't participate in the normal build process and therefore auto-complete won't be enabled for these files (and other Java editor features!). You must add the folders with the Java files to be built to the build path using the 'source path' section of the project properties. This can be accessed by right clicking on a project in the project navigator / package explorer and going to Properties. See http://www.informit.com/articles/article.aspx?p=367962 for details.
Additionally, if the files aren't part of a Java project in the first place, you must create a project and move the files in, or put the files in an existing one. Again, make sure these file are under a source directory as described by that section of the project properties.
(source: teradata.com)
I cope with the issue by deleting the file if autocomplete does not work. Just before copying the source code. Then I have recreated the java file with the same name. Pasted the source code previously copied.
As an addendum to the #VonC answer, make sure that the Java files are part of the Inclusion pattern. I had a case where a build process was creating the project while only including .js files and not the Java files:
You can manually edit the inclusions via the Edit button. In my case, a fix was made to the build script to make it permanent.
Neither Restoring Defaults or my build path (file was already in package directory w/other files where auto-complete was working) fixed problem. Fix for me was to close the file explicitly (right click on file name in tab) and re-open. Interestingly, just re-starting Eclipse didn't work either.
Make sure you have the right directory structure. I believe that:
Hollow J icon beside Java file - will not be build
Normal J icon beside Java file - is a file to be build.
I made a mistake when I created webapp artefact. By default it does not create folder for Java, but for resources. I mistakenly put my sources there.
Have a look - see the difference.
I was able to get this fixed in Visual Studio Code, VSCode but entering crtl-shift-p and typing in clean. When I did that I ran the "Java: Clean Java Language Sever Workspace" command. This fixed my autocomplete issue for me.