if (null == output) {
LOGGER.warn("Parser result was null");
return null;
}
final AstResult astResult = new AstResult();
final List<SourceAnnotation> warnings = new ArrayList<SourceAnnotation>();
// TODO should this use the LINE_SEPARATOR_UNIX instead of the system separator?
for (String line : StringUtils.split(output, IOUtils.LINE_SEPARATOR)) {
line = line.trim();
if (0 == line.length()) {
continue;
}
LOGGER.trace("Attempt to parse result line: {}", line);
if (RESULT_OK.equals(line)) {
astResult.setError(new SourceAnnotation(AstResult.ErrorCode.NoError.getErrorCode(), null, null));
} else if (line.startsWith(RESULT_ERROR)) {
line = line.substring(RESULT_ERROR.length() + 1).trim();
astResult.setError(getSourceAnnotation(line));
} else if (line.startsWith(RESULT_WARNING)) {
line = line.substring(RESULT_WARNING.length() + 1).trim();
warnings.add(getSourceAnnotation(line));
} else {
LOGGER.warn("Result line did not match any expected format: {}" + line);
}
}
astResult.setWarnings(warnings.toArray(new SourceAnnotation[warnings.size()]));
return astResult;
}