]> git.uio.no Git - ifi-stolz-refaktor.git/commitdiff
now also works with blockless constructs (if, for, etc)
authorAnna Eilertsen <anna.eilertsen@student.uib.no>
Thu, 8 Oct 2015 13:36:17 +0000 (15:36 +0200)
committerAnna Eilertsen <anna.eilertsen@student.uib.no>
Thu, 8 Oct 2015 13:36:17 +0000 (15:36 +0200)
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/refactorings/ExtractTempWithAssertsRefactoring.java

index 5874dbccbd68410d112980de0b788bd4cb17d8a4..4d615e05139375d343f944a3eff7d6d58c84e7d2 100644 (file)
@@ -437,16 +437,20 @@ public class ExtractTempWithAssertsRefactoring extends ExtractTempRefactoring {
                         * Anna's code from here
                         */
 
-                       ASTNode block = fragment.getAssociatedNode();
-                       while(! (block instanceof Block)){
-                               block = block.getParent();
+                       ASTNode exprstatement = fragment.getAssociatedNode();
+                       while( !(exprstatement instanceof ExpressionStatement)){
+                               exprstatement = exprstatement.getParent();
                        }
+
                        
-                       ASTNode exprstatement = fragment.getAssociatedNode();
-                       while( ! (exprstatement instanceof ExpressionStatement)){
+                       ASTNode block = exprstatement.getParent();
+                       
+                       while(! (block instanceof Block)){
+                               block = block.getParent();
                                exprstatement = exprstatement.getParent();
                        }
                        
+                       
                        ListRewrite lr = rewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY);
                        
                        lr.insertBefore(getAssertStatement(block.getAST()), exprstatement, null);