@Test public void test1() { AnnotatedString in_string = AnnotatedString.read(new Scanner(CheckStackedHeadingsTest.class.getResourceAsStream("data/test-stacked-1.tex"))); CheckStackedHeadings r = new CheckStackedHeadings(); List<Advice> ad_list = r.evaluate(in_string, in_string); assertEquals(1, ad_list.size()); Advice ad = ad_list.get(0); assertEquals(4, ad.getRange().getStart().getLine()); }
@Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); List<String> lines = s.getLines(); boolean found_text = true; for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_headingPattern.matcher(line); if (mat.find()) { if (!found_text) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1))); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1) + mat.group(1).length())); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(CheckStackedHeadingsAdvice.instance, r, "Avoid stacked headings, i.e. consecutive headings without text in between.", original.getResourceName(), original.getLine(r.getStart().getLine()), original.getOffset(start_pos))); } found_text = false; } else if (!line.trim().isEmpty()) { found_text = true; } } return out_list; }
CheckStackedHeadings extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); List<String> lines = s.getLines(); boolean found_text = true; for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_headingPattern.matcher(line); if (mat.find()) { if (!found_text) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1))); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1) + mat.group(1).length())); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(CheckStackedHeadingsAdvice.instance, r, "Avoid stacked headings, i.e. consecutive headings without text in between.", original.getResourceName(), original.getLine(r.getStart().getLine()), original.getOffset(start_pos))); } found_text = false; } else if (!line.trim().isEmpty()) { found_text = true; } } return out_list; } }
CheckStackedHeadings extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); List<String> lines = s.getLines(); boolean found_text = true; for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_headingPattern.matcher(line); if (mat.find()) { if (!found_text) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1))); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1) + mat.group(1).length())); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(CheckStackedHeadingsAdvice.instance, r, "Avoid stacked headings, i.e. consecutive headings without text in between.", original.getResourceName(), original.getLine(r.getStart().getLine()), original.getOffset(start_pos))); } found_text = false; } else if (!line.trim().isEmpty()) { found_text = true; } } return out_list; } CheckStackedHeadings(); }
CheckStackedHeadings extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); List<String> lines = s.getLines(); boolean found_text = true; for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_headingPattern.matcher(line); if (mat.find()) { if (!found_text) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1))); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1) + mat.group(1).length())); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(CheckStackedHeadingsAdvice.instance, r, "Avoid stacked headings, i.e. consecutive headings without text in between.", original.getResourceName(), original.getLine(r.getStart().getLine()), original.getOffset(start_pos))); } found_text = false; } else if (!line.trim().isEmpty()) { found_text = true; } } return out_list; } CheckStackedHeadings(); @Override List<Advice> evaluate(AnnotatedString s, AnnotatedString original); @Override String getDescription(); }
CheckStackedHeadings extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); List<String> lines = s.getLines(); boolean found_text = true; for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_headingPattern.matcher(line); if (mat.find()) { if (!found_text) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1))); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start(1) + mat.group(1).length())); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(CheckStackedHeadingsAdvice.instance, r, "Avoid stacked headings, i.e. consecutive headings without text in between.", original.getResourceName(), original.getLine(r.getStart().getLine()), original.getOffset(start_pos))); } found_text = false; } else if (!line.trim().isEmpty()) { found_text = true; } } return out_list; } CheckStackedHeadings(); @Override List<Advice> evaluate(AnnotatedString s, AnnotatedString original); @Override String getDescription();  }