IDEA-149813 Decompiler has lost generic parameter

master
Egor.Ushakov 8 years ago
parent fe5260df8a
commit 32693c314a
  1. 23
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 21
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
  3. 3
      test/org/jetbrains/java/decompiler/SingleClassesTest.java
  4. BIN
      testData/classes/pkg/TestAnonymousSignature$1.class
  5. BIN
      testData/classes/pkg/TestAnonymousSignature$2.class
  6. BIN
      testData/classes/pkg/TestAnonymousSignature.class
  7. 50
      testData/results/TestAnonymousSignature.dec
  8. 40
      testData/src/pkg/TestAnonymousSignature.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.
@ -331,16 +331,9 @@ public class ClassWriter {
buffer.append("class "); buffer.append("class ");
} }
GenericClassDescriptor descriptor = null;
if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES)) {
StructGenericSignatureAttribute attr = (StructGenericSignatureAttribute)cl.getAttributes().getWithKey("Signature");
if (attr != null) {
descriptor = GenericMain.parseClassSignature(attr.getSignature());
}
}
buffer.append(node.simpleName); buffer.append(node.simpleName);
GenericClassDescriptor descriptor = getGenericClassDescriptor(cl);
if (descriptor != null && !descriptor.fparameters.isEmpty()) { if (descriptor != null && !descriptor.fparameters.isEmpty()) {
appendTypeParameters(buffer, descriptor.fparameters, descriptor.fbounds); appendTypeParameters(buffer, descriptor.fparameters, descriptor.fbounds);
} }
@ -1051,7 +1044,17 @@ public class ClassWriter {
} }
} }
private static void appendTypeParameters(TextBuffer buffer, List<String> parameters, List<List<GenericType>> bounds) { public static GenericClassDescriptor getGenericClassDescriptor(StructClass cl) {
if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES)) {
StructGenericSignatureAttribute attr = (StructGenericSignatureAttribute)cl.getAttributes().getWithKey("Signature");
if (attr != null) {
return GenericMain.parseClassSignature(attr.getSignature());
}
}
return null;
}
public static void appendTypeParameters(TextBuffer buffer, List<String> parameters, List<List<GenericType>> bounds) {
buffer.append('<'); buffer.append('<');
for (int i = 0; i < parameters.size(); i++) { for (int i = 0; i < parameters.size(); i++) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2015 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.
@ -21,12 +21,15 @@ import org.jetbrains.java.decompiler.main.ClassesProcessor.ClassNode;
import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.TextBuffer; import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor; import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.vars.CheckTypesResult; import org.jetbrains.java.decompiler.modules.decompiler.vars.CheckTypesResult;
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair; import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair;
import org.jetbrains.java.decompiler.struct.StructClass; import org.jetbrains.java.decompiler.struct.StructClass;
import org.jetbrains.java.decompiler.struct.gen.VarType; import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.struct.gen.generics.GenericClassDescriptor;
import org.jetbrains.java.decompiler.struct.gen.generics.GenericMain;
import org.jetbrains.java.decompiler.util.InterpreterUtil; import org.jetbrains.java.decompiler.util.InterpreterUtil;
import org.jetbrains.java.decompiler.util.ListStack; import org.jetbrains.java.decompiler.util.ListStack;
@ -181,8 +184,24 @@ public class NewExprent extends Exprent {
typename = typename.substring(typename.lastIndexOf('.') + 1); typename = typename.substring(typename.lastIndexOf('.') + 1);
} }
} }
GenericClassDescriptor descriptor = ClassWriter.getGenericClassDescriptor(child.classStruct);
if (descriptor != null) {
if (descriptor.superinterfaces.isEmpty()) {
buf.append(GenericMain.getGenericCastTypeName(descriptor.superclass));
}
else {
if (descriptor.superinterfaces.size() > 1) {
DecompilerContext.getLogger().writeMessage("Inconsistent anonymous class signature: " + child.classStruct.qualifiedName,
IFernflowerLogger.Severity.WARN);
}
buf.append(GenericMain.getGenericCastTypeName(descriptor.superinterfaces.get(0)));
}
}
else {
buf.append(typename); buf.append(typename);
} }
}
buf.append('('); buf.append('(');

@ -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.
@ -76,6 +76,7 @@ public class SingleClassesTest {
@Test public void testInnerLocal() { doTest("pkg/TestInnerLocal"); } @Test public void testInnerLocal() { doTest("pkg/TestInnerLocal"); }
@Test public void testInnerLocalPkg() { doTest("pkg/TestInnerLocalPkg"); } @Test public void testInnerLocalPkg() { doTest("pkg/TestInnerLocalPkg"); }
@Test public void testInnerSignature() { doTest("pkg/TestInnerSignature"); } @Test public void testInnerSignature() { doTest("pkg/TestInnerSignature"); }
@Test public void testAnonymousSignature() { doTest("pkg/TestAnonymousSignature"); }
@Test public void testParameterizedTypes() { doTest("pkg/TestParameterizedTypes"); } @Test public void testParameterizedTypes() { doTest("pkg/TestParameterizedTypes"); }
@Test public void testShadowing() { doTest("pkg/TestShadowing", "pkg/Shadow", "ext/Shadow"); } @Test public void testShadowing() { doTest("pkg/TestShadowing", "pkg/Shadow", "ext/Shadow"); }
@Test public void testStringConcat() { doTest("pkg/TestStringConcat"); } @Test public void testStringConcat() { doTest("pkg/TestStringConcat"); }

@ -0,0 +1,50 @@
package pkg;
import java.util.ArrayList;
import java.util.Comparator;
public class TestAnonymousSignature {
public static void main(String[] var0) {
System.out.println(new ArrayList<String>() {// 25
public int size() {
return super.size();// 28
}
});
System.out.println(new Comparator<String>() {// 33
public int compare(String var1, String var2) {
return 0;// 36
}
});
}// 39
}
class 'pkg/TestAnonymousSignature$1' {
method 'size ()I' {
1 9
4 9
}
}
class 'pkg/TestAnonymousSignature$2' {
method 'compare (Ljava/lang/String;Ljava/lang/String;)I' {
0 14
1 14
}
}
class 'pkg/TestAnonymousSignature' {
method 'main ([Ljava/lang/String;)V' {
0 7
a 7
d 12
17 12
1a 17
}
}
Lines mapping:
25 <-> 8
28 <-> 10
33 <-> 13
36 <-> 15
39 <-> 18

@ -0,0 +1,40 @@
/*
* 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.
*/
package pkg;
import java.util.ArrayList;
import java.util.Comparator;
public class TestAnonymousSignature {
public static void main(String[] args) {
// anonymous from class
System.out.println(new ArrayList<String>() {
@Override
public int size() {
return super.size();
}
});
// anonymous from class
System.out.println(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return 0;
}
});
}
}
Loading…
Cancel
Save