Skip to content

Commit

Permalink
feat(objectionary#528): move all writers under CustomClassWriter class
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Apr 3, 2024
1 parent 64f5331 commit 92758fa
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.eolang.jeo.representation.BytecodeRepresentation;
import org.eolang.jeo.representation.xmir.XmlAnnotations;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.util.CheckClassAdapter;

Expand All @@ -54,7 +53,7 @@ public final class BytecodeClass implements Testable {
* Class writer.
*/
@ToString.Exclude
private final CustomClassVisitor visitor;
private final CustomClassWriter visitor;

/**
* Methods.
Expand Down Expand Up @@ -128,16 +127,7 @@ public BytecodeClass(
final BytecodeClassProperties properties,
final boolean verify
) {
this(name, BytecodeClass.writer(verify, false), new ArrayList<>(0), properties);
}

public BytecodeClass(
final String name,
final BytecodeClassProperties properties,
final boolean verify,
final boolean frames
) {
this(name, BytecodeClass.writer(verify, frames), new ArrayList<>(0), properties);
this(name, new CustomClassWriter(verify), new ArrayList<>(0), properties);
}

/**
Expand All @@ -151,7 +141,7 @@ public BytecodeClass(
*/
public BytecodeClass(
final String name,
final CustomClassVisitor writer,
final CustomClassWriter writer,
final Collection<BytecodeMethod> methods,
final BytecodeClassProperties properties
) {
Expand Down Expand Up @@ -383,25 +373,4 @@ public BytecodeClass helloWorldMethod() {
.opcode(Opcodes.RETURN)
.up();
}

/**
* Which class writer to use.
* @param verify Verify bytecode.
* @return Verified class writer if verify is true, otherwise custom class writer.
*/
private static CustomClassVisitor writer(final boolean verify, final boolean frames) {
final CustomClassWriter result;
final int flags;
if (frames) {
flags = ClassWriter.COMPUTE_FRAMES;
} else {
flags = 0;
}
if (verify) {
result = new VerifiedClassWriter(flags);
} else {
result = new CustomClassWriter(flags);
}
return new CustomClassVisitor(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class BytecodeMethod implements Testable {
/**
* ASM class visitor.
*/
private final CustomClassVisitor visitor;
private final CustomClassWriter visitor;

/**
* Original class.
Expand Down Expand Up @@ -91,7 +91,7 @@ public final class BytecodeMethod implements Testable {
*/
BytecodeMethod(
final String name,
final CustomClassVisitor visitor,
final CustomClassWriter visitor,
final BytecodeClass clazz,
final String descriptor,
final int... modifiers
Expand All @@ -107,7 +107,7 @@ public final class BytecodeMethod implements Testable {
*/
BytecodeMethod(
final BytecodeMethodProperties properties,
final CustomClassVisitor visitor,
final CustomClassWriter visitor,
final BytecodeClass clazz
) {
this(properties, visitor, clazz, 0, 0);
Expand All @@ -124,7 +124,7 @@ public final class BytecodeMethod implements Testable {
*/
public BytecodeMethod(
final BytecodeMethodProperties properties,
final CustomClassVisitor visitor,
final CustomClassWriter visitor,
final BytecodeClass clazz,
final int stack,
final int locals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean isAbstract() {
* @param writer Class writer.
* @return Method visitor.
*/
MethodVisitor writeMethod(final CustomClassVisitor writer, final boolean compute) {
MethodVisitor writeMethod(final CustomClassWriter writer, final boolean compute) {
Logger.debug(
this,
String.format("Creating method visitor with the following properties %s", this)
Expand Down

This file was deleted.

Loading

0 comments on commit 92758fa

Please sign in to comment.