fixed access to private outer class methods with params

master
Egor.Ushakov 8 years ago
parent 85f61bee81
commit 45384fb8c5
  1. 12
      src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java
  2. 1
      test/org/jetbrains/java/decompiler/SingleClassesTest.java
  3. BIN
      testData/classes/pkg/TestAccessReplace$Inner.class
  4. BIN
      testData/classes/pkg/TestAccessReplace.class
  5. 69
      testData/results/TestAccessReplace.dec
  6. 32
      testData/src/pkg/TestAccessReplace.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; InvocationExprent invexpr = (InvocationExprent)exprCore;
if ((invexpr.isStatic() && invexpr.getLstParameters().size() == parcount) || boolean isStatic = invexpr.isStatic();
(!invexpr.isStatic() && invexpr.getInstance().type == Exprent.EXPRENT_VAR if ((isStatic && invexpr.getLstParameters().size() == parcount) ||
(!isStatic && invexpr.getInstance().type == Exprent.EXPRENT_VAR
&& ((VarExprent)invexpr.getInstance()).getIndex() == 0 && invexpr.getLstParameters().size() == parcount - 1)) { && ((VarExprent)invexpr.getInstance()).getIndex() == 0 && invexpr.getLstParameters().size() == parcount - 1)) {
boolean equalpars = true; boolean equalpars = true;
int index = isStatic ? 0 : 1;
for (int i = 0; i < invexpr.getLstParameters().size(); i++) { for (int i = 0; i < invexpr.getLstParameters().size(); i++) {
Exprent parexpr = invexpr.getLstParameters().get(i); Exprent parexpr = invexpr.getLstParameters().get(i);
if (parexpr.type != Exprent.EXPRENT_VAR || if (parexpr.type != Exprent.EXPRENT_VAR || ((VarExprent)parexpr).getIndex() != index) {
((VarExprent)parexpr).getIndex() != i + (invexpr.isStatic() ? 0 : 1)) {
equalpars = false; equalpars = false;
break; break;
} }
index += mtdesc.params[i + (isStatic ? 0 : 1)].stackSize;
} }
if (equalpars) { if (equalpars) {

@ -97,6 +97,7 @@ public class SingleClassesTest {
@Test public void testLocalsNames() { doTest("pkg/TestLocalsNames"); } @Test public void testLocalsNames() { doTest("pkg/TestLocalsNames"); }
@Test public void testAnonymousParamNames() { doTest("pkg/TestAnonymousParamNames"); } @Test public void testAnonymousParamNames() { doTest("pkg/TestAnonymousParamNames"); }
@Test public void testAnonymousParams() { doTest("pkg/TestAnonymousParams"); } @Test public void testAnonymousParams() { doTest("pkg/TestAnonymousParams"); }
@Test public void testAccessReplace() { doTest("pkg/TestAccessReplace"); }
private void doTest(String testFile, String... companionFiles) { private void doTest(String testFile, String... companionFiles) {
ConsoleDecompiler decompiler = fixture.getDecompiler(); ConsoleDecompiler decompiler = fixture.getDecompiler();

@ -0,0 +1,69 @@
package pkg;
public class TestAccessReplace {
private static void fooS() {
}// 19
private void foo() {
}// 20
private static void fooSParams(long a, long b) {
}// 21
private void fooParams(long a, long b) {
}// 22
public class Inner {
public Inner(String b) {
TestAccessReplace.fooS();// 25
TestAccessReplace.this.foo();
TestAccessReplace.fooSParams(1L, 2L);// 28
TestAccessReplace.this.fooParams(1L, 2L);// 29
}// 30
}
}
class 'pkg/TestAccessReplace' {
method 'fooS ()V' {
0 4
}
method 'foo ()V' {
0 7
}
method 'fooSParams (JJ)V' {
0 10
}
method 'fooParams (JJ)V' {
0 13
}
}
class 'pkg/TestAccessReplace$Inner' {
method '<init> (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

@ -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);
}
}
}
Loading…
Cancel
Save