From b65a11dfc53b5af50c2924e66ffef503e652759b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 28 Sep 2023 13:16:23 -0400 Subject: [PATCH 1/2] separate minimization part --- .../specimin/SpeciminRunner.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/checkerframework/specimin/SpeciminRunner.java b/src/main/java/org/checkerframework/specimin/SpeciminRunner.java index 06ca7d93..760193b1 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 provides a simplified way for users to perform the minimization job using Specimin. + * Users can call this method directly instead of invoking the main method of Specimin to initiate + * the minimization process. + * + * @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())) { From 27d15b312e78633fc25800bd1bb8ffe0bfd43fac Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 28 Sep 2023 15:21:28 -0400 Subject: [PATCH 2/2] clarify javadoc --- .../java/org/checkerframework/specimin/SpeciminRunner.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/checkerframework/specimin/SpeciminRunner.java b/src/main/java/org/checkerframework/specimin/SpeciminRunner.java index 760193b1..3b14f32b 100644 --- a/src/main/java/org/checkerframework/specimin/SpeciminRunner.java +++ b/src/main/java/org/checkerframework/specimin/SpeciminRunner.java @@ -69,9 +69,9 @@ public static void main(String... args) throws IOException { } /** - * This method provides a simplified way for users to perform the minimization job using Specimin. - * Users can call this method directly instead of invoking the main method of Specimin to initiate - * the minimization process. + * 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.