-
Notifications
You must be signed in to change notification settings - Fork 81
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
added ccmCalculus especially to find ncc value for ccm metric. The lo… #548
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
); | |
).affirm(); |
* | ||
* @since 0.30.9 | ||
*/ | ||
public final class CcmXslCalculus implements Calculus { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -68,6 +84,7 @@ public XML node( | |||
* @param skeleton XML Skeleton | |||
* @return XML with fixed NCC. | |||
*/ | |||
@SuppressWarnings("PMD.UnusedPrivateMethod") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
<xsl:for-each select="$methods"> | ||
<xsl:variable name="method" select="."/> | ||
<node id="{$method/@name}"> | ||
<xsl:for-each select="$edges/edge[method[1]/text() = $method/@name]"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<xsl:for-each select="$edges/edge[method[1]/text() = $method/@name]"> | |
<xsl:for-each select="$edges/edge[method/text() = $method/@name]"> |
<node id="{$method/@name}"> | ||
<xsl:for-each select="$edges/edge[method[1]/text() = $method/@name]"> | ||
<edge> | ||
<xsl:value-of select="method[2]/text()"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<xsl:value-of select="method[2]/text()"/> | |
<xsl:value-of select="method[text() != $method/@name]/text()"/> |
<xsl:for-each select="$edges/edge[method[1]/text() = $method/@name]"> | ||
<edge> | ||
<xsl:value-of select="method[2]/text()"/> | ||
</edge> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If apply two changes below, then you do not need to duplicate edges
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -56,13 +61,21 @@ SOFTWARE. | |||
<xsl:value-of select="$other/@name"/> | |||
</method> | |||
</edge> | |||
<edge> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
…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.