private void processDecl(SimpleName name, CompilationUnit cu, IResource resource,
HistoryDefinitionLocation parent, LinkedList<MethodInvocation> stack,
IProgressMonitor monitor)
{
VariableDeclaration decl = name2decl(name, cu, resource);
// if(TRACE) System.out.print('.');
if(monitor.isCanceled()) {
// check if the search has been cancelled
return;
}
//monitor.setTaskName("Processing " + name + " in " + resource.getName/*getFullPath*/());
monitor.subTask("Processing " + name + " in " + resource.getName/*getFullPath*/());
if(decl == null) {
logError(
"decl: " + decl + " on line " + (decl == null ? DefinitionLocation.INVALID_SOURCE_LINE : fRoot.getLineNumber(decl.getStartPosition())) +
" and name: " + name + "(" + name.hashCode() + ") on line " + fRoot.getLineNumber(name.getStartPosition()));
// the case of no declaration found -- add a question mark
/*HistoryDefinitionLocation dl = */new HistoryDefinitionLocation(
name.toString(),
null, // this will be ignored
DefinitionLocation.INVALID_SOURCE_LINE,
name, parent, HistoryDefinitionLocation.UNDEFINED);
//System.out.println("Case 1");
} else
if(decl.getParent() instanceof MethodDeclaration){
// the case of a parameter -- add the actuals and recurse
//showMessage(decl.toString() + " is a parameter of " + parent.getClass());
MethodDeclaration methodDecl = (MethodDeclaration) decl.getParent();
IMethod method = new MethodFinder((IFile) resource).convertMethodDecl2IMethod(methodDecl);
if(method == null) {
JavaPlugin.logErrorMessage("Internal error: No method found for " + methodDecl);
return;
}
HistoryDefinitionLocation paramDL = new HistoryDefinitionLocation(
decl.toString(),
resource,
cu.getLineNumber(decl.getStartPosition()),
decl, parent, HistoryDefinitionLocation.FORMAL_PARAMETER);
if(!registerExpansion(paramDL)) {
// recursion detected here
return;
}
Expression onlyCall = (Expression) (stack.isEmpty() ? null : stack.getLast());
log("Looking for calls from " + onlyCall);
Collection/*<ExpressionUnitPair>*/ c = CallerFinder.getActualsForFormal(method, name, onlyCall, monitor, null);
if(c.isEmpty()){
logError(
"No suitable actual arguments for formal argument " +
name + " of " + method.getElementName() + " at " +
resource.getName() + " found");
} else
for (Iterator iter = c.iterator(); iter.hasNext();) {
Utils.ExpressionUnitPair eup = (Utils.ExpressionUnitPair) iter.next();
Expression e = eup.getExpression();
CompilationUnit nextCU = eup.getCompilationUnit();
IResource nextResource = eup.getResource();
processExpression(paramDL, e, nextCU, nextResource, stack, monitor, HistoryDefinitionLocation.CALL_ARG,false);
}
//System.out.println("Case 2");
} else {
/**
* The case of a declaration -- look at the right hand side.
* */
Object obj = (decl.getParent() instanceof VariableDeclaration) ?
decl.getParent() :
decl;
String desc = obj.toString();
int type = (decl.getParent() instanceof FieldDeclaration) ?
HistoryDefinitionLocation.FIELD :
HistoryDefinitionLocation.DECLARATION;
// the case of a regilar declaration being found
HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
desc,
resource,
cu.getLineNumber(decl.getStartPosition()),
decl, parent, type);
Expression e = decl.getInitializer();
if(e != null) {
// TODO: add processing of the RHS of the declaration
processExpression(dl, e, cu, resource, stack, monitor, HistoryDefinitionLocation.COPY,false);
}