static string GetVisibleReturnTypeString(JavaMethodModel method) { if (GetVisibleNonSpecialType(method, method.ReturnTypeModel) is JavaTypeReference jtr) { return(jtr.ToString()); } return(method.Return); }
static void SaveMethod(JavaMethodModel method, XmlWriter writer) { bool check(JavaMethodModel _) => _.BaseMethod?.DeclaringType?.Visibility == "public" && !method.IsStatic && method.Parameters.All(p => p.InstantiatedGenericArgumentName == null); // skip synthetic methods, that's what jar2xml does. // However, jar2xml is based on Java reflection and it generates synthetic methods // that actually needs to be generated in the output XML (they are not marked as // "synthetic" either by asm or java reflection), when: // - the synthetic method is actually from non-public ancestor class // (e.g. FileBackupHelperBase.writeNewStateDescription()) // For such case, it does not skip generation. if (method.IsSynthetic && (method.BaseMethod == null || check(method))) { return; } // Here we skip most of the overriding methods of a virtual method, unless // - the method visibility or final-ity has changed: protected Object#clone() is often // overriden as public. In that case, we need a "new" method. // - the method is covariant. In that case we need another overload. // - they differ in "abstract" or "final" method attribute. // - the derived method is static. // - the base method is in the NON-public class. // - none of the arguments are type parameters. // - finally, it is the synthetic method already checked above. if (method.BaseMethod != null && !method.BaseMethod.IsAbstract && method.BaseMethod.Visibility == method.Visibility && method.BaseMethod.IsAbstract == method.IsAbstract && method.BaseMethod.IsFinal == method.IsFinal && !method.IsSynthetic && check(method)) { return; } SaveMember(m: method, writer: writer, elementName: "method", abs: XmlConvert.ToString(method.IsAbstract), native: XmlConvert.ToString(method.IsNative), ret: GetVisibleReturnTypeString(method), sync: XmlConvert.ToString(method.IsSynchronized), transient: null, type: null, typeGeneric: null, value: null, volat: null, parameters: method.Parameters, extBridge: method.IsBridge, jniReturn: method.ReturnJni, extSynthetic: method.IsSynthetic, notNull: method.ReturnNotNull); }
public static JavaParameterModel ParseParameter(JavaMethodModel method, XElement element) { var parameter = new JavaParameterModel( declaringMethod: method, javaName: element.XGetAttribute("name"), javaType: element.XGetAttribute("type"), jniType: element.XGetAttribute("jni-type"), isNotNull: element.XGetAttributeAsBool("not-null") ); return(parameter); }
public static JavaMethodModel ParseMethod(JavaTypeModel type, XElement element) { var method = new JavaMethodModel( javaName: element.XGetAttribute("name"), javaVisibility: element.XGetAttribute("visibility"), javaAbstract: element.XGetAttributeAsBool("abstract"), javaFinal: element.XGetAttributeAsBool("final"), javaStatic: element.XGetAttributeAsBool("static"), javaReturn: element.XGetAttribute("return"), javaDeclaringType: type, deprecated: element.XGetAttribute("deprecated"), jniSignature: element.XGetAttribute("jni-signature"), isSynthetic: element.XGetAttributeAsBool("synthetic"), isBridge: element.XGetAttributeAsBool("bridge"), returnJni: element.XGetAttribute("jni-return"), isNative: element.XGetAttributeAsBool("native"), isSynchronized: element.XGetAttributeAsBool("synchronized"), returnNotNull: element.XGetAttributeAsBool("return-not-null") ); if (element.Element("typeParameters") is XElement tp) { ParseTypeParameters(method.TypeParameters, tp); } foreach (var child in element.Elements("parameter")) { method.Parameters.Add(ParseParameter(method, child)); } foreach (var child in element.Elements("exception")) { method.Exceptions.Add(ParseException(child)); } if (element.XGetAttribute("merge.SourceFile") is string source && source.HasValue()) { method.PropertyBag.Add("merge.SourceFile", source); } if (element.XGetAttribute("deprecated-since") is string dep && dep.HasValue()) { method.PropertyBag.Add("deprecated-since", dep); } return(method); }
static JavaParameterModel ParseParameterModel(JavaMethodModel declaringMethod, JniTypeName jniParameter, ParameterDefinition managedParameter) { var raw_type = jniParameter.Type; // This covers a special case where we have generated an interface method like: // void DoThing (System.Collections.Generics.IList<MyPackage.MyType> p0); // However the [Register] JNI signature for this method is missing generic information: // "(Ljava/util/List;)V" // We need to try to rebuild the generic signature from the [Register] attributes // on the type components that make up the signature: // java.util.List<mypackage.MyType> // TODO: This is more correct, but differs from ApiXmlAdjuster. //if (managedParameter.ParameterType is GenericInstanceType) // if (TypeReferenceToJavaType (managedParameter.ParameterType) is string s) // raw_type = s; return(new JavaParameterModel(declaringMethod, managedParameter.Name, raw_type, jniParameter.Jni, false)); }
public static JavaMethodModel?ParseMethod(MethodDefinition method, JavaTypeModel declaringType) { if (method.IsPrivate || method.IsAssembly) { return(null); } var obs_attr = GetObsoleteAttribute(method.CustomAttributes); var reg_attr = GetRegisterAttribute(method.CustomAttributes); if (reg_attr is null) { return(null); } var deprecated = (obs_attr != null) ? (string)obs_attr.ConstructorArguments [0].Value ?? "deprecated" : "not deprecated"; var jni_signature = JniSignature.Parse((string)reg_attr.ConstructorArguments [1].Value !); var model = new JavaMethodModel( javaName: (string)reg_attr.ConstructorArguments [0].Value, javaVisibility: method.Visibility(), javaAbstract: method.IsAbstract, javaFinal: method.IsFinal, javaStatic: method.IsStatic, javaReturn: jni_signature.Return.Type, javaDeclaringType: declaringType, deprecated: deprecated, jniSignature: jni_signature.ToString(), isSynthetic: false, isBridge: false, returnJni: jni_signature.Return.Jni, isNative: false, isSynchronized: false, returnNotNull: false ); for (var i = 0; i < jni_signature.Parameters.Count; i++) { model.Parameters.Add(ParseParameterModel(model, jni_signature.Parameters [i], method.Parameters [i])); } return(model); }
static JavaTypeReference?GetVisibleNonSpecialType(JavaMethodModel method, JavaTypeReference?r) { if (r == null || r.SpecialName != null || r.ReferencedTypeParameter != null || r.ArrayPart != null) { return(null); } var requiredVisibility = method?.Visibility == "public" && method.DeclaringType?.Visibility == "public" ? "public" : method?.Visibility; for (var t = r; t != null; t = (t.ReferencedType as JavaClassModel)?.BaseTypeReference) { if (t.ReferencedType == null) { break; } if (IsAcceptableVisibility(required: requiredVisibility, actual: t.ReferencedType.Visibility)) { return(t); } } return(null); }