Re: Make SWIG generated Java interface file not visible outside package

lille stor via Swig-user <[email protected]> Tue, 25 Jun 2024 08:09:58 +0200
Newsgroups gmane.comp.programming.swig
Message-ID <trinity-cddae9cf-4a9d-46f8-b825-611b55190adf-1719295798819@3c-app-mailcom-bs03>
--===============4009639688266349590==
Content-Type: text/html; charset=UTF-8

<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div>Hi William,<br/>
<br/>
Thanks for the info!<br/>
<br/>
I&#39;m a bit confused now... I though that the sole purpose of typemap &quot;javainterfacemodifiers&quot; was to actually change, e.g., the visibility of the generated Java interface class. See this commit: <a href="https://deref-gmx.com/mail/client/gVi7LFeAy8M/dereferrer/?redirectUrl=https%3A%2F%2Fgithub.com%2Fswig%2Fswig%2Fcommit%2Fc1b004f4fa62b1b15e047fd9462ddf3b46e55357" target="_blank">https://github.com/swig/swig/commit/c1b004f4fa62b1b15e047fd9462ddf3b46e55357</a>. Also, when looking at this line <a href="https://deref-gmx.com/mail/client/8i3vhEUjpo0/dereferrer/?redirectUrl=https%3A%2F%2Fgithub.com%2Fswig%2Fswig%2Fblob%2Fce2bb71a486bd575afb3c19ef98aae5f5e147905%2FSource%2FModules%2Fjava.cxx%23L2098" target="_blank">https://github.com/swig/swig/blob/ce2bb71a486bd575afb3c19ef98aae5f5e
 147905/Source/Modules/java.cxx#L2098</a> (in java.cxx), it seems to indicate that.<br/>
<br/>
Not sure how to proceed from here... thanks for the clarification!</div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div>&nbsp;
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Sent:</b>&nbsp;Friday, June 21, 2024 at 4:05 PM<br/>
<b>From:</b>&nbsp;&quot;William S Fulton&quot; &lt;[email protected]&gt;<br/>
<b>To:</b>&nbsp;&quot;lille stor&quot; &lt;[email protected]&gt;<br/>
<b>Cc:</b>&nbsp;[email protected]<br/>
<b>Subject:</b>&nbsp;Re: [Swig-user] Make SWIG generated Java interface file not visible outside package</div>

<div name="quoted-content">
<div>
<div>&nbsp;</div>

<div>This is not possible as it is hard coded to &#39;public&#39;. We could add in some pragmas similar to the Java module class pragmas <a href="https://swig.org/Doc4.2/Java.html#Java_module_class_pragmas" target="_blank">https://swig.org/Doc4.2/Java.html#Java_module_class_pragmas</a> to provide this flexibility. I suggest adding in a Github issue for this.</div>

<div>&nbsp;</div>

<div>William</div>
</div>
&nbsp;

<div class="gmail_quote">
<div class="gmail_attr">On Thu, 20 Jun 2024 at 10:21, lille stor via Swig-user &lt;<a href="mailto:[email protected]" onclick="" target="_blank">[email protected]</a>&gt; wrote:</div>

<blockquote class="gmail_quote" style="margin: 0.0px 0.0px 0.0px 0.8ex;border-left: 1.0px solid rgb(204,204,204);padding-left: 1.0ex;">
<div>
<div style="font-family: Verdana;font-size: 12.0px;">
<div>I am using SWIG (version 4.2.1) to generate a Java wrapper for some C code. This C code has some constants that SWIG represents with the Java interface file below. As it stands, this interface can be accessed by classes outside the &quot;abc&quot; package because it is declared as &quot;public&quot;.</div>

<div>&nbsp;</div>

<div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; /* ----------------------------------------------------------------------------<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* This file was automatically generated by SWIG (<a href="http://www.swig.org" target="_blank">http://www.swig.org</a>).<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* Version 4.2.1<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;*<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* Do not make changes to this file unless you know what you are doing--modify<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* the SWIG interface file instead.<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;* ----------------------------------------------------------------------------- */</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp; package abc;</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp; public interface TestConstants {<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public final static int YES = TestJNI.YES_get();<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public final static int NO = TestJNI.NO_get();<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public final static int ENABLED = TestJNI.ENABLED_get();<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public final static int DISABLED = TestJNI.DISABLED_get();<br/>
&nbsp;&nbsp;&nbsp;&nbsp; }</div>

<div>&nbsp;</div>
</div>

<div>&nbsp;</div>

<div>How can I make this interface visible only to classes within the same package (i.e., change &quot;public interface TestConstants&quot; to just &quot;interface TestConstants&quot;)? I have tried:</div>

<div>&nbsp;</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp; %typemap(javainterfacemodifiers) SWIGTYPE &quot;interface&quot;</div>

<div>&nbsp;</div>

<div>... but it did not work. How can I achieve this using SWIG?</div>

<div>&nbsp;</div>
</div>
</div>
_______________________________________________<br/>
Swig-user mailing list<br/>
<a href="mailto:[email protected]" onclick="" target="_blank">[email protected]</a><br/>
<a href="https://lists.sourceforge.net/lists/listinfo/swig-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/swig-user</a></blockquote>
</div>
</div>
</div>
</div>
</div></div></body></html>


--===============4009639688266349590==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============4009639688266349590==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user

--===============4009639688266349590==--