2

So I wanted to try out converting our backend API source code which is written in Java and see how it looks (IIRC there is a preview before converting), but once I did it it automatically started converting all the files in the selected folders, and in the end it asked for code corrections, which I responded with no as I wanted to cancel it and now I am stuck with a broken code base with no other options than:

  • Reverting to the last git commit and reimplementing all the changes done from my side (I could have prevented it but committing before the conversion but oh well)
  • Continue using Kotlin to code in but I have code errors which I don't know how to fix

What I am asking instead is if there's anyway to convert Kotlin back to Java in IntelliJ IDEA? Thank you in advance

WalidSabihi
  • 77
  • 10
  • 4
    There is no way to convert Kotlin to Java that would give you your original source back. If you don't know how to fix those problems, you're welcome to ask. – yole Sep 05 '16 at 11:29
  • 2
    This is a good reason to commit regularly or at least before you try something as big as this. I think you'll just have to re-implement everything you didn't commit. – byxor Sep 05 '16 at 11:54
  • 1
    If theres _too_ much stuff to re-implement then I would just convert it back and refactor it to something acceptable. – byxor Sep 05 '16 at 11:59
  • @BrandonIbbotson Well what exactly do you mean by converting it back as there is no way to convert it back in IntelliJ, only Java>Kotlin – WalidSabihi Sep 05 '16 at 12:08
  • 2
    @WalidNawfalSabihi http://stackoverflow.com/questions/34957430/how-to-convert-a-kotlin-source-file-to-a-java-source-file – byxor Sep 05 '16 at 12:10
  • 1
    @BrandonIbbotson Decompiling doesn't always result in clean, close to original code so I guess I will just reimplement what I have lost seeing that it's going to take much less effort especially if I compare it with Kotlin (I can code in Kotlin I just am not ready to switch the full code base to it from Java) – WalidSabihi Sep 05 '16 at 12:18
  • 1
    Have you tried to use "Undo" in IDEA? – Kirill Rakhman Sep 05 '16 at 14:49
  • @KirillRakhman Yeah at the time there was no Undo possible – WalidSabihi Sep 05 '16 at 15:59
  • Can't you use Local history? – Bas Leijdekkers Sep 05 '16 at 17:15
  • @BasLeijdekkers What's that? – WalidSabihi Sep 06 '16 at 08:28
  • @WalidNawfalSabihi Right-click on a changed folder in the project view and invoke `Local History | Show History`. – Bas Leijdekkers Sep 06 '16 at 08:32
  • I have since restarted the computer and closed IntelliJ IDEA, will the history still work? And is it related to Git or what – WalidSabihi Sep 06 '16 at 08:34

1 Answers1

9

Intellij has a feature called Local History and it can be used to go back in time for things you did not commit to your source control system. This history is retained until you install a new version of IntelliJ IDEA or invalidate caches. Read more in the Intellij help for the feature.

Your source code constantly changes as you edit, test, or compile. Any version control system tracks the differences between the committed versions, but the local changes between commits pass unnoticed. Local History is your personal version control system that tracks changes to your source code on your computer and enables you to compare versions and roll changes back, if necessary. Local History is always at your disposal, no steps are required to enable it.

Local History is independent of external version control systems and works with the directories of your project even when they are not under any VCS control. It applies to any structural artifacts: a project, a directory or package, a file, a class, class members, tags, or selected fragment of text.

Community
  • 1
  • 1
Jayson Minard
  • 74,658
  • 30
  • 167
  • 210