private static String renderParameter( ValueParameterDescriptor descriptor, boolean named, BindingContext bindingContext) { StringBuilder builder = new StringBuilder(); if (named) builder.append("["); if (descriptor.getVarargElementType() != null) { builder.append("vararg "); } builder .append(descriptor.getName()) .append(": ") .append(DescriptorRenderer.TEXT.renderType(getActualParameterType(descriptor))); if (descriptor.hasDefaultValue()) { PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor); String defaultExpression = "?"; if (element instanceof JetParameter) { JetParameter parameter = (JetParameter) element; JetExpression defaultValue = parameter.getDefaultValue(); if (defaultValue != null) { if (defaultValue instanceof JetConstantExpression) { JetConstantExpression constantExpression = (JetConstantExpression) defaultValue; defaultExpression = constantExpression.getText(); if (defaultExpression.length() > 10) { if (defaultExpression.startsWith("\"")) defaultExpression = "\"...\""; else if (defaultExpression.startsWith("\'")) defaultExpression = "\'...\'"; else defaultExpression = defaultExpression.substring(0, 7) + "..."; } } } } builder.append(" = ").append(defaultExpression); } if (named) builder.append("]"); return builder.toString(); }
private static String renderParameter(ValueParameterDescriptor parameter, boolean named) { StringBuilder builder = new StringBuilder(); if (named) builder.append("["); if (parameter.getVarargElementType() != null) { builder.append("vararg "); } builder .append(parameter.getName()) .append(": ") .append( DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(getActualParameterType(parameter))); if (DescriptorUtilPackage.hasDefaultValue(parameter)) { PsiElement parameterDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(parameter); builder.append(" = ").append(getDefaultExpressionString(parameterDeclaration)); } if (named) builder.append("]"); return builder.toString(); }
private static JetType getActualParameterType(ValueParameterDescriptor descriptor) { JetType paramType = descriptor.getType(); if (descriptor.getVarargElementType() != null) paramType = descriptor.getVarargElementType(); return paramType; }