InspectionProfileManagerImpl.shouldBeSaved should returns false for local scheme

This commit is contained in:
Vladimir Krivosheev
2014-11-18 20:22:45 +01:00
parent 32dc43326f
commit 417375dd18
2 changed files with 24 additions and 42 deletions
@@ -67,8 +67,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl");
@NonNls private static final String VALID_VERSION = "1.0";
@NonNls private static final String VERSION_TAG = "version";
@NonNls private static final String PROFILE_NAME_TAG = "profile_name";
@NonNls private static final String ROOT_ELEMENT_TAG = "inspections";
@NonNls private static final String USED_LEVELS = "used_levels";
@NonNls private static final String IS_LOCKED = "is_locked";
@NonNls private static final String DESCRIPTION = "description";
@@ -313,12 +311,12 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
element.addContent(new Element(DESCRIPTION).addContent(myDescription));
}
synchronized (myExternalInfo) {
if (!myInitialized) {
if (!myInitialized) {
for (Element el : myDeinstalledInspectionsSettings.values()) {
element.addContent(el.clone());
}
return;
}
return;
}
}
Map<String, Boolean> diffMap = getDisplayLevelMap();
@@ -559,7 +557,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
try {
tools = createTools(project);
}
catch (ProcessCanceledException e) {
catch (ProcessCanceledException ignored) {
return false;
}
final Map<String, List<String>> dependencies = new HashMap<String, List<String>>();
@@ -821,19 +819,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
myDescription = description;
}
public Element saveToDocument() throws WriteExternalException {
if (isLocal()) {
Element root = new Element(ROOT_ELEMENT_TAG);
root.setAttribute(PROFILE_NAME_TAG, myName);
writeExternal(root);
//myVisibleTreeState.writeExternal(root);
return root;
}
else {
return null;
}
}
@Override
public void convert(@NotNull Element element, @NotNull Project project) {
initInspectionTools(project);
@@ -66,7 +66,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
*/
public class InspectionProfileManagerImpl extends InspectionProfileManager implements SeverityProvider, ExportableComponent, JDOMExternalizable,
NamedComponent {
private final InspectionToolRegistrar myRegistrar;
private final SchemesManager<Profile, InspectionProfileImpl> mySchemesManager;
private final AtomicBoolean myProfilesAreInitialized = new AtomicBoolean(false);
@@ -86,20 +85,33 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
@NotNull
@Override
public InspectionProfileImpl readScheme(@NotNull Element element) {
InspectionProfileImpl profile = new InspectionProfileImpl(InspectionProfileLoadUtil.getProfileName(element), myRegistrar, InspectionProfileManagerImpl.this);
read(profile, element);
final InspectionProfileImpl profile = new InspectionProfileImpl(InspectionProfileLoadUtil.getProfileName(element), myRegistrar, InspectionProfileManagerImpl.this);
try {
profile.readExternal(element);
}
catch (Exception ignored) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
Messages.showErrorDialog(InspectionsBundle.message("inspection.error.loading.message", 0, profile.getName()),
InspectionsBundle.message("inspection.errors.occurred.dialog.title"));
}
}, ModalityState.NON_MODAL);
}
return profile;
}
@Override
public boolean shouldBeSaved(@NotNull final InspectionProfileImpl scheme) {
return scheme.wasInitialized();
public boolean shouldBeSaved(@NotNull InspectionProfileImpl scheme) {
return !scheme.isLocal() && scheme.wasInitialized();
}
@Override
public Element writeScheme(@NotNull final InspectionProfileImpl scheme) throws WriteExternalException {
return scheme.saveToDocument();
public Element writeScheme(@NotNull InspectionProfileImpl scheme) throws WriteExternalException {
Element root = new Element("inspections");
root.setAttribute("profile_name", scheme.myName);
scheme.writeExternal(root);
return root;
}
@Override
@@ -128,21 +140,6 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
mySeverityRegistrar = new SeverityRegistrar(messageBus);
}
private static void read(@NotNull final InspectionProfileImpl profile, @NotNull Element element) {
try {
profile.readExternal(element);
}
catch (Exception ignored) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
Messages.showErrorDialog(InspectionsBundle.message("inspection.error.loading.message", 0, profile.getName()),
InspectionsBundle.message("inspection.errors.occurred.dialog.title"));
}
}, ModalityState.NON_MODAL);
}
}
@NotNull
private static InspectionProfileImpl createSampleProfile() {
return new InspectionProfileImpl("Default");