diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a688cf3..3e00672b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
- upgrade JDK from 11 to 17
- [#4](https://github.com/green-code-initiative/creedengo-java/issues/4) Improvement: "++i" statement is not so bad
+- huge refacto to have all the test files in the same place, to avoid maintaining 2...
### Deleted
diff --git a/pom.xml b/pom.xml
index ae43a190..f3d069ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -236,6 +236,11 @@
org.apache.maven.plugins
maven-surefire-plugin
3.5.2
+
+
+ src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks
+
+
org.jacoco
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index 3a51b723..4308202b 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -33,20 +33,20 @@ void testGCI27() {
String ruleId = "creedengo-java:GCI27";
String ruleMsg = "Use System.arraycopy to copy arrays";
int[] startLines = new int[]{
- 51, 56, 63, 72, 85, 94,
- 105, 116, 139, 145, 153, 163,
- 177, 187, 199, 211, 229, 236,
- 245, 256, 271, 282, 295, 308,
- 334, 341, 350, 361, 376, 389,
- 415, 422, 431, 442, 457, 470
+ 68, 73, 80, 89, 102, 111,
+ 122, 133, 156, 162, 170, 180,
+ 194, 204, 216, 228, 246, 253,
+ 262, 273, 288, 299, 312, 325,
+ 351, 358, 367, 378, 393, 406,
+ 432, 439, 448, 459, 474, 487
};
int[] endLines = new int[]{
- 53, 60, 69, 82, 91, 102,
- 113, 124, 141, 149, 159, 173,
- 183, 195, 207, 219, 232, 241,
- 252, 267, 278, 291, 304, 317,
- 337, 346, 357, 372, 385, 398,
- 418, 427, 438, 453, 466, 479
+ 70, 77, 86, 99, 108, 119,
+ 130, 141, 158, 166, 176, 190,
+ 200, 212, 224, 236, 249, 258,
+ 269, 284, 295, 308, 321, 334,
+ 354, 363, 374, 389, 402, 415,
+ 435, 444, 455, 470, 483, 496
};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
@@ -57,8 +57,8 @@ void testGCI27() {
void testGCI74() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java";
- int[] startLines = new int[]{8, 12, 17, 23};
- int[] endLines = new int[]{8, 12, 17, 23};
+ int[] startLines = new int[]{25, 29, 34, 40};
+ int[] endLines = new int[]{25, 29, 34, 40};
String ruleId = "creedengo-java:GCI74";
String ruleMsg = "Don't use the query SELECT * FROM";
@@ -83,8 +83,8 @@ void testGCI3_forEachLoopIgnored() {
void testGCI3_forLoopBad() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
- int[] startLines = new int[]{13};
- int[] endLines = new int[]{13};
+ int[] startLines = new int[]{30};
+ int[] endLines = new int[]{30};
String ruleId = "creedengo-java:GCI3";
String ruleMsg = "Avoid getting the size of the collection in the loop";
@@ -122,8 +122,8 @@ void testGCI3_forLoopIgnored() {
void testGCI3_whileLoopBad() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java";
- int[] startLines = new int[]{17};
- int[] endLines = new int[]{17};
+ int[] startLines = new int[]{34};
+ int[] endLines = new int[]{34};
String ruleId = "creedengo-java:GCI3";
String ruleMsg = "Avoid getting the size of the collection in the loop";
@@ -163,17 +163,17 @@ void testGCI2() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java";
int[] startLines = new int[]{
- 24, 43, 45, 71, 88, 110,
- 112, 131, 135, 137, 158, 164,
- 190, 209, 212, 214, 211, 236,
- 257, 259
+ 41, 60, 62, 88, 105, 127,
+ 129, 148, 152, 154, 175,
+ 181, 207, 226, 228, 229,
+ 231, 253, 274, 276
};
int[] endLines = new int[]{
- 24, 43, 47, 71, 90, 110,
- 114, 133, 135, 139, 160, 166,
- 192, 209, 212, 216, 217, 238,
- 257, 261
+ 41, 60, 64, 88, 107, 127,
+ 131, 150, 152, 156, 177,
+ 183, 209, 226, 234, 229,
+ 233, 255, 274, 278
};
String ruleId = "creedengo-java:GCI2";
@@ -251,8 +251,8 @@ void testGCI2_noIssue() {
void testGCI77_invalid() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java";
- int[] startLines = new int[]{8};
- int[] endLines = new int[]{8};
+ int[] startLines = new int[]{25};
+ int[] endLines = new int[]{25};
String ruleId = "creedengo-java:GCI77";
String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
@@ -304,20 +304,20 @@ void testGCI78() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java";
int[] startLines = new int[]{
- 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 44, 45,
- 46, 61, 63, 64, 65, 66,
- 67, 70, 86, 88, 90, 91,
- 92, 93, 94, 96, 114, 116,
- 117, 118, 119, 120, 121, 123
+ 51, 52, 53, 54, 55, 56,
+ 57, 58, 59, 60, 61, 62,
+ 63, 78, 80, 81, 82, 83,
+ 84, 87, 103, 105, 107, 108,
+ 109, 110, 111, 113, 131, 133,
+ 134, 135, 136, 137, 138, 140
};
int[] endLines = new int[]{
- 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 44, 45,
- 46, 61, 63, 64, 65, 66,
- 67, 70, 86, 88, 90, 91,
- 92, 93, 94, 96, 114, 116,
- 117, 118, 119, 120, 121, 123
+ 51, 52, 53, 54, 55, 56,
+ 57, 58, 59, 60, 61, 62,
+ 63, 78, 80, 81, 82, 83,
+ 84, 87, 103, 105, 107, 108,
+ 109, 110, 111, 113, 131, 133,
+ 134, 135, 136, 137, 138, 140
};
String ruleId = "creedengo-java:GCI78";
String ruleMsg = "Avoid setting constants in batch update";
@@ -363,8 +363,8 @@ void testGCI72() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java";
String ruleId = "creedengo-java:GCI72";
String ruleMsg = "Avoid SQL request in loop";
- int[] startLines = new int[]{57, 88, 119};
- int[] endLines = new int[]{57, 88, 119};
+ int[] startLines = new int[]{74, 105, 136};
+ int[] endLines = new int[]{74, 105, 136};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN);
}
@@ -374,8 +374,8 @@ void testGCI5() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java";
String ruleId = "creedengo-java:GCI5";
String ruleMsg = "You must not use Statement for a DML query";
- int[] startLines = new int[]{18};
- int[] endLines = new int[]{18};
+ int[] startLines = new int[]{32};
+ int[] endLines = new int[]{32};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN);
}
@@ -385,8 +385,8 @@ void testGCI76() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java";
String ruleId = "creedengo-java:GCI76";
String ruleMsg = "Avoid usage of static collections.";
- int[] startLines = new int[]{10, 12, 14};
- int[] endLines = new int[]{10, 12, 14};
+ int[] startLines = new int[]{27, 29, 31};
+ int[] endLines = new int[]{27, 29, 31};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
}
@@ -407,8 +407,8 @@ void testGCI79() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java";
String ruleId = "creedengo-java:GCI79";
String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface.";
- int[] startLines = new int[]{23};
- int[] endLines = new int[]{36};
+ int[] startLines = new int[]{40};
+ int[] endLines = new int[]{53};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_15MIN);
}
@@ -418,19 +418,19 @@ void testGCI32() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java";
String ruleId = "creedengo-java:GCI32";
String ruleMsg = "Initialize StringBuilder or StringBuffer with appropriate size";
- int[] startLines = new int[]{16, 24};
- int[] endLines = new int[]{16, 24};
+ int[] startLines = new int[]{33, 41};
+ int[] endLines = new int[]{33, 41};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
}
@Test
void testGCI67() {
- String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java";
+ String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/gci67/IncrementCheck.java";
String ruleId = "creedengo-java:GCI67";
String ruleMsg = "Use ++i instead of i++";
- int[] startLines = new int[]{9, 24, 47};
- int[] endLines = new int[]{9, 24, 47};
+ int[] startLines = new int[]{31, 51, 74};
+ int[] endLines = new int[]{31, 51, 74};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
}
@@ -440,8 +440,8 @@ void testGCI82() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java";
String ruleId = "creedengo-java:GCI82";
String ruleMsg = "The variable is never reassigned and can be 'final'";
- int[] startLines = new int[]{7, 12, 13, 45};
- int[] endLines = new int[]{7, 12, 13, 45};
+ int[] startLines = new int[]{26, 31, 32, 64};
+ int[] endLines = new int[]{26, 31, 32, 64};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
}
@@ -451,8 +451,8 @@ void testGCI69() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java";
String ruleId = "creedengo-java:GCI69";
String ruleMsg = "Do not call a function when declaring a for-type loop";
- int[] startLines = new int[]{58, 66, 74, 101};
- int[] endLines = new int[]{58, 66, 74, 101};
+ int[] startLines = new int[]{60, 68, 76, 103};
+ int[] endLines = new int[]{60, 68, 76, 103};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
}
@@ -462,9 +462,9 @@ void testGCI28() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java";
- int[] startLines = new int[]{23};
+ int[] startLines = new int[]{38};
- int[] endLines = new int[]{23};
+ int[] endLines = new int[]{38};
String ruleId = "creedengo-java:GCI28";
String ruleMsg = "Optimize Read File Exceptions";
@@ -478,9 +478,9 @@ void testGCI28_2() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java";
- int[] startLines = new int[]{20};
+ int[] startLines = new int[]{37};
- int[] endLines = new int[]{20};
+ int[] endLines = new int[]{37};
String ruleId = "creedengo-java:GCI28";
String ruleMsg = "Optimize Read File Exceptions";
@@ -494,9 +494,9 @@ void testGCI28_3() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java";
- int[] startLines = new int[]{19};
+ int[] startLines = new int[]{36};
- int[] endLines = new int[]{19};
+ int[] endLines = new int[]{36};
String ruleId = "creedengo-java:GCI28";
String ruleMsg = "Optimize Read File Exceptions";
@@ -510,9 +510,9 @@ void testGCI28_4() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java";
- int[] startLines = new int[]{18};
+ int[] startLines = new int[]{35};
- int[] endLines = new int[]{18};
+ int[] endLines = new int[]{35};
String ruleId = "creedengo-java:GCI28";
String ruleMsg = "Optimize Read File Exceptions";
@@ -526,9 +526,9 @@ void testGCI28_5() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java";
- int[] startLines = new int[]{18};
+ int[] startLines = new int[]{35};
- int[] endLines = new int[]{18};
+ int[] endLines = new int[]{35};
String ruleId = "creedengo-java:GCI28";
String ruleMsg = "Optimize Read File Exceptions";
@@ -542,8 +542,8 @@ void testGCI94() {
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java";
String ruleId = "creedengo-java:GCI94";
String ruleMsg = "Use optional orElseGet instead of orElse.";
- int[] startLines = new int[]{25};
- int[] endLines = new int[]{25};
+ int[] startLines = new int[]{27};
+ int[] endLines = new int[]{27};
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN);
}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
index 4a7d153c..71ec1553 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.Arrays;
@@ -48,28 +65,28 @@ public void copyWithForLoop() {
boolean[] dest = new boolean[len];
// Simple copy
- for (int i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}}
dest[i] = src[i];
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with nested conditions
- for (int i = 0; i < len; i++) {
- if (i + 2 < len) {
+ for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}}
+ if(i + 2 < len) {
dest[i] = src[i + 2];
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with nested ELSE conditions
- for (int i = 0; i < len; i++) {
- if (i + 2 >= len) {
+ for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}}
+ if(i + 2 >= len) {
i++;
} else {
dest[i] = src[i + 2];
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with more nested conditions
- for (int i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 < len) {
if (dest != null) {
if (src != null) {
@@ -79,19 +96,19 @@ public void copyWithForLoop() {
}
}
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch
- for (int i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest[i] = src[i];
} catch (RuntimeException e) {
e.printStackTrace();
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch and if
- for (int i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
if (dest != null) {
dest[i] = src[i];
@@ -99,10 +116,10 @@ public void copyWithForLoop() {
} catch (RuntimeException e) {
e.printStackTrace();
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch in catch
- for (int i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest.toString();
} catch (RuntimeException e) {
@@ -110,10 +127,10 @@ public void copyWithForLoop() {
dest[i] = src[i];
}
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch in finally
- for (int i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest.toString();
} catch (RuntimeException e) {
@@ -121,7 +138,7 @@ public void copyWithForLoop() {
} finally {
dest[i] = src[i];
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Array transformation
for (int i = 0; i < len; i++) {
@@ -136,31 +153,31 @@ public void copyWithForEachLoop() {
// Simple copy by foreach
int i = -1;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
dest[++i] = b;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with nested conditions by foreach
i = -1;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (b) {
dest[++i] = b;
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with nested ELSE conditions by foreach
i = -1;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 >= len) {
i++;
} else {
dest[++i] = b;
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with more nested conditions
i = -1;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 < len) {
if (dest != null) {
if (src != null) {
@@ -170,21 +187,21 @@ public void copyWithForEachLoop() {
}
}
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch
i = -1;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest[++i] = b;
} catch (RuntimeException e) {
e.printStackTrace();
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch and if
i = -1;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
if (dest != null) {
dest[++i] = b;
@@ -192,11 +209,11 @@ public void copyWithForEachLoop() {
} catch (RuntimeException e) {
e.printStackTrace();
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch in catch
i = -1;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest.toString();
} catch (RuntimeException e) {
@@ -204,11 +221,11 @@ public void copyWithForEachLoop() {
dest[++i] = b;
}
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch in finally
i = -1;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest.toString();
} catch (RuntimeException e) {
@@ -216,7 +233,7 @@ public void copyWithForEachLoop() {
} finally {
dest[++i] = b;
}
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Array transformation
i = -1;
@@ -226,34 +243,34 @@ public void copyWithForEachLoop() {
// Simple copy
i = 0;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
dest[i] = src[i];
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with nested conditions
i = 0;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (b) {
dest[i] = src[i];
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with nested ELSE conditions
i = 0;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 >= len) {
i++;
} else {
dest[i] = src[i + 2];
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with more nested conditions
i = 0;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 < len) {
if (dest != null) {
if (src != null) {
@@ -264,22 +281,22 @@ public void copyWithForEachLoop() {
}
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch
i = 0;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest[i] = src[i];
} catch (RuntimeException e) {
e.printStackTrace();
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch and if
i = 0;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
if (dest != null) {
dest[i] = src[i];
@@ -288,11 +305,11 @@ public void copyWithForEachLoop() {
e.printStackTrace();
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch in catch
i = 0;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest.toString();
} catch (RuntimeException e) {
@@ -301,11 +318,11 @@ public void copyWithForEachLoop() {
}
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch in finally
i = 0;
- for (boolean b : src) {
+ for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest.toString();
} catch (RuntimeException e) {
@@ -314,7 +331,7 @@ public void copyWithForEachLoop() {
dest[i] = src[i];
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Array transformation
i = 0;
@@ -331,34 +348,34 @@ public void copyWithWhileLoop() {
// Simple copy
int i = 0;
- while (i < len) {
+ while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}}
dest[i] = src[i];
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with nested conditions
i = 0;
- while (i < len) {
+ while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 < len) {
dest[i] = src[i + 2];
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with nested ELSE conditions
i = 0;
- while (i < len) {
+ while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 >= len) {
i++;
} else {
dest[i] = src[i + 2];
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy with more nested conditions
i = 0;
- while (i < len) {
+ while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 < len) {
if (dest != null) {
if (src != null) {
@@ -369,11 +386,11 @@ public void copyWithWhileLoop() {
}
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch and if
i = 0;
- while (i < len) {
+ while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
if (dest != null) {
dest[i] = src[i];
@@ -382,11 +399,11 @@ public void copyWithWhileLoop() {
e.printStackTrace();
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Copy nested by try/catch in catch
i = 0;
- while (i < len) {
+ while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest.toString();
} catch (RuntimeException e) {
@@ -395,7 +412,7 @@ public void copyWithWhileLoop() {
}
}
i++;
- } // Noncompliant {{Use System.arraycopy to copy arrays}}
+ }
// Array transformation
i = 0;
@@ -412,34 +429,34 @@ public void copyWithDoWhileLoop() {
// Simple copy
int i = 0;
- do {
+ do { // Noncompliant {{Use System.arraycopy to copy arrays}}
dest[i] = src[i];
i++;
- } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}}
+ } while (i < len);
// Copy with nested conditions
i = 0;
- do {
+ do { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 < len) {
dest[i] = src[i + 2];
}
i++;
- } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}}
+ } while (i < len);
// Copy with nested ELSE conditions
i = 0;
- do {
+ do { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 >= len) {
i++;
} else {
dest[i] = src[i + 2];
}
i++;
- } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}}
+ } while (i < len);
// Copy with more nested conditions
i = 0;
- do {
+ do { // Noncompliant {{Use System.arraycopy to copy arrays}}
if (i + 2 < len) {
if (dest != null) {
if (src != null) {
@@ -450,11 +467,11 @@ public void copyWithDoWhileLoop() {
}
}
i++;
- } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}}
+ } while (i < len);
// Copy nested by try/catch and if
i = 0;
- do {
+ do { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
if (dest != null) {
dest[i] = src[i];
@@ -463,11 +480,11 @@ public void copyWithDoWhileLoop() {
e.printStackTrace();
}
i++;
- } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}}
+ } while (i < len);
// Copy nested by try/catch in catch
i = 0;
- do {
+ do { // Noncompliant {{Use System.arraycopy to copy arrays}}
try {
dest.toString();
} catch (RuntimeException e) {
@@ -476,7 +493,7 @@ public void copyWithDoWhileLoop() {
}
}
i++;
- } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}}
+ } while (i < len);
// Array transformation
i = 0;
@@ -484,7 +501,6 @@ public void copyWithDoWhileLoop() {
dest[i] = transform(src[i]);
i++;
} while (i < len);
-
}
private boolean transform(boolean a) {
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java
index a525a429..a2731a7a 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
class AvoidFullSQLRequestCheck {
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java
index c24f9c92..6eb54828 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.ArrayList;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
index 03efe7c7..de3d8f8e 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.ArrayList;
@@ -10,7 +27,7 @@ public void badForLoop() {
numberList.add(10);
numberList.add(20);
- for (int i = 0; i < numberList.size(); ++i) { // Noncompliant
+ for (int i = 0; i < numberList.size(); ++i) { // Noncompliant {{Avoid getting the size of the collection in the loop}}
System.out.println("numberList.size()");
}
}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java
index 88d98861..4c0a4491 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.Collection;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
index 3ef6359e..df9e62c1 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.ArrayList;
@@ -19,6 +36,4 @@ public void badForLoop() {
System.out.println(it.next());
}
}
-
-
}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java
index 7410af92..b791cd4f 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.ArrayList;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java
index a09e89e5..10f02233 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.ArrayList;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java
index c22b216b..23d5ae54 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.ArrayList;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
index 3e4ee746..5c066f66 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
class AvoidMultipleIfElseStatement {
@@ -42,9 +59,9 @@ public int shouldBeNotCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVari
&& nb3 == 2
&& nb3 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 1;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb2 = 2;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
if (nb2 == 2) {
nb1 = 3;
@@ -85,9 +102,9 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInIfStatementsAtD
if (nb1 == 1) {
if (nb1 == 2) {
nb1 = 1;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 3;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
} else {
nb1 = 2;
}
@@ -109,9 +126,9 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta
} else {
if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 1;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 3;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
}
return nb1;
@@ -128,15 +145,15 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta
if (nb1 == 1) {
if (nb1 == 3) {
nb1 = 4;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 5;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
} else {
if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 1;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 3;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
}
return nb1;
@@ -155,15 +172,15 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta
if (nb1 == 1) {
if (nb1 == 3) {
nb1 = 4;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 5;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
} else if (nb2 == 2) {
if (nb1 == 4) {
nb1 = 5;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 6;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
}
return nb1;
@@ -187,9 +204,9 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta
} else if (nb2 == 2) {
if (nb1 == 3) {
nb1 = 4;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 5;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
}
return nb1;
@@ -208,13 +225,13 @@ public int shouldBeNotCompliantBecauseVariableUsedMaximumTwiceInComposedElseStat
} else {
if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 1;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
if (nb1 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 4;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 5;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
+ }
}
return nb1;
@@ -233,9 +250,9 @@ public int shouldBeNotCompliantBecauseTheSameVariableIsUsedMoreThanTwice() // NO
nb2 = 1;
} else if (nb1 == nb2) {
nb2 = 2;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb2 = 4;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
return nb2;
}
@@ -256,9 +273,9 @@ public int shouldBeNotCompliantBecauseTheSameVariableIsUsedManyTimes() // NOT Co
nb2 = 2;
} else if (nb3 == nb1) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb2 = 3;
- } else {
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb2 = 4;
- } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ }
return nb2;
}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java
index 1095d923..9a013908 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
class AvoidMultipleIfElseStatementCompareMethodNoIssue {
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java
index f787785c..3c7df17d 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
class AvoidMultipleIfElseStatementNoIssue {
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
index 20d9c24d..76387635 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.regex.Pattern;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java
index 29ff6bbe..638ffd96 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.regex.Pattern;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java
index b238d4c2..0ef9517c 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.regex.Pattern;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java
index 0e748b13..f1378974 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.regex.Pattern;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java
index cb185891..f75e0c92 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.sql.Connection;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
index 342f6588..294cf9ed 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.math.BigDecimal;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
index 6e1a2d89..3d386901 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
@@ -53,5 +53,5 @@ public Employee(Integer id, String name) {
public interface EmployeeRepository extends JpaRepository {
}
-
+
}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
index def8b5b8..f62ae877 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.sql.Connection;
@@ -5,9 +22,6 @@
import java.sql.*;
import java.sql.PreparedStatement;
-import javax.sql.DataSource;
-
-
class AvoidStatementForDMLQueries {
AvoidStatementForDMLQueries(AvoidStatementForDMLQueries mc) {
}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
index 476fbda8..f14de6aa 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.*;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java
index bf6d3e06..e7a60938 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.util.*;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
index 95ed3506..a6401735 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.io.*;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
deleted file mode 100644
index b42caa96..00000000
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.greencodeinitiative.creedengo.java.checks;
-
-class IncrementCheck {
- IncrementCheck(IncrementCheck mc) {
- }
-
- int foo1() {
- int counter = 0;
- return counter++; // Noncompliant {{Use ++i instead of i++}}
- }
-
- private int j = 0;
- int foo10() {
- return this.j++; // Compliant because maybe the use case needs to return j AND increment it
- }
-
- int foo11() {
- int counter = 0;
- return ++counter;
- }
-
- int foo2() {
- int counter = 0;
- counter++; // Noncompliant {{Use ++i instead of i++}}
- return counter;
- }
-
- int foo22() {
- int counter = 0;
- ++counter;
- return counter;
- }
-
- int foo3() {
- int counter = 0;
- counter = counter + 197845 ;
- return counter;
- }
-
- int foo4() {
- int counter = 0;
- counter = counter + 35 + 78 ;
- return counter;
- }
-
- void foo50() {
- for (int i=0; i < 10; i++) { // Noncompliant {{Use ++i instead of i++}}
- System.out.println(i); //NOSONAR
- }
- }
-
- void foo51() {
- for (int i=0; i < 10; ++i) {
- System.out.println(i); //NOSONAR
- }
- }
-
- void bar61(int value) {
- // For test purpose
- }
-
- int foo61() {
- int i = 0;
- bar61(i++); // Compliant because maybe bar61 needs the unincremented value
- return i;
- }
-
- int foo62() {
- int i = 0;
- bar61(2 + i++); // Compliant because maybe bar61 needs the unincremented value
- return i;
- }
-
- void foo71() {
- int counter = 0;
- int a = 2 + counter++; // Compliant because we probably want to increment counter
- // then to add it to 2 to initialize a
- }
-}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
index 8cc73e29..42fd687f 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
class InitializeBufferWithAppropriateSize {
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
index bef640d4..c358c4fe 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -1,3 +1,22 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
+package org.greencodeinitiative.creedengo.java.checks;
+
import java.util.logging.Logger;
public class MakeNonReassignedVariablesConstants {
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index 42326070..85cdb1bf 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -1,5 +1,5 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;/*
- * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+/*
+* creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
*
* This program is free software: you can redistribute it and/or modify
@@ -15,6 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+package org.greencodeinitiative.creedengo.java.checks;
+
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java
index 91520bd5..1163a226 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.io.FileInputStream;
@@ -7,8 +24,6 @@
import java.util.List;
import java.util.logging.Logger;
-import static java.lang.System.Logger.Level.ERROR;
-
class OptimizeReadFileExceptionCheck {
Logger logger = Logger.getLogger("");
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java
index 205b814a..9f1dda5e 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.io.FileInputStream;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java
index a26b6ea7..7a3a3409 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.io.FileInputStream;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java
index 80a75d9d..eab3367b 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.io.FileInputStream;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java
index 2115bef1..04999b71 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java
@@ -1,3 +1,20 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * 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 .
+ */
package org.greencodeinitiative.creedengo.java.checks;
import java.io.FileInputStream;
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
index 20a0decc..6a93a0be 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
@@ -16,6 +16,8 @@
* along with this program. If not, see .
*/
+package org.greencodeinitiative.creedengo.java.checks;
+
import java.util.Optional;
class UseOptionalOrElseGetVsOrElse {
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java
deleted file mode 100644
index f90c2cb4..00000000
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.greencodeinitiative.creedengo.java.checks;
-
-import org.springframework.data.jpa.repository.Query;
-
-import java.util.ArrayList;
-import java.util.List;
-
-class ZzzDDCToCheckOptimizeSQLQueriesWithLimit {
-
- public void literalSQLrequest() {
- dummyCall("SELECT user FROM myTable"); // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}}
- dummyCall("SELECT user FROM myTable LIMIT 50"); // Compliant
- }
-
- @Query("select t from Todo t where t.status != 'COMPLETED'") // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}}
- public List