phpdoc #return with lazy loading - return

I don't know how to documents my methods for autocompletion.
My model Training has a getAnimators() method who returns a Db_MysqlResult which implements SeekableIterator and Countable. This Db_MysqlResult will create my Animator objects when I iterates on it, for example :
<?php
foreach ($training->getAnimators() as $animator) {
// Autocompletion shows me next, seek, etc. not getName
echo $animator->getName();
}
?>
I can write #return Animators[] in my getAnimators() even if it is not true because it returns a Db_MysqlResult?
Thanks in advance for your help.

If you are looking for your $animator variable to autocomplete its methods, your best bet may be to add an #var line hint in there:
/** #var Animator $animator */
echo $animator->
Some IDEs have the ability to recognize that #var line as a type hint and use it to give you autocompletion.
However, I'm not aware of any IDE that will recognize your return value of $training->getAnimators() and automatically know the type for $animator just from them being tied together in that foreach().

Related

Netbeans + ZF2 - Type hinting in view files

The task is simple, I want to add type hinting in Netbeans so I can get code assist in view files. How to do it the right way? The example below does not work:
/**
* #var \Zend\Paginator\Paginator $this->paginator
*/
$pageOffset = ($this->paginator->getCurrentPageNumber() - 1) * $this->paginator->getItemCountPerPage();
This is done in phtml file not php class file.
Many IDEs fail to provide type hinting for view properties in view files.
One workaround would be to assign the property of the view class to a new variable at the top of the view file.
/**
* #var \Zend\Paginator\Paginator $paginator
*/
$paginator = $this->paginator;
You used the wrong order. Variable name comes first, then the type. Also write it in one line.
/* #var $this->paginator \Zend\Paginator\Paginator */

deleting elements from a list and/or a set

I have a situation where I defined a couple of module-level instance variables using the 'private' scope identifier. I require to do this because these variables will be used in several functions within the module. Also, some of these variables are 'lists' or 'sets'. I realized that values of these variables persist between repeated calls to a certain function within the module. This is as expected.
I am also creating a test where I call one of the functions repeatedly. I would prefer to have a fresh copy of the instance variables (just like with instance members in Java). I can't seem to do so. If I try to nullify the content of the list/set, I get into trouble as follows:
module foo::bar
private set[DataType_1] data1;
public void nullifyInstanceVars( )
{
//tried
data1={}
}
//method that gets called repeatedly:
public void repeatCallMe(..)
{
nullifyInstanceVars( );
...
..
//Throws an error like: trying to add an element of type 1 to set[void]
data1 += anElementOfType1
}
So, I modified the nullifyInstanceVars( ) method to have set[DataType1] data1={ }. It doesn't work because I believe that simply creates a new variable scoped only within the function and really doesn't clear the element!
Any help is appreciated...
This really looks like a bug in the Rascal interpreter. I will file a bug report for it.
The work around is to initialize data1 in the declaration as well:
private set[int] data1 = {};
Can you confirm that this solves your problem?

Is there a Closure Compiler Extern for jQueryUI 1.9.1?

Does anyone know of an extern file for jQueryUI 1.9.1?
Alternately is there a tool that can generate an extern file? Seems like someone out there must be smart enough to have figured out how to do it automatically.
Thanks!
Unfortunately the answer is that no known extern for any version of jQuery UI currently exists.
The jQuery UI documentation now has public feeds which would make generating an extern from that documentation possible, but that has yet to be done.
As far as I can tell, it is not possible to have a meaningful closure extern declaration for the jQuery UI API. The problem is stems from the API structure. Instead of creating typeable methods, such as:
var date = $("#datepicker").getDate(); // does not work
the API exposes sub-methods for each type of widget with the method selector given as a string for the first argument, e.g.
var date = $("#datepicker").datepicker("getDate");
So that means that the datepicker function can take a wide variety of arguments, and return a wide variety of types, depending both on what method selector is provided. The best I can figure out how to do with just an externs declaration is something following this pattern:
/**
* #param {(string|Object)} fnName
* #param {...?} fnArgs
* #return {?}
*/
jQuery.prototype.datepicker = function(fnName, fnArgs) {};
This has the effect of quieting warning messages for correct calls to jQuery UI APIs, but does not help in finding incorrect calls.

JBehave examples table and Date objects

I have a JBehave test which lists some expected results in an ExamplesTable
Then result is :
|name|value|
|foo|2011-05-29|
|bar|baz|
And the object under test is something like:
class A {
private Date foo;
private String bar;
/* ... */
}
How do I tell JBehave to consider the parameter for foo as a date? I would prefer to implement my own converter.
See the documentation on parameter converters. Of course, if you are taking in an ExampleTable object and calling get on the row, you need to convert it yourself, or reuse an existing converter. Also look at JBEHAVE-398 which I've not tried yet, but might help if you are using JBehave 3.2 or higher.

What does [Bindable] mean in actionscript?

[Bindable]
/**
* Display output of video device.
*/
public var videoLocal : Video;
Anyone knows?
[Bindable] is a one of several meta tags that you can use in flex ActionScript code. It can be applied to properties, or methods that are marked in any scope. It cannot be used with static class members.
The key to using the [Bindable] meta tag is understanding what is going on under the hood when you use it. Essentially using data binding is a type of shorthand for adding event listeners and dispatching events.
There are two basic forms of the [Bindable] tag. The first is just [Bindable] followed by a var/property declaration. The Second is [Bindable(event="eventname")] followed by either a var/property declaration, a function/method declaration or one half of a getter/setter declaration.
I'll explain the longer notation first since the other builds on the same concept but with even more shorthand.
When you use [Bindable(event="eventname")] you are essentially telling the compiler that this var/property/function/method (call this the instance member) is 'available' to be used as the source for data binding. You are also telling it that when the value of the instance member has been invalidated/changed and it needs to be re-read that the "eventname" event will be dispatched.
In this longer form this all you are doing. You the developer are responsible for actually dispatching the "eventname" event whenever the value needs to be updated in the binding subscribers.
The real efficiency of using data binding comes on the subscribing side. The typical notation you will see in MXML is value="{instance.propertyName}" When you use the notation { } you are telling the compiler to do the following:
Create an event listener that listens to the event named in the bindable meta tag
In that event listener re-read the instance.propertyName and update this value
If you use the shorter form [Bindable], and you add the tag before a property/var, the compiler fills in the blanks and adds some additional functionality to make the property bindable. Essentially you are telling the compiler "add the events and methods you need to make this property bindable"
Now the way to think of what the compiler will do under the hood is this.
make a private version of your var
create an "event" to trigger the binding
create a getter function with scope and name of your original var that returns the private verson of the var when called.
create a setter function with scope and name of your original var that sets the private version of the var when called AND dispatches the triggering event.
In essence the compiler will do much of the work for you.
[Bindable]
public var xyz
is equivalent to
private var _xyz:String;
[Bindable(event="updateXYZValue")]
public function get xyz():String{
return _xyz;
}
public function set xyz(newxyz:String):void{
_xyz = newxyz;
dispatchEvent(new Event("updateXYZValue"));
}
The only functional differences in these is that in the first instance;
you do not know the name of the event that will be dispatched to trigger the binding
there is no way to update the underlying value without triggering the data binding
This second example also demonstrates one special case of the [Bindable] meta tag. This is that when you are applying it to a getter/setter pair defined for the same variable name you need only apply it to one or the other, it will apply to both. Typically you should set it on the getter.
You can use either notation on a function/method however if you do not specify an event the binding will never be triggered so if you are trying to bind to a function you should alway specify an event. It is also possible to specify more than one triggering event by stacking the tag. eg.
[Bindable(event="metaDataChanged")]
[Bindable(event="metaObjectUpdated")]
public function readMyMetaData():MetaDataObject{
var myMetaDataObject:MetaDataObject;
.
.
.
return myMetaDataObject;
}
This would presume that somewhere else you your class you will dispatch this metaDataChanged event or the metaObjectUpdated event when you want trigger the binding.
Also note that with this notation you can tie the binding of any instance member to any event that the instance will dispatch. Even inherited events that you yourself do not generate such as FrameEnter, OnChange, etc...
Data bindings can also be setup and destroyed during runtime. If you are interested in this take a look at the mx.binding.utils classes.
It is used in Databinding with Flex, you can read more about it here
http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_2.html
Creating properties to use as the source for data binding
When you create a property that you
want to use as the source of a data
binding expression, Flex can
automatically copy the value of the
source property to any destination
property when the source property
changes. To signal to Flex to perform
the copy, you must use the [Bindable]
data tag to register the property with
Flex.
As an addition to what Justin said, you can actually use two ways data binding in Flex with the # character. Here's an example:
<s:TextInput id="txt1" text="#{txt2.text}" />
For a working example with source code enabled you can check out this article I wrote a while back:
Two-ways data binding in Flex

Resources