From c89c687bc09da4d1acef2591545fc406cbb1e7c5 Mon Sep 17 00:00:00 2001 From: Jan-Thurner <107639007+Jan-Thurner@users.noreply.github.com> Date: Thu, 15 Aug 2024 11:52:57 +0200 Subject: [PATCH] coderabbit --- .../endpointanalysis/EndpointAnalyzer.java | 21 ++++++++------- .../endpointanalysis/RestCallAnalyzer.java | 20 +++++++------- .../AnalysisOfEndpointConnectionsClient.ts | 26 ++++++++++++------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/supporting_scripts/analysis-of-endpoint-connections/src/main/java/de/tum/cit/endpointanalysis/EndpointAnalyzer.java b/supporting_scripts/analysis-of-endpoint-connections/src/main/java/de/tum/cit/endpointanalysis/EndpointAnalyzer.java index 8a3218ce84d8..32867618e02c 100644 --- a/supporting_scripts/analysis-of-endpoint-connections/src/main/java/de/tum/cit/endpointanalysis/EndpointAnalyzer.java +++ b/supporting_scripts/analysis-of-endpoint-connections/src/main/java/de/tum/cit/endpointanalysis/EndpointAnalyzer.java @@ -94,18 +94,19 @@ private static void printEndpointAnalysisResult() { }); } catch (IOException e) { - throw new RuntimeException(e); + logger.error("Failed to deserialize endpoint analysis result", e); } + endpointsAndMatchingRestCalls.getUnusedEndpoints().stream().forEach(endpoint -> { - System.out.println("============================================="); - System.out.println("Endpoint URI: " + endpoint.buildCompleteEndpointURI()); - System.out.println("HTTP method: " + endpoint.getHttpMethodAnnotation()); - System.out.println("File path: " + endpoint.getClassName()); - System.out.println("Line: " + endpoint.getLine()); - System.out.println("============================================="); - System.out.println("No matching REST call found for endpoint: " + endpoint.buildCompleteEndpointURI()); - System.out.println("---------------------------------------------"); - System.out.println(); + logger.info("============================================="); + logger.info("Endpoint URI: {}", endpoint.buildCompleteEndpointURI()); + logger.info("HTTP method: {}", endpoint.getHttpMethodAnnotation()); + logger.info("File path: {}", endpoint.getClassName()); + logger.info("Line: {}", endpoint.getLine()); + logger.info("============================================="); + logger.info("No matching REST call found for endpoint: {}", endpoint.buildCompleteEndpointURI()); + logger.info("---------------------------------------------"); + logger.info(""); }); } } diff --git a/supporting_scripts/analysis-of-endpoint-connections/src/main/java/de/tum/cit/endpointanalysis/RestCallAnalyzer.java b/supporting_scripts/analysis-of-endpoint-connections/src/main/java/de/tum/cit/endpointanalysis/RestCallAnalyzer.java index 4609274b361d..dd41c2199489 100644 --- a/supporting_scripts/analysis-of-endpoint-connections/src/main/java/de/tum/cit/endpointanalysis/RestCallAnalyzer.java +++ b/supporting_scripts/analysis-of-endpoint-connections/src/main/java/de/tum/cit/endpointanalysis/RestCallAnalyzer.java @@ -100,17 +100,17 @@ private static void printRestCallAnalysisResult() { } restCallsAndMatchingEndpoints.getRestCallsWithoutMatchingEndpoints().stream().forEach(endpoint -> { - System.out.println("============================================="); - System.out.println("REST call URI: " + endpoint.buildCompleteRestCallURI()); - System.out.println("HTTP method: " + endpoint.getMethod()); - System.out.println("File path: " + endpoint.getFileName()); - System.out.println("Line: " + endpoint.getLine()); - System.out.println("============================================="); - System.out.println("No matching endpoint found for REST call: " + endpoint.buildCompleteRestCallURI()); - System.out.println("---------------------------------------------"); - System.out.println(); + logger.info("============================================="); + logger.info("REST call URI: {}", endpoint.buildCompleteRestCallURI()); + logger.info("HTTP method: {}", endpoint.getMethod()); + logger.info("File path: {}", endpoint.getFileName()); + logger.info("Line: {}", endpoint.getLine()); + logger.info("============================================="); + logger.info("No matching endpoint found for REST call: {}", endpoint.buildCompleteRestCallURI()); + logger.info("---------------------------------------------"); + logger.info(""); }); - System.out.println("Number of REST calls without matching endpoints: " + restCallsAndMatchingEndpoints.getRestCallsWithoutMatchingEndpoints().size()); + logger.info("Number of REST calls without matching endpoints: {}", restCallsAndMatchingEndpoints.getRestCallsWithoutMatchingEndpoints().size()); } } diff --git a/supporting_scripts/analysis-of-endpoint-connections/src/main/typeScript/AnalysisOfEndpointConnectionsClient.ts b/supporting_scripts/analysis-of-endpoint-connections/src/main/typeScript/AnalysisOfEndpointConnectionsClient.ts index 5e1051c95a9c..f375fd06fe51 100644 --- a/supporting_scripts/analysis-of-endpoint-connections/src/main/typeScript/AnalysisOfEndpointConnectionsClient.ts +++ b/supporting_scripts/analysis-of-endpoint-connections/src/main/typeScript/AnalysisOfEndpointConnectionsClient.ts @@ -33,15 +33,20 @@ function collectTypeScriptFiles(dir: string, files: string[] = []) : string[] { * @param filePath - The path to the TypeScript file to be parsed. * @returns The TSESTree of the parsed TypeScript file. */ -function parseTypeScriptFile(filePath: string): TSESTree.Program { +function parseTypeScriptFile(filePath: string): TSESTree.Program | null { const code = readFileSync(filePath, 'utf8'); - return parse(code, { - loc: true, - comment: true, - tokens: true, - ecmaVersion: 2020, - sourceType: 'module', - }); + try { + return parse(code, { + loc: true, + comment: true, + tokens: true, + ecmaVersion: 2020, + sourceType: 'module', + }); + } catch (error) { + console.error(`Failed to parse TypeScript file at ${filePath}:`, error); + return null; + } } const clientDirPath = resolve('src/main/webapp/app'); @@ -51,7 +56,10 @@ const tsFiles = collectTypeScriptFiles(clientDirPath); // create and store Syntax Tree for each file const astMap = new Map; tsFiles.forEach((filePath) => { - astMap.set(filePath, parseTypeScriptFile(filePath)); + const ast = parseTypeScriptFile(filePath); + if (ast) { + astMap.set(filePath, ast); + } }); // preprocess each file