Skip to content

Commit

Permalink
Merge branch 'master' into 2251-fixing-sonar-violations
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Jun 26, 2024
2 parents a78c4cd + ba2a9e3 commit 2f8ddba
Show file tree
Hide file tree
Showing 42 changed files with 252 additions and 209 deletions.
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
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
5 changes: 3 additions & 2 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 @@ -79,7 +79,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 @@ -101,6 +101,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
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 @@ -63,7 +63,7 @@ public final class PhTraced implements Phi {
/**
* Locator of encaged object.
*/
private final Integer locator;
private final Integer locatr;

/**
* Max depth of cage recursion.
Expand All @@ -80,7 +80,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 @@ -93,13 +93,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 @@ -193,13 +193,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 @@ -234,11 +234,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
Loading

0 comments on commit 2f8ddba

Please sign in to comment.