下面列出了怎么用com.intellij.psi.codeStyle.DocCommentSettings的API类实例代码及写法,或者点击链接到github查看源代码。
@Nonnull
private static String createLine(String lineData, CodeDocumentationAwareCommenter commenter, DocCommentSettings settings) {
if (!settings.isLeadingAsteriskEnabled()) {
return " " + lineData + " ";
}
else {
if (lineData.length() == 0) {
return commenter.getDocumentationCommentLinePrefix() + " ";
}
else {
return commenter.getDocumentationCommentLinePrefix() + " " + lineData + " ";
}
}
}
private static void reformatCommentKeepingEmptyTags(@Nonnull PsiFile file, @Nonnull Project project, int start, int end) {
CodeStyleSettings tempSettings = CodeStyle.getSettings(file).clone();
LanguageCodeStyleSettingsProvider langProvider = LanguageCodeStyleSettingsProvider.forLanguage(file.getLanguage());
if (langProvider != null) {
DocCommentSettings docCommentSettings = langProvider.getDocCommentSettings(tempSettings);
docCommentSettings.setRemoveEmptyTags(false);
}
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
CodeStyle.doWithTemporarySettings(project, tempSettings, () -> codeStyleManager.reformatText(file, start, end));
}
@Override
public DocCommentSettings getDocCommentSettings(PsiFile file) {
return this.delegate.getDocCommentSettings(file);
}
@Override
public DocCommentSettings getDocCommentSettings(PsiFile file) {
return delegate.getDocCommentSettings(file);
}
/**
* @deprecated Use createDocCommentLine(lineData,file,commenter) instead.
*/
@SuppressWarnings("unused")
@Deprecated
public static String createDocCommentLine(String lineData, Project project, CodeDocumentationAwareCommenter commenter) {
return createLine(lineData, commenter, DocCommentSettings.DEFAULTS);
}
public static String createDocCommentLine(String lineData, PsiFile file, CodeDocumentationAwareCommenter commenter) {
DocCommentSettings settings = CodeStyleManager.getInstance(file.getProject()).getDocCommentSettings(file);
return createLine(lineData, commenter, settings);
}