phpDoc和代码完成通过' - >' NetBeans 8.0中的T_OBJECT_OPERATOR

时间:2014-04-24 11:32:27

标签: php netbeans phpdoc

如何使用T_OBJECT_OPERATOR加载的phpDoc块完成代码完成,而不必预设变量,如下所示:

唯一重要的类是parentExample,因为它设置了提供有效解决方案的所需$cc,但不希望以这种方式预设变量。

示例代码显示了不需要的解决方案和多次非工作尝试。

由于代码完成基于先前设置的信息,因此首选使用完整的示例脚本而不仅仅是片段。此外,因为它与phpDocumentor有关,所以也包括基本的phpDoc块。希望这些docBlocks作为代码完成的一部分加载,而不仅仅是命名对象。

<?php
/**
 * This is a parent class.
 * 
 * @package Examples/doubledVars
 */
class parentExample 
{   
    /* @var $a parentExample */
    public $a;

    /**
     * This is a var named b
     * @var $b parentExample
     */
    public $b;

    public $c;
    public $cc;
    // notice^ <------------------------------------------------------SEE ME

    /**
     * A basic contructor
     */
    public function __construct() 
    { 
        echo '::PE Class initiated::'; 

        $this -> a = 'we are value "a" in the parent class'; 
        $this -> b = 'we are value "b"  in the parent class'; 
        $this -> c = 'we are value "c"  in the parent class'; 
    }
} 

/**
 * This is an Example of doubling occuring due to failed to __construct()
 * 
 * @package Examples/doubledVars
 */
class doubledVars extends parentExample 
{   
    /**
     * Value is obtained via parent constuctor.
     * 
     * @return string assigned during construction of parent class.
     */
    public function getA() 
    { 
        return $this -> a; 
    } 
}

/**
 * This is an Example of no doubling occuring due to __construct()
 * 
 * @package Examples/doubledVars
 */
class noDouble extends parentExample 
{  
    /**
     * an empty constructor used to prevent doubling during construction.
     * child class makes use of parent constructor unless it has it's own.
     * or none exsist.
     */
    public function __construct() 
    { 

    } 

    /**
     * Empty string return
     * 
     * Shows an example of returning values set based on the constructor 
     * class. In this case there is no default values set at any point, but
     * rather value is assigned during the construction of a object.
     * 
     * @return string This string is empty
     */
    public function getB() 
    { 
        return $this -> b; 
    } 
} 

/**
 * This is an Example of no doubling occuring due to __construct()
 * @see noDouble
 * 
 * @package Examples/codeCompletion
 */
class codeCompletion extends parentExample 
{  
    /**
     * @see noDouble::__construct()
     */
    public function __construct() 
    { 
        //empty constructor prevents doubling
    }


    public function getC() 
    { 
        return $this -> c; 
    } 
}


/** @var $parentExampleDV parentExample */
$parentExampleDV = new parentExample;

// Tried this for Code completion, it did not work <------------------SEE ME
/** @var $doubledVars doubledVars */
$parentExampleDV->doubledVars = new doubledVars; 

/* output on next 'echo' will be as follows */
//::PE Class initiated::::PE Class initiated::we are in the parent class
echo '@@'.$parentExampleDV->doubledVars->getA().'@@';// NO CC <-------SEE ME

echo '<br><br>----------<br><br>';


/** @var $parentExampleDV parentExample */
$parentExampleND = new parentExample;

// Tried this for Code completion, it did not work <------------------SEE ME
/** @var $parentExample->noDouble noDouble */
$parentExampleND -> noDouble = new noDouble;

/* output on next 'echo' will be as follows */
//we are in the parent class
echo '!!'.$parentExampleND->noDouble->getB().'!!';// NO CC <----------SEE ME

echo '<br><br>----------<br><br>';

$parentExampleCC = new parentExample;

$parentExampleCC->cc = new codeCompletion;

echo '##'.$parentExampleCC->cc->getC().'##';//CC working <------------SEE ME

echo '<br><br>----------<br><br>';

1 个答案:

答案 0 :(得分:0)

我想现在不可能......