/** * Display information * * @param io.StringWriter $out * @return void */ public function display($out) { $out->write(self::declarationOf($this->mirror)); $parent = $this->mirror->parent(); if ('lang.Enum' !== $parent->name()) { $this->displayExtensions([$parent], $out, 'extends'); } $this->displayExtensions($this->mirror->interfaces()->declared(), $out, 'implements'); $separator = false; $out->writeLine(' {'); $this->displayMembers($this->mirror->constants(), $out, $separator); foreach (Enum::valuesOf($this->mirror->type()) as $member) { $out->write(' ', $member->name(), '(', $member->ordinal(), ')'); $mirror = new TypeMirror(typeof($member)); if ($mirror->isSubtypeOf($this->mirror)) { $out->writeLine(' {'); foreach ($mirror->methods()->declared() as $method) { $out->writeLine(' ', (string) $method); } $separator = true; $out->writeLine(' }'); } else { $out->writeLine(); $separator = true; } } $constructor = $this->mirror->constructor(); if ($constructor->present()) { $this->displayMembers([$constructor], $out, $separator); } $this->displayMembers($this->mirror->methods()->all(Methods::ofClass()), $out, $separator); $this->displayMembers($this->mirror->methods()->all(Methods::ofInstance()), $out, $separator); $out->writeLine('}'); }
/** * Processes cell value * * @param var in * @return var * @throws lang.FormatException */ public function process($in) { try { return $this->proceed(Enum::valueOf($this->enum, $in)); } catch (\lang\IllegalArgumentException $e) { throw new \lang\FormatException($e->getMessage()); } }
public function abstract_enum_with_one_member() { $class = self::define('abstract enum', 'PartialOperation', null, '{ plus { public int evaluate(int $x, int $y) { return $x + $y; } }; public abstract int evaluate(int $x, int $y); }'); $this->assertEquals('SourcePartialOperation', $class->getName()); $this->assertTrue($class->isEnum()); $plus = Enum::valueOf($class, 'plus'); $this->assertEquals(2, $plus->evaluate(1, 1)); }
/** * Handles enums * * @param lang.XPClass class */ protected static function printEnum(XPClass $enum) { Console::write(implode(' ', Modifiers::namesOf($enum->getModifiers()))); Console::write(' enum ', self::displayNameOf($enum)); // Parent class, if not lang.Enum if (!XPClass::forName('lang.Enum')->equals($parent = $enum->getParentClass())) { Console::write(' extends ', self::displayNameOf($parent)); } // Interfaces if ($interfaces = $enum->getInterfaces()) { Console::write(' implements '); $s = sizeof($interfaces) - 1; foreach ($interfaces as $i => $iface) { Console::write(self::displayNameOf($iface)); $i < $s && Console::write(', '); } } // Constants Console::writeLine(' {'); $i = 0; foreach ($enum->getConstants() as $name => $value) { Console::writeLine(' const ', $name, ' = ', \xp::stringOf($value)); $i++; } // Members $i && Console::writeLine(); $i = 0; foreach (\lang\Enum::valuesOf($enum) as $member) { Console::write(' ', $member->ordinal(), ': ', $member->name()); $class = $member->getClass(); if ($class->isSubclassOf($enum)) { Console::writeLine(' {'); foreach ($class->getDeclaredMethods() as $method) { Console::writeLine(' ', $method); $i++; } Console::writeLine(' }'); } else { Console::writeLine(); } $i++; } // Methods $i && Console::writeLine(); self::printMethods($enum->getMethods()); Console::writeLine('}'); }
/** * Constructor */ public function __construct() { $this->marshallers = create('new util.collections.HashTable<lang.Type, webservices.rest.TypeMarshaller>'); // Deprecated! if (PHP_VERSION < 7 && ClassLoader::getDefault()->providesPackage('lang.types')) { $strings = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return $t->toString(); }, 'unmarshal' => function (Type $target, $in) { return $target->newInstance($in); }]); $integers = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return $t->intValue(); }, 'unmarshal' => function (Type $target, $in) { return $target->newInstance($in); }]); $decimals = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return $t->doubleValue(); }, 'unmarshal' => function (Type $target, $in) { return $target->newInstance($in); }]); $booleans = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return (bool) $t->value; }, 'unmarshal' => function (Type $target, $in) { return $target->newInstance($in); }]); $this->marshallers[XPClass::forName('lang.types.String')] = $strings; $this->marshallers[XPClass::forName('lang.types.Character')] = $strings; $this->marshallers[XPClass::forName('lang.types.Long')] = $integers; $this->marshallers[XPClass::forName('lang.types.Integer')] = $integers; $this->marshallers[XPClass::forName('lang.types.Short')] = $integers; $this->marshallers[XPClass::forName('lang.types.Byte')] = $integers; $this->marshallers[XPClass::forName('lang.types.Float')] = $decimals; $this->marshallers[XPClass::forName('lang.types.Double')] = $decimals; $this->marshallers[XPClass::forName('lang.types.Boolean')] = $booleans; } $this->marshallers[XPClass::forName('lang.Enum')] = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return $t->name(); }, 'unmarshal' => function (Type $target, $in) { return Enum::valueOf($target, (string) $in); }]); }
/** * Return a field type * * @return unittest.web.Fields */ public static function forTag($type) { return parent::valueOf(\lang\XPClass::forName('unittest.web.Fields'), strtoupper($type)); }
public function diff($type, $strdate1, $strdate2) { return DateMath::diff(Enum::valueOf(XPClass::forName('util.TimeInterval'), strtoupper($type)), new Date($strdate1), new Date($strdate2)); }
/** * Gets the currency instance for a given currency code * * @param string code ISO 4217 code * @return self * @throws lang.IllegalArgumentException */ public static function getInstance($code) { return parent::valueOf(new XPClass(__CLASS__), $code); }
/** * Constructor * * @param int ordinal * @param string name * @param webservices.rest.RestSerializer serializer * @param webservices.rest.RestDeserializer deserializer */ public function __construct($ordinal, $name, $serializer, $deserializer) { parent::__construct($ordinal, $name); $this->serializer = $serializer; $this->deserializer = $deserializer; }
/** * Constructor * * @param int ordinal default 0 * @param string name default '' * @param string op The query operator (see constants) */ public function __construct($ordinal, $name, $op) { parent::__construct($ordinal, $name); $this->op = $op; }
public function member_color($name, $ordinal, $color) { $this->assertEquals($color, Enum::valueOf(self::$fixture, $name)->color()); }
public function monday_is_not_a_weekend() { $this->assertFalse(Enum::valueOf(self::$fixture, 'MON')->isWeekend()); }
public function staticPrimitiveMemberNotInEnumValuesOf() { Profiling::$fixture = [$this, $this->name]; $this->assertEquals([Profiling::$INSTANCE, Profiling::$EXTENSION], Enum::valuesOf(XPClass::forName('net.xp_framework.unittest.core.Profiling'))); Profiling::$fixture = null; }
public function minus() { $this->assertEquals(-1, Enum::valueOf(self::$fixture, 'minus')->evaluate(1, 2)); }
/** * Creates a new fixture * * @param int $ordinal * @param string $name * @param string $string * @param var $object */ public function __construct($ordinal, $name, $string, $object) { parent::__construct($ordinal, $name); $this->string = $string; $this->object = $object; }
/** * Returns a operation member by a specified name, case-insensitively * * @param string $name * @return text.json.patch.Operations */ public static function named($name) { return parent::valueOf(new XPClass(self::class), strtoupper($name)); }
/** * Returns all enum members * * @return lang.Enum[] */ public static function values() { return parent::membersOf(__CLASS__); }
public function staticPrimitiveMemberNotInEnumValuesOf() { Profiling::$fixture = array($this, $this->name); $this->assertEquals(array(Profiling::$INSTANCE, Profiling::$EXTENSION), \lang\Enum::valuesOf(\lang\XPClass::forName('net.xp_framework.unittest.core.Profiling'))); Profiling::$fixture = NULL; }
/** * Gets the currency instance for a given currency code * * @param string code ISO 4217 code * @return self * @throws lang.IllegalArgumentException */ public static function getInstance($code) { return parent::valueOf(new XPClass(self::class), $code); }