Skip to content

Commit

Permalink
added interfaces' inheritance
Browse files Browse the repository at this point in the history
Added interfaces' inheritance and looking for methods in collection.
Separated scope processing from index processing
Added SaveCommand to dump current project to .padawan dir
  • Loading branch information
mkusher committed May 8, 2015
1 parent ed6e5b2 commit 1cc6b9c
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 27 deletions.
1 change: 1 addition & 0 deletions specs/completer/resolver/ContextResolver.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
expect($context->isObject())->to->be->false;
});
it('hasn\'t type object after object operator with TString and space', function(){
/** @var Context $context */
$context = $this->resolver->getContext('$var->param ');
expect($context->isObject())->to->be->false;
});
Expand Down
15 changes: 15 additions & 0 deletions src/Command/SaveCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Command;

class SaveCommand extends AbstractCommand {
public function run(array $arguments){
$project = $arguments["project"];
/** @var \IO\Writer $writer */
$writer = $this->get('IO\Writer');
$writer->write($project);
return [
'status' => 'ok'
];
}
}
14 changes: 8 additions & 6 deletions src/Complete/CompleteEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Complete\Resolver\ScopeResolver;
use Parser\Processor\IndexProcessor;
use Parser\Processor\ScopeProcessor;
use Parser\Processor\ProcessorInterface;
use Psr\Log\LoggerInterface;

class CompleteEngine {
Expand Down Expand Up @@ -102,7 +103,6 @@ protected function prepareContent($content, $line, $column){
}

/**
*
* @return Scope
*/
protected function processFileContent(Project $project, $lines, $line, $file){
Expand All @@ -127,18 +127,18 @@ protected function processFileContent(Project $project, $lines, $line, $file){
}
if(empty($scopeNodes)) {
$this->indexProcessor->clearResultNodes();
$this->scopeProcessor->clearResultNodes();
$this->scopeProcessor->setIndex($project->getIndex());
$this->scopeProcessor->setLine($line);
$parser = $this->parser;
$parser->addProcessor($this->indexProcessor);
$parser->addProcessor($this->scopeProcessor);
$nodes = $parser->parseContent($fqcn, $file, $content);
$this->generator->processFileNodes(
$project->getIndex(),
$nodes
);
$scopeNodes = $this->scopeProcessor->getResultNodes();
$this->scopeProcessor->setIndex($project->getIndex());
$this->scopeProcessor->setLine($line);
$this->scopeProcessor->clearResultNodes();
$parser->addProcessor($this->scopeProcessor);
$scopeNodes = $parser->parseContent($fqcn, $file, $content);
$contentHash = hash('sha1', $content);
$this->cachePool[$file] = [$contentHash, $nodes, $scopeNodes];
}
Expand All @@ -155,7 +155,9 @@ private function isValidCache($file, $content){
private $generator;
private $contextResolver;
private $completerFactory;
/** @property IndexProcessor */
private $indexProcessor;
/** @property ScopeProcessor */
private $scopeProcessor;
private $cachePool;
private $logger;
Expand Down
44 changes: 30 additions & 14 deletions src/Entity/Collection/MethodsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class MethodsCollection{
private $methods = [];
/** @property ClassData */
private $class;

public function __construct($class){
Expand All @@ -32,16 +33,24 @@ public function get($name, Specification $spec = null){
}
return null;
}
if($this->class instanceof InterfaceData){
return;
$parentSpec =new Specification(
$spec->getParentMode(),
$spec->isStatic(),
$spec->isMagic()
);
if($this->class instanceof ClassData){
$parent = $this->class->getParent();
if($parent instanceof ClassData){
return $parent->methods->get($name, $parentSpec);
}
}
$parent = $this->class->getParent();
if($parent instanceof ClassData){
return $parent->methods->get($name, new Specification(
$spec->getParentMode(),
$spec->isStatic(),
$spec->isMagic()
));
foreach($this->class->getInterfaces() as $interface){
if($interface instanceof InterfaceData){
$method = $interface->methods->get($name, $parentSpec);
if($method instanceof MethodData){
return $method;
}
}
}
}
public function all(Specification $spec = null){
Expand All @@ -54,20 +63,27 @@ public function all(Specification $spec = null){
$methods[$method->name] = $method;
}
}
$parentSpec = new Specification(
$spec->getParentMode(),
$spec->isStatic(),
$spec->isMagic()
);
if($this->class instanceof ClassData){
$parent = $this->class->getParent();
if($parent instanceof ClassData){
$parentM = $parent->methods->all(new Specification(
$spec->getParentMode(),
$spec->isStatic(),
$spec->isMagic()
));
$parentM = $parent->methods->all($parentSpec);
$methods = array_merge(
$parentM,
$methods
);
}
}
foreach($this->class->getInterfaces() as $interface){
if($interface instanceof InterfaceData){
$parentM = $interface->methods->all( $parentSpec);
$methods = array_merge($parentM, $methods);
}
}
return $methods;
}
}
9 changes: 7 additions & 2 deletions src/Entity/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getInterfaces(){

public function addClass(ClassData $class){
$this->classes[$class->fqcn->toString()] = $class;
if(!empty($class->getParent())){
if($class->getParent() instanceof FQCN){
$this->addExtend($class, $class->getParent());
}
foreach($class->getInterfaces() as $interface){
Expand All @@ -114,6 +114,11 @@ public function addInterface(InterfaceData $interface){
foreach($this->findInterfaceChildrenClasses($interface->fqcn) as $child){
$this->addImplement($child, $interface->fqcn);
}
foreach($interface->getInterfaces() as $parent){
if($parent instanceof FQCN){
$this->addImplement($interface, $parent);
}
}
}

public function addFQCN(FQCN $fqcn){
Expand Down Expand Up @@ -146,7 +151,7 @@ protected function addExtend(ClassData $class, FQCN $parent){
}
}

protected function addImplement(ClassData $class, FQCN $fqcn){
protected function addImplement($class, FQCN $fqcn){
$this->findInterfaceChildrenClasses($fqcn);
$this->implements[$fqcn->toString()][$class->fqcn->toString()] = $class;
$interface = $this->findInterfaceByFQCN($fqcn);
Expand Down
10 changes: 10 additions & 0 deletions src/Entity/Node/InterfaceData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ public function __construct(FQCN $fqcn, $file){
public function addMethod(MethodData $method){
$this->methods->add($method);
}
public function getInterfaces(){
return $this->interfaces;
}
public function addInterface($interface){
$fqcn = $interface;
if($interface instanceof InterfaceData){
$fqcn = $interface->fqcn;
}
$this->interfaces[$fqcn->toString()] = $interface;
}
}
19 changes: 15 additions & 4 deletions src/Parser/InterfaceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

class InterfaceParser {

public function __construct(MethodParser $methodParser){
public function __construct(
MethodParser $methodParser,
UseParser $useParser
){
$this->methodParser = $methodParser;
$this->useParser = $useParser;
}

/**
Expand All @@ -22,19 +26,26 @@ public function __construct(MethodParser $methodParser){
public function parse(Interface_ $node, FQN $fqn, $file)
{
$fqcn = new FQCN($node->name, $fqn);
$interace = new InterfaceData($fqcn, $file);
$interface = new InterfaceData($fqcn, $file);
foreach($node->extends AS $interfaceName){
$interface->addInterface(
$this->useParser->getFQCN($interfaceName)
);
}
foreach($node->stmts AS $child){
if($child instanceof ClassMethod){
$interace->addMethod($this->parseMethod($child));
$interface->addMethod($this->parseMethod($child));
}
}
return $interace;
return $interface;
}

protected function parseMethod(ClassMethod $node){
return $this->methodParser->parse($node);
}

/** @var UseParser */
private $useParser;
/**
* @property MethodParser
*/
Expand Down
5 changes: 4 additions & 1 deletion src/Router.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

class Router{

/**
* Finds command by its name
*
* @param $commandName String
* @param $arguments array
* @return Command\CommandInterface
* @return \Command\CommandInterface
*/
public function getCommand($commandName, array $arguments = []){
if ($commandName == 'generate') {
Expand All @@ -15,6 +16,8 @@ public function getCommand($commandName, array $arguments = []){
$command = new \Command\UpdateCommand;
} else if($commandName == 'complete'){
$command = new \Command\CompleteCommand;
} else if ($commandName == 'save'){
$command = new \Command\SaveCommand;
} else {
$command = new \Command\ErrorCommand;
}
Expand Down

0 comments on commit 1cc6b9c

Please sign in to comment.