Skip to content

Commit

Permalink
feat(#165): refactor the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Nov 8, 2023
1 parent 7874256 commit d5a57de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,15 +71,6 @@ public Iterator<Directive> 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();
}
Expand Down

0 comments on commit d5a57de

Please sign in to comment.