From 4fcda28a14096ecc2a3af220aa0dc956e0563f1d Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 2 Jul 2024 12:31:09 +0300 Subject: [PATCH] feat(#627): add suffix for method names --- .../jeo/representation/directives/DirectivesMethod.java | 2 +- .../directives/DirectivesMethodProperties.java | 6 ++++++ .../org/eolang/jeo/representation/xmir/XmlMethod.java | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethod.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethod.java index 61f3b6fa7..fe938faeb 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethod.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethod.java @@ -161,7 +161,7 @@ public Iterator iterator() { final Directives directives = new Directives(); final String eoname; if ("".equals(this.name)) { - eoname = "new"; + eoname = "new" + "-" + this.properties.suffix(); } else { eoname = this.name; } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java index ecb0374a0..516e68362 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java @@ -23,6 +23,8 @@ */ package org.eolang.jeo.representation.directives; +import java.nio.charset.StandardCharsets; +import java.util.Base64; import java.util.Iterator; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; @@ -117,6 +119,10 @@ public void maxs(final int stack, final int locals) { this.max.set(new DirectivesMaxs(stack, locals)); } + public String suffix() { + return Base64.getEncoder().encodeToString(this.descriptor.getBytes(StandardCharsets.UTF_8)); + } + @Override public Iterator iterator() { return new Directives() diff --git a/src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java b/src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java index 64b17ae69..0e9a8343c 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java @@ -130,12 +130,17 @@ public String name() { final String original = this.node.attribute("name").orElseThrow( () -> new IllegalStateException("Method 'name' attribute is not present") ); - if ("new".equals(original)) { + if (original.contains("new")) { result = ""; } else { result = original; } - return result; + final int endIndex = result.lastIndexOf('-'); + if (endIndex > 0) { + return result.substring(0, endIndex); + } else { + return result; + } } /**