Update getDocBlock to use context information. All Definition tests pass!
parent
e45648daab
commit
167b6ac6f2
|
@ -52,7 +52,7 @@ class LoggedTolerantDefinitionResolver extends TolerantDefinitionResolver
|
||||||
} else {
|
} else {
|
||||||
$resultText = $result ?? "NULL";
|
$resultText = $result ?? "NULL";
|
||||||
}
|
}
|
||||||
echo "> RESULT[$methodName]: " . $resultText . "\n";
|
echo "> RESULT[$callStr]: " . $resultText . "\n";
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,11 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
*/
|
*/
|
||||||
private $prettyPrinter;
|
private $prettyPrinter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DocBlockFactory
|
||||||
|
*/
|
||||||
|
private $docBlockFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReadableIndex $index
|
* @param ReadableIndex $index
|
||||||
*/
|
*/
|
||||||
|
@ -38,6 +43,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
$this->index = $index;
|
$this->index = $index;
|
||||||
$this->typeResolver = new TypeResolver;
|
$this->typeResolver = new TypeResolver;
|
||||||
$this->prettyPrinter = new PrettyPrinter;
|
$this->prettyPrinter = new PrettyPrinter;
|
||||||
|
$this->docBlockFactory = DocBlockFactory::createInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,11 +141,20 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDocBlock(Tolerant\Node $node) {
|
function getDocBlock(Tolerant\Node $node) {
|
||||||
// TODO context information
|
// TODO make more efficient
|
||||||
static $docBlockFactory;
|
$namespaceDefinition = $node->getNamespaceDefinition();
|
||||||
$docBlockFactory = $docBlockFactory ?? DocBlockFactory::createInstance();
|
$context = null;
|
||||||
|
if ($namespaceDefinition !== null && $namespaceDefinition->name !== null) {
|
||||||
|
$name = (string)$namespaceDefinition->name->getNamespacedName();
|
||||||
|
list($namespaceImportTable,,) = $namespaceDefinition->name->getImportTablesForCurrentScope($namespaceDefinition);
|
||||||
|
foreach ($namespaceImportTable as $alias=>$name) {
|
||||||
|
$namespaceImportTable[$alias] = (string)$name;
|
||||||
|
}
|
||||||
|
$context = new Types\Context($name, $namespaceImportTable);
|
||||||
|
}
|
||||||
|
|
||||||
$docCommentText = $node->getDocCommentText();
|
$docCommentText = $node->getDocCommentText();
|
||||||
return $docCommentText !== null ? $docBlockFactory->create($docCommentText) : null;
|
return $docCommentText !== null ? $this->docBlockFactory->create($docCommentText, $context) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -309,7 +324,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
}
|
}
|
||||||
// Get the type of the left-hand expression
|
// Get the type of the left-hand expression
|
||||||
$varType = $this->resolveExpressionNodeToType($access->dereferencableExpression);
|
$varType = $this->resolveExpressionNodeToType($access->dereferencableExpression);
|
||||||
var_dump($varType);
|
// var_dump($varType);
|
||||||
if ($varType instanceof Types\Compound) {
|
if ($varType instanceof Types\Compound) {
|
||||||
// For compound types, use the first FQN we find
|
// For compound types, use the first FQN we find
|
||||||
// (popular use case is ClassName|null)
|
// (popular use case is ClassName|null)
|
||||||
|
@ -336,8 +351,11 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
// Left-hand expression could not be resolved to a class
|
// Left-hand expression could not be resolved to a class
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
var_dump("AAAHHHHH");
|
// var_dump("AAAHHHHH");
|
||||||
$classFqn = substr((string)$varType->getFqsen(), 1);
|
$classFqn = substr((string)$varType->getFqsen(), 1);
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// $classFqn = $node->getNamespaceDefinition()->name->getNamespacedName() . (string)$varType->getFqsen();
|
||||||
var_dump($classFqn);
|
var_dump($classFqn);
|
||||||
}
|
}
|
||||||
$memberSuffix = '->' . (string)($access->memberName->getText() ?? $access->memberName->getText($node->getFileContents()));
|
$memberSuffix = '->' . (string)($access->memberName->getText() ?? $access->memberName->getText($node->getFileContents()));
|
||||||
|
@ -348,7 +366,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
$implementorFqns = [$classFqn];
|
$implementorFqns = [$classFqn];
|
||||||
|
|
||||||
while ($implementorFqn = array_shift($implementorFqns)) {
|
while ($implementorFqn = array_shift($implementorFqns)) {
|
||||||
var_dump($implementorFqn . $memberSuffix);
|
// var_dump($implementorFqn . $memberSuffix);
|
||||||
// If the member FQN exists, return it
|
// If the member FQN exists, return it
|
||||||
if ($this->index->getDefinition($implementorFqn . $memberSuffix)) {
|
if ($this->index->getDefinition($implementorFqn . $memberSuffix)) {
|
||||||
|
|
||||||
|
@ -368,9 +386,9 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var_dump("SUFFIX");
|
// var_dump("SUFFIX");
|
||||||
var_dump($classFqn);
|
// var_dump($classFqn);
|
||||||
var_dump($memberSuffix);
|
// var_dump($memberSuffix);
|
||||||
return $classFqn . $memberSuffix;
|
return $classFqn . $memberSuffix;
|
||||||
}
|
}
|
||||||
else if ($parent instanceof Tolerant\Node\Expression\CallExpression && $node instanceof Tolerant\Node\QualifiedName) {
|
else if ($parent instanceof Tolerant\Node\Expression\CallExpression && $node instanceof Tolerant\Node\QualifiedName) {
|
||||||
|
@ -618,11 +636,12 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
if ($access->memberName instanceof Tolerant\Node\Expression) {
|
if ($access->memberName instanceof Tolerant\Node\Expression) {
|
||||||
return new Types\Mixed;
|
return new Types\Mixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
$var = $access->dereferencableExpression;
|
$var = $access->dereferencableExpression;
|
||||||
|
|
||||||
|
var_dump("HERE!!!");
|
||||||
// Resolve object
|
// Resolve object
|
||||||
$objType = $this->resolveExpressionNodeToType($var);
|
$objType = $this->resolveExpressionNodeToType($var);
|
||||||
|
// var_dump($objType);
|
||||||
if (!($objType instanceof Types\Compound)) {
|
if (!($objType instanceof Types\Compound)) {
|
||||||
$objType = new Types\Compound([$objType]);
|
$objType = new Types\Compound([$objType]);
|
||||||
}
|
}
|
||||||
|
@ -636,12 +655,16 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
return new Types\Mixed;
|
return new Types\Mixed;
|
||||||
} else {
|
} else {
|
||||||
$classFqn = substr((string)$t->getFqsen(), 1);
|
$classFqn = substr((string)$t->getFqsen(), 1);
|
||||||
|
var_dump($classFqn);
|
||||||
}
|
}
|
||||||
$fqn = $classFqn . '->' . $access->memberName->getText($expr->getFileContents());
|
$fqn = $classFqn . '->' . $access->memberName->getText($expr->getFileContents());
|
||||||
if ($expr instanceof Tolerant\Node\Expression\CallExpression) {
|
if ($expr instanceof Tolerant\Node\Expression\CallExpression) {
|
||||||
$fqn .= '()';
|
$fqn .= '()';
|
||||||
}
|
}
|
||||||
|
var_dump($fqn);
|
||||||
|
// var_dump($fqn);
|
||||||
$def = $this->index->getDefinition($fqn);
|
$def = $this->index->getDefinition($fqn);
|
||||||
|
var_dump($def);
|
||||||
if ($def !== null) {
|
if ($def !== null) {
|
||||||
return $def->type;
|
return $def->type;
|
||||||
}
|
}
|
||||||
|
@ -652,7 +675,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
|| ($scopedAccess = $expr) instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression
|
|| ($scopedAccess = $expr) instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression
|
||||||
) {
|
) {
|
||||||
$classType = $this->resolveClassNameToType($scopedAccess->scopeResolutionQualifier);
|
$classType = $this->resolveClassNameToType($scopedAccess->scopeResolutionQualifier);
|
||||||
var_dump($classType);
|
// var_dump($classType);
|
||||||
if (!($classType instanceof Types\Object_) || $classType->getFqsen() === null /*|| $expr->name instanceof Tolerant\Node\Expression*/) {
|
if (!($classType instanceof Types\Object_) || $classType->getFqsen() === null /*|| $expr->name instanceof Tolerant\Node\Expression*/) {
|
||||||
return new Types\Mixed;
|
return new Types\Mixed;
|
||||||
}
|
}
|
||||||
|
@ -664,7 +687,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
if ($expr instanceof Tolerant\Node\Expression\CallExpression) {
|
if ($expr instanceof Tolerant\Node\Expression\CallExpression) {
|
||||||
$fqn .= '()';
|
$fqn .= '()';
|
||||||
}
|
}
|
||||||
var_dump($fqn);
|
// var_dump($fqn);
|
||||||
$def = $this->index->getDefinition($fqn);
|
$def = $this->index->getDefinition($fqn);
|
||||||
if ($def === null) {
|
if ($def === null) {
|
||||||
return new Types\Mixed;
|
return new Types\Mixed;
|
||||||
|
@ -797,9 +820,9 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
return new Types\Array_($valueType, $keyType);
|
return new Types\Array_($valueType, $keyType);
|
||||||
}
|
}
|
||||||
if ($expr instanceof Tolerant\Node\Expression\SubscriptExpression) {
|
if ($expr instanceof Tolerant\Node\Expression\SubscriptExpression) {
|
||||||
var_dump("SUBSCRIPT");
|
// var_dump("SUBSCRIPT");
|
||||||
$varType = $this->resolveExpressionNodeToType($expr->postfixExpression);
|
$varType = $this->resolveExpressionNodeToType($expr->postfixExpression);
|
||||||
var_dump($varType);
|
// var_dump($varType);
|
||||||
if (!($varType instanceof Types\Array_)) {
|
if (!($varType instanceof Types\Array_)) {
|
||||||
return new Types\Mixed;
|
return new Types\Mixed;
|
||||||
}
|
}
|
||||||
|
@ -972,6 +995,8 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
||||||
&& !empty($varTags = $docBlock->getTagsByName('var'))
|
&& !empty($varTags = $docBlock->getTagsByName('var'))
|
||||||
&& ($type = $varTags[0]->getType())
|
&& ($type = $varTags[0]->getType())
|
||||||
) {
|
) {
|
||||||
|
// var_dump("BOOYAH");
|
||||||
|
// var_dump($type);
|
||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
// Resolve the expression
|
// Resolve the expression
|
||||||
|
|
Loading…
Reference in New Issue