Beispiel #1
0
        public static List <BaijiField> BuildFields(ParseTreeNode fieldNodes, string structName)
        {
            var fields = new List <BaijiField>();

            foreach (var fieldNode in fieldNodes.ChildNodes)
            {
                string[]           docStringLines = null;
                string             fieldName      = null;
                Required           fieldReq       = Required.NONE;
                BaijiType          fieldType      = null;
                IList <Annotation> annotations    = null;
                foreach (var fieldChildNode in fieldNode.ChildNodes)
                {
                    if (fieldChildNode.Term.Name == IdlGrammar.NTNAME_TDOCSTRINGOREMPTY &&
                        fieldChildNode.ChildNodes.Count > 0)
                    {
                        docStringLines = ParseDocStringLines(fieldChildNode.ChildNodes[0].FindTokenAndGetText());
                    }
                    else if (fieldChildNode.Term.Name == IdlGrammar.NTNAME_FIELD_REQ &&
                             fieldChildNode.ChildNodes.Count > 0)
                    {
                        var fieldReqText = fieldChildNode.ChildNodes[0].FindTokenAndGetText();
                        if (fieldReqText == "required")
                        {
                            fieldReq = Required.REQUIRED;
                        }
                        else if (fieldReqText == "optional")
                        {
                            fieldReq = Required.OPTIONAL;
                        }
                        else
                        {
                            fieldReq = Required.NONE;
                        }
                    }
                    else if (fieldChildNode.Term.Name == IdlGrammar.NTNAME_TFIELD_TYPE)
                    {
                        fieldType = BuildFieldType(fieldChildNode);
                    }
                    else if (fieldChildNode.Term.Name == IdlGrammar.TNAME_TIDENTIFIER)
                    {
                        fieldName = fieldChildNode.Token.Text;
                    }
                    else if (fieldChildNode.Term.Name == IdlGrammar.NTNAME_TANNOTATIONSOREMPTY &&
                             fieldChildNode.ChildNodes.Count > 0)
                    {
                        annotations = BuildAnnotations(fieldChildNode.ChildNodes);
                    }
                }

                var field = new BaijiField(docStringLines, fieldName, fieldType, fieldReq, annotations);
                fields.Add(field);
            }

            return(fields);
        }
        public virtual FieldContext FieldFromIdl(BaijiField field)
        {
            var context = new FieldContext(field.DocStringLines,
                                           field.Name,
                                           _typeMangler.MangleFieldName(field.Name),
                                           field.Required == Required.REQUIRED,
                                           _typeConverter.ConvertToGenType(field.Type));

            return(context);
        }
        public override FieldContext FieldFromIdl(BaijiField field)
        {
            var fc = new OCFieldContext(field.DocStringLines,
                                        field.Name,
                                        _typeMangler.MangleMethodName(field.Name),
                                        field.Required == Required.REQUIRED,
                                        _typeConverter.ConvertToGenType(field.Type));

            return(fc);
        }
Beispiel #4
0
 public void Visit(BaijiField field)
 {
     AppendDocStringLines(field.DocStringLines);
     if (field.Required != Required.NONE)
     {
         sb.Append(field.Required.ToString().ToLower()).Append(" ");
     }
     VisitType(field.Type);
     sb.Append(" ").Append(field.Name).Append(" ");
 }
        public FieldContext FieldFromTrip(BaijiField field)
        {
            var fc = new FieldContext(
                field.DocStringLines,
                field.Name,
                (short)field.Identifier,
                //typeConverter.ConvertToString(field.Type),
                MangleCSharpFieldName(field.Name),
                MangleCSharpTypeName(field.Name),
                field.Required == Required.REQUIRED,
                typeConverter.ConvertToGenType(field.Type)
                );

            return(fc);
        }
Beispiel #6
0
        public FieldContext FieldFromLean(BaijiField field)
        {
            var fc = new FieldContext(field.DocStringLines,
                                      field.Name,
                                      (short)field.Identifier,
                                      //typeConverter.ConvertToString(field.Type),
                                      MangleJavaMethodName(field.Name),
                                      SetterName(field),
                                      GetterName(field),
                                      field.Required == Required.REQUIRED,
                                      typeConverter.ConvertToGenType(field.Type)
                                      );

            return(fc);
        }
Beispiel #7
0
        public void Visit(Struct _struct)
        {
            var structContext = contextGenerator.StructFromTrip(_struct);

            BaijiField responseStatusField = null;

            foreach (var field in _struct.Fields)
            {
                if (field.Name == "responseStatus" || field.Name == "ResponseStatus")
                {
                    responseStatusField = field;
                }
                structContext.AddField(contextGenerator.FieldFromTrip(field));
            }

            if (_struct.IsServiceResponse)
            {
                if (responseStatusField == null)
                {
                    var message = string.Format("{0} must have a responseStatus field in order to be used as a service response.",
                                                _struct.Name);
                    throw new ArgumentException(message);
                }
                var fieldType       = responseStatusField.Type as IdentifierType;
                var lastTypeSegment = fieldType != null?fieldType.Name.Split('.').Last() : null;

                if (lastTypeSegment != "ResponseStatusType")
                {
                    var message = string.Format("The type of {0} field in {1} must be ResponseStatusType.",
                                                responseStatusField.Name, _struct.Name);
                    throw new ArgumentException(message);
                }
            }


            Render(structContext, "struct");
        }
Beispiel #8
0
 public void Visit(BaijiField field)
 {
     throw new NotImplementedException();
 }
Beispiel #9
0
 public void Visit(BaijiField field)
 {
     throw new NotSupportedException();
 }
Beispiel #10
0
 private string SetterName(BaijiField field)
 {
     return("set" + MangleJavaTypeName(field.Name));
 }
Beispiel #11
0
        private string GetterName(BaijiField field)
        {
            string type = typeConverter.ConvertToString(field.Type);

            return(("Boolean".Equals(type) ? "is" : "get") + MangleJavaTypeName(field.Name));
        }
Beispiel #12
0
 private string SetterName(BaijiField field)
 {
     return("set" + _typeMangler.MangleTypeName(field.Name));
 }