/** * {@inheritDoc} */ @Override public ParseResult parse(RSyntaxDocument doc, String style) { result.clearNotices(); Element root = doc.getDefaultRootElement(); result.setParsedLines(0, root.getElementCount()-1); if (spf==null || doc.getLength()==0) { return result; } try { SAXParser sp = spf.newSAXParser(); Handler handler = new Handler(doc); DocumentReader r = new DocumentReader(doc); InputSource input = new InputSource(r); sp.parse(input, handler); r.close(); } catch (SAXParseException spe) { // A fatal parse error - ignore; a ParserNotice was already created. } catch (Exception e) { //e.printStackTrace(); // Will print if DTD specified and can't be found result.addNotice(new DefaultParserNotice(this, "Error parsing XML: " + e.getMessage(), 0, -1, -1)); } return result; }
throw new BadLocationException("Invalid document position", p0); else if (p1>doc.getLength()) { throw new BadLocationException("Invalid document position", p1);
if (offs==doc.getLength()) { return offs;
@Test public void testFireDocumentEvent_InsertWithTwoNewLines() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); insertHelloWorldC(doc); TestDocumentListener l = new TestDocumentListener(); doc.addDocumentListener(l); // Two events sent - one "change" event containing line range AFTER // insert repaint, second one is actual "insert" event. int oldLen = doc.getLength(); String text = "// Inserted line 1\nprintf(\"This is working\n\");"; doc.insertString(oldLen - 4, text, null); Assert.assertEquals(2, l.events.size()); DocumentEvent e = l.events.get(0); // offset and length == start and end lines AFTER insert with new EOL tokens // In this case a new line was "added" by this change. assertDocumentEvent(e, DocumentEvent.EventType.CHANGE, 8, 8); e = l.events.get(1); assertDocumentEvent(e, DocumentEvent.EventType.INSERT, oldLen - 4, text.length()); }
@Test public void testFireDocumentEvent_InsertWithTwoNewLinesOneReplaced() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); insertHelloWorldC(doc); TestDocumentListener l = new TestDocumentListener(); doc.addDocumentListener(l); int oldLen = doc.getLength(); String text = "// Inserted line 1\nprintf(\"This is working\n\");"; doc.replace(oldLen - 4, 1, text, null); // Four events sent - One change/remove pair and one change/insert // pair. Remove is the one line replaced. Assert.assertEquals(4, l.events.size()); DocumentEvent e = l.events.get(0); // offset and length == start and end lines AFTER remove with new EOL // tokens. In this case a new line was "added" by this change. assertDocumentEvent(e, DocumentEvent.EventType.CHANGE, 6, 6); e = l.events.get(1); assertDocumentEvent(e, DocumentEvent.EventType.REMOVE, oldLen - 4, 1); e = l.events.get(2); // offset and length == start and end lines AFTER insert with new EOL // tokens. In this case a new line was "added" by this change. assertDocumentEvent(e, DocumentEvent.EventType.CHANGE, 8, 8); e = l.events.get(3); assertDocumentEvent(e, DocumentEvent.EventType.INSERT, oldLen - 4, text.length()); }
/** * Verifies that using an {@link RSyntaxDocument}'s iterator returns the * same set of tokens as manually getting the token list for each line. */ @Test public void testBasicIteration() throws Exception { RSyntaxDocument doc = null; // A well-formed Java document. doc = loadResource("TokenIteratorTest_JavaBasic.txt", SyntaxConstants.SYNTAX_STYLE_JAVA); assertIteratorMatchesList(doc); // An unterminated Javadoc comment. doc = loadResource("TokenIteratorTest_UnterminatedJavadoc.txt", SyntaxConstants.SYNTAX_STYLE_JAVA); assertIteratorMatchesList(doc); // A single line. doc.replace(0, doc.getLength(), "one two three", null); assertIteratorMatchesList(doc); // A single-line unterminated MLC. doc.replace(0, doc.getLength(), "/* Unterminated MLC", null); assertIteratorMatchesList(doc); }
if (offs==doc.getLength()) { return offs;
/** * Tests empty documents, documents with lots of blank lines, etc. */ @Test public void testEmptyLines() throws Exception { RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVA); // An empty document. doc.remove(0, doc.getLength()); assertIteratorMatchesList(doc); // A document with nothing but empty lines. doc.insertString(0, "\n\n\n\n", null); assertIteratorMatchesList(doc); // A document with nothing lots of empty lines before text. doc.insertString(0, "\n\n\n\nfor if while\n\n\n\n", null); assertIteratorMatchesList(doc); }
if (index==-1 && caretPosition<doc.getLength()-1) { bracket = doc.charAt(++caretPosition);
/** * {@inheritDoc} */ @Override public ParseResult parse(RSyntaxDocument doc, String style) { result.clearNotices(); Element root = doc.getDefaultRootElement(); result.setParsedLines(0, root.getElementCount()-1); if (spf==null || doc.getLength()==0) { return result; } try { SAXParser sp = spf.newSAXParser(); Handler handler = new Handler(doc); DocumentReader r = new DocumentReader(doc); InputSource input = new InputSource(r); sp.parse(input, handler); r.close(); } catch (SAXParseException spe) { // A fatal parse error - ignore; a ParserNotice was already created. } catch (Exception e) { //e.printStackTrace(); // Will print if DTD specified and can't be found result.addNotice(new DefaultParserNotice(this, "Error parsing XML: " + e.getMessage(), 0, -1, -1)); } return result; }
if (offs==doc.getLength()) { return offs;
@Override public ParseResult parse(RSyntaxDocument doc, String style) { DefaultParseResult res = new DefaultParseResult(this); int docLength = doc.getLength(); if (docLength==0) { return res;
if (offs==doc.getLength()) { return offs;
String codigo = documento.getText(0, documento.getLength()); if (!codigo.isEmpty())
else if (p1>doc.getLength()) throw new BadLocationException("Invalid document position", p1);
if (offs==doc.getLength()) { return offs;
Assert.assertEquals(7, action.getWordStart(textArea, 7)); doc.replace(0, doc.getLength(), "", null); Assert.assertEquals(0, action.getWordStart(textArea, 0));
Assert.assertEquals(7, action.getWordEnd(textArea, 7)); doc.replace(0, doc.getLength(), "", null); Assert.assertEquals(0, action.getWordEnd(textArea, 0));
if (offs==doc.getLength()) { return offs;