fix IllegalArgumentException
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInsight / daemon / DaemonCodeAnalyzerSettings.java
blob6bb75f5d667a15adc838afbf18196ddf7ae903d3
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.codeInsight.daemon;
19 import com.intellij.openapi.application.PathManager;
20 import com.intellij.openapi.components.*;
21 import com.intellij.openapi.diagnostic.Logger;
22 import com.intellij.openapi.util.DefaultJDOMExternalizer;
23 import com.intellij.openapi.util.InvalidDataException;
24 import com.intellij.openapi.util.JDOMUtil;
25 import com.intellij.openapi.util.WriteExternalException;
26 import com.intellij.profile.codeInspection.InspectionProfileManager;
27 import org.jdom.Element;
28 import org.jetbrains.annotations.NonNls;
29 import org.jetbrains.annotations.NotNull;
31 import java.io.File;
33 @State(
34 name="DaemonCodeAnalyzerSettings",
35 storages= {
36 @Storage(
37 id="other",
38 file = "$APP_CONFIG$/editor.codeinsight.xml"
41 public class DaemonCodeAnalyzerSettings implements PersistentStateComponent<Element>, Cloneable, ExportableComponent {
42 private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings");
43 @NonNls private static final String ROOT_TAG = "root";
44 @NonNls private static final String PROFILE_ATT = "profile";
45 @NonNls public static final String DEFAULT_PROFILE_ATT = "Default";
46 @NonNls public static final String PROFILE_COPY_NAME = "copy";
47 private final InspectionProfileManager myManager;
50 public DaemonCodeAnalyzerSettings(InspectionProfileManager manager) {
51 myManager = manager;
54 public static DaemonCodeAnalyzerSettings getInstance() {
55 return ServiceManager.getService(DaemonCodeAnalyzerSettings.class);
58 @NotNull
59 public File[] getExportFiles() {
60 return new File[]{PathManager.getOptionsFile("editor.codeinsight")};
63 @NotNull
64 public String getPresentableName() {
65 return DaemonBundle.message("error.highlighting.settings");
68 public boolean NEXT_ERROR_ACTION_GOES_TO_ERRORS_FIRST = false;
69 public int AUTOREPARSE_DELAY = 300;
70 public boolean SHOW_ADD_IMPORT_HINTS = true;
71 @NonNls public String NO_AUTO_IMPORT_PATTERN = "[a-z].?";
72 public boolean SUPPRESS_WARNINGS = true;
73 public boolean SHOW_METHOD_SEPARATORS = false;
74 public int ERROR_STRIPE_MARK_MIN_HEIGHT = 3;
75 public boolean SHOW_SMALL_ICONS_IN_GUTTER = true;
77 public boolean isCodeHighlightingChanged(DaemonCodeAnalyzerSettings oldSettings) {
78 try {
79 Element rootNew = new Element(ROOT_TAG);
80 writeExternal(rootNew);
81 Element rootOld = new Element(ROOT_TAG);
82 oldSettings.writeExternal(rootOld);
84 return !JDOMUtil.areElementsEqual(rootOld, rootNew);
86 catch (WriteExternalException e) {
87 LOG.error(e);
90 return false;
93 public Object clone() {
94 DaemonCodeAnalyzerSettings settings = new DaemonCodeAnalyzerSettings(myManager);
95 settings.AUTOREPARSE_DELAY = AUTOREPARSE_DELAY;
96 settings.SHOW_ADD_IMPORT_HINTS = SHOW_ADD_IMPORT_HINTS;
97 settings.SHOW_METHOD_SEPARATORS = SHOW_METHOD_SEPARATORS;
98 settings.NO_AUTO_IMPORT_PATTERN = NO_AUTO_IMPORT_PATTERN;
99 settings.SHOW_SMALL_ICONS_IN_GUTTER = SHOW_SMALL_ICONS_IN_GUTTER;
100 return settings;
103 public Element getState() {
104 Element e = new Element("state");
105 try {
106 writeExternal(e);
108 catch (WriteExternalException ex) {
109 LOG.error(ex);
111 return e;
114 public void loadState(final Element state) {
115 try {
116 readExternal(state);
118 catch (InvalidDataException e) {
119 LOG.error(e);
123 public void readExternal(Element element) throws InvalidDataException {
124 DefaultJDOMExternalizer.readExternal(this, element);
125 myManager.getConverter().storeEditorHighlightingProfile(element);
126 myManager.setRootProfile(element.getAttributeValue(PROFILE_ATT));
129 public void writeExternal(Element element) throws WriteExternalException {
130 DefaultJDOMExternalizer.writeExternal(this, element);
131 element.setAttribute(PROFILE_ATT, myManager.getRootProfile().getName());
134 public boolean isImportHintEnabled() {
135 return SHOW_ADD_IMPORT_HINTS;
138 public void setImportHintEnabled(boolean isImportHintEnabled) {
139 SHOW_ADD_IMPORT_HINTS = isImportHintEnabled;