Newer
Older
MagnetRON / src / org / ntlab / deltaViewer / DeltaAliasCollector.java
package org.ntlab.deltaViewer;

import java.util.ArrayList;
import java.util.Collection;

import org.ntlab.deltaExtractor.Alias;
import org.ntlab.deltaExtractor.IAliasCollector;
import org.ntlab.trace.MethodExecution;
import org.ntlab.trace.MethodInvocation;

/**
 * Collect delta aliases for MagnetRON. 
 * 
 * @author Nitta Lab.
 */
public class DeltaAliasCollector implements IAliasCollector {

	private String srcObjId;
	private String dstObjId;
	private ArrayList<Alias> aliasList = new ArrayList<>();
	
	public DeltaAliasCollector() {
	}
	
	/**
	 * @param srcObjId
	 * @param dstObjId
	 */
	public DeltaAliasCollector(String srcObjId, String dstObjId) {
		this.srcObjId = srcObjId;
		this.dstObjId = dstObjId;
	}
	
	@Override
	public void addAlias(Alias alias) {
		switch(alias.getAliasType()) {
			case FORMAL_PARAMETER:
				aliasList.add(0, alias);
				alias.getOccurrencePoint().getMethodExecution().getThisObjId();
				break;
			case THIS:
				aliasList.add(0, alias);
				break;
			case METHOD_INVOCATION:
				aliasList.add(0, alias);
				break;
			case CONSTRACTOR_INVOCATION:
				aliasList.add(0, alias);
				break;
			case FIELD:
				aliasList.add(0, alias);
				break;
			case ARRAY:
				aliasList.add(0, alias);
				break;
			case ACTUAL_ARGUMENT:
				aliasList.add(0, alias);
				break;
			case RECEIVER:
				aliasList.add(0, alias);
				if (alias.getOccurrencePoint().getStatement() instanceof MethodInvocation) {
					MethodExecution me = ((MethodInvocation) alias.getOccurrencePoint().getStatement()).getCalledMethodExecution();
				}
				break;
			case RETURN_VALUE:
				aliasList.add(0, alias);
				break;
			default:
				break;
		}
		System.out.println(alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo() + " : " + alias.getAliasType().toString());
	}

	@Override
	public void changeTrackingObject(String fromObjId, String toObjId) {
		System.out.println(fromObjId + " -> " + toObjId);
	}
	
	public Collection getAliasList() {
		return this.aliasList;
	}

}