Example #1
0
  @NotNull
  public StackValue putInstanceOnStack(
      @NotNull final ExpressionCodegen codegen,
      @Nullable final FunctionDescriptor functionReferenceTarget) {
    return StackValue.operation(
        asmType,
        new Function1<InstructionAdapter, Unit>() {
          @Override
          public Unit invoke(InstructionAdapter v) {
            if (isConst(closure)) {
              v.getstatic(
                  asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, asmType.getDescriptor());
            } else {
              v.anew(asmType);
              v.dup();

              codegen.pushClosureOnStack(classDescriptor, true, codegen.defaultCallGenerator);
              v.invokespecial(
                  asmType.getInternalName(), "<init>", constructor.getDescriptor(), false);
            }

            if (functionReferenceTarget != null) {
              equipFunctionReferenceWithReflection(v, functionReferenceTarget);
            }

            return Unit.INSTANCE$;
          }
        });
  }