/** * Returns the foreground color to use when painting a token. * * @param t The token. * @return The foreground color to use for that token. This * value is never <code>null</code>. * @see #getBackgroundForToken(Token) */ public Color getForegroundForToken(Token t) { if (getHyperlinksEnabled() && hoveredOverLinkOffset==t.getOffset() && (t.isHyperlink() || linkGeneratorResult!=null)) { return hyperlinkFG; } return getForegroundForTokenType(t.getType()); }
/** * Returns whether the specified token should be underlined. * A token is underlined if its syntax style includes underlining, * or if it is a hyperlink and hyperlinks are enabled. * * @param t The token. * @return Whether the specified token should be underlined. */ public boolean getUnderlineForToken(Token t) { return (getHyperlinksEnabled() && (t.isHyperlink() || (linkGeneratorResult!=null && linkGeneratorResult.getSourceOffset()==t.getOffset()))) || syntaxScheme.getStyle(t.getType()).underline; }
@Override public boolean equals(Object obj) { if (obj==this) { return true; } if (!(obj instanceof Token)) { return false; } Token t2 = (Token)obj; return offset==t2.getOffset() && type==t2.getType() && languageIndex==t2.getLanguageIndex() && hyperlink==t2.isHyperlink() && ((getLexeme()==null && t2.getLexeme()==null) || (getLexeme()!=null && getLexeme().equals(t2.getLexeme()))); }
/** * Makes one token point to the same text segment, and have the same value * as another token. * * @param t2 The token from which to copy. */ public void copyFrom(Token t2) { text = t2.getTextArray(); textOffset = t2.getTextOffset(); textCount = t2.length(); setOffset(t2.getOffset()); setType(t2.getType()); hyperlink = t2.isHyperlink(); languageIndex = t2.getLanguageIndex(); nextToken = t2.getNextToken(); }
@Test public void testHtml_comment_URL() { String code = "<!-- Hello world http://www.google.com -->"; Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.MARKUP_COMMENT, "<!-- Hello world ")); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.MARKUP_COMMENT, "http://www.google.com")); token = token.getNextToken(); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.MARKUP_COMMENT, " -->")); }
@Test public void testCss_comment_URL() { String code = "/* Hello world http://www.google.com */"; Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, CSS_PREV_TOKEN_TYPE, 0); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_MULTILINE, "/* Hello world ")); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_MULTILINE, "http://www.google.com")); token = token.getNextToken(); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_MULTILINE, " */")); }
@Test public void testNameValuePair_happyPath() { String code = "dialog.title=Options"; Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.RESERVED_WORD, "dialog.title")); token = token.getNextToken(); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.isSingleChar(TokenTypes.OPERATOR, '=')); token = token.getNextToken(); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.LITERAL_STRING_DOUBLE_QUOTE, "Options")); }
@Test public void testCss_comment_URL() { String code = "/* Hello world http://www.google.com */"; Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, CSS_PREV_TOKEN_TYPE, 0); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_MULTILINE, "/* Hello world ")); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_MULTILINE, "http://www.google.com")); token = token.getNextToken(); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_MULTILINE, " */")); }
@Test public void testMxml_comment_URL() { String code = "<!-- Hello world http://www.google.com -->"; Segment segment = createSegment(code); MxmlTokenMaker tm = new MxmlTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue("Token is not type MARKUP_COMMENT: " + token, token.is(TokenTypes.MARKUP_COMMENT, "<!-- Hello world ")); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.MARKUP_COMMENT, "http://www.google.com")); token = token.getNextToken(); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.MARKUP_COMMENT, " -->")); }
@Test public void testDtd_comment_URL() { String code = "<!-- Hello world http://www.google.com -->"; Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue("Token is not type MARKUP_COMMENT: " + token, token.is(TokenTypes.MARKUP_COMMENT, "<!-- Hello world ")); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.MARKUP_COMMENT, "http://www.google.com")); token = token.getNextToken(); Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.MARKUP_COMMENT, " -->")); }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "; Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "# Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testJS_EolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, JS_PREV_TOKEN_TYPE, 0); Assert.assertEquals("Unexpected token: " + token, TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "; Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }