diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index 35c0fb4600a..ac38ba856e8 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -19,8 +19,6 @@ package org.jetbrains.jet.codegen; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.ArrayUtil; -import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; @@ -32,17 +30,11 @@ import org.jetbrains.jet.codegen.context.PackageContext; import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.config.IncrementalCompilation; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.descriptors.annotations.Annotated; -import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.Annotations; import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl; import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil; -import org.jetbrains.jet.lang.resolve.constants.ArrayValue; -import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; -import org.jetbrains.jet.lang.resolve.constants.JavaClassValue; -import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.TypeUtils; @@ -284,34 +276,4 @@ public class CodegenUtil { return null; } - - @NotNull - public static String[] getExceptions(@NotNull Annotated annotatedDescriptor, @NotNull final JetTypeMapper mapper) { - // Can't say 'throws.class', because 'throws' is a reserved work in Java - AnnotationDescriptor annotation = annotatedDescriptor.getAnnotations().findAnnotation(new FqName("kotlin.throws")); - if (annotation == null) return ArrayUtil.EMPTY_STRING_ARRAY; - - Collection> values = annotation.getAllValueArguments().values(); - if (values.isEmpty()) return ArrayUtil.EMPTY_STRING_ARRAY; - - Object value = values.iterator().next(); - if (!(value instanceof ArrayValue)) return ArrayUtil.EMPTY_STRING_ARRAY; - ArrayValue arrayValue = (ArrayValue) value; - - List strings = ContainerUtil.mapNotNull( - arrayValue.getValue(), - new Function, String>() { - @Override - public String fun(CompileTimeConstant constant) { - if (constant instanceof JavaClassValue) { - JavaClassValue classValue = (JavaClassValue) constant; - ClassDescriptor classDescriptor = DescriptorUtils.getClassDescriptorForType(classValue.getValue()); - return mapper.mapClass(classDescriptor).getInternalName(); - } - return null; - } - } - ); - return strings.toArray(new String[strings.size()]); - } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 1d346890698..f8cc6f27169 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -19,6 +19,9 @@ package org.jetbrains.jet.codegen; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.psi.PsiElement; +import com.intellij.util.ArrayUtil; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.org.objectweb.asm.AnnotationVisitor; @@ -38,9 +41,15 @@ import org.jetbrains.jet.codegen.signature.JvmMethodSignature; import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.psi.JetNamedFunction; import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; +import org.jetbrains.jet.lang.resolve.constants.ArrayValue; +import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; +import org.jetbrains.jet.lang.resolve.constants.JavaClassValue; import org.jetbrains.jet.lang.resolve.java.JvmAbi; +import org.jetbrains.jet.lang.resolve.name.FqName; import java.io.PrintWriter; import java.io.StringWriter; @@ -108,7 +117,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { asmMethod.getName(), asmMethod.getDescriptor(), jvmSignature.getGenericsSignature(), - CodegenUtil.getExceptions(functionDescriptor, typeMapper)); + getThrownExceptions(functionDescriptor, typeMapper)); if (owner instanceof PackageFacadeContext) { Type ownerType = ((PackageFacadeContext) owner).getDelegateToClassType(); @@ -449,6 +458,35 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { } } + @NotNull + private static String[] getThrownExceptions(@NotNull FunctionDescriptor function, @NotNull final JetTypeMapper mapper) { + AnnotationDescriptor annotation = function.getAnnotations().findAnnotation(new FqName("kotlin.throws")); + if (annotation == null) return ArrayUtil.EMPTY_STRING_ARRAY; + + Collection> values = annotation.getAllValueArguments().values(); + if (values.isEmpty()) return ArrayUtil.EMPTY_STRING_ARRAY; + + Object value = values.iterator().next(); + if (!(value instanceof ArrayValue)) return ArrayUtil.EMPTY_STRING_ARRAY; + ArrayValue arrayValue = (ArrayValue) value; + + List strings = ContainerUtil.mapNotNull( + arrayValue.getValue(), + new Function, String>() { + @Override + public String fun(CompileTimeConstant constant) { + if (constant instanceof JavaClassValue) { + JavaClassValue classValue = (JavaClassValue) constant; + ClassDescriptor classDescriptor = DescriptorUtils.getClassDescriptorForType(classValue.getValue()); + return mapper.mapClass(classDescriptor).getInternalName(); + } + return null; + } + } + ); + return strings.toArray(new String[strings.size()]); + } + static void generateConstructorWithoutParametersIfNeeded( @NotNull GenerationState state, @NotNull CallableMethod method, @@ -460,7 +498,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { } int flags = getVisibilityAccessFlag(constructorDescriptor); MethodVisitor mv = classBuilder.newMethod(null, flags, "", "()V", null, - CodegenUtil.getExceptions(constructorDescriptor, state.getTypeMapper())); + getThrownExceptions(constructorDescriptor, state.getTypeMapper())); if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return; @@ -530,7 +568,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC), isConstructor ? "" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, descriptor, null, - CodegenUtil.getExceptions(functionDescriptor, typeMapper)); + getThrownExceptions(functionDescriptor, typeMapper)); if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { generateDefaultImpl(owner, signature, functionDescriptor, isStatic, mv, loadStrategy); @@ -739,7 +777,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { int flags = ACC_PUBLIC; MethodVisitor mv = v.newMethod(null, flags, delegateMethod.getName(), delegateMethod.getDescriptor(), null, - CodegenUtil.getExceptions(functionDescriptor, typeMapper)); + getThrownExceptions(functionDescriptor, typeMapper)); if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return; mv.visitCode();