Skip to content

Commit 7049808

Browse files
committed
Adds location information to relected elements
1 parent 0587bdc commit 7049808

File tree

17 files changed

+168
-21
lines changed

17 files changed

+168
-21
lines changed

src/phpDocumentor/Reflection/Php/Class_.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public function __construct(
8383
$final = false,
8484
Location $location = null
8585
) {
86+
if ($location === null) {
87+
$location = new Location(-1);
88+
}
89+
8690
$this->fqsen = $fqsen;
8791
$this->parent = $parent;
8892
$this->docBlock = $docBlock;

src/phpDocumentor/Reflection/Php/Constant.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use phpDocumentor\Reflection\DocBlock;
1616
use phpDocumentor\Reflection\Element;
1717
use phpDocumentor\Reflection\Fqsen;
18+
use phpDocumentor\Reflection\Location;
1819

1920
/**
2021
* Descriptor representing a constant
@@ -34,18 +35,30 @@ final class Constant implements Element
3435
/** @var null|string $value */
3536
protected $value;
3637

38+
/**
39+
* @var Location
40+
*/
41+
private $location;
42+
3743
/**
3844
* Initializes the object.
3945
*
4046
* @param Fqsen $fqsen
4147
* @param DocBlock|null $docBlock
4248
* @param null|string $value
49+
* @param Location|null $location
4350
*/
44-
public function __construct(Fqsen $fqsen, DocBlock $docBlock = null, $value = null)
51+
public function __construct(Fqsen $fqsen, DocBlock $docBlock = null, $value = null, Location $location = null)
4552
{
4653
$this->fqsen = $fqsen;
4754
$this->docBlock = $docBlock;
4855
$this->value = $value;
56+
57+
if ($location === null) {
58+
$location = new Location(-1);
59+
}
60+
61+
$this->location = $location;
4962
}
5063

5164
/**
@@ -87,4 +100,12 @@ public function getDocBlock()
87100
{
88101
return $this->docBlock;
89102
}
103+
104+
/**
105+
* @return Location
106+
*/
107+
public function getLocation()
108+
{
109+
return $this->location;
110+
}
90111
}

src/phpDocumentor/Reflection/Php/Factory/Constant.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@
1313

1414
namespace phpDocumentor\Reflection\Php\Factory;
1515

16+
use phpDocumentor\Reflection\Location;
1617
use phpDocumentor\Reflection\Php\Constant as ConstantElement;
17-
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
1818
use phpDocumentor\Reflection\Php\StrategyContainer;
1919
use phpDocumentor\Reflection\PrettyPrinter;
2020
use phpDocumentor\Reflection\Types\Context;
21-
use PhpParser\Comment\Doc;
2221

2322
/**
2423
* Strategy to convert ClassConstantIterator to ConstantElement
2524
*
2625
* @see ConstantElement
2726
* @see ClassConstantIterator
2827
*/
29-
final class Constant extends AbstractFactory implements ProjectFactoryStrategy
28+
final class Constant extends AbstractFactory
3029
{
3130
/**
3231
* @var PrettyPrinter
@@ -62,7 +61,7 @@ public function matches($object)
6261
* @param ClassConstantIterator $object object to convert to an Element
6362
* @param StrategyContainer $strategies used to convert nested objects.
6463
* @param Context $context of the created object
65-
* @return Constant
64+
* @return ConstantElement
6665
*/
6766
protected function doCreate($object, StrategyContainer $strategies, Context $context = null)
6867
{
@@ -72,6 +71,6 @@ protected function doCreate($object, StrategyContainer $strategies, Context $con
7271
$default = $this->valueConverter->prettyPrintExpr($object->getValue());
7372
}
7473

75-
return new ConstantElement($object->getFqsen(), $docBlock, $default);
74+
return new ConstantElement($object->getFqsen(), $docBlock, $default, new Location($object->getLine()));
7675
}
7776
}

src/phpDocumentor/Reflection/Php/Factory/Function_.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use InvalidArgumentException;
1616
use phpDocumentor\Reflection\Fqsen;
17+
use phpDocumentor\Reflection\Location;
1718
use phpDocumentor\Reflection\Php\Factory;
1819
use phpDocumentor\Reflection\Php\Function_ as FunctionDescriptor;
1920
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
@@ -56,7 +57,7 @@ protected function doCreate($object, StrategyContainer $strategies, Context $con
5657
{
5758
$docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context);
5859

59-
$function = new FunctionDescriptor($object->fqsen, $docBlock);
60+
$function = new FunctionDescriptor($object->fqsen, $docBlock, new Location($object->getLine()));
6061

6162
foreach ($object->params as $param) {
6263
$strategy = $strategies->findMatching($param);

src/phpDocumentor/Reflection/Php/Factory/Interface_.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use InvalidArgumentException;
1717
use phpDocumentor\Reflection\Element;
1818
use phpDocumentor\Reflection\Fqsen;
19+
use phpDocumentor\Reflection\Location;
1920
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
2021
use phpDocumentor\Reflection\Php\StrategyContainer;
2122
use phpDocumentor\Reflection\Types\Context;
@@ -63,7 +64,7 @@ protected function doCreate($object, StrategyContainer $strategies, Context $con
6364
$parents['\\' . (string)$extend] = new Fqsen('\\' . (string)$extend);
6465
}
6566

66-
$interface = new InterfaceElement($object->fqsen, $parents, $docBlock);
67+
$interface = new InterfaceElement($object->fqsen, $parents, $docBlock, new Location($object->getLine()));
6768

6869
if (isset($object->stmts)) {
6970
foreach ($object->stmts as $stmt) {

src/phpDocumentor/Reflection/Php/Factory/Method.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace phpDocumentor\Reflection\Php\Factory;
1414

1515
use InvalidArgumentException;
16+
use phpDocumentor\Reflection\Location;
1617
use phpDocumentor\Reflection\Php\Method as MethodDescriptor;
1718
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
1819
use phpDocumentor\Reflection\Php\StrategyContainer;
@@ -40,7 +41,7 @@ public function matches($object)
4041
/**
4142
* Creates an MethodDescriptor out of the given object including its child elements.
4243
*
43-
* @param object $object object to convert to an MethodDescriptor
44+
* @param ClassMethod $object object to convert to an MethodDescriptor
4445
* @param StrategyContainer $strategies used to convert nested objects.
4546
* @param Context $context of the created object
4647
* @return MethodDescriptor
@@ -55,7 +56,8 @@ protected function doCreate($object, StrategyContainer $strategies, Context $con
5556
$docBlock,
5657
$object->isAbstract(),
5758
$object->isStatic(),
58-
$object->isFinal()
59+
$object->isFinal(),
60+
new Location($object->getLine())
5961
);
6062

6163
foreach ($object->params as $param) {

src/phpDocumentor/Reflection/Php/Factory/Property.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace phpDocumentor\Reflection\Php\Factory;
1414

1515
use InvalidArgumentException;
16+
use phpDocumentor\Reflection\Location;
1617
use phpDocumentor\Reflection\Php\Factory;
1718
use phpDocumentor\Reflection\Php\Property as PropertyDescriptor;
1819
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
@@ -75,7 +76,14 @@ protected function doCreate($object, StrategyContainer $strategies, Context $con
7576
}
7677
$docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context);
7778

78-
return new PropertyDescriptor($object->getFqsen(), $visibility, $docBlock, $default, $object->isStatic());
79+
return new PropertyDescriptor(
80+
$object->getFqsen(),
81+
$visibility,
82+
$docBlock,
83+
$default,
84+
$object->isStatic(),
85+
new Location($object->getLine())
86+
);
7987
}
8088

8189
/**

src/phpDocumentor/Reflection/Php/Factory/Trait_.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use InvalidArgumentException;
1616
use phpDocumentor\Reflection\Element;
1717
use phpDocumentor\Reflection\Fqsen;
18+
use phpDocumentor\Reflection\Location;
1819
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
1920
use phpDocumentor\Reflection\Php\StrategyContainer;
2021
use phpDocumentor\Reflection\Php\Trait_ as TraitElement;
@@ -55,7 +56,7 @@ protected function doCreate($object, StrategyContainer $strategies, Context $con
5556
{
5657
$docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context);
5758

58-
$trait = new TraitElement($object->fqsen, $docBlock);
59+
$trait = new TraitElement($object->fqsen, $docBlock, new Location($object->getLine()));
5960

6061
if (isset($object->stmts)) {
6162
foreach ($object->stmts as $stmt) {

src/phpDocumentor/Reflection/Php/Function_.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use phpDocumentor\Reflection\DocBlock;
1616
use phpDocumentor\Reflection\Element;
1717
use phpDocumentor\Reflection\Fqsen;
18+
use phpDocumentor\Reflection\Location;
1819

1920
/**
2021
* Descriptor representing a function
@@ -36,16 +37,26 @@ final class Function_ implements Element
3637
*/
3738
private $docBlock;
3839

40+
/**
41+
* @var Location
42+
*/
43+
private $location;
44+
3945
/**
4046
* Initializes the object.
4147
*
4248
* @param Fqsen $fqsen
4349
* @param DocBlock|null $docBlock
4450
*/
45-
public function __construct(Fqsen $fqsen, DocBlock $docBlock = null)
51+
public function __construct(Fqsen $fqsen, DocBlock $docBlock = null, Location $location = null)
4652
{
53+
if ($location === null) {
54+
$location = new Location(-1);
55+
}
56+
4757
$this->fqsen = $fqsen;
4858
$this->docBlock = $docBlock;
59+
$this->location = $location;
4960
}
5061

5162
/**
@@ -97,4 +108,12 @@ public function getDocBlock()
97108
{
98109
return $this->docBlock;
99110
}
111+
112+
/**
113+
* @return Location
114+
*/
115+
public function getLocation()
116+
{
117+
return $this->location;
118+
}
100119
}

src/phpDocumentor/Reflection/Php/Interface_.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use phpDocumentor\Reflection\Element;
1616
use phpDocumentor\Reflection\Fqsen;
1717
use phpDocumentor\Reflection\DocBlock;
18+
use phpDocumentor\Reflection\Location;
1819

1920
/**
2021
* Descriptor representing an Interface.
@@ -42,18 +43,32 @@ final class Interface_ implements Element
4243
/** @var Fqsen[] $parents */
4344
protected $parents = array();
4445

46+
/**
47+
* @var Location
48+
*/
49+
private $location;
50+
4551
/**
4652
* Initializes the object.
4753
*
4854
* @param Fqsen $fqsen
4955
* @param Fqsen[] $parents
5056
* @param DocBlock $docBlock
5157
*/
52-
public function __construct(Fqsen $fqsen, array $parents = array(), DocBlock $docBlock = null)
53-
{
58+
public function __construct(
59+
Fqsen $fqsen,
60+
array $parents = array(),
61+
DocBlock $docBlock = null,
62+
Location $location = null
63+
) {
64+
if ($location === null) {
65+
$location = new Location(-1);
66+
}
67+
5468
$this->fqsen = $fqsen;
5569
$this->docBlock = $docBlock;
5670
$this->parents = $parents;
71+
$this->location = $location;
5772
}
5873

5974
/**
@@ -137,4 +152,12 @@ public function getParents()
137152
{
138153
return $this->parents;
139154
}
155+
156+
/**
157+
* @return Location
158+
*/
159+
public function getLocation()
160+
{
161+
return $this->location;
162+
}
140163
}

0 commit comments

Comments
 (0)