How do I get rid of "Current text selection cannot be opened in an editor" in Eclipse?
Asked Answered
C

3

15

Sometimes, I get this message in the status bar when I press F3 on a Type in a Java editor:

Current text selection cannot be opened in an editor

When I copy the selection into the clipboard and use Ctrl+Shift+T to open the "Open Type" dialog, I can paste the value and it will display the type and I can open it. The type is on the class path (no compile errors).

In other Java editors in the same project, F3 / Ctrl-Click works.

In the "broken" editor, it only works on internal fields and methods. For internal fields, it only works in the place where the field is defined. All places where a field is used are dead. "Mark Occurrences" works, though.

How do I get rid of it?

So far, I tried:

  1. Close and open the editor
  2. Clean the project
  3. Clean all projects
  4. "Update Project..." in the Maven context menu
  5. Restart Eclipse
  6. Restart Eclipse with -clean

This happens on Eclipse 3.7.2 with m2e 1.3.1 installed.

Colston answered 14/8, 2013 at 9:20 Comment(0)
C
6

[UPDATE] This seems to be a bug somewhere in the depths of m2e and JDT. Usually, it appears when you have several projects (Maven multi module / reactor build) and the modules MA, MB and MC depend on each other:

MC depends on MB depends on an inner parameterized type X.Y<T> of MA.

and you have closed the module MB. On the classpath of MC, this will look like so:

MB.jar
MA

That is MB exists as a JAR on the classpath while MA is imported as an Eclipse project from the workspace.

In this situation, Eclipse gets confused when reading .class files in MB.jar which need inner parameterized types from MA. My guess is that it needs the type from MB.jar, parses it which tells it of the dependency to the type in MA which it then tries to parse only to find that the type parameter for T can't be resolved since parsing of MB isn't finished, yet.

There are three fixes:

  1. Close MA. That will import everything as a JAR.
  2. Open the project MB.
  3. Make the inner type a toplevel type

[OLD]

If this happens, try these steps in order of increasing despair:

  1. Close the editor and open it again.
  2. Clean the project
  3. Close the project and open it again.
  4. Restart Eclipse

If all that fails:

  1. Export your preferences
  2. Exit Eclipse
  3. Delete (or rename) the folder .metadata in your workspace. It's an invisible folder on some OSs but it's there.
  4. Start Eclipse again
  5. Import your preferences
  6. Import all projects again. For this, select the workspace. Eclipse will then list all projects in the dialog and you can select all of them at once.

Related:

  • Bug 430605 - [select] Current text selection cannot be opened in an editor
Colston answered 7/11, 2013 at 16:23 Comment(1)
@Aaron, is there anything else you tried? I still have this error after doing all the steps above!Drumfire
S
2

There is a bug in Eclipse (in Luna at least) for a very specific workflow, which might not be the answer to this specific question, but might be helpful for others.

If you perform an import into the src (meaning src folder has focus before performing import) folder from an extracted jar (as source code), and you place breakpoints in the nested *.java files in the nested packages, it won't hit those breakpoints. In order to get things to work, you must keep hitting F3 instead of using "Open Declaration" to get to the *.java file you want to set a breakpoint in, then add the breakpoint by double clicking in the far left margin. Then Run > Debug As > Java Application.

Senseless answered 22/9, 2014 at 23:11 Comment(0)
O
0

this issue comes because eclipse workspace created by eclipse unable to load source code properly into its cache please follow below steps to resolve this issue

  1. goto eclipse workspace for eg i have loaded source code on below path: C:\Users\ABCD\WorkingSourceCode7july (it will have .metadata) just remove current working folder (WorkingSourceCode7july)
  2. after that open eclipse again and create new working folder(WorkingSourceCode7july) and try to import same source code

i hope this may resolve the issue

this worked for me

Oversee answered 8/7, 2022 at 5:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.