Minor, move and rename getExceptions
Should only be used in FunctionCodegen from now on, because every method generation should go through FunctionCodegen
This commit is contained in:
@@ -19,8 +19,6 @@ package org.jetbrains.jet.codegen;
|
|||||||
import com.intellij.openapi.util.Condition;
|
import com.intellij.openapi.util.Condition;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
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.ContainerUtil;
|
||||||
import com.intellij.util.containers.Stack;
|
import com.intellij.util.containers.Stack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.jet.config.IncrementalCompilation;
|
import org.jetbrains.jet.config.IncrementalCompilation;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
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.annotations.Annotations;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
|
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil;
|
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.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
@@ -284,34 +276,4 @@ public class CodegenUtil {
|
|||||||
|
|
||||||
return null;
|
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<CompileTimeConstant<?>> 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<String> strings = ContainerUtil.mapNotNull(
|
|
||||||
arrayValue.getValue(),
|
|
||||||
new Function<CompileTimeConstant<?>, 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()]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ package org.jetbrains.jet.codegen;
|
|||||||
|
|
||||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||||
import com.intellij.psi.PsiElement;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
|
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.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
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.psi.JetNamedFunction;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
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.java.JvmAbi;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
@@ -108,7 +117,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
asmMethod.getName(),
|
asmMethod.getName(),
|
||||||
asmMethod.getDescriptor(),
|
asmMethod.getDescriptor(),
|
||||||
jvmSignature.getGenericsSignature(),
|
jvmSignature.getGenericsSignature(),
|
||||||
CodegenUtil.getExceptions(functionDescriptor, typeMapper));
|
getThrownExceptions(functionDescriptor, typeMapper));
|
||||||
|
|
||||||
if (owner instanceof PackageFacadeContext) {
|
if (owner instanceof PackageFacadeContext) {
|
||||||
Type ownerType = ((PackageFacadeContext) owner).getDelegateToClassType();
|
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<CompileTimeConstant<?>> 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<String> strings = ContainerUtil.mapNotNull(
|
||||||
|
arrayValue.getValue(),
|
||||||
|
new Function<CompileTimeConstant<?>, 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(
|
static void generateConstructorWithoutParametersIfNeeded(
|
||||||
@NotNull GenerationState state,
|
@NotNull GenerationState state,
|
||||||
@NotNull CallableMethod method,
|
@NotNull CallableMethod method,
|
||||||
@@ -460,7 +498,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
}
|
}
|
||||||
int flags = getVisibilityAccessFlag(constructorDescriptor);
|
int flags = getVisibilityAccessFlag(constructorDescriptor);
|
||||||
MethodVisitor mv = classBuilder.newMethod(null, flags, "<init>", "()V", null,
|
MethodVisitor mv = classBuilder.newMethod(null, flags, "<init>", "()V", null,
|
||||||
CodegenUtil.getExceptions(constructorDescriptor, state.getTypeMapper()));
|
getThrownExceptions(constructorDescriptor, state.getTypeMapper()));
|
||||||
|
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
|
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),
|
MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC),
|
||||||
isConstructor ? "<init>" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX,
|
isConstructor ? "<init>" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX,
|
||||||
descriptor, null,
|
descriptor, null,
|
||||||
CodegenUtil.getExceptions(functionDescriptor, typeMapper));
|
getThrownExceptions(functionDescriptor, typeMapper));
|
||||||
|
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||||
generateDefaultImpl(owner, signature, functionDescriptor, isStatic, mv, loadStrategy);
|
generateDefaultImpl(owner, signature, functionDescriptor, isStatic, mv, loadStrategy);
|
||||||
@@ -739,7 +777,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
int flags = ACC_PUBLIC;
|
int flags = ACC_PUBLIC;
|
||||||
|
|
||||||
MethodVisitor mv = v.newMethod(null, flags, delegateMethod.getName(), delegateMethod.getDescriptor(), null,
|
MethodVisitor mv = v.newMethod(null, flags, delegateMethod.getName(), delegateMethod.getDescriptor(), null,
|
||||||
CodegenUtil.getExceptions(functionDescriptor, typeMapper));
|
getThrownExceptions(functionDescriptor, typeMapper));
|
||||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
|
|||||||
Reference in New Issue
Block a user