| |
---|
| | import java.io.BufferedReader; |
---|
| | import java.io.FileReader; |
---|
| | import java.io.IOException; |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.Arrays; |
---|
| | import java.util.HashMap; |
---|
| | import java.util.HashSet; |
---|
| | import java.util.Iterator; |
---|
| | import java.util.LinkedHashMap; |
---|
| |
---|
| | |
---|
| | public static ArrayList<Alias> findAllStartAlias(MethodExecution me) { |
---|
| | ArrayList<Alias> startAliasList = new ArrayList<>(); |
---|
| | List<Statement> statements = me.getStatements(); |
---|
| | String[] primitives = {"byte", "short", "int", "long", "float", "double", "char", "boolean"}; |
---|
| | List<String> primitiveList = Arrays.asList(primitives); |
---|
| | for (int i = 0; i < statements.size(); i++) { |
---|
| | TracePoint tp = me.getTracePoint(i); |
---|
| | Statement statement = statements.get(i); |
---|
| | if (statement instanceof FieldAccess) { |
---|
| | FieldAccess fa = (FieldAccess)statement; |
---|
| | String objId = fa.getContainerObjId(); |
---|
| | if (!("0".equals(objId))) { |
---|
| | startAliasList.add(new Alias(objId, tp, Alias.OCCURRENCE_EXP_CONTAINER)); |
---|
| | if (objId != null && !(objId.equals("0")) && !(primitiveList.contains(fa.getContainerClassName()))) { |
---|
| | startAliasList.add(new Alias(objId, tp, Alias.OCCURRENCE_EXP_CONTAINER)); |
---|
| | } |
---|
| | objId = fa.getValueObjId(); |
---|
| | if ((!"0".equals(objId))) { |
---|
| | startAliasList.add(new Alias(objId, tp, Alias.OCCURRENCE_EXP_FIELD)); |
---|
| | if (objId != null && !(objId.equals("0")) && !(primitiveList.contains(fa.getValueClassName()))) { |
---|
| | startAliasList.add(new Alias(objId, tp, Alias.OCCURRENCE_EXP_FIELD)); |
---|
| | } |
---|
| | } else if (statement instanceof FieldUpdate) { |
---|
| | FieldUpdate fu = (FieldUpdate)statement; |
---|
| | String objId = fu.getContainerObjId(); |
---|
| | if ((!"0".equals(objId))) { |
---|
| | startAliasList.add(new Alias(objId, tp, Alias.OCCURRENCE_EXP_CONTAINER)); |
---|
| | if (objId != null && !(objId.equals("0")) && !(primitiveList.contains(fu.getContainerClassName()))) { |
---|
| | startAliasList.add(new Alias(objId, tp, Alias.OCCURRENCE_EXP_CONTAINER)); |
---|
| | } |
---|
| | objId = fu.getValueObjId(); |
---|
| | if ((!"0".equals(objId))) { |
---|
| | startAliasList.add(new Alias(objId, tp, Alias.OCCURRENCE_EXP_FIELD)); |
---|
| | if (objId != null && !(objId.equals("0")) && !(primitiveList.contains(fu.getValueClassName()))) { |
---|
| | startAliasList.add(new Alias(objId, tp, Alias.OCCURRENCE_EXP_FIELD)); |
---|
| | } |
---|
| | } else if (statement instanceof ArrayAccess) { |
---|
| | String valueObjId = ((ArrayAccess)statement).getValueObjectId(); |
---|
| | if (!("0".equals(valueObjId))) { |
---|
| | startAliasList.add(new Alias(valueObjId, tp, Alias.OCCURRENCE_EXP_ARRAY)); |
---|
| | } |
---|
| | ArrayAccess aa = (ArrayAccess)statement; |
---|
| | String valueObjId = aa.getValueObjectId(); |
---|
| | if (valueObjId != null && !(valueObjId.equals("0")) && !(primitiveList.contains(aa.getValueClassName()))) { |
---|
| | startAliasList.add(new Alias(valueObjId, tp, Alias.OCCURRENCE_EXP_ARRAY)); |
---|
| | } |
---|
| | } else if (statement instanceof ArrayUpdate) { |
---|
| | String valueObjId = ((ArrayUpdate)statement).getValueObjectId(); |
---|
| | if (!("0".equals(valueObjId))) { |
---|
| | startAliasList.add(new Alias(valueObjId, tp, Alias.OCCURRENCE_EXP_ARRAY)); |
---|
| | ArrayUpdate au = (ArrayUpdate)statement; |
---|
| | String valueObjId = au.getValueObjectId(); |
---|
| | if (valueObjId != null && !(valueObjId.equals("0")) && !(primitiveList.contains(au.getValueClassName()))) { |
---|
| | startAliasList.add(new Alias(valueObjId, tp, Alias.OCCURRENCE_EXP_ARRAY)); |
---|
| | } |
---|
| | } else if (statement instanceof ArrayCreate) { |
---|
| | String valueObjId = ((ArrayAccess)statement).getValueObjectId(); |
---|
| | if (!("0".equals(valueObjId))) { |
---|
| | startAliasList.add(new Alias(valueObjId, tp, Alias.OCCURRENCE_EXP_RETURN)); |
---|
| | ArrayCreate ac = (ArrayCreate)statement; |
---|
| | String arrayObjId = ac.getArrayObjectId(); |
---|
| | if (arrayObjId != null && !(arrayObjId.equals("0")) && !(primitiveList.contains(ac.getArrayClassName()))) { |
---|
| | startAliasList.add(new Alias(arrayObjId, tp, Alias.OCCURRENCE_EXP_RETURN)); |
---|
| | } |
---|
| | } else if (statement instanceof MethodInvocation) { |
---|
| | MethodExecution calledMe = ((MethodInvocation)statement).getCalledMethodExecution(); |
---|
| | String thisObjId = calledMe.getThisObjId(); |
---|
| | if (!("0".equals(thisObjId))) { |
---|
| | startAliasList.add(new Alias(thisObjId, tp, Alias.OCCURRENCE_EXP_RECEIVER)); |
---|
| | if (thisObjId != null && !(thisObjId.equals("0"))) { |
---|
| | startAliasList.add(new Alias(thisObjId, tp, Alias.OCCURRENCE_EXP_RECEIVER)); |
---|
| | } |
---|
| | List<ObjectReference> args = calledMe.getArguments(); |
---|
| | for (int j = 0; j < args.size(); j++) { |
---|
| | String argValueId = args.get(j).getId(); |
---|
| | if (!("0".equals(argValueId))) { |
---|
| | startAliasList.add(new Alias(argValueId, tp, (j + Alias.OCCURRENCE_EXP_FIRST_ARG))); |
---|
| | ObjectReference arg = args.get(j); |
---|
| | String argValueId = arg.getId(); |
---|
| | if (argValueId != null && !(argValueId.equals("0")) && !(primitiveList.contains(arg.getActualType()))) { |
---|
| | startAliasList.add(new Alias(argValueId, tp, (j + Alias.OCCURRENCE_EXP_FIRST_ARG))); |
---|
| | } |
---|
| | } |
---|
| | ObjectReference returnValue = calledMe.getReturnValue(); |
---|
| | if (returnValue != null) { |
---|
| | String returnValueId = returnValue.getId(); |
---|
| | if (!("0".equals(returnValueId))) { |
---|
| | if (returnValueId != null && !(returnValueId.equals("0") && !(primitiveList.contains(returnValue.getActualType())))) { |
---|
| | startAliasList.add(new Alias(returnValueId, tp, Alias.OCCURRENCE_EXP_RETURN)); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| |
---|
| | } |
---|
| | } |
---|
| | return aliasLists; |
---|
| | } |
---|
| | |
---|
| | public static int countMethodExecutionInTraceCollector(List<MethodExecution> methodExecutions, String targetSignature, int count, String indent) { |
---|
| | if (methodExecutions == null || methodExecutions.isEmpty()) { |
---|
| | return count; |
---|
| | } |
---|
| | for (int i = 0; i < methodExecutions.size(); i++) { |
---|
| | MethodExecution me = methodExecutions.get(i); |
---|
| | String signature = me.getSignature(); |
---|
| | // System.out.println(indent + signature); |
---|
| | if (targetSignature.equals(signature)) { |
---|
| | count++; |
---|
| | } |
---|
| | List<MethodExecution> children = me.getChildren(); |
---|
| | count = countMethodExecutionInTraceCollector(children, targetSignature, count, indent + "--------"); |
---|
| | } |
---|
| | return count; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |
前回のマージからいくつか変更と修正を加えました.
マージします.
2318a54
intomaster
fromobjectFlowGUI
on 11 Sep 2018