Search in sources :

Example 71 with CodeStyleSettings

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();
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Example 72 with CodeStyleSettings

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;
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) IndentInfo(com.intellij.formatting.IndentInfo) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 73 with CodeStyleSettings

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);
        }
    }
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) InvalidDataException(com.intellij.openapi.util.InvalidDataException)

Example 74 with CodeStyleSettings

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;
    }
}
Also used : JavaCodeStyleSettings(com.intellij.psi.codeStyle.JavaCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) JavaCodeStyleSettings(com.intellij.psi.codeStyle.JavaCodeStyleSettings)

Example 75 with CodeStyleSettings

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();
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Aggregations

CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)190 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)84 Project (com.intellij.openapi.project.Project)12 XmlCodeStyleSettings (com.intellij.psi.formatter.xml.XmlCodeStyleSettings)12 ECMA4CodeStyleSettings (com.intellij.lang.javascript.formatter.ECMA4CodeStyleSettings)9 JSCodeStyleSettings (com.intellij.lang.javascript.formatter.JSCodeStyleSettings)9 Document (com.intellij.openapi.editor.Document)9 JavaCodeStyleSettings (com.intellij.psi.codeStyle.JavaCodeStyleSettings)9 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiFile (com.intellij.psi.PsiFile)5 Nullable (org.jetbrains.annotations.Nullable)5 FormattingModel (com.intellij.formatting.FormattingModel)4 PsiElement (com.intellij.psi.PsiElement)4 CodeStyleSettingsManager (com.intellij.psi.codeStyle.CodeStyleSettingsManager)4 File (java.io.File)4 FormattingModelBuilder (com.intellij.formatting.FormattingModelBuilder)3 ASTNode (com.intellij.lang.ASTNode)3 Language (com.intellij.lang.Language)3 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)3