Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now, the calls to method reference are counted in the RFC metrics #58

Conversation

maykon-oliveira
Copy link
Contributor

@maykon-oliveira maykon-oliveira commented Apr 28, 2020

I disabled one test method, bc no works well.

(@mauricioaniche ) wrote in README.md that RFC fails when a method has overloads with same number of parameters, but different types.

So I disabled this test case, it should be 2, not 1, but I go to improve RFC metric.

@codecov
Copy link

codecov bot commented Apr 28, 2020

Codecov Report

Merging #58 into master will decrease coverage by 1.33%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #58      +/-   ##
============================================
- Coverage     75.16%   73.82%   -1.34%     
+ Complexity      933      887      -46     
============================================
  Files            42       40       -2     
  Lines          2158     2124      -34     
  Branches        256      252       -4     
============================================
- Hits           1622     1568      -54     
- Misses          388      412      +24     
+ Partials        148      144       -4     
Impacted Files Coverage Δ Complexity Δ
.../java/com/github/mauricioaniche/ck/metric/RFC.java 95.65% <100.00%> (-0.51%) 10.00 <3.00> (-1.00)
...n/java/com/github/mauricioaniche/ck/CKVisitor.java 63.21% <0.00%> (-4.23%) 292.00% <0.00%> (-32.00%)
.../github/mauricioaniche/ck/metric/CKASTVisitor.java 43.43% <0.00%> (-3.54%) 86.00% <0.00%> (-7.00%)
...a/com/github/mauricioaniche/ck/CKMethodResult.java 93.10% <0.00%> (-0.23%) 53.00% <0.00%> (-2.00%)
...com/github/mauricioaniche/ck/util/StringUtils.java
.../github/mauricioaniche/ck/metric/JavadocLines.java

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 317afa0...ec4a860. Read the comment docs.

Copy link
Owner

@mauricioaniche mauricioaniche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR!

Only a small catch that I think we can reuse a method that already exists to get the full name of the method.

src/main/java/com/github/mauricioaniche/ck/metric/RFC.java Outdated Show resolved Hide resolved
Copy link
Owner

@mauricioaniche mauricioaniche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @maykon-oliveira! I gave another review to the code, and I have a few extra comments!

src/test/java/com/github/mauricioaniche/ck/RFCTest.java Outdated Show resolved Hide resolved
}

@Test
@DisplayName("Counts the number of super methods invocations")
public void countSuperInvocations() {
CKClassResult a = report.get("rfc.GO3");
Assertions.assertEquals(2, a.getRfc());
}

@Test
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, if it's returning 2, it's because we are now able to differentiate it. Maybe the new method name function made the trick.

This is an exceptional test case, as a() is not available, so JDT has to guess things. Suggestion: make the assertion to 2 again, and just rename it to methodCallsToAMethodNotInTheProject, or something like that.

String method = JDTUtils.getMethodFullName(binding);
methodInvocations.add(method);
}

private String arguments(List<?> arguments) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method should disappear too!

import org.eclipse.jdt.core.dom.*;

import java.util.HashSet;
import java.util.List;

public class RFC implements CKASTVisitor, ClassLevelMetric, MethodLevelMetric {

private HashSet<String> methodInvocations = new HashSet<String>();
private final HashSet<String> methodInvocations = new HashSet<String>();

public void visit(MethodInvocation node) {
IMethodBinding binding = node.resolveMethodBinding();
count(node.getName() + "/" + arguments(node.arguments()), binding);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably use the getMethodFullName here too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauricioaniche JDTUtils#getMethodFullName not accept null values.

public void visit(MethodInvocation node) {
	IMethodBinding binding = node.resolveMethodBinding();
	count(node.getName()  + "/" + arguments(node.arguments()), binding);
}

Here, sometimes binding is null, so I cannot get method full name using JDTUtils#getMethodFullName

JDTUtils#getMethodFullName not accepts MethodInvocation type as argument.

binding is always null when method not belongs to class.

visit(ExpressionMethodReference node)

have same behavior

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, I think you should deal with the null case here, instead of duplicating code.

This is all about getting the name of the method, right? So, suggestion:

IMethodBinding binding = node.resolveMethodBinding();
String methodName = binding!=null ? JDTUtils.getMethodFullName(binding) : JDTUtils.getMethodFullName(node);

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about this.

I can to create a overload of JDTUtils#getMethodFullName that accepts MethodInvocation and ExpressionMethodReference types. And we can get rid of duplicating code.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me! If you need any help, let me know!

@maykon-oliveira
Copy link
Contributor Author

Hm, something went wrong

@mauricioaniche
Copy link
Owner

@maykon-oliveira shall I close this one and we reopen when you get back to this ?

@maykon-oliveira
Copy link
Contributor Author

Yes, ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants