[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.pdt] inheritance, fluent interfaces, and code completion

Hi.

I have an abstract base class called Article.  It has a mutator like this:

  /**
   * Set the Title of the Article
   *
   * @param string $title
   * @return Article
   */
  public function setTitle($title = null)
  {
    if (! is_string($title))
      throw new Exception('Invalid title');
    $this->title = $title;
    return $this;
  }

I have a concrete sub class called News Article.  It has a mutator like
this:

  /**
   * Sets the Role that is permitted to view this article
   *
   * @param string $role
   * @return NewsArticle
   */
  public function setRole($role = null)
  {
    if (! is_string($role))
      throw new Exception(sprintf("Invalid role: '%s'", $role));
    $this->role = $role;
    return $this;
  }

This fluent interface allows me to write code like this:

$article = new NewsArticle();
$article
  ->setRole('public')
  ->setTitle('Foo Bar');

PDT gives me nice code completion for this.

However, code completion breaks when I use methods from the abstract class
(even though the code works just fine):

$article
  ->setTitle('Foo Bar')
  ->setRole('public');  // no code completion here

I guess this is because setTitle has @return Article in the doc block.

I could change it to @return Article|NewsArticle, but this feels wrong,
since the base class shouldn't know anything about classes that derive from
it.

Is there a better way to do it?