Skip to content

Commit

Permalink
Merge pull request #24 from LoiNguyenCS/separate-api
Browse files Browse the repository at this point in the history
separate minimization part
  • Loading branch information
kelloggm authored Sep 28, 2023
2 parents 591e7dd + 27d15b3 commit 162e080
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/main/java/org/checkerframework/specimin/SpeciminRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> targetFiles = options.valuesOf(targetFilesOption);
List<String> 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<String> targetFiles,
List<String> jarPaths,
List<String> targetMethodNames,
String outputDirectory)
throws IOException {

// Set up the parser's symbol solver, so that we can resolve definitions.
CombinedTypeSolver typeSolver =
Expand Down Expand Up @@ -106,7 +129,6 @@ public static void main(String... args) throws IOException {
parsedTargetFiles.put(targetFile, parseJavaFile(root, targetFile));
}
}
List<String> 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.
Expand Down Expand Up @@ -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<String, CompilationUnit> target : parsedTargetFiles.entrySet()) {
// If a compilation output's entire body has been removed, do not output it.
if (isEmptyCompilationUnit(target.getValue())) {
Expand Down

0 comments on commit 162e080

Please sign in to comment.