コード例 #1
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);
  }
コード例 #2
0
 private void copyOldIndentOptions(@NonNls final String extension, final IndentOptions options) {
   final FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(extension);
   if (fileType != FileTypes.UNKNOWN
       && fileType != FileTypes.PLAIN_TEXT
       && !myAdditionalIndentOptions.containsKey(fileType)
       && !fileType.getDefaultExtension().isEmpty()) {
     registerAdditionalIndentOptions(fileType, options);
     //
     // Upgrade to version 11
     //
     if (fileType instanceof LanguageFileType) {
       Language lang = ((LanguageFileType) fileType).getLanguage();
       CommonCodeStyleSettings langSettings = myCommonSettingsManager.getCommonSettings(lang);
       if (langSettings != this && langSettings.getIndentOptions() != null) {
         langSettings.importOldIndentOptions(this);
       }
     }
   }
 }
コード例 #3
0
 /**
  * @param langName The language name.
  * @return Language-specific code style settings or shared settings if not found.
  * @see CommonCodeStyleSettingsManager#getCommonSettings
  */
 public CommonCodeStyleSettings getCommonSettings(String langName) {
   return myCommonSettingsManager.getCommonSettings(langName);
 }
コード例 #4
0
 public CommonCodeStyleSettings getCommonSettings(Language lang) {
   return myCommonSettingsManager.getCommonSettings(lang);
 }
コード例 #5
0
  @Override
  public void readExternal(Element element) throws InvalidDataException {
    DefaultJDOMExternalizer.readExternal(this, element);
    if (LAYOUT_STATIC_IMPORTS_SEPARATELY) {
      // add <all other static imports> entry if there is none
      boolean found = false;
      for (PackageEntry entry : IMPORT_LAYOUT_TABLE.getEntries()) {
        if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
          found = true;
          break;
        }
      }
      if (!found) {
        PackageEntry last =
            IMPORT_LAYOUT_TABLE.getEntryCount() == 0
                ? null
                : IMPORT_LAYOUT_TABLE.getEntryAt(IMPORT_LAYOUT_TABLE.getEntryCount() - 1);
        if (last != PackageEntry.BLANK_LINE_ENTRY) {
          IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.BLANK_LINE_ENTRY);
        }
        IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
      }
    }
    boolean oldOptionsImported = importOldIndentOptions(element);
    for (final CustomCodeStyleSettings settings : getCustomSettingsValues()) {
      settings.readExternal(element);
      settings.importLegacySettings();
    }

    final List list = element.getChildren(ADDITIONAL_INDENT_OPTIONS);
    if (list != null) {
      for (Object o : list) {
        if (o instanceof Element) {
          final Element additionalIndentElement = (Element) o;
          final String fileTypeId = additionalIndentElement.getAttributeValue(FILETYPE);

          if (fileTypeId != null && !fileTypeId.isEmpty()) {
            FileType target = FileTypeManager.getInstance().getFileTypeByExtension(fileTypeId);
            if (FileTypes.UNKNOWN == target
                || FileTypes.PLAIN_TEXT == target
                || target.getDefaultExtension().isEmpty()) {
              target = new TempFileType(fileTypeId);
            }

            final IndentOptions options = getDefaultIndentOptions(target);
            options.readExternal(additionalIndentElement);
            registerAdditionalIndentOptions(target, options);
          }
        }
      }
    }

    myCommonSettingsManager.readExternal(element);

    if (oldOptionsImported) {
      copyOldIndentOptions("java", JAVA_INDENT_OPTIONS);
      copyOldIndentOptions("jsp", JSP_INDENT_OPTIONS);
      copyOldIndentOptions("xml", XML_INDENT_OPTIONS);
    }

    if (USE_SAME_INDENTS) IGNORE_SAME_INDENTS_FOR_LANGUAGES = true;
  }