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

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

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

Utilities.getWordEnd介绍

暂无

代码示例

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

public static int getWordEnd(JTextComponent c, int offset) throws BadLocationException {
  return getWordEnd((BaseDocument) c.getDocument(), offset);
}

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

public static int getWordEnd(JTextComponent c, int offset)
throws BadLocationException {
  return getWordEnd((BaseDocument)c.getDocument(), offset);
}

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

/** Get the word at given position.
*/
public static String getWord(BaseDocument doc, int offset)
throws BadLocationException {
  int wordEnd = getWordEnd(doc, offset);
  if (wordEnd != -1) {
    return new String(doc.getChars(offset, wordEnd - offset), 0,
             wordEnd - offset);
  }
  return null;
}

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

/**
 * Get the word at given position.
 */
public static String getWord(BaseDocument doc, int offset) throws BadLocationException {
  int wordEnd = getWordEnd(doc, offset);
  if (wordEnd != -1) {
    return new String(doc.getChars(offset, wordEnd - offset), 0, wordEnd - offset);
  }
  return null;
}

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

private synchronized boolean instantSubstitutionImpl(int caretPos){
  if (getLastResult() == null) return false;
  JTextComponent comp = extEditorUI.getComponent();
  try{
    if ((comp == null) || Utilities.getWordEnd(comp,caretPos) > caretPos) return false;
    return getLastResult().substituteText(0, false);
  }catch(BadLocationException ble){
    return false;
  }
}

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

public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
      Caret caret = target.getCaret();
      try {
        int dot = Utilities.getWordEnd(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.getWordEnd(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

/** 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.java.abeille/abeille

int idStart = getWordStart(doc, offset);
if (idStart >= 0) {
  int idEnd = getWordEnd(doc, idStart);
  if (idEnd >= 0) {
    String id = doc.getText(idStart, idEnd - idStart);

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

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

相关文章