Skip to content

Commit 91a7f79

Browse files
authored
Merge pull request #230 from arogachev/224-end-line
Add end location to all applicable elements
2 parents f867dfe + 6182fab commit 91a7f79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+354
-211
lines changed

src/phpDocumentor/Reflection/Php/Class_.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ final class Class_ implements Element, MetaDataContainerInterface
6161
/** @var Location */
6262
private $location;
6363

64+
/** @var Location */
65+
private $endLocation;
66+
6467
/**
6568
* Initializes a number of properties with the given values. Others are initialized by definition.
6669
*/
@@ -70,18 +73,24 @@ public function __construct(
7073
?Fqsen $parent = null,
7174
bool $abstract = false,
7275
bool $final = false,
73-
?Location $location = null
76+
?Location $location = null,
77+
?Location $endLocation = null
7478
) {
7579
if ($location === null) {
7680
$location = new Location(-1);
7781
}
7882

79-
$this->fqsen = $fqsen;
80-
$this->parent = $parent;
81-
$this->docBlock = $docBlock;
82-
$this->abstract = $abstract;
83-
$this->final = $final;
84-
$this->location = $location;
83+
if ($endLocation === null) {
84+
$endLocation = new Location(-1);
85+
}
86+
87+
$this->fqsen = $fqsen;
88+
$this->parent = $parent;
89+
$this->docBlock = $docBlock;
90+
$this->abstract = $abstract;
91+
$this->final = $final;
92+
$this->location = $location;
93+
$this->endLocation = $endLocation;
8594
}
8695

8796
/**
@@ -223,4 +232,9 @@ public function getLocation(): Location
223232
{
224233
return $this->location;
225234
}
235+
236+
public function getEndLocation(): Location
237+
{
238+
return $this->endLocation;
239+
}
226240
}

src/phpDocumentor/Reflection/Php/Constant.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ final class Constant implements Element, MetaDataContainerInterface
3838
/** @var Location */
3939
private $location;
4040

41+
/** @var Location */
42+
private $endLocation;
43+
4144
/** @var Visibility */
4245
private $visibility;
4346

@@ -52,13 +55,15 @@ public function __construct(
5255
?DocBlock $docBlock = null,
5356
?string $value = null,
5457
?Location $location = null,
58+
?Location $endLocation = null,
5559
?Visibility $visibility = null,
5660
bool $final = false
5761
) {
5862
$this->fqsen = $fqsen;
5963
$this->docBlock = $docBlock;
6064
$this->value = $value;
6165
$this->location = $location ?: new Location(-1);
66+
$this->endLocation = $endLocation ?: new Location(-1);
6267
$this->visibility = $visibility ?: new Visibility(Visibility::PUBLIC_);
6368
$this->final = $final;
6469
}
@@ -100,6 +105,11 @@ public function getLocation(): Location
100105
return $this->location;
101106
}
102107

108+
public function getEndLocation(): Location
109+
{
110+
return $this->endLocation;
111+
}
112+
103113
public function getVisibility(): Visibility
104114
{
105115
return $this->visibility;

src/phpDocumentor/Reflection/Php/EnumCase.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,31 @@ final class EnumCase implements Element, MetaDataContainerInterface
2323
/** @var Location */
2424
private $location;
2525

26+
/** @var Location */
27+
private $endLocation;
28+
2629
/** @var string|null */
2730
private $value;
2831

29-
public function __construct(Fqsen $fqsen, ?DocBlock $docBlock, ?Location $location = null, ?string $value = null)
30-
{
32+
public function __construct(
33+
Fqsen $fqsen,
34+
?DocBlock $docBlock,
35+
?Location $location = null,
36+
?Location $endLocation = null,
37+
?string $value = null
38+
) {
3139
if ($location === null) {
3240
$location = new Location(-1);
3341
}
3442

43+
if ($endLocation === null) {
44+
$endLocation = new Location(-1);
45+
}
46+
3547
$this->fqsen = $fqsen;
3648
$this->docBlock = $docBlock;
3749
$this->location = $location;
50+
$this->endLocation = $endLocation;
3851
$this->value = $value;
3952
}
4053

@@ -58,6 +71,11 @@ public function getLocation(): Location
5871
return $this->location;
5972
}
6073

74+
public function getEndLocation(): Location
75+
{
76+
return $this->endLocation;
77+
}
78+
6179
public function getValue(): ?string
6280
{
6381
return $this->value;

src/phpDocumentor/Reflection/Php/Enum_.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ final class Enum_ implements Element, MetaDataContainerInterface
3333
/** @var Location */
3434
private $location;
3535

36+
/** @var Location */
37+
private $endLocation;
38+
3639
/** @var EnumCase[] */
3740
private $cases = [];
3841

@@ -52,16 +55,22 @@ public function __construct(
5255
Fqsen $fqsen,
5356
?Type $backedType,
5457
?DocBlock $docBlock = null,
55-
?Location $location = null
58+
?Location $location = null,
59+
?Location $endLocation = null
5660
) {
5761
if ($location === null) {
5862
$location = new Location(-1);
5963
}
6064

61-
$this->fqsen = $fqsen;
62-
$this->docBlock = $docBlock;
63-
$this->location = $location;
64-
$this->backedType = $backedType;
65+
if ($endLocation === null) {
66+
$endLocation = new Location(-1);
67+
}
68+
69+
$this->fqsen = $fqsen;
70+
$this->docBlock = $docBlock;
71+
$this->location = $location;
72+
$this->endLocation = $endLocation;
73+
$this->backedType = $backedType;
6574
}
6675

6776
public function getFqsen(): Fqsen
@@ -84,6 +93,11 @@ public function getLocation(): Location
8493
return $this->location;
8594
}
8695

96+
public function getEndLocation(): Location
97+
{
98+
return $this->endLocation;
99+
}
100+
87101
public function addCase(EnumCase $case): void
88102
{
89103
$this->cases[(string) $case->getFqsen()] = $case;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ protected function doCreate(
7878
$this->createDocBlock($const->getDocComment(), $context->getTypeContext()),
7979
$const->getValue() !== null ? $this->valueConverter->prettyPrintExpr($const->getValue()) : null,
8080
new Location($const->getLine()),
81+
new Location($const->getEndLine()),
8182
$this->buildVisibility($const),
8283
$const->isFinal()
8384
));

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public function getLine(): int
4949
return $this->classConstants->getLine();
5050
}
5151

52+
/**
53+
* Gets line the node ended in.
54+
*
55+
* @return int Line
56+
*/
57+
public function getEndLine(): int
58+
{
59+
return $this->classConstants->getEndLine();
60+
}
61+
5262
/**
5363
* Returns the name of the current constant.
5464
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ protected function doCreate(ContextStack $context, object $object, StrategyConta
5252
$object->extends ? new Fqsen('\\' . $object->extends) : null,
5353
$object->isAbstract(),
5454
$object->isFinal(),
55-
new Location($object->getLine())
55+
new Location($object->getLine()),
56+
new Location($object->getEndLine())
5657
);
5758

5859
if (isset($object->implements)) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ private function promoteParameterToProperty(ContextStack $context, Param $param)
7777
$param->default !== null ? $this->valueConverter->prettyPrintExpr($param->default) : null,
7878
false,
7979
new Location($param->getLine()),
80+
new Location($param->getEndLine()),
8081
(new Type())->fromPhpParser($param->type),
8182
$this->readOnly($param->flags)
8283
);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ protected function doCreate(
106106
$this->determineFqsen($name),
107107
$this->createDocBlock($object->getDocComment(), $context->getTypeContext()),
108108
$this->determineValue($value),
109-
new Location($object->getLine())
109+
new Location($object->getLine()),
110+
new Location($object->getEndLine())
110111
);
111112

112113
$file->addConstant($constant);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function doCreate(ContextStack $context, object $object, StrategyConta
4242
$object->fqsen,
4343
$docBlock,
4444
new Location($object->getLine()),
45+
new Location($object->getEndLine()),
4546
$object->expr !== null ? $this->prettyPrinter->prettyPrintExpr($object->expr) : null
4647
));
4748
}

0 commit comments

Comments
 (0)