1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

Find needed classes in catch, instanceof and newv()

Test Plan:
  try {} catch (X $ex) {}
  $a instanceof X;
  newv('X');

Linted Phabricator.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6143
This commit is contained in:
Jakub Vrana 2013-06-05 18:08:20 -07:00
parent f3e32d8366
commit 3de4984256
2 changed files with 52 additions and 3 deletions

View file

@ -21,7 +21,7 @@ final class PhutilLibraryMapBuilder {
const LIBRARY_MAP_VERSION = 2; const LIBRARY_MAP_VERSION = 2;
const SYMBOL_CACHE_VERSION_KEY = '__symbol_cache_version__'; const SYMBOL_CACHE_VERSION_KEY = '__symbol_cache_version__';
const SYMBOL_CACHE_VERSION = 10; const SYMBOL_CACHE_VERSION = 11;
/* -( Mapping libphutil Libraries )---------------------------------------- */ /* -( Mapping libphutil Libraries )---------------------------------------- */

View file

@ -225,11 +225,12 @@ foreach ($classes as $class) {
// - Static property access // - Static property access
// - Use of class constant // - Use of class constant
// - typehints // - typehints
// - catch
// - instanceof
// - newv()
// //
// TODO: Possibly support these: // TODO: Possibly support these:
// //
// - instanceof
// - catch
// - String literal in ReflectionClass(). // - String literal in ReflectionClass().
@ -289,6 +290,54 @@ foreach ($parameters as $parameter) {
); );
} }
// This is "catch (Exception $ex)".
$catches = $root->selectDescendantsOfType('n_CATCH');
foreach ($catches as $catch) {
$need[] = array(
'type' => 'class/interface',
'symbol' => $catch->getChildOfType(0, 'n_CLASS_NAME'),
);
}
// This is "$x instanceof X".
$instanceofs = $root->selectDescendantsOfType('n_BINARY_EXPRESSION');
foreach ($instanceofs as $instanceof) {
$operator = $instanceof->getChildOfType(1, 'n_OPERATOR');
if ($operator->getConcreteString() != 'instanceof') {
continue;
}
$class = $instanceof->getChildByIndex(2);
if ($class->getTypeName() != 'n_CLASS_NAME') {
continue;
}
$need[] = array(
'type' => 'class/interface',
'symbol' => $class,
);
}
// This is "newv('X')".
$calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
foreach ($calls as $call) {
$call_name = $call->getChildByIndex(0)->getConcreteString();
if ($call_name != 'newv') {
continue;
}
$params = $call->getChildByIndex(1)->getChildren();
if (!count($params)) {
continue;
}
$symbol = reset($params);
$symbol_value = $symbol->getStringLiteralValue();
if ($symbol_value && strpos($symbol_value, '$') === false) {
$need[] = array(
'type' => 'class',
'name' => $symbol_value,
'symbol' => $symbol,
);
}
}
// -( Interfaces )------------------------------------------------------------ // -( Interfaces )------------------------------------------------------------