diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java index a7496256d9e3..5d3136763de8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java @@ -117,11 +117,11 @@ JMethod resolve(JMethodRequest jMethodRequest) { if (jMethods.isEmpty()) { if (jMethodRequest.kind == JMethodKind.CONSTRUCTOR) { throw new JInteropException(DiagnosticErrorCode.CONSTRUCTOR_NOT_FOUND, - "No such public constructor found in class '" + jMethodRequest.declaringClass + "'"); + "No such public constructor found in class '" + jMethodRequest.declaringClass.getName() + "'"); } else { throw new JInteropException(DiagnosticErrorCode.METHOD_NOT_FOUND, "No such public method '" + jMethodRequest.methodName + "' found in class '" + - jMethodRequest.declaringClass + "'"); + jMethodRequest.declaringClass.getName() + "'"); } } @@ -399,15 +399,8 @@ private void validateArgumentTypes(JMethodRequest jMethodRequest, JMethod jMetho receiverIndex = jMethodRequest.pathParamCount; } BType receiverType = bParamTypes[receiverIndex]; - boolean isLastParam = (bParamTypes.length - jMethodRequest.pathParamCount) == 1; - if (!isValidParamBType(jMethodRequest.declaringClass, receiverType, isLastParam, - jMethodRequest.restParamExist)) { - if (jParamTypes.length == 0 || bParamTypes[0].tag != TypeTags.HANDLE) { - throwMethodNotFoundError(jMethodRequest); - } else { - throwNoSuchMethodError(jMethodRequest.methodName, jParamTypes[0], receiverType, - jMethodRequest.declaringClass); - } + if (receiverType.tag != TypeTags.HANDLE) { + throwMethodNotFoundError(jMethodRequest); } for (int k = receiverIndex; k < bParamTypes.length - 1; k++) { bParamTypes[k] = bParamTypes[k + 1]; @@ -854,12 +847,12 @@ private JMethod resolveMatchingMethod(JMethodRequest jMethodRequest, List 1) { if (jMethodRequest.kind == JMethodKind.CONSTRUCTOR) { @@ -983,18 +976,18 @@ private void throwMethodNotFoundError(JMethodRequest jMethodRequest) throws JInt if (jMethodRequest.kind == JMethodKind.CONSTRUCTOR) { throw new JInteropException(DiagnosticErrorCode.CONSTRUCTOR_NOT_FOUND, "No such public constructor with '" + jMethodRequest.bFuncParamCount + - "' parameter(s) found in class '" + jMethodRequest.declaringClass + "'"); + "' parameter(s) found in class '" + jMethodRequest.declaringClass.getName() + "'"); } else { if (jMethodRequest.bFuncParamCount == 0 || jMethodRequest.bParamTypes[0].tag != TypeTags.HANDLE) { throw new JInteropException(DiagnosticErrorCode.METHOD_NOT_FOUND, "No such public static method '" + jMethodRequest.methodName + "' with '" + jMethodRequest.bFuncParamCount + - "' parameter(s) found in class '" + jMethodRequest.declaringClass + "'"); + "' parameter(s) found in class '" + jMethodRequest.declaringClass.getName() + "'"); } else { throw new JInteropException(DiagnosticErrorCode.METHOD_NOT_FOUND, "No such public method '" + jMethodRequest.methodName + "' with '" + jMethodRequest.bFuncParamCount + - "' parameter(s) found in class '" + jMethodRequest.declaringClass + "'"); + "' parameter(s) found in class '" + jMethodRequest.declaringClass.getName() + "'"); } } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/ClassWithPrivateConstructor.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/ClassWithPrivateConstructor.java new file mode 100644 index 000000000000..1672797c584a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/ClassWithPrivateConstructor.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.ballerinalang.nativeimpl.jvm.tests; + +/** + * This class is used for Java interoperability tests. + * + * @since 2201.9.0 + */ +public class ClassWithPrivateConstructor { + + private ClassWithPrivateConstructor() { + } +} diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/StaticMethods.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/StaticMethods.java index eabbe8a11feb..f30075fb2591 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/StaticMethods.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/tests/StaticMethods.java @@ -816,4 +816,12 @@ public static void getMapValueWithBalEnv(Environment env, BString name, long age output.put(StringUtils.fromString("results"), results); balFuture.complete(output); } + + public static BString testOverloadedMethods(Environment env, BArray arr, BString str) { + return str; + } + + public static BString testOverloadedMethods(ArrayValue obj, BString str) { + return str; + } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/javainterop/basic/NegativeValidationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/javainterop/basic/NegativeValidationTest.java index a3381dab4d75..6623c907dc8c 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/javainterop/basic/NegativeValidationTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/javainterop/basic/NegativeValidationTest.java @@ -34,7 +34,6 @@ public class NegativeValidationTest { @Test public void testAcceptNothing() { - String path = "test-src/javainterop/ballerina_types_as_interop_types_negative.bal"; CompileResult compileResult = BCompileUtil.compile(path); Assert.assertEquals(compileResult.getDiagnostics().length, 12); @@ -42,7 +41,6 @@ public void testAcceptNothing() { @Test public void testClassNotFound() { - String path = "test-src/javainterop/negative/class_not_found.bal"; CompileResult compileResult = BCompileUtil.compile(path); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -53,110 +51,130 @@ public void testClassNotFound() { @Test public void testMethodNotFound1() { - String path = "test-src/javainterop/negative/method_not_found1.bal"; CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); BAssertUtil.validateError(compileResult, 0, "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public method " + - "'acceptStringOrErrorReturn' found in class 'class org.ballerinalang.nativeimpl." + + "'acceptStringOrErrorReturn' found in class 'org.ballerinalang.nativeimpl." + "jvm.tests.StaticMethods''", "method_not_found1.bal", 8, 1); } @Test public void testMethodNotFound2() { - String path = "test-src/javainterop/negative/method_not_found2.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); BAssertUtil.validateError(compileResult, 0, "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public static method " + - "'acceptObjectAndObjectReturn' with '3' " + "parameter(s) found in class 'class " + + "'acceptObjectAndObjectReturn' with '3' " + "parameter(s) found in class '" + "org.ballerinalang.nativeimpl.jvm.tests.StaticMethods''", "method_not_found2.bal", 22, 1); } @Test public void testMethodNotFound3() { - String path = "test-src/javainterop/negative/method_not_found3.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); BAssertUtil.validateError(compileResult, 0, "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public static method " + "'acceptRecordAndRecordReturn' with '3' " + "parameter(s) found in class " + - "'class org.ballerinalang.nativeimpl.jvm.tests.StaticMethods''", + "'org.ballerinalang.nativeimpl.jvm.tests.StaticMethods''", "method_not_found3.bal", 21, 1); } @Test public void testMethodNotFound4() { - String path = "test-src/javainterop/negative/method_not_found4.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); BAssertUtil.validateError(compileResult, 0, "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public method " + - "'acceptIntAndUnionReturn' found in class 'class org.ballerinalang.nativeimpl.jvm." + + "'acceptIntAndUnionReturn' found in class 'org.ballerinalang.nativeimpl.jvm." + "tests.StaticMethods''", "method_not_found4.bal", 23, 1); } @Test public void testMethodNotFound5() { - String path = "test-src/javainterop/negative/method_not_found5.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); BAssertUtil.validateError(compileResult, 0, "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public method " + - "'acceptIntStringAndUnionReturn' found in class 'class org.ballerinalang.nativeimpl." + + "'acceptIntStringAndUnionReturn' found in class 'org.ballerinalang.nativeimpl." + "jvm.tests.StaticMethods''", "method_not_found5.bal", 23, 1); } @Test public void testMethodNotFound6() { - String testFileName = "method_not_found6.bal"; String path = "test-src/javainterop/negative/" + testFileName; - CompileResult compileResult = BCompileUtil.compile(path); Assert.assertEquals(compileResult.getDiagnostics().length, 4); - String message = "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public method '%s' that matches with " + - "parameter types '(%s)' found in class 'class org.ballerinalang.nativeimpl.jvm.tests.StaticMethods''"; + "parameter types '(%s)' found in class 'org.ballerinalang.nativeimpl.jvm.tests.StaticMethods''"; String bTypeDescClassName = BTypedesc.class.getName(); String bFutureClassName = BFuture.class.getName(); - BAssertUtil.validateError(compileResult, 0, String.format(message, "getFuture", bTypeDescClassName), testFileName, 3, 1); - BAssertUtil.validateError(compileResult, 1, String.format(message, "getTypeDesc", bFutureClassName), testFileName, 9, 1); - BAssertUtil.validateError(compileResult, 2, String.format(message, "getFutureOnly", bFutureClassName + "," + bTypeDescClassName), testFileName, 15, 1); - BAssertUtil.validateError(compileResult, 3, String.format(message, "getTypeDescOnly", bTypeDescClassName + "," + bFutureClassName), testFileName, 21, 1); } @Test - public void testMethodSignatureNotMatch1() { + public void testMethodNotFound7() { + String path = "test-src/javainterop/negative/method_not_found7.bal"; + CompileResult compileResult = BCompileUtil.compile(path); + Assert.assertEquals(compileResult.getDiagnostics().length, 3); + String message = "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public static method '%s' with " + + "'%s' parameter(s) found in class '%s''"; + BAssertUtil.validateError(compileResult, 0, String.format(message, "getPrintableStackTrace", "1", + "io.ballerina.runtime.api.values.BError"), "method_not_found7.bal", 19, 1); + BAssertUtil.validateError(compileResult, 1, String.format(message, "concat", "2", + "io.ballerina.runtime.api.values.BString"), "method_not_found7.bal", 23, 1); + BAssertUtil.validateError(compileResult, 2, + "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public method 'concat' " + + "with '3' parameter(s) found in class 'io.ballerina.runtime.api.values.BString''", + "method_not_found7.bal", 27, 1); + } - String path = "test-src/javainterop/negative/method_sig_not_match1.bal"; + @Test + public void testConstructorNotFound() { + String path = "test-src/javainterop/negative/constructor_not_found.bal"; + CompileResult compileResult = BCompileUtil.compile(path); + Assert.assertEquals(compileResult.getDiagnostics().length, 3); + BAssertUtil.validateError(compileResult, 0, + "{ballerina/jballerina.java}CONSTRUCTOR_NOT_FOUND 'No such public constructor found " + + "in class 'org.ballerinalang.nativeimpl.jvm.tests.ClassWithPrivateConstructor''", + "constructor_not_found.bal", 19, 1); + BAssertUtil.validateError(compileResult, 1, + "{ballerina/jballerina.java}CONSTRUCTOR_NOT_FOUND " + + "'No such public constructor with '2' parameter(s) found in class " + + "'org.ballerinalang.nativeimpl.jvm.tests.ClassWithOneParamConstructor''", + "constructor_not_found.bal", 23, 1); + BAssertUtil.validateError(compileResult, 2, + "{ballerina/jballerina.java}CONSTRUCTOR_NOT_FOUND " + + "'No such public constructor that matches with parameter types '(int)' found in class " + + "'org.ballerinalang.nativeimpl.jvm.tests.ClassWithDefaultConstructor''", + "constructor_not_found.bal", 27, 1); + } + @Test + public void testMethodSignatureNotMatch1() { + String path = "test-src/javainterop/negative/method_sig_not_match1.bal"; CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -170,9 +188,7 @@ public void testMethodSignatureNotMatch1() { @Test public void testMethodSignatureNotMatch2() { - String path = "test-src/javainterop/negative/method_sig_not_match2.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -187,9 +203,7 @@ public void testMethodSignatureNotMatch2() { @Test public void testMethodSignatureNotMatch3() { - String path = "test-src/javainterop/negative/method_sig_not_match3.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -204,9 +218,7 @@ public void testMethodSignatureNotMatch3() { @Test public void testMethodSignatureNotMatch4() { - String path = "test-src/javainterop/negative/method_sig_not_match4.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -221,9 +233,7 @@ public void testMethodSignatureNotMatch4() { @Test public void testMethodSignatureNotMatch5() { - String path = "test-src/javainterop/negative/method_sig_not_match5.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -238,9 +248,7 @@ public void testMethodSignatureNotMatch5() { @Test public void testMethodSignatureNotMatch6() { - String path = "test-src/javainterop/negative/method_sig_not_match6.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -255,9 +263,7 @@ public void testMethodSignatureNotMatch6() { @Test public void testMethodSignatureNotMatch7() { - String path = "test-src/javainterop/negative/method_sig_not_match15.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -286,9 +292,7 @@ public void testMethodSignatureNotMatch8() { @Test public void testMethodSignatureNotMatch9() { - String path = "test-src/javainterop/negative/method_sig_not_match7.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -300,9 +304,7 @@ public void testMethodSignatureNotMatch9() { @Test public void testMethodSignatureNotMatch10() { - String path = "test-src/javainterop/negative/method_sig_not_match8.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -314,9 +316,7 @@ public void testMethodSignatureNotMatch10() { @Test public void testMethodSignatureNotMatch11() { - String path = "test-src/javainterop/negative/method_sig_not_match9.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -330,9 +330,7 @@ public void testMethodSignatureNotMatch11() { @Test public void testMethodSignatureNotMatch12() { - String path = "test-src/javainterop/negative/method_sig_not_match10.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -346,7 +344,6 @@ public void testMethodSignatureNotMatch12() { @Test public void testReturnStringForBUnionFromJava() { - String path = "test-src/javainterop/negative/method_sig_not_match11.bal"; CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); @@ -361,7 +358,6 @@ public void testReturnStringForBUnionFromJava() { @Test public void testJavaPrimitiveForBJsonParam() { - String path = "test-src/javainterop/negative/method_sig_not_match12.bal"; CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); @@ -375,7 +371,6 @@ public void testJavaPrimitiveForBJsonParam() { @Test public void testJavaPrimitiveForBUnionParam() { - String path = "test-src/javainterop/negative/method_sig_not_match13.bal"; CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); @@ -389,7 +384,6 @@ public void testJavaPrimitiveForBUnionParam() { @Test public void testMethodSignatureNotMatch14() { - String path = "test-src/javainterop/negative/method_sig_not_match14.bal"; CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); @@ -421,6 +415,22 @@ public void testResolveWithInstanceAndStatic() { } + @Test + public void testOverloadedMethods() { + String path = "test-src/javainterop/negative/overloaded_methods.bal"; + CompileResult compileResult = BCompileUtil.compile(path); + Assert.assertEquals(compileResult.getDiagnostics().length, 2); + BAssertUtil.validateError(compileResult, 0, + "{ballerina/jballerina.java}OVERLOADED_METHODS 'Overloaded methods " + + "cannot be differentiated. Please specify the parameterTypes for each " + + "parameter in 'paramTypes' field in the annotation'", + "overloaded_methods.bal", 24, 5); + BAssertUtil.validateError(compileResult, 1, + "{ballerina/jballerina.java}OVERLOADED_METHODS 'Overloaded methods " + + "cannot be differentiated. Please specify the parameterTypes for each parameter in " + + "'paramTypes' field in the annotation'", "overloaded_methods.bal", 30, 1); + } + @Test public void testNoClassDefFoundError() { String path = "test-src/javainterop/negative/project_no_class_def_found"; @@ -506,9 +516,7 @@ public void testStaticFieldGetWithAnyParameter() { @Test public void testMethodSignatureNotMatch16() { - String path = "test-src/javainterop/negative/method_sig_not_match16.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); @@ -524,9 +532,7 @@ public void testMethodSignatureNotMatch16() { @Test public void testMethodSignatureNotMatch17() { - String path = "test-src/javainterop/negative/method_sig_not_match17.bal"; - CompileResult compileResult = BCompileUtil.compile(path); compileResult.getDiagnostics(); Assert.assertEquals(compileResult.getDiagnostics().length, 1); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/constructor_not_found.bal b/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/constructor_not_found.bal new file mode 100644 index 000000000000..900bd88024a0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/constructor_not_found.bal @@ -0,0 +1,30 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/jballerina.java; + +function getConstructor() returns handle = @java:Constructor { + 'class: "org.ballerinalang.nativeimpl.jvm.tests.ClassWithPrivateConstructor" +} external; + +function getConstructorWithDifferentArgsCount(string name, int age) returns handle = @java:Constructor { + 'class: "org.ballerinalang.nativeimpl.jvm.tests.ClassWithOneParamConstructor" +} external; + +function getConstructorWithArgs() returns handle = @java:Constructor { + 'class: "org.ballerinalang.nativeimpl.jvm.tests.ClassWithDefaultConstructor", + paramTypes: ["int"] +} external; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/method_not_found7.bal b/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/method_not_found7.bal new file mode 100644 index 000000000000..c6cc062a3d30 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/method_not_found7.bal @@ -0,0 +1,30 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/jballerina.java; + +function getPrintableStackTrace(error s) returns handle = @java:Method { + 'class: "io.ballerina.runtime.api.values.BError" +} external; + +function concat(string s1, string s2) returns handle = @java:Method { + 'class: "io.ballerina.runtime.api.values.BString" +} external; + +function concatString(handle h, string s1, string s2) returns handle = @java:Method { + 'class: "io.ballerina.runtime.api.values.BString", + name: "concat" +} external; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/overloaded_methods.bal b/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/overloaded_methods.bal new file mode 100644 index 000000000000..3da564d53ca4 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/overloaded_methods.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/jballerina.java; + +public client isolated class Client { + + public isolated function init() { + } + + isolated resource function get abc/[string ...path]() returns int = @java:Method { + 'class: "org/ballerinalang/nativeimpl/jvm/tests/StaticMethods", + name: "getResource" + } external; +} + +function testOverloadedMethods(int[] arr, string str) returns string = @java:Method { + 'class: "org/ballerinalang/nativeimpl/jvm/tests/StaticMethods", + name: "testOverloadedMethods" +} external;