SimpleName nextName = CallerFinder.SlicingUtils.getVariable(e);
if(nextName != null) {
/**
* Follow a simple assignment.
* */
HistoryDefinitionLocation actualDL = new HistoryDefinitionLocation(
nextName/*.getParent()*/.toString(),
resource,
cu.getLineNumber(nextName.getStartPosition()),
nextName,
parent, defaultType);
//showMessage("Type " + nextName.getParent().getClass());
// marks actualDL as recursive if necessary
if(registerExpansion(actualDL)) {
processDecl(nextName, cu, resource, actualDL, stack, monitor);
}
} else
if(e instanceof MethodInvocation) {
/**
* Go back through a method invocation.
* */
MethodInvocation mi = (MethodInvocation) e;
SimpleName methodName = mi.getName();
log("Going back through callee " + methodName.toString());
HistoryDefinitionLocation callDL;
if(!first){
callDL= new HistoryDefinitionLocation(
mi.toString(),
resource,
cu.getLineNumber(mi.getStartPosition()),
mi,
parent, HistoryDefinitionLocation.CALL);
}
else{
callDL=parent;
}
if(registerExpansion(callDL)) {
Collection/*<MethodDeclarationUnitPair>*/ callees = CallerFinder.findCallees(monitor, methodName.toString(), null, false);
if(callees.isEmpty()) {
if(SinkView.isDerivationName(methodName.getFullyQualifiedName()))
{
HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
mi.getExpression().toString(),
resource,
cu.getLineNumber(mi.getStartPosition()),
mi.getExpression(), callDL, HistoryDefinitionLocation.DERIVATION);
if(registerExpansion(dl)) {
Expression expr = mi.getExpression();
if(expr != null) {
// Recurse on the returned expression
processExpression(dl, expr, cu, resource, stack, monitor, HistoryDefinitionLocation.DERIVATION,false);
}
}
}
else{
logError("No suitable callees for " + methodName + " in " + resource + " found");
System.out.println("No suitable callees for " + methodName + " in " + resource + " found");
}
} else
for (Iterator iter = callees.iterator(); iter.hasNext();) {
Utils.MethodDeclarationUnitPair element
= (Utils.MethodDeclarationUnitPair) iter.next();
MethodDeclaration methodDeclaration = element.getMethod();
CompilationUnit nextCU = element.getCompilationUnit();
IResource nextResource = element.getResource();
if(methodDeclaration != null){
if(!LapsePlugin.FOLLOW_INTO_FUNCTIONS) {
/*HistoryDefinitionLocation dl = */new HistoryDefinitionLocation(
"Method " + methodDeclaration.getName().getFullyQualifiedName(),
nextResource,
nextCU.getLineNumber(e.getStartPosition()),
methodDeclaration, callDL, HistoryDefinitionLocation.RETURN);
} else {
Collection/*<ReturnStatement>*/ returns = CallerFinder.findReturns(monitor, methodDeclaration, null);
for (Iterator iter2 = returns.iterator(); iter2.hasNext();) {
ReturnStatement returnStmt = (ReturnStatement) iter2.next();
HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
returnStmt.toString(),
nextResource,
nextCU.getLineNumber(returnStmt.getStartPosition()),
returnStmt, callDL, HistoryDefinitionLocation.RETURN);
if(registerExpansion(dl)) {
Expression expr = returnStmt.getExpression();
if(expr != null) {
// Recurse on the returned expression
stack.addLast(mi);
processExpression(dl, expr, nextCU, nextResource, stack, monitor, HistoryDefinitionLocation.COPY,false);
stack.removeLast();
}
}
}
}
}
else{
//check if it is a derivtion expression
if(SinkView.isDerivationName(methodName.getFullyQualifiedName()))
{
processExpression(callDL, mi.getExpression(), cu, resource, stack, monitor, HistoryDefinitionLocation.DERIVATION,false);
break;
}
}
}
}
} else
if ( e instanceof InfixExpression && ( ((InfixExpression)e).getOperator() == InfixExpression.Operator.PLUS ) ) {
/**
* Follow arguments of a string concatenation.
* */
InfixExpression ie = (InfixExpression) e;
Expression leftExpr = ie.getLeftOperand();
Expression rightExpr = ie.getRightOperand();
HistoryDefinitionLocation concatDL;
if(!first){
concatDL = new HistoryDefinitionLocation(
e.toString(),
resource,
cu.getLineNumber(e.getStartPosition()),
e,
parent, HistoryDefinitionLocation.STRING_CONCAT);
}
else
concatDL=parent;
if(registerExpansion(concatDL)) {
processExpression(concatDL, leftExpr, cu, resource, stack, monitor, HistoryDefinitionLocation.COPY,false);
processExpression(concatDL, rightExpr, cu, resource, stack, monitor, HistoryDefinitionLocation.COPY,false);
if(ie.extendedOperands() != null) {
for(Iterator iter = ie.extendedOperands().iterator(); iter.hasNext(); ) {
Expression ext_e = (Expression) iter.next();
processExpression(concatDL, ext_e, cu, resource, stack, monitor, HistoryDefinitionLocation.COPY,false);
}
}
}
}
else if(e instanceof ParenthesizedExpression){
ParenthesizedExpression ex=(ParenthesizedExpression)e;
processExpression(parent, ex.getExpression(), cu, resource, stack, monitor, HistoryDefinitionLocation.UNDEFINED,false);
}
else if(e instanceof CastExpression){
CastExpression cex=(CastExpression)e;
processExpression(parent, cex.getExpression(), cu, resource, stack, monitor, HistoryDefinitionLocation.UNDEFINED,false);
}
else if(e instanceof ArrayAccess) {
ArrayAccess ae=(ArrayAccess)e;
HistoryDefinitionLocation arrAccess;
if(!first){
arrAccess= new HistoryDefinitionLocation(
e.toString(),
resource,
cu.getLineNumber(e.getStartPosition()),
e,
parent, HistoryDefinitionLocation.ARRAYACCESS);
}
else arrAccess=parent;
if(registerExpansion(arrAccess))
processExpression(arrAccess, ae.getArray(), cu, resource, stack, monitor, HistoryDefinitionLocation.ARRAYACCESS,false);
}
else if(e instanceof ClassInstanceCreation)
{
ClassInstanceCreation c=(ClassInstanceCreation)e;
HistoryDefinitionLocation cc;
if(!first){
cc= new HistoryDefinitionLocation(
e.toString(),
resource,
cu.getLineNumber(e.getStartPosition()),
e,
parent, HistoryDefinitionLocation.CLASS_INSTANCE_CREATION);
}else
cc=parent;
String aux=(c.getType()).toString();
if(SinkView.isDerivationName(aux)){
for(Object arg:c.arguments()){
if(registerExpansion(cc))
processExpression(cc,(Expression)arg,cu,resource,stack,monitor,HistoryDefinitionLocation.DERIVATION,false);
}
}
}
else {
/**
* Some other expression.
*/
/*HistoryDefinitionLocation dl = */new HistoryDefinitionLocation(
e.toString(),
resource,
cu.getLineNumber(e.getStartPosition()),
e, parent, getExpressionType(e, cu, resource));
}