From 4f6a2a388eee5cb25101857840d839e8150f199f Mon Sep 17 00:00:00 2001 From: tball Date: Mon, 16 Nov 2015 11:26:15 -0800 Subject: [PATCH] Issue #660: fixed metadata signature for methods with parameterized return types. Change on 2015/11/16 by tball ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=107959033 --- jre_emul/JreEmulation.xcodeproj/project.pbxproj | 4 ++++ .../Tests/java/lang/reflect/ReflectionTest.java | 13 +++++++++++++ .../devtools/j2objc/gen/SignatureGenerator.java | 3 ++- .../devtools/j2objc/gen/SignatureGeneratorTest.java | 9 +++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/jre_emul/JreEmulation.xcodeproj/project.pbxproj b/jre_emul/JreEmulation.xcodeproj/project.pbxproj index a51d49b716..6d45389d36 100644 --- a/jre_emul/JreEmulation.xcodeproj/project.pbxproj +++ b/jre_emul/JreEmulation.xcodeproj/project.pbxproj @@ -77,6 +77,7 @@ 062463D41A000CE3006D52C9 /* JRETestsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 062463D31A000CE3006D52C9 /* JRETestsTableViewController.m */; }; 062463DA1A005995006D52C9 /* JRELogPaneViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 062463D91A005995006D52C9 /* JRELogPaneViewController.m */; }; 06459FC71A4223F000F5ED23 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 06C54AD31A40C7A4004B3ACD /* libicucore.dylib */; }; + 064EDBEF1BF5580900D25A14 /* NSErrorExceptionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 064EDBEE1BF5577000D25A14 /* NSErrorExceptionTest.m */; }; 06574A1A1A8EAF0B000A3616 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06C73F5719180E64001D3CC8 /* Security.framework */; }; 06574A1C1A8EAF84000A3616 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06574A1B1A8EAF84000A3616 /* QuartzCore.framework */; }; 06574A3D1A8EB04A000A3616 /* AlgorithmParametersSpiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 06574A1D1A8EB04A000A3616 /* AlgorithmParametersSpiTest.m */; }; @@ -1210,6 +1211,7 @@ 0649A7BD1AE07A4500DE2494 /* XMLFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = XMLFilter.m; path = build_result/Classes/org/xml/sax/XMLFilter.m; sourceTree = ""; }; 0649A7BE1AE07A4500DE2494 /* XMLReader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = XMLReader.m; path = build_result/Classes/org/xml/sax/XMLReader.m; sourceTree = ""; }; 0649A7BF1AE07A4500DE2494 /* XmlSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = XmlSerializer.m; path = build_result/Classes/org/xmlpull/v1/XmlSerializer.m; sourceTree = ""; }; + 064EDBEE1BF5577000D25A14 /* NSErrorExceptionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSErrorExceptionTest.m; path = com/google/j2objc/net/NSErrorExceptionTest.m; sourceTree = ""; }; 064FB746172705F400DC0D51 /* URI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = URI.h; path = build_result/Classes/java/net/URI.h; sourceTree = ""; }; 064FB747172705F400DC0D51 /* URI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = URI.m; path = build_result/Classes/java/net/URI.m; sourceTree = ""; }; 064FB74A172705F400DC0D51 /* URISyntaxException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = URISyntaxException.h; path = build_result/Classes/java/net/URISyntaxException.h; sourceTree = ""; }; @@ -6528,6 +6530,7 @@ 06FADA7C1B3B29B300A9579E /* NoPackageTest.h */, 06FADA7D1B3B29B300A9579E /* NoPackageTest.m */, 06574A631A8EB150000A3616 /* NormalizerTest.m */, + 064EDBEE1BF5577000D25A14 /* NSErrorExceptionTest.m */, 06E4E4F9197F1D46005DDE69 /* org */, 0615D3DB1BD83E7300132067 /* OtherBean.m */, 061AA0CC19FEF01800457D2B /* package-info.h */, @@ -8217,6 +8220,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 064EDBEF1BF5580900D25A14 /* NSErrorExceptionTest.m in Sources */, 0600C0121B715D13005FDEF9 /* CreationReferenceTest.m in Sources */, 0600C0131B715D13005FDEF9 /* ExpressionMethodReferenceTest.m in Sources */, 0600C0141B715D13005FDEF9 /* Lambdas.m in Sources */, diff --git a/jre_emul/Tests/java/lang/reflect/ReflectionTest.java b/jre_emul/Tests/java/lang/reflect/ReflectionTest.java index 487b5e1ea1..1df641738b 100644 --- a/jre_emul/Tests/java/lang/reflect/ReflectionTest.java +++ b/jre_emul/Tests/java/lang/reflect/ReflectionTest.java @@ -36,6 +36,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.util.List; import junit.framework.TestCase; @@ -55,6 +56,13 @@ public NoEquals() {} public NoEquals(String s) {} } + static class ParameterizedReturnTest { + // Method that returns a parameterized type. + public List getStringList() { + return null; + } + } + // Assert equals method can be found using reflection. Because it's a mapped // method with a parameter, reflection was trying to find "equalsWithId:" // instead of "isEqual:". @@ -91,4 +99,9 @@ public void testNonDefaultConstructorAnnotations() { } } + public void testParameterizedTypeMethodReturn() throws Exception { + Method method = ParameterizedReturnTest.class.getMethod("getStringList"); + Type returnType = method.getGenericReturnType(); + assertTrue(returnType instanceof ParameterizedType); + } } diff --git a/translator/src/main/java/com/google/devtools/j2objc/gen/SignatureGenerator.java b/translator/src/main/java/com/google/devtools/j2objc/gen/SignatureGenerator.java index 383b464f6d..966fd6b7a5 100644 --- a/translator/src/main/java/com/google/devtools/j2objc/gen/SignatureGenerator.java +++ b/translator/src/main/java/com/google/devtools/j2objc/gen/SignatureGenerator.java @@ -174,7 +174,8 @@ private static String createTypeSignature(ITypeBinding type) { } private static boolean hasGenericSignature(IMethodBinding method) { - if (method.isGenericMethod() || method.getReturnType().isTypeVariable()) { + if (method.isGenericMethod() || method.getReturnType().isTypeVariable() + || method.getReturnType().isParameterizedType()) { return true; } for (ITypeBinding param : method.getParameterTypes()) { diff --git a/translator/src/test/java/com/google/devtools/j2objc/gen/SignatureGeneratorTest.java b/translator/src/test/java/com/google/devtools/j2objc/gen/SignatureGeneratorTest.java index 52f8703b6e..028b7a3947 100644 --- a/translator/src/test/java/com/google/devtools/j2objc/gen/SignatureGeneratorTest.java +++ b/translator/src/test/java/com/google/devtools/j2objc/gen/SignatureGeneratorTest.java @@ -188,4 +188,13 @@ public void testGenericTypeMetadata() throws IOException { assertTranslation(translation, "\"set_\", NULL, 0x0, \"Ljava.util.Set;\", NULL, \"Ljava/util/Set;\","); } + + public void testMethodParameterizedReturnTypeMetadata() throws IOException { + String translation = translateSourceFile( + "import java.util.*; class Test { List getStringList() { return null; }}", + "Test", "Test.m"); + + // Assert method metadata has generic return signature. + assertTranslation(translation, "\"()Ljava/util/List;\""); + } }