From cc855619dac21af57fd3cb9cf0aeba901b4950fd Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Fri, 2 Aug 2024 15:59:51 +0300 Subject: [PATCH] feat(#344): fix all qulice suggestions --- .../handlers/InvokespecialHandler.java | 26 +++++++++++-------- src/test/java/it/JeoAndOpeoTest.java | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokespecialHandler.java b/src/main/java/org/eolang/opeo/decompilation/handlers/InvokespecialHandler.java index 0c691cee..d85e423e 100644 --- a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokespecialHandler.java +++ b/src/main/java/org/eolang/opeo/decompilation/handlers/InvokespecialHandler.java @@ -84,8 +84,7 @@ public void handle(final DecompilerState state) { ); Collections.reverse(args); final AstNode target = state.stack().pop(); - final boolean istarget = InvokespecialHandler.isThis(target); - if (istarget) { + if (InvokespecialHandler.isThis(target)) { state.stack().push( new Super(target, args, descriptor, type, name) ); @@ -97,28 +96,33 @@ public void handle(final DecompilerState state) { args ) ); - } else { state.stack().push( new Super(target, args, descriptor, type, name) ); -// state.stack().push( -// new Super(target, args, descriptor, type, name) -// ); } } - //todo wtf? + /** + * Check if the target is a new address. + * @param target Where to check if it is a new address. + * @return True if the target is a new address. + * @todo #344:90min Remove ugly {{@link #isNewAddress(AstNode)}} method. + * We need to find a better algorithm to decompile Constructors and Super calls. + * The usage of 'instanceof' tells us about pure design decisions made before. + */ private boolean isNewAddress(final AstNode target) { + final boolean result; if (target instanceof NewAddress) { - return true; + result = true; } else if (target instanceof Duplicate) { - return this.isNewAddress(((Duplicate) target).origin()); + result = this.isNewAddress(((Duplicate) target).origin()); } else if (target instanceof Labeled) { - return this.isNewAddress(((Labeled) target).origin()); + result = this.isNewAddress(((Labeled) target).origin()); } else { - return false; + result = false; } + return result; } /** diff --git a/src/test/java/it/JeoAndOpeoTest.java b/src/test/java/it/JeoAndOpeoTest.java index ecca8f8f..d92fddaf 100644 --- a/src/test/java/it/JeoAndOpeoTest.java +++ b/src/test/java/it/JeoAndOpeoTest.java @@ -130,7 +130,7 @@ void compilesDecompiled(final String path) { "xmir/disassembled/WebProperties$Resources$Chain$Strategy$Content.xmir", "xmir/disassembled/OAuth2ClientRegistrationRepositoryConfiguration.xmir", "xmir/disassembled/DefaultRouterFunctionSpec.xmir", - "xmir/disassembled/SpringBootExceptionHandler$LoggedExceptionHandlerThreadLocal.xmir", + "xmir/disassembled/SpringBootExceptionHandler$LoggedExceptionHandlerThreadLocal.xmir" }) void decompilesCompilesAndKeepsTheSameInstructions(final String path) throws Exception { final XMLDocument original = new XMLDocument(new BytesOf(new ResourceOf(path)).asBytes());