void FindsProperty(string code, Func <ClassDeclaration, bool> classFinder, Func <PropertyDeclaration, bool> propFinder) { CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind"); var errors = new ErrorHandling(); ModuleInventory mi = ModuleInventory.FromFile(Path.Combine(compiler.DirectoryPath, "libCanFind.dylib"), errors); ModuleDeclaration mod = compiler.ReflectToModules(new string [] { compiler.DirectoryPath }, new string [] { compiler.DirectoryPath }, null, "CanFind") [0]; ClassDeclaration classDecl = mod.AllClasses.FirstOrDefault(classFinder); Assert.IsNotNull(classDecl, "null class"); PropertyDeclaration propDecl = classDecl.Members.OfType <PropertyDeclaration> ().FirstOrDefault(propFinder); Assert.IsNotNull(propDecl, "null property"); FunctionDeclaration getter = propDecl.GetGetter(); Assert.IsNotNull(getter, "null getter"); FunctionDeclaration setter = propDecl.GetSetter(); Assert.IsNotNull(setter, "null setter"); TLFunction tlgetter = XmlToTLFunctionMapper.ToTLFunction(getter, mi); Assert.IsNotNull(tlgetter, "null tlgetter"); TLFunction tlsetter = XmlToTLFunctionMapper.ToTLFunction(setter, mi); Assert.IsNotNull(tlsetter, "null tlsetter"); }
public void FindsPropertyGetterAndSetterFuncs() { string code = "public class Bar { public var x:Int = 0; }"; CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind"); ModuleDeclaration mod = compiler.ReflectToModules(new string [] { compiler.DirectoryPath }, new string [] { compiler.DirectoryPath }, null, "CanFind") [0]; ClassDeclaration classDecl = mod.AllClasses.FirstOrDefault(cl => cl.Name == "Bar"); Assert.IsNotNull(classDecl); PropertyDeclaration propDecl = classDecl.Members.OfType <PropertyDeclaration> ().FirstOrDefault(p => p.Name == "x"); Assert.IsNotNull(propDecl); FunctionDeclaration getter = propDecl.GetGetter(); Assert.IsNotNull(getter); FunctionDeclaration setter = propDecl.GetSetter(); Assert.IsNotNull(setter); }
void CompileProp(PropertyDeclaration propDecl, ProtocolDeclaration proto, CSInterface iface, CSUsingPackages use) { var getter = propDecl.GetGetter(); var setter = propDecl.GetSetter(); var publicProp = topLevelFunctionCompiler.CompileProperty(use, null, getter, setter, CSMethodKind.None); publicProp = new CSProperty(publicProp.PropType, CSMethodKind.None, publicProp.Name, CSVisibility.None, new CSCodeBlock(), CSVisibility.None, setter != null ? new CSCodeBlock() : null); ExportAttribute(getter.ObjCSelector).AttachBefore(publicProp); if (!propDecl.IsOptional) { kAbstractAttribute.AttachBefore(publicProp); } iface.Properties.Add(publicProp); }
public static void Set_PropertyValue(this InstructionWriter instructionWriter, PropertyDeclaration propertyDeclaration, Action valueGetter) { instructionWriter.Get_This(); valueGetter(); instructionWriter.EmitInstructionMethod(OpCodeNumber.Call, propertyDeclaration.GetSetter()); }