问题
I'm really curious if anyone knows if Eclipse's Content Assist can be configured to display a code block's declaration by hovering over the block's closing brace (or something similar).
Rather than having to mark long code blocks with a comment, I would much rather hover over the closing brace to view which block it ends.
If what I'm saying isn't clear, imagine you had the code block below:
if (obj instanceof Double)
{
//...PROGRAM LOGIC...
}
In this example, if I were to move the caret to the end brace, right-click the end brace, or simply hover over it. A popup window would show giving me the original declaration at the top:
if (obj instanceof Double) { //...
Also, I'm interested to know if this can be done in Visual Studio; I've asked that question here.
回答1:
This is nothing to do with content assist.
You can see the block of code as explained below.
Collapse all methods(By pressing Ctrl+Shift+NUM_KEYPAD_DIVIDE. Note you can expand all methods by pressing Ctrl+Shift+NUM_KEYPAD_MULTIPLY)
Hover the mouse cursor towards method collapse icon "+" as shown below.
You will see the content of the method in a popup window. Now press F2 to freez this popup and press ESC to close the popup. Scroll back and forth to see the content. Note that this works for methods, javadocs and import statements only and not for other block statements inside methods and on CLASS body.
Refer How to use Coffee-Bytes code folding for if block folding and try to check the if block content as said above.
Also you can check the scope of block statements by keeping caret after the block start("{") or block end("}") flower brackets and double clicking on it.
See below
You can expand or reduce the block selection by pressing Alt + Shift + Up Arrow and Alt + Shift + Down Arrow respectively and jump to matching bracket(Like "( or )", "{ or }") by keeping caret after the bracket and pressing Ctrl + Shift + P
回答2:
You mean something like this, when hovering over the closing brace of a code block?
It seems, that this feature has already been implemented and is by default enabled - at least for org.eclipse.jdt.ui_3.9.1.v20140306-2106.
One can enable/disable this text hover (and others) by going to Window/Preferences/Java/Editor/Hovers
and selecting the corresponding Source
hover. By default the source hover will be activated when pressing "shift" while hovering. When the "Combined Hover" is activated, the source hover should also be automatically be activated without pressing any additional keys.
Note also, that it is quite easy to implement a custom text hover for JDT by writing a plugin and extending the org.eclipse.jdt.ui.javaEditorTextHovers
extension point. As an example for how this can be done, have a look at the code of one of the default JDT hovers.
来源:https://stackoverflow.com/questions/22566885/eclipse-content-assist-for-viewing-block-declarations-from-the-closing-brace