Menu

#56 find a IMehtod of a given MethodDeclaration buggy

open
nobody
None
5
2004-11-15
2004-11-15
fr@nk
No

Symptom:
----------

Sometimes when I click on a method, no metric
information for this method is shown.

The method looks e.g. like this:
public void sayALot(int x[]) {...}

If the method looks like this, it works:
public void sayALot(int[] x) {...}

Problem:
---------

In the class
net.sourceforge.metrics.core.sources.TypeMetrics
the method:
private IMethod findMethod(MethodDeclaration m) {...}

has a bug.
It cuts of the "[]" at the end of the paremeters.

Solution:
---------
Count how many time at the end of a parameter of the
MethodDeclaration m is found. Append this then to the
local variable svd, just before finding the method.
Someting like this:

private IMethod findMethod(MethodDeclaration m) {
IType type = (IType)getJavaElement();
List parms = m.parameters();
String[] argtypes = new String[parms.size()];
int index = 0;
for (Iterator i = parms.iterator();i.hasNext();index++) {

String svd = i.next().toString();

// FIX of Frank Buchli
String arrayBugCorrection = "";
svd = svd.trim();
while (svd.endsWith("[]")) {
svd = svd.substring(0,svd.length()-2);
arrayBugCorrection += "[]";
}

int space = svd.lastIndexOf(' ');
// FIX submitted by Jacob Eckel 5/27/03 - remove
final modifiers
svd = svd.substring(0, space).trim();
if (svd.startsWith("final"))
svd = svd.substring("final".length()).trim();
// FIX F.S. 2/23/03 - without, invalid handles are
produced by found method
svd = svd + arrayBugCorrection;
argtypes[index] = Signature.createTypeSignature(svd,
false);
}
IMethod im =
type.getMethod(m.getName().getIdentifier(), argtypes);
if (im == null) {
Log.logError("No method found for " +
m.getName().getIdentifier() + " (" + argtypes + ")", null);
}
return im;
}

Discussion


Log in to post a comment.