Skip to content

Add Source which encapsulates file-based reflection - #37

Open
thekid wants to merge 7 commits into
mainfrom
feature/source
Open

Add Source which encapsulates file-based reflection#37
thekid wants to merge 7 commits into
mainfrom
feature/source

Conversation

@thekid

@thekidthekid commented Jul 30, 2023

Copy link
Copy Markdown
Member

API

publicclass lang.reflection.Source implements lang.Value {
publicfunction __construct(ReflectionClass|ReflectionMethod$reflect)
publicfunction fileName(): string
public function startLine(): int
publicfunction endLine(): int
public function usedTypes(): [:string]
public function usedConstants(): [:string]
publicfunction usedFunctions(): [:string]
publicfunction toString(): string
public function hashCode(): string
publicfunctioncompareTo(var$value): int
}

Declaration site

1 | <?php2 |
3 | $source= Reflection::type(newclass() { })->source();
4 |
5 | $source->fileName(); // current file6 | $source->startLine(); // 37 | $source->endLine(); // 3, the anonymous type is declared in one line!

Imports

1 | <?php2 |
3 | use util\{Date as DateTime, Money};
4 | use function strncmp;
5 |
6 | class T { }
7 |
8 | $source= Reflection::type(T::class)->source();
9 | $source->usedTypes(); // ['DateTime' => 'util\\Date', 'Money' => 'util\\Money']10 | $source->usedFunctions(); // ['strncmp' => 'strncmp']

Example

This code inside test.execution.TestClass could be rewritten:

-return $this->context->type->class()->reflect()->getFileName();+return $this->context->type->source->fileName();

@thekidthekid changed the title Add Source which encapsulates filename, start and end lines for types and methodsAdd Source which encapsulates file-based reflectionJul 30, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@thekid