Java 类com.intellij.psi.codeStyle.CodeStyleSettingsManager 实例源码

项目:intellij-csv-validator    文件:CsvFormatterTest.java   
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) {
    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;
}
项目:dotplugin    文件:DotFormatterTest.java   
public void testFormatter() {
    myFixture.configureByFiles("FormatterTestData.dot");

    // everything is turned on test
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AFTER_SEMICOLON = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_EQUALITY_OPERATORS = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_CLASS_LBRACE = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_METHOD_LBRACE = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_BRACKETS= true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_CLASS_LBRACE = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_METHOD_LBRACE = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_BRACKETS= true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AFTER_SEMICOLON = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_SEMICOLON = true;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AFTER_COLON = true;
    new WriteCommandAction.Simple(getProject()) {
        @Override
        protected void run() throws Throwable {
            CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
                    ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
        }
    }.execute();
    myFixture.checkResultByFile("FormatterTestDataFormatted.dot");
}
项目:intellij-ce-playground    文件:CheckoutProjectOperation.java   
public CheckoutProjectOperation(String[] moduleNames,
                               CvsEnvironment environment,
                               boolean makeNewFilesReadOnly,
                               File root,
                               String alternateCheckoutDirectory,
                               boolean pruneEmptyDirectories,
                               KeywordSubstitution keywordSubstitution) {
  super(new CheckoutAdminReader(),
    new CheckoutAdminWriter(CodeStyleSettingsManager.getInstance().getCurrentSettings().getLineSeparator(),
      CvsApplicationLevelConfiguration.getCharset()));
  myModuleNames = moduleNames;
  myEnvironment = environment;
  myMakeNewFilesReadOnly = makeNewFilesReadOnly;
  myRoot = root;
  myAlternateCheckoutDirectory = alternateCheckoutDirectory;
  myPruneEmptyDirectories = pruneEmptyDirectories;
  myKeywordSubstitution = keywordSubstitution;
}
项目:intellij-ce-playground    文件:AdapterToListenerIntention.java   
private static void implementMethodInClass(@NotNull PsiMethod method,
                                           @NotNull PsiClass aClass) {
  final PsiMethod newMethod = (PsiMethod)aClass.add(method);
  final PsiDocComment comment = newMethod.getDocComment();
  if (comment != null) {
    comment.delete();
  }
  final PsiModifierList modifierList = newMethod.getModifierList();
  modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
  final Project project = aClass.getProject();
  final CodeStyleSettings codeStyleSettings =
    CodeStyleSettingsManager.getSettings(project);
  if (codeStyleSettings.INSERT_OVERRIDE_ANNOTATION &&
      PsiUtil.isLanguageLevel6OrHigher(aClass)) {
    modifierList.addAnnotation("java.lang.Override");
  }
  final PsiElementFactory factory =
    JavaPsiFacade.getElementFactory(project);
  final PsiCodeBlock codeBlock = factory.createCodeBlock();
  newMethod.add(codeBlock);
}
项目:intellij-ce-playground    文件:ReferenceExpressionCompletionContributor.java   
private static void addToArrayConversion(final PsiElement element, final String prefix, @NonNls final String expressionString, @NonNls String presentableString, final Consumer<LookupElement> result, PsiElement qualifier) {
  final boolean callSpace = CodeStyleSettingsManager.getSettings(element.getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES;
  final PsiExpression conversion;
  try {
    conversion = createExpression(
      getQualifierText(qualifier) + prefix + ".toArray(" + getSpace(callSpace) + expressionString + getSpace(callSpace) + ")", element);
  }
  catch (IncorrectOperationException e) {
    return;
  }

  String[] lookupStrings = {prefix + ".toArray(" + getSpace(callSpace) + expressionString + getSpace(callSpace) + ")", presentableString};
  result.consume(new ExpressionLookupItem(conversion, PlatformIcons.METHOD_ICON, prefix + ".toArray(" + presentableString + ")", lookupStrings) {
      @Override
      public void handleInsert(InsertionContext context) {
        FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.SECOND_SMART_COMPLETION_TOAR);

        context.commitDocument();
        JavaCodeStyleManager.getInstance(context.getProject()).shortenClassReferences(context.getFile(), context.getStartOffset(), context.getTailOffset());
      }
    });
}
项目:intellij-ce-playground    文件:QuickChangeCodeStyleSchemeAction.java   
@Override
protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull 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(@NotNull 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);
  }
}
项目:intellij-ce-playground    文件:ForStatementFixer.java   
/**
 * {@link JavaSmartEnterProcessor#registerUnresolvedError(int) registers target offset} taking care of the situation when
 * current code style implies white space after 'for' part's semicolon.
 * 
 * @param editor            target editor
 * @param processor         target smart enter processor
 * @param lastValidForPart  last valid element of the target 'for' loop
 * @param forStatement      PSI element for the target 'for' loop
 */
private static void registerErrorOffset(@NotNull Editor editor, @NotNull JavaSmartEnterProcessor processor,
                                        @NotNull PsiElement lastValidForPart, @NotNull PsiForStatement forStatement)
{
  final Project project = editor.getProject();
  int offset = lastValidForPart.getTextRange().getEndOffset();
  if (project != null && CodeStyleSettingsManager.getSettings(project).SPACE_AFTER_COMMA) {
    if (editor.getDocument().getCharsSequence().charAt(lastValidForPart.getTextRange().getEndOffset() - 1) != ';') {
      offset++;
    }
    for (PsiElement element = lastValidForPart.getNextSibling();
         element != null && element != forStatement.getRParenth() && element.getParent() == forStatement;
         element = element.getNextSibling()) {
      final ASTNode node = element.getNode();
      if (node != null && JavaJspElementType.WHITE_SPACE_BIT_SET.contains(node.getElementType()) && element.getTextLength() > 0) {
        offset++;
        break;
      }
    }
  }

  processor.registerUnresolvedError(offset);
}
项目:intellij-ce-playground    文件:SettingsImpl.java   
private void reinitDocumentIndentOptions() {
  if (myEditor == null) 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;

  CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
  CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptionsByFile(file);

  if (CodeStyleSettings.isRecalculateForCommittedDocument(options)) {
    PsiDocumentManager.getInstance(project).performForCommittedDocument(document, new Runnable() {
      @Override
      public void run() {
        CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
      }
    });
  }
  else {
    CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
  }
}
项目:intellij-ce-playground    文件:CodeStyleSettingsUtilImpl.java   
/**
 * Shows code style settings suitable for the project passed. I.e. it shows project code style page if one
 * is configured to use own code style scheme or global one in other case.
 * @param project
 * @return Returns true if settings were modified during editing session.
 */
@Override
public boolean showCodeStyleSettings(Project project, final Class pageToSelect) {
  CodeStyleSettingsManager settingsManager = CodeStyleSettingsManager.getInstance(project);
  CodeStyleSettings savedSettings = settingsManager.getCurrentSettings().clone();
  final CodeStyleSchemesConfigurable configurable = new CodeStyleSchemesConfigurable(project);
  ShowSettingsUtil.getInstance().editConfigurable(project, configurable, new Runnable() {
    @Override
    public void run() {
      if (pageToSelect != null) {
        configurable.selectPage(pageToSelect);
      }
    }
  });

  return !savedSettings.equals(settingsManager.getCurrentSettings());
}
项目:intellij-ce-playground    文件:ReturnValueBeanBuilder.java   
private void outputConstructor(StringBuilder out) {
  final String typeText = myValueType.getCanonicalText(true);
  final String name = "value";
  final String parameterName = JavaCodeStyleManager.getInstance(myProject).propertyNameToVariableName(name, VariableKind.PARAMETER);
  final String fieldName = getFieldName(name);
  out.append("\tpublic ").append(myClassName).append('(');
  out.append(CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS ? "final " : "");
  out.append(typeText).append(' ').append(parameterName);
  out.append(") {\n");
  if (fieldName.equals(parameterName)) {
    out.append("\t\tthis.").append(fieldName).append(" = ").append(parameterName).append(";\n");
  }
  else {
    out.append("\t\t").append(fieldName).append(" = ").append(parameterName).append(";\n");
  }
  out.append("\t}");
}
项目:intellij-ce-playground    文件:FormatterTestCase.java   
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;
}
项目:intellij-ce-playground    文件:JavaAutoDetectIndentTest.java   
private static void doTestLineToIndentMapping(@NotNull String text, int... spacesForLine) {
  configureFromFileText("x.java", text);
  Document document = PsiDocumentManager.getInstance(getProject()).getDocument(myFile);
  FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);

  Assert.assertNotNull(document);
  Assert.assertNotNull(builder);

  FormattingModel model = builder.createModel(myFile, CodeStyleSettingsManager.getSettings(getProject()));
  Block block = model.getRootBlock();
  List<LineIndentInfo> list = new FormatterBasedLineIndentInfoBuilder(document, block).build();

  Assert.assertEquals(list.size(), spacesForLine.length);
  for (int i = 0; i < spacesForLine.length; i++) {
    int indentSize = list.get(i).getIndentSize();
    Assert.assertEquals("Mismatch on line " + i, spacesForLine[i], indentSize);
  }
}
项目:intellij-ce-playground    文件:IndentSelectionAction.java   
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);
}
项目:intellij-spring-assistant    文件:Util.java   
@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);
}
项目:intellij-csv-validator    文件:CsvCodeStyleSettings.java   
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;
}
项目:intellij-ce-playground    文件:Xslt2RefactoringTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
  XmlCodeStyleSettings xmlSettings = settings.getCustomSettings(XmlCodeStyleSettings.class);
  xmlSettings.XML_SPACE_INSIDE_EMPTY_TAG = true;
  settings.getIndentOptions(StdFileTypes.XML).INDENT_SIZE = 2;
}
项目:intellij-ce-playground    文件:ProblematicWhitespaceInspectionTest.java   
public void testSuppression3() {
  final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  settings.getIndentOptions(JavaFileType.INSTANCE).USE_TAB_CHARACTER = false;
  doTest("@SuppressWarnings(\"ProblematicWhitespace\") class X {\n" +
         "\tString s;\n" +
         "}\n");
}
项目:intellij-ce-playground    文件:UnnecessaryFullyQualifiedNameInspectionTest.java   
private void doTestWithFqnInJavadocSetting(String dirPath, int classNamesInJavadoc) {
  final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);

  int oldClassNamesInJavadoc = javaSettings.CLASS_NAMES_IN_JAVADOC;
  try {
    javaSettings.CLASS_NAMES_IN_JAVADOC = classNamesInJavadoc;
    doTest(dirPath, new UnnecessaryFullyQualifiedNameInspection());
  }
  finally {
    javaSettings.CLASS_NAMES_IN_JAVADOC = oldClassNamesInJavadoc;
  }
}
项目:intellij-ce-playground    文件:CustomFoldingSurroundDescriptor.java   
private static void adjustLineIndent(@NotNull 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;
}
项目:intellij-ce-playground    文件:AbstractNewLineBlocksIteratorTest.java   
@NotNull
protected static Iterator<Block> newLineBlockIterator() {
  FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);
  Assert.assertNotNull(builder);

  CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
  FormattingModel model = builder.createModel(myFile, settings);

  Block root = model.getRootBlock();
  Document document = PsiDocumentManager.getInstance(getProject()).getDocument(myFile);
  Assert.assertNotNull(document);

  return new NewLineBlocksIterator(root, document);
}
项目:intellij-ce-playground    文件:SmartCompletionDecorator.java   
private static void replaceMethodCallIfNeeded(InsertionContext context) {
  PsiFile file = context.getFile();
  PsiElement element = file.findElementAt(context.getTailOffset());
  if (element instanceof PsiWhiteSpace &&
      (!element.textContains('\n') ||
       CodeStyleSettingsManager.getSettings(file.getProject()).getCommonSettings(JavaLanguage.INSTANCE).METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
      )) {
    element = file.findElementAt(element.getTextRange().getEndOffset());
  }
  if (element != null && PsiUtilCore.getElementType(element) == JavaTokenType.LPARENTH && element.getParent() instanceof PsiExpressionList) {
    context.getDocument().deleteString(context.getTailOffset(), element.getParent().getTextRange().getEndOffset());
  }
}
项目:intellij-ce-playground    文件:ExtractMethodTest.java   
private void doTestReturnTypeChanged(PsiType type) throws PrepareFailedException {
  final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  settings.ELSE_ON_NEW_LINE = true;
  settings.CATCH_ON_NEW_LINE = myCatchOnNewLine;
  configureByFile(BASE_PATH + getTestName(false) + ".java");
  boolean success = performExtractMethod(true, true, getEditor(), getFile(), getProject(), false, type, false, null);
  assertTrue(success);
  checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
项目:intellij-ce-playground    文件:FormattingDocumentModelImpl.java   
public FormattingDocumentModelImpl(@NotNull 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);
}
项目:intellij-ce-playground    文件:PyDocumentationBuilder.java   
private static void addFormattedDocString(@NotNull PsiElement element,
                                          @NotNull String docstring,
                                          @NotNull ChainIterable<String> formattedOutput,
                                          @NotNull ChainIterable<String> unformattedOutput) {
  final Project project = element.getProject();

  final List<String> formatted = PyStructuredDocstringFormatter.formatDocstring(element, docstring);
  if (formatted != null) {
    unformattedOutput.add(formatted);
    return;
  }

  boolean isFirstLine;
  final List<String> result = new ArrayList<String>();
  final String[] lines = removeCommonIndentation(docstring);

  // reconstruct back, dropping first empty fragment as needed
  isFirstLine = true;
  final int tabSize = CodeStyleSettingsManager.getSettings(project).getTabSize(PythonFileType.INSTANCE);
  for (String line : lines) {
    if (isFirstLine && ourSpacesPattern.matcher(line).matches()) continue; // ignore all initial whitespace
    if (isFirstLine) {
      isFirstLine = false;
    }
    else {
      result.add(BR);
    }
    int leadingTabs = 0;
    while (leadingTabs < line.length() && line.charAt(leadingTabs) == '\t') {
      leadingTabs++;
    }
    if (leadingTabs > 0) {
      line = StringUtil.repeatSymbol(' ', tabSize * leadingTabs) + line.substring(leadingTabs);
    }
    result.add(combUp(line));
  }
  formattedOutput.add(result);
}
项目:intellij-ce-playground    文件:AndroidXmlFormatterTest.java   
@Override
public void tearDown() throws Exception {
  try {
    CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
  }
  finally {
    super.tearDown();
  }
}
项目:intellij-ce-playground    文件:JoinLinesTest.java   
public void testSCR3493b() 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;
  }
}
项目:intellij-ce-playground    文件:DetectIndentAndTypeTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(new CodeStyleSettings());
  mySettings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
  mySettings.AUTODETECT_INDENTS = true;
  DetectableIndentOptionsProvider optionsProvider = DetectableIndentOptionsProvider.getInstance();
  if (optionsProvider != null) {
    optionsProvider.setEnabledInTest(true);
  }
}
项目:intellij-ce-playground    文件:SemicolonFixer.java   
private static boolean fixForUpdate(@NotNull Editor editor, @Nullable PsiElement psiElement, @NotNull JavaSmartEnterProcessor processor) {
  if (!(psiElement instanceof PsiForStatement)) {
    return false;
  }

  PsiForStatement forStatement = (PsiForStatement)psiElement;
  final PsiExpression condition = forStatement.getCondition();
  if (forStatement.getUpdate() != null || condition == null) {
    return false;
  }

  final TextRange range = condition.getTextRange();
  final Document document = editor.getDocument();
  final CharSequence text = document.getCharsSequence();
  for (int i = range.getEndOffset() - 1, max = forStatement.getTextRange().getEndOffset(); i < max; i++) {
    if (text.charAt(i) == ';') {
      return false;
    }
  }

  String toInsert = ";";
  final Project project = editor.getProject();
  if (project != null && CodeStyleSettingsManager.getSettings(project).SPACE_AFTER_SEMICOLON) {
    toInsert += " ";
  }
  document.insertString(range.getEndOffset(), toInsert);
  return true;
}
项目:intellij-ce-playground    文件:PyWrapTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
  final CommonCodeStyleSettings pythonSettings = settings.getCommonSettings(PythonLanguage.getInstance());
  myOldWrap = settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN;
  myOldMargin = pythonSettings.RIGHT_MARGIN;
  settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = true;
  pythonSettings.RIGHT_MARGIN = 80;
}
项目:intellij-ce-playground    文件:ProblematicWhitespaceInspectionTest.java   
public void testSmartTabsInFile() {
  final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  final CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptions(JavaFileType.INSTANCE);
  options.USE_TAB_CHARACTER = true;
  options.SMART_TABS = true;
  doTest("/*File 'X.java' uses spaces for indentation*/class X {\n" +
         "  \tString s;\n" +
         "}\n/**/");
}
项目:intellij-ce-playground    文件:ExtractMethodTest.java   
private void doTestPassFieldsAsParams() throws PrepareFailedException {
  final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  settings.ELSE_ON_NEW_LINE = true;
  settings.CATCH_ON_NEW_LINE = myCatchOnNewLine;
  configureByFile(BASE_PATH + getTestName(false) + ".java");
  boolean success = performExtractMethod(true, true, getEditor(), getFile(), getProject(), false, null, true, null);
  assertTrue(success);
  checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
项目:intellij-ce-playground    文件:PlatformTestCase.java   
@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);
  }
  IdeaLogger.ourErrorsOccurred = null;

  LOG.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();
}
项目:intellij-ce-playground    文件:JavaFormatterInEditorTest.java   
public void testKeepIndentsOnBlankLinesCaretPosition() throws IOException {
  CommonCodeStyleSettings.IndentOptions indentOptions =
    CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE).getIndentOptions();
  assertNotNull(indentOptions);
  indentOptions.KEEP_INDENTS_ON_EMPTY_LINES = true;
  final String initial =
    "public class Main {\n" +
    "    public void foo(boolean a, int x, int y, int z) {\n" +
    "        do {\n" +
    "            if (x > 0) {\n" +
    "                <caret>\n" +
    "            }\n" +
    "        }\n" +
    "        while (y > 0);\n" +
    "    }\n" +
    "}";

  doTest(
    initial,

    "public class Main {\n" +
    "    public void foo(boolean a, int x, int y, int z) {\n" +
    "        do {\n" +
    "            if (x > 0) {\n" +
    "                <caret>\n" +
    "            }\n" +
    "        }\n" +
    "        while (y > 0);\n" +
    "    }\n" +
    "}"
  );
}
项目:intellij-ce-playground    文件:XsltRefactoringTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
  XmlCodeStyleSettings xmlSettings = settings.getCustomSettings(XmlCodeStyleSettings.class);
  xmlSettings.XML_SPACE_INSIDE_EMPTY_TAG = true;
  settings.getIndentOptions(StdFileTypes.XML).INDENT_SIZE = 2;
}
项目:intellij-ce-playground    文件:CodeStyleSchemesModel.java   
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();

  ((CodeStyleSchemesImpl)CodeStyleSchemes.getInstance()).getSchemeManager().setSchemes(mySchemes, myGlobalSelected, null);

  // 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();
}
项目:intellij-ce-playground    文件:bigFile.java   
private void reinitDocumentIndentOptions() {
  if (myProject != null && !myProject.isDisposed()) {
    PsiDocumentManager.getInstance(myProject).performForCommittedDocument(myDocument, new Runnable() {
      @Override
      public void run() {
        CodeStyleSettingsManager.updateDocumentIndentOptions(myProject, myDocument);
      }
    });
  }
}
项目:intellij-ce-playground    文件:CustomRegexpFilter.java   
protected HyperlinkInfo createOpenFileHyperlink(String fileName, final int line, int column) {
  if ((fileName == null || fileName.length() == 0)) {
      if (myBase != null) {
          fileName = myBase.getPresentableUrl();
      } else {
          return null;
      }
  }
  fileName = fileName.replace(File.separatorChar, '/');

  VirtualFile file;
  // try to interpret the filename as URL
  if (URLUtil.containsScheme(fileName)) {
    try {
      file = VfsUtil.findFileByURL(new URL(fileName));
    } catch (MalformedURLException e) {
      file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(fileName));
    }
  } else {
    file = VfsUtil.findRelativeFile(fileName, myBase);
  }
  if (file == null) {
    //noinspection ConstantConditions
    return null;
  }

  final FileType fileType = file.getFileType();
  if (fileType != null && column > 0) {
    final Document document = FileDocumentManager.getInstance().getDocument(file);

    final int start = document.getLineStartOffset(line);
    final int max = document.getLineEndOffset(line);
    final int tabSize = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings().getTabSize(fileType);
    column = EditorUtil.calcColumnNumber(null, document.getCharsSequence(), start, Math.min(start + column, max), tabSize);
  }
  return new OpenFileHyperlinkInfo(myProject, file, line, column);
}
项目:intellij-ce-playground    文件:PyWrapTest.java   
@Override
protected void tearDown() throws Exception {
  final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
  final CommonCodeStyleSettings pythonSettings = settings.getCommonSettings(PythonLanguage.getInstance());
  settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = myOldWrap;
  pythonSettings.RIGHT_MARGIN = myOldMargin;
  super.tearDown();
}
项目:intellij-ce-playground    文件:CvsFileUtil.java   
private static String getLineSeparatorFor(File file) {
  VirtualFile virtualFile = CvsVfsUtil.findFileByIoFile(file);
  if (virtualFile != null) {
    return FileDocumentManager.getInstance().getLineSeparator(virtualFile, null);
  }
  else {
    return CodeStyleSettingsManager.getInstance().getCurrentSettings().getLineSeparator();
  }
}
项目:intellij-ce-playground    文件:ClsMirrorBuildingTest.java   
public void testTextPsiMismatch() {
  CommonCodeStyleSettings.IndentOptions options =
    CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getIndentOptions(JavaFileType.INSTANCE);
  int indent = options.INDENT_SIZE;
  options.INDENT_SIZE *= 2;
  try {
    doTest("Bounds");
  }
  finally {
    options.INDENT_SIZE = indent;
  }
}