Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 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);
  }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 private void renderValVarPrefix(
     @NotNull VariableDescriptor variable, @NotNull StringBuilder builder) {
   builder.append(renderKeyword(variable.isVar() ? "var" : "val")).append(" ");
 }