Java Code Examples for com.intellij.psi.codeStyle.CodeStyleSettings

The following are top voted examples for showing how to use com.intellij.psi.codeStyle.CodeStyleSettings. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: hybris-integration-intellij-idea-plugin   File: ImpexFormattingModelBuilder.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {

    final Block impexBlock = new ImpexBlock(
        element.getNode(),
        null,
        Alignment.createAlignment(),
        createSpaceBuilder(settings)
    );

    return FormattingModelProvider.createFormattingModelForPsiFile(
        element.getContainingFile(),
        impexBlock,
        settings
    );
}
 
Example 2
Project: intellij-csv-validator   File: CsvFormattingModelBuilder.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    ASTNode root = CsvFormatHelper.getRoot(element.getNode());
    CsvFormattingInfo formattingInfo = new CsvFormattingInfo(
            settings,
            CsvFormatHelper.createSpaceBuilder(settings),
            CsvFormatHelper.createColumnInfoMap(root, settings)
    );

    return FormattingModelProvider.createFormattingModelForPsiFile(
            element.getContainingFile(),
            new CsvBlock(root, formattingInfo),
            settings
    );
}
 
Example 3
Project: intellij-csv-validator   File: CsvFormatHelper.java   Source Code and License 6 votes vote down vote up
public static Map<Integer, CsvColumnInfo<ASTNode>> createColumnInfoMap(ASTNode root, CodeStyleSettings settings) {
    Map<Integer, CsvColumnInfo<ASTNode>> columnInfoMap = new HashMap<>();
    ASTNode child = root.getFirstChildNode();
    while (child != null) {
        if (child.getElementType() == CsvTypes.RECORD) {
            Integer column = 0;
            ASTNode subChild = child.getFirstChildNode();
            while (subChild != null) {
                if (subChild.getElementType() == CsvTypes.FIELD) {
                    int length = getTextLength(subChild, settings);
                    if (!columnInfoMap.containsKey(column)) {
                        columnInfoMap.put(column, new CsvColumnInfo(column, length));
                    } else if (columnInfoMap.get(column).getMaxLength() < length) {
                        columnInfoMap.get(column).setMaxLength(length);
                    }
                    columnInfoMap.get(column).addElement(subChild);
                    ++column;
                }
                subChild = subChild.getTreeNext();
            }
        }
        child = child.getTreeNext();
    }
    return columnInfoMap;
}
 
Example 4
Project: lua-for-idea   File: LuaSpacingProcessor.java   Source Code and License 6 votes vote down vote up
private static Spacing getSpacing(ASTNode node, CodeStyleSettings settings) {
  LuaSpacingProcessor spacingProcessor = mySharedProcessorAllocator.get();
  try {
    if (spacingProcessor == null) {
      spacingProcessor = new LuaSpacingProcessor(new MyLuaSpacingVisitor(node, settings));
      mySharedProcessorAllocator.set(spacingProcessor);
    } else {
      spacingProcessor.setVisitor(new MyLuaSpacingVisitor(node, settings));
    }
    spacingProcessor.doInit();
    return spacingProcessor.getResult();
  }
  catch (Exception e) {
    LOG.error(e);
    return null;
  }
  finally {
    spacingProcessor.clear();
  }
}
 
Example 5
Project: lua-for-idea   File: LuaBlockGenerator.java   Source Code and License 6 votes vote down vote up
/**
 * Generates blocks for binary expressions
 *
 * @param node
 * @return
 */
private static List<Block> generateForBinaryExpr(final ASTNode node, Wrap myWrap, CodeStyleSettings mySettings) {
    final ArrayList<Block> subBlocks = new ArrayList<Block>();
    Alignment alignment = mySettings.ALIGN_MULTILINE_BINARY_OPERATION ? Alignment.createAlignment() : null;
    LuaBinaryExpression myExpr = (LuaBinaryExpression) node.getPsi();
    ASTNode[] children = node.getChildren(null);
    if (myExpr.getLeftExpression() instanceof LuaBinaryExpression) {
        addBinaryChildrenRecursively(myExpr.getLeftExpression(), subBlocks, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings);
    }
    for (ASTNode childNode : children) {
        if (canBeCorrectBlock(childNode) &&
                !(childNode.getPsi() instanceof LuaBinaryExpression)) {
            subBlocks.add(new LuaFormattingBlock(childNode, alignment, Indent.getContinuationWithoutFirstIndent(), myWrap, mySettings));
        }
    }
    if (myExpr.getRightExpression() instanceof LuaBinaryExpression) {
        addBinaryChildrenRecursively(myExpr.getRightExpression(), subBlocks, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings);
    }
    return subBlocks;
}
 
Example 6
Project: lua-for-idea   File: LuaBlockGenerator.java   Source Code and License 6 votes vote down vote up
/**
 * Adds all children of specified element to given list
 *
 * @param elem
 * @param list
 * @param indent
 * @param alignment
 */
private static void addBinaryChildrenRecursively(PsiElement elem,
                                                 List<Block> list,
                                                 Indent indent,
                                                 Alignment alignment, Wrap myWrap, CodeStyleSettings mySettings) {
    if (elem == null) return;
    ASTNode[] children = elem.getNode().getChildren(null);
    // For binary expressions
    if ((elem instanceof LuaBinaryExpression)) {
        LuaBinaryExpression myExpr = ((LuaBinaryExpression) elem);
        if (myExpr.getLeftExpression() instanceof LuaBinaryExpression) {
            addBinaryChildrenRecursively(myExpr.getLeftExpression(), list, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings);
        }
        for (ASTNode childNode : children) {
            if (canBeCorrectBlock(childNode) &&
                    !(childNode.getPsi() instanceof LuaBinaryExpression)) {
                list.add(new LuaFormattingBlock(childNode, alignment, indent, myWrap, mySettings));
            }
        }
        if (myExpr.getRightExpression() instanceof LuaBinaryExpression) {
            addBinaryChildrenRecursively(myExpr.getRightExpression(), list, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings);
        }
    }
}
 
Example 7
Project: intellij-ce-playground   File: JavaFormatterTest.java   Source Code and License 6 votes vote down vote up
public void testCommentAfterDeclaration() throws Exception {
  CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject());
  CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);

  int oldMargin = codeStyleSettings.getDefaultRightMargin();
  int oldWrap = javaSettings.ASSIGNMENT_WRAP;

  try {
    codeStyleSettings.setDefaultRightMargin(20);
    javaSettings.ASSIGNMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    doMethodTest(
      "int i=0; //comment comment",
      "int i =\n" +
      "        0; //comment comment"
    );

  }
  finally {
    codeStyleSettings.setDefaultRightMargin(oldMargin);
    javaSettings.ASSIGNMENT_WRAP = oldWrap;
  }
}
 
Example 8
Project: intellij-ce-playground   File: TabPostFormatProcessor.java   Source Code and License 6 votes vote down vote up
@NotNull
private static TextRange doProcess(@NotNull PsiElement source, @NotNull TextRange range, @NotNull CodeStyleSettings settings) {
  ASTNode node = source.getNode();
  if (node == null) {
    return range;
  }

  Language language = source.getLanguage();
  if (language != JavaLanguage.INSTANCE) {
    // We had the only complaint for tabs not being converted to spaces for now. It was for the java code which has
    // a single block for the multi-line comment. This check should be removed if it is decided to generalize
    // this logic to other languages as well.
    return range;
  }

  if (!source.isValid()) return range;
  PsiFile file = source.getContainingFile();
  CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptionsByFile(file, range);

  boolean useTabs = indentOptions.USE_TAB_CHARACTER;
  boolean smartTabs = indentOptions.SMART_TABS;
  int tabWidth = indentOptions.TAB_SIZE;
  return processViaPsi(node, range, new TreeHelperImpl(), useTabs, smartTabs, tabWidth);
}
 
Example 9
Project: intellij-ce-playground   File: GeneralCodeStylePanel.java   Source Code and License 6 votes vote down vote up
@Override
public void apply(CodeStyleSettings settings) {
  settings.LINE_SEPARATOR = getSelectedLineSeparator();

  settings.setDefaultRightMargin(getRightMargin());
  settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = myCbWrapWhenTypingReachesRightMargin.isSelected();

  settings.FORMATTER_TAGS_ENABLED = myEnableFormatterTags.isSelected();
  settings.FORMATTER_TAGS_ACCEPT_REGEXP = myAcceptRegularExpressionsCheckBox.isSelected();

  settings.FORMATTER_OFF_TAG = getTagText(myFormatterOffTagField, settings.FORMATTER_OFF_TAG);
  settings.setFormatterOffPattern(compilePattern(settings, myFormatterOffTagField, settings.FORMATTER_OFF_TAG));

  settings.FORMATTER_ON_TAG = getTagText(myFormatterOnTagField, settings.FORMATTER_ON_TAG);
  settings.setFormatterOnPattern(compilePattern(settings, myFormatterOnTagField, settings.FORMATTER_ON_TAG));

  settings.AUTODETECT_INDENTS = myAutodetectIndentsBox.isSelected();
  if (myShowDetectedIndentNotification.isEnabled()) {
    FileIndentOptionsProvider.setShowNotification(myShowDetectedIndentNotification.isSelected());
  }

  for (GeneralCodeStyleOptionsProvider option : myAdditionalOptions) {
    option.apply(settings);
  }
}
 
Example 10
Project: intellij-ce-playground   File: GeneralCodeFormatterTest.java   Source Code and License 6 votes vote down vote up
public void testLastLineIndent() throws Exception{
  final String initialText = "a\n";
  final TestFormattingModel model = new TestFormattingModel(initialText);

  model.setRootBlock(new FormattingModelXmlReader(model).readTestBlock("lineIndent"));
  final CommonCodeStyleSettings.IndentOptions indentOptions = new CommonCodeStyleSettings.IndentOptions();
  indentOptions.CONTINUATION_INDENT_SIZE = 8;
  indentOptions.INDENT_SIZE = 4;
  indentOptions.LABEL_INDENT_SIZE = 1;
  final CodeStyleSettings settings = new CodeStyleSettings(false);
  settings.setDefaultRightMargin(myRightMargin);
  try {
    FormatterEx.getInstanceEx().adjustLineIndent(model, settings, indentOptions, initialText.length() - 1, new TextRange(0, initialText.length()));
  }
  catch (IncorrectOperationException e) {
    fail();
  }

  assertEquals("a\n    ", FormatterImpl.getText(model));

}
 
Example 11
Project: intellij-ce-playground   File: ImportHelper.java   Source Code and License 6 votes vote down vote up
public static List<Pair<String, Boolean>> sortItemsAccordingToSettings(List<Pair<String, Boolean>> names, final CodeStyleSettings settings) {
  int[] entryForName = ArrayUtil.newIntArray(names.size());
  PackageEntry[] entries = settings.IMPORT_LAYOUT_TABLE.getEntries();
  for(int i = 0; i < names.size(); i++){
    Pair<String, Boolean> pair = names.get(i);
    String packageName = pair.getFirst();
    Boolean isStatic = pair.getSecond();
    entryForName[i] = findEntryIndex(packageName, isStatic, entries);
  }

  List<Pair<String, Boolean>> resultList = new ArrayList<Pair<String, Boolean>>(names.size());
  for(int i = 0; i < entries.length; i++){
    for(int j = 0; j < names.size(); j++){
      if (entryForName[j] == i){
        resultList.add(names.get(j));
        names.set(j, null);
      }
    }
  }
  for (Pair<String, Boolean> name : names) {
    if (name != null) resultList.add(name);
  }
  return resultList;
}
 
Example 12
Project: intellij-spring-assistant   File: Util.java   Source Code and License 5 votes vote down vote up
@NotNull
public static String getCodeStyleIntent(InsertionContext insertionContext) {
  final CodeStyleSettings currentSettings =
      CodeStyleSettingsManager.getSettings(insertionContext.getProject());
  final CommonCodeStyleSettings.IndentOptions indentOptions =
      currentSettings.getIndentOptions(insertionContext.getFile().getFileType());
  return indentOptions.USE_TAB_CHARACTER ?
      "\t" :
      StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE);
}
 
Example 13
Project: AppleScript-IDEA   File: AppleScriptBlock.java   Source Code and License 5 votes vote down vote up
AppleScriptBlock(ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, CodeStyleSettings settings) {
  super(node, wrap, alignment);
  mySettings = settings;
  myIndentProcessor = new AppleScriptIndentProcessor(settings.getCommonSettings(AppleScriptLanguage.INSTANCE));
  myIndent = myIndentProcessor.getChildIndent(myNode);
  mySpacingProcessor = new AppleScriptSpacingProcessor(node, settings.getCommonSettings(AppleScriptLanguage.INSTANCE));
  myWrappingProcessor = new AppleScriptWrappingProcessor(node, settings.getCommonSettings(AppleScriptLanguage.INSTANCE));
}
 
Example 14
Project: AppleScript-IDEA   File: AppleScriptFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
  PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(AppleScriptLanguage.INSTANCE);
  assert containingFile != null : element.getContainingFile();
  ASTNode astNode = containingFile.getNode();
  assert astNode != null;
  CommonCodeStyleSettings appleScriptSettings = settings.getCommonSettings(AppleScriptLanguage.INSTANCE);
  final AppleScriptBlock rootBlock = new AppleScriptBlock(astNode, null, null, settings);
  return new AppleScriptFormattingModel(containingFile, rootBlock, FormattingDocumentModelImpl.createOn(containingFile));
}
 
Example 15
Project: bamboo-soy   File: SoyFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
@Override
public TemplateLanguageBlock createTemplateLanguageBlock(
    @NotNull ASTNode node,
    @Nullable Wrap wrap,
    @Nullable Alignment alignment,
    @Nullable List<DataLanguageBlockWrapper> foreignChildren,
    @NotNull CodeStyleSettings codeStyleSettings) {
  final FormattingDocumentModelImpl documentModel =
      FormattingDocumentModelImpl.createOn(node.getPsi().getContainingFile());
  if (node.getPsi() instanceof TagElement) {
    return new SoyTagBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else if(node.getPsi() instanceof TagBlockElement) {
    return new SoyTagBlockBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else if (node.getPsi() instanceof SoyStatementList) {
    return new SoyStatementListBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else {
    return new SoyBlock(
      this,
      codeStyleSettings,
      node,
      foreignChildren,
      new HtmlPolicy(codeStyleSettings, documentModel));
  }
}
 
Example 16
Project: bamboo-soy   File: SoyFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
  final PsiFile file = element.getContainingFile();

  if (element.getNode().getElementType() == SoyTypes.OTHER) {
    return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
  } else {
    return new DocumentBasedFormattingModel(
        getRootBlock(file, file.getViewProvider(), settings),
        element.getProject(),
        settings,
        file.getFileType(),
        file);
  }
}
 
Example 17
Project: bamboo-soy   File: SoyStatementListBlock.java   Source Code and License 5 votes vote down vote up
public SoyStatementListBlock(
    @NotNull TemplateLanguageBlockFactory blockFactory,
    @NotNull CodeStyleSettings settings,
    @NotNull ASTNode node,
    @Nullable List<DataLanguageBlockWrapper> foreignChildren,
    HtmlPolicy htmlPolicy) {
  super(blockFactory, settings, node, foreignChildren, htmlPolicy);
}
 
Example 18
Project: bamboo-soy   File: SoyBlock.java   Source Code and License 5 votes vote down vote up
public SoyBlock(
    @NotNull TemplateLanguageBlockFactory blockFactory,
    @NotNull CodeStyleSettings settings,
    @NotNull ASTNode node,
    @Nullable List<DataLanguageBlockWrapper> foreignChildren,
    HtmlPolicy htmlPolicy) {
  super(blockFactory, settings, node, foreignChildren);
  myHtmlPolicy = htmlPolicy;
}
 
Example 19
Project: bamboo-soy   File: SoyTagBlock.java   Source Code and License 5 votes vote down vote up
public SoyTagBlock(
    @NotNull TemplateLanguageBlockFactory blockFactory,
    @NotNull CodeStyleSettings settings,
    @NotNull ASTNode node,
    @Nullable List<DataLanguageBlockWrapper> foreignChildren,
    HtmlPolicy htmlPolicy) {
  super(blockFactory, settings, node, foreignChildren, htmlPolicy);
}
 
Example 20
Project: bamboo-soy   File: SoyTagBlockBlock.java   Source Code and License 5 votes vote down vote up
public SoyTagBlockBlock(
    @NotNull TemplateLanguageBlockFactory blockFactory,
    @NotNull CodeStyleSettings settings,
    @NotNull ASTNode node,
    @Nullable List<DataLanguageBlockWrapper> foreignChildren,
    HtmlPolicy htmlPolicy) {
  super(blockFactory, settings, node, foreignChildren, htmlPolicy);
}
 
Example 21
Project: intellij-postfix-templates   File: CptCodeStyleMainPanel.java   Source Code and License 5 votes vote down vote up
@Override
protected void initTabs(CodeStyleSettings settings) {
	addIndentOptionsTab(settings);
	addSpacesTab(settings);
	addWrappingAndBracesTab(settings);
	addBlankLinesTab(settings);
}
 
Example 22
Project: intellij-postfix-templates   File: CptFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
	return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(),
		new CptBlock(element.getNode(),
			Wrap.createWrap(WrapType.NONE, false),
			Indent.getNoneIndent(),
			Indent.getNoneIndent(),
			Alignment.createAlignment(),
			createSpaceBuilder(settings)),
		settings);
}
 
Example 23
Project: intellij-postfix-templates   File: CptFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
	return new SpacingBuilder(settings, CptLanguage.INSTANCE)
		.around(CptTypes.SEPARATOR)
		.spaceIf(settings.SPACE_AROUND_ASSIGNMENT_OPERATORS)
		//.around(CptTypes.MAP)
		//.spaceIf(settings.SPACE_AROUND_LAMBDA_ARROW)
		.before(CptTypes.MAPPING)
		.spaces(2);
}
 
Example 24
Project: hybris-integration-intellij-idea-plugin   File: ImportProjectProgressModalWindow.java   Source Code and License 5 votes vote down vote up
private void disableWrapOnType(final Language impexLanguage) {
    final CodeStyleScheme currentScheme = CodeStyleSchemes.getInstance().getCurrentScheme();
    final CodeStyleSettings codeStyleSettings = currentScheme.getCodeStyleSettings();
    if (impexLanguage != null) {
        CommonCodeStyleSettings langSettings = codeStyleSettings.getCommonSettings(impexLanguage);
        if (langSettings != null) {
            langSettings.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.NO_WRAP.intValue;
        }
    }
}
 
Example 25
Project: hybris-integration-intellij-idea-plugin   File: FlexibleSearchFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(
    final PsiElement element, final CodeStyleSettings settings
) {
    final Block block = new FlexibleSearchBlock(
        element.getNode(),
        null,
        Alignment.createAlignment(),
        createSpaceBuilder(settings)
    );

    return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), block, settings);
}
 
Example 26
Project: hybris-integration-intellij-idea-plugin   File: FlexibleSearchFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
private static SpacingBuilder createSpaceBuilder(final CodeStyleSettings settings) {

        return new SpacingBuilder(settings, FlexibleSearchLanguage.getInstance())
            .after(FlexibleSearchTypes.COMP_OP)
            .spaceIf(true)

            .before(FlexibleSearchTypes.COMP_OP)
            .spaceIf(true)

            .after(FlexibleSearchTypes.LEFT_DOUBLE_BRACE)
            .spaceIf(true)

            .before(FlexibleSearchTypes.RIGHT_DOUBLE_BRACE)
            .spaceIf(true)

            .before(FlexibleSearchTypes.LEFT_BRACE)
            .spaceIf(true)

            .after(FlexibleSearchTypes.RIGHT_BRACE)
            .spaceIf(true)

            .before(FlexibleSearchTypes.LEFT_PAREN)
            .spaceIf(true)

            .after(FlexibleSearchTypes.RIGHT_PAREN)
            .spaceIf(true)

            .around(TokenSet.create(FlexibleSearchTypes.WHERE, FlexibleSearchTypes.WHERE_CLAUSE))
            .spaceIf(true)
            ;
    }
 
Example 27
Project: intellij-csv-validator   File: CsvFormatHelper.java   Source Code and License 5 votes vote down vote up
public static int getTextLength(ASTNode node, CodeStyleSettings codeStyleSettings) {
    CsvCodeStyleSettings csvCodeStyleSettings = codeStyleSettings.getCustomSettings(CsvCodeStyleSettings.class);
    String text = node.getText();
    int length = node.getTextLength();
    if (csvCodeStyleSettings.TABULARIZE && !csvCodeStyleSettings.WHITE_SPACES_OUTSIDE_QUOTES && text.startsWith("\"")) {
        text = text.substring(1, text.length() - 1);
        text = BEGIN_WHITE_SPACE_PATTERN.matcher(text).replaceFirst("");
        text = END_WHITE_SPACE_PATTERN.matcher(text).replaceFirst("");
        length = text.length() + 2;
    }
    return length;
}
 
Example 28
Project: intellij-csv-validator   File: CsvFormatHelper.java   Source Code and License 5 votes vote down vote up
public static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
    CsvCodeStyleSettings csvCodeStyleSettings = settings.getCustomSettings(CsvCodeStyleSettings.class);
    SpacingBuilder builder = new SpacingBuilder(settings, CsvLanguage.INSTANCE);
    if (csvCodeStyleSettings.TRIM_LEADING_WHITE_SPACES || csvCodeStyleSettings.TABULARIZE) {
        builder
                .after(CsvTypes.COMMA).spaceIf(csvCodeStyleSettings.SPACE_AFTER_SEPARATOR)
                .after(CsvTypes.CRLF).spaces(0);
        if (csvCodeStyleSettings.TABULARIZE && !csvCodeStyleSettings.WHITE_SPACES_OUTSIDE_QUOTES) {
            builder.before(CsvTypes.QUOTE).spaces(0);
        }
    } else if (csvCodeStyleSettings.SPACE_AFTER_SEPARATOR) {
        builder.after(CsvTypes.COMMA).spaces(1);
    }

    if (csvCodeStyleSettings.TRIM_TRAILING_WHITE_SPACES || csvCodeStyleSettings.TABULARIZE) {
        builder
                .before(CsvTypes.COMMA).spaceIf(csvCodeStyleSettings.SPACE_BEFORE_SEPARATOR)
                .before(CsvTypes.CRLF).spaces(0);
        if (csvCodeStyleSettings.TABULARIZE && !csvCodeStyleSettings.WHITE_SPACES_OUTSIDE_QUOTES) {
            builder.after(CsvTypes.QUOTE).spaces(0);
        }
    } else if (csvCodeStyleSettings.SPACE_BEFORE_SEPARATOR) {
        builder.before(CsvTypes.COMMA).spaces(1);
    }
    
    return builder;
}
 
Example 29
Project: intellij-csv-validator   File: CsvCodeStyleSettings.java   Source Code and License 5 votes vote down vote up
public static String getCurrentSeparator(@Nullable Project project) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return DEFAULT_SEPARATOR;
    }
    if (project != null) {
        CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
        if (codeStyleSettings != null) {
            CsvCodeStyleSettings csvCodeStyleSettings = codeStyleSettings.getCustomSettings(CsvCodeStyleSettings.class);
            if (csvCodeStyleSettings != null) {
                return csvCodeStyleSettings.getSeparator();
            }
        }
    }
    return DEFAULT_SEPARATOR;
}
 
Example 30
Project: intellij-ce-playground   File: WhiteSpaceFormattingStrategyAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public CharSequence adjustWhiteSpaceIfNecessary(@NotNull CharSequence whiteSpaceText,
                                                @NotNull PsiElement startElement,
                                                int startOffset,
                                                int endOffset, CodeStyleSettings codeStyleSettings) {
  return whiteSpaceText;
}
 
Example 31
Project: intellij-ce-playground   File: RightMarginForm.java   Source Code and License 5 votes vote down vote up
public void apply(@NotNull CodeStyleSettings settings) {
  CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
  if (langSettings != settings) {
    if (myDefaultGeneralCheckBox.isSelected()) {
      langSettings.RIGHT_MARGIN = -1;
    }
    else {
      langSettings.RIGHT_MARGIN = getFieldRightMargin(settings.getDefaultRightMargin());
    }
  }
  langSettings.WRAP_ON_TYPING = getSelectedWrapOnTypingValue();
}
 
Example 32
Project: intellij-ce-playground   File: JoinLinesTest.java   Source Code and License 5 votes vote down vote up
public void testSCR3493e() throws Exception {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  boolean use_tab_character = settings.useTabCharacter(null);
  boolean smart_tabs = settings.isSmartTabs(null);
  try {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
    doTest();
  } finally {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
  }
}
 
Example 33
Project: intellij-ce-playground   File: ArrangementEngine.java   Source Code and License 5 votes vote down vote up
private Context(@NotNull Rearranger<E> rearranger,
                @NotNull Collection<ArrangementEntryWrapper<E>> wrappers,
                @NotNull Document document,
                @NotNull List<ArrangementSectionRule> sectionRules,
                @NotNull List<? extends ArrangementMatchRule> rulesByPriority,
                @NotNull CodeStyleSettings settings, @NotNull Changer changer)
{
  this.rearranger = rearranger;
  this.wrappers = wrappers;
  this.document = document;
  this.sectionRules = sectionRules;
  this.rulesByPriority = rulesByPriority;
  this.settings = settings;
  this.changer = changer;
}
 
Example 34
Project: lua-for-idea   File: LuaBlockGenerator.java   Source Code and License 5 votes vote down vote up
public static List<Block> generateSubBlocks(ASTNode node,
                                                Alignment myAlignment,
                                                Wrap myWrap,
                                                CodeStyleSettings mySettings,
                                                LuaFormattingBlock formattingBlock) {
//        //For binary expressions
        PsiElement blockPsi = formattingBlock.getNode().getPsi();
        if (blockPsi instanceof LuaBinaryExpression &&
                !(blockPsi.getParent() instanceof LuaBinaryExpression)) {
            return generateForBinaryExpr(node, myWrap, mySettings);
        }

        LOG.info(">> parent: " + blockPsi + ": " + node);
        // For other cases
        final ArrayList<Block> subBlocks = new ArrayList<Block>();
        ASTNode[] children = getLuaChildren(node);
        ASTNode prevChildNode = null;
        for (ASTNode childNode : children) {
            LOG.info("Processing: " + childNode);
            if (canBeCorrectBlock(childNode)) {
                final Indent indent = LuaIndentProcessor.getChildIndent(formattingBlock, prevChildNode, childNode);
                LOG.info("" + level + "     child: " + childNode + "indent " + indent);
                level++;
                subBlocks.add(
                        new LuaFormattingBlock(childNode,
                                blockPsi instanceof LuaFormattingBlock ? null : myAlignment,
                                indent, myWrap, mySettings));
                --level;
                prevChildNode = childNode;
            }
        }
        LOG.info("<< parent: " + blockPsi+ ": " + node);
        return subBlocks;
    }
 
Example 35
Project: lua-for-idea   File: LuaFormattingBlock.java   Source Code and License 5 votes vote down vote up
public LuaFormattingBlock(@NotNull final ASTNode node, @Nullable final Alignment alignment, @NotNull final Indent indent, @Nullable final Wrap wrap, final CodeStyleSettings settings) {
  myNode = node;
  myAlignment = alignment;
  myIndent = indent;
  myWrap = wrap;
  mySettings = settings;
}
 
Example 36
Project: intellij-ce-playground   File: CodeStyleGenerationConfigurable.java   Source Code and License 5 votes vote down vote up
public boolean isModified(CodeStyleSettings settings) {
  Iterable<String> oldProperties = getPropertyNames(settings);
  int i = 0;
  for (String property : oldProperties) {
    if (i >= myModel.size() || !property.equals(myModel.getElementAt(i))) {
      return true;
    }
    i++;
  }
  return false;
}
 
Example 37
Project: intellij-ce-playground   File: XmlCodeStyleMainPanel.java   Source Code and License 5 votes vote down vote up
@Override
protected void initTabs(CodeStyleSettings settings) {
  addIndentOptionsTab(settings);
  addTab(new CodeStyleXmlPanel(settings));
  addTab(new XmlArrangementPanel(settings));

  for (CodeStyleSettingsProvider provider : Extensions.getExtensions(CodeStyleSettingsProvider.EXTENSION_POINT_NAME)) {
    if (provider.getLanguage() == XMLLanguage.INSTANCE && !provider.hasSettingsPage()) {
      createTab(provider);
    }
  }
}
 
Example 38
Project: intellij-ce-playground   File: GeneralCodeStylePanel.java   Source Code and License 5 votes vote down vote up
@Override
protected void resetImpl(final CodeStyleSettings settings) {

  String lineSeparator = settings.LINE_SEPARATOR;
  if ("\n".equals(lineSeparator)) {
    myLineSeparatorCombo.setSelectedItem(UNIX_STRING);
  }
  else if ("\r\n".equals(lineSeparator)) {
    myLineSeparatorCombo.setSelectedItem(WINDOWS_STRING);
  }
  else if ("\r".equals(lineSeparator)) {
    myLineSeparatorCombo.setSelectedItem(MACINTOSH_STRING);
  }
  else {
    myLineSeparatorCombo.setSelectedItem(SYSTEM_DEPENDANT_STRING);
  }

  myRightMarginField.setText(String.valueOf(settings.getDefaultRightMargin()));
  myCbWrapWhenTypingReachesRightMargin.setSelected(settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN);

  myAcceptRegularExpressionsCheckBox.setSelected(settings.FORMATTER_TAGS_ACCEPT_REGEXP);
  myEnableFormatterTags.setSelected(settings.FORMATTER_TAGS_ENABLED);

  myFormatterOnTagField.setText(settings.FORMATTER_ON_TAG);
  myFormatterOffTagField.setText(settings.FORMATTER_OFF_TAG);

  setFormatterTagControlsEnabled(settings.FORMATTER_TAGS_ENABLED);

  myAutodetectIndentsBox.setSelected(settings.AUTODETECT_INDENTS);
  myShowDetectedIndentNotification.setEnabled(myAutodetectIndentsBox.isSelected());
  myShowDetectedIndentNotification.setSelected(FileIndentOptionsProvider.isShowNotification());

  for (GeneralCodeStyleOptionsProvider option : myAdditionalOptions) {
    option.reset(settings);
  }
}
 
Example 39
Project: intellij-ce-playground   File: OptionTableWithPreviewPanel.java   Source Code and License 5 votes vote down vote up
@Override
public Object getValue(CodeStyleSettings settings) {
  try {
    return field.getInt(getSettings(settings));
  }
  catch (IllegalAccessException e) {
    return null;
  }      
}
 
Example 40
Project: intellij-neos   File: FusionFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement psiElement, CodeStyleSettings settings) {
    SpacingBuilder spacingBuilder = createSpaceBuilder(settings);
    final FusionBlock block = new FusionBlock(psiElement.getNode(), null, null, settings, spacingBuilder);
    return FormattingModelProvider.createFormattingModelForPsiFile(psiElement.getContainingFile(), block, settings);
}
 
Example 41
Project: intellij-ce-playground   File: CodeFragmentCodeStyleSettingsPanel.java   Source Code and License 5 votes vote down vote up
private void reformatSelectedTextWithNewSettings() {
  try {
    apply(getSettings());
  }
  catch (ConfigurationException e) {
    LOG.debug("Cannot apply code style settings", e);
  }

  CodeStyleSettings clonedSettings = getSettings().clone();
  mySelectedTextFormatter.reformatSelectedText(clonedSettings);
}
 
Example 42
Project: intellij-ce-playground   File: JoinLinesTest.java   Source Code and License 5 votes vote down vote up
public void testSCR3493c() throws Exception {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  boolean use_tab_character = settings.useTabCharacter(null);
  boolean smart_tabs = settings.isSmartTabs(null);
  try {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
    doTest();
  } finally {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
  }
}
 
Example 43
Project: intellij-ce-playground   File: TemplateLanguageBlock.java   Source Code and License 5 votes vote down vote up
protected TemplateLanguageBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment,
                                @NotNull TemplateLanguageBlockFactory blockFactory,
                                @NotNull CodeStyleSettings settings,
                                @Nullable List<DataLanguageBlockWrapper> foreignChildren) {
  super(node, wrap, alignment);
  myBlockFactory = blockFactory;
  myForeignChildren = foreignChildren;
  mySettings = settings;
}
 
Example 44
Project: protobuf-jetbrains-plugin   File: FormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(ProtoLanguage.INSTANCE);
    ASTNode fileNode = containingFile.getNode();
    Wrap wrap = Wrap.createWrap(WrapType.NONE, false);
    Alignment alignment = Alignment.createAlignment();
    ProtoFileBlock block = new ProtoFileBlock(fileNode, wrap, alignment, settings);
    return FormattingModelProvider.createFormattingModelForPsiFile(containingFile, block, settings);
}
 
Example 45
Project: intellij-ce-playground   File: CodeFragmentCodeStyleSettingsPanel.java   Source Code and License 5 votes vote down vote up
public CodeFragmentCodeStyleSettingsPanel(@NotNull CodeStyleSettings settings,
                                          @NotNull CodeStyleSettingsCodeFragmentFilter.CodeStyleSettingsToShow settingsToShow,
                                          @NotNull Language language,
                                          @NotNull SelectedTextFormatter selectedTextFormatter)
{
  super(language, settings, settings.clone());
  mySettingsToShow = settingsToShow;
  mySelectedTextFormatter = selectedTextFormatter;

  ensureTabs();
}
 
Example 46
Project: intellij-ce-playground   File: OverrideImplement15Test.java   Source Code and License 5 votes vote down vote up
public void testOverridingLibraryFunctionWithConfiguredParameterPrefix() throws Exception {
  CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
  try {
    codeStyleSettings.PARAMETER_NAME_PREFIX = "in";
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
    doTest(false);
  }
  finally {
    CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
  }
}
 
Example 47
Project: intellij-ce-playground   File: CompositeWhiteSpaceFormattingStrategy.java   Source Code and License 5 votes vote down vote up
@Override
public CharSequence adjustWhiteSpaceIfNecessary(@NotNull CharSequence whiteSpaceText,
                                                @NotNull PsiElement startElement,
                                                int startOffset,
                                                int endOffset, CodeStyleSettings codeStyleSettings)
{
  CharSequence result = whiteSpaceText;
  for (WhiteSpaceFormattingStrategy strategy : myStrategies) {
    result = strategy.adjustWhiteSpaceIfNecessary(result, startElement, startOffset, endOffset, codeStyleSettings);
  }
  return result;
}
 
Example 48
Project: intellij-ce-playground   File: UnnecessaryFullyQualifiedNameInspection.java   Source Code and License 5 votes vote down vote up
private static boolean acceptFqnInJavadoc(PsiJavaFile javaFile, String fullyQualifiedName, CodeStyleSettings styleSettings) {
  if ("package-info.java".equals(javaFile.getName())) {
    return true;
  }
  JavaCodeStyleSettings javaSettings = styleSettings.getCustomSettings(JavaCodeStyleSettings.class);
  if (javaSettings.CLASS_NAMES_IN_JAVADOC == JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_IF_NOT_IMPORTED) {
    return !ImportHelper.isAlreadyImported(javaFile, fullyQualifiedName);
  }
  return javaSettings.useFqNamesInJavadocAlways();
}
 
Example 49
Project: dotplugin   File: DotFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
    return new SpacingBuilder(settings, DotLanguage.INSTANCE)
            .around(DotTypes.EDGE_RHS)
            .spaceIf(settings.SPACE_AROUND_EQUALITY_OPERATORS)
            .around(DotTypes.EDGE_OP)
            .spaceIf(settings.SPACE_AROUND_EQUALITY_OPERATORS)
            .before(DotTypes.ATTR_LIST)
            .spaces(1)
            .before(DotTypes.CURLY_BRACHET_LEFT)
            .spaceIf(settings.SPACE_BEFORE_CLASS_LBRACE)
            .before(DotTypes.BRACHET_LEFT)
            .spaceIf(settings.SPACE_BEFORE_METHOD_LBRACE)
            .after(DotTypes.BRACHET_LEFT)
            .spaceIf(settings.SPACE_WITHIN_BRACKETS)
            .before(DotTypes.BRACKET_RIGHT)
            .spaceIf(settings.SPACE_WITHIN_BRACKETS)
            .after(DotTypes.EOS)
            .spaceIf(settings.SPACE_AFTER_SEMICOLON)
            .before(DotTypes.COMMENT)
            .spaces(1)
            .around(DotTypes.EQUAL)
            .spaceIf(settings.SPACE_AROUND_ASSIGNMENT_OPERATORS)
            .before(DotTypes.EOS)
            .spaceIf(settings.SPACE_BEFORE_SEMICOLON)
            .around(DotTypes.COLON)
            .spaceIf(settings.SPACE_AFTER_COLON);
}
 
Example 50
Project: intellij-ce-playground   File: CreateConstructorParameterFromFieldTest.java   Source Code and License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  enableInspectionTools(new UnusedDeclarationInspection(), new MissortedModifiersInspection(), new UnqualifiedFieldAccessInspection());
  final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  myPreferLongNames = settings.PREFER_LONGER_NAMES;
  if (getTestName(false).contains("SameParameter")) {
    settings.PREFER_LONGER_NAMES = false;
  }
}
 
Example 51
Project: intellij-ce-playground   File: BaseIndentEnterHandler.java   Source Code and License 5 votes vote down vote up
protected String getNewIndent(
  @NotNull final PsiFile file,
  @NotNull final Document document,
  @NotNull final CharSequence oldIndent)
{
  CharSequence nonEmptyIndent = oldIndent;
  final CharSequence editorCharSequence = document.getCharsSequence();
  final int nLines = document.getLineCount();
  for (int line = 0; line < nLines && nonEmptyIndent.length() == 0; ++line) {
    final int lineStart = document.getLineStartOffset(line);
    final int indentEnd = EditorActionUtil.findFirstNonSpaceOffsetOnTheLine(document, line);
    if (lineStart < indentEnd) {
      nonEmptyIndent = editorCharSequence.subSequence(lineStart, indentEnd);
    }
  }

  final boolean usesSpacesForIndentation = nonEmptyIndent.length() > 0 && nonEmptyIndent.charAt(nonEmptyIndent.length() - 1) == ' ';
  final boolean firstIndent = nonEmptyIndent.length() == 0;

  final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getSettings(file.getProject());
  final CommonCodeStyleSettings.IndentOptions indentOptions = currentSettings.getIndentOptions(file.getFileType());
  if (firstIndent && indentOptions.USE_TAB_CHARACTER || !firstIndent && !usesSpacesForIndentation) {
    int nTabsToIndent = indentOptions.INDENT_SIZE / indentOptions.TAB_SIZE;
    if (indentOptions.INDENT_SIZE % indentOptions.TAB_SIZE != 0) {
      ++nTabsToIndent;
    }
    return oldIndent + StringUtil.repeatSymbol('\t', nTabsToIndent);
  }
  return oldIndent + StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE);
}
 
Example 52
Project: ion-intellij-plugin   File: IonFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {

        SpacingBuilder sb = new SpacingBuilder(settings, IonLanguage.INSTANCE);
        sb.after(IonTypes.COMMA).lineBreakInCode();
        sb.after(IonTypes.LBRACE).lineBreakInCode();
        sb.before(IonTypes.RBRACE).lineBreakInCode();
        sb.after(IonTypes.LBRACKET).lineBreakInCode();
        sb.before(IonTypes.RBRACKET).lineBreakInCode();
        sb.before(IonTypes.PAIR).lineBreakInCode();
        sb.around(IonTypes.COMMA).spacing(0, 1, 0, false, 0);
        sb.afterInside(IonTypes.KEY, IonTypes.OBJECT).lineBreakInCode();
        sb.around(IonTypes.SEPARATOR).spaces(1);
        return sb;
    }
 
Example 53
Project: intellij-kubernetes   File: KubernetesYamlCompletionContributor.java   Source Code and License 5 votes vote down vote up
/**
 * Create a {@link LookupElementBuilder} for completing the text of a key. Do not use when completing a value.
 *
 * @param completionObject the object to pass to {@link LookupElementBuilder#create(Object)}.
 * @param addLayerOfNesting whether a newline and indent should be added when accepting the completed value - this is used when inserting the value will introduce a level of nesting (i.e. for an
 * object or array type).
 * @return the created {@code LookupElementBuilder}.
 */
private static LookupElementBuilder createKeyLookupElement(@NotNull final Object completionObject, final boolean addLayerOfNesting) {
    return LookupElementBuilder.create(completionObject).withInsertHandler((insertionContext, lookupElement) -> {
        // If the caret is at the end of the line, add in the property colon when completing
        if (insertionContext.getCompletionChar() != ':' && insertionContext.getCompletionChar() != ' ') {
            final Editor editor = insertionContext.getEditor();
            final int offset = editor.getCaretModel().getOffset();
            final int lineNumber = editor.getDocument().getLineNumber(offset);
            final int lineEndOffset = editor.getDocument().getLineEndOffset(lineNumber);
            if (lineEndOffset == offset) {
                final String autocompleteString;
                if (addLayerOfNesting) {
                    // Copy the indentation characters present on this line, and add one additional level of indentation
                    final int lineStartOffset = editor.getDocument().getLineStartOffset(lineNumber);
                    final String lineContent = editor.getDocument().getText().substring(lineStartOffset, lineEndOffset);
                    final int offsetOfContent = lineContent.length() - StringUtil.trimLeading(lineContent).length();
                    final String indentToLine = lineContent.substring(0, offsetOfContent);
                    final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getSettings(insertionContext.getProject());
                    final CommonCodeStyleSettings.IndentOptions indentOptions = currentSettings.getIndentOptions(insertionContext.getFile().getFileType());
                    final String additionalIndent = indentOptions.USE_TAB_CHARACTER ? "\t" : StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE);
                    autocompleteString = ":\n" + indentToLine + additionalIndent;
                } else {
                    autocompleteString = ": ";
                }
                EditorModificationUtil.insertStringAtCaret(editor, autocompleteString);
            }
        }
    });
}
 
Example 54
Project: intellij-ce-playground   File: XsltFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
static Block getDelegatingBlock(final CodeStyleSettings settings, FormattingModel baseModel) {
  final Block block = baseModel.getRootBlock();
  if (block instanceof XmlBlock) {
    final XmlBlock xmlBlock = (XmlBlock)block;

    final XmlPolicy xmlPolicy = new XmlPolicy(settings, baseModel.getDocumentModel()) {
      @Override
      public boolean keepWhiteSpacesInsideTag(XmlTag xmlTag) {
        return super.keepWhiteSpacesInsideTag(xmlTag) || isXslTextTag(xmlTag);
      }

      @Override
      public boolean isTextElement(XmlTag tag) {
        return super.isTextElement(tag) || isXslTextTag(tag) || isXslValueOfTag(tag);
      }
    };

    final ASTNode node = xmlBlock.getNode();
    final Wrap wrap = xmlBlock.getWrap();
    final Alignment alignment = xmlBlock.getAlignment();
    final Indent indent = xmlBlock.getIndent();
    final TextRange textRange = xmlBlock.getTextRange();

    return new XmlBlock(node, wrap, alignment, xmlPolicy, indent, textRange);
  } else {
    return block;
  }
}
 
Example 55
Project: intellij-ce-playground   File: AndroidXmlFormattingModelBuilder.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
  final FormattingModel baseModel = myXmlFormattingModelBuilder.createModel(element, settings);
  final AndroidXmlCodeStyleSettings baseSettings = AndroidXmlCodeStyleSettings.getInstance(settings);

  if (!baseSettings.USE_CUSTOM_SETTINGS) {
    return baseModel;
  }
  final ContextSpecificSettingsProviders.Provider provider = getContextSpecificSettings(element);
  final AndroidXmlCodeStyleSettings.MySettings s = provider != null ? provider.getSettings(baseSettings) : null;
  return s != null ? new DelegatingFormattingModel(baseModel, createDelegatingBlock(baseModel, s, settings)) : baseModel;
}
 
Example 56
Project: intellij-ce-playground   File: CodeStyleBlankLinesPanel.java   Source Code and License 5 votes vote down vote up
public void setFieldValue(CodeStyleSettings settings, int value) {
  try {
    if (myTargetClass != null) {
      myTarget.setInt(settings.getCustomSettings(myTargetClass), value);
    }
    else {
      CommonCodeStyleSettings commonSettings = settings.getCommonSettings(getDefaultLanguage());
      myTarget.setInt(commonSettings, value);
    }
  }
  catch (IllegalAccessException e) {
    LOG.error(e);
  }
}
 
Example 57
Project: intellij-ce-playground   File: OptionTreeWithPreviewPanel.java   Source Code and License 5 votes vote down vote up
private void resetNode(TreeNode node, final CodeStyleSettings settings) {
  if (node instanceof MyToggleTreeNode) {
    resetMyTreeNode((MyToggleTreeNode)node, settings);
    return;
  }
  for (int j = 0; j < node.getChildCount(); j++) {
    TreeNode child = node.getChildAt(j);
    resetNode(child, settings);
  }
}
 
Example 58
Project: intellij-ce-playground   File: JsonCodeStylePanel.java   Source Code and License 5 votes vote down vote up
@Override
protected void resetImpl(CodeStyleSettings settings) {
  for (int i = 0; i < myPropertiesAlignmentCombo.getItemCount(); i++) {
    if (((PropertyAlignment)myPropertiesAlignmentCombo.getItemAt(i)).getId() == getCustomSettings(settings).PROPERTY_ALIGNMENT) {
      myPropertiesAlignmentCombo.setSelectedIndex(i);
      break;
    }
  }
}
 
Example 59
Project: intellij-ce-playground   File: JavaIndentOptionsEditor.java   Source Code and License 5 votes vote down vote up
public void apply(final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions options) {
  super.apply(settings, options);
  options.LABEL_INDENT_SIZE = getFieldValue(myLabelIndent, Integer.MIN_VALUE, options.LABEL_INDENT_SIZE);

  options.LABEL_INDENT_ABSOLUTE = myLabelIndentAbsolute.isSelected();
  CommonCodeStyleSettings javaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
  javaSettings.DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS = myCbDontIndentTopLevelMembers.isSelected();
  options.USE_RELATIVE_INDENTS = myCbUseRelativeIndent.isSelected();
}
 
Example 60
Project: intellij-ce-playground   File: AndroidCodeStyleNotificationProvider.java   Source Code and License 5 votes vote down vote up
@Nullable
@Override
public MyPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
  if (file.getFileType() != XmlFileType.INSTANCE ||
      !(fileEditor instanceof TextEditor)) {
    return null;
  }
  final Module module = ModuleUtilCore.findModuleForFile(file, myProject);

  if (module == null) {
    return null;
  }
  final AndroidFacet facet = AndroidFacet.getInstance(module);

  if (facet == null) {
    return null;
  }
  final VirtualFile parent = file.getParent();
  final VirtualFile resDir = parent != null ? parent.getParent() : null;

  if (resDir == null || !facet.getLocalResourceManager().isResourceDir(resDir)) {
    return null;
  }
  final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myProject);
  final AndroidXmlCodeStyleSettings androidSettings = AndroidXmlCodeStyleSettings.getInstance(settings);

  if (androidSettings.USE_CUSTOM_SETTINGS) {
    return null;
  }
  if (NotificationsConfigurationImpl.getSettings(ANDROID_XML_CODE_STYLE_NOTIFICATION_GROUP).
    getDisplayType() == NotificationDisplayType.NONE) {
    return null;
  }
  NotificationsConfiguration.getNotificationsConfiguration().register(
    ANDROID_XML_CODE_STYLE_NOTIFICATION_GROUP, NotificationDisplayType.BALLOON, false);
  return new MyPanel();
}