Skip to content

Sweep up various IntelliJ inspections #395

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

Merged
merged 11 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ Since 2019, the project has been actively developed and extensively rewritten by

## License

Licensed under the [GNU Lesser General Public License, Version 3.0](http://www.gnu.org/licenses/lgpl.txt).
Licensed under the [GNU Lesser General Public License, Version 3.0](https://www.gnu.org/licenses/lgpl.txt).
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.check.Rule;
Expand Down Expand Up @@ -249,11 +250,13 @@ public int length() {
}

@Override
@Nonnull
public CharSequence subSequence(int start, int end) {
return new RegexTimeoutCharSequence(sequence.subSequence(start, end), deadline);
}

@Override
@Nonnull
public String toString() {
return sequence.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@
import org.sonar.plugins.communitydelphi.api.check.DelphiCheckContext;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;

/**
* This rule looks for exception blocks where the caught exception is explicitly re-raised. This is
* a Bad Thing™ because the exception will be freed at the end of the handler, causing tricky access
* errors
*
* @see <a href="https://bit.ly/2AQp1GW">On Delphi Exception raising, re-raising and try-except
* blocks</a>
* @see <a href="http://delphi.org/2017/06/really-bad-exception-abuse/">Exceptionally Bad Exception
* Abuse</a>
*/
@DeprecatedRuleKey(ruleKey = "ReRaiseExceptionRule", repositoryKey = "delph")
@Rule(key = "ReRaiseException")
public class ReRaiseExceptionCheck extends DelphiCheck {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h2>Why is this an issue?</h2>
explicitly inherit from TObject for readability.
</p>
<h2>How to fix it</h2>
<p>Specify <code>TObject</code> as the class's ancestor:
<p>Specify <code>TObject</code> as the class's ancestor:</p>
<pre data-diff-id="1" data-diff-type="noncompliant">
type
TMyClass = class
Expand All @@ -20,9 +20,8 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Classes_and_Objects_(Delphi)#TObject_and_TClass">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Classes_and_Objects_(Delphi)#TObject_and_TClass">
RAD Studio documentation: TObject and TClass
</a>
</li>
</ul>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/Libraries/en/System.SysUtils.Format#Format_Strings">
<a href="https://docwiki.embarcadero.com/Libraries/en/System.SysUtils.Format#Format_Strings">
RAD Studio API documentation: System.SysUtils.Format
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/Libraries/en/System.SysUtils.Format#Format_Strings">
<a href="https://docwiki.embarcadero.com/Libraries/en/System.SysUtils.Format#Format_Strings">
RAD Studio API documentation: System.SysUtils.Format
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/Libraries/en/System.SysUtils.Format#Format_Strings">
<a href="https://docwiki.embarcadero.com/Libraries/en/System.SysUtils.Format#Format_Strings">
RAD Studio API documentation: System.SysUtils.Format
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ <h2>How to fix it</h2>
Use <code>TList.Last</code> instead of indexing with <code>Count - 1</code>:
</p>
<pre data-diff-id="1" data-diff-type="noncompliant">
procedure PrintMostRecent(MyList: TList<Integer>);
procedure PrintMostRecent(MyList: TList&lt;Integer&gt;);
begin
WriteLn(MyList[MyList.Count - 1]);
end;
</pre>
<pre data-diff-id="1" data-diff-type="compliant">
procedure PrintMostRecent(MyList: TList<Integer>);
procedure PrintMostRecent(MyList: TList&lt;Integer&gt;);
begin
WriteLn(MyList.Last);
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>Why is this an issue?</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Using_Inline_Assembly_Code">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Using_Inline_Assembly_Code">
RAD Studio documentation: Using Inline Assembly Code
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Inline_Variable_Declaration#Type_Inference_for_Inlined_Variables">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Inline_Variable_Declaration#Type_Inference_for_Inlined_Variables">
RAD Studio documentation: Type Inference for Inlined Variables
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Inline_Variable_Declaration#Type_Inference_for_Inlined_Variables">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Inline_Variable_Declaration#Type_Inference_for_Inlined_Variables">
RAD Studio documentation: Type Inference for Inlined Variables
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Inline_Variable_Declaration#Type_Inference_for_Inlined_Variables">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Inline_Variable_Declaration#Type_Inference_for_Inlined_Variables">
RAD Studio documentation: Type Inference for Inlined Variables
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Programs_and_Units_(Delphi)#The_Initialization_Section">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Programs_and_Units_(Delphi)#The_Initialization_Section">
RAD Studio documentation: Programs and Units (Delphi)
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/Libraries/en/System.Assigned">
<a href="https://docwiki.embarcadero.com/Libraries/en/System.Assigned">
RAD Studio documentation: System.Assigned
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Classes_and_Objects_(Delphi)#Object_Types">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Classes_and_Objects_(Delphi)#Object_Types">
RAD Studio documentation: Classes and Objects
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Converting_32-bit_Delphi_Applications_to_64-bit_Windows">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Converting_32-bit_Delphi_Applications_to_64-bit_Windows">
RAD Studio documentation: Converting 32-bit Delphi Applications to 64-bit Windows
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/RADStudio/en/Converting_32-bit_Delphi_Applications_to_64-bit_Windows">
<a href="https://docwiki.embarcadero.com/RADStudio/en/Converting_32-bit_Delphi_Applications_to_64-bit_Windows">
RAD Studio documentation: Converting 32-bit Delphi Applications to 64-bit Windows
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href='http://docwiki.embarcadero.com/RADStudio/en/Parameters_(Delphi)#Out_Parameters'>
<a href='https://docwiki.embarcadero.com/RADStudio/en/Parameters_(Delphi)#Out_Parameters'>
RAD Studio documentation: Out Parameters
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h2>How to fix it</h2>
<h2>Resources</h2>
<ul>
<li>
<a href="http://docwiki.embarcadero.com/Libraries/en/System.Classes.TStringList.Duplicates">
<a href="https://docwiki.embarcadero.com/Libraries/en/System.Classes.TStringList.Duplicates">
RAD Studio API documentation: System.Classes.TStringList.Duplicates
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -236,11 +238,14 @@ private static Path sonarWayMetadata() {

private static List<Path> listMetadata(String extension) {
String path = "/" + new MetadataResourcePathImpl().forRepository(CheckList.REPOSITORY_KEY);
return Stream.of(
DelphiUtils.getResource(path)
.listFiles((dir, name) -> name.toLowerCase().endsWith(extension)))
.map(File::toPath)
.collect(Collectors.toUnmodifiableList());
File resource = DelphiUtils.getResource(path);
try (Stream<Path> paths = Files.list(resource.toPath())) {
return paths
.filter(p -> p.getFileName().toString().toLowerCase().endsWith(extension))
.collect(Collectors.toUnmodifiableList());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private static JsonObject getMetadataForRuleKey(String ruleKey) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ dllName : {!input.LT(1).getText().equals("name")}? expressi
;
externalSpecifier : NAME^ expression
| INDEX^ expression // specific to a platform
| DELAYED // Use delayed loading (See: http://docwiki.embarcadero.com/RADStudio/en/Libraries_and_Packages_(Delphi))
| DELAYED // Use delayed loading (See: https://docwiki.embarcadero.com/RADStudio/en/Libraries_and_Packages_(Delphi))
;
dispIDDirective : DISPID expression
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public DelphiTokenStream(TokenSource tokenSource) {
*
* @return Token list
*/
@SuppressWarnings("unchecked")
@Override
public List<Token> getTokens() {
return tokens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public <T> T accept(DelphiParserVisitor<T> visitor, T data) {
}

@Override
@Nonnull
public TypeNode getElementTypeNode() {
return (TypeNode) getChild(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package au.com.integradev.delphi.antlr.ast.node;

import au.com.integradev.delphi.antlr.ast.visitors.DelphiParserVisitor;
import javax.annotation.Nonnull;
import org.antlr.runtime.Token;
import org.sonar.plugins.communitydelphi.api.ast.AttributeListNode;
import org.sonar.plugins.communitydelphi.api.ast.ConstDeclarationNode;
Expand Down Expand Up @@ -65,6 +66,7 @@ public AttributeListNode getAttributeList() {
}

@Override
@Nonnull
public Type getType() {
TypeNode typeNode = getTypeNode();
if (typeNode != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private Set<String> getConditionalDefines() {
* @param toolchain The compiler toolchain
* @param compilerVersion The compiler version
* @return set of conditional symbols that are defined on this compiler toolchain
* @see <a href="http://bit.ly/delphi_predefined_conditionals">Predefined Conditionals</a>
* @see <a href="https://bit.ly/delphi_predefined_conditionals">Predefined Conditionals</a>
*/
public static Set<String> getConditionalDefines(
Toolchain toolchain, CompilerVersion compilerVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ private static boolean isBinaryDigit(char character) {
}

private final class NumberReader {
TokenType type;
StringBuilder value = new StringBuilder();
private TokenType type;
private final StringBuilder value = new StringBuilder();
private Predicate<Character> isDigitCharacter;
private boolean canBeReal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package au.com.integradev.delphi.symbol.declaration;

import java.util.Objects;
import javax.annotation.Nonnull;
import org.sonar.plugins.communitydelphi.api.ast.EnumElementNode;
import org.sonar.plugins.communitydelphi.api.symbol.declaration.EnumElementNameDeclaration;
import org.sonar.plugins.communitydelphi.api.symbol.declaration.NameDeclaration;
Expand Down Expand Up @@ -49,7 +50,7 @@ public int hashCode() {
}

@Override
public int compareTo(NameDeclaration other) {
public int compareTo(@Nonnull NameDeclaration other) {
int result = super.compareTo(other);
if (result == 0) {
EnumElementNameDeclarationImpl that = (EnumElementNameDeclarationImpl) other;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.sonar.plugins.communitydelphi.api.ast.AttributeListNode;
import org.sonar.plugins.communitydelphi.api.ast.DelphiNode;
Expand Down Expand Up @@ -312,7 +313,7 @@ public int hashCode() {
}

@Override
public int compareTo(NameDeclaration other) {
public int compareTo(@Nonnull NameDeclaration other) {
int result = super.compareTo(other);
if (result == 0) {
PropertyNameDeclarationImpl that = (PropertyNameDeclarationImpl) other;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.sonar.plugins.communitydelphi.api.ast.AttributeListNode;
import org.sonar.plugins.communitydelphi.api.ast.DelphiNode;
Expand Down Expand Up @@ -328,7 +329,7 @@ public int hashCode() {
}

@Override
public int compareTo(NameDeclaration other) {
public int compareTo(@Nonnull NameDeclaration other) {
int result = super.compareTo(other);
if (result == 0) {
RoutineNameDeclarationImpl that = (RoutineNameDeclarationImpl) other;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nonnull;
import org.sonar.plugins.communitydelphi.api.ast.FileHeaderNode;
import org.sonar.plugins.communitydelphi.api.symbol.declaration.NameDeclaration;
import org.sonar.plugins.communitydelphi.api.symbol.declaration.UnitNameDeclaration;
Expand Down Expand Up @@ -114,7 +115,7 @@ public int hashCode() {
}

@Override
public int compareTo(NameDeclaration other) {
public int compareTo(@Nonnull NameDeclaration other) {
int result = super.compareTo(other);
if (result == 0) {
UnitNameDeclarationImpl that = (UnitNameDeclarationImpl) other;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @see <a href="https://github.com/fpc/FPCSource/blob/main/compiler/symconst.pas#L817">tequaltype
* </a>
*/
enum EqualityType {
public enum EqualityType {
INCOMPATIBLE_TYPES,
CONVERT_LEVEL_8,
CONVERT_LEVEL_7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private Type handleSyntaxToken(Type type, DelphiTokenType tokenType) {
case DEREFERENCE:
case DOT:
// Delphi Extended syntax is assumed.
// See: http://docwiki.embarcadero.com/RADStudio/en/Extended_syntax_(Delphi)
// See: https://docwiki.embarcadero.com/RADStudio/en/Extended_syntax_(Delphi)
return TypeUtils.dereference(type);

case STRING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public HelperType shallowGetHelperForType(Type type) {
@Override
public Set<NameDeclaration> shallowFindDeclaration(NameOccurrence occurrence) {
return super.findDeclaration(occurrence).stream()
.map(NameDeclaration.class::cast)
.filter(not(NameDeclaration::isImplementationDeclaration))
.filter(not(UnitImportNameDeclaration.class::isInstance))
.collect(Collectors.toSet());
Expand Down
Loading