コード例 #1
0
  @WrapInCommand
  public void testReimportConflictingClasses() throws Exception {
    configureByFile(BASE_PATH + "/x/Usage.java", BASE_PATH);
    assertEmpty(highlightErrors());

    CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
    settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 2;
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
    try {
      new WriteCommandAction.Simple(getProject()) {
        @Override
        protected void run() throws Throwable {
          JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile());
        }
      }.execute().throwException();
    } finally {
      CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
    }

    @NonNls String fullPath = getTestDataPath() + BASE_PATH + "/x/Usage_afterOptimize.txt";
    final VirtualFile vFile =
        LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/'));
    String text = LoadTextUtil.loadText(vFile).toString();
    assertEquals(text, getFile().getText());
  }
コード例 #2
0
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
   settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 100;
   CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
   DaemonCodeAnalyzer.getInstance(getProject()).setUpdateByTimerEnabled(false);
 }
コード例 #3
0
  @Override
  public void writeExternal(Element element) throws WriteExternalException {
    final CodeStyleSettings parentSettings = new CodeStyleSettings();
    DefaultJDOMExternalizer.writeExternal(
        this, element, new DifferenceFilter<CodeStyleSettings>(this, parentSettings));
    List<CustomCodeStyleSettings> customSettings =
        new ArrayList<CustomCodeStyleSettings>(getCustomSettingsValues());

    Collections.sort(
        customSettings,
        new Comparator<CustomCodeStyleSettings>() {
          @Override
          public int compare(final CustomCodeStyleSettings o1, final CustomCodeStyleSettings o2) {
            return o1.getTagName().compareTo(o2.getTagName());
          }
        });

    for (final CustomCodeStyleSettings settings : customSettings) {
      final CustomCodeStyleSettings parentCustomSettings =
          parentSettings.getCustomSettings(settings.getClass());
      if (parentCustomSettings == null) {
        throw new WriteExternalException("Custom settings are null for " + settings.getClass());
      }
      settings.writeExternal(element, parentCustomSettings);
    }

    final FileType[] fileTypes =
        myAdditionalIndentOptions
            .keySet()
            .toArray(new FileType[myAdditionalIndentOptions.keySet().size()]);
    Arrays.sort(
        fileTypes,
        new Comparator<FileType>() {
          @Override
          public int compare(final FileType o1, final FileType o2) {
            return o1.getDefaultExtension().compareTo(o2.getDefaultExtension());
          }
        });

    for (FileType fileType : fileTypes) {
      final IndentOptions indentOptions = myAdditionalIndentOptions.get(fileType);
      Element additionalIndentOptions = new Element(ADDITIONAL_INDENT_OPTIONS);
      indentOptions.serialize(additionalIndentOptions, getDefaultIndentOptions(fileType));
      additionalIndentOptions.setAttribute(FILETYPE, fileType.getDefaultExtension());
      if (!additionalIndentOptions.getChildren().isEmpty()) {
        element.addContent(additionalIndentOptions);
      }
    }

    myCommonSettingsManager.writeExternal(element);
  }
コード例 #4
0
  private void copyCustomSettingsFrom(@NotNull CodeStyleSettings from) {
    synchronized (myCustomSettings) {
      myCustomSettings.clear();

      for (final CustomCodeStyleSettings settings : from.getCustomSettingsValues()) {
        addCustomSettings((CustomCodeStyleSettings) settings.clone());
      }

      FIELD_TYPE_TO_NAME.copyFrom(from.FIELD_TYPE_TO_NAME);
      STATIC_FIELD_TYPE_TO_NAME.copyFrom(from.STATIC_FIELD_TYPE_TO_NAME);
      PARAMETER_TYPE_TO_NAME.copyFrom(from.PARAMETER_TYPE_TO_NAME);
      LOCAL_VARIABLE_TYPE_TO_NAME.copyFrom(from.LOCAL_VARIABLE_TYPE_TO_NAME);

      PACKAGES_TO_USE_IMPORT_ON_DEMAND.copyFrom(from.PACKAGES_TO_USE_IMPORT_ON_DEMAND);
      IMPORT_LAYOUT_TABLE.copyFrom(from.IMPORT_LAYOUT_TABLE);

      OTHER_INDENT_OPTIONS.copyFrom(from.OTHER_INDENT_OPTIONS);

      myAdditionalIndentOptions.clear();
      for (Map.Entry<FileType, IndentOptions> optionEntry :
          from.myAdditionalIndentOptions.entrySet()) {
        IndentOptions options = optionEntry.getValue();
        myAdditionalIndentOptions.put(optionEntry.getKey(), (IndentOptions) options.clone());
      }

      myCommonSettingsManager = from.myCommonSettingsManager.clone(this);
    }
  }
コード例 #5
0
 @Override
 public CodeStyleSettings clone() {
   CodeStyleSettings clone = new CodeStyleSettings();
   clone.copyFrom(this);
   return clone;
 }
コード例 #6
0
 public static CommonCodeStyleSettings getSettings() {
   CodeStyleSettings rootSettings = CodeStyleSettingsManager.getSettings(getProject());
   return rootSettings.getCommonSettings(JavaLanguage.INSTANCE);
 }