Compare commits

...

14 Commits

Author SHA1 Message Date
dholle 1cc679afb4 Improvements 2026-06-25 15:59:09 +02:00
dholle 40e5549062 Correctly strip off package names 2026-06-24 14:49:11 +02:00
dholle 4e4eb45842 Update plugin 2026-06-24 14:23:50 +02:00
dholle c0a30af6ef Fix old api usage 2026-04-29 10:31:54 +02:00
dholle 68843eac17 delimiter, not sep 2025-11-26 18:15:32 +01:00
dholle 2c4ff6e237 Update version 2025-11-26 18:14:27 +01:00
dholle c9d878cf30 Fix path delimiter for windows 2025-11-26 18:12:53 +01:00
dholle 75943a8d95 Resolve file paths in emacs client 2025-11-12 13:24:26 +01:00
dholle 53e6d94180 README 2025-10-29 13:34:53 +01:00
dholle d6db2d70e7 Move file 2025-10-22 11:41:30 +02:00
dholle 3bc2340a0c Add emacs mode and fix some incompatibilities 2025-10-22 11:40:32 +02:00
dholle b691d6e0e3 Resolve path 2025-10-09 17:48:00 +02:00
dholle 6917c43c33 Specify compiler path in extension settings 2025-10-02 18:10:50 +02:00
Vic Nightfall 1a0596ca71 Version bump 2025-09-28 14:20:59 +02:00
21 changed files with 3020 additions and 938 deletions
+2571 -632
View File
File diff suppressed because it is too large Load Diff
+14 -1
View File
@@ -3,7 +3,7 @@
"name": "java-tx-language-extension",
"displayName": "Java-TX Language Extension",
"description": "The Language Extension for Java-TX with Typehints and Syntax Checks",
"version": "0.0.14",
"version": "0.0.21",
"engines": {
"vscode": "^1.94.0"
},
@@ -20,6 +20,18 @@
"command": "tx.restartLanguageServer",
"title": "TX: Restart Language Server"
}
],
"configuration": [
{
"title": "JavaTX Language Server Plugin",
"properties": {
"tx.compilerLocation": {
"type": "string",
"format": "file",
"description": "JavaTX Compiler Location"
}
}
}
]
},
"scripts": {
@@ -42,6 +54,7 @@
"typescript": "^5.6.2"
},
"dependencies": {
"@vscode/vsce": "^3.6.1",
"vscode-languageclient": "^9.0.1"
}
}
+58 -21
View File
@@ -1,28 +1,67 @@
import path from 'path';
import os from "os";
import * as vscode from 'vscode';
import {
Executable,
LanguageClient,
LanguageClientOptions,
ServerOptions
} from 'vscode-languageclient/node';
let homeDirectory: string;
let currentUser: string;
function untildify(pathWithTilde: string) {
if (homeDirectory === undefined) {
homeDirectory = os.homedir();
}
// Handle regular ~ expansion (current user)
if (homeDirectory && /^~(?=$|\/|\\)/.test(pathWithTilde)) {
return pathWithTilde.replace(/^~/, homeDirectory);
}
// Handle ~username expansion (only for current user)
const userMatch = pathWithTilde.match(/^~([^/\\]+)(.*)/);
if (userMatch) {
if (currentUser === undefined) {
currentUser = os.userInfo().username;
}
if (currentUser) {
const username = userMatch[1];
const rest = userMatch[2];
if (username === currentUser) {
return homeDirectory + rest;
}
}
}
// Return unchanged if no expansion occurred
return pathWithTilde;
}
let client: LanguageClient | undefined; // <— global, damit wir neu starten können
function createClient(context: vscode.ExtensionContext): LanguageClient {
function createClient(context: vscode.ExtensionContext): LanguageClient | null {
const workspaceFolder = context.extensionPath;
const config = vscode.workspace.getConfiguration("tx");
let compiler = config.get<string>("compilerLocation");
if (!compiler || compiler.trim() === "") {
vscode.window.showErrorMessage("Bitte konfiguriere den Pfad des Java-TX Compilers in den Einstellungen!");
return null;
}
compiler = path.resolve(untildify(compiler));
const cmd: Executable = {
command: 'java',
args: ['-Xss10m', '-cp', `${compiler}${path.delimiter}${workspaceFolder}/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar`, "de.dhbw.JavaTXLanguageServerLauncher"],
};
const serverOptions: ServerOptions = {
run: {
command: 'java',
args: ['-Xss10m', '-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"],
},
debug: {
command: 'java',
args: [
'-Xss10m',
'-jar',
workspaceFolder + '/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar',
],
}
run: cmd,
debug: cmd
};
const clientOptions: LanguageClientOptions = {
@@ -42,7 +81,9 @@ function createClient(context: vscode.ExtensionContext): LanguageClient {
}
export async function activate(context: vscode.ExtensionContext) {
client = createClient(context);
const c = createClient(context);
if (!c) return;
client = c;
client.start()
.then(() => console.log("Language Client erfolgreich gestartet"))
@@ -50,12 +91,6 @@ export async function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "tx" is now active!');
// Beispiel-Command aus deinem Code bleibt
const hello = vscode.commands.registerCommand('lspclient.helloWorld', () => {
vscode.window.showInformationMessage('Hello World from TX!');
});
context.subscriptions.push(hello);
// *** NEU: Restart-Command ***
const restart = vscode.commands.registerCommand('tx.restartLanguageServer', async () => {
if (!client) {
@@ -68,7 +103,9 @@ export async function activate(context: vscode.ExtensionContext) {
} catch (e) {
console.error('Fehler beim Stoppen des Language Clients:', e);
}
client = createClient(context); // komplett neu erzeugen
const c = createClient(context); // komplett neu erzeugen
if (!c) return;
client = c;
try {
await client.start();
vscode.window.showInformationMessage('Java-TX Language Server neu gestartet.');
+11
View File
@@ -0,0 +1,11 @@
## Install emacs plugin:
Edit your .emacs file and add the following:
```
(use-package javatx-mode
:custom
(javatx-compiler-path "$PATH_TO_COMPILER$")
(javatx-lsp-server-path "$PATH_TO_LSP$")
:load-path "~/.emacs.d/lisp")
```
+84
View File
@@ -0,0 +1,84 @@
;;; javatx-mode.el --- Major mode for .jav files -*- lexical-binding: t; -*-
(defvar javatx-mode-hook nil
"Hook called when entering `javatx-mode`.")
;; Define the mode
(define-derived-mode javatx-mode java-mode "Javatx"
"Major mode for editing `.jav` files.")
;; Automatically use javatx-mode for .jav files
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.jav\\'" . javatx-mode))
(provide 'javatx-mode)
;;; javatx-mode.el ends here
;; Initialize package sources
(require 'package)
(setq package-archives
'(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
;; Refresh package contents if needed
(unless package-archive-contents
(package-refresh-contents))
;; Install use-package if not installed
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t) ;; automatically install packages if missing
(use-package lsp-mode
:hook (prog-mode . lsp)
:commands lsp
:config
(setq lsp-prefer-flymake nil)) ;; use flycheck instead of flymake
(use-package lsp-ui
:commands lsp-ui-mode
:hook (lsp-mode . lsp-ui-mode)
:config
(setq lsp-ui-sideline-show-hover t
lsp-ui-sideline-show-code-actions t
lsp-ui-sideline-show-diagnostics t))
(defcustom javatx-compiler-path nil
"Path to the JavaTX Compiler jar."
:type 'string
:group 'javatx)
(defcustom javatx-lsp-server-path nil
"Path to the JavaTX Language Server jar."
:type 'string
:group 'javatx)
;;register javatx-mode lsp
(with-eval-after-load 'lsp-mode
(message "Compiler path: %s" javatx-compiler-path)
(message "Server path: %s" javatx-lsp-server-path)
(add-to-list 'lsp-language-id-configuration '(javatx-mode . "Java-TX"))
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection (lambda () `("java" "-cp" ,(format "%s:%s" (expand-file-name javatx-compiler-path) (expand-file-name javatx-lsp-server-path)) "de.dhbw.JavaTXLanguageServerLauncher")))
:major-modes '(javatx-mode)
:server-id 'javatx-lsp-proxy)))
(add-hook 'javatx-mode-hook #'lsp) ;; start LSP automatically for .jav files
;; Automatically enable inlay hints for javatx-mode
(add-hook 'javatx-mode-hook
(lambda ()
;; Replace 'lsp-inlay-hints-mode' with whatever inlay hints function you use
(when (fboundp 'lsp-inlay-hints-mode)
(lsp-inlay-hints-mode 1))))
(setq lsp-log-io t) ;; enable logging of LSP messages
(with-eval-after-load 'lsp-mode
(define-key lsp-mode-map (kbd "C-c a") 'lsp-execute-code-action))
+29 -45
View File
@@ -14,61 +14,22 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4 -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>4.11.1</version>
</dependency>
<dependency>
<groupId>io.github.java-diff-utils</groupId>
<artifactId>java-diff-utils</artifactId>
<version>4.12</version>
</dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.172</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.2.0-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j</artifactId>
@@ -78,6 +39,7 @@
<groupId>de.dhbwstuttgart</groupId>
<artifactId>JavaTXcompiler</artifactId>
<version>0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
@@ -110,7 +72,6 @@
<release>21</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
@@ -134,6 +95,29 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-fat-jar</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${project.basedir}/../Clients/VisualStudioCode"/>
<copy
file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar"
todir="${project.basedir}/../Clients/VisualStudioCode"
overwrite="true"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -17,6 +17,7 @@ import java.util.concurrent.CompletableFuture;
* */
public class JavaTXLanguageServer implements LanguageServer {
private static final Logger logger = LogManager.getLogger(JavaTXLanguageServer.class);
public static ClientCapabilities capabilities;
private LanguageClient client;
public void connect(LanguageClient client) {
@@ -48,6 +49,7 @@ public class JavaTXLanguageServer implements LanguageServer {
if(params.getWorkspaceFolders() != null && !params.getWorkspaceFolders().isEmpty()) {
textDocumentService.setFileRoot(params.getWorkspaceFolders());
}
JavaTXLanguageServer.capabilities = params.getCapabilities();
return CompletableFuture.supplyAsync(() -> new InitializeResult(capabilities));
}
@@ -113,8 +113,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
if (!syntaxErrors.isEmpty()) {
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
}
client.refreshDiagnostics();
client.refreshInlayHints();
clientService.updateClient();
textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText());
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), params.getTextDocument().getText());
}
@@ -154,10 +153,10 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
@Override
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
logService.log("[didSave] Client triggered didSave-Event.");
clientService.startLoading("compile-task", "Inferring types...", client);
clientService.startLoading("compile-task", "Inferring types...");
saveHandler.handleSave(didSaveTextDocumentParams);
clientService.stopLoading("compile-task", "Types successfully inferred", client);
clientService.updateClient(client);
clientService.stopLoading("compile-task", "Types successfully inferred");
clientService.updateClient();
}
@Override
@@ -298,7 +297,9 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
logService.log("[codeAction] Client requested Insert at Line [" + params.getRange().getStart().getLine() + "] and from Char [" + params.getRange().getStart().getCharacter() + "] to [" + params.getRange().getEnd().getCharacter() + "].", MessageType.Info);
logService.log("Code-Action Context was: " + params.getContext().getTriggerKind().name(), MessageType.Info);
var triggerKind = params.getContext().getTriggerKind();
if (triggerKind != null)
logService.log("Code-Action Context was: " + triggerKind.name(), MessageType.Info);
return CompletableFuture.supplyAsync(() -> {
return codeActionHandler.handleNewCodeAction(params);
@@ -3,6 +3,7 @@ package de.dhbw.handler;
import com.google.common.base.Stopwatch;
import de.dhbw.helper.ConversionHelper;
import de.dhbw.helper.TypeResolver;
import de.dhbw.helper.TypeResolver.InferenceResult;
import de.dhbw.model.*;
import de.dhbw.service.*;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
@@ -107,105 +108,101 @@ public class ChangeHandler {
logService.log("Should Calculate is: " + shouldCalculate);
if (false) {
try {
File tempDir = new File(System.getProperty("java.io.tmpdir"));
File tempFile = File.createTempFile("newText", ".tmp", tempDir);
FileWriter fileWriter = new FileWriter(tempFile, true);
System.out.println(tempFile.getAbsolutePath());
BufferedWriter bw = new BufferedWriter(fileWriter);
bw.write(summedUp.get());
bw.close();
typeResolver.updateAst(tempFile.toURI().getPath());
tempFile.delete();
} catch (Exception e) {
logService.log(e.getMessage());
/*try {
File tempDir = new File(System.getProperty("java.io.tmpdir"));
File tempFile = File.createTempFile("newText", ".tmp", tempDir);
FileWriter fileWriter = new FileWriter(tempFile, true);
System.out.println(tempFile.getAbsolutePath());
BufferedWriter bw = new BufferedWriter(fileWriter);
bw.write(summedUp.get());
bw.close();
typeResolver.updateAst(tempFile.toURI().getPath());
tempFile.delete();
} catch (Exception e) {
logService.log(e.getMessage());
}
var sWatch = Stopwatch.createUnstarted();
sWatch.start();
try {
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereChangeInput();
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(typesOfMethodAndParameters, params.getTextDocument().getUri());
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
} catch (Exception e) {
logService.log("[didChange] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
for (var stackTrace : e.getStackTrace()) {
logService.log(stackTrace.toString());
}
var sWatch = Stopwatch.createUnstarted();
sWatch.start();
clientService.showMessage(MessageType.Error, e.getMessage());
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
} finally {
sWatch.stop();
logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
}
List<Diagnostic> typeDiagnostics = cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri());
ArrayList<Diagnostic> allDiagnostics = new ArrayList<>(typeDiagnostics);
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);*/
logService.log("Calculating again.");
var sWatch = Stopwatch.createUnstarted();
sWatch.start();
try {
try {
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereChangeInput();
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(typesOfMethodAndParameters, params.getTextDocument().getUri());
File tempDir2 = Path.of(new URI(params.getTextDocument().getUri())).getParent().toFile();
File tempFile2 = File.createTempFile("jtx_temp", ".tmp", tempDir2);
FileWriter fileWriter = new FileWriter(tempFile2, true);
BufferedWriter bw = new BufferedWriter(fileWriter);
bw.write(input);
bw.close();
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
try {
InferenceResult inferenceResult = typeResolver.infereInput(tempFile2.toURI().toString(), input);
cacheService.setVariables(inferenceResult.variables());
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(inferenceResult, input);
} catch (Exception e) {
logService.log("[didChange] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
for (var stackTrace : e.getStackTrace()) {
logService.log(stackTrace.toString());
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
} catch (Exception | VerifyError f) {
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + f.getMessage(), MessageType.Error);
for (StackTraceElement elem : f.getStackTrace()) {
logService.log(elem.toString());
}
clientService.showMessage(MessageType.Error, f.getMessage() == null ? "null" : f.getMessage());
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
}
clientService.showMessage(MessageType.Error, e.getMessage());
tempFile2.delete();
} catch (Exception e) {
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
} finally {
sWatch.stop();
logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
}
List<Diagnostic> typeDiagnostics = cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri());
ArrayList<Diagnostic> allDiagnostics = new ArrayList<>(typeDiagnostics);
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
} else {
logService.log("Calculating again.");
var sWatch = Stopwatch.createUnstarted();
sWatch.start();
try {
try {
File tempDir2 = Path.of(new URI(params.getTextDocument().getUri())).getParent().toFile();
File tempFile2 = File.createTempFile("jtx_temp", ".tmp", tempDir2);
FileWriter fileWriter = new FileWriter(tempFile2, true);
BufferedWriter bw = new BufferedWriter(fileWriter);
bw.write(input);
bw.close();
try {
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input);
cacheService.setVariables(variables);
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(variables, input);
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
} catch (Exception | VerifyError f) {
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + f.getMessage(), MessageType.Error);
for (StackTraceElement elem : f.getStackTrace()) {
logService.log(elem.toString());
}
clientService.showMessage(MessageType.Error, f.getMessage() == null ? "null" : f.getMessage());
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
}
tempFile2.delete();
} catch (Exception e) {
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
} finally {
sWatch.stop();
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
}
} catch (Exception e) {
logService.log(e.getMessage());
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
}
} catch (Exception e) {
logService.log(e.getMessage());
}
}
}
}
@@ -1,6 +1,8 @@
package de.dhbw.handler;
import de.dhbw.helper.ASTTransformationHelper;
import de.dhbw.helper.ConversionHelper;
import de.dhbw.helper.InsertPoint;
import de.dhbw.helper.TextHelper;
import de.dhbw.helper.TypeResolver;
import de.dhbw.service.CacheService;
@@ -68,8 +70,8 @@ public class CodeActionHandler {
}
public static <V> Map<String, V> getOverlapping(
Map<String, V> map,
public static <V> Map<InsertPoint, V> getOverlapping(
Map<InsertPoint, V> map,
int line,
int startChar,
int endChar
@@ -83,20 +85,13 @@ public class CodeActionHandler {
final int s = startChar, e = endChar;
return map.entrySet().stream()
.filter(entry -> {
String key = entry.getKey();
String[] parts = key.split("\\s+");
if (parts.length != 2) return false;
try {
int kLine = Integer.parseInt(parts[0]);
int kChar = Integer.parseInt(parts[1]);
return kLine == line && kChar >= s && kChar <= e;
} catch (NumberFormatException ex) {
// Key nicht im erwarteten Format
return false;
}
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.filter(entry -> {
InsertPoint key = entry.getKey();
int kLine = key.line();
int kChar = key.character();
return kLine == line && kChar >= s && kChar <= e;
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
@@ -107,9 +102,9 @@ public class CodeActionHandler {
if (typeResolver.getInserts() != null) {
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
Map<InsertPoint, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
logService.log("Inserts are:");
typeResolver.getInserts().forEach((key, value) -> logService.log(key));
typeResolver.getInserts().forEach((key, value) -> logService.log(key.toString()));
logService.log("Size is: " + typeInsertsOverlapping.size());
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
List<Either<Command, CodeAction>> actions = new ArrayList<>();
@@ -125,15 +120,18 @@ public class CodeActionHandler {
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
var isTypeImported = false;
Map<String, List<TextEdit>> changes = new HashMap<>();
changes.put(documentUri, listOfChanges);
WorkspaceEdit edit = new WorkspaceEdit();
edit.setChanges(changes);
CodeAction action = new CodeAction("Insert " + conversionHelper.cleanType(typeInsert.getInsertString()));
var constraints = typeInsert.getConstraints();
var genericsString = "";
if (constraints != null && !constraints.isEmpty()) {
genericsString = ASTTransformationHelper.createConstraintsString(constraints);
}
CodeAction action = new CodeAction("Insert " + ConversionHelper.cleanType(typeInsert.getInsertString()) + genericsString);
action.setKind(CodeActionKind.QuickFix);
action.setEdit(edit);
@@ -6,6 +6,7 @@ import de.dhbw.model.DiagnosticsAndTypehints;
import de.dhbw.service.*;
import de.dhbw.helper.ConversionHelper;
import de.dhbw.helper.TypeResolver;
import de.dhbw.helper.TypeResolver.InferenceResult;
import de.dhbw.model.LSPVariable;
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
@@ -65,10 +66,10 @@ public class SaveHandler {
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
}
ArrayList<LSPVariable> variables = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
cacheService.setVariables(variables);
InferenceResult inferenceResult = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
cacheService.setVariables(inferenceResult.variables());
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(variables, didSaveTextDocumentParams.getTextDocument().getUri());
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(inferenceResult, didSaveTextDocumentParams.getTextDocument().getUri());
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
@@ -15,12 +15,13 @@ import de.dhbwstuttgart.typeinference.result.*;
import org.antlr.v4.runtime.Token;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class ASTTransformationHelper {
public static Set<PlaceholderVariable> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, GenericsResult generics) {
return new PlaceholderPlacer().getTypeInserts(forSourcefile, withResults, generics);
public static Set<PlaceholderVariable> createTypeInsertPoints(SourceFile forSourcefile, GenericsResult generics) {
return new PlaceholderPlacer(forSourcefile, generics).getTypeInserts();
}
public static PlaceholderVariable createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
@@ -29,27 +30,20 @@ public class ASTTransformationHelper {
ResolvedType resolvedType = resultSet.resolveType(type);
PlaceholderPoint insertPoint = new PlaceholderPoint(offset,
new PlaceholderToInsertString(resolvedType.resolvedType, constraints, classConstraints).insert, PlaceholderType.NORMAL_INSERT);
return new PlaceholderVariable(insertPoint, createGenericInsert(constraints, classConstraints, cl, m, resultSet, offset), resolvedType.getResultPair());
return new PlaceholderVariable(insertPoint, createGenericInsert(constraints, classConstraints, cl, m, offset), resolvedType.getResultPair(), constraints);
}
private static synchronized Set<PlaceholderPoint> createGenericInsert(GenericsResultSet methodConstraints, GenericsResultSet classConstraints, ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){
private static synchronized Set<PlaceholderPoint> createGenericInsert(GenericsResultSet methodConstraints, GenericsResultSet classConstraints, ClassOrInterface cl, Method m, Token mOffset){
Set<PlaceholderPoint> result = createGenericClassInserts(classConstraints, cl);
if (m != null) {
result.addAll(createMethodConstraints(methodConstraints, m.getOffset() != null ? m.getOffset() : mOffset));
createMethodConstraints(methodConstraints, m.getOffset() != null ? m.getOffset() : mOffset).ifPresent(result::add);
}
return result;
}
private static Set<PlaceholderPoint> createMethodConstraints(GenericsResultSet constraints, Token mOffset) {
Set<PlaceholderPoint> result = new HashSet<>();
Token offset = mOffset;
if (constraints.size() == 0) {
return result;
}
public static String createConstraintsString(GenericsResultSet constraints) {
String insert = " <";
for (var genericInsertConstraint : constraints) {
@@ -63,9 +57,16 @@ public class ASTTransformationHelper {
insert = insert.substring(0, insert.length() -2);
insert += ">";
result.add(new PlaceholderPoint(offset, insert, PlaceholderType.GENERERIC_METHOD_INSERT));
return result;
return insert;
}
private static Optional<PlaceholderPoint> createMethodConstraints(GenericsResultSet constraints, Token mOffset) {
Token offset = mOffset;
if (constraints.size() == 0) {
return Optional.empty();
}
return Optional.of(new PlaceholderPoint(offset, createConstraintsString(constraints), PlaceholderType.GENERERIC_METHOD_INSERT));
}
private static Set<PlaceholderPoint> createGenericClassInserts(GenericsResultSet classConstraints, ClassOrInterface cl) {
@@ -75,23 +76,7 @@ public class ASTTransformationHelper {
if (classConstraints == null || classConstraints.size() == 0) {
return result;
}
String insert = " <";
for (var genericInsertConstraint : classConstraints) {
if (genericInsertConstraint instanceof GenerateGenerics.PairEQ peq) {
insert += peq.left.resolve().getName();
} else if (genericInsertConstraint instanceof GenerateGenerics.PairLT psm) {
insert += psm.left.resolve().getName() + " extends " + psm.right.resolve().getName();
}
insert += ", ";
}
insert = insert.substring(0, insert.length() -2);
insert += ">";
result.add(new PlaceholderPoint(offset, insert, PlaceholderType.GENERIC_CLASS_INSERT));
result.add(new PlaceholderPoint(offset, createConstraintsString(classConstraints), PlaceholderType.GENERIC_CLASS_INSERT));
return result;
}
}
@@ -1,9 +1,11 @@
package de.dhbw.helper;
import de.dhbw.helper.TypeResolver.InferenceResult;
import de.dhbw.model.DiagnosticsAndTypehints;
import de.dhbw.service.TextDocumentService;
import de.dhbw.model.LSPVariable;
import de.dhbw.model.Type;
import de.dhbwstuttgart.exceptions.CompilerWarning;
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
import org.eclipse.lsp4j.*;
@@ -20,8 +22,9 @@ public class ConversionHelper {
this.textDocumentService = textDocumentService;
}
public String cleanType(String type){
return type.replaceAll("java.lang.", "").replaceAll("java.util.", "");
public static String cleanType(String type) {
// Strip package from type string for better readability in diagnostics and inlay hints
return type.replaceAll("\\b(?:[A-Za-z_]\\w*\\.)+(\\w+)\\b", "$1");
}
public InlayHint getInlayHint(LSPVariable variable) {
@@ -29,7 +32,7 @@ public class ConversionHelper {
String typeDisplay = "";
for (Type type : variable.getPossibleTypes()) {
typeDisplay += " | " + cleanType(type.getType().replaceAll("GTV ", ""));
typeDisplay += "| " + cleanType(type.getType().replaceAll("GTV ", ""));
}
@@ -90,11 +93,35 @@ public class ConversionHelper {
}).toList();
}
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(ArrayList<LSPVariable> typesOfMethodAndParameters, String uri) {
public DiagnosticsAndTypehints addWarningsToDiagnostics(DiagnosticsAndTypehints diagnosticsAndTypehints, List<CompilerWarning> warnings) {
List<Diagnostic> diagnostics = new ArrayList<>(diagnosticsAndTypehints.getDiagnostics());
for (var warning : warnings) {
var offset = warning.getOffset();
Range warningRange = new Range(
new Position(offset.getLine() - 1, offset.getCharPositionInLine()),
new Position(offset.getLine() - 1, offset.getCharPositionInLine() + offset.getText().length())
);
Diagnostic diagnostic = new Diagnostic(
warningRange,
warning.getMessage(),
DiagnosticSeverity.Warning,
"JavaTX Language Server"
);
diagnostics.add(diagnostic);
}
return new DiagnosticsAndTypehints(diagnostics, diagnosticsAndTypehints.getInlayHints());
}
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(InferenceResult inferenceResult, String uri) {
var diagnosticsAndTypehints = variablesToDiagnosticsAndTypehints(inferenceResult.variables(), uri);
return addWarningsToDiagnostics(diagnosticsAndTypehints, inferenceResult.warnings());
}
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(ArrayList<LSPVariable> variables, String uri) {
List<InlayHint> typeHint = new ArrayList<>();
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
for (var variable : typesOfMethodAndParameters) {
for (var variable : variables) {
InlayHint inlayHint = getInlayHint(variable);
typeHint.add(inlayHint);
@@ -108,11 +135,11 @@ public class ConversionHelper {
return new DiagnosticsAndTypehints(diagnostics, typeHint);
}
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(ArrayList<LSPVariable> typesOfMethodAndParameters, String input) {
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(InferenceResult inferenceResult, String input) {
List<InlayHint> typeHint = new ArrayList<>();
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
for (var variable : typesOfMethodAndParameters) {
for (var variable : inferenceResult.variables()) {
InlayHint inlayHint = getInlayHint(variable);
typeHint.add(inlayHint);
@@ -123,6 +150,6 @@ public class ConversionHelper {
}
}
return new DiagnosticsAndTypehints(diagnostics, typeHint);
return addWarningsToDiagnostics(new DiagnosticsAndTypehints(diagnostics, typeHint), inferenceResult.warnings());
}
}
@@ -0,0 +1,3 @@
package de.dhbw.helper;
public record InsertPoint(int line, int character) {}
@@ -3,29 +3,32 @@ package de.dhbw.helper;
import de.dhbw.model.PlaceholderVariable;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.target.generate.GenericsResult;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import java.util.HashSet;
import java.util.Set;
public class PlaceholderPlacer extends AbstractASTWalker {
Set<PlaceholderVariable> inserts = new HashSet<>();
private ResultSet withResults;
Set<PlaceholderVariable> inserts = new HashSet<>();
String pkgName;
private GenericsResult genericsResult;
private SourceFile forSourceFile;
public Set<PlaceholderVariable> getTypeInserts(SourceFile forSourceFile, ResultSet withResults, GenericsResult genericsResult){
this.withResults = withResults;
public PlaceholderPlacer(SourceFile forSourceFile, GenericsResult genericsResult) {
this.forSourceFile = forSourceFile;
this.genericsResult = genericsResult;
pkgName = forSourceFile.getPkgName();
forSourceFile.accept(this);
inserts.forEach(el -> el.reducePackage());
return inserts;
this.pkgName = forSourceFile.getPkgName();
}
public Set<PlaceholderVariable> getTypeInserts() {
this.inserts = new HashSet<>();
this.forSourceFile.accept(this);
this.inserts.forEach(el -> el.reducePackage());
return this.inserts;
}
@Override
public void visit(ClassOrInterface classOrInterface) {
de.dhbw.helper.PlaceholderPlacerClass cl = new de.dhbw.helper.PlaceholderPlacerClass(classOrInterface, withResults, genericsResult);
de.dhbw.helper.PlaceholderPlacerClass cl = new de.dhbw.helper.PlaceholderPlacerClass(classOrInterface, genericsResult);
this.inserts.addAll(cl.inserts);
}
}
@@ -21,10 +21,10 @@ class PlaceholderPlacerClass extends AbstractASTWalker{
GenericsResultSet constraints;
GenericsResultSet classConstraints;
PlaceholderPlacerClass(ClassOrInterface forClass, ResultSet withResults, GenericsResult generatedGenerics){
PlaceholderPlacerClass(ClassOrInterface forClass, GenericsResult generatedGenerics) {
this.cl = forClass;
this.method = null;
this.results = withResults;
this.results = generatedGenerics.getGenerics().getResultSet();
this.generatedGenerics = generatedGenerics;
forClass.accept(this);
}
@@ -32,7 +32,7 @@ class PlaceholderPlacerClass extends AbstractASTWalker{
@Override
public void visit(Method method) {
this.method = method;
constraints = generatedGenerics.get(method);
constraints = generatedGenerics.get(cl, method);
classConstraints = generatedGenerics.get(cl);
if(method.getReturnType() instanceof TypePlaceholder)
inserts.add(ASTTransformationHelper.createInsertPoints(
@@ -1,6 +1,7 @@
package de.dhbw.helper;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.target.generate.GenerateGenerics;
import de.dhbwstuttgart.target.generate.GenericsResultSet;
import de.dhbwstuttgart.typeinference.result.*;
@@ -60,14 +61,14 @@ public class PlaceholderToInsertString implements ResultSetVisitor{
@Override
public void visit(TypePlaceholder typePlaceholder) {
ResultPair<?, ?> resultPair = null;
GenerateGenerics.Pair resultPair = null;
if (constraints != null)
resultPair = constraints.getResultPairFor(typePlaceholder).orElse(null);
if (resultPair == null)
resultPair = classConstraints.getResultPairFor(typePlaceholder).orElse(null);
if (resultPair != null)
insert += ((TypePlaceholder)resultPair.getLeft()).getName();
insert += resultPair.left.toString();
}
@Override
@@ -3,30 +3,21 @@ package de.dhbw.helper;
import de.dhbw.model.*;
import de.dhbw.model.PlaceholderVariable;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.exceptions.CompilerWarning;
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.target.generate.GenericsResult;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/**
* Helper-Class for finding the Type of a selected Word
*/
@@ -37,10 +28,10 @@ public class TypeResolver {
private final DuplicationUtils duplicationUtils;
private final boolean ENABLE_GENERICS = true;
private List<GenericsResult> generatedGenerics = null;
private HashMap<String, List<PlaceholderVariable>> inserts;
private HashMap<InsertPoint, List<PlaceholderVariable>> inserts;
public HashMap<String, List<PlaceholderVariable>> getInserts() {
public HashMap<InsertPoint, List<PlaceholderVariable>> getInserts() {
return inserts;
}
@@ -50,9 +41,7 @@ public class TypeResolver {
private LanguageServerTransferObject current;
public void reset() {
HashMap<String, List<TypeInsert>> inserts = null;
List<GenericsResult> generatedGenerics = null;
current = null;
this.current = null;
}
@@ -82,7 +71,7 @@ public class TypeResolver {
public void getCompilerInput(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
LanguageServerInterface languageServer = new LanguageServerInterface();
var transferObj = languageServer.getResultSetAndAbastractSyntax(path, RESET_TO_LETTER);
var transferObj = languageServer.getResultSetAndAbstractSyntax(path, RESET_TO_LETTER);
current = transferObj;
}
@@ -99,25 +88,37 @@ public class TypeResolver {
Set<PlaceholderVariable> tips = new HashSet<>();
for (int i = 0; i < current.getResultSets().size(); i++) {
ResultSet tiResult = current.getResultSets().get(i);
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(current.getAst(), tiResult, generatedGenerics.get(i)));
for (var results : generatedGenerics) {
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(current.getAst(), results));
}
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
HashMap<InsertPoint, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
for (PlaceholderVariable insert : tips) {
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
var insertPoint = new InsertPoint(insert.point.point.getLine(), insert.point.point.getCharPositionInLine());
if (!insertsOnLines.containsKey(insertPoint)) {
insertsOnLines.put(insertPoint, new ArrayList<>(List.of(insert)));
} else {
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
insertsOnLines.get(insertPoint).add(insert);
}
}
inserts = insertsOnLines;
ArrayList<LSPVariable> variables = new ArrayList<>(insertsOnLines.entrySet().stream().map(el -> new LSPVariable("test", new ArrayList<>(el.getValue().stream().map(typeinsert -> new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint())).toList()), el.getValue().getFirst().point.point.getLine(), el.getValue().getFirst().point.point.getCharPositionInLine(), el.getValue().get(0).point.point.getStopIndex(), el.getValue().get(0).getResultPair().getLeft())).toList());
ArrayList<LSPVariable> variables = new ArrayList<>(
insertsOnLines.entrySet().stream().map(el -> {
var v = el.getValue().getFirst();
return new LSPVariable("test",
new ArrayList<>(el.getValue().stream()
.map(typeinsert -> new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint()))
.toList()),
v.point.point.getLine(),
v.point.point.getCharPositionInLine(),
v.point.point.getStopIndex(),
v.getResultPair().getLeft());
}
).toList()
);
for (var variable : variables) {
@@ -140,31 +141,32 @@ public class TypeResolver {
return variables;
}
public ArrayList<LSPVariable> infereInput(String pathString, String input) throws IOException, ClassNotFoundException, URISyntaxException {
public record InferenceResult(ArrayList<LSPVariable> variables, List<CompilerWarning> warnings) {}
public InferenceResult infereInput(String pathString, String input) throws IOException, ClassNotFoundException, URISyntaxException {
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
LanguageServerTransferObject lsTransfer = languageServerInterface.getResultSetAndAbstractSyntax(pathString);
var parsedSource = lsTransfer.getAst();
var tiResults = lsTransfer.getResultSets();
Set<PlaceholderVariable> tips = new HashSet<>();
generatedGenerics = lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst());
for (int i = 0; i < tiResults.size(); i++) {
ResultSet tiResult = tiResults.get(i);
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, tiResult, lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst()).get(i)));
for (var generics : generatedGenerics) {
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, generics));
}
System.setOut(System.out);
this.current = lsTransfer;
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
HashMap<InsertPoint, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
for (PlaceholderVariable insert : tips) {
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
var insertPoint = new InsertPoint(insert.point.point.getLine(), insert.point.point.getCharPositionInLine());
if (!insertsOnLines.containsKey(insertPoint)) {
insertsOnLines.put(insertPoint, new ArrayList<>(List.of(insert)));
} else {
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
insertsOnLines.get(insertPoint).add(insert);
}
}
@@ -181,8 +183,13 @@ public class TypeResolver {
for(PlaceholderVariable typeinsert : entrySet.getValue()){
typesOfVariable.add(new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint()));
}
variables.add(new LSPVariable("test",typesOfVariable , entrySet.getValue().getFirst().point.point.getLine(), entrySet.getValue().getFirst().point.point.getCharPositionInLine(), entrySet.getValue().get(0).point.point.getStopIndex(), entrySet.getValue().get(0).getResultPair().getLeft()));
var variable = entrySet.getValue().getFirst();
variables.add(new LSPVariable("test", typesOfVariable,
variable.point.point.getLine(),
variable.point.point.getCharPositionInLine(),
variable.point.point.getStopIndex(),
variable.getResultPair().getLeft()));
}
@@ -203,26 +210,7 @@ public class TypeResolver {
}
return variables;
}
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables) {
for (var lines : combinedList.entrySet()) {
var contentChange = lines.getValue();
for (LSPVariable variable : variables) {
for (Type typeOfVariable : variable.getPossibleTypes()) {
if (typeOfVariable.getType().equalsIgnoreCase(contentChange.replaceAll(" ", ""))) {
if (variable.getLine() - 1 == lines.getKey().line && variable.getCharPosition() == lines.getKey().charPosition) {
current.getResultSets().removeIf(el -> !el.resolveType(variable.getOriginalTphName()).resolvedType.toString().equalsIgnoreCase(contentChange.replaceAll(" ", "")));
return;
}
}
}
}
}
return new InferenceResult(variables, lsTransfer.getWarnings());
}
public SourceFile getNewAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
@@ -233,7 +221,7 @@ public class TypeResolver {
public void updateAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
logger.info("Old AST:");
logger.info(ASTPrinter.print(this.current.getAst()));
this.current = new LanguageServerTransferObject(current.getResultSets(), getNewAst(uri), "", current.getGeneratedGenerics());
this.current = new LanguageServerTransferObject(getNewAst(uri), "", current.getGeneratedGenerics(), current.getWarnings());
logger.info("NEW AST:");
logger.info(ASTPrinter.print(current.getAst()));
@@ -1,5 +1,7 @@
package de.dhbw.model;
import de.dhbw.helper.ConversionHelper;
import de.dhbwstuttgart.target.generate.GenericsResultSet;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import java.util.*;
@@ -11,10 +13,11 @@ public class PlaceholderVariable {
public final PlaceholderPoint point;
Set<PlaceholderPoint> inserts;
ResultPair<?, ?> resultPair;
private final GenericsResultSet constraints;
public PlaceholderVariable(PlaceholderPoint point, Set<PlaceholderPoint> additionalPoints, ResultPair<?, ?> resultPair) {
public PlaceholderVariable(PlaceholderPoint point, Set<PlaceholderPoint> additionalPoints, ResultPair<?, ?> resultPair, GenericsResultSet constraints) {
this.point = point;
this.constraints = constraints;
inserts = additionalPoints;
this.resultPair = resultPair;
}
@@ -43,7 +46,7 @@ public class PlaceholderVariable {
}
public void reducePackage() {
point.setInsertString(point.getInsertString().replaceAll("java\\.lang\\.", "").replaceAll("java\\.util\\.", ""));
point.setInsertString(ConversionHelper.cleanType(point.getInsertString()));
}
public ResultPair<?, ?> getResultPair() {
@@ -73,4 +76,8 @@ public class PlaceholderVariable {
public String toString() {
return point.toString();
}
public GenericsResultSet getConstraints() {
return constraints;
}
}
@@ -3,8 +3,12 @@ package de.dhbw.service;
import org.eclipse.lsp4j.*;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageServer;
import de.dhbw.JavaTXLanguageServer;
import java.util.List;
import java.util.Map;
public class ClientService {
@@ -39,21 +43,18 @@ public class ClientService {
this.client = client;
}
public void updateClient(LanguageClient client) {
client.refreshInlayHints();
client.refreshDiagnostics();
}
public void updateClient() {
client.refreshInlayHints();
client.refreshDiagnostics();
if (JavaTXLanguageServer.capabilities.getWorkspace().getInlayHint() != null)
client.refreshInlayHints();
if (JavaTXLanguageServer.capabilities.getWorkspace().getDiagnostics() != null)
client.refreshDiagnostics();
}
public LanguageClient getClient() {
return client;
}
public void startLoading(String taskName, String title, LanguageClient client) {
public void startLoading(String taskName, String title) {
Either<String, Integer> token = Either.forLeft(taskName);
client.createProgress(new WorkDoneProgressCreateParams(token));
@@ -67,7 +68,7 @@ public class ClientService {
}
public void stopLoading(String taskName, String title, LanguageClient client) {
public void stopLoading(String taskName, String title) {
Either<String, Integer> token = Either.forLeft(taskName);
WorkDoneProgressEnd end = new WorkDoneProgressEnd();
end.setMessage(title);