]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Find needed classes in catch, instanceof and newv()
authorJakub Vrana <jakub@vrana.cz>
Thu, 6 Jun 2013 01:08:20 +0000 (18:08 -0700)
committerJakub Vrana <jakub@vrana.cz>
Thu, 6 Jun 2013 14:25:08 +0000 (07:25 -0700)
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

scripts/lib/PhutilLibraryMapBuilder.php
scripts/phutil_symbols.php

index dace26a36841b92ae57f26c88535ac68a5f824d1..88a739463731c7160630aedb3d3de67d9bf4fb39 100755 (executable)
@@ -21,7 +21,7 @@ final class PhutilLibraryMapBuilder {
   const LIBRARY_MAP_VERSION       = 2;
 
   const SYMBOL_CACHE_VERSION_KEY  = '__symbol_cache_version__';
-  const SYMBOL_CACHE_VERSION      = 10;
+  const SYMBOL_CACHE_VERSION      = 11;
 
 
 /* -(  Mapping libphutil Libraries  )---------------------------------------- */
index 72f0b53b87970782749d547e93a2f0ff0c12535e..8a7fbeedc1a5183228fbb7febdca62afa8634041 100755 (executable)
@@ -225,11 +225,12 @@ foreach ($classes as $class) {
 //  - Static property access
 //  - Use of class constant
 //  - typehints
+//  - catch
+//  - instanceof
+//  - newv()
 //
 // TODO: Possibly support these:
 //
-//  - instanceof
-//  - catch
 //  - 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  )------------------------------------------------------------