Macro/投稿/175
をテンプレートにして作成
Land.to
[
ホーム
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
* PHP \& JS向けのxDocコメント作成 [#o6ca37d8]
-ページ: [[Macro/投稿]]
-作者: [[てふてふ]]
-カテゴリー: js
-投稿日: 2007-09-24 (月) 20:53:38
** メッセージ [#jf90348c]
JavaDocのようなコメントを生成します。
PHPやJavaScriptなど、関数宣言に型を使わない言語専用です。
(Javaはだめ)
関数・クラス・変数・ファイルヘッダ対応のつもり。
あえてJSぽく書いてみました。
----
#code(javascript){{
/**
* サクラエディタマクロ
* PHP・JS向けxDoc風コメント作成
* @author てふてふさん
* @license http://www.opensource.org/licenses/gpl-licens...
* @version 1.0
* @link
* @since sakura:1.5.5.0
* @see 似たようなのがあったので参考にしました
* @see → doxgen用のコメントを付加
* @see http://sakura.qp.land.to/?Macro%2F%C5%EA%B9%C6%2...
*
* 起動方法:対象となる function や class 行の上でマクロ...
* 種別 :JScript
*/
// 改行コードの取得
var cr = ["\x0d\x0a", "\x0a", "\x0a"][Editor.GetLineCode(...
d("cr:「" + cr + "」");
/**
* デバッグ出力
* @param s 文字列
*/
function d(s) {
// Editor.AddTail(s + cr);
}
/**
* オブジェクトの要素表示(デバッグ)
* @param o オブジェクト
*/
function inspect(o) {
var s = "";
for (key in o) {
s += key + " => " + o[key].toString() + cr;
}
d(s);
}
/**
* スクリプト離脱
* @throw number=0の例外オブジェクト
* @param s メッセージ
*/
function exit(s) {
throw {number: 0, message: s};
}
/**
* ファイルヘッダを出力する
*/
function fileHeader() {
out.put("/**" + cr);
out.put(" * " + cr);
// 以下、不要なものはコメントアウトしてください。
out.put(" * @package " + cr);
out.put(" * @author " + cr);
out.put(" * @copyright " + cr);
out.put(" * @license " + cr);
out.put(" * @version " + cr);
out.put(" * @filesource " + cr);
out.put(" * @link " + cr);
out.put(" * @see " + cr);
out.put(" * @since " + cr);
out.put(" */" + cr);
out.flush();
up(out.line - 1);
Editor.GoLineEnd();
exit("ファイルヘッダ出力");
}
/**
* カーソルを上に移動
* @return
* @param n 移動回数
*/
function up(n) {
if (n > 0) {
for (var i = 0; i < n; i++) {
Editor.Up();
}
} else if (n < 0) {
for (var i = 0; i > n; i--) {
Editor.Down();
}
}
}
try {
/**
* @var out 出力コメントオブジェクト
*/
var out = {
line: 0, /* 出力行数 */
/**
* コメント行追加
* @param s 行。改行は自分で付加すること。
*/
put: function(s) {
this[this.line++] = s;
},
/**
* コメント行出力
*/
flush: function() {
Editor.GoLineTop(1);
out.buf = "";
for (var i = 0; i < out.line; i++) {
out.buf += out[i];
}
Editor.InsText(out.buf);
}
};
// カーソル行取得
var line = Editor.GetLineStr(0);
if (line.length == 0) {
exit("line.len = 0");
}
// 行番号取得
Editor.GoLineTop();
Editor.GoLineEnd_Sel();
var lineno = Editor.GetSelectLineFrom().toString();
// 1、2行目のときは、ファイルヘッダを出す。
if (lineno <= 2) {
fileHeader();
exit("ファイルヘッダ出力");
}
// 行をトークンわけする
var norm = line.match(/[\$a-zA-Z0-9_]+|\(|\)/g).toStrin...
d("norm:" + norm);
var tok = norm.split(",");
if (tok.length == 0) {
exit("tok.len = 0");
}
// インデントの取得
var head = line.search(tok[0]);
d("head:" + head);
var indent = line.slice(0, head);
d("indent:「" + indent + "」");
out.put(indent + "/**" + cr);
// コメントの作成
if (tok[0] == "function") {
// 関数
out.put(indent + " * " + cr);
out.put(indent + " * @return " + cr);
out.put(indent + " * @throws " + cr);
for (var i = 3; i < tok.length && tok[i] != ")"; i++) {
out.put(indent + " * @param " + tok[i] + " " + cr);
}
} else if (tok[0] == "class") {
// クラス
out.put(indent + " * " + cr);
out.put(indent + " * @package " + cr);
} else if (tok[0] == "var") {
// 変数
out.put(indent + " * " + cr);
out.put(indent + " * @var"
+ (tok.length > 1 ? " " + tok[1] : "") + " " ...
} else {
// 空のコメント
out.put(indent + " * " + cr);
}
out.put(indent + " */" + cr);
// コメントの出力
out.flush();
// カーソル移動
up(out.line - 1);
Editor.GoLineEnd();
d("正常終了");
} catch (e) {
if (e.number == 0) {
d("離脱:" + e.message);
} else {
d(cr + e.name + ": " + e.description);
d("エラー終了");
}
}
}}
#comment
終了行:
* PHP \& JS向けのxDocコメント作成 [#o6ca37d8]
-ページ: [[Macro/投稿]]
-作者: [[てふてふ]]
-カテゴリー: js
-投稿日: 2007-09-24 (月) 20:53:38
** メッセージ [#jf90348c]
JavaDocのようなコメントを生成します。
PHPやJavaScriptなど、関数宣言に型を使わない言語専用です。
(Javaはだめ)
関数・クラス・変数・ファイルヘッダ対応のつもり。
あえてJSぽく書いてみました。
----
#code(javascript){{
/**
* サクラエディタマクロ
* PHP・JS向けxDoc風コメント作成
* @author てふてふさん
* @license http://www.opensource.org/licenses/gpl-licens...
* @version 1.0
* @link
* @since sakura:1.5.5.0
* @see 似たようなのがあったので参考にしました
* @see → doxgen用のコメントを付加
* @see http://sakura.qp.land.to/?Macro%2F%C5%EA%B9%C6%2...
*
* 起動方法:対象となる function や class 行の上でマクロ...
* 種別 :JScript
*/
// 改行コードの取得
var cr = ["\x0d\x0a", "\x0a", "\x0a"][Editor.GetLineCode(...
d("cr:「" + cr + "」");
/**
* デバッグ出力
* @param s 文字列
*/
function d(s) {
// Editor.AddTail(s + cr);
}
/**
* オブジェクトの要素表示(デバッグ)
* @param o オブジェクト
*/
function inspect(o) {
var s = "";
for (key in o) {
s += key + " => " + o[key].toString() + cr;
}
d(s);
}
/**
* スクリプト離脱
* @throw number=0の例外オブジェクト
* @param s メッセージ
*/
function exit(s) {
throw {number: 0, message: s};
}
/**
* ファイルヘッダを出力する
*/
function fileHeader() {
out.put("/**" + cr);
out.put(" * " + cr);
// 以下、不要なものはコメントアウトしてください。
out.put(" * @package " + cr);
out.put(" * @author " + cr);
out.put(" * @copyright " + cr);
out.put(" * @license " + cr);
out.put(" * @version " + cr);
out.put(" * @filesource " + cr);
out.put(" * @link " + cr);
out.put(" * @see " + cr);
out.put(" * @since " + cr);
out.put(" */" + cr);
out.flush();
up(out.line - 1);
Editor.GoLineEnd();
exit("ファイルヘッダ出力");
}
/**
* カーソルを上に移動
* @return
* @param n 移動回数
*/
function up(n) {
if (n > 0) {
for (var i = 0; i < n; i++) {
Editor.Up();
}
} else if (n < 0) {
for (var i = 0; i > n; i--) {
Editor.Down();
}
}
}
try {
/**
* @var out 出力コメントオブジェクト
*/
var out = {
line: 0, /* 出力行数 */
/**
* コメント行追加
* @param s 行。改行は自分で付加すること。
*/
put: function(s) {
this[this.line++] = s;
},
/**
* コメント行出力
*/
flush: function() {
Editor.GoLineTop(1);
out.buf = "";
for (var i = 0; i < out.line; i++) {
out.buf += out[i];
}
Editor.InsText(out.buf);
}
};
// カーソル行取得
var line = Editor.GetLineStr(0);
if (line.length == 0) {
exit("line.len = 0");
}
// 行番号取得
Editor.GoLineTop();
Editor.GoLineEnd_Sel();
var lineno = Editor.GetSelectLineFrom().toString();
// 1、2行目のときは、ファイルヘッダを出す。
if (lineno <= 2) {
fileHeader();
exit("ファイルヘッダ出力");
}
// 行をトークンわけする
var norm = line.match(/[\$a-zA-Z0-9_]+|\(|\)/g).toStrin...
d("norm:" + norm);
var tok = norm.split(",");
if (tok.length == 0) {
exit("tok.len = 0");
}
// インデントの取得
var head = line.search(tok[0]);
d("head:" + head);
var indent = line.slice(0, head);
d("indent:「" + indent + "」");
out.put(indent + "/**" + cr);
// コメントの作成
if (tok[0] == "function") {
// 関数
out.put(indent + " * " + cr);
out.put(indent + " * @return " + cr);
out.put(indent + " * @throws " + cr);
for (var i = 3; i < tok.length && tok[i] != ")"; i++) {
out.put(indent + " * @param " + tok[i] + " " + cr);
}
} else if (tok[0] == "class") {
// クラス
out.put(indent + " * " + cr);
out.put(indent + " * @package " + cr);
} else if (tok[0] == "var") {
// 変数
out.put(indent + " * " + cr);
out.put(indent + " * @var"
+ (tok.length > 1 ? " " + tok[1] : "") + " " ...
} else {
// 空のコメント
out.put(indent + " * " + cr);
}
out.put(indent + " */" + cr);
// コメントの出力
out.flush();
// カーソル移動
up(out.line - 1);
Editor.GoLineEnd();
d("正常終了");
} catch (e) {
if (e.number == 0) {
d("離脱:" + e.message);
} else {
d(cr + e.name + ": " + e.description);
d("エラー終了");
}
}
}}
#comment
ページ名: