Bug 515908 - Fix / Turn off auto indentation for } in shell ed when
typing ${var}

Use the rule for variables in the edit strategy and exclude it from
indent/dedent.

Change-Id: I98bb973c621002e30f7c5087d398f90533d72383
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellSourceViewerConfiguration.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellSourceViewerConfiguration.java
index bb2b8fb..a7d50c4 100644
--- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellSourceViewerConfiguration.java
+++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellSourceViewerConfiguration.java
@@ -18,6 +18,7 @@
 import org.eclipse.dltk.sh.internal.ui.IShellColorConstants;
 import org.eclipse.dltk.sh.internal.ui.ShellContentAssistPreference;
 import org.eclipse.dltk.sh.internal.ui.completion.ShellCompletionProcessor;
+import org.eclipse.dltk.sh.internal.ui.text.DollarBraceCountingRule;
 import org.eclipse.dltk.sh.internal.ui.text.DoubleQuoteScanner;
 import org.eclipse.dltk.sh.internal.ui.text.EvalScanner;
 import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions;
@@ -95,13 +96,14 @@
 
 		ArrayList<IRule> rules = new ArrayList<>();
 		rules.add(new WhitespaceRule(new WhitespaceDetector()));
+		rules.add(new DollarBraceCountingRule('{', '}', new Token(IShellPartitions.EVAL_CONTENT_TYPE), '\\'));
 		rules.add(getKeywords(new Token(IndentType.INCREMENT), new String[] { "do", "case", "{", "then" },
 				Token.UNDEFINED));
 		rules.add(getKeywords(new Token(IndentType.DECREMENT), new String[] { "done", "esac", "}", "fi" },
 				Token.UNDEFINED));
 		rules.add(getKeywords(new Token(IndentType.INFLEXION), new String[] { "else" }, Token.UNDEFINED));
 
-		strategy.setRules(rules.toArray(new IRule[0]));
+		strategy.setRules(rules.toArray(new IRule[rules.size()]));
 
 		return new IAutoEditStrategy[] { strategy };
 	}
diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java
index 19d73b7..19cb4fb 100644
--- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java
+++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java
@@ -207,15 +207,17 @@
 			}
 
 			if (token.isOther()) {
-				IndentType type = (IndentType) token.getData();
-				if (type == IndentType.INCREMENT) {
-					++bracketcount;
-				} else if (type == IndentType.DECREMENT) {
-					--bracketcount;
-				} else if ((type == IndentType.INFLEXION) && ignoreInflexions) {
-					++bracketcount;
-				} else if ((type == IndentType.INFLEXION) && !ignoreInflexions) {
-					--bracketcount;
+				if (token.getData() instanceof IndentType) {
+					IndentType type = (IndentType) token.getData();
+					if (type == IndentType.INCREMENT) {
+						++bracketcount;
+					} else if (type == IndentType.DECREMENT) {
+						--bracketcount;
+					} else if ((type == IndentType.INFLEXION) && ignoreInflexions) {
+						++bracketcount;
+					} else if ((type == IndentType.INFLEXION) && !ignoreInflexions) {
+						--bracketcount;
+					}
 				}
 			}
 		}