From d9dd9a4789e1bd7b0d0383ac9f74ae53c9ae1bcf Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 14 Mar 2024 18:28:29 +0300 Subject: [PATCH 1/4] feat(#488): identify problem with loop and and swich statement intersection inside 'spring-fat' integration test --- .../java/org/eolang/innerclasses/Top.java | 44 +++++++++++++++++++ .../eolang/spring/SwitchInsideLoopCase.java | 40 +++++++++++++++++ .../java/org/eolang/spring/package-info.java | 29 ++++++++++++ src/it/spring-fat/pom.xml | 3 +- .../bytecode/VerifiedClassWriter.java | 2 +- 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 src/it/custom-transformations/src/main/java/org/eolang/innerclasses/Top.java create mode 100644 src/it/custom-transformations/src/main/java/org/eolang/spring/SwitchInsideLoopCase.java create mode 100644 src/it/custom-transformations/src/main/java/org/eolang/spring/package-info.java diff --git a/src/it/custom-transformations/src/main/java/org/eolang/innerclasses/Top.java b/src/it/custom-transformations/src/main/java/org/eolang/innerclasses/Top.java new file mode 100644 index 000000000..a38f7225b --- /dev/null +++ b/src/it/custom-transformations/src/main/java/org/eolang/innerclasses/Top.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.innerclasses; + +public class Top { + + public void print() { + new TopInnerStatic().print(); + this.new TopInnerInstance().print(); + } + + private static class TopInnerStatic { + public void print() { + System.out.println("TopInnerStatic"); + } + } + + private class TopInnerInstance { + public void print() { + System.out.println("TopInnerInstance"); + } + } +} \ No newline at end of file diff --git a/src/it/custom-transformations/src/main/java/org/eolang/spring/SwitchInsideLoopCase.java b/src/it/custom-transformations/src/main/java/org/eolang/spring/SwitchInsideLoopCase.java new file mode 100644 index 000000000..825e20dac --- /dev/null +++ b/src/it/custom-transformations/src/main/java/org/eolang/spring/SwitchInsideLoopCase.java @@ -0,0 +1,40 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.spring; + +public class SwitchInsideLoopCase { + + public int justSwithcCase(byte x) { + for (int i = 0; i < 10; ++i) { + switch (x) { + case 1: + break; + default: + throw new IllegalArgumentException("Unexpected value: " + x); + } + } + return 2; + } + +} \ No newline at end of file diff --git a/src/it/custom-transformations/src/main/java/org/eolang/spring/package-info.java b/src/it/custom-transformations/src/main/java/org/eolang/spring/package-info.java new file mode 100644 index 000000000..9ba1a91b1 --- /dev/null +++ b/src/it/custom-transformations/src/main/java/org/eolang/spring/package-info.java @@ -0,0 +1,29 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/** + * This package contains all the cases that accidentaly broke `spring-fat` integration test. + * So, all the identified cases are placed here. + * @since 0.3 + */ +package org.eolang.spring; diff --git a/src/it/spring-fat/pom.xml b/src/it/spring-fat/pom.xml index f512d15a0..9160719c3 100644 --- a/src/it/spring-fat/pom.xml +++ b/src/it/spring-fat/pom.xml @@ -90,7 +90,8 @@ SOFTWARE. support many java features. We need to implement them and enable the test. --> - true + false + true diff --git a/src/main/java/org/eolang/jeo/representation/bytecode/VerifiedClassWriter.java b/src/main/java/org/eolang/jeo/representation/bytecode/VerifiedClassWriter.java index 1ab9bb835..9c0b052e5 100644 --- a/src/main/java/org/eolang/jeo/representation/bytecode/VerifiedClassWriter.java +++ b/src/main/java/org/eolang/jeo/representation/bytecode/VerifiedClassWriter.java @@ -71,7 +71,7 @@ private static void verify(final byte[] bytes) { ); verifier.setClassLoader(Thread.currentThread().getContextClassLoader()); new Analyzer<>(verifier).analyze(clazz.name, method); - } catch (final AnalyzerException exception) { + } catch (final ClassFormatError | AnalyzerException exception) { throw new IllegalStateException( String.format( "Bytecode verification failed for the class '%s' and method '%s'", From fd141ad0d109565c4d0b3711d74be25b578afa49 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 14 Mar 2024 18:47:51 +0300 Subject: [PATCH 2/4] feat(#488): identify the problem --- .../eolang/spring/SwitchInsideLoopCase.java | 2 +- .../directives/DirectivesMethodVisitor.java | 49 ++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/it/custom-transformations/src/main/java/org/eolang/spring/SwitchInsideLoopCase.java b/src/it/custom-transformations/src/main/java/org/eolang/spring/SwitchInsideLoopCase.java index 825e20dac..7aadb4aae 100644 --- a/src/it/custom-transformations/src/main/java/org/eolang/spring/SwitchInsideLoopCase.java +++ b/src/it/custom-transformations/src/main/java/org/eolang/spring/SwitchInsideLoopCase.java @@ -25,7 +25,7 @@ public class SwitchInsideLoopCase { - public int justSwithcCase(byte x) { + public int example(byte x) { for (int i = 0; i < 10; ++i) { switch (x) { case 1: diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java index b835c00d3..fc0fce29a 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java @@ -26,6 +26,7 @@ import java.util.Iterator; import org.eolang.jeo.representation.DefaultVersion; import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Attribute; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -42,6 +43,13 @@ * Probably in this issue you will need to add some additional * parsing logic. * See {@link #visitInvokeDynamicInsn} method. + * @todo #488:90min Implement the rest of instruction mappings to XMIR directives. + * Currently we left several instructions unimplemented: + * {@link #visitLookupSwitchInsn}, + * {@link #visitTableSwitchInsn}, + * {@link #visitMultiANewArrayInsn}, + * {@link #visitIincInsn}. + * We need to implement them and add tests for them. */ @SuppressWarnings("PMD.TooManyMethods") public final class DirectivesMethodVisitor extends MethodVisitor implements Iterable { @@ -156,8 +164,25 @@ public void visitTryCatchBlock( } @Override - public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { - return super.visitAnnotation(descriptor, visible); + public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) { + super.visitLookupSwitchInsn(dflt, keys, labels); + } + + @Override + public void visitTableSwitchInsn( + final int min, final int max, final Label dflt, final Label... labels + ) { + super.visitTableSwitchInsn(min, max, dflt, labels); + } + + @Override + public void visitMultiANewArrayInsn(final String descriptor, final int numDimensions) { + super.visitMultiANewArrayInsn(descriptor, numDimensions); + } + + @Override + public void visitIincInsn(final int varIndex, final int increment) { + super.visitIincInsn(varIndex, increment); } @Override @@ -165,6 +190,26 @@ public Iterator iterator() { return this.method.iterator(); } + @Override + public void visitMaxs(final int maxStack, final int maxLocals) { + super.visitMaxs(maxStack, maxLocals); + } + + @Override + public void visitParameter(final String name, final int access) { + super.visitParameter(name, access); + } + + @Override + public void visitAttribute(final Attribute attribute) { + super.visitAttribute(attribute); + } + + @Override + public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { + return super.visitAnnotation(descriptor, visible); + } + /** * Add opcode to the directives. * @param opcode Opcode From fbb458ff05f52710099dfcd34e1ce0404fa688a1 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 14 Mar 2024 19:00:13 +0300 Subject: [PATCH 3/4] feat(#488): disable failing integration tests --- pom.xml | 8 ++++++++ src/it/spring-fat/pom.xml | 2 +- .../directives/DirectivesMethodVisitor.java | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7d2f28c63..87d3c7362 100644 --- a/pom.xml +++ b/pom.xml @@ -244,6 +244,14 @@ SOFTWARE. + + maven-invoker-plugin + + + custom-transformations/pom.xml + + + diff --git a/src/it/spring-fat/pom.xml b/src/it/spring-fat/pom.xml index 9160719c3..5c5709794 100644 --- a/src/it/spring-fat/pom.xml +++ b/src/it/spring-fat/pom.xml @@ -90,7 +90,7 @@ SOFTWARE. support many java features. We need to implement them and enable the test. --> - false + true true diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java index fc0fce29a..2b5e15b9e 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java @@ -50,6 +50,7 @@ * {@link #visitMultiANewArrayInsn}, * {@link #visitIincInsn}. * We need to implement them and add tests for them. + * Don't forget to enable 'custom-transformations' integration test. */ @SuppressWarnings("PMD.TooManyMethods") public final class DirectivesMethodVisitor extends MethodVisitor implements Iterable { From 5507c2ef7329b0f25574825c111ce40a65bc0ab9 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 14 Mar 2024 19:02:30 +0300 Subject: [PATCH 4/4] feat(#488): remove redundant method implementations --- .../directives/DirectivesMethodVisitor.java | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java index 2b5e15b9e..3ee3660d2 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMethodVisitor.java @@ -25,8 +25,6 @@ import java.util.Iterator; import org.eolang.jeo.representation.DefaultVersion; -import org.objectweb.asm.AnnotationVisitor; -import org.objectweb.asm.Attribute; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -164,53 +162,11 @@ public void visitTryCatchBlock( super.visitTryCatchBlock(start, end, handler, type); } - @Override - public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) { - super.visitLookupSwitchInsn(dflt, keys, labels); - } - - @Override - public void visitTableSwitchInsn( - final int min, final int max, final Label dflt, final Label... labels - ) { - super.visitTableSwitchInsn(min, max, dflt, labels); - } - - @Override - public void visitMultiANewArrayInsn(final String descriptor, final int numDimensions) { - super.visitMultiANewArrayInsn(descriptor, numDimensions); - } - - @Override - public void visitIincInsn(final int varIndex, final int increment) { - super.visitIincInsn(varIndex, increment); - } - @Override public Iterator iterator() { return this.method.iterator(); } - @Override - public void visitMaxs(final int maxStack, final int maxLocals) { - super.visitMaxs(maxStack, maxLocals); - } - - @Override - public void visitParameter(final String name, final int access) { - super.visitParameter(name, access); - } - - @Override - public void visitAttribute(final Attribute attribute) { - super.visitAttribute(attribute); - } - - @Override - public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { - return super.visitAnnotation(descriptor, visible); - } - /** * Add opcode to the directives. * @param opcode Opcode