Menu

#9 _getJavaModelElement has several shortcomings

v4.0
open
nobody
Database (3)
5
2009-04-14
2009-04-14
A.B.
No

1.
Method JQueryTyRuBaAPI#_getJavaModelElement(Object) does not work for inner classes/interfaces and their members. Parts like this:

result = p.findType(getPackage(target), JQueryAPI.getElementLabel(target));

should be replaced by

result = p.findType(_getQualifiedElementLabel(target));

where _getQualifiedElementLabel returns the qualified name of the targe. One could even consider to add getQualifiedElementLabel to the public API.

private String _getQualifiedElementLabel(Object target) {
return _getStringProperty(target, "qname"); //works for classes/interfaces only
}

2.
The p.findType() call should not be used for fields and methods. According to the documentation it is only intended for types. So in the field and method section I suggest to replace

IType t = p.findType(getPackage(target), getParent(target));

with

Object parent = getParent(target); //changed the existing getParent method to return the real parent object, not just the name
String parentQualifiedName = _getQualifiedElementLabel(parent);
IType t = p.findType(parentQualifiedName);

3.
Sometimes a false method is returned. Suppose there are 2 methods in a class: meth() and secondmeth().

The following code might return secondmeth() if actually meth() is searched:
for (int i = 0; i < m.length; i++) {
if (getMethodName(m[i]).contains(mName)) {
result = m[i];
}
}

If there is no reason to check the method names with contains(), I suggest to replace it wit equals(), as in the fields section.
The complete (documented) changes can be found in the RuBaDoc project here on Sourceforge.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.