zhaohua0317 发表于 2012-7-3 10:20:31

送上一个自己写的netbeans用的代码补全插件


一直在ci论坛拿东西,今天送给大家一个代码补全插件,希望大家可以喜欢。这个插件是在某先人的CI_Autocomplete_2.0基础上开发的,思路就是重写CI_Autocomplete_2.0文件,再让netbeans读取。
不多说 代码呈上:
index.php

<?php
$filearr = file('CI_Autocomplete_2.0.php');
$startpos = array();
$conpos = 0;
$modpos=0;
getpos($startpos, $conpos, $modpos, $filearr);
$model = '';
$lib = '';
$resultnames = array();
//getdirfilesname('../application/models');
$filesmodel = ListFiles('../application/models');
$fileslib = ListFiles('../application/libraries');
$tets=filenamechange($filesmodel);
$resultnames = array_merge(filenamechange($filesmodel), filenamechange($fileslib));//过滤到index并且得到字符串
//$insertarr=array();
//var_dump($resultnames);
array_splice($filearr, $startpos + 1, $conpos - $startpos - 3, $resultnames);
getpos($startpos, $conpos, $modpos, $filearr);
$porarr=array_slice($filearr, 3, $conpos-5);
array_splice($filearr, $conpos+3, $modpos - $conpos - 5, $porarr);
$resultstr = "";
for ($i = 0; $i < count($filearr); $i++) {
    $temstr = $filearr[$i];
    //   var_dump($filearr[$i]);
    $resultstr.=$temstr;
}
///$resultstr=implode(" ", $filearr);
//var_dump($resultstr);
//写入文件
//file_put_contents ( string filename, string data [, int flags [, resource context]])
if (file_exists('CI_Autocomplete_2.0.php')) {
    unlink('CI_Autocomplete_2.0.php');
}
file_put_contents('CI_Autocomplete_2.0.php', $resultstr);
echo '<html><head>';
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title></title>';
echo '</head><body>';
echo '<p align="center">转换完成!</p></body></html>';
//var_dump($files);
//scandir//();
//var_dump($startpos.' '.$endpos);
//$start=array_search('* @property CI_Zip $zip\n', $filearr);
//array_splice(array,offset,length,array);
//var_dump($start);
//var_dump($filearr);
//var_dump($filearr);
function getdirfilesname($dir) {
    $namearr = scandir($dir);
    $namearr = array_diff($namearr, array('..', '.'));
    var_dump($namearr);
}
function ListFiles($dir) {
    if ($dh = opendir($dir)) {
      $files = Array();
      $inner_files = Array();
      while ($file = readdir($dh)) {
            if ($file != "." && $file != ".." && $file != '.') {
                if (is_dir($dir . "/" . $file)) {
                  $inner_files = ListFiles($dir . "/" . $file);
                  if (is_array($inner_files))
                        $files = array_merge($files, $inner_files);
                } else {
                  //    array_push($files, $dir . "/" . $file);
                  array_push($files, $file);
                }
            }
      }
      closedir($dh);
      return $files;
    }
}
function filenamechange($filesname, $ucfirst=0) {
    $count=count($filesname);
    for ($i = 0; $i <$count ; $i++) {
      //$startpos=strrpos($filearr[$i],$startstr)===FALSE?continue:
      if (strrpos($filesname[$i], 'ndex.html'))
            unset($filesname[$i]);
      if (isset($filesname[$i])) {
            $filesname[$i] = str_ireplace('.php', '', $filesname[$i]);
            //   $resultnames[$i]['name']=ucfirst($filesname[$i]);
            //$resultnames[$i]['value']='$'.$filesname[$i];
            if ($ucfirst) {
                $resultnames[] = "* @property " . ucfirst($filesname[$i]) . " $" . ucfirst($filesname[$i]) . "\r\n";
            }else
                $resultnames[] = "* @property " . ucfirst($filesname[$i]) . " $" . strtolower($filesname[$i]) . "\r\n"; //* @property Kslevel $kslevel

//$filesname[$i]=strtr($filesname[$i],'php',' ' );
      }
    }
    return $resultnames;
}
function getpos(&$startpos,&$conpos,&$modpos,$filearr) {
    $startstr = '* @property CI_Zip $zip';
$constr = 'class CI_Controller {};';
$modstr='class CI_Model {};';
    for ($i = 0; $i < count($filearr); $i++) {//找到位置
    //$startpos=strrpos($filearr[$i],$startstr)===FALSE?continue:
    if (strrpos($filearr[$i], $startstr) !== FALSE)
      $startpos[] = $i;
    if (strrpos($filearr[$i], $constr) !== FALSE)
      $conpos = $i;
      if (strrpos($filearr[$i], $modstr) !== FALSE)
      $modpos = $i;
}
//echo 'OK';
}
?>


CI_Autocomplete_2.0.php

<?php
/**
* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge
* @property CI_Benchmark $benchmark
* @property CI_Calendar $calendar
* @property CI_Cart $cart
* @property CI_Config $config
* @property CI_Controller $controller
* @property CI_Email $email
* @property CI_Encrypt $encrypt
* @property CI_Exceptions $exceptions
* @property CI_Form_validation $form_validation
* @property CI_Ftp $ftp
* @property CI_Hooks $hooks
* @property CI_Image_lib $image_lib
* @property CI_Input $input
* @property CI_Language $language
* @property CI_Loader $load
* @property CI_Log $log
* @property CI_Model $model
* @property CI_Output $output
* @property CI_Pagination $pagination
* @property CI_Parser $parser
* @property CI_Profiler $profiler
* @property CI_Router $router
* @property CI_Session $session
* @property CI_Sha1 $sha1
* @property CI_Table $table
* @property CI_Trackback $trackback
* @property CI_Typography $typography
* @property CI_Unit_test $unit_test
* @property CI_Upload $upload
* @property CI_URI $uri
* @property CI_User_agent $user_agent
* @property CI_Validation $validation
* @property CI_Xmlrpc $xmlrpc
* @property CI_Xmlrpcs $xmlrpcs
* @property CI_Zip $zip
* @property User_group_m $user_group_m
* @property M_role $m_role
* @property M_1 $m_1
* @property M_kaojuan $m_kaojuan
* @property Ml_shijuan $ml_shijuan
* @property M_makekj $m_makekj
* @property M_kaoshi $m_kaoshi
* @property M_shitimanage $m_shitimanage
* @property Ml_class $ml_class
* @property Ion_auth_model $ion_auth_model
* @property Exam_shiti_duoxuan_data_m $exam_shiti_duoxuan_data_m
* @property Exam_kaojuan_base_m $exam_kaojuan_base_m
* @property Exam_tixing_m $exam_tixing_m
* @property Exam_shititype_m $exam_shititype_m
* @property Exam_shiti_main_m $exam_shiti_main_m
* @property Exam_tiku_m $exam_tiku_m
* @property Exam_class_m $exam_class_m
* @property X_m_1_1 $x_m_1_1
* @property X_m_1_2 $x_m_1_2
* @property Exam_shiti_danxuan_data_m $exam_shiti_danxuan_data_m
* @property Exam_shijuan_base_m $exam_shijuan_base_m
* @property Ion_group_ext_m $ion_group_ext_m
* @property User_department_m $user_department_m
* @property Exam_shijuantype_m $exam_shijuantype_m
* @property Ion_group_m $ion_group_m
* @property Exam_kaojuan_data_m $exam_kaojuan_data_m
* @property Layout $layout
* @property Ion_auth $ion_auth
* @property Level_1_1 $level_1_1
* @property Level $level
* @property Kslevel $kslevel
* @property Msgexpection $msgexpection
*/
class CI_Controller {};
/**
* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge
* @property CI_Benchmark $benchmark
* @property CI_Calendar $calendar
* @property CI_Cart $cart
* @property CI_Config $config
* @property CI_Controller $controller
* @property CI_Email $email
* @property CI_Encrypt $encrypt
* @property CI_Exceptions $exceptions
* @property CI_Form_validation $form_validation
* @property CI_Ftp $ftp
* @property CI_Hooks $hooks
* @property CI_Image_lib $image_lib
* @property CI_Input $input
* @property CI_Language $language
* @property CI_Loader $load
* @property CI_Log $log
* @property CI_Model $model
* @property CI_Output $output
* @property CI_Pagination $pagination
* @property CI_Parser $parser
* @property CI_Profiler $profiler
* @property CI_Router $router
* @property CI_Session $session
* @property CI_Sha1 $sha1
* @property CI_Table $table
* @property CI_Trackback $trackback
* @property CI_Typography $typography
* @property CI_Unit_test $unit_test
* @property CI_Upload $upload
* @property CI_URI $uri
* @property CI_User_agent $user_agent
* @property CI_Validation $validation
* @property CI_Xmlrpc $xmlrpc
* @property CI_Xmlrpcs $xmlrpcs
* @property CI_Zip $zip
* @property User_group_m $user_group_m
* @property M_role $m_role
* @property M_1 $m_1
* @property M_kaojuan $m_kaojuan
* @property Ml_shijuan $ml_shijuan
* @property M_makekj $m_makekj
* @property M_kaoshi $m_kaoshi
* @property M_shitimanage $m_shitimanage
* @property Ml_class $ml_class
* @property Ion_auth_model $ion_auth_model
* @property Exam_shiti_duoxuan_data_m $exam_shiti_duoxuan_data_m
* @property Exam_kaojuan_base_m $exam_kaojuan_base_m
* @property Exam_tixing_m $exam_tixing_m
* @property Exam_shititype_m $exam_shititype_m
* @property Exam_shiti_main_m $exam_shiti_main_m
* @property Exam_tiku_m $exam_tiku_m
* @property Exam_class_m $exam_class_m
* @property X_m_1_1 $x_m_1_1
* @property X_m_1_2 $x_m_1_2
* @property Exam_shiti_danxuan_data_m $exam_shiti_danxuan_data_m
* @property Exam_shijuan_base_m $exam_shijuan_base_m
* @property Ion_group_ext_m $ion_group_ext_m
* @property User_department_m $user_department_m
* @property Exam_shijuantype_m $exam_shijuantype_m
* @property Ion_group_m $ion_group_m
* @property Exam_kaojuan_data_m $exam_kaojuan_data_m
* @property Layout $layout
* @property Ion_auth $ion_auth
* @property Level_1_1 $level_1_1
* @property Level $level
* @property Kslevel $kslevel
* @property Msgexpection $msgexpection
*/
class CI_Model {};
?>

按我的格式和文件名把这两个文件放到项目文件根目录的nbproject文件夹下面,
运行index.php如:http://localhost/CI_IONTH/nbproject/index.php
重启netbeans。试试写$this->看后面出现什么!

项目目录:

自动补全代码:

hcsch1 发表于 2015-6-24 21:41:08

绛色红缨 发表于 2014-8-20 11:53
netbeans 8.0好象不起作用.

好像的确是。不知是netbeans8的问题还是CI3.0的问题。

绛色红缨 发表于 2014-8-20 11:53:55

netbeans 8.0好象不起作用.

maxud 发表于 2014-9-3 17:08:39

确实好东西,谢谢分享!

zhaohua0317 发表于 2012-7-3 10:24:29

忘了说了 这个小东东的功能是能够让你在$this->之后出现项目下所有的LIBRARY和model,应该比较实用。喜欢吧。嘻嘻。

SHIFT+DEL 发表于 2012-8-10 11:39:03

这么好的东东,怎么没有人顶呢,收了哈,谢谢楼主的奉献。

binarx 发表于 2012-8-11 14:46:27

谢谢楼主

(忞)忞)+(忟( 发表于 2012-8-25 12:09:08

你代码写的够多时,就不会在意这样的插件了$this->后面才几种呀,记都记住了。倒是我用sublime text 2 写view层页面时,那个方便啊
输入 echo 按TAB 就出来<?php echo $var ?>;类似还有很多,它是我用的最爽的编辑器,没有之一

loveinlove 发表于 2012-8-30 01:02:58

(忞)忞)+(忟( 发表于 2012-8-25 12:09 static/image/common/back.gif
你代码写的够多时,就不会在意这样的插件了$this->后面才几种呀,记都记住了。倒是我用sublime text 2 写vi ...

那是你没用过textmate 1 ,sublime也以兼容textmate 的 bundle 为亮点之一。

另外sublime2碰到 非utf8的文档也只有哭的份。

lnlingyuan 发表于 2012-9-4 21:55:10

不错

android_zhu 发表于 2013-4-11 16:14:40

围观中,学习下,谢谢楼主
页: [1] 2
查看完整版本: 送上一个自己写的netbeans用的代码补全插件