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

William S Fulton <[email protected]> Fri, 21 Jun 2024 15:05:45 +0100
Newsgroups gmane.comp.programming.swig
Message-ID <CANGqftAnB5Qy5aEXJqFR8X=RmNSjHiDWw=30UZhErvVEzN5Log@mail.gmail.com>
--===============6898041939659250086==
Content-Type: multipart/alternative; boundary="000000000000aa7492061b66efab"

--000000000000aa7492061b66efab
Content-Type: text/plain; charset="UTF-8"

This is not possible as it is hard coded to 'public'. We could add in some
pragmas similar to the Java module class pragmas
https://swig.org/Doc4.2/Java.html#Java_module_class_pragmas to provide this
flexibility. I suggest adding in a Github issue for this.

William

On Thu, 20 Jun 2024 at 10:21, lille stor via Swig-user <
[email protected]> wrote:

> 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 "abc" package because it is declared as "public".
>
>      /*
> ----------------------------------------------------------------------------
>       * This file was automatically generated by SWIG (http://www.swig.org
> ).
>       * Version 4.2.1
>       *
>       * Do not make changes to this file unless you know what you are
> doing--modify
>       * the SWIG interface file instead.
>       *
> -----------------------------------------------------------------------------
> */
>      package abc;
>      public interface TestConstants {
>             public final static int YES = TestJNI.YES_get();
>             public final static int NO = TestJNI.NO_get();
>             public final static int ENABLED = TestJNI.ENABLED_get();
>             public final static int DISABLED = TestJNI.DISABLED_get();
>      }
>
>
> How can I make this interface visible only to classes within the same
> package (i.e., change "public interface TestConstants" to just "interface
> TestConstants")? I have tried:
>
>      %typemap(javainterfacemodifiers) SWIGTYPE "interface"
>
> ... but it did not work. How can I achieve this using SWIG?
>
> _______________________________________________
> Swig-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/swig-user
>

--000000000000aa7492061b66efab
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><br></div><div>This is not possible as it is hard cod=
ed to &#39;public&#39;. We could add in some pragmas similar to the Java mo=
dule class pragmas <a href=3D"https://swig.org/Doc4.2/Java.html#Java_module=
_class_pragmas">https://swig.org/Doc4.2/Java.html#Java_module_class_pragmas=
</a> to provide this flexibility. I suggest adding in a Github issue for th=
is.</div><div><br></div><div>William<br></div></div><br><div class=3D"gmail=
_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, 20 Jun 2024 at 10:21,=
 lille stor via Swig-user &lt;<a href=3D"mailto:[email protected]=
.net">[email protected]</a>&gt; wrote:<br></div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px soli=
d rgb(204,204,204);padding-left:1ex"><div><div style=3D"font-family:Verdana=
;font-size:12px"><div>I am using SWIG (version 4.2.1) to generate a Java wr=
apper 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 acc=
essed by classes outside the &quot;abc&quot; package because it is declared=
 as &quot;public&quot;.</div>

<div>=C2=A0</div>

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

<div>=C2=A0=C2=A0=C2=A0=C2=A0 package abc;</div>

<div>=C2=A0=C2=A0=C2=A0=C2=A0 public interface TestConstants {<br>
=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 public final stati=
c int YES =3D TestJNI.YES_get();<br>
=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 public final stati=
c int NO =3D TestJNI.NO_get();<br>
=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 public final stati=
c int ENABLED =3D TestJNI.ENABLED_get();<br>
=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 public final stati=
c int DISABLED =3D TestJNI.DISABLED_get();<br>
=C2=A0=C2=A0=C2=A0=C2=A0 }</div>

<div>=C2=A0</div>
</div>

<div>=C2=A0</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 &q=
uot;interface TestConstants&quot;)? I have tried:</div>

<div>=C2=A0</div>

<div>=C2=A0=C2=A0=C2=A0=C2=A0 %typemap(javainterfacemodifiers) SWIGTYPE &qu=
ot;interface&quot;</div>

<div>=C2=A0</div>

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

<div>=C2=A0</div></div></div>

_______________________________________________<br>
Swig-user mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Swig-u=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/swig-user" rel=3D"n=
oreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/s=
wig-user</a><br>
</blockquote></div>

--000000000000aa7492061b66efab--


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


--===============6898041939659250086==
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

--===============6898041939659250086==--