下面列出了com.intellij.psi.codeStyle.CodeStyleSettings# getCommonSettings ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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)
;
}
/**
* 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;
}
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;
}
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");
}
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);
}
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;
}
@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;
}
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());
}
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);
}
}
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;
}
}
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);
}
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);
}
}
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);
}
}
@Override
public void apply(CodeStyleSettings settings) {
CommonCodeStyleSettings commonSettings = settings.getCommonSettings(myLanguage);
commonSettings.setArrangementSettings(createSettings());
if (myForceArrangementPanel != null) {
commonSettings.FORCE_REARRANGE_MODE = myForceArrangementPanel.getRearrangeMode();
}
}
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();
}
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;
}
protected Object getSettings(CodeStyleSettings settings) {
if (clazz != null) return settings.getCustomSettings(clazz);
return settings.getCommonSettings(getDefaultLanguage());
}
@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();
}
/**
* 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);
}