dotnet / java-interop

Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#
Other
201 stars 53 forks source link

Internal methods #53

Closed lobster2012-user closed 6 years ago

lobster2012-user commented 8 years ago

Hello, add please ability to extent or replace default codegenerator from box(i can fork, i know) Thanks.

jonpryor commented 8 years ago

I am not sure what you're requesting.

There is already a generator --codegen-target=NAME option to control parts of the generated output; see the CodeGenerator abstract class. Would this be sufficient, or a suitable starting point?

lobster2012-user commented 8 years ago
v => opts.CodeGenerationTarget = ParseCodeGenerationTarget (v) },

switch (value.ToLowerInvariant ()) {
            case "xamarinandroid":
                return CodeGenerationTarget.XamarinAndroid;
            case "xajavainterop1":
                return CodeGenerationTarget.XAJavaInterop1;
            case "javainterop1":
                return CodeGenerationTarget.JavaInterop1;
            }
            throw new NotSupportedException ($"Don't know how to convert '{value}' to a CodeGenerationTarget value!");

this option does not solve my problem

I want you custom codegenerator or(and) customrules for example With default rules i created bindings for ACRA without 'remove' only via extra code in additions I have problem with ImmutableMap for method entryset, because not implicit convertion for ICollection, javaset return (ICollection)new JavaSet, it does not have implicit conversion to ICollection With common rules without addtional code and without 'remove' in metadata i can not create clear code. In other project i have problem with genenetic types, with has method return this; class T T fluentmethod() { return this } After conversion code returned java.lang.Object instead of T (sorry for my english)

jonpryor commented 8 years ago

There are a number of known issues in the Java binding process, many of which it would be nice to fix. Unfortunately, generator hasn't gotten as much love as it needs.

I don't understand what you mean regarding ACRA's ImmutableMap and an entrySet() method, because I don't see an entrySet() method, nor does the java.util.Set<T> interface define one.

JavaSet does implement System.Collections.ICollection, so I'm further confused by your first statement.

Regarding your problem with generic types, that's a longstanding issue because, within JNI, generic types do not exist. Java.Interop/Xamarin.Android don't provide a "Java as seen through Java" view of Java types; it provides a "Java as seen through JNI" view of Java types, which differs in many subtle ways. From JNI, T.fluentmethod() returns java.lang.Object; you can verify that by using javap -s and looking at the JNI signature of the method.

lobster2012-user commented 8 years ago

1.For fluent methods i know implementation and i can change safely code on T flluentMethod() { some_work(); return this } I need ability to do this from box

  1. ACRA acra/ImmutableMap

2.1

[Register("java/util/HashSet", DoNotGenerateAcw = true)]
  public class JavaSet : Java.Lang.Object, **System.Collections.ICollection**, IEnumerable
  {
}
JavaSet implements System.Collections.ICollection

2.2
interface IMap 
{
  [Register("keySet", "()Ljava/util/Set;", "GetKeySetHandler:Java.Util.IMapInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
    System.Collections.ICollection KeySet();
}
public sealed partial class ImmutableMap : global::Java.Lang.Object, global::Java.IO.ISerializable, global::Java.Util.IMap 
{
[Register ("entrySet", "()Ljava/util/Set;", "")]
        public unsafe global::System.Collections.Generic.ICollection<global::Java.Util.IMapEntry> EntrySet ()
        {
            if (id_entrySet == IntPtr.Zero)
                id_entrySet = JNIEnv.GetMethodID (class_ref, "entrySet", "()Ljava/util/Set;");
            try {
                return global::Android.Runtime.JavaSet<global::Java.Util.IMapEntry>.FromJniHandle (JNIEnv.CallObjectMethod  (Handle, id_entrySet), JniHandleOwnership.TransferLocalRef);
            } finally {
            }
        }
}

Via metadata i set returnType on ICollection for implementing ICollection entrySet() But i do not know how change global::Android.Runtime.JavaSetglobal::Java.Util.IMapEntry.FromJniHandle on global::Android.Runtime.JavaSet.FromJniHandle I play with mamagedType, without good result...

FromJniHandle return JavaSet as ICollection JavaSet inherits from Javaset Javaset implement ICollection, but does not exist explicit conversion from ICollection to ICollection

jonpryor commented 6 years ago

Unfortunately, I'm still unable to properly interpret or understand what is being requested.

Would you be able to add an example program which describes what problem you're encountering?