From cbd1b9c7ba0b3ee27e07fa5d8c6086eba41fa66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1zaro=20Clapp=20Jim=C3=A9nez=20Labora?= Date: Mon, 25 Jul 2016 08:59:22 -0700 Subject: [PATCH] Refactor common code on multiple methods of InferRestults Reviewed By: sblackshear Differential Revision: D3611216 fbshipit-source-id: 28ebd23 --- infer/tests/utils/InferResults.java | 86 +++++++++++++---------------- 1 file changed, 37 insertions(+), 49 deletions(-) diff --git a/infer/tests/utils/InferResults.java b/infer/tests/utils/InferResults.java index 9cc07be2f..2912484cd 100644 --- a/infer/tests/utils/InferResults.java +++ b/infer/tests/utils/InferResults.java @@ -154,76 +154,64 @@ public class InferResults { return inferResults; } - public static InferResults loadInferResults(Class currentClass, String sourceFile) { + private static InferResults loadResultsFromPath(Class currentClass, String sourceFile, + String csvPath, Pattern procnamePattern) { BufferedReader reader = new BufferedReader( new InputStreamReader( - currentClass.getResourceAsStream( - "/infer/tests/codetoanalyze/java/infer/report.csv"))); + currentClass.getResourceAsStream(csvPath))); return loadResultsFromReader( Preconditions.checkNotNull(reader), sourceFile, - InferResults.JAVA_METHOD_NAME); + procnamePattern); + } + + public static InferResults loadInferResults(Class currentClass, String sourceFile) { + return loadResultsFromPath( + currentClass, + sourceFile, + "/infer/tests/codetoanalyze/java/infer/report.csv", + InferResults.JAVA_METHOD_NAME); } public static InferResults loadEradicateResults(Class currentClass, String sourceFile) { - BufferedReader reader = - new BufferedReader( - new InputStreamReader( - currentClass.getResourceAsStream( - "/infer/tests/codetoanalyze/java/eradicate/report.csv"))); - return loadResultsFromReader( - Preconditions.checkNotNull(reader), - sourceFile, - InferResults.JAVA_METHOD_NAME); + return loadResultsFromPath( + currentClass, + sourceFile, + "/infer/tests/codetoanalyze/java/eradicate/report.csv", + InferResults.JAVA_METHOD_NAME); } public static InferResults loadCheckersResults(Class currentClass, String sourceFile) { - BufferedReader reader = - new BufferedReader( - new InputStreamReader( - currentClass.getResourceAsStream( - "/infer/tests/codetoanalyze/java/checkers/report.csv"))); - return loadResultsFromReader( - Preconditions.checkNotNull(reader), - sourceFile, - InferResults.JAVA_METHOD_NAME); + return loadResultsFromPath( + currentClass, + sourceFile, + "/infer/tests/codetoanalyze/java/checkers/report.csv", + InferResults.JAVA_METHOD_NAME); } public static InferResults loadTracingResults(Class currentClass, String sourceFile) { - BufferedReader reader = - new BufferedReader( - new InputStreamReader( - currentClass.getResourceAsStream( - "/infer/tests/codetoanalyze/java/tracing/report.csv"))); - return loadResultsFromReader( - Preconditions.checkNotNull(reader), - sourceFile, - InferResults.JAVA_METHOD_NAME); + return loadResultsFromPath( + currentClass, + sourceFile, + "/infer/tests/codetoanalyze/java/tracing/report.csv", + InferResults.JAVA_METHOD_NAME); } public static InferResults loadTracingComparisonResults(Class currentClass, String sourceFile) { - BufferedReader reader = - new BufferedReader( - new InputStreamReader( - currentClass.getResourceAsStream( - "/infer/tests/codetoanalyze/java/infer/comparison_report.csv"))); - return loadResultsFromReader( - Preconditions.checkNotNull(reader), - sourceFile, - InferResults.JAVA_METHOD_NAME); + return loadResultsFromPath( + currentClass, + sourceFile, + "/infer/tests/codetoanalyze/java/infer/comparison_report.csv", + InferResults.JAVA_METHOD_NAME); } public static InferResults loadCInferResults(Class currentClass, String sourceFile) { - BufferedReader reader = - new BufferedReader( - new InputStreamReader( - currentClass.getResourceAsStream( - "/infer/tests/codetoanalyze/c/errors/report.csv"))); - return loadResultsFromReader( - Preconditions.checkNotNull(reader), - sourceFile, - InferResults.C_FUNCTION_NAME); + return loadResultsFromPath( + currentClass, + sourceFile, + "/infer/tests/codetoanalyze/c/errors/report.csv", + InferResults.C_FUNCTION_NAME); } }