本文整理了Java中org.netbeans.editor.Utilities.getIdentifierBlock()
方法的一些代码示例,展示了Utilities.getIdentifierBlock()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.getIdentifierBlock()
方法的具体详情如下:
包路径:org.netbeans.editor.Utilities
类名称:Utilities
方法名:getIdentifierBlock
[英]Get the identifier around the given position or null if there's no identifier around the given position. The identifier is not verified against SyntaxSupport.isIdentifier().
[中]获取给定位置周围的标识符,如果给定位置周围没有标识符,则为null。未根据SyntaxSupport验证标识符。isIdentifier()。
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/** Get the word around the given position .
* @param c component to work with
* @param offset position in document - usually the caret.getDot()
* @return the word.
*/
public static String getWord(JTextComponent c, int offset)
throws BadLocationException {
int[] blk = getIdentifierBlock(c, offset);
Document doc = c.getDocument();
return (blk != null) ? doc.getText(blk[0], blk[1] - blk[0]) : null;
}
代码示例来源:origin: net.java.abeille/abeille
/**
* Get the identifier around the given position or null if there's no
* identifier
*
* @see getIdentifierBlock()
*/
public static String getIdentifier(BaseDocument doc, int offset) throws BadLocationException {
int[] blk = getIdentifierBlock(doc, offset);
return (blk != null) ? doc.getText(blk[0], blk[1] - blk[0]) : null;
}
代码示例来源: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
* @see getIdentifierBlock()
*/
public static String getIdentifier(BaseDocument doc, int offset)
throws BadLocationException {
int[] blk = getIdentifierBlock(doc, offset);
return (blk != null) ? doc.getText(blk[0], blk[1] - blk[0]) : null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-completion
private static int[] getIdentifierAndMethodBlock(BaseDocument doc, int offset)
throws BadLocationException {
int[] idBlk = Utilities.getIdentifierBlock(doc, offset);
if (idBlk != null) {
int[] funBlk = getFunctionBlock(doc, idBlk);
if (funBlk != null) {
return new int[] { idBlk[0], idBlk[1], funBlk[1] };
}
}
return idBlk;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-completion
private static int[] getIdentifierAndInstantiationBlock(BaseDocument doc, int offset) throws BadLocationException {
int[] idBlk = Utilities.getIdentifierBlock(doc, offset);
if (idBlk != null) {
int[] instBlk = getInstantiationBlock(doc, idBlk);
if (instBlk != null) {
return new int[] { idBlk[0], idBlk[1], instBlk[1] };
}
}
return idBlk;
}
代码示例来源:origin: net.java.abeille/abeille
public int[] getFunctionBlock(int offset) throws BadLocationException {
return getFunctionBlock(Utilities.getIdentifierBlock(getDocument(), offset));
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public int[] getFunctionBlock(int offset) throws BadLocationException {
return getFunctionBlock(Utilities.getIdentifierBlock(getDocument(), offset));
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public JavaFastImport(JTextComponent target) {
this.target = target;
try{
block = Utilities.getIdentifierBlock (target, target.getCaret().getDot());
javax.swing.text.Document doc = target.getDocument();
exp = (block != null) ? doc.getText(block[0], block[1] - block[0]) : null;
}catch(BadLocationException ble){
ble.printStackTrace();
}
importType = getPackageImportSetting();
// Bugfix for #26966
if (exp != null) {
// Eliminating extra spaces
String untrimmedExp = exp;
exp = exp.trim();
// Recalculating block beginning and ending
int nLeadingSpaces = untrimmedExp.indexOf(exp);
int nTrailingSpaces = untrimmedExp.length() - exp.length() - nLeadingSpaces;
block[0] += nLeadingSpaces;
block[1] -= nTrailingSpaces;
}
}
代码示例来源: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.
* @param c component to work with
* @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[] getSelectionOrIdentifierBlock(JTextComponent c, int offset)
throws BadLocationException {
Document doc = c.getDocument();
Caret caret = c.getCaret();
int[] ret;
if (caret.isSelectionVisible()) {
ret = new int[] { c.getSelectionStart(), c.getSelectionEnd() };
} else if (doc instanceof BaseDocument){
ret = getIdentifierBlock((BaseDocument)doc, caret.getDot());
} else {
ret = getIdentifierBlock(c, offset);
}
return ret;
}
代码示例来源:origin: net.java.abeille/abeille
try {
int[] block = org.netbeans.editor.Utilities.getIdentifierBlock(doc, dotPos);
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
if (!target.isEditable() || !target.isEnabled()) {
target.getToolkit().beep();
return;
}
try {
Caret caret = target.getCaret();
BaseDocument doc = (BaseDocument)target.getDocument();
int[] idBlk = Utilities.getIdentifierBlock(doc, caret.getDot());
if (idBlk != null) {
Utilities.changeCase(doc, idBlk[0], 1, Utilities.CASE_SWITCH);
}
} catch (BadLocationException e) {
target.getToolkit().beep();
}
}
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-editor-deprecated-pre61completion
private synchronized boolean instantSubstitutionImpl(int caretPos){
if (getLastResult() == null) return false;
JTextComponent comp = extEditorUI.getComponent();
try{
if (comp != null) {
int[] block = Utilities.getIdentifierBlock(comp,caretPos);
if (block == null || block[1] == caretPos)
return getLastResult().substituteText(0, false);
}
}catch(BadLocationException ble){
}
return false;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
try {
int[] block = org.netbeans.editor.Utilities.getIdentifierBlock(doc, dotPos);
代码示例来源:origin: net.java.abeille/abeille
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
if (!target.isEditable() || !target.isEnabled()) {
target.getToolkit().beep();
return;
}
try {
Caret caret = target.getCaret();
BaseDocument doc = (BaseDocument) target.getDocument();
int[] idBlk = Utilities.getIdentifierBlock(doc, caret.getDot());
if (idBlk != null) {
Utilities.changeCase(doc, idBlk[0], 1, Utilities.CASE_SWITCH);
}
} catch (BadLocationException e) {
target.getToolkit().beep();
}
}
}
}
代码示例来源:origin: net.java.abeille/abeille
/**
* Get the selection if there's any or get the identifier around the
* position if there's no selection.
*
* @param c
* component to work with
* @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[] getSelectionOrIdentifierBlock(JTextComponent c, int offset) throws BadLocationException {
BaseDocument doc = (BaseDocument) c.getDocument();
Caret caret = c.getCaret();
int[] ret;
if (caret.isSelectionVisible()) {
ret = new int[] { c.getSelectionStart(), c.getSelectionEnd() };
}
else {
ret = getIdentifierBlock(doc, caret.getDot());
}
return ret;
}
代码示例来源:origin: net.java.abeille/abeille
public boolean gotoDeclaration(JTextComponent target) {
try {
Caret caret = target.getCaret();
int dotPos = caret.getDot();
BaseDocument doc = (BaseDocument) target.getDocument();
int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos);
ExtSyntaxSupport extSup = (ExtSyntaxSupport) doc.getSyntaxSupport();
if (idBlk != null) {
int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]);
if (decPos >= 0) {
caret.setDot(decPos);
return true;
}
}
} catch (BadLocationException e) {
}
return false;
}
代码示例来源:origin: net.java.abeille/abeille
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
Caret caret = target.getCaret();
try {
if (caret.isSelectionVisible()) {
caret.setSelectionVisible(false); // unselect if
// anything selected
}
else { // selection not visible
int block[] = Utilities.getIdentifierBlock((BaseDocument) target.getDocument(), caret.getDot());
if (block != null) {
caret.setDot(block[0]);
caret.moveDot(block[1]);
}
}
} catch (BadLocationException e) {
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 {
if (caret.isSelectionVisible()) {
caret.setSelectionVisible(false); // unselect if anything selected
} else { // selection not visible
int block[] = Utilities.getIdentifierBlock((BaseDocument)target.getDocument(),
caret.getDot());
if (block != null) {
caret.setDot(block[0]);
caret.moveDot(block[1]);
}
}
} catch (BadLocationException e) {
target.getToolkit().beep();
}
}
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public boolean gotoDeclaration(JTextComponent target) {
try {
Caret caret = target.getCaret();
int dotPos = caret.getDot();
BaseDocument doc = (BaseDocument)target.getDocument();
int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos);
ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport();
if (idBlk != null) {
int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]);
if (decPos >= 0) {
caret.setDot(decPos);
return true;
}
}
} catch (BadLocationException e) {
}
return false;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf
org.netbeans.editor.Utilities.getIdentifierBlock((BaseDocument)doc,
offset);
内容来源于网络,如有侵权,请联系作者删除!