From 640299089895ace8d77ccc4a0a56fe0d103c43db Mon Sep 17 00:00:00 2001 From: "Karl E. Nelson" Date: Sun, 17 Oct 2021 10:59:25 -0700 Subject: [PATCH 1/3] Conversion hints now apply to java.lang.Class --- doc/CHANGELOG.rst | 3 +++ native/common/jp_classtype.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index ad1039609..61b768bc8 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -5,6 +5,9 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o Latest Changes: - **1.3.1_dev0 - 2021-06-05** + + - Support for user defined conversions for java.lang.Class. + - **1.3.0 - 2021-05-19** - Fixes for memory issues found when upgrading to Python 3.10 beta. diff --git a/native/common/jp_classtype.cpp b/native/common/jp_classtype.cpp index b79f573a7..f02c30e25 100644 --- a/native/common/jp_classtype.cpp +++ b/native/common/jp_classtype.cpp @@ -36,11 +36,10 @@ JPClassType::~JPClassType() JPMatch::Type JPClassType::findJavaConversion(JPMatch& match) { JP_TRACE_IN("JPClass::findJavaConversion"); - if (nullConversion->matches(this, match) != JPMatch::_none) - return match.type; - if (objectConversion->matches(this, match) != JPMatch::_none) - return match.type; - if (classConversion->matches(this, match) != JPMatch::_none) + if (nullConversion->matches(this, match) + || objectConversion->matches(this, match) + || classConversion->matches(this, match) + || hintsConversion->matches(this, match)) return match.type; return match.type = JPMatch::_none; JP_TRACE_OUT; @@ -52,5 +51,6 @@ void JPClassType::getConversionInfo(JPConversionInfo &info) nullConversion->getInfo(this, info); objectConversion->getInfo(this, info); classConversion->getInfo(this, info); + hintsConversion->getInfo(this, info); PyList_Append(info.ret, PyJPClass_create(frame, this).get()); -} \ No newline at end of file +} From 042530d56c62259e6af36c72f8f8f1c807020669 Mon Sep 17 00:00:00 2001 From: "Karl E. Nelson" Date: Sun, 17 Oct 2021 11:18:46 -0700 Subject: [PATCH 2/3] Arrays and test --- doc/CHANGELOG.rst | 2 +- native/common/jp_arrayclass.cpp | 2 ++ test/jpypetest/test_classhints.py | 42 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 61b768bc8..4ea2494d9 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -6,7 +6,7 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o Latest Changes: - **1.3.1_dev0 - 2021-06-05** - - Support for user defined conversions for java.lang.Class. + - Support for user defined conversions for java.lang.Class and array types. - **1.3.0 - 2021-05-19** diff --git a/native/common/jp_arrayclass.cpp b/native/common/jp_arrayclass.cpp index afc557e57..c719af0e6 100644 --- a/native/common/jp_arrayclass.cpp +++ b/native/common/jp_arrayclass.cpp @@ -43,6 +43,7 @@ JPMatch::Type JPArrayClass::findJavaConversion(JPMatch &match) || charArrayConversion->matches(this, match) || byteArrayConversion->matches(this, match) || sequenceConversion->matches(this, match) + || hintsConversion->matches(this, match) ) return match.type; JP_TRACE("None"); @@ -57,6 +58,7 @@ void JPArrayClass::getConversionInfo(JPConversionInfo &info) charArrayConversion->getInfo(this, info); byteArrayConversion->getInfo(this, info); sequenceConversion->getInfo(this, info); + hintsConversion->getInfo(this, info); PyList_Append(info.ret, PyJPClass_create(frame, this).get()); } diff --git a/test/jpypetest/test_classhints.py b/test/jpypetest/test_classhints.py index 1c3c9b72b..bcf895622 100644 --- a/test/jpypetest/test_classhints.py +++ b/test/jpypetest/test_classhints.py @@ -24,6 +24,21 @@ def blah(self): pass +class ClassProxy: + def __init__(self, proxy): + self.proxy = proxy + + +class ArrayProxy: + def __init__(self, proxy): + self.proxy = proxy + + +class StringProxy: + def __init__(self, proxy): + self.proxy = proxy + + class ClassHintsTestCase(common.JPypeTestCase): def setUp(self): @@ -85,3 +100,30 @@ def StrToCustom(jcls, args): cht.call(MyImpl()) self.assertIsInstance(cht.input, self.MyCustom) self.assertIsInstance(cht.input.arg, MyImpl) + + def testClassCustomizer(self): + + @jpype.JConversion("java.lang.Class", instanceof=ClassProxy) + def ClassCustomizer(jcls, obj): + return obj.proxy + + hints = jpype.JClass('java.lang.Class')._hints + self.assertTrue(ClassProxy in hints.implicit) + + def testArrayCustomizer(self): + + @jpype.JConversion(jpype.JInt[:], instanceof=ArrayProxy) + def ArrayCustomizer(jcls, obj): + return obj.proxy + + hints = jpype.JClass(jpype.JInt[:])._hints + self.assertTrue(ArrayProxy in hints.implicit) + + def testStringCustomizer(self): + + @jpype.JConversion("java.lang.String", instanceof=StringProxy) + def STringCustomizer(jcls, obj): + return obj.proxy + + hints = jpype.JClass("java.lang.String")._hints + self.assertTrue(StringProxy in hints.implicit) From 32b8857afcf2919068dbb900178626fa46caea9e Mon Sep 17 00:00:00 2001 From: "Karl E. Nelson" Date: Fri, 22 Oct 2021 16:06:43 -0700 Subject: [PATCH 3/3] Update .azure so CI runs --- .azure/build.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index 374edb661..5538848d7 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -22,19 +22,19 @@ variables: jobs: - job: Deps pool: - vmImage: "ubuntu-16.04" + vmImage: "ubuntu-latest" steps: - template: scripts/ivy.yml - job: Documentation pool: - vmImage: "ubuntu-16.04" + vmImage: "ubuntu-latest" steps: - template: scripts/documentation.yml - job: Coverage pool: - vmImage: "ubuntu-16.04" + vmImage: "ubuntu-latest" dependsOn: Deps steps: - template: scripts/deps.yml @@ -42,7 +42,7 @@ jobs: - job: Tracing pool: - vmImage: "ubuntu-16.04" + vmImage: "ubuntu-latest" steps: - template: scripts/tracing.yml @@ -51,19 +51,19 @@ jobs: strategy: matrix: linux-3.5: - imageName: "ubuntu-16.04" + imageName: "ubuntu-latest" python.version: '3.5' linux-3.6: - imageName: "ubuntu-16.04" + imageName: "ubuntu-latest" python.version: '3.6' linux-3.7: - imageName: "ubuntu-16.04" + imageName: "ubuntu-latest" python.version: '3.7' linux-3.8: - imageName: "ubuntu-16.04" + imageName: "ubuntu-latest" python.version: '3.8' linux-3.9: - imageName: "ubuntu-16.04" + imageName: "ubuntu-latest" python.version: '3.9' windows-3.5: imageName: "vs2017-win2016"