From 45384fb8c5f5903b707da79a047a1bb6ac640979 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 23 Jan 2017 18:07:50 +0300 Subject: [PATCH] fixed access to private outer class methods with params --- .../main/rels/NestedMemberAccess.java | 12 +-- .../java/decompiler/SingleClassesTest.java | 1 + .../classes/pkg/TestAccessReplace$Inner.class | Bin 0 -> 723 bytes testData/classes/pkg/TestAccessReplace.class | Bin 0 -> 1079 bytes testData/results/TestAccessReplace.dec | 69 ++++++++++++++++++ testData/src/pkg/TestAccessReplace.java | 32 ++++++++ 6 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 testData/classes/pkg/TestAccessReplace$Inner.class create mode 100644 testData/classes/pkg/TestAccessReplace.class create mode 100644 testData/results/TestAccessReplace.dec create mode 100644 testData/src/pkg/TestAccessReplace.java diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java b/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java index a460ef9..5be55d0 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java +++ b/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -149,19 +149,21 @@ public class NestedMemberAccess { InvocationExprent invexpr = (InvocationExprent)exprCore; - if ((invexpr.isStatic() && invexpr.getLstParameters().size() == parcount) || - (!invexpr.isStatic() && invexpr.getInstance().type == Exprent.EXPRENT_VAR + boolean isStatic = invexpr.isStatic(); + if ((isStatic && invexpr.getLstParameters().size() == parcount) || + (!isStatic && invexpr.getInstance().type == Exprent.EXPRENT_VAR && ((VarExprent)invexpr.getInstance()).getIndex() == 0 && invexpr.getLstParameters().size() == parcount - 1)) { boolean equalpars = true; + int index = isStatic ? 0 : 1; for (int i = 0; i < invexpr.getLstParameters().size(); i++) { Exprent parexpr = invexpr.getLstParameters().get(i); - if (parexpr.type != Exprent.EXPRENT_VAR || - ((VarExprent)parexpr).getIndex() != i + (invexpr.isStatic() ? 0 : 1)) { + if (parexpr.type != Exprent.EXPRENT_VAR || ((VarExprent)parexpr).getIndex() != index) { equalpars = false; break; } + index += mtdesc.params[i + (isStatic ? 0 : 1)].stackSize; } if (equalpars) { diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index 7a69a8e..8b876c8 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -97,6 +97,7 @@ public class SingleClassesTest { @Test public void testLocalsNames() { doTest("pkg/TestLocalsNames"); } @Test public void testAnonymousParamNames() { doTest("pkg/TestAnonymousParamNames"); } @Test public void testAnonymousParams() { doTest("pkg/TestAnonymousParams"); } + @Test public void testAccessReplace() { doTest("pkg/TestAccessReplace"); } private void doTest(String testFile, String... companionFiles) { ConsoleDecompiler decompiler = fixture.getDecompiler(); diff --git a/testData/classes/pkg/TestAccessReplace$Inner.class b/testData/classes/pkg/TestAccessReplace$Inner.class new file mode 100644 index 0000000000000000000000000000000000000000..a339ed0fd9f6e56b0a11d258692b121b58baf5c9 GIT binary patch literal 723 zcmZ`%+fKqj5ItKcNG*zYLm;-;}NZ(f!&Wz4n9I&WH z(Pr6yWe6Bo-AB(-r#2^E{P(?Weqv%0rinNTQ4~$AqhMkKnEZxF!C8yB?mn&*6Y;yAF#t9Ij+Yn_ru&}re10^{s#9rm>&0>xyaLO z7&HeWk>D@$iFO=QWTy#v&=De^t5jbgDzDJ`2vz$C8}rcnh*pPw;+Z%a5@eHzkX_-K uBfS*G(pW+UtH@%8m4z2LKEe3l z2l!ErXOk3TDamB_-o1Oy-m{zEe}4V~@B|NYaBx@5Ju&yi)N*jK>7wpp%f$l)`(3YR z1`1x}ce^?aO{n0!2ztTrr9!5*d7zNp?SD23bM2sK-k%|w^)uK%xUg`8)`@}z%yBKLOh6tt>2q>9Mg+XXPaY*el>*L_ zhC-6Gt>`pKOY<+J_$evjXB!gWQv$PN{xq-{0ZXhRbxT;Jm(?w (Lpkg/TestAccessReplace;Ljava/lang/String;)V' { + 0 17 + 1 18 + 2 19 + 3 20 + 10 19 + 11 19 + 18 20 + 19 20 + 1f 21 + } +} + +Lines mapping: +19 <-> 5 +20 <-> 8 +21 <-> 11 +22 <-> 14 +25 <-> 18 +28 <-> 20 +29 <-> 21 +30 <-> 22 +Not mapped: +26 +27 diff --git a/testData/src/pkg/TestAccessReplace.java b/testData/src/pkg/TestAccessReplace.java new file mode 100644 index 0000000..e5a21bc --- /dev/null +++ b/testData/src/pkg/TestAccessReplace.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2017 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. + */ +package pkg; + +public class TestAccessReplace { + private static void fooS() {}; + private void foo() {}; + private static void fooSParams(long a, long b) {}; + private void fooParams(long a, long b) {}; + + public class Inner { + public Inner(String b) { + fooS(); + foo(); + fooSParams(1,2); + fooParams(1,2); + } + } +}