public static boolean isVarCapturedInClosure(
     BindingContext bindingContext, DeclarationDescriptor descriptor) {
   if (!(descriptor instanceof VariableDescriptor) || descriptor instanceof PropertyDescriptor)
     return false;
   VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
   return bindingContext.get(CAPTURED_IN_CLOSURE, variableDescriptor) != null
       && variableDescriptor.isVar();
 }
Beispiel #2
0
  public static boolean shouldRecordInitializerForProperty(
      @NotNull VariableDescriptor variable, @NotNull KotlinType type) {
    if (variable.isVar() || type.isError()) return false;

    if (TypeUtils.acceptsNullable(type)) return true;

    KotlinBuiltIns builtIns = getBuiltIns(variable);
    return KotlinBuiltIns.isPrimitiveType(type)
        || KotlinTypeChecker.DEFAULT.equalTypes(builtIns.getStringType(), type)
        || KotlinTypeChecker.DEFAULT.equalTypes(builtIns.getNumber().getDefaultType(), type)
        || KotlinTypeChecker.DEFAULT.equalTypes(builtIns.getAnyType(), type);
  }
 protected Void visitVariableDescriptor(
     VariableDescriptor descriptor, StringBuilder builder, boolean skipValVar) {
   JetType type = descriptor.getType();
   if (descriptor instanceof ValueParameterDescriptor) {
     JetType varargElementType = ((ValueParameterDescriptor) descriptor).getVarargElementType();
     if (varargElementType != null) {
       builder.append(renderKeyword("vararg")).append(" ");
       type = varargElementType;
     }
   }
   String typeString =
       renderPropertyPrefixAndComputeTypeString(
           builder,
           skipValVar ? null : descriptor.isVar(),
           Collections.<TypeParameterDescriptor>emptyList(),
           ReceiverDescriptor.NO_RECEIVER,
           type);
   renderName(descriptor, builder);
   builder.append(" : ").append(escape(typeString));
   return null;
 }
  private void renderVariable(
      @NotNull VariableDescriptor variable, @NotNull StringBuilder builder, boolean topLevel) {
    JetType realType = variable.getType();

    JetType varargElementType =
        variable instanceof ValueParameterDescriptor
            ? ((ValueParameterDescriptor) variable).getVarargElementType()
            : null;
    JetType typeToRender = varargElementType != null ? varargElementType : realType;

    if (varargElementType != null) {
      builder.append(renderKeyword("vararg")).append(" ");
    }
    if (topLevel && !startFromName) {
      renderValVarPrefix(variable, builder);
    }

    renderName(variable, builder);
    builder.append(": ").append(escape(renderType(typeToRender)));

    if (verbose && varargElementType != null) {
      builder.append(" /*").append(escape(renderType(realType))).append("*/");
    }
  }
 private void renderValVarPrefix(
     @NotNull VariableDescriptor variable, @NotNull StringBuilder builder) {
   builder.append(renderKeyword(variable.isVar() ? "var" : "val")).append(" ");
 }