mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
@@ -17,18 +17,18 @@ package com.intellij.openapi.options;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.util.UniqueFileNamesProvider;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public abstract class AbstractSchemesManager<T extends Scheme, E extends ExternalizableScheme> implements SchemesManager<T,E> {
|
||||
public abstract class AbstractSchemesManager<T extends Scheme, E extends ExternalizableScheme> implements SchemesManager<T, E> {
|
||||
private static final Logger LOG = Logger.getInstance(AbstractSchemesManager.class);
|
||||
|
||||
protected final List<T> mySchemes = new ArrayList<T>();
|
||||
@@ -42,7 +42,7 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
|
||||
for (int i = 0; i < mySchemes.size(); i++) {
|
||||
T t = mySchemes.get(i);
|
||||
if (Comparing.equal(scheme.getName(),t.getName()) && newSchemeIsShared == isShared(t)) {
|
||||
if (Comparing.equal(scheme.getName(), t.getName()) && newSchemeIsShared == isShared(t)) {
|
||||
toReplace = i;
|
||||
break;
|
||||
}
|
||||
@@ -55,6 +55,7 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
mySchemes.set(toReplace, scheme);
|
||||
}
|
||||
else {
|
||||
//noinspection unchecked
|
||||
renameScheme((E)scheme, generateUniqueName(scheme));
|
||||
mySchemes.add(scheme);
|
||||
}
|
||||
@@ -65,17 +66,18 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
|
||||
protected void checkCurrentScheme(final Scheme scheme) {
|
||||
if (myCurrentScheme == null && myCurrentSchemeName != null && myCurrentSchemeName.equals(scheme.getName())) {
|
||||
//noinspection unchecked
|
||||
myCurrentScheme = (T)scheme;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String generateUniqueName(final T scheme) {
|
||||
private String generateUniqueName(@NotNull T scheme) {
|
||||
return UniqueNameGenerator.generateUniqueName(UniqueFileNamesProvider.convertName(scheme.getName()), collectExistingNames(mySchemes));
|
||||
}
|
||||
|
||||
private Collection<String> collectExistingNames(final Collection<T> schemes) {
|
||||
HashSet<String> result = new HashSet<String>();
|
||||
Set<String> result = new THashSet<String>();
|
||||
for (T scheme : schemes) {
|
||||
result.add(scheme.getName());
|
||||
}
|
||||
@@ -92,24 +94,20 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
@Override
|
||||
@NotNull
|
||||
public List<T> getAllSchemes() {
|
||||
return Collections.unmodifiableList(new ArrayList<T>(mySchemes));
|
||||
return new ArrayList<T>(mySchemes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T findSchemeByName(final String schemeName) {
|
||||
for (T scheme : mySchemes) {
|
||||
if (Comparing.equal(scheme.getName(),schemeName)) {
|
||||
if (Comparing.equal(scheme.getName(), schemeName)) {
|
||||
return scheme;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void save() throws WriteExternalException;
|
||||
|
||||
@Override
|
||||
public void setCurrentSchemeName(final String schemeName) {
|
||||
myCurrentSchemeName = schemeName;
|
||||
@@ -140,17 +138,15 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
onSchemeDeleted(toDelete);
|
||||
}
|
||||
|
||||
protected abstract void onSchemeDeleted(final Scheme toDelete);
|
||||
protected abstract void onSchemeDeleted(@NotNull Scheme toDelete);
|
||||
|
||||
private Scheme findSchemeToDelete(final String schemeName) {
|
||||
for (T scheme : mySchemes) {
|
||||
if (Comparing.equal(schemeName,scheme.getName())) return scheme;
|
||||
if (Comparing.equal(schemeName, scheme.getName())) return scheme;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<String> getAllSchemeNames() {
|
||||
@@ -165,12 +161,12 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
return names;
|
||||
}
|
||||
|
||||
protected abstract void onSchemeAdded(final T scheme);
|
||||
protected abstract void onSchemeAdded(@NotNull T scheme);
|
||||
|
||||
protected void renameScheme(final E scheme, @NotNull String newName){
|
||||
if (!Comparing.equal(newName,scheme.getName())) {
|
||||
protected void renameScheme(@NotNull E scheme, @NotNull String newName) {
|
||||
if (!Comparing.equal(newName, scheme.getName())) {
|
||||
scheme.setName(newName);
|
||||
LOG.assertTrue(Comparing.equal(newName,scheme.getName()));
|
||||
LOG.assertTrue(Comparing.equal(newName, scheme.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -18,8 +18,8 @@ package com.intellij.psi.impl.source.codeStyle;
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.ExternalizableScheme;
|
||||
import com.intellij.openapi.options.ExternalInfo;
|
||||
import com.intellij.openapi.options.ExternalizableScheme;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.JDOMExternalizable;
|
||||
@@ -31,7 +31,6 @@ import com.intellij.psi.codeStyle.CodeStyleSchemes;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -131,7 +130,7 @@ public class CodeStyleSchemeImpl implements JDOMExternalizable, CodeStyleScheme,
|
||||
myCodeStyleSettings.readExternal(element);
|
||||
}
|
||||
|
||||
public static CodeStyleSchemeImpl readScheme(Document document) throws InvalidDataException, JDOMException, IOException{
|
||||
public static CodeStyleSchemeImpl readScheme(Document document) throws InvalidDataException {
|
||||
Element root = document.getRootElement();
|
||||
if (root == null){
|
||||
throw new InvalidDataException("No root element in code style scheme file");
|
||||
|
||||
+2
-2
@@ -28,8 +28,8 @@ import com.intellij.psi.PsiBundle;
|
||||
import com.intellij.psi.codeStyle.CodeStyleScheme;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSchemes;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jdom.Parent;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class CodeStyleSchemesImpl extends CodeStyleSchemes implements E
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parent writeScheme(@NotNull final CodeStyleSchemeImpl scheme) throws WriteExternalException {
|
||||
public Element writeScheme(@NotNull final CodeStyleSchemeImpl scheme) throws WriteExternalException {
|
||||
return scheme.saveToDocument();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,28 +15,21 @@
|
||||
*/
|
||||
package com.intellij.openapi.actionSystem.ex;
|
||||
|
||||
|
||||
import com.intellij.openapi.options.ExternalInfo;
|
||||
import com.intellij.openapi.options.ExternalizableScheme;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
public class QuickList implements ExternalizableScheme {
|
||||
|
||||
@NonNls public static final String QUICK_LIST_PREFIX = "QuickList.";
|
||||
|
||||
@NonNls public static final String SEPARATOR_ID = QUICK_LIST_PREFIX + "$Separator$";
|
||||
|
||||
|
||||
|
||||
@NonNls private static final String ID_TAG = "id";
|
||||
|
||||
@NonNls private static final String READONLY_TAG = "readonly";
|
||||
@@ -47,31 +40,17 @@ public class QuickList implements ExternalizableScheme {
|
||||
|
||||
@NonNls private static final String DESCRIPTION_TAG = "description";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private String myDisplayName;
|
||||
|
||||
private String myDescription;
|
||||
|
||||
private String[] myActionIds;
|
||||
|
||||
private boolean myReadonly;
|
||||
|
||||
private final ExternalInfo myExternalInfo = new ExternalInfo();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* With read external to be called immediately after in mind
|
||||
|
||||
*/
|
||||
|
||||
QuickList() {}
|
||||
|
||||
|
||||
QuickList() {
|
||||
}
|
||||
|
||||
public QuickList(String displayName, String description, String[] actionIds, boolean isReadonly) {
|
||||
|
||||
@@ -82,168 +61,88 @@ public class QuickList implements ExternalizableScheme {
|
||||
myActionIds = actionIds;
|
||||
|
||||
myReadonly = isReadonly;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getDisplayName() {
|
||||
|
||||
return myDisplayName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
|
||||
return getDisplayName();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isReadonly() {
|
||||
|
||||
return myReadonly;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
|
||||
return myDescription;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String[] getActionIds() {
|
||||
|
||||
return myActionIds;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) return true;
|
||||
|
||||
if (!(o instanceof QuickList)) return false;
|
||||
|
||||
|
||||
|
||||
final QuickList quickList = (QuickList)o;
|
||||
|
||||
|
||||
|
||||
if (!Arrays.equals(myActionIds, quickList.myActionIds)) return false;
|
||||
|
||||
if (!myDescription.equals(quickList.myDescription)) return false;
|
||||
|
||||
if (!myDisplayName.equals(quickList.myDisplayName)) return false;
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
|
||||
return 29 * myDisplayName.hashCode() + myDescription.hashCode();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getActionId() {
|
||||
|
||||
return QUICK_LIST_PREFIX + getDisplayName();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void writeExternal(Element groupElement) {
|
||||
|
||||
groupElement.setAttribute(DISPLAY_NAME_TAG, getDisplayName());
|
||||
|
||||
groupElement.setAttribute(DESCRIPTION_TAG, getDescription());
|
||||
|
||||
groupElement.setAttribute(READONLY_TAG, String.valueOf(isReadonly()));
|
||||
|
||||
|
||||
|
||||
for (String actionId : getActionIds()) {
|
||||
|
||||
Element actionElement = new Element(ACTION_TAG);
|
||||
|
||||
actionElement.setAttribute(ID_TAG, actionId);
|
||||
|
||||
groupElement.addContent(actionElement);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void readExternal(Element element) {
|
||||
|
||||
myDisplayName = element.getAttributeValue(DISPLAY_NAME_TAG);
|
||||
|
||||
myDescription = element.getAttributeValue(DESCRIPTION_TAG);
|
||||
|
||||
myReadonly = Boolean.valueOf(element.getAttributeValue(READONLY_TAG)).booleanValue();
|
||||
|
||||
List<String> ids = new ArrayList<String>();
|
||||
|
||||
List<String> ids = new SmartList<String>();
|
||||
for (Object action : element.getChildren(ACTION_TAG)) {
|
||||
|
||||
Element actionElement = (Element)action;
|
||||
|
||||
ids.add(actionElement.getAttributeValue(ID_TAG));
|
||||
|
||||
}
|
||||
|
||||
myActionIds = ArrayUtil.toStringArray(ids);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setDisplayName(final String name) {
|
||||
|
||||
myDisplayName = name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
|
||||
public ExternalInfo getExternalInfo() {
|
||||
|
||||
return myExternalInfo;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setName(@NotNull final String newName) {
|
||||
|
||||
setDisplayName(newName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-5
@@ -86,7 +86,7 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Name
|
||||
loadSchemesFromBeans();
|
||||
}
|
||||
|
||||
loadAllSchemes();
|
||||
mySchemesManager.loadSchemes();
|
||||
|
||||
loadAdditionalTextAttributes();
|
||||
|
||||
@@ -280,10 +280,6 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Name
|
||||
// Routines responsible for loading & saving colors schemes.
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private void loadAllSchemes() {
|
||||
mySchemesManager.loadSchemes();
|
||||
}
|
||||
|
||||
private static File getColorsDir(boolean create) {
|
||||
@NonNls String directoryPath = PathManager.getConfigPath() + File.separator + "colors";
|
||||
File directory = new File(directoryPath);
|
||||
|
||||
@@ -99,6 +99,8 @@ public class JDOMUtil {
|
||||
return addToHash(0, root);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated
|
||||
public static int getTreeHash(@NotNull Document document) {
|
||||
return getTreeHash(document.getRootElement());
|
||||
}
|
||||
@@ -158,6 +160,8 @@ public class JDOMUtil {
|
||||
return list.toArray(new Element[list.size()]);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
@NotNull
|
||||
public static String concatTextNodesValues(@NotNull final Object[] nodes) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
*/
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UniqueFileNamesProvider {
|
||||
private final ArrayList<String> myExistingNames;
|
||||
private final List<String> myExistingNames;
|
||||
|
||||
public UniqueFileNamesProvider() {
|
||||
myExistingNames = new ArrayList<String>();
|
||||
@@ -50,10 +53,11 @@ public class UniqueFileNamesProvider {
|
||||
}
|
||||
|
||||
public static String convertName(String s) {
|
||||
if (s == null || s.isEmpty()) {
|
||||
if (StringUtil.isEmpty(s)) {
|
||||
return "_";
|
||||
}
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (Character.isJavaIdentifierPart(c) || c == ' ') {
|
||||
|
||||
@@ -108,5 +108,4 @@ public class UniqueNameGenerator implements Condition<String> {
|
||||
public String generateUniqueName(final String defaultName) {
|
||||
return generateUniqueName(defaultName, "", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user