From 1c2e8ad550960f1f435871f92eddb332e4a26d6a Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Wed, 22 Aug 2012 14:33:27 +0400 Subject: [PATCH] BindingContextUtils.getNotNull() --- .../jet/lang/resolve/BindingContextUtils.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java index 78bfc7e0cf4..e363cef7ebb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java @@ -194,4 +194,27 @@ public class BindingContextUtils { trace.record(BindingContext.FUNCTION, psiElement, function); } + + @NotNull + public static V getNotNull( + @NotNull BindingContext bindingContext, + @NotNull ReadOnlySlice slice, + @NotNull K key + ) { + return getNotNull(bindingContext, slice, key, "Value at " + slice + " must not be null for " + key); + } + + @NotNull + public static V getNotNull( + @NotNull BindingContext bindingContext, + @NotNull ReadOnlySlice slice, + @NotNull K key, + @NotNull String messageIfNull + ) { + V value = bindingContext.get(slice, key); + if (value == null) { + throw new IllegalStateException(messageIfNull); + } + return value; + } }