com.intellij.psi.codeStyle.CodeStyleSettingsManager Java Examples

The following examples show how to use com.intellij.psi.codeStyle.CodeStyleSettingsManager. 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: CsvFormatterTest.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
private void initCsvCodeStyleSettings(boolean SPACE_BEFORE_SEPARATOR,
                                      boolean SPACE_AFTER_SEPARATOR,
                                      boolean TRIM_LEADING_WHITE_SPACES,
                                      boolean TRIM_TRAILING_WHITE_SPACES,
                                      boolean TABULARIZE,
                                      boolean WHITE_SPACES_OUTSIDE_QUOTES,
                                      boolean LEADING_WHITE_SPACES,
                                      boolean ENABLE_WIDE_CHARACTER_DETECTION,
                                      boolean TREAT_AMBIGUOUS_CHARACTERS_AS_WIDE) {
    CsvCodeStyleSettings csvCodeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(CsvCodeStyleSettings.class);
    csvCodeStyleSettings.SPACE_BEFORE_SEPARATOR = SPACE_BEFORE_SEPARATOR;
    csvCodeStyleSettings.SPACE_AFTER_SEPARATOR = SPACE_AFTER_SEPARATOR;
    csvCodeStyleSettings.TRIM_LEADING_WHITE_SPACES = TRIM_LEADING_WHITE_SPACES;
    csvCodeStyleSettings.TRIM_TRAILING_WHITE_SPACES = TRIM_TRAILING_WHITE_SPACES;
    csvCodeStyleSettings.TABULARIZE = TABULARIZE;
    csvCodeStyleSettings.WHITE_SPACES_OUTSIDE_QUOTES = WHITE_SPACES_OUTSIDE_QUOTES;
    csvCodeStyleSettings.LEADING_WHITE_SPACES = LEADING_WHITE_SPACES;
    csvCodeStyleSettings.ENABLE_WIDE_CHARACTER_DETECTION = ENABLE_WIDE_CHARACTER_DETECTION;
    csvCodeStyleSettings.TREAT_AMBIGUOUS_CHARACTERS_AS_WIDE = TREAT_AMBIGUOUS_CHARACTERS_AS_WIDE;
}
 
Example #2
Source File: SettingsImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public int getTabSize(Project project) {
  if (myTabSize != null) return myTabSize;
  if (myCachedTabSize != null) return myCachedTabSize;
  int tabSize;
  if (project == null || project.isDisposed()) {
    tabSize = CodeStyleSettingsManager.getSettings(null).getTabSize(null);
  }
  else {
    PsiFile file = getPsiFile(project);
    if (myEditor != null && myEditor.isViewer()) {
      FileType fileType = file != null ? file.getFileType() : null;
      tabSize = CodeStyleSettingsManager.getSettings(project).getIndentOptions(fileType).TAB_SIZE;
    }
    else {
      tabSize = CodeStyleSettingsManager.getSettings(project).getIndentOptionsByFile(file).TAB_SIZE;
    }
  }
  myCachedTabSize = Integer.valueOf(tabSize);
  return tabSize;
}
 
Example #3
Source File: FileTemplateUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static String mergeTemplate(String templateContent, final VelocityContext context, boolean useSystemLineSeparators) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  try {
    VelocityWrapper.evaluate(null, context, stringWriter, templateContent);
  }
  catch (final VelocityException e) {
    LOG.error("Error evaluating template:\n" + templateContent, e);
    ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(IdeBundle.message("error.parsing.file.template", e.getMessage()), IdeBundle.message("title.velocity.error")));
  }
  final String result = stringWriter.toString();

  if (useSystemLineSeparators) {
    final String newSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
    if (!"\n".equals(newSeparator)) {
      return StringUtil.convertLineSeparators(result, newSeparator);
    }
  }

  return result;
}
 
Example #4
Source File: QuickChangeCodeStyleSchemeAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void fillActions(Project project, @Nonnull DefaultActionGroup group, @Nonnull DataContext dataContext) {
  final CodeStyleSettingsManager manager = CodeStyleSettingsManager.getInstance(project);
  if (manager.PER_PROJECT_SETTINGS != null) {
    //noinspection HardCodedStringLiteral
    group.add(new AnAction("<project>", "",
                           manager.USE_PER_PROJECT_SETTINGS ? ourCurrentAction : ourNotCurrentAction) {
      @Override
      public void actionPerformed(@Nonnull AnActionEvent e) {
        manager.USE_PER_PROJECT_SETTINGS = true;
      }
    });
  }

  CodeStyleScheme currentScheme = CodeStyleSchemes.getInstance().getCurrentScheme();
  for (CodeStyleScheme scheme : CodeStyleSchemes.getInstance().getSchemes()) {
    addScheme(group, manager, currentScheme, scheme, false);
  }
}
 
Example #5
Source File: IndentSelectionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void indentSelection(Editor editor, Project project) {
  int oldSelectionStart = editor.getSelectionModel().getSelectionStart();
  int oldSelectionEnd = editor.getSelectionModel().getSelectionEnd();
  if(!editor.getSelectionModel().hasSelection()) {
    oldSelectionStart = editor.getCaretModel().getOffset();
    oldSelectionEnd = oldSelectionStart;
  }

  Document document = editor.getDocument();
  int startIndex = document.getLineNumber(oldSelectionStart);
  if(startIndex == -1) {
    startIndex = document.getLineCount() - 1;
  }
  int endIndex = document.getLineNumber(oldSelectionEnd);
  if(endIndex > 0 && document.getLineStartOffset(endIndex) == oldSelectionEnd && editor.getSelectionModel().hasSelection()) {
    endIndex --;
  }
  if(endIndex == -1) {
    endIndex = document.getLineCount() - 1;
  }

  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
  int blockIndent = CodeStyleSettingsManager.getSettings(project).getIndentOptionsByFile(file).INDENT_SIZE;
  doIndent(endIndex, startIndex, document, project, editor, blockIndent);
}
 
Example #6
Source File: FormatterTestCase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void defaultSettings() {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());

  settings.ALIGN_MULTILINE_PARAMETERS = true;
  settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false;
  settings.ALIGN_MULTILINE_FOR = true;

  settings.ALIGN_MULTILINE_BINARY_OPERATION = false;
  settings.ALIGN_MULTILINE_TERNARY_OPERATION = false;
  settings.ALIGN_MULTILINE_THROWS_LIST = false;
  settings.ALIGN_MULTILINE_EXTENDS_LIST = false;
  settings.ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION = false;
  settings.DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS = false;

  getSettings().SPACE_BEFORE_ANOTATION_PARAMETER_LIST = false;
  getSettings().SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
  getSettings().SPACE_WITHIN_ANNOTATION_PARENTHESES = false;
  getSettings().SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
}
 
Example #7
Source File: TextPainter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public TextPainter(DocumentEx editorDocument,
                   EditorHighlighter highlighter,
                   String fileName,
                   final Project project,
                   final FileType fileType, final List<LineMarkerInfo> separators) {
  myCodeStyleSettings = CodeStyleSettingsManager.getSettings(project);
  myDocument = editorDocument;
  myPrintSettings = PrintSettings.getInstance();
  String fontName = myPrintSettings.FONT_NAME;
  int fontSize = myPrintSettings.FONT_SIZE;
  myPlainFont = new Font(fontName, Font.PLAIN, fontSize);
  myBoldFont = new Font(fontName, Font.BOLD, fontSize);
  myItalicFont = new Font(fontName, Font.ITALIC, fontSize);
  myBoldItalicFont = new Font(fontName, Font.BOLD | Font.ITALIC, fontSize);
  myHighlighter = highlighter;
  myHeaderFont = new Font(myPrintSettings.FOOTER_HEADER_FONT_NAME, Font.PLAIN,
                          myPrintSettings.FOOTER_HEADER_FONT_SIZE);
  myFileName = fileName;
  mySegmentEnd = myDocument.getTextLength();
  myFileType = fileType;
  myMethodSeparators = separators != null ? separators.toArray(new LineMarkerInfo[separators.size()]) : new LineMarkerInfo[0];
  myCurrentMethodSeparator = 0;
}
 
Example #8
Source File: GenericUtil.java    From intellij-spring-assistant with MIT 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 #9
Source File: UnindentSelectionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void unindentSelection(Editor editor, Project project) {
  int oldSelectionStart = editor.getSelectionModel().getSelectionStart();
  int oldSelectionEnd = editor.getSelectionModel().getSelectionEnd();
  if(!editor.getSelectionModel().hasSelection()) {
    oldSelectionStart = editor.getCaretModel().getOffset();
    oldSelectionEnd = oldSelectionStart;
  }

  Document document = editor.getDocument();
  int startIndex = document.getLineNumber(oldSelectionStart);
  if(startIndex == -1) {
    startIndex = document.getLineCount() - 1;
  }
  int endIndex = document.getLineNumber(oldSelectionEnd);
  if(endIndex > 0 && document.getLineStartOffset(endIndex) == oldSelectionEnd && endIndex > startIndex) {
    endIndex --;
  }
  if(endIndex == -1) {
    endIndex = document.getLineCount() - 1;
  }

  if (startIndex < 0 || endIndex < 0) return;

  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);

  int blockIndent = CodeStyleSettingsManager.getSettings(project).getIndentOptionsByFile(file).INDENT_SIZE;
  IndentSelectionAction.doIndent(endIndex, startIndex, document, project, editor, -blockIndent);
}
 
Example #10
Source File: FormatterTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
protected void setUp() throws Exception {
  super.setUp();
  assertFalse(CodeStyleSettingsManager.getInstance(getProject()).USE_PER_PROJECT_SETTINGS);
  assertNull(CodeStyleSettingsManager.getInstance(getProject()).PER_PROJECT_SETTINGS);
}
 
Example #11
Source File: LightPlatformCodeInsightTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void checkCaretPosition(final RangeMarker caretMarker, String newFileText, String message) {
  if (caretMarker != null) {
    int caretLine = StringUtil.offsetToLineNumber(newFileText, caretMarker.getStartOffset());
    //int caretCol = caretMarker.getStartOffset() - StringUtil.lineColToOffset(newFileText, caretLine, 0);
    int caretCol = EditorUtil.calcColumnNumber(null, newFileText,
                                               StringUtil.lineColToOffset(newFileText, caretLine, 0),
                                               caretMarker.getStartOffset(),
                                               CodeStyleSettingsManager.getSettings(getProject()).getIndentOptions(InternalStdFileTypes.JAVA).TAB_SIZE);

    assertEquals(getMessage("caretLine", message), caretLine, myEditor.getCaretModel().getLogicalPosition().line);
    assertEquals(getMessage("caretColumn", message), caretCol, myEditor.getCaretModel().getLogicalPosition().column);
  }
}
 
Example #12
Source File: LightPlatformCodeInsightTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void setupCaret(final RangeMarker caretMarker, String fileText) {
  if (caretMarker != null) {
    int caretLine = StringUtil.offsetToLineNumber(fileText, caretMarker.getStartOffset());
    int caretCol = EditorUtil.calcColumnNumber(null, myEditor.getDocument().getText(),
                                               myEditor.getDocument().getLineStartOffset(caretLine), caretMarker.getStartOffset(),
                                               CodeStyleSettingsManager.getSettings(getProject()).getIndentOptions(InternalStdFileTypes.JAVA).TAB_SIZE);
    LogicalPosition pos = new LogicalPosition(caretLine, caretCol);
    myEditor.getCaretModel().moveToLogicalPosition(pos);
  }
}
 
Example #13
Source File: CustomFoldingSurroundDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void adjustLineIndent(@Nonnull Project project, PsiFile file, Language language, TextRange range) {
  CommonCodeStyleSettings formatSettings = CodeStyleSettingsManager.getSettings(project).getCommonSettings(language);
  boolean keepAtFirstCol = formatSettings.KEEP_FIRST_COLUMN_COMMENT;
  formatSettings.KEEP_FIRST_COLUMN_COMMENT = false;
  CodeStyleManager.getInstance(project).adjustLineIndent(file, range);
  formatSettings.KEEP_FIRST_COLUMN_COMMENT = keepAtFirstCol;
}
 
Example #14
Source File: LightIdeaTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
  Project project = getProject();
  CodeStyleSettingsManager.getInstance(project).dropTemporarySettings();

  LightPlatformTestCase.doTearDown(project, LightPlatformTestCase.getApplication(), true);
  super.tearDown();
  InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project);
  PersistentFS.getInstance().clearIdCache();
}
 
Example #15
Source File: LightPlatformTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
  Project project = getProject();
  CodeStyleSettingsManager.getInstance(project).dropTemporarySettings();
  checkForSettingsDamage();
  doTearDown(project, ourApplication, true);

  try {
    super.tearDown();
  }
  finally {
    myThreadTracker.checkLeak();
  }
}
 
Example #16
Source File: EnterInStringLiteralHandlerTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
@After
protected void tearDown() throws Exception {
    CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();

    super.tearDown();
}
 
Example #17
Source File: BashFormatterTestCase.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
protected void setSettingsBack() {
    final CodeStyleSettingsManager manager = CodeStyleSettingsManager.getInstance(myFixture.getProject());
    myTempSettings.getIndentOptions(BashFileType.BASH_FILE_TYPE).INDENT_SIZE = 200;
    myTempSettings.getIndentOptions(BashFileType.BASH_FILE_TYPE).CONTINUATION_INDENT_SIZE = 200;
    myTempSettings.getIndentOptions(BashFileType.BASH_FILE_TYPE).TAB_SIZE = 200;

    myTempSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 5;
    manager.dropTemporarySettings();
    myTempSettings = null;
}
 
Example #18
Source File: EnterInStringLiteralHandlerTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Before
protected void setUp() throws Exception {
    super.setUp();
    CodeStyleSettings temp = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().clone();
    temp.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.WRAP.intValue;
    CodeStyleSettingsManager.getInstance(myFixture.getProject()).setTemporarySettings(temp);
}
 
Example #19
Source File: SettingsImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void reinitDocumentIndentOptions() {
  if (myEditor == null || myEditor.isViewer()) return;
  final Project project = myEditor.getProject();
  final DocumentEx document = myEditor.getDocument();

  if (project == null || project.isDisposed()) return;

  final PsiDocumentManager psiManager = PsiDocumentManager.getInstance(project);
  final PsiFile file = psiManager.getPsiFile(document);
  if (file == null) return;

  CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
}
 
Example #20
Source File: PlatformTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  if (ourTestCase != null) {
    String message = "Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call.";
    ourTestCase = null;
    fail(message);
  }

  LOGGER.info(getClass().getName() + ".setUp()");

  initApplication();

  myEditorListenerTracker = new EditorListenerTracker();
  myThreadTracker = new ThreadTracker();

  setUpProject();

  storeSettings();
  ourTestCase = this;
  if (myProject != null) {
    ProjectManagerEx.getInstanceEx().openTestProject(myProject);
    CodeStyleSettingsManager.getInstance(myProject).setTemporarySettings(new CodeStyleSettings());
    InjectedLanguageManagerImpl.pushInjectors(getProject());
  }

  DocumentCommitThread.getInstance().clearQueue();
  UIUtil.dispatchAllInvocationEvents();
}
 
Example #21
Source File: BaseIndentEnterHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected String getNewIndent(
        @Nonnull final PsiFile file,
        @Nonnull final Document document,
        @Nonnull 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 #22
Source File: CodeStyleSchemesModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Updates 'use per-project settings' value within the current model and optionally at the project settings.
 *
 * @param usePerProjectSettings  defines whether 'use per-project settings' are in use
 * @param commit                 flag that defines if current project settings should be applied as well
 */
public void setUsePerProjectSettings(final boolean usePerProjectSettings, final boolean commit) {
  if (commit) {
    final CodeStyleSettingsManager projectSettings = getProjectSettings();
    projectSettings.USE_PER_PROJECT_SETTINGS = usePerProjectSettings;
    projectSettings.PER_PROJECT_SETTINGS = myProjectScheme.getCodeStyleSettings();
  }

  if (myUsePerProjectSettings != usePerProjectSettings) {
    myUsePerProjectSettings = usePerProjectSettings;
    myDispatcher.getMulticaster().usePerProjectSettingsOptionChanged();
    myDispatcher.getMulticaster().currentSchemeChanged(this);
  }
}
 
Example #23
Source File: CodeStyleSchemesModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void apply() {
  CodeStyleSettingsManager projectSettingsManager = getProjectSettings();
  projectSettingsManager.USE_PER_PROJECT_SETTINGS = myUsePerProjectSettings;
  projectSettingsManager.PREFERRED_PROJECT_CODE_STYLE =
          myUsePerProjectSettings || myGlobalSelected == null ? null : myGlobalSelected.getName();
  projectSettingsManager.PER_PROJECT_SETTINGS = myProjectScheme.getCodeStyleSettings();

  final CodeStyleScheme[] savedSchemes = CodeStyleSchemes.getInstance().getSchemes();
  final Set<CodeStyleScheme> savedSchemesSet = new HashSet<CodeStyleScheme>(Arrays.asList(savedSchemes));
  List<CodeStyleScheme> configuredSchemes = getSchemes();

  for (CodeStyleScheme savedScheme : savedSchemes) {
    if (!configuredSchemes.contains(savedScheme)) {
      CodeStyleSchemes.getInstance().deleteScheme(savedScheme);
    }
  }

  for (CodeStyleScheme configuredScheme : configuredSchemes) {
    if (!savedSchemesSet.contains(configuredScheme)) {
      CodeStyleSchemes.getInstance().addScheme(configuredScheme);
    }
  }

  CodeStyleSchemes.getInstance().setCurrentScheme(myGlobalSelected);

  // We want to avoid the situation when 'real code style' differs from the copy stored here (e.g. when 'real code style' changes
  // are 'committed' by pressing 'Apply' button). So, we reset the copies here assuming that this method is called on 'Apply'
  // button processing
  mySettingsToClone.clear();
}
 
Example #24
Source File: HTMLTextPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"HardCodedStringLiteral"})
private void writeString(Writer writer, CharSequence charArray, int start, int length, FileType fileType) throws IOException {
  for(int i=start; i<start+length; i++) {
    char c = charArray.charAt(i);
    if(c=='<') {
      writeChar(writer, "&lt;");
    }
    else if(c=='>') {
      writeChar(writer, "&gt;");
    }
    else if (c=='&') {
      writeChar(writer, "&amp;");
    }
    else if (c=='\"') {
      writeChar(writer, "&quot;");
    }
    else if (c == '\t') {
      int tabSize = CodeStyleSettingsManager.getSettings(myProject).getTabSize(fileType);
      if (tabSize <= 0) tabSize = 1;
      int nSpaces = tabSize - myColumn % tabSize;
      for (int j = 0; j < nSpaces; j++) {
        writeChar(writer, " ");
      }
    }
    else if (c == '\n' || c == '\r') {
      if (c == '\r' && i+1 < start+length && charArray.charAt(i+1) == '\n') {
        writeChar(writer, " \r");
        i++;
      }
      else if (c == '\n') {
        writeChar(writer, " ");
      }
      writeLineNumber(writer);
    }
    else {
      writeChar(writer, String.valueOf(c));
    }
  }
}
 
Example #25
Source File: PsiViewerDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Block buildBlocks(@Nonnull 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;
  }
}
 
Example #26
Source File: FormattingDocumentModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FormattingDocumentModelImpl(@Nonnull final Document document, PsiFile file) {
  myDocument = document;
  myFile = file;
  if (file != null) {
    Language language = file.getLanguage();
    myWhiteSpaceStrategy = WhiteSpaceFormattingStrategyFactory.getStrategy(language);
  }
  else {
    myWhiteSpaceStrategy = WhiteSpaceFormattingStrategyFactory.getStrategy();
  }
  mySettings = CodeStyleSettingsManager.getSettings(file != null ? file.getProject() : null);
}
 
Example #27
Source File: IndentOptionsDetectorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public IndentOptions getIndentOptions() {
  IndentOptions indentOptions = (IndentOptions)CodeStyleSettingsManager.getSettings(myProject).getIndentOptions(myFile.getFileType()).clone();

  List<LineIndentInfo> linesInfo = calcLineIndentInfo();
  if (linesInfo != null) {
    IndentUsageStatistics stats = new IndentUsageStatisticsImpl(linesInfo);
    adjustIndentOptions(indentOptions, stats);
  }

  return indentOptions;
}
 
Example #28
Source File: IndentOptionsDetectorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private List<LineIndentInfo> calcLineIndentInfo() {
  if (myDocument == null) 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).build();
}
 
Example #29
Source File: MemberChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void customizeOptionsPanel() {
  if (myInsertOverrideAnnotationCheckbox != null && myIsInsertOverrideVisible) {
    CodeStyleSettings styleSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings();
    myInsertOverrideAnnotationCheckbox.setSelected(styleSettings.INSERT_OVERRIDE_ANNOTATION);
  }
  if (myCopyJavadocCheckbox != null) {
    myCopyJavadocCheckbox.setSelected(PropertiesComponent.getInstance().isTrueValue(PROP_COPYJAVADOC));
  }
}
 
Example #30
Source File: CppFormattingModelBuilder.java    From CppTools with Apache License 2.0 5 votes vote down vote up
@Nullable
public Spacing getSpacing(Block block, Block block1) {
  final IElementType type = ((CppBlock) block).myNode.getElementType();
  final IElementType type2 = ((CppBlock) block1).myNode.getElementType();
  if (type == CppTokenTypes.LBRACE || type2 == CppTokenTypes.RBRACE) {
    CodeStyleSettings mySettings = CodeStyleSettingsManager.getSettings((myNode.getPsi().getProject()));
    return Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
  }
  return null;
}