4 * This file is part of Psy Shell.
6 * (c) 2012-2018 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\TabCompletion\Matcher;
15 * A class attribute tab completion Matcher.
17 * Given a namespace and class, this matcher provides completion for constants
18 * and static properties.
20 * @author Marc Garcia <markcial@gmail.com>
22 class ClassAttributesMatcher extends AbstractMatcher
27 public function getMatches(array $tokens, array $info = [])
29 $input = $this->getInput($tokens);
31 $firstToken = \array_pop($tokens);
32 if (self::tokenIs($firstToken, self::T_STRING)) {
33 // second token is the nekudotayim operator
37 $class = $this->getNamespaceAndClass($tokens);
40 $reflection = new \ReflectionClass($class);
41 } catch (\ReflectionException $re) {
50 \array_keys($reflection->getStaticProperties())
52 \array_keys($reflection->getConstants())
56 function ($name) use ($class) {
57 $chunks = \explode('\\', $class);
58 $className = \array_pop($chunks);
60 return $className . '::' . $name;
64 function ($var) use ($input) {
65 return AbstractMatcher::startsWith($input, $var);
74 public function hasMatched(array $tokens)
76 $token = \array_pop($tokens);
77 $prevToken = \array_pop($tokens);
80 case self::tokenIs($prevToken, self::T_DOUBLE_COLON) && self::tokenIs($token, self::T_STRING):
81 case self::tokenIs($token, self::T_DOUBLE_COLON):