IDEA-166073 Extended Width (long, double) constructors cause issues with anonymous classes

master
Egor.Ushakov 8 years ago
parent abbf2daf30
commit 0684264b3a
  1. 4
      src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java
  2. 24
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
  3. 2
      test/org/jetbrains/java/decompiler/SingleClassesTest.java
  4. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$1.class
  5. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$10.class
  6. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$11.class
  7. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$12.class
  8. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$2.class
  9. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$3.class
  10. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$4.class
  11. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$5.class
  12. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$6.class
  13. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$7.class
  14. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$8.class
  15. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$9.class
  16. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$InnerPrivate.class
  17. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$InnerPrivateString.class
  18. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$InnerPublic.class
  19. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$InnerPublicString.class
  20. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$InnerStaticPrivate.class
  21. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$InnerStaticPrivateString.class
  22. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$InnerStaticPublic.class
  23. BIN
      testData/classes/pkg/TestAnonymousClassConstructor$InnerStaticPublicString.class
  24. BIN
      testData/classes/pkg/TestAnonymousClassConstructor.class
  25. BIN
      testData/classes/pkg/TestAnonymousParamNames$1.class
  26. BIN
      testData/classes/pkg/TestAnonymousParamNames$Clazz.class
  27. BIN
      testData/classes/pkg/TestAnonymousParamNames.class
  28. 308
      testData/results/TestAnonymousClassConstructor.dec
  29. 22
      testData/results/TestAnonymousParamNames.dec
  30. 103
      testData/src/pkg/TestAnonymousClassConstructor.java
  31. 27
      testData/src/pkg/TestAnonymousParamNames.java

@ -393,7 +393,7 @@ public class NestedClassProcessor {
mergeListSignatures(interPairMask, interMask, true); mergeListSignatures(interPairMask, interMask, true);
for (VarFieldPair pair : interPairMask) { for (VarFieldPair pair : interPairMask) {
if (pair != null && pair.fieldKey.length() > 0) { if (pair != null && !pair.fieldKey.isEmpty()) {
nestedNode.mapFieldsToVars.put(pair.fieldKey, pair.varPair); nestedNode.mapFieldsToVars.put(pair.fieldKey, pair.varPair);
} }
} }
@ -406,7 +406,7 @@ public class NestedClassProcessor {
method.signatureFields = new ArrayList<>(); method.signatureFields = new ArrayList<>();
for (VarFieldPair pair : entry.getValue()) { for (VarFieldPair pair : entry.getValue()) {
method.signatureFields.add(pair == null ? null : pair.varPair); method.signatureFields.add(pair == null || pair.fieldKey.isEmpty() ? null : pair.varPair);
} }
} }
} }

@ -210,8 +210,8 @@ public class NewExprent extends Exprent {
ClassNode newNode = DecompilerContext.getClassProcessor().getMapRootClasses().get(invSuper.getClassname()); ClassNode newNode = DecompilerContext.getClassProcessor().getMapRootClasses().get(invSuper.getClassname());
List<VarVersionPair> sigFields = null; List<VarVersionPair> sigFields = child.getWrapper().getMethodWrapper(CodeConstants.INIT_NAME, constructor.getStringDescriptor()).signatureFields;
if (newNode != null) { // own class if (sigFields == null && newNode != null) { // own class
if (newNode.getWrapper() != null) { if (newNode.getWrapper() != null) {
sigFields = newNode.getWrapper().getMethodWrapper(CodeConstants.INIT_NAME, invSuper.getStringDescriptor()).signatureFields; sigFields = newNode.getWrapper().getMethodWrapper(CodeConstants.INIT_NAME, invSuper.getStringDescriptor()).signatureFields;
} }
@ -224,27 +224,17 @@ public class NewExprent extends Exprent {
} }
} }
List<Exprent> lstParameters = constructor.getLstParameters();
int start = enumConst ? 2 : 0;
boolean firstParam = true; boolean firstParam = true;
int start = 0, end = invSuper.getLstParameters().size(); for (int i = start; i < lstParameters.size(); i++) {
if (enumConst) {
start += 2;
end -= 1;
}
for (int i = start; i < end; i++) {
if (sigFields == null || sigFields.get(i) == null) { if (sigFields == null || sigFields.get(i) == null) {
if (!firstParam) { if (!firstParam) {
buf.append(", "); buf.append(", ");
} }
Exprent param = invSuper.getLstParameters().get(i); ExprProcessor.getCastedExprent(lstParameters.get(i), constructor.getDescriptor().params[i], buf, indent, true, tracer);
if (param.type == Exprent.EXPRENT_VAR) {
int varIndex = ((VarExprent)param).getIndex();
if (varIndex > 0 && varIndex <= constructor.getLstParameters().size()) {
param = constructor.getLstParameters().get(varIndex - 1);
}
}
ExprProcessor.getCastedExprent(param, invSuper.getDescriptor().params[i], buf, indent, true, tracer);
firstParam = false; firstParam = false;
} }

@ -62,6 +62,7 @@ public class SingleClassesTest {
@Test public void testEnum() { doTest("pkg/TestEnum"); } @Test public void testEnum() { doTest("pkg/TestEnum"); }
@Test public void testDebugSymbols() { doTest("pkg/TestDebugSymbols"); } @Test public void testDebugSymbols() { doTest("pkg/TestDebugSymbols"); }
@Test public void testInvalidMethodSignature() { doTest("InvalidMethodSignature"); } @Test public void testInvalidMethodSignature() { doTest("InvalidMethodSignature"); }
@Test public void testAnonymousClassConstructor() { doTest("pkg/TestAnonymousClassConstructor"); }
@Test public void testInnerClassConstructor() { doTest("pkg/TestInnerClassConstructor"); } @Test public void testInnerClassConstructor() { doTest("pkg/TestInnerClassConstructor"); }
@Test public void testInnerClassConstructor11() { doTest("v11/TestInnerClassConstructor"); } @Test public void testInnerClassConstructor11() { doTest("v11/TestInnerClassConstructor"); }
@Test public void testTryCatchFinally() { doTest("pkg/TestTryCatchFinally"); } @Test public void testTryCatchFinally() { doTest("pkg/TestTryCatchFinally"); }
@ -94,6 +95,7 @@ public class SingleClassesTest {
@Test public void testKotlinConstructor() { doTest("pkg/TestKotlinConstructorKt"); } @Test public void testKotlinConstructor() { doTest("pkg/TestKotlinConstructorKt"); }
@Test public void testAsserts() { doTest("pkg/TestAsserts"); } @Test public void testAsserts() { doTest("pkg/TestAsserts"); }
@Test public void testLocalsNames() { doTest("pkg/TestLocalsNames"); } @Test public void testLocalsNames() { doTest("pkg/TestLocalsNames"); }
@Test public void testAnonymousParamNames() { doTest("pkg/TestAnonymousParamNames"); }
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,308 @@
package pkg;
class TestAnonymousClassConstructor {
void innerPrivateString() {
TestAnonymousClassConstructor.InnerPrivateString var10001 = new TestAnonymousClassConstructor.InnerPrivateString("text") {// 5
};
}// 6
void innerPrivate() {
TestAnonymousClassConstructor.InnerPrivate var10001 = new TestAnonymousClassConstructor.InnerPrivate(3L, 4) {// 9
};
}// 10
void innerStaticPrivateString() {
TestAnonymousClassConstructor.InnerStaticPrivateString var10001 = new TestAnonymousClassConstructor.InnerStaticPrivateString("text") {// 13
};
}// 14
void innerStaticPrivate() {
TestAnonymousClassConstructor.InnerStaticPrivate var10001 = new TestAnonymousClassConstructor.InnerStaticPrivate(3L, 4) {// 17
};
}// 18
static void innerStaticPrivateStringStatic() {
TestAnonymousClassConstructor.InnerStaticPrivateString var10001 = new TestAnonymousClassConstructor.InnerStaticPrivateString("text") {// 21
};
}// 22
static void innerStaticPrivateStatic() {
TestAnonymousClassConstructor.InnerStaticPrivate var10001 = new TestAnonymousClassConstructor.InnerStaticPrivate(3L, 4) {// 25
};
}// 26
void innerPublicString() {
TestAnonymousClassConstructor.InnerPublicString var10001 = new TestAnonymousClassConstructor.InnerPublicString("text") {// 29
};
}// 30
void innerPublic() {
TestAnonymousClassConstructor.InnerPublic var10001 = new TestAnonymousClassConstructor.InnerPublic(3L, 4) {// 33
};
}// 34
void innerStaticPublicString() {
TestAnonymousClassConstructor.InnerStaticPublicString var10001 = new TestAnonymousClassConstructor.InnerStaticPublicString("text") {// 37
};
}// 38
void innerStaticPublic() {
TestAnonymousClassConstructor.InnerStaticPublic var10001 = new TestAnonymousClassConstructor.InnerStaticPublic(3L, 4) {// 41
};
}// 42
static void innerStaticPublicStringStatic() {
TestAnonymousClassConstructor.InnerStaticPublicString var10001 = new TestAnonymousClassConstructor.InnerStaticPublicString("text") {// 45
};
}// 46
static void innerStaticPublicStatic() {
TestAnonymousClassConstructor.InnerStaticPublic var10001 = new TestAnonymousClassConstructor.InnerStaticPublic(3L, 4) {// 49
};
}// 50
static void n(String s) {
System.out.println("n(): " + s);// 53
}// 54
static class InnerStaticPublic {
public InnerStaticPublic(long a, int b) {
TestAnonymousClassConstructor.n(a + "+" + b);// 100
}// 101
}
static class InnerStaticPublicString {
public InnerStaticPublicString(String s) {
TestAnonymousClassConstructor.n(s);// 94
}// 95
}
class InnerPublic {
public InnerPublic(long a, int b) {
TestAnonymousClassConstructor.n(a + "+" + b);// 88
}// 89
}
class InnerPublicString {
public InnerPublicString(String s) {
TestAnonymousClassConstructor.n(s);// 82
}// 83
}
static class InnerStaticPrivate {
private InnerStaticPrivate(long a, int b) {
TestAnonymousClassConstructor.n(a + "+" + b);// 76
}// 77
}
static class InnerStaticPrivateString {
private InnerStaticPrivateString(String s) {
TestAnonymousClassConstructor.n(s);// 70
}// 71
}
class InnerPrivate {
private InnerPrivate(long a, int b) {
TestAnonymousClassConstructor.n(a + "+" + b);// 64
}// 65
}
class InnerPrivateString {
private InnerPrivateString(String s) {
TestAnonymousClassConstructor.n(s);// 58
}// 59
}
}
class 'pkg/TestAnonymousClassConstructor' {
method 'innerPrivateString ()V' {
5 4
b 6
}
method 'innerPrivate ()V' {
5 9
8 9
d 11
}
method 'innerStaticPrivateString ()V' {
5 14
b 16
}
method 'innerStaticPrivate ()V' {
5 19
8 19
d 21
}
method 'innerStaticPrivateStringStatic ()V' {
4 24
a 26
}
method 'innerStaticPrivateStatic ()V' {
4 29
7 29
c 31
}
method 'innerPublicString ()V' {
5 34
b 36
}
method 'innerPublic ()V' {
5 39
8 39
d 41
}
method 'innerStaticPublicString ()V' {
5 44
b 46
}
method 'innerStaticPublic ()V' {
5 49
8 49
d 51
}
method 'innerStaticPublicStringStatic ()V' {
4 54
a 56
}
method 'innerStaticPublicStatic ()V' {
4 59
7 59
c 61
}
method 'n (Ljava/lang/String;)V' {
0 64
a 64
13 64
16 64
19 65
}
}
class 'pkg/TestAnonymousClassConstructor$InnerStaticPublic' {
method '<init> (JI)V' {
f 69
18 69
1b 69
1e 70
}
}
class 'pkg/TestAnonymousClassConstructor$InnerStaticPublicString' {
method '<init> (Ljava/lang/String;)V' {
5 75
8 76
}
}
class 'pkg/TestAnonymousClassConstructor$InnerPublic' {
method '<init> (Lpkg/TestAnonymousClassConstructor;JI)V' {
14 81
1e 81
21 81
24 82
}
}
class 'pkg/TestAnonymousClassConstructor$InnerPublicString' {
method '<init> (Lpkg/TestAnonymousClassConstructor;Ljava/lang/String;)V' {
a 87
d 88
}
}
class 'pkg/TestAnonymousClassConstructor$InnerStaticPrivate' {
method '<init> (JI)V' {
f 93
18 93
1b 93
1e 94
}
}
class 'pkg/TestAnonymousClassConstructor$InnerStaticPrivateString' {
method '<init> (Ljava/lang/String;)V' {
5 99
8 100
}
}
class 'pkg/TestAnonymousClassConstructor$InnerPrivate' {
method '<init> (Lpkg/TestAnonymousClassConstructor;JI)V' {
14 105
1e 105
21 105
24 106
}
}
class 'pkg/TestAnonymousClassConstructor$InnerPrivateString' {
method '<init> (Lpkg/TestAnonymousClassConstructor;Ljava/lang/String;)V' {
a 111
d 112
}
}
Lines mapping:
5 <-> 5
6 <-> 7
9 <-> 10
10 <-> 12
13 <-> 15
14 <-> 17
17 <-> 20
18 <-> 22
21 <-> 25
22 <-> 27
25 <-> 30
26 <-> 32
29 <-> 35
30 <-> 37
33 <-> 40
34 <-> 42
37 <-> 45
38 <-> 47
41 <-> 50
42 <-> 52
45 <-> 55
46 <-> 57
49 <-> 60
50 <-> 62
53 <-> 65
54 <-> 66
58 <-> 112
59 <-> 113
64 <-> 106
65 <-> 107
70 <-> 100
71 <-> 101
76 <-> 94
77 <-> 95
82 <-> 88
83 <-> 89
88 <-> 82
89 <-> 83
94 <-> 76
95 <-> 77
100 <-> 70
101 <-> 71
Not mapped:
57
63
69
75
81
87
93
99

@ -0,0 +1,22 @@
package pkg;
public class TestAnonymousParamNames {
private final TestAnonymousParamNames.Clazz reference = new TestAnonymousParamNames.Clazz(0L, false) {
};
private class Clazz {
public Clazz(long paramL, boolean paramB) {
}// 25
}
}
class 'pkg/TestAnonymousParamNames$Clazz' {
method '<init> (Lpkg/TestAnonymousParamNames;JZ)V' {
9 8
}
}
Lines mapping:
25 <-> 9
Not mapped:
24

@ -0,0 +1,103 @@
package pkg;
class TestAnonymousClassConstructor {
void innerPrivateString() {
new InnerPrivateString("text"){};
}
void innerPrivate() {
new InnerPrivate(3, 4){};
}
void innerStaticPrivateString() {
new InnerStaticPrivateString("text"){};
}
void innerStaticPrivate() {
new InnerStaticPrivate(3, 4){};
}
static void innerStaticPrivateStringStatic() {
new InnerStaticPrivateString("text"){};
}
static void innerStaticPrivateStatic() {
new InnerStaticPrivate(3, 4){};
}
void innerPublicString() {
new InnerPublicString("text"){};
}
void innerPublic() {
new InnerPublic(3, 4){};
}
void innerStaticPublicString() {
new InnerStaticPublicString("text"){};
}
void innerStaticPublic() {
new InnerStaticPublic(3, 4){};
}
static void innerStaticPublicStringStatic() {
new InnerStaticPublicString("text"){};
}
static void innerStaticPublicStatic() {
new InnerStaticPublic(3, 4){};
}
static void n(String s) {
System.out.println("n(): " + s);
}
class InnerPrivateString {
private InnerPrivateString(String s) {
n(s);
}
}
class InnerPrivate {
private InnerPrivate(long a, int b) {
n(a + "+" + b);
}
}
static class InnerStaticPrivateString {
private InnerStaticPrivateString(String s) {
n(s);
}
}
static class InnerStaticPrivate {
private InnerStaticPrivate(long a, int b) {
n(a + "+" + b);
}
}
class InnerPublicString {
public InnerPublicString(String s) {
n(s);
}
}
class InnerPublic {
public InnerPublic(long a, int b) {
n(a + "+" + b);
}
}
static class InnerStaticPublicString {
public InnerStaticPublicString(String s) {
n(s);
}
}
static class InnerStaticPublic {
public InnerStaticPublic(long a, int b) {
n(a + "+" + b);
}
}
}

@ -0,0 +1,27 @@
/*
* Copyright 2000-2016 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;
import java.io.File;
public class TestAnonymousParamNames {
private final Clazz reference = new Clazz(0, false) {};
private class Clazz {
public Clazz(long paramL, boolean paramB) {
}
}
}
Loading…
Cancel
Save