Robert
Robert

Reputation: 42799

How to get the full class name of the of an Java file in Eclipse?

Often I would like to copy the fully qualified class name of the class the is open in the Java file editor in Eclipse.

There is a similar question: How do you get the fully qualified class name in Eclipse? but all the answers only work for classes you use in your source code but not for the Java class file currently open in the editor.

There is also an menu entry called "Copy qualified Name" in the context menu of the file element shown in the Package Explorer view, but if you execute this you only get the path name within the current project and not the class name.

How can I get the fully qualified class name separated with dots for an arbitrary Java file in a project or for an Java file that is currently open. For example if I have the file src/min/java/com/example/MyClass.java open in the Java editor how can I get directly the class name com.exmaple.MyClass?

Upvotes: 0

Views: 825

Answers (2)

Graeme Geldenhuys
Graeme Geldenhuys

Reputation: 21

Pretty much what the previous answer said. I however have shortcuts to do that.

  1. I bound the shortcut Ctrl+Shift+S to focus/show the current file in the Package Explorer
  2. You can then right-click the class in the Package Explorer treeview to select "Copy Qualified Name", or if you use that often, bind a shortcut to it (eg: Ctrl+Shift+C). It is listed in the available commands of the Keys dialog.

Upvotes: 2

Abra
Abra

Reputation: 20924

Highlight the class in the Outline view and right click the mouse. In the context menu, there is menu item Copy Qualified Name

Eclipse Outline view context menu screen capture

I am using Eclipse 2021-03

About Eclipse

You can also right click on any class name in the editor window. Copy Qualified Name appears in the context menu.

Eclipse editor context menu

Upvotes: 1

Related Questions