/* * Copyright 2008 Wishnu Prasetya. * * This file is part of T2. * T2 is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License (GPL) as published by the * Free Software Foundation; either version 3 of the License, or any * later version. * * T2 is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * A copy of the GNU General Public License can be found in T2 distribution. * If it is missing, see http://www.gnu.org/licenses. */ package t2ext.trace.utils; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Hashtable; import java.util.LinkedList; import java.util.List; import java.util.TreeSet; import Sequenic.T2.Pool; import Sequenic.T2.Seq.Trace; import Sequenic.T2.Seq.TraceStep; import Sequenic.T2.Seq.UPDATE_FIELD; /** * @author Maaike Gerritsen */ public class TraceAnalysis { private Trace _trace; private List _methodNames; private Hashtable> _pathsPerMethod; private Hashtable> _specPathsPerMethod; private Pool _originalPool; private Object _originalTargetObj; private LinkedList _steps; private List _fields; private List _modifiedFields; private boolean _foundAllFields; public TraceAnalysis(Trace trace){ _trace = trace; _methodNames = new ArrayList(); _steps = new LinkedList(); _pathsPerMethod = new Hashtable>(); _specPathsPerMethod = new Hashtable>(); _fields = new ArrayList(); _modifiedFields = new ArrayList(); _foundAllFields = false; } public void setFields(List fields){ _fields = fields; } public List getFields(){ return _fields; } public void addToModifiedFields(Field field){ if(!_modifiedFields.contains(field)) _modifiedFields.add(field); } public boolean foundAllFields(){ return _foundAllFields; } public void addToSteps(TraceStep step, String methodName, Pool pool){ TraceStepAnalysis tsa = new TraceStepAnalysis(step); tsa.setMethodName(methodName); tsa.setPoolAndObject(pool, _trace.indexOfTargetObj); _steps.add(tsa); addToMethodNames(methodName); if(step instanceof UPDATE_FIELD){ UPDATE_FIELD updateField = (UPDATE_FIELD) step; addToModifiedFields(updateField.field); if(_modifiedFields.size()==_fields.size()) _foundAllFields = true; }else tsa.setModidfiedFields(_modifiedFields); } public void bla(){ System.out.println("B: "+_fields.size()+" "+_modifiedFields.size()); } public void setPathsForLastStep(List paths, String name, List specPaths){ _steps.getLast().setPathIds(paths); _steps.getLast().setSpecPathIds(specPaths); TreeSet list = _pathsPerMethod.get(name); TreeSet specList = _specPathsPerMethod.get(name); if(list==null) list = new TreeSet(); if(specList==null) specList = new TreeSet(); list.addAll(paths); specList.addAll(specPaths); _pathsPerMethod.put(name, list); _specPathsPerMethod.put(name, specList); } public TreeSet getPathsForMethod(String name){ return _pathsPerMethod.get(name); } public TreeSet getSpecPathsForMethod(String name){ return _specPathsPerMethod.get(name); } public LinkedList getSteps(){ return _steps; } public List getMethodNames(){ return _methodNames; } public Trace getTrace(){ return _trace; } private void addToMethodNames(String name){ _methodNames.add(name); } public Pool getPool() { return _originalPool; } public void setPool(Pool pool) { _originalPool = pool; } public Object getTargetObj() { return _originalTargetObj; } public void setTargetObj(Object targetObj) { _originalTargetObj = targetObj; } }