当前位置: 首页>>代码示例>>Java>>正文


Java Utilities.getIdentifierBlock方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ExtKit.java

示例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);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:AddCaretSelectNextAction.java

示例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) {
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:GotoAction.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:NbEditorUtilities.java

示例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);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:AddCaretSelectAllAction.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:48,代码来源:CompletionImpl.java


注:本文中的org.netbeans.editor.Utilities.getIdentifierBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。