public static NSObjectTypeInfo ParseHeader (string headerFile) { string text = File.ReadAllText (headerFile); string userType = null, userBaseType = null; MatchCollection matches; NSObjectTypeInfo type; // First, grep for classes matches = typeInfoRegex.Matches (text); foreach (Match match in matches) { if (match.Groups[1].Value != "interface") continue; if (userType != null) { // UNSUPPORTED: more than 1 user-type defined in this header return null; } userType = match.Groups[2].Value; userBaseType = match.Groups[3].Value; } if (userType == null) return null; type = new NSObjectTypeInfo (userType, null, userBaseType, null, false, true, true); // Now grep for IBActions and IBOutlets matches = ibRegex.Matches (text); foreach (Match match in matches) { var kind = match.Groups[1].Value; var def = match.Groups[2].Value; if (kind == "IBOutlet") { var split = def.Split (whitespaceChars, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) continue; string objcName = split[1].TrimStart ('*'); string objcType = split[0].TrimEnd ('*'); if (objcType == "id") objcType = "NSObject"; if (string.IsNullOrEmpty (objcType)) { MessageService.ShowError (GettextCatalog.GetString ("Error while parsing header file."), string.Format (GettextCatalog.GetString ("The definition '{0}' can't be parsed."), def)); objcType = "NSObject"; } IBOutlet outlet = new IBOutlet (objcName, objcName, objcType, null); outlet.IsDesigner = true; type.Outlets.Add (outlet); } else { string[] split = def.Split (colonChar); string name = split[0].Trim (); var action = new IBAction (name, name); action.IsDesigner = true; string label = null; for (int i = 1; i < split.Length; i++) { var s = split[i].Split (splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries); string objcType = s[0]; if (objcType == "id") objcType = "NSObject"; var par = new IBActionParameter (label, s[1], objcType, null); label = s.Length == 3? s[2] : null; action.Parameters.Add (par); } type.Actions.Add (action); } } return type; }
public static NSObjectTypeInfo ParseHeader(string headerFile) { string text = File.ReadAllText(headerFile); string userType = null, userBaseType = null; MatchCollection matches; NSObjectTypeInfo type; // First, grep for classes matches = typeInfoRegex.Matches(text); foreach (Match match in matches) { if (match.Groups[1].Value != "interface") { continue; } if (userType != null) { // UNSUPPORTED: more than 1 user-type defined in this header return(null); } userType = match.Groups[2].Value; userBaseType = match.Groups[3].Value; } if (userType == null) { return(null); } type = new NSObjectTypeInfo(userType, null, userBaseType, null, false, true, true); // Now grep for IBActions and IBOutlets matches = ibRegex.Matches(text); foreach (Match match in matches) { var kind = match.Groups[1].Value; var def = match.Groups[2].Value; if (kind == "IBOutlet") { var split = def.Split(whitespaceChars, StringSplitOptions.RemoveEmptyEntries); string objcType = split[0].TrimEnd('*'); string objcName = null; for (int i = 1; i < split.Length; i++) { objcName = split[i].TrimStart('*'); if (string.IsNullOrEmpty(objcName)) { continue; } if (i + 1 < split.Length) { // This is a bad sign... what tokens are after the name?? objcName = null; break; } } if (string.IsNullOrEmpty(objcType) || string.IsNullOrEmpty(objcName)) { MessageService.ShowError(GettextCatalog.GetString("Error while parsing header file."), string.Format(GettextCatalog.GetString("The definition '{0}' can't be parsed."), def)); // We can't recover if objcName is empty... if (string.IsNullOrEmpty(objcName)) { continue; } // We can try using NSObject... objcType = "NSObject"; } if (objcType == "id") { objcType = "NSObject"; } IBOutlet outlet = new IBOutlet(objcName, objcName, objcType, null); outlet.IsDesigner = true; type.Outlets.Add(outlet); } else { string[] split = def.Split(colonChar); string name = split[0].Trim(); var action = new IBAction(name, name); action.IsDesigner = true; string label = null; for (int i = 1; i < split.Length; i++) { var s = split[i].Split(splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries); string objcType = s[0]; if (objcType == "id") { objcType = "NSObject"; } var par = new IBActionParameter(label, s[1], objcType, null); label = s.Length == 3? s[2] : null; action.Parameters.Add(par); } type.Actions.Add(action); } } return(type); }
void UpdateTypeMembers (ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear (); info.Outlets.Clear (); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { bool isIBOutlet = att.AttributeType.FullName == iboutletAttType.FullName; if (!isIBOutlet) { if (att.AttributeType.FullName != connectAttType.FullName) continue; } string name = null; if (att.PositionalArguments.Count == 1) name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (string.IsNullOrEmpty (name)) name = prop.Name; // HACK: Work around bug #1586 in the least obtrusive way possible. Strip out any outlet // with the name 'view' on subclasses of MonoTouch.UIKit.UIViewController to avoid // conflicts with the view property mapped there if (name == "view") if (dom.GetInheritanceTree (type).Any (p => p.FullName == "MonoTouch.UIKit.UIViewController")) continue; var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.FullName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (prop.DeclaringType.CompilationUnit.FileName)) ol.IsDesigner = true; info.Outlets.Add (ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { bool isIBAction = att.AttributeType.FullName == ibactionAttType.FullName; if (!isIBAction) { if (att.AttributeType.FullName != exportAttType.FullName) continue; } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile ( meth.DeclaringType.CompilationUnit.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) continue; string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (!string.IsNullOrEmpty (n)) name = n.Split (colonChar); } var action = new IBAction (name != null? name [0] : meth.Name, meth.Name); int i = 1; foreach (var param in meth.Parameters) { string label = name != null && i < name.Length? name[i] : null; if (label != null && label.Length == 0) label = null; action.Parameters.Add (new IBActionParameter (label, param.Name, null, param.ReturnType.FullName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (meth.DeclaringType.CompilationUnit.FileName)) action.IsDesigner = true; info.Actions.Add (action); break; } } }
void UpdateTypeMembers(TypeSystemService.ProjectContentWrapper dom, NSObjectTypeInfo info, ITypeDefinition type) { info.Actions.Clear(); info.Outlets.Clear(); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { var attType = att.AttributeType; bool isIBOutlet = attType.Equals(Resolve(dom, iboutletAttType)); if (!isIBOutlet) { if (!attType.Equals(Resolve(dom, connectAttType))) { continue; } } string name = null; var posArgs = att.PositionalArguments; if (posArgs.Count == 1) { name = posArgs [0].ConstantValue as string; } if (string.IsNullOrEmpty(name)) { name = prop.Name; } // HACK: Work around bug #1586 in the least obtrusive way possible. Strip out any outlet // with the name 'view' on subclasses of MonoTouch.UIKit.UIViewController to avoid // conflicts with the view property mapped there if (name == "view") { if (type.GetAllBaseTypeDefinitions().Any(p => p.ReflectionName == "MonoTouch.UIKit.UIViewController")) { continue; } } var ol = new IBOutlet(name, prop.Name, null, prop.ReturnType.ReflectionName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(prop.Region.FileName)) { ol.IsDesigner = true; } info.Outlets.Add(ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { var attType = att.AttributeType; bool isIBAction = attType.Equals(Resolve(dom, ibactionAttType)); if (!isIBAction) { if (!attType.Equals(Resolve(dom, exportAttType))) { continue; } } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(meth.Region.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) { continue; } string[] name = null; var posArgs = att.PositionalArguments; if (posArgs.Count == 1 || posArgs.Count == 2) { var n = posArgs [0].ConstantValue as string; if (!string.IsNullOrEmpty(n)) { name = n.Split(colonChar); } } var action = new IBAction(name != null ? name [0] : meth.Name, meth.Name); int i = 1; foreach (var param in meth.Parameters) { string label = name != null && i < name.Length ? name [i] : null; if (label != null && label.Length == 0) { label = null; } action.Parameters.Add(new IBActionParameter(label, param.Name, null, param.Type.ReflectionName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(meth.Region.FileName)) { action.IsDesigner = true; } info.Actions.Add(action); break; } } }
void UpdateTypeMembers (ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear (); info.Outlets.Clear (); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { bool isIBOutlet = att.AttributeType.FullName == iboutletAttType.FullName; if (!isIBOutlet) { if (att.AttributeType.FullName != connectAttType.FullName) continue; } string name = null; if (att.PositionalArguments.Count == 1) name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (string.IsNullOrEmpty (name)) name = prop.Name; var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.FullName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (prop.DeclaringType.CompilationUnit.FileName)) ol.IsDesigner = true; info.Outlets.Add (ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { bool isIBAction = att.AttributeType.FullName == ibactionAttType.FullName; if (!isIBAction) { if (att.AttributeType.FullName != exportAttType.FullName) continue; } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile ( meth.DeclaringType.CompilationUnit.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) continue; string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (!string.IsNullOrEmpty (n)) name = n.Split (colonChar); } var action = new IBAction (name != null? name [0] : meth.Name, meth.Name); int i = 1; foreach (var param in meth.Parameters) { string label = name != null && i < name.Length? name[i] : null; if (label != null && label.Length == 0) label = null; action.Parameters.Add (new IBActionParameter (label, param.Name, null, param.ReturnType.FullName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (meth.DeclaringType.CompilationUnit.FileName)) action.IsDesigner = true; info.Actions.Add (action); break; } } }
void UpdateTypeMembers (TypeSystemService.ProjectContentWrapper dom, NSObjectTypeInfo info, ITypeDefinition type) { info.Actions.Clear (); info.Outlets.Clear (); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { var attType = att.AttributeType; bool isIBOutlet = attType.Equals (Resolve (dom, iboutletAttType)); if (!isIBOutlet) { if (!attType.Equals (Resolve (dom, connectAttType))) continue; } string name = null; var posArgs = att.PositionalArguments; if (posArgs.Count == 1) name = posArgs [0].ConstantValue as string; if (string.IsNullOrEmpty (name)) name = prop.Name; // HACK: Work around bug #1586 in the least obtrusive way possible. Strip out any outlet // with the name 'view' on subclasses of MonoTouch.UIKit.UIViewController to avoid // conflicts with the view property mapped there if (name == "view") { if (type.GetAllBaseTypeDefinitions ().Any (p => p.ReflectionName == "MonoTouch.UIKit.UIViewController")) continue; } var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.ReflectionName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (prop.Region.FileName)) ol.IsDesigner = true; info.Outlets.Add (ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { var attType = att.AttributeType; bool isIBAction = attType.Equals (Resolve (dom, ibactionAttType)); if (!isIBAction) { if (!attType.Equals (Resolve (dom, exportAttType))) continue; } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile ( meth.DeclaringTypeDefinition.Region.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) continue; string[] name = null; var posArgs = att.PositionalArguments; if (posArgs.Count == 1 || posArgs.Count == 2) { var n = posArgs [0].ConstantValue as string; if (!string.IsNullOrEmpty (n)) name = n.Split (colonChar); } var action = new IBAction (name != null ? name [0] : meth.Name, meth.Name); int i = 1; foreach (var param in meth.Parameters) { string label = name != null && i < name.Length ? name [i] : null; if (label != null && label.Length == 0) label = null; action.Parameters.Add (new IBActionParameter (label, param.Name, null, param.Type.ReflectionName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (meth.Region.FileName)) action.IsDesigner = true; info.Actions.Add (action); break; } } }
static void UpdateTypeMembers(ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear(); info.Outlets.Clear(); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { if (att.AttributeType.FullName != connectAttType.FullName) { continue; } string name = null; if (att.PositionalArguments.Count == 1) { name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; } if (string.IsNullOrEmpty(name)) { name = prop.Name; } var ol = new IBOutlet(name, prop.Name, null, prop.ReturnType.FullName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(prop.DeclaringType.CompilationUnit.FileName)) { ol.IsDesigner = true; } info.Outlets.Add(ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { if (att.AttributeType.FullName != exportAttType.FullName) { continue; } string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (!string.IsNullOrEmpty(n)) { name = n.Split(colonChar); } } var action = new IBAction(name != null? name [0] : meth.Name, meth.Name); int i = 1; foreach (var param in meth.Parameters) { string label = name != null && i < name.Length? name[i] : null; if (label != null && label.Length == 0) { label = null; } action.Parameters.Add(new IBActionParameter(label, param.Name, null, param.ReturnType.FullName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(meth.DeclaringType.CompilationUnit.FileName)) { action.IsDesigner = true; } info.Actions.Add(action); break; } } }
void UpdateTypeMembers(ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear(); info.Outlets.Clear(); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { bool isIBOutlet = att.AttributeType.FullName == iboutletAttType.FullName; if (!isIBOutlet) { if (att.AttributeType.FullName != connectAttType.FullName) { continue; } } string name = null; if (att.PositionalArguments.Count == 1) { name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; } if (string.IsNullOrEmpty(name)) { name = prop.Name; } // HACK: Work around bug #1586 in the least obtrusive way possible. Strip out any outlet // with the name 'view' on subclasses of MonoTouch.UIKit.UIViewController to avoid // conflicts with the view property mapped there if (name == "view") { if (dom.GetInheritanceTree(type).Any(p => p.FullName == "MonoTouch.UIKit.UIViewController")) { continue; } } var ol = new IBOutlet(name, prop.Name, null, prop.ReturnType.FullName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(prop.DeclaringType.CompilationUnit.FileName)) { ol.IsDesigner = true; } info.Outlets.Add(ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { bool isIBAction = att.AttributeType.FullName == ibactionAttType.FullName; if (!isIBAction) { if (att.AttributeType.FullName != exportAttType.FullName) { continue; } } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile( meth.DeclaringType.CompilationUnit.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) { continue; } string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (!string.IsNullOrEmpty(n)) { name = n.Split(colonChar); } } var action = new IBAction(name != null? name [0] : meth.Name, meth.Name); int i = 1; foreach (var param in meth.Parameters) { string label = name != null && i < name.Length? name[i] : null; if (label != null && label.Length == 0) { label = null; } action.Parameters.Add(new IBActionParameter(label, param.Name, null, param.ReturnType.FullName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(meth.DeclaringType.CompilationUnit.FileName)) { action.IsDesigner = true; } info.Actions.Add(action); break; } } }