From 84542872b8fd84fe2d27a64145eb8e86bacdc1e9 Mon Sep 17 00:00:00 2001 From: develar Date: Thu, 6 Sep 2012 10:11:31 +0400 Subject: [PATCH] JS backend: cleanup, use BindingContextUtils.getNotNull instead BindingContextUtils.get + assert (cherry picked from commit 111805f) --- .../k2js/translate/utils/BindingUtils.java | 52 ++++--------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java b/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java index d54bb560144..b1b1ef15dcc 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java @@ -98,17 +98,13 @@ public final class BindingUtils { } public static boolean isStatement(@NotNull BindingContext context, @NotNull JetExpression expression) { - Boolean isStatement = context.get(BindingContext.STATEMENT, expression); - assert isStatement != null : message(expression, "Invalid behaviour of get(BindingContext.STATEMENT) at"); - return isStatement; + return BindingContextUtils.getNotNull(context, BindingContext.STATEMENT, expression); } @NotNull public static JetType getTypeByReference(@NotNull BindingContext context, @NotNull JetTypeReference typeReference) { - JetType result = context.get(BindingContext.TYPE, typeReference); - assert result != null : message(typeReference, "TypeReference should reference a type"); - return result; + return BindingContextUtils.getNotNull(context, BindingContext.TYPE, typeReference); } @NotNull @@ -126,11 +122,8 @@ public final class BindingUtils { @Nullable public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context, @NotNull JetReferenceExpression reference) { - DeclarationDescriptor referencedDescriptor = getNullableDescriptorForReferenceExpression(context, reference); if (BindingContextUtils.isExpressionWithValidReference(reference, context)) { - assert referencedDescriptor != null - : message(reference, "Reference expression must reference a descriptor for reference " + reference.getText()); - return referencedDescriptor; + return BindingContextUtils.getNotNull(context, BindingContext.REFERENCE_TARGET, reference); } return null; } @@ -168,12 +161,9 @@ public final class BindingUtils { } public static boolean isVariableReassignment(@NotNull BindingContext context, @NotNull JetExpression expression) { - Boolean result = context.get(BindingContext.VARIABLE_REASSIGNMENT, expression); - assert result != null : message(expression); - return result; + return BindingContextUtils.getNotNull(context, BindingContext.VARIABLE_REASSIGNMENT, expression); } - @Nullable public static FunctionDescriptor getFunctionDescriptorForOperationExpression(@NotNull BindingContext context, @NotNull JetOperationExpression expression) { @@ -190,10 +180,7 @@ public final class BindingUtils { @NotNull public static DeclarationDescriptor getDescriptorForElement(@NotNull BindingContext context, @NotNull PsiElement element) { - DeclarationDescriptor descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element); - - assert descriptor != null : message(element, element + " doesn't have a descriptor"); - return descriptor; + return BindingContextUtils.getNotNull(context, BindingContext.DECLARATION_TO_DESCRIPTOR, element); } @Nullable @@ -230,55 +217,38 @@ public final class BindingUtils { @NotNull public static ResolvedCall getIteratorFunction(@NotNull BindingContext context, @NotNull JetExpression rangeExpression) { - ResolvedCall resolvedCall = context.get(BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, rangeExpression); - assert resolvedCall != null : - message(rangeExpression, "Range expression must have a descriptor for iterator function"); - return resolvedCall; + return BindingContextUtils.getNotNull(context, BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, rangeExpression); } @NotNull public static ResolvedCall getNextFunction(@NotNull BindingContext context, @NotNull JetExpression rangeExpression) { - ResolvedCall resolvedCall = context.get(BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL, rangeExpression); - assert resolvedCall != null : ErrorReportingUtils - .message(rangeExpression, "Range expression must have a descriptor for next function"); - return resolvedCall; + return BindingContextUtils.getNotNull(context, BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL, rangeExpression); } @NotNull public static ResolvedCall getHasNextCallable(@NotNull BindingContext context, @NotNull JetExpression rangeExpression) { - ResolvedCall resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, rangeExpression); - assert resolvedCall != null - : message(rangeExpression, "Range expression must have a descriptor for hasNext function or property"); - return resolvedCall; + return BindingContextUtils.getNotNull(context, BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, rangeExpression); } @NotNull public static PropertyDescriptor getPropertyDescriptorForObjectDeclaration(@NotNull BindingContext context, @NotNull JetObjectDeclarationName name) { - PropertyDescriptor propertyDescriptor = context.get(BindingContext.OBJECT_DECLARATION, name); - assert propertyDescriptor != null : message(name); - return propertyDescriptor; + return BindingContextUtils.getNotNull(context, BindingContext.OBJECT_DECLARATION, name); } @NotNull public static JetType getTypeForExpression(@NotNull BindingContext context, @NotNull JetExpression expression) { - JetType type = context.get(BindingContext.EXPRESSION_TYPE, expression); - assert type != null : message(expression); - return type; + return BindingContextUtils.getNotNull(context, BindingContext.EXPRESSION_TYPE, expression); } @NotNull public static ResolvedCall getResolvedCallForArrayAccess(@NotNull BindingContext context, @NotNull JetArrayAccessExpression arrayAccessExpression, boolean isGet) { - ResolvedCall resolvedCall = context.get(isGet - ? INDEXED_LVALUE_GET - : INDEXED_LVALUE_SET, arrayAccessExpression); - assert resolvedCall != null : message(arrayAccessExpression); - return resolvedCall; + return BindingContextUtils.getNotNull(context, isGet ? INDEXED_LVALUE_GET : INDEXED_LVALUE_SET, arrayAccessExpression); } public static ConstructorDescriptor getConstructor(@NotNull BindingContext bindingContext,