groovyc stub generator: use API instead of a hack
authorpeter <peter@jetbrains.com>
Thu, 19 Feb 2015 07:45:20 +0000 (08:45 +0100)
committerpeter <peter@jetbrains.com>
Fri, 20 Feb 2015 06:13:37 +0000 (07:13 +0100)
plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/DependentGroovycRunner.java

index 620894301b506b8bafe8006949415a5cad95132b..ad1babb2a347816ae113df27016d3b8c321e1b68 100644 (file)
@@ -26,6 +26,8 @@ import org.codehaus.groovy.classgen.GeneratorContext;
 import org.codehaus.groovy.control.*;
 import org.codehaus.groovy.control.messages.WarningMessage;
 import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
+import org.codehaus.groovy.tools.javac.JavaCompiler;
+import org.codehaus.groovy.tools.javac.JavaCompilerFactory;
 
 import java.io.*;
 import java.lang.reflect.*;
@@ -361,20 +363,7 @@ public class DependentGroovycRunner {
       }
 
       public void gotoPhase(int phase) throws CompilationFailedException {
-        if (phase == Phases.SEMANTIC_ANALYSIS) {
-          System.out.println(GroovyRtConstants.PRESENTABLE_MESSAGE + "Generating Groovy stubs...");
-          // clear javaSources field so that no javac is invoked
-          try {
-            Field field = JavaAwareCompilationUnit.class.getDeclaredField("javaSources");
-            field.setAccessible(true);
-            LinkedList javaSources = (LinkedList)field.get(this);
-            javaSources.clear();
-          }
-          catch (Exception e) {
-            e.printStackTrace();
-          }
-        }
-        else if (phase <= Phases.ALL) {
+        if (phase <= Phases.ALL) {
           System.out.println(GroovyRtConstants.PRESENTABLE_MESSAGE + "Groovy stub generator: " + getPhaseDescription());
         }
 
@@ -382,6 +371,15 @@ public class DependentGroovycRunner {
       }
 
     };
+    unit.setCompilerFactory(new JavaCompilerFactory() {
+      public JavaCompiler createCompiler(CompilerConfiguration config) {
+        return new JavaCompiler() {
+          public void compile(List<String> files, CompilationUnit cu) {
+            //do nothing
+          }
+        };
+      }
+    });
     unit.addSources(new String[]{"SomeClass.java"});
     return unit;
   }