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

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

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

Utilities.getWordStart介绍

[英]Get start of the current word. If there are no more words till the begining of the document, this method returns -1.
[中]获取当前单词的开头。如果在文档开始之前没有其他单词,该方法将返回-1。

代码示例

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

/** Get start of the current word. If there are no more words till
* the begining of the document, this method returns -1.
* @param c text component to operate on
* @param offset position in document from which the current line is determined
*/
public static int getWordStart(JTextComponent c, int offset)
throws BadLocationException {
  return getWordStart((BaseDocument)c.getDocument(), offset);
}

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

/**
 * Get start of the current word. If there are no more words till the
 * begining of the document, this method returns -1.
 * 
 * @param c
 *            text component to operate on
 * @param offset
 *            position in document from which the current line is determined
 */
public static int getWordStart(JTextComponent c, int offset) throws BadLocationException {
  return getWordStart((BaseDocument) c.getDocument(), offset);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor

private void substitute(final JTextComponent component, final String directive) {
  final int offset = component.getCaret().getDot();
  final Document doc=component.getDocument();
  
  try {
    int wordStart=org.netbeans.editor.Utilities.getWordStart(component, offset);
    final int wordEnd=org.netbeans.editor.Utilities.getWordEnd(component, offset);
    
    if (wordStart > 0) {
      String word = doc.getText(wordStart, wordEnd - wordStart);
      if (word.startsWith("//#")) {
        word=word.substring(3);
        wordStart+=3;
      }
      doc.remove(wordStart, word.length());
      doc.insertString(wordStart, directive, null);
      
    } else {
      doc.insertString(offset, directive, null);
    }
  } catch (BadLocationException ble) {}
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor

private void substitute(final JTextComponent component, final String variable) {
  final int offset = component.getCaret().getDot();
  final Document doc = component.getDocument();
  
  try {
    final int wordStart = org.netbeans.editor.Utilities.getWordStart(component, offset);
    final int wordEnd = org.netbeans.editor.Utilities.getWordEnd(component, offset);
    
    if (wordStart > 0) {
      final String word = doc.getText(wordStart, wordEnd - wordStart);
      if ("()".equals(word) || "(".equals(word)) {
        doc.insertString(wordStart+1, variable, null);
      } else if (")".equals(word)) {
        doc.insertString(wordStart, variable, null);
      } else {
        doc.remove(wordStart, word.length());
        doc.insertString(wordStart, variable, null);
      }
    } else {
      doc.insertString(offset, variable, null);
    }
  } catch (BadLocationException ble) {
  }
}

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

/** Get the identifier before the given position (ending at given offset)
* or null if there's no identifier
*/
public static String getIdentifierBefore(BaseDocument doc, int offset)
throws BadLocationException {
  int wordStart = getWordStart(doc, offset);
  if (wordStart != -1) {
    String word = new String(doc.getChars(wordStart,
                       offset - wordStart), 0, offset - wordStart);
    if (doc.getSyntaxSupport().isIdentifier(word)) {
      return word;
    }
  }
  return null;
}

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

/**
 * Get the identifier before the given position (ending at given offset) or
 * null if there's no identifier
 */
public static String getIdentifierBefore(BaseDocument doc, int offset) throws BadLocationException {
  int wordStart = getWordStart(doc, offset);
  if (wordStart != -1) {
    String word = new String(doc.getChars(wordStart, offset - wordStart), 0, offset - wordStart);
    if (doc.getSyntaxSupport().isIdentifier(word)) {
      return word;
    }
  }
  return null;
}

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

public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
      Caret caret = target.getCaret();
      try {
        int dot = Utilities.getWordStart(target, caret.getDot());
        if (select) {
          caret.moveDot(dot);
        }
        else {
          caret.setDot(dot);
        }
      } catch (BadLocationException ex) {
        target.getToolkit().beep();
      }
    }
  }
}

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

public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
      Caret caret = target.getCaret();
      try {
        int dot = Utilities.getWordStart(target, caret.getDot());
        if (select) {
          caret.moveDot(dot);
        } else {
          caret.setDot(dot);
        }
      } catch (BadLocationException ex) {
        target.getToolkit().beep();
      }
    }
  }
}

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

int idStart = getWordStart(doc, offset);
if (idStart >= 0) {
  int idEnd = getWordEnd(doc, idStart);

代码示例来源: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: org.netbeans.modules/org-netbeans-modules-php-editor

VariableScope variableScope = model.getVariableScope(caretOffset);
if (variableScope != null) {
  int wordStart = Utilities.getWordStart(doc, caretOffset);
  int wordEnd = Utilities.getWordEnd(doc, caretOffset);
  VariableName variable = ModelUtils.getFirst(variableScope.getDeclaredVariables(), identifier);

代码示例来源: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

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

相关文章

微信公众号

最新文章

更多