Skip to content

Commit ab589ae

Browse files
committed
correction from copilot review
1 parent 898cfb6 commit ab589ae

6 files changed

Lines changed: 15 additions & 15 deletions

File tree

IA_description.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ Each unit test class checking rule implementation class has the same template of
5252
- usage of "CheckVerifier.verifyNoIssues" to check there is no issues raised
5353
- each call to "CheckVerifier" needs a test resource file : this one is the resource code file for the simulated analysis
5454

55-
each test resource file is in the "test/resources/checks" directory (or sub-directories).
55+
each test resource file is in the "src/test/files" directory (or sub-directories).
5656
each test resource file contains compliuant code or / and non compliant code.
57-
If there is no compliant code on which Sonarqube analysis should raise an issue, the line with the issue has a comment at the end of the line with the following template :
58-
"# Noncompliant {{ERROR_MESSAGE_TO_DISPLAY}}"
57+
If there is non compliant code on which Sonarqube analysis should raise an issue, the line with the issue has a comment at the end of the line with the following template :
58+
"// Noncompliant {{ERROR_MESSAGE_TO_DISPLAY}}"
5959
- the "ERROR_MESSAGE_TO_DISPLAY" in the previous template is replaced by the real error message.
60-
- this comment give the information to "CheckVerifier", the simulation tool, that an error is expected at this line
60+
- this comment gives the information to "CheckVerifier", the simulation tool, that an error is expected at this line
6161

6262
Integration Tests Implementation Structure
6363
---

IA_rule.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ Use the TDD (Test-Driven Development) methodology to implement a rule in an effi
1313
- Non-compliant code
1414
- Code with elements that should not be analyzed
1515
- Location of test resource files:
16-
- Files for unit tests: in "test/resources/checks" or subdirectories
16+
- Files for unit tests: in "src/test/files" or subdirectories
1717
- Files for integration tests: in "src/it/test-projects" or subdirectories
1818
- Create the rule implementation class in the package "org.greencodeinitiative.creedengo.java.checks"
1919
- Add the "Rule" annotation with the correct rule id (the rule is previously defined in another maven component named "creedengo-rules-specifications")
2020
- Extend the "IssuableSubscriptionVisitor" class
21-
- Implement the "initialize" method which will be used to declare the AST node types to analyze in depth but leave it empty for now
21+
- Override the "nodesToVisit", "visitNode" and (optionally) "leaveNode" methods, which will be used respectively to declare the AST node types to analyze in depth and to implement the analysis logic, but leave their bodies empty for now
2222
- Create the rule unit test class in the package "org.greencodeinitiative.creedengo.java.checks"
2323
- Verify that unit tests fail with non-compliant test resources
2424

2525
## STEP 2: Implement the rule + unit test validation
2626
- Implement the rule in the implementation class created in step 1
27-
- Implement the "initialize" method to declare the AST node types to analyze in depth
27+
- Implement the "nodesToVisit" method to declare the AST node types to analyze in depth and implement the "visitNode" and, if needed, "leaveNode" methods to perform the analysis on those nodes
2828
- Implement private methods to analyze in depth the declared AST nodes and raise issues if needed
29-
- Verify that unit tests pass with both compliant and non-compliant test resources
29+
- Verify that unit tests pass with both compliant and non-compliant test resources, and call them from "visitNode"/"leaveNode"
3030

3131
## STEP 3: Implement integration tests
3232
- Add a test method in the integration class "GCIRulesIT" for the implemented rule using the same pattern as other existing test methods

src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void testGCI76_good() {
408408
void testGCI79() {
409409
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java";
410410
String ruleId = "creedengo-java:GCI79";
411-
String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface.";
411+
String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface.";
412412
int[] startLines = new int[]{23};
413413
int[] endLines = new int[]{36};
414414

src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void foo2() throws IOException {
3737
}
3838

3939
/**
40-
* The first methods adds a "try" in the stack used to follow if the code is in a try
40+
* The first method adds a "try" in the stack used to follow if the code is in a try
4141
*/
4242
public void callingMethodWithTheTry() throws IOException {
4343
try { // Compliant
@@ -48,7 +48,7 @@ public void callingMethodWithTheTry() throws IOException {
4848
}
4949

5050
/**
51-
* The "try" should have been poped from the stack before entering here
51+
* The "try" should have been popped from the stack before entering here
5252
*/
5353
private void calledMethodWithoutTry() throws IOException {
5454
FileWriter myWriter = new FileWriter("somefilepath");

src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class FreeResourcesOfAutoCloseableInterface extends IssuableSubscriptionV
5656
private final Deque<TryStatementContext> tryStack = new ArrayDeque<>();
5757

5858
private static final String JAVA_LANG_AUTOCLOSEABLE = "java.lang.AutoCloseable";
59-
protected static final String MESSAGE_RULE = "try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface.";
59+
protected static final String MESSAGE_RULE = "try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface.";
6060

6161
@Override
6262
@ParametersAreNonnullByDefault

src/test/files/FreeResourcesOfAutoCloseableInterface.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void foo1() {
3535

3636
public void foo2() {
3737
String fileName = "./FreeResourcesOfAutoCloseableInterface.java";
38-
try { // Noncompliant {{try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface.}}
38+
try { // Noncompliant {{try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface.}}
3939
FileReader fr = new FileReader(fileName);
4040
BufferedReader br = new BufferedReader(fr);
4141
System.out.printl(br.readLine());
@@ -52,7 +52,7 @@ public void foo2() {
5252
}
5353

5454
/**
55-
* The first methods adds a "try" in the stack used to follow if the code is in a try
55+
* The first method adds a "try" in the stack used to follow if the code is in a try
5656
*/
5757
public void callingMethodWithTheTry() throws IOException {
5858
try { // Compliant
@@ -63,7 +63,7 @@ public void callingMethodWithTheTry() throws IOException {
6363
}
6464

6565
/**
66-
* The "try" should have been poped from the stack before entering here
66+
* The "try" should have been popped from the stack before entering here
6767
*/
6868
private void calledMethodWithoutTry() throws IOException {
6969
FileWriter myWriter = new FileWriter("somefilepath");

0 commit comments

Comments
 (0)