Skip to content

Commit

Permalink
cleanup & fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jan 22, 2024
1 parent 5cecceb commit 7796746
Show file tree
Hide file tree
Showing 30 changed files with 75 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import com.intellij.compiler.server.BuildProcessParametersProvider;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.application.PathManager;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;

public class ErlangBuildProcessParametersProvider extends BuildProcessParametersProvider {
@NotNull
@Override
public List<String> getClassPath() {
return ContainerUtil.immutableList(PathManager.getJarPathForClass(ExecutionException.class));
return Collections.singletonList(PathManager.getJarPathForClass(ExecutionException.class));
}
}
28 changes: 14 additions & 14 deletions src/org/intellij/erlang/ErlangElementTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ private ErlangElementTypeFactory() {

@NotNull
public static IElementType factory(@NotNull String name) {
switch (name) {
case "ERL_FUNCTION": return new ErlangFunctionStubElementType(name);
case "ERL_BEHAVIOUR": return new ErlangBehaviourStubElementType(name);
case "ERL_MODULE": return new ErlangModuleStubElementType(name);
case "ERL_TYPE_DEFINITION": return new ErlangTypeDefinitionElementType(name);
case "ERL_MACROS_DEFINITION": return new ErlangMacrosDefinitionElementType(name);
case "ERL_RECORD_DEFINITION": return new ErlangRecordDefinitionElementType(name);
case "ERL_INCLUDE": return new ErlangIncludeElementType(name);
case "ERL_INCLUDE_LIB": return new ErlangIncludeLibElementType(name);
case "ERL_CALLBACK_SPEC": return new ErlangCallbackStubElementType(name);
case "ERL_CALLBACK_FUNCTION": return new ErlangCallbackFunctionStubElementType(name);
case "ERL_SPECIFICATION": return new ErlangSpecificationElementType(name);
}
throw new RuntimeException("Unknown element type: " + name);
return switch (name) {
case "ERL_FUNCTION" -> new ErlangFunctionStubElementType(name);
case "ERL_BEHAVIOUR" -> new ErlangBehaviourStubElementType(name);
case "ERL_MODULE" -> new ErlangModuleStubElementType(name);
case "ERL_TYPE_DEFINITION" -> new ErlangTypeDefinitionElementType(name);
case "ERL_MACROS_DEFINITION" -> new ErlangMacrosDefinitionElementType(name);
case "ERL_RECORD_DEFINITION" -> new ErlangRecordDefinitionElementType(name);
case "ERL_INCLUDE" -> new ErlangIncludeElementType(name);
case "ERL_INCLUDE_LIB" -> new ErlangIncludeLibElementType(name);
case "ERL_CALLBACK_SPEC" -> new ErlangCallbackStubElementType(name);
case "ERL_CALLBACK_FUNCTION" -> new ErlangCallbackFunctionStubElementType(name);
case "ERL_SPECIFICATION" -> new ErlangSpecificationElementType(name);
default -> throw new RuntimeException("Unknown element type: " + name);
};
}
}
2 changes: 1 addition & 1 deletion src/org/intellij/erlang/ErlangParameterInfoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ else if (p instanceof ErlangBifDescriptor) {
}
}

if (builder.length() == 0) {
if (builder.isEmpty()) {
builder.append("<no parameters>");
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/intellij/erlang/ErlangSpellcheckingStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static class AtomTokenizer extends Tokenizer<ErlangAtom> {
private static final AtomTokenizer INSTANCE = new AtomTokenizer();

@Override
public void tokenize(@NotNull ErlangAtom a, TokenConsumer consumer) {
public void tokenize(@NotNull ErlangAtom a, @NotNull TokenConsumer consumer) {
PsiElement identifier = a.getNameIdentifier();
TextRange range = identifier.getTextRange();
if (range.isEmpty()) return;
Expand Down
5 changes: 2 additions & 3 deletions src/org/intellij/erlang/ErlangStructureViewFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean isAlwaysLeaf(StructureViewTreeElement structureViewTreeElement) {

@NotNull
@Override
public Sorter[] getSorters() {
public Sorter @NotNull [] getSorters() {
return new Sorter[] {
Sorter.ALPHA_SORTER,
};
Expand Down Expand Up @@ -133,8 +133,7 @@ public ItemPresentation getPresentation() {
return elementsArray(clauses);
}
}
else if (myElement instanceof ErlangFile) {
ErlangFile file = (ErlangFile) myElement;
else if (myElement instanceof ErlangFile file) {
return elementsArray(
file.getMacroses(),
file.getRecords(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.ide.SaveAndSyncHandler;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
Expand Down
3 changes: 1 addition & 2 deletions src/org/intellij/erlang/bif/ErlangOperatorTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.intellij.erlang.bif;

import com.intellij.util.containers.ContainerUtil;
import org.intellij.erlang.psi.impl.ErlangPsiImplUtil;
import org.jetbrains.annotations.NotNull;

Expand All @@ -25,7 +24,7 @@
public class ErlangOperatorTable {
//Source: http://erlang.org/doc/reference_manual/expressions.html
//Operators '=', 'andalso', 'orelse' cannot be invoked as functions because of loss of semantics.
private static final Set<String> OPERATORS_ALLOWED_INVOKING_AS_FUNCTION = ContainerUtil.immutableSet(
private static final Set<String> OPERATORS_ALLOWED_INVOKING_AS_FUNCTION = Set.of(
"'!'/2",
"'=='/2",
"'/='/2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import static com.intellij.patterns.StandardPatterns.instanceOf;

public class ErlangKeywordsCompletionContributor extends CompletionContributor implements DumbAware {
private static final Set<String> KEYWORDS_WITH_PARENTHESIS = ContainerUtil.immutableSet(
private static final Set<String> KEYWORDS_WITH_PARENTHESIS = Set.of(
"include", "include_lib", "module", "export", "export_type", "import",
"define", "record", "behaviour", "behavior", "optional_callbacks"
);
Expand Down
20 changes: 9 additions & 11 deletions src/org/intellij/erlang/debugger/node/ErlangDebuggerNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package org.intellij.erlang.debugger.node;

import com.ericsson.otp.erlang.*;
import com.intellij.concurrency.AsyncFutureFactory;
import com.intellij.concurrency.AsyncFutureResult;
import com.intellij.openapi.application.ApplicationManager;
import org.intellij.erlang.debugger.node.commands.ErlangDebuggerCommandsProducer;
import org.intellij.erlang.debugger.node.events.ErlangDebuggerEvent;
Expand All @@ -36,6 +34,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -48,7 +47,7 @@ public class ErlangDebuggerNode {
private OtpErlangPid myLastSuspendedPid;

private final Queue<ErlangDebuggerCommandsProducer.ErlangDebuggerCommand> myCommandsQueue = new LinkedList<>();
private int myLocalDebuggerPort = -1;
private final int myLocalDebuggerPort;
@NotNull
private final ErlangDebuggerEventListener myEventListener;
@NotNull
Expand Down Expand Up @@ -129,17 +128,17 @@ private void addCommand(ErlangDebuggerCommandsProducer.ErlangDebuggerCommand com

@NotNull
private Future<Integer> runDebuggerServer() {
final AsyncFutureResult<Integer> portFuture = AsyncFutureFactory.getInstance().createAsyncFutureResult();
final CompletableFuture<Integer> portFuture = new CompletableFuture<>();
ApplicationManager.getApplication().executeOnPooledThread(() -> runDebuggerServerImpl(portFuture));
return portFuture;
}

private void runDebuggerServerImpl(@NotNull AsyncFutureResult<Integer> portFuture) {
private void runDebuggerServerImpl(@NotNull CompletableFuture<Integer> portFuture) {
try {
Exception cachedException = null;
LOG.debug("Opening a server socket.");
try (ServerSocket serverSocket = new ServerSocket(0)) {
portFuture.set(serverSocket.getLocalPort());
portFuture.complete(serverSocket.getLocalPort());

LOG.debug("Listening on port " + serverSocket.getLocalPort() + ".");

Expand Down Expand Up @@ -174,7 +173,7 @@ private void runDebuggerServerImpl(@NotNull AsyncFutureResult<Integer> portFutur
}
catch (Exception th) {
if (!portFuture.isDone()) {
portFuture.setException(th);
portFuture.completeExceptionally(th);
}
else {
LOG.debug(th);
Expand Down Expand Up @@ -274,12 +273,11 @@ private static int readObjectSize(@NotNull InputStream in) throws SocketExceptio
* @param in
* @param size
* @param force
* @return bytes read or null if the request was not forced and it timed out, or if an I/O exception occurred.
* @return bytes read or null if the request was not forced, and it timed out, or if an I/O exception occurred.
* @throws SocketException when a socket exception is thrown from passed input stream or if a number of
* retry attempts was exceeded.
*/
@Nullable
private static byte[] readBytes(@NotNull InputStream in, int size, boolean force) throws SocketException {
private static byte @Nullable [] readBytes(@NotNull InputStream in, int size, boolean force) throws SocketException {
try {
int bytesReadTotal = 0;
byte[] buffer = new byte[size];
Expand Down Expand Up @@ -315,7 +313,7 @@ private static byte[] readBytes(@NotNull InputStream in, int size, boolean force
}

@Nullable
private static OtpErlangObject decode(@NotNull byte[] bytes) {
private static OtpErlangObject decode(byte @NotNull [] bytes) {
try {
return new OtpInputStream(bytes).read_any();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public abstract class ErlangDebuggerEvent {

@Nullable
public static ErlangDebuggerEvent create(OtpErlangObject message) {
if (!(message instanceof OtpErlangTuple)) return null;
OtpErlangTuple messageTuple = (OtpErlangTuple) message;
if (!(message instanceof OtpErlangTuple messageTuple)) return null;
String messageName = OtpErlangTermUtil.getAtomText(messageTuple.elementAt(0));
if (messageName == null) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public static OtpErlangList getListValue(@Nullable OtpErlangObject listObject) {
if (listObject instanceof OtpErlangList) {
return (OtpErlangList)listObject;
}
if (listObject instanceof OtpErlangString) {
OtpErlangString string = (OtpErlangString) listObject;
if (listObject instanceof OtpErlangString string) {
return new OtpErlangList(string.stringValue());
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public SetBreakpointResponseEvent(@NotNull OtpErlangTuple message) throws Debugg
if (OtpErlangTermUtil.isOkAtom(statusObject)) {
myError = null;
}
else if (statusObject instanceof OtpErlangTuple) {
OtpErlangTuple errorTuple = (OtpErlangTuple) statusObject;
else if (statusObject instanceof OtpErlangTuple errorTuple) {
if (!OtpErlangTermUtil.isErrorAtom(errorTuple.elementAt(0))) throw new DebuggerEventFormatException();
myError = OtpErlangTermUtil.toString(errorTuple.elementAt(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,25 @@ private ElementDocProviderFactory() {
@Nullable
static ElementDocProvider create(@NotNull PsiElement psiElement) {
Project project = psiElement.getProject();
if (psiElement instanceof ErlangModule) {
if (psiElement instanceof ErlangModule erlangModule) {
VirtualFile virtualFile = getVirtualFile(psiElement);
if (virtualFile == null) return null;
ErlangModule erlangModule = (ErlangModule) psiElement;
if (isFileFromErlangSdk(project, virtualFile)) {
return new ErlangSdkModuleDocProvider(project, virtualFile);
}
return new ErlangModuleDocProvider(erlangModule);
}
else if (psiElement instanceof ErlangFunction) {
else if (psiElement instanceof ErlangFunction erlangFunction) {
VirtualFile virtualFile = getVirtualFile(psiElement);
if (virtualFile == null) return null;
ErlangFunction erlangFunction = (ErlangFunction) psiElement;
if (isFileFromErlangSdk(project, virtualFile)) {
return new ErlangSdkFunctionDocProvider(project, erlangFunction.getName(), erlangFunction.getArity(), virtualFile);
}
return new ErlangFunctionDocProvider(erlangFunction);
}
else if (psiElement instanceof ErlangTypeDefinition) {
else if (psiElement instanceof ErlangTypeDefinition typeDefinition) {
VirtualFile virtualFile = getVirtualFile(psiElement);
if (virtualFile == null) return null;
ErlangTypeDefinition typeDefinition = (ErlangTypeDefinition) psiElement;
if (isFileFromErlangSdk(project, virtualFile)) {
return new ErlangSdkTypeDocProvider(project, virtualFile, typeDefinition.getName());
}
Expand Down
14 changes: 7 additions & 7 deletions src/org/intellij/erlang/documentation/ErlangDocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@ public final class ErlangDocUtil {
/**
* <a href="https://www.erlang.org/doc/apps/edoc/chapter.html#generic-tags">Generic tags</a>
*/
private static final Set<String> EDOC_GENERIC_TAGS = ContainerUtil.set(
private static final Set<String> EDOC_GENERIC_TAGS = ContainerUtil.newHashSet(
"@clear", "@docfile", "@end", "@headerfile", "@todo", "@TODO", "@type"
);

/**
* <a href="https://www.erlang.org/doc/apps/edoc/chapter.html#overview-tags">Overview tags</a>
*/
private static final Set<String> EDOC_OVERVIEW_TAGS = ContainerUtil.set(
private static final Set<String> EDOC_OVERVIEW_TAGS = ContainerUtil.newHashSet(
"@author", "@copyright", "@doc", "@reference", "@see", "@since", "@title", "@version"
);

/**
* <a href="https://www.erlang.org/doc/apps/edoc/chapter.html#module-tags">Module tags</a>
*/
public static final Set<String> EDOC_MODULE_TAGS = ContainerUtil.set(
public static final Set<String> EDOC_MODULE_TAGS = ContainerUtil.newHashSet(
"@author", "@copyright", "@deprecated", "@doc", "@hidden", "@private", "@reference", "@see", "@since", "@version"
);

/**
* <a href="https://www.erlang.org/doc/apps/edoc/chapter.html#function-tags">Function tags</a>
*/
public static final Set<String> EDOC_FUNCTION_TAGS = ContainerUtil.set(
public static final Set<String> EDOC_FUNCTION_TAGS = ContainerUtil.newHashSet(
"@deprecated", "@doc", "@equiv", "@hidden", "@param", "@private", "@returns",
"@see", "@since", "@spec", "@throws", "@type"
);
Expand All @@ -71,9 +71,9 @@ public final class ErlangDocUtil {
private ErlangDocUtil() {
}

public static String getCommentsText(@NotNull List<PsiComment> comments,
@NotNull final String commentStartsWith,
@NotNull final Set<String> contextTags) {
public static String getCommentText(@NotNull List<PsiComment> comments,
@NotNull final String commentStartsWith,
@NotNull final Set<String> contextTags) {
List<String> lines = ContainerUtil.map(comments, PsiElement::getText);
return StringUtil.join(ContainerUtil.map(lines, s -> {
String replace = StringUtil.replace(s, commentStartsWith, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String getDocText() {
}
if (comment != null && comment.getTokenType() == ErlangParserDefinition.ERL_FUNCTION_DOC_COMMENT &&
ErlangPsiImplUtil.notFromPreviousFunction(comment, prevFunction)) {
commentText += "<b>Comment:</b><br/>" + ErlangDocUtil.getCommentsText(
commentText += "<b>Comment:</b><br/>" + ErlangDocUtil.getCommentText(
ErlangDocUtil.collectPrevComments(comment), "%%", ErlangDocUtil.EDOC_FUNCTION_TAGS);
}
return ErlangDocUtil.wrapInPreTag(commentText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getDocText() {
PsiComment comment = PsiTreeUtil.getPrevSiblingOfType(parent, PsiComment.class);
if (comment != null && comment.getTokenType() == ErlangParserDefinition.ERL_MODULE_DOC_COMMENT) {
List<PsiComment> comments = ErlangDocUtil.collectPrevComments(comment);
String commentsText = ErlangDocUtil.getCommentsText(comments, "%%%", ErlangDocUtil.EDOC_MODULE_TAGS);
String commentsText = ErlangDocUtil.getCommentText(comments, "%%%", ErlangDocUtil.EDOC_MODULE_TAGS);
return ErlangDocUtil.wrapInPreTag(commentsText);
}
return null;
Expand Down
5 changes: 2 additions & 3 deletions src/org/intellij/erlang/editor/ErlangFoldingBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public class ErlangFoldingBuilder extends FoldingBuilderEx implements DumbAware
@NotNull
@Override
public FoldingDescriptor @NotNull [] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
if (!(root instanceof ErlangFile)) return FoldingDescriptor.EMPTY;
ErlangFile file = (ErlangFile) root;
if (!(root instanceof ErlangFile file)) return FoldingDescriptor.EMPTY_ARRAY;

final List<FoldingDescriptor> result = new ArrayList<>();
for (ErlangFunction function : file.getFunctions()) {
Expand All @@ -55,7 +54,7 @@ public class ErlangFoldingBuilder extends FoldingBuilderEx implements DumbAware
});
}

return result.toArray(new FoldingDescriptor[result.size()]);
return result.toArray(new FoldingDescriptor[0]);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ private ErlangUnitRunConfiguration createRerunFailedTestsRunConfiguration() {
Location location = testProxy.getLocation(project, GlobalSearchScope.allScope(project));
PsiElement psiElement = location != null ? location.getPsiElement() : null;

if (!(psiElement instanceof ErlangFunction)) continue;
if (!(psiElement instanceof ErlangFunction function)) continue;

ErlangFunction function = (ErlangFunction) psiElement;
String functionName = ErlangPsiImplUtil.getQualifiedFunctionName(function);
testsToRerun.add(functionName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/intellij/erlang/eunit/ErlangUnitRunningState.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ else if (kind == ErlangUnitRunConfiguration.ErlangUnitRunConfigurationKind.FUNCT
for (Map.Entry<String, List<String>> e : modules.entrySet()) {
String moduleName = e.getKey();

result.append("{\"module \'").append(moduleName).append("\'\", [");
result.append("{\"module '").append(moduleName).append("'\", [");
for (String function : e.getValue()) {
boolean isGenerator = ErlangPsiImplUtil.isEunitTestGeneratorFunctionName(function);
result.append(isGenerator ? "{generator, " : "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ private void onTestKindSwitch() {
}

private static ListCellRendererWrapper<ErlangUnitRunConfiguration.ErlangUnitRunConfigurationKind> getTestKindListCellRendererWrapper() {
return new ListCellRendererWrapper<ErlangUnitRunConfiguration.ErlangUnitRunConfigurationKind>() {
return new ListCellRendererWrapper<>() {
@Override
public void customize(JList list, ErlangUnitRunConfiguration.ErlangUnitRunConfigurationKind kind, int index, boolean selected, boolean hasFocus) {
public void customize(JList list,
ErlangUnitRunConfiguration.ErlangUnitRunConfigurationKind kind,
int index,
boolean selected,
boolean hasFocus) {
if (kind != null) {
String kindName = StringUtil.capitalize(kind.toString().toLowerCase());
setText(kindName);
Expand Down
Loading

0 comments on commit 7796746

Please sign in to comment.