-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Senior-Capstone-2024/longParameters
Code Smell long Parameters Completed Version 1.0
- Loading branch information
Showing
4 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"3":["Improper Capitalized Primitive Type"],"4":["Improper Capitalized Primitive Type"],"12":["Code Smell: Consider refactoring to reduce method length"],"15":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"16":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"17":["Improper Capitalized Primitive Type"],"31":["Code Smell: Consider refactoring to reduce method length"],"50":["Improper Capitalized Primitive Type"]} | ||
{"3":["Improper Capitalized Primitive Type"],"4":["Improper Capitalized Primitive Type"],"12":["Code Smell: Consider refactoring to reduce method length"],"15":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"16":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"17":["Improper Capitalized Primitive Type"],"30":["Code smell found: Long Parameters in method public static int addNumbers (int a, int b, int c, int d){"],"38":["Code Smell: Consider refactoring to reduce method length"],"57":["Improper Capitalized Primitive Type"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export function longParameters(myMap: Map<number, string[]>): Map<number, string[]> { | ||
let editor = vscode.window.activeTextEditor; | ||
if (!editor) { | ||
vscode.window.showErrorMessage('No active text editor.'); | ||
return myMap; // Early return if no editor | ||
} | ||
|
||
let text = editor.document.getText(); | ||
// Updated regex to match Java method declarations with 3 or more parameters and exclude main method and methods with 1 or 2 parameters | ||
let methodRegex = /(\b(?:public|private|protected|static|\s)+[\w<>]+\s+(\w+)\s*\(([^)]+)\)\s*{)/g; | ||
let match; | ||
while ((match = methodRegex.exec(text))) { | ||
let methodName = match[1]; | ||
let parameters = match[3].split(',').map(param => param.trim()); | ||
if (methodName !== 'main' && parameters.length >= 3) { | ||
let lineIndex = editor.document.positionAt(match.index).line; | ||
let errorMessage = `Code smell found: Long Parameters in method ${methodName}`; | ||
if (!myMap.has(lineIndex)) { | ||
myMap.set(lineIndex, [errorMessage]); | ||
} else { | ||
myMap.get(lineIndex)?.push(errorMessage); | ||
} | ||
} | ||
} | ||
|
||
return myMap; | ||
} |