Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3160 Enable PMD for eo-runime #3171

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
68f7bb9
#3160 enable pmd for eo-runtime and exclude EOorg package
c71n93 May 6, 2024
931958c
#3160 resolve PMD violations for tests from eo-runtime/src/test/java/…
c71n93 May 6, 2024
22fa0a4
#3160 resolve PMD violations for tests from eo-runtime/src/main/java/…
c71n93 May 6, 2024
8bf5e84
Merge branch 'master' into 3160-enable-pmd-in-eo-runtime
c71n93 May 6, 2024
8e82e95
#3160 fix code duplication for DataizedTest and resolve some new PMD …
c71n93 May 6, 2024
029b7b2
#3160 add todo
c71n93 May 6, 2024
aa4542d
#3160 get rid of parametrized test
c71n93 May 6, 2024
db2d4d5
#3160 suppress false positive PMD.CloseResource
c71n93 May 6, 2024
cf5db6a
#3160 restart CI
c71n93 May 6, 2024
33b264a
#3160 set up file.encoding to UTF8
c71n93 May 10, 2024
ff1c2ed
Merge branch 'master' into 3160-enable-pmd-in-eo-runtime
c71n93 May 13, 2024
1286ee0
#3160 remove file.encoding
c71n93 May 13, 2024
5f15eb3
#3160 restart CI
c71n93 May 13, 2024
058015a
#3160 remove unnecessary import
c71n93 May 13, 2024
380976e
#3160 shortened the variable name
c71n93 May 14, 2024
b2a049c
#3160 copy array instead of storing directly
c71n93 May 14, 2024
d3a8376
#3160 resolve PMD.ConstructorShouldDoInitialization warning
c71n93 May 16, 2024
f4a0dd2
#3160 locatr
c71n93 May 16, 2024
8f827f3
Merge branch 'master' into 3160-enable-pmd-in-eo-runtime
c71n93 May 16, 2024
b63ec99
#3160 remove PhWrite
c71n93 May 16, 2024
88d82de
#3160 add todo for refactoring
c71n93 May 16, 2024
2e6fade
#3160 fix todo
c71n93 May 16, 2024
56c2ee1
Merge branch 'master' into 3160-enable-pmd-in-eo-runtime
c71n93 May 21, 2024
72ce8c8
#3160 rename variable
c71n93 May 27, 2024
df95e60
#3160 shorten variable name
c71n93 May 27, 2024
ba2a9e3
Merge branch 'master' into 3160-enable-pmd-in-eo-runtime
c71n93 Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,14 @@ SOFTWARE.
<artifactId>qulice-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>pmd:.*</exclude>
<!--
@todo #3160:60min Enable PMD check for eo-runtime/src/main/java/EOorg package,
excluding only those rules that cannot be resolved
(PMD.PackageCase, PMD.AvoidDollarSigns). All the others PMD violations should be
resolved.
-->
<exclude>pmd:/src/main/java/EOorg/.*</exclude>
<exclude>pmd:/src/test/java/EOorg/.*</exclude>
<exclude>dependencies:org.eolang:eo-maven-plugin</exclude>
</excludes>
</configuration>
Expand Down
3 changes: 2 additions & 1 deletion eo-runtime/src/main/java/org/eolang/Bytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public interface Bytes {
* OR operation.
* @param other Bytes.
* @return Bytes.
* @checkstyle MethodNameCheck (2 lines)
* @checkstyle MethodNameCheck (3 lines)
*/
@SuppressWarnings("PMD.ShortMethodName")
Bytes or(Bytes other);

/**
Expand Down
10 changes: 9 additions & 1 deletion eo-runtime/src/main/java/org/eolang/BytesOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@
* Bytes.
*
* @since 1.0
* @todo #3160:90min This class requires refactoring. As a result of refactoring you should remove
* {@code @SuppressWarnings("PMD.GodClass")} from this class and
* {@code @SuppressWarnings("PMD.CognitiveComplexity")} from {@link BytesOf#shift} method. You can
* check description of this rules here
* <a href="https://pmd.github.io/pmd/pmd_rules_java_design">pmd.github.io</a>
*/
@Versionized
@SuppressWarnings({"PMD.TooManyMethods", "PMD.GodClass"})
public final class BytesOf implements Bytes {

/**
Expand All @@ -45,7 +51,7 @@ public final class BytesOf implements Bytes {
* @param data Data.
*/
public BytesOf(final byte[] data) {
this.data = data;
this.data = Arrays.copyOf(data, data.length);
}

/**
Expand Down Expand Up @@ -108,6 +114,7 @@ public Bytes and(final Bytes other) {
}

@Override
@SuppressWarnings("PMD.ShortMethodName")
public Bytes or(final Bytes other) {
final byte[] first = this.take();
final byte[] second = other.take();
Expand All @@ -128,6 +135,7 @@ public Bytes xor(final Bytes other) {
}

@Override
@SuppressWarnings("PMD.CognitiveComplexity")
public Bytes shift(final int bits) {
// @checkstyle MethodBodyCommentsCheck (3 lines)
// @checkstyle NestedIfDepthCheck (40 lines)
Expand Down
18 changes: 14 additions & 4 deletions eo-runtime/src/main/java/org/eolang/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @since 0.1
*/
@Versionized
@SuppressWarnings("PMD.TooManyMethods")
public interface Data {
/**
* Attach data to the object.
Expand Down Expand Up @@ -192,11 +193,20 @@ private static Phi toPhi(final Object obj) {
* </ul>
* @param str A string optionally containing standard java escape sequences.
* @return The translated string
* @todo #3160:90min This method should be refactored because it has high cognitive
* complexity and other problems. All {@code @checkstyle} warnings suppression and
* {@code SuppressWarnings("PMD.WarningName")} annotations for this method should be
* removed as a result of refactoring.
* @checkstyle CyclomaticComplexityCheck (100 lines)
* @checkstyle JavaNCSSCheck (100 lines)
* @checkstyle NestedIfDepthCheck (100 lines)
* @checkstyle ModifiedControlVariableCheck (100 lines)
*/
@SuppressWarnings({
"PMD.AvoidReassigningLoopVariables",
"PMD.CognitiveComplexity",
"PMD.NPathComplexity"
})
private static String unescapeJavaString(final String str) {
final StringBuilder unescaped = new StringBuilder(str.length());
for (int idx = 0; idx < str.length(); ++idx) {
Expand All @@ -209,19 +219,19 @@ private static String unescapeJavaString(final String str) {
next = str.charAt(idx + 1);
}
if (next >= '0' && next <= '7') {
String code = String.valueOf(next);
final StringBuilder code = new StringBuilder(String.valueOf(next));
++idx;
if (idx < str.length() - 1 && str.charAt(idx + 1) >= '0'
&& str.charAt(idx + 1) <= '7') {
code += str.charAt(idx + 1);
code.append(str.charAt(idx + 1));
++idx;
if (idx < str.length() - 1 && str.charAt(idx + 1) >= '0'
&& str.charAt(idx + 1) <= '7') {
code += str.charAt(idx + 1);
code.append(str.charAt(idx + 1));
++idx;
}
}
unescaped.append((char) Integer.parseInt(code, 8));
unescaped.append((char) Integer.parseInt(code.toString(), 8));
continue;
}
switch (next) {
Expand Down
10 changes: 0 additions & 10 deletions eo-runtime/src/main/java/org/eolang/Dataized.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,4 @@ public <T> T take(final Class<T> type) {
}
return type.cast(strong);
}

/**
* Clean up resources.
* This includes call of {@link ThreadLocal#remove()} method to prevent
* memory leaks.
*/
public static void cleanUp() {
Dataized.LEVEL.remove();
Dataized.MAX_LEVEL.remove();
}
}
15 changes: 8 additions & 7 deletions eo-runtime/src/main/java/org/eolang/ExAbstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,26 @@ public abstract class ExAbstract extends RuntimeException {

/**
* Ctor.
* @param cause Exception cause
*/
public ExAbstract() {
this(null);
public ExAbstract(final String cause) {
super(cause);
}

/**
* Ctor.
* @param cause Exception cause
* @param root Root cause exception
*/
public ExAbstract(final String cause) {
super(cause);
public ExAbstract(final String cause, final Throwable root) {
super(cause, root);
}

/**
* Ctor.
* @param cause Exception cause
* @param root Root cause exception
*/
ExAbstract(final String cause, final Throwable root) {
super(cause, root);
public ExAbstract(final Throwable root) {
super(root);
}
}
5 changes: 3 additions & 2 deletions eo-runtime/src/main/java/org/eolang/ExInterrupted.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public class ExInterrupted extends ExAbstract {

/**
* Ctor.
* @param root Root cause exception
*/
public ExInterrupted() {
super(null);
public ExInterrupted(final InterruptedException root) {
super(root);
}
}
4 changes: 3 additions & 1 deletion eo-runtime/src/main/java/org/eolang/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* @since 0.1
*/
@Versionized
@SuppressWarnings("PMD.MoreThanOneLogger")
public final class Main {

/**
Expand Down Expand Up @@ -182,7 +183,8 @@ private static void run(final List<String> opts) throws Exception {
.newInstance();
} catch (final ClassNotFoundException ex) {
throw new ExUnset(
String.format("Can not find '%s' object", opts.get(0))
String.format("Can not find '%s' object", opts.get(0)),
ex
);
}
if (opts.size() > 1) {
Expand Down
14 changes: 3 additions & 11 deletions eo-runtime/src/main/java/org/eolang/PhDefault.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @checkstyle DesignForExtensionCheck (500 lines)
*/
@Versionized
@SuppressWarnings({"PMD.TooManyMethods", "PMD.ConstructorShouldDoInitialization"})
@SuppressWarnings({"PMD.TooManyMethods", "PMD.GodClass"})
public class PhDefault implements Phi, Cloneable {
/**
* Vertices.
Expand Down Expand Up @@ -74,7 +74,7 @@ public class PhDefault implements Phi, Cloneable {
* Data.
* @checkstyle VisibilityModifierCheck (2 lines)
*/
private AtomicReference<byte[]> data = new AtomicReference<>(null);
private AtomicReference<byte[]> data;

/**
* Forma of it.
Expand All @@ -96,6 +96,7 @@ public class PhDefault implements Phi, Cloneable {
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
public PhDefault() {
this.data = new AtomicReference<>(null);
this.vertex = PhDefault.VTX.next();
this.form = this.getClass().getName();
this.attrs = new HashMap<>(0);
Expand Down Expand Up @@ -300,15 +301,6 @@ public String forma() {
return this.form;
}

/**
* Clean up resources.
* This includes call of {@link ThreadLocal#remove()} method to prevent
* memory leaks.
*/
public static void cleanUp() {
PhDefault.NESTING.remove();
}

/**
* Add new attribute.
*
Expand Down
1 change: 1 addition & 0 deletions eo-runtime/src/main/java/org/eolang/PhFake.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public PhFake() {
* Ctor.
* @param sup The function to return the real object
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
public PhFake(final Supplier<Phi> sup) {
this.add("args", new AtVoid("args"));
this.add("φ", new AtComposite(this, rho -> sup.get()));
Expand Down
1 change: 1 addition & 0 deletions eo-runtime/src/main/java/org/eolang/PhLocated.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @since 0.21
*/
@SuppressWarnings("PMD.TooManyMethods")
@Versionized
public final class PhLocated implements Phi {

Expand Down
1 change: 1 addition & 0 deletions eo-runtime/src/main/java/org/eolang/PhLogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @since 0.24
*/
@Versionized
@SuppressWarnings({"PMD.TooManyMethods", "PMD.SystemPrintln"})
public final class PhLogged implements Phi {

/**
Expand Down
1 change: 1 addition & 0 deletions eo-runtime/src/main/java/org/eolang/PhNamed.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @since 0.17
*/
@Versionized
@SuppressWarnings("PMD.TooManyMethods")
final class PhNamed implements Phi {

/**
Expand Down
1 change: 1 addition & 0 deletions eo-runtime/src/main/java/org/eolang/PhOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @since 0.1
*/
@Versionized
@SuppressWarnings("PMD.TooManyMethods")
class PhOnce implements Phi {

/**
Expand Down
8 changes: 5 additions & 3 deletions eo-runtime/src/main/java/org/eolang/PhPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @since 0.22
*/
@Versionized
@SuppressWarnings("PMD.TooManyMethods")
final class PhPackage implements Phi {

/**
Expand All @@ -45,16 +46,17 @@ final class PhPackage implements Phi {
/**
* All of them.
*/
private final ThreadLocal<Map<String, Phi>> objects = ThreadLocal.withInitial(
() -> new ConcurrentHashMap<>(0)
);
private final ThreadLocal<Map<String, Phi>> objects;

/**
* Ctor.
* @param name The name
*/
PhPackage(final String name) {
this.pkg = name;
this.objects = ThreadLocal.withInitial(
() -> new ConcurrentHashMap<>(0)
);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions eo-runtime/src/main/java/org/eolang/PhSafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @since 0.26
*/
@Versionized
@SuppressWarnings("PMD.TooManyMethods")
public final class PhSafe implements Phi {

/**
Expand Down
20 changes: 10 additions & 10 deletions eo-runtime/src/main/java/org/eolang/PhTraced.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
* @since 0.36
*/
@Versionized
@SuppressWarnings("PMD.TooManyMethods")
public final class PhTraced implements Phi {

/**
* Name of property that responsible for keeping max depth.
*/
public static final String
MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME = "EO_MAX_CAGE_RECURSION_DEPTH";
public static final String RECURSION_LIMIT = "EO_MAX_CAGE_RECURSION_DEPTH";

/**
* Cages that are currently being dataized. If one cage is being datazed, and
Expand All @@ -58,7 +58,7 @@ public final class PhTraced implements Phi {
/**
* Locator of encaged object.
*/
private final Integer locator;
private final Integer locatr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c71n93 what was wrong with locator name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon it repeats the method name (prohibited by PMD)


/**
* Max depth of cage recursion.
Expand All @@ -75,7 +75,7 @@ public PhTraced(final Phi object, final Integer locator) {
object,
locator,
Integer.parseInt(
System.getProperty(PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, "100")
System.getProperty(PhTraced.RECURSION_LIMIT, "100")
)
);
}
Expand All @@ -88,13 +88,13 @@ public PhTraced(final Phi object, final Integer locator) {
*/
public PhTraced(final Phi object, final Integer locator, final int depth) {
this.object = object;
this.locator = locator;
this.locatr = locator;
this.depth = depth;
}

@Override
public Phi copy() {
return new PhTraced(this.object.copy(), this.locator);
return new PhTraced(this.object.copy(), this.locatr);
}

@Override
Expand Down Expand Up @@ -188,13 +188,13 @@ public T get() {
*/
private Integer incrementCageCounter() {
return PhTraced.DATAIZING_CAGES.get().compute(
PhTraced.this.locator, (key, counter) -> {
PhTraced.this.locatr, (key, counter) -> {
final int ret = this.incremented(counter);
if (ret > PhTraced.this.depth) {
throw new ExFailure(
"The cage %s with locator %d has reached the maximum nesting depth = %d",
PhTraced.this.object,
PhTraced.this.locator,
PhTraced.this.locatr,
PhTraced.this.depth
);
}
Expand Down Expand Up @@ -229,11 +229,11 @@ private void decrementCageCounter(final int incremented) {
final int decremented = incremented - 1;
if (decremented == 0) {
PhTraced.DATAIZING_CAGES.get().remove(
PhTraced.this.locator
PhTraced.this.locatr
);
} else {
PhTraced.DATAIZING_CAGES.get().put(
PhTraced.this.locator, decremented
PhTraced.this.locatr, decremented
);
}
}
Expand Down