如何识别所选代码是方法、函数、变量...???
public class Modifiers implements IObjectActionDelegate{
private Shell shell;
public void run(IAction action) {
SelectedText selectedText;
IEditorPart editor = getActiveEditor();
if (editor instanceof AbstractTextEditor) {
selectedText = getSelectedText(editor);
//HOW TO IDENTIFY THE SELECTED CODE
}
}
public void selectionChanged(IAction action, ISelection selection) {
}
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
shell = targetPart.getSite().getShell();
}
private IEditorPart getActiveEditor() {
return Activator.getDefault().getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor();
}
private SelectedText getSelectedText(IEditorPart editor) {
SelectedText selectedText;
try {
final ISelection selection = editor.getEditorSite().getSelectionProvider().getSelection();
final ITextSelection textSelection = (ITextSelection) selection;
selectedText = new SelectedText(textSelection.getText(), textSelection.getOffset(), textSelection.getLength());
} catch (Exception e) {
selectedText = new SelectedText("", 0, 0);
}
return selectedText;
}
}
如您所见,我在selectedText
. 现在我想知道如何确定该变量中的代码是方法、变量还是它包含的任何内容。
使用 eclipse 进行重构时,它会显示您选择的代码信息。这个想法是做类似的事情。
谢谢你的帮助。