Skip to content

Commit

Permalink
Merge pull request #18 from Senior-Capstone-2024/methodName2.0
Browse files Browse the repository at this point in the history
Added line error to single datastructure, highlighting partially broken
  • Loading branch information
aravindrsripada authored May 6, 2024
2 parents 4228ce9 + c4f12c5 commit b505dd0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion output/data.json
Original file line number Diff line number Diff line change
@@ -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"]}
{"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"]}
12 changes: 7 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ import { findCapitalizedMethodName } from './findCapitalizedMethodName';
import { singleStatementPerLineChecker } from './singleStatementPerLineChecker';
import { findAllErrors } from './findAllErrors';
import { convertMapToJson } from './convertMapToJson';
import { findDuplicateCode } from './findDuplicateCode';


const myMap: Map<number, string[]> = 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', () => {
findCapitalizedPrimitiveTypes(myMap);
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);
Expand Down
2 changes: 1 addition & 1 deletion src/findAllErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { singleStatementPerLineChecker } from "./singleStatementPerLineChecker";

// Call all methods
export function findAllErrors() {
findCapitalizedMethodName();
// findCapitalizedMethodName();
// findCapitalizedPrimitiveTypes();
findLowercaseClassOrInterface();
singleStatementPerLineChecker();
Expand Down
16 changes: 10 additions & 6 deletions src/findCapitalizedMethodName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';

export function findCapitalizedMethodName() {
export function findCapitalizedMethodName(myMap: Map<number, string[]>): Map<number, string[]> {
// activeTextEditor allows access to text inside the opened document.
const editor = vscode.window.activeTextEditor;
if (editor) {
Expand All @@ -11,20 +11,24 @@ 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);
const range = new vscode.Range(methodStartPosition, methodEndPosition);
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({
Expand Down

0 comments on commit b505dd0

Please sign in to comment.