Skip to content

Commit ab0caf7

Browse files
committed
Prefix class name to methods already defined in a superclass
This is to prevent collisions with inherited methods.
1 parent 74cf62d commit ab0caf7

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/gir2java/GirParser.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.PrintWriter;
1010
import java.lang.reflect.Method;
1111
import java.util.ArrayList;
12+
import java.util.Collection;
1213
import java.util.Collections;
1314
import java.util.HashMap;
1415
import java.util.HashSet;
@@ -41,7 +42,6 @@
4142
import com.sun.codemodel.JDefinedClass;
4243
import com.sun.codemodel.JEnumConstant;
4344
import com.sun.codemodel.JExpr;
44-
import com.sun.codemodel.JExpression;
4545
import com.sun.codemodel.JFieldVar;
4646
import com.sun.codemodel.JInvocation;
4747
import com.sun.codemodel.JMethod;
@@ -836,6 +836,23 @@ private void parseMethodOrFunction(Element root, ParsingContext context) {
836836
name = nativeName;
837837
}
838838
name = NameUtils.neutralizeKeyword(name);
839+
840+
JClass klass = enclosing;
841+
outer:
842+
while ( (klass != null) && (klass instanceof JDefinedClass) ) {
843+
JDefinedClass definedClass = (JDefinedClass) klass;
844+
845+
Collection<JMethod> methods = definedClass.methods();
846+
for (JMethod method : methods) {
847+
if (method.name().equals(name)) {
848+
name = enclosing.name().toLowerCase() + "_" + name;
849+
break outer;
850+
}
851+
}
852+
853+
klass = klass._extends();
854+
}
855+
839856
JMethod wrapper = enclosing.method(JMod.PUBLIC | staticModifier, returnType.getJType(), name);
840857

841858
JInvocation nativeCall;

0 commit comments

Comments
 (0)