added more descriptive assertions if we get nulls when compiling

This commit is contained in:
James Strachan
2012-05-30 10:27:10 +01:00
parent 4ef8a3ce50
commit e6f2f7043b
2 changed files with 8 additions and 0 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.k2js.translate.reference;
import com.google.common.base.Preconditions;
import com.google.dart.compiler.backend.js.ast.JsExpression;
import com.google.dart.compiler.backend.js.ast.JsName;
import org.jetbrains.annotations.NotNull;
@@ -57,6 +58,7 @@ public final class ReferenceTranslator {
public static JsExpression translateAsLocalNameReference(@NotNull DeclarationDescriptor referencedDescriptor,
@NotNull TranslationContext context) {
DeclarationDescriptor effectiveDescriptor = getReferencedDescriptor(referencedDescriptor, context);
Preconditions.checkNotNull(effectiveDescriptor, "Could not find DeclarationDescriptor for %s", referencedDescriptor);
return context.getNameForDescriptor(effectiveDescriptor).makeRef();
}
@@ -68,9 +70,11 @@ public final class ReferenceTranslator {
DeclarationDescriptor effectiveDescriptor;
if (context.isEcma5() && referencedDescriptor instanceof PropertyAccessorDescriptor) {
effectiveDescriptor = ((PropertyAccessorDescriptor) referencedDescriptor).getCorrespondingProperty();
Preconditions.checkNotNull(effectiveDescriptor, "No correspondingProperty available for descriptor %s", referencedDescriptor);
}
else {
effectiveDescriptor = referencedDescriptor;
Preconditions.checkNotNull(effectiveDescriptor, "No referencedDescriptor available");
}
return effectiveDescriptor;
}
@@ -16,11 +16,13 @@
package org.jetbrains.k2js.translate.utils;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
@@ -188,6 +190,8 @@ public final class BindingUtils {
@NotNull JetReferenceExpression reference) {
DeclarationDescriptor referencedDescriptor = getNullableDescriptorForReferenceExpression(context, reference);
assert referencedDescriptor != null : "Reference expression must reference a descriptor.";
Preconditions.checkNotNull(referencedDescriptor, "Reference expression must reference a descriptor for reference %s at %s", reference.getText(),
DiagnosticUtils.atLocation(reference));
return referencedDescriptor;
}