Skip to content

Commit

Permalink
Keeping Sonar happy
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Jun 30, 2023
1 parent d2c75c3 commit 4af44f8
Show file tree
Hide file tree
Showing 53 changed files with 147 additions and 226 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nl.ramsolutions.sw.magik.checks;

import java.util.List;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.checks.checks.CommentRegularExpressionCheck;
import nl.ramsolutions.sw.magik.checks.checks.CommentedCodeCheck;
import nl.ramsolutions.sw.magik.checks.checks.DuplicateMethodInFileCheck;
Expand Down Expand Up @@ -105,7 +104,7 @@ public static List<Class<?>> getChecks() {
public static List<Class<?>> getDisabledByDefaultChecks() {
return getChecks().stream()
.filter(checkClass -> checkClass.getAnnotation(DisabledByDefault.class) != null)
.collect(Collectors.toList());
.toList();
}

/**
Expand All @@ -115,7 +114,7 @@ public static List<Class<?>> getDisabledByDefaultChecks() {
public static List<Class<?>> getTemplatedChecks() {
return getChecks().stream()
.filter(checkClass -> checkClass.getAnnotation(TemplatedMagikCheck.class) != null)
.collect(Collectors.toList());
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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());
.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 @@ -45,7 +45,7 @@ protected void walkPostMagik(final AstNode node) {
.collect(Collectors.toMap(
MethodDefinition::getName,
List::of,
(list1, list2) -> Stream.concat(list1.stream(), list2.stream()).collect(Collectors.toList())));
(list1, list2) -> Stream.concat(list1.stream(), list2.stream()).toList()));
definitions.entrySet().stream()
.filter(entry -> entry.getValue().size() > 1)
.flatMap(entry -> entry.getValue().stream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,38 +145,22 @@ 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("^<<"))) {
// part 1 of augmented assignment
Expand All @@ -186,8 +170,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.scope.GlobalScope;
import nl.ramsolutions.sw.magik.analysis.scope.Scope;
import nl.ramsolutions.sw.magik.analysis.scope.ScopeEntry;
Expand Down Expand Up @@ -66,7 +65,7 @@ private void checkScopeCount(final AstNode node) {
final List<ScopeEntry> procedureScopeEntries = 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 @@ -57,7 +57,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 @@ -70,8 +70,7 @@ protected void walkPreMagik(AstNode node) {
final AstNodeXPathQuery<Object> xpath = query();
if (xpath != null) {
for (final Object object : xpath.selectNodes(node)) {
if (object instanceof AstNode) {
final AstNode astNode = (AstNode) object;
if (object instanceof final AstNode astNode) {
this.addIssue(astNode, message);
} else if (object instanceof Boolean && (boolean) object) {
this.addFileIssue(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,21 @@ public List<MagikBreakpoint> setBreakpoints(final Source source, final SourceBre
// Add new breakpoints.
final List<Integer> magikBreakpointLines = breakpoints.stream()
.map(MagikBreakpoint::getMethodLine)
.collect(Collectors.toList());
.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());
.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 @@ -444,9 +444,8 @@ private MagikBreakpoint sendSetBreakpoint(final String method, final int line)
magikBreakpoint.setBreakpointId(breakpointId);
} catch (ExecutionException exception) {
final Throwable cause = exception.getCause();
if (cause instanceof SlapErrorException) {
if (cause instanceof final 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);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,19 +572,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 final 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 final ThreadStartedEvent threadStartedEvent) {
this.threadManager.handleThreadStartedEvent(threadStartedEvent);
} else if (event instanceof ThreadEndedEvent) {
final ThreadEndedEvent threadEndedEvent = (ThreadEndedEvent) event;
} else if (event instanceof final ThreadEndedEvent threadEndedEvent) {
this.threadManager.handleThreadEndedEvent(threadEndedEvent);
} else if (event instanceof StepCompletedEvent) {
final StepCompletedEvent stepCompletedEvent = (StepCompletedEvent) event;
} else if (event instanceof final 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 @@ -92,9 +92,10 @@ List<Thread> threads() throws IOException, InterruptedException, ExecutionExcept
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)) {
throw exception;
if (cause instanceof final SlapErrorException slapErrorException) {
if (slapErrorException.getError().getErrorMessage() == ErrorMessage.UNKNOWN_ERROR) {
throw exception;
}
}
}
}
Expand Down Expand Up @@ -174,9 +175,10 @@ private Path determinePath(final long threadId, final ThreadStackResponse.StackE
}
} catch (final ExecutionException exception) {
final Throwable cause = exception.getCause();
if (cause instanceof SlapErrorException
&& ((SlapErrorException) cause).getError().getErrorMessage() != ErrorMessage.METHOD_NOT_FOUND) {
throw exception;
if (cause instanceof final SlapErrorException slapErrorException) {
if (slapErrorException.getError().getErrorMessage() == ErrorMessage.METHOD_NOT_FOUND) {
throw exception;
}
}
}

Expand All @@ -194,9 +196,8 @@ 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();
final ErrorResponse error = exception2.getError();
if (exception.getCause() instanceof final SlapErrorException slapErrorException) {
final ErrorResponse error = slapErrorException.getError();
final ErrorMessage errorMessage = error.getErrorMessage();
if (errorMessage != ErrorMessage.THREAD_ALREADY_SUSPENDED) {
// Ignore 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 @@ -293,7 +292,7 @@ List<MagikVariable> getVariables(final int reference) throws IOException, Interr
final Comparator<MagikVariable> byName = Comparator.comparing(MagikVariable::getName);
return magikVariables.stream()
.sorted(byName)
.collect(Collectors.toList());
.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 @@ -188,9 +187,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);
break;
Expand Down Expand Up @@ -243,7 +240,7 @@ public RequestType getRequestType() {
public StackFrameLocalsResponse(final List<ISlapResponse> subResponses) {
this.locals = subResponses.stream()
.map(Local.class::cast)
.collect(Collectors.toList());
.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 @@ -123,7 +122,7 @@ public static StackElement decode(final ByteBuffer buffer) {
public ThreadStackResponse(final List<ISlapResponse> subResponses) {
this.stackFrames = subResponses.stream()
.map(StackElement.class::cast)
.collect(Collectors.toList());
.toList();
}

public List<StackElement> getStackFrames() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private List<CompletionItem> provideMethodInvocationCompletion(
item.setKind(CompletionItemKind.Method);
return item;
})
.collect(Collectors.toList());
.toList();
}

/**
Expand Down Expand Up @@ -345,7 +345,7 @@ private List<CompletionItem> provideKeywordCompletions() {
item.setKind(CompletionItemKind.Keyword);
return item;
})
.collect(Collectors.toList());
.toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import nl.ramsolutions.sw.magik.MagikFile;
import nl.ramsolutions.sw.magik.checks.MagikCheckHolder;
Expand Down Expand Up @@ -81,7 +80,7 @@ public List<Diagnostic> getDiagnostics(final MagikFile magikFile) throws IOExcep
final String diagnosticSource = String.format("magik-lint (%s)", checkKeyKebabCase);
return new Diagnostic(range, message, severity, diagnosticSource);
})
.collect(Collectors.toList());
.toList();
}

private DiagnosticSeverity diagnosticSeverityForMagikLintSeverity(final MagikCheckHolder holder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public List<Diagnostic> getDiagnostics(final MagikTypedFile magikFile) throws IO
final String diagnosticSource = "mtype";
return new Diagnostic(range, message, severity, diagnosticSource);
})
.collect(Collectors.toList());
.toList();
}

private Set<MagikTypedCheck> createTypedChecks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.sonar.sslr.api.AstNode;
import java.util.List;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.MagikTypedFile;
import nl.ramsolutions.sw.magik.analysis.Range;
import nl.ramsolutions.sw.magik.analysis.definitions.BinaryOperatorDefinition;
Expand Down Expand Up @@ -49,7 +48,7 @@ public List<Either<org.eclipse.lsp4j.SymbolInformation, DocumentSymbol>> provide
return definitionReader.getDefinitions().stream()
.map(this::convertDefinition)
.map(Either::<org.eclipse.lsp4j.SymbolInformation, DocumentSymbol>forRight)
.collect(Collectors.toList());
.toList();
}

private DocumentSymbol convertDefinition(final Definition definition) {
Expand All @@ -59,8 +58,7 @@ private DocumentSymbol convertDefinition(final Definition definition) {
symbolKind,
Lsp4jConversion.rangeToLsp4j(new Range(definition.getNode())),
Lsp4jConversion.rangeToLsp4j(new Range(definition.getNode())));
if (definition instanceof SlottedExemplarDefinition) {
final SlottedExemplarDefinition exemplarDefinition = (SlottedExemplarDefinition) definition;
if (definition instanceof final SlottedExemplarDefinition exemplarDefinition) {
final List<DocumentSymbol> slotSymbols = this.convertedSlotsFromDefinition(exemplarDefinition);
documentSymbol.setChildren(slotSymbols);
}
Expand Down Expand Up @@ -90,7 +88,7 @@ private List<DocumentSymbol> convertedSlotsFromDefinition(final SlottedExemplarD
SymbolKind.Field,
Lsp4jConversion.rangeToLsp4j(new Range(slotDefinition.getNode())),
Lsp4jConversion.rangeToLsp4j(new Range(slotDefinition.getNode()))))
.collect(Collectors.toList());
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.sonar.sslr.api.AstNode;
import java.util.List;
import java.util.stream.Collectors;
import nl.ramsolutions.sw.magik.MagikTypedFile;
import nl.ramsolutions.sw.magik.api.MagikGrammar;
import org.eclipse.lsp4j.FoldingRange;
Expand Down Expand Up @@ -41,7 +40,7 @@ public List<FoldingRange> provideFoldingRanges(final MagikTypedFile magikFile) {
final int endLine = folderNode.getLastToken().getLine() - 1;
return new FoldingRange(startLine, endLine);
})
.collect(Collectors.toList());
.toList();
}

}
Loading

0 comments on commit 4af44f8

Please sign in to comment.