Search in sources :

Example 61 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class CodeStyleSchemesModel method differsFromDefault.

@Override
public boolean differsFromDefault(@NotNull CodeStyleScheme scheme) {
    CodeStyleSettings defaults = CodeStyleSettings.getDefaults();
    CodeStyleSettings clonedSettings = getCloneSettings(scheme);
    return !defaults.equals(clonedSettings);
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Example 62 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class IndentOptionsDetectorImpl method calcLineIndentInfo.

@Nullable
private List<LineIndentInfo> calcLineIndentInfo(@Nullable ProgressIndicator indicator) {
    if (myDocument == null || myDocument.getLineCount() < 3 || isFileBigToDetect()) {
        return null;
    }
    CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myProject);
    FormattingModelBuilder modelBuilder = LanguageFormatting.INSTANCE.forContext(myFile);
    if (modelBuilder == null)
        return null;
    FormattingModel model = modelBuilder.createModel(myFile, settings);
    Block rootBlock = model.getRootBlock();
    return new FormatterBasedLineIndentInfoBuilder(myDocument, rootBlock, indicator).build();
}
Also used : FormattingModel(com.intellij.formatting.FormattingModel) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) FormattingModelBuilder(com.intellij.formatting.FormattingModelBuilder) Block(com.intellij.formatting.Block) Nullable(org.jetbrains.annotations.Nullable)

Example 63 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class PsiViewerDialog method buildBlocks.

@Nullable
private static Block buildBlocks(@NotNull PsiElement rootElement) {
    FormattingModelBuilder formattingModelBuilder = LanguageFormatting.INSTANCE.forContext(rootElement);
    CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(rootElement.getProject());
    if (formattingModelBuilder != null) {
        FormattingModel formattingModel = formattingModelBuilder.createModel(rootElement, settings);
        return formattingModel.getRootBlock();
    } else {
        return null;
    }
}
Also used : FormattingModel(com.intellij.formatting.FormattingModel) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) FormattingModelBuilder(com.intellij.formatting.FormattingModelBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 64 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class SimpleIndentingBackspaceHandlerTest method testDeletingTabWhenIndentSizeIsSmaller.

public void testDeletingTabWhenIndentSizeIsSmaller() {
    CodeStyleSettings settings = new CodeStyleSettings();
    CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions();
    assertNotNull(indentOptions);
    indentOptions.INDENT_SIZE = 2;
    indentOptions.TAB_SIZE = 4;
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
    try {
        doTest("\t<caret>text", "  <caret>text");
    } finally {
        CodeStyleSettingsManager.getInstance().dropTemporarySettings();
    }
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 65 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings 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));
        }
    }
}
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)

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