This commit is contained in:
Vladimir Krivosheev
2016-02-16 17:06:05 +01:00
parent 31349f7192
commit 9d3f11d7e8
10 changed files with 68 additions and 114 deletions
@@ -25,6 +25,7 @@ public abstract class SchemesManagerFactory {
/**
* directoryName — like "keymaps".
*/
@SuppressWarnings("unused")
@NotNull
public <T extends Scheme, E extends ExternalizableScheme> SchemesManager<T, E> createSchemesManager(@NotNull String directoryName,
@NotNull SchemeProcessor<E> processor,
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import java.util.List;
public abstract class CodeStyleSchemes {
public static CodeStyleSchemes getInstance(){
return ServiceManager.getService(CodeStyleSchemes.class);
@@ -65,8 +63,5 @@ public abstract class CodeStyleSchemes {
public abstract CodeStyleScheme getDefaultScheme();
public abstract void addScheme(@NotNull CodeStyleScheme currentScheme);
@Deprecated
public abstract void setSchemes(@NotNull List<CodeStyleScheme> schemes);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,10 +46,9 @@ import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class CodeStyleSettings extends CommonCodeStyleSettings implements Cloneable, JDOMExternalizable {
public static final int MAX_RIGHT_MARGIN = 1000;
private static final Logger LOG = Logger.getInstance("#" + CodeStyleSettings.class.getName());
private static final Logger LOG = Logger.getInstance(CodeStyleSettings.class);
private final ClassMap<CustomCodeStyleSettings> myCustomSettings = new ClassMap<CustomCodeStyleSettings>();
@@ -123,6 +122,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
public <T extends CustomCodeStyleSettings> T getCustomSettings(@NotNull Class<T> aClass) {
synchronized (myCustomSettings) {
//noinspection unchecked
return (T)myCustomSettings.get(aClass);
}
}
@@ -490,50 +490,42 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
}
}
for (final CustomCodeStyleSettings settings : getCustomSettingsValues()) {
for (CustomCodeStyleSettings settings : getCustomSettingsValues()) {
settings.readExternal(element);
settings.importLegacySettings();
}
final List list = element.getChildren(ADDITIONAL_INDENT_OPTIONS);
List<Element> 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);
for (Element additionalIndentElement : list) {
String fileTypeId = additionalIndentElement.getAttributeValue(FILETYPE);
if (!StringUtil.isEmpty(fileTypeId)) {
FileType target = FileTypeManager.getInstance().getFileTypeByExtension(fileTypeId);
if (FileTypes.UNKNOWN == target || FileTypes.PLAIN_TEXT == target || target.getDefaultExtension().isEmpty()) {
target = new TempFileType(fileTypeId);
}
IndentOptions options = getDefaultIndentOptions(target);
options.readExternal(additionalIndentElement);
registerAdditionalIndentOptions(target, options);
}
}
}
myCommonSettingsManager.readExternal(element);
if (USE_SAME_INDENTS) IGNORE_SAME_INDENTS_FOR_LANGUAGES = true;
if (USE_SAME_INDENTS) {
IGNORE_SAME_INDENTS_FOR_LANGUAGES = true;
}
}
@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());
}
});
Collections.sort(customSettings, (o1, o2) -> o1.getTagName().compareTo(o2.getTagName()));
for (final CustomCodeStyleSettings settings : customSettings) {
final CustomCodeStyleSettings parentCustomSettings = parentSettings.getCustomSettings(settings.getClass());
@@ -544,12 +536,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
}
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());
}
});
Arrays.sort(fileTypes, (o1, o2) -> o1.getDefaultExtension().compareTo(o2.getDefaultExtension()));
for (FileType fileType : fileTypes) {
final IndentOptions indentOptions = myAdditionalIndentOptions.get(fileType);
@@ -564,7 +551,6 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
myCommonSettingsManager.writeExternal(element);
}
private static IndentOptions getDefaultIndentOptions(FileType fileType) {
final FileTypeIndentOptionsProvider[] providers = Extensions.getExtensions(FileTypeIndentOptionsProvider.EP_NAME);
for (final FileTypeIndentOptionsProvider provider : providers) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -79,19 +79,11 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
return CodeStyleSchemes.getInstance().findPreferredScheme(PREFERRED_PROJECT_CODE_STYLE).getCodeStyleSettings();
}
private void readExternal(Element element) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, element);
}
private void writeExternal(Element element) throws WriteExternalException {
DefaultJDOMExternalizer.writeExternal(this, element, new DifferenceFilter<CodeStyleSettingsManager>(this, new CodeStyleSettingsManager()));
}
@Override
public Element getState() {
Element result = new Element("state");
try {
writeExternal(result);
DefaultJDOMExternalizer.writeExternal(this, result, new DifferenceFilter<CodeStyleSettingsManager>(this, new CodeStyleSettingsManager()));
}
catch (WriteExternalException e) {
LOG.error(e);
@@ -102,7 +94,7 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
@Override
public void loadState(Element state) {
try {
readExternal(state);
DefaultJDOMExternalizer.readExternal(this, state);
myIsLoaded = true;
}
catch (InvalidDataException e) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -119,7 +119,7 @@ public class CommonCodeStyleSettings {
CommonCodeStyleSettings commonSettings = new CommonCodeStyleSettings(myLanguage, getFileType());
copyPublicFields(this, commonSettings);
commonSettings.setRootSettings(rootSettings);
commonSettings.myForceArrangeMenuAvailable = this.myForceArrangeMenuAvailable;
commonSettings.myForceArrangeMenuAvailable = myForceArrangeMenuAvailable;
if (myIndentOptions != null) {
IndentOptions targetIndentOptions = commonSettings.initIndentOptions();
targetIndentOptions.copyFrom(myIndentOptions);
@@ -394,7 +394,7 @@ public class CommonCodeStyleSettings {
public boolean INDENT_CASE_FROM_SWITCH = true;
/**
* Controls "break" position realtive to "case".
* Controls "break" position relative to "case".
* <pre>
* case 0:
* <--->break;
@@ -905,7 +905,7 @@ public class CommonCodeStyleSettings {
public int intValue;
WrapOnTyping(int i) {
this.intValue = i;
intValue = i;
}
}
@@ -916,7 +916,7 @@ public class CommonCodeStyleSettings {
public int WRAP_ON_TYPING = WrapOnTyping.DEFAULT.intValue;
//-------------------------Indent options-------------------------------------------------
public static class IndentOptions implements JDOMExternalizable, Cloneable {
public static class IndentOptions implements Cloneable {
public int INDENT_SIZE = 4;
public int CONTINUATION_INDENT_SIZE = 8;
public int TAB_SIZE = 4;
@@ -931,21 +931,16 @@ public class CommonCodeStyleSettings {
private static final Key<CommonCodeStyleSettings.IndentOptions> INDENT_OPTIONS_KEY = Key.create("INDENT_OPTIONS_KEY");
private boolean myInaccurate;
@Override
public void readExternal(Element element) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, element);
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
DefaultJDOMExternalizer.writeExternal(this, element, new DefaultJDOMExternalizer.JDOMFilter() {
@Override
public boolean isAccept(@NotNull Field field) {
if ("KEEP_INDENTS_ON_EMPTY_LINES".equals(field.getName())) {
return KEEP_INDENTS_ON_EMPTY_LINES;
}
return true;
DefaultJDOMExternalizer.writeExternal(this, element, field -> {
if ("KEEP_INDENTS_ON_EMPTY_LINES".equals(field.getName())) {
return KEEP_INDENTS_ON_EMPTY_LINES;
}
return true;
});
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,24 +18,28 @@ package com.intellij.psi.codeStyle;
import com.intellij.lang.Language;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.HashMap;
import gnu.trove.THashMap;
import gnu.trove.THashSet;
import org.jdom.Content;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
/**
* Manages common code style settings for every language using them.
*
* @author Rustam Vishnyakov
*/
public class CommonCodeStyleSettingsManager implements JDOMExternalizable {
public class CommonCodeStyleSettingsManager {
private volatile Map<Language, CommonCodeStyleSettings> myCommonSettingsMap;
private volatile Map<String, Content> myUnknownSettingsMap;
@@ -44,7 +48,6 @@ public class CommonCodeStyleSettingsManager implements JDOMExternalizable {
@NonNls private static final String COMMON_SETTINGS_TAG = "codeStyleSettings";
private static final String LANGUAGE_ATTR = "language";
CommonCodeStyleSettingsManager(@NotNull CodeStyleSettings parentSettings) {
myParentSettings = parentSettings;
}
@@ -155,15 +158,12 @@ public class CommonCodeStyleSettingsManager implements JDOMExternalizable {
}
}
@Override
public void readExternal(@NotNull Element element) throws InvalidDataException {
synchronized (this) {
initCommonSettingsMap();
final List list = element.getChildren(COMMON_SETTINGS_TAG);
for (Object o : list) {
final Element commonSettingsElement = (Element)o;
for (Element commonSettingsElement : element.getChildren(COMMON_SETTINGS_TAG)) {
final String languageId = commonSettingsElement.getAttributeValue(LANGUAGE_ATTR);
if (languageId != null && !languageId.isEmpty()) {
if (!StringUtil.isEmpty(languageId)) {
Language target = Language.findLanguageByID(languageId);
boolean isKnownLanguage = target != null;
if (isKnownLanguage) {
@@ -180,7 +180,7 @@ public class CommonCodeStyleSettingsManager implements JDOMExternalizable {
}
}
if (!isKnownLanguage) {
myUnknownSettingsMap.put(languageId, (Content)commonSettingsElement.clone());
myUnknownSettingsMap.put(languageId, commonSettingsElement.clone());
}
}
}
@@ -188,27 +188,23 @@ public class CommonCodeStyleSettingsManager implements JDOMExternalizable {
}
}
@Override
public void writeExternal(@NotNull Element element) throws WriteExternalException {
synchronized (this) {
if (myCommonSettingsMap == null) return;
if (myCommonSettingsMap == null) {
return;
}
final Map<String, Language> id2lang = new HashMap<String, Language>();
for (final Language language : myCommonSettingsMap.keySet()) {
final Map<String, Language> id2lang = new THashMap<>();
for (Language language : myCommonSettingsMap.keySet()) {
id2lang.put(language.getID(), language);
}
final Set<String> langIdList = new HashSet<String>();
final Set<String> langIdList = new THashSet<>();
langIdList.addAll(myUnknownSettingsMap.keySet());
langIdList.addAll(id2lang.keySet());
final String[] languages = ArrayUtil.toStringArray(langIdList);
Arrays.sort(languages, new Comparator<String>() {
@Override
public int compare(@NotNull final String o1, final String o2) {
return o1.compareTo(o2);
}
});
Arrays.sort(languages, String::compareTo);
for (final String id : languages) {
final Language language = id2lang.get(id);
@@ -220,9 +216,12 @@ public class CommonCodeStyleSettingsManager implements JDOMExternalizable {
if (!commonSettingsElement.getChildren().isEmpty()) {
element.addContent(commonSettingsElement);
}
} else {
}
else {
final Content unknown = myUnknownSettingsMap.get(id);
if (unknown != null) element.addContent(unknown.detach());
if (unknown != null) {
element.addContent(unknown.detach());
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,8 @@
*/
package com.intellij.psi.impl.source.codeStyle;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.SchemeExporter;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.codeStyle.CodeStyleScheme;
import org.jdom.Element;
import org.jdom.output.Format;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ public class CodeStyleSchemeImpl extends ExternalizableSchemeAdapter implements
private final boolean myIsDefault;
private volatile CodeStyleSettings myCodeStyleSettings;
public CodeStyleSchemeImpl(@NotNull String name, String parentSchemeName, Element rootElement) {
CodeStyleSchemeImpl(@NotNull String name, String parentSchemeName, Element rootElement) {
myName = name;
myRootElement = rootElement;
myIsDefault = false;
@@ -47,7 +47,7 @@ public class CodeStyleSchemeImpl extends ExternalizableSchemeAdapter implements
init(parentScheme, null);
}
public void init(@NotNull CodeStyleSchemes schemesManager) {
void init(@NotNull CodeStyleSchemes schemesManager) {
LOG.assertTrue(myCodeStyleSettings == null, "Already initialized");
init(myParentSchemeName == null ? null : schemesManager.findSchemeByName(myParentSchemeName), myRootElement);
myParentSchemeName = null;
@@ -68,7 +68,7 @@ public class CodeStyleSchemeImpl extends ExternalizableSchemeAdapter implements
}
if (root != null) {
try {
readExternal(root);
myCodeStyleSettings.readExternal(root);
}
catch (InvalidDataException e) {
LOG.error(e);
@@ -93,8 +93,4 @@ public class CodeStyleSchemeImpl extends ExternalizableSchemeAdapter implements
public void writeExternal(Element element) throws WriteExternalException{
myCodeStyleSettings.writeExternal(element);
}
public void readExternal(Element element) throws InvalidDataException{
myCodeStyleSettings.readExternal(element);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
public abstract class CodeStyleSchemesImpl extends CodeStyleSchemes {
protected static final String DEFAULT_SCHEME_NAME = "Default";
@@ -129,11 +128,6 @@ public abstract class CodeStyleSchemesImpl extends CodeStyleSchemes {
mySchemesManager.removeScheme(scheme);
}
@Override
public void setSchemes(@NotNull List<CodeStyleScheme> schemes) {
mySchemesManager.setSchemes(schemes);
}
@NotNull
public SchemesManager<CodeStyleScheme, CodeStyleSchemeImpl> getSchemeManager() {
return mySchemesManager;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -263,14 +263,13 @@ public class DefaultJDOMExternalizer {
field.set(data, color);
}
else if (ReflectionUtil.isAssignable(JDOMExternalizable.class, type)) {
final List children = e.getChildren("value");
final List<Element> children = e.getChildren("value");
if (!children.isEmpty()) {
// compatibility with Selena's serialization which writes an empty tag for a bean which has a default value
JDOMExternalizable object = null;
for (final Object o1 : children) {
Element el = (Element)o1;
for (Element element : children) {
object = (JDOMExternalizable)type.newInstance();
object.readExternal(el);
object.readExternal(element);
}
field.set(data, object);