org.netbeans.editor.Utilities.getWord()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(56)

本文整理了Java中org.netbeans.editor.Utilities.getWord()方法的一些代码示例,展示了Utilities.getWord()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.getWord()方法的具体详情如下:
包路径:org.netbeans.editor.Utilities
类名称:Utilities
方法名:getWord

Utilities.getWord介绍

[英]Get the word around the given position .
[中]让单词围绕给定的位置。

代码示例

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

/** Get the identifier around the given position or null if there's no identifier
* around the given position. The identifier must be
* accepted by SyntaxSupport.isIdnetifier() otherwise null is returned.
* @param doc document to work on
* @param offset position in document - usually the caret.getDot()
* @return the block (starting and ending position) enclosing the identifier
*   or null if no identifier was found
*/
public static int[] getIdentifierBlock(BaseDocument doc, int offset)
throws BadLocationException {
  int[] ret = null;
  int idStart = getWordStart(doc, offset);
  if (idStart >= 0) {
    int idEnd = getWordEnd(doc, idStart);
    if (idEnd >= 0) {
      String id = doc.getText(idStart, idEnd - idStart);
      if (doc.getSyntaxSupport().isIdentifier(id)) {
        ret = new int[] { idStart, idEnd };
      } else { // not identifier by syntax support
        id = getWord(doc, offset); // try right at offset
        if (doc.getSyntaxSupport().isIdentifier(id)) {
          ret = new int[] { offset, offset + id.length() };
        }
      }
    }
  }
  return ret;
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

/** Get the selection if there's any or get the identifier around
* the position if there's no selection.
*/
public static String getSelectionOrIdentifier(JTextComponent c, int offset)
throws BadLocationException {
  Document doc = c.getDocument();
  Caret caret = c.getCaret();
  String ret;
  if (caret.isSelectionVisible()) {
    ret = c.getSelectedText();
  if (ret != null) return ret;
  } 
if (doc instanceof BaseDocument){
  ret = getIdentifier((BaseDocument) doc, caret.getDot());
  } else {
  ret = getWord(c, offset);
}
  return ret;
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

wordAtCursor = Utilities.getWord(doc,Utilities.getWordStart(doc,offset));
} catch( BadLocationException e ) {

代码示例来源:origin: net.java.abeille/abeille

id = getWord(doc, offset); // try right at offset
if (doc.getSyntaxSupport().isIdentifier(id)) {
  ret = new int[] { offset, offset + id.length() };

代码示例来源:origin: net.java.abeille/abeille

wordAtCursor = Utilities.getWord(doc, Utilities.getWordStart(doc, offset));
} catch (BadLocationException e) {

代码示例来源:origin: net.java.abeille/abeille

/**
 * Get the selection if there's any or get the identifier around the
 * position if there's no selection.
 */
public static String getSelectionOrIdentifier(JTextComponent c, int offset) throws BadLocationException {
  Document doc = c.getDocument();
  Caret caret = c.getCaret();
  String ret;
  if (caret.isSelectionVisible()) {
    ret = c.getSelectedText();
    if (ret != null)
      return ret;
  }
  if (doc instanceof BaseDocument) {
    ret = getIdentifier((BaseDocument) doc, caret.getDot());
  }
  else {
    ret = getWord(c, offset);
  }
  return ret;
}

相关文章

微信公众号

最新文章

更多