From 397e9e402650b7c1965f494de401b6615349eac3 Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 19 Nov 2024 18:38:06 +0100 Subject: [PATCH] docs: add Java-Docs --- .../java/de/dhbw/JavaTXLanguageServer.java | 18 ++++++- .../de/dhbw/JavaTXLanguageServerLauncher.java | 5 ++ .../de/dhbw/JavaTXTextDocumentService.java | 51 ++++++++++++++++++- .../java/de/dhbw/JavaTXWorkspaceService.java | 5 ++ .../de/dhbw/helper/CodeSnippetOptions.java | 4 ++ .../main/java/de/dhbw/helper/TypeFinder.java | 17 +++++-- 6 files changed, 94 insertions(+), 6 deletions(-) diff --git a/LanguageServer/src/main/java/de/dhbw/JavaTXLanguageServer.java b/LanguageServer/src/main/java/de/dhbw/JavaTXLanguageServer.java index e272313..6587bb5 100644 --- a/LanguageServer/src/main/java/de/dhbw/JavaTXLanguageServer.java +++ b/LanguageServer/src/main/java/de/dhbw/JavaTXLanguageServer.java @@ -8,7 +8,11 @@ import org.eclipse.lsp4j.services.LanguageServer; import java.util.List; import java.util.concurrent.CompletableFuture; - +/** + * + * Configuration of the Language Server + * + * */ public class JavaTXLanguageServer implements LanguageServer { private LanguageClient client; @@ -21,6 +25,9 @@ public class JavaTXLanguageServer implements LanguageServer { private final JavaTXTextDocumentService textDocumentService = new JavaTXTextDocumentService(); private final JavaTXWorkspaceService workspaceService = new JavaTXWorkspaceService(); + /** + * Configure the Features of the LanguageServer + * */ @Override public CompletableFuture initialize(InitializeParams params) { ServerCapabilities capabilities = new ServerCapabilities(); @@ -35,16 +42,25 @@ public class JavaTXLanguageServer implements LanguageServer { return CompletableFuture.supplyAsync(() -> new InitializeResult(capabilities)); } + /** + * @return the TextDocumentService + * */ @Override public TextDocumentService getTextDocumentService() { return textDocumentService; } + /** + * @return the WorkspaceService + * */ @Override public WorkspaceService getWorkspaceService() { return workspaceService; } + /** + * @return the Client + * */ public LanguageClient getClient() { return client; } diff --git a/LanguageServer/src/main/java/de/dhbw/JavaTXLanguageServerLauncher.java b/LanguageServer/src/main/java/de/dhbw/JavaTXLanguageServerLauncher.java index 77b28e0..89ec2dc 100644 --- a/LanguageServer/src/main/java/de/dhbw/JavaTXLanguageServerLauncher.java +++ b/LanguageServer/src/main/java/de/dhbw/JavaTXLanguageServerLauncher.java @@ -7,6 +7,11 @@ import org.eclipse.lsp4j.services.LanguageClient; import java.util.HashSet; +/** + * + * Start the JavaTX language Server and use System In and System Out for Communication + * + * */ public class JavaTXLanguageServerLauncher { public static void main(String[] args) { diff --git a/LanguageServer/src/main/java/de/dhbw/JavaTXTextDocumentService.java b/LanguageServer/src/main/java/de/dhbw/JavaTXTextDocumentService.java index 90cc448..581997b 100644 --- a/LanguageServer/src/main/java/de/dhbw/JavaTXTextDocumentService.java +++ b/LanguageServer/src/main/java/de/dhbw/JavaTXTextDocumentService.java @@ -22,6 +22,11 @@ import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTreeWalker; +/** +* +* Handles Actions in Documents, such as Autocompletion, Change-Events and Syntax-Checks +* +* */ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.TextDocumentService { LanguageClient client; @@ -33,6 +38,14 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex this.client = client; } + + /** + * + * Handles Completion Events + * + * @param params the completion Context + * @return the Auto-Completion Items that will be displayed + * */ @Override public CompletableFuture, CompletionList>> completion(CompletionParams params) { List completions = new ArrayList<>(); @@ -50,11 +63,23 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex return CompletableFuture.completedFuture(Either.forLeft(completions)); } + /** + * + * Handles didOpen Events + * + * @param params the Context of the newly opened Document + * */ @Override public void didOpen(DidOpenTextDocumentParams params) { client.showMessage(new MessageParams(MessageType.Info, "Datei geƶffnet: " + params.getTextDocument().getUri())); } + /** + * + * Handles didChange + * + * @param params the Context of the Changed Document, including the incremental change as well as the whole Document + * */ @Override public void didChange(DidChangeTextDocumentParams params) { @@ -84,6 +109,12 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex } + /** + * + * Handles a Formatting-Event + * + * @param params the Context of the Formatting + * */ @Override public CompletableFuture> formatting(DocumentFormattingParams params) { List edits = new ArrayList<>(); @@ -196,8 +227,18 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex return null; } + /** + * + * returns the whole Word of the selected Character - Currently not correctly working + * + * @param line the line of the Character + * @param character the character in the line + * @param document the Document-Content as String + * + * @return the String containing the Word + * */ public String getWordOfLineAndCharacter(int line, int character, String document) { - var textArr = document.split("\n"); + var textArr = document.replace(";", " ; ").replace("{", " { ").replace("}", " } ").split("\n"); var selectedLine = textArr[line]; var hoverWord = ""; @@ -207,13 +248,19 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex index += word.length(); if (index - word.length() <= character && index >= character) { - hoverWord = word; + hoverWord = word.replace(" ", ""); } } return hoverWord; } + /** + * + * Handles a Hover-Event + * + * @param params the Context of the Hovering + * */ @Override public CompletableFuture hover(HoverParams params) { diff --git a/LanguageServer/src/main/java/de/dhbw/JavaTXWorkspaceService.java b/LanguageServer/src/main/java/de/dhbw/JavaTXWorkspaceService.java index 2cfb889..e72c268 100644 --- a/LanguageServer/src/main/java/de/dhbw/JavaTXWorkspaceService.java +++ b/LanguageServer/src/main/java/de/dhbw/JavaTXWorkspaceService.java @@ -4,6 +4,11 @@ import org.eclipse.lsp4j.DidChangeConfigurationParams; import org.eclipse.lsp4j.services.WorkspaceService; import org.eclipse.lsp4j.DidChangeWatchedFilesParams; +/** + * + * Handles Actions in Workspace + * + * */ public class JavaTXWorkspaceService implements WorkspaceService { diff --git a/LanguageServer/src/main/java/de/dhbw/helper/CodeSnippetOptions.java b/LanguageServer/src/main/java/de/dhbw/helper/CodeSnippetOptions.java index d6c39d7..cd648d9 100644 --- a/LanguageServer/src/main/java/de/dhbw/helper/CodeSnippetOptions.java +++ b/LanguageServer/src/main/java/de/dhbw/helper/CodeSnippetOptions.java @@ -4,6 +4,10 @@ import de.dhbw.model.SnippetWithName; import java.util.ArrayList; +/** + * Helper-Class containing all Snippets + * + * */ public class CodeSnippetOptions { private ArrayList snippets = new ArrayList<>(); diff --git a/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java b/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java index 08be09b..bd65fd1 100644 --- a/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java +++ b/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java @@ -6,11 +6,22 @@ import java.util.Arrays; import java.util.Stack; import java.util.concurrent.atomic.AtomicReference; + +/** + * Helper-Class for finding the Type of a selected Word + * + * */ public class TypeFinder { - - - + /** + * find the Type of a specific Word, given by its line and character. The character must be any Part of the Word. + * + * DOES NOT WORK RIGHT NOW + * + * @param line the line of the character + * @param character the character of the character or the char-Number of the String + * @param currentTextDocument the String of the Content of the current Document. + * */ public String find(int line, int character, String currentTextDocument) { String[] validTypes = {