diff --git a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethod.java b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethod.java index ff7604f66..88a6a23ed 100644 --- a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethod.java +++ b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethod.java @@ -242,30 +242,19 @@ public String testCode() { @SuppressWarnings("PMD.AvoidCatchingGenericException") void write() { try { - if (this.stack == 0 && this.locals == 0) { - final MethodVisitor mvisitor = this.properties.writeCustomMethodWithComputation( - this.visitor); - this.annotations.forEach(annotation -> annotation.write(mvisitor)); - this.defvalues.forEach(defvalue -> defvalue.writeTo(mvisitor)); - if (!this.properties.isAbstract()) { - mvisitor.visitCode(); - this.tryblocks.forEach(block -> block.writeTo(mvisitor)); - this.instructions.forEach(instruction -> instruction.writeTo(mvisitor)); - mvisitor.visitMaxs(this.stack, this.locals); - } - mvisitor.visitEnd(); - } else { - final MethodVisitor mvisitor = this.properties.writeMethod(this.visitor); - this.annotations.forEach(annotation -> annotation.write(mvisitor)); - this.defvalues.forEach(defvalue -> defvalue.writeTo(mvisitor)); - if (!this.properties.isAbstract()) { - mvisitor.visitCode(); - this.tryblocks.forEach(block -> block.writeTo(mvisitor)); - this.instructions.forEach(instruction -> instruction.writeTo(mvisitor)); - mvisitor.visitMaxs(this.stack, this.locals); - } - mvisitor.visitEnd(); + final MethodVisitor mvisitor = this.properties.writeMethod( + this.visitor, + this.stack == 0 && this.locals == 0 + ); + this.annotations.forEach(annotation -> annotation.write(mvisitor)); + this.defvalues.forEach(defvalue -> defvalue.writeTo(mvisitor)); + if (!this.properties.isAbstract()) { + mvisitor.visitCode(); + this.tryblocks.forEach(block -> block.writeTo(mvisitor)); + this.instructions.forEach(instruction -> instruction.writeTo(mvisitor)); + mvisitor.visitMaxs(this.stack, this.locals); } + mvisitor.visitEnd(); } catch (final NegativeArraySizeException exception) { throw new IllegalStateException( String.format( diff --git a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethodProperties.java b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethodProperties.java index 71fa54b52..697ab7c6d 100644 --- a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethodProperties.java +++ b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethodProperties.java @@ -132,32 +132,12 @@ public boolean isAbstract() { return (this.access & Opcodes.ACC_ABSTRACT) != 0; } - - /** - * Add method to class writer. - * @param writer Class writer. - * @return Method visitor. - */ - MethodVisitor writeCustomMethodWithComputation(final CustomClassVisitor writer) { - Logger.debug( - this, - String.format("Creating method visitor with the following properties %s", this) - ); - return writer.visitCustomMethodWithComputation( - this.access, - new JavaName(this.name).decode(), - this.descriptor, - this.signature, - this.exceptions - ); - } - /** * Add method to class writer. * @param writer Class writer. * @return Method visitor. */ - MethodVisitor writeMethod(final CustomClassVisitor writer) { + MethodVisitor writeMethod(final CustomClassVisitor writer, final boolean compute) { Logger.debug( this, String.format("Creating method visitor with the following properties %s", this) @@ -167,7 +147,8 @@ MethodVisitor writeMethod(final CustomClassVisitor writer) { new JavaName(this.name).decode(), this.descriptor, this.signature, - this.exceptions + this.exceptions, + compute ); } } diff --git a/src/main/java/org/eolang/jeo/representation/bytecode/CustomClassVisitor.java b/src/main/java/org/eolang/jeo/representation/bytecode/CustomClassVisitor.java index de5de719c..3730953a5 100644 --- a/src/main/java/org/eolang/jeo/representation/bytecode/CustomClassVisitor.java +++ b/src/main/java/org/eolang/jeo/representation/bytecode/CustomClassVisitor.java @@ -21,7 +21,26 @@ public CustomClassVisitor(final int api, final CustomClassWriter writer) { this.writer = writer; } - public MethodVisitor visitCustomMethodWithComputation( + public MethodVisitor visitMethod( + final int access, + final String name, + final String descriptor, + final String signature, + final String[] exceptions, + final boolean compute + ) { + MethodVisitor result; + if (compute) { + result = this.visitCustomMethodWithComputation( + access, name, descriptor, signature, exceptions + ); + } else { + result = super.visitMethod(access, name, descriptor, signature, exceptions); + } + return result; + } + + private MethodVisitor visitCustomMethodWithComputation( final int access, final String name, final String descriptor, 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 80ba8cbe1..bd2e719ff 100644 --- a/src/main/java/org/eolang/jeo/representation/bytecode/VerifiedClassWriter.java +++ b/src/main/java/org/eolang/jeo/representation/bytecode/VerifiedClassWriter.java @@ -43,13 +43,6 @@ */ public final class VerifiedClassWriter extends CustomClassWriter { - /** - * Default constructor. - */ - public VerifiedClassWriter() { - this(ClassWriter.COMPUTE_FRAMES); - } - /** * Constructor. * @param flags Flags. See {@link ClassWriter#COMPUTE_FRAMES} for more info.