diff --git a/src/main/java/org/checkerframework/specimin/SpeciminRunner.java b/src/main/java/org/checkerframework/specimin/SpeciminRunner.java index 06ca7d932..3b14f32bb 100644 --- a/src/main/java/org/checkerframework/specimin/SpeciminRunner.java +++ b/src/main/java/org/checkerframework/specimin/SpeciminRunner.java @@ -59,10 +59,33 @@ public static void main(String... args) throws IOException { optionParser.accepts("outputDirectory").withRequiredArg(); OptionSet options = optionParser.parse(args); + String output = options.valueOf(outputDirectoryOption); + performMinimization( + options.valueOf(rootOption), + options.valuesOf(targetFilesOption), + options.valuesOf(jarPath), + options.valuesOf(targetMethodsOption), + options.valueOf(outputDirectoryOption)); + } - String root = options.valueOf(rootOption); - List targetFiles = options.valuesOf(targetFilesOption); - List jarPaths = options.valuesOf(jarPath); + /** + * This method acts as an API for users who want to incorporate Specimin as a library into their + * projects. It offers an easy way to do the minimization job without needing to directly call + * Specimin's main method. + * + * @param root The root directory of the input files. + * @param targetFiles A list of files that contain the target methods. + * @param jarPaths Paths to relevant JAR files. + * @param targetMethodNames A set of target method names to be preserved. + * @param outputDirectory The directory for the output. + */ + public static void performMinimization( + String root, + List targetFiles, + List jarPaths, + List targetMethodNames, + String outputDirectory) + throws IOException { // Set up the parser's symbol solver, so that we can resolve definitions. CombinedTypeSolver typeSolver = @@ -106,7 +129,6 @@ public static void main(String... args) throws IOException { parsedTargetFiles.put(targetFile, parseJavaFile(root, targetFile)); } } - List targetMethodNames = options.valuesOf(targetMethodsOption); // Use a two-phase approach: the first phase finds the target(s) and records // what specifications they use, and the second phase takes that information // and removes all non-used code. @@ -158,9 +180,6 @@ public static void main(String... args) throws IOException { LexicalPreservingPrinter.setup(cu); cu.accept(methodPruner, null); } - - String outputDirectory = options.valueOf(outputDirectoryOption); - for (Entry target : parsedTargetFiles.entrySet()) { // If a compilation output's entire body has been removed, do not output it. if (isEmptyCompilationUnit(target.getValue())) {