Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Aug 12, 2014
1 parent fb55dc2 commit e1507fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/php/lang/GenericTypes.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ public function newType0($base, $arguments) {
array_shift($state);
array_unshift($state, 4);
$src.= '{';

foreach ($placeholders as $placeholder => $type) {
$src.= 'static $'.$placeholder.'= "'.$type.'";';
}
if (isset($annotations[0]['generic']['return'])) {
$meta[1][$m][DETAIL_RETURNS]= strtr($annotations[0]['generic']['return'], $placeholders);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,10 @@ public function partiallyClosedNS() {
Type::forName('net.xp_framework.unittest.core.generics.NSTypeLookup<string>')->getParentclass()
);
}

#[@test, @values([['', null], ['1', 1], ['Test', 'Test']])]
public function type_variable_available($expect, $value) {
$fixture= create('new net.xp_framework.unittest.core.generics.Unserializer<string>');
$this->assertEquals($expect, $fixture->newInstance($value));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php namespace net\xp_framework\unittest\core\generics;

use lang\Type;

/**
* List of elements
*/
#[@generic(self= 'T')]
class Unserializer extends \lang\Object {

/**
* Returns a list of all elements
*
* @param var $arg
* @return T element
*/
#[@generic(return= 'T')]
public function newInstance($arg= null) {
$type= Type::forName($T);
return null === $arg ? $type->default : $type->newInstance($arg);
}
}

0 comments on commit e1507fe

Please sign in to comment.