Ethan
Ethan

Reputation: 1266

Eclipse suddenly closes Java file, and now refuses to recognize it as such

I've come across quite an odd problem with eclipse.

I was working on a project and I right clicked on a method call declared in another class and used Eclipse's handy find declaration in project (saves me quite a bit of scrolling) to run a search for that specific method declaration. Right as it should my search pane pops up with a link to the method declaration. So I click the link, the other file the method is declared in is opened automatically, and poof the Java file I had searched from disappears from my editor tabs.

So I say to myself, "damn this old version of eclipse (Indigo) has some bugs...now I've got to go reopen my file and get back to my spot...GREAT!". But when I open the file, it is treated like a plain text file. All the text is the same color, and the outline won't work!!!

Upvotes: 1

Views: 412

Answers (2)

malat
malat

Reputation: 12502

This happened to me a couple of minutes ago. Trying to close/open the projet, restarting eclipse did not work for me.

The steps I used were:

  1. Pick another Java file (same package) right next to the bogus one (make sure syntax highlighting works on this one)
  2. Choose 'Save As' and override the bogus one.
  3. Verify that the bogus one now has proper syntax highlighting
  4. Use git checkout -- to retrieve you original file
  5. Et voilà !

Upvotes: 0

Ethan
Ethan

Reputation: 1266

So I solved the problem whilst I was typing the above up and decided to post the answer since it isn't a nice clean solution..and I doubt one exists.

Okay so file wasn't being recognized by eclipse..

So I open the file and do a Save As, and save it under another name in the same package. Then, I went to my test code and right clicked on a method call that was declared in the file that eclipse had buggered up, and went to search for declaration in project. Sure enough two results popped up, one in the newly saved as file, and one in the old one. I clicked on the old one, and still plain text...no difference. But then I clicked on the new one, and my highlighting was back! So then I just deleted the old file and refactored.

I think somehow eclipse made the file disappear without properly closing it...just my guess, glad I resolved this nice and quickly, hopefully anyone who has the same issue can be helped by this.

Upvotes: 1

Related Questions