summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakosyakov2013-07-22 05:13:59 (EDT)
committer akosyakov2013-07-22 05:13:59 (EDT)
commit6c9436f493f9dadc16c8647130ae076330020a41 (patch)
tree2ff8bdc92570e5cf55fdf4d1d53cb19587f2963e
parent780febc6f6e8ccfa68f492e4cfc20afd725cda71 (diff)
downloadorg.eclipse.xtext-6c9436f493f9dadc16c8647130ae076330020a41.zip
org.eclipse.xtext-6c9436f493f9dadc16c8647130ae076330020a41.tar.gz
org.eclipse.xtext-6c9436f493f9dadc16c8647130ae076330020a41.tar.bz2
[412779]: added the flag to set whether the pair of terminals can berefs/changes/05/14505/2
nested or not Change-Id: Ia7f1aa25846397950e01737d52a0e3c486c97b4f Signed-off-by: akosyakov <anton.kosyakov@itemis.de>
-rw-r--r--plugins/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/ui/AbstractCStyleLanguageAutoEditTest.java11
-rw-r--r--plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/autoedit/MultiLineTerminalsEditStrategy.java33
-rw-r--r--plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategy.java2
-rw-r--r--tests/org.eclipse.xtext.xtext.ui.tests/src-longrunning/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategyTest.java33
4 files changed, 71 insertions, 8 deletions
diff --git a/plugins/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/ui/AbstractCStyleLanguageAutoEditTest.java b/plugins/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/ui/AbstractCStyleLanguageAutoEditTest.java
index 8561330..ad3deaf 100644
--- a/plugins/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/ui/AbstractCStyleLanguageAutoEditTest.java
+++ b/plugins/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/ui/AbstractCStyleLanguageAutoEditTest.java
@@ -427,6 +427,17 @@ public abstract class AbstractCStyleLanguageAutoEditTest extends AbstractAutoEdi
pressKey(editor, '\n');
assertState("{{foo}\n\t|{bar}\n}", editor);
}
+
+ @Test
+ public void testCurlyBracesBlock_19() throws Exception {
+ XtextEditor editor = openEditor("{{|");
+ pressKey(editor, '\n');
+ assertState("{{\n\t|\n}", editor);
+ pressKey(editor, '\n');
+ assertState("{{\n\t\n\t|\n\t}\n}", editor);
+ pressKey(editor, '\n');
+ assertState("{{\n\t\n\t\n\t|\n\t}\n}", editor);
+ }
@Test public void testCurlyBracesWithSelection_1() throws Exception {
XtextEditor editor = openEditor("{|foo}");
diff --git a/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/autoedit/MultiLineTerminalsEditStrategy.java b/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/autoedit/MultiLineTerminalsEditStrategy.java
index 0cbd4ca..4a7fbb1 100644
--- a/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/autoedit/MultiLineTerminalsEditStrategy.java
+++ b/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/autoedit/MultiLineTerminalsEditStrategy.java
@@ -33,21 +33,40 @@ public class MultiLineTerminalsEditStrategy extends AbstractTerminalsEditStrateg
private IIndentationInformation indentationInformation;
public MultiLineTerminalsEditStrategy newInstance(String leftTerminal, String indentationString, String rightTerminal) {
- indentationString = indentationString == null ? indentationInformation.getIndentString()
- : indentationString;
- MultiLineTerminalsEditStrategy strategy = new MultiLineTerminalsEditStrategy(leftTerminal, indentationString, rightTerminal);
- injector.injectMembers(strategy);
+ return newInstance(leftTerminal, indentationString, rightTerminal, true);
+ }
+
+ /**
+ * @since 2.4
+ * */
+ public MultiLineTerminalsEditStrategy newInstance(String leftTerminal, String indentationString, String rightTerminal, boolean nested) {
+ indentationString = indentationString == null ? indentationInformation.getIndentString() : indentationString;
+ MultiLineTerminalsEditStrategy strategy = new MultiLineTerminalsEditStrategy(leftTerminal, indentationString, rightTerminal, nested);
+ injector.injectMembers(strategy);
return strategy;
}
}
@SuppressWarnings("unused")
private final static Logger log = Logger.getLogger(MultiLineTerminalsEditStrategy.class);
+
+ /**
+ * <p>Whether the pair of terminals can be nested or not.</p>
+ * */
+ private final boolean nested;
private String indentationString;
-
+
public MultiLineTerminalsEditStrategy(String leftTerminal, String indentationString, String rightTerminal) {
+ this(leftTerminal, indentationString, rightTerminal, true);
+ }
+
+ /**
+ * @since 2.4
+ */
+ public MultiLineTerminalsEditStrategy(String leftTerminal, String indentationString, String rightTerminal, boolean nested) {
super(leftTerminal,rightTerminal);
+ this.nested = nested;
this.indentationString = indentationString;
}
@@ -65,11 +84,11 @@ public class MultiLineTerminalsEditStrategy extends AbstractTerminalsEditStrateg
return;
IRegion stopTerminal = findStopTerminal(document, command.offset);
// check whether this is our stop terminal
- if (stopTerminal != null) {
+ if (stopTerminal != null && nested) {
IRegion previousStart = startTerminal;
IRegion previousStop = stopTerminal;
while(stopTerminal != null && previousStart != null && previousStop != null) {
- previousStart = findStartTerminal(document, previousStart.getOffset() - 1);
+ previousStart = findStartTerminal(document, previousStart.getOffset());
if (previousStart != null) {
previousStop = findStopTerminal(document, previousStop.getOffset() + 1);
if (previousStop == null) {
diff --git a/plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategy.java b/plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategy.java
index 35ee9dd..c487b79 100644
--- a/plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategy.java
+++ b/plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategy.java
@@ -47,7 +47,7 @@ public class XtextAutoEditStrategy extends DefaultAutoEditStrategyProvider {
}
protected MultiLineTerminalsEditStrategy createColonSemicolonStrategy() {
- MultiLineTerminalsEditStrategy configure = multiLineTerminals.newInstance(":", null, ";");
+ MultiLineTerminalsEditStrategy configure = multiLineTerminals.newInstance(":", null, ";", false);
// the following is a cheap but working hack, which replaces any double colons '::' by whitespace ' ' temporarily.
configure.setDocumentUtil(new DocumentUtil() {
@Override
diff --git a/tests/org.eclipse.xtext.xtext.ui.tests/src-longrunning/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategyTest.java b/tests/org.eclipse.xtext.xtext.ui.tests/src-longrunning/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategyTest.java
index e431442..c4809c4 100644
--- a/tests/org.eclipse.xtext.xtext.ui.tests/src-longrunning/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategyTest.java
+++ b/tests/org.eclipse.xtext.xtext.ui.tests/src-longrunning/org/eclipse/xtext/xtext/ui/editor/autoedit/XtextAutoEditStrategyTest.java
@@ -242,6 +242,39 @@ public class XtextAutoEditStrategyTest extends AbstractCStyleLanguageAutoEditTes
editor);
}
+ @Test public void testBug412779() throws Exception {
+ XtextEditor editor = openEditor(
+ "grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase\n" +
+ "\n" +
+ "generate myDsl \"http://www.xtext.org/example/mydsl/MyDsl\"\n" +
+ "\n" +
+ "A:\n" +
+ "\n" +
+ "B:|");
+ pressKey(editor, '\n');
+ assertState(
+ "grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase\n" +
+ "\n" +
+ "generate myDsl \"http://www.xtext.org/example/mydsl/MyDsl\"\n" +
+ "\n" +
+ "A:\n" +
+ "\n" +
+ "B:\n" +
+ "\t|\n" +
+ ";" , editor);
+ pressKey(editor, '\n');
+ assertState(
+ "grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase\n" +
+ "\n" +
+ "generate myDsl \"http://www.xtext.org/example/mydsl/MyDsl\"\n" +
+ "\n" +
+ "A:\n" +
+ "\n" +
+ "B:\n" +
+ "\t\n" +
+ "\t|\n" +
+ ";" , editor);
+ }
@Override
public void setUp() throws Exception {