Include error type in error message

Everything besides it is almost always useless: descriptor is usually
ERROR_CLASS, declarations are usually nulls because they come from a different
module
This commit is contained in:
Alexander Udalov
2013-12-19 19:14:55 +04:00
parent 8695a0e283
commit 00cad9df91
@@ -264,7 +264,7 @@ public class JetTypeMapper extends BindingTraceAware {
if (ErrorUtils.isError(descriptor)) { if (ErrorUtils.isError(descriptor)) {
if (classBuilderMode != ClassBuilderMode.LIGHT_CLASSES) { if (classBuilderMode != ClassBuilderMode.LIGHT_CLASSES) {
throw new IllegalStateException(generateErrorMessageForErrorType(descriptor)); throw new IllegalStateException(generateErrorMessageForErrorType(jetType, descriptor));
} }
Type asmType = Type.getObjectType("error/NonExistentClass"); Type asmType = Type.getObjectType("error/NonExistentClass");
if (signatureVisitor != null) { if (signatureVisitor != null) {
@@ -319,7 +319,8 @@ public class JetTypeMapper extends BindingTraceAware {
return Type.getObjectType(getAsmType(bindingTrace, descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX); return Type.getObjectType(getAsmType(bindingTrace, descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
} }
private String generateErrorMessageForErrorType(@NotNull DeclarationDescriptor descriptor) { @NotNull
private String generateErrorMessageForErrorType(@NotNull JetType type, @NotNull DeclarationDescriptor descriptor) {
PsiElement declarationElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor); PsiElement declarationElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
PsiElement parentDeclarationElement = null; PsiElement parentDeclarationElement = null;
if (declarationElement != null) { if (declarationElement != null) {
@@ -329,13 +330,16 @@ public class JetTypeMapper extends BindingTraceAware {
} }
} }
return String.format("Error types are not allowed when classBuilderMode = %s. Descriptor: %s. For declaration %s:%s in %s:%s", return String.format("Error types are not allowed when classBuilderMode = %s. " +
classBuilderMode, "Type: %s (%s). Descriptor: %s. For declaration %s:%s in %s:%s",
descriptor, classBuilderMode,
declarationElement, type,
declarationElement != null ? declarationElement.getText() : "null", type.getClass().getSimpleName(),
parentDeclarationElement, descriptor,
parentDeclarationElement != null ? parentDeclarationElement.getText() : "null"); declarationElement,
declarationElement != null ? declarationElement.getText() : "null",
parentDeclarationElement,
parentDeclarationElement != null ? parentDeclarationElement.getText() : "null");
} }
private void writeGenericType( private void writeGenericType(