diff --git a/src/main/java/org/cadixdev/mercury/RewriteContext.java b/src/main/java/org/cadixdev/mercury/RewriteContext.java index 8e16173..5e24296 100644 --- a/src/main/java/org/cadixdev/mercury/RewriteContext.java +++ b/src/main/java/org/cadixdev/mercury/RewriteContext.java @@ -96,7 +96,12 @@ private static TextEdit combineEdit(TextEdit before, TextEdit edit) { return edit; } if (edit != null) { - before.addChild(edit); + if (edit instanceof MultiTextEdit) { + MultiTextEdit multiTextEdit = (MultiTextEdit) edit; + before.addChildren(multiTextEdit.removeChildren()); + } else { + before.addChild(edit); + } } return before; } diff --git a/src/test/java/org/cadixdev/mercury/test/RemappingTests.java b/src/test/java/org/cadixdev/mercury/test/RemappingTests.java index 85d920f..ee920d3 100644 --- a/src/test/java/org/cadixdev/mercury/test/RemappingTests.java +++ b/src/test/java/org/cadixdev/mercury/test/RemappingTests.java @@ -55,6 +55,7 @@ class RemappingTests { // 5. Anonymous class remapping // This test verifies we can handle remapping cases for different anonymous class remapping // combinations (GH-31). + // 6. Import remapping tests (GH-28) @Test void remap() throws Exception { @@ -81,6 +82,11 @@ void remap() throws Exception { //this.copy(in, "eclipse/Test.java"); // - Test 5 this.copy(in, "anon/Test.java"); + // - Test 6 + this.copy(in, "com/example/ImportTest.java"); + this.copy(in, "com/example/other/AnotherClass.java"); + this.copy(in, "com/example/other/OtherClass.java"); + this.copy(in, "com/example/pkg/Constants.java"); // Load our test mappings final MappingSet mappings = MappingSet.create(); @@ -110,6 +116,11 @@ void remap() throws Exception { //this.verify(out, "eclipse/Test.java"); // - Test 5 this.verify(out, "anon/Anon.java"); + // - Test 6 + this.verify(out, "net/example/ImportTestNew.java"); + this.verify(out, "net/example/newother/AnotherClass.java"); + this.verify(out, "net/example/newother/OtherClass.java"); + this.verify(out, "net/example/pkg/Util.java"); // Delete the directory Files.walk(tempDir) diff --git a/src/test/resources/a/com/example/ImportTest.java b/src/test/resources/a/com/example/ImportTest.java new file mode 100644 index 0000000..76bcade --- /dev/null +++ b/src/test/resources/a/com/example/ImportTest.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018 Cadix Development (https://www.cadixdev.org) + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package com.example; + +import com.example.other.AnotherClass; +import static com.example.pkg.Constants.*; +import com.example.other.OtherClass; +import java.lang.String; +import java.lang.Exception; + +public class ImportTest { + + public void test() { + OtherClass otherClass = new OtherClass(); + AnotherClass anotherClass = new AnotherClass(); + } + +} diff --git a/src/test/resources/a/com/example/other/AnotherClass.java b/src/test/resources/a/com/example/other/AnotherClass.java new file mode 100644 index 0000000..b3dd8d7 --- /dev/null +++ b/src/test/resources/a/com/example/other/AnotherClass.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018 Cadix Development (https://www.cadixdev.org) + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package com.example.other; + +public class AnotherClass { + +} diff --git a/src/test/resources/a/com/example/other/OtherClass.java b/src/test/resources/a/com/example/other/OtherClass.java new file mode 100644 index 0000000..0412ca8 --- /dev/null +++ b/src/test/resources/a/com/example/other/OtherClass.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018 Cadix Development (https://www.cadixdev.org) + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package com.example.other; + +public class OtherClass { + +} diff --git a/src/test/resources/a/com/example/pkg/Constants.java b/src/test/resources/a/com/example/pkg/Constants.java new file mode 100644 index 0000000..9aa1d05 --- /dev/null +++ b/src/test/resources/a/com/example/pkg/Constants.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018 Cadix Development (https://www.cadixdev.org) + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package com.example.pkg; + +public class Constants { + + public static final String NAME = "George"; + public static final String BIRTHDAY = "1st June"; + public static final String VERSION = "1"; + +} diff --git a/src/test/resources/b/net/example/ImportTestNew.java b/src/test/resources/b/net/example/ImportTestNew.java new file mode 100644 index 0000000..a826e8d --- /dev/null +++ b/src/test/resources/b/net/example/ImportTestNew.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018 Cadix Development (https://www.cadixdev.org) + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package net.example; + +import static net.example.pkg.Util.*; + +import java.lang.String; +import net.example.newother.AnotherClass; +import net.example.newother.OtherClass; +import java.lang.Exception; + +public class ImportTestNew { + + public void test() { + OtherClass otherClass = new OtherClass(); + AnotherClass anotherClass = new AnotherClass(); + } + +} diff --git a/src/test/resources/b/net/example/newother/AnotherClass.java b/src/test/resources/b/net/example/newother/AnotherClass.java new file mode 100644 index 0000000..cec2c8b --- /dev/null +++ b/src/test/resources/b/net/example/newother/AnotherClass.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018 Cadix Development (https://www.cadixdev.org) + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package net.example.newother; + +public class AnotherClass { + +} diff --git a/src/test/resources/b/net/example/newother/OtherClass.java b/src/test/resources/b/net/example/newother/OtherClass.java new file mode 100644 index 0000000..b2d987e --- /dev/null +++ b/src/test/resources/b/net/example/newother/OtherClass.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018 Cadix Development (https://www.cadixdev.org) + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package net.example.newother; + +public class OtherClass { + +} diff --git a/src/test/resources/b/net/example/pkg/Util.java b/src/test/resources/b/net/example/pkg/Util.java new file mode 100644 index 0000000..c6e567f --- /dev/null +++ b/src/test/resources/b/net/example/pkg/Util.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018 Cadix Development (https://www.cadixdev.org) + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package net.example.pkg; + +public class Util { + + public static final String NAME = "George"; + public static final String BIRTHDAY = "1st June"; + public static final String VERSION = "1"; + +} diff --git a/src/test/resources/test.jam b/src/test/resources/test.jam index 5520111..e122c6a 100644 --- a/src/test/resources/test.jam +++ b/src/test/resources/test.jam @@ -36,3 +36,9 @@ FD anon/Test$2 field I abc MD anon/Test$1 name (II)V remapped MD anon/Test$2 name (DD)V remapped MD anon/Test$3 name (ZZ)V remapped + +# Test 6. Import tests +CL com/example/pkg/Constants net/example/pkg/Util +CL com/example/ImportTest net/example/ImportTestNew +CL com/example/other/OtherClass net/example/newother/OtherClass +CL com/example/other/AnotherClass net/example/newother/AnotherClass