# Copyright (c) Meta Platforms, Inc. and affiliates. # common predicates between java and kotlin used for interopobility schema kotlin.alpha.2 { import javakotlin.alpha import src predicate DeclarationLocation : { file : src.File, span : src.ByteSpan } predicate Type : { type : javakotlin.alpha.Type, location : maybe DeclarationLocation, typeArgs: [TypeArg], isNullable: bool } predicate TypeArg: { type: Type } # A variable declaration predicate VariableDeclaration : { name: javakotlin.alpha.QName, type : Type, location : DeclarationLocation, } # A method declaration predicate MethodDeclaration : { name : javakotlin.alpha.MethodName, parameters : [VariableDeclaration], returnType : maybe Type, loc : src.Loc, # deprecated. unused location: maybe DeclarationLocation, container: maybe Declaration } predicate ClassDeclaration : { name : javakotlin.alpha.QName, implements_ : [javakotlin.alpha.QName], location : DeclarationLocation, } # Parent of variables that are methods. I.e. method contains the variable predicate VariableParent: { child: VariableDeclaration, parent: MethodDeclaration, } stored { Child, Parent } where Parent = MethodDeclaration { parameters = Ps }; Child = Ps[..]; # Inverse table of method members of classes predicate ClassMember: { parent: ClassDeclaration, child: MethodDeclaration } stored { Parent, Child } where Child = MethodDeclaration { container = { just = { class_ = Parent } } } # The type of Kotlin symbol entities type Declaration = { class_ : ClassDeclaration | method : MethodDeclaration | variable : VariableDeclaration | } # # Re-indexing by file for codemarkup use # predicate FileDeclarations: { file: src.File, decl: Declaration } stored { File, Decl } where ( CDecl = ClassDeclaration { location = Loc }; { class_ = CDecl } = Decl; ) | ( VDecl = VariableDeclaration { location = Loc }; { variable = VDecl } = Decl; ) | ( MDecl = MethodDeclaration { location = { just = Loc } }; { method = MDecl } = Decl; ); { file = File } = Loc; predicate DeclarationFileLocation: { decl: Declaration, file: src.File, span: src.ByteSpan, name: string, } { Decl, File, Span, NameStr } where ( { class_ = CDecl } = Decl; ClassDeclaration { location = Location, name = QName } = CDecl; ) | ( { variable = VDecl } = Decl; VariableDeclaration { location = Location, name = QName } = VDecl; ) | ( { method = MDecl } = Decl; MethodDeclaration { location = { just = Location }, name = MName} = MDecl; { name = QName } = MName; ); { File, Span } = Location; { name = javakotlin.alpha.Name NameStr } = QName # entity relationships # Container parent (by scope) predicate ParentDeclaration: { child: Declaration, parent: Declaration } { Child, Parent } where ( { method = MDecl } = Child; { container = { just = Parent } } = MDecl ) | ( { variable = VDecl } = Child; VariableParent { VDecl, MDecl }; { method = MDecl } = Parent ) # Inverse relationship: parent contains child (e.g. class -> method) predicate ContainsDeclaration: { parent: Declaration, child: Declaration } { Parent, Child } where ( { method = MDecl } = Parent; { parameters = VDecls } = MDecl; VDecl = VDecls[..]; { variable = VDecl } = Child ) | ( { class_ = CDecl } = Parent; ClassMember { CDecl, MDecl }; { method = MDecl } = Child ) # extends parent (classes `implement` interfaces, but we don't have # InterfaceDecls currently). So this isn't very useful yet predicate ExtendsDeclaration: { child: Declaration, parent: Declaration } { Child, Parent } where { class_ = CDecl } = Child; { implements_ = QNames } = CDecl; QName = QNames[..]; PDecl = ClassDeclaration { name = QName }; # don't think this matches { class_ = PDecl } = Parent }