-
Notifications
You must be signed in to change notification settings - Fork 0
Description
@Lan-Jingbo We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
No easy-to-detect issues 👍
Aspect: Naming boolean variables/methods
No easy-to-detect issues 👍
Aspect: Brace Style
No easy-to-detect issues 👍
Aspect: Package Name Style
No easy-to-detect issues 👍
Aspect: Class Name Style
No easy-to-detect issues 👍
Aspect: Dead Code
No easy-to-detect issues 👍
Aspect: Method Length
Example from src/main/java/duke/Duke.java lines 128-180:
public void run() {
ui.greet();
while (true) {
String str = ui.requirement();
try {
if (str.startsWith("todo")) {
tasks.addTask(Parser.todo(str));
System.out.println("Now you have " + tasks.getSize() + " task(s)");
} else if (str.startsWith("deadline")) {
tasks.addTask(Parser.deadline(str));
System.out.println("Now you have " + tasks.getSize() + " task(s)");
} else if (str.startsWith("event")) {
tasks.addTask(Parser.event(str));
System.out.println("Now you have " + tasks.getSize() + " task(s)");
} else if (str.startsWith("mark")) {
String[] temp = str.split(" ");
int key = Parser.parseInteger(temp[1]);
mark(key);
} else if (str.startsWith("unmark")) {
String[] temp = str.split(" ");
int key = Parser.parseInteger(temp[1]);
unmark(key);
} else if (str.startsWith("list")) {
showList();
} else if (str.startsWith("bye")) {
System.out.println("Bye! Hope to see you again soon!");
break;
} else if (str.startsWith("delete")) {
delete(str);
} else if (str.startsWith("on")) {
String[] temp = str.split(" ");
String date = temp[1].trim();
LocalDate lc = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
getOnDate(lc);
} else if (str.startsWith("search")) {
search(Parser.convertInfo(str));
} else {
throw new CannotUnderstandException();
}
// Handling exceptions
} catch (WrongMessageException | CannotUnderstandException e) {
System.out.println(e.getMessage());
}
}
try {
storage.saveFile(tasks);
} catch (IOException e) {
System.err.println(e.getMessage());
}
}Example from src/main/java/duke/Main.java lines 27-78:
public void start(Stage stage) throws Exception {
scrollPane = new ScrollPane();
dialogContainer = new VBox();
scrollPane.setContent(dialogContainer);
userInput = new TextField();
sendButton = new Button("Send");
AnchorPane mainLayout = new AnchorPane();
mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);
scene = new Scene(mainLayout);
stage.setScene(scene);
stage.show();
// Step 2
stage.setTitle("DUKE BOT");
stage.setResizable(false);
stage.setMinHeight(600.0);
stage.setMinWidth(400.0);
mainLayout.setPrefSize(400.0, 600.0);
scrollPane.setPrefSize(385, 535);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
scrollPane.setVvalue(1.0);
scrollPane.setFitToWidth(true);
dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);
userInput.setPrefWidth(325.0);
sendButton.setPrefWidth(55.0);
AnchorPane.setTopAnchor(scrollPane, 1.0);
AnchorPane.setBottomAnchor(sendButton, 1.0);
AnchorPane.setRightAnchor(sendButton, 1.0);
AnchorPane.setLeftAnchor(userInput , 1.0);
AnchorPane.setBottomAnchor(userInput, 1.0);
//Step 3
sendButton.setOnMouseClicked((event) -> {
dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
userInput.clear();
});
userInput.setOnAction((event) -> {
dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
userInput.clear();
});
dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
sendButton.setOnMouseClicked((event) -> {
handleUserInput();
});
userInput.setOnAction((event) -> {
handleUserInput();
});
}Example from src/main/java/duke/Storage.java lines 47-82:
public ArrayList<Task> extractFile() throws WrongMessageException {
ArrayList<Task> list = new ArrayList<>();
File file = new File(filePath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (Exception e) {
System.out.println(e.getMessage());
}
} else {
try {
Scanner reader = new Scanner(file);
while (reader.hasNextLine()) {
String temp = reader.nextLine();
if (temp.equals("")) continue;
String[] series = temp.split("\\|");
String type = series[0].trim();
if (type.equals("T")) {
Task task = Todo.fromFileDescription(temp);
list.add(task);
} else if (type.equals("E")) {
Task task = Event.fromFileDescription(temp);
list.add(task);
} else if (type.equals("D")) {
Task task = Event.fromFileDescription(temp);
list.add(task);
} else {
throw new WrongMessageException();
}
}
} catch (IOException e) {
assert false : e.getMessage(); // If the file has errors, stop the program execution.
}
}
return list;
}Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues 👍
Aspect: Header Comments
Example from src/main/java/duke/Deadline.java lines 25-30:
/**
* To check if the task due in input date.
*
* @param localDate the input date
* @return whether it is on the expected date
*/Example from src/main/java/duke/Deadline.java lines 44-49:
/**
* convert the file information to concrete deadline task.
*
* @param input the string format in the .txt file
* @return the concrete deadline
*/Example from src/main/java/duke/Duke.java lines 35-40:
/**
* mark the targeted task to "complete".
*
* @param target the index of task
* @throws WrongMessageException potential exception
*/Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
Aspect: Recent Git Commit Message (Subject Only)
possible problems in commit 1887555:
Added assertions to the code
- Not in imperative mood (?)
possible problems in commit f76e306:
nothing here-2
- Not in imperative mood (?)
possible problems in commit b265ea9:
nothing here
- Not in imperative mood (?)
Suggestion: Follow the given conventions for Git commit messages for future commits (no need to modify past commit messages).
Aspect: Binary files in repo
No easy-to-detect issues 👍
ℹ️ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected] if you want to follow up on this post.