1
0
Fork 0

support constants

pull/341/head
jens1o 2017-03-19 13:55:41 +01:00
parent debda85ea3
commit e63ee99b81
3 changed files with 41 additions and 7 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace HELLO {
/**
* Does something really cool!
*/
function world() {
}
\HELLO;
}
namespace {
define('HELLO', true);
HELLO;
HELLO\world();
}

View File

@ -882,6 +882,11 @@ class DefinitionResolver
} }
return (string)$class->namespacedName . '::' . $node->name; return (string)$class->namespacedName . '::' . $node->name;
} }
} } else if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && (string)$node->name === 'define') {
if (!isset($node->args[0]) || !($node->args[0]->value instanceof Node\Scalar\String_)) {
return null;
}
return (string)$node->args[0]->value->value;
}
} }
} }

View File

@ -50,13 +50,9 @@ class SymbolInformation
{ {
$parent = $node->getAttribute('parentNode'); $parent = $node->getAttribute('parentNode');
$symbol = new self; $symbol = new self;
if ($node instanceof Node\Stmt\Class_) { if ($node instanceof Node\Stmt\Class_|| $node instanceof Node\Stmt\Trait_) {
$symbol->kind = SymbolKind::CLASS_; $symbol->kind = SymbolKind::CLASS_;
} else if ($node instanceof Node\Stmt\Trait_) { } else if ($node instanceof Node\Stmt\Interface_ || ($node instanceof Node\Name && $parent instanceof Node\Stmt\Namespace_)) {
$symbol->kind = SymbolKind::CLASS_;
} else if ($node instanceof Node\Stmt\Interface_) {
$symbol->kind = SymbolKind::INTERFACE;
} else if ($node instanceof Node\Name && $parent instanceof Node\Stmt\Namespace_) {
$symbol->kind = SymbolKind::NAMESPACE; $symbol->kind = SymbolKind::NAMESPACE;
} else if ($node instanceof Node\Stmt\Function_) { } else if ($node instanceof Node\Stmt\Function_) {
$symbol->kind = SymbolKind::FUNCTION; $symbol->kind = SymbolKind::FUNCTION;
@ -86,6 +82,17 @@ class SymbolInformation
$symbol->name = $node->var; $symbol->name = $node->var;
} else if (isset($node->name)) { } else if (isset($node->name)) {
$symbol->name = (string)$node->name; $symbol->name = (string)$node->name;
} else if
(
$node instanceof Node\Expr\FuncCall
&& $node->name instanceof Node\Name
&& (string)$node->name === 'define'
&& isset($node->args[0])
&& $node->args[0]->value instanceof Node\Scalar\String_
) {
// constants with define()
$symbol->kind = SymbolKind::CONSTANT;
$symbol->name = (string)$node->args[0]->value->value;
} else { } else {
return null; return null;
} }