private int getLineCount() { return doc.getDefaultRootElement().getElementCount(); }
/** * 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); }
/** * Makes our private <code>Segment s</code> point to the text in our * document referenced by the specified element. Note that * <code>line</code> MUST be a valid line number in the document. * * @param line The line number you want to get. */ private void setSharedSegment(int line) { Element map = getDefaultRootElement(); //int numLines = map.getElementCount(); Element element = map.getElement(line); if (element==null) { throw new InternalError("Invalid line number: " + line); } int startOffset = element.getStartOffset(); //int endOffset = (line==numLines-1 ? // element.getEndOffset()-1 : element.getEndOffset() - 1); int endOffset = element.getEndOffset()-1; // Why always "-1"? try { getText(startOffset, endOffset-startOffset, s); } catch (BadLocationException ble) { throw new InternalError("Text range not in document: " + startOffset + "-" + endOffset); } }
@Override protected int getWordStart(RTextArea textArea, int offs) throws BadLocationException { RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); Element root = doc.getDefaultRootElement(); int line = root.getElementIndex(offs); Element elem = root.getElement(line); return getWordStartImpl(doc, elem, offs); }
/** * Deserializes a document. * * @param in The stream to read from. * @throws ClassNotFoundException * @throws IOException */ private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { in.defaultReadObject(); // Install default TokenMakerFactory. To support custom TokenMakers, // both JVM's should install default TokenMakerFactories that support // the language they want to use beforehand. setTokenMakerFactory(null); // Handle other transient stuff this.s = new Segment(); int lineCount = getDefaultRootElement().getElementCount(); lastTokensOnLines = new DynamicIntArray(lineCount); setSyntaxStyle(syntaxStyle); // Actually install (transient) TokenMaker }
/** * {@inheritDoc} */ @Override public ParseResult parse(RSyntaxDocument doc, String style) { result.clearNotices(); Element root = doc.getDefaultRootElement(); result.setParsedLines(0, root.getElementCount()-1); if (spf==null || doc.getLength()==0) { return result; } try { SAXParser sp = spf.newSAXParser(); Handler handler = new Handler(doc); DocumentReader r = new DocumentReader(doc); InputSource input = new InputSource(r); sp.parse(input, handler); r.close(); } catch (SAXParseException spe) { // A fatal parse error - ignore; a ParserNotice was already created. } catch (Exception e) { //e.printStackTrace(); // Will print if DTD specified and can't be found result.addNotice(new DefaultParserNotice(this, "Error parsing XML: " + e.getMessage(), 0, -1, -1)); } return result; }
int p1 = Math.max(dot, mark); RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); Element map = doc.getDefaultRootElement();
@Override protected int getWordEnd(RTextArea textArea, int offs) throws BadLocationException { RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); Element root = doc.getDefaultRootElement(); int line = root.getElementIndex(offs); Element elem = root.getElement(line); int end = elem.getEndOffset() - 1; int wordEnd = offs; while (wordEnd <= end) { if (!isIdentifierChar(doc.charAt(wordEnd))) { break; } wordEnd++; } return wordEnd; }
@Override public ParseResult parse(RSyntaxDocument doc, String style) { Element root = doc.getDefaultRootElement(); int lineCount = root.getElementCount();
/** * 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)); }
/** * 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; }
public Token getTokenListForPhysicalLineAbove(int offset) { RSyntaxDocument document = (RSyntaxDocument)getDocument(); Element map = document.getDefaultRootElement(); int line = map.getElementIndex(offset); FoldManager fm = host.getFoldManager();
Element root = doc.getDefaultRootElement(); int firstLine = firstOffsetModded==null ? 0 : root.getElementIndex(firstOffsetModded.getOffset());
/** * 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; }
Element map = doc.getDefaultRootElement(); Caret c = textArea.getCaret(); int dot = c.getDot();
/** * 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(); } } }
Element map = getDefaultRootElement(); Element elem = map.getElement(line); int startOffset = elem.getStartOffset();
public Token getTokenListForPhysicalLineBelow(int offset) { RSyntaxDocument document = (RSyntaxDocument)getDocument(); Element map = document.getDefaultRootElement(); int lineCount = map.getElementCount(); int line = map.getElementIndex(offset);
Element root = doc.getDefaultRootElement(); int line = root.getElementIndex(offs); Element elem = root.getElement(line);
Element lineMap = getDefaultRootElement(); DocumentEvent.ElementChange change = e.getChange(lineMap); Element[] added = change==null ? null : change.getChildrenAdded();