--- resources/intentionDescriptions/ExpandBooleanIntention/description.html	Sun Jul 29 08:25:42 EDT 2007
+++ resources/intentionDescriptions/ExpandBooleanIntention/description.html	Sun Jul 29 08:25:42 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+  <font face="verdana" size="-1">This intention replaces uses of boolean values with equivalent if-then-else statements,
+if possible.</font>
+
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/MakeClosureCallExplicitIntention/before.groovy.template	Thu Aug 02 15:43:56 EDT 2007
+++ resources/intentionDescriptions/MakeClosureCallExplicitIntention/before.groovy.template	Thu Aug 02 15:43:56 EDT 2007
@@ -0,0 +1,3 @@
+
+def Closure myClosure
+<spot>myClosure(arg1, arg2)</spot>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertGStringToStringIntention.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertGStringToStringIntention.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,55 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+public class ConvertGStringToStringIntention extends Intention {
+
+    @NotNull
+    public PsiElementPredicate getElementPredicate() {
+        return new ConvertibleGStringLiteralPredicate();
+    }
+
+    public void processIntention(PsiElement element)
+            throws IncorrectOperationException {
+        final GrLiteral exp = (GrLiteral) element;
+        final String textString = exp.getText();
+
+        replaceExpression(convertGStringLiteralToStringLiteral(textString), exp);
+    }
+
+    private static String convertGStringLiteralToStringLiteral(String stringLiteral){
+            final String delimiter;
+        final String contents;
+        if (stringLiteral.startsWith("\"\"\"")) {
+            delimiter = "'''";
+            contents = stringLiteral.substring(3, stringLiteral.length() - 3);
+        } else {
+            delimiter = "'";
+            contents = stringLiteral.substring(1, stringLiteral.length() - 1);
+        }
+        return delimiter + escape(contents) + delimiter;
+    }
+
+    private static String escape(String contents) {
+        final StringBuilder out = new StringBuilder();
+        final char[] chars = contents.toCharArray();
+        for (int i = 0; i < chars.length; i++) {
+            if (chars[i] == '\'') {
+                if (i > 0 && chars[i - 1] == '\\') {
+                    out.append('\'');
+                } else {
+                    out.append("\\\'");
+                }
+            }else {
+                out.append(chars[i]);
+            }
+
+        }
+        return out.toString();
+    }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ConvertIntegerToDecimalIntention/description.html	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToDecimalIntention/description.html	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,8 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts selected integer literal (written in either <b>hexadecimal</b> or <b>octal</b> notation)
+into <b>decimal</b> notation.
+</font>
+</body>
+</html>
\ No newline at end of file
--- testdata/intentions/ForToEach.groovy	Thu Aug 02 21:45:14 EDT 2007
+++ testdata/intentions/ForToEach.groovy	Thu Aug 02 21:45:14 EDT 2007
@@ -0,0 +1,5 @@
+
+x = [1, 2, 4, 8]
+for(i in x) {print(i)};
+x.each{i-> print i; print(i)}
+x.each{i-> println i}
\ No newline at end of file
--- resources/intentionDescriptions/ExpandBooleanIntention/before.groovy.template	Sun Jul 29 08:25:42 EDT 2007
+++ resources/intentionDescriptions/ExpandBooleanIntention/before.groovy.template	Sun Jul 29 08:25:42 EDT 2007
@@ -0,0 +1,5 @@
+public class X {
+  boolean f(boolean a) {
+    <spot>return a</spot>;
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/MakeClosureCallImplicitIntention/after.groovy.template	Thu Aug 02 16:01:27 EDT 2007
+++ resources/intentionDescriptions/MakeClosureCallImplicitIntention/after.groovy.template	Thu Aug 02 16:01:27 EDT 2007
@@ -0,0 +1,3 @@
+
+def Closure myClosure
+myClosure(arg1, arg2)
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/IndexedExpressionConversionPredicate.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/IndexedExpressionConversionPredicate.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,46 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
+
+
+class IndexedExpressionConversionPredicate implements PsiElementPredicate {
+    public boolean satisfiedBy(PsiElement element) {
+        if (!(element instanceof GrIndexProperty)) {
+            return false;
+        }
+
+        if (ErrorUtil.containsError(element)) {
+            return false;
+        }
+        final GrIndexProperty arrayIndexExpression = (GrIndexProperty) element;
+        final PsiElement lastChild = arrayIndexExpression.getLastChild();
+        if (!(lastChild instanceof GrArgumentList)) {
+            return false;
+        }
+        final GrArgumentList argList = (GrArgumentList) lastChild;
+
+        final GrExpression[] arguments = argList.getExpressionArguments();
+        if (arguments.length != 1) {
+            return false;
+        }
+        final PsiElement parent = element.getParent();
+        if (!(parent instanceof GrAssignmentExpression)) {
+            return true;
+        }
+        final GrAssignmentExpression assignmentExpression = (GrAssignmentExpression) parent;
+        if (assignmentExpression.getRValue().equals(element)) {
+            return true;
+        }
+        final IElementType operator = assignmentExpression.getOperationToken();
+        return GroovyTokenTypes.mASSIGN.equals(operator);
+    }
+
+}
\ No newline at end of file
--- testdata/intentions/SpreadDot.groovy	Mon Aug 06 07:06:16 EDT 2007
+++ testdata/intentions/SpreadDot.groovy	Mon Aug 06 07:06:16 EDT 2007
@@ -0,0 +1,4 @@
+
+x = [1, 2, 4, 8]
+
+x*.toString()
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/DemorgansLawIntention.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/DemorgansLawIntention.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,115 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
+import org.jetbrains.plugins.groovy.intentions.utils.BoolUtils;
+import org.jetbrains.plugins.groovy.intentions.utils.ComparisonUtils;
+import org.jetbrains.plugins.groovy.intentions.utils.ParenthesesUtils;
+import org.jetbrains.plugins.groovy.intentions.base.MutablyNamedIntention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+public class DemorgansLawIntention extends MutablyNamedIntention {
+
+  protected String getTextForElement(PsiElement element) {
+    final GrBinaryExpression binaryExpression =
+        (GrBinaryExpression) element;
+    final IElementType tokenType = binaryExpression.getOperationTokenType();
+    if (tokenType.equals(GroovyTokenTypes.mLAND)) {
+      return GroovyIntentionsBundle.message("demorgans.intention.name1");
+    } else {
+      return GroovyIntentionsBundle.message("demorgans.intention.name2");
+    }
+  }
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ConjunctionPredicate();
+  }
+
+  public void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException {
+    GrBinaryExpression exp =
+        (GrBinaryExpression) element;
+    final IElementType tokenType = exp.getOperationTokenType();
+    PsiElement parent = exp.getParent();
+    while (isConjunctionExpression(parent, tokenType)) {
+      exp = (GrBinaryExpression) parent;
+      assert exp != null;
+      parent = exp.getParent();
+    }
+    final String newExpression =
+        convertConjunctionExpression(exp, tokenType);
+    replaceExpressionWithNegatedExpressionString(newExpression, exp);
+  }
+
+  private String convertConjunctionExpression(GrBinaryExpression exp,
+                                              IElementType tokenType) {
+    final GrExpression lhs = exp.getLeftOperand();
+    final String lhsText;
+    if (isConjunctionExpression(lhs, tokenType)) {
+      lhsText = convertConjunctionExpression((GrBinaryExpression) lhs,
+          tokenType);
+    } else {
+      lhsText = convertLeafExpression(lhs);
+    }
+    final GrExpression rhs = exp.getRightOperand();
+    final String rhsText;
+    if (isConjunctionExpression(rhs, tokenType)) {
+      rhsText = convertConjunctionExpression((GrBinaryExpression) rhs,
+          tokenType);
+    } else {
+      rhsText = convertLeafExpression(rhs);
+    }
+
+    final String flippedConjunction;
+    if (tokenType.equals(GroovyTokenTypes.mLAND)) {
+      flippedConjunction = "||";
+    } else {
+      flippedConjunction = "&&";
+    }
+
+    return lhsText + flippedConjunction + rhsText;
+  }
+
+  private static String convertLeafExpression(GrExpression condition) {
+    if (BoolUtils.isNegation(condition)) {
+      final GrExpression negated = BoolUtils.getNegated(condition);
+      if (ParenthesesUtils.getPrecendence(negated) >
+          ParenthesesUtils.OR_PRECEDENCE) {
+        return '(' + negated.getText() + ')';
+      }
+      return negated.getText();
+    } else if (ComparisonUtils.isComparison(condition)) {
+      final GrBinaryExpression binaryExpression =
+          (GrBinaryExpression) condition;
+      final IElementType sign = binaryExpression.getOperationTokenType();
+      final String negatedComparison =
+          ComparisonUtils.getNegatedComparison(sign);
+      final GrExpression lhs = binaryExpression.getLeftOperand();
+      final GrExpression rhs = binaryExpression.getRightOperand();
+      assert rhs != null;
+      return lhs.getText() + negatedComparison + rhs.getText();
+    } else if (ParenthesesUtils.getPrecendence(condition) >
+        ParenthesesUtils.PREFIX_PRECEDENCE) {
+      return "!(" + condition.getText() + ')';
+    } else {
+      return '!' + condition.getText();
+    }
+  }
+
+  private static boolean isConjunctionExpression(PsiElement exp,
+                                                 IElementType conjunctionType) {
+    if (!(exp instanceof GrBinaryExpression)) {
+      return false;
+    }
+    final GrBinaryExpression binExp = (GrBinaryExpression) exp;
+    final IElementType tokenType = binExp.getOperationTokenType();
+    return tokenType.equals(conjunctionType);
+  }
+}
--- resources/intentionDescriptions/ConvertStringToGStringIntention/description.html	Sun Aug 05 12:37:21 EDT 2007
+++ resources/intentionDescriptions/ConvertStringToGStringIntention/description.html	Sun Aug 05 12:37:21 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts selected String literal into an equivalent GString literal.
+</font>
+</body>
+</html>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToDecimalPredicate.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToDecimalPredicate.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,34 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+
+class ConvertIntegerToDecimalPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrLiteral)) {
+      return false;
+    }
+    final GrLiteral expression = (GrLiteral) element;
+    final PsiType type = expression.getType();
+    if (type == null) {
+      return false;
+    }
+    if (!PsiType.INT.equals(type) && !PsiType.LONG.equals(type) &&
+        !type.equalsToText("java.lang.Integer") && !type.equalsToText("java.lang.Long")) {
+      return false;
+    }
+    @NonNls final String text = expression.getText();
+    if (text == null || text.length() < 2) {
+      return false;
+    }
+    if ("0".equals(text) || "0L".equals(text) || "0l".equals(text)) {
+      return false;
+    }
+    return text.charAt(0) == '0';
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ConvertIntegerToHexIntention/description.html	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToHexIntention/description.html	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,8 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts selected integer literal (written in either <b>decimal</b> or <b>octal</b> notation)
+into <b>hexadecimal</b> notation.
+</font>
+</body>
+</html>
\ No newline at end of file
--- testdata/intentions/ExpandBoolean.groovy	Sun Jul 29 09:16:56 EDT 2007
+++ testdata/intentions/ExpandBoolean.groovy	Sun Jul 29 09:16:56 EDT 2007
@@ -0,0 +1,10 @@
+class ExpandBoolean {
+  private boolean x;
+  private boolean y;
+  boolean foo()
+  {
+    x = y;
+    return x;
+  }
+
+}
\ No newline at end of file
--- resources/intentionDescriptions/FlipConjunctionIntention/description.html	Tue Jul 31 09:40:28 EDT 2007
+++ resources/intentionDescriptions/FlipConjunctionIntention/description.html	Tue Jul 31 09:40:28 EDT 2007
@@ -0,0 +1,6 @@
+<html>
+<body>
+<font face="verdana" size="-1">This intention reverses the order of evaluation of an '&&' or '||' expression.
+</font>
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/ConvertGStringToStringIntention/after.groovy.template	Sun Aug 05 12:38:23 EDT 2007
+++ resources/intentionDescriptions/ConvertGStringToStringIntention/after.groovy.template	Sun Aug 05 12:38:23 EDT 2007
@@ -0,0 +1,1 @@
+x = '48\''
\ No newline at end of file
--- testdata/intentions/MergeIfAnd.groovy	Sat Jul 28 23:39:00 EDT 2007
+++ testdata/intentions/MergeIfAnd.groovy	Sat Jul 28 23:39:00 EDT 2007
@@ -0,0 +1,8 @@
+x = true;
+y = false;
+if(x)
+{
+  if(y){
+     print(3);
+    }
+  }
\ No newline at end of file
--- resources/intentionDescriptions/MergeIfAndIntention/after.groovy.template	Sat Jul 28 23:26:53 EDT 2007
+++ resources/intentionDescriptions/MergeIfAndIntention/after.groovy.template	Sat Jul 28 23:26:53 EDT 2007
@@ -0,0 +1,5 @@
+public class X {
+  void f(a,  b) {
+    <spot>if (a &&b)
+         return;</spot>
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/utils/BoolUtils.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/utils/BoolUtils.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,97 @@
+package org.jetbrains.plugins.groovy.intentions.utils;
+
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpr;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+public class BoolUtils {
+  private BoolUtils() {
+    super();
+  }
+
+  public static boolean isNegated(GrExpression exp) {
+    GrExpression ancestor = exp;
+    while (ancestor.getParent() instanceof GrParenthesizedExpr) {
+      ancestor = (GrExpression) ancestor.getParent();
+    }
+    if (ancestor.getParent() instanceof GrUnaryExpression) {
+      final GrUnaryExpression prefixAncestor =
+          (GrUnaryExpression) ancestor.getParent();
+      final IElementType sign = prefixAncestor.getOperationTokenType();
+      if (GroovyTokenTypes.mLNOT.equals(sign)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  @Nullable
+  public static GrExpression findNegation(GrExpression exp) {
+    GrExpression ancestor = exp;
+    while (ancestor.getParent() instanceof GrParenthesizedExpr) {
+      ancestor = (GrExpression) ancestor.getParent();
+    }
+    if (ancestor.getParent() instanceof GrUnaryExpression) {
+      final GrUnaryExpression prefixAncestor =
+          (GrUnaryExpression) ancestor.getParent();
+      final IElementType sign = prefixAncestor.getOperationTokenType();
+      if (GroovyTokenTypes.mLNOT.equals(sign)) {
+        return prefixAncestor;
+      }
+    }
+    return null;
+  }
+
+  public static boolean isNegation(GrExpression exp) {
+    if (!(exp instanceof GrUnaryExpression)) {
+      return false;
+    }
+    final GrUnaryExpression prefixExp = (GrUnaryExpression) exp;
+    final IElementType sign = prefixExp.getOperationTokenType();
+    return GroovyTokenTypes.mLNOT.equals(sign);
+  }
+
+  public static GrExpression getNegated(GrExpression exp) {
+    final GrUnaryExpression prefixExp = (GrUnaryExpression) exp;
+    final GrExpression operand = prefixExp.getOperand();
+    return ParenthesesUtils.stripParentheses(operand);
+  }
+
+  public static boolean isBooleanLiteral(GrExpression exp) {
+    if (exp instanceof GrLiteral) {
+      final GrLiteral expression = (GrLiteral) exp;
+      @NonNls final String text = expression.getText();
+      return "true".equals(text) || "false".equals(text);
+    }
+    return false;
+  }
+
+  public static String getNegatedExpressionText(GrExpression condition) {
+    if (isNegation(condition)) {
+      final GrExpression negated = getNegated(condition);
+      return negated.getText();
+    } else if (ComparisonUtils.isComparison(condition)) {
+      final GrBinaryExpression binaryExpression =
+          (GrBinaryExpression) condition;
+      final IElementType sign = binaryExpression.getOperationTokenType();
+      final String negatedComparison =
+          ComparisonUtils.getNegatedComparison(sign);
+      final GrExpression lhs = binaryExpression.getLeftOperand();
+      final GrExpression rhs = binaryExpression.getRightOperand();
+      assert rhs != null;
+      return lhs.getText() + negatedComparison + rhs.getText();
+    } else if (ParenthesesUtils.getPrecendence(condition) >
+        ParenthesesUtils.PREFIX_PRECEDENCE) {
+      return "!(" + condition.getText() + ')';
+    } else {
+      return '!' + condition.getText();
+    }
+  }
+}
+
--- resources/intentionDescriptions/FlipComparisonIntention/before.groovy.template	Tue Jul 31 09:41:51 EDT 2007
+++ resources/intentionDescriptions/FlipComparisonIntention/before.groovy.template	Tue Jul 31 09:41:51 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    if (<spot>a < b</spot>) return;
+}
--- testdata/intentions/DeMorgansLaw.groovy	Sat Jul 28 23:08:47 EDT 2007
+++ testdata/intentions/DeMorgansLaw.groovy	Sat Jul 28 23:08:47 EDT 2007
@@ -0,0 +1,4 @@
+x = true;
+y = false;
+z = x && y;
+z = x || y;
--- src/org/jetbrains/plugins/groovy/intentions/control/ConditionalPredicate.java	Wed Aug 01 14:08:46 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/ConditionalPredicate.java	Wed Aug 01 14:08:46 EDT 2007
@@ -0,0 +1,19 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression;
+
+class ConditionalPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrConditionalExpression)) {
+      return false;
+    }
+    return !ErrorUtil.containsError(element);
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/IndexedExpressionConversionIntention.java	Mon Aug 06 15:36:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/IndexedExpressionConversionIntention.java	Mon Aug 06 15:36:00 EDT 2007
@@ -0,0 +1,53 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
+
+public class IndexedExpressionConversionIntention extends Intention {
+
+    @NotNull
+    public PsiElementPredicate getElementPredicate() {
+        return new IndexedExpressionConversionPredicate();
+    }
+
+    public void processIntention(@NotNull PsiElement element)
+            throws IncorrectOperationException {
+
+        final GrIndexProperty arrayIndexExpression = (GrIndexProperty) element;
+
+        final GrArgumentList argList = (GrArgumentList) arrayIndexExpression.getLastChild();
+
+        assert argList != null;
+        final GrExpression[] arguments = argList.getExpressionArguments();
+
+        final PsiElement parent = element.getParent();
+        final GrExpression arrayExpression = arrayIndexExpression.getArrayExpression();
+        if (!(parent instanceof GrAssignmentExpression)) {
+            rewriteAsGetAt(arrayIndexExpression, arrayExpression, arguments[0]);
+            return;
+        }
+        final GrAssignmentExpression assignmentExpression = (GrAssignmentExpression) parent;
+        final GrExpression rhs = assignmentExpression.getRValue();
+        if (rhs.equals(element)) {
+            rewriteAsGetAt(arrayIndexExpression, arrayExpression, arguments[0]);
+        } else {
+            rewriteAsSetAt(assignmentExpression, arrayExpression, arguments[0], rhs);
+        }
+    }
+
+    private static void rewriteAsGetAt(GrIndexProperty arrayIndexExpression, GrExpression arrayExpression, GrExpression argument) throws IncorrectOperationException {
+        replaceExpression(arrayExpression.getText() + ".getAt(" + argument.getText() + ')', arrayIndexExpression);
+    }
+
+    private static void rewriteAsSetAt(GrAssignmentExpression assignment, GrExpression arrayExpression, GrExpression argument, GrExpression value) throws IncorrectOperationException {
+        replaceExpression(arrayExpression.getText() + ".setAt(" + argument.getText() + ", " + value.getText() + ')', assignment);
+    }
+
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/base/ErrorUtil.java	Sun Jul 29 11:32:43 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/base/ErrorUtil.java	Sun Jul 29 11:32:43 EDT 2007
@@ -0,0 +1,30 @@
+package org.jetbrains.plugins.groovy.intentions.base;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiRecursiveElementVisitor;
+import com.intellij.psi.PsiErrorElement;
+
+public class ErrorUtil {
+
+  private ErrorUtil() {
+    super();
+  }
+
+  public static boolean containsError(PsiElement element) {
+    final ErrorElementVisitor visitor = new ErrorElementVisitor();
+    element.accept(visitor);
+    return visitor.containsErrorElement();
+  }
+
+  private static class ErrorElementVisitor extends PsiRecursiveElementVisitor {
+    private boolean containsErrorElement = false;
+
+    public void visitErrorElement(PsiErrorElement element) {
+      containsErrorElement = true;
+    }
+
+    public boolean containsErrorElement() {
+      return containsErrorElement;
+    }
+  }
+}
--- src/org/jetbrains/plugins/groovy/intentions/control/NegateComparisonIntention.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/NegateComparisonIntention.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,48 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
+import org.jetbrains.plugins.groovy.intentions.utils.ComparisonUtils;
+import org.jetbrains.plugins.groovy.intentions.base.MutablyNamedIntention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+public class NegateComparisonIntention extends MutablyNamedIntention {
+  protected String getTextForElement(PsiElement element) {
+    final GrBinaryExpression binaryExpression =
+        (GrBinaryExpression) element;
+    final IElementType tokenType = binaryExpression.getOperationTokenType();
+    final String comparison = ComparisonUtils.getStringForComparison(tokenType);
+    final String negatedComparison = ComparisonUtils.getNegatedComparison(tokenType);
+
+    return GroovyIntentionsBundle.message("negate.comparison.intention.name", comparison, negatedComparison);
+  }
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ComparisonPredicate();
+  }
+
+  public void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException {
+    final GrBinaryExpression exp =
+        (GrBinaryExpression) element;
+    final IElementType tokenType = exp.getOperationTokenType();
+
+    final GrExpression lhs = exp.getLeftOperand();
+    final String lhsText = lhs.getText();
+
+    final GrExpression rhs = exp.getRightOperand();
+    final String rhsText = rhs.getText();
+
+    final String negatedComparison = ComparisonUtils.getNegatedComparison(tokenType);
+
+    final String newExpression = lhsText + negatedComparison + rhsText;
+    replaceExpressionWithNegatedExpressionString(newExpression, exp);
+  }
+
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java	Wed Aug 01 16:39:43 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java	Wed Aug 01 16:39:43 EDT 2007
@@ -0,0 +1,29 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrBlockStatement;
+
+public class SplitElseIfIntention extends Intention {
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new SplitElseIfPredicate();
+  }
+
+  public void processIntention(PsiElement element)
+      throws IncorrectOperationException {
+    final GrIfStatement parentStatement = (GrIfStatement) element;
+    assert parentStatement != null;
+    final GrCondition elseBranch = parentStatement.getElseBranch();
+    replaceStatement("if(" + parentStatement.getCondition().getText()+ ")"+ parentStatement.getThenBranch().getText() +
+        "else{\n" + elseBranch.getText() +"\n}", parentStatement);
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/FlipConjunctionIntention.java	Wed Aug 01 14:49:13 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/FlipConjunctionIntention.java	Wed Aug 01 14:49:13 EDT 2007
@@ -0,0 +1,57 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
+import org.jetbrains.plugins.groovy.intentions.base.MutablyNamedIntention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+public class FlipConjunctionIntention extends MutablyNamedIntention {
+  protected String getTextForElement(PsiElement element) {
+    final GrBinaryExpression binaryExpression =
+        (GrBinaryExpression) element;
+    final IElementType tokenType = binaryExpression.getOperationTokenType();
+    final String conjunction;
+    if (tokenType.equals(GroovyTokenTypes.mLAND)) {
+      conjunction = "&&";
+    } else {
+      conjunction = "||";
+    }
+    return GroovyIntentionsBundle.message("flip.smth.intention.name", conjunction);
+  }
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ConjunctionPredicate();
+  }
+
+  public void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException {
+    final GrBinaryExpression exp =
+        (GrBinaryExpression) element;
+    final IElementType tokenType = exp.getOperationTokenType();
+
+    final GrExpression lhs = exp.getLeftOperand();
+    final String lhsText = lhs.getText();
+
+    final GrExpression rhs = exp.getRightOperand();
+    final String rhsText = rhs.getText();
+
+    final String conjunction;
+    if (tokenType.equals(GroovyTokenTypes.mLAND)) {
+      conjunction = "&&";
+    } else {
+      conjunction = "||";
+    }
+
+    final String newExpression =
+        rhsText + conjunction + lhsText;
+    replaceExpression(newExpression, exp);
+  }
+
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/utils/ConditionalUtils.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/utils/ConditionalUtils.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,73 @@
+package org.jetbrains.plugins.groovy.intentions.utils;
+
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrBlockStatement;
+
+public class ConditionalUtils {
+
+  private ConditionalUtils() {
+    super();
+  }
+
+  public static GrStatement stripBraces(GrStatement branch) {
+    if (branch instanceof GrBlockStatement) {
+      final GrBlockStatement block = (GrBlockStatement) branch;
+      final GrOpenBlock codeBlock = block.getBlock();
+      final GrStatement[] statements = codeBlock.getStatements();
+      if (statements.length == 1) {
+        return statements[0];
+      } else {
+        return block;
+      }
+    } else {
+      return branch;
+    }
+  }
+
+  public static boolean isReturn(GrStatement statement, @NonNls String value) {
+    if (statement == null) {
+      return false;
+    }
+    if (!(statement instanceof GrReturnStatement)) {
+      return false;
+    }
+    final GrReturnStatement returnStatement =
+        (GrReturnStatement) statement;
+    final GrExpression returnValue = returnStatement.getReturnValue();
+    if (returnValue == null) {
+      return false;
+    }
+    final String returnValueText = returnValue.getText();
+    return value.equals(returnValueText);
+  }
+
+  public static boolean isAssignment(GrStatement statement, @NonNls String value) {
+    if (statement == null) {
+      return false;
+    }
+    if (!(statement instanceof GrExpression)) {
+      return false;
+    }
+    final GrExpression expression = (GrExpression) statement;
+    if (!(expression instanceof GrAssignmentExpression)) {
+      return false;
+    }
+    final GrAssignmentExpression assignment =
+        (GrAssignmentExpression) expression;
+    final GrExpression rhs = assignment.getRValue();
+    if (rhs == null) {
+      return false;
+    }
+    final String rhsText = rhs.getText();
+    return value.equals(rhsText);
+  }
+
+  public static boolean isAssignment(GrStatement statement) {
+    return statement instanceof GrAssignmentExpression;
+  }
+}
--- resources/intentionDescriptions/DemorgansLawIntention/description.html	Sat Jul 28 16:41:20 EDT 2007
+++ resources/intentionDescriptions/DemorgansLawIntention/description.html	Sat Jul 28 16:41:20 EDT 2007
@@ -0,0 +1,16 @@
+<html>
+<body>
+<font face="verdana" size="-1">This intention replaces either</font>
+<table>
+<tr><td> &nbsp;&nbsp;&nbsp;</td><td>
+<font face="verdana" size="-1"> <b>a || b</b> with <b>!(!a && !b)</b> or</font>
+</td></tr>
+<tr><td> &nbsp;&nbsp;&nbsp;</td><td>
+<font face="verdana" size="-1"> <b>a && b</b> with <b>!(!a || !b)</b></font>
+</td></tr>
+</table>
+<font face="verdana" size="-1">
+inside boolean expression.
+</font>
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/FlipComparisonIntention/description.html	Tue Jul 31 09:41:51 EDT 2007
+++ resources/intentionDescriptions/FlipComparisonIntention/description.html	Tue Jul 31 09:41:51 EDT 2007
@@ -0,0 +1,6 @@
+<html>
+<body>
+<font face="verdana" size="-1">This intention reverses the order of evaluation of a comparison.
+</font>
+</body>
+</html>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToHexPredicate.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToHexPredicate.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,28 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+class ConvertIntegerToHexPredicate implements PsiElementPredicate {
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrLiteral)) {
+      return false;
+    }
+    final GrLiteral expression = (GrLiteral) element;
+    final PsiType type = expression.getType();
+    if (type == null) {
+      return false;
+    }
+    if (!PsiType.INT.equals(type) && !PsiType.LONG.equals(type) &&
+        !type.equalsToText("java.lang.Integer") && !type.equalsToText("java.lang.Long")) {
+      return false;
+    }
+    @NonNls final String text = expression.getText();
+
+    return !(text.startsWith("0x") || text.startsWith("0X"));
+
+  }
+}
--- testdata/intentions/MethodClosure.groovy	Thu Aug 02 21:45:14 EDT 2007
+++ testdata/intentions/MethodClosure.groovy	Thu Aug 02 21:45:14 EDT 2007
@@ -0,0 +1,3 @@
+
+def Closure myPrintClosure = System.out.&println
+myPrintClosure("foo");
\ No newline at end of file
--- resources/intentionDescriptions/ConvertStringToGStringIntention/after.groovy.template	Sun Aug 05 12:37:42 EDT 2007
+++ resources/intentionDescriptions/ConvertStringToGStringIntention/after.groovy.template	Sun Aug 05 12:37:42 EDT 2007
@@ -0,0 +1,1 @@
+x = "48\$"
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/closure/SingleArgClosurePredicate.java	Thu Aug 02 21:45:14 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/closure/SingleArgClosurePredicate.java	Thu Aug 02 21:45:14 EDT 2007
@@ -0,0 +1,24 @@
+package org.jetbrains.plugins.groovy.intentions.closure;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
+
+class SingleArgClosurePredicate implements PsiElementPredicate {
+
+    public boolean satisfiedBy(PsiElement element) {
+        if (!(element instanceof GrClosableBlock)) {
+            return false;
+        }
+        final GrClosableBlock closure = (GrClosableBlock) element;
+        if(closure.getParameterList().getParametersCount() !=1)
+        {
+            return false;
+        }
+        return !ErrorUtil.containsError(element);
+    }
+}
\ No newline at end of file
--- resources/intentionDescriptions/MakeClosureCallImplicitIntention/before.groovy.template	Thu Aug 02 16:01:27 EDT 2007
+++ resources/intentionDescriptions/MakeClosureCallImplicitIntention/before.groovy.template	Thu Aug 02 16:01:27 EDT 2007
@@ -0,0 +1,3 @@
+
+def Closure myClosure
+<spot>myClosure.call(arg1, arg2)</spot>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToOctalPredicate.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToOctalPredicate.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,35 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+class ConvertIntegerToOctalPredicate implements PsiElementPredicate {
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrLiteral)) {
+      return false;
+    }
+    final GrLiteral expression = (GrLiteral) element;
+    final PsiType type = expression.getType();
+    if (type == null) {
+      return false;
+    }
+    if (!PsiType.INT.equals(type) && !PsiType.LONG.equals(type) &&
+        !type.equalsToText("java.lang.Integer") && !type.equalsToText("java.lang.Long")) {
+      return false;
+    }
+    @NonNls final String text = expression.getText();
+    if (text == null || text.length() == 0) {
+      return false;
+    }
+    if (text.startsWith("0x") || text.startsWith("0X")) {
+      return true;
+    }
+    if ("0".equals(text) || "0L".equals(text)) {
+      return false;
+    }
+    return text.charAt(0) != '0';
+  }
+}
--- resources/intentionDescriptions/SplitElseIfIntention/description.html	Wed Aug 01 16:35:28 EDT 2007
+++ resources/intentionDescriptions/SplitElseIfIntention/description.html	Wed Aug 01 16:35:28 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+ <font face="verdana" size="-1">This intention splits an <b>else-if</b> branch into an equivalent nested if statement.<br>
+</font>
+
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/SplitElseIfIntention/after.groovy.template	Wed Aug 01 16:35:27 EDT 2007
+++ resources/intentionDescriptions/SplitElseIfIntention/after.groovy.template	Wed Aug 01 16:35:27 EDT 2007
@@ -0,0 +1,15 @@
+public class X {
+  int f(int a) {
+    if (a == 0) {
+      return 0;
+    }
+    else {
+      if (a == 1) {
+        return 2;
+      }
+      else {
+        return 18;
+      }
+    }
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertStringToGStringIntention.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertStringToGStringIntention.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,61 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+public class ConvertStringToGStringIntention extends Intention {
+
+    @NotNull
+    public PsiElementPredicate getElementPredicate() {
+        return new StringLiteralPredicate();
+    }
+
+    public void processIntention(PsiElement element)
+            throws IncorrectOperationException {
+        final GrLiteral exp = (GrLiteral) element;
+        final String textString = exp.getText();
+
+        replaceExpression(convertStringLiteralToGStringLiteral(textString), exp);
+    }
+
+    private static String convertStringLiteralToGStringLiteral(String stringLiteral) {
+        final String delimiter;
+        final String contents;
+        if (stringLiteral.startsWith("'''")) {
+            delimiter = "\"\"\"";
+            contents = stringLiteral.substring(3, stringLiteral.length() - 3);
+        } else {
+            delimiter = "\"";
+            contents = stringLiteral.substring(1, stringLiteral.length() - 1);
+        }
+        return delimiter + escape(contents) + delimiter;
+    }
+
+    private static String escape(String contents) {
+        final StringBuilder out = new StringBuilder();
+        final char[] chars = contents.toCharArray();
+        for (int i = 0; i < chars.length; i++) {
+            if (chars[i] == '\"') {
+                if (i > 0 && chars[i - 1] == '\\') {
+                    out.append('"');
+                } else {
+                    out.append("\\\"");
+                }
+            } else if (chars[i] == '$') {
+                if (i > 0 && chars[i - 1] == '\\') {
+                    out.append('$');
+                } else {
+                    out.append("\\$");
+                }
+            } else {
+                out.append(chars[i]);
+            }
+
+        }
+        return out.toString();
+    }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/ExpandBooleanPredicate.java	Sun Jul 29 08:42:14 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/ExpandBooleanPredicate.java	Sun Jul 29 08:42:14 EDT 2007
@@ -0,0 +1,64 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+class ExpandBooleanPredicate implements PsiElementPredicate {
+  private static Logger LOGGER = Logger.getInstance("ExpandBooleanPredicate");
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrStatement)) {
+      return false;
+    }
+    final GrStatement statement = (GrStatement) element;
+    return isBooleanReturn(statement) || isBooleanAssignment(statement);
+  }
+
+  public static boolean isBooleanReturn(GrStatement statement) {
+    if (!(statement instanceof GrReturnStatement)) {
+      return false;
+    }
+    final GrReturnStatement returnStatement =
+        (GrReturnStatement) statement;
+    final GrExpression returnValue = returnStatement.getReturnValue();
+    if (returnValue == null) {
+      return false;
+    }
+    if (returnValue instanceof GrLiteral) {
+      return false;
+    }
+    final PsiType returnType = returnValue.getType();
+    if (returnType == null) {
+      return false;
+    }
+    return returnType.equals(PsiType.BOOLEAN) || returnType.equalsToText("java.lang.Boolean");
+  }
+
+  public static boolean isBooleanAssignment(GrStatement expression) {
+
+    if (!(expression instanceof GrAssignmentExpression)) {
+      return false;
+    }
+    final GrAssignmentExpression assignment =
+        (GrAssignmentExpression) expression;
+    final GrExpression rhs = assignment.getRValue();
+    if (rhs == null) {
+      return false;
+    }
+    if (rhs instanceof GrLiteral) {
+      return false;
+    }
+    final PsiType assignmentType = rhs.getType();
+    if (assignmentType == null) {
+      return false;
+    }
+    return assignmentType.equals(PsiType.BOOLEAN) || assignmentType.equalsToText("java.lang.Boolean");
+  }
+}
--- src/org/jetbrains/plugins/groovy/intentions/closure/MakeClosureCallExplicitIntention.java	Thu Aug 02 15:47:42 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/closure/MakeClosureCallExplicitIntention.java	Thu Aug 02 15:47:42 EDT 2007
@@ -0,0 +1,39 @@
+package org.jetbrains.plugins.groovy.intentions.closure;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+
+public class MakeClosureCallExplicitIntention extends Intention {
+
+
+    @NotNull
+    public PsiElementPredicate getElementPredicate() {
+        return new ImplicitClosureCallPredicate();
+    }
+
+    public void processIntention(PsiElement element)
+            throws IncorrectOperationException {
+        final GrMethodCallExpression expression =
+                (GrMethodCallExpression) element;
+        final GrExpression invokedExpression = expression.getInvokedExpression();
+        final GrArgumentList argList = expression.getArgumentList();
+        final GrClosableBlock[] closureArgs = expression.getClosureArguments();
+        final StringBuilder newExpression = new StringBuilder();
+        newExpression.append(invokedExpression.getText());
+        newExpression.append(".call");
+        if (argList != null) {
+            newExpression.append(argList.getText());
+        }
+        for (GrClosableBlock closureArg : closureArgs) {
+            newExpression.append(closureArg.getText());
+        }
+        replaceExpression(newExpression.toString(), expression);
+    }
+}
\ No newline at end of file
--- testdata/intentions/IndexMethodConversion.groovy	Mon Aug 06 11:20:57 EDT 2007
+++ testdata/intentions/IndexMethodConversion.groovy	Mon Aug 06 11:20:57 EDT 2007
@@ -0,0 +1,6 @@
+
+Map q;
+x = y.getAt(z)
+x.setAt(y, z)
+x = q.get(z)
+q.put(y, z)
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/MergeIfAndIntention.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/MergeIfAndIntention.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,56 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.utils.ConditionalUtils;
+import org.jetbrains.plugins.groovy.intentions.utils.ParenthesesUtils;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+public class MergeIfAndIntention extends Intention {
+
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new MergeIfAndPredicate();
+  }
+
+  public void processIntention(PsiElement element)
+      throws IncorrectOperationException {
+    final GrIfStatement parentStatement =
+        (GrIfStatement) element;
+    assert parentStatement != null;
+    final GrStatement parentThenBranch = (GrStatement) parentStatement.getThenBranch();
+    final GrIfStatement childStatement =
+        (GrIfStatement) ConditionalUtils.stripBraces(parentThenBranch);
+
+    final GrExpression childCondition = (GrExpression) childStatement.getCondition();
+    final String childConditionText;
+    if (ParenthesesUtils.getPrecendence(childCondition)
+        > ParenthesesUtils.AND_PRECEDENCE) {
+      childConditionText = '(' + childCondition.getText() + ')';
+    } else {
+      childConditionText = childCondition.getText();
+    }
+
+    final GrExpression parentCondition = (GrExpression) parentStatement.getCondition();
+    final String parentConditionText;
+    if (ParenthesesUtils.getPrecendence(parentCondition)
+        > ParenthesesUtils.AND_PRECEDENCE) {
+      parentConditionText = '(' + parentCondition.getText() + ')';
+    } else {
+      parentConditionText = parentCondition.getText();
+    }
+
+    final GrStatement childThenBranch = (GrStatement) childStatement.getThenBranch();
+    @NonNls final String statement =
+        "if(" + parentConditionText + "&&" + childConditionText + ')' +
+            childThenBranch.getText();
+    replaceStatement(statement, parentStatement);
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.java	Wed Aug 01 14:49:13 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.java	Wed Aug 01 14:49:13 EDT 2007
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2000-2007 JetBrains s.r.o.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.plugins.groovy.intentions;
+
+import com.intellij.CommonBundle;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.PropertyKey;
+
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
+import java.util.ResourceBundle;
+
+/**
+ * @author ilyas
+ */
+public class GroovyIntentionsBundle {
+
+  private static Reference<ResourceBundle> ourBundle;
+
+  @NonNls
+  private static final String BUNDLE = "org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle";
+
+  public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Object... params) {
+    return CommonBundle.message(getBundle(), key, params);
+  }
+
+  private static ResourceBundle getBundle() {
+    ResourceBundle bundle = null;
+
+    if (ourBundle != null) bundle = ourBundle.get();
+
+    if (bundle == null) {
+      bundle = ResourceBundle.getBundle(BUNDLE);
+      ourBundle = new SoftReference<ResourceBundle>(bundle);
+    }
+    return bundle;
+  }
+
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/base/PsiElementPredicate.java	Sat Jul 28 16:34:15 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/base/PsiElementPredicate.java	Sat Jul 28 16:34:15 EDT 2007
@@ -0,0 +1,7 @@
+package org.jetbrains.plugins.groovy.intentions.base;
+
+import com.intellij.psi.PsiElement;
+
+public interface PsiElementPredicate {
+  boolean satisfiedBy(PsiElement element);
+}
--- resources/intentionDescriptions/ChangeToEndOfLineCommentIntention/before.groovy.template	Wed Aug 01 15:21:00 EDT 2007
+++ resources/intentionDescriptions/ChangeToEndOfLineCommentIntention/before.groovy.template	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,4 @@
+
+<spot>/*comment line 1
+comment line 2 */</spot>
+x = 0x30
\ No newline at end of file
--- resources/intentionDescriptions/MergeElseIfIntention/after.groovy.template	Tue Jul 31 14:32:28 EDT 2007
+++ resources/intentionDescriptions/MergeElseIfIntention/after.groovy.template	Tue Jul 31 14:32:28 EDT 2007
@@ -0,0 +1,13 @@
+public class X {
+  int f(int a) {
+    if (a == 0) {
+      return 0;
+    }
+    else if (a == 1) {
+      return 2;
+    }
+    else {
+      return 18;
+    }
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertibleGStringLiteralPredicate.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertibleGStringLiteralPredicate.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,20 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+
+class ConvertibleGStringLiteralPredicate implements PsiElementPredicate {
+
+    public boolean satisfiedBy(PsiElement element) {
+        if (!(element instanceof GrLiteral)) {
+            return false;
+        }
+
+        @NonNls final String text = element.getText();
+
+        return text.charAt(0) == '"' && !text.contains("$");
+    }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ConvertGStringToStringIntention/before.groovy.template	Sun Aug 05 12:38:23 EDT 2007
+++ resources/intentionDescriptions/ConvertGStringToStringIntention/before.groovy.template	Sun Aug 05 12:38:23 EDT 2007
@@ -0,0 +1,1 @@
+x = <spot>"48'"</spot>
\ No newline at end of file
--- resources/intentionDescriptions/ForToEachIntention/after.groovy.template	Sun Jul 29 11:48:53 EDT 2007
+++ resources/intentionDescriptions/ForToEachIntention/after.groovy.template	Sun Jul 29 11:48:53 EDT 2007
@@ -0,0 +1,2 @@
+
+[1, 2, 3].each{ x-> print(x) }
\ No newline at end of file
--- resources/intentionDescriptions/MergeElseIfIntention/description.html	Tue Jul 31 14:32:28 EDT 2007
+++ resources/intentionDescriptions/MergeElseIfIntention/description.html	Tue Jul 31 14:32:28 EDT 2007
@@ -0,0 +1,8 @@
+<html>
+<body>
+ <font face="verdana" size="-1">This intention merges the <b>else</b> branch of an <b>if-else</b> statement,
+if the <b>else</b> contains nothing but a nested <b>if-else</b> statement.<br>
+</font>
+
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/IndexedExpressionConversionIntention/before.groovy.template	Mon Aug 06 10:04:02 EDT 2007
+++ resources/intentionDescriptions/IndexedExpressionConversionIntention/before.groovy.template	Mon Aug 06 10:04:02 EDT 2007
@@ -0,0 +1,2 @@
+
+<spot>x = y.getAt(z) </spot>
--- src/org/jetbrains/plugins/groovy/intentions/control/FlipComparisonIntention.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/FlipComparisonIntention.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,49 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
+import org.jetbrains.plugins.groovy.intentions.utils.ComparisonUtils;
+import org.jetbrains.plugins.groovy.intentions.base.MutablyNamedIntention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+public class FlipComparisonIntention extends MutablyNamedIntention {
+  protected String getTextForElement(PsiElement element) {
+    final GrBinaryExpression binaryExpression =
+        (GrBinaryExpression) element;
+    final IElementType tokenType = binaryExpression.getOperationTokenType();
+    final String comparison = ComparisonUtils.getStringForComparison(tokenType);
+    final String flippedComparison = ComparisonUtils.getFlippedComparison(tokenType);
+
+    return GroovyIntentionsBundle.message("flip.comparison.intention.name", comparison, flippedComparison);
+  }
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ComparisonPredicate();
+  }
+
+  public void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException {
+    final GrBinaryExpression exp =
+        (GrBinaryExpression) element;
+    final IElementType tokenType = exp.getOperationTokenType();
+
+    final GrExpression lhs = exp.getLeftOperand();
+    final String lhsText = lhs.getText();
+
+    final GrExpression rhs = exp.getRightOperand();
+    final String rhsText = rhs.getText();
+
+    final String flippedComparison = ComparisonUtils.getFlippedComparison(tokenType);
+
+    final String newExpression =
+        rhsText + flippedComparison + lhsText;
+    replaceExpression(newExpression, exp);
+  }
+
+}
\ No newline at end of file
--- resources/intentionDescriptions/IndexingMethodConversionIntention/description.html	Mon Aug 06 10:04:02 EDT 2007
+++ resources/intentionDescriptions/IndexingMethodConversionIntention/description.html	Mon Aug 06 10:04:02 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts access to an indexed value using ".getAt()" or ".setAt()" methods to the equivalent [] form.
+</font>
+</body>
+</html>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,50 @@
+intention.category.groovy=Groovy
+intention.category.conversions=Expression conversions
+intention.category.closures=Closures
+intention.category.comments=Comments
+intention.category.control.flow=Control Flow
+demorgans.law.intention.family.name=DeMorgan's Law
+demorgans.intention.name1=Replace \\&\\& with ||
+demorgans.intention.name2=Replace || with \\&\\&
+merge.if.and.intention.name=Merge if's
+merge.if.and.intention.family.name=Merge Nested Ifs To ANDed Condition
+make.closure.call.explicit.intention.name=Make closure call explicit
+make.closure.call.explicit.intention.family.name=Make Closure Call Explicit
+make.closure.call.implicit.intention.name=Make closure call implicit
+make.closure.call.implicit.intention.family.name=Make Closure Call Implicit
+convert.closure.arg.to.it.intention.name=Convert closure arg to 'it'
+convert.closure.arg.to.it.intention.family.name=Convert Closure Arg To 'it'
+flip.conjunction.intention.family.name=Flip Conjunction Operands
+flip.comparison.intention.family.name=Flip Comparison Operands
+negate.comparison.intention.family.name=Negate Comparison
+expand.boolean.intention.name=Expand boolean use to if-else
+expand.boolean.intention.family.name=Expand Boolean
+for.to.each.intention.name=Replace with ".each"
+for.to.each.intention.family.name=Replace For-In With Each
+convert.integer.to.hex.intention.name=Convert to hex
+convert.integer.to.hex.intention.family.name=Convert To Hexadecimal
+convert.integer.to.decimal.intention.name=Convert to decimal
+convert.integer.to.decimal.intention.family.name=Convert To Decimal
+convert.integer.to.octal.intention.name=Convert to octal
+convert.integer.to.octal.intention.family.name=Convert To Octal
+flip.comparison.intention.name=Flip {0} to {1}
+negate.comparison.intention.name=Negate {0} to {1}
+flip.smth.intention.name=Flip {0}
+merge.else.if.intention.name=Merge else-if
+merge.else.if.intention.family.name=Merge Else If
+split.else.if.intention.name=Split else-if
+split.else.if.intention.family.name=Split Else If
+flip.conditional.intention.name=Flip ?:
+flip.conditional.intention.family.name=Flip Conditional
+change.to.end.of.line.comment.intention.name=Replace with end-of-line comment
+change.to.end.of.line.comment.intention.family.name=Replace With End Of Line Comment
+change.to.c.style.comment.intention.name=Replace with C-style comment
+change.to.c.style.comment.intention.family.name=Replace With C-Style Comment
+convert.string.to.g.string.intention.name=Convert to GString
+convert.string.to.g.string.intention.family.name=Convert String To GString
+convert.g.string.to.string.intention.name=Convert to String
+convert.g.string.to.string.intention.family.name=Convert GString To String
+indexing.method.conversion.intention.name=Convert to [] form
+indexing.method.conversion.intention.family.name=Convert Indexing Method To [] Form
+indexed.expression.conversion.intention.name=Convert [] access to method form
+indexed.expression.conversion.intention.family.name=Convert [] Form To Index Method
\ No newline at end of file
--- resources/intentionDescriptions/MakeClosureCallExplicitIntention/description.html	Thu Aug 02 15:43:56 EDT 2007
+++ resources/intentionDescriptions/MakeClosureCallExplicitIntention/description.html	Thu Aug 02 15:43:56 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+ <font face="verdana" size="-1">This converts an implicit call to a closure into an explicit call.<br>
+</font>
+
+</body>
+</html>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/closure/ConvertClosureArgToItIntention.java	Fri Aug 03 11:25:19 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/closure/ConvertClosureArgToItIntention.java	Fri Aug 03 11:25:19 EDT 2007
@@ -0,0 +1,52 @@
+package org.jetbrains.plugins.groovy.intentions.closure;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class ConvertClosureArgToItIntention extends Intention {
+
+
+    @NotNull
+    public PsiElementPredicate getElementPredicate() {
+        return new SingleArgClosurePredicate();
+    }
+
+    public void processIntention(PsiElement element)
+            throws IncorrectOperationException {
+        final GrClosableBlock closure =
+                (GrClosableBlock) element;
+
+        final GrParameterList parameterList = closure.getParameterList();
+        final GrParameter parameter = parameterList.getParameters()[0];
+        final Set<GrReferenceExpression> referencesToChange = new HashSet<GrReferenceExpression>();
+        final GroovyRecursiveElementVisitor visitor = new GroovyRecursiveElementVisitor() {
+            public void visitReferenceExpression(GrReferenceExpression referenceExpression) {
+                super.visitReferenceExpression(referenceExpression);
+                if (!referenceExpression.getText().equals(parameter.getName())) {
+                    return;
+                }
+                final PsiElement referent = referenceExpression.resolve();
+                if (parameter.equals(referent)) {
+                    referencesToChange.add(referenceExpression);
+                }
+            }
+        };
+        closure.accept(visitor);
+        parameter.delete();
+        for (GrReferenceExpression referenceExpression : referencesToChange) {
+            replaceExpression("it", referenceExpression );
+        }
+    }
+
+}
\ No newline at end of file
--- resources/intentionDescriptions/IndexingMethodConversionIntention/before.groovy.template	Mon Aug 06 10:04:02 EDT 2007
+++ resources/intentionDescriptions/IndexingMethodConversionIntention/before.groovy.template	Mon Aug 06 10:04:02 EDT 2007
@@ -0,0 +1,2 @@
+
+<spot>x = y.getAt(z) </spot>
--- resources/intentionDescriptions/MakeClosureCallExplicitIntention/after.groovy.template	Thu Aug 02 16:01:27 EDT 2007
+++ resources/intentionDescriptions/MakeClosureCallExplicitIntention/after.groovy.template	Thu Aug 02 16:01:27 EDT 2007
@@ -0,0 +1,3 @@
+
+def Closure myClosure
+myClosure.call(arg1, arg2)
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfPredicate.java	Wed Aug 01 16:35:27 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfPredicate.java	Wed Aug 01 16:35:27 EDT 2007
@@ -0,0 +1,26 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrBlockStatement;
+
+class SplitElseIfPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrIfStatement)) {
+      return false;
+    }
+    final GrIfStatement ifStatement = (GrIfStatement) element;
+    final GrCondition thenBranch = ifStatement.getThenBranch();
+    if (!(thenBranch instanceof GrStatement)) {
+      return false;
+    }
+    final GrCondition elseBranch = ifStatement.getElseBranch();
+    return elseBranch instanceof GrIfStatement;
+  }
+}
\ No newline at end of file
--- testdata/intentions/NegateComparison.groovy	Tue Jul 31 13:08:41 EDT 2007
+++ testdata/intentions/NegateComparison.groovy	Tue Jul 31 13:08:41 EDT 2007
@@ -0,0 +1,8 @@
+
+x = 3;
+y = 4;
+
+if(x == y)
+{
+    print "less"
+}
--- src/org/jetbrains/plugins/groovy/intentions/control/ExpandBooleanIntention.java	Sun Jul 29 08:25:42 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/ExpandBooleanIntention.java	Sun Jul 29 08:25:42 EDT 2007
@@ -0,0 +1,49 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+public class ExpandBooleanIntention extends Intention {
+
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ExpandBooleanPredicate();
+  }
+
+  public void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException {
+    final GrStatement containingStatement = (GrStatement) element;
+    if (ExpandBooleanPredicate.isBooleanAssignment(containingStatement)) {
+
+      final GrAssignmentExpression assignmentExpression =
+          (GrAssignmentExpression) containingStatement;
+      final GrExpression rhs = assignmentExpression.getRValue();
+      assert rhs != null;
+      final String rhsText = rhs.getText();
+      final GrExpression lhs = assignmentExpression.getLValue();
+      final String lhsText = lhs.getText();
+      @NonNls final String statement =
+          "if(" + rhsText + "){" + lhsText + " = true;}else{" +
+              lhsText +
+              " = false;}";
+      replaceStatement(statement, containingStatement);
+    } else if (ExpandBooleanPredicate.isBooleanReturn(containingStatement)) {
+      final GrReturnStatement returnStatement =
+          (GrReturnStatement) containingStatement;
+      final GrExpression returnValue = returnStatement.getReturnValue();
+      final String valueText = returnValue.getText();
+      @NonNls final String statement =
+          "if(" + valueText + "){return true;}else{return false;}";
+      replaceStatement(statement, containingStatement);
+    }
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ConvertStringToGStringIntention/before.groovy.template	Sun Aug 05 12:37:50 EDT 2007
+++ resources/intentionDescriptions/ConvertStringToGStringIntention/before.groovy.template	Sun Aug 05 12:37:50 EDT 2007
@@ -0,0 +1,1 @@
+x = <spot>'48$'</spot>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/closure/ForToEachIntention.java	Thu Aug 02 15:35:39 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/closure/ForToEachIntention.java	Thu Aug 02 15:35:39 EDT 2007
@@ -0,0 +1,45 @@
+package org.jetbrains.plugins.groovy.intentions.closure;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrBlockStatement;
+
+public class ForToEachIntention extends Intention {
+
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ForToEachPredicate();
+  }
+
+  public void processIntention(PsiElement element)
+      throws IncorrectOperationException {
+    final GrForStatement parentStatement =
+        (GrForStatement) element;
+    assert parentStatement != null;
+    final GrForInClause clause = (GrForInClause) parentStatement.getClause();
+    final GrVariable var = clause.getDeclaredVariables()[0];
+    final GrStatement body = parentStatement.getBody();
+    final String bodyText;
+    if (body instanceof GrBlockStatement) {
+      final String text = body.getText();
+      bodyText = text.substring(1, text.length()-1);
+    } else {
+      bodyText = body.getText();
+
+    }
+
+    final GrExpression collection = clause.getIteratedExpression();
+    @NonNls final String statement = collection.getText() + ".each{" + var.getText() + " -> " + bodyText + " }";
+    replaceStatement(statement, parentStatement);
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ConvertIntegerToHexIntention/before.groovy.template	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToHexIntention/before.groovy.template	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,2 @@
+
+x = <spot>48</spot>;
\ No newline at end of file
--- testdata/intentions/ArraySyntax.groovy	Mon Aug 06 15:40:21 EDT 2007
+++ testdata/intentions/ArraySyntax.groovy	Mon Aug 06 15:40:21 EDT 2007
@@ -0,0 +1,5 @@
+
+Map map = new HashMap();
+
+map[3] = 4
+print map[3]
--- resources/intentionDescriptions/ConvertClosureArgToItIntention/description.html	Thu Aug 02 15:43:56 EDT 2007
+++ resources/intentionDescriptions/ConvertClosureArgToItIntention/description.html	Thu Aug 02 15:43:56 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+ <font face="verdana" size="-1">This converts an implicit call to a closure into an explicit call.<br>
+</font>
+
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/MergeIfAndIntention/before.groovy.template	Sat Jul 28 23:26:53 EDT 2007
+++ resources/intentionDescriptions/MergeIfAndIntention/before.groovy.template	Sat Jul 28 23:26:53 EDT 2007
@@ -0,0 +1,6 @@
+public class X {
+  void f(a,  b) {
+    <spot>if (a)
+       if(b)
+         return;</spot>
+}
--- resources/intentionDescriptions/ForToEachIntention/description.html	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ForToEachIntention/description.html	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,8 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts selected integer literal (written in either <b>hexadecimal</b> or <b>octal</b> notation)
+into <b>decimal</b> notation.
+</font>
+</body>
+</html>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/comments/EndOfLineCommentPredicate.java	Wed Aug 01 14:49:13 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/comments/EndOfLineCommentPredicate.java	Wed Aug 01 14:49:13 EDT 2007
@@ -0,0 +1,24 @@
+package org.jetbrains.plugins.groovy.intentions.comments;
+
+import com.intellij.psi.JavaTokenType;
+import com.intellij.psi.PsiComment;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.javadoc.PsiDocComment;
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+
+class EndOfLineCommentPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof PsiComment)) {
+      return false;
+    }
+    if (element instanceof PsiDocComment) {
+      return false;
+    }
+    final PsiComment comment = (PsiComment) element;
+    final IElementType type = comment.getTokenType();
+    return GroovyTokenTypes.mSL_COMMENT.equals(type);
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToDecimalIntention.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToDecimalIntention.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,44 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+import java.math.BigInteger;
+
+public class ConvertIntegerToDecimalIntention extends Intention {
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ConvertIntegerToDecimalPredicate();
+  }
+
+  public void processIntention(PsiElement element)
+      throws IncorrectOperationException {
+    final GrLiteral exp = (GrLiteral) element;
+    @NonNls String textString = exp.getText();
+    final int textLength = textString.length();
+    final char lastChar = textString.charAt(textLength - 1);
+    final boolean isLong = lastChar == 'l' || lastChar == 'L';
+    if (isLong) {
+      textString = textString.substring(0, textLength - 1);
+    }
+    final BigInteger val;
+    if (textString.startsWith("0x")) {
+      final String rawIntString = textString.substring(2);
+      val = new BigInteger(rawIntString, 16);
+    } else {
+      final String rawIntString = textString.substring(1);
+      val = new BigInteger(rawIntString, 8);
+    }
+    String decimalString = val.toString(10);
+    if (isLong) {
+      decimalString += 'L';
+    }
+    replaceExpression(decimalString, exp);
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/comments/ChangeToCStyleCommentIntention.java	Wed Aug 01 15:08:43 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/comments/ChangeToCStyleCommentIntention.java	Wed Aug 01 15:08:43 EDT 2007
@@ -0,0 +1,116 @@
+package org.jetbrains.plugins.groovy.intentions.comments;
+
+import com.intellij.psi.*;
+import com.intellij.psi.codeStyle.CodeStyleManager;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ChangeToCStyleCommentIntention extends Intention {
+
+
+  @NotNull
+  protected PsiElementPredicate getElementPredicate() {
+    return new EndOfLineCommentPredicate();
+  }
+
+  public void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException {
+    final PsiComment selectedComment = (PsiComment) element;
+    PsiComment firstComment = selectedComment;
+
+    while (true) {
+      final PsiElement prevComment =
+          getPrevNonWhiteSpace(firstComment);
+      if (!isEndOfLineComment(prevComment)) {
+        break;
+      }
+      firstComment = (PsiComment) prevComment;
+    }
+    final PsiManager manager = selectedComment.getManager();
+    final PsiElementFactory factory = manager.getElementFactory();
+    String text = getCommentContents(firstComment);
+    final List<PsiElement> commentsToDelete = new ArrayList<PsiElement>();
+    PsiElement nextComment = firstComment;
+    while (true) {
+      nextComment = getNextNonWhiteSpace(nextComment);
+      if (!isEndOfLineComment(nextComment)) {
+        break;
+      }
+      text += nextComment.getPrevSibling().getText() + "  " //to get the whitespace for proper spacing
+          + getCommentContents((PsiComment) nextComment);
+      commentsToDelete.add(nextComment);
+    }
+    final PsiComment newComment =
+        factory.createCommentFromText("/*" + text + " */", selectedComment.getParent());
+    final PsiElement insertedElement = firstComment.replace(newComment);
+    final CodeStyleManager codeStyleManager = manager.getCodeStyleManager();
+    for (PsiElement commentToDelete : commentsToDelete) {
+      commentToDelete.delete();
+    }
+  }
+
+  @Nullable
+  private PsiElement getNextNonWhiteSpace(PsiElement nextComment) {
+    PsiElement elementToCheck = nextComment;
+    while(true)
+    {
+      final PsiElement sibling = elementToCheck.getNextSibling();
+      if(sibling == null)
+      {
+        return null;
+      }
+      if(sibling.getText().trim().replace("\n", "").length() == 0)
+      {
+         elementToCheck = sibling;
+      }
+      else
+      {
+        return sibling;
+      }
+    }
+  }
+
+  @Nullable
+  private PsiElement getPrevNonWhiteSpace(PsiElement nextComment) {
+    PsiElement elementToCheck = nextComment;
+    while(true)
+    {
+      final PsiElement sibling = elementToCheck.getPrevSibling();
+      if(sibling == null)
+      {
+        return null;
+      }
+      if(sibling.getText().trim().replace("\n", "").length() == 0)
+      {
+         elementToCheck = sibling;
+      }
+      else
+      {
+        return sibling;
+      }
+    }
+  }
+
+  private boolean isEndOfLineComment(PsiElement element) {
+    if (!(element instanceof PsiComment)) {
+      return false;
+    }
+    final PsiComment comment = (PsiComment) element;
+    final IElementType tokenType = comment.getTokenType();
+    return GroovyTokenTypes.mSL_COMMENT.equals(tokenType);
+  }
+
+  private static String getCommentContents(PsiComment comment) {
+    final String text = comment.getText();
+    return text.substring(2);
+  }
+}
--- src/org/jetbrains/plugins/groovy/intentions/conversions/StringLiteralPredicate.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/StringLiteralPredicate.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,21 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+
+class StringLiteralPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrLiteral)) {
+      return false;
+    }
+
+    @NonNls final String text = element.getText();
+
+    return text.charAt(0) == '\'';
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/closure/ExplicitClosureCallPredicate.java	Thu Aug 02 16:01:27 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/closure/ExplicitClosureCallPredicate.java	Thu Aug 02 16:01:27 EDT 2007
@@ -0,0 +1,43 @@
+package org.jetbrains.plugins.groovy.intentions.closure;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+
+class ExplicitClosureCallPredicate implements PsiElementPredicate {
+
+    public boolean satisfiedBy(PsiElement element) {
+        if (!(element instanceof GrMethodCallExpression)) {
+            return false;
+        }
+        final GrMethodCallExpression call = (GrMethodCallExpression) element;
+        final GrExpression invokedExpression = call.getInvokedExpression();
+        if (invokedExpression == null) {
+            return false;
+        }
+        if (!(invokedExpression instanceof GrReferenceExpression)) {
+            return false;
+        }
+        final GrReferenceExpression referenceExpression = (GrReferenceExpression) invokedExpression;
+        final String name = referenceExpression.getReferenceName();
+        if (!"call".equals(name)) {
+            return false;
+        }
+        final GrExpression qualifier = referenceExpression.getQualifierExpression();
+        if (qualifier == null) {
+            return false;
+        }
+        final PsiType qualifierType = qualifier.getType();
+        if (qualifierType == null) {
+            return false;
+        }
+        if (!qualifierType.equalsToText("groovy.lang.Closure")) {
+            return false;
+        }
+        return !ErrorUtil.containsError(element);
+    }
+}
\ No newline at end of file
--- resources/intentionDescriptions/NegateComparisonIntention/description.html	Tue Jul 31 11:49:49 EDT 2007
+++ resources/intentionDescriptions/NegateComparisonIntention/description.html	Tue Jul 31 11:49:49 EDT 2007
@@ -0,0 +1,6 @@
+<html>
+<body>
+<font face="verdana" size="-1">This intention negates a comparison to it's opposite.
+</font>
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/DemorgansLawIntention/before.groovy.template	Sat Jul 28 16:41:20 EDT 2007
+++ resources/intentionDescriptions/DemorgansLawIntention/before.groovy.template	Sat Jul 28 16:41:20 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    if (<spot>!a || !b</spot>) return;
+}
--- src/org/jetbrains/plugins/groovy/intentions/closure/ImplicitClosureCallPredicate.java	Thu Aug 02 16:01:27 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/closure/ImplicitClosureCallPredicate.java	Thu Aug 02 16:01:27 EDT 2007
@@ -0,0 +1,31 @@
+package org.jetbrains.plugins.groovy.intentions.closure;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+
+class ImplicitClosureCallPredicate implements PsiElementPredicate {
+
+    public boolean satisfiedBy(PsiElement element) {
+        if (!(element instanceof GrMethodCallExpression)) {
+            return false;
+        }
+        final GrMethodCallExpression call = (GrMethodCallExpression) element;
+        final GrExpression invokedExpression = call.getInvokedExpression();
+        if (invokedExpression == null) {
+            return false;
+        }
+        final PsiType type = invokedExpression.getType();
+        if(type == null)
+        {
+            return false;
+        }
+        if (!type.equalsToText("groovy.lang.Closure")) {
+            return false;
+        }
+        return !ErrorUtil.containsError(element);
+    }
+}
\ No newline at end of file
--- resources/intentionDescriptions/IndexedExpressionConversionIntention/description.html	Mon Aug 06 15:30:11 EDT 2007
+++ resources/intentionDescriptions/IndexedExpressionConversionIntention/description.html	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts access to an indexed value using "[]" to an equivalent call to a ".getAt()" or ".setAt()" method.
+</font>
+</body>
+</html>
\ No newline at end of file
--- testdata/intentions/ChangeToCStyleComment.groovy	Wed Aug 01 16:35:27 EDT 2007
+++ testdata/intentions/ChangeToCStyleComment.groovy	Wed Aug 01 16:35:27 EDT 2007
@@ -0,0 +1,9 @@
+/*comment */
+public void foo()
+{
+  /*comment
+    comment line 2
+    comment line 3
+    comment line 4 */
+
+}
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToHexIntention.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToHexIntention.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,45 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+import java.math.BigInteger;
+
+public class ConvertIntegerToHexIntention extends Intention {
+
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ConvertIntegerToHexPredicate();
+  }
+
+  public void processIntention(PsiElement element)
+      throws IncorrectOperationException {
+    final GrLiteral exp = (GrLiteral) element;
+    String textString = exp.getText();
+    final int textLength = textString.length();
+    final char lastChar = textString.charAt(textLength - 1);
+    final boolean isLong = lastChar == 'l' || lastChar == 'L';
+    if (isLong) {
+      textString = textString.substring(0, textLength - 1);
+    }
+
+    final BigInteger val;
+    if (textString.charAt(0) == '0') {
+      val = new BigInteger(textString, 8);
+    } else {
+      val = new BigInteger(textString, 10);
+    }
+    @NonNls String hexString = "0x" + val.toString(16);
+    if (isLong) {
+      hexString += 'L';
+    }
+    replaceExpression(hexString, exp);
+  }
+
+}
--- src/org/jetbrains/plugins/groovy/intentions/utils/ComparisonUtils.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/utils/ComparisonUtils.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,63 @@
+package org.jetbrains.plugins.groovy.intentions.utils;
+
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ComparisonUtils {
+  private static final Map<IElementType, String> s_comparisonStrings = new HashMap<IElementType, String>(6);
+  private static final Map<IElementType, String> s_swappedComparisons = new HashMap<IElementType, String>(6);
+  private static final Map<IElementType, String> s_invertedComparisons = new HashMap<IElementType, String>(6);
+
+  private ComparisonUtils() {
+    super();
+  }
+
+  static {
+    s_comparisonStrings.put(GroovyTokenTypes.mEQUAL, "==");
+    s_comparisonStrings.put(GroovyTokenTypes.mNOT_EQUAL, "!=");
+    s_comparisonStrings.put(GroovyTokenTypes.mGT, ">");
+    s_comparisonStrings.put(GroovyTokenTypes.mLT, "<");
+    s_comparisonStrings.put(GroovyTokenTypes.mGE, ">=");
+    s_comparisonStrings.put(GroovyTokenTypes.mLE, "<=");
+
+    s_swappedComparisons.put(GroovyTokenTypes.mEQUAL, "==");
+    s_swappedComparisons.put(GroovyTokenTypes.mNOT_EQUAL, "!=");
+    s_swappedComparisons.put(GroovyTokenTypes.mGT, "<");
+    s_swappedComparisons.put(GroovyTokenTypes.mLT, ">");
+    s_swappedComparisons.put(GroovyTokenTypes.mGE, "<=");
+    s_swappedComparisons.put(GroovyTokenTypes.mLE, ">=");
+
+    s_invertedComparisons.put(GroovyTokenTypes.mEQUAL, "!=");
+    s_invertedComparisons.put(GroovyTokenTypes.mNOT_EQUAL, "==");
+    s_invertedComparisons.put(GroovyTokenTypes.mGT, "<=");
+    s_invertedComparisons.put(GroovyTokenTypes.mLT, ">=");
+    s_invertedComparisons.put(GroovyTokenTypes.mGE, "<");
+    s_invertedComparisons.put(GroovyTokenTypes.mLE, ">");
+  }
+
+  public static boolean isComparison(GrExpression exp) {
+    if (!(exp instanceof GrBinaryExpression)) {
+      return false;
+    }
+    final GrBinaryExpression binaryExpression = (GrBinaryExpression) exp;
+    final IElementType sign = binaryExpression.getOperationTokenType();
+    return s_comparisonStrings.containsKey(sign);
+  }
+
+  public static String getStringForComparison(IElementType str) {
+    return s_comparisonStrings.get(str);
+  }
+
+  public static String getFlippedComparison(IElementType str) {
+    return s_swappedComparisons.get(str);
+  }
+
+  public static String getNegatedComparison(IElementType str) {
+    return s_invertedComparisons.get(str);
+  }
+}
--- resources/intentionDescriptions/ConvertIntegerToDecimalIntention/before.groovy.template	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToDecimalIntention/before.groovy.template	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,2 @@
+
+x = <spot>0x30</spot>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/utils/TreeUtil.java	Wed Aug 01 15:15:51 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/utils/TreeUtil.java	Wed Aug 01 15:15:51 EDT 2007
@@ -0,0 +1,52 @@
+package org.jetbrains.plugins.groovy.intentions.utils;
+
+import org.jetbrains.annotations.Nullable;
+import com.intellij.psi.PsiElement;
+
+public class TreeUtil {
+  private TreeUtil() {
+    super();
+  }
+
+  @Nullable
+  public static PsiElement getNextLeaf(PsiElement element) {
+    if (element == null) {
+      return null;
+    }
+    final PsiElement sibling = element.getNextSibling();
+    if (sibling == null) {
+      final PsiElement parent = element.getParent();
+      return getNextLeaf(parent);
+    }
+    return getFirstLeaf(sibling);
+  }
+
+  private static PsiElement getFirstLeaf(PsiElement element) {
+    final PsiElement[] children = element.getChildren();
+    if (children.length == 0) {
+      return element;
+    }
+    return getFirstLeaf(children[0]);
+  }
+
+  @Nullable
+  public static PsiElement getPrevLeaf(PsiElement element) {
+    if (element == null) {
+      return null;
+    }
+    final PsiElement sibling = element.getPrevSibling();
+    if (sibling == null) {
+      final PsiElement parent = element.getParent();
+      return getPrevLeaf(parent);
+    }
+    return getLastLeaf(sibling);
+  }
+
+  private static PsiElement getLastLeaf(PsiElement element) {
+    final PsiElement[] children = element.getChildren();
+    if (children.length == 0) {
+      return element;
+    }
+    return getLastLeaf(children[children.length - 1]);
+  }
+}
--- src/org/jetbrains/plugins/groovy/intentions/comments/ChangeToEndOfLineCommentIntention.java	Wed Aug 01 15:44:14 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/comments/ChangeToEndOfLineCommentIntention.java	Wed Aug 01 15:44:14 EDT 2007
@@ -0,0 +1,46 @@
+package org.jetbrains.plugins.groovy.intentions.comments;
+
+import com.intellij.psi.PsiComment;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiElementFactory;
+import com.intellij.psi.PsiManager;
+import com.intellij.psi.codeStyle.CodeStyleManager;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+
+public class ChangeToEndOfLineCommentIntention extends Intention {
+
+  @NotNull
+  protected PsiElementPredicate getElementPredicate() {
+    return new CStyleCommentPredicate();
+  }
+
+  public void processIntention(PsiElement element)
+      throws IncorrectOperationException {
+    final PsiComment comment = (PsiComment) element;
+    final PsiManager manager = comment.getManager();
+    final PsiElement parent = comment.getParent();
+    assert parent != null;
+    final PsiElementFactory factory = manager.getElementFactory();
+    final String commentText = comment.getText();
+    final PsiElement whitespace = comment.getNextSibling();
+    final String text = commentText.substring(2, commentText.length() - 2);
+    final String[] lines = text.split("\n");
+    for (int i = lines.length - 1; i >= 1; i--) {
+      final PsiComment nextComment =
+          factory.createCommentFromText("//" + lines[i].trim() + '\n',
+              parent);
+      parent.addAfter(nextComment, comment);
+     /* if (whitespace != null) {
+        final PsiElement newWhiteSpace =
+            factory.createWhiteSpaceFromText(whitespace.getText());
+        parent.addAfter(newWhiteSpace, comment);
+      }  */
+    }
+    final PsiComment newComment =
+        factory.createCommentFromText("//" + lines[0], parent);
+    comment.replace(newComment);
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/FlipConjunctionIntention/after.groovy.template	Tue Jul 31 09:40:08 EDT 2007
+++ resources/intentionDescriptions/FlipConjunctionIntention/after.groovy.template	Tue Jul 31 09:40:08 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    if (b &&a) return;
+}
\ No newline at end of file
--- resources/intentionDescriptions/ConvertIntegerToDecimalIntention/after.groovy.template	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToDecimalIntention/after.groovy.template	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,1 @@
+x = 48
\ No newline at end of file
--- resources/intentionDescriptions/NegateComparisonIntention/before.groovy.template	Tue Jul 31 09:41:51 EDT 2007
+++ resources/intentionDescriptions/NegateComparisonIntention/before.groovy.template	Tue Jul 31 09:41:51 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    if (<spot>a < b</spot>) return;
+}
--- src/org/jetbrains/plugins/groovy/intentions/conversions/IndexingMethodConversionPredicate.java	Mon Aug 06 15:13:58 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/IndexingMethodConversionPredicate.java	Mon Aug 06 15:13:58 EDT 2007
@@ -0,0 +1,94 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.*;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.util.InheritanceUtil;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+
+
+class IndexingMethodConversionPredicate implements PsiElementPredicate {
+    public boolean satisfiedBy(PsiElement element) {
+        if (!(element instanceof GrMethodCallExpression)) {
+            return false;
+        }
+
+        if (ErrorUtil.containsError(element)) {
+            return false;
+        }
+        final GrMethodCallExpression callExpression = (GrMethodCallExpression) element;
+        final GrArgumentList argList = callExpression.getArgumentList();
+        if (argList == null) {
+            return false;
+        }
+        final GrExpression[] arguments = argList.getExpressionArguments();
+
+        final GrExpression invokedExpression = callExpression.getInvokedExpression();
+        if (!(invokedExpression instanceof GrReferenceExpression)) {
+            return false;
+        }
+        final GrReferenceExpression referenceExpression = (GrReferenceExpression) invokedExpression;
+        final GrExpression qualifier = referenceExpression.getQualifierExpression();
+        if (qualifier == null) {
+            return false;
+        }
+        final IElementType referenceType = referenceExpression.getDotTokenType();
+        if (!GroovyTokenTypes.mDOT.equals(referenceType)) {
+            return false;
+        }
+        final String methodName = referenceExpression.getName();
+        if ("getAt".equals(methodName)) {
+            return arguments.length == 1;
+        }
+        if ("get".equals(methodName)) {
+            final PsiType qualifierType = qualifier.getType();
+            if (!isMap(qualifierType)) {
+                return false;
+            }
+            return arguments.length == 1;
+        } else if ("setAt".equals(methodName)) {
+            return arguments.length == 2;
+        } else if ("put".equals(methodName)) {
+            final PsiType qualifierType = qualifier.getType();
+            if (!isMap(qualifierType)) {
+                return false;
+            }
+            return arguments.length == 2;
+        }
+        return false;
+    }
+
+    private static boolean isMap(PsiType type) {
+        if (type == null) {
+            return false;
+        }
+        if (!(type instanceof PsiClassType)) {
+            return false;
+        }
+        final PsiClass referentClass = ((PsiClassType) type).resolve();
+        return isSubclass(referentClass, "java.util.Map");
+    }
+
+    public static boolean isSubclass(@Nullable PsiClass aClass,
+                                     @NonNls String ancestorName) {
+        if (aClass == null) {
+            return false;
+        }
+        final PsiManager psiManager = aClass.getManager();
+        final Project project = psiManager.getProject();
+        final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
+        final PsiClass ancestorClass =
+                psiManager.findClass(ancestorName, scope);
+        return InheritanceUtil.isCorrectDescendant(aClass, ancestorClass, true);
+    }
+
+}
\ No newline at end of file
--- resources/intentionDescriptions/SplitElseIfIntention/before.groovy.template	Wed Aug 01 16:35:27 EDT 2007
+++ resources/intentionDescriptions/SplitElseIfIntention/before.groovy.template	Wed Aug 01 16:35:27 EDT 2007
@@ -0,0 +1,14 @@
+
+public class X {
+  int f(int a) {
+    if (a == 0) {
+      return 0;
+    }
+    <spot>else</spot> if (a == 1) {
+      return 2;
+    }
+    else {
+      return 18;
+    }
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/FlipComparisonIntention/after.groovy.template	Tue Jul 31 09:41:51 EDT 2007
+++ resources/intentionDescriptions/FlipComparisonIntention/after.groovy.template	Tue Jul 31 09:41:51 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    if (b > a) return;
+}
\ No newline at end of file
--- resources/intentionDescriptions/FlipConjunctionIntention/before.groovy.template	Tue Jul 31 09:40:18 EDT 2007
+++ resources/intentionDescriptions/FlipConjunctionIntention/before.groovy.template	Tue Jul 31 09:40:18 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    if (<spot>a && b</spot>) return;
+}
--- resources/intentionDescriptions/ConvertClosureArgToItIntention/before.groovy.template	Thu Aug 02 21:45:14 EDT 2007
+++ resources/intentionDescriptions/ConvertClosureArgToItIntention/before.groovy.template	Thu Aug 02 21:45:14 EDT 2007
@@ -0,0 +1,2 @@
+
+def myClosure = <spot>{i -> print i}</spot>
\ No newline at end of file
--- resources/intentionDescriptions/ChangeToCStyleCommentIntention/description.html	Wed Aug 01 14:49:13 EDT 2007
+++ resources/intentionDescriptions/ChangeToCStyleCommentIntention/description.html	Wed Aug 01 14:49:13 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts one of more "end-of-line" comments to block comments.
+</font>
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/ChangeToEndOfLineCommentIntention/after.groovy.template	Wed Aug 01 15:21:00 EDT 2007
+++ resources/intentionDescriptions/ChangeToEndOfLineCommentIntention/after.groovy.template	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,4 @@
+
+//comment line 1
+//comment line 2
+x = 0x30
--- src/org/jetbrains/plugins/groovy/intentions/base/MutablyNamedIntention.java	Sat Jul 28 16:34:15 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/base/MutablyNamedIntention.java	Sat Jul 28 16:34:15 EDT 2007
@@ -0,0 +1,26 @@
+package org.jetbrains.plugins.groovy.intentions.base;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.editor.Editor;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class MutablyNamedIntention extends Intention {
+  private String text = null;
+
+  protected abstract String getTextForElement(PsiElement element);
+
+  @NotNull
+  public String getText() {
+    return text;
+  }
+
+  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
+    final PsiElement element = findMatchingElement(file, editor);
+    if (element != null) {
+      text = getTextForElement(element);
+    }
+    return element != null;
+  }
+}
--- testdata/intentions/IntegerConversion.groovy	Sun Jul 29 11:32:43 EDT 2007
+++ testdata/intentions/IntegerConversion.groovy	Sun Jul 29 11:32:43 EDT 2007
@@ -0,0 +1,2 @@
+
+int x = 30;
--- resources/intentionDescriptions/ConvertIntegerToOctalIntention/after.groovy.template	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToOctalIntention/after.groovy.template	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,2 @@
+
+x = 060;
\ No newline at end of file
--- testdata/intentions/FlipConditional.groovy	Wed Aug 01 14:13:58 EDT 2007
+++ testdata/intentions/FlipConditional.groovy	Wed Aug 01 14:13:58 EDT 2007
@@ -0,0 +1,6 @@
+
+x = 3;
+y = 4;
+
+x <= y?x:y
+
--- resources/intentionDescriptions/MakeClosureCallImplicitIntention/description.html	Thu Aug 02 16:01:27 EDT 2007
+++ resources/intentionDescriptions/MakeClosureCallImplicitIntention/description.html	Thu Aug 02 16:01:27 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+ <font face="verdana" size="-1">This converts an explicit call to a closure into an implicit call.<br>
+</font>
+
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/ConvertIntegerToOctalIntention/before.groovy.template	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToOctalIntention/before.groovy.template	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,2 @@
+
+x = <spot>48</spot>;
\ No newline at end of file
--- resources/intentionDescriptions/IndexingMethodConversionIntention/after.groovy.template	Mon Aug 06 10:04:02 EDT 2007
+++ resources/intentionDescriptions/IndexingMethodConversionIntention/after.groovy.template	Mon Aug 06 10:04:02 EDT 2007
@@ -0,0 +1,2 @@
+
+x = y[z]
--- src/org/jetbrains/plugins/groovy/intentions/control/ConjunctionPredicate.java	Sun Jul 29 08:25:42 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/ConjunctionPredicate.java	Sun Jul 29 08:25:42 EDT 2007
@@ -0,0 +1,24 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+
+class ConjunctionPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrBinaryExpression)) {
+      return false;
+    }
+    final GrBinaryExpression expression = (GrBinaryExpression) element;
+    final IElementType tokenType =  expression.getOperationTokenType();
+    if (!tokenType.equals(GroovyTokenTypes.mLAND) &&
+        !tokenType.equals(GroovyTokenTypes.mLOR)) {
+      return false;
+    }
+    return !ErrorUtil.containsError(element);
+  }
+}
--- resources/intentionDescriptions/ChangeToEndOfLineCommentIntention/description.html	Wed Aug 01 15:21:00 EDT 2007
+++ resources/intentionDescriptions/ChangeToEndOfLineCommentIntention/description.html	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts a block comment to one or more "end-of-line" comments.
+</font>
+</body>
+</html>
\ No newline at end of file
--- testdata/intentions/FlipComparison.groovy	Tue Jul 31 13:08:41 EDT 2007
+++ testdata/intentions/FlipComparison.groovy	Tue Jul 31 13:08:41 EDT 2007
@@ -0,0 +1,8 @@
+
+x = 3;
+y = 4;
+
+if(x <= y)
+{
+    print "less"
+}
--- testdata/intentions/MergeElseIf.groovy	Sun Aug 05 21:26:27 EDT 2007
+++ testdata/intentions/MergeElseIf.groovy	Sun Aug 05 21:26:27 EDT 2007
@@ -0,0 +1,8 @@
+if (foo()) {
+  print "bar"
+} else {
+  if (bar())
+  {
+    print "baz"
+  }
+}
--- resources/intentionDescriptions/ConvertIntegerToOctalIntention/description.html	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToOctalIntention/description.html	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,8 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts selected integer literal (written in either <b>decimal</b> or <b>hexadecimal</b> notation)
+back into <b>octal</b> notation.
+</font>
+</body>
+</html>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/MergeElseIfPredicate.java	Tue Jul 31 14:52:31 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/MergeElseIfPredicate.java	Tue Jul 31 14:52:31 EDT 2007
@@ -0,0 +1,32 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrBlockStatement;
+
+class MergeElseIfPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrIfStatement)) {
+      return false;
+    }
+    final GrIfStatement ifStatement = (GrIfStatement) element;
+    final GrCondition thenBranch = ifStatement.getThenBranch();
+    if (!(thenBranch instanceof GrStatement)) {
+      return false;
+    }
+    final GrCondition elseBranch = ifStatement.getElseBranch();
+    if (!(elseBranch instanceof GrOpenBlock)) {
+      return false;
+    }
+    final GrOpenBlock block = ((GrOpenBlock) elseBranch);
+    final GrStatement[] statements = block.getStatements();
+    return statements.length == 1 &&
+        statements[0] instanceof GrIfStatement;
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/MergeIfAndPredicate.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/MergeIfAndPredicate.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,41 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import org.jetbrains.plugins.groovy.intentions.utils.ConditionalUtils;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+
+
+class MergeIfAndPredicate implements PsiElementPredicate {
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrIfStatement)) {
+      return false;
+    }
+    final GrIfStatement ifStatement = (GrIfStatement) element;
+    if (ErrorUtil.containsError(ifStatement)) {
+      return false;
+    }
+    GrCondition thenBranch = ifStatement.getThenBranch();
+    if (!(thenBranch instanceof GrStatement)) {
+      return false;
+    }
+    thenBranch = ConditionalUtils.stripBraces((GrStatement) thenBranch);
+    if (!(thenBranch instanceof GrIfStatement)) {
+      return false;
+    }
+    GrCondition elseBranch = ifStatement.getElseBranch();
+    if (elseBranch != null) {
+      elseBranch = ConditionalUtils.stripBraces((GrStatement) elseBranch);
+      if (elseBranch != null) {
+        return false;
+      }
+    }
+
+    final GrIfStatement childIfStatement = (GrIfStatement) thenBranch;
+
+    return childIfStatement.getElseBranch() == null;
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ConvertGStringToStringIntention/description.html	Sun Aug 05 12:38:23 EDT 2007
+++ resources/intentionDescriptions/ConvertGStringToStringIntention/description.html	Sun Aug 05 12:38:23 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+<font face="verdana" size="-1">
+This intention converts selected GString literal into an equivalent String literal.
+</font>
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/ConvertIntegerToHexIntention/after.groovy.template	Sun Jul 29 09:22:38 EDT 2007
+++ resources/intentionDescriptions/ConvertIntegerToHexIntention/after.groovy.template	Sun Jul 29 09:22:38 EDT 2007
@@ -0,0 +1,2 @@
+
+x = 0x30;
\ No newline at end of file
--- resources/intentionDescriptions/DemorgansLawIntention/after.groovy.template	Sat Jul 28 16:41:20 EDT 2007
+++ resources/intentionDescriptions/DemorgansLawIntention/after.groovy.template	Sat Jul 28 16:41:20 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    if (!(a && b)) return;
+}
\ No newline at end of file
--- resources/intentionDescriptions/FlipConditionalIntention/after.groovy.template	Wed Aug 01 14:08:46 EDT 2007
+++ resources/intentionDescriptions/FlipConditionalIntention/after.groovy.template	Wed Aug 01 14:08:46 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    return a<=b?b:a
+}
--- resources/intentionDescriptions/FlipConditionalIntention/description.html	Wed Aug 01 14:08:46 EDT 2007
+++ resources/intentionDescriptions/FlipConditionalIntention/description.html	Wed Aug 01 14:08:46 EDT 2007
@@ -0,0 +1,6 @@
+<html>
+<body>
+<font face="verdana" size="-1">This intention flips branches of the conditional operator.
+</font>
+</body>
+</html>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/conversions/IndexingMethodConversionIntention.java	Mon Aug 06 15:13:36 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/IndexingMethodConversionIntention.java	Mon Aug 06 15:13:36 EDT 2007
@@ -0,0 +1,44 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
+
+public class IndexingMethodConversionIntention extends Intention {
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new IndexingMethodConversionPredicate();
+  }
+
+  public void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException {
+    final GrMethodCallExpression callExpression =
+        (GrMethodCallExpression) element;
+      final GrArgumentList argList = callExpression.getArgumentList();
+      final GrExpression[] arguments = argList.getExpressionArguments();
+
+      GrReferenceExpression methodExpression = (GrReferenceExpression) callExpression.getInvokedExpression();
+      final IElementType referenceType = methodExpression.getDotTokenType();
+
+      final String methodName = methodExpression.getName();
+      final GrExpression qualifier = methodExpression.getQualifierExpression();
+      if("getAt".equals(methodName)|| "get".equals(methodName))
+      {
+          replaceExpression(qualifier.getText() + '[' + arguments[0].getText() + ']',
+                  callExpression);
+      }
+      else{
+          replaceExpression(qualifier.getText() + '[' + arguments[0].getText() + "]=" +arguments[1].getText(),
+                  callExpression);
+      }
+  }
+
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/FlipConditionalIntention.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/FlipConditionalIntention.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,38 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.utils.BoolUtils;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+public class FlipConditionalIntention extends Intention {
+
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ConditionalPredicate();
+  }
+
+  public void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException {
+    final GrConditionalExpression exp =
+        (GrConditionalExpression) element;
+
+    final GrExpression condition = exp.getCondition();
+    final GrExpression elseExpression = exp.getElseBranch();
+    final GrExpression thenExpression = exp.getThenBranch();
+    assert elseExpression != null;
+    assert thenExpression != null;
+    final String newExpression =
+        BoolUtils.getNegatedExpressionText(condition) + '?' +
+            elseExpression.getText() +
+            ':' +
+            thenExpression.getText();
+    replaceExpression(newExpression, exp);
+  }
+
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/base/Intention.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/base/Intention.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,163 @@
+package org.jetbrains.plugins.groovy.intentions.base;
+
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.openapi.editor.CaretModel;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.ReadonlyStatusHandler;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.*;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
+import org.jetbrains.plugins.groovy.intentions.utils.BoolUtils;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyElementFactory;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+
+
+public abstract class Intention implements IntentionAction {
+  private final PsiElementPredicate predicate;
+
+  /**
+   * @noinspection AbstractMethodCallInConstructor,OverridableMethodCallInConstructor
+   */
+  protected Intention() {
+    super();
+    predicate = getElementPredicate();
+  }
+
+  public void invoke(@NotNull Project project, Editor editor, PsiFile file)
+      throws IncorrectOperationException {
+    if (isFileReadOnly(project, file)) {
+      return;
+    }
+    final PsiElement element = findMatchingElement(file, editor);
+    if (element == null) {
+      return;
+    }
+    processIntention(element);
+  }
+
+  protected abstract void processIntention(@NotNull PsiElement element)
+      throws IncorrectOperationException;
+
+  @NotNull
+  protected abstract PsiElementPredicate getElementPredicate();
+
+  protected static void replaceExpression(@NotNull String newExpression,
+                                          @NotNull GrExpression expression)
+      throws IncorrectOperationException {
+    final PsiManager mgr = expression.getManager();
+    final GroovyElementFactory factory = GroovyElementFactory.getInstance(expression.getProject());
+    final GrExpression newCall =
+        factory.createExpressionFromText(newExpression);
+    final PsiElement insertedElement = expression.replaceWithExpression(newCall);
+  //  final CodeStyleManager codeStyleManager = mgr.getCodeStyleManager();
+   // codeStyleManager.reformat(insertedElement);
+  }
+
+
+  protected static void replaceStatement(
+      @NonNls @NotNull String newStatement,
+      @NonNls @NotNull GrStatement statement)
+      throws IncorrectOperationException {
+    final PsiManager mgr = statement.getManager();
+    final GroovyElementFactory factory = GroovyElementFactory.getInstance(statement.getProject());
+    final GrStatement newCall =
+        (GrStatement) factory.createTopElementFromText(newStatement);
+    final PsiElement insertedElement = statement.replaceWithStatement(newCall);
+  //  final CodeStyleManager codeStyleManager = mgr.getCodeStyleManager();
+   // codeStyleManager.reformat(insertedElement);
+  }
+
+
+  protected static void replaceExpressionWithNegatedExpressionString(
+      @NotNull String newExpression,
+      @NotNull GrExpression expression)
+      throws IncorrectOperationException {
+    final PsiManager mgr = expression.getManager();
+    final GroovyElementFactory factory = GroovyElementFactory.getInstance(expression.getProject());
+
+    GrExpression expressionToReplace = expression;
+    final String expString;
+    if (BoolUtils.isNegated(expression)) {
+      expressionToReplace = BoolUtils.findNegation(expression);
+      expString = newExpression;
+    } else {
+      expString = "!(" + newExpression + ')';
+    }
+    final GrExpression newCall =
+        factory.createExpressionFromText(expString);
+    assert expressionToReplace != null;
+    final PsiElement insertedElement = expressionToReplace.replaceWithExpression(newCall);
+   //  final CodeStyleManager codeStyleManager = mgr.getCodeStyleManager();
+   //  codeStyleManager.reformat(insertedElement);
+  }
+
+
+  @Nullable
+  PsiElement findMatchingElement(PsiFile file,
+                                 Editor editor) {
+    final CaretModel caretModel = editor.getCaretModel();
+    final int position = caretModel.getOffset();
+    PsiElement element = file.findElementAt(position);
+    while (element != null) {
+      if (predicate.satisfiedBy(element)) {
+        return element;
+      } else {
+        element = element.getParent();
+        if (element instanceof PsiFile) {
+          break;
+        }
+      }
+    }
+    return null;
+  }
+
+  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
+    return findMatchingElement(file, editor) != null;
+  }
+
+  public boolean startInWriteAction() {
+    return true;
+  }
+
+  private static boolean isFileReadOnly(Project project, PsiFile file) {
+    final VirtualFile virtualFile = file.getVirtualFile();
+    final ReadonlyStatusHandler readonlyStatusHandler =
+        ReadonlyStatusHandler.getInstance(project);
+    final ReadonlyStatusHandler.OperationStatus operationStatus =
+        readonlyStatusHandler.ensureFilesWritable(virtualFile);
+    return operationStatus.hasReadonlyFiles();
+  }
+
+  private String getPrefix() {
+    final Class<? extends Intention> aClass = getClass();
+    final String name = aClass.getSimpleName();
+    final StringBuilder buffer = new StringBuilder(name.length() + 10);
+    buffer.append(Character.toLowerCase(name.charAt(0)));
+    for (int i = 1; i < name.length(); i++) {
+      final char c = name.charAt(i);
+      if (Character.isUpperCase(c)) {
+        buffer.append('.');
+        buffer.append(Character.toLowerCase(c));
+      } else {
+        buffer.append(c);
+      }
+    }
+    return buffer.toString();
+  }
+
+  @NotNull
+  public String getText() {
+    return GroovyIntentionsBundle.message(getPrefix() + ".name");
+  }
+
+  @NotNull
+  public String getFamilyName() {
+    return GroovyIntentionsBundle.message(getPrefix() + ".family.name");
+  }
+}
--- resources/intentionDescriptions/MergeIfAndIntention/description.html	Sat Jul 28 23:27:12 EDT 2007
+++ resources/intentionDescriptions/MergeIfAndIntention/description.html	Sat Jul 28 23:27:12 EDT 2007
@@ -0,0 +1,7 @@
+<html>
+<body>
+  <font face="verdana" size="-1">This intention merges <b>if-else</b> statement inside then-branch of another <b>if-else</b> into one.<br>
+  </font>
+
+</body>
+</html>
\ No newline at end of file
--- resources/intentionDescriptions/IndexedExpressionConversionIntention/after.groovy.template	Mon Aug 06 10:04:02 EDT 2007
+++ resources/intentionDescriptions/IndexedExpressionConversionIntention/after.groovy.template	Mon Aug 06 10:04:02 EDT 2007
@@ -0,0 +1,2 @@
+
+x = y[z]
--- resources/intentionDescriptions/NegateComparisonIntention/after.groovy.template	Tue Jul 31 11:49:49 EDT 2007
+++ resources/intentionDescriptions/NegateComparisonIntention/after.groovy.template	Tue Jul 31 11:49:49 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    if (!(b >= a)) return;
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/control/MergeElseIfIntention.java	Tue Jul 31 15:00:34 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/MergeElseIfIntention.java	Tue Jul 31 15:00:34 EDT 2007
@@ -0,0 +1,30 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrBlockStatement;
+
+public class MergeElseIfIntention extends Intention {
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new MergeElseIfPredicate();
+  }
+
+  public void processIntention(PsiElement element)
+      throws IncorrectOperationException {
+    final GrIfStatement parentStatement = (GrIfStatement) element;
+    assert parentStatement != null;
+    final GrOpenBlock elseBranch =
+        (GrOpenBlock) parentStatement.getElseBranch();
+    assert elseBranch != null;
+    final GrStatement elseBranchContents = elseBranch.getStatements()[0];
+    replaceStatement("if(" + parentStatement.getCondition().getText()+ ")"+ parentStatement.getThenBranch().getText() + "else " + elseBranchContents.getText(), parentStatement);
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/FlipConditionalIntention/before.groovy.template	Wed Aug 01 14:08:46 EDT 2007
+++ resources/intentionDescriptions/FlipConditionalIntention/before.groovy.template	Wed Aug 01 14:08:46 EDT 2007
@@ -0,0 +1,4 @@
+public class X {
+  void f(a,  b) {
+    return <spot>a>b?a:b</spot>
+}
--- resources/intentionDescriptions/MergeElseIfIntention/before.groovy.template	Tue Jul 31 14:32:28 EDT 2007
+++ resources/intentionDescriptions/MergeElseIfIntention/before.groovy.template	Tue Jul 31 14:32:28 EDT 2007
@@ -0,0 +1,15 @@
+public class X {
+  int f(int a) {
+    if (a == 0) {
+      return 0;
+    }
+    <spot>else</spot> {
+      if (a == 1) {
+        return 2;
+      }
+      else {
+        return 18;
+      }
+    }
+  }
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsProvider.java	Mon Aug 06 15:40:21 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsProvider.java	Mon Aug 06 15:40:21 EDT 2007
@@ -0,0 +1,70 @@
+package org.jetbrains.plugins.groovy.intentions;
+
+import com.intellij.codeInsight.intention.IntentionManager;
+import com.intellij.openapi.components.ProjectComponent;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.closure.ForToEachIntention;
+import org.jetbrains.plugins.groovy.intentions.closure.MakeClosureCallExplicitIntention;
+import org.jetbrains.plugins.groovy.intentions.closure.MakeClosureCallImplicitIntention;
+import org.jetbrains.plugins.groovy.intentions.comments.ChangeToCStyleCommentIntention;
+import org.jetbrains.plugins.groovy.intentions.control.*;
+import org.jetbrains.plugins.groovy.intentions.conversions.*;
+import org.jetbrains.plugins.groovy.intentions.conversions.ConvertGStringToStringIntention;
+import org.jetbrains.plugins.groovy.intentions.conversions.ConvertStringToGStringIntention;
+
+
+public class GroovyIntentionsProvider implements ProjectComponent {
+  @SuppressWarnings({"UnusedDeclaration"})
+  public GroovyIntentionsProvider(Project project) {
+    final IntentionManager mgr = IntentionManager.getInstance();
+
+    final String groovyCategory = GroovyIntentionsBundle.message("intention.category.groovy");
+    final String controlCategory = GroovyIntentionsBundle.message("intention.category.control.flow");
+    mgr.registerIntentionAndMetaData(new DemorgansLawIntention(), groovyCategory, controlCategory);
+    mgr.registerIntentionAndMetaData(new MergeIfAndIntention(), groovyCategory, controlCategory);
+    mgr.registerIntentionAndMetaData(new ExpandBooleanIntention(), groovyCategory, controlCategory);
+    mgr.registerIntentionAndMetaData(new FlipConjunctionIntention(), groovyCategory, controlCategory);
+    mgr.registerIntentionAndMetaData(new FlipComparisonIntention(), groovyCategory, controlCategory);
+    mgr.registerIntentionAndMetaData(new NegateComparisonIntention(), groovyCategory, controlCategory);
+    mgr.registerIntentionAndMetaData(new MergeElseIfIntention(), groovyCategory, controlCategory);
+    mgr.registerIntentionAndMetaData(new SplitElseIfIntention(), groovyCategory, controlCategory);
+    mgr.registerIntentionAndMetaData(new FlipConditionalIntention(), groovyCategory, controlCategory);
+      final String closuresCategory = GroovyIntentionsBundle.message("intention.category.closures");
+      mgr.registerIntentionAndMetaData(new MakeClosureCallExplicitIntention(), groovyCategory, closuresCategory);
+      mgr.registerIntentionAndMetaData(new MakeClosureCallImplicitIntention(), groovyCategory, closuresCategory);
+      mgr.registerIntentionAndMetaData(new ForToEachIntention(), groovyCategory, closuresCategory);
+      //  TODO: make this work
+      //  mgr.registerIntentionAndMetaData(new ConvertClosureArgToItIntention(), groovyCategory, closuresCategory);
+      final String commentCategory = GroovyIntentionsBundle.message("intention.category.comments");
+    mgr.registerIntentionAndMetaData(new ChangeToCStyleCommentIntention(),groovyCategory, commentCategory);
+    //  TODO: make this work
+    //    mgr.registerIntentionAndMetaData(new ChangeToEndOfLineCommentIntention(),groovyCategory, commentCategory);
+    final String conversionsCategory = GroovyIntentionsBundle.message("intention.category.conversions");
+    mgr.registerIntentionAndMetaData(new ConvertIntegerToDecimalIntention(),groovyCategory, conversionsCategory);
+    mgr.registerIntentionAndMetaData(new ConvertIntegerToHexIntention(), groovyCategory, conversionsCategory);
+    mgr.registerIntentionAndMetaData(new ConvertIntegerToOctalIntention(), groovyCategory, conversionsCategory);
+      mgr.registerIntentionAndMetaData(new IndexingMethodConversionIntention(), groovyCategory, conversionsCategory);
+      mgr.registerIntentionAndMetaData(new IndexedExpressionConversionIntention(), groovyCategory, conversionsCategory);
+
+      mgr.registerIntentionAndMetaData(new ConvertStringToGStringIntention(), groovyCategory, conversionsCategory);
+      mgr.registerIntentionAndMetaData(new ConvertGStringToStringIntention(), groovyCategory, conversionsCategory);
+  }
+
+  public void initComponent() {
+  }
+
+  public void disposeComponent() {
+  }
+
+  @NotNull
+  public String getComponentName() {
+    return "GroovyIntentionsProvider";
+  }
+
+  public void projectOpened() {
+  }
+
+  public void projectClosed() {
+  }
+}
--- src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToOctalIntention.java	Mon Aug 06 15:30:11 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertIntegerToOctalIntention.java	Mon Aug 06 15:30:11 EDT 2007
@@ -0,0 +1,44 @@
+package org.jetbrains.plugins.groovy.intentions.conversions;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+
+import java.math.BigInteger;
+
+public class ConvertIntegerToOctalIntention extends Intention {
+
+
+  @NotNull
+  public PsiElementPredicate getElementPredicate() {
+    return new ConvertIntegerToOctalPredicate();
+  }
+
+  public void processIntention(PsiElement element)
+      throws IncorrectOperationException {
+    final GrLiteral exp = (GrLiteral) element;
+    @NonNls String textString = exp.getText();
+    final int textLength = textString.length();
+    final char lastChar = textString.charAt(textLength - 1);
+    final boolean isLong = lastChar == 'l' || lastChar == 'L';
+    if (isLong) {
+      textString = textString.substring(0, textLength - 1);
+    }
+    final BigInteger val;
+    if (textString.startsWith("0x")) {
+      final String rawTextString = textString.substring(2);
+      val = new BigInteger(rawTextString, 16);
+    } else {
+      val = new BigInteger(textString, 10);
+    }
+    String octString = '0' + val.toString(8);
+    if (isLong) {
+      octString += 'L';
+    }
+    replaceExpression(octString, exp);
+  }
+}
--- src/org/jetbrains/plugins/groovy/intentions/utils/ParenthesesUtils.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/utils/ParenthesesUtils.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,133 @@
+package org.jetbrains.plugins.groovy.intentions.utils;
+
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ParenthesesUtils {
+
+  private ParenthesesUtils() {
+    super();
+  }
+
+  private static final int PARENTHESIZED_PRECEDENCE = 0;
+  private static final int LITERAL_PRECEDENCE = 0;
+  public static final int METHOD_CALL_PRECEDENCE = 1;
+
+  private static final int POSTFIX_PRECEDENCE = 2;
+  public static final int PREFIX_PRECEDENCE = 3;
+  public static final int TYPE_CAST_PRECEDENCE = 4;
+  public static final int EXPONENTIAL_PRECEDENCE = 5;
+  public static final int MULTIPLICATIVE_PRECEDENCE = 6;
+  private static final int ADDITIVE_PRECEDENCE = 7;
+  public static final int SHIFT_PRECEDENCE = 8;
+  private static final int RELATIONAL_PRECEDENCE = 9;
+  public static final int EQUALITY_PRECEDENCE = 10;
+
+  private static final int BINARY_AND_PRECEDENCE = 11;
+  private static final int BINARY_XOR_PRECEDENCE = 12;
+  private static final int BINARY_OR_PRECEDENCE = 13;
+  public static final int AND_PRECEDENCE = 14;
+  public static final int OR_PRECEDENCE = 15;
+  public static final int CONDITIONAL_PRECEDENCE = 16;
+  private static final int ASSIGNMENT_PRECEDENCE = 17;
+
+  private static final int NUM_PRECEDENCES = 18;
+
+  private static final Map<IElementType, Integer> s_binaryOperatorPrecedence =
+      new HashMap<IElementType, Integer>(NUM_PRECEDENCES);
+
+  static {
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mPLUS, ADDITIVE_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mMINUS, ADDITIVE_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mSTAR, MULTIPLICATIVE_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mDIV, MULTIPLICATIVE_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mMOD, MULTIPLICATIVE_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mSTAR_STAR, EXPONENTIAL_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mLAND, AND_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mLOR, OR_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mBAND, BINARY_AND_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mBOR, BINARY_OR_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mBXOR, BINARY_XOR_PRECEDENCE);
+   // s_binaryOperatorPrecedence.put(GroovyTokenTypes.mBSL, SHIFT_PRECEDENCE);
+   // s_binaryOperatorPrecedence.put(GroovyTokenTypes.mBSR, SHIFT_PRECEDENCE);
+  //  s_binaryOperatorPrecedence.put(">>>", SHIFT_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mGT, RELATIONAL_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mGE, RELATIONAL_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mLT, RELATIONAL_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mLE, RELATIONAL_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mEQUAL, EQUALITY_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mNOT_EQUAL, EQUALITY_PRECEDENCE);
+    s_binaryOperatorPrecedence.put(GroovyTokenTypes.mCOMPARE_TO, EQUALITY_PRECEDENCE);
+  }
+
+  @Nullable
+  public static GrExpression stripParentheses(
+      @Nullable GrExpression expression) {
+    GrExpression parenthesized = expression;
+    while (parenthesized instanceof GrParenthesizedExpr) {
+      final GrParenthesizedExpr parenthesizedExpression =
+          (GrParenthesizedExpr) parenthesized;
+      parenthesized = parenthesizedExpression.getOperand();
+    }
+    return parenthesized;
+  }
+
+  public static int getPrecendence(GrExpression expression) {
+    if (expression instanceof GrThisReferenceExpression ||
+        expression instanceof GrLiteral ||
+        expression instanceof GrSuperReferenceExpression ) {
+      return LITERAL_PRECEDENCE;
+    }
+    if (expression instanceof GrReferenceExpression) {
+      final GrReferenceExpression referenceExpression =
+          (GrReferenceExpression) expression;
+      if (referenceExpression.getQualifierExpression() != null) {
+        return METHOD_CALL_PRECEDENCE;
+      } else {
+        return LITERAL_PRECEDENCE;
+      }
+    }
+    if (expression instanceof GrMethodCallExpression) {
+      return METHOD_CALL_PRECEDENCE;
+    }
+    if (expression instanceof GrTypeCastExpression ||
+        expression instanceof GrNewExpression) {
+      return TYPE_CAST_PRECEDENCE;
+    }
+    if (expression instanceof GrPostfixExpression) {
+      return POSTFIX_PRECEDENCE;
+    }
+    if (expression instanceof GrUnaryExpression) {
+      return PREFIX_PRECEDENCE;
+    }
+    if (expression instanceof GrBinaryExpression) {
+      final GrBinaryExpression binaryExpression =
+          (GrBinaryExpression) expression;
+      final IElementType sign = binaryExpression.getOperationTokenType();
+      return precedenceForBinaryOperator(sign);
+    }
+    if (expression instanceof GrConditionalExpression) {
+      return CONDITIONAL_PRECEDENCE;
+    }
+    if (expression instanceof GrAssignmentExpression) {
+      return ASSIGNMENT_PRECEDENCE;
+    }
+    if (expression instanceof GrParenthesizedExpr) {
+      return PARENTHESIZED_PRECEDENCE;
+    }
+    return -1;
+  }
+
+  private static int precedenceForBinaryOperator(@NotNull IElementType sign) {
+    return s_binaryOperatorPrecedence.get(sign);
+  }
+
+}
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/comments/CStyleCommentPredicate.java	Wed Aug 01 15:26:58 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/comments/CStyleCommentPredicate.java	Wed Aug 01 15:26:58 EDT 2007
@@ -0,0 +1,42 @@
+package org.jetbrains.plugins.groovy.intentions.comments;
+
+import com.intellij.psi.PsiComment;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiWhiteSpace;
+import com.intellij.psi.javadoc.PsiDocComment;
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.intentions.utils.TreeUtil;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+
+class CStyleCommentPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof PsiComment)) {
+      return false;
+    }
+    if (element instanceof PsiDocComment) {
+      return false;
+    }
+    final PsiComment comment = (PsiComment) element;
+    final IElementType type = comment.getTokenType();
+    if (!GroovyTokenTypes.mML_COMMENT.equals(type)) {
+      return false;
+    }
+    final PsiElement sibling = TreeUtil.getNextLeaf(comment);
+    if(sibling == null)
+    {
+      return true;
+    }
+    if (!(isWhitespace(sibling))) {
+      return false;
+    }
+    final String whitespaceText = sibling.getText();
+    return whitespaceText.indexOf((int) '\n') >= 0 ||
+        whitespaceText.indexOf((int) '\r') >= 0;
+  }
+
+  private static boolean isWhitespace(PsiElement element) {
+    return element.getText().replace("\n", "").trim().length() == 0;
+  }
+}
--- src/org/jetbrains/plugins/groovy/intentions/control/ComparisonPredicate.java	Wed Aug 01 15:21:00 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/control/ComparisonPredicate.java	Wed Aug 01 15:21:00 EDT 2007
@@ -0,0 +1,21 @@
+package org.jetbrains.plugins.groovy.intentions.control;
+
+import com.intellij.psi.PsiElement;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
+import org.jetbrains.plugins.groovy.intentions.utils.ComparisonUtils;
+
+class ComparisonPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrBinaryExpression)) {
+      return false;
+    }
+    final GrBinaryExpression expression = (GrBinaryExpression) element;
+    if (!ComparisonUtils.isComparison(expression)) {
+      return false;
+    }
+    return !ErrorUtil.containsError(element);
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ExpandBooleanIntention/after.groovy.template	Sun Jul 29 08:25:42 EDT 2007
+++ resources/intentionDescriptions/ExpandBooleanIntention/after.groovy.template	Sun Jul 29 08:25:42 EDT 2007
@@ -0,0 +1,10 @@
+public class X {
+  boolean f(boolean a) {
+    if(a){
+        return true;
+    }
+    else{
+        return false;
+    }
+  }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ForToEachIntention/before.groovy.template	Sun Jul 29 11:48:53 EDT 2007
+++ resources/intentionDescriptions/ForToEachIntention/before.groovy.template	Sun Jul 29 11:48:53 EDT 2007
@@ -0,0 +1,5 @@
+
+<spot>for(x in [1, 2, 3])
+{
+   print(x)
+}</spot>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/closure/MakeClosureCallImplicitIntention.java	Thu Aug 02 16:01:27 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/closure/MakeClosureCallImplicitIntention.java	Thu Aug 02 16:01:27 EDT 2007
@@ -0,0 +1,40 @@
+package org.jetbrains.plugins.groovy.intentions.closure;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.intentions.base.Intention;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+
+public class MakeClosureCallImplicitIntention extends Intention {
+
+
+    @NotNull
+    public PsiElementPredicate getElementPredicate() {
+        return new ExplicitClosureCallPredicate();
+    }
+
+    public void processIntention(PsiElement element)
+            throws IncorrectOperationException {
+        final GrMethodCallExpression expression =
+                (GrMethodCallExpression) element;
+        final GrReferenceExpression invokedExpression = (GrReferenceExpression) expression.getInvokedExpression();
+        final GrExpression qualifier = invokedExpression.getQualifierExpression();
+        final GrArgumentList argList = expression.getArgumentList();
+        final GrClosableBlock[] closureArgs = expression.getClosureArguments();
+        final StringBuilder newExpression = new StringBuilder();
+        newExpression.append(qualifier.getText());
+        if (argList != null) {
+            newExpression.append(argList.getText());
+        }
+        for (GrClosableBlock closureArg : closureArgs) {
+            newExpression.append(closureArg.getText());
+        }
+        replaceExpression(newExpression.toString(), expression);
+    }
+}
\ No newline at end of file
--- resources/intentionDescriptions/ChangeToCStyleCommentIntention/after.groovy.template	Wed Aug 01 14:49:13 EDT 2007
+++ resources/intentionDescriptions/ChangeToCStyleCommentIntention/after.groovy.template	Wed Aug 01 14:49:13 EDT 2007
@@ -0,0 +1,4 @@
+
+/*comment line 1
+comment line 2 */
+x = 0x30
--- resources/intentionDescriptions/ChangeToCStyleCommentIntention/before.groovy.template	Wed Aug 01 14:49:13 EDT 2007
+++ resources/intentionDescriptions/ChangeToCStyleCommentIntention/before.groovy.template	Wed Aug 01 14:49:13 EDT 2007
@@ -0,0 +1,4 @@
+
+<spot>//comment line 1
+//comment line 2 </spot>
+x = 0x30
\ No newline at end of file
--- resources/intentionDescriptions/ConvertClosureArgToItIntention/after.groovy.template	Thu Aug 02 21:45:14 EDT 2007
+++ resources/intentionDescriptions/ConvertClosureArgToItIntention/after.groovy.template	Thu Aug 02 21:45:14 EDT 2007
@@ -0,0 +1,2 @@
+
+def myClosure = <spot>{print it}</spot>
\ No newline at end of file
--- src/org/jetbrains/plugins/groovy/intentions/closure/ForToEachPredicate.java	Thu Aug 02 15:29:12 EDT 2007
+++ src/org/jetbrains/plugins/groovy/intentions/closure/ForToEachPredicate.java	Thu Aug 02 15:29:12 EDT 2007
@@ -0,0 +1,23 @@
+package org.jetbrains.plugins.groovy.intentions.closure;
+
+import com.intellij.psi.PsiElement;
+import org.jetbrains.plugins.groovy.intentions.base.ErrorUtil;
+import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause;
+
+class ForToEachPredicate implements PsiElementPredicate {
+
+  public boolean satisfiedBy(PsiElement element) {
+    if (!(element instanceof GrForStatement)) {
+      return false;
+    }
+    final GrForStatement statement = (GrForStatement) element;
+    final GrForClause clause = statement.getClause();
+    if (!(clause instanceof GrForInClause)) {
+      return false;
+    }
+    return !ErrorUtil.containsError(element);
+  }
+}
\ No newline at end of file
