use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class ForLoopConventionsChecker method checkConventionForIterator.
@Nullable
private KotlinType checkConventionForIterator(@NotNull ExpressionTypingContext context, @NotNull KtExpression loopRangeExpression, @NotNull KotlinType iteratorType, @NotNull Name name, @NotNull DiagnosticFactory1<KtExpression, KotlinType> ambiguity, @NotNull DiagnosticFactory1<KtExpression, KotlinType> missing, @NotNull DiagnosticFactory1<KtExpression, KotlinType> noneApplicable, @NotNull WritableSlice<KtExpression, ResolvedCall<FunctionDescriptor>> resolvedCallKey) {
OverloadResolutionResults<FunctionDescriptor> nextResolutionResults = fakeCallResolver.resolveFakeCall(context, new TransientReceiver(iteratorType), name, loopRangeExpression, loopRangeExpression, FakeCallKind.OTHER, Collections.<KtExpression>emptyList());
if (nextResolutionResults.isAmbiguity()) {
context.trace.report(ambiguity.on(loopRangeExpression, iteratorType));
} else if (nextResolutionResults.isNothing()) {
context.trace.report(missing.on(loopRangeExpression, iteratorType));
} else if (!nextResolutionResults.isSuccess()) {
context.trace.report(noneApplicable.on(loopRangeExpression, iteratorType));
} else {
assert nextResolutionResults.isSuccess();
ResolvedCall<FunctionDescriptor> resolvedCall = nextResolutionResults.getResultingCall();
context.trace.record(resolvedCallKey, loopRangeExpression, resolvedCall);
FunctionDescriptor functionDescriptor = resolvedCall.getResultingDescriptor();
checkIfOperatorModifierPresent(loopRangeExpression, functionDescriptor, context.trace);
return functionDescriptor.getReturnType();
}
return null;
}
use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class JetTestFunctionDetector method getTestFunctions.
@NotNull
private static List<FunctionDescriptor> getTestFunctions(@NotNull BindingContext bindingContext, @NotNull List<KtDeclaration> declarations) {
List<FunctionDescriptor> answer = Lists.newArrayList();
for (KtDeclaration declaration : declarations) {
MemberScope scope = null;
if (declaration instanceof KtClass) {
KtClass klass = (KtClass) declaration;
ClassDescriptor classDescriptor = BindingUtils.getClassDescriptor(bindingContext, klass);
if (classDescriptor.getModality() != Modality.ABSTRACT) {
scope = classDescriptor.getDefaultType().getMemberScope();
}
}
if (scope != null) {
Collection<DeclarationDescriptor> allDescriptors = DescriptorUtils.getAllDescriptors(scope);
List<FunctionDescriptor> testFunctions = ContainerUtil.mapNotNull(allDescriptors, new Function<DeclarationDescriptor, FunctionDescriptor>() {
@Override
public FunctionDescriptor fun(DeclarationDescriptor descriptor) {
if (descriptor instanceof FunctionDescriptor) {
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
if (isTest(functionDescriptor))
return functionDescriptor;
}
return null;
}
});
answer.addAll(testFunctions);
}
}
return answer;
}
use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class Translation method generateCallToMain.
//TODO: determine whether should throw exception
@Nullable
private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull Collection<KtFile> files, @NotNull List<String> arguments) {
MainFunctionDetector mainFunctionDetector = new MainFunctionDetector(context.bindingContext());
KtNamedFunction mainFunction = mainFunctionDetector.getMainFunction(files);
if (mainFunction == null) {
return null;
}
FunctionDescriptor functionDescriptor = getFunctionDescriptor(context.bindingContext(), mainFunction);
JsArrayLiteral argument = new JsArrayLiteral(toStringLiteralList(arguments, context.program()));
return CallTranslator.INSTANCE.buildCall(context, functionDescriptor, Collections.singletonList(argument), null).makeStmt();
}
use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class ArrayAccessTranslator method translateAsMethodCall.
@NotNull
private JsExpression translateAsMethodCall(@NotNull JsExpression arrayExpression, @Nullable JsExpression toSetTo) {
boolean isGetter = toSetTo == null;
TranslationContext context = context();
ResolvedCall<FunctionDescriptor> resolvedCall = BindingUtils.getResolvedCallForArrayAccess(bindingContext(), expression, isGetter);
if (!isGetter) {
context = contextWithValueParameterAliasInArrayGetAccess(toSetTo);
}
return CallTranslator.translate(context, resolvedCall, arrayExpression);
}
use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class ArrayAccessTranslator method contextWithValueParameterAliasInArrayGetAccess.
// this is hack for a[b]++ -> a.set(b, a.get(b) + 1). Frontend generate fake expression for a.get(b) + 1.
@NotNull
private TranslationContext contextWithValueParameterAliasInArrayGetAccess(@NotNull JsExpression toSetTo) {
ResolvedCall<FunctionDescriptor> resolvedCall = BindingUtils.getResolvedCallForArrayAccess(bindingContext(), expression, /*isGetter = */
false);
List<ResolvedValueArgument> arguments = resolvedCall.getValueArgumentsByIndex();
if (arguments == null) {
throw new IllegalStateException("Failed to arrange value arguments by index: " + resolvedCall.getResultingDescriptor());
}
ResolvedValueArgument lastArgument = arguments.get(arguments.size() - 1);
assert lastArgument instanceof ExpressionValueArgument : "Last argument of array-like setter must be ExpressionValueArgument: " + lastArgument;
ValueArgument valueArgument = ((ExpressionValueArgument) lastArgument).getValueArgument();
assert valueArgument != null;
KtExpression element = valueArgument.getArgumentExpression();
return context().innerContextWithAliasesForExpressions(Collections.singletonMap(element, toSetTo));
}
Aggregations