Skip to content

Commit

Permalink
feat(#953): simplify code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Dec 27, 2024
1 parent 1274c74 commit 67e79ec
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.nio.file.Path;
import org.eolang.jeo.representation.bytecode.Bytecode;
import org.eolang.jeo.representation.xmir.JcabiXmlDoc;
import org.eolang.jeo.representation.xmir.NativeXmlDoc;
import org.eolang.jeo.representation.xmir.XmlDoc;
import org.eolang.jeo.representation.xmir.XmlNode;
import org.eolang.jeo.representation.xmir.XmlProgram;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ private static XML open(final Path path) {
String.format("Can't find file '%s'", path),
exception
);
} catch (final Exception broken) {
} catch (final RuntimeException broken) {
throw new IllegalStateException(
String.format(
"Can't parse XML from the file '%s'",
"Can't parse Jcabi XML from the file '%s'",
path
),
broken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public final class JcabiXmlNode implements XmlNode {
* Ctor.
* @param xml XML string.
*/
JcabiXmlNode(final String xml) {
this(new XMLDocument(xml).inner().getFirstChild());
JcabiXmlNode(final String... xml) {
this(new XMLDocument(String.join("\n", xml)).inner().getFirstChild());
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public interface XmlNode {
*/
boolean hasAttribute(String name, String value);

/**
* Validate the node.
*/
void validate();

}
26 changes: 2 additions & 24 deletions src/main/java/org/eolang/jeo/representation/xmir/XmlProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@
package org.eolang.jeo.representation.xmir;

import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import org.eolang.jeo.representation.ClassName;
import org.eolang.jeo.representation.PrefixedName;
import org.eolang.jeo.representation.bytecode.BytecodeProgram;
import org.eolang.jeo.representation.directives.DirectivesClass;
import org.eolang.jeo.representation.directives.DirectivesMetas;
import org.eolang.jeo.representation.directives.DirectivesProgram;
import org.xembly.Xembler;

/**
* XMIR Program.
Expand All @@ -49,31 +43,15 @@ public final class XmlProgram {
* @param lines Xmir lines.
*/
public XmlProgram(final String... lines) {
this(new XMLDocument(String.join("\n", lines)));
this(new JcabiXmlNode(lines));
}

/**
* Constructor.
* @param xml Raw XMIR.
*/
public XmlProgram(final XML xml) {
this(new NativeXmlNode(xml.inner().getFirstChild()));
}

/**
* Constructor.
* @param name Class name.
*/
XmlProgram(final ClassName name) {
this(
new XMLDocument(
new Xembler(
new DirectivesProgram(
new DirectivesClass(name), new DirectivesMetas(name)
)
).xmlQuietly()
)
);
this(new JcabiXmlDoc(xml).root());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ void createsFromFile(@TempDir final Path dir) throws IOException {
@Test
void findsFirstChildInFileWithComment(@TempDir final Path dir) throws IOException {
final Path path = dir.resolve("test.xml");
Files.write(path, String.format("<!-- Some comment -->%s", JcabiXmlDocTest.XML)
.getBytes(StandardCharsets.UTF_8));
Files.write(
path,
String.format("<!-- Some comment -->%s", JcabiXmlDocTest.XML)
.getBytes(StandardCharsets.UTF_8)
);
MatcherAssert.assertThat(
"Can't read XML from file",
new JcabiXmlDoc(path).root().firstChild(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.jeo.representation.xmir;

import com.jcabi.xml.XMLDocument;
import org.eolang.jeo.representation.ClassName;
import org.eolang.jeo.representation.bytecode.BytecodeClass;
import org.eolang.jeo.representation.bytecode.BytecodeProgram;
Expand Down Expand Up @@ -51,7 +52,18 @@ void convertsToBytecode() {
final String name = "FooBar";
MatcherAssert.assertThat(
"Can't convert program to bytecode.",
new XmlProgram(new ClassName(pckg, name)).bytecode(),
new XmlProgram(
new XMLDocument(
new Xembler(
new DirectivesProgram(
new DirectivesClass(new ClassName(pckg, name)),
new DirectivesMetas(
new ClassName(pckg, name)
)
)
).xmlQuietly()
)
).bytecode(),
Matchers.equalTo(
new BytecodeProgram(
pckg,
Expand Down

1 comment on commit 67e79ec

@0pdd
Copy link

@0pdd 0pdd commented on 67e79ec Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 948-f592bc18 disappeared from src/main/java/org/eolang/jeo/representation/XmirRepresentation.java), that's why I closed #953. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.