public class ByteCodeHelper
extends java.lang.Object
edit(CtClass, Class) method.| Constructor and Description |
|---|
ByteCodeHelper(com.github.randomcodeorg.ppplugin.PContext context)
Creates a new
ByteCodeHelper using the given context. |
| Modifier and Type | Method and Description |
|---|---|
void |
commit()
The same as
ByteCodeHelper#commit(true). |
void |
commit(boolean continueOnException)
Compiles the changes and applies them to the corresponding .class-files.
|
boolean |
edit(javassist.CtClass cl,
java.lang.Class<?> runtimeClass)
Marks the given class as edited.
|
static javassist.CtMethod |
findMethod(javassist.CtClass clazz,
java.lang.reflect.Method m)
Finds the
Method corresponding to the given javassist CtMethod. |
javassist.ClassPool |
getClassPool()
Returns the javassist
ClassPool used by this instance. |
javassist.CtField |
getOrCreateField(javassist.CtClass ctClass,
java.lang.String typeName,
java.lang.String fieldPrefix,
java.lang.String visibility,
boolean isStatic,
boolean isFinal,
java.lang.String initValue)
Returns a existing field or creates one.
|
void |
releaseResources()
Releases the resources of created by this instance.
|
public ByteCodeHelper(com.github.randomcodeorg.ppplugin.PContext context)
ByteCodeHelper using the given context.context - The context to be used by this ByteCodeHelper.public static javassist.CtMethod findMethod(javassist.CtClass clazz,
java.lang.reflect.Method m)
Method corresponding to the given javassist CtMethod.clazz - The CtClass that contains the CtMethod.m - The reflection Method thats corresponding CtMethod should be returned.CtMethod with the same name and input parameters as the given reflection Method.public javassist.ClassPool getClassPool()
throws javassist.NotFoundException
ClassPool used by this instance.ClassPool used by this instance.javassist.NotFoundException - If the class pool could not be created.public boolean edit(javassist.CtClass cl,
java.lang.Class<?> runtimeClass)
throws java.lang.IllegalStateException
Marks the given class as edited. A future call to commit() will compile and save the changes of this class.
Note: Some processors in this project (AbstractClassModificationProcessor, AbstractLoggingProcessor, ...) will call the commit() method automatically.
cl - The CtClass to edit.runtimeClass - The corresponding reflection Class.false if the given class is already marked as edited.java.lang.IllegalStateException - Is thrown if there is no ClassPool for this instance. See getClassPool().public javassist.CtField getOrCreateField(javassist.CtClass ctClass,
java.lang.String typeName,
java.lang.String fieldPrefix,
java.lang.String visibility,
boolean isStatic,
boolean isFinal,
java.lang.String initValue)
throws javassist.CannotCompileException
Returns a existing field or creates one.
Note: This method will not call edit(CtClass, Class). One should do this himself.
ctClass - The CtClass that contains the field.typeName - A string containing the canonical type of the field to return.fieldPrefix - The prefix of the fields name.visibility - The visibility of the field (public, private, protected).isStatic - true if the field is static.isFinal - true if the field is final.initValue - The initial value of the field (4, new java.lang.Object(), new java.lang.StringBuilder()) or null.javassist.CannotCompileException - If the field could not be found and the creation failed.public void commit(boolean continueOnException)
throws javassist.CannotCompileException,
java.io.IOException
Note: Some processors in this project (AbstractClassModificationProcessor, AbstractLoggingProcessor, ...) will call the commit() method automatically.
continueOnException - false if the process should abort if an exception is thrown. true if the process should continue if an exception is thrown (in this case the exception will be logged).javassist.CannotCompileException - Is thrown if the changes could not be compiled and continueOnException is false.java.io.IOException - Is thrown if the changes could not be written to the corresponding .class-files and continueOnException is false.public void commit()
ByteCodeHelper#commit(true).public void releaseResources()
Copyright © 2015. All Rights Reserved.