diff --git a/output/data.json b/output/data.json index f290a90..7886452 100644 --- a/output/data.json +++ b/output/data.json @@ -1 +1 @@ -{"4":["Improper Capitalized Primitive Type"],"5":["Improper Capitalized Primitive Type"],"6":["Improper Capitalized Primitive Type"],"7":["Improper Capitalized Primitive Type"],"12":["Improper Capitalized Primitive Type"]} \ No newline at end of file +{"3":["Improper Capitalized Primitive Type"],"4":["Improper Capitalized Primitive Type"],"11":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"12":["Improper Capitalized Primitive Type","Improper Capitalized Primitive Type"],"13":["Improper Capitalized Primitive Type"],"24":["Improper Method Name"],"28":["Improper Method Name","Improper Capitalized Primitive Type"]} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index a36350c..7f35293 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,11 +8,10 @@ import { findCapitalizedMethodName } from './findCapitalizedMethodName'; import { singleStatementPerLineChecker } from './singleStatementPerLineChecker'; import { findAllErrors } from './findAllErrors'; import { convertMapToJson } from './convertMapToJson'; -import { findDuplicateCode } from './findDuplicateCode'; - const myMap: Map = new Map(); -const filePath = "/Users/willscomputer/Desktop/abc/gradeFast-1.0/output/data.json"; +const filePath = 'C:\\Users\\Will\\Desktop\\cw\\gradeFast-1.0\\output\\data.json'; + export function activate(context: vscode.ExtensionContext) { const disposable = vscode.commands.registerCommand('extension.findCapitalizedPrimitiveTypes', () => { @@ -20,11 +19,14 @@ export function activate(context: vscode.ExtensionContext) { convertMapToJson(myMap, filePath); }); + const disposable2 = vscode.commands.registerCommand('extension.findCapitalizedMethodName', () => { + findCapitalizedMethodName(myMap); + } ); + + const disposable1 = vscode.commands.registerCommand('extension.findLowercaseClassOrInterface', findLowercaseClassOrInterface); - const disposable2 = vscode.commands.registerCommand('extension.findCapitalizedMethodName', findCapitalizedMethodName); const disposable3 = vscode.commands.registerCommand('extension.singleStatementPerLineChecker', singleStatementPerLineChecker); const disposable0 = vscode.commands.registerCommand('extension.findAllErrors', findAllErrors); - const disposable4 = vscode.commands.registerCommand('extension.findDuplicateCode', findDuplicateCode); const commentController = vscode.comments.createCommentController('comment-sample', 'Comment API Sample'); context.subscriptions.push(commentController); diff --git a/src/findAllErrors.ts b/src/findAllErrors.ts index dd0ef83..51a7880 100644 --- a/src/findAllErrors.ts +++ b/src/findAllErrors.ts @@ -11,7 +11,7 @@ import { singleStatementPerLineChecker } from "./singleStatementPerLineChecker"; // Call all methods export function findAllErrors() { - findCapitalizedMethodName(); + // findCapitalizedMethodName(); // findCapitalizedPrimitiveTypes(); findLowercaseClassOrInterface(); singleStatementPerLineChecker(); diff --git a/src/findCapitalizedMethodName.ts b/src/findCapitalizedMethodName.ts index 38dd8af..c184704 100644 --- a/src/findCapitalizedMethodName.ts +++ b/src/findCapitalizedMethodName.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; -export function findCapitalizedMethodName() { +export function findCapitalizedMethodName(myMap: Map): Map { // activeTextEditor allows access to text inside the opened document. const editor = vscode.window.activeTextEditor; if (editor) { @@ -11,6 +11,7 @@ export function findCapitalizedMethodName() { const improperMethodNames = []; while ((match = javaMethodRegex.exec(text))) { const methodName = match[1]; + const lineNumber = document.positionAt(match.index).line + 1; // Get the line number if (!isValidMethodName(methodName)) { const methodStartPosition = document.positionAt(match.index); const methodEndPosition = document.positionAt(match.index + methodName.length); @@ -18,13 +19,16 @@ export function findCapitalizedMethodName() { improperMethodNames.push(range); vscode.window.showInformationMessage('Java Method Name Convention Mistake!! Highlighted in RED'); } - } - if (improperMethodNames.length > 0) { - editor.setDecorations(improperMethodNameDecorationType, improperMethodNames); - } else { - vscode.window.showInformationMessage('All Java method names follow proper conventions!'); + if (!myMap.has(lineNumber)) { + myMap.set(lineNumber, []); + } + const errorMessage = "Improper Method Name"; + const currentErrors = myMap.get(lineNumber) || []; + currentErrors.push(errorMessage); + myMap.set(lineNumber, currentErrors); } } + return myMap; } const improperMethodNameDecorationType = vscode.window.createTextEditorDecorationType({