From f83c480383d02966143c5c6b85f454a3941a0b43 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 6 Dec 2017 12:20:13 +0100 Subject: [PATCH] [java decompiler] better filter for synthetic constructor parameters --- .../jetbrains/java/decompiler/main/ClassWriter.java | 2 +- .../java/decompiler/main/ClassesProcessor.java | 1 - .../decompiler/main/rels/NestedClassProcessor.java | 4 ---- .../modules/decompiler/exps/NewExprent.java | 12 +++++++----- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index 5b6ae7e..dc3b829 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -227,7 +227,7 @@ public class ClassWriter { for (ClassNode inner : node.nested) { if (inner.type == ClassNode.CLASS_MEMBER) { StructClass innerCl = inner.classStruct; - boolean isSynthetic = (inner.access & CodeConstants.ACC_SYNTHETIC) != 0 || innerCl.isSynthetic() || inner.namelessConstructorStub; + boolean isSynthetic = (inner.access & CodeConstants.ACC_SYNTHETIC) != 0 || innerCl.isSynthetic(); boolean hide = isSynthetic && DecompilerContext.getOption(IFernflowerPreferences.REMOVE_SYNTHETIC) || wrapper.getHiddenMembers().contains(innerCl.qualifiedName); if (hide) continue; diff --git a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java index 26817be..bda88c6 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java @@ -327,7 +327,6 @@ public class ClassesProcessor { public final Set enclosingClasses = new HashSet<>(); public ClassNode parent; public LambdaInformation lambdaInformation; - public boolean namelessConstructorStub = false; public ClassNode(String content_class_name, String content_method_name, diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java index 4a77471..20f4859 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java @@ -61,10 +61,6 @@ public class NestedClassProcessor { DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN); child.simpleName = "NamelessClass_" + (++nameless); } - child.namelessConstructorStub = !cl.hasModifier(CodeConstants.ACC_STATIC) && cl.getMethods().size() + cl.getFields().size() == 0; - } - else if (child.type == ClassNode.CLASS_ANONYMOUS && (child.access & CodeConstants.ACC_SYNTHETIC) != 0 || cl.isSynthetic()) { - child.namelessConstructorStub = !cl.hasModifier(CodeConstants.ACC_STATIC) && cl.getMethods().size() + cl.getFields().size() == 0; } } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java index 95cf2f7..541e91d 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java @@ -283,11 +283,8 @@ public class NewExprent extends Exprent { Exprent expr = InvocationExprent.unboxIfNeeded(parameters.get(i)); VarType leftType = constructor.getDescriptor().params[i]; - if (i == parameters.size() - 1 && expr.getExprType() == VarType.VARTYPE_NULL) { - ClassNode node = DecompilerContext.getClassProcessor().getMapRootClasses().get(leftType.value); - if (node != null && node.namelessConstructorStub) { - break; // skip last parameter of synthetic constructor call - } + if (i == parameters.size() - 1 && expr.getExprType() == VarType.VARTYPE_NULL && probablySyntheticParameter(leftType.value)) { + break; // skip last parameter of synthetic constructor call } if (!firstParam) { @@ -360,6 +357,11 @@ public class NewExprent extends Exprent { return buf; } + private static boolean probablySyntheticParameter(String className) { + ClassNode node = DecompilerContext.getClassProcessor().getMapRootClasses().get(className); + return node != null && node.type == ClassNode.CLASS_ANONYMOUS; + } + private static String getQualifiedNewInstance(String classname, List lstParams, int indent, BytecodeMappingTracer tracer) { ClassNode node = DecompilerContext.getClassProcessor().getMapRootClasses().get(classname);