DartAnalyzerReportParser { public List<DartAnalyzerReportIssue> parse(String input) { List<DartAnalyzerReportIssue> issues = new ArrayList<>(); String[] lines = input.split(System.getProperty("line.separator")); Pattern pattern = Pattern.compile("(error|hint|lint)(.*)(-|•)(.*)(-|•)(.*):(.*):(.*)(-|•)(.*)"); for (int i = 0; i < lines.length; i++) { Matcher matcher = pattern.matcher(lines[i]); while (matcher.find()) { String filePath = matcher.group(6).trim(); int lineNum = Integer.parseInt(matcher.group(7).trim()); String message = matcher.group(4).trim(); String ruleId = matcher.group(10).trim(); issues.add(new DartAnalyzerReportIssue(ruleId, message, filePath, lineNum)); } } return issues; }  List<DartAnalyzerReportIssue> parse(String input);  }
@Test public void parseWithCircles() { String input = " lint • Close instances of `dart.core.Sink`. • lib/main.dart:63:9 • close_sinks\n" + " hint • The value of the local variable '_controller' isn't used. • lib/main.dart:63:9 • unused_local_variable"; List<DartAnalyzerReportIssue> issues = parser.parse(input); assertThat(issues.size()).isEqualTo(2); assertFilePath(issues.get(0), FILE_PATH); assertLineNumber(issues.get(0), 63); assertRuleId(issues.get(0), "close_sinks"); assertMessage(issues.get(0), "Close instances of `dart.core.Sink`."); assertFilePath(issues.get(1), FILE_PATH); assertLineNumber(issues.get(1), 63); assertRuleId(issues.get(1), RULE_ID_UNUSED_LOCAL_VARIABLE); assertMessage(issues.get(1), "The value of the local variable '_controller' isn't used."); }
@Test public void parseWithTraces() { String input = "Analyzing D:\\workspace\\samples-master\\platform_design\\lib\\main.dart, D:\\workspace\\samples-master\\platform_design\\lib\\utils.dart, D:\\workspace\\samples-master\\platform_design\\lib\\songs_tab.dart, D:\\workspace\\samples-master\\platform_design\\lib\\news_tab.dart, D:\\workspace\\samples-master\\platform_design\\lib\\song_detail_tab.dart...\r\n" + " error - Target of URI doesn't exist: 'package:flutter/material.dart'. - lib/main.dart:1:8 - uri_does_not_exist\r\n" + " hint - The value of the local variable 'a' isn't used. - lib/main.dart:7:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'b' isn't used. - lib/main.dart:8:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'c' isn't used. - lib/main.dart:9:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'd' isn't used. - lib/main.dart:10:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'e' isn't used. - lib/main.dart:11:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'f' isn't used. - lib/main.dart:12:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'g' isn't used. - lib/main.dart:13:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'h' isn't used. - lib/main.dart:14:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'i' isn't used. - lib/main.dart:15:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'j' isn't used. - lib/main.dart:16:7 - unused_local_variable\r\n" + " hint - The value of the local variable 'k' isn't used. - lib/main.dart:17:7 - unused_local_variable\r\n" + "1 errors and 11 hints found."; List<DartAnalyzerReportIssue> issues = parser.parse(input); assertThat(issues.size()).isEqualTo(12); assertFilePath(issues.get(0), FILE_PATH); assertLineNumber(issues.get(0), 1); assertRuleId(issues.get(0), "uri_does_not_exist"); assertMessage(issues.get(0), "Target of URI doesn't exist: 'package:flutter/material.dart'."); assertFilePath(issues.get(10), FILE_PATH); assertLineNumber(issues.get(10), 16); assertRuleId(issues.get(10), RULE_ID_UNUSED_LOCAL_VARIABLE); assertMessage(issues.get(10), "The value of the local variable 'j' isn't used."); }