@@ -88,6 +88,45 @@ public void testExtractVariable() throws Exception {
8888 Assert .assertEquals (1 , refactorEdit .command .getArguments ().size ());
8989 }
9090
91+ @ Test
92+ public void testExtractVariableFinal () throws Exception {
93+ preferences .setCodeGenerationAddFinalForNewDeclaration ("all" );
94+
95+ IPackageFragment pack1 = fSourceFolder .createPackageFragment ("test1" , false , null );
96+
97+ StringBuilder buf = new StringBuilder ();
98+ buf .append ("package test1;\n " );
99+ buf .append ("class A{\n " );
100+ buf .append (" void m(int i){\n " );
101+ buf .append (" int x= /*]*/0/*[*/;\n " );
102+ buf .append (" }\n " );
103+ buf .append ("}\n " );
104+
105+ ICompilationUnit cu = pack1 .createCompilationUnit ("E.java" , buf .toString (), false , null );
106+ Range selection = getRange (cu , null );
107+ CodeActionParams params = CodeActionUtil .constructCodeActionParams (cu , selection );
108+ GetRefactorEditParams editParams = new GetRefactorEditParams (RefactorProposalUtility .EXTRACT_VARIABLE_COMMAND , params );
109+ RefactorWorkspaceEdit refactorEdit = GetRefactorEditHandler .getEditsForRefactor (editParams );
110+ Assert .assertNotNull (refactorEdit );
111+ Assert .assertNotNull (refactorEdit .edit );
112+ String actual = AbstractQuickFixTest .evaluateWorkspaceEdit (refactorEdit .edit );
113+
114+ buf = new StringBuilder ();
115+ buf .append ("package test1;\n " );
116+ buf .append ("class A{\n " );
117+ buf .append (" void m(int i){\n " );
118+ buf .append (" final int j = 0;\n " );
119+ buf .append (" int x= /*]*/j/*[*/;\n " );
120+ buf .append (" }\n " );
121+ buf .append ("}\n " );
122+ AbstractSourceTestCase .compareSource (buf .toString (), actual );
123+
124+ Assert .assertNotNull (refactorEdit .command );
125+ Assert .assertEquals (GetRefactorEditHandler .RENAME_COMMAND , refactorEdit .command .getCommand ());
126+ Assert .assertNotNull (refactorEdit .command .getArguments ());
127+ Assert .assertEquals (1 , refactorEdit .command .getArguments ().size ());
128+ }
129+
91130 @ Test
92131 public void testExtractVariableAllOccurrence () throws Exception {
93132 IPackageFragment pack1 = fSourceFolder .createPackageFragment ("test1" , false , null );
@@ -125,6 +164,45 @@ public void testExtractVariableAllOccurrence() throws Exception {
125164 Assert .assertEquals (1 , refactorEdit .command .getArguments ().size ());
126165 }
127166
167+ @ Test
168+ public void testExtractVariableAllOccurrenceFinal () throws Exception {
169+ preferences .setCodeGenerationAddFinalForNewDeclaration ("all" );
170+
171+ IPackageFragment pack1 = fSourceFolder .createPackageFragment ("test1" , false , null );
172+
173+ StringBuilder buf = new StringBuilder ();
174+ buf .append ("package test1;\n " );
175+ buf .append ("class A{\n " );
176+ buf .append (" void m(int i){\n " );
177+ buf .append (" int x= /*]*/0/*[*/;\n " );
178+ buf .append (" }\n " );
179+ buf .append ("}\n " );
180+
181+ ICompilationUnit cu = pack1 .createCompilationUnit ("E.java" , buf .toString (), false , null );
182+ Range selection = getRange (cu , null );
183+ CodeActionParams params = CodeActionUtil .constructCodeActionParams (cu , selection );
184+ GetRefactorEditParams editParams = new GetRefactorEditParams (RefactorProposalUtility .EXTRACT_VARIABLE_ALL_OCCURRENCE_COMMAND , params );
185+ RefactorWorkspaceEdit refactorEdit = GetRefactorEditHandler .getEditsForRefactor (editParams );
186+ Assert .assertNotNull (refactorEdit );
187+ Assert .assertNotNull (refactorEdit .edit );
188+ String actual = AbstractQuickFixTest .evaluateWorkspaceEdit (refactorEdit .edit );
189+
190+ buf = new StringBuilder ();
191+ buf .append ("package test1;\n " );
192+ buf .append ("class A{\n " );
193+ buf .append (" void m(int i){\n " );
194+ buf .append (" final int j = 0;\n " );
195+ buf .append (" int x= /*]*/j/*[*/;\n " );
196+ buf .append (" }\n " );
197+ buf .append ("}\n " );
198+ AbstractSourceTestCase .compareSource (buf .toString (), actual );
199+
200+ Assert .assertNotNull (refactorEdit .command );
201+ Assert .assertEquals (GetRefactorEditHandler .RENAME_COMMAND , refactorEdit .command .getCommand ());
202+ Assert .assertNotNull (refactorEdit .command .getArguments ());
203+ Assert .assertEquals (1 , refactorEdit .command .getArguments ().size ());
204+ }
205+
128206 @ Test
129207 public void testExtractField () throws Exception {
130208 IPackageFragment pack1 = fSourceFolder .createPackageFragment ("test1" , false , null );
0 commit comments