package pingis.utils;

import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseResult;
import com.github.javaparser.ParseStart;
import com.github.javaparser.Providers;
import com.github.javaparser.ast.CompilationUnit;
import org.apache.commons.lang3.ArrayUtils;

/**
 * Helper class for checking the syntax of Java code. Created by dwarfcrank on 7/21/17.
 */
public class JavaSyntaxChecker {

  /**
   * Parses the code to check its syntax.
   *
   * @param code Code to parse. Expects a whole Java compilation unit (i.e. package
   * declarations/imports, class definitions, etc.).
   * @return Array of strings describing the encountered parse errors, or null if the syntax is
   * correct.
   */
  public static String[] parseCode(String code) {
    ParseResult<CompilationUnit> parseResult = new JavaParser().parse(ParseStart.COMPILATION_UNIT,
        Providers.provider(code));

    if (parseResult.isSuccessful()) {
      return null;
    }

    return parseResult.getProblems().stream().map((prob) ->
        prob.getVerboseMessage()
    ).toArray(String[]::new);
  }

  public static String[] checkTaskPairErrors(String submissionCode, String staticCode) {
    String[] submissionSyntaxErrors = parseCode(submissionCode);
    String[] staticSyntaxErrors = parseCode(staticCode);
    if (submissionSyntaxErrors != null || staticSyntaxErrors != null) {
      String[] errors = ArrayUtils.addAll(submissionSyntaxErrors, staticSyntaxErrors);
      return errors;
    }
    return null;
  }
}

@@ -174,66 +174,229 @@
 er.P
-roviders;%0Aimport com.github.javaparser.ast.CompilationUnit
+osition;%0Aimport com.github.javaparser.Problem;%0Aimport com.github.javaparser.Providers;%0Aimport com.github.javaparser.ast.CompilationUnit;%0Aimport java.util.List;%0Aimport java.util.Optional;%0Aimport java.util.stream.Collectors
 ;%0Aim
@@ -1251,16 +1251,855 @@
 );%0A  %7D%0A%0A
+  private static SyntaxError convertProblem(Problem problem) %7B%0A    Position faultyToken = problem.getLocation().get().getBegin().getRange().begin;%0A%0A    // Ace editor expects line numbers to be zero-based while JavaParser starts from 1.%0A    int row = faultyToken.line - 1;%0A    int column = faultyToken.column;%0A    String text = problem.getMessage();%0A%0A    return new SyntaxError(row, column, text);%0A  %7D%0A%0A  public static Optional%3CList%3CSyntaxError%3E%3E getSyntaxErrors(String code) %7B%0A    ParseResult%3CCompilationUnit%3E parseResult = new JavaParser().parse(ParseStart.COMPILATION_UNIT,%0A        Providers.provider(code));%0A%0A    if (parseResult.isSuccessful()) %7B%0A      return Optional.empty();%0A    %7D%0A%0A    return Optional.of(parseResult.getProblems().stream()%0A        .map(JavaSyntaxChecker::convertProblem)%0A        .collect(Collectors.toList()));%0A  %7D%0A%0A
   public

Implement JavaSyntaxChecker::getSyntaxErrors.