示例#1
0
 /**
  * Builds a new method instance.
  *
  * @param  string $name
  * @return \PDepend\Source\AST\ASTMethod
  */
 public function buildMethod($name)
 {
     $this->checkBuilderState();
     // Debug method creation
     Log::debug("Creating: \\PDepend\\Source\\AST\\ASTMethod({$name})");
     // Create a new method instance
     $method = new ASTMethod($name);
     $method->setCache($this->cache);
     return $method;
 }
示例#2
0
 /**
  * Generates an identifier for the given method instance.
  *
  * @param  \PDepend\Source\AST\ASTMethod $method
  * @return string
  */
 public function forMethod(ASTMethod $method)
 {
     return sprintf('%s-%s', $method->getParent()->getId(), $this->hash(strtolower($method->getName())));
 }
示例#3
0
 /**
  * Visits the given method.
  *
  * @param  \PDepend\Source\AST\ASTMethod $method
  * @return void
  */
 public function visitMethod(ASTMethod $method)
 {
     if ($method->isAbstract() === false) {
         $this->visitCallable($method);
     }
 }
 /**
  * Visits a method node.
  *
  * @param \PDepend\Source\AST\ASTMethod $method
  * @return void
  */
 public function visitMethod(ASTMethod $method)
 {
     $this->visits[] = $method->getName();
     parent::visitMethod($method);
 }
示例#5
0
    /**
     * Adds the given method to this type.
     *
     * @param \PDepend\Source\AST\ASTMethod $method
     * @return \PDepend\Source\AST\ASTMethod
     */
    public function addMethod(ASTMethod $method)
    {
        $method->setParent($this);

        $this->methods[] = $method;

        return $method;
    }
示例#6
0
    /**
     * Visits a method node.
     *
     * @param \PDepend\Source\AST\ASTMethod $method
     * @return void
     */
    public function visitMethod(ASTMethod $method)
    {
        $xml = end($this->xmlStack);
        $doc = $xml->ownerDocument;

        $methodXml = $doc->createElement('method');
        $methodXml->setAttribute('name', $method->getName());

        $this->writeNodeMetrics($methodXml, $method);

        $xml->appendChild($methodXml);
    }
示例#7
0
 /**
  * Returns an <b>array</b> with all aliases for the given method. If no
  * alias exists for the given method, this method will simply return the
  * an <b>array</b> with the original method.
  *
  * @param  \PDepend\Source\AST\ASTMethod $method
  * @return \PDepend\Source\AST\ASTMethod[]
  */
 private function getAliasesFor(ASTMethod $method)
 {
     $name = strtolower($method->getName());
     $newNames = array();
     foreach ($this->getAliases() as $alias) {
         $name2 = strtolower($alias->getImage());
         if ($name2 !== $name) {
             continue;
         }
         $modifier = $method->getModifiers();
         if (-1 < $alias->getNewModifier()) {
             $modifier &= ~(State::IS_PUBLIC | State::IS_PROTECTED | State::IS_PRIVATE);
             $modifier |= $alias->getNewModifier();
         }
         $newName = $method->getName();
         if ($alias->getNewName()) {
             $newName = $alias->getNewName();
         }
         if (0 === count($alias->getChildren())) {
             $newMethod = clone $method;
             $newMethod->setName($newName);
             $newMethod->setModifiers($modifier);
             $newNames[] = $newMethod;
             continue;
         }
         if ($alias->getChild(0)->getType() !== $method->getParent()) {
             continue;
         }
         $newMethod = clone $method;
         $newMethod->setName($newName);
         $newMethod->setModifiers($modifier);
         $newNames[] = $newMethod;
     }
     if (count($newNames) > 0) {
         return $newNames;
     }
     return array($method);
 }
示例#8
0
文件: Xml.php 项目: pdepend/pdepend
 /**
  * Visits a method node.
  *
  * @param  \PDepend\Source\AST\ASTMethod $method
  * @return void
  */
 public function visitMethod(ASTMethod $method)
 {
     $xml = end($this->xmlStack);
     $doc = $xml->ownerDocument;
     $methodXml = $doc->createElement('method');
     $methodXml->setAttribute('name', Utf8Util::ensureEncoding($method->getName()));
     $methodXml->setAttribute('start', Utf8Util::ensureEncoding($method->getStartLine()));
     $methodXml->setAttribute('end', Utf8Util::ensureEncoding($method->getEndLine()));
     $this->writeNodeMetrics($methodXml, $method);
     $xml->appendChild($methodXml);
 }
示例#9
0
文件: Parser.php 项目: flavius/phpmd
 /**
  * Visits a method node.
  *
  * @param \PDepend\Source\AST\ASTMethod $node
  * @return void
  */
 public function visitMethod(ASTMethod $node)
 {
     if ($node->getCompilationUnit()->getFileName() === null) {
         return;
     }
     $this->apply(new MethodNode($node));
 }
 /**
  * Creates an abstract item instance.
  *
  * @return \PDepend\Source\AST\AbstractASTArtifact
  */
 protected function createItem()
 {
     $method = new ASTMethod('method');
     $method->setCompilationUnit(new ASTCompilationUnit(__FILE__));
     return $method;
 }
 /**
  * testBuilderCreatesCaseInSensitiveMethodIdentifiers
  *
  * @return void
  */
 public function testBuilderCreatesCaseInSensitiveMethodIdentifiers()
 {
     $compilationUnit = new ASTCompilationUnit(__FILE__);
     $compilationUnit->setId(__FUNCTION__);
     $class = new ASTClass(__FUNCTION__);
     $class->setCompilationUnit($compilationUnit);
     $method0 = new ASTMethod(__FUNCTION__);
     $method0->setParent($class);
     $method1 = new ASTMethod(strtolower(__FUNCTION__));
     $method1->setParent($class);
     $builder0 = new IdBuilder();
     $builder1 = new IdBuilder();
     $this->assertEquals($builder0->forMethod($method0), $builder1->forMethod($method1));
 }
 /**
  * Creates a ready to use method fixture.
  *
  * @param string $name Optional method name.
  * @return \PDepend\Source\AST\ASTMethod
  * @since 1.0.2
  */
 protected function createMethodFixture($name = null)
 {
     $name = $name ? $name : get_class($this);
     $method = new ASTMethod($name);
     $method->setCache(new MemoryCacheDriver());
     $method->addChild(new ASTFormalParameters());
     return $method;
 }