Skip to content

Commit

Permalink
Ignores methods and constructors belonging to packages containing 'ja…
Browse files Browse the repository at this point in the history
…va.' - fix
  • Loading branch information
williamniemiec committed Feb 15, 2021
1 parent 9680f31 commit 7a07711
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 33 deletions.
Binary file added dist/6.x/ExecutionFlow_ConsoleExporter_v6.0.6.jar
Binary file not shown.
Binary file added dist/6.x/ExecutionFlow_FileExporter_v6.0.6.jar
Binary file not shown.
38 changes: 21 additions & 17 deletions src/executionflow/runtime/collector/MethodCallsCollector.aj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public aspect MethodCallsCollector extends RuntimeCollector {
// Join points
//-------------------------------------------------------------------------
before(): invokedSignature() {
if (isNativeMethod(thisJoinPoint) || !isValidSignature(thisJoinPoint))
if (isNativeMethod(getSignature(thisJoinPoint)) || !isValidSignature(thisJoinPoint))
return;

invoked = new InvokedInfo.Builder()
Expand All @@ -90,7 +90,7 @@ public aspect MethodCallsCollector extends RuntimeCollector {
}

before(): invokedMethodByTestedInvoker() {
if (!isMethod(thisJoinPoint) || isNativeMethod(thisJoinPoint) || (invoked == null))
if (!isMethod(thisJoinPoint) || isNativeMethod(getSignature(thisJoinPoint)) || (invoked == null))
return;

collectMethod(extractMethodCalledSignature(thisJoinPoint));
Expand All @@ -102,6 +102,10 @@ public aspect MethodCallsCollector extends RuntimeCollector {
//-------------------------------------------------------------------------
// Methods
//-------------------------------------------------------------------------
private String getSignature(JoinPoint jp) {
return jp.getSignature().toString();
}

private boolean isValidSignature(JoinPoint jp) {
String signature = jp.getSignature().toString();

Expand All @@ -124,21 +128,21 @@ public aspect MethodCallsCollector extends RuntimeCollector {
return jp.getKind().equals("method-call");
}

private String getSignature(JoinPoint jp) {
if (jp.getSignature().getName().contains("<init>"))
return jp.getSignature().getDeclaringTypeName();

StringBuilder signature = new StringBuilder();
Signature jpSignature = jp.getSignature();

signature.append(jp.getSignature().getDeclaringTypeName());
signature.append(".");
signature.append(jpSignature.getName());
signature.append(jpSignature.toString()
.substring(jpSignature.toString().indexOf("(")));

return signature.toString();
}
// private String getSignature(JoinPoint jp) {
// if (jp.getSignature().getName().contains("<init>"))
// return jp.getSignature().getDeclaringTypeName();
//
// StringBuilder signature = new StringBuilder();
// Signature jpSignature = jp.getSignature();
//
// signature.append(jp.getSignature().getDeclaringTypeName());
// signature.append(".");
// signature.append(jpSignature.getName());
// signature.append(jpSignature.toString()
// .substring(jpSignature.toString().indexOf("(")));
//
// return signature.toString();
// }

private String removeReturnTypeFromSignature(String signature) {
return signature.substring(signature.indexOf(' ') + 1);
Expand Down
14 changes: 7 additions & 7 deletions src/executionflow/runtime/collector/MethodCollector.aj
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public aspect MethodCollector extends RuntimeCollector {
return;

String key = generateKey(thisJoinPoint);

if (alreadyCollected(key))
return;

collectSourceAndBinaryPaths(thisJoinPoint);

if ((srcPath == null) || (classPath == null))
return;

collectMethod(thisJoinPoint, key);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ public aspect MethodCollector extends RuntimeCollector {
private boolean isValidState(JoinPoint jp) {
return (isStaticMethod(jp) || !constructorBelongsToTestMethod(jp))
&& isMethodSignature(jp)
&& !isNativeMethod(jp)
&& !isNativeMethod(signature)
&& !belongsToTestMethod(jp);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ public aspect MethodCollector extends RuntimeCollector {
.invocationLine(getInvocationLine(jp))
.build();
methodInfo.setConcreteMethodSignature(getConcreteMethodSignature(jp));

System.out.println("5");
storeCollector(jp, methodInfo);
collectedMethods.add(key);

Expand Down Expand Up @@ -294,11 +294,11 @@ public aspect MethodCollector extends RuntimeCollector {
}

private void storeCollector(JoinPoint jp, InvokedInfo methodInfo) {
if (methodCollector.containsKey(getInvocationLine(jp))) {
if (methodCollector.containsKey(getInvocationLine(jp))) {System.out.println("6");
List<InvokedContainer> list = methodCollector.get(getInvocationLine(jp));
list.add(new InvokedContainer(methodInfo, testMethodInfo));
}
else {
else { System.out.println("7");
List<InvokedContainer> list = new ArrayList<>();
list.add(new InvokedContainer(methodInfo, testMethodInfo));

Expand Down
14 changes: 6 additions & 8 deletions src/executionflow/runtime/collector/RuntimeCollector.aj
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,18 @@ public abstract aspect RuntimeCollector {
// Methods
//-------------------------------------------------------------------------
/**
* Checks whether a method signature belongs to a native Java method or
* Checks whether a signature belongs to a native Java method or
* if it is a JUnit method.
*
* @param methodSignature Signature of the method
* @param signature Signature to be analyzed
*
* @return If the method is a native method or JUnit method
*/
protected boolean isNativeMethod(JoinPoint jp) {
String signature = jp.getSignature().toString();

protected boolean isNativeMethod(String signature) {
return (signature == null)
|| signature.contains("java.")
|| signature.contains("jdk.")
|| signature.contains("org.junit.")
|| signature.matches("^java\\..+")
|| signature.matches("^jdk\\..+")
|| signature.contains("^org\\.junit\\..+")
|| signature.matches(".+(\\$|\\.)[0-9]+.+");
}

Expand Down
2 changes: 1 addition & 1 deletion src/executionflow/runtime/collector/TestMethodCollector.aj
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public aspect TestMethodCollector extends RuntimeCollector {
methodCollector
);
methodExecutionFlow.run();

ExecutionFlow constructorExecutionFlow = new ConstructorExecutionFlow(
processingManager,
constructorCollector.values()
Expand Down

0 comments on commit 7a07711

Please sign in to comment.