public DisableHint(BaseDocument doc, int offset) { this.doc = doc; try { this.offset = Utilities.getRowFirstNonWhite(doc, offset); } catch (BadLocationException ble) { } }
/** Get indentation on the current line. If this line is white then * return -1. * @param doc document to operate on * @param offset position in document anywhere on the line * @return indentation or -1 if the line is white */ public static int getRowIndent(BaseDocument doc, int offset) throws BadLocationException { offset = getRowFirstNonWhite(doc, offset); if (offset == -1) { return -1; } return doc.getVisColFromPos(offset); }
/** * Return true iff the line for the given offset is a comment line. * This will return false for lines that contain comments (even when the * offset is within the comment portion) but also contain code. */ public static boolean isCommentOnlyLine(BaseDocument doc, int offset) throws BadLocationException { int begin = Utilities.getRowFirstNonWhite(doc, offset); if (begin == -1) { return false; // whitespace only } if (begin == doc.getLength()) { return false; } return false; //doc.getText(begin, 2).equals("//") || doc.getText(begin, 1).equals("*"); }
/** * Get indentation on the current line. If this line is white then return * -1. * * @param doc * document to operate on * @param offset * position in document anywhere on the line * @return indentation or -1 if the line is white */ public static int getRowIndent(BaseDocument doc, int offset) throws BadLocationException { offset = getRowFirstNonWhite(doc, offset); if (offset == -1) { return -1; } return doc.op.getVisColFromPos(offset); }
/** Get indentation on the current line. If this line is white then * go either up or down an return indentation of the first non-white row. * The <tt>getRowFirstNonWhite()</tt> is used to find the indentation * on particular line. * @param doc document to operate on * @param offset position in document anywhere on the line * @param downDir if this flag is set to true then if the row is white * then the indentation of the next first non-white row is returned. If it's * false then the indentation of the previous first non-white row is returned. * @return indentation or -1 if there's no non-white line in the specified direction */ public static int getRowIndent(BaseDocument doc, int offset, boolean downDir) throws BadLocationException { int p = getRowFirstNonWhite(doc, offset); if (p == -1) { p = getFirstNonWhiteRow(doc, offset, downDir); if (p == -1) { return -1; // non-white line not found } p = getRowFirstNonWhite(doc, p); if (p == -1) { return -1; // non-white line not found } } return doc.getVisColFromPos(p); }
private boolean allComments(BaseDocument doc, int startOffset, int lineCount) throws BadLocationException { for (int offset = startOffset; lineCount > 0; lineCount--) { int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset); if (firstNonWhitePos != -1) { // Ignore empty lines if (!isLineCommented(doc, firstNonWhitePos)) { return false; } } offset = Utilities.getRowStart(doc, offset, +1); } return true; }
/** * Return true iff the line for the given offset is a Ruby comment line. * This will return false for lines that contain comments (even when the * offset is within the comment portion) but also contain code. */ public static boolean isCommentOnlyLine(BaseDocument doc, int offset) throws BadLocationException { int begin = Utilities.getRowFirstNonWhite(doc, offset); if (begin == -1) { return false; // whitespace only } if (begin == doc.getLength()) { return false; } return doc.getText(begin, 1).equals("#"); }
protected boolean hasTextBefore(JTextComponent target, String typedText) { BaseDocument doc = Utilities.getDocument(target); int dotPos = target.getCaret().getDot(); try { int fnw = Utilities.getRowFirstNonWhite(doc, dotPos); return dotPos != fnw+typedText.length(); } catch (BadLocationException e) { return false; } }
protected boolean hasTextBefore(JTextComponent target, String typedText) { BaseDocument doc = Utilities.getDocument(target); int dotPos = target.getCaret().getDot(); try { int fnw = Utilities.getRowFirstNonWhite(doc, dotPos); return dotPos != fnw + typedText.length(); } catch (BadLocationException e) { return false; } }
private boolean isJavaDocComment(BaseDocument doc, int offset, int endOfLine) throws BadLocationException { int pos = Utilities.getRowFirstNonWhite(doc, offset); if (pos != -1) { Token<GroovyTokenId> token = LexUtilities.getToken(doc, pos); if (token != null) { TokenId id = token.id(); if (id == GroovyTokenId.BLOCK_COMMENT) { String text = doc.getText(offset, endOfLine - offset); if (text.trim().startsWith("*")) { return true; } } } } return false; }
/** * Return true iff the line for the given offset is a JavaScript comment line. * This will return false for lines that contain comments (even when the * offset is within the comment portion) but also contain code. */ public static boolean isCommentOnlyLine(BaseDocument doc, int offset) throws BadLocationException { int begin = Utilities.getRowFirstNonWhite(doc, offset); if (begin == -1) { return false; // whitespace only } Token<? extends PHPTokenId> token = LexUtilities.getToken(doc, begin); if (token != null) { return token.id() == PHPTokenId.PHP_LINE_COMMENT; } return false; }
private boolean isJustCommentOnLine(int rowStartOffset) throws BadLocationException { boolean result = false; int rowFirstNonWhite = Utilities.getRowFirstNonWhite(baseDocument, rowStartOffset); int rowLastNonWhite = Utilities.getRowLastNonWhite(baseDocument, rowStartOffset); for (OffsetRange commentRange : commentRanges) { if (commentRange.containsInclusive(rowFirstNonWhite) && commentRange.containsInclusive(rowLastNonWhite)) { result = true; break; } } return result; }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { Caret caret = target.getCaret(); try { int pos = Utilities.getRowFirstNonWhite((BaseDocument) target.getDocument(), caret.getDot()); if (pos >= 0) { if (select) { caret.moveDot(pos); } else { caret.setDot(pos); } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { Caret caret = target.getCaret(); try { int pos = Utilities.getRowFirstNonWhite((BaseDocument)target.getDocument(), caret.getDot()); if (pos >= 0) { if (select) { caret.moveDot(pos); } else { caret.setDot(pos); } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public static String getContextLine(CsmFile csmFile, final int stToken, final int endToken) { CloneableEditorSupport ces = CsmUtilities.findCloneableEditorSupport(csmFile); StyledDocument stDoc = CsmUtilities.openDocument(ces); String displayText = null; if (stDoc instanceof BaseDocument) { BaseDocument doc = (BaseDocument) stDoc; try { int startLine = Utilities.getRowFirstNonWhite(doc, stToken); int endLine = Utilities.getRowLastNonWhite(doc, endToken) + 1; displayText = doc.getText(startLine, endLine - startLine); } catch (BadLocationException ex) { // skip } } return displayText; }
private boolean isEndIndent(BaseDocument doc, int offset) throws BadLocationException { int lineBegin = Utilities.getRowFirstNonWhite(doc, offset); if (lineBegin != -1) { Token<GroovyTokenId> token = LexUtilities.getToken(doc, lineBegin); if (token == null) { return false; } TokenId id = token.id(); // If the line starts with an end-marker, such as "end", "}", "]", etc., // find the corresponding opening marker, and indent the line to the same // offset as the beginning of that line. return (LexUtilities.isIndentToken(id) && !LexUtilities.isBeginToken(id, doc, offset)) || id == GroovyTokenId.RBRACE || id == GroovyTokenId.RBRACKET || id == GroovyTokenId.RPAREN; } return false; }
private boolean isScope(CsmReference ref) { CsmFile csmFile = ref.getContainingFile(); int stToken = ref.getStartOffset(); int endToken = ref.getEndOffset(); CloneableEditorSupport ces = CsmUtilities.findCloneableEditorSupport(csmFile); StyledDocument stDoc = CsmUtilities.openDocument(ces); if (stDoc instanceof BaseDocument) { BaseDocument doc = (BaseDocument) stDoc; try { int startLine = Utilities.getRowFirstNonWhite(doc, stToken); int endLine = Utilities.getRowLastNonWhite(doc, endToken) + 1; String restText = doc.getText(endToken, endLine - startLine).trim(); return restText.startsWith("::"); //NOI18N } catch (BadLocationException ex) { // skip } } return false; }
public static String getContextLineHtml(CsmFile csmFile, final int stToken, final int endToken, boolean tokenInBold) { CloneableEditorSupport ces = CsmUtilities.findCloneableEditorSupport(csmFile); StyledDocument stDoc = CsmUtilities.openDocument(ces); String displayText = null; if (stDoc instanceof BaseDocument) { BaseDocument doc = (BaseDocument) stDoc; try { int stOffset = stToken; int endOffset = endToken; int startLine = Utilities.getRowFirstNonWhite(doc, stOffset); int endLine = Utilities.getRowLastNonWhite(doc, endOffset) + 1; if (!tokenInBold) { stOffset = -1; endOffset = -1; } displayText = getLineHtml(startLine, endLine, stOffset, endOffset, doc); } catch (BadLocationException ex) { // skip } } return displayText; }
int rowStart = Utilities.getRowFirstNonWhite(doc, lexOffset); if (rowStart != -1 && lexOffset <= rowStart) { lexOffset = rowStart + 1;
/** * Change the indent of the given row. Document is atomically locked during * this operation. */ public void changeRowIndent(BaseDocument doc, int pos, int newIndent) throws BadLocationException { doc.atomicLock(); try { if (newIndent < 0) { newIndent = 0; } int firstNW = Utilities.getRowFirstNonWhite(doc, pos); if (firstNW == -1) { // valid first non-blank firstNW = Utilities.getRowEnd(doc, pos); } int bolPos = Utilities.getRowStart(doc, pos); doc.remove(bolPos, firstNW - bolPos); // !!! indent by spaces/tabs doc.insertString(bolPos, getIndentString(doc, newIndent), null); } finally { doc.atomicUnlock(); } }