JS backend: cleanup, use BindingContextUtils.getNotNull instead BindingContextUtils.get + assert

(cherry picked from commit 111805f)
This commit is contained in:
develar
2012-09-06 10:11:31 +04:00
committed by Zalim Bashorov
parent 66325808c4
commit 84542872b8
@@ -98,17 +98,13 @@ public final class BindingUtils {
} }
public static boolean isStatement(@NotNull BindingContext context, @NotNull JetExpression expression) { public static boolean isStatement(@NotNull BindingContext context, @NotNull JetExpression expression) {
Boolean isStatement = context.get(BindingContext.STATEMENT, expression); return BindingContextUtils.getNotNull(context, BindingContext.STATEMENT, expression);
assert isStatement != null : message(expression, "Invalid behaviour of get(BindingContext.STATEMENT) at");
return isStatement;
} }
@NotNull @NotNull
public static JetType getTypeByReference(@NotNull BindingContext context, public static JetType getTypeByReference(@NotNull BindingContext context,
@NotNull JetTypeReference typeReference) { @NotNull JetTypeReference typeReference) {
JetType result = context.get(BindingContext.TYPE, typeReference); return BindingContextUtils.getNotNull(context, BindingContext.TYPE, typeReference);
assert result != null : message(typeReference, "TypeReference should reference a type");
return result;
} }
@NotNull @NotNull
@@ -126,11 +122,8 @@ public final class BindingUtils {
@Nullable @Nullable
public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context, public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context,
@NotNull JetReferenceExpression reference) { @NotNull JetReferenceExpression reference) {
DeclarationDescriptor referencedDescriptor = getNullableDescriptorForReferenceExpression(context, reference);
if (BindingContextUtils.isExpressionWithValidReference(reference, context)) { if (BindingContextUtils.isExpressionWithValidReference(reference, context)) {
assert referencedDescriptor != null return BindingContextUtils.getNotNull(context, BindingContext.REFERENCE_TARGET, reference);
: message(reference, "Reference expression must reference a descriptor for reference " + reference.getText());
return referencedDescriptor;
} }
return null; return null;
} }
@@ -168,12 +161,9 @@ public final class BindingUtils {
} }
public static boolean isVariableReassignment(@NotNull BindingContext context, @NotNull JetExpression expression) { public static boolean isVariableReassignment(@NotNull BindingContext context, @NotNull JetExpression expression) {
Boolean result = context.get(BindingContext.VARIABLE_REASSIGNMENT, expression); return BindingContextUtils.getNotNull(context, BindingContext.VARIABLE_REASSIGNMENT, expression);
assert result != null : message(expression);
return result;
} }
@Nullable @Nullable
public static FunctionDescriptor getFunctionDescriptorForOperationExpression(@NotNull BindingContext context, public static FunctionDescriptor getFunctionDescriptorForOperationExpression(@NotNull BindingContext context,
@NotNull JetOperationExpression expression) { @NotNull JetOperationExpression expression) {
@@ -190,10 +180,7 @@ public final class BindingUtils {
@NotNull @NotNull
public static DeclarationDescriptor getDescriptorForElement(@NotNull BindingContext context, public static DeclarationDescriptor getDescriptorForElement(@NotNull BindingContext context,
@NotNull PsiElement element) { @NotNull PsiElement element) {
DeclarationDescriptor descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element); return BindingContextUtils.getNotNull(context, BindingContext.DECLARATION_TO_DESCRIPTOR, element);
assert descriptor != null : message(element, element + " doesn't have a descriptor");
return descriptor;
} }
@Nullable @Nullable
@@ -230,55 +217,38 @@ public final class BindingUtils {
@NotNull @NotNull
public static ResolvedCall<FunctionDescriptor> getIteratorFunction(@NotNull BindingContext context, public static ResolvedCall<FunctionDescriptor> getIteratorFunction(@NotNull BindingContext context,
@NotNull JetExpression rangeExpression) { @NotNull JetExpression rangeExpression) {
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, rangeExpression); return BindingContextUtils.getNotNull(context, BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, rangeExpression);
assert resolvedCall != null :
message(rangeExpression, "Range expression must have a descriptor for iterator function");
return resolvedCall;
} }
@NotNull @NotNull
public static ResolvedCall<FunctionDescriptor> getNextFunction(@NotNull BindingContext context, public static ResolvedCall<FunctionDescriptor> getNextFunction(@NotNull BindingContext context,
@NotNull JetExpression rangeExpression) { @NotNull JetExpression rangeExpression) {
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL, rangeExpression); return BindingContextUtils.getNotNull(context, BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL, rangeExpression);
assert resolvedCall != null : ErrorReportingUtils
.message(rangeExpression, "Range expression must have a descriptor for next function");
return resolvedCall;
} }
@NotNull @NotNull
public static ResolvedCall<FunctionDescriptor> getHasNextCallable(@NotNull BindingContext context, public static ResolvedCall<FunctionDescriptor> getHasNextCallable(@NotNull BindingContext context,
@NotNull JetExpression rangeExpression) { @NotNull JetExpression rangeExpression) {
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, rangeExpression); return BindingContextUtils.getNotNull(context, 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;
} }
@NotNull @NotNull
public static PropertyDescriptor getPropertyDescriptorForObjectDeclaration(@NotNull BindingContext context, public static PropertyDescriptor getPropertyDescriptorForObjectDeclaration(@NotNull BindingContext context,
@NotNull JetObjectDeclarationName name) { @NotNull JetObjectDeclarationName name) {
PropertyDescriptor propertyDescriptor = context.get(BindingContext.OBJECT_DECLARATION, name); return BindingContextUtils.getNotNull(context, BindingContext.OBJECT_DECLARATION, name);
assert propertyDescriptor != null : message(name);
return propertyDescriptor;
} }
@NotNull @NotNull
public static JetType getTypeForExpression(@NotNull BindingContext context, public static JetType getTypeForExpression(@NotNull BindingContext context,
@NotNull JetExpression expression) { @NotNull JetExpression expression) {
JetType type = context.get(BindingContext.EXPRESSION_TYPE, expression); return BindingContextUtils.getNotNull(context, BindingContext.EXPRESSION_TYPE, expression);
assert type != null : message(expression);
return type;
} }
@NotNull @NotNull
public static ResolvedCall<FunctionDescriptor> getResolvedCallForArrayAccess(@NotNull BindingContext context, public static ResolvedCall<FunctionDescriptor> getResolvedCallForArrayAccess(@NotNull BindingContext context,
@NotNull JetArrayAccessExpression arrayAccessExpression, @NotNull JetArrayAccessExpression arrayAccessExpression,
boolean isGet) { boolean isGet) {
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(isGet return BindingContextUtils.getNotNull(context, isGet ? INDEXED_LVALUE_GET : INDEXED_LVALUE_SET, arrayAccessExpression);
? INDEXED_LVALUE_GET
: INDEXED_LVALUE_SET, arrayAccessExpression);
assert resolvedCall != null : message(arrayAccessExpression);
return resolvedCall;
} }
public static ConstructorDescriptor getConstructor(@NotNull BindingContext bindingContext, public static ConstructorDescriptor getConstructor(@NotNull BindingContext bindingContext,