本文整理汇总了Java中org.netbeans.editor.Utilities.getIdentifierBlock方法的典型用法代码示例。如果您正苦于以下问题:Java Utilities.getIdentifierBlock方法的具体用法?Java Utilities.getIdentifierBlock怎么用?Java Utilities.getIdentifierBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.editor.Utilities
的用法示例。
在下文中一共展示了Utilities.getIdentifierBlock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gotoDeclaration
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public boolean gotoDeclaration(JTextComponent target) {
BaseDocument doc = Utilities.getDocument(target);
if (doc == null)
return false;
try {
Caret caret = target.getCaret();
int dotPos = caret.getDot();
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;
}
示例2: actionPerformed
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
Caret caret = target.getCaret();
if (Utilities.isSelectionShowing(caret)) {
EditorFindSupport findSupport = EditorFindSupport.getInstance();
HashMap<String, Object> props = new HashMap<>(findSupport.createDefaultFindProperties());
String searchWord = target.getSelectedText();
int n = searchWord.indexOf('\n');
if (n >= 0) {
searchWord = searchWord.substring(0, n);
}
props.put(EditorFindSupport.FIND_WHAT, searchWord);
props.put(EditorFindSupport.ADD_MULTICARET, Boolean.TRUE);
EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(target);
if (eui.getComponent().getClientProperty("AsTextField") == null) { //NOI18N
findSupport.setFocusedTextComponent(eui.getComponent());
}
findSupport.putFindProperties(props);
findSupport.find(null, false);
props.put(EditorFindSupport.ADD_MULTICARET, Boolean.FALSE);
findSupport.putFindProperties(props);
} else {
try {
int[] identifierBlock = Utilities.getIdentifierBlock((BaseDocument) target.getDocument(), caret.getDot());
if (identifierBlock != null) {
caret.setDot(identifierBlock[0]);
caret.moveDot(identifierBlock[1]);
}
} catch (BadLocationException e) {
LOGGER.log(Level.WARNING, null, e);
}
}
}
}
示例3: actionPerformed
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
String actionName = actionName();
if (EditorActionNames.gotoDeclaration.equals(actionName)) {
resetCaretMagicPosition(target);
if (target != null) {
if (hyperlinkGoTo(target)) {
return;
}
BaseDocument doc = Utilities.getDocument(target);
if (doc != null) {
try {
Caret caret = target.getCaret();
int dotPos = caret.getDot();
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);
}
}
} catch (BadLocationException e) {
}
}
}
}
}
示例4: getIdentifierAndMethodBlock
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
/** This method is a composition of <tt>Utilities.getIdentifierBlock()</tt>
* and <tt>SyntaxSupport.getFunctionBlock()</tt>.
* @return null if there's no identifier at the given position.
* identifier block if there's identifier but it's not a function call.
* three member array for the case that there is an identifier followed
* by the function call character. The first two members are members
* of the identifier block and the third member is the second member
* of the function block.
*/
public static int[] getIdentifierAndMethodBlock(BaseDocument doc, int offset)
throws BadLocationException {
int[] idBlk = Utilities.getIdentifierBlock(doc, offset);
if (idBlk != null) {
int[] funBlk = ((ExtSyntaxSupport)doc.getSyntaxSupport()).getFunctionBlock(idBlk);
if (funBlk != null) {
return new int[] { idBlk[0], idBlk[1], funBlk[1] };
}
}
return idBlk;
}
示例5: actionPerformed
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
Caret caret = target.getCaret();
if (!Utilities.isSelectionShowing(caret)) {
try {
int[] identifierBlock = Utilities.getIdentifierBlock((BaseDocument) target.getDocument(), caret.getDot());
if (identifierBlock != null) {
caret.setDot(identifierBlock[0]);
caret.moveDot(identifierBlock[1]);
}
} catch (BadLocationException e) {
LOGGER.log(Level.WARNING, null, e);
}
}
EditorFindSupport findSupport = EditorFindSupport.getInstance();
HashMap<String, Object> props = new HashMap<>(findSupport.createDefaultFindProperties());
String searchWord = target.getSelectedText();
if (searchWord != null) {
int n = searchWord.indexOf('\n');
if (n >= 0) {
searchWord = searchWord.substring(0, n);
}
props.put(EditorFindSupport.FIND_WHAT, searchWord);
Document doc = target.getDocument();
EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(target);
if (eui.getComponent().getClientProperty("AsTextField") == null) { //NOI18N
findSupport.setFocusedTextComponent(eui.getComponent());
}
findSupport.putFindProperties(props);
findSupport.find(null, false);
if (caret instanceof EditorCaret) {
EditorCaret editorCaret = (EditorCaret) caret;
try {
int[] blocks = findSupport.getBlocks(new int[]{-1, -1}, doc, 0, doc.getLength());
if (blocks[0] >= 0 && blocks.length % 2 == 0) {
List<Position> newCarets = new ArrayList<>();
for (int i = 0; i < blocks.length; i += 2) {
int start = blocks[i];
int end = blocks[i + 1];
if (start == -1 || end == -1) {
break;
}
Position startPos = doc.createPosition(start);
Position endPos = doc.createPosition(end);
newCarets.add(endPos);
newCarets.add(startPos);
}
editorCaret.replaceCarets(newCarets, null); // TODO handle biases
}
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
}
示例6: getCompletionPreSelectionIndex
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private int getCompletionPreSelectionIndex(List<CompletionItem> items) {
String prefix = null;
if(getActiveDocument() instanceof BaseDocument) {
BaseDocument doc = (BaseDocument)getActiveDocument();
int caretOffset = getActiveComponent().getSelectionStart();
try {
int[] block = Utilities.getIdentifierBlock(doc, caretOffset);
if (block != null) {
block[1] = caretOffset;
prefix = doc.getText(block);
}
} catch (BadLocationException ble) {
}
}
int closestIdx = 0;
if (prefix != null && prefix.length() > 0) {
int distance = Integer.MAX_VALUE;
int idx = 0;
String prefLC = prefix.toLowerCase();
for (CompletionItem item : items) {
CharSequence text = item.getInsertPrefix();
int prio = item.getSortPriority() * 1000;
boolean isSmart = prio < 0;
String name = text != null ? text.toString() : null;
if (name != null) {
for (String part : name.split("\\.")) {
if (part.startsWith(prefix) && (!(item instanceof LazyCompletionItem) || ((LazyCompletionItem)item).accept())) {
return idx;
}
int d = prio + getDistance(part.toLowerCase(), prefLC);
if (part.toLowerCase().startsWith(prefLC)) {
d -= 500;
}
if (d < distance) {
distance = d;
closestIdx = idx;
}
if (!isSmart) {
break;
}
}
}
idx++;
}
}
return closestIdx;
}