|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padawan\Domain\Completion; |
|
4
|
|
|
|
|
5
|
|
|
use Padawan\Domain\Scope; |
|
6
|
|
|
|
|
7
|
|
|
class Context |
|
8
|
|
|
{ |
|
9
|
|
|
const T_USE = 2; |
|
10
|
|
|
const T_NAMESPACE = 4; |
|
11
|
|
|
const T_OBJECT = 8; |
|
12
|
|
|
const T_CLASSNAME = 16; |
|
13
|
|
|
const T_INTERFACENAME = 32; |
|
14
|
|
|
const T_THIS = 64; |
|
15
|
|
|
const T_CLASS_STATIC = 128; |
|
16
|
|
|
const T_CLASS_METHODS = 256; |
|
17
|
|
|
const T_METHOD_CALL = 512; |
|
18
|
|
|
const T_VAR = 1024; |
|
19
|
|
|
const T_ANY_NAME = 2048; |
|
20
|
|
|
|
|
21
|
|
|
private $type = 0; |
|
22
|
|
|
private $token; |
|
23
|
|
|
private $scope; |
|
24
|
|
|
private $data; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(Scope $scope, Token $token) { |
|
27
|
|
|
$this->scope = $scope; |
|
28
|
|
|
$this->setToken($token); |
|
29
|
|
|
} |
|
30
|
|
|
public function setToken(Token $token) { |
|
31
|
|
|
$this->token = $token; |
|
32
|
|
|
if ($token->isVar()) { |
|
33
|
|
|
$this->addType(Context::T_VAR); |
|
34
|
|
|
} elseif ($token->isObjectOperator()) { |
|
35
|
|
|
$this->addType(Context::T_OBJECT); |
|
36
|
|
|
} elseif ($token->isStaticOperator()) { |
|
37
|
|
|
$this->addType(Context::T_CLASS_STATIC); |
|
38
|
|
|
} elseif ($token->isNamespaceOperator()) { |
|
39
|
|
|
$this->addType(Context::T_NAMESPACE); |
|
40
|
|
|
} elseif ($token->isUseOperator()) { |
|
41
|
|
|
$this->addType(Context::T_USE); |
|
42
|
|
|
$this->addType(Context::T_CLASSNAME); |
|
43
|
|
|
} elseif ($token->isNewOperator()) { |
|
44
|
|
|
$this->addType(Context::T_CLASSNAME); |
|
45
|
|
|
} elseif ($token->isExtendsOperator()) { |
|
46
|
|
|
$this->addType(Context::T_CLASSNAME); |
|
47
|
|
|
} elseif ($token->isImplementsOperator()) { |
|
48
|
|
|
$this->addType(Context::T_INTERFACENAME); |
|
49
|
|
|
} elseif ($token->isMethodCall()) { |
|
50
|
|
|
$this->addType(Context::T_METHOD_CALL); |
|
51
|
|
|
} elseif ($token->isString()) { |
|
52
|
|
|
$this->addType(self::T_ANY_NAME); |
|
53
|
|
|
$this->setData($token->getSymbol()); |
|
54
|
|
|
} elseif ($token->isTerminate()) { |
|
55
|
|
|
$this->setData($token->getSymbol()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function setData($data) { |
|
60
|
|
|
$this->data = $data; |
|
61
|
|
|
} |
|
62
|
|
|
public function getData() { |
|
63
|
|
|
return $this->data; |
|
64
|
|
|
} |
|
65
|
|
|
public function addType($type) { |
|
66
|
|
|
$this->type = $this->type | $type; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return Scope |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getScope() { |
|
73
|
|
|
return $this->scope; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return Token |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getToken() { |
|
80
|
|
|
return $this->token; |
|
81
|
|
|
} |
|
82
|
|
|
public function isEmpty() { |
|
83
|
|
|
return $this->type === 0; |
|
84
|
|
|
} |
|
85
|
|
|
public function isVar() { |
|
86
|
|
|
return (bool) ($this->type & self::T_VAR); |
|
87
|
|
|
} |
|
88
|
|
|
public function isUse() { |
|
89
|
|
|
return (bool) ($this->type & self::T_USE); |
|
90
|
|
|
} |
|
91
|
|
|
public function isNamespace() { |
|
92
|
|
|
return (bool) ($this->type & self::T_NAMESPACE); |
|
93
|
|
|
} |
|
94
|
|
|
public function isObject() { |
|
95
|
|
|
return (bool) ($this->type & self::T_OBJECT); |
|
96
|
|
|
} |
|
97
|
|
|
public function isClassName() { |
|
98
|
|
|
return (bool) ($this->type & self::T_CLASSNAME); |
|
99
|
|
|
} |
|
100
|
|
|
public function isInterfaceName() { |
|
101
|
|
|
return (bool) ($this->type & self::T_INTERFACENAME); |
|
102
|
|
|
} |
|
103
|
|
|
public function isThis() { |
|
104
|
|
|
return (bool) ($this->type & self::T_THIS); |
|
105
|
|
|
} |
|
106
|
|
|
public function isClassStatic() { |
|
107
|
|
|
return (bool) ($this->type & self::T_CLASS_STATIC); |
|
108
|
|
|
} |
|
109
|
|
|
public function isClassMethods() |
|
110
|
|
|
{ |
|
111
|
|
|
return (bool) ($this->type & self::T_CLASS_METHODS); |
|
112
|
|
|
} |
|
113
|
|
|
public function isMethodCall() |
|
114
|
|
|
{ |
|
115
|
|
|
return (bool) ($this->type & self::T_METHOD_CALL); |
|
116
|
|
|
} |
|
117
|
|
|
public function isString() |
|
118
|
|
|
{ |
|
119
|
|
|
return (bool) ($this->type & self::T_ANY_NAME); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|