Search in sources :

Example 1 with SimpleFunctionDescriptor

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);
    }
}
Also used : PropertyDescriptor(org.jetbrains.kotlin.descriptors.PropertyDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType) SimpleFunctionDescriptor(org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor) Map(java.util.Map)

Example 2 with SimpleFunctionDescriptor

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;
        }
    });
}
Also used : JvmSerializerExtension(org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension) TypeAliasDescriptor(org.jetbrains.kotlin.descriptors.TypeAliasDescriptor) ArrayList(java.util.ArrayList) VariableDescriptor(org.jetbrains.kotlin.descriptors.VariableDescriptor) Unit(kotlin.Unit) ProtoBuf(org.jetbrains.kotlin.serialization.ProtoBuf) DescriptorSerializer(org.jetbrains.kotlin.serialization.DescriptorSerializer) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) AnnotationVisitor(org.jetbrains.org.objectweb.asm.AnnotationVisitor) SimpleFunctionDescriptor(org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor)

Example 3 with SimpleFunctionDescriptor

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);
}
Also used : NameSuggestion(org.jetbrains.kotlin.js.naming.NameSuggestion) SimpleFunctionDescriptor(org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor) SuggestedName(org.jetbrains.kotlin.js.naming.SuggestedName) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with SimpleFunctionDescriptor

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);
}
Also used : ModuleDescriptor(org.jetbrains.kotlin.descriptors.ModuleDescriptor) SimpleFunctionDescriptor(org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor) KtFile(org.jetbrains.kotlin.psi.KtFile) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) SimpleFunctionDescriptor(org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor)

Aggregations

SimpleFunctionDescriptor (org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor)4 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Unit (kotlin.Unit)1 NotNull (org.jetbrains.annotations.NotNull)1 JvmSerializerExtension (org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)1 PropertyDescriptor (org.jetbrains.kotlin.descriptors.PropertyDescriptor)1 TypeAliasDescriptor (org.jetbrains.kotlin.descriptors.TypeAliasDescriptor)1 VariableDescriptor (org.jetbrains.kotlin.descriptors.VariableDescriptor)1 NameSuggestion (org.jetbrains.kotlin.js.naming.NameSuggestion)1 SuggestedName (org.jetbrains.kotlin.js.naming.SuggestedName)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 DescriptorSerializer (org.jetbrains.kotlin.serialization.DescriptorSerializer)1 ProtoBuf (org.jetbrains.kotlin.serialization.ProtoBuf)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 AnnotationVisitor (org.jetbrains.org.objectweb.asm.AnnotationVisitor)1