Example #1
0
 /**
  * This method performs the parsing process of all source files. It expects
  * that the <b>$_builder</b> property was initialized with a concrete builder
  * implementation.
  *
  * @return void
  */
 private function performParseProcess()
 {
     // Reset list of thrown exceptions
     $this->parseExceptions = array();
     $tokenizer = new PHPTokenizerInternal();
     $this->fireStartParseProcess($this->builder);
     foreach ($this->createFileIterator() as $file) {
         $tokenizer->setSourceFile($file);
         $parser = new PHPParserGeneric($tokenizer, $this->builder, $this->cacheFactory->create());
         $parser->setMaxNestingLevel($this->configuration->parser->nesting);
         // Disable annotation parsing?
         if ($this->withoutAnnotations === true) {
             $parser->setIgnoreAnnotations();
         }
         $this->fireStartFileParsing($tokenizer);
         try {
             $parser->parse();
         } catch (\PDepend\Source\Parser\ParserException $e) {
             $this->parseExceptions[] = $e;
         }
         $this->fireEndFileParsing($tokenizer);
     }
     $this->fireEndParseProcess($this->builder);
 }
 /**
  * Parses the given test file and then returns the builder instance.
  *
  * @param string $file Relative path to a test file for the calling test.
  * @return \PDepend\Source\Builder\Builder
  */
 protected function parseSourceAndReturnBuilder($file)
 {
     copy(self::createCodeResourceUriForTest() . '/' . $file, $this->testFile);
     $cache = new FileCacheDriver($this->cacheDir);
     $tokenizer = new PHPTokenizerInternal();
     $tokenizer->setSourceFile($this->testFile);
     $builder = new PHPBuilder();
     $builder->setCache($cache);
     $parser = new PHPParserGeneric($tokenizer, $builder, $cache);
     $parser->parse();
     return $builder;
 }
 /**
  * testParserStopsProcessingWhenCacheContainsValidResult
  *
  * @return void
  */
 public function testParserStopsProcessingWhenCacheContainsValidResult()
 {
     $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder');
     $tokenizer = new PHPTokenizerInternal();
     $tokenizer->setSourceFile(__FILE__);
     $cache = $this->createCacheFixture();
     $cache->expects($this->once())->method('restore')->will(self::returnValue(true));
     $cache->expects($this->never())->method('store');
     $parser = new PHPParserGeneric($tokenizer, $builder, $cache);
     $parser->parse();
 }
 /**
  * Parses the given source file or directory with the default tokenizer
  * and node builder implementations.
  *
  * @param string  $fileOrDirectory
  * @param boolean $ignoreAnnotations
  * @return \PDepend\Source\AST\ASTNamespace[]
  */
 public static function parseSource($fileOrDirectory, $ignoreAnnotations = false)
 {
     if (file_exists($fileOrDirectory) === false) {
         $fileOrDirectory = self::createCodeResourceURI($fileOrDirectory);
     }
     if (is_dir($fileOrDirectory)) {
         $it = new Iterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fileOrDirectory)), new ExcludePathFilter(array('.svn')));
     } else {
         $it = new \ArrayIterator(array($fileOrDirectory));
     }
     $files = array();
     foreach ($it as $file) {
         if (is_object($file)) {
             $files[] = realpath($file->getPathname());
         } else {
             $files[] = $file;
         }
     }
     sort($files);
     $cache = new MemoryCacheDriver();
     $builder = new PHPBuilder();
     foreach ($files as $file) {
         $tokenizer = new PHPTokenizerInternal();
         $tokenizer->setSourceFile($file);
         $parser = new PHPParserGeneric($tokenizer, $builder, $cache);
         if ($ignoreAnnotations === true) {
             $parser->setIgnoreAnnotations();
         }
         $parser->parse();
     }
     return $builder->getNamespaces();
 }