add ultra-light classes/members that work without backend in simple cases

This commit is contained in:
peter
2018-10-25 17:58:05 +02:00
parent 387efc3791
commit ebc998d710
48 changed files with 2502 additions and 98 deletions
@@ -64,7 +64,7 @@ public abstract class AnnotationCodegen {
public static final List<JvmFlagAnnotation> FIELD_FLAGS = Arrays.asList(
new JvmFlagAnnotation(JvmAnnotationUtilKt.VOLATILE_ANNOTATION_FQ_NAME.asString(), Opcodes.ACC_VOLATILE),
new JvmFlagAnnotation("kotlin.jvm.Transient", Opcodes.ACC_TRANSIENT)
new JvmFlagAnnotation(JvmAnnotationUtilKt.TRANSIENT_ANNOTATION_FQ_NAME.asString(), Opcodes.ACC_TRANSIENT)
);
public static final List<JvmFlagAnnotation> METHOD_FLAGS = Arrays.asList(
@@ -1112,34 +1112,37 @@ public class FunctionCodegen {
}
@NotNull
public static String[] getThrownExceptions(@NotNull FunctionDescriptor function, @NotNull KotlinTypeMapper typeMapper) {
public static String[] getThrownExceptions(@NotNull FunctionDescriptor function, @NotNull KotlinTypeMapper mapper) {
return ArrayUtil.toStringArray(CollectionsKt.map(getThrownExceptions(function), d -> mapper.mapClass(d).getInternalName()));
}
@NotNull
public static List<ClassDescriptor> getThrownExceptions(@NotNull FunctionDescriptor function) {
AnnotationDescriptor annotation = function.getAnnotations().findAnnotation(new FqName("kotlin.throws"));
if (annotation == null) {
annotation = function.getAnnotations().findAnnotation(new FqName("kotlin.jvm.Throws"));
}
if (annotation == null) return ArrayUtil.EMPTY_STRING_ARRAY;
if (annotation == null) return Collections.emptyList();
Collection<ConstantValue<?>> values = annotation.getAllValueArguments().values();
if (values.isEmpty()) return ArrayUtil.EMPTY_STRING_ARRAY;
if (values.isEmpty()) return Collections.emptyList();
Object value = values.iterator().next();
if (!(value instanceof ArrayValue)) return ArrayUtil.EMPTY_STRING_ARRAY;
if (!(value instanceof ArrayValue)) return Collections.emptyList();
ArrayValue arrayValue = (ArrayValue) value;
List<String> strings = CollectionsKt.mapNotNull(
return CollectionsKt.mapNotNull(
arrayValue.getValue(),
(ConstantValue<?> constant) -> {
if (constant instanceof KClassValue) {
ClassDescriptor classDescriptor = DescriptorUtils.getClassDescriptorForType(
return DescriptorUtils.getClassDescriptorForType(
((KClassValue) constant).getArgumentType(DescriptorUtilsKt.getModule(function))
);
return typeMapper.mapClass(classDescriptor).getInternalName();
}
return null;
}
);
return ArrayUtil.toStringArray(strings);
}
void generateDefaultIfNeeded(
@@ -398,8 +398,8 @@ public class PropertyCodegen {
modifiers |= ACC_SYNTHETIC;
}
KotlinType kotlinType =
isDelegate ? getDelegateTypeForProperty((KtProperty) element, propertyDescriptor) : propertyDescriptor.getType();
KotlinType kotlinType = isDelegate ? getDelegateTypeForProperty((KtProperty) element, propertyDescriptor, bindingContext)
: propertyDescriptor.getType();
Type type = typeMapper.mapType(kotlinType);
ClassBuilder builder = v;
@@ -438,7 +438,11 @@ public class PropertyCodegen {
}
@NotNull
private KotlinType getDelegateTypeForProperty(@NotNull KtProperty p, @NotNull PropertyDescriptor propertyDescriptor) {
public static KotlinType getDelegateTypeForProperty(
@NotNull KtProperty p,
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull BindingContext bindingContext
) {
KotlinType delegateType = null;
ResolvedCall<FunctionDescriptor> provideDelegateResolvedCall =
@@ -1419,7 +1419,7 @@ public class KotlinTypeMapper {
* In that case the generated method's return type should be boxed: otherwise it's not possible to use
* this class from Java since javac issues errors when loading the class (incompatible return types)
*/
private boolean forceBoxedReturnType(@NotNull FunctionDescriptor descriptor) {
public boolean forceBoxedReturnType(@NotNull FunctionDescriptor descriptor) {
if (isBoxMethodForInlineClass(descriptor)) return true;
//noinspection ConstantConditions