Updating a class after changing its Interface - visual-studio

Say I add a function to an outstanding Interface.
In Visual Studio, within a class which implements it I can right click the Interface declaration and re-implement it. This will update the code to reflect the changes made. Is there anyway to do the same thing in eclipse?
It'd be nice if there was.
I've searched the net, alas no joy.

Put the cursor on the name of the class and press CTRL+1 to activate the quick-fix. That should offer the option of adding the new method.
UPDATE: BTW, here's a really handy list of Eclipse keyboard shortcuts. If you're on Mac, you can usually substitute ⌘ for CTRL.

You can also use the source menu. Select Source > Override/Implement methods.

Related

Find out what class a method belongs to (in Visual Studio or Resharper)

If I'm looking at a method definition in Visual Studio (with Resharper) is there an easy way to find out what class it belongs to? (As of now, I've resorted to a text search in the "up" direction for the string "class".)
The Resharper command Go to containing declaration (ctrl + [) should do the trick
Edit:
Or if you have the navigation bar at the top of the code window enabled, that should display the type name. But I have that turned off, since I use keyboard navigation and the bar itself slows down Visual Studio.
You have files with more than one class in? That makes ponies sad...
Anyway, to actually answer, can't you just look at the navigation bar?
The best (direct) way specific to your question is PHeiberg's answer.
But if you ask this question I guess you don't know the File Structure window that can be enabled by ReSharper->Windows->File Structure or by shortcut Ctrl+Alt+F.
With that window you see always where you are in your file.
Aside from using ReSharper's File Structure and/or Go to Containing Declaration - options mentioned previously - there's also a tiny feature in ReSharper called Quick Documentation that in my view is better suited for this kind of task since it shows you method info in-place, without forcing you to navigate anywhere from the method you're on. Ctrl+Q, Esc, and you're done. It works on all kinds of symbols (not limited to methods), both on declarations and on usages.
For VS, right click on the function and select 'Go To Declaration'. (Ctrl + F12)

What interfaces are implemented by a class?

I think it is a simple stuff, but I cannot find it.
Are there any easy way to know what interfaces a class implements? Directly or in its ancestor classes.
I have Visual Studio 2010 Pro without commercial addons.
Thanks.
Another way is to open Class View window (menu View -> Class View) and see it in a graphical representation under Base Types:
Also, make sure you've installed Productivity Power Tools because it allows you to see base / derived types, references, etc. through very handy interactive tool tips:
Not exactly what you asked, but you can press F12 on a class name (right click -> Go to definition) and then just look at the class Foo : IBar line.
You can see this in the Object Browser (under the "Base Types" folder). You will need to have the "Show Base Types" option checked though:

Can I auto-import a namespace in MS Visual Studio 2010?

When developing for Android in Eclipse, for example, it's easy to automatically import packages and classes by hitting Ctrl+Shift+O. I'm finding it difficult to write code every time I have to go google a function to figure out its namespace ... is there an easier way?
Once you've added a dll as a reference, VS will suggest this as part of its intellisense feature. Type in the name, and then hover over it - there will be a blue (maybe it is red?) underline - and VS will give you an arrow to click that lets you add the namespace.
If it is a namespace you find yourself adding frequently, you can add it to your config so that you're not doing it in files across your project.
(I do have Resharper installed so I can't check this, but I'm pretty sure VS has this natively...)
There is Ctrl + Shift + F10 or Ctrl+ shortcut, that provides some light refactorings like creating method stubs, renames methods and variables and imports usings.
This shortcut is not always available - it can be used when a small red box underneath, after you click it you'll see the drop-down menu with a choice of possible actions
When you type in a class name, hit Ctrl + . a list would appear, then hit Enter on what you need

How to show all implement instance of an interface method?

In my project, there are tons of interface classes used. I have difficulties in reading to understand the code since browsing the definition of the codes (by selecting the method name and pressing F12 or right click + go to Definition) just lead me to the interface.
Is there a way (built-in or addon) in Visual Studio 2010 to list out all of the instance of a method of an interface?
Hope to hear from you.
After a while, I found that just with VS 2010, I can archive this all alone: Use "Call Hierarchy"!
Place your cursor on any member of the interface class
Right click and choose "View Call Hierarchy"
Open the "Implements..." node in the "Call Hierarchy" pane.
That's it. Enjoy ^_^!
Resharper can do this and is an excellent addition to VS.net for many other reasons that you'll discover...

ReSharper: Rename namespace not available?

I'm trying to rename a namespace. For some reason, ReSharper isn't giving me the option to do so. I right click on it and choose Refactor, but everything except "Convert" is greyed out. I try the key combination CTRL R + R, and it says the command is unavailable. What am I doing wrong?
Here is documentation suggesting that what I am trying to do should work:
http://www.jetbrains.com/resharper/documentation/help20/Refactoring/renaming.html#renameNamespace
I'm using Visual Studio 2008 with R# 4.5
I have come across this before and the answer is very subtle. Do not select (eg by double clicking) the entire method name(or namespace if renaming a namespace). Instead, ensure the method name is deselected and place the caret over the method name.
eg
NOT this
When you select the Convert menu the items should now be available for methods, and 'Rename' will become available if you had the caret over a namespace.
In my mind this should be changed, it is not obvious.
Apparently, the way to do this now is via ReSharper => Refactor => Adjust Namespaces menu or open the Class View, right click on the namespace you wanted to rename and again select Refactor => Adjust Namespaces.
See also: Fastest way to update namespaces with ReSharper?
For what it's worth, I just had this problem. Closing Visual Studio and re-opening it fixed the problem for me. HTH.
This is an old issue but I just had this and perhaps know a workaround.
Since someone has commented just yesterday timing could not be more perfect.
Anyways,
I had the same issue and was finally able to do a rename refactoring on my namespace.
I chose one of the classes in my project and did the move to another namespace refactor.
Then I was able to go to another class and do the rename namespace refactor.
Perhaps a bug in Resharper that if the namespace is consistent throughout the class then it's disabled? Unlikely since this was reported as far back as 4.5...

Resources