public function generate($defClass) {
		list($className, $refClass) = $this->getClassInfo($defClass);

		$companionName = $this->getCompanionName($className);

		$companionNameParts = explode('\\', $companionName);
		$companionClass = array_pop($companionNameParts);
		$companionNs = implode('\\', $companionNameParts);

		$companionNsPath = $this->nsToPath($companionNs);
		$outDir = $this->target->getPath()->pathJoin($companionNsPath);
		$outPath = $outDir->pathJoin($companionClass . '.php');

		$psr4Prefix = $this->target->getPrefix()->rtrim('\\');
		if (!empty($psr4Prefix)) {
			$companionNs = $psr4Prefix->join($companionNs, '\\');
		}
		$values = $this->director->getValuesFor($refClass);
		$values['companionNs'] = $companionNs;
		$values['companionClass'] = $companionClass;
		$values['model'] = $className;
		$values['modelStr'] = str_replace('\\', '\\\\', $className);

		$resolved = $this->template->forValues($values);

		if (!file_exists($outDir)) {
			mkdir($outDir, 0755, true);
		}

		$file = new SplFileObject($outPath, 'w');
		$file->fwrite($resolved);

		return $companionNs->join($companionClass, '\\')->__toString();
	}