How to retrieve value from VariableImpl instance in PhpType provider

I'm trying to create a plugin similar to magicento and yiistorm.

The difference is that factory method retrieves not the instance of StringLiteralExpressionImpl class as an argument, but the instance of VariableImpl class.

Is there a way to retrieve actual value of the variable, passed to factory method? This value is always a string, but the factory method itself is never invoked directly.

Here are some examples, describing the code I am working with.

class FirstDecorator
{
    public function getModel($modelName)
    {
        // some specific code here
        return Factory::getModel($modelName);
    }
}

class SecondDecorator
{
    public function getModel($modelName)
    {
        // some specific code here
        return Factory::getModel($modelName);
    }
}

...

There are even more points in the code, from which the main factory method called, so writing the code for each of them looks wrong for me and I believe that I'm missing something.
I used the next code and it works correct when the factory method called directly.

    private String getModelName(MethodReferenceImpl e) {
        String modelName = null;

        PsiElement[] parameters = e.getParameters();

        if (parameters.length > 0 && parameters[0] instanceof StringLiteralExpressionImpl) {
            modelName = parameters[0].getText();
            modelName = modelName.substring(1, modelName.length() - 1);
        }

        return modelName;
    }

So, again, is there a way to retrieve actual value of the variable, passed to factory method from the decorator?

1 comment
Comment actions Permalink

same as here: https://github.com/adrienbrault/idea-php-symfony2-plugin/issues/46
if you have good working code let me know :)

this one does it:

 
PhpPsiElement value = ((AssignmentExpression)parent).getValue();

see full code here:
http://confluence.jetbrains.com/display/PhpStorm/PHP+Open+API#PHPOpenAPI-PhpTypeProvider
0

Please sign in to leave a comment.