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


Java Utilities.getIdentifier方法代码示例

本文整理汇总了Java中org.netbeans.editor.Utilities.getIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Java Utilities.getIdentifier方法的具体用法?Java Utilities.getIdentifier怎么用?Java Utilities.getIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.editor.Utilities的用法示例。


在下文中一共展示了Utilities.getIdentifier方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIdentifierUnderCursor

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
/** 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:ToolTipSupport.java

示例2: invokeInstantRename

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void invokeInstantRename(final Lookup lookup, final EditorCookie ec) {
    try {
        JEditorPane target = ec.getOpenedPanes()[0];
        final int caret = target.getCaretPosition();
        String ident = Utilities.getIdentifier(Utilities.getDocument(target), caret);
        
        if (ident == null) {
            Utilities.setStatusBoldText(target, WARN_CannotPerformHere());
            return;
        }
        
        DataObject od = (DataObject) target.getDocument().getProperty(Document.StreamDescriptionProperty);
        JavaSource js = od != null ? JavaSource.forFileObject(od.getPrimaryFile()) : null;

        if (js == null) {
            Utilities.setStatusBoldText(target, WARN_CannotPerformHere());
            return;
        }
        InstantRefactoringUI ui = InstantRefactoringUIImpl.create(js, caret);
        
        if (ui != null) {
            if (ui.getRegions().isEmpty() || ui.getKeyStroke() == null) {
                doFullRename(lookup);
            } else {
                doInstantRename(target, js, caret, ui);
            }
        } else {
            Utilities.setStatusBoldText(target, WARN_CannotPerformHere());
        }
    } catch (BadLocationException e) {
        Exceptions.printStackTrace(e);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:RefactoringActionsProvider.java

示例3: actionPerformed

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        EditorFindSupport findSupport = EditorFindSupport.getInstance();
        Caret caret = target.getCaret();
        int dotPos = caret.getDot();
        HashMap<String, Object> props = new HashMap<>(findSupport.createDefaultFindProperties());
        String searchWord = null;
        boolean revert = false;
        Boolean originalValue = null;
        Map<String, Object> revertMap = (Map<String, Object>) props.get(EditorFindSupport.REVERT_MAP);
        Boolean revertValue = revertMap != null ? (Boolean) revertMap.get(EditorFindSupport.FIND_WHOLE_WORDS) : null;
        if (Utilities.isSelectionShowing(caret)) {
            // valid selection
            searchWord = target.getSelectedText();
            originalValue = (Boolean) props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
            if (Boolean.FALSE.equals(revertValue)) {
                revertMap.remove(EditorFindSupport.FIND_WHOLE_WORDS);
            } else {
                revert = !Boolean.FALSE.equals(originalValue);
            }
        } else {
            // no selection, get current word
            try {
                searchWord = Utilities.getIdentifier((BaseDocument) target.getDocument(), dotPos);
                originalValue = (Boolean) props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.TRUE);
                if (Boolean.TRUE.equals(revertValue)) {
                    revertMap.remove(EditorFindSupport.FIND_WHOLE_WORDS);
                } else {
                    revert = !Boolean.TRUE.equals(originalValue);
                }
            } catch (BadLocationException e) {
                LOGGER.log(Level.WARNING, null, e);
            }
        }
        if (searchWord != null) {
            int n = searchWord.indexOf('\n');
            if (n >= 0) {
                searchWord = searchWord.substring(0, n);
            }
            props.put(EditorFindSupport.FIND_WHAT, searchWord);
            if (revert) {
                revertMap = new HashMap<>();
                revertMap.put(EditorFindSupport.FIND_WHOLE_WORDS, originalValue != null ? originalValue : Boolean.FALSE);
                props.put(EditorFindSupport.REVERT_MAP, revertMap);
            }
            props.put(EditorFindSupport.FIND_BLOCK_SEARCH, Boolean.FALSE);
            props.put(EditorFindSupport.FIND_BLOCK_SEARCH_START, null);
            props.put(EditorFindSupport.FIND_BLOCK_SEARCH_END, null);
            EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(target);
            if (eui.getComponent().getClientProperty("AsTextField") == null) {
                //NOI18N
                findSupport.setFocusedTextComponent(eui.getComponent());
            }
            findSupport.putFindProperties(props);
            if (findSupport.find(null, false)) {
                findSupport.addToHistory(new EditorFindSupport.SPW((String) props.get(EditorFindSupport.FIND_WHAT), (Boolean) props.get(EditorFindSupport.FIND_WHOLE_WORDS), (Boolean) props.get(EditorFindSupport.FIND_MATCH_CASE), (Boolean) props.get(EditorFindSupport.FIND_REG_EXP)));
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:FindSelectionAction.java

示例4: invokeInstantRename

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public static void invokeInstantRename(JTextComponent target) {
    try {
        final int caret = target.getCaretPosition();
        String ident = Utilities.getIdentifier(Utilities.getDocument(target), caret);
        
        if (ident == null) {
            Utilities.setStatusBoldText(target, NbBundle.getMessage(InstantRenamePerformer.class, "WARN_CannotPerformHere"));
            return;
        }
        
        DataObject od = (DataObject) target.getDocument().getProperty(Document.StreamDescriptionProperty);
        JavaSource js = od != null ? JavaSource.forFileObject(od.getPrimaryFile()) : null;

        if (js == null) {
            Utilities.setStatusBoldText(target, NbBundle.getMessage(InstantRenamePerformer.class, "WARN_CannotPerformHere"));
            return ;
        }
        
        final boolean[] wasResolved = new boolean[1];

        Set<Token> changePoints = ComputeOffAWT.computeOffAWT(new Worker<Set<Token>>() {
            @Override
            public Set<Token> process(CompilationInfo info) {
                try {
                    return computeChangePoints(info, caret, wasResolved);
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                    return null;
                }
            }
        }, "Instant Rename", js, Phase.RESOLVED);
        
        if (wasResolved[0]) {
            if (changePoints != null) {
                doInstantRename(changePoints, target, caret, ident);
            } else {
                doFullRename(od.getCookie(EditorCookie.class), od.getNodeDelegate());
            }
        } else {
            Utilities.setStatusBoldText(target, NbBundle.getMessage(InstantRenamePerformer.class, "WARN_CannotPerformHere"));
        }
    } catch (BadLocationException e) {
        Exceptions.printStackTrace(e);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:InstantRenamePerformer.java


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