title: Java to JavaScript using GWT compiler
body: <p>I have some Java code written that I'd like to convert to JavaScript.
  I wonder if it is possible to use the GWT compiler to compile the mentioned Java code into JavaScript code <strong>preserving all the names</strong> of the methods, variables and parameters.
  I tried to compile it with code optimizations turned off using -draftCompile but the method names are mangled.
  If GWT compiler can't do this, can some other tool?</p>
  
  <p><strong>Update</strong></p>
  
  <p>The Java code would have dependencies only to GWT emulated classes so the GWT compiler would definitely be able to process it.</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>This Java method :</p>
  
  <pre><code>public String method()
  </code></pre>
  
  <p>got translated to this JavaScript funciton :</p>
  
  <pre><code>function com_client_T_$method__Lcom_client_T_2Ljava_lang_String_2()
  </code></pre>
  
  <p>using the compiler options :</p>
  
  <pre><code>-style DETAILED
  -optimize 0
  -draftCompile
  </code></pre>
  
  <p>So names can't be preserved. But is there a way to control how they are changed?</p>
  
  <p><strong>Clarification</strong> </p>
  
  <p>Say, for example, you have a sort algorithm written in Java (or some other simple Maths utility). The method sort() takes an array of integers. and returns these integers in an array sorted. Say now, I have both Java and JavaScript applications. I want to write this method once, in Java, run it through the GWT compiler and either keep the method name the same, or have it change in a predictable way, so I can detect it and know how to change it back to sort(). I can then put that code in my JavaScript application and use it. I can also automatically re-generate it if the Java version changes. I have a very good reason technically for this, I understand the concepts of GWT at a high level, I'm just looking for an answer to this point only.</p>
  
  <p><strong>Conclusion</strong></p>
  
  <p>The answer to the main question is <strong>NO</strong>.
  While method name can be somewhat preserved, its body is not usable. Method calls inside it are scattered throughout the generated file and as such, they can't be used in a JavaScript library which was the whole point of this topic.</p>