if (type == TokenTypes.IDENTIFIER) { sourceOffset = token.getOffset(); } else if (type == TokenTypes.ANNOTATION && token.length() > 1) { sourceOffset = token.getOffset() + 1; } else { if (token.length() == 1) { char ch = token.getTextArray()[token.getTextOffset()]; if (ch == '.' || ch == ',' || ch == ';') {
@Override public boolean getShouldIndentNextLineAfter(Token t) { if (t!=null && t.length()==1) { char ch = t.charAt(0); return ch=='{' || ch=='('; } return false; }
/** * {@inheritDoc} */ @Override public boolean getShouldIndentNextLineAfter(Token t) { if (t!=null && t.length()==1) { char ch = t.charAt(0); return ch=='{' || ch=='('; } return false; }
@Override public boolean getShouldIndentNextLineAfter(Token t) { if (t!=null && t.length()==1) { char ch = t.charAt(0); return ch=='{' || ch=='['; } return false; }
/** * Returns whether the specified token is a single non-word char (e.g. not * in <code>[A-Za-z]</code>. This is a HACK to work around the fact that * many standard token makers return things like semicolons and periods as * {@link Token#IDENTIFIER}s just to make the syntax highlighting coloring * look a little better. * * @param t The token to check. This cannot be <code>null</code>. * @return Whether the token is a single non-word char. */ public static boolean isNonWordChar(Token t) { return t.length()==1 && !RSyntaxUtilities.isLetter(t.charAt(0)); }
/** * Returns whether a regular expression token can follow the specified * token. * * @param t The token to check, which may be <code>null</code>. * @return Whether a regular expression token may follow this one. */ private static final boolean regexCanFollow(Token t) { char ch; return t==null || //t.isOperator() || (t.length()==1 && ( (ch=t.charAt(0))=='=' || ch=='(' || ch==',' || ch=='?' || ch==':' || ch=='[' )) || /* Operators "==", "===", "!=", "!==", etc. */ (t.getType()==Token.OPERATOR && ((ch=t.charAt(t.length()-1))=='=' || ch=='~')); }
/** * Returns whether a regular expression token can follow the specified * token. * * @param t The token to check, which may be <code>null</code>. * @return Whether a regular expression token may follow this one. */ private static final boolean regexCanFollow(Token t) { char ch; // We basically try to mimic Eclipse's JS editor's behavior here. return t==null || //t.isOperator() || (t.length()==1 && ( (ch=t.charAt(0))=='=' || ch=='(' || ch==',' || ch=='?' || ch==':' || ch=='[' || ch=='!' || ch=='&' )) || /* Operators "==", "===", "!=", "!==", etc. */ (t.getType()==Token.OPERATOR && ((ch=t.charAt(t.length()-1))=='=' || ch=='~')); }
/** * Overridden to handle newlines in JS and CSS differently than those in * markup. */ @Override public boolean getShouldIndentNextLineAfter(Token token) { int languageIndex = token==null ? 0 : token.getLanguageIndex(); if (getCurlyBracesDenoteCodeBlocks(languageIndex)) { if (token!=null && token.length()==1) { char ch = token.charAt(0); return ch=='{' || ch=='('; } } return false; }
/** * Overridden to handle newlines in JS and CSS differently than those in * markup. */ @Override public boolean getShouldIndentNextLineAfter(Token token) { int languageIndex = token==null ? 0 : token.getLanguageIndex(); if (getCurlyBracesDenoteCodeBlocks(languageIndex)) { if (token!=null && token.length()==1) { char ch = token.charAt(0); return ch=='{' || ch=='('; } } return false; }
/** * Overridden to handle newlines in JS and CSS differently than those in * markup. */ @Override public boolean getShouldIndentNextLineAfter(Token token) { int languageIndex = token==null ? 0 : token.getLanguageIndex(); if (getCurlyBracesDenoteCodeBlocks(languageIndex)) { if (token!=null && token.length()==1) { char ch = token.charAt(0); return ch=='{' || ch=='('; } } return false; }
private static int getOpenBraceCount(RSyntaxDocument doc, int languageIndex) { int openCount = 0; for (Token t : doc) { if (t.getType()==Token.SEPARATOR && t.length()==1 && t.getLanguageIndex()==languageIndex) { char ch = t.charAt(0); if (ch=='{') { openCount++; } else if (ch=='}') { openCount--; } } } return openCount; }
/** * Returns whether a regular expression token can follow the specified * token in JavaScript. * * @param t The token to check, which may be <code>null</code>. * @return Whether a regular expression token may follow this one in * JavaScript. */ public static boolean regexCanFollowInJavaScript(Token t) { char ch; // We basically try to mimic Eclipse's JS editor's behavior here. return t==null || //t.isOperator() || (t.length()==1 && ( (ch=t.charAt(0))=='=' || ch=='(' || ch==',' || ch=='?' || ch==':' || ch=='[' || ch=='!' || ch=='&' )) || /* Operators "==", "===", "!=", "!==", "&&", "||" */ (t.getType()==Token.OPERATOR && (t.charAt(t.length()-1)=='=' || t.is(JS_AND) || t.is(JS_OR))) || t.is(Token.RESERVED_WORD_2, JS_KEYWORD_RETURN); }
/** * 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(); }
while (i<textOffset+t.length()-1) { if (t.charAt(i-textOffset)=='/' && t.charAt(i-textOffset+1)=='*') { return true;
private byte[] getTextAsRtf(int start, int end) { // Create the RTF selection. RtfGenerator gen = new RtfGenerator(getBackground()); Token tokenList = getTokenListFor(start, end); for (Token t = tokenList; t != null; t = t.getNextToken()) { if (t.isPaintable()) { if (t.length() == 1 && t.charAt(0) == '\n') { gen.appendNewline(); } else { Font font = getFontForTokenType(t.getType()); Color bg = getBackgroundForToken(t); boolean underline = getUnderlineForToken(t); // Small optimization - don't print fg color if this // is a whitespace color. Saves on RTF size. if (t.isWhitespace()) { gen.appendToDocNoFG(t.getLexeme(), font, bg, underline); } else { Color fg = getForegroundForToken(t); gen.appendToDoc(t.getLexeme(), font, fg, bg, underline); } } } } // RTF text is 7-bit ASCII so this should cover us return gen.getRtf().getBytes(StandardCharsets.UTF_8); }
@Test public void testJS_EolComments_URL() { String[] eolCommentLiterals = { // Note: The 0-length token at the end of the first example is a // minor bug/performance thing "// Hello world http://www.sas.com", "// Hello world http://www.sas.com extra", }; 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()); token = token.getNextToken(); // Note: The 0-length token at the end of the first example is a // minor bug/performance thing if (token != null && token.isPaintable() && token.length() > 0) { Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_EOL, " extra")); } } }
@Test public void testJS_EolComments_URL() { String[] eolCommentLiterals = { // Note: The 0-length token at the end of the first example is a // minor bug/performance thing "// Hello world http://www.sas.com", "// Hello world http://www.sas.com extra", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, HTMLTokenMaker.INTERNAL_IN_JS, 0); Assert.assertEquals("nope - " + 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()); token = token.getNextToken(); // Note: The 0-length token at the end of the first example is a // minor bug/performance thing if (token != null && token.isPaintable() && token.length() > 0) { Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_EOL, " extra")); } } }
@Test public void testJS_EolComments_URL() { String[] eolCommentLiterals = { // Note: The 0-length token at the end of the first example is a // minor bug/performance thing "// Hello world http://www.sas.com", "// Hello world http://www.sas.com extra", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, JS_PREV_TOKEN_TYPE, 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()); token = token.getNextToken(); // Note: The 0-length token at the end of the first example is a // minor bug/performance thing if (token != null && token.isPaintable() && token.length() > 0) { Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_EOL, " extra")); } } }
@Test public void testTS_EolComments_URL() { String[] eolCommentLiterals = { // Note: The 0-length token at the end of the first example is a // minor bug/performance thing "// Hello world http://www.sas.com", "// Hello world http://www.sas.com extra", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TS_PREV_TOKEN_TYPE, 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()); token = token.getNextToken(); // Note: The 0-length token at the end of the first example is a // minor bug/performance thing if (token != null && token.isPaintable() && token.length() > 0) { Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_EOL, " extra")); } } }
@Test public void testJS_EolComments_URL() { String[] eolCommentLiterals = { // Note: The 0-length token at the end of the first example is a // minor bug/performance thing "// Hello world http://www.sas.com", "// Hello world http://www.sas.com extra", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, JS_PREV_TOKEN_TYPE, 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()); token = token.getNextToken(); // Note: The 0-length token at the end of the first example is a // minor bug/performance thing if (token != null && token.isPaintable() && token.length() > 0) { Assert.assertFalse(token.isHyperlink()); Assert.assertTrue(token.is(TokenTypes.COMMENT_EOL, " extra")); } } }