/** * Returns whether the current programming language uses curly braces * ('<code>{</code>' and '<code>}</code>') to denote code blocks. * * @param languageIndex The language index at the offset in question. * Since some <code>TokenMaker</code>s effectively have nested * languages (such as JavaScript in HTML), this parameter tells the * <code>TokenMaker</code> what sub-language to look at. * @return Whether curly braces denote code blocks. */ public boolean getCurlyBracesDenoteCodeBlocks(int languageIndex) { return tokenMaker.getCurlyBracesDenoteCodeBlocks(languageIndex); }
/** * Returns the text to place at the beginning and end of a * line to "comment" it in this programming language. * * @return The start and end strings to add to a line to "comment" * it out. A <code>null</code> value for either means there * is no string to add for that part. A value of * <code>null</code> for the array means this language * does not support commenting/uncommenting lines. */ public String[] getLineCommentStartAndEnd(int languageIndex) { return tokenMaker.getLineCommentStartAndEnd(languageIndex); }
/** * Returns whether tokens of the specified type should have "mark * occurrences" enabled for the current programming language. * * @param type The token type. * @return Whether tokens of this type should have "mark occurrences" * enabled. */ boolean getMarkOccurrencesOfTokenType(int type) { return tokenMaker.getMarkOccurrencesOfTokenType(type); }
@Test public void testTS_Regexes() { String[] regexes = { "/foobar/", "/foobar/gim", "/foo\\/bar\\/bas/g", }; for (String code : regexes) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TS_PREV_TOKEN_TYPE, 0); Assert.assertEquals(TokenTypes.REGEX, token.getType()); } }
/** * Updates internal state information; e.g. the "last tokens on lines" * data. After this, a changed update is fired to let listeners know that * the document's structure has changed.<p> * * This is called internally whenever the syntax style changes. */ private void updateSyntaxHighlightingInformation() { // Reinitialize the "last token on each line" array. Note that since // the actual text in the document isn't changing, the number of lines // is the same. Element map = getDefaultRootElement(); int numLines = map.getElementCount(); int lastTokenType = Token.NULL; for (int i=0; i<numLines; i++) { setSharedSegment(i); lastTokenType = tokenMaker.getLastTokenTypeOnLine(s, lastTokenType); lastTokensOnLines.set(i, lastTokenType); } // Clear our token cache to force re-painting lastLine = -1; cachedTokenList = null; // Let everybody know that syntax styles have (probably) changed. fireChangedUpdate(new DefaultDocumentEvent( 0, numLines-1, DocumentEvent.EventType.CHANGE)); }
/** * This method returns whether auto indentation should be done if Enter * is pressed at the end of the specified line. * * @param line The line to check. * @return Whether an extra indentation should be done. */ public boolean getShouldIndentNextLine(int line) { Token t = getTokenListForLine(line); t = t.getLastNonCommentNonWhitespaceToken(); return tokenMaker.getShouldIndentNextLineAfter(t); }
/** * Returns whether a character could be part of an "identifier" token * in a specific language. This is used to identify such things as the * bounds of the "word" to select on double-clicking. * * @param languageIndex The language index the character was found in. * @param ch The character. * @return Whether the character could be part of an "identifier" token. */ public boolean isIdentifierChar(int languageIndex, char ch) { return tokenMaker.isIdentifierChar(languageIndex, ch); }
/** * Returns whether the current language is a markup language, such as * HTML, XML or PHP. * * @return Whether the current language is a markup language. */ public boolean getLanguageIsMarkup() { return tokenMaker.isMarkupLanguage(); }
/** * Returns the closest {@link TokenTypes "standard" token type} for a given * "internal" token type (e.g. one whose value is <code>< 0</code>). * * @param type The token type. * @return The closest "standard" token type. If a mapping is not defined * for this language, then <code>type</code> is returned. */ public int getClosestStandardTokenTypeForInternalType(int type) { return tokenMaker.getClosestStandardTokenTypeForInternalType(type); }
@Test public void testTS_Separators_renderedAsIdentifiers() { String[] separators2 = { ";", ",", "." }; for (String code : separators2) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TS_PREV_TOKEN_TYPE, 0); Assert.assertEquals(TokenTypes.IDENTIFIER, token.getType()); } }
int newTokenType = tokenMaker.getLastTokenTypeOnLine(s, previousTokenType);
/** * This method returns whether auto indentation should be done if Enter * is pressed at the end of the specified line. * * @param line The line to check. * @return Whether an extra indentation should be done. */ public boolean getShouldIndentNextLine(int line) { Token t = getTokenListForLine(line); t = t.getLastNonCommentNonWhitespaceToken(); return tokenMaker.getShouldIndentNextLineAfter(t); }
@Test public void testCss_isIdentifierChar() { TokenMaker tm = createTokenMaker(); for (int ch = 'A'; ch <= 'Z'; ch++) { Assert.assertTrue(tm.isIdentifierChar(0, (char)ch)); Assert.assertTrue(tm.isIdentifierChar(0, (char)(ch+('a'-'A')))); } Assert.assertTrue(tm.isIdentifierChar(0, '-')); Assert.assertTrue(tm.isIdentifierChar(0, '_')); Assert.assertTrue(tm.isIdentifierChar(0, '.')); }
/** * Returns whether the current language is a markup language, such as * HTML, XML or PHP. * * @return Whether the current language is a markup language. */ public boolean getLanguageIsMarkup() { return tokenMaker.isMarkupLanguage(); }
/** * Returns the closest {@link TokenTypes "standard" token type} for a given * "internal" token type (e.g. one whose value is <code>< 0</code>). * * @param type The token type. * @return The closest "standard" token type. If a mapping is not defined * for this language, then <code>type</code> is returned. */ public int getClosestStandardTokenTypeForInternalType(int type) { return tokenMaker.getClosestStandardTokenTypeForInternalType(type); }
@Test public void testMultiLineComments() { String[] mlcLiterals = { "/* Hello world */", }; for (String code : mlcLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_MULTILINE, token.getType()); } }
@Test public void testJS_api_getLineCommentStartAndEnd() { TokenMaker tm = createTokenMaker(); Assert.assertEquals("//", tm.getLineCommentStartAndEnd(0)[0]); Assert.assertNull(tm.getLineCommentStartAndEnd(0)[1]); }
@Test public void testLess_getMarkOccurrencesOfTokenType() { TokenMaker tm = createTokenMaker(); Assert.assertTrue(tm.getMarkOccurrencesOfTokenType(TokenTypes.RESERVED_WORD)); Assert.assertTrue(tm.getMarkOccurrencesOfTokenType(TokenTypes.VARIABLE)); Assert.assertFalse(tm.getMarkOccurrencesOfTokenType(TokenTypes.COMMENT_EOL)); }
int tokenType = tokenMaker.getLastTokenTypeOnLine(s, previousTokenType); lastTokensOnLines.add(i, tokenType);
@Test public void testCss_getCurlyBracesDenoteCodeBlocks() { TokenMaker tm = createTokenMaker(); Assert.assertTrue(tm.getCurlyBracesDenoteCodeBlocks(0)); }