package org.ntlab.deltaViewer; import java.util.ArrayList; import java.util.List; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.Alias.AliasType; import org.ntlab.deltaExtractor.IAliasTracker; import org.ntlab.trace.MethodExecution; import org.ntlab.trace.MethodInvocation; import org.ntlab.trace.Statement; /** * Collect delta alias for MagnetRON.(Derived from DeltaAliasTracker.) * * @author Nitta Lab. */ public class DeltaAliasCollector implements IAliasTracker { // Reverse execution order. private List<Alias> aliasList = new ArrayList<>(); public DeltaAliasCollector() { } @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; } System.out.println(alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo() + " : " + alias.getAliasType().toString()); } @Override public List<Alias> getAliasList() { return this.aliasList; } /* * Don't write anything here. */ @Override public void changeTrackingObject(String from, String to, boolean isSrcSide) { } public void shrink() { // TODO Implement shrink(). List<Alias> standardMethodInvocations = collectStandardMethodInvocations(aliasList); List<List<Alias>> invocatoinChains = collectInvocatoinChains(standardMethodInvocations); replaceInvocatoinChains(aliasList, invocatoinChains); } private List<Alias> collectStandardMethodInvocations(List<Alias> aliasList) { // TODO Implement collectStandardMethodInvocations(). for (int i = 0; i < aliasList.size(); i++) { Alias alias = aliasList.get(i); if (alias.getAliasType() == AliasType.RECEIVER) { Statement st = alias.getOccurrencePoint().getStatement(); MethodInvocation methodInvocation = (MethodInvocation)st; if (methodInvocation.getCalledMethodExecution().isCollectionType()) { } } else if (alias.getAliasType() == AliasType.THIS) { if (alias.getMethodExecution().isCollectionType()) { } } else if (alias.getAliasType() == AliasType.RETURN_VALUE) { if (alias.getMethodExecution().isCollectionType()) { } } else if (alias.getAliasType() == AliasType.METHOD_INVOCATION) { Statement st = alias.getOccurrencePoint().getStatement(); MethodInvocation methodInvocation = (MethodInvocation)st; if (methodInvocation.getCalledMethodExecution().isCollectionType()) { } } } return null; } private List<List<Alias>> collectInvocatoinChains(List<Alias> standardMethodInvocations) { // TODO Implement collectInvocatoinChains(). return null; } private List<Alias> replaceInvocatoinChains(List<Alias> aliasList, List<List<Alias>> invocatoinChains) { // TODO Implement replaceInvocatoinChains(). return null; } }