diff --git a/src/it/annotations/README.md b/src/it/annotations/README.md index 44031f678..755541a99 100644 --- a/src/it/annotations/README.md +++ b/src/it/annotations/README.md @@ -5,5 +5,5 @@ The integration test verifies that the program can run successfully, and the jeo If you only need to run this test, use the following command: ```shell -mvn clean integration-test invoker:run -Dinvoker.test=annotations -DskipTests +mvn clean integration-test -Dinvoker.test=annotations -DskipTests ``` \ No newline at end of file diff --git a/src/it/annotations/pom.xml b/src/it/annotations/pom.xml index 4c2b67a22..e380f6d45 100644 --- a/src/it/annotations/pom.xml +++ b/src/it/annotations/pom.xml @@ -63,7 +63,7 @@ SOFTWARE. org.eolang eo-maven-plugin - 0.38.1 + 0.38.4 convert-xmir-to-eo @@ -72,7 +72,6 @@ SOFTWARE. xmir-to-phi - false ${project.build.directory}/generated-sources/jeo-xmir ${project.build.directory}/generated-sources/jeo-eo diff --git a/src/it/spring/pom.xml b/src/it/spring/pom.xml index 9f9f15fda..a9f5d30c8 100644 --- a/src/it/spring/pom.xml +++ b/src/it/spring/pom.xml @@ -66,7 +66,7 @@ SOFTWARE. bytecode-to-eo - process-classes + process-classes disassemble @@ -80,24 +80,24 @@ SOFTWARE. - - org.eolang - eo-maven-plugin - 0.38.4 - - - convert-xmir-to-phi - process-classes - - xmir-to-phi - - - ${project.build.directory}/generated-sources/jeo-xmir - ${project.build.directory}/generated-sources/phi-jeo - - - - + + org.eolang + eo-maven-plugin + 0.38.4 + + + convert-xmir-to-phi + process-classes + + xmir-to-phi + + + ${project.build.directory}/generated-sources/jeo-xmir + ${project.build.directory}/generated-sources/phi-jeo + + + + org.springframework.boot spring-boot-maven-plugin diff --git a/src/main/java/org/eolang/jeo/representation/xmir/XmlAnnotationProperty.java b/src/main/java/org/eolang/jeo/representation/xmir/XmlAnnotationProperty.java index e247e65ad..1f64033a1 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlAnnotationProperty.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlAnnotationProperty.java @@ -51,14 +51,28 @@ public XmlAnnotationProperty(final XmlNode node) { * @return Bytecode annotation property. */ public BytecodeAnnotationProperty toBytecode() { - final List all = this.node.children().collect(Collectors.toList()); - return BytecodeAnnotationProperty.byType( - (String) new XmlOperand(all.get(0)).asObject(), - all.subList(1, all.size()) - .stream() - .map(XmlOperand::new) - .map(XmlOperand::asObject) - .collect(Collectors.toList()) - ); + return BytecodeAnnotationProperty.byType(this.type(), this.params()); } -} + + /** + * Type of the property. + * @return Type. + */ + public String type() { + return (String) new XmlOperand( + this.node.children().collect(Collectors.toList()).get(0) + ).asObject(); + } + + /** + * Property parameters. + * @return Parameters. + */ + public List params() { + return this.node.children() + .skip(1) + .map(XmlOperand::new) + .map(XmlOperand::asObject) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationPropertyTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationPropertyTest.java index 135b86ebf..c56253b80 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationPropertyTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesAnnotationPropertyTest.java @@ -24,8 +24,13 @@ package org.eolang.jeo.representation.directives; import com.jcabi.matchers.XhtmlMatchers; +import java.util.List; import org.eolang.jeo.representation.DataType; +import org.eolang.jeo.representation.bytecode.BytecodeAnnotation; +import org.eolang.jeo.representation.xmir.XmlAnnotationProperty; +import org.eolang.jeo.representation.xmir.XmlNode; import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import org.objectweb.asm.Type; import org.xembly.ImpossibleModificationException; @@ -102,4 +107,136 @@ void createsAnnotationProperty() throws ImpossibleModificationException { ) ); } + + @Test + void createsAnnotationPlainProperty() throws ImpossibleModificationException { + final String name = "hello"; + final int value = 1; + final XmlAnnotationProperty property = new XmlAnnotationProperty( + new XmlNode( + new Xembler(DirectivesAnnotationProperty.plain(name, value)).xml() + ) + ); + final List params = property.params(); + MatcherAssert.assertThat( + "Incorrect annotation property type", + property.type(), + Matchers.equalTo("PLAIN") + ); + MatcherAssert.assertThat( + "Incorrect annotation property name", + params.get(0), + Matchers.equalTo(name) + ); + MatcherAssert.assertThat( + "Incorrect annotation property value", + params.get(1), + Matchers.equalTo(value) + ); + } + + @Test + void createsAnnotationEnumProperty() throws ImpossibleModificationException { + final String name = "name"; + final String descriptor = "Lorg/eolang/jeo/representation/DataType"; + final String value = "BOOL"; + final XmlAnnotationProperty property = new XmlAnnotationProperty( + new XmlNode( + new Xembler(DirectivesAnnotationProperty.enump(name, descriptor, value)).xml() + ) + ); + final List params = property.params(); + MatcherAssert.assertThat( + "Incorrect annotation property type", + property.type(), + Matchers.equalTo("ENUM") + ); + MatcherAssert.assertThat( + "Incorrect annotation property name", + params.get(0), + Matchers.equalTo(name) + ); + MatcherAssert.assertThat( + "Incorrect annotation property descriptor", + params.get(1), + Matchers.equalTo(descriptor) + ); + MatcherAssert.assertThat( + "Incorrect annotation property value", + params.get(2), + Matchers.equalTo(value) + ); + } + + @Test + void createsAnnotationArrayProperty() throws ImpossibleModificationException { + final String name = "name"; + final String descriptor = "java/lang/Override"; + final boolean visible = true; + final XmlAnnotationProperty property = new XmlAnnotationProperty( + new XmlNode( + new Xembler( + DirectivesAnnotationProperty.array( + name, + new DirectivesAnnotation(descriptor, visible) + ) + ).xml() + ) + ); + final List params = property.params(); + MatcherAssert.assertThat( + "Incorrect annotation property type", + property.type(), + Matchers.equalTo("ARRAY") + ); + MatcherAssert.assertThat( + "Incorrect annotation property name", + params.get(0), + Matchers.equalTo(name) + ); + MatcherAssert.assertThat( + "Incorrect annotation property child", + (BytecodeAnnotation) params.get(1), + Matchers.equalTo(new BytecodeAnnotation(descriptor, visible)) + ); + } + + @Test + void createsAnnotationAnnotationProperty() throws ImpossibleModificationException { + final String name = "name"; + final String descriptor = "java/lang/Override"; + final boolean visible = true; + final XmlAnnotationProperty property = new XmlAnnotationProperty( + new XmlNode( + new Xembler( + DirectivesAnnotationProperty.annotation( + name, + descriptor, + new DirectivesAnnotation(descriptor, visible) + ) + ).xml() + ) + ); + final List params = property.params(); + MatcherAssert.assertThat( + "Incorrect annotation property type", + property.type(), + Matchers.equalTo("ANNOTATION") + ); + MatcherAssert.assertThat( + "Incorrect annotation property name", + params.get(0), + Matchers.equalTo(name) + ); + MatcherAssert.assertThat( + "Incorrect annotation property descriptor", + params.get(1), + Matchers.equalTo(descriptor) + ); + MatcherAssert.assertThat( + "Incorrect annotation property child", + (BytecodeAnnotation) params.get(2), + Matchers.equalTo(new BytecodeAnnotation(descriptor, visible)) + ); + } }