Java Code Examples for com.intellij.psi.codeStyle.CodeStyleSettings#getCommonSettings()

The following examples show how to use com.intellij.psi.codeStyle.CodeStyleSettings#getCommonSettings() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLSLFormattingModelBuilder.java    From glsl4idea with GNU Lesser General Public License v3.0 8 votes vote down vote up
private SpacingBuilder createSpacingBuilder(CodeStyleSettings codeStyleSettings) {
    final CommonCodeStyleSettings commonSettings = codeStyleSettings.getCommonSettings(GLSLLanguage.GLSL_LANGUAGE);

    return new SpacingBuilder(codeStyleSettings, GLSLLanguage.GLSL_LANGUAGE)
            .before(COMMA).spaceIf(commonSettings.SPACE_BEFORE_COMMA)
            .after(COMMA).spaceIf(commonSettings.SPACE_AFTER_COMMA)
            .before(SEMICOLON).none()

            .after(LEFT_BRACKET).none()
            .before(RIGHT_BRACKET).none()

            .after(LEFT_BRACE).spaces(1)
            .before(RIGHT_BRACE).spaces(1)

            .withinPair(LEFT_PAREN, RIGHT_PAREN).spaceIf(commonSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES)

            .around(FLOW_KEYWORDS).spaces(1)

            .before(COMMENT_LINE).spaceIf(commonSettings.LINE_COMMENT_ADD_SPACE)
            ;
}
 
Example 2
Source File: FormattingModelBuilder.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Create spacing builder using given settings.
 */
public static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) {
    CommonCodeStyleSettings protoSettings = settings.getCommonSettings(ProtoLanguage.INSTANCE);
    SpacingBuilder builder = new SpacingBuilder(settings, ProtoLanguage.INSTANCE);
    builder.around(ASSIGN).spacing(1, 1, 0, false, 0);
    builder.before(SEMICOLON).spacing(0, 0, 0, false, 0);
    builder.after(LINE_COMMENT).spacing(0, 0, 1, true, 2);
    builder.after(LCURLY).spacing(0, 0, 1, true, 2);
    builder.before(RCURLY).spacing(0, 0, 1, true, 2);
    builder.after(LPAREN).spacing(0, 0, 0, false, 0);
    builder.before(RPAREN).spacing(0, 0, 0, false, 0);
    builder.after(LSQUARE).spacing(0, 0, 0, false, 0);
    builder.before(RSQUARE).spacing(0, 0, 0, false, 0);
    builder.before(LT).spacing(0, 0, 0, false, 0);
    builder.after(LT).spacing(0, 0, 0, false, 0);
    builder.before(GT).spacing(0, 0, 0, false, 0);
    builder.before(COMMA).spacing(0, 0, 0, false, 0);
    builder.before(SEMICOLON).spacing(0, 0, 0, false, 0);
    builder.after(COMMA).spacing(1, 1, 0, false, 0);
    return builder;
}
 
Example 3
Source File: OptionTreeWithPreviewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setValue(CodeStyleSettings settings, Boolean aBoolean) {
  try {
    CommonCodeStyleSettings commonSettings = settings.getCommonSettings(getDefaultLanguage());
    field.set(commonSettings, aBoolean);
  }
  catch (Throwable e) {
    LOG.error("Field: " + field, e);
  }
}
 
Example 4
Source File: ArrangementSettingsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(CodeStyleSettings settings) {
  CommonCodeStyleSettings commonSettings = settings.getCommonSettings(myLanguage);
  commonSettings.setArrangementSettings(createSettings());
  if (myForceArrangementPanel != null) {
    commonSettings.FORCE_REARRANGE_MODE = myForceArrangementPanel.getRearrangeMode();
  }
}
 
Example 5
Source File: CodeStyleBlankLinesPanel.java    From consulo with Apache License 2.0 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 6
Source File: CodeStyleBlankLinesPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private int getFieldValue(CodeStyleSettings settings) {
  try {
    if (myTargetClass != null) {
      return myTarget.getInt(settings.getCustomSettings(myTargetClass));
    }
    CommonCodeStyleSettings commonSettings = settings.getCommonSettings(getDefaultLanguage());
    return myTarget.getInt(commonSettings);
  }
  catch (IllegalAccessException e) {
    throw new RuntimeException(e);
  }
}
 
Example 7
Source File: CommenterForm.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void reset(@Nonnull CodeStyleSettings settings) {
  CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
  myLineCommentAtFirstColumnCb.setSelected(langSettings.LINE_COMMENT_AT_FIRST_COLUMN);
  myBlockCommentAtFirstJBCheckBox.setSelected(langSettings.BLOCK_COMMENT_AT_FIRST_COLUMN);
  myLineCommentAddSpaceCb.setSelected(langSettings.LINE_COMMENT_ADD_SPACE && !langSettings.LINE_COMMENT_AT_FIRST_COLUMN);
  myLineCommentAddSpaceCb.setEnabled(!langSettings.LINE_COMMENT_AT_FIRST_COLUMN);
}
 
Example 8
Source File: OptionTreeWithPreviewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean getValue(CodeStyleSettings settings) throws IllegalAccessException {
  try {
    CommonCodeStyleSettings commonSettings = settings.getCommonSettings(getDefaultLanguage());
    return field.getBoolean(commonSettings);
  }
  catch (Throwable e) {
    LOG.error("Field: " + field, e);
    return false;
  }
}
 
Example 9
Source File: FusionFormattingModelBuilder.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
    final FusionCodeStyleSettings fusionSettings = settings.getCustomSettings(FusionCodeStyleSettings.class);
    final CommonCodeStyleSettings commonSettings = settings.getCommonSettings(FusionLanguage.INSTANCE);

    SpacingBuilder spacingBuilder = new SpacingBuilder(settings, FusionLanguage.INSTANCE);
    spacingBuilder.before(FusionTypes.BLOCK).spaces(1);

    if (commonSettings.SPACE_AFTER_COMMA) {
        spacingBuilder.after(FusionTypes.VALUE_SEPARATOR).spaces(1);
    } else {
        spacingBuilder.after(FusionTypes.VALUE_SEPARATOR).none();
    }

    if (commonSettings.SPACE_AROUND_ASSIGNMENT_OPERATORS) {
        spacingBuilder.around(FusionTypes.ASSIGNMENT_OPERATOR).spaces(1);
    } else {
        spacingBuilder.around(FusionTypes.VALUE_SEPARATOR).none();
    }

    spacingBuilder.before(FusionTypes.UNSET_OPERATOR).spaces(1)
    .around(FusionTypes.COPY_OPERATOR).spaces(1)
    .around(FusionTypes.EEL_ADDITION_OPERATOR).spaces(1)
    .around(FusionTypes.EEL_SUBTRACTION_OPERATOR).spaces(1)
    .around(FusionTypes.EEL_MULTIPLICATION_OPERATOR).spaces(1)
    .around(FusionTypes.EEL_DIVISION_OPERATOR).spaces(1)
    .around(FusionTypes.EEL_MODULO_OPERATOR).spaces(1)
    .around(FusionTypes.EEL_COMPARISON_OPERATOR).spaces(1)
    .around(FusionTypes.NAMESPACE_ALIAS_SEPARATOR).spaces(1)
    .before(FusionTypes.NAMESPACE_SEPARATOR).none()
    .after(FusionTypes.NAMESPACE_SEPARATOR).spaces(1)
    .before(FusionTypes.INCLUDE_SEPARATOR).none()
    .after(FusionTypes.INCLUDE_SEPARATOR).spaces(1)
    .after(FusionTypes.EEL_LEFT_BRACE).none()
    .before(FusionTypes.EEL_RIGHT_BRACE).none()
    .between(FusionTypes.BLOCK, FusionTypes.PATH).blankLines(1);

    return spacingBuilder;
}
 
Example 10
Source File: CodeStyleManager.java    From editorconfig-jetbrains with MIT License 5 votes vote down vote up
private void applyCodeStyleSettings(final List<OutPair> outPairs, final CodeStyleSettings codeStyleSettings,
                                    final VirtualFile file) {
    // Apply indent options
    final String indentSize = Utils.configValueForKey(outPairs, indentSizeKey);
    final String tabWidth = Utils.configValueForKey(outPairs, tabWidthKey);
    final String indentStyle = Utils.configValueForKey(outPairs, indentStyleKey);
    final FileType fileType = file.getFileType();
    final Language language = fileType instanceof LanguageFileType ? ((LanguageFileType)fileType).getLanguage() :
        PlainTextLanguage.INSTANCE;
    final CommonCodeStyleSettings commonSettings = codeStyleSettings.getCommonSettings(language);
    final CommonCodeStyleSettings.IndentOptions indentOptions = commonSettings.getIndentOptions();
    applyIndentOptions(indentOptions, indentSize, tabWidth, indentStyle, file.getCanonicalPath());
}
 
Example 11
Source File: XQueryFormattingModelBuilder.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    CommonCodeStyleSettings commonSettings = settings.getCommonSettings(XQueryLanguage.INSTANCE);
    XQueryCodeStyleSettings xQuerySettings = settings.getCustomSettings(XQueryCodeStyleSettings.class);
    final XQueryFormattingBlock block = new XQueryFormattingBlock(element.getNode(), null, null, commonSettings,
            createSpacingBuilder(commonSettings, xQuerySettings, settings));
    FormattingModel result = createFormattingModelForPsiFile(element.getContainingFile(), block, settings);
    return result;
}
 
Example 12
Source File: HaxeFormatterTest.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
protected void defineStyleSettings(CodeStyleSettings tempSettings) {
  myTestStyleSettings = tempSettings.getCommonSettings(HaxeLanguage.INSTANCE);
  myTestStyleSettings.KEEP_BLANK_LINES_IN_CODE = 2;
  myTestStyleSettings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
  myTestStyleSettings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
  myTestStyleSettings.ALIGN_MULTILINE_PARAMETERS = false;
  myTestStyleSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false;
  myTestStyleSettings.KEEP_FIRST_COLUMN_COMMENT = false;
}
 
Example 13
Source File: CSharpFormattingBlock.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public CSharpFormattingBlock(@Nonnull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, @Nonnull CodeStyleSettings settings)
{
	super(node, wrap, alignment);
	mySettings = settings;
	CommonCodeStyleSettings commonSettings = settings.getCommonSettings(CSharpLanguage.INSTANCE);
	CSharpCodeStyleSettings customSettings = settings.getCustomSettings(CSharpCodeStyleSettings.class);

	myWrappingProcessor = new CSharpWrappingProcessor(node, commonSettings, customSettings);
	myIndentProcessor = new CSharpIndentProcessor(this, commonSettings, customSettings);
	mySpacingProcessor = new CSharpSpacingProcessor(this, commonSettings, customSettings);
}
 
Example 14
Source File: FormatterTest.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
private void run(String test, Consumer<CommonCodeStyleSettings> settings) {
    myFixture.configureByFiles(test + "/Source.proto");
    CodeStyleSettings codeStyleSettings = CodeStyle.getSettings(getProject());
    CommonCodeStyleSettings protoSettings = codeStyleSettings.getCommonSettings(ProtoLanguage.INSTANCE);
    settings.accept(protoSettings);
    WriteCommandAction.writeCommandAction(getProject())
            .run(() -> CodeStyleManager.getInstance(getProject()).reformat(myFixture.getFile()));
    myFixture.checkResultByFile(test + "/Expected.proto");
}
 
Example 15
Source File: CommenterForm.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void apply(@Nonnull CodeStyleSettings settings) {
  CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
  langSettings.LINE_COMMENT_AT_FIRST_COLUMN = myLineCommentAtFirstColumnCb.isSelected();
  langSettings.BLOCK_COMMENT_AT_FIRST_COLUMN = myBlockCommentAtFirstJBCheckBox.isSelected();
  langSettings.LINE_COMMENT_ADD_SPACE = myLineCommentAddSpaceCb.isSelected();
}
 
Example 16
Source File: CommenterForm.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean isModified(@Nonnull CodeStyleSettings settings) {
  CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
  return myLineCommentAtFirstColumnCb.isSelected() != langSettings.LINE_COMMENT_AT_FIRST_COLUMN ||
         myBlockCommentAtFirstJBCheckBox.isSelected() != langSettings.BLOCK_COMMENT_AT_FIRST_COLUMN ||
         myLineCommentAddSpaceCb.isSelected() != langSettings.LINE_COMMENT_ADD_SPACE;
}
 
Example 17
Source File: OptionTableWithPreviewPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected Object getSettings(CodeStyleSettings settings) {
  if (clazz != null) return settings.getCustomSettings(clazz);
  return settings.getCommonSettings(getDefaultLanguage());
}
 
Example 18
Source File: ArrangementSettingsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isModified(CodeStyleSettings settings) {
  final StdArrangementSettings s = createSettings();
  return !Comparing.equal(getSettings(settings), s)
         || myForceArrangementPanel != null && settings.getCommonSettings(myLanguage).FORCE_REARRANGE_MODE != myForceArrangementPanel.getRearrangeMode();
}
 
Example 19
Source File: SpacingBuilder.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Creates SpacingBuilder with given code style settings and language whose settings must be used.
 * @param codeStyleSettings The root code style settings.
 * @param language          The language to obtain settings for.
 */
public SpacingBuilder(@Nonnull CodeStyleSettings codeStyleSettings, @Nonnull Language language) {
  myCodeStyleSettings = codeStyleSettings.getCommonSettings(language);
}