2 * Copyright 2000-2016 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.
16 package com.intellij.profile;
18 import com.intellij.profile.codeInspection.ProjectInspectionProfileManagerKt;
19 import com.intellij.util.xmlb.SmartSerializer;
20 import com.intellij.util.xmlb.annotations.OptionTag;
21 import com.intellij.util.xmlb.annotations.Transient;
22 import org.jdom.Element;
23 import org.jetbrains.annotations.NotNull;
29 public abstract class ProfileEx implements Profile {
30 public static final String SCOPE = "scope";
31 public static final String NAME = "name";
33 private final SmartSerializer mySerializer;
36 protected String myName;
38 protected ProfileManager myProfileManager;
40 private boolean myIsProjectLevel;
42 public ProfileEx(@NotNull String name) {
43 this(name, SmartSerializer.skipEmptySerializer());
46 protected ProfileEx(@NotNull String name, @NotNull SmartSerializer serializer) {
48 mySerializer = serializer;
53 // ugly name to preserve compatibility
55 public String getName() {
61 public boolean isProjectLevel() {
62 return myIsProjectLevel;
66 public void setProjectLevel(boolean isProjectLevel) {
67 myIsProjectLevel = isProjectLevel;
71 public void setName(@NotNull String name) {
78 public ProfileManager getProfileManager() {
79 return myProfileManager;
83 public void setProfileManager(@NotNull ProfileManager profileManager) {
84 myProfileManager = profileManager;
88 public void readExternal(Element element) {
89 mySerializer.readExternal(this, element);
92 public void serializeInto(@NotNull Element element, boolean preserveCompatibility) {
93 mySerializer.writeExternal(this, element, preserveCompatibility);
97 public final void writeExternal(Element element) {
98 serializeInto(element, true);
101 public boolean equals(Object o) {
102 return this == o || o instanceof ProfileEx && myName.equals(((ProfileEx)o).myName);
105 public int hashCode() {
106 return myName.hashCode();
110 public int compareTo(@NotNull Object o) {
111 if (o instanceof Profile) {
112 return getName().compareToIgnoreCase(((Profile)o).getName());
118 public final void copyFrom(@NotNull Profile profile) {
119 readExternal(serializeProfile(profile));
123 public static Element serializeProfile(@NotNull Profile profile) {
124 Element result = new Element(ProjectInspectionProfileManagerKt.PROFILE);
125 profile.writeExternal(result);