1
0
Fork 0

Make FQNs more distinct

* use -> for instance methods/properties
* use ::$ for static properties
pull/165/head
Felix Becker 2016-11-22 17:12:24 +01:00
parent 06636ded54
commit 151dea6ad1
4 changed files with 37 additions and 19 deletions

View File

@ -20,10 +20,10 @@ class Definition
* - testFunction() * - testFunction()
* - TestNamespace\TestClass * - TestNamespace\TestClass
* - TestNamespace\TestClass::TEST_CONSTANT * - TestNamespace\TestClass::TEST_CONSTANT
* - TestNamespace\TestClass::staticTestProperty * - TestNamespace\TestClass::$staticTestProperty
* - TestNamespace\TestClass::testProperty * - TestNamespace\TestClass->testProperty
* - TestNamespace\TestClass::staticTestMethod() * - TestNamespace\TestClass::staticTestMethod()
* - TestNamespace\TestClass::testMethod() * - TestNamespace\TestClass->testMethod()
* *
* @var string|null * @var string|null
*/ */

View File

@ -221,7 +221,7 @@ class DefinitionResolver
} else { } else {
$classFqn = substr((string)$varType->getFqsen(), 1); $classFqn = substr((string)$varType->getFqsen(), 1);
} }
$name = $classFqn . '::' . (string)$node->name; $name = $classFqn . '->' . (string)$node->name;
} else if ($parent instanceof Node\Expr\FuncCall) { } else if ($parent instanceof Node\Expr\FuncCall) {
if ($parent->name instanceof Node\Expr) { if ($parent->name instanceof Node\Expr) {
return null; return null;
@ -255,7 +255,11 @@ class DefinitionResolver
$className = (string)$classNode->namespacedName; $className = (string)$classNode->namespacedName;
} }
} }
if ($node instanceof Node\Expr\StaticPropertyFetch) {
$name = (string)$className . '::$' . $node->name;
} else {
$name = (string)$className . '::' . $node->name; $name = (string)$className . '::' . $node->name;
}
} else { } else {
return null; return null;
} }
@ -404,7 +408,7 @@ class DefinitionResolver
} else { } else {
$classFqn = substr((string)$t->getFqsen(), 1); $classFqn = substr((string)$t->getFqsen(), 1);
} }
$fqn = $classFqn . '::' . $expr->name; $fqn = $classFqn . '->' . $expr->name;
if ($expr instanceof Node\Expr\MethodCall) { if ($expr instanceof Node\Expr\MethodCall) {
$fqn .= '()'; $fqn .= '()';
} }
@ -423,7 +427,11 @@ class DefinitionResolver
if (!($classType instanceof Types\Object_) || $classType->getFqsen() === null || $expr->name instanceof Node\Expr) { if (!($classType instanceof Types\Object_) || $classType->getFqsen() === null || $expr->name instanceof Node\Expr) {
return new Types\Mixed; return new Types\Mixed;
} }
$fqn = substr((string)$classType->getFqsen(), 1) . '::' . $expr->name; $fqn = substr((string)$classType->getFqsen(), 1) . '::';
if ($expr instanceof Node\Expr\StaticPropertyFetch) {
$fqn .= '$';
}
$fqn .= $expr->name;
if ($expr instanceof Node\Expr\StaticCall) { if ($expr instanceof Node\Expr\StaticCall) {
$fqn .= '()'; $fqn .= '()';
} }
@ -735,21 +743,31 @@ class DefinitionResolver
// Function: use functionName() as the name // Function: use functionName() as the name
return (string)$node->namespacedName . '()'; return (string)$node->namespacedName . '()';
} else if ($node instanceof Node\Stmt\ClassMethod) { } else if ($node instanceof Node\Stmt\ClassMethod) {
// Class method: use ClassName::methodName() as name // Class method: use ClassName->methodName() as name
$class = $node->getAttribute('parentNode'); $class = $node->getAttribute('parentNode');
if (!isset($class->name)) { if (!isset($class->name)) {
// Ignore anonymous classes // Ignore anonymous classes
return null; return null;
} }
if ($node->isStatic()) {
return (string)$class->namespacedName . '::' . (string)$node->name . '()'; return (string)$class->namespacedName . '::' . (string)$node->name . '()';
} else {
return (string)$class->namespacedName . '->' . (string)$node->name . '()';
}
} else if ($node instanceof Node\Stmt\PropertyProperty) { } else if ($node instanceof Node\Stmt\PropertyProperty) {
// Property: use ClassName::propertyName as name $property = $node->getAttribute('parentNode');
$class = $node->getAttribute('parentNode')->getAttribute('parentNode'); $class = $property->getAttribute('parentNode');
if (!isset($class->name)) { if (!isset($class->name)) {
// Ignore anonymous classes // Ignore anonymous classes
return null; return null;
} }
return (string)$class->namespacedName . '::' . (string)$node->name; if ($property->isStatic()) {
// Static Property: use ClassName::$propertyName as name
return (string)$class->namespacedName . '::$' . (string)$node->name;
} else {
// Instance Property: use ClassName->propertyName as name
return (string)$class->namespacedName . '->' . (string)$node->name;
}
} else if ($node instanceof Node\Const_) { } else if ($node instanceof Node\Const_) {
$parent = $node->getAttribute('parentNode'); $parent = $node->getAttribute('parentNode');
if ($parent instanceof Node\Stmt\Const_) { if ($parent instanceof Node\Stmt\Const_) {

View File

@ -88,7 +88,7 @@ class SymbolInformation
} }
$symbol->location = Location::fromNode($node); $symbol->location = Location::fromNode($node);
if ($fqn !== null) { if ($fqn !== null) {
$parts = preg_split('/(::|\\\\)/', $fqn); $parts = preg_split('/(::|->|\\\\)/', $fqn);
array_pop($parts); array_pop($parts);
$symbol->containerName = implode('\\', $parts); $symbol->containerName = implode('\\', $parts);
} }

View File

@ -33,10 +33,10 @@ class DefinitionCollectorTest extends TestCase
'TestNamespace\\TEST_CONST', 'TestNamespace\\TEST_CONST',
'TestNamespace\\TestClass', 'TestNamespace\\TestClass',
'TestNamespace\\TestClass::TEST_CLASS_CONST', 'TestNamespace\\TestClass::TEST_CLASS_CONST',
'TestNamespace\\TestClass::staticTestProperty', 'TestNamespace\\TestClass::$staticTestProperty',
'TestNamespace\\TestClass::testProperty', 'TestNamespace\\TestClass->testProperty',
'TestNamespace\\TestClass::staticTestMethod()', 'TestNamespace\\TestClass::staticTestMethod()',
'TestNamespace\\TestClass::testMethod()', 'TestNamespace\\TestClass->testMethod()',
'TestNamespace\\TestTrait', 'TestNamespace\\TestTrait',
'TestNamespace\\TestInterface', 'TestNamespace\\TestInterface',
'TestNamespace\\test_function()' 'TestNamespace\\test_function()'
@ -44,10 +44,10 @@ class DefinitionCollectorTest extends TestCase
$this->assertInstanceOf(Node\Const_::class, $defNodes['TestNamespace\\TEST_CONST']); $this->assertInstanceOf(Node\Const_::class, $defNodes['TestNamespace\\TEST_CONST']);
$this->assertInstanceOf(Node\Stmt\Class_::class, $defNodes['TestNamespace\\TestClass']); $this->assertInstanceOf(Node\Stmt\Class_::class, $defNodes['TestNamespace\\TestClass']);
$this->assertInstanceOf(Node\Const_::class, $defNodes['TestNamespace\\TestClass::TEST_CLASS_CONST']); $this->assertInstanceOf(Node\Const_::class, $defNodes['TestNamespace\\TestClass::TEST_CLASS_CONST']);
$this->assertInstanceOf(Node\Stmt\PropertyProperty::class, $defNodes['TestNamespace\\TestClass::staticTestProperty']); $this->assertInstanceOf(Node\Stmt\PropertyProperty::class, $defNodes['TestNamespace\\TestClass::$staticTestProperty']);
$this->assertInstanceOf(Node\Stmt\PropertyProperty::class, $defNodes['TestNamespace\\TestClass::testProperty']); $this->assertInstanceOf(Node\Stmt\PropertyProperty::class, $defNodes['TestNamespace\\TestClass->testProperty']);
$this->assertInstanceOf(Node\Stmt\ClassMethod::class, $defNodes['TestNamespace\\TestClass::staticTestMethod()']); $this->assertInstanceOf(Node\Stmt\ClassMethod::class, $defNodes['TestNamespace\\TestClass::staticTestMethod()']);
$this->assertInstanceOf(Node\Stmt\ClassMethod::class, $defNodes['TestNamespace\\TestClass::testMethod()']); $this->assertInstanceOf(Node\Stmt\ClassMethod::class, $defNodes['TestNamespace\\TestClass->testMethod()']);
$this->assertInstanceOf(Node\Stmt\Trait_::class, $defNodes['TestNamespace\\TestTrait']); $this->assertInstanceOf(Node\Stmt\Trait_::class, $defNodes['TestNamespace\\TestTrait']);
$this->assertInstanceOf(Node\Stmt\Interface_::class, $defNodes['TestNamespace\\TestInterface']); $this->assertInstanceOf(Node\Stmt\Interface_::class, $defNodes['TestNamespace\\TestInterface']);
$this->assertInstanceOf(Node\Stmt\Function_::class, $defNodes['TestNamespace\\test_function()']); $this->assertInstanceOf(Node\Stmt\Function_::class, $defNodes['TestNamespace\\test_function()']);