diff --git a/src/main/java/org/cadixdev/mercury/remapper/RemapperVisitor.java b/src/main/java/org/cadixdev/mercury/remapper/RemapperVisitor.java index e4303de..3447e72 100644 --- a/src/main/java/org/cadixdev/mercury/remapper/RemapperVisitor.java +++ b/src/main/java/org/cadixdev/mercury/remapper/RemapperVisitor.java @@ -121,7 +121,7 @@ private void remapType(SimpleName node, ITypeBinding binding) { String qualifiedName = (mapping != null ? mapping.getFullDeobfuscatedName().replace('/', '.') : binding.getBinaryName()).replace('$', '.'); String newName = this.importRewrite.addImport(qualifiedName, this.importStack.peek()); - if (!node.getIdentifier().equals(newName)) { + if (!node.getIdentifier().equals(newName) && !node.isVar()) { if (newName.indexOf('.') == -1) { this.context.createASTRewrite().set(node, SimpleName.IDENTIFIER_PROPERTY, newName, null); } else { diff --git a/src/main/java/org/cadixdev/mercury/remapper/SimpleRemapperVisitor.java b/src/main/java/org/cadixdev/mercury/remapper/SimpleRemapperVisitor.java index 4780af8..bbce412 100644 --- a/src/main/java/org/cadixdev/mercury/remapper/SimpleRemapperVisitor.java +++ b/src/main/java/org/cadixdev/mercury/remapper/SimpleRemapperVisitor.java @@ -68,7 +68,7 @@ class SimpleRemapperVisitor extends ASTVisitor { } final void updateIdentifier(SimpleName node, String newName) { - if (!node.getIdentifier().equals(newName)) { + if (!node.getIdentifier().equals(newName) && !node.isVar()) { this.context.createASTRewrite().set(node, SimpleName.IDENTIFIER_PROPERTY, newName, null); } } diff --git a/src/test/java/org/cadixdev/mercury/test/RemappingTests.java b/src/test/java/org/cadixdev/mercury/test/RemappingTests.java index ee920d3..e7668b5 100644 --- a/src/test/java/org/cadixdev/mercury/test/RemappingTests.java +++ b/src/test/java/org/cadixdev/mercury/test/RemappingTests.java @@ -19,6 +19,7 @@ import org.cadixdev.lorenz.io.MappingsReader; import org.cadixdev.mercury.Mercury; import org.cadixdev.mercury.remapper.MercuryRemapper; +import org.eclipse.jdt.core.JavaCore; import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; @@ -97,6 +98,7 @@ void remap() throws Exception { // Run Mercury final Mercury mercury = new Mercury(); + mercury.setSourceCompatibility(JavaCore.VERSION_11); mercury.getProcessors().add(MercuryRemapper.create(mappings)); mercury.setFlexibleAnonymousClassMemberLookups(true); mercury.rewrite(in, out); diff --git a/src/test/resources/a/OverrideChild.java b/src/test/resources/a/OverrideChild.java index dc1f2de..05ef671 100644 --- a/src/test/resources/a/OverrideChild.java +++ b/src/test/resources/a/OverrideChild.java @@ -12,7 +12,8 @@ class OverrideChild extends OverrideParent { @Override public String abc() { - return "Hello, World!"; + var result = "Hello, World!"; + return result; } @Override diff --git a/src/test/resources/a/com/example/ImportTest.java b/src/test/resources/a/com/example/ImportTest.java index 76bcade..54e6a2c 100644 --- a/src/test/resources/a/com/example/ImportTest.java +++ b/src/test/resources/a/com/example/ImportTest.java @@ -19,8 +19,8 @@ public class ImportTest { public void test() { - OtherClass otherClass = new OtherClass(); - AnotherClass anotherClass = new AnotherClass(); + var otherClass = new OtherClass(); + var anotherClass = new AnotherClass(); } } diff --git a/src/test/resources/b/OverrideChild.java b/src/test/resources/b/OverrideChild.java index 15f6a43..73fb29d 100644 --- a/src/test/resources/b/OverrideChild.java +++ b/src/test/resources/b/OverrideChild.java @@ -12,7 +12,8 @@ class OverrideChild extends OverrideParent { @Override public String get() { - return "Hello, World!"; + var result = "Hello, World!"; + return result; } @Override diff --git a/src/test/resources/b/net/example/ImportTestNew.java b/src/test/resources/b/net/example/ImportTestNew.java index a826e8d..6be1802 100644 --- a/src/test/resources/b/net/example/ImportTestNew.java +++ b/src/test/resources/b/net/example/ImportTestNew.java @@ -20,8 +20,8 @@ public class ImportTestNew { public void test() { - OtherClass otherClass = new OtherClass(); - AnotherClass anotherClass = new AnotherClass(); + var otherClass = new OtherClass(); + var anotherClass = new AnotherClass(); } }