diff --git a/tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/xamarin/JavaType.java b/tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/xamarin/JavaType.java index baad63fb1..d87cacb49 100644 --- a/tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/xamarin/JavaType.java +++ b/tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/xamarin/JavaType.java @@ -6,6 +6,7 @@ /** * JNI sig: Lcom/xamarin/JavaEnum; */ +// Disconnective comment? enum JavaEnum { /** FIRST; JNI sig: Lcom/xamarin/JavaEnum; */ FIRST, @@ -161,6 +162,7 @@ public int compareTo (JavaType value) { } /** JNI sig: func.(Ljava/lang/StringBuilder;)Ljava/util/List; */ + // Comment to "disconnect" Javadoc from the member public List func (StringBuilder value) { return null; } diff --git a/tools/java-source-utils/src/main/java/com/microsoft/android/JniPackagesInfoFactory.java b/tools/java-source-utils/src/main/java/com/microsoft/android/JniPackagesInfoFactory.java index b91e6eb37..3886ec8bb 100644 --- a/tools/java-source-utils/src/main/java/com/microsoft/android/JniPackagesInfoFactory.java +++ b/tools/java-source-utils/src/main/java/com/microsoft/android/JniPackagesInfoFactory.java @@ -361,7 +361,7 @@ static String getJavaType(JniTypeInfo typeInfo, JniMethodInfo methodInfo, Type t final ResolvedType rt = type.resolve(); return rt.describe(); } catch (final Throwable thr) { - return ".*" + type.asString(); + return getUnresolvedJavaType(type); } } @@ -389,7 +389,8 @@ static String getJniType(JniTypeInfo typeInfo, JniMethodInfo methodInfo, Type ty } catch (final Exception thr) { } - return ".*" + type.asString(); + + return getUnresolvedJniType(type); } static String getJniType(JniTypeInfo typeInfo, JniMethodInfo methodInfo, ArrayType type) { @@ -412,7 +413,7 @@ static String getPrimitiveJniType(String javaType) { case "short": return "S"; case "void": return "V"; } - throw new Error("Don't know JNI type for `" + javaType + "`!"); + throw new Error("Don't know JNI type for primitive type `" + javaType + "`!"); } static String getJniType(ResolvedType type) { @@ -453,4 +454,42 @@ static String getJniType(ResolvedReferenceType type) { name.append(";"); return name.toString(); } + + static String getUnresolvedJavaType(Type type) { + final StringBuilder jniType = new StringBuilder(); + + jniType.append(".*"); + + if (type.isClassOrInterfaceType()) { + // Special-case class-or-interface declarations so that we skip type parameters. + type.ifClassOrInterfaceType(c -> { + c.getScope().ifPresent(s -> jniType.append(s.asString()).append(".")); + jniType.append(c.getName().asString()); + }); + } else { + jniType.append(type.asString()); + } + + return jniType.toString(); + } + + static String getUnresolvedJniType(Type type) { + final StringBuilder jniType = new StringBuilder(); + + jniType.append("L.*"); + + if (type.isClassOrInterfaceType()) { + // Special-case class-or-interface declarations so that we skip type parameters. + type.ifClassOrInterfaceType(c -> { + c.getScope().ifPresent(s -> jniType.append(s.asString()).append(".")); + jniType.append(c.getName().asString()); + }); + } else { + jniType.append(type.asString()); + } + + jniType.append(";"); + + return jniType.toString(); + } } diff --git a/tools/java-source-utils/src/test/java/com/microsoft/android/JavadocXmlGeneratorTest.java b/tools/java-source-utils/src/test/java/com/microsoft/android/JavadocXmlGeneratorTest.java index e46d8738c..28107fc68 100644 --- a/tools/java-source-utils/src/test/java/com/microsoft/android/JavadocXmlGeneratorTest.java +++ b/tools/java-source-utils/src/test/java/com/microsoft/android/JavadocXmlGeneratorTest.java @@ -109,6 +109,11 @@ public void testWritePackages_JavaType_java() throws Throwable { testWritePackages("../../../com/xamarin/JavaType.java", "JavaType.xml"); } + @Test + public void testWritePackages_UnresolvedTypes_txt() throws Throwable { + testWritePackages("../../../UnresolvedTypes.txt", "../../../UnresolvedTypes.xml"); + } + private static void testWritePackages(final String resourceJava, final String resourceXml) throws Throwable { final JavaParser parser = JniPackagesInfoFactoryTest.createParser(); final JniPackagesInfoFactory factory = new JniPackagesInfoFactory(parser); diff --git a/tools/java-source-utils/src/test/resources/UnresolvedTypes.txt b/tools/java-source-utils/src/test/resources/UnresolvedTypes.txt new file mode 100644 index 000000000..14965966e --- /dev/null +++ b/tools/java-source-utils/src/test/resources/UnresolvedTypes.txt @@ -0,0 +1,11 @@ +package example; + +public class UnresolvedTypes { + /** + * Method using unresolvable types. As such, we make do. + * + * JNI Sig: method.(L.*example.name.UnresolvedParameterType;)L.*UnresolvedReturnType; + */ + public static UnresolvedReturnType method(example.name.UnresolvedParameterType parameter) { + } +} \ No newline at end of file diff --git a/tools/java-source-utils/src/test/resources/UnresolvedTypes.xml b/tools/java-source-utils/src/test/resources/UnresolvedTypes.xml new file mode 100644 index 000000000..b80c679a2 --- /dev/null +++ b/tools/java-source-utils/src/test/resources/UnresolvedTypes.xml @@ -0,0 +1,13 @@ + + + + + + + + + + +