Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

code completion and factory pattern in eclipse pdt

Lets say I have a typical factory pattern in PHP code:

abstract class Model
{
    function m()
    {
    }
}

class model_A
{
    function a()
    {
    }
}

class model_B
{
    function b()
    {
    }
}

function modelFactory($name)
{
    $className = 'model_' . $name;
    $object = new $className();
    // ... do some magic stuff ...
    return $object;
}

I know about the @var and @return phpdoc tags, but is there any magic way so after typing this:

$x = modelFactory('A');

Eclipse will know $x is an instance of model_A?

Can I define somewhere a fixed vector of strings like this:

"modelFactory('A')" => "new model_A()"
"modelFactory('B')" => "new model_B()"

For Eclipse to replace in memory before processing with code completion.

like image 520
fsw Avatar asked Jan 08 '13 18:01

fsw


1 Answers

Short answer, this is not possible in the way you want it.

As you've already rightfully pointed out in another comment you should use @var manually to achieve code completion goodness, because it's impossible for the editor to understand the concept of programming patterns by itself

Although theoretically possible, manually authoring rules for type inference just seems backwards imho (let alone the required changes to the Docblock notation itself).

like image 67
Ja͢ck Avatar answered Sep 27 '22 19:09

Ja͢ck