/** * Constructor. * * @param doc The document for the editor. */ public RSyntaxTextArea(RSyntaxDocument doc) { super(doc); setSyntaxEditingStyle(doc.getSyntaxStyle()); }
/** * Sets the document used by this text area. This is overridden so that * only instances of {@link RSyntaxDocument} are accepted; for all * others, an exception will be thrown. * * @param document The new document for this text area. * @throws IllegalArgumentException If the document is not an * <code>RSyntaxDocument</code>. */ @Override public void setDocument(Document document) { if (!(document instanceof RSyntaxDocument)) { throw new IllegalArgumentException("Documents for " + "RSyntaxTextArea must be instances of " + "RSyntaxDocument!"); } if (markOccurrencesSupport != null) { markOccurrencesSupport.clear(); } super.setDocument(document); setSyntaxEditingStyle(((RSyntaxDocument)document).getSyntaxStyle()); if (markOccurrencesSupport != null) { markOccurrencesSupport.doMarkOccurrences(); } }
@Test public void testGetSyntaxStyle() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); syntaxStyle = SyntaxConstants.SYNTAX_STYLE_XML; doc.setSyntaxStyle(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); syntaxStyle = "text/custom"; doc.setSyntaxStyle(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); }
@Test public void testSetSyntaxStyle() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); syntaxStyle = SyntaxConstants.SYNTAX_STYLE_XML; doc.setSyntaxStyle(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); syntaxStyle = "text/custom"; doc.setSyntaxStyle(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); }
@Test public void testSetSyntaxStyle_CustomTokenMaker() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); TokenMaker tokenMaker = new HTMLTokenMaker(); doc.setSyntaxStyle(tokenMaker); Assert.assertNotEquals(syntaxStyle, doc.getSyntaxStyle()); }
@Test public void testParse_emptyDocument() throws Exception { XmlParser parser = new XmlParser(); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_XML); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); assertCleanParseResult_oneLineDocument(parser, res); }
@Test public void testParse_happyPath() throws Exception { XmlParser parser = new XmlParser(); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_XML); doc.insertString(0, "<?xml version='1.0'?><books></books>", null); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); assertCleanParseResult_oneLineDocument(parser, res); }
/** * Constructor. * * @param doc The document for the editor. */ public RSyntaxTextArea(RSyntaxDocument doc) { super(doc); setSyntaxEditingStyle(doc.getSyntaxStyle()); }
@Test public void testParse_happyPath() throws Exception { TaskTagParser parser = new TaskTagParser(); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_C); doc.insertString(0, "/* TODO: Fix this */", null); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); Assert.assertEquals(parser, res.getParser()); Assert.assertEquals(0, res.getFirstLineParsed()); Assert.assertEquals(0, res.getLastLineParsed()); List<ParserNotice> notices = res.getNotices(); Assert.assertEquals(1, notices.size()); // Note that the parser does not understand EOL vs. MLC comments, so // it just returns everything from the start of the task to the end of // the line. Assert.assertEquals("TODO: Fix this */", notices.get(0).getToolTipText()); }
@Test public void testParse_error_unclosedTag_nodtd() throws Exception { XmlParser parser = new XmlParser(); // Include a DTD just for more code coverage RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_XML); doc.insertString(0, "<?xml version='1.0'?>\n" + "<books>", null); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); Assert.assertEquals(parser, res.getParser()); Assert.assertEquals(0, res.getFirstLineParsed()); Assert.assertEquals(1, res.getLastLineParsed()); List<ParserNotice> notices = res.getNotices(); Assert.assertEquals(1, notices.size()); ParserNotice notice = notices.get(0); Assert.assertEquals(ParserNotice.Level.ERROR, notice.getLevel()); }
@Test public void testParse_error_unclosedTag_withDtd() throws Exception { XmlParser parser = new XmlParser(); // Include a DTD just for more code coverage RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_XML); doc.insertString(0, "<?xml version='1.0'?>\n" + "<!DOCTYPE RSyntaxTheme SYSTEM \"theme.dtd\">\n" + "<books>", null); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); Assert.assertEquals(parser, res.getParser()); Assert.assertEquals(0, res.getFirstLineParsed()); Assert.assertEquals(2, res.getLastLineParsed()); List<ParserNotice> notices = res.getNotices(); Assert.assertEquals(1, notices.size()); ParserNotice notice = notices.get(0); Assert.assertEquals(ParserNotice.Level.ERROR, notice.getLevel()); }
@Test public void testParse_nullTaskPattern() throws Exception { TaskTagParser parser = new TaskTagParser(); parser.setTaskPattern(null); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_C); doc.insertString(0, "/* TODO: Fix this */ for", null); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); Assert.assertEquals(parser, res.getParser()); Assert.assertEquals(0, res.getFirstLineParsed()); Assert.assertEquals(0, res.getLastLineParsed()); List<ParserNotice> notices = res.getNotices(); Assert.assertEquals(0, notices.size()); }
@Test public void testParse_noLanguage() throws Exception { TaskTagParser parser = new TaskTagParser(); parser.setTaskPattern(null); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_NONE); doc.insertString(0, "/* TODO: Fix this */ for", null); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); Assert.assertEquals(parser, res.getParser()); Assert.assertEquals(0, res.getFirstLineParsed()); Assert.assertEquals(0, res.getLastLineParsed()); List<ParserNotice> notices = res.getNotices(); Assert.assertEquals(0, notices.size()); doc.setSyntaxStyle((String)null); // Not really valid, but whatever res = parser.parse(doc, doc.getSyntaxStyle()); Assert.assertEquals(parser, res.getParser()); Assert.assertEquals(0, res.getFirstLineParsed()); Assert.assertEquals(0, res.getLastLineParsed()); notices = res.getNotices(); Assert.assertEquals(0, notices.size()); }
/** * Sets the document used by this text area. This is overridden so that * only instances of {@link RSyntaxDocument} are accepted; for all * others, an exception will be thrown. * * @param document The new document for this text area. * @throws IllegalArgumentException If the document is not an * <code>RSyntaxDocument</code>. */ @Override public void setDocument(Document document) { if (!(document instanceof RSyntaxDocument)) { throw new IllegalArgumentException("Documents for " + "RSyntaxTextArea must be instances of " + "RSyntaxDocument!"); } if (markOccurrencesSupport != null) { markOccurrencesSupport.clear(); } super.setDocument(document); setSyntaxEditingStyle(((RSyntaxDocument)document).getSyntaxStyle()); if (markOccurrencesSupport != null) { markOccurrencesSupport.doMarkOccurrences(); } }