1 package spoon.support.builder; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.util.Set ; 6 7 import spoon.processing.Builder; 8 import spoon.processing.BuildingException; 9 import spoon.reflect.Factory; 10 import spoon.support.builder.support.CtFolderVirtual; 11 12 public class SpoonBuildingManager implements Builder { 13 14 private boolean build = false; 15 16 CtFolderVirtual source = new CtFolderVirtual(); 17 18 CtFolderVirtual templates = new CtFolderVirtual(); 19 20 public SpoonBuildingManager() { 21 super(); 22 } 23 24 public void addInputSource(CtResource source) throws IOException { 25 if (source.isFile()) 26 this.source.addFile((CtFile) source); 27 else 28 this.source.addFolder((CtFolder) source); 29 } 30 31 public void addInputSource(File source) throws IOException { 32 if (FileFactory.isFile(source)) 33 this.source.addFile(FileFactory.createFile(source)); 34 else 35 this.source.addFolder(FileFactory.createFolder(source)); 36 } 37 38 public void addTemplateSource(CtResource source) throws IOException { 39 if (source.isFile()) 40 this.templates.addFile((CtFile) source); 41 else 42 this.templates.addFolder((CtFolder) source); 43 } 44 45 public void addTemplateSource(File source) throws IOException { 46 if (FileFactory.isFile(source)) 47 this.templates.addFile(FileFactory.createFile(source)); 48 else 49 this.templates.addFolder(FileFactory.createFolder(source)); 50 } 51 52 public void build(Factory factory) throws BuildingException { 53 if (build) 54 throw new BuildingException("Model already built"); 55 build = true; 56 57 factory.setBuilder(this); 58 59 JDTCompiler.javaCompilant = factory.getEnvironment() 60 .getComplianceLevel(); 61 62 try { 63 JDTCompiler.compileSrc(factory, source.getAllJavaFile()); 64 } catch (Throwable e) { 65 throw new BuildingException(e.getMessage()); 66 } 67 68 try { 69 JDTCompiler.compileTemplate(factory, templates.getAllJavaFile()); 70 } catch (Throwable e) { 71 throw new BuildingException(e.getMessage()); 72 } 73 74 factory.Template().parseTypes(); 75 76 } 77 78 public Set <File > getInputSources() { 79 return null; 81 } 82 83 public CtFolderVirtual getSource() { 84 return source; 85 } 86 87 public CtFolderVirtual getTemplates() { 88 return templates; 89 } 90 91 public Set <File > getTemplateSources() { 92 return null; 94 } 95 96 } 97 | Popular Tags |