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
.codeInspection
.ex
;
19 import com
.intellij
.codeHighlighting
.HighlightDisplayLevel
;
20 import com
.intellij
.codeInsight
.daemon
.HighlightDisplayKey
;
21 import com
.intellij
.codeInspection
.InspectionProfile
;
22 import com
.intellij
.codeInspection
.InspectionProfileEntry
;
23 import com
.intellij
.openapi
.diagnostic
.Logger
;
24 import com
.intellij
.openapi
.util
.WriteExternalException
;
25 import com
.intellij
.psi
.search
.scope
.packageSet
.NamedScope
;
26 import org
.jdom
.Element
;
27 import org
.jetbrains
.annotations
.NonNls
;
28 import org
.jetbrains
.annotations
.NotNull
;
34 public class Descriptor
{
35 private final String myText
;
36 private final String
[] myGroup
;
37 private final HighlightDisplayKey myKey
;
39 private final Element myConfig
;
40 private final InspectionProfileEntry myTool
;
41 private final HighlightDisplayLevel myLevel
;
42 private boolean myEnabled
= false;
43 private final NamedScope myScope
;
44 private static final Logger LOG
= Logger
.getInstance("#com.intellij.codeInspection.ex.Descriptor");
45 private final ScopeToolState myState
;
47 public Descriptor(ScopeToolState pair
, InspectionProfile inspectionProfile
) {
49 final InspectionProfileEntry tool
= pair
.getTool();
50 @NonNls Element config
= new Element("options");
52 tool
.writeSettings(config
);
54 catch (WriteExternalException e
) {
58 myText
= tool
.getDisplayName();
59 final String
[] groupPath
= tool
.getGroupPath();
60 myGroup
= groupPath
.length
== 0 ?
new String
[]{InspectionProfileEntry
.GENERAL_GROUP_NAME
} : groupPath
;
61 myKey
= HighlightDisplayKey
.find(tool
.getShortName());
62 myLevel
= ((InspectionProfileImpl
)inspectionProfile
).getErrorLevel(myKey
, pair
.getScope());
63 myEnabled
= ((InspectionProfileImpl
)inspectionProfile
).isToolEnabled(myKey
, pair
.getScope());
65 myScope
= pair
.getScope();
68 public boolean equals(Object obj
) {
69 if (!(obj
instanceof Descriptor
)) return false;
70 final Descriptor descriptor
= (Descriptor
)obj
;
71 return myKey
.equals(descriptor
.getKey()) &&
72 myLevel
.equals(descriptor
.getLevel()) &&
73 myEnabled
== descriptor
.isEnabled() &&
74 myState
.equalTo(descriptor
.getState());
77 public int hashCode() {
78 final int hash
= myKey
.hashCode() + 29 * myLevel
.hashCode();
79 return myScope
!= null ? myScope
.hashCode() + 29 * hash
: hash
;
82 public boolean isEnabled() {
86 public void setEnabled(final boolean enabled
) {
90 public String
getText() {
95 public HighlightDisplayKey
getKey() {
99 public HighlightDisplayLevel
getLevel() {
105 public Element
getConfig() {
109 public InspectionProfileEntry
getTool() {
113 public String
loadDescription() {
114 if (!(myTool
instanceof InspectionTool
)) return null;
115 return myTool
.loadDescription();
118 public String
[] getGroup() {
122 public NamedScope
getScope() {
126 public ScopeToolState
getState() {
131 public String
toString() {
132 return myKey
.toString();