use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.
the class IndentHelperImpl method fillIndent.
public static String fillIndent(Project project, FileType fileType, int indent) {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
int indentLevel = (indent + INDENT_FACTOR / 2) / INDENT_FACTOR;
int spaceCount = indent - indentLevel * INDENT_FACTOR;
int indentLevelSize = indentLevel * settings.getIndentSize(fileType);
int totalSize = indentLevelSize + spaceCount;
StringBuilder buffer = new StringBuilder();
if (settings.useTabCharacter(fileType)) {
if (settings.isSmartTabs(fileType)) {
int tabCount = indentLevelSize / settings.getTabSize(fileType);
int leftSpaces = indentLevelSize - tabCount * settings.getTabSize(fileType);
for (int i = 0; i < tabCount; i++) {
buffer.append('\t');
}
for (int i = 0; i < leftSpaces + spaceCount; i++) {
buffer.append(' ');
}
} else {
int size = totalSize;
while (size > 0) {
if (size >= settings.getTabSize(fileType)) {
buffer.append('\t');
size -= settings.getTabSize(fileType);
} else {
buffer.append(' ');
size--;
}
}
}
} else {
for (int i = 0; i < totalSize; i++) {
buffer.append(' ');
}
}
return buffer.toString();
}
use of com.intellij.psi.codeStyle.CodeStyleSettings 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.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.
the class CodeStyleSchemeImpl method init.
private void init(@Nullable CodeStyleScheme parentScheme, @Nullable Element root) {
if (parentScheme == null) {
myCodeStyleSettings = new CodeStyleSettings();
} else {
CodeStyleSettings parentSettings = parentScheme.getCodeStyleSettings();
myCodeStyleSettings = parentSettings.clone();
while (parentSettings.getParentSettings() != null) {
parentSettings = parentSettings.getParentSettings();
}
myCodeStyleSettings.setParentSettings(parentSettings);
}
if (root != null) {
try {
myCodeStyleSettings.readExternal(root);
} catch (InvalidDataException e) {
LOG.error(e);
}
}
}
use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.
the class JavaClassNameInsertHandler method shouldInsertFqnInJavadoc.
private static boolean shouldInsertFqnInJavadoc(@NotNull JavaPsiClassReferenceElement item, @NotNull PsiFile file, @NotNull Project project) {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
switch(javaSettings.CLASS_NAMES_IN_JAVADOC) {
case FULLY_QUALIFY_NAMES_ALWAYS:
return true;
case SHORTEN_NAMES_ALWAYS_AND_ADD_IMPORT:
return false;
case FULLY_QUALIFY_NAMES_IF_NOT_IMPORTED:
if (file instanceof PsiJavaFile) {
PsiJavaFile javaFile = ((PsiJavaFile) file);
return item.getQualifiedName() != null && !ImportHelper.isAlreadyImported(javaFile, item.getQualifiedName());
}
default:
return false;
}
}
use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.
the class AssignFieldFromParameterTest method tearDown.
@Override
protected void tearDown() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.readExternal(myOldSettings);
super.tearDown();
}
Aggregations