protected function mergeEvents($events) {
        $result = array();
        foreach ($events as $event) {
            /* @var $event \ManiaScript\Builder\Event\Custom */
            if ($event->getInline()) {
                $code = $event->getCode() . PHP_EOL;
            } else {
                $code = $this->buildHandlerFunctionCall($event) . PHP_EOL;
            }
            if (!isset($result[$event->getName()])) {
                 $result[$event->getName()] = '';
            }
            $result[$event->getName()] .= $code;
        }
        return $result;
    }