@Test public void test2() { AnnotatedString in_string = AnnotatedString.read(new Scanner("\\cite{foo}\n" + "\\citep{bar}\n" + "\\citet{baz}")); Rule r = new CheckCiteMix(); List<Advice> ad_list = r.evaluate(in_string, in_string); assertEquals(1, ad_list.size()); }
@Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); boolean found_citep = false, found_cite = false; List<String> lines = s.getLines(); for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_citePattern.matcher(line); if (mat.find()) { found_cite = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 6)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } mat = m_citepPattern.matcher(line); if (mat.find()) { found_citep = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 7)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } } return out_list; }
CheckCiteMix extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); boolean found_citep = false, found_cite = false; List<String> lines = s.getLines(); for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_citePattern.matcher(line); if (mat.find()) { found_cite = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 6)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } mat = m_citepPattern.matcher(line); if (mat.find()) { found_citep = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 7)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } } return out_list; } }
CheckCiteMix extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); boolean found_citep = false, found_cite = false; List<String> lines = s.getLines(); for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_citePattern.matcher(line); if (mat.find()) { found_cite = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 6)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } mat = m_citepPattern.matcher(line); if (mat.find()) { found_citep = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 7)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } } return out_list; } CheckCiteMix(); }
CheckCiteMix extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); boolean found_citep = false, found_cite = false; List<String> lines = s.getLines(); for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_citePattern.matcher(line); if (mat.find()) { found_cite = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 6)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } mat = m_citepPattern.matcher(line); if (mat.find()) { found_citep = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 7)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } } return out_list; } CheckCiteMix(); @Override List<Advice> evaluate(AnnotatedString s, AnnotatedString original); @Override String getDescription(); }
CheckCiteMix extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); boolean found_citep = false, found_cite = false; List<String> lines = s.getLines(); for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_citePattern.matcher(line); if (mat.find()) { found_cite = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 6)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } mat = m_citepPattern.matcher(line); if (mat.find()) { found_citep = true; if (found_citep && found_cite) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start())); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start() + 7)); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not mix \\cite with \\citep or \\citet in the same document.", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); break; } } } return out_list; } CheckCiteMix(); @Override List<Advice> evaluate(AnnotatedString s, AnnotatedString original); @Override String getDescription();  }