FeaturesPluginsDocs & SupportCommunityPartners

NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

force autocomplete

 
Post new topic   Reply to topic    NetBeans Forums -> PHP Users
View previous topic :: View next topic  
Author Message
ziad



Joined: 10 Mar 2009
Posts: 20

PostPosted: Sat Jun 20, 2009 6:12 pm    Post subject: force autocomplete Reply with quote

Hi,

I have a DAO registry class to get hold of DAOs in an easy way and to limit to one instance of the DAOs. To get a DAO you do this:

Code:
$agentDAO = DAOReg::get('AgentDAO');
$agent = $agentDAO->findByName($name);


or usually I'll just access the methods directly like this:

Code:
$agent = DAOReg::get('AgentDAO')->findByName($name);


The problem is that because NB doesn't know what is being returned in the DAOReg::get method, I can't use autocomplete.

What would be the best way to get NB to do autocomplete on this? Is there a way to 'teach' NB which DAO will come back on the DAOReg::get call and hence do autocomplete?

If I used the first method of getting a DAO first explicitly, is there a way to force the class of the $agentDAO?

Thanks
Ziad
Back to top
View user's profile Send private message
christianachatz



Joined: 21 May 2009
Posts: 12
Location: Germany

PostPosted: Sat Jun 20, 2009 10:27 pm    Post subject: Reply with quote

Hi Zaid,

the way to teach is to add code comment to your method. If you have something like this

Code:
/**
 * @return MyType The type that is returned.
 */
public function get($param){
   return ...;
}

NB knows about the return type.

Cheers,
Christian
Back to top
View user's profile Send private message Visit poster's website
ziad



Joined: 10 Mar 2009
Posts: 20

PostPosted: Sat Jun 20, 2009 11:29 pm    Post subject: Reply with quote

Thanks for your response Christian. I guess I could use your suggestion for 'regular' functions but my DAOReg::get function actually returns different types. I guess I didn't make myself clear in the question.

Code:

// returns AgentDAO type
$agentDAO = DAOReg::get('AgentDAO');

// returns MemberDAO type
$memberDAO = DAOReg::get('MemberDAO');


So is there anyway to teach NB that the type of the object returned is what was passed in as the parameter to the DAOReg::get method? I'm guessing this is probably not possible.

But is it possible to tell NB the type of my variable on the client end (i.e. where DAOReg::get is called) instead of in the function itself? So is there a way to tell NB that the $agentDAO is of type AgentDAO in the following code?

Code:

$agentDAO = DAOReg::get('AgentDAO');


Thanks
Ziad
Back to top
View user's profile Send private message
christianachatz



Joined: 21 May 2009
Posts: 12
Location: Germany

PostPosted: Sun Jun 21, 2009 11:33 am    Post subject: Reply with quote

Hello Ziad,

Quote:
So is there anyway to teach NB that the type of the object returned is what was passed in as the parameter to the DAOReg::get method? I'm guessing this is probably not possible.

I don't think so, PHP does not support generics. Perheps you can try to annotate your code like in JAVA using generic. Have never done that, but give it a try.

Quote:
But is it possible to tell NB the type of my variable on the client end (i.e. where DAOReg::get is called) instead of in the function itself? So is there a way to tell NB that the $agentDAO is of type AgentDAO in the following code?

AFAIK you can add

Code:
/**
 * @var AgentDAO $agentDAO
 */
$agentDAO = DAOReg::get('AgentDAO');


Cheers,
Christian
Back to top
View user's profile Send private message Visit poster's website
Eugene Morgan
Posted via mailing list.





PostPosted: Mon Jun 22, 2009 2:06 pm    Post subject: force autocomplete Reply with quote

Another thing you can try is if all your DAOs extend a base DAO class, you can specify that class in the documentation for the
Back to top
ziad



Joined: 10 Mar 2009
Posts: 20

PostPosted: Tue Jun 23, 2009 4:37 am    Post subject: Re: force autocomplete Reply with quote

Eugene Morgan wrote:
Another thing you can try is if all your DAOs extend a base DAO class, you can specify that class in the documentation for the


Yes all my DAOs do extend a base DAO. It looks like your message got cut off. Please complete the rest of your post.

Thanks
Back to top
View user's profile Send private message
ziad



Joined: 10 Mar 2009
Posts: 20

PostPosted: Tue Jun 23, 2009 4:41 am    Post subject: Reply with quote

christianachatz wrote:

I don't think so, PHP does not support generics. Perheps you can try to annotate your code like in JAVA using generic. Have never done that, but give it a try.


How would I do that? Thanks.
Back to top
View user's profile Send private message
Tomas Mysik
Posted via mailing list.





PostPosted: Tue Jun 23, 2009 12:23 pm    Post subject: force autocomplete Reply with quote

Hi,

Dne sobota 20 června 2009 20:13:03 ziad napsal(a):
Quote:
If I used the first method of getting a DAO first explicitly, is there a
way to force the class of the $agentDAO?

as written earlier by other NB users, there is a way - use variable type in
comment [1].

HTH,
Tomas
[1] http://blogs.sun.com/netbeansphp/entry/defining_variable_type_in_a
[2] http://blogs.sun.com/netbeansphp/entry/defining_variable_type_in_a
--
Tomas Mysik
address-removed
Back to top
ziad



Joined: 10 Mar 2009
Posts: 20

PostPosted: Tue Jun 23, 2009 1:36 pm    Post subject: Re: force autocomplete Reply with quote

Hi Tomas,

Yeah I got how to force the type to a particular type using the @var comment but I was wondering about generics and what christian mentioned. How/where do I comment/annotate generics?

Tomas Mysik wrote:
Hi,

Dne sobota 20 června 2009 20:13:03 ziad napsal(a):
Quote:
If I used the first method of getting a DAO first explicitly, is there a
way to force the class of the $agentDAO?

as written earlier by other NB users, there is a way - use variable type in
comment [1].

HTH,
Tomas
[1] http://blogs.sun.com/netbeansphp/entry/defining_variable_type_in_a
[2] http://blogs.sun.com/netbeansphp/entry/defining_variable_type_in_a
--
Tomas Mysik
address-removed
Back to top
View user's profile Send private message
Tomas Mysik
Posted via mailing list.





PostPosted: Tue Jun 23, 2009 2:01 pm    Post subject: force autocomplete Reply with quote

Hi,

Dne úterý 23 června 2009 15:36:58 ziad napsal(a):
Quote:
Yeah I got how to force the type to a particular type using the @var
comment but I was wondering about generics and what christian mentioned.
How/where do I comment/annotate generics?

IMHO there's no such possibility for PHP.

Tomas
--
Tomas Mysik
address-removed
Back to top
Eugene Morgan
Posted via mailing list.





PostPosted: Tue Jun 23, 2009 4:18 pm    Post subject: force autocomplete Reply with quote

Not sure how much it will help, but the rest of my post was ...
... you can specify that class [the base class] in the documentation
for the DAOReg::get function -- at least that will give you some
autocompletion for any methods that are inherited by all DAOs.

On Mon, Jun 22, 2009 at 11:38 PM, ziad<address-removed> wrote:
Quote:

Eugene Morgan wrote:
Quote:
Another thing you can try is if all your DAOs extend a base DAO class, you can specify that class in the documentation for the




Yes all my DAOs do extend a base DAO. It looks like your message got cut off. Please complete the rest of your post.



Thanks










Back to top
ziad



Joined: 10 Mar 2009
Posts: 20

PostPosted: Tue Jun 23, 2009 5:20 pm    Post subject: Reply with quote

Hi Eugene,

Yeah that definitely does help but it would be nice to be able to get it to work properly. I saw how you can get auto-complete to work for CakePHP helpers by adding them onto an include fine and giving them types so I might try that.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> PHP Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB