use of org.jetbrains.kotlin.psi.KtExpression 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.psi.KtExpression 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.psi.KtExpression in project kotlin by JetBrains.
the class KotlinTypeCheckerTest method assertErrorType.
private void assertErrorType(String expression) {
Project project = getProject();
KtExpression ktExpression = KtPsiFactoryKt.KtPsiFactory(project).createExpression(expression);
KotlinType type = expressionTypingServices.safeGetType(scopeWithImports, ktExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfoFactory.EMPTY, KotlinTestUtils.DUMMY_TRACE);
assertTrue("Error type expected but " + type + " returned", type.isError());
}
Aggregations