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(); }
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 renderValVarPrefix( @NotNull VariableDescriptor variable, @NotNull StringBuilder builder) { builder.append(renderKeyword(variable.isVar() ? "var" : "val")).append(" "); }