Skip to content

Commit

Permalink
feat(#939): catch only XMIR errors instead of all the warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Dec 10, 2024
1 parent 86f03be commit f575475
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ SOFTWARE.
<dependency>
<groupId>org.eolang</groupId>
<artifactId>lints</artifactId>
<version>0.0.21</version>
<version>0.0.22</version>
</dependency>
<dependency>
<groupId>org.cactoos</groupId>
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/eolang/jeo/representation/VerifiedEo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,12 +67,14 @@ XML asXml() throws ImpossibleModificationException {
try {
final Collection<Defect> 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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +37,8 @@
*/
public final class DirectivesClassProperties implements Iterable<Directive> {

private static final Random RANDOM = new SecureRandom();

/**
* Class bytecode version.
*/
Expand Down Expand Up @@ -126,18 +130,28 @@ public DirectivesClassProperties(

@Override
public Iterator<Directive> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +40,8 @@
*/
public final class DirectivesJeoObject implements Iterable<Directive> {

private final static Random RANDOM = new SecureRandom();

/**
* The base of the object.
*/
Expand Down Expand Up @@ -118,10 +122,11 @@ public DirectivesJeoObject(final String base, final String name, final List<Dire

@Override
public Iterator<Directive> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -32,6 +34,8 @@
*/
public final class DirectivesMaxs implements Iterable<Directive> {

private static final Random RANDOM = new SecureRandom();

/**
* Max stack size.
*/
Expand Down Expand Up @@ -62,10 +66,11 @@ public DirectivesMaxs(final int stack, final int locals) {

@Override
public Iterator<Directive> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public DirectivesMetas(
@Override
public Iterator<Directive> 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();
}

Expand Down Expand Up @@ -136,10 +136,22 @@ private Set<String> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +38,8 @@
*/
public final class DirectivesMethodProperties implements Iterable<Directive> {

private static final Random RANDOM = new SecureRandom();

/**
* Method access modifiers.
*/
Expand Down Expand Up @@ -125,11 +129,12 @@ public DirectivesMethodProperties(

@Override
public Iterator<Directive> 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();
Expand Down

0 comments on commit f575475

Please sign in to comment.