Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Feb 29, 2024
1 parent 52714e3 commit c58978d
Show file tree
Hide file tree
Showing 70 changed files with 198 additions and 311 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
"connectionId": "SonarCloud",
"projectKey": "StevenLooman_magik-tools"
},
"java.debug.settings.onBuildFailureProceed": true,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.checks.checks.CommentedCodeCheck;
import nl.ramsolutions.sw.magik.checks.checks.DuplicateMethodInFileCheck;
import nl.ramsolutions.sw.magik.checks.checks.EmptyBlockCheck;
Expand Down Expand Up @@ -117,6 +116,6 @@ public static List<Class<? extends MagikCheck>> getChecks() {
public static List<Class<? extends MagikCheck>> getDisabledByDefaultChecks() {
return getChecks().stream()
.filter(checkClass -> checkClass.getAnnotation(DisabledByDefault.class) != null)
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ protected void walkPreMagik(final AstNode node) {
}

private Map<Token, List<Token>> extractCommentBlocks(final AstNode node) {
final List<Token> commentTokens =
MagikCommentExtractor.extractLineComments(node).collect(Collectors.toList());
final List<Token> commentTokens = MagikCommentExtractor.extractLineComments(node).toList();

// Iterate over all comment tokens and combine blocks together.
final Map<Token, List<Token>> commentBlocks = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,34 @@ private void handleToken() {
this.visitTokenDot(this.currentToken);
break;

case "{":
case "[":
case "(":
case "{", "[", "(":
this.visitTokenBracketOpen(this.currentToken);
break;

case "}":
case "]":
case ")":
case "}", "]", ")":
this.visitTokenBracketClose(this.currentToken);
break;

// case "+": // Can be unary expression.
// case "-": // Can be unary expression.
case "*":
case "**":
case "/":
case "=":
case "<":
case "<=":
case ">":
case ">=":
case "_div":
case "_mod":
case "_is":
case "_isnt":
case "_or":
case "_orif":
case "_and":
case "_andif":
case "_xor":
case "_cf":
case "*",
"**",
"/",
"=",
"<",
"<=",
">",
">=",
"_div",
"_mod",
"_is",
"_isnt",
"_or",
"_orif",
"_and",
"_andif",
"_xor",
"_cf":
if (this.nextToken != null
&& (this.nextToken.getValue().equals("<<")
|| this.nextToken.getValue().equals("^<<"))) {
Expand All @@ -170,8 +166,7 @@ private void handleToken() {
}
break;

case "<<":
case "^<<":
case "<<", "^<<":
if (this.previousToken != null
&& AUGMENTED_ASSIGNMENT_TOKENS.contains(this.previousToken.getValue())) {
// Part 2 of augmented assignment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.sonar.sslr.api.AstNode;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper;
import nl.ramsolutions.sw.magik.analysis.helpers.ProcedureDefinitionNodeHelper;
import nl.ramsolutions.sw.magik.analysis.scope.GlobalScope;
Expand Down Expand Up @@ -66,7 +65,7 @@ private void checkScopeCount(final AstNode node) {
procedureScope.getSelfAndDescendantScopes().stream()
.flatMap(scope -> scope.getScopeEntriesInScope().stream())
.filter(scopeEntry -> !scopeEntry.isType(ScopeEntry.Type.IMPORT))
.collect(Collectors.toList());
.toList();
final int scopeCount = procedureScopeEntries.size();
if (scopeCount > this.maxScopeCount) {
final String message = String.format(MESSAGE, scopeCount, this.maxScopeCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private Set<String> getMethodParameters(final AstNode node) {
.map(parameterNode -> parameterNode.getFirstChild(MagikGrammar.IDENTIFIER))
.map(AstNode::getTokenValue)
.map(String::toUpperCase)
.collect(Collectors.toList());
.toList();
parameters.addAll(names);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,23 @@ public List<MagikBreakpoint> setBreakpoints(

// Add new breakpoints.
final List<Integer> magikBreakpointLines =
breakpoints.stream().map(MagikBreakpoint::getMethodLine).collect(Collectors.toList());
breakpoints.stream().map(MagikBreakpoint::getMethodLine).toList();
final List<SourceBreakpoint> addedBreakpoints =
Arrays.stream(newSourceBreakpoints)
.filter(breakpoint -> !magikBreakpointLines.contains(breakpoint.getLine()))
.collect(Collectors.toList());
.toList();
for (final SourceBreakpoint sourceBreakpoint : addedBreakpoints) {
this.addBreakpoint(source, sourceBreakpoint);
}

// Remove old breakpoints.
final List<Integer> sourceBreakpointLines =
Arrays.stream(newSourceBreakpoints)
.map(SourceBreakpoint::getLine)
.collect(Collectors.toList());
Arrays.stream(newSourceBreakpoints).map(SourceBreakpoint::getLine).toList();
final List<MagikBreakpoint> removedBreakpoints =
breakpoints.stream()
.filter(
magikBreakpoint -> !sourceBreakpointLines.contains(magikBreakpoint.getMethodLine()))
.collect(Collectors.toList());
.toList();
for (final MagikBreakpoint magikBreakpoint : removedBreakpoints) {
this.removeBreakpoint(source, magikBreakpoint);
}
Expand Down Expand Up @@ -447,9 +445,8 @@ private MagikBreakpoint sendSetBreakpoint(final String method, final int line)
LOGGER.trace("Created breakpoint: {}", magikBreakpoint);
} catch (ExecutionException exception) {
final Throwable cause = exception.getCause();
if (cause instanceof SlapErrorException) {
if (cause instanceof SlapErrorException slapErrorException) {
// Do nothing, verified will become false, error will be shown to user.
final SlapErrorException slapErrorException = (SlapErrorException) cause;
final String message = slapErrorException.getError().getErrorMessage().name();
magikBreakpoint.setMessage(message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,19 +588,15 @@ public void handleEvent(final ISlapEvent event) {
* @param event Event to process.
*/
void processEvent(final ISlapEvent event) {
if (event instanceof BreakpointEvent) {
final BreakpointEvent breakpointEvent = (BreakpointEvent) event;
if (event instanceof BreakpointEvent breakpointEvent) {
this.breakpointManager.handleBreakpointEvent(breakpointEvent);
this.threadManager.handleBreakpointEvent(breakpointEvent);
this.variableManager.handleBreakpointEvent(breakpointEvent);
} else if (event instanceof ThreadStartedEvent) {
final ThreadStartedEvent threadStartedEvent = (ThreadStartedEvent) event;
} else if (event instanceof ThreadStartedEvent threadStartedEvent) {
this.threadManager.handleThreadStartedEvent(threadStartedEvent);
} else if (event instanceof ThreadEndedEvent) {
final ThreadEndedEvent threadEndedEvent = (ThreadEndedEvent) event;
} else if (event instanceof ThreadEndedEvent threadEndedEvent) {
this.threadManager.handleThreadEndedEvent(threadEndedEvent);
} else if (event instanceof StepCompletedEvent) {
final StepCompletedEvent stepCompletedEvent = (StepCompletedEvent) event;
} else if (event instanceof StepCompletedEvent stepCompletedEvent) {
this.threadManager.handleStepCompletedEvent(stepCompletedEvent);
this.variableManager.handleStepCompletedEvent(stepCompletedEvent);
} else if (event instanceof DisconnectedEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ List<Thread> threads() throws IOException, InterruptedException, ExecutionExcept

final Thread thread = Lsp4jConversion.toLsp4j(threadId, threadInfo);
threads.add(thread);
} catch (ExecutionException exception) {
} catch (final ExecutionException exception) {
LOGGER.trace(
"Exception while getting thread, id: {}, exception: {}",
threadId,
exception.getMessage());

final Throwable cause = exception.getCause();
if (!(cause instanceof SlapErrorException
&& ((SlapErrorException) cause).getError().getErrorMessage()
== ErrorMessage.UNKNOWN_ERROR)) {
// If not ErrorMessage.UNKNOWN_ERROR, then re-throw.
if (exception.getCause() instanceof SlapErrorException slapErrorException
&& slapErrorException.getError().getErrorMessage() != ErrorMessage.UNKNOWN_ERROR) {
throw exception;
}
}
Expand Down Expand Up @@ -183,10 +182,8 @@ private Path determinePath(
return this.pathMapper.applyMapping(daPath);
}
} catch (final ExecutionException exception) {
final Throwable cause = exception.getCause();
if (cause instanceof SlapErrorException
&& ((SlapErrorException) cause).getError().getErrorMessage()
!= ErrorMessage.METHOD_NOT_FOUND) {
if (exception.getCause() instanceof SlapErrorException slapErrorException
&& slapErrorException.getError().getErrorMessage() != ErrorMessage.METHOD_NOT_FOUND) {
throw exception;
}
}
Expand All @@ -206,8 +203,7 @@ void pause(final long threadId) throws IOException, InterruptedException, Execut
try {
this.slapProtocol.suspendThread(threadId).get();
} catch (ExecutionException exception) {
if (exception.getCause() instanceof SlapErrorException) {
final SlapErrorException exception2 = (SlapErrorException) exception.getCause();
if (exception.getCause() instanceof SlapErrorException exception2) {
final ErrorResponse error = exception2.getError();
final ErrorMessage errorMessage = error.getErrorMessage();
if (errorMessage != ErrorMessage.THREAD_ALREADY_SUSPENDED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.debugadapter.slap.ISlapProtocol;
import nl.ramsolutions.sw.magik.debugadapter.slap.events.BreakpointEvent;
import nl.ramsolutions.sw.magik.debugadapter.slap.events.StepCompletedEvent;
Expand Down Expand Up @@ -302,7 +301,7 @@ List<MagikVariable> getVariables(final int reference)

// Sort variables.
final Comparator<MagikVariable> byName = Comparator.comparing(MagikVariable::getName);
return magikVariables.stream().sorted(byName).collect(Collectors.toList());
return magikVariables.stream().sorted(byName).toList();
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.debugadapter.slap.ByteBufferHelper;
import nl.ramsolutions.sw.magik.debugadapter.slap.ISlapResponse;
import nl.ramsolutions.sw.magik.debugadapter.slap.RequestType;
Expand Down Expand Up @@ -182,9 +181,7 @@ public static Local decode(final ByteBuffer buffer) {
break;
}

case TYPE_BYTE:
case TYPE_SHORT:
case TYPE_INT:
case TYPE_BYTE, TYPE_SHORT, TYPE_INT:
{
int value = buffer.getInt(valueOffset);
valueStr = Integer.toString(value);
Expand Down Expand Up @@ -241,7 +238,7 @@ public RequestType getRequestType() {
* @param subResponses Locals.
*/
public StackFrameLocalsResponse(final List<ISlapResponse> subResponses) {
this.locals = subResponses.stream().map(Local.class::cast).collect(Collectors.toList());
this.locals = subResponses.stream().map(Local.class::cast).toList();
}

public List<Local> getLocals() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.debugadapter.slap.ByteBufferHelper;
import nl.ramsolutions.sw.magik.debugadapter.slap.ISlapResponse;
import nl.ramsolutions.sw.magik.debugadapter.slap.RequestType;
Expand Down Expand Up @@ -124,8 +123,7 @@ public static StackElement decode(final ByteBuffer buffer) {
* @param subResponses Stack elements.
*/
public ThreadStackResponse(final List<ISlapResponse> subResponses) {
this.stackFrames =
subResponses.stream().map(StackElement.class::cast).collect(Collectors.toList());
this.stackFrames = subResponses.stream().map(StackElement.class::cast).toList();
}

public List<StackElement> getStackFrames() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.Serializable;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.MagikTypedFile;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionKind;
Expand Down Expand Up @@ -49,7 +48,7 @@ public static CodeAction createCodeAction(
final String description,
final List<nl.ramsolutions.sw.magik.TextEdit> textEdits) {
final List<org.eclipse.lsp4j.TextEdit> lsp4jTextEdits =
textEdits.stream().map(Lsp4jConversion::textEditToLsp4j).collect(Collectors.toList());
textEdits.stream().map(Lsp4jConversion::textEditToLsp4j).toList();
final VersionedTextDocumentIdentifier versionedTextDocumentIdentifier =
new VersionedTextDocumentIdentifier(magikFile.getUri().toString(), TEXT_DOCUMENT_VERSION);
final TextDocumentEdit textDocumentEdit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.MagikTypedFile;
import nl.ramsolutions.sw.magik.analysis.MagikAnalysisConfiguration;
import nl.ramsolutions.sw.magik.analysis.definitions.IDefinitionKeeper;
Expand Down Expand Up @@ -321,7 +320,7 @@ public CompletableFuture<Hover> hover(final HoverParams params) {
LOGGER.debug("Implementations found: {}", locations.size());

final List<Location> lsp4jLocations =
locations.stream().map(Lsp4jConversion::locationToLsp4j).collect(Collectors.toList());
locations.stream().map(Lsp4jConversion::locationToLsp4j).toList();
return Either.forLeft(lsp4jLocations);
});
}
Expand Down Expand Up @@ -379,7 +378,7 @@ public CompletableFuture<List<FoldingRange>> foldingRange(
LOGGER.debug("Definitions found: {}", locations.size());

final List<Location> lsp4jLocations =
locations.stream().map(Lsp4jConversion::locationToLsp4j).collect(Collectors.toList());
locations.stream().map(Lsp4jConversion::locationToLsp4j).toList();
return Either.forLeft(lsp4jLocations);
});
}
Expand All @@ -398,9 +397,7 @@ public CompletableFuture<List<? extends Location>> references(final ReferencePar
final List<nl.ramsolutions.sw.magik.Location> locations =
this.referencesProvider.provideReferences(magikFile, position);
LOGGER.debug("References found: {}", locations.size());
return locations.stream()
.map(Lsp4jConversion::locationToLsp4j)
.collect(Collectors.toList());
return locations.stream().map(Lsp4jConversion::locationToLsp4j).toList();
});
}

Expand Down Expand Up @@ -507,9 +504,7 @@ public CompletableFuture<List<SelectionRange>> selectionRange(final SelectionRan

final MagikTypedFile magikFile = this.openFiles.get(textDocument);
final List<nl.ramsolutions.sw.magik.Position> positions =
params.getPositions().stream()
.map(Lsp4jConversion::positionFromLsp4j)
.collect(Collectors.toList());
params.getPositions().stream().map(Lsp4jConversion::positionFromLsp4j).toList();
return CompletableFuture.supplyAsync(
() -> this.selectionRangeProvider.provideSelectionRanges(magikFile, positions));
}
Expand Down Expand Up @@ -594,7 +589,7 @@ public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(
Lsp4jUtils.createCodeAction(
magikFile, codeAction.getTitle(), codeAction.getEdits()))
.map(Either::<Command, CodeAction>forRight)
.collect(Collectors.toList());
.toList();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import nl.ramsolutions.sw.magik.CodeAction;
import nl.ramsolutions.sw.magik.MagikTypedFile;
Expand Down Expand Up @@ -47,7 +46,7 @@ public List<CodeAction> provideCodeActions(
return Stream.concat(
this.checksCodeActionProvider.provideCodeActions(magikFile, range).stream(),
this.typedChecksCodeActionProvider.provideCodeActions(magikFile, range).stream())
.collect(Collectors.toList());
.toList();
} catch (final IOException | ReflectiveOperationException exception) {
LOGGER.error(exception.getMessage(), exception);
}
Expand Down
Loading

0 comments on commit c58978d

Please sign in to comment.