diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index a996eb8..cc7f2dd 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -639,7 +639,16 @@ public class ClassWriter { descriptor = GenericMain.parseMethodSignature(attr.getSignature()); if (descriptor != null) { int actualParams = md.params.length; - if (isEnum && init) actualParams -= 2; + List sigFields = methodWrapper.signatureFields; + if (sigFields != null) { + actualParams = 0; + for (VarVersionPair field : methodWrapper.signatureFields) { + if (field == null) { + actualParams++; + } + } + } + else if (isEnum && init) actualParams -= 2; if (actualParams != descriptor.params.size()) { String message = "Inconsistent generic signature in method " + mt.getName() + " " + mt.getDescriptor(); DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN); @@ -685,10 +694,11 @@ public class ClassWriter { boolean firstParameter = true; int index = isEnum && init ? 3 : thisVar ? 1 : 0; - int start = isEnum && init && descriptor == null ? 2 : 0; - int params = descriptor == null ? md.params.length : descriptor.params.size(); + boolean hasDescriptor = descriptor != null; + int start = isEnum && init && !hasDescriptor ? 2 : 0; + int params = hasDescriptor ? descriptor.params.size() : md.params.length; for (int i = start; i < params; i++) { - if (signFields == null || signFields.get(i) == null) { + if (hasDescriptor || (signFields == null || signFields.get(i) == null)) { if (!firstParameter) { buffer.append(", "); } diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index 62fef0a..a65ab26 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -58,4 +58,5 @@ public class SingleClassesTest extends SingleClassesTestBase { @Test public void testAnonymousClass() { doTest("pkg/TestAnonymousClass"); } @Test public void testThrowException() { doTest("pkg/TestThrowException"); } @Test public void testInnerLocal() { doTest("pkg/TestInnerLocal"); } + @Test public void testInnerSignature() { doTest("pkg/TestInnerSignature"); } } diff --git a/testData/classes/pkg/TestInnerSignature$Inner.class b/testData/classes/pkg/TestInnerSignature$Inner.class new file mode 100644 index 0000000..d335f61 Binary files /dev/null and b/testData/classes/pkg/TestInnerSignature$Inner.class differ diff --git a/testData/classes/pkg/TestInnerSignature$InnerStatic.class b/testData/classes/pkg/TestInnerSignature$InnerStatic.class new file mode 100644 index 0000000..2bd775b Binary files /dev/null and b/testData/classes/pkg/TestInnerSignature$InnerStatic.class differ diff --git a/testData/classes/pkg/TestInnerSignature.class b/testData/classes/pkg/TestInnerSignature.class new file mode 100644 index 0000000..e2f9489 Binary files /dev/null and b/testData/classes/pkg/TestInnerSignature.class differ diff --git a/testData/results/TestInnerSignature.dec b/testData/results/TestInnerSignature.dec new file mode 100644 index 0000000..e40a832 --- /dev/null +++ b/testData/results/TestInnerSignature.dec @@ -0,0 +1,70 @@ +public class TestInnerSignature { + A a; + B b; + C c; + + public TestInnerSignature(A var1, B var2, C var3) { + this.a = var1;// 23 + this.b = var2;// 24 + this.c = var3;// 25 + } + + public static class InnerStatic { + A a; + B b; + C c; + + public InnerStatic(A var1, B var2, C var3) { + this.a = var1;// 46 + this.b = var2;// 47 + this.c = var3;// 48 + } + } + + public class Inner { + A a; + B b; + C c; + + public Inner(A var1, B var2, C var3) { + this.a = var2;// 34 + this.b = var3;// 35 + this.c = var4;// 36 + } + } +} + +class 'TestInnerSignature' { + method ' (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V' { + 6 6 + b 7 + 10 8 + } +} + +class 'TestInnerSignature$InnerStatic' { + method ' (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V' { + 6 17 + b 18 + 10 19 + } +} + +class 'TestInnerSignature$Inner' { + method ' (LTestInnerSignature;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V' { + b 29 + 10 30 + 16 31 + } +} + +Lines mapping: +23 <-> 7 +24 <-> 8 +25 <-> 9 +34 <-> 30 +35 <-> 31 +36 <-> 32 +46 <-> 18 +47 <-> 19 +48 <-> 20 diff --git a/testData/src/pkg/TestInnerSignature.java b/testData/src/pkg/TestInnerSignature.java new file mode 100644 index 0000000..d69f0b3 --- /dev/null +++ b/testData/src/pkg/TestInnerSignature.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2014 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. + */ + +public class TestInnerSignature { + A a; + B b; + C c; + + public TestInnerSignature(A a,B b,C c) { + this.a = a; + this.b = b; + this.c = c; + } + + public class Inner { + A a; + B b; + C c; + + public Inner(A a, B b, C c) { + this.a = a; + this.b = b; + this.c = c; + } + } + + public static class InnerStatic { + A a; + B b; + C c; + + public InnerStatic(A a, B b, C c) { + this.a = a; + this.b = b; + this.c = c; + } + } +} \ No newline at end of file