diff --git a/src/main/java/org/eolang/jeo/representation/XmirRepresentation.java b/src/main/java/org/eolang/jeo/representation/XmirRepresentation.java index f19743d0c..aa18ecacd 100644 --- a/src/main/java/org/eolang/jeo/representation/XmirRepresentation.java +++ b/src/main/java/org/eolang/jeo/representation/XmirRepresentation.java @@ -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; diff --git a/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlDoc.java b/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlDoc.java index ed4acb8fb..5408d603f 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlDoc.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlDoc.java @@ -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 diff --git a/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlNode.java b/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlNode.java index 5addca3da..0e9d79102 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlNode.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlNode.java @@ -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()); } /** 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 5cb7c0a9e..2953a656a 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlNode.java @@ -100,6 +100,9 @@ public interface XmlNode { */ boolean hasAttribute(String name, String value); + /** + * Validate the node. + */ void validate(); } diff --git a/src/main/java/org/eolang/jeo/representation/xmir/XmlProgram.java b/src/main/java/org/eolang/jeo/representation/xmir/XmlProgram.java index 6d5a27d44..cce0b24fc 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlProgram.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlProgram.java @@ -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. @@ -49,7 +43,7 @@ public final class XmlProgram { * @param lines Xmir lines. */ public XmlProgram(final String... lines) { - this(new XMLDocument(String.join("\n", lines))); + this(new JcabiXmlNode(lines)); } /** @@ -57,23 +51,7 @@ public XmlProgram(final String... lines) { * @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()); } /** diff --git a/src/test/java/org/eolang/jeo/representation/xmir/JcabiXmlDocTest.java b/src/test/java/org/eolang/jeo/representation/xmir/JcabiXmlDocTest.java index c5438f383..6ebcdf8f1 100644 --- a/src/test/java/org/eolang/jeo/representation/xmir/JcabiXmlDocTest.java +++ b/src/test/java/org/eolang/jeo/representation/xmir/JcabiXmlDocTest.java @@ -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("%s", JcabiXmlDocTest.XML) - .getBytes(StandardCharsets.UTF_8)); + Files.write( + path, + String.format("%s", JcabiXmlDocTest.XML) + .getBytes(StandardCharsets.UTF_8) + ); MatcherAssert.assertThat( "Can't read XML from file", new JcabiXmlDoc(path).root().firstChild(), diff --git a/src/test/java/org/eolang/jeo/representation/xmir/XmlProgramTest.java b/src/test/java/org/eolang/jeo/representation/xmir/XmlProgramTest.java index 836340720..9dd6717c9 100644 --- a/src/test/java/org/eolang/jeo/representation/xmir/XmlProgramTest.java +++ b/src/test/java/org/eolang/jeo/representation/xmir/XmlProgramTest.java @@ -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; @@ -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,