eclipse add objects to class, automatically and retroactively - java

I changed the location of a object classes that my class in question relies on.
Now many references to other objects are broken
Is there an automated way for it to add those classes back without my right clicking on every object reference and choosing what the correct coarse of action should be (which is always Import this shockingly matching class)

Yes there is a way:
select all related projects from the project browser >> right click >> Source >> Organize imports.
OR
select all related projects from the project browser >> CTRL + SHIFT + O
And next time you want to move a class and automatically all the references, please select the class (right click the class name) and choose the Refactor menu item >> Move.. option.

Related

In Java eclipse IDE, how to get all classes with the corresponding methods of a project in one view

Please let me know, Is there any possibility to get all classes with the corresponding methods of a project in one view in eclipse IDE.
Outline view is there but that's for only one class but i need for whole projects.
Kind of outline view for the whole projects.
Thanks.
Point given by HighCommander4
I think I know understand what your 'corresponding' means. In fact you want to see all classes in your project with all their methods. Simple as that.
What you are looking for is the 'Package Explorer' view. Basically it shows an Overview over your workspace, but it can do much more.
To view all classes and methods, select the project you are looking for, right click its src folder and select go into. Unfortunately you now have to manually elapse all classes, as there is no elapse all; only a collapse all.
If you are just looking for classes with methods that 'look like' the method you are corresponding to, the 'Search' view is what you are looking for.
To perform a search for a specific method, simply mark or select it and press Ctrl + Shift + G.
However, the 'Search' view will go through your complete workspace, but you can group the results after projects.
Edit: I never knew of Ctrl + Shift + G until I read Thomas' answer just know. Ctrl + G brings up the 'Search' view, too, but somehow it filters the results to a specific project (not the selected one).
If you are looking for classes that implement the method you are corresponding to, the 'Type Hierarchy' view is what you are looking for.
To build up a type hierarchy for a specific method, simply mark or select it and press Ctrl + T for a quick context menu style or press F4 to open the 'Type Hierarchy` view.
With the Shortcut Ctrl+Shift+G you can search for all references of a selected method.

Using marker interfaces in android studio / IntelliJ IDEA

I am trying to manage relatively large projects in Android Studio and IntelliJ IDEA. I want to use a marker interface to indicate a class that is unfinished in some way.
public interface ToDo {
}
The trouble is that when I click the "has implementations" icon, I get a list of all subclasses of classes that include the words implements ToDo, including anonymous ones (as I should). Is it possible to do a search so that I only get a list of classes where the words implements ToDo actually appear? If not, is there an alternative way to do it?
Alternative way for intellij & Android Studio
From the app menu, Edit > Find > Find in Path (quick tip the keyboard shortcut will be listed next to the menu option)
type in " implements ToDo" in text to find
For Scope, Select Custom "Project Files" (this will help you avoid some generated classes coming up in your search results)
For File name filter, check the checkbox for "File masks" and type in "*.java" in the textbox next to it.
Click "find".
"Find in path" on the project folder will do the work.

How to automate adding multiple methods in android studio 1.0?

I am following a tutorial on how to create a flappy bird clone from http://www.kilobolt.com/day-3-understanding-the-libgdx-framework.html
This is where I am at
I know what's going because GScreen is a concrete class, it has to provide implementations of all the methods in the Screen interface.
To do this, I looked up "Add unimplemented methods" feature in the Android Studio
and used the control o shortcut to get to this dialog.
However from this dialog, is there a way of selecting multiple methods that you want stubs for? If I double click one, I just get the stub for that method. Is there a way to get multiple stubs at a time, for efficiency sakes?
You can select multiple methods using the control (Command on a Mac) key or the shift key, then single click. The shift key selects a continuous list of methods, the control key allows non-contiguous selections.
You can right click on the class name in java file. A drop down arrow will come containing an various options like "GENERATE". Click it and select which unimplemented you want to apply it will be automatic generated.

Eclipse Quick Fix or menu option for importing different Java class?

I have written a project that includes a Character class. In this project, in a different package, I have another class that's trying to use it:
for (int i = 0; i < NUM_CHARACTERS; i++) {
Character c = new Character(10);
}
The problem is that Eclipse is automatically trying to use java.lang.Character:
What I would like to do, is find a way either via the contextual menu, keyboard shortcut, Quick Fix menu, etc. to have Eclipse provide me with alternate imports.
The issue is obviously that the class is part of the standard API, otherwise it would certainly ask me which Character class to import. Normally if you've imported the wrong one accidentally, you can just delete it from your import block at the top, and use Quick Fix to pick the right one.
But how, in this case, can I easily tell Eclipse I want to use a different class, without having to manually type the import into the top? I have a number of classes that will be named similarly to the java.lang classes, so I'm looking for a time-saving solution.
Ctrl+Space will give you an option to select the required package.
Just place the cursor at end like Character^ and press Ctrl+Space
where ^ show your cursor position. For example
Date class is present in java.util as well as java.sql, so when you will type
Date^ Ctrl + Space, it will pop-up with all the packages where Date class is present and you can choose your desired import from there.
Another way, Just delete all the auto imports & press Ctrl + Shift + O to organize imports. Eclipse will prompt you for all the place wherever there is any ambiguity in identifying the right package.

How to get eclipse to go to the ONLY implementation of an interface's method?

If I'm in an interface and pointing to a method name, what can I do to quickly go to the ONLY implementation of that method?
Using Eclipse 3.6.
F3 is the typical "go to implementation". For interfaces that go to the interface definition.
Instead use Ctrl + T to see all implementations of the interface definition. You can then easily go to the one you want with the arrow keys and Enter. I believe that the first one is automatically selected so that Ctrl-T + Enter will do what you need.
I just checked this on my Eclipse 3.6 install: Hold control (command on Mac), hover over the method name and select "Open Implementation".
You may assign a keyboard shortcut to this action by using Window > Preferences > General > Keys and searching for "Open Implementation".
In the keymap (General > Keys) search for "open implementation" and map it to whatever you want. I chose Ctrl + Shift + I. Make sure you select "Editing Java Source" in the When box. I tested it, and having the cursor over the method name and pressing Ctrl + Shift + I took me directly to the implementation instead of showing the hierarchy that you get with Ctrl + T.
Also you can see an answer to a nearly identical question for other options:
In eclipse, ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly to that implementation?
If someone still need this information nowadays (Eclipse version 2022), to jump into interface method definition starting from an #Override method, now in Eclipse you can see on the left, next to the method signature, a little white triangle. By clicking on that you will jump to the implemented interface method. here an image of the little triangle
Oterwise, if you are on a interface method definition and you need to jump to one of the implementations, you must use CTRL+T shortcut to see the list of available implementations and than click on one of them.

Categories