surround with statement master
authoralexey.ivanov <alexey.ivanov@jetbrains.com>
Thu, 11 Nov 2010 15:30:35 +0000 (18:30 +0300)
committeralexey.ivanov <alexey.ivanov@jetbrains.com>
Thu, 11 Nov 2010 15:30:35 +0000 (18:30 +0300)
22 files changed:
src/META-INF/plugin.xml
src/org/jetbrains/javafx/lang/psi/JavaFxIfExpression.java
src/org/jetbrains/javafx/lang/psi/impl/JavaFxIfExpressionImpl.java
src/org/jetbrains/javafx/refactoring/JavaFxRefactoringUtil.java
src/org/jetbrains/javafx/refactoring/surround/JavaFxExpressionSurroundDescriptor.java
src/org/jetbrains/javafx/refactoring/surround/JavaFxStatementSurroundDescriptor.java [new file with mode: 0644]
src/org/jetbrains/javafx/refactoring/surround/surrounders/expressions/JavaFxWithAsSurrounder.java
src/org/jetbrains/javafx/refactoring/surround/surrounders/expressions/JavaFxWithExpressionSurrounder.java [moved from src/org/jetbrains/javafx/refactoring/surround/surrounders/expressions/JavaFxExpressionSurrounder.java with 96% similarity]
src/org/jetbrains/javafx/refactoring/surround/surrounders/expressions/JavaFxWithNotInstanceofSurrounder.java
src/org/jetbrains/javafx/refactoring/surround/surrounders/expressions/JavaFxWithNotSurrounder.java
src/org/jetbrains/javafx/refactoring/surround/surrounders/expressions/JavaFxWithParenthesesSurrounder.java
src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithIfElseSurrounder.java [new file with mode: 0644]
src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithIfSurrounder.java [new file with mode: 0644]
src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithStatementSurrounder.java [new file with mode: 0644]
src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithWhileSurrounder.java [new file with mode: 0644]
testData/surround/If.fx [new file with mode: 0644]
testData/surround/IfElse.fx [new file with mode: 0644]
testData/surround/IfElse_after.fx [new file with mode: 0644]
testData/surround/If_after.fx [new file with mode: 0644]
testData/surround/While.fx [new file with mode: 0644]
testData/surround/While_after.fx [new file with mode: 0644]
testSrc/org/jetbrains/javafx/JavaFxSurroundWithTest.java

index a854240582f7dea12e8d61c666828043a2748c8c..bf61ceb3867b9e6b8a5f9ed7a36ba1520a8d00f4 100644 (file)
@@ -88,6 +88,8 @@
                              implementationClass="org.jetbrains.javafx.lang.psi.impl.resolve.JavaFxReferenceElementManipulator"/>
     <lang.surroundDescriptor language="JavaFx"
                              implementationClass="org.jetbrains.javafx.refactoring.surround.JavaFxExpressionSurroundDescriptor"/>
+    <lang.surroundDescriptor language="JavaFx"
+                             implementationClass="org.jetbrains.javafx.refactoring.surround.JavaFxStatementSurroundDescriptor"/>
     <lang.findUsagesProvider language="JavaFx" implementationClass="org.jetbrains.javafx.findUsages.JavaFxFindUsagesProvider"/>
     <lang.namesValidator language="JavaFx" implementationClass="org.jetbrains.javafx.refactoring.rename.JavaFxNamesValidator"/>
 
index 0521c29c9a56c4bc4aaa99ca3618fa4fb4d06234..e79c9ae9708d6de884aeb1548719d2d9d6db4189 100644 (file)
@@ -24,6 +24,9 @@ import org.jetbrains.annotations.Nullable;
  * Time:   18:14:11
  */
 public interface JavaFxIfExpression extends JavaFxValueExpression {
+  @Nullable
+  JavaFxExpression getCondition();
+
   @Nullable
   JavaFxExpression getIfBranch();
 
index 436bd2de9665c80630d1c28862c88b263822fdfc..944b19efb0ef9389d47540851cb65fa548caec87 100644 (file)
@@ -35,6 +35,11 @@ public class JavaFxIfExpressionImpl extends JavaFxBaseElementImpl implements Jav
     super(node);
   }
 
+  @Override
+  public JavaFxExpression getCondition() {
+    return (JavaFxExpression)childToPsi(JavaFxElementTypes.EXPRESSIONS, 0);
+  }
+
   @Nullable
   @Override
   public JavaFxExpression getIfBranch() {
index 0552395a8f5e9d39011e0ec4fd82c7ee59a118da..47c79d8f804622ae176d48eabcfa1ade062f1537 100644 (file)
  */
 package org.jetbrains.javafx.refactoring;
 
+import com.intellij.lang.ASTNode;
+import com.intellij.psi.PsiComment;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiWhiteSpace;
 import com.intellij.psi.util.PsiTreeUtil;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.jetbrains.javafx.lang.lexer.JavaFxTokenTypes;
+import org.jetbrains.javafx.lang.parser.JavaFxElementTypes;
+import org.jetbrains.javafx.lang.psi.JavaFxBlockExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxFile;
 import org.jetbrains.javafx.lang.psi.JavaFxValueExpression;
 
+import java.util.ArrayList;
+
 /**
  * Created by IntelliJ IDEA.
  *
- * @author: Alexey.Ivanov
+ * @author Alexey.Ivanov
  */
 public class JavaFxRefactoringUtil {
   private JavaFxRefactoringUtil() {
   }
 
   @Nullable
-  public static JavaFxValueExpression findExpressionInRange(final PsiFile file, final int startOffset, final int endOffset) {
+  public static JavaFxValueExpression findValueExpressionInRange(final PsiFile file, final int startOffset, final int endOffset) {
     if (startOffset > endOffset) {
       return null;
     }
@@ -51,4 +61,91 @@ public class JavaFxRefactoringUtil {
     }
     return expression;
   }
+
+  @NotNull
+  public static PsiElement[] findExpressionsInRange(final PsiFile file, int startOffset, int endOffset) {
+    if (startOffset > endOffset) {
+      return JavaFxExpression.EMPTY_ARRAY;
+    }
+    PsiElement element1 = file.findElementAt(startOffset);
+    PsiElement element2 = file.findElementAt(endOffset - 1);
+    if (element1 instanceof PsiWhiteSpace) {
+      startOffset = element1.getTextRange().getEndOffset();
+      element1 = file.findElementAt(startOffset);
+    }
+    if (element2 instanceof PsiWhiteSpace) {
+      endOffset = element2.getTextRange().getStartOffset();
+      element2 = file.findElementAt(endOffset - 1);
+    }
+    if (element1 == null || element2 == null || element1.getNode().getElementType() == JavaFxElementTypes.SEMICOLON) {
+      return JavaFxExpression.EMPTY_ARRAY;
+    }
+
+    final PsiElement commonParent = PsiTreeUtil.findCommonParent(element1, element2);
+    if (commonParent == null) {
+      return JavaFxExpression.EMPTY_ARRAY;
+    }
+    PsiElement parent =
+      PsiTreeUtil.getParentOfType(commonParent, JavaFxExpression.class, false, JavaFxBlockExpression.class, JavaFxFile.class);
+    if (parent == null) {
+      if (commonParent instanceof JavaFxFile) {
+        parent = commonParent;
+      }
+      else {
+        return JavaFxExpression.EMPTY_ARRAY;
+      }
+    }
+
+    if (!parent.equals(element1)) {
+      while (!parent.equals(element1.getParent())) {
+        element1 = element1.getParent();
+      }
+    }
+    if (startOffset != element1.getTextRange().getStartOffset()) {
+      return JavaFxExpression.EMPTY_ARRAY;
+    }
+
+    if (!parent.equals(element2)) {
+      while (!parent.equals(element2.getParent())) {
+        element2 = element2.getParent();
+      }
+    }
+    if (endOffset != element2.getTextRange().getEndOffset()) {
+      return JavaFxExpression.EMPTY_ARRAY;
+    }
+
+    final ASTNode node = parent.getNode();
+    if (node == null) {
+      return JavaFxExpression.EMPTY_ARRAY;
+    }
+    ASTNode astNode = node.getFirstChildNode();
+    final ArrayList<PsiElement> array = new ArrayList<PsiElement>();
+    boolean flag = false;
+    while (astNode != null) {
+      final PsiElement child = astNode.getPsi();
+      astNode = astNode.getTreeNext();
+      if (child == null) {
+        break;
+      }
+      if (child.equals(element1)) {
+        flag = true;
+      }
+      if (flag && !(child instanceof PsiWhiteSpace)) {
+        array.add(child);
+      }
+      if (child.equals(element2)) {
+        break;
+      }
+    }
+
+    for (PsiElement element : array) {
+      if (!(element instanceof JavaFxExpression ||
+            element instanceof PsiWhiteSpace ||
+            element instanceof PsiComment ||
+            element.getNode().getElementType() == JavaFxTokenTypes.SEMICOLON)) {
+        return JavaFxExpression.EMPTY_ARRAY;
+      }
+    }
+    return array.toArray(new PsiElement[array.size()]);
+  }
 }
index 8aa4daefef01cfb1df70d0b937275a4d07b791b6..afcaa43afd1f85ab1b83e5fdcd1e35a6b13c9524 100644 (file)
@@ -40,7 +40,10 @@ public class JavaFxExpressionSurroundDescriptor implements SurroundDescriptor {
   @NotNull
   @Override
   public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
-    final JavaFxValueExpression expression = JavaFxRefactoringUtil.findExpressionInRange(file, startOffset, endOffset);
+    final JavaFxValueExpression expression = JavaFxRefactoringUtil.findValueExpressionInRange(file, startOffset, endOffset);
+    if (expression == null) {
+      return PsiElement.EMPTY_ARRAY;
+    }
     return new PsiElement[]{expression};
   }
 
diff --git a/src/org/jetbrains/javafx/refactoring/surround/JavaFxStatementSurroundDescriptor.java b/src/org/jetbrains/javafx/refactoring/surround/JavaFxStatementSurroundDescriptor.java
new file mode 100644 (file)
index 0000000..0321bae
--- /dev/null
@@ -0,0 +1,37 @@
+package org.jetbrains.javafx.refactoring.surround;
+
+import com.intellij.lang.surroundWith.SurroundDescriptor;
+import com.intellij.lang.surroundWith.Surrounder;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.javafx.refactoring.JavaFxRefactoringUtil;
+import org.jetbrains.javafx.refactoring.surround.surrounders.statements.JavaFxWithIfElseSurrounder;
+import org.jetbrains.javafx.refactoring.surround.surrounders.statements.JavaFxWithIfSurrounder;
+import org.jetbrains.javafx.refactoring.surround.surrounders.statements.JavaFxWithWhileSurrounder;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author Alexey.Ivanov
+ */
+public class JavaFxStatementSurroundDescriptor implements SurroundDescriptor {
+  private static final Surrounder[] SURROUNDERS =
+    {new JavaFxWithIfSurrounder(), new JavaFxWithIfElseSurrounder(), new JavaFxWithWhileSurrounder()};
+
+  @NotNull
+  @Override
+  public PsiElement[] getElementsToSurround(final PsiFile file, final int startOffset, final int endOffset) {
+    final PsiElement[] expressions = JavaFxRefactoringUtil.findExpressionsInRange(file, startOffset, endOffset);
+    if (expressions.length == 0) {
+      return PsiElement.EMPTY_ARRAY;
+    }
+    return expressions;
+  }
+
+  @NotNull
+  @Override
+  public Surrounder[] getSurrounders() {
+    return SURROUNDERS;
+  }
+}
index cfbd893054962b3818fdfe86a5de1f95957f17fb..aa201bdd420de3d1d41cb32a500e15cf6fc3d3f0 100644 (file)
@@ -26,7 +26,7 @@ import org.jetbrains.javafx.lang.psi.JavaFxValueExpression;
  * Created by IntelliJ IDEA.
  * @author: Alexey.Ivanov
  */
-public class JavaFxWithAsSurrounder extends JavaFxExpressionSurrounder {
+public class JavaFxWithAsSurrounder extends JavaFxWithExpressionSurrounder {
   @Override
   protected boolean isApplicable(JavaFxValueExpression element) {
     return true;
similarity index 96%
rename from src/org/jetbrains/javafx/refactoring/surround/surrounders/expressions/JavaFxExpressionSurrounder.java
rename to src/org/jetbrains/javafx/refactoring/surround/surrounders/expressions/JavaFxWithExpressionSurrounder.java
index 81fd18b69929bcb8d2f5f70491dc09f383ef8739..36e602a74d2b67d835de6fff335319922d8222cf 100644 (file)
@@ -33,8 +33,8 @@ import org.jetbrains.javafx.refactoring.JavaFxChangeUtil;
  * Created by IntelliJ IDEA.
  * @author: Alexey.Ivanov
  */
-public abstract class JavaFxExpressionSurrounder implements Surrounder {
-  private static final Logger LOG = Logger.getInstance("#org.jetbrains.javafx.refactoring.surround.surrounders.expressions.JavaFxExpressionSurrounder");
+public abstract class JavaFxWithExpressionSurrounder implements Surrounder {
+  private static final Logger LOG = Logger.getInstance("#org.jetbrains.javafx.refactoring.surround.surrounders.expressions.JavaFxWithExpressionSurrounder");
 
   @Override
   public boolean isApplicable(@NotNull PsiElement[] elements) {
index c34198c418a3739f98696b5d7de1d13ed4111092..81bc65cfd44cd34b6e9468a1741a5a83e5abfa9f 100644 (file)
@@ -23,7 +23,7 @@ import org.jetbrains.javafx.lang.psi.*;
  * Created by IntelliJ IDEA.
  * @author: Alexey.Ivanov
  */
-public class JavaFxWithNotInstanceofSurrounder extends JavaFxExpressionSurrounder {
+public class JavaFxWithNotInstanceofSurrounder extends JavaFxWithExpressionSurrounder {
   @Override
   protected boolean isApplicable(JavaFxValueExpression element) {
     return true;
index e9f65ad94343981e154311daccfa99a67b4a3941..40d8ef7fa56eb6beafec84c2a7e7068fc6b579aa 100644 (file)
@@ -25,7 +25,7 @@ import org.jetbrains.javafx.lang.psi.impl.types.JavaFxPrimitiveType;
  *
  * @author: Alexey.Ivanov
  */
-public class JavaFxWithNotSurrounder extends JavaFxExpressionSurrounder {
+public class JavaFxWithNotSurrounder extends JavaFxWithExpressionSurrounder {
   @Override
   protected boolean isApplicable(final JavaFxValueExpression element) {
     return JavaFxPrimitiveType.BOOLEAN.equals(element.getType());
index 8a5c01dd8c3cf3e8e50f222e6cdfe19c1220a910..15b299902676f24a75de9b629c81c2620b1cb22f 100644 (file)
@@ -24,7 +24,7 @@ import org.jetbrains.javafx.lang.psi.JavaFxValueExpression;
  *
  * @author: Alexey.Ivanov
  */
-public class JavaFxWithParenthesesSurrounder extends JavaFxExpressionSurrounder {
+public class JavaFxWithParenthesesSurrounder extends JavaFxWithExpressionSurrounder {
   @Override
   protected boolean isApplicable(final JavaFxValueExpression element) {
     return true;
diff --git a/src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithIfElseSurrounder.java b/src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithIfElseSurrounder.java
new file mode 100644 (file)
index 0000000..4721c2c
--- /dev/null
@@ -0,0 +1,44 @@
+package org.jetbrains.javafx.refactoring.surround.surrounders.statements;
+
+import com.intellij.codeInsight.CodeInsightBundle;
+import com.intellij.codeInsight.CodeInsightUtilBase;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.javafx.lang.psi.JavaFxBlockExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxIfExpression;
+import org.jetbrains.javafx.refactoring.JavaFxChangeUtil;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author Alexey.Ivanov
+ */
+public class JavaFxWithIfElseSurrounder extends JavaFxWithStatementSurrounder {
+  @Override
+  public String getTemplateDescription() {
+    return CodeInsightBundle.message("surround.with.ifelse.template");
+  }
+
+  @Override
+  public TextRange surroundElements(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiElement[] elements)
+    throws IncorrectOperationException {
+    JavaFxExpression ifExpression = JavaFxChangeUtil.createExpressionFromText(project, "if (true) {\n\n}\nelse {\n}");
+    final PsiElement parent = elements[0].getParent();
+    if (ifExpression instanceof JavaFxIfExpression) {
+      final JavaFxBlockExpression blockExpression = (JavaFxBlockExpression)((JavaFxIfExpression)ifExpression).getIfBranch();
+      assert blockExpression != null;
+      blockExpression.addRangeAfter(elements[0], elements[elements.length - 1], blockExpression.getFirstChild().getNextSibling());
+      ifExpression = (JavaFxExpression)parent.addBefore(ifExpression, elements[0]);
+      parent.deleteChildRange(elements[0], elements[elements.length - 1]);
+      ifExpression = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(ifExpression);
+      if (ifExpression != null) {
+        return ((JavaFxIfExpression)ifExpression).getCondition().getTextRange();
+      }
+    }
+    return null;
+  }
+}
diff --git a/src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithIfSurrounder.java b/src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithIfSurrounder.java
new file mode 100644 (file)
index 0000000..a31eaed
--- /dev/null
@@ -0,0 +1,44 @@
+package org.jetbrains.javafx.refactoring.surround.surrounders.statements;
+
+import com.intellij.codeInsight.CodeInsightBundle;
+import com.intellij.codeInsight.CodeInsightUtilBase;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.javafx.lang.psi.JavaFxBlockExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxIfExpression;
+import org.jetbrains.javafx.refactoring.JavaFxChangeUtil;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author Alexey.Ivanov
+ */
+public class JavaFxWithIfSurrounder extends JavaFxWithStatementSurrounder {
+  @Override
+  public String getTemplateDescription() {
+    return CodeInsightBundle.message("surround.with.if.template");
+  }
+
+  @Override
+  public TextRange surroundElements(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiElement[] elements)
+    throws IncorrectOperationException {
+    JavaFxExpression ifExpression = JavaFxChangeUtil.createExpressionFromText(project, "if (true) {\n\n}");
+    final PsiElement parent = elements[0].getParent();
+    if (ifExpression instanceof JavaFxIfExpression) {
+      final JavaFxBlockExpression blockExpression = (JavaFxBlockExpression)((JavaFxIfExpression)ifExpression).getIfBranch();
+      assert blockExpression != null;
+      blockExpression.addRangeAfter(elements[0], elements[elements.length - 1], blockExpression.getFirstChild().getNextSibling());
+      ifExpression = (JavaFxExpression)parent.addBefore(ifExpression, elements[0]);
+      parent.deleteChildRange(elements[0], elements[elements.length - 1]);
+      ifExpression = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(ifExpression);
+      if (ifExpression != null) {
+        return ((JavaFxIfExpression)ifExpression).getCondition().getTextRange();
+      }
+    }
+    return null;
+  }
+}
diff --git a/src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithStatementSurrounder.java b/src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithStatementSurrounder.java
new file mode 100644 (file)
index 0000000..1ea83a9
--- /dev/null
@@ -0,0 +1,16 @@
+package org.jetbrains.javafx.refactoring.surround.surrounders.statements;
+
+import com.intellij.lang.surroundWith.Surrounder;
+import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author Alexey.Ivanov
+ */
+public abstract class JavaFxWithStatementSurrounder implements Surrounder {
+  @Override
+  public boolean isApplicable(@NotNull final PsiElement[] elements) {
+    return true;
+  }
+}
diff --git a/src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithWhileSurrounder.java b/src/org/jetbrains/javafx/refactoring/surround/surrounders/statements/JavaFxWithWhileSurrounder.java
new file mode 100644 (file)
index 0000000..329fc1f
--- /dev/null
@@ -0,0 +1,44 @@
+package org.jetbrains.javafx.refactoring.surround.surrounders.statements;
+
+import com.intellij.codeInsight.CodeInsightBundle;
+import com.intellij.codeInsight.CodeInsightUtilBase;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.javafx.lang.psi.JavaFxBlockExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxWhileExpression;
+import org.jetbrains.javafx.refactoring.JavaFxChangeUtil;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author Alexey.Ivanov
+ */
+public class JavaFxWithWhileSurrounder extends JavaFxWithStatementSurrounder {
+  @Override
+  public String getTemplateDescription() {
+    return CodeInsightBundle.message("surround.with.while.template");
+  }
+
+  @Override
+  public TextRange surroundElements(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiElement[] elements)
+    throws IncorrectOperationException {
+    JavaFxExpression whileExpression = JavaFxChangeUtil.createExpressionFromText(project, "while (true) {\n\n}");
+    final PsiElement parent = elements[0].getParent();
+    if (whileExpression instanceof JavaFxWhileExpression) {
+      final JavaFxBlockExpression blockExpression = (JavaFxBlockExpression)((JavaFxWhileExpression)whileExpression).getBody();
+      assert blockExpression != null;
+      blockExpression.addRangeAfter(elements[0], elements[elements.length - 1], blockExpression.getFirstChild().getNextSibling());
+      whileExpression = (JavaFxExpression)parent.addBefore(whileExpression, elements[0]);
+      parent.deleteChildRange(elements[0], elements[elements.length - 1]);
+      whileExpression = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(whileExpression);
+      if (whileExpression != null) {
+        return ((JavaFxWhileExpression)whileExpression).getCondition().getTextRange();
+      }
+    }
+    return null;
+  }
+}
diff --git a/testData/surround/If.fx b/testData/surround/If.fx
new file mode 100644 (file)
index 0000000..a2e919d
--- /dev/null
@@ -0,0 +1,3 @@
+var a = 3;<selection>
+var b = a * 3;
+var c = bind b;</selection>
\ No newline at end of file
diff --git a/testData/surround/IfElse.fx b/testData/surround/IfElse.fx
new file mode 100644 (file)
index 0000000..3d3c949
--- /dev/null
@@ -0,0 +1,4 @@
+function foo(a: Integer) {
+   <selection> var b = a * 3;
+    </selection>return b + 5
+}
\ No newline at end of file
diff --git a/testData/surround/IfElse_after.fx b/testData/surround/IfElse_after.fx
new file mode 100644 (file)
index 0000000..85a4406
--- /dev/null
@@ -0,0 +1,8 @@
+function foo(a: Integer) {
+    if (<selection>true</selection>) {
+        var b = a * 3;
+    }
+    else {
+    }
+    return b + 5
+}
\ No newline at end of file
diff --git a/testData/surround/If_after.fx b/testData/surround/If_after.fx
new file mode 100644 (file)
index 0000000..98b2a31
--- /dev/null
@@ -0,0 +1,5 @@
+var a = 3;
+if (<selection>true</selection>) {
+    var b = a * 3;
+    var c = bind b;
+}
\ No newline at end of file
diff --git a/testData/surround/While.fx b/testData/surround/While.fx
new file mode 100644 (file)
index 0000000..5867314
--- /dev/null
@@ -0,0 +1,7 @@
+function foo(a: Integer) {
+    var b = 0;
+    <selection>b += a;
+    --a;
+    </selection>
+    return b;
+}
\ No newline at end of file
diff --git a/testData/surround/While_after.fx b/testData/surround/While_after.fx
new file mode 100644 (file)
index 0000000..5f70168
--- /dev/null
@@ -0,0 +1,9 @@
+function foo(a: Integer) {
+    var b = 0;
+    while (<selection>true</selection>) {
+        b += a;
+        --a;
+    }
+    
+    return b;
+}
\ No newline at end of file
index 0ef7d27c964ce92e64c49b84865008345f1208e0..7de4c997e4a7df0d9920f1fe04d333c53c29ab7e 100644 (file)
@@ -22,11 +22,14 @@ import org.jetbrains.javafx.refactoring.surround.surrounders.expressions.JavaFxW
 import org.jetbrains.javafx.refactoring.surround.surrounders.expressions.JavaFxWithNotInstanceofSurrounder;
 import org.jetbrains.javafx.refactoring.surround.surrounders.expressions.JavaFxWithNotSurrounder;
 import org.jetbrains.javafx.refactoring.surround.surrounders.expressions.JavaFxWithParenthesesSurrounder;
+import org.jetbrains.javafx.refactoring.surround.surrounders.statements.JavaFxWithIfElseSurrounder;
+import org.jetbrains.javafx.refactoring.surround.surrounders.statements.JavaFxWithIfSurrounder;
+import org.jetbrains.javafx.refactoring.surround.surrounders.statements.JavaFxWithWhileSurrounder;
 import org.jetbrains.javafx.testUtils.JavaFxLightFixtureTestCase;
 
 /**
  * Created by IntelliJ IDEA.
- * @author: Alexey.Ivanov
+ * @author Alexey.Ivanov
  */
 public class JavaFxSurroundWithTest extends JavaFxLightFixtureTestCase {
   public void testParentheses() {
@@ -45,6 +48,18 @@ public class JavaFxSurroundWithTest extends JavaFxLightFixtureTestCase {
     doTest(new JavaFxWithNotInstanceofSurrounder());
   }
 
+  public void testIf() {
+    doTest(new JavaFxWithIfSurrounder());
+  }
+
+  public void testIfElse() {
+    doTest(new JavaFxWithIfElseSurrounder());
+  }
+
+  public void testWhile() {
+    doTest(new JavaFxWithWhileSurrounder());
+  }
+
   private void doTest(final Surrounder surrounder) {
     final String baseName = "/surround/" + getTestName(false);
     myFixture.configureByFile(baseName + ".fx");