本文整理汇总了PHP中PhpParser\Node::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::setAttribute方法的具体用法?PHP Node::setAttribute怎么用?PHP Node::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\Node
的用法示例。
在下文中一共展示了Node::setAttribute方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enterNode
/**
* Check all nodes
*
* @param Node $node
* @return void
**/
public function enterNode(Node $node)
{
// Skip nodes without comments.
if (!$node->hasAttribute("comments")) {
return;
}
// Check if annotations should be preserved. Only nodes with actual
// doc comment blocks are processed.
$comments = [];
if ($this->preserveAnnotations) {
$docComment = $node->getDocComment();
if ($docComment) {
$text = $docComment->getText();
// Check if it is a doc comment.
if (strpos($text, "/**") !== false) {
$text = $this->stripComment($text);
if ($text) {
$comments = [new Comment($text)];
}
}
}
}
// Remove (or set) comments.
$node->setAttribute("comments", $comments);
return $node;
}
示例2: enterNode
public function enterNode(Node $node)
{
if (!empty($this->stack)) {
$node->setAttribute('parent', $this->stack[count($this->stack) - 1]);
}
$this->stack[] = $node;
}
示例3: leaveNode
public function leaveNode(Node $node)
{
if ($node instanceof Node\Expr\Assign && $node->var instanceof Node\Expr\Variable && $this->var == $node->var->name) {
$this->var = null;
} elseif (!is_null($this->var) && ($node instanceof Node\Expr\FuncCall || $node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\StaticCall || $node instanceof Node\Expr\Closure)) {
$node->setAttribute('in_var', $this->var);
return $node;
}
}
示例4: enterNode
public function enterNode(Node $node)
{
$node->setAttribute('scope', implode(self::SCOPE_SEPARATOR, $this->scope));
if ($node instanceof Node\Stmt\NameSpace_ || $node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\ClassMethod || $node instanceof Node\Stmt\Function_) {
$this->scope[] = $node->name;
} elseif ($node instanceof Node\Expr\Closure) {
$this->scope[] = self::CLOSURE_NAME;
}
return $node;
}
示例5: resolveVariableType
/**
* {@inheritdoc}
*/
public function resolveVariableType(Node $node)
{
if ($node instanceof Node\Expr\PropertyFetch) {
// $this->someProperty
if ($node->var instanceof Node\Expr\Variable && $node->var->name === 'this') {
$node->setAttribute('guessedType', $this->table->lookUpClassProperty($node->name)->type());
}
// $x->someProperty
}
}
示例6: enterNode
public function enterNode(Node $node)
{
$node->setAttribute("scope", end($this->scope));
if ($node instanceof Stmt\Namespace_ and !empty($node->name)) {
$this->namespace = new NamespaceName($node->name->parts);
$this->scope[] = new Scope\NamespaceScope($this->namespace);
} elseif ($node instanceof Stmt\Class_) {
$this->scope[] = new Scope\ClassScope($this->namespace, $node->name);
} elseif ($node instanceof Stmt\Function_) {
$this->scope[] = new Scope\FunctionScope($this->namespace, $node->name);
} elseif ($node instanceof Stmt\ClassMethod) {
$this->scope[] = new Scope\ClassMethodScope(end($this->scope), $node->name);
} elseif ($node instanceof Expr\Closure) {
$identifier = $node->getAttribute("startFilePos", mt_rand());
$node->setAttribute("identifier", $identifier);
// The Closure node now has identifier for common use
$this->scope[] = new Scope\ClosureScope(end($this->scope), $identifier);
}
$node->setAttribute("scopeInner", end($this->scope));
}
示例7: enterNode
public function enterNode(Node $node)
{
$node->setAttribute("scope", end($this->scope));
if ($node instanceof Stmt\Namespace_ and !empty($node->name)) {
$this->namespace = new NamespaceName($node->name->parts);
} elseif ($node instanceof Stmt\Class_) {
$this->scope[] = new Scope\ClassScope($this->namespace, $node->name);
} elseif ($node instanceof Stmt\Function_) {
$this->scope[] = new Scope\FunctionScope($this->namespace, $node->name);
} elseif ($node instanceof Stmt\ClassMethod) {
$this->scope[] = new Scope\ClassMethodScope(end($this->scope), $node->name);
} elseif ($node instanceof Expr\Closure) {
$this->scope[] = new Scope\ClosureScope(end($this->scope), $node->getAttribute("startFilePos", mt_rand()));
}
}
示例8: resolveVariableType
/**
* {@inheritdoc}
*/
public function resolveVariableType(Node $node)
{
if ($node instanceof Node\Expr\Variable) {
$node->setAttribute('guessedType', $this->table->lookUp($node->name)->type());
}
}
示例9: computeInternalVersions
/**
* Compute the version of an internal function.
*
* @param Node $node
* @param string $element
* @param string $context
*
* @return void
*/
private function computeInternalVersions(Node $node, $element, $context, $extra = null)
{
$versions = $node->getAttribute('compatinfo');
if ($versions === null) {
// find reference info
$argc = isset($node->args) ? count($node->args) : 0;
$versions = $this->references->find($context, $element, $argc, $extra);
$versions['ext.all'] = $versions['php.all'] = '';
if ($argc) {
foreach ($node->args as $arg) {
if ($arg->value instanceof Node\Expr\BinaryOp\Pow) {
// Exponentiation
$this->updateVersion('5.6.0', $versions['php.min']);
}
}
}
// cache to speed-up later uses
$node->setAttribute('compatinfo', $versions);
}
$node->setAttribute('fileName', $this->file);
if ('methods' == $context) {
$element = sprintf('%s::%s', $extra, $element);
}
// update versions of $element
$this->updateElementVersion($context, $element, $versions);
++$this->metrics[$context][$element]['matches'];
// update local context
$this->updateLocalVersions($versions, isset($this->metrics[$context][$element]['optional']));
}
示例10: transform
protected function transform(Node $node)
{
$node->type = null;
$node->setAttribute('changed', true);
return $node;
}
示例11: leaveNode
/**
* Perform action
*
* @param Node $node
* @return void|bool Void if node should remain, false if not
*/
public function leaveNode(Node $node)
{
$node->setAttribute('comments', []);
}
示例12: transform
protected function transform(Node $node)
{
$node->name = '__construct';
$node->setAttribute('changed', true);
return $node;
}