Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you quickly find the implementation(s) of an interface's method? [duplicate]

Is there a quick way to find all of the implementations of, not references to, an interface's method/property/etc? Here's some sample code:

public class SomeClass : IBaseClass {   public Int32 GetInt()   {      return 1;   } }  public interface IBaseClass {   public Int32 GetInt(); }  public class SomeOtherClass {   IBaseClass _someClass;   private TestMethod()   {     _someClass = new SomeClass();     _someClass.GetInt();   } } 

I want to quickly get to SomeClass.GetInt() while reviewing SomeOtherClass.TestMethod(). If I right click on _someClass.GetInt() and click 'Go To Definition', it takes me to the interface. If I click 'Find All References', I could potentially see a list of all uses ... not just the classes that implement the GetInt() method.

Is there a faster way to find this? Any tips from other developers? We are using D.I. for most of our dependencies, which means that tracing through deeply nested code takes forever.

like image 582
Beep beep Avatar asked Aug 11 '09 16:08

Beep beep


People also ask

How do you open the implementation method in Visual Studio?

Choose Navigate | Go To Implementation in the main menu, press Ctrl+F12 , or click the symbol while holding Ctrl+Alt keys. Note that in Visual Studio 2017 and later, the Ctrl+Alt -click is used for adding multiple carets.

Where is the implementation class of interface in Intellij?

Press Ctrl+F12 or choose Navigate | Implementation(s) from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.

How interface methods are implemented in Java?

On implementation of an interface, you must override all of its methods. Interface methods are by default abstract and public. Interface attributes are by default public , static and final. An interface cannot contain a constructor (as it cannot be used to create objects)


2 Answers

Since I don't like to use the mouse while coding, I usually

  • move the cursor over the method
  • type ctrl+k clrl+t to open the Call Hierarchy window
  • move down to Implements node.
  • type Return to go to the selected implementation

AFAIK this is the quickest way to find the implementation of a method, without ReSharper.

(By the way: you can use the same system to move from a class method implementation to the corresponding interface declaration: just select the root)

like image 174
Arialdo Martini Avatar answered Nov 15 '22 23:11

Arialdo Martini


Alt-End will do this in ReSharper, I believe.

like image 38
lance Avatar answered Nov 15 '22 22:11

lance