Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [pdt-dev] Extending PDT: type inference questions

Hello,

It is really simple - here it is:

<?php

class ClassRegistry {
	public static function init($classname) {
		$a = new $classname();
		
		if ($a) {
			return $a;
		}
		
		return null;
	}
}

class A {
	public function aaa() { echo "A"; }
}

class B {
	public function bbb() { echo "B"; }
}

ClassRegistry::init(B)->


I'm not using quotes around class name in method call currently (it is
because of quotes are included in value of classname in GoalEvaluator
- just didn't handle this yet)

--
Victor Kupriyanov

On Thu, Dec 30, 2010 at 4:00 PM, Roy Ganor <roy@xxxxxxxx> wrote:
> Hi Victor,
>
> Can you provide a code snippet of your ClassRegistry class? Including the "init" static method.
>
> Thanks,
> Roy
> -----Original Message-----
> From: pdt-dev-bounces@xxxxxxxxxxx [mailto:pdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Kooper
> Sent: Wednesday, December 29, 2010 12:55 PM
> To: pdt-dev@xxxxxxxxxxx
> Subject: [pdt-dev] Extending PDT: type inference questions
>
> Hello,
>
> I'm trying to write a custom extension to PDT 2.2 that adds code assistance for
> object instantiation for particular framework. I'm following the guidelines at
> http://wiki.eclipse.org/Extending_PDT_2.2#Type_inference_hinting and have a
> working code for exactly the case from the article:
>
> $myObject = ClassRegistry::init('MyClass');
> $myObject->... // A list of methods of MyClass is shown ok
>
> However it seems like the same type inference approach does not work when
> not using variable assignment:
>
> ClassRegistry::init('MyClass')->... // No proposals available
>
> Tracing goals evaluation factory for the latter case I found that this
> code snippet does not bring up evaluation of any ExpressionTypeGoal goals for
> context of the call, but starts with evaluation of MethodElementReturnTypeGoal
> that later leads to evaluation of method 'ClassRegistry::init's code.
>
> Attempting to implement evaluation of MethodElementReturnTypeGoal I was
> unable to access call context and actual arguments' values. Neither I
> succeeded in attempts to obtain MethodReturnTypeGoal object (which has
> getArguments() method)
>
>
> I also tried to utilize code assist strategy via ClassMemberContext. At
> first glance it looked promising. However I was unable to find out reciever
> class for '->' operator, as ClassMemberContext.getLhsTypes() returns empty
> list for the example above.
>
> Albeit I'm actually have access to call context with ClassMemberContext, I'm
> not happy with it - as it provides only text of call context via
> getStatementText() and it turns out that I have to parse this text manually.
>
> * So, can anybody help me by pointing directions that I should dig further?
> * Is there an access from MethodElementReturnTypeGoal to call context or actual
> call arguments?
> * Why there is no attempt to evaluate goal for call context prior to
> goal for method's content?
> * Is there a way to access goal evaluator from ClassMemberContext?
> * Do I have a broken installation or facing a known bug?
>
>
> Thank you in advance.
>
> --
> Victor Kupriyanov
> _______________________________________________
> pdt-dev mailing list
> pdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/pdt-dev
> _______________________________________________
> pdt-dev mailing list
> pdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/pdt-dev
>


Back to the top