use of org.jetbrains.kotlin.descriptors.ValueParameterDescriptor in project kotlin by JetBrains.
the class FunctionBodyTranslator method setDefaultValueForArguments.
@NotNull
public static List<JsStatement> setDefaultValueForArguments(@NotNull FunctionDescriptor descriptor, @NotNull TranslationContext functionBodyContext) {
List<ValueParameterDescriptor> valueParameters = descriptor.getValueParameters();
List<JsStatement> result = new ArrayList<JsStatement>(valueParameters.size());
for (ValueParameterDescriptor valueParameter : valueParameters) {
if (!valueParameter.declaresDefaultValue())
continue;
JsNameRef jsNameRef = functionBodyContext.getNameForDescriptor(valueParameter).makeRef();
KtExpression defaultArgument = getDefaultArgument(valueParameter);
JsBlock defaultArgBlock = new JsBlock();
JsExpression defaultValue = Translation.translateAsExpression(defaultArgument, functionBodyContext, defaultArgBlock);
JsStatement assignStatement = assignment(jsNameRef, defaultValue).makeStmt();
JsStatement thenStatement = JsAstUtils.mergeStatementInBlockIfNeeded(assignStatement, defaultArgBlock);
JsBinaryOperation checkArgIsUndefined = equality(jsNameRef, Namer.getUndefinedExpression());
JsIf jsIf = JsAstUtils.newJsIf(checkArgIsUndefined, thenStatement);
result.add(jsIf);
}
return result;
}
use of org.jetbrains.kotlin.descriptors.ValueParameterDescriptor in project kotlin by JetBrains.
the class CallBasedArgumentGenerator method generateExpression.
@Override
protected void generateExpression(int i, @NotNull ExpressionValueArgument argument) {
ValueParameterDescriptor parameter = valueParameters.get(i);
Type type = valueParameterTypes.get(i);
ValueArgument valueArgument = argument.getValueArgument();
assert valueArgument != null;
KtExpression argumentExpression = valueArgument.getArgumentExpression();
assert argumentExpression != null : valueArgument.asElement().getText();
callGenerator.genValueAndPut(parameter, argumentExpression, type, i);
}
use of org.jetbrains.kotlin.descriptors.ValueParameterDescriptor in project kotlin by JetBrains.
the class MemberMatching method valueParametersTypesMatch.
static boolean valueParametersTypesMatch(@NotNull KtNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) {
List<KtParameter> declarationParameters = getValueParameters(declaration);
List<ValueParameterDescriptor> descriptorParameters = descriptor.getValueParameters();
if (descriptorParameters.size() != declarationParameters.size()) {
return false;
}
for (int i = 0; i < descriptorParameters.size(); i++) {
ValueParameterDescriptor descriptorParameter = descriptorParameters.get(i);
KtParameter declarationParameter = declarationParameters.get(i);
KtTypeReference typeReference = declarationParameter.getTypeReference();
if (typeReference == null) {
return false;
}
KtModifierList modifierList = declarationParameter.getModifierList();
boolean varargInDeclaration = modifierList != null && modifierList.hasModifier(KtTokens.VARARG_KEYWORD);
boolean varargInDescriptor = descriptorParameter.getVarargElementType() != null;
if (varargInDeclaration != varargInDescriptor) {
return false;
}
String declarationTypeText = typeReference.getText();
KotlinType typeToRender = varargInDeclaration ? descriptorParameter.getVarargElementType() : descriptorParameter.getType();
assert typeToRender != null;
String descriptorParameterText = DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(typeToRender);
if (!declarationTypeText.equals(descriptorParameterText)) {
return false;
}
}
return true;
}
Aggregations