From f575475ccb16e3979f824b25cc81ace58cacc432 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Tue, 10 Dec 2024 15:23:49 +0300 Subject: [PATCH] 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();