use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.
the class KtInvokeFunctionReference method getTargetDescriptors.
@Override
@NotNull
protected Collection<DeclarationDescriptor> getTargetDescriptors(@NotNull BindingContext context) {
Call call = CallUtilKt.getCall(getElement(), context);
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(call, context);
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
return Collections.<DeclarationDescriptor>singleton(((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall().getCandidateDescriptor());
}
if (call != null && resolvedCall != null && call.getCallType() == Call.CallType.INVOKE) {
return Collections.<DeclarationDescriptor>singleton(resolvedCall.getCandidateDescriptor());
}
return Collections.emptyList();
}
use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor 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.DeclarationDescriptor in project kotlin by JetBrains.
the class FunctionBodyTranslator method translateFunctionBody.
@NotNull
public static JsBlock translateFunctionBody(@NotNull FunctionDescriptor descriptor, @NotNull KtDeclarationWithBody declarationWithBody, @NotNull TranslationContext functionBodyContext) {
Map<DeclarationDescriptor, JsExpression> aliases = new HashMap<DeclarationDescriptor, JsExpression>();
LocalFunctionCollector functionCollector = new LocalFunctionCollector(functionBodyContext.bindingContext());
declarationWithBody.acceptChildren(functionCollector, null);
for (FunctionDescriptor localFunction : functionCollector.getFunctions()) {
String localIdent = localFunction.getName().isSpecial() ? "lambda" : localFunction.getName().asString();
JsName localName = functionBodyContext.scope().getParent().declareTemporaryName(NameSuggestion.sanitizeName(localIdent));
MetadataProperties.setDescriptor(localName, localFunction);
JsExpression alias = JsAstUtils.pureFqn(localName, null);
aliases.put(localFunction, alias);
}
if (!aliases.isEmpty()) {
functionBodyContext = functionBodyContext.innerContextWithDescriptorsAliased(aliases);
}
return (new FunctionBodyTranslator(descriptor, declarationWithBody, functionBodyContext)).translate();
}
Aggregations