-
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathJavaCheckRegistrar.java
More file actions
79 lines (73 loc) · 3.12 KB
/
Copy pathJavaCheckRegistrar.java
File metadata and controls
79 lines (73 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java;
import fr.greencodeinitiative.java.checks.*;
import org.sonar.plugins.java.api.CheckRegistrar;
import org.sonar.plugins.java.api.JavaCheck;
import org.sonarsource.api.sonarlint.SonarLintSide;
import java.util.Collections;
import java.util.List;
/**
* Provide the "checks" (implementations of rules) classes that are going be executed during
* source code analysis.
* <p>
* This class is a batch extension by implementing the {@link org.sonar.plugins.java.api.CheckRegistrar} interface.
*/
@SonarLintSide
public class JavaCheckRegistrar implements CheckRegistrar {
private static final List<Class<? extends JavaCheck>> ANNOTATED_RULE_CLASSES = List.of(
ArrayCopyCheck.class,
IncrementCheck.class,
AvoidUsageOfStaticCollections.class,
AvoidGettingSizeCollectionInLoop.class,
AvoidRegexPatternNotStatic.class,
NoFunctionCallWhenDeclaringForLoop.class,
AvoidStatementForDMLQueries.class,
AvoidSpringRepositoryCallInLoopOrStreamCheck.class,
AvoidSQLRequestInLoop.class,
AvoidFullSQLRequest.class,
OptimizeReadFileExceptions.class,
InitializeBufferWithAppropriateSize.class,
AvoidSetConstantInBatchUpdate.class,
FreeResourcesOfAutoCloseableInterface.class,
AvoidMultipleIfElseStatement.class,
AvoidEnergyConsumingMethods.class,
MakeNonReassignedVariablesConstants.class,
ForceLazyFetchTypeForJPA.class
);
/**
* Register the classes that will be used to instantiate checks during analysis.
*/
@Override
public void register(RegistrarContext registrarContext) {
// Call to registerClassesForRepository to associate the classes with the correct repository key
registrarContext.registerClassesForRepository(JavaRulesDefinition.REPOSITORY_KEY, checkClasses(), testCheckClasses());
}
/**
* Lists all the main checks provided by the plugin
*/
public static List<Class<? extends JavaCheck>> checkClasses() {
return ANNOTATED_RULE_CLASSES;
}
/**
* Lists all the test checks provided by the plugin
*/
public static List<Class<? extends JavaCheck>> testCheckClasses() {
return Collections.emptyList();
}
}