@NotNull private static FunctionDescriptor standardFunction( ClassDescriptor classDescriptor, String name, Project project, KotlinType... parameterTypes) { ModuleDescriptorImpl emptyModule = KotlinTestUtils.createEmptyModule(); ContainerForTests container = InjectionKt.createContainerForTests(project, emptyModule); emptyModule.setDependencies(emptyModule); emptyModule.initialize(PackageFragmentProvider.Empty.INSTANCE); LexicalScopeImpl lexicalScope = new LexicalScopeImpl( ImportingScope.Empty.INSTANCE, classDescriptor, false, classDescriptor.getThisAsReceiverParameter(), LexicalScopeKind.SYNTHETIC); ExpressionTypingContext context = ExpressionTypingContext.newContext( new BindingTraceContext(), lexicalScope, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE); OverloadResolutionResults<FunctionDescriptor> functions = container .getFakeCallResolver() .resolveFakeCall( context, null, Name.identifier(name), null, null, FakeCallKind.OTHER, parameterTypes); for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) { List<ValueParameterDescriptor> unsubstitutedValueParameters = resolvedCall.getResultingDescriptor().getValueParameters(); for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) { ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i); if (unsubstitutedValueParameter.getType().equals(parameterTypes[i])) { return resolvedCall.getResultingDescriptor(); } } } throw new IllegalArgumentException( "Not found: kotlin::" + classDescriptor.getName() + "." + name + "(" + Arrays.toString(parameterTypes) + ")"); }
@NotNull @Override public String getText() { if (functionsToAdd.size() == 1) { FunctionDescriptor newFunction = functionsToAdd.get(0); ClassDescriptor supertype = (ClassDescriptor) newFunction.getContainingDeclaration(); return JetBundle.message( "add.function.to.type.action.single", IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.render(newFunction), supertype.getName().toString()); } else { return JetBundle.message("add.function.to.supertype.action.multiple"); } }