Public visibilities for lambdas in inline methods
This commit is contained in:
@@ -28,6 +28,7 @@ import org.jetbrains.asm4.commons.Method;
|
||||
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||
import org.jetbrains.jet.codegen.context.LocalLookup;
|
||||
import org.jetbrains.jet.codegen.context.MethodContext;
|
||||
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
|
||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
@@ -41,7 +42,6 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.asm4.Opcodes.*;
|
||||
@@ -58,6 +58,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
private final FunctionGenerationStrategy strategy;
|
||||
private final CalculatedClosure closure;
|
||||
private final Type asmType;
|
||||
private final int visibilityFlag;
|
||||
|
||||
private Method constructor;
|
||||
|
||||
@@ -67,7 +68,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
@NotNull FunctionDescriptor funDescriptor,
|
||||
@Nullable ClassDescriptor samInterface,
|
||||
@NotNull Type closureSuperClass,
|
||||
@NotNull CodegenContext context,
|
||||
@NotNull CodegenContext parentContext,
|
||||
@NotNull LocalLookup localLookup,
|
||||
@NotNull FunctionGenerationStrategy strategy,
|
||||
@Nullable MemberCodegen parentCodegen
|
||||
@@ -78,7 +79,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
this.funDescriptor = funDescriptor;
|
||||
this.samInterface = samInterface;
|
||||
this.superClass = closureSuperClass;
|
||||
this.context = context.intoClosure(funDescriptor, localLookup, typeMapper);
|
||||
this.context = parentContext.intoClosure(funDescriptor, localLookup, typeMapper);
|
||||
this.strategy = strategy;
|
||||
|
||||
ClassDescriptor classDescriptor = anonymousClassForFunction(bindingContext, funDescriptor);
|
||||
@@ -86,6 +87,13 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
assert closure != null : "Closure must be calculated for class: " + classDescriptor;
|
||||
|
||||
this.asmType = asmTypeForAnonymousClass(bindingContext, funDescriptor);
|
||||
|
||||
//TODO: We should write header on lambda class and filter all completions by header
|
||||
if (parentContext instanceof MethodContext) {
|
||||
visibilityFlag = ((MethodContext) parentContext).isInlineFunction() ? ACC_PUBLIC : NO_FLAG_PACKAGE_PRIVATE;
|
||||
} else {
|
||||
visibilityFlag = NO_FLAG_PACKAGE_PRIVATE;
|
||||
}
|
||||
}
|
||||
|
||||
public void gen() {
|
||||
@@ -105,7 +113,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
|
||||
cv.defineClass(fun,
|
||||
V1_6,
|
||||
ACC_FINAL | ACC_SUPER,
|
||||
ACC_FINAL | ACC_SUPER | visibilityFlag,
|
||||
asmType.getInternalName(),
|
||||
getGenericSignature(),
|
||||
superClass.getInternalName(),
|
||||
@@ -207,7 +215,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
private Method generateConstructor(@NotNull ClassBuilder cv) {
|
||||
List<FieldInfo> args = calculateConstructorParameters(typeMapper, closure, asmType);
|
||||
|
||||
return generateConstructor(cv, args, fun, superClass, state);
|
||||
return generateConstructor(cv, args, fun, superClass, state, visibilityFlag);
|
||||
}
|
||||
|
||||
public static Method generateConstructor(
|
||||
@@ -215,12 +223,13 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
@NotNull List<FieldInfo> args,
|
||||
@Nullable PsiElement fun,
|
||||
@NotNull Type superClass,
|
||||
@NotNull GenerationState state
|
||||
@NotNull GenerationState state,
|
||||
int flags
|
||||
) {
|
||||
Type[] argTypes = fieldListToTypeArray(args);
|
||||
|
||||
Method constructor = new Method("<init>", Type.VOID_TYPE, argTypes);
|
||||
MethodVisitor mv = cv.newMethod(fun, NO_FLAG_PACKAGE_PRIVATE, "<init>", constructor.getDescriptor(), null,
|
||||
MethodVisitor mv = cv.newMethod(fun, flags, "<init>", constructor.getDescriptor(), null,
|
||||
ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||
mv.visitCode();
|
||||
|
||||
@@ -162,7 +162,7 @@ public class LambdaTransformer {
|
||||
|
||||
AsmUtil.genClosureFields(newConstructorSignature, classBuilder);
|
||||
|
||||
Method newConstructor = ClosureCodegen.generateConstructor(classBuilder, fields, null, Type.getObjectType(superName), state);
|
||||
Method newConstructor = ClosureCodegen.generateConstructor(classBuilder, fields, null, Type.getObjectType(superName), state, AsmUtil.NO_FLAG_PACKAGE_PRIVATE);
|
||||
invocation.setNewConstructorDescriptor(newConstructor.getDescriptor());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user