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

The following examples show how to use com.intellij.psi.codeStyle.CodeStyleSettings#getCustomSettings() . 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: CsvFormatHelper.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public static int getTextLength(String textInput, CodeStyleSettings codeStyleSettings) {
    String text = textInput;
    CsvCodeStyleSettings csvCodeStyleSettings = codeStyleSettings.getCustomSettings(CsvCodeStyleSettings.class);
    int length = 0;
    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 += 2;
    }
    length += CsvHelper.getMaxTextLineLength(text, input ->
            csvCodeStyleSettings.ENABLE_WIDE_CHARACTER_DETECTION ?
                    charWidth(input, csvCodeStyleSettings.TREAT_AMBIGUOUS_CHARACTERS_AS_WIDE) :
                    input.length()
    );

    return length;
}
 
Example 2
Source File: FluidTypedHandler.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
private static boolean isWhitespaceRequired(Project project, char c) {
    CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
    FluidCodeStyleSettings options = settings.getCustomSettings(FluidCodeStyleSettings.class);

    switch(c) {
    case '{':
        return options.SPACES_INSIDE_VARIABLE_DELIMITERS;
    default:
        return false;
    }
}
 
Example 3
Source File: CsvFormatHelper.java    From intellij-csv-validator with Apache License 2.0 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)
                .after(CsvElementType.DOCUMENT_START).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 4
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 5
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 6
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 7
Source File: IdeHelper.java    From yiistorm with MIT License 5 votes vote down vote up
public static XmlCodeStyleSettings getXmlSettings(Project project) {
    CodeStyleSettings settings = getSettings(project);
    if (settings != null) {
        return settings.getCustomSettings(XmlCodeStyleSettings.class);
    }
    return null;
}
 
Example 8
Source File: OptionTreeWithPreviewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setValue(CodeStyleSettings settings, Boolean aBoolean) {
  final CustomCodeStyleSettings customSettings = settings.getCustomSettings(mySettingsClass);
  try {
    field.set(customSettings, aBoolean);
  }
  catch (Throwable e) {
    LOG.error("Field: " + field, e);
  }
}
 
Example 9
Source File: OptionTreeWithPreviewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getValue(CodeStyleSettings settings) throws IllegalAccessException {
  try {
    final CustomCodeStyleSettings customSettings = settings.getCustomSettings(mySettingsClass);
    return field.getBoolean(customSettings);
  }
  catch (Throwable e) {
    LOG.error("Field: " + field, e);
    return false;
  }
}
 
Example 10
Source File: BuildEnterHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
/**
 * Returns null if an appropriate indent cannot be found. In that case we do nothing, and pass it
 * along to the next EnterHandler.
 */
@Nullable
private static Integer determineIndent(
    PsiFile file, Editor editor, int offset, CodeStyleSettings settings) {
  if (offset == 0) {
    return null;
  }
  Document doc = editor.getDocument();
  PsiElement element = getRelevantElement(file, doc, offset);
  PsiElement parent = element != null ? element.getParent() : null;
  if (parent == null) {
    return null;
  }

  IndentOptions indentOptions = settings.getIndentOptions(file.getFileType());
  BuildCodeStyleSettings buildSettings = settings.getCustomSettings(BuildCodeStyleSettings.class);
  if (endsBlock(element)) {
    // current line indent subtract block indent
    return Math.max(0, getIndent(doc, element) - indentOptions.INDENT_SIZE);
  }

  if (parent instanceof BuildListType) {
    BuildListType list = (BuildListType) parent;
    if (endsList(list, element) && element.getTextOffset() < offset) {
      return null;
    }
    int listOffset = list.getStartOffset();
    LogicalPosition caretPosition = editor.getCaretModel().getLogicalPosition();
    LogicalPosition listStart = editor.offsetToLogicalPosition(listOffset);
    if (listStart.line != caretPosition.line) {
      // take the minimum of the current line's indent and the current caret position
      return indentOfLineUpToCaret(doc, caretPosition.line, offset);
    }
    BuildElement firstChild = ((BuildListType) parent).getFirstElement();
    if (firstChild != null && firstChild.getNode().getStartOffset() < offset) {
      return getIndent(doc, firstChild);
    }
    return lineIndent(doc, listStart.line)
        + additionalIndent(parent, buildSettings, indentOptions);
  }
  if (parent instanceof StatementListContainer && afterColon(doc, offset)) {
    return getIndent(doc, parent) + additionalIndent(parent, buildSettings, indentOptions);
  }
  return null;
}
 
Example 11
Source File: BuildIndentOptionsEditor.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static BuildCodeStyleSettings getCustomSettings(CodeStyleSettings settings) {
  return settings.getCustomSettings(BuildCodeStyleSettings.class);
}
 
Example 12
Source File: CSharpCodeGenerationSettingsConfigurable.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CSharpCodeGenerationSettingsConfigurable(CodeStyleSettings settings)
{
	mySettings = settings.getCustomSettings(CSharpCodeGenerationSettings.class);
}
 
Example 13
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());
}