use of kotlin.Unit in project kotlin by JetBrains.
the class ExpressionCodegen method generateElvis.
private StackValue generateElvis(@NotNull final KtBinaryExpression expression) {
KtExpression left = expression.getLeft();
final Type exprType = expressionType(expression);
final Type leftType = expressionType(left);
final Label ifNull = new Label();
assert left != null : "left expression in elvis should be not null: " + expression.getText();
final StackValue value = generateExpressionWithNullFallback(left, ifNull);
if (isPrimitive(leftType)) {
return value;
}
return StackValue.operation(exprType, new Function1<InstructionAdapter, Unit>() {
@Override
public Unit invoke(InstructionAdapter v) {
value.put(value.type, v);
v.dup();
v.ifnull(ifNull);
StackValue.onStack(leftType).put(exprType, v);
Label end = new Label();
v.goTo(end);
v.mark(ifNull);
v.pop();
gen(expression.getRight(), exprType);
v.mark(end);
return null;
}
});
}
use of kotlin.Unit in project kotlin by JetBrains.
the class ExpressionCodegen method genSamInterfaceValue.
@Nullable
private StackValue genSamInterfaceValue(@NotNull KtExpression probablyParenthesizedExpression, @NotNull final KtVisitor<StackValue, StackValue> visitor) {
final KtExpression expression = KtPsiUtil.deparenthesize(probablyParenthesizedExpression);
final SamType samType = bindingContext.get(SAM_VALUE, probablyParenthesizedExpression);
if (samType == null || expression == null)
return null;
if (expression instanceof KtLambdaExpression) {
return genClosure(((KtLambdaExpression) expression).getFunctionLiteral(), samType);
}
if (expression instanceof KtNamedFunction) {
return genClosure((KtNamedFunction) expression, samType);
}
final Type asmType = state.getSamWrapperClasses().getSamWrapperClass(samType, expression.getContainingKtFile(), this);
return StackValue.operation(asmType, new Function1<InstructionAdapter, Unit>() {
@Override
public Unit invoke(InstructionAdapter v) {
v.anew(asmType);
v.dup();
Type functionType = typeMapper.mapType(samType.getKotlinFunctionType());
expression.accept(visitor, StackValue.none()).put(functionType, v);
Label ifNonNull = new Label();
Label afterAll = new Label();
v.dup();
v.ifnonnull(ifNonNull);
// if null: pop function value and wrapper objects, put null
v.pop();
v.pop2();
v.aconst(null);
v.goTo(afterAll);
v.mark(ifNonNull);
v.invokespecial(asmType.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType), false);
v.mark(afterAll);
return null;
}
});
}
use of kotlin.Unit in project kotlin by JetBrains.
the class MemberCodegen method generateKotlinClassMetadataAnnotation.
protected void generateKotlinClassMetadataAnnotation(@NotNull ClassDescriptor descriptor, boolean isScript) {
final DescriptorSerializer serializer = DescriptorSerializer.create(descriptor, new JvmSerializerExtension(v.getSerializationBindings(), state));
final ProtoBuf.Class classProto = serializer.classProto(descriptor).build();
int flags = isScript ? JvmAnnotationNames.METADATA_SCRIPT_FLAG : 0;
WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.CLASS, flags, new Function1<AnnotationVisitor, Unit>() {
@Override
public Unit invoke(AnnotationVisitor av) {
writeAnnotationData(av, serializer, classProto);
return Unit.INSTANCE;
}
});
}
use of kotlin.Unit in project kotlin by JetBrains.
the class TypeUnifierTest method makeType.
private TypeProjection makeType(String typeStr) {
LexicalScope withX = new LexicalScopeImpl(builtinsImportingScope, module, false, null, LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
handler.addClassifierDescriptor(x);
handler.addClassifierDescriptor(y);
return Unit.INSTANCE;
}
});
KtTypeProjection projection = KtPsiFactoryKt.KtPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0);
KtTypeReference typeReference = projection.getTypeReference();
assert typeReference != null;
KotlinType type = typeResolver.resolveType(withX, typeReference, KotlinTestUtils.DUMMY_TRACE, true);
return new TypeProjectionImpl(getProjectionKind(typeStr, projection), type);
}
Aggregations