Skip to content

Commit

Permalink
Work around odd constructor oddities
Browse files Browse the repository at this point in the history
  • Loading branch information
sschr15 committed Jan 21, 2024
1 parent 58f0785 commit b59d6bd
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,31 @@ public boolean stringify(TextBuffer buffer, int indent) {
parameter.stringify(indent + 1, buf);
}

buf.appendPossibleNewline("", true).popNewlineGroup().append(") : ");
buf.appendPossibleNewline("", true).popNewlineGroup();

Exprent firstExpr = method.getOrBuildGraph().first.exprents.get(0);
if (!(firstExpr instanceof InvocationExprent)) {
throw new IllegalStateException("First expression of constructor is not InvocationExprent");
String methodDescriptor = method.methodStruct.getName() + method.methodStruct.getDescriptor();
String containingClass = node.classStruct.qualifiedName;

List<Exprent> exprents = method.getOrBuildGraph().first.exprents;
if (exprents.isEmpty()) {
DecompilerContext.getLogger().writeMessage("Unexpected empty constructor body in " + containingClass + " " + methodDescriptor, IFernflowerLogger.Severity.WARN);
return true;
}

InvocationExprent invocation = (InvocationExprent) firstExpr;
buf.append(invocation.toJava(indent + 1), node.classStruct.qualifiedName, InterpreterUtil.makeUniqueKey(method.methodStruct.getName(), method.methodStruct.getDescriptor()));
buf.append(") ");

Exprent firstExpr = exprents.get(0);
if (!(firstExpr instanceof InvocationExprent)) {
// no detected super / this constructor call (something isn't right)
DecompilerContext.getLogger().writeMessage("Unexpected missing super/this constructor call in " + containingClass + " " + methodDescriptor, IFernflowerLogger.Severity.WARN);
} else {
buf.append(": ");

InvocationExprent invocation = (InvocationExprent) firstExpr;
buf.append(invocation.toJava(indent + 1), node.classStruct.qualifiedName, InterpreterUtil.makeUniqueKey(method.methodStruct.getName(), method.methodStruct.getDescriptor()));

method.getOrBuildGraph().first.exprents.remove(0);
method.getOrBuildGraph().first.exprents.remove(0);
}
}

if (method.getOrBuildGraph().first.exprents.isEmpty()) {
Expand Down

0 comments on commit b59d6bd

Please sign in to comment.