diff --git a/platform/util/src/com/intellij/openapi/util/Key.java b/platform/util/src/com/intellij/openapi/util/Key.java index 27ad43b24332..c3867ddb18bd 100644 --- a/platform/util/src/com/intellij/openapi/util/Key.java +++ b/platform/util/src/com/intellij/openapi/util/Key.java @@ -17,8 +17,13 @@ package com.intellij.openapi.util; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -@SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod", "UnusedDeclaration"}) +/** + * @author max + * @author Konstantin Bulenkov + */ +@SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod", "UnusedDeclaration", "EqualsWhichDoesntCheckParameterClass"}) public class Key { private static int ourKeysCounter = 0; private final int myIndex = ourKeysCounter++; @@ -45,4 +50,18 @@ public class Key { public static Key create(@NotNull @NonNls String name) { return new Key(name); } + + @Nullable + public T get(@Nullable UserDataHolder holder) { + return holder == null ? null : holder.getUserData(this); + } + + public T get(@Nullable UserDataHolder holder, T defaultValue) { + final T t = get(holder); + return t == null ? defaultValue : t; + } + + public boolean containsIn(@Nullable UserDataHolder holder) { + return get(holder) != null; + } }