IDEA-149813 Decompiler has lost generic parameter

This commit is contained in:
Egor.Ushakov
2017-01-10 12:03:26 +03:00
parent fe5260df8a
commit 32693c314a
8 changed files with 126 additions and 13 deletions

View File

@@ -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.
@@ -331,16 +331,9 @@ public class ClassWriter {
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);
GenericClassDescriptor descriptor = getGenericClassDescriptor(cl);
if (descriptor != null && !descriptor.fparameters.isEmpty()) {
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('<');
for (int i = 0; i < parameters.size(); i++) {

View File

@@ -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");
* 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.TextBuffer;
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.modules.decompiler.ExprProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.vars.CheckTypesResult;
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair;
import org.jetbrains.java.decompiler.struct.StructClass;
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.ListStack;
@@ -181,7 +184,23 @@ public class NewExprent extends Exprent {
typename = typename.substring(typename.lastIndexOf('.') + 1);
}
}
buf.append(typename);
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('(');