public function refine($role) {
        $fileSource = $role->getFileSpecification()->getSource();
        $parser = (new fphp\Helper\PhpParser())->parseFile($fileSource);
        $ast = $parser->getAst();
        $class = $parser->getExactlyOneClass($fileSource);

        if (!$this->targetClass) { // not refining, but defining the target class
            $this->targetClass = $class->name;
            $this->mangleClassName($class, $role);
        } else { // refining
            if ($class->name !== $this->targetClass)
                throw new ClassComposerException("\"$fileSource\" refines \"$class->name\" (expected \"$this->targetClass\")");
            if ($class->extends)
                throw new ClassComposerException("refining role at \"$fileSource\" may not extend a class");
            
            $this->mangleClassName($class, $role);
            $this->extendClass($class);
        }
        
        return new ClassComposer($this->targetClass, $class->name, array_merge($this->ast, $ast));
    }