Class BytecodeClass
java.lang.Object
org.eolang.jeo.representation.bytecode.BytecodeClass
- All Implemented Interfaces:
Testable
Class useful for generating bytecode for testing purposes.
- Since:
- 0.1.0
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.BytecodeClass
(String name) Constructor.BytecodeClass
(String name, int access) Constructor.BytecodeClass
(String name, BytecodeClassProperties properties) Constructor.BytecodeClass
(String name, BytecodeClassProperties properties, boolean verify) Constructor.BytecodeClass
(String name, CustomClassWriter writer, Collection<BytecodeMethod> methods, BytecodeClassProperties properties) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbytecode()
Generate bytecode.Hello world bytecode.testCode()
Generate test Java code.Add anns.withAttribute
(BytecodeAttribute attribute) Add attribute.withConstructor
(int... modifiers) Add constructor.withConstructor
(String descriptor, int... modifiers) Add constructor.Add field.Add field.withMethod
(String mname, String descriptor, int... modifiers) Add method.withMethod
(BytecodeMethodProperties properties) Add method.withMethod
(BytecodeMethodProperties properties, int stack, int locals) Add method.com.jcabi.xml.XML
xml()
Converts bytecode into XML.
-
Constructor Details
-
BytecodeClass
public BytecodeClass()Constructor. Used in tests only. -
BytecodeClass
Constructor. Used in tests only.- Parameters:
name
- Class name.
-
BytecodeClass
Constructor. Used in tests only.- Parameters:
name
- Class name.access
- Access modifiers.
-
BytecodeClass
Constructor. Used in tests only.- Parameters:
name
- Class name.properties
- Class properties.
-
BytecodeClass
Constructor. Has real usages.- Parameters:
name
- Class name.properties
- Class properties.verify
- Verify bytecode.
-
BytecodeClass
public BytecodeClass(String name, CustomClassWriter writer, Collection<BytecodeMethod> methods, BytecodeClassProperties properties) Constructor.- Parameters:
name
- Class name.writer
- ASM class writer.methods
- Methods.properties
- Class properties.
-
-
Method Details
-
xml
public com.jcabi.xml.XML xml()Converts bytecode into XML.- Returns:
- XML representation of bytecode.
-
bytecode
Generate bytecode.In this method we intentionally use the Thread.currentThread().getContextClassLoader() for the class loader of the
CheckClassAdapter.verify(ClassReader, ClassLoader, boolean, PrintWriter)
instead of default implementation. This is because the default class loader doesn't know about classes compiled on the previous maven step. You can read more about the problem here:PluginStartup.init()
()}- Returns:
- Bytecode.
-
withConstructor
Add constructor.- Parameters:
modifiers
- Constructor modifiers.- Returns:
- This object.
-
withMethod
Add method.- Parameters:
properties
- Method properties.- Returns:
- This object.
-
withMethod
Add method.- Parameters:
properties
- Method properties.stack
- Stack size.locals
- Local variables size.- Returns:
- This object.
-
withConstructor
Add constructor.- Parameters:
descriptor
- Constructor descriptor.modifiers
- Constructor modifiers.- Returns:
- This object.
-
withMethod
Add method.- Parameters:
mname
- Method name.descriptor
- Method descriptor.modifiers
- Access modifiers.- Returns:
- This object.
-
withField
Add field.- Parameters:
fname
- Field name.- Returns:
- This object.
-
withAttribute
Add attribute.- Parameters:
attribute
- Attribute.- Returns:
- This object.
-
withField
public BytecodeField withField(String fname, String descriptor, String signature, Object value, int... modifiers) Add field.- Parameters:
fname
- Field name.descriptor
- Field descriptor.signature
- Field signature.value
- Field value.modifiers
- Access modifiers.- Returns:
- This object.
-
withAnnotations
Add anns.- Parameters:
all
- Annotations.- Returns:
- This object.
-
testCode
Description copied from interface:Testable
Generate test Java code. -
helloWorldMethod
Hello world bytecode.- Returns:
- The same class with the hello world method.
-