スタイラー
お勧めのスタンダードに沿ってソースコードのデザインを素早く提供します。 これより、コードはプロフェッショナルで読みやすいものになります。 適切に設計されたコードは、その作成者と他のユーザーの両方にとって、将来有用です。 起動する
ツールのスタイラーCtrl キーを押しながらクリックします。
- コードデザインの変更は、元に戻すことができます。 利用できるオプションを一覧にするには、
Editメニューの元に戻すまたは Ctrl + Z キーを押します。
- スタイラーではさまざまなコーディング標準をサポートしています。スタイルはエディタ設定で変更できます。推奨されるMetaQuotesスタイルのデザインルールについては、以下で詳しく説明します。
一般
次のアクションは、コードを適切にフォーマットするために提供されます。
- 特定のラインを指定したものに置き換える。
- 言語演算子の整列
- ファイルヘッダへのコメントの挿入;
- 関数、構造体、クラス、およびそのメソッドの前にコメントを挿入します。
- ファイルの最後にコメントを挿入します。
上記のタイプのアクションに基づいて、以下の調整が行われます。
スペースと空白行
不必要なスペース文字を削除すると、コードをよりコンパクトにして見た目を向上させることができます。 また、サードパーティ製のプログラムで開いたときの書式の歪みを回避するために、各タブ文字が3つのスペースに置き換えられます。
スタイラーはスペースを削除します
- At the end of lines;
- Before ";";
- Between "if" and "(", "while" and "(", "for" and "(", "switch" and "(", "return" and "(".
- After ";" inside "for()";
- After "!";
- Near "(" and ")";
- Near "<" and ">";
- Near "|" and "^";
- Near "+", "-", "/" and "%";
- Near "[" and "]";
- Near "==" and "==";
- Near "!=" and "!=";
- Near "<=" and ">=";
- Near "+=" and "+=";
- Near "-=" and "-=";
- Near "*=" and "*=";
- Near "/=" and "/=";
- Near "<<" and ">>";
- One space to the right and left of "," and "=".
スタイラーセット:
- "||" 及び"&&" (result: " || " and " && ")の前と後にスペースを入れます.
その他の置換:
- "int* a" 型の構文において、"*" 及び "&"は、型ではなく変数を参照するので、"int *a";に置き換えられます。
- 2重の空白行は1つに置き換えられます。
書式設定前
|
書式設定後
|
void myFunction()
{
if (I < 10)
{
printf (“Hello\n”) ;
if (I < 5 )
{
printf (“i<5 !\n”) ;
if (i < 3)
{
printf (“i<3 !\n”) ;
if (i < 2)
{
}
}
}
}
}
|
void myFunction()
{
if(I<10)
{
printf(“Hello\n”);
if(I<5)
{
printf(“i<5 !\n”);
if(i<3)
{
printf(“i<3 !\n”);
if(i<2)
{
}
}
}
}
}
|
MetaEditorの設定に関係なく、スタイラーのタブは常に3つのスペースに等しくなるようになっています。
インターラインアライメントを考慮したフォーマット時の置換を除く
上記で指定された交換ルールは、場合によっては適用されません。 隣接するラインの整列に違反しないために提供されます。 次のキーワードとシンボルについて、次の行でインターラインアライメントを認識します。
- "//" — С comment symbols;
- "{" — opening curly bracket;
- "}" — closing curly bracket;
- "return" — "return" operator;
- "delete" — "delete" operator;
- "=" — equality symbol;
- ":" — colon;
- "." — full stop.
前または後続のラインと同じ位置に上記の単語またはシンボルのいずれかが見つかった場合、その中で置換は行われません。
関数と演算子の書式設定
- 関数/演算子の型宣言からの2つのスペースは、 関数/演算子を開閉する"{" and "} "シンボルの前に設定されています。
- 演算子の先頭から3つのスペースは、 {" and "} "関数/演算子のシンボルの間にある各行の前に配置されます
- アンクローズの{" or "}がある場合、 "演算子内のシンボルテキストを使用すると、シンボルとテキストが異なる行に設定されます。
- また、前行の内容を考慮して整列が行われます。 かっこが閉じていない場合、または前の行で算術式が完了していない場合、現在の行は、前の行の "(" または "=" の後の最初の位置から始まります。
- "else "条件は常に " ifと同等に設定されています。".
書式設定前
|
書式設定後
|
void myFunction() {
int k[10],t=0;
for(int i=0;i<10;i++){
k[i]=i;
t+=i;}
if (button==name) {
bool state=ObjectGetInteger(0,name,OBJPROP_STATE);
if(!state)
ObjectSetInteger(0,name,OBJPROP_STATE,false);}
else {
ObjectSetInteger(0,name,OBJPROP_STATE,false);}
}
|
void myFunction()
{
int k[10],t=0;
for(int i=0;i<10;i++)
{
k[i]=i;
t+=i;
}
if(button==name)
{
bool state=ObjectGetInteger(0,name,OBJPROP_STATE);
if(!state)
ObjectSetInteger(0,name,OBJPROP_STATE,false);
}
else
{
ObjectSetInteger(0,name,OBJPROP_STATE,false);
}
}
|
構造、クラス、および列挙体を宣言するときの配置
このような式は、いわゆる2レベル集計にも適用されます。
- 説明するメンバ/メソッドの型を指定する前に、3つのスペースを設定します。
- 記述された構造体またはクラスメンバまたはメソッドの名前は、行の22位から示されます。
- メンバ及びメソッドにアクセスする指定子は、 ("private", "protected", "private" and "virtual") "class"に整列されます。
書式設定前
|
書式設定後
|
class CTradePad {
private:
int m_rows;
int m_columns;
int m_button_width;
int m_button_height;
int m_top;
int m_left;
int m_left_previous_header;
};
|
class CTradePad
{
private:
int m_rows;
int m_columns;
int m_button_width;
int m_button_height;
int m_top;
int m_left;
int m_left_previous_header;
};
|
コメントの整列
コメントは、宣言と定義の中で異なる方法で整列されます。
- 関数またはメソッドの定義の最初のレベルのコメントは、左 (インデントなし) に整列されます。
- 宣言内の最初のレベルのコメントは、行の3番目のポジションによって整列されます。
- 以下のレベルのコメントは、指定された演算子の対応するレベルで均等に整列されます。
書式設定前
|
書式設定後
|
void myFunction() {
//--- 1st level comment
int k[10],t=0;
for(int i=0;i<10;i++){
k[i]=i;
t+=i;}
if (button==name) {
bool state=ObjectGetInteger(0,name,OBJPROP_STATE);
//--- 2nd level comment
if(!state)
ObjectSetInteger(0,name,OBJPROP_STATE,false);}
else {
ObjectSetInteger(0,name,OBJPROP_STATE,false);}
}
|
void myFunction()
{
//--- 1st level comment
int k[10],t=0;
for(int i=0;i<10;i++)
{
k[i]=i;
t+=i;
}
if(button==name)
{
bool state=ObjectGetInteger(0,name,OBJPROP_STATE);
//--- 2nd level comment
if(!state)
ObjectSetInteger(0,name,OBJPROP_STATE,false);
}
else
{
ObjectSetInteger(0,name,OBJPROP_STATE,false);
}
}
|
class CTradePad
{
private:
int m_rows;
//--- number of lines
int m_columns;
//--- number of columns
int m_button_width;
//--- cell width
};
|
class CTradePad
{
private:
int m_rows;
//--- number of lines
int m_columns;
//--- number of columns
int m_button_width;
//--- cell width
};
|
挿入コメント
次のフォームのコメントが見つからない場合は、ファイルヘッダに挿入されます。
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright © 2009, CompanyName.|
//| http://www.companyname.net |
//+------------------------------------------------------------------+
次の形式のコメントは、関数、クラス、構造体などが欠落している場合に挿入されます。
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
次の型の切り取りコメントは、ファイルの最後に挿入されます。
//+------------------------------------------------------------------+