Search in sources :

Example 1 with AfterBurnerImpossibleException

use of com.github.stephanenicolas.afterburner.exception.AfterBurnerImpossibleException in project afterburner by stephanenicolas.

the class AfterBurner method insertConstructor.

/**
     * Inserts java instructions into all constructors a given class.
     * @param insertableConstructor contains all information about insertion.
     * @throws CannotCompileException if the source contained in insertableMethod can't be compiled.
     * @throws AfterBurnerImpossibleException if something else goes wrong, wraps other exceptions.
     */
public void insertConstructor(InsertableConstructor insertableConstructor) throws CannotCompileException, AfterBurnerImpossibleException, NotFoundException {
    // create or complete onViewCreated
    List<CtConstructor> constructorList = extractExistingConstructors(insertableConstructor);
    log.info("constructor : " + constructorList.toString());
    if (!constructorList.isEmpty()) {
        for (CtConstructor constructor : constructorList) {
            constructor.insertBeforeBody(insertableConstructor.getConstructorBody(constructor.getParameterTypes()));
        }
    } else {
        throw new AfterBurnerImpossibleException("No suitable constructor was found in class " + insertableConstructor.getClassToInsertInto().getName() + ". Add a constructor that is accepted by the InsertableConstructor. Don't use non static inner classes.");
    }
}
Also used : AfterBurnerImpossibleException(com.github.stephanenicolas.afterburner.exception.AfterBurnerImpossibleException) CtConstructor(javassist.CtConstructor)

Aggregations

AfterBurnerImpossibleException (com.github.stephanenicolas.afterburner.exception.AfterBurnerImpossibleException)1 CtConstructor (javassist.CtConstructor)1