From d5a57def5c4d499a5d43075c328c05ba1991e9c3 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 8 Nov 2023 11:41:25 +0300 Subject: [PATCH] feat(#165): refactor the code a bit --- .../ImprovementDistilledObjects.java | 39 +++++++------------ .../directives/DirectivesData.java | 10 ----- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/eolang/jeo/improvement/ImprovementDistilledObjects.java b/src/main/java/org/eolang/jeo/improvement/ImprovementDistilledObjects.java index 6d275f106..79c31c135 100644 --- a/src/main/java/org/eolang/jeo/improvement/ImprovementDistilledObjects.java +++ b/src/main/java/org/eolang/jeo/improvement/ImprovementDistilledObjects.java @@ -380,7 +380,7 @@ private Representation combine() { */ private void handleClass(final XmlClass decor) { final Node root = decor.node(); - this.removeOldFields(root); + this.removeFieldsThatWillBeInlined(root); decor.replaceArguments(this.decorator.name(), this.combinedName()); DecoratorPair.removeOldConstructors(root); final XmlClass clazz = new XmlProgram(this.decorated.toEO()).top(); @@ -412,36 +412,23 @@ private static void removeOldConstructors(final Node root) { /** * Remove old fields. * @param root Root node. - * @todo #157:90min Handle fields correctly during inlining optimization. - * Right now we just remove all fields from the decorated object. - * It's not correct, because we need to handle fields correctly and probably remove only - * those fields that are used in the decorator. */ - private void removeOldFields(final Node root) { + private void removeFieldsThatWillBeInlined(final Node root) { new XmlClass(root).fields() .stream() - .forEach(field -> this.handleField(root, field)); - } - - private void handleField(final Node root, final XmlField field) { - if (this.isInlinedField(field)) { - root.removeChild(field.node()); - } + .filter(this::isInlined) + .map(XmlField::node) + .forEach(root::removeChild); } - private boolean isInlinedField(final XmlField field) { - boolean inner = field.access() == (Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL); - final String descriptor = field.descriptor(); - final String name = String.format("L%s;", this.decorated.name()); - Logger.info( - this, - "Compare %s and %s, access modifier %d", - descriptor, - name, - field.access() - ); - boolean same = descriptor.equals(name); - return inner && same; + /** + * Check if field will be inlined. + * @param field Field. + * @return True if field will be inlined. + */ + private boolean isInlined(final XmlField field) { + return field.access() == (Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL) + && field.descriptor().equals(String.format("L%s;", this.decorated.name())); } } } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesData.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesData.java index 6f703acb8..3da878052 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesData.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesData.java @@ -23,7 +23,6 @@ */ package org.eolang.jeo.representation.directives; -import com.jcabi.log.Logger; import java.util.Iterator; import org.eolang.jeo.representation.HexData; import org.xembly.Directive; @@ -72,15 +71,6 @@ public Iterator iterator() { .attr("data", "bytes"); if (!this.name.isEmpty()) { directives.attr("name", this.name); - if (name.equals("value")) { - Logger.info(this, - String.format( - "We are trying to save the next value into XMIR: '%s' with type '%s'", - this.data, - this.data.getClass().getSimpleName() - ) - ); - } } return directives.set(hex.value()).up().iterator(); }