Commits

Martin Skurla committed 50f6d2f

- refactoring

Comments (0)

Files changed (4)

src/main/java/org/crazyjavahacking/astvisualizer/impl/javac/JavacASTParser.java

             JavaCompiler.CompilationTask compilationTask =
                     JavaCompilerUtils.getCompilationTaskFromJavaFileObject(javaFileObjectContainingSyntacticSugar);
 
-            CompilationUnitTree compilationUnitTree = JavaCompilerUtils.parseCompilationTask(compilationTask);
+            CompilationUnitTree compilationUnitTree = JavaCompilerUtils.compile(compilationTask);
 
             return javacTreePathScanner.doScanning(compilationTask, compilationUnitTree);
         }
     }
 
     private String sourceCodeAfterCompilation(JavaFileObject javaFileObject) {
-        CompilationUnitTree compilationUnitTree =
-                CompilerTreeAPIUtils.getCompilationUnitTreeFromJavaFileObject(javaFileObject);
+        CompilationUnitTree compilationUnitTree = JavaCompilerUtils.compile(javaFileObject);
 
         return compilationUnitTree.toString();
     }

src/main/java/org/crazyjavahacking/astvisualizer/impl/javac/util/CompilerTreeAPIUtils.java

 package org.crazyjavahacking.astvisualizer.impl.javac.util;
 
 
-import java.io.OutputStreamWriter;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.tools.JavaCompiler;
-import javax.tools.JavaFileObject;
-import javax.tools.ToolProvider;
-
 import com.sun.source.tree.BlockTree;
 import com.sun.source.tree.CompilationUnitTree;
 import com.sun.source.tree.ImportTree;
     public static boolean isImportTree(Tree tree) {
         return tree instanceof ImportTree;
     }
-
-    public static CompilationUnitTree getCompilationUnitTreeFromJavaFileObject(JavaFileObject javaFileObject) {
-        List<JavaFileObject> javaSources = Arrays.asList(javaFileObject);
-
-        JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
-
-        JavaCompiler.CompilationTask compilationTask = javaCompiler.getTask(
-                new OutputStreamWriter(System.out),
-                null,  // default file manager
-                null,  // default diagnostic listener
-                null,  // no compiler options
-                null,  // no classes for annotation processing
-                javaSources);
-
-        CompilationUnitTree compilationUnitTree = JavaCompilerUtils.parseCompilationTask(compilationTask);
-
-        return compilationUnitTree;
-    }
 }

src/main/java/org/crazyjavahacking/astvisualizer/impl/javac/util/JavaCompilerUtils.java

 import java.util.List;
 
 import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
 import javax.tools.JavaFileObject;
 import javax.tools.ToolProvider;
 
      *
      * @return CompilationUnitTree
      */
-    public static CompilationUnitTree parseCompilationTask(JavaCompiler.CompilationTask compilationTask) {
+    public static CompilationUnitTree compile(JavaCompiler.CompilationTask compilationTask) {
         JavacTask javacTask = (JavacTask) compilationTask;
 
         try {
         }
     }
 
+    public static CompilationUnitTree compile(JavaFileObject javaFileObject) {
+        CompilationTask compilationTask = getCompilationTaskFromJavaFileObject(javaFileObject);
+
+        return compile(compilationTask);
+    }
+
 
    //-----------------------------------------------------------------------------------------------------------------
     // Inner classes.

src/main/java/run/Runner.java

 import java.io.FileReader;
 import java.io.IOException;
 import java.io.Reader;
-import java.io.StringReader;
 import java.util.Set;
 
 import javax.swing.JComponent;
 import org.crazyjavahacking.astvisualizer.api.model.NodeModel;
 import org.crazyjavahacking.astvisualizer.impl.javac.JavacASTParser;
 import org.crazyjavahacking.astvisualizer.impl.javac.util.CollectionUtils;
-import org.crazyjavahacking.astvisualizer.impl.javac.util.CompilerTreeAPIUtils;
+import org.crazyjavahacking.astvisualizer.impl.javac.util.JavaCompilerUtils;
 import org.crazyjavahacking.astvisualizer.util.JavaFileObjectUtils;
 import org.jgrapht.DirectedGraph;
 import org.jgrapht.traverse.BreadthFirstIterator;
                     throw new AssertionError();
                 }
 
-                CompilationUnitTree compilationUnitTree =
-                        CompilerTreeAPIUtils.getCompilationUnitTreeFromJavaFileObject(javaFileObject);
-//
+                CompilationUnitTree compilationUnitTree = JavaCompilerUtils.compile(javaFileObject);
+
                 sourceTextArea.setText(compilationUnitTree.toString());
 
                 try {