internal static void Load(this JavaTypeParameters tps, XmlReader reader) { reader.MoveToContent(); if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); do { reader.MoveToContent(); if (reader.NodeType == XmlNodeType.EndElement) { break; // </typeParameters> } if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "typeParameter") { throw XmlUtil.UnexpectedElementOrContent("typeParameters", reader, "typeParameter"); } var tp = new JavaTypeParameter(tps); tp.Load(reader); tps.TypeParameters.Add(tp); } while (true); XmlUtil.VerifyEndElement(reader, "typeParameters"); reader.Read(); } }
static void ResolveMethodBase(this JavaMethodBase m, JavaTypeParameters methodTypeParameters) { foreach (var p in m.Parameters) { p.ResolvedType = m.GetApi().Parse(p.Type, m.Parent.TypeParameters, methodTypeParameters); } }
internal static bool TryLoadCommonElement(this JavaType type, XmlReader reader) { if (reader.LocalName == "implements") { var implements = new JavaImplements(); implements.Load(reader); type.Implements.Add(implements); } else if (reader.LocalName == "typeParameters") { var tp = new JavaTypeParameters(type); tp.Load(reader); type.TypeParameters = tp; } else if (reader.LocalName == "field") { var field = new JavaField(type); field.Load(reader); type.Members.Add(field); } else if (reader.LocalName == "method") { var method = new JavaMethod(type); method.Load(reader); type.Members.Add(method); } else { return(false); } return(true); }
static void LoadMethodBase(this JavaMethodBase methodBase, string elementName, XmlReader reader) { var method = methodBase as JavaMethod; // kind of ugly hack yeah... methodBase.LoadMemberAttributes(reader); //methodBase.ExtendedJniSignature = reader.GetAttribute ("jni-signature"); methodBase.ExtendedJniReturn = reader.GetAttribute("jni-return"); methodBase.ExtendedSynthetic = XmlConvert.ToBoolean(reader.GetAttribute("synthetic") ?? "false"); methodBase.ExtendedBridge = XmlConvert.ToBoolean(reader.GetAttribute("bridge") ?? "false"); reader.MoveToElement(); if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); do { reader.MoveToContent(); if (reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.NodeType != XmlNodeType.Element) { throw XmlUtil.UnexpectedElementOrContent(elementName, reader, "parameter"); } if (reader.LocalName == "typeParameters") { var tp = new JavaTypeParameters(methodBase); tp.Load(reader); methodBase.TypeParameters = tp; } else if (reader.LocalName == "parameter") { var p = new JavaParameter(methodBase); p.Load(reader); methodBase.Parameters.Add(p); } else if (reader.LocalName == "exception") { var p = new JavaException(); p.Load(reader); methodBase.Exceptions.Add(p); } else { throw XmlUtil.UnexpectedElementOrContent(elementName, reader, "parameter"); } } while (true); XmlUtil.VerifyEndElement(reader, elementName); reader.Read(); } }
// Content of this value is not stable. public string ToStringHelper(string returnType, string name, JavaTypeParameters typeParameters) { return(string.Format("{0}{1}{2}{3}{4}{5}({6})", returnType, returnType == null ? null : " ", Name, typeParameters == null ? null : "<", typeParameters == null ? null : string.Join(", ", typeParameters.TypeParameters), typeParameters == null ? null : ">", string.Join(", ", Parameters))); }
static void Save(this JavaTypeParameters typeParameters, XmlWriter writer, string indent) { writer.WriteStartElement("typeParameters"); foreach (var tp in typeParameters.TypeParameters) { writer.WriteStartElement("typeParameter"); writer.WriteAttributeString("name", tp.Name); if (!string.IsNullOrEmpty(tp.ExtendedClassBound)) { writer.WriteAttributeString("classBound", tp.ExtendedClassBound); } if (!string.IsNullOrEmpty(tp.ExtendedJniClassBound)) { writer.WriteAttributeString("jni-classBound", tp.ExtendedJniClassBound); } if (!string.IsNullOrEmpty(tp.ExtendedInterfaceBounds)) { writer.WriteAttributeString("interfaceBounds", tp.ExtendedInterfaceBounds); } if (!string.IsNullOrEmpty(tp.ExtendedJniInterfaceBounds)) { writer.WriteAttributeString("jni-interfaceBounds", tp.ExtendedJniInterfaceBounds); } if (tp.GenericConstraints != null) { // If there is only one generic constraint that specifies java.lang.Object, // that is not really a constraint, so skip that. // jar2xml does not emit that either. var gcs = tp.GenericConstraints.GenericConstraints; var gctr = gcs.Count == 1 ? gcs [0].ResolvedType : null; if (gctr == null || gctr.ReferencedType.FullName != "java.lang.Object") { writer.WriteStartElement("genericConstraints"); foreach (var g in tp.GenericConstraints.GenericConstraints) { writer.WriteStartElement("genericConstraint"); writer.WriteAttributeString("type", g.Type); writer.WriteString("\n" + indent + " "); writer.WriteFullEndElement(); } writer.WriteFullEndElement(); } } else { writer.WriteString("\n" + indent + " "); } writer.WriteFullEndElement(); } writer.WriteString("\n" + indent); writer.WriteFullEndElement(); }
static void Resolve(this JavaTypeParameters tp, JavaApi api, params JavaTypeParameters [] additionalTypeParameters) { foreach (var t in tp.TypeParameters) { if (t.GenericConstraints != null) { foreach (var g in t.GenericConstraints.GenericConstraints) { try { g.ResolvedType = api.Parse(g.Type, additionalTypeParameters); } catch (JavaTypeResolutionException ex) { Log.LogWarning("Warning: failed to resolve generic constraint: '{0}': {1}", g.Type, ex.Message); } } } } }
static void Load(this JavaTypeParameters tps, GenericParameterDefinitionList gtps) { foreach (var stp in gtps) { var tp = new JavaTypeParameter(tps) { Name = stp.Name, }; if (stp.Constraints != null) { tp.GenericConstraints = new JavaGenericConstraints() { BoundsType = stp.Name, GenericConstraints = stp.Constraints.Select(_ => new JavaGenericConstraint() { Type = _.JavaName }).ToArray() } } ; tps.TypeParameters.Add(tp); } } }
public JavaTypeParameter(JavaTypeParameters parent) { Parent = parent; }
static void SaveCommon(this JavaMember m, XmlWriter writer, string elementName, string abs, string native, string ret, string sync, string transient, string type, string typeGeneric, string value, string volat, JavaTypeParameters typeParameters, IEnumerable <JavaParameter> parameters, IEnumerable <JavaException> exceptions, bool?extBridge, string jniReturn, bool?extSynthetic) { // If any of the parameters contain reference to non-public type, it cannot be generated. if (parameters != null && parameters.Any(p => p.ResolvedType.ReferencedType != null && string.IsNullOrEmpty(p.ResolvedType.ReferencedType.Visibility))) { return; } writer.WriteStartElement(elementName); if (abs != null) { writer.WriteAttributeString("abstract", abs); } writer.WriteAttributeString("deprecated", m.Deprecated); writer.WriteAttributeString("final", XmlConvert.ToString(m.Final)); writer.WriteAttributeString("name", m.Name); writer.WriteAttributeString("jni-signature", m.ExtendedJniSignature); if (extBridge.HasValue) { writer.WriteAttributeString("bridge", extBridge.Value ? "true" : "false"); } if (native != null) { writer.WriteAttributeString("native", native); } if (ret != null) { writer.WriteAttributeString("return", ret); } if (jniReturn != null) { writer.WriteAttributeString("jni-return", jniReturn); } writer.WriteAttributeString("static", XmlConvert.ToString(m.Static)); if (sync != null) { writer.WriteAttributeString("synchronized", sync); } if (transient != null) { writer.WriteAttributeString("transient", transient); } if (type != null) { writer.WriteAttributeString("type", type); } if (typeGeneric != null) { writer.WriteAttributeString("type-generic-aware", typeGeneric); } if (value != null) { writer.WriteAttributeString("value", value); } if (extSynthetic.HasValue) { writer.WriteAttributeString("synthetic", extSynthetic.Value ? "true" : "false"); } writer.WriteAttributeString("visibility", m.Visibility); if (volat != null) { writer.WriteAttributeString("volatile", volat); } if (typeParameters != null) { typeParameters.Save(writer, " "); } if (parameters != null) { foreach (var p in parameters) { writer.WriteStartElement("parameter"); writer.WriteAttributeString("name", p.Name); writer.WriteAttributeString("type", p.GetVisibleTypeName()); if (!string.IsNullOrEmpty(p.JniType)) { writer.WriteAttributeString("jni-type", p.JniType); } writer.WriteString("\n "); writer.WriteFullEndElement(); } } if (exceptions != null) { foreach (var e in exceptions.OrderBy(e => e.Name.Substring(e.Name.LastIndexOf('/') + 1).Replace('$', '.'), StringComparer.Ordinal)) { writer.WriteStartElement("exception"); writer.WriteAttributeString("name", e.Name.Substring(e.Name.LastIndexOf('/') + 1).Replace('$', '.')); writer.WriteAttributeString("type", e.Type); if (!string.IsNullOrEmpty(e.TypeGenericAware)) { writer.WriteAttributeString("type-generic-aware", e.TypeGenericAware); } writer.WriteString("\n "); writer.WriteFullEndElement(); } } writer.WriteString("\n "); writer.WriteFullEndElement(); }