1 package spoon.processing; 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.util.Set; 6 7 import spoon.reflect.Factory; 8 import spoon.support.builder.CtResource; 9 10 /** 11 * This interface defines the API to build a Spoon meta-model from input sources 12 * given as files. You should add your sources, and use {@link #build(Factory)} 13 * to create the Spoon meta-model. Once the meta-model is built and stored in 14 * the factory, it can be processed by using a 15 * {@link spoon.processing.ProcessingManager}. As an example of use, take a 16 * look at the {@link spoon.Launcher} implementation. 17 */ 18 public interface Builder { 19 /** 20 * Adds a file/directory to be built. By default, the files could be Java 21 * source files or Jar files. Directories are processed recursively. 22 * 23 * @param source 24 * file or directory to add 25 */ 26 void addInputSource(File source) throws IOException; 27 28 /** 29 * Adds a file/directory (as a CtResource) to be built. By default, the 30 * files could be Java source files or Jar files. Directories are processed 31 * recursively. 32 * 33 * @param source 34 * file or directory to add 35 */ 36 void addInputSource(CtResource source) throws IOException; 37 38 /** 39 * Gets all the files/directories given as input sources to this builder 40 * (see {@link #addInputSource(File)}). 41 */ 42 Set<File> getInputSources(); 43 44 /** 45 * Adds a file/directory to be used to build templates. By default, the 46 * files should be Java source files or Jar files containing the sources. 47 * Directories are processed recursively. Templates are set apart from the 48 * program to be processed for logical reasons. However, if a template was 49 * needed to be processed, it could be added as an input source. 50 * 51 * @param source 52 * file or directory to add 53 */ 54 void addTemplateSource(File source) throws IOException; 55 56 /** 57 * Adds a file/directory (as a CtResource) to be used to build templates. By 58 * default, the files should be Java source files or Jar files containing 59 * the sources. Directories are processed recursively. Templates are set 60 * apart from the program to be processed for logical reasons. However, if a 61 * template was needed to be processed, it could be added as an input 62 * source. 63 * 64 * @param source 65 * file or directory to add 66 */ 67 void addTemplateSource(CtResource source) throws IOException; 68 69 /** 70 * Gets all the files/directories given as template sources to this builder 71 * (see {@link #addTemplateSource(File)}). 72 */ 73 Set<File> getTemplateSources(); 74 75 /** 76 * Builds the program's model with a given factory and stores the result 77 * into this factory. Note that this method can only be used once on a given 78 * factory. If more attempts are made, it throws a {@link BuildingException}. 79 * 80 * @exception BuildingException 81 * when a building problem occurs 82 */ 83 void build(Factory factory) throws BuildingException; 84 85 } 86