@Test public void test1() { String filename = "file"; String rulename = "rule"; String line1 = "foo"; String line2 = "bar"; String message = "warning message"; AnnotatedString as = new AnnotatedString().append(line1).appendNewLine().append(line2).appendNewLine(); int startLine = 1; int startCol = 0; int endLine = 1; int endCol = 2; Position start = new Position(startLine, startCol); Position end = new Position(endLine, endCol); Range range = new Range(start, end); Rule rule = new Rule(rulename) { @Override public List<Advice> evaluate( AnnotatedString s, AnnotatedString original) { return new ArrayList<Advice>(); } @Override public String getDescription() { return ""; } }; ArrayList<Advice> adList = new ArrayList<Advice>(); Advice ad = new Advice(rule, range, message, filename, line2, 0); adList.add(ad); ByteArrayOutputStream baos = new ByteArrayOutputStream(); AnsiPrinter printer = new AnsiPrinter(baos); printer.disableColors(); SinglelineAdviceRenderer renderer = new SinglelineAdviceRenderer(printer); renderer.addAdvice(filename, as, adList); renderer.render(); String output = new String(baos.toByteArray()); assertNotNull(output); String expected = String.format(filename + "(L" + (startLine + 1) + "C" + (startCol + 1) + "-L" + (endLine + 1) + "C" + (endCol + 1) + "): " + message + " \"" + line2 + "\"%n"); assertEquals(expected, output); }
@Override public void render() { for (Map.Entry<String, List<Advice>> entry : m_advice.entrySet()) { String filename = entry.getKey(); List<Advice> list = entry.getValue(); if (!list.isEmpty()) { for (Advice ad : list) { m_printer.setForegroundColor(Color.YELLOW); m_printer.print(filename + "(" + ad.getRange() + ")"); m_printer.resetColors(); m_printer.print(": "); m_printer.print( ad.getMessage().replaceAll("<suggestion>", "").replaceAll("</suggestion", "").trim()); renderExcerpt(ad.getLine(), ad.getRange()); m_printer.println(); } } } }
SinglelineAdviceRenderer extends AdviceRenderer { @Override public void render() { for (Map.Entry<String, List<Advice>> entry : m_advice.entrySet()) { String filename = entry.getKey(); List<Advice> list = entry.getValue(); if (!list.isEmpty()) { for (Advice ad : list) { m_printer.setForegroundColor(Color.YELLOW); m_printer.print(filename + "(" + ad.getRange() + ")"); m_printer.resetColors(); m_printer.print(": "); m_printer.print( ad.getMessage().replaceAll("<suggestion>", "").replaceAll("</suggestion", "").trim()); renderExcerpt(ad.getLine(), ad.getRange()); m_printer.println(); } } } } }
SinglelineAdviceRenderer extends AdviceRenderer { @Override public void render() { for (Map.Entry<String, List<Advice>> entry : m_advice.entrySet()) { String filename = entry.getKey(); List<Advice> list = entry.getValue(); if (!list.isEmpty()) { for (Advice ad : list) { m_printer.setForegroundColor(Color.YELLOW); m_printer.print(filename + "(" + ad.getRange() + ")"); m_printer.resetColors(); m_printer.print(": "); m_printer.print( ad.getMessage().replaceAll("<suggestion>", "").replaceAll("</suggestion", "").trim()); renderExcerpt(ad.getLine(), ad.getRange()); m_printer.println(); } } } } SinglelineAdviceRenderer(AnsiPrinter printer); }
SinglelineAdviceRenderer extends AdviceRenderer { @Override public void render() { for (Map.Entry<String, List<Advice>> entry : m_advice.entrySet()) { String filename = entry.getKey(); List<Advice> list = entry.getValue(); if (!list.isEmpty()) { for (Advice ad : list) { m_printer.setForegroundColor(Color.YELLOW); m_printer.print(filename + "(" + ad.getRange() + ")"); m_printer.resetColors(); m_printer.print(": "); m_printer.print( ad.getMessage().replaceAll("<suggestion>", "").replaceAll("</suggestion", "").trim()); renderExcerpt(ad.getLine(), ad.getRange()); m_printer.println(); } } } } SinglelineAdviceRenderer(AnsiPrinter printer); @Override void render(); }
SinglelineAdviceRenderer extends AdviceRenderer { @Override public void render() { for (Map.Entry<String, List<Advice>> entry : m_advice.entrySet()) { String filename = entry.getKey(); List<Advice> list = entry.getValue(); if (!list.isEmpty()) { for (Advice ad : list) { m_printer.setForegroundColor(Color.YELLOW); m_printer.print(filename + "(" + ad.getRange() + ")"); m_printer.resetColors(); m_printer.print(": "); m_printer.print( ad.getMessage().replaceAll("<suggestion>", "").replaceAll("</suggestion", "").trim()); renderExcerpt(ad.getLine(), ad.getRange()); m_printer.println(); } } } } SinglelineAdviceRenderer(AnsiPrinter printer); @Override void render();  }