mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplification — introduce StateSplitterEx
This commit is contained in:
+6
-23
@@ -15,37 +15,20 @@
|
||||
*/
|
||||
package com.intellij.packaging.impl.artifacts;
|
||||
|
||||
import com.intellij.openapi.components.StateSplitter;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.components.StateSplitterEx;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.serialization.artifact.ArtifactState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ArtifactManagerStateSplitter implements StateSplitter {
|
||||
public List<Pair<Element, String>> splitState(Element e) {
|
||||
final UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
|
||||
List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>();
|
||||
|
||||
for (Element element : JDOMUtil.getElements(e)) {
|
||||
final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(element.getAttributeValue(ArtifactState.NAME_ATTRIBUTE))) + ".xml";
|
||||
result.add(Pair.create(element, name));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void mergeStatesInto(Element target, Element[] elements) {
|
||||
for (Element e : elements) {
|
||||
target.addContent(e);
|
||||
}
|
||||
final class ArtifactManagerStateSplitter extends StateSplitterEx {
|
||||
@Override
|
||||
public List<Pair<Element, String>> splitState(@NotNull Element state) {
|
||||
return splitState(state, ArtifactState.NAME_ATTRIBUTE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config>
|
||||
<profiles>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default" />
|
||||
<option name="myLocal" value="false" />
|
||||
</profile>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="p1" />
|
||||
<option name="myLocal" value="false" />
|
||||
<inspection_tool class="ConstantConditions" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="true" />
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</profiles>
|
||||
<option name="PROJECT_PROFILE" value="p1" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</config>
|
||||
<state>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default"/>
|
||||
<option name="myLocal" value="false"/>
|
||||
</profile>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="p1"/>
|
||||
<option name="myLocal" value="false"/>
|
||||
<inspection_tool class="ConstantConditions" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="true"/>
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="true"/>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
<option name="PROJECT_PROFILE" value="p1"/>
|
||||
<option name="USE_PROJECT_PROFILE" value="true"/>
|
||||
<version value="1.0"/>
|
||||
</state>
|
||||
@@ -59,7 +59,6 @@
|
||||
</component>
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<option name="PROJECT_PROFILE" value="p1" />
|
||||
<profiles>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default" />
|
||||
<option name="myLocal" value="false" />
|
||||
@@ -72,7 +71,6 @@
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</profiles>
|
||||
<list size="5">
|
||||
<item index="0" class="java.lang.String" itemvalue="TYPO" />
|
||||
<item index="1" class="java.lang.String" itemvalue="SERVER PROBLEM" />
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config>
|
||||
<profiles>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default" />
|
||||
<option name="myLocal" value="false" />
|
||||
</profile>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="p1" />
|
||||
<option name="myLocal" value="false" />
|
||||
<inspection_tool class="ConstantConditions" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="Production" level="WARNING" enabled="true">
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="false" />
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="false" />
|
||||
</scope>
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="true" />
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</profiles>
|
||||
<option name="PROJECT_PROFILE" value="p1" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</config>
|
||||
<state>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default"/>
|
||||
<option name="myLocal" value="false"/>
|
||||
</profile>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="p1"/>
|
||||
<option name="myLocal" value="false"/>
|
||||
<inspection_tool class="ConstantConditions" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="Production" level="WARNING" enabled="true">
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="false"/>
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="false"/>
|
||||
</scope>
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="true"/>
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="true"/>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
<option name="PROJECT_PROFILE" value="p1"/>
|
||||
<option name="USE_PROJECT_PROFILE" value="true"/>
|
||||
<version value="1.0"/>
|
||||
</state>
|
||||
@@ -62,7 +62,6 @@
|
||||
<scopes>
|
||||
<scope profile="Project Default" name="Production" />
|
||||
</scopes>
|
||||
<profiles>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default" />
|
||||
<option name="myLocal" value="false" />
|
||||
@@ -75,7 +74,6 @@
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</profiles>
|
||||
<list size="5">
|
||||
<item index="0" class="java.lang.String" itemvalue="TYPO" />
|
||||
<item index="1" class="java.lang.String" itemvalue="SERVER PROBLEM" />
|
||||
|
||||
+4
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -25,7 +25,6 @@ import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jdom.Element;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
@@ -44,17 +43,13 @@ public class InspectionProfilesConverterTest extends LightIdeaTestCase {
|
||||
try {
|
||||
final String relativePath = "/inspection/converter/";
|
||||
final File projectFile = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.ipr");
|
||||
final List children = JDOMUtil.loadDocument(projectFile).getRootElement().getChildren("component");
|
||||
|
||||
for (Object child : children) {
|
||||
final Element element = (Element)child;
|
||||
for (Element element : JDOMUtil.loadDocument(projectFile).getRootElement().getChildren("component")) {
|
||||
if (Comparing.strEqual(element.getAttributeValue("name"), "InspectionProjectProfileManager")) {
|
||||
final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(getProject());
|
||||
InspectionProfileImpl.INIT_INSPECTIONS = true;
|
||||
profileManager.readExternal(element);
|
||||
profileManager.loadState(element);
|
||||
|
||||
final Element configElement = new Element("config");
|
||||
profileManager.writeExternal(configElement);
|
||||
Element configElement = profileManager.getState();
|
||||
final File file = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.after.xml");
|
||||
PlatformTestUtil.assertElementsEqual(configElement, JDOMUtil.loadDocument(file).getRootElement());
|
||||
break;
|
||||
|
||||
+106
-124
@@ -16,50 +16,55 @@
|
||||
package com.intellij.profile;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.components.StateSplitter;
|
||||
import com.intellij.openapi.components.MainConfigurationStateSplitter;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import com.intellij.util.xmlb.XmlSerializer;
|
||||
import com.intellij.util.xmlb.annotations.OptionTag;
|
||||
import gnu.trove.THashMap;
|
||||
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.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 30-Nov-2005
|
||||
*/
|
||||
public abstract class DefaultProjectProfileManager extends ProjectProfileManager implements JDOMExternalizable {
|
||||
public abstract class DefaultProjectProfileManager extends ProjectProfileManager implements PersistentStateComponent<Element> {
|
||||
protected static final Logger LOG = Logger.getInstance("#com.intellij.profile.DefaultProjectProfileManager");
|
||||
|
||||
@NonNls protected static final String PROFILES = "profiles";
|
||||
@NonNls public static final String SCOPES = "scopes";
|
||||
@NonNls protected static final String SCOPE = "scope";
|
||||
@NonNls public static final String PROFILE = "profile";
|
||||
@NonNls protected static final String NAME = "name";
|
||||
|
||||
|
||||
private static final String VERSION = "1.0";
|
||||
|
||||
@NotNull
|
||||
protected final Project myProject;
|
||||
|
||||
/** This field is used for serialization. Do not rename it or make access weaker */
|
||||
public String PROJECT_PROFILE;
|
||||
protected String myProjectProfile;
|
||||
/** This field is used for serialization. Do not rename it or make access weaker */
|
||||
public boolean USE_PROJECT_PROFILE = true;
|
||||
|
||||
private final ApplicationProfileManager myApplicationProfileManager;
|
||||
|
||||
private final Map<String, Profile> myProfiles = new HashMap<String, Profile>();
|
||||
private final Map<String, Profile> myProfiles = new THashMap<String, Profile>();
|
||||
protected final DependencyValidationManager myHolder;
|
||||
private final List<ProfileChangeAdapter> myProfilesListener = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
@NonNls private static final String PROJECT_DEFAULT_PROFILE_NAME = "Project Default";
|
||||
@@ -90,81 +95,85 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public synchronized void readExternal(Element element) throws InvalidDataException {
|
||||
myProfiles.clear();
|
||||
DefaultJDOMExternalizer.readExternal(this, element);
|
||||
final Element profilesElement = element.getChild(PROFILES);
|
||||
if (profilesElement != null) {
|
||||
for (Object o : profilesElement.getChildren(PROFILE)) {
|
||||
final Profile profile = myApplicationProfileManager.createProfile();
|
||||
profile.setProfileManager(this);
|
||||
profile.readExternal((Element)o);
|
||||
final String name = profile.getName();
|
||||
if (myApplicationProfileManager.getProfile(name) != null) { //override ide profile
|
||||
// myApplicationProfileManager.deleteProfile(name);
|
||||
}
|
||||
myProfiles.put(name, profile);
|
||||
}
|
||||
}
|
||||
if (element.getChild("version") == null || !Comparing.strEqual(element.getChild("version").getAttributeValue("value"), VERSION)) {
|
||||
boolean toConvert = true;
|
||||
for (Object o : element.getChildren("option")) {
|
||||
if (Comparing.strEqual(((Element)o).getAttributeValue("name"), "USE_PROJECT_LEVEL_SETTINGS")) {
|
||||
toConvert = Boolean.parseBoolean(((Element)o).getAttributeValue("value"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (toConvert) {
|
||||
convert(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
public synchronized Element getState() {
|
||||
Element state = new Element("state");
|
||||
|
||||
protected void convert(Element element) throws InvalidDataException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void writeExternal(Element element) throws WriteExternalException {
|
||||
|
||||
final List<String> sortedProfiles = new ArrayList<String>(myProfiles.keySet());
|
||||
Collections.sort(sortedProfiles);
|
||||
Element profiles = null;
|
||||
String[] sortedProfiles = myProfiles.keySet().toArray(new String[myProfiles.size()]);
|
||||
Arrays.sort(sortedProfiles);
|
||||
for (String profile : sortedProfiles) {
|
||||
final Profile projectProfile = myProfiles.get(profile);
|
||||
if (projectProfile != null) {
|
||||
final Element profileElement = new Element(PROFILE);
|
||||
projectProfile.writeExternal(profileElement);
|
||||
boolean hasSmthToSave = sortedProfiles.size() > 1 || isDefaultProfileUsed();
|
||||
Element profileElement = new Element(PROFILE);
|
||||
try {
|
||||
projectProfile.writeExternal(profileElement);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
boolean hasSmthToSave = sortedProfiles.length > 1 || isDefaultProfileUsed();
|
||||
if (!hasSmthToSave) {
|
||||
for (Object child : profileElement.getChildren()) {
|
||||
if (!((Element)child).getName().equals("option")) {
|
||||
for (Element child : profileElement.getChildren()) {
|
||||
if (!child.getName().equals("option")) {
|
||||
hasSmthToSave = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasSmthToSave) continue;
|
||||
|
||||
if (profiles == null) {
|
||||
profiles = new Element(PROFILES);
|
||||
element.addContent(profiles);
|
||||
if (!hasSmthToSave) {
|
||||
continue;
|
||||
}
|
||||
|
||||
profiles.addContent(profileElement);
|
||||
state.addContent(profileElement);
|
||||
}
|
||||
}
|
||||
|
||||
if (profiles != null || isDefaultProfileUsed()) {
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
final Element version = new Element("version");
|
||||
version.setAttribute("value", VERSION);
|
||||
element.addContent(version);
|
||||
if (!state.getChildren().isEmpty() || isDefaultProfileUsed()) {
|
||||
XmlSerializer.serializeInto(this, state);
|
||||
state.addContent(new Element("version").setAttribute("value", VERSION));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void loadState(Element state) {
|
||||
myProfiles.clear();
|
||||
XmlSerializer.deserializeInto(this, state);
|
||||
for (Element o : state.getChildren(PROFILE)) {
|
||||
final Profile profile = myApplicationProfileManager.createProfile();
|
||||
profile.setProfileManager(this);
|
||||
try {
|
||||
profile.readExternal(o);
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
final String name = profile.getName();
|
||||
if (myApplicationProfileManager.getProfile(name) != null) { //override ide profile
|
||||
// myApplicationProfileManager.deleteProfile(name);
|
||||
}
|
||||
myProfiles.put(name, profile);
|
||||
}
|
||||
if (state.getChild("version") == null || !Comparing.strEqual(state.getChild("version").getAttributeValue("value"), VERSION)) {
|
||||
boolean toConvert = true;
|
||||
for (Element o : state.getChildren("option")) {
|
||||
if (Comparing.strEqual(o.getAttributeValue("name"), "USE_PROJECT_LEVEL_SETTINGS")) {
|
||||
toConvert = Boolean.parseBoolean(o.getAttributeValue("value"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (toConvert) {
|
||||
convert(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void convert(Element element) {
|
||||
}
|
||||
|
||||
private boolean isDefaultProfileUsed() {
|
||||
return PROJECT_PROFILE != null && !Comparing.strEqual(PROJECT_PROFILE, PROJECT_DEFAULT_PROFILE_NAME);
|
||||
return myProjectProfile != null && !Comparing.strEqual(myProjectProfile, PROJECT_DEFAULT_PROFILE_NAME);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -192,14 +201,19 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
}
|
||||
|
||||
@Override
|
||||
@OptionTag("PROJECT_PROFILE")
|
||||
public synchronized String getProjectProfile() {
|
||||
return PROJECT_PROFILE;
|
||||
return myProjectProfile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setProjectProfile(@Nullable final String newProfile) {
|
||||
final String oldProfile = PROJECT_PROFILE;
|
||||
PROJECT_PROFILE = newProfile;
|
||||
public synchronized void setProjectProfile(@Nullable String newProfile) {
|
||||
if (Comparing.strEqual(newProfile, myProjectProfile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String oldProfile = myProjectProfile;
|
||||
myProjectProfile = newProfile;
|
||||
USE_PROJECT_PROFILE = newProfile != null;
|
||||
if (oldProfile != null) {
|
||||
for (ProfileChangeAdapter adapter : myProfilesListener) {
|
||||
@@ -210,8 +224,10 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
|
||||
@NotNull
|
||||
public synchronized Profile getProjectProfileImpl(){
|
||||
if (!USE_PROJECT_PROFILE) return myApplicationProfileManager.getRootProfile();
|
||||
if (PROJECT_PROFILE == null || myProfiles.isEmpty()){
|
||||
if (!USE_PROJECT_PROFILE) {
|
||||
return myApplicationProfileManager.getRootProfile();
|
||||
}
|
||||
if (myProjectProfile == null || myProfiles.isEmpty()){
|
||||
setProjectProfile(PROJECT_DEFAULT_PROFILE_NAME);
|
||||
final Profile projectProfile = myApplicationProfileManager.createProfile();
|
||||
projectProfile.copyFrom(myApplicationProfileManager.getRootProfile());
|
||||
@@ -219,11 +235,10 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
projectProfile.setName(PROJECT_DEFAULT_PROFILE_NAME);
|
||||
myProfiles.put(PROJECT_DEFAULT_PROFILE_NAME, projectProfile);
|
||||
}
|
||||
else if (!myProfiles.containsKey(PROJECT_PROFILE)){
|
||||
final String projectProfileAttempt = myProfiles.keySet().iterator().next();
|
||||
setProjectProfile(projectProfileAttempt);
|
||||
else if (!myProfiles.containsKey(myProjectProfile)){
|
||||
setProjectProfile(myProfiles.keySet().iterator().next());
|
||||
}
|
||||
final Profile profile = myProfiles.get(PROJECT_PROFILE);
|
||||
final Profile profile = myProfiles.get(myProjectProfile);
|
||||
profile.setProfileManager(this);
|
||||
return profile;
|
||||
}
|
||||
@@ -242,61 +257,28 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
myProfilesListener.remove(profilesListener);
|
||||
}
|
||||
|
||||
public static class ProfileStateSplitter implements StateSplitter {
|
||||
|
||||
public static class ProfileStateSplitter extends MainConfigurationStateSplitter {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Pair<Element, String>> splitState(final Element e) {
|
||||
final UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>();
|
||||
|
||||
final Element[] elements = JDOMUtil.getElements(e);
|
||||
for (Element element : elements) {
|
||||
if (element.getName().equals("profiles")) {
|
||||
element.detach();
|
||||
|
||||
final Element[] profiles = JDOMUtil.getElements(element);
|
||||
for (Element profile : profiles) {
|
||||
String profileName = null;
|
||||
|
||||
final Element[] options = JDOMUtil.getElements(profile);
|
||||
for (Element option : options) {
|
||||
if (option.getName().equals("option") && option.getAttributeValue("name").equals("myName")) {
|
||||
profileName = option.getAttributeValue("value");
|
||||
}
|
||||
}
|
||||
|
||||
assert profileName != null;
|
||||
|
||||
final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(profileName)) + ".xml";
|
||||
result.add(Pair.create(profile, name));
|
||||
}
|
||||
protected String getSubStateFileName(@NotNull Element element) {
|
||||
for (Element option : element.getChildren("option")) {
|
||||
if (option.getAttributeValue("name").equals("myName")) {
|
||||
return option.getAttributeValue("value");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!e.getContent().isEmpty()) result.add(Pair.create(e, generator.generateUniqueName("profiles_settings") + ".xml"));
|
||||
|
||||
return result;
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void mergeStatesInto(final Element target, final Element[] elements) {
|
||||
Element profiles = new Element("profiles");
|
||||
target.addContent(profiles);
|
||||
protected String getComponentStateFileName() {
|
||||
return "profiles_settings";
|
||||
}
|
||||
|
||||
for (Element element : elements) {
|
||||
if (element.getName().equals("profile")) {
|
||||
element.detach();
|
||||
profiles.addContent(element);
|
||||
}
|
||||
else {
|
||||
final Element[] states = JDOMUtil.getElements(element);
|
||||
for (Element state : states) {
|
||||
state.detach();
|
||||
target.addContent(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getSubStateTagName() {
|
||||
return PROFILE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -25,5 +25,6 @@ public abstract class ProjectProfileManager implements ProfileManager {
|
||||
public abstract String getProfileName();
|
||||
|
||||
public abstract String getProjectProfile();
|
||||
public abstract void setProjectProfile(@Nullable final String projectProfile);
|
||||
|
||||
public abstract void setProjectProfile(@Nullable String projectProfile);
|
||||
}
|
||||
|
||||
+17
-36
@@ -22,23 +22,22 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.scope.packageSet.*;
|
||||
import com.intellij.ui.LayeredIcon;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jdom.Attribute;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@State(
|
||||
name = "DependencyValidationManager",
|
||||
@@ -312,41 +311,23 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager
|
||||
return new DependencyRule(fromNamedScope, toNamedScope, Boolean.valueOf(denyRule).booleanValue());
|
||||
}
|
||||
|
||||
static class ScopesStateSplitter extends StateSplitterEx {
|
||||
static final class ScopesStateSplitter extends MainConfigurationStateSplitter {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Pair<Element, String>> splitState(@NotNull Element state) {
|
||||
UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
List<Pair<Element, String>> result = new SmartList<Pair<Element, String>>();
|
||||
for (Iterator<Element> iterator = state.getChildren("scope").iterator(); iterator.hasNext(); ) {
|
||||
Element element = iterator.next();
|
||||
iterator.remove();
|
||||
String scopeName = element.getAttributeValue("name");
|
||||
assert scopeName != null;
|
||||
result.add(Pair.create(element, generator.generateUniqueName(FileUtil.sanitizeFileName(scopeName)) + ".xml"));
|
||||
}
|
||||
if (!state.getChildren().isEmpty()) {
|
||||
result.add(Pair.create(state, generator.generateUniqueName("scope_settings") + ".xml"));
|
||||
}
|
||||
return result;
|
||||
protected String getSubStateFileName(@NotNull Element element) {
|
||||
return element.getAttributeValue("name");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void mergeStateInto(@NotNull Element target, @NotNull Element subState) {
|
||||
if (subState.getName().equals("scope")) {
|
||||
target.addContent(subState);
|
||||
}
|
||||
else {
|
||||
for (Iterator<Element> iterator = subState.getChildren().iterator(); iterator.hasNext(); ) {
|
||||
Element configuration = iterator.next();
|
||||
iterator.remove();
|
||||
target.addContent(configuration);
|
||||
}
|
||||
for (Iterator<Attribute> iterator = subState.getAttributes().iterator(); iterator.hasNext(); ) {
|
||||
Attribute attribute = iterator.next();
|
||||
iterator.remove();
|
||||
target.setAttribute(attribute);
|
||||
}
|
||||
}
|
||||
protected String getComponentStateFileName() {
|
||||
return "scope_settings";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getSubStateTagName() {
|
||||
return "scope";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-26
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -19,8 +19,6 @@ import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ProjectComponent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
import com.intellij.profile.DefaultProjectProfileManager;
|
||||
import com.intellij.profile.Profile;
|
||||
@@ -49,29 +47,6 @@ public abstract class InspectionProjectProfileManager extends DefaultProjectProf
|
||||
return getInspectionProfile().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
try {
|
||||
final Element e = new Element("settings");
|
||||
writeExternal(e);
|
||||
return e;
|
||||
}
|
||||
catch (WriteExternalException e1) {
|
||||
LOG.error(e1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
try {
|
||||
readExternal(state);
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public InspectionProfile getInspectionProfile(){
|
||||
return (InspectionProfile)getProjectProfileImpl();
|
||||
|
||||
+27
-34
@@ -21,7 +21,10 @@ import com.intellij.codeInspection.ex.InspectionProfileWrapper;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StoragePathMacros;
|
||||
import com.intellij.openapi.components.StorageScheme;
|
||||
import com.intellij.openapi.project.DumbAwareRunnable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
@@ -54,7 +57,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
stateSplitter = InspectionProjectProfileManagerImpl.ProfileStateSplitter.class)
|
||||
}
|
||||
)
|
||||
public class InspectionProjectProfileManagerImpl extends InspectionProjectProfileManager implements ProjectComponent, PersistentStateComponent<Element> {
|
||||
public class InspectionProjectProfileManagerImpl extends InspectionProjectProfileManager {
|
||||
private final Map<String, InspectionProfileWrapper> myName2Profile = new ConcurrentHashMap<String, InspectionProfileWrapper>();
|
||||
private final SeverityRegistrar mySeverityRegistrar;
|
||||
private final NamedScopeManager myLocalScopesHolder;
|
||||
@@ -73,29 +76,6 @@ public class InspectionProjectProfileManagerImpl extends InspectionProjectProfil
|
||||
return (InspectionProjectProfileManagerImpl)project.getComponent(InspectionProjectProfileManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
try {
|
||||
final Element e = new Element("settings");
|
||||
writeExternal(e);
|
||||
return e;
|
||||
}
|
||||
catch (WriteExternalException e1) {
|
||||
LOG.error(e1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
try {
|
||||
readExternal(state);
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProfileLoaded() {
|
||||
return myName2Profile.containsKey(getInspectionProfile().getName());
|
||||
@@ -133,7 +113,9 @@ public class InspectionProjectProfileManagerImpl extends InspectionProjectProfil
|
||||
@Override
|
||||
public void projectOpened() {
|
||||
StartupManager startupManager = StartupManager.getInstance(myProject);
|
||||
if (startupManager == null) return; // upsource
|
||||
if (startupManager == null) {
|
||||
return; // upsource
|
||||
}
|
||||
startupManager.registerPostStartupActivity(new DumbAwareRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -219,15 +201,26 @@ public class InspectionProjectProfileManagerImpl extends InspectionProjectProfil
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(final Element element) throws InvalidDataException {
|
||||
mySeverityRegistrar.readExternal(element);
|
||||
super.readExternal(element);
|
||||
public void loadState(Element state) {
|
||||
try {
|
||||
mySeverityRegistrar.readExternal(state);
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
super.loadState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(final Element element) throws WriteExternalException {
|
||||
super.writeExternal(element);
|
||||
mySeverityRegistrar.writeExternal(element);
|
||||
public Element getState() {
|
||||
Element state = super.getState();
|
||||
try {
|
||||
mySeverityRegistrar.writeExternal(state);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,9 +229,9 @@ public class InspectionProjectProfileManagerImpl extends InspectionProjectProfil
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert(Element element) throws InvalidDataException {
|
||||
public void convert(Element element) {
|
||||
super.convert(element);
|
||||
if (PROJECT_PROFILE != null) {
|
||||
if (myProjectProfile != null) {
|
||||
((ProfileEx)getProjectProfileImpl()).convert(element, getProject());
|
||||
}
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.components;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MainConfigurationStateSplitter extends StateSplitterEx {
|
||||
@Override
|
||||
public final List<Pair<Element, String>> splitState(@NotNull Element state) {
|
||||
UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
List<Pair<Element, String>> result = new SmartList<Pair<Element, String>>();
|
||||
for (Iterator<Element> iterator = state.getChildren(getSubStateTagName()).iterator(); iterator.hasNext(); ) {
|
||||
Element element = iterator.next();
|
||||
iterator.remove();
|
||||
result.add(createItem(getSubStateFileName(element), generator, element));
|
||||
}
|
||||
if (!JDOMUtil.isEmpty(state)) {
|
||||
result.add(createItem(getComponentStateFileName(), generator, state));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void mergeStateInto(@NotNull Element target, @NotNull Element subState) {
|
||||
mergeStateInto(target, subState, getSubStateTagName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract String getSubStateFileName(@NotNull Element element);
|
||||
|
||||
@NotNull
|
||||
protected abstract String getComponentStateFileName();
|
||||
|
||||
@NotNull
|
||||
protected abstract String getSubStateTagName();
|
||||
}
|
||||
@@ -16,19 +16,65 @@
|
||||
package com.intellij.openapi.components;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jdom.Attribute;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class StateSplitterEx implements StateSplitter {
|
||||
@Override
|
||||
public abstract List<Pair<Element, String>> splitState(@NotNull Element state);
|
||||
|
||||
public abstract void mergeStateInto(@NotNull Element target, @NotNull Element subState);
|
||||
public void mergeStateInto(@NotNull Element target, @NotNull Element subState) {
|
||||
target.addContent(subState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void mergeStatesInto(Element target, Element[] elements) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static List<Pair<Element, String>> splitState(@NotNull Element state, @NotNull String attributeName) {
|
||||
UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
List<Pair<Element, String>> result = new SmartList<Pair<Element, String>>();
|
||||
for (Element subState : state.getChildren()) {
|
||||
result.add(createItem(generator, subState, attributeName));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static Pair<Element, String> createItem(@NotNull UniqueNameGenerator generator, @NotNull Element element, @NotNull String attributeName) {
|
||||
return createItem(element.getAttributeValue(attributeName), generator, element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static Pair<Element, String> createItem(@NotNull String fileName, @NotNull UniqueNameGenerator generator, @NotNull Element element) {
|
||||
return Pair.create(element, generator.generateUniqueName(FileUtil.sanitizeFileName(fileName)) + ".xml");
|
||||
}
|
||||
|
||||
protected static void mergeStateInto(@NotNull Element target, @NotNull Element subState, @NotNull String subStateName) {
|
||||
if (subState.getName().equals(subStateName)) {
|
||||
target.addContent(subState);
|
||||
}
|
||||
else {
|
||||
for (Iterator<Element> iterator = subState.getChildren().iterator(); iterator.hasNext(); ) {
|
||||
Element configuration = iterator.next();
|
||||
iterator.remove();
|
||||
target.addContent(configuration);
|
||||
}
|
||||
for (Iterator<Attribute> iterator = subState.getAttributes().iterator(); iterator.hasNext(); ) {
|
||||
Attribute attribute = iterator.next();
|
||||
iterator.remove();
|
||||
target.setAttribute(attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-21
@@ -23,15 +23,13 @@ import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
* @author dsl
|
||||
*/
|
||||
@State(
|
||||
name = "libraryTable",
|
||||
@@ -77,24 +75,10 @@ public class ProjectLibraryTable extends LibraryTableBase {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class LibraryStateSplitter implements StateSplitter {
|
||||
public final static class LibraryStateSplitter extends StateSplitterEx {
|
||||
@Override
|
||||
public List<Pair<Element, String>> splitState(Element e) {
|
||||
final UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
|
||||
List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>();
|
||||
for (Element library : e.getChildren()) {
|
||||
String name = generator.generateUniqueName(FileUtil.sanitizeFileName(library.getAttributeValue(LibraryImpl.LIBRARY_NAME_ATTR))) + ".xml";
|
||||
result.add(Pair.create(library, name));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeStatesInto(Element target, Element[] elements) {
|
||||
for (Element e : elements) {
|
||||
target.addContent(e);
|
||||
}
|
||||
public List<Pair<Element, String>> splitState(@NotNull Element state) {
|
||||
return splitState(state, LibraryImpl.LIBRARY_NAME_ATTR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,10 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
@@ -41,19 +43,20 @@ import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.psi.search.scope.packageSet.PackageSet;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import com.maddyhome.idea.copyright.actions.UpdateCopyrightProcessor;
|
||||
import com.maddyhome.idea.copyright.options.LanguageOptions;
|
||||
import com.maddyhome.idea.copyright.options.Options;
|
||||
import com.maddyhome.idea.copyright.util.FileTypeUtil;
|
||||
import com.maddyhome.idea.copyright.util.NewFileTracker;
|
||||
import org.jdom.Attribute;
|
||||
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.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@State(name = "CopyrightManager",
|
||||
storages = {@Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
@@ -292,53 +295,28 @@ public class CopyrightManager extends AbstractProjectComponent implements Persis
|
||||
addCopyright(copyrightProfile);
|
||||
}
|
||||
|
||||
public static class CopyrightStateSplitter implements StateSplitter {
|
||||
static final class CopyrightStateSplitter extends MainConfigurationStateSplitter {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Pair<Element, String>> splitState(Element e) {
|
||||
final UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
final List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>();
|
||||
|
||||
final Element[] elements = JDOMUtil.getElements(e);
|
||||
for (Element element : elements) {
|
||||
if (element.getName().equals("copyright")) {
|
||||
element.detach();
|
||||
|
||||
String profileName = null;
|
||||
final Element[] options = JDOMUtil.getElements(element);
|
||||
for (Element option : options) {
|
||||
if (option.getName().equals("option") && option.getAttributeValue("name").equals("myName")) {
|
||||
profileName = option.getAttributeValue("value");
|
||||
}
|
||||
}
|
||||
|
||||
assert profileName != null;
|
||||
|
||||
final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(profileName)) + ".xml";
|
||||
result.add(Pair.create(element, name));
|
||||
protected String getSubStateFileName(@NotNull Element element) {
|
||||
for (Element option : element.getChildren("option")) {
|
||||
if (option.getAttributeValue("name").equals("myName")) {
|
||||
return option.getAttributeValue("value");
|
||||
}
|
||||
}
|
||||
result.add(Pair.create(e, generator.generateUniqueName("profiles_settings") + ".xml"));
|
||||
return result;
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void mergeStatesInto(Element target, Element[] elements) {
|
||||
for (Element element : elements) {
|
||||
if (element.getName().equals("copyright")) {
|
||||
element.detach();
|
||||
target.addContent(element);
|
||||
}
|
||||
else {
|
||||
final Element[] states = JDOMUtil.getElements(element);
|
||||
for (Element state : states) {
|
||||
state.detach();
|
||||
target.addContent(state);
|
||||
}
|
||||
for (Object attr : element.getAttributes()) {
|
||||
target.setAttribute(((Attribute)attr).clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
protected String getComponentStateFileName() {
|
||||
return "profiles_settings";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getSubStateTagName() {
|
||||
return "copyright";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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,35 +15,19 @@
|
||||
*/
|
||||
package com.intellij.spellchecker.state;
|
||||
|
||||
import com.intellij.openapi.components.StateSplitter;
|
||||
import com.intellij.openapi.components.StateSplitterEx;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
*
|
||||
* @author shkate@jetbrains.com
|
||||
*/
|
||||
public class ProjectDictionarySplitter implements StateSplitter {
|
||||
public class ProjectDictionarySplitter extends StateSplitterEx {
|
||||
@Override
|
||||
public List<Pair<Element, String>> splitState(Element e) {
|
||||
final UniqueNameGenerator generator = new UniqueNameGenerator();
|
||||
List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>();
|
||||
for (Element element : e.getChildren()) {
|
||||
result.add(Pair.create(element, generator.generateUniqueName(FileUtil.sanitizeFileName(element.getAttributeValue(DictionaryState.NAME_ATTRIBUTE))) + ".xml"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeStatesInto(Element target, Element[] elements) {
|
||||
for (Element e : elements) {
|
||||
target.addContent(e);
|
||||
}
|
||||
public List<Pair<Element, String>> splitState(@NotNull Element state) {
|
||||
return splitState(state, DictionaryState.NAME_ATTRIBUTE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user