32
32
33
33
import eu .solven .cleanthat .formatter .ISourceCodeFormatter ;
34
34
import eu .solven .cleanthat .formatter .LineEnding ;
35
- import eu .solven .cleanthat .github .CleanthatJavaProcessorProperties ;
36
35
import eu .solven .cleanthat .language .ILanguageProperties ;
37
36
import eu .solven .cleanthat .rules .CreateTempFilesUsingNio ;
38
37
import eu .solven .cleanthat .rules .EnumsWithoutEquals ;
39
38
import eu .solven .cleanthat .rules .IJdkVersionConstants ;
40
39
import eu .solven .cleanthat .rules .ModifierOrder ;
41
40
import eu .solven .cleanthat .rules .OptionalNotEmpty ;
42
41
import eu .solven .cleanthat .rules .PrimitiveBoxedForString ;
42
+ import eu .solven .cleanthat .rules .UseDiamondOperator ;
43
+ import eu .solven .cleanthat .rules .UseDiamondOperatorJdk8 ;
43
44
import eu .solven .cleanthat .rules .UseIsEmptyOnCollections ;
44
45
import eu .solven .cleanthat .rules .VariableEqualsConstant ;
45
46
import eu .solven .cleanthat .rules .meta .IClassTransformer ;
@@ -56,28 +57,49 @@ public class RulesJavaMutator implements ISourceCodeFormatter {
56
57
private static final Logger LOGGER = LoggerFactory .getLogger (RulesJavaMutator .class );
57
58
58
59
private final ILanguageProperties languageProperties ;
59
- private final CleanthatJavaProcessorProperties properties ;
60
+ private final JavaRulesMutatorProperties properties ;
60
61
61
62
private static final List <IClassTransformer > ALL_TRANSFORMERS = Arrays .asList (new CreateTempFilesUsingNio (),
62
63
new EnumsWithoutEquals (),
63
64
new PrimitiveBoxedForString (),
64
65
new OptionalNotEmpty (),
65
66
new ModifierOrder (),
66
- // new UseDiamondOperator(),
67
- // new UseDiamondOperatorJdk8(),
67
+ new UseDiamondOperator (),
68
+ new UseDiamondOperatorJdk8 (),
68
69
new UseIsEmptyOnCollections (),
69
70
new VariableEqualsConstant ());
70
71
71
72
private final List <IClassTransformer > transformers ;
72
73
73
- public RulesJavaMutator (ILanguageProperties languageProperties , CleanthatJavaProcessorProperties properties ) {
74
+ public RulesJavaMutator (ILanguageProperties languageProperties , JavaRulesMutatorProperties properties ) {
74
75
this .languageProperties = languageProperties ;
75
76
this .properties = properties ;
76
77
77
78
VersionWrapper languageVersion = new VersionWrapper (languageProperties .getLanguageVersion ());
79
+
80
+ List <String > excludedRules = properties .getExcluded ();
81
+ boolean productionReadyOnly = properties .isProductionReadyOnly ();
82
+
78
83
this .transformers = ALL_TRANSFORMERS .stream ().filter (ct -> {
79
84
VersionWrapper transformerVersion = new VersionWrapper (ct .minimalJavaVersion ());
80
85
return languageVersion .compareTo (transformerVersion ) >= 0 ;
86
+ }).filter (ct -> {
87
+ boolean isExclusion = excludedRules .stream ()
88
+ .filter (excludedRule -> ct .getIds ().contains (excludedRule ))
89
+ .findAny ()
90
+ .isPresent ();
91
+
92
+ if (isExclusion ) {
93
+ LOGGER .info ("We exclude '{}'" , ct .getIds ());
94
+ }
95
+
96
+ return !isExclusion ;
97
+ }).filter (ct -> {
98
+ if (!productionReadyOnly ) {
99
+ return true ;
100
+ } else {
101
+ return ct .isProductionReady ();
102
+ }
81
103
}).collect (Collectors .toList ());
82
104
83
105
this .transformers .forEach (ct -> {
0 commit comments