use of org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor in project kotlin by JetBrains.
the class ControlFlowAnalyzer method process.
public void process(@NotNull BodiesResolveContext c) {
for (KtFile file : c.getFiles()) {
checkDeclarationContainer(c, file);
}
for (KtClassOrObject aClass : c.getDeclaredClasses().keySet()) {
checkDeclarationContainer(c, aClass);
}
for (KtScript script : c.getScripts().keySet()) {
checkDeclarationContainer(c, script);
}
for (KtSecondaryConstructor constructor : c.getSecondaryConstructors().keySet()) {
checkSecondaryConstructor(constructor);
}
for (Map.Entry<KtNamedFunction, SimpleFunctionDescriptor> entry : c.getFunctions().entrySet()) {
KtNamedFunction function = entry.getKey();
SimpleFunctionDescriptor functionDescriptor = entry.getValue();
KotlinType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType() ? NO_EXPECTED_TYPE : functionDescriptor.getReturnType();
checkFunction(c, function, expectedReturnType);
}
for (Map.Entry<KtProperty, PropertyDescriptor> entry : c.getProperties().entrySet()) {
KtProperty property = entry.getKey();
PropertyDescriptor propertyDescriptor = entry.getValue();
checkProperty(c, property, propertyDescriptor);
}
}
use of org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor in project kotlin by JetBrains.
the class PackagePartCodegen method generateKotlinMetadataAnnotation.
@Override
protected void generateKotlinMetadataAnnotation() {
List<DeclarationDescriptor> members = new ArrayList<DeclarationDescriptor>();
for (KtDeclaration declaration : element.getDeclarations()) {
if (declaration instanceof KtNamedFunction) {
SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
members.add(functionDescriptor);
} else if (declaration instanceof KtProperty) {
VariableDescriptor property = bindingContext.get(BindingContext.VARIABLE, declaration);
members.add(property);
} else if (declaration instanceof KtTypeAlias) {
TypeAliasDescriptor typeAlias = bindingContext.get(BindingContext.TYPE_ALIAS, declaration);
members.add(typeAlias);
}
}
final DescriptorSerializer serializer = DescriptorSerializer.createTopLevel(new JvmSerializerExtension(v.getSerializationBindings(), state));
final ProtoBuf.Package packageProto = serializer.packagePartProto(element.getPackageFqName(), members).build();
WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.FILE_FACADE, 0, new Function1<AnnotationVisitor, Unit>() {
@Override
public Unit invoke(AnnotationVisitor av) {
writeAnnotationData(av, serializer, packageProto);
return Unit.INSTANCE;
}
});
}
use of org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor in project kotlin by JetBrains.
the class Namer method getStableMangledNameForDescriptor.
// TODO: get rid of this function
@NotNull
public static String getStableMangledNameForDescriptor(@NotNull ClassDescriptor descriptor, @NotNull String functionName) {
Collection<SimpleFunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getContributedFunctions(Name.identifier(functionName), NoLookupLocation.FROM_BACKEND);
assert functions.size() == 1 : "Can't select a single function: " + functionName + " in " + descriptor;
SuggestedName suggested = new NameSuggestion().suggest(functions.iterator().next());
assert suggested != null : "Suggested name for class members is always non-null: " + functions.iterator().next();
return suggested.getNames().get(0);
}
use of org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor in project kotlin by JetBrains.
the class BoundsSubstitutorTest method doTest.
//public void testWithWhereTwoBoundsLoop() throws Exception {
// doTest("fun <T, R> f(l: List<R>): R where T : R, R : T",
// "");
//}
private void doTest(String text, String expected) {
KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("fun.kt", text);
ModuleDescriptor module = JvmResolveUtil.analyze(ktFile, getEnvironment()).getModuleDescriptor();
Collection<SimpleFunctionDescriptor> functions = module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST);
FunctionDescriptor substituted = BoundsSubstitutor.substituteBounds(CollectionsKt.single(functions));
String actual = DescriptorRenderer.COMPACT.render(substituted);
assertEquals(expected, actual);
}
Aggregations