NotNull
[fedora-idea.git] / platform / lang-api / src / com / intellij / codeInsight / daemon / HighlightDisplayKey.java
blob3ccad92eb7c54ca29321f9facac732273c007914
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.diagnostic.Logger;
20 import com.intellij.openapi.util.Comparing;
21 import com.intellij.util.containers.HashMap;
22 import org.jetbrains.annotations.NonNls;
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
26 import java.util.Map;
28 public class HighlightDisplayKey {
29 private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.HighlightDisplayKey");
31 private static final HashMap<String,HighlightDisplayKey> ourNameToKeyMap = new HashMap<String, HighlightDisplayKey>();
32 private static final HashMap<String,HighlightDisplayKey> ourIdToKeyMap = new HashMap<String, HighlightDisplayKey>();
33 private static final Map<HighlightDisplayKey, String> ourKeyToDisplayNameMap = new HashMap<HighlightDisplayKey, String>();
34 private static final Map<HighlightDisplayKey, String> ourKeyToAlternativeIDMap = new HashMap<HighlightDisplayKey, String>();
36 private final String myName;
37 private final String myID;
39 public static HighlightDisplayKey find(@NonNls @NotNull String name){
40 return ourNameToKeyMap.get(name);
43 public static HighlightDisplayKey findById(@NonNls @NotNull String id){
44 HighlightDisplayKey key = ourIdToKeyMap.get(id);
45 if (key != null) return key;
46 key = ourNameToKeyMap.get(id);
47 if (key != null && key.getID().equals(id)) return key;
48 return null;
51 @Nullable
52 public static HighlightDisplayKey register(@NonNls @NotNull String name) {
53 if (find(name) != null) {
54 LOG.info("Key with name \'" + name + "\' already registered");
55 return null;
57 return new HighlightDisplayKey(name);
60 @Nullable
61 public static HighlightDisplayKey register(@NonNls @NotNull String name, @NotNull String displayName, @NotNull @NonNls String id){
62 if (find(name) != null) {
63 LOG.info("Key with name \'" + name + "\' already registered");
64 return null;
66 HighlightDisplayKey highlightDisplayKey = new HighlightDisplayKey(name, id);
67 ourKeyToDisplayNameMap.put(highlightDisplayKey, displayName);
68 return highlightDisplayKey;
71 @Nullable
72 public static HighlightDisplayKey register(@NonNls @NotNull String name, @NotNull String displayName) {
73 return register(name, displayName, name);
76 public static String getDisplayNameByKey(@Nullable HighlightDisplayKey key){
77 return key == null ? null : ourKeyToDisplayNameMap.get(key);
80 private HighlightDisplayKey(@NotNull String name) {
81 this(name, name);
84 public HighlightDisplayKey(@NonNls @NotNull final String name, @NotNull @NonNls final String ID) {
85 myName = name;
86 myID = ID;
87 ourNameToKeyMap.put(myName, this);
88 if (!Comparing.equal(ID, name)) {
89 ourIdToKeyMap.put(ID, this);
93 public String toString() {
94 return myName;
97 public String getID(){
98 return myID;
101 public static HighlightDisplayKey register(@NotNull String shortName, @NotNull String displayName, @NotNull String id, String alternativeID) {
102 final HighlightDisplayKey key = register(shortName, displayName, id);
103 if (alternativeID != null) {
104 ourKeyToAlternativeIDMap.put(key, alternativeID);
106 return key;
109 public static String getAlternativeID(@NotNull HighlightDisplayKey key) {
110 return ourKeyToAlternativeIDMap.get(key);