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

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

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

Utilities.getIdentifier介绍

[英]Get the identifier around the given position or null if there's no identifier
[中]获取给定位置周围的标识符,如果没有标识符,则为null

代码示例

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

} else { // no selection, get current word
  try {
    searchWord = Utilities.getIdentifier((BaseDocument)target.getDocument(),
                       dotPos);
    revert =  !Boolean.TRUE.equals(props.put(SettingsNames.FIND_WHOLE_WORDS, Boolean.TRUE));

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

/**
 * Helper method to get the identifier under the mouse cursor.
 * 
 * @return string containing identifier under mouse cursor.
 */
public String getIdentifierUnderCursor() {
  String word = null;
  try {
    JTextComponent component = extEditorUI.getComponent();
    BaseTextUI ui = (BaseTextUI) component.getUI();
    int pos = ui.viewToModel(component, lastMouseEvent.getPoint());
    if (pos >= 0) {
      BaseDocument doc = (BaseDocument) component.getDocument();
      int eolPos = Utilities.getRowEnd(doc, pos);
      Rectangle eolRect = ui.modelToView(component, eolPos);
      int lineHeight = extEditorUI.getLineHeight();
      if (lastMouseEvent.getX() <= eolRect.x && lastMouseEvent.getY() <= eolRect.y + lineHeight) {
        word = Utilities.getIdentifier(doc, pos);
      }
    }
  } catch (BadLocationException e) {
    // word will be null
  }
  return word;
}

代码示例来源: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.java.abeille/abeille

public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
      FindSupport findSupport = FindSupport.getFindSupport();
      Caret caret = target.getCaret();
      int dotPos = caret.getDot();
      HashMap props = new HashMap(findSupport.getFindProperties());
      String searchWord = null;
      if (caret.isSelectionVisible()) { // valid selection
        searchWord = target.getSelectedText();
        props.put(SettingsNames.FIND_WHOLE_WORDS, Boolean.FALSE);
      }
      else { // no selection, get current word
        try {
          searchWord = Utilities.getIdentifier((BaseDocument) target.getDocument(), dotPos);
          props.put(SettingsNames.FIND_WHOLE_WORDS, Boolean.TRUE);
        } catch (BadLocationException e) {
          e.printStackTrace();
        }
      }
      if (searchWord != null) {
        int n = searchWord.indexOf('\n');
        if (n >= 0)
          searchWord = searchWord.substring(0, n);
        props.put(SettingsNames.FIND_WHAT, searchWord);
        findSupport.putFindProperties(props);
        findSupport.find(null, false);
      }
    }
  }
}

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

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

/** Helper method to get the identifier
 * under the mouse cursor.
 * @return string containing identifier under
 * mouse cursor.
 */
public String getIdentifierUnderCursor() {
  String word = null;
  if (!isGlyphGutterMouseEvent(lastMouseEvent)) {
    try {
      JTextComponent component = extEditorUI.getComponent();
      BaseTextUI ui = (BaseTextUI)component.getUI();
      Point lmePoint = getLastMouseEventPoint();
      int pos = ui.viewToModel(component, lmePoint);
      if (pos >= 0) {
        BaseDocument doc = (BaseDocument)component.getDocument();
        int eolPos = Utilities.getRowEnd(doc, pos);
        Rectangle eolRect = ui.modelToView(component, eolPos);
        int lineHeight = extEditorUI.getLineHeight();
        if (lmePoint.x <= eolRect.x && lmePoint.y <= eolRect.y + lineHeight) {
          word = Utilities.getIdentifier(doc, pos);
        }
      }
    } catch (BadLocationException e) {
      // word will be null
    }
  }
  return word;
}

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

if (lineBounds.containsInclusive(caretOffset) && fileObject != null) {
  try {
    String identifier = Utilities.getIdentifier(doc, caretOffset);
    if (identifier != null && identifier.startsWith("$")) {
      PHPParseResult parseResult = (PHPParseResult) context.parserResult;

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

try {
  ident = Utilities.getIdentifier( doc, caret);
} catch (BadLocationException e) {
  ErrorManager.getDefault().notify(e);

相关文章