diff --git a/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/trace/TraceJSON.java b/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/trace/TraceJSON.java index 71608fc..bcaa443 100644 --- a/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/trace/TraceJSON.java +++ b/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/trace/TraceJSON.java @@ -4,6 +4,7 @@ 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; @@ -1001,61 +1002,67 @@ public static ArrayList findAllStartAlias(MethodExecution me) { ArrayList startAliasList = new ArrayList<>(); List statements = me.getStatements(); + String[] primitives = {"byte", "short", "int", "long", "float", "double", "char", "boolean"}; + List 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 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)); } } @@ -1157,4 +1164,21 @@ } return aliasLists; } + + public static int countMethodExecutionInTraceCollector(List 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 children = me.getChildren(); + count = countMethodExecutionInTraceCollector(children, targetSignature, count, indent + "--------"); + } + return count; + } }