Exemple #1
0
 private static boolean isDeclaredInJava(
     @NotNull CallableDescriptor callableDescriptor, @NotNull BindingContext context) {
   CallableDescriptor descriptor = callableDescriptor;
   while (true) {
     if (Boolean.TRUE.equals(context.get(BindingContext.IS_DECLARED_IN_JAVA, descriptor))) {
       return true;
     }
     CallableDescriptor original = descriptor.getOriginal();
     if (descriptor == original) break;
     descriptor = original;
   }
   return false;
 }
Exemple #2
0
  private static void genNotNullAssertion(
      @NotNull InstructionAdapter v,
      @NotNull GenerationState state,
      @NotNull CallableDescriptor descriptor,
      @NotNull String assertMethodToCall) {
    if (!state.isGenerateNotNullAssertions()) return;

    if (!isDeclaredInJava(descriptor, state.getBindingContext())) return;

    JetType type = descriptor.getReturnType();
    if (type == null || isNullableType(type)) return;

    Type asmType = state.getTypeMapper().mapReturnType(type);
    if (asmType.getSort() == Type.OBJECT || asmType.getSort() == Type.ARRAY) {
      v.dup();
      v.visitLdcInsn(descriptor.getContainingDeclaration().getName().asString());
      v.visitLdcInsn(descriptor.getName().asString());
      v.invokestatic(
          "jet/runtime/Intrinsics",
          assertMethodToCall,
          "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V");
    }
  }