This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
When using Refactor->Introduce method, the new method will appear at somewhat random locations in the file (although it appears to be based on the method name, see below for example), and sometimes very far away from the original method. Expected behavior should be: put the method adjacent to the previous method, ideally directly below it. Small example: package testrefactor; public class Main { public static void main(String[] args) { blah(); } private static void blah() { int i = 5; } } If you highlight "int i=5;", and introduce a method called "a", then the method "a" appears ABOVE blah(). If you highlight "int i=5;", and introduce a method called "c", then the method "c" appears BELOW blah().
I don't think this is a defect, but this behavior could certainly enhance user's experience, IMO -> P2 Enhancement.
Created attachment 78859 [details] Patch that fixes the sorting issue for introduced methods
The attached patch should fix the issue. The problem was caused because introduced methods were being sorted in the same way as introduced classes. (Although classes have a defined order per the Java Sun coding standards, methods are to be put in a functional order, so this fix makes sense.) I was not certain if the fix also needed to be applied to the class IntroduceExpressionBasedMethodFix, so I left that one the same. If it does need to be applied to that class, it should only require changing the same three lines as changed in IntroduceMethodFix.
Can this be added to the 6.8 release? There is an attached patch for this.
Thanks for your contribution. There is already an implementation in org.netbeans.api.java.source.GeneratorUtilities, which adds even more logic. ie. GeneratorUtilities.get(copy).insertClassMember((ClassTree)pathToClass.getLeaf(), method); I'll fix this soon.
Fixed. --- http://hg.netbeans.org/jet-main/rev/27d3056062a7
Integrated into 'main-golden', will be available in build *200909021401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/27d3056062a7 User: Max Sauer <msauer@netbeans.org> Log: #152701: "Introduce method" puts new method in an arbitrary location
I verified that the original sample works. However, a similar one does not. public class Main { private void main() {} void blah() { int i=5; } } If you highlight "int i=5;", and introduce a method called "a", then the method "a" appears ABOVE main(). If you highlight "int i=5;", and introduce a method called "c", then the method "c" appears BELOW blah().