private void loadTokenListForCurLine() { token = doc.getTokenListForLine(curLine); if (token!=null && !token.isPaintable()) { // Common end of document scenario token = null; } }
/** * Returns a list of tokens representing the given line. * * @param line The line number to get tokens for. * @return A linked list of tokens representing the line's text. */ public Token getTokenListForLine(int line) { return ((RSyntaxDocument)getDocument()).getTokenListForLine(line); }
/** * 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 the last non-whitespace, non-comment token, starting with the * specified line. * * @param doc The document. * @param line The line at which to start looking. * @return The last non-whitespace, non-comment token, or <code>null</code> * if there isn't one. * @see #getNextImportantToken(Token, RSyntaxTextArea, int) * @see #getPreviousImportantTokenFromOffs(RSyntaxDocument, int) */ public static Token getPreviousImportantToken(RSyntaxDocument doc, int line) { if (line<0) { return null; } Token t = doc.getTokenListForLine(line); if (t!=null) { t = t.getLastNonCommentNonWhitespaceToken(); if (t!=null) { return t; } } return getPreviousImportantToken(doc, line-1); }
/** * Calculates the width of the line represented by the given element. * * @param line The line for which to get the length. * @param lineNumber The line number of the specified line in the document. * @return The width of the line. */ private float getLineWidth(int lineNumber) { Token tokenList = ((RSyntaxDocument)getDocument()). getTokenListForLine(lineNumber); return RSyntaxUtilities.getTokenListWidth(tokenList, (RSyntaxTextArea)getContainer(), this); }
/** * Returns the token at the specified offset. * * @param doc The document. * @param offset The offset of the token. * @return The token, or <code>null</code> if the offset is not valid. * @see #getTokenAtOffset(RSyntaxTextArea, int) * @see #getTokenAtOffset(Token, int) */ public static Token getTokenAtOffset(RSyntaxDocument doc, int offset) { Element root = doc.getDefaultRootElement(); int lineIndex = root.getElementIndex(offset); Token t = doc.getTokenListForLine(lineIndex); return RSyntaxUtilities.getTokenAtOffset(t, offset); }
line--; if (line>=0) { return document.getTokenListForLine(line); line = fm.getVisibleLineAbove(line); if (line>=0) { return document.getTokenListForLine(line);
if (!host.isCodeFoldingEnabled()) { if (line<lineCount-1) { return document.getTokenListForLine(line+1); line = fm.getVisibleLineBelow(line); if (line>=0 && line<lineCount) { return document.getTokenListForLine(line);
Token t = doc.getTokenListForLine(line-1); t = t.getLastNonCommentNonWhitespaceToken();
Token t = doc.getTokenListForLine(line); int offs = -1; int start = -1;
RSyntaxDocument doc = (RSyntaxDocument)getDocument(); int lineIndex = map.getElementIndex(pos); Token tokenList = doc.getTokenListForLine(lineIndex); Rectangle lineArea = lineToRect(a, lineIndex);
/** * Returns the set of expected paintable tokens from a document. * * @param doc The document. * @return The list of tokens, in the order in which they appear. */ private static final List<Token> getTokens(RSyntaxDocument doc) { Element root = doc.getDefaultRootElement(); int lineCount = root.getElementCount(); List<Token> list = new ArrayList<Token>(); for (int i=0; i<lineCount; i++) { Token t = doc.getTokenListForLine(i); while (t!=null && t.isPaintable()) { list.add(new TokenImpl(t)); // Copy since Tokens are pooled t = t.getNextToken(); } } return list; }
/** * Returns the last non-whitespace, non-comment token, before the * specified offset. * * @param doc The document. * @param offs The ending offset for the search. * @return The last non-whitespace, non-comment token, or <code>null</code> * if there isn't one. * @see #getPreviousImportantToken(RSyntaxDocument, int) * @see #getNextImportantToken(Token, RSyntaxTextArea, int) */ public static Token getPreviousImportantTokenFromOffs( RSyntaxDocument doc, int offs) { Element root = doc.getDefaultRootElement(); int line = root.getElementIndex(offs); Token t = doc.getTokenListForLine(line); // Check line containing offs Token target = null; while (t!=null && t.isPaintable() && !t.containsPosition(offs)) { if (!t.isCommentOrWhitespace()) { target = t; } t = t.getNextToken(); } // Check previous line(s) if (target==null) { target = RSyntaxUtilities.getPreviousImportantToken(doc, line-1); } return target; }
int end = Math.max(line1, line2); Token t = doc.getTokenListForLine(start); int languageIndex = t!=null ? t.getLanguageIndex() : 0; String[] startEnd = doc.getLineCommentStartAndEnd(languageIndex);
/** * Highlights all instances of tokens identical to <code>t</code> in the * specified document. * * @param doc The document. * @param t The document whose relevant occurrences should be marked. * @param h The highlighter to add the highlights to. * @param p The painter for the highlights. */ public static final void markOccurrencesOfToken(RSyntaxDocument doc, Token t, RSyntaxTextAreaHighlighter h, SmartHighlightPainter p) { char[] lexeme = t.getLexeme().toCharArray(); int type = t.getType(); int lineCount = doc.getDefaultRootElement().getElementCount(); for (int i=0; i<lineCount; i++) { Token temp = doc.getTokenListForLine(i); while (temp!=null && temp.isPaintable()) { if (temp.is(type, lexeme)) { try { int end = temp.getEndOffset(); h.addMarkedOccurrenceHighlight(temp.getOffset(),end,p); } catch (BadLocationException ble) { ble.printStackTrace(); // Never happens } } temp = temp.getNextToken(); } } }
Token t = doc.getTokenListForLine(i); while (t!=null && t.isPaintable()) {
Element map = doc.getDefaultRootElement(); int line = map.getElementIndex(startOffset); Token tokenList = doc.getTokenListForLine(line); float x0 = 0;// FIXME: should be alloc.x!! alloc.x;//0;
Token tokenList = doc.getTokenListForLine(lineIndex); tabBase = alloc.x; int offs = tokenList.getListOffset(
if (ch=='<' || ch=='[') { Token t = doc.getTokenListForLine( rsta.getCaretLineNumber()); t = RSyntaxUtilities.getTokenAtOffset(t, dot-1);
@Test public void testGetTokenListForLine() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); insertHelloWorldC(doc); // #include <stdio.h> Token t = doc.getTokenListForLine(0); Assert.assertTrue(t.is(TokenTypes.PREPROCESSOR, "#include")); t = t.getNextToken(); Assert.assertTrue(t.isSingleChar(TokenTypes.WHITESPACE, ' ')); t = t.getNextToken(); Assert.assertTrue(t.isSingleChar(TokenTypes.OPERATOR, '<')); t = t.getNextToken(); Assert.assertTrue(t.is(TokenTypes.IDENTIFIER, "stdio")); t = t.getNextToken(); Assert.assertTrue(t.isSingleChar(TokenTypes.OPERATOR, '.')); t = t.getNextToken(); Assert.assertTrue(t.isSingleChar(TokenTypes.IDENTIFIER, 'h')); t = t.getNextToken(); Assert.assertTrue(t.isSingleChar(TokenTypes.OPERATOR, '>')); t = t.getNextToken(); Assert.assertEquals(new TokenImpl(), t); // Null token }