added ccmCalculus especially to find ncc value for ccm metric. The lo…#548
added ccmCalculus especially to find ncc value for ccm metric. The lo…#548starkda wants to merge 57 commits into
Conversation
…gic that finds connected components not implemented yet.
|
@yegor256 please review |
|
@pnatashap can you please take a look? |
| "Must have 2 ncc vars", | ||
| result.xpath("/metric/app/package/class/vars/var[@id=\'ncc\']/text()").size() == 2, | ||
| new IsTrue() | ||
| ); |
There was a problem hiding this comment.
| ); | |
| ).affirm(); |
| * | ||
| * @since 0.30.9 | ||
| */ | ||
| public final class CcmXslCalculus implements Calculus { |
There was a problem hiding this comment.
There is an existing class https://github.com/cqfn/jpeek/blob/master/src/main/java/org/jpeek/calculus/java/Ccm.java for this metric. I do not see any reason for the new class.
| new UncheckedText( | ||
| new TextOf( | ||
| new ResourceOf( | ||
| new FormattedText("org/jpeek/metrics/%s.xsl", metric) |
There was a problem hiding this comment.
Please take a look in referenced class implementation, only CMM metric should be allowed
|
@pnatashap please review |
|
@starkda looks like some loop is possible, test for macos with jdk 11 failed due time-out (6 hours) |
|
@starkda It would be better if you create all required tests with manually calculated metrics (ccm and all parts inside) to understands what we want to achieve. (should be with one connectivity component inside, with several of them, with and without constructor inside). This will really add some value for the next steps. |
@pnatashap I guess it is not problem from the changes i made. I effectively changed nothing, but now it works |
|
pnatashap
left a comment
There was a problem hiding this comment.
As we have am example with invalid metric calculation, so it is better to create a tests (in disabled status) to highlight all situations that we need to cover. After that we can start working on fixing
| * @param skeleton XML Skeleton | ||
| * @return XML with fixed NCC. | ||
| */ | ||
| @SuppressWarnings("PMD.UnusedPrivateMethod") |
There was a problem hiding this comment.
really bed suppression, method is not used and confusing for all, why do we need it
| ) | ||
| ) | ||
| ).asString(), | ||
| Sources.DUMMY, |
There was a problem hiding this comment.
not clear why do we need to apply xsl for dymmy sources, while ccm contains 5 columns for now and we have a problem with 2 of them only
https://user-images.githubusercontent.com/63350301/117303386-4ff0da00-ae85-11eb-82c3-869f1a66521d.png
| builder = factory.newDocumentBuilder(); | ||
| doc = builder.newDocument(); | ||
| final Element meta = doc.createElement("meta"); | ||
| Node packages = skeleton.node().getFirstChild().getFirstChild().getNextSibling() |
There was a problem hiding this comment.
Really near to impossible to support this code, I can not remember the order of the nodes in XML and nobody wants, that's why there are a lot of ways to work with XML using XSL, XPATH, tag names.
If you walk with order only, your code will be broken by any sceleton structure changes.
| final Node id = map.getNamedItem("id"); | ||
| root.setAttribute("id", id.getNodeValue()); | ||
| final Integer value = 1; | ||
| final Element ncc = doc.createElement("ncc"); |
There was a problem hiding this comment.
not only ncc metric should be presented, you can check current implementation
https://user-images.githubusercontent.com/63350301/117303386-4ff0da00-ae85-11eb-82c3-869f1a66521d.png
| ).affirm(); | ||
| new Assertion<>( | ||
| "Must have 2 ncc vars", | ||
| result.xpath("/metric/app/package/class/vars/var[@id=\'ncc\']/text()").size() == 2, |
There was a problem hiding this comment.
While we have a specific problem with specific class, lets create a tests to check metric values, not just their existing.
|
@starkda you have already one example for the test in issue, it is very easy to add a test for it. all other code does not bring anything usefull in the project, just brake existing even more |
|
@starkda I've added a tests and find an issue with nc calculation. It is definitely can be solved in xsl (and the issue with build freezing is also solved) |
|
@pnatashap could you please elaborate how it can be made in xsl. Any approach requires to change state while xsl variables can not be changed after initialization |
|
@starkda for fix nc calculation you just need to add one more condition in if and that it. |
…gic that finds connected components not implemented yet.
|
@pnatashap what about returning to my initial approach and use java instead of xsl to calculate ncc? I suppose the main problem with heap overflow can not be solved anyway. Such solution eats a lot of memory and may not be acceptable for more or less big repos |
|
@starkda you can try to calculate it, not just add a comment, that it should be calculated here, as we have already a task to calculate it properly |
|
@pnatashap please review. |
| try { | ||
| final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() | ||
| .newDocument(); | ||
| final Element meta = doc.createElement("meta"); |
There was a problem hiding this comment.
it is not required to change XML document and add some data, it is easier to call XSL with parameter, so you need to read ncc value in XSL and use it.
There was a problem hiding this comment.
You do not understand, we can run XSL for class skeleton with parameter cmm, so we do not need to create package and all others inside, as all this arledy implemented and can be changed in case if it is needed in xsl using common way. it is absolutely not readable in code, xsl is much clear
|
@pnatashap please review |
| try { | ||
| final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() | ||
| .newDocument(); | ||
| final Element meta = doc.createElement("meta"); |
There was a problem hiding this comment.
You do not understand, we can run XSL for class skeleton with parameter cmm, so we do not need to create package and all others inside, as all this arledy implemented and can be changed in case if it is needed in xsl using common way. it is absolutely not readable in code, xsl is much clear
|
@pnatashap please review |
pnatashap
left a comment
There was a problem hiding this comment.
Still not clear to support
| clazz.toString() | ||
| ).toString() | ||
| final Element ncc = doc.createElement("ncc"); | ||
| ncc.appendChild(doc.createTextNode(calculateComponents(clazz, params).toString())); |
There was a problem hiding this comment.
Now incapsulation is better, but according to OOP we should have
ncc.appendChild(doc.createTextNode(new GraphClass(clazz, params).components().lenght().toString()));
and all other calculations should be inside of that class
| Ccm.updateNcc(skeleton, pack, clazz); | ||
| private static XML addMetaInformation(final XML skeleton, final Map<String, Object> params) { | ||
| try { | ||
| final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() |
There was a problem hiding this comment.
I do not understand why you ignore the comment below. This part of the code is very difficult to support. You can add child element to the class without coping all this structure.
| <xsl:value-of select="$other/@name"/> | ||
| </method> | ||
| </edge> | ||
| <edge> |
There was a problem hiding this comment.
this should be reverted as I understand
|
@pnatashap I re-implemented CcmCalculus using XmlGraph. I also added several xsl files to add meta information without in-code xml modification. |
|
This pull request has merge conflicts. Please rebase it on the default branch to resolve them so it can be merged. |
…gic that finds connected components not implemented yet.
one of pull requests that resolve #522
In this pr I've added separate calculus that would be used to find CCM metrics. It would traverse over existing XML skeleton, and add . NCC it is not calculated yet, it is always 1. In further prs I would add logic for it and sligthly modify CCM.xsl to capture ncc from skeleton.