Skip to content

Commit

Permalink
Add instruction to use Main class in ug, improve user feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
limhawjia committed Nov 10, 2019
1 parent cbd6ad3 commit 39ff6d5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ The help page is where you can get a quick summary of all of the features and co

[[BeforeStart]]
== Before you start
. The programe evaluator searches for a class with the class name `Main` as the entry point into your program. Please ensure
that you declare your *main method* in a class called `Main`.

. The program evaluator uses *stdin* to feed your program inputs and *stdout* to receive your program's outputs. Thus,
it is important that your program uses the `Scanner` class to read inputs and for you to print your results.
Expand Down
2 changes: 1 addition & 1 deletion docs/diagrams/NoteSavingSequence.puml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ NotesLogicManager -> UI: getNoteAndSketchPair()
UI -> NotesLogicManager: Note and Sketch
NotesLogicManager -> NoteBankStorage: Modify and Save new note
NotesLogicManager -> Sketch: saveSketch(sketchId, sketch)
@enduml
@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public CommandResult execute() throws CommandException {
resultsOptional = this.programSubmissionLogic.submitUserProgram(userProgram);
} catch (IncorrectCanonicalNameException e) {
logger.warning("Main class not detected, command will not be executed");
throw new CommandException("Main class needed as entry point.");
throw new CommandException("Please write your main method in a class called Main");
} catch (EmptyUserProgramException e) {
logger.warning("Program is empty, command will not be executed");
throw new CommandException("Program must not be empty.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ private static boolean checkContainsMatchingClass(String canonicalName, String p
String[] canonicalNameSplit = canonicalName.split("\\.");
String className = canonicalNameSplit[canonicalNameSplit.length - 1];

// Remove any class declarations that could be in comments
String programRemoveComments = program
.replaceAll("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)", "");

// Split the program by class declaration with the required class name
String[] programSplit = programRemoveComments.split("class " + className);

if (programSplit.length == 1) {
// Class declaration not found
return false;
}

// For each occurrence of the class declaration, check to see if it is an outermost class declaration by
// matching the number of opening/closing braces
for (int i = 1; i < programSplit.length; i++) {
Stack<Character> braceStack = new Stack<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class SubmitCommandTest {
// Check that an exception is thrown if no appropriate class name is found
UserProgram invalidClassNameSubmission = new UserProgram("Main", "public class Test {}");
submissionLogic.setUserProgramSubmissionChannel(() -> invalidClassNameSubmission);
assertThrows(CommandException.class, "Main class needed as entry point.", command::execute);
assertThrows(CommandException.class, "Please write your main method in a class called Main",
command::execute);

// Check that questionsLogic has changed accordingly
List<Question> expected = TypicalQuestions.getTypicalQuestions();
Expand Down

0 comments on commit 39ff6d5

Please sign in to comment.