Skip to content

Commit 74cf62d

Browse files
committed
Make private fields private in the generated code as well
They cause name clashes when a class and its superclass both declare a pointer field named "priv", but the pointers are differently typed. We do not have to know about private fields anyways, so make them private to prevent inheritance. Leave them in place so that BridJ knows about them.
1 parent b0e3364 commit 74cf62d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/gir2java/GirParser.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ private ConvertedType findType(Element root, ParsingContext context) {
661661

662662
@SuppressWarnings("unused")
663663
private void parseRecordField(Element root, ParsingContext context) {
664+
664665
JDefinedClass record = (JDefinedClass) context.getCmNode();
665666
String name = "field_" + root.getAttributeValue("name");
666667

@@ -679,11 +680,17 @@ private void parseRecordField(Element root, ParsingContext context) {
679680
String bridjType = convType.bridjMethodifyTypeName();
680681
JType fieldType = convType.getJType();
681682

682-
JMethod getter = record.method(JMod.PUBLIC, fieldType, name);
683+
String privateAttribute = root.getAttributeValue("private");
684+
int modifier = JMod.PUBLIC;
685+
if ("1".equals(privateAttribute)) {
686+
modifier = JMod.PRIVATE;
687+
}
688+
689+
JMethod getter = record.method(modifier, fieldType, name);
683690
getter.annotate(Field.class).param("value", fieldIdx);
684691
getter.body().directStatement("return this.io.get" + bridjType + "Field(this, " + fieldIdx + ");");
685692

686-
JMethod setter = record.method(JMod.PUBLIC, record, name);
693+
JMethod setter = record.method(modifier, record, name);
687694
setter.annotate(Field.class).param("value", fieldIdx);
688695
setter.param(fieldType, name);
689696
setter.body().directStatement("this.io.set" + bridjType + "Field(this, " + fieldIdx + ", " + name + ");");

0 commit comments

Comments
 (0)