From bdf080f9015c04533467cac1f95c3827c4681a86 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 3 Dec 2024 17:42:15 +0300 Subject: [PATCH 01/30] feat(#939): upgrate eo up to 0.45.0 version - build fails --- pom.xml | 2 +- src/it/annotations/pom.xml | 2 +- src/it/bytecode-to-eo/pom.xml | 4 ++-- src/it/custom-transformations/pom.xml | 2 +- src/it/exceptions/pom.xml | 2 +- src/it/generics/pom.xml | 2 +- src/it/jna/pom.xml | 2 +- src/it/phi-unphi/pom.xml | 2 +- src/it/spring/pom.xml | 2 +- src/it/takes/pom.xml | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index d5e0aff91..4d50f263c 100644 --- a/pom.xml +++ b/pom.xml @@ -184,7 +184,7 @@ SOFTWARE. org.eolang eo-parser - 0.44.0 + 0.45.0 com.github.volodya-lombrozo diff --git a/src/it/annotations/pom.xml b/src/it/annotations/pom.xml index 22557a91c..4cde80fdf 100644 --- a/src/it/annotations/pom.xml +++ b/src/it/annotations/pom.xml @@ -64,7 +64,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.44.0 + 0.45.0 convert-xmir-to-eo diff --git a/src/it/bytecode-to-eo/pom.xml b/src/it/bytecode-to-eo/pom.xml index 99c447e45..9d610c618 100644 --- a/src/it/bytecode-to-eo/pom.xml +++ b/src/it/bytecode-to-eo/pom.xml @@ -70,7 +70,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.44.0 + 0.45.0 convert-xmir-to-phi @@ -98,7 +98,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.44.0 + 0.45.0 convert-xmir-to-eo diff --git a/src/it/custom-transformations/pom.xml b/src/it/custom-transformations/pom.xml index 5674402c3..df7207943 100644 --- a/src/it/custom-transformations/pom.xml +++ b/src/it/custom-transformations/pom.xml @@ -64,7 +64,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.44.0 + 0.45.0 + + org.eolang + lints + 0.0.21 + org.cactoos cactoos diff --git a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java index 4c7345a6f..4587a3621 100644 --- a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java +++ b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java @@ -26,6 +26,10 @@ import com.jcabi.xml.StrictXML; import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; +import java.io.IOException; +import java.util.Collection; +import org.eolang.lints.Defect; +import org.eolang.lints.Program; import org.xembly.Directive; import org.xembly.ImpossibleModificationException; import org.xembly.Xembler; @@ -58,7 +62,24 @@ final class VerifiedEo { */ XML asXml() throws ImpossibleModificationException { final XML res = new XMLDocument(new Xembler(this.directives).xml()); - new StrictXML(res).validate(); + try { + final Collection defects = new Program( + new StrictXML(res) + ).defects(); + if (defects.size() > 0) { + throw new IllegalStateException( + String.format( + "EO is incorrect: %s", + defects + ) + ); + } + } catch (final IOException exception) { + throw new IllegalStateException( + "Failed to verify EO", + exception + ); + } return res; } } From f575475ccb16e3979f824b25cc81ace58cacc432 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 15:23:49 +0300 Subject: [PATCH 12/30] feat(#939): catch only XMIR errors instead of all the warnings --- pom.xml | 2 +- .../eolang/jeo/representation/VerifiedEo.java | 10 +++++--- .../directives/DirectivesClassProperties.java | 24 +++++++++++++++---- .../directives/DirectivesField.java | 2 ++ .../directives/DirectivesJeoObject.java | 7 +++++- .../directives/DirectivesMaxs.java | 9 +++++-- .../directives/DirectivesMetas.java | 24 ++++++++++++++----- .../DirectivesMethodProperties.java | 13 ++++++---- 8 files changed, 69 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 4947c3f04..825f176e9 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ SOFTWARE. org.eolang lints - 0.0.21 + 0.0.22 org.cactoos diff --git a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java index 4587a3621..716f3250b 100644 --- a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java +++ b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java @@ -28,8 +28,10 @@ import com.jcabi.xml.XMLDocument; import java.io.IOException; import java.util.Collection; +import java.util.stream.Collectors; import org.eolang.lints.Defect; import org.eolang.lints.Program; +import org.eolang.lints.Severity; import org.xembly.Directive; import org.xembly.ImpossibleModificationException; import org.xembly.Xembler; @@ -65,12 +67,14 @@ XML asXml() throws ImpossibleModificationException { try { final Collection defects = new Program( new StrictXML(res) - ).defects(); + ).defects().stream().filter(defect -> defect.severity().equals(Severity.ERROR)) + .collect(Collectors.toList()); if (defects.size() > 0) { throw new IllegalStateException( String.format( - "EO is incorrect: %s", - defects + "EO is incorrect: %s, %n%s%n", + defects, + res ) ); } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesClassProperties.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesClassProperties.java index 9c86e1e06..66811970e 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesClassProperties.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesClassProperties.java @@ -23,7 +23,9 @@ */ package org.eolang.jeo.representation.directives; +import java.security.SecureRandom; import java.util.Iterator; +import java.util.Random; import org.eolang.jeo.representation.DefaultVersion; import org.xembly.Directive; import org.xembly.Directives; @@ -35,6 +37,8 @@ */ public final class DirectivesClassProperties implements Iterable { + private static final Random RANDOM = new SecureRandom(); + /** * Class bytecode version. */ @@ -126,18 +130,28 @@ public DirectivesClassProperties( @Override public Iterator iterator() { + final int number = Math.abs(DirectivesClassProperties.RANDOM.nextInt()); final Directives directives = new Directives() - .append(new DirectivesValue("version", this.version)) - .append(new DirectivesValue("access", this.access)); + .append( + new DirectivesValue( + DirectivesClassProperties.format("version", number), + this.version + ) + ) + .append(new DirectivesValue(format("access", number), this.access)); if (this.signature != null) { - directives.append(new DirectivesValue("signature", this.signature)); + directives.append(new DirectivesValue(format("signature", number), this.signature)); } if (this.supername != null) { - directives.append(new DirectivesValue("supername", this.supername)); + directives.append(new DirectivesValue(format("supername", number), this.supername)); } if (this.interfaces != null) { - directives.append(new DirectivesValues("interfaces", this.interfaces)); + directives.append(new DirectivesValues(format("interfaces", number), this.interfaces)); } return directives.iterator(); } + + private static String format(final String name, final int number) { + return String.format("%s-%d", name, number); + } } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesField.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesField.java index cb810ff0b..09ed2ee25 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesField.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesField.java @@ -23,8 +23,10 @@ */ package org.eolang.jeo.representation.directives; +import java.security.SecureRandom; import java.util.Iterator; import java.util.Optional; +import java.util.Random; import lombok.EqualsAndHashCode; import lombok.ToString; import org.eolang.jeo.representation.PrefixedName; diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesJeoObject.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesJeoObject.java index 246bab329..a41c4fa39 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesJeoObject.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesJeoObject.java @@ -23,9 +23,11 @@ */ package org.eolang.jeo.representation.directives; +import java.security.SecureRandom; import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.Random; import java.util.stream.Collectors; import org.xembly.Directive; import org.xembly.Directives; @@ -38,6 +40,8 @@ */ public final class DirectivesJeoObject implements Iterable { + private final static Random RANDOM = new SecureRandom(); + /** * The base of the object. */ @@ -118,10 +122,11 @@ public DirectivesJeoObject(final String base, final String name, final List iterator() { + final int number = Math.abs(DirectivesJeoObject.RANDOM.nextInt()); final Directives directives = new Directives().add("o") .attr("base", new JeoFqn(this.base).fqn()); if (!this.name.isEmpty()) { - directives.attr("name", this.name); + directives.attr("name", String.format("%s-%d", this.name, number)); } return directives .append(this.inner.stream().reduce(new Directives(), Directives::append)) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java index b192ccfeb..241316f91 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java @@ -23,7 +23,9 @@ */ package org.eolang.jeo.representation.directives; +import java.security.SecureRandom; import java.util.Iterator; +import java.util.Random; import org.xembly.Directive; /** @@ -32,6 +34,8 @@ */ public final class DirectivesMaxs implements Iterable { + private static final Random RANDOM = new SecureRandom(); + /** * Max stack size. */ @@ -62,10 +66,11 @@ public DirectivesMaxs(final int stack, final int locals) { @Override public Iterator iterator() { + final int number = Math.abs(DirectivesMaxs.RANDOM.nextInt()); return new DirectivesJeoObject( "maxs", - new DirectivesValue("stack", this.stack), - new DirectivesValue("locals", this.locals) + new DirectivesValue(String.format("stack-%d", number), this.stack), + new DirectivesValue(String.format("locals-%d", number), this.locals) ).iterator(); } } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java index 7fe75bfc0..a24fa3886 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java @@ -73,11 +73,11 @@ public DirectivesMetas( @Override public Iterator iterator() { final Directives metas = new Directives().add("metas").append(this.pckg()); - this.jeo() - .stream() - .filter(object -> !object.isEmpty()) - .map(DirectivesMetas::alias) - .forEach(metas::append); +// this.jeo() +// .stream() +// .filter(object -> !object.isEmpty()) +// .map(DirectivesMetas::alias) +// .forEach(metas::append); return metas.up().iterator(); } @@ -136,10 +136,22 @@ private Set jeo() { * @return Alias directive. */ private static Directives alias(final String object) { + String substring; + if (object.contains(".")) { + substring = object.substring(object.indexOf(".") + 1); + } else { + substring = object; + } + + if (substring.contains(".")) { + substring = substring.substring(0, substring.indexOf(".")); + } + return new Directives() .add("meta") .add("head").set("alias").up() - .add("tail").set(object).up() + .add("tail").set(substring + " " + object).up() + .add("part").set(substring).up() .add("part").set(object).up() .up(); } 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 16650bf13..224a56946 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java @@ -23,8 +23,10 @@ */ package org.eolang.jeo.representation.directives; +import java.security.SecureRandom; import java.util.Iterator; import java.util.Optional; +import java.util.Random; import java.util.concurrent.atomic.AtomicReference; import org.objectweb.asm.Opcodes; import org.xembly.Directive; @@ -36,6 +38,8 @@ */ public final class DirectivesMethodProperties implements Iterable { + private static final Random RANDOM = new SecureRandom(); + /** * Method access modifiers. */ @@ -125,11 +129,12 @@ public DirectivesMethodProperties( @Override public Iterator iterator() { + final int number = Math.abs(DirectivesMethodProperties.RANDOM.nextInt()); return new Directives() - .append(new DirectivesValue("access", this.access)) - .append(new DirectivesValue("descriptor", this.descriptor)) - .append(new DirectivesValue("signature", this.signature)) - .append(new DirectivesValues("exceptions", this.exceptions)) + .append(new DirectivesValue(String.format("access-%d", number), this.access)) + .append(new DirectivesValue(String.format("descriptor-%d", number), this.descriptor)) + .append(new DirectivesValue(String.format("signature-%d", number), this.signature)) + .append(new DirectivesValues(String.format("exceptions-%d", number), this.exceptions)) .append(this.max.get()) .append(this.params) .iterator(); From 751814aad2cfe1655b9795c58c89fb8991e9376e Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 15:54:13 +0300 Subject: [PATCH 13/30] feat(#939): remove unnecessary numbers from names --- .../directives/DirectivesClassProperties.java | 24 ++++--------------- .../directives/DirectivesMaxs.java | 9 ++----- .../DirectivesMethodProperties.java | 11 ++++----- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesClassProperties.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesClassProperties.java index 66811970e..9c86e1e06 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesClassProperties.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesClassProperties.java @@ -23,9 +23,7 @@ */ package org.eolang.jeo.representation.directives; -import java.security.SecureRandom; import java.util.Iterator; -import java.util.Random; import org.eolang.jeo.representation.DefaultVersion; import org.xembly.Directive; import org.xembly.Directives; @@ -37,8 +35,6 @@ */ public final class DirectivesClassProperties implements Iterable { - private static final Random RANDOM = new SecureRandom(); - /** * Class bytecode version. */ @@ -130,28 +126,18 @@ public DirectivesClassProperties( @Override public Iterator iterator() { - final int number = Math.abs(DirectivesClassProperties.RANDOM.nextInt()); final Directives directives = new Directives() - .append( - new DirectivesValue( - DirectivesClassProperties.format("version", number), - this.version - ) - ) - .append(new DirectivesValue(format("access", number), this.access)); + .append(new DirectivesValue("version", this.version)) + .append(new DirectivesValue("access", this.access)); if (this.signature != null) { - directives.append(new DirectivesValue(format("signature", number), this.signature)); + directives.append(new DirectivesValue("signature", this.signature)); } if (this.supername != null) { - directives.append(new DirectivesValue(format("supername", number), this.supername)); + directives.append(new DirectivesValue("supername", this.supername)); } if (this.interfaces != null) { - directives.append(new DirectivesValues(format("interfaces", number), this.interfaces)); + directives.append(new DirectivesValues("interfaces", this.interfaces)); } return directives.iterator(); } - - private static String format(final String name, final int number) { - return String.format("%s-%d", name, number); - } } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java index 241316f91..b192ccfeb 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java @@ -23,9 +23,7 @@ */ package org.eolang.jeo.representation.directives; -import java.security.SecureRandom; import java.util.Iterator; -import java.util.Random; import org.xembly.Directive; /** @@ -34,8 +32,6 @@ */ public final class DirectivesMaxs implements Iterable { - private static final Random RANDOM = new SecureRandom(); - /** * Max stack size. */ @@ -66,11 +62,10 @@ public DirectivesMaxs(final int stack, final int locals) { @Override public Iterator iterator() { - final int number = Math.abs(DirectivesMaxs.RANDOM.nextInt()); return new DirectivesJeoObject( "maxs", - new DirectivesValue(String.format("stack-%d", number), this.stack), - new DirectivesValue(String.format("locals-%d", number), this.locals) + new DirectivesValue("stack", this.stack), + new DirectivesValue("locals", this.locals) ).iterator(); } } 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 224a56946..80adfdb15 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java @@ -38,8 +38,6 @@ */ public final class DirectivesMethodProperties implements Iterable { - private static final Random RANDOM = new SecureRandom(); - /** * Method access modifiers. */ @@ -129,12 +127,11 @@ public DirectivesMethodProperties( @Override public Iterator iterator() { - final int number = Math.abs(DirectivesMethodProperties.RANDOM.nextInt()); return new Directives() - .append(new DirectivesValue(String.format("access-%d", number), this.access)) - .append(new DirectivesValue(String.format("descriptor-%d", number), this.descriptor)) - .append(new DirectivesValue(String.format("signature-%d", number), this.signature)) - .append(new DirectivesValues(String.format("exceptions-%d", number), this.exceptions)) + .append(new DirectivesValue("access", this.access)) + .append(new DirectivesValue("descriptor", this.descriptor)) + .append(new DirectivesValue("signature", this.signature)) + .append(new DirectivesValues("exceptions", this.exceptions)) .append(this.max.get()) .append(this.params) .iterator(); From 5efe07e4e049766978d7c3596fdf5929ae05295a Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 16:04:48 +0300 Subject: [PATCH 14/30] feat(#939): remove random numbers at all --- .../directives/DirectivesJeoObject.java | 10 +++---- .../jeo/representation/xmir/XmlNode.java | 26 +++++++++++++------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesJeoObject.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesJeoObject.java index a41c4fa39..12363cd92 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesJeoObject.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesJeoObject.java @@ -23,11 +23,9 @@ */ package org.eolang.jeo.representation.directives; -import java.security.SecureRandom; import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.Random; import java.util.stream.Collectors; import org.xembly.Directive; import org.xembly.Directives; @@ -40,8 +38,6 @@ */ public final class DirectivesJeoObject implements Iterable { - private final static Random RANDOM = new SecureRandom(); - /** * The base of the object. */ @@ -122,14 +118,14 @@ public DirectivesJeoObject(final String base, final String name, final List iterator() { - final int number = Math.abs(DirectivesJeoObject.RANDOM.nextInt()); final Directives directives = new Directives().add("o") .attr("base", new JeoFqn(this.base).fqn()); if (!this.name.isEmpty()) { - directives.attr("name", String.format("%s-%d", this.name, number)); + directives.attr("name", this.name); } return directives .append(this.inner.stream().reduce(new Directives(), Directives::append)) - .up().iterator(); + .up() + .iterator(); } } diff --git a/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java b/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java index 2ce640f66..86bb5ebd9 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java @@ -112,14 +112,24 @@ public String text() { * @return Attribute. */ public Optional attribute(final String name) { - final Optional result; - final NamedNodeMap attrs = this.node.getAttributes(); - if (attrs == null) { - result = Optional.empty(); - } else { - result = Optional.ofNullable(attrs.getNamedItem(name)).map(Node::getTextContent); + final NamedNodeMap attributes = this.node.getAttributes(); + final int length = attributes.getLength(); + for (int index = 0; index < length; index++) { + final Node item = attributes.item(index); + if (item.getNodeName().startsWith(name)) { + return Optional.of(item.getTextContent()); + } } - return result; + return Optional.empty(); + +// final Optional result; +// final NamedNodeMap attrs = this.node.getAttributes(); +// if (attrs == null) { +// result = Optional.empty(); +// } else { +// result = Optional.ofNullable(attrs.getNamedItem(name)).map(Node::getTextContent); +// } +// return result; } /** @@ -194,7 +204,7 @@ XmlNode firstChild() { boolean hasAttribute(final String name, final String value) { return this.attribute(name) .map(String::valueOf) - .map(val -> val.equals(value)) + .map(val -> val.startsWith(value)) .orElse(false); } From 78c4fb51f3b71b5c951f246c590915751d2e92ea Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 16:13:38 +0300 Subject: [PATCH 15/30] feat(#939): remove random numbers at all --- .../jeo/representation/directives/DirectivesMaxs.java | 4 ++-- .../directives/DirectivesMethodProperties.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java index b192ccfeb..25ed3519c 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMaxs.java @@ -64,8 +64,8 @@ public DirectivesMaxs(final int stack, final int locals) { public Iterator iterator() { return new DirectivesJeoObject( "maxs", - new DirectivesValue("stack", this.stack), - new DirectivesValue("locals", this.locals) + new DirectivesValue(this.stack), + new DirectivesValue(this.locals) ).iterator(); } } 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 80adfdb15..0ec14a4db 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java @@ -128,10 +128,10 @@ public DirectivesMethodProperties( @Override public Iterator iterator() { return new Directives() - .append(new DirectivesValue("access", this.access)) - .append(new DirectivesValue("descriptor", this.descriptor)) - .append(new DirectivesValue("signature", this.signature)) - .append(new DirectivesValues("exceptions", this.exceptions)) + .append(new DirectivesValue(this.access)) + .append(new DirectivesValue(this.descriptor)) + .append(new DirectivesValue(this.signature)) + .append(new DirectivesValues(this.exceptions)) .append(this.max.get()) .append(this.params) .iterator(); From 3e217a989a297b37577f9eb4d90e0a3570e42eef Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 16:40:07 +0300 Subject: [PATCH 16/30] feat(#939): add numbers for all sequence names --- .../directives/DirectivesAnnotations.java | 14 +++++++++++++- .../directives/DirectivesMethodParams.java | 2 +- .../representation/directives/DirectivesSeq.java | 7 ++++++- .../eolang/jeo/representation/xmir/XmlClass.java | 2 ++ .../eolang/jeo/representation/xmir/XmlMethod.java | 2 ++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java index 37cf1539a..61dd7e382 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java @@ -23,10 +23,12 @@ */ package org.eolang.jeo.representation.directives; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.Random; import lombok.EqualsAndHashCode; import lombok.ToString; import org.xembly.Directive; @@ -39,6 +41,8 @@ @EqualsAndHashCode public final class DirectivesAnnotations implements Iterable { + private static final Random RANDOM = new SecureRandom(); + /** * All the annotations. */ @@ -88,7 +92,15 @@ public DirectivesAnnotations(final List> annotations, final * @param annotations Annotations. */ private DirectivesAnnotations(final List> annotations) { - this(annotations, "annotations"); + this( + annotations, + String.format( + String.format( + "annotations-%d", + DirectivesAnnotations.RANDOM.nextInt() + ) + ) + ); } @Override diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodParams.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodParams.java index e13520e6d..ac424d8cc 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodParams.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodParams.java @@ -60,7 +60,7 @@ public DirectivesMethodParams(final List> params) { public Iterator iterator() { return new DirectivesJeoObject( "params", - "method-params", +// "method-params", this.params.stream().map(Directives::new).collect(Collectors.toList()) ).iterator(); } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesSeq.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesSeq.java index 3d09a1eef..3e63a111d 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesSeq.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesSeq.java @@ -23,10 +23,12 @@ */ package org.eolang.jeo.representation.directives; +import java.security.SecureRandom; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Objects; +import java.util.Random; import java.util.stream.Collectors; import java.util.stream.Stream; import org.cactoos.scalar.LengthOf; @@ -80,14 +82,17 @@ private DirectivesSeq(final String name, final Iterable... elements) this(name, Arrays.asList(elements)); } + private final static Random RANDOM = new SecureRandom(); + @Override public Iterator iterator() { + final int number = RANDOM.nextInt(); final List all = this.stream() .map(Directives::new) .collect(Collectors.toList()); return new DirectivesJeoObject( String.format("seq.of%d", all.size()), - this.name, + String.format("%s-%d", this.name, number), all ).iterator(); } diff --git a/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java b/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java index cb710fe27..4fc7844ba 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java @@ -142,6 +142,8 @@ private String name() { */ private Optional annotations() { return this.node.children() +// .filter(o -> o.attribute("name").isPresent()) +// .filter(o -> o.attribute("name").get().startsWith("annotations")) .filter(o -> o.hasAttribute("name", "annotations")) .findFirst() .map(XmlAnnotations::new); 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 a9d05548a..0b7c8732f 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java @@ -290,6 +290,8 @@ private List trycatchEntries() { */ private BytecodeAnnotations annotations() { return this.node.children() +// .filter(o -> o.attribute("name").isPresent()) +// .filter(o -> o.attribute("name").get().startsWith("annotations")) .filter(element -> element.hasAttribute("name", "annotations")) .findFirst() .map(XmlAnnotations::new) From 796b617a798d7a89b77813e19b8de00e82485966 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 16:54:50 +0300 Subject: [PATCH 17/30] feat(#939): repair all the integration tests --- src/it/spring/verify.groovy | 3 --- .../org/eolang/jeo/representation/VerifiedEo.java | 11 ++++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/it/spring/verify.groovy b/src/it/spring/verify.groovy index 000a8aad0..8582ee072 100644 --- a/src/it/spring/verify.groovy +++ b/src/it/spring/verify.groovy @@ -32,10 +32,7 @@ def app = new File(basedir, 'target/generated-sources/jeo-xmir/org/eolang/jeo/sp assert app.exists() assert app.text.contains("metas") assert app.text.contains("package") -// Check that we have "opcode" and "label" imports where they are needed -assert app.text.contains("jeo.opcode.return") //Check that if class doesn't have instructions, it doesn't have "opcode" imports. def empty = new File(basedir, 'target/generated-sources/jeo-xmir/org/eolang/jeo/spring/WithoutInstructions.xmir') assert empty.exists() -assert !empty.text.contains("jeo.opcode.return") true \ No newline at end of file diff --git a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java index 716f3250b..f11e7fc7d 100644 --- a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java +++ b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java @@ -27,7 +27,9 @@ import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; +import java.util.Optional; import java.util.stream.Collectors; import org.eolang.lints.Defect; import org.eolang.lints.Program; @@ -65,9 +67,12 @@ final class VerifiedEo { XML asXml() throws ImpossibleModificationException { final XML res = new XMLDocument(new Xembler(this.directives).xml()); try { - final Collection defects = new Program( - new StrictXML(res) - ).defects().stream().filter(defect -> defect.severity().equals(Severity.ERROR)) + final Collection defects = Optional.ofNullable(new Program( + new StrictXML(res) + ).defects() + ).orElse(new ArrayList<>(0)) + .stream() + .filter(defect -> defect.severity().equals(Severity.ERROR)) .collect(Collectors.toList()); if (defects.size() > 0) { throw new IllegalStateException( From 4efc021bfc42f71d0a4beb36c6a092426f38fd63 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 17:35:52 +0300 Subject: [PATCH 18/30] feat(#939): fix most of the unit tests --- pom.xml | 2 +- .../eolang/jeo/representation/VerifiedEo.java | 14 +++- .../bytecode/BytecodeProgram.java | 5 +- .../directives/DirectivesMetas.java | 80 ++----------------- .../jeo/representation/xmir/XmlMethod.java | 4 +- .../directives/DirectivesAnnotationsTest.java | 10 ++- .../directives/DirectivesClassTest.java | 22 +++-- .../directives/DirectivesMetasTest.java | 19 ----- .../directives/DirectivesSeqTest.java | 8 +- .../directives/DirectivesValuesTest.java | 4 +- .../representation/xmir/XmlMethodTest.java | 4 +- 11 files changed, 44 insertions(+), 128 deletions(-) diff --git a/pom.xml b/pom.xml index 825f176e9..fe7c1bd29 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ SOFTWARE. org.eolang lints - 0.0.22 + 0.0.23 org.cactoos diff --git a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java index f11e7fc7d..b14054ca5 100644 --- a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java +++ b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java @@ -67,10 +67,7 @@ final class VerifiedEo { XML asXml() throws ImpossibleModificationException { final XML res = new XMLDocument(new Xembler(this.directives).xml()); try { - final Collection defects = Optional.ofNullable(new Program( - new StrictXML(res) - ).defects() - ).orElse(new ArrayList<>(0)) + final Collection defects = VerifiedEo.defects(res) .stream() .filter(defect -> defect.severity().equals(Severity.ERROR)) .collect(Collectors.toList()); @@ -91,4 +88,13 @@ XML asXml() throws ImpossibleModificationException { } return res; } + + private static Collection defects(final XML res) throws IOException { +// return Optional.ofNullable( +// new Program( +// new StrictXML(res) +// ).defects() +// ).orElse(new ArrayList<>(0)); + return new Program(new StrictXML(res)).defects(); + } } diff --git a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeProgram.java b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeProgram.java index a57354586..b2951d633 100644 --- a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeProgram.java +++ b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeProgram.java @@ -154,10 +154,7 @@ public DirectivesProgram directives(final String listing) { return new DirectivesProgram( listing, clazz, - new DirectivesMetas( - classname, - clazz - ) + new DirectivesMetas(classname) ); } } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java index a24fa3886..536c28fc3 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java @@ -23,15 +23,11 @@ */ package org.eolang.jeo.representation.directives; -import com.jcabi.xml.XMLDocument; -import java.util.HashSet; import java.util.Iterator; -import java.util.Set; import org.eolang.jeo.representation.ClassName; import org.eolang.jeo.representation.PrefixedName; import org.xembly.Directive; import org.xembly.Directives; -import org.xembly.Xembler; /** * Directives for meta-information of a class. @@ -44,41 +40,23 @@ public final class DirectivesMetas implements Iterable { */ private final ClassName name; - /** - * Class directives. - */ - private final DirectivesClass clazz; - /** * Constructor. * @param classname Class name. */ public DirectivesMetas(final ClassName classname) { - this(classname, new DirectivesClass(new ClassName("org.jeo", "SomeClass"))); - } - - /** - * Constructor. - * @param classname Class name. - * @param clazz Class directives. - */ - public DirectivesMetas( - final ClassName classname, - final DirectivesClass clazz - ) { this.name = classname; - this.clazz = clazz; } @Override public Iterator iterator() { - final Directives metas = new Directives().add("metas").append(this.pckg()); -// this.jeo() -// .stream() -// .filter(object -> !object.isEmpty()) -// .map(DirectivesMetas::alias) -// .forEach(metas::append); - return metas.up().iterator(); + final Iterator result; + if (this.name.pckg().isEmpty()) { + result = new Directives().iterator(); + } else { + result = new Directives().add("metas").append(this.pckg()).up().iterator(); + } + return result; } /** @@ -111,48 +89,4 @@ private Directives pckg() { } return result; } - - /** - * Find all jeo objects. - * @return Set of jeo objects. - * @todo #883:90min Optimize jeo.* Objects Collection for Metas. - * Currently, we are required to pre-build a part of XML, find all the jeo objects - * by using Xpath and then build the XML. This is not efficient. - * We should find a way to collect all the jeo objects on the way. - */ - private Set jeo() { - return new HashSet<>( - new XMLDocument( - new Xembler( - new Directives(this.clazz) - ).xmlQuietly() - ).xpath(".//o[starts-with(@base, 'jeo.')]/@base") - ); - } - - /** - * Alias directive for an object. - * @param object Some object name. - * @return Alias directive. - */ - private static Directives alias(final String object) { - String substring; - if (object.contains(".")) { - substring = object.substring(object.indexOf(".") + 1); - } else { - substring = object; - } - - if (substring.contains(".")) { - substring = substring.substring(0, substring.indexOf(".")); - } - - return new Directives() - .add("meta") - .add("head").set("alias").up() - .add("tail").set(substring + " " + object).up() - .add("part").set(substring).up() - .add("part").set(object).up() - .up(); - } } 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 0b7c8732f..7ea9764c1 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java @@ -279,7 +279,7 @@ private List trycatchEntries() { .map(s -> s.contains("trycatchblocks")) .orElse(false)) .flatMap(XmlNode::children) - .map(entry -> new XmlTryCatchEntry(entry)) + .map(XmlTryCatchEntry::new) .collect(Collectors.toList()); } @@ -290,8 +290,6 @@ private List trycatchEntries() { */ private BytecodeAnnotations annotations() { return this.node.children() -// .filter(o -> o.attribute("name").isPresent()) -// .filter(o -> o.attribute("name").get().startsWith("annotations")) .filter(element -> element.hasAttribute("name", "annotations")) .findFirst() .map(XmlAnnotations::new) diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationsTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationsTest.java index 9440030eb..5eed28fdb 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationsTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationsTest.java @@ -41,7 +41,9 @@ void returnsEmptyDirectviesIfNoAnnotations() throws ImpossibleModificationExcept MatcherAssert.assertThat( "Must return empty directives if no annotations", new Xembler(new DirectivesAnnotations()).xml(), - new SameXml("") + XhtmlMatchers.hasXPaths( + "/o[contains(@base,'jeo.seq.of0') and contains(@name,'annotations')]" + ) ); } @@ -54,13 +56,13 @@ void returnsSingleAnnotation() throws ImpossibleModificationException { new DirectivesAnnotations().add(new DirectivesAnnotation(annotation, true)) ).xml(), XhtmlMatchers.hasXPaths( - "/o[contains(@base,'seq.of1') and @name='annotations']/o", + "/o[contains(@base,'seq.of1') and contains(@name,'annotations')]/o", String.format( - "/o[contains(@base,'seq.of1') and @name='annotations']/o/o[1][contains(@base,'string')]/o[text()='%s']", + "/o[contains(@base,'seq.of1') and contains(@name,'annotations')]/o/o[1][contains(@base,'string')]/o[text()='%s']", new DirectivesValue(annotation).hex() ), String.format( - "/o[contains(@base,'seq.of1') and @name='annotations']/o/o[2][contains(@base,'bool')]/o[text()='%s']", + "/o[contains(@base,'seq.of1') and contains(@name,'annotations')]/o/o[2][contains(@base,'bool')]/o[text()='%s']", new DirectivesValue(true).hex() ) ) diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassTest.java index 57eaa0bc7..82789112a 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassTest.java @@ -52,19 +52,15 @@ void createsWithSimpleConstructor() throws ImpossibleModificationException { new DirectivesClass(new ClassName("Neo"), new DirectivesClassProperties()), new Transformers.Node() ).xml(), - new SameXml( - String.join( - "", - "", - "00-00-00-00-00-00-00-34", - "00-00-00-00-00-00-00-00", - "--", - "--", - "", - "", - "", - "" - ) + XhtmlMatchers.hasXPaths( + "/o[@name='Neo']", + "/o[@name='Neo']/o[contains(@name,'version')]", + "/o[@name='Neo']/o[contains(@name,'access')]", + "/o[@name='Neo']/o[contains(@name,'signature')]", + "/o[@name='Neo']/o[contains(@name,'supername')]", + "/o[@name='Neo']/o[contains(@name,'interfaces')]", + "/o[@name='Neo']/o[contains(@name,'annotations')]", + "/o[@name='Neo']/o[contains(@name,'attributes')]" ) ); } diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java index 6381bd4c4..b8d349fbe 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java @@ -56,25 +56,6 @@ void createsMetasWithPackage() { ); } - @Test - void addsAliasesForAllTheRequiredObjects() throws ImpossibleModificationException { - MatcherAssert.assertThat( - "Can't create corresponding xembly directives for all the required objects", - new Xembler( - new BytecodeProgram(new BytecodeClass().helloWorldMethod()).directives("") - ).xml(), - Matchers.allOf( - XhtmlMatchers.hasXPath("/program/metas/meta/head[text()='alias']"), - XhtmlMatchers.hasXPath("/program/metas/meta/tail[text()='jeo.opcode.return']"), - XhtmlMatchers.hasXPath("/program/metas/meta/tail[text()='jeo.label']"), - XhtmlMatchers.hasXPath("/program/metas/meta/part[text()='jeo.int']"), - XhtmlMatchers.hasXPath("/program/metas/meta/part[text()='jeo.bool']"), - XhtmlMatchers.hasXPath("/program/metas/meta/part[text()='jeo.param']"), - XhtmlMatchers.hasXPath("/program/metas/meta/part[text()='jeo.params']") - ) - ); - } - @Test void addsNothingExceptPackage() { MatcherAssert.assertThat( diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesSeqTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesSeqTest.java index bea279387..66fec2a0e 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesSeqTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesSeqTest.java @@ -51,9 +51,9 @@ void convertsToNumberedSeq() throws ImpossibleModificationException { ) ).xml(), XhtmlMatchers.hasXPaths( - "/o[contains(@base,'seq.of2') and @name='seq']", - "/o[contains(@base,'seq.of2') and @name='seq']/o[contains(@base,'string')]/o[@base='org.eolang.bytes' and text()='31-']", - "/o[contains(@base,'seq.of2') and @name='seq']/o[contains(@base,'string')]/o[@base='org.eolang.bytes' and text()='32-']" + "/o[contains(@base,'seq.of2') and contains(@name,'seq')]", + "/o[contains(@base,'seq.of2') and contains(@name,'seq')]/o[contains(@base,'string')]/o[@base='org.eolang.bytes' and text()='31-']", + "/o[contains(@base,'seq.of2') and contains(@name,'seq')]/o[contains(@base,'string')]/o[@base='org.eolang.bytes' and text()='32-']" ) ); } @@ -68,7 +68,7 @@ void computesSize( new Xembler(actual).xml(), XhtmlMatchers.hasXPath( String.format( - "/o[contains(@base,'seq.of%d') and @name='seq']", + "/o[contains(@base,'seq.of%d') and contains(@name,'seq')]", expected ) ) diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesValuesTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesValuesTest.java index 4d8f38ccd..a7fd4d00d 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesValuesTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesValuesTest.java @@ -44,8 +44,8 @@ void convertsToXmir() throws ImpossibleModificationException { "We expect that array of values will be converted to correct Xembly directives", new Xembler(new DirectivesValues("name", "value")).xml(), XhtmlMatchers.hasXPaths( - "./o[contains(@base,'seq.of1') and @name='name']", - "./o[contains(@base,'seq.of1') and @name='name']/o/o[@base='org.eolang.bytes' and text()='76-61-6C-75-65']" + "./o[contains(@base,'seq.of1') and contains(@name,'name')]", + "./o[contains(@base,'seq.of1') and contains(@name,'name')]/o/o[@base='org.eolang.bytes' and text()='76-61-6C-75-65']" ) ); } diff --git a/src/test/java/org/eolang/jeo/representation/xmir/XmlMethodTest.java b/src/test/java/org/eolang/jeo/representation/xmir/XmlMethodTest.java index 50aa69941..415762f07 100644 --- a/src/test/java/org/eolang/jeo/representation/xmir/XmlMethodTest.java +++ b/src/test/java/org/eolang/jeo/representation/xmir/XmlMethodTest.java @@ -109,7 +109,9 @@ void catchesMethodParsingException() { new BytecodeMethod( "someMethodName" ).directives() - ).xpath(".//o[@name='exceptions']").append(new DirectivesBytes("???")) + ).xpath( + ".//o[contains(@name,'exceptions')]" + ).append(new DirectivesBytes("???")) ).xmlQuietly() ) ).bytecode() From 1416df5909e3900ce8d1f1032feae3e6a01b5039 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 17:50:47 +0300 Subject: [PATCH 19/30] feat(#939): repair all the unit tests --- .../directives/DirectivesAnnotations.java | 2 +- .../directives/DirectivesSeq.java | 8 ++++--- .../bytecode/BytecodeMethodTest.java | 2 +- .../DirectivesClassPropertiesTest.java | 23 +++++++------------ .../directives/DirectivesMetasTest.java | 14 +++-------- .../representation/directives/HasMethod.java | 8 +++---- .../representation/xmir/XmlMethodTest.java | 5 ++-- 7 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java index 61dd7e382..db93d31e4 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java @@ -97,7 +97,7 @@ private DirectivesAnnotations(final List> annotations) { String.format( String.format( "annotations-%d", - DirectivesAnnotations.RANDOM.nextInt() + Math.abs(DirectivesAnnotations.RANDOM.nextInt()) ) ) ); diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesSeq.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesSeq.java index 3e63a111d..aa244ca9f 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesSeq.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesSeq.java @@ -41,6 +41,10 @@ * @since 0.6 */ public final class DirectivesSeq implements Iterable { + /** + * Random number generator. + */ + private static final Random RANDOM = new SecureRandom(); /** * Name of the sequence. @@ -82,11 +86,9 @@ private DirectivesSeq(final String name, final Iterable... elements) this(name, Arrays.asList(elements)); } - private final static Random RANDOM = new SecureRandom(); - @Override public Iterator iterator() { - final int number = RANDOM.nextInt(); + final int number = Math.abs(DirectivesSeq.RANDOM.nextInt()); final List all = this.stream() .map(Directives::new) .collect(Collectors.toList()); diff --git a/src/test/java/org/eolang/jeo/representation/bytecode/BytecodeMethodTest.java b/src/test/java/org/eolang/jeo/representation/bytecode/BytecodeMethodTest.java index 08d529478..2f1b3d4b8 100644 --- a/src/test/java/org/eolang/jeo/representation/bytecode/BytecodeMethodTest.java +++ b/src/test/java/org/eolang/jeo/representation/bytecode/BytecodeMethodTest.java @@ -370,7 +370,7 @@ void doesNotContainTryCatchBlock() { "We expect that method without try-catch block doesn't contain try-catch directives.", new BytecodeProgram(new BytecodeClass().helloWorldMethod()).xml().toString(), XhtmlMatchers.hasXPath( - ".//o[contains(@base,'seq.of0') and @name='trycatchblocks-main']" + ".//o[contains(@base,'seq.of0') and contains(@name,'trycatchblocks-main')]" ) ); } diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassPropertiesTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassPropertiesTest.java index 3cc01fc90..93fa144d5 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassPropertiesTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassPropertiesTest.java @@ -23,7 +23,7 @@ */ package org.eolang.jeo.representation.directives; -import org.eolang.jeo.matchers.SameXml; +import com.jcabi.matchers.XhtmlMatchers; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import org.xembly.Directives; @@ -53,20 +53,13 @@ void createsDirectives() throws ImpossibleModificationException { ) ).up() ).xml(), - new SameXml( - String.join( - "", - "\n", - "\n", - " 00-00-00-00-00-00-00-34\n", - " 00-00-00-00-00-00-00-01\n", - " 6F-72-67-2F-65-6F-6C-61-6E-67-2F-53-6F-6D-65-43-6C-61-73-73\n", - " 6A-61-76-61-2F-6C-61-6E-67-2F-4F-62-6A-65-63-74\n", - " \n", - " 6F-72-67-2F-65-6F-6C-61-6E-67-2F-53-6F-6D-65-49-6E-74-65-72-66-61-63-65\n", - " \n", - "\n" - ) + XhtmlMatchers.hasXPaths( + "/o/o[contains(@base,'jeo.int') and contains(@name,'version')]", + "/o/o[contains(@base,'jeo.int') and contains(@name,'access')]", + "/o/o[contains(@base,'org.eolang.string') and contains(@name,'signature')]", + "/o/o[contains(@base,'org.eolang.string') and contains(@name,'supername')]", + "/o/o[contains(@base,'jeo.seq.of1') and contains(@name,'interfaces')]" + ) ); } diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java index b8d349fbe..e840e99d2 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java @@ -25,12 +25,9 @@ import com.jcabi.matchers.XhtmlMatchers; import org.eolang.jeo.representation.ClassName; -import org.eolang.jeo.representation.bytecode.BytecodeClass; -import org.eolang.jeo.representation.bytecode.BytecodeProgram; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; -import org.xembly.ImpossibleModificationException; import org.xembly.Transformers; import org.xembly.Xembler; @@ -79,16 +76,11 @@ void addsNothingExceptPackage() { } @Test - void createsDirectivesWithEmptyPackage() throws ImpossibleModificationException { + void createsDirectivesWithEmptyPackage() { MatcherAssert.assertThat( "We expect that / won't be created if package is empty", - new Xembler( - new DirectivesMetas(new ClassName("WithoutPackage")), - new Transformers.Node() - ).xml(), - Matchers.not( - XhtmlMatchers.hasXPath("/metas/meta/head[text()='package']") - ) + new DirectivesMetas(new ClassName("WithoutPackage")), + Matchers.emptyIterable() ); } } diff --git a/src/test/java/org/eolang/jeo/representation/directives/HasMethod.java b/src/test/java/org/eolang/jeo/representation/directives/HasMethod.java index 88d2f22e0..8ca4174e8 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/HasMethod.java +++ b/src/test/java/org/eolang/jeo/representation/directives/HasMethod.java @@ -204,7 +204,7 @@ private Stream parameters() { return this.params.stream() .map( param -> String.format( - "%s/o[contains(@base,'params')]/o[@name='%s' and contains(@base,'param')]/@name", + "%s/o[contains(@base,'params')]/o[contains(@name,'%s') and contains(@base,'param')]/@name", root, param ) @@ -247,7 +247,7 @@ private Stream labels() { */ private String root() { return String.format( - "/program/objects/o[@name='%s']/o[contains(@name,'%s')]", + "/program/objects/o[contains(@name,'%s')]/o[contains(@name,'%s')]", this.clazz, this.name ); @@ -296,7 +296,7 @@ private static final class HasInstruction { */ Stream checks(final String root) { final String instruction = String.format( - "%s/o[contains(@base,'seq') and @name='body']/o[contains(@base,'opcode')]", + "%s/o[contains(@base,'seq') and contains(@name,'body')]/o[contains(@base,'opcode')]", root ); return Stream.concat( @@ -420,7 +420,7 @@ private static final class HasLabel { static Stream checks(final String root) { return Stream.of( String.format( - "%s/o[contains(@base,'seq') and @name='body']/o[contains(@base,'label')]/o[@base='org.eolang.bytes']/@base", + "%s/o[contains(@base,'seq') and contains(@name,'body')]/o[contains(@base,'label')]/o[@base='org.eolang.bytes']/@base", root ) ); diff --git a/src/test/java/org/eolang/jeo/representation/xmir/XmlMethodTest.java b/src/test/java/org/eolang/jeo/representation/xmir/XmlMethodTest.java index 415762f07..1e6fb93f6 100644 --- a/src/test/java/org/eolang/jeo/representation/xmir/XmlMethodTest.java +++ b/src/test/java/org/eolang/jeo/representation/xmir/XmlMethodTest.java @@ -109,9 +109,8 @@ void catchesMethodParsingException() { new BytecodeMethod( "someMethodName" ).directives() - ).xpath( - ".//o[contains(@name,'exceptions')]" - ).append(new DirectivesBytes("???")) + ).xpath(".//o[contains(@name, 'body')]") + .append(new DirectivesBytes("???")) ).xmlQuietly() ) ).bytecode() From 1cec5de769506a6acf2df1a8cf91b18cdba78317 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 18:01:31 +0300 Subject: [PATCH 20/30] feat(#939): fix all the code offences --- .../eolang/jeo/representation/VerifiedEo.java | 22 ++++++------------- .../directives/DirectivesAnnotations.java | 3 +++ .../directives/DirectivesField.java | 2 -- .../directives/DirectivesMethodParams.java | 1 - .../DirectivesMethodProperties.java | 2 -- .../directives/DirectivesProgram.java | 2 +- .../jeo/representation/xmir/XmlClass.java | 2 -- .../jeo/representation/xmir/XmlNode.java | 17 +++++--------- .../XmirRepresentationTest.java | 15 ++++++++----- .../directives/DirectivesAnnotationsTest.java | 1 - .../DirectivesClassPropertiesTest.java | 3 --- .../directives/DirectivesClassTest.java | 1 - 12 files changed, 26 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java index b14054ca5..11738b3ff 100644 --- a/src/main/java/org/eolang/jeo/representation/VerifiedEo.java +++ b/src/main/java/org/eolang/jeo/representation/VerifiedEo.java @@ -27,9 +27,7 @@ import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; -import java.util.Optional; import java.util.stream.Collectors; import org.eolang.lints.Defect; import org.eolang.lints.Program; @@ -63,15 +61,18 @@ final class VerifiedEo { * We also check if the EO is correct. * @return XML representation. * @throws ImpossibleModificationException If something goes wrong. + * @todo #939:60min Fix All The Warnings in the EO Representation. + * Here we just catch only the errors in the EO representation. + * We need to fix all the warnings in the EO representation as well. */ XML asXml() throws ImpossibleModificationException { final XML res = new XMLDocument(new Xembler(this.directives).xml()); try { - final Collection defects = VerifiedEo.defects(res) + final Collection defects = new Program(new StrictXML(res)).defects() .stream() - .filter(defect -> defect.severity().equals(Severity.ERROR)) + .filter(defect -> defect.severity() == Severity.ERROR) .collect(Collectors.toList()); - if (defects.size() > 0) { + if (!defects.isEmpty()) { throw new IllegalStateException( String.format( "EO is incorrect: %s, %n%s%n", @@ -82,19 +83,10 @@ XML asXml() throws ImpossibleModificationException { } } catch (final IOException exception) { throw new IllegalStateException( - "Failed to verify EO", + String.format("Failed to verify EO: %n%s%n", res), exception ); } return res; } - - private static Collection defects(final XML res) throws IOException { -// return Optional.ofNullable( -// new Program( -// new StrictXML(res) -// ).defects() -// ).orElse(new ArrayList<>(0)); - return new Program(new StrictXML(res)).defects(); - } } diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java index db93d31e4..8953219ce 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesAnnotations.java @@ -41,6 +41,9 @@ @EqualsAndHashCode public final class DirectivesAnnotations implements Iterable { + /** + * Random number generator. + */ private static final Random RANDOM = new SecureRandom(); /** diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesField.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesField.java index 09ed2ee25..cb810ff0b 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesField.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesField.java @@ -23,10 +23,8 @@ */ package org.eolang.jeo.representation.directives; -import java.security.SecureRandom; import java.util.Iterator; import java.util.Optional; -import java.util.Random; import lombok.EqualsAndHashCode; import lombok.ToString; import org.eolang.jeo.representation.PrefixedName; diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodParams.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodParams.java index ac424d8cc..83cccd3e1 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodParams.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodParams.java @@ -60,7 +60,6 @@ public DirectivesMethodParams(final List> params) { public Iterator iterator() { return new DirectivesJeoObject( "params", -// "method-params", this.params.stream().map(Directives::new).collect(Collectors.toList()) ).iterator(); } 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 0ec14a4db..34ef8f307 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodProperties.java @@ -23,10 +23,8 @@ */ package org.eolang.jeo.representation.directives; -import java.security.SecureRandom; import java.util.Iterator; import java.util.Optional; -import java.util.Random; import java.util.concurrent.atomic.AtomicReference; import org.objectweb.asm.Opcodes; import org.xembly.Directive; diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesProgram.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesProgram.java index bd7523df0..e377ddf52 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesProgram.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesProgram.java @@ -115,7 +115,7 @@ public Iterator iterator() { .attr("revision", Manifests.read("JEO-Revision")) .attr("dob", Manifests.read("JEO-Dob")) .attr("time", now) - .attr("xsi:noNamespaceSchemaLocation","https://www.eolang.org/xsd/XMIR-0.46.0.xsd") + .attr("xsi:noNamespaceSchemaLocation", "https://www.eolang.org/xsd/XMIR-0.46.0.xsd") .add("listing") .set(this.listing) .up() diff --git a/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java b/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java index 4fc7844ba..cb710fe27 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java @@ -142,8 +142,6 @@ private String name() { */ private Optional annotations() { return this.node.children() -// .filter(o -> o.attribute("name").isPresent()) -// .filter(o -> o.attribute("name").get().startsWith("annotations")) .filter(o -> o.hasAttribute("name", "annotations")) .findFirst() .map(XmlAnnotations::new); diff --git a/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java b/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java index 86bb5ebd9..ecc0b5760 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java @@ -112,24 +112,17 @@ public String text() { * @return Attribute. */ public Optional attribute(final String name) { + Optional result = Optional.empty(); final NamedNodeMap attributes = this.node.getAttributes(); final int length = attributes.getLength(); - for (int index = 0; index < length; index++) { + for (int index = 0; index < length; ++index) { final Node item = attributes.item(index); if (item.getNodeName().startsWith(name)) { - return Optional.of(item.getTextContent()); + result = Optional.of(item.getTextContent()); + break; } } - return Optional.empty(); - -// final Optional result; -// final NamedNodeMap attrs = this.node.getAttributes(); -// if (attrs == null) { -// result = Optional.empty(); -// } else { -// result = Optional.ofNullable(attrs.getNamedItem(name)).map(Node::getTextContent); -// } -// return result; + return result; } /** diff --git a/src/test/java/org/eolang/jeo/representation/XmirRepresentationTest.java b/src/test/java/org/eolang/jeo/representation/XmirRepresentationTest.java index a177877b3..b48762c66 100644 --- a/src/test/java/org/eolang/jeo/representation/XmirRepresentationTest.java +++ b/src/test/java/org/eolang/jeo/representation/XmirRepresentationTest.java @@ -53,6 +53,11 @@ final class XmirRepresentationTest { private static final String MESSAGE = "The bytecode representation of the EO object is not correct,%nexpected:%n%s%nbut got:%n%s"; + /** + * Math class name. + */ + private static final String MATH = "org/eolang/foo/Math"; + @Test void retrievesName() { final String name = "Math"; @@ -80,7 +85,7 @@ void returnsXmlRepresentationOfEo() { "The XML representation of the EO object is not correct", new BytecodeProgram( "org.eolang", - new BytecodeClass("org/eolang/foo/Math") + new BytecodeClass(XmirRepresentationTest.MATH) ).xml(), XhtmlMatchers.hasXPath("/program[@name='j$Math']") ); @@ -139,7 +144,7 @@ void failsToOpenBrokenXmirRepresentationFromFile(@TempDir final Path dir) throws Files.write( xmir, new BytecodeProgram( - new BytecodeClass("org/eolang/foo/Math") + new BytecodeClass(XmirRepresentationTest.MATH) ).xml().toString().substring(42).getBytes(StandardCharsets.UTF_8) ); MatcherAssert.assertThat( @@ -167,7 +172,7 @@ void failsToOpenBrokenXmirRepresentationFromFile(@TempDir final Path dir) throws @SuppressWarnings("PMD.GuardLogStatement") void convertsToXmirAndBack() { final Bytecode before = new BytecodeProgram( - new BytecodeClass("org/eolang/foo/Math") + new BytecodeClass(XmirRepresentationTest.MATH) .helloWorldMethod() ).bytecode(); final int attempts = 500; @@ -202,7 +207,7 @@ void throwsExceptionIfXmirIsInvalid() { () -> new XmirRepresentation( new XMLDocument( new BytecodeProgram( - new BytecodeClass("org/eolang/foo/Math") + new BytecodeClass(XmirRepresentationTest.MATH) ).xml().toString().replace("package", "") ) ).toBytecode() @@ -216,7 +221,7 @@ void throwsExceptionIfXmirIsInvalid() { @Test void createsXmirRepresentationFromFile(@TempDir final Path path) throws IOException { final BytecodeProgram program = new BytecodeProgram( - new BytecodeClass("org/eolang/foo/Math").helloWorldMethod() + new BytecodeClass(XmirRepresentationTest.MATH).helloWorldMethod() ); final Bytecode expected = program.bytecode(); final Path address = path.resolve("Math.xmir"); diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationsTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationsTest.java index 5eed28fdb..0c8946581 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationsTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationsTest.java @@ -24,7 +24,6 @@ package org.eolang.jeo.representation.directives; import com.jcabi.matchers.XhtmlMatchers; -import org.eolang.jeo.matchers.SameXml; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import org.xembly.ImpossibleModificationException; diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassPropertiesTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassPropertiesTest.java index 93fa144d5..1e03a60d3 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassPropertiesTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassPropertiesTest.java @@ -32,7 +32,6 @@ /** * Test case for {@link org.eolang.jeo.representation.directives.DirectivesClassProperties}. - * * @since 0.1.0 */ final class DirectivesClassPropertiesTest { @@ -59,9 +58,7 @@ void createsDirectives() throws ImpossibleModificationException { "/o/o[contains(@base,'org.eolang.string') and contains(@name,'signature')]", "/o/o[contains(@base,'org.eolang.string') and contains(@name,'supername')]", "/o/o[contains(@base,'jeo.seq.of1') and contains(@name,'interfaces')]" - ) ); } - } diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassTest.java index 82789112a..06592c479 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesClassTest.java @@ -25,7 +25,6 @@ import com.jcabi.matchers.XhtmlMatchers; import com.jcabi.xml.XMLDocument; -import org.eolang.jeo.matchers.SameXml; import org.eolang.jeo.representation.ClassName; import org.eolang.jeo.representation.bytecode.BytecodeClass; import org.eolang.jeo.representation.bytecode.BytecodeClassProperties; From ddc26d9cc46cbbe6334e2ffa86a6cadde2e8445f Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Sun, 15 Dec 2024 09:20:53 +0300 Subject: [PATCH 21/30] feat(#939): upgrade eo from 0.46.0 to 0.48.2 --- pom.xml | 2 +- src/it/annotations/pom.xml | 2 +- src/it/bytecode-to-eo/pom.xml | 4 ++-- src/it/custom-transformations/pom.xml | 2 +- src/it/exceptions/pom.xml | 2 +- src/it/generics/pom.xml | 2 +- src/it/jna/pom.xml | 2 +- src/it/phi-unphi/pom.xml | 2 +- src/it/spring/pom.xml | 2 +- src/it/takes/pom.xml | 2 +- .../jeo/representation/directives/DirectivesProgram.java | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index fe7c1bd29..88bdf7321 100644 --- a/pom.xml +++ b/pom.xml @@ -189,7 +189,7 @@ SOFTWARE. org.eolang eo-parser - 0.46.0 + 0.48.2 com.github.volodya-lombrozo diff --git a/src/it/annotations/pom.xml b/src/it/annotations/pom.xml index 0f92361c6..dacc3f0d9 100644 --- a/src/it/annotations/pom.xml +++ b/src/it/annotations/pom.xml @@ -64,7 +64,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.46.0 + 0.48.2 convert-xmir-to-eo diff --git a/src/it/bytecode-to-eo/pom.xml b/src/it/bytecode-to-eo/pom.xml index e0702117a..6aa21ed13 100644 --- a/src/it/bytecode-to-eo/pom.xml +++ b/src/it/bytecode-to-eo/pom.xml @@ -70,7 +70,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.46.0 + 0.48.2 convert-xmir-to-phi @@ -98,7 +98,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.46.0 + 0.48.2 convert-xmir-to-eo diff --git a/src/it/custom-transformations/pom.xml b/src/it/custom-transformations/pom.xml index 73e6290cd..739fca895 100644 --- a/src/it/custom-transformations/pom.xml +++ b/src/it/custom-transformations/pom.xml @@ -64,7 +64,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.46.0 + 0.48.2