use of com.intellij.formatting.IndentInfo in project intellij-community by JetBrains.
the class JDParamListOwnerComment method generateList.
/**
* Generates parameters or exceptions
*
*/
protected void generateList(@NotNull String prefix, @NotNull StringBuilder sb, @NotNull List<NameDesc> list, @NotNull String tag, boolean align_comments, boolean generate_empty_tags, boolean wrapDescription) {
CodeStyleSettings settings = myFormatter.getSettings();
CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(JavaFileType.INSTANCE);
String continuationIndent = new IndentInfo(0, indentOptions.CONTINUATION_INDENT_SIZE, 0).generateNewWhiteSpace(indentOptions);
int max = 0;
if (align_comments && !wrapDescription) {
for (NameDesc nd : list) {
int currentLength = nd.name.length();
if (isNull(nd.desc) && !generate_empty_tags)
continue;
//finding longest parameter length
if (currentLength > max) {
max = currentLength;
}
}
}
StringBuilder fill = new StringBuilder(prefix.length() + tag.length() + max + 1);
fill.append(prefix);
StringUtil.repeatSymbol(fill, ' ', max + 1 + tag.length());
String wrapParametersPrefix = prefix + continuationIndent;
for (NameDesc nd : list) {
if (isNull(nd.desc) && !generate_empty_tags)
continue;
if (wrapDescription && !isNull(nd.desc)) {
sb.append(prefix).append(tag).append(nd.name).append("\n");
sb.append(wrapParametersPrefix);
sb.append(myFormatter.getParser().formatJDTagDescription(nd.desc, wrapParametersPrefix));
} else if (align_comments) {
sb.append(prefix);
sb.append(tag);
sb.append(nd.name);
int spacesNumber = max + 1 - nd.name.length();
StringUtil.repeatSymbol(sb, ' ', Math.max(0, spacesNumber));
sb.append(myFormatter.getParser().formatJDTagDescription(nd.desc, fill));
} else {
sb.append(prefix);
String description = (nd.desc == null) ? "" : nd.desc;
sb.append(myFormatter.getParser().formatJDTagDescription(tag + nd.name + " " + description, prefix));
}
}
}
use of com.intellij.formatting.IndentInfo in project intellij-community by JetBrains.
the class IndentCalculator method getIndentString.
@Nullable
String getIndentString(@Nullable Language language, @NotNull SemanticEditorPosition currPosition) {
String baseIndent = getBaseIndent(currPosition);
Document document = myEditor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
if (file != null) {
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(myProject);
CommonCodeStyleSettings.IndentOptions options = language != null && !(language.is(file.getLanguage()) || language.is(Language.ANY)) ? codeStyleSettings.getCommonSettings(language).getIndentOptions() : codeStyleSettings.getIndentOptionsByFile(file);
return baseIndent + new IndentInfo(0, indentTypeToSize(myIndentType, options), 0, false).generateNewWhiteSpace(options);
}
return null;
}
use of com.intellij.formatting.IndentInfo in project intellij-community by JetBrains.
the class PyEmacsHandler method changeIndent.
private static void changeIndent(@NotNull ChangeIndentContext context, int newIndent) {
int caretOffset = context.editor.getCaretModel().getOffset();
String newIndentString = new IndentInfo(0, newIndent, 0).generateNewWhiteSpace(context.getIndentOptions());
int start = context.document.getLineStartOffset(context.targetLine);
int end = DocumentUtil.getFirstNonSpaceCharOffset(context.document, context.targetLine);
context.editor.getDocument().replaceString(start, end, newIndentString);
if (caretOffset >= start && caretOffset < end) {
context.editor.getCaretModel().moveToOffset(start + newIndentString.length());
}
}
Aggregations