/** * Override the default getter to fill in a future * union type if available. */ public function getUnionType() : UnionType { if (null !== ($union_type = $this->getFutureUnionType())) { $this->getUnionType()->addUnionType($union_type); } return parent::getUnionType(); }
/** * @param \phan\Context $context * The context in which the structural element lives * * @param string $name, * The name of the typed structural element * * @param UnionType $type, * A '|' delimited set of types satisfyped by this * typed structural element. * * @param int $flags, * The flags property contains node specific flags. It is * always defined, but for most nodes it is always zero. * ast\kind_uses_flags() can be used to determine whether * a certain kind has a meaningful flags value. * * @param int $number_of_required_parameters * * @param int $number_of_optional_parameters * * @param bool $is_dynamic */ public function __construct(Context $context, string $name, UnionType $type, int $flags, int $number_of_required_parameters = 0, int $number_of_optional_parameters = 0, bool $is_dynamic = false) { parent::__construct($context, $name, $type, $flags); $this->number_of_required_parameters = $number_of_required_parameters; $this->number_of_optional_parameters = $number_of_optional_parameters; $this->is_dynamic = $is_dynamic; }
public function getUnionType() : UnionType { if (!empty($this->future_union_type)) { // null out the future_union_type before // we compute it to avoid unbounded // recursion $future_union_type = $this->future_union_type; $this->future_union_type = null; // Set a default value for my type in case // there's some unbounded recursion $this->setUnionType(new UnionType([IntType::instance(), FloatType::instance(), StringType::instance(), BoolType::instance()])); $this->setUnionType($future_union_type->get()); } return parent::getUnionType(); }
/** * @param Context $context * * @return UnionType * The type of this method in its given context. */ public function getUnionType() : UnionType { $union_type = parent::getUnionType(); // If the type is 'static', add this context's class // to the return type if ($union_type->hasStaticType()) { $union_type = clone $union_type; $union_type->addType($this->getFQSEN()->getFullyQualifiedClassName()->asType()); } // If the type is a generic array of 'static', add // a generic array of this context's class to the return type if ($union_type->genericArrayElementTypes()->hasStaticType()) { $union_type = clone $union_type; $union_type->addType($this->getFQSEN()->getFullyQualifiedClassName()->asType()->asGenericArrayType()); } return $union_type; }
/** * @param \phan\Context $context * The context in which the structural element lives * * @param string $name, * The name of the typed structural element * * @param UnionType $type, * A '|' delimited set of types satisfyped by this * typed structural element. * * @param int $flags, * The flags property contains node specific flags. It is * always defined, but for most nodes it is always zero. * ast\kind_uses_flags() can be used to determine whether * a certain kind has a meaningful flags value. */ public function __construct(Context $context, string $name, UnionType $type, int $flags) { parent::__construct($context, $name, $type, $flags); }