package org.ntlab.deltaViewer; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.IAliasCollector; import org.ntlab.deltaExtractor.ObjectIdPair; import org.ntlab.trace.MethodExecution; import org.ntlab.trace.MethodInvocation; /** * Collect delta aliases for MagnetRON. * * @author Nitta Lab. */ public class DeltaAliasCollector implements IAliasCollector { // Reverse execution order. private String srcObjId; private String dstObjId; private List<Alias> aliasList = new ArrayList<>(); private Map<Alias, ObjectIdPair> aliasToObjIdPairMap = new HashMap<>(); private Alias curAlias; 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); 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_ELEMENT: 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; } curAlias = alias; System.out.println(alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo() + " : " + alias.getAliasType().toString()); } @Override public void changeTrackingObject(String fromObjId, String toObjId, boolean isSrcSideChanged) { aliasToObjIdPairMap.put(curAlias, new ObjectIdPair(toObjId, fromObjId, isSrcSideChanged)); System.out.println(fromObjId + " -> " + toObjId + " " + isSrcSideChanged); } public List<Alias> getAliasList() { return this.aliasList; } public Map<Alias, ObjectIdPair> getAliasToObjectPair() { return aliasToObjIdPairMap; } public ObjectIdPair getObjectPairByAlias(Alias alias) { return aliasToObjIdPairMap.get(alias); } }