Java 类通常被划分为逻辑“块”。是否有标记这些部分的约定?理想情况下,主要 IDE 都支持它。
我个人使用这个方法:
//// Section name here ////
然而,一些编辑似乎对此有疑问。
例如,在 Objective-C 代码中,您可以使用此方法:
#pragma mark -
#pragma mark Section name here
这将导致 XCode 中的菜单如下所示:
对于 intellij/android studio 有一个惊人的解决方案。
从...开始:
//region Description
并以以下内容结尾:
//endregion
The shortcut for that is in the menu you can open with Command+Alt+T (Mac) or Ctrl+Alt+T (Windows)
You can also add your own line for additional visual separation if you need it.
The region can be contracted and expanded at will with the +/- buttons like any function.
You can also navigate between regions with Command+Alt+Period (Ctrl+Alt+Period)
Source https://www.jetbrains.com/idea/help/folding-custom-regions-with-line-comments.html.
Example:
//region Parceler Implementation
//---------------------------------------------------------------------------------------
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(this.die, 0);
dest.writeParcelable(this.dieSprite, 0);
}
private DieVm(Parcel in) {
this.die = in.readParcelable(Die.class.getClassLoader());
this.dieSprite = in.readParcelable(Sprite.class.getClassLoader());
}
public static final Parcelable.Creator<DieVm> CREATOR = new Parcelable.Creator<DieVm>() {
public DieVm createFromParcel(Parcel source) {
return new DieVm(source);
}
public DieVm[] newArray(int size) {
return new DieVm[size];
}
};
//---------------------------------------------------------------------------------------
//endregion
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)