Community
Participate
Working Groups
Build Identifier: 20110916-0149 If a user's selection begins from within a comment, the Extract Method refactoring tool will complain by showing the error message: "Selection begins inside a comment" and prevent the user from continuing the refactoring. However, Eclipse could have been more flexible, automatically widened or narrowed the selection to include or exclude the overlapping comment, and informed the user about the auto correction of the selection. We learned from the CodingSpectator <http://codingspectator.cs.illinois.edu/> study that programmers prefer flexible refactoring tools than restrictive ones that stop programmers from performing the refactoring for failures of preconditions. Therefore, we suggest that the refactoring tools be more flexible and let the user continue the refactoring when her selection overlaps with a comment. See Bug 365129 for the desirability of flexible refactoring tools. Fortunately, programmers rarely overlap their selections with comments. Only one of our participants got the error message "Selection begins inside a comment". In that case, our participant had begun his selection at the end of a line comment (See below for an example of such a selection). Consequently, Eclipse reported an error and prevented the user from continuing the refactoring. In this case, our participant quickly figured out the problem and reinvoked the Extract Method refactoring with a selection that didn't overlap with the comment line. Although such selection problems seem to be rare it would have been nice if Eclipse had automatically narrowed the selection in this case to begin at the line following the comment line. Reproducible: Always Steps to Reproduce: 1. The "[" and "]" characters in the following piece of code are selection markers. ---- public class C { void m() { // a comment[ System.out.println("statement 1"); System.out.println("statement 2");] } } ---- 2. Invoke Refactor > Extact Method. 3. The refactoring tool will report the error message "Selection begins inside a comment" and prevent the user from continuing the refactoring.
Created attachment 207819 [details] An example of a problem when the selection begins at the end of a line comment. The screenshot corresponds to the example described in <https://bugs.eclipse.org/bugs/show_bug.cgi?id=365372#c0>.
This bug might be related to Bug 41302.
A very rare scenario, and hence low priority.
This doesn't seem so rare: I stumbled upon this issue a few times already. For example, with this code: private void abc() { /** * This is a javadoc comment * <p> * Inside a method. */ final String abc = "test"; System.out.println(abc); } I cannot extract the contents of the method into another method: - if I select everything inside the method body, I get the error "The beginning of the selection contains characters that do not belong to a statement." - if I select the last two lines from the method body (omitting the javadoc comment), I get "Not all selected statements are enclosed by the same parent statement." These error messages make no sense in this context. Granted, we're not supposed to put javadoc comments *inside* methods like this, but I did in my case because I wanted to add a long comment with paragraphs and get them formatted properly by the JDT formatter.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.