private XElement CreateInParamElement(InParameter param) { return(new XElement("inParam", new XAttribute("name", param.Name ?? string.Empty), new XAttribute("type", param.Type.Name), new XAttribute("optional", param.IsOptional), new XElement("description", param.Description) )); }
private static Method CreateMethod(MoaiClass moaiClass, Annotation[] annotations, MethodPosition methodPosition, TypeCollection types, WarningList warnings) { // Get @lua annotation var luaNameAnnotation = GetNameAnnotation(moaiClass, annotations, methodPosition, warnings); if (luaNameAnnotation == null) { return(null); } // Check that there is a single @text annotation CheckTextAnnotation(annotations, methodPosition, warnings); // Parse annotations var method = new Method { MethodPosition = methodPosition, Name = luaNameAnnotation.Value, OwningClass = moaiClass, }; moaiClass.Members.Add(method); MethodOverload currentOverload = null; foreach (var annotation in annotations) { if (annotation is LuaNameAnnotation) { // Nothing to do - name has already been set. } else if (annotation is TextAnnotation) { // Set method description method.Description = ((TextAnnotation)annotation).Value; } else if (annotation is ParameterAnnotation) { if (currentOverload == null) { currentOverload = new MethodOverload { OwningMethod = method }; method.Overloads.Add(currentOverload); } var parameterAnnotation = (ParameterAnnotation)annotation; string paramName = parameterAnnotation.Name; if (annotation is InParameterAnnotation | annotation is OptionalInParameterAnnotation) { // Add input parameter if (currentOverload.InParameters.Any(param => param.Name == paramName)) { warnings.Add(methodPosition, WarningType.UnexpectedValue, "Found multiple params with name '{0}' for single overload.", paramName); } var inParameter = new InParameter { Name = paramName, Description = parameterAnnotation.Description, Type = types.GetOrCreate(parameterAnnotation.Type, methodPosition), IsOptional = annotation is OptionalInParameterAnnotation }; currentOverload.InParameters.Add(inParameter); } else { // Add output parameter var outParameter = new OutParameter { Name = paramName, Type = types.GetOrCreate(parameterAnnotation.Type, methodPosition), Description = parameterAnnotation.Description }; currentOverload.OutParameters.Add(outParameter); } } else if (annotation is OverloadAnnotation) { // Let the next parameter annotation start a new override currentOverload = null; } else { warnings.Add(methodPosition, WarningType.UnexpectedAnnotation, "Unexpected {0} annotation.", annotation.Command); } } return(method); }