Skip to content

added ccmCalculus especially to find ncc value for ccm metric. The lo…#548

Open
starkda wants to merge 57 commits into
cqfn:masterfrom
starkda:ccmCalculus
Open

added ccmCalculus especially to find ncc value for ccm metric. The lo…#548
starkda wants to merge 57 commits into
cqfn:masterfrom
starkda:ccmCalculus

Conversation

@starkda

@starkda starkda commented Mar 20, 2024

Copy link
Copy Markdown
Contributor

…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.

…gic that finds connected components not implemented yet.
@starkda

starkda commented Mar 20, 2024

Copy link
Copy Markdown
Contributor Author

@yegor256 please review

@yegor256

Copy link
Copy Markdown
Member

@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()
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
);
).affirm();

*
* @since 0.30.9
*/
public final class CcmXslCalculus implements Calculus {

Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

@starkda as implementation is not completed, all things that are not completed should be in @todo puzzle in the code, not in PR. Pull request will be closed and all future plans from it will not be accessible for anybody, but their must be.

@starkda

starkda commented Mar 21, 2024

Copy link
Copy Markdown
Contributor Author

@pnatashap please review

@starkda starkda requested a review from pnatashap March 21, 2024 22:07
@pnatashap

Copy link
Copy Markdown
Contributor

@starkda looks like some loop is possible, test for macos with jdk 11 failed due time-out (6 hours)

@pnatashap

Copy link
Copy Markdown
Contributor

@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.
And I do not see any huge problem to calculate it inside of xsl: all information about methods and attribute usage, so using call-template with parameters looks like possible to divide it into the groups. Even if we can not calculate something in xsl, we can calculate it and pass as a parameter to XSL, because reading all this xml document transformation is really very difficult.

@starkda

starkda commented Mar 22, 2024

Copy link
Copy Markdown
Contributor Author

@starkda looks like some loop is possible, test for macos with jdk 11 failed due time-out (6 hours)

@pnatashap I guess it is not problem from the changes i made. I effectively changed nothing, but now it works

@starkda

starkda commented Mar 22, 2024

Copy link
Copy Markdown
Contributor Author

@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. And I do not see any huge problem to calculate it inside of xsl: all information about methods and attribute usage, so using call-template with parameters looks like possible to divide it into the groups. Even if we can not calculate something in xsl, we can calculate it and pass as a parameter to XSL, because reading all this xml document transformation is really very difficult.

@pnatashap,

  1. You're right. I'll add more test in further pull request(I've added puzzle in code for more tests)
  2. That's what i did: we cannot calculate number of connected components(ncc) in xsl so I passed it as a parameter. Yet it looks terrifying I guess that's the best option, I wish I could delegate some steps to xsl, but the problem in very last step: running dfs.

@pnatashap pnatashap left a comment

Copy link
Copy Markdown
Contributor

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

* @param skeleton XML Skeleton
* @return XML with fixed NCC.
*/
@SuppressWarnings("PMD.UnusedPrivateMethod")

Copy link
Copy Markdown
Contributor

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,

Copy link
Copy Markdown
Contributor

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()

Copy link
Copy Markdown
Contributor

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");

Copy link
Copy Markdown
Contributor

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,

Copy link
Copy Markdown
Contributor

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.

@pnatashap

Copy link
Copy Markdown
Contributor

@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

@pnatashap

pnatashap commented Mar 23, 2024

Copy link
Copy Markdown
Contributor

@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)

@starkda

starkda commented Mar 23, 2024

Copy link
Copy Markdown
Contributor Author

@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

@pnatashap

Copy link
Copy Markdown
Contributor

@starkda for fix nc calculation you just need to add one more condition in if and that it.
variables in xsl can not be changed, but you can call template with any value that you need. I still agree with this comment #523 (comment)

@starkda

starkda commented Mar 29, 2024

Copy link
Copy Markdown
Contributor Author

@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

@pnatashap

Copy link
Copy Markdown
Contributor

@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

@starkda

starkda commented Apr 1, 2024

Copy link
Copy Markdown
Contributor Author

@pnatashap please review.
hope it more readeable now.
To find components i used union find instead of dfs

Comment thread src/main/java/org/jpeek/calculus/java/Ccm.java Outdated
Comment thread src/main/java/org/jpeek/calculus/java/Ccm.java Outdated
Comment thread src/main/java/org/jpeek/calculus/java/Ccm.java Outdated
Comment thread src/main/java/org/jpeek/calculus/java/Ccm.java Outdated
try {
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument();
final Element meta = doc.createElement("meta");

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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

Comment thread src/main/java/org/jpeek/calculus/java/Ccm.java Outdated
@starkda

starkda commented Apr 2, 2024

Copy link
Copy Markdown
Contributor Author

@pnatashap please review

try {
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument();
final Element meta = doc.createElement("meta");

Copy link
Copy Markdown
Contributor

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

Comment thread src/main/java/org/jpeek/calculus/java/Ccm.java Outdated
@starkda

starkda commented Apr 4, 2024

Copy link
Copy Markdown
Contributor Author

@pnatashap please review
I've put Union-Find into separate class. I've also created separate package for it, as i did not find suitable place for it.
Graph package is not a good place for it i think, as it is related to xml.

@starkda starkda requested a review from pnatashap April 6, 2024 15:38

@pnatashap pnatashap left a comment

Copy link
Copy Markdown
Contributor

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()));

Copy link
Copy Markdown
Contributor

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()

Copy link
Copy Markdown
Contributor

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.

<xsl:value-of select="$other/@name"/>
</method>
</edge>
<edge>

Copy link
Copy Markdown
Contributor

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

@starkda starkda requested a review from pnatashap April 18, 2024 15:57
@starkda

starkda commented Apr 18, 2024

Copy link
Copy Markdown
Contributor Author

@pnatashap I re-implemented CcmCalculus using XmlGraph. I also added several xsl files to add meta information without in-code xml modification.
XmlGraph implementation has some bugs, so it does not always give correct ncc.

@yegor256

Copy link
Copy Markdown
Member

This pull request has merge conflicts. Please rebase it on the default branch to resolve them so it can be merged.

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.

Problem with CCM metric addition

3 participants