Plugins
xdry itself is programming language agnostic. To tell xdry, how it can detect clones on different levels, it needs language specific plugins.
Before using xdry, you have to either search, if there is already a plugin available for your programming language or implement your own plugin.
Requirements on plugins
There are a few mandatory requirements: 1. Plugin has to be callable via CLI (directly or via additional scripts or via Docker etc.) 2. Plugin takes a filepath as input and outputs normalized code in stdout
Normalization levels
There are different normalization levels, a plugin should support
Level 1
Level-1 normalization should remove all non-mandatory whitespaces and comments.
Consider the following code as an example
<?php
// This is the best class of the application!
class Foo
{
public function bar(
private int $bar,
private string $bas
): string
{
return "$bas: " . $bar * 100 + 20;
}
}
?>
This code should get normalized to
<?php class Foo { public function bar ( private int $bar, private string $bas ) : string { return "$bas: " . $bar * 100 + 20; } }
Level 2
Level-2 normalization should perform level-1 normalization and additionally normalize names and literals. For example, every classname should replaced with "Str", every function name with "str", every integer with 1 and so on.
Consider the following level-1 normalized code
<?php class Foo { public function bar ( private int $bar, private string $bas ) : string { return "$bas: " . $bar * 100 + 20; } }
This code should get normalized to
<?php class Str { public function str ( private int $x, private string $x ) : string { return "$x: " . $x * 1 + 1; } }