Skip to content

Commit 9bc5f02

Browse files
committed
added multiple processors working in Parser
1 parent b5e1642 commit 9bc5f02

3 files changed

Lines changed: 34 additions & 18 deletions

File tree

src/Complete/ContentManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ protected function prepareContent($content, $line, $column){
9090
return [$lines, trim($badLine), trim($completionLine)];
9191
}
9292
protected function updateFileIndex(Project $project, $lines, $file){
93+
//gc_disable();
9394
if(is_array($lines)){
9495
$content = implode("\n", $lines);
9596
}
@@ -105,13 +106,14 @@ protected function updateFileIndex(Project $project, $lines, $file){
105106
}
106107
$this->indexProcessor->clearResultNodes();
107108
$parser = $this->parser;
108-
$parser->setProcessor($this->indexProcessor);
109+
$parser->addProcessor($this->indexProcessor);
109110
$nodes = $parser->parseContent($fqcn, $file, $content);
110111
$this->generator->processFileNodes(
111112
$project->getIndex(),
112113
$fqcn,
113114
$nodes
114115
);
116+
//gc_enable();
115117
}
116118

117119
private $parser;

src/Generator/IndexGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function processFile(Index $index, $fqcn, $file, $rewrite=false){
141141
$processor = $this->processor;
142142
$processor->clearResultNodes();
143143
$parser = $this->getClassUtils()->getParser();
144-
$parser->setProcessor($processor);
144+
$parser->addProcessor($processor);
145145
$nodes = $this->getClassUtils()->getParser()
146146
->parseFile($fqcn, $file);
147147
$end = microtime(1) - $startParser;

src/Parser/Parser.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99
use PhpParser\NodeTraverser AS Traverser;
1010

1111
class Parser{
12-
private $parsedClasses = [];
13-
/** @var PathResolver */
14-
private $path;
15-
/** @var PhpParser */
16-
private $parser;
17-
/** @var Traverser */
18-
private $traverser;
19-
/** @var Visitor\Visitor */
20-
private $visitor;
2112

2213
public function __construct(
2314
ASTGenerator $parser,
@@ -41,7 +32,7 @@ public function parseContent(FQCN $fqcn, $file, $content){
4132
$this->useParser->setUses($uses);
4233
$ast = $this->parser->parse($content);
4334

44-
$this->visitor->setFileInfo($fqcn, $file);
35+
$this->setFileInfo($fqcn, $file);
4536
$this->traverser->traverse($ast);
4637
}
4738
catch(\Exception $e){
@@ -52,14 +43,37 @@ public function parseContent(FQCN $fqcn, $file, $content){
5243
public function parseFQCN($fqcn){
5344
return $this->useParser->parseFQCN($fqcn);
5445
}
55-
public function setProcessor(Processor\ProcessorInterface $visitor){
56-
if(!empty($this->visitor)){
57-
$this->traverser->removeVisitor($this->visitor);
46+
public function addProcessor(Processor\ProcessorInterface $processor){
47+
$this->processors[] = $processor;
48+
$this->traverser->addVisitor($processor);
49+
}
50+
public function clearProcessors(){
51+
foreach($this->processors AS $processor){
52+
$this->traverser->removeVisitor($processor);
5853
}
59-
$this->visitor = $visitor;
60-
$this->traverser->addVisitor($this->visitor);
54+
$this->processors = [];
6155
}
6256
public function getResultNode(){
63-
return $this->visitor->getResultNodes();
57+
$nodes = [];
58+
foreach($this->processors as $processor){
59+
$nodes = array_merge($processor->getResultNodes(), $nodes);
60+
}
61+
return $nodes;
62+
}
63+
64+
protected function setFileInfo(FQCN $fqcn, $file){
65+
foreach($this->processors AS $processor){
66+
$processor->setFileInfo($fqcn, $file);
67+
}
6468
}
69+
70+
private $parsedClasses = [];
71+
/** @var PathResolver */
72+
private $path;
73+
/** @var PhpParser */
74+
private $parser;
75+
/** @var Traverser */
76+
private $traverser;
77+
/** @var Processor\ProcessorInterface[] */
78+
private $processors;
6579
}

0 commit comments

Comments
 (0)