This repository has been archived on 2026-03-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
CSE-122/linter/BreakCheck.java
2026-03-18 00:39:22 -07:00

24 lines
731 B
Java

// Nik Johnson
// 2-24-2024
// TA: Andy Ruan
import java.util.*;
// checks Strings for the characters "break" that come BEFORE the characters "//"
public class BreakCheck implements Check {
// if the line being checked has "break" in it
// after removing all single line comments, return a new error (code 2)
// takes line and line number
// returns error inside optional
public Optional<Error> lint(String line, int lineNumber) {
String input = line;
String output = input.replaceAll("//.*", "");
if (output.contains("break")) {
return Optional.of(new Error(2, lineNumber, "we cant use break in this class bro"));
}
return Optional.empty();
}
}