Compare commits
31 Commits
7de2b2764a
...
0.0.7
Author | SHA1 | Date | |
---|---|---|---|
|
ed26f869c3 | ||
|
ee0b51868c | ||
|
98b32fd418 | ||
|
558fcb5ebb | ||
|
1e4541b705 | ||
|
205b243d32 | ||
|
dda95006ef | ||
|
1efec1d854 | ||
|
74d4f7018b | ||
|
f54004b21a | ||
|
1b84b77677 | ||
|
6b40ce7e64 | ||
|
3fe253ae63 | ||
|
9d42e829e2 | ||
|
a88e34431f | ||
|
a53b79f91d | ||
|
e119d42148 | ||
|
1e125407f1 | ||
|
579d736efc | ||
|
c5760210fe | ||
|
2e6be4079a | ||
|
bb9be2c319 | ||
|
57c82542f4 | ||
|
cb54606a93 | ||
|
31ed1f16b6 | ||
|
5569b6d0db | ||
|
2a87b85dc1 | ||
|
11fb843efe | ||
|
701caab9cd | ||
|
c2cbd0aa92 | ||
|
e1b000b976 |
13
Clients/Intellij/installation.md
Normal file
13
Clients/Intellij/installation.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Installation des Intellij Language Clients
|
||||
|
||||
Um den Language Client für Intellij installieren zu können, kann die Erweiterung
|
||||
[LSP4IJ](https://plugins.jetbrains.com/plugin/23257-lsp4ij) installiert werden.
|
||||
|
||||
## Installation
|
||||
1. Installiere [LSP4IJ](https://plugins.jetbrains.com/plugin/23257-lsp4ij)
|
||||
2. Öffne den Language Server Tab
|
||||
3. Füge einen neuen Language-Server hinzu
|
||||
4. Vergebe einen Namen und füge folgenden Command hinzu: `java -jar "<path/to/LanguageServer.jar>`
|
||||
5. Füge unter Mappings -> File name patterns *.jav und Language ID java_tx hinzu
|
||||
6. öffne eine Datei mit Dateiendung .jav
|
||||
7. Fertig
|
Binary file not shown.
BIN
Clients/VisualStudioCode/TX.png
Normal file
BIN
Clients/VisualStudioCode/TX.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 902 KiB |
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "lspclient",
|
||||
"displayName": "LSPClient",
|
||||
"description": "",
|
||||
"version": "0.0.1",
|
||||
"icon": "TX.png",
|
||||
"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.7",
|
||||
"engines": {
|
||||
"vscode": "^1.94.0"
|
||||
},
|
||||
@@ -16,8 +17,8 @@
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "lspclient.helloWorld",
|
||||
"title": "Hello World"
|
||||
"command": "tx.restartLanguageServer",
|
||||
"title": "TX: Restart Language Server"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@@ -1,39 +1,30 @@
|
||||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { workspace, ExtensionContext } from 'vscode';
|
||||
import {
|
||||
LanguageClient,
|
||||
LanguageClientOptions,
|
||||
ServerOptions,
|
||||
TransportKind
|
||||
ServerOptions
|
||||
} from 'vscode-languageclient/node';
|
||||
|
||||
let client: LanguageClient | undefined; // <— global, damit wir neu starten können
|
||||
|
||||
|
||||
|
||||
// This method is called when your extension is activated
|
||||
// Your extension is activated the very first time the command is executed
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
|
||||
|
||||
function createClient(context: vscode.ExtensionContext): LanguageClient {
|
||||
const workspaceFolder = context.extensionPath;
|
||||
|
||||
const serverOptions: ServerOptions = {
|
||||
run: {
|
||||
command: 'java',
|
||||
args: ['-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], // Absolute Pfadangabe
|
||||
args: ['-Xss2m', '-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"],
|
||||
},
|
||||
debug: {
|
||||
command: 'java',
|
||||
args: ['-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], // Absolute Pfadangabe für Debug
|
||||
args: [
|
||||
'-Xss2m',
|
||||
'-jar',
|
||||
workspaceFolder + '/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar',
|
||||
],
|
||||
}
|
||||
};
|
||||
|
||||
console.log("SERVER CREATED.")
|
||||
console.log(workspaceFolder)
|
||||
// Clientoptionen: definiere, welche Dateitypen der Client unterstützt
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{ scheme: 'file', language: 'java' }],
|
||||
synchronize: {
|
||||
@@ -42,37 +33,53 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
revealOutputChannelOn: 4
|
||||
};
|
||||
|
||||
|
||||
// Language Client erstellen und starten
|
||||
const client = new LanguageClient(
|
||||
'javaTxLanguageServer', // ID des Clients
|
||||
'Java-TX Language Server', // Name des Clients
|
||||
return new LanguageClient(
|
||||
'javaTxLanguageServer',
|
||||
'Java-TX Language Server',
|
||||
serverOptions,
|
||||
clientOptions
|
||||
);
|
||||
|
||||
// Client starten
|
||||
client.start().then(() => {
|
||||
console.log("Language Client erfolgreich gestartet");
|
||||
}).catch(error => {
|
||||
console.error("Fehler beim Starten des Language Clients:", error);
|
||||
});
|
||||
|
||||
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||||
// This line of code will only be executed once when your extension is activated
|
||||
console.log('Congratulations, your extension "tx" is now active!');
|
||||
|
||||
// The command has been defined in the package.json file
|
||||
// Now provide the implementation of the command with registerCommand
|
||||
// The commandId parameter must match the command field in package.json
|
||||
const disposable = vscode.commands.registerCommand('lspclient.helloWorld', () => {
|
||||
// The code you place here will be executed every time your command is executed
|
||||
// Display a message box to the user
|
||||
vscode.window.showInformationMessage('Hello World from TX!');
|
||||
});
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
|
||||
// This method is called when your extension is deactivated
|
||||
export function deactivate() { }
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
client = createClient(context);
|
||||
|
||||
client.start()
|
||||
.then(() => console.log("Language Client erfolgreich gestartet"))
|
||||
.catch(err => console.error("Fehler beim Starten des Language Clients:", err));
|
||||
|
||||
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) {
|
||||
vscode.window.showWarningMessage('Language Client ist nicht initialisiert.');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await client.stop(); // stoppt den Serverprozess
|
||||
client.dispose(); // räumt Ressourcen auf
|
||||
} catch (e) {
|
||||
console.error('Fehler beim Stoppen des Language Clients:', e);
|
||||
}
|
||||
client = createClient(context); // komplett neu erzeugen
|
||||
try {
|
||||
await client.start();
|
||||
vscode.window.showInformationMessage('Java-TX Language Server neu gestartet.');
|
||||
} catch (e) {
|
||||
console.error('Fehler beim Neustarten des Language Clients:', e);
|
||||
vscode.window.showErrorMessage('Neustart des Language Servers fehlgeschlagen – Details in der Konsole.');
|
||||
}
|
||||
});
|
||||
context.subscriptions.push(restart);
|
||||
}
|
||||
|
||||
export function deactivate(): Thenable<void> | undefined {
|
||||
return client?.stop();
|
||||
}
|
BIN
LanguageServer/lib/JavaTXcompiler-0.1-jar-with-dependencies.jar
Normal file
BIN
LanguageServer/lib/JavaTXcompiler-0.1-jar-with-dependencies.jar
Normal file
Binary file not shown.
@@ -8,7 +8,6 @@ import org.eclipse.lsp4j.services.TextDocumentService;
|
||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||
import org.eclipse.lsp4j.services.LanguageServer;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
/**
|
||||
|
@@ -1,20 +1,15 @@
|
||||
package de.dhbw;
|
||||
|
||||
import de.dhbw.handler.ChangeHandler;
|
||||
import de.dhbw.handler.CodeActionHandler;
|
||||
import de.dhbw.handler.FormattingHandler;
|
||||
import de.dhbw.handler.*;
|
||||
import de.dhbw.service.CacheService;
|
||||
import de.dhbw.service.ClientService;
|
||||
import de.dhbw.service.LogService;
|
||||
import de.dhbw.handler.SaveHandler;
|
||||
import de.dhbw.helper.CodeSnippetOptions;
|
||||
import de.dhbw.helper.ConversionHelper;
|
||||
import de.dhbw.helper.TextHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbw.model.SnippetWithName;
|
||||
import de.dhbw.service.ParserService;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.lsp4j.*;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.lsp4j.services.LanguageClient;
|
||||
@@ -52,7 +47,6 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
|
||||
public JavaTXTextDocumentService() {
|
||||
this.textHelper = new TextHelper();
|
||||
this.parserService = new ParserService();
|
||||
this.cacheService = new CacheService();
|
||||
this.clientService = new ClientService(null);
|
||||
this.typeResolver = new TypeResolver();
|
||||
@@ -60,8 +54,9 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
this.conversionHelper = new ConversionHelper(textHelper, textDocumentService);
|
||||
this.logService = new LogService(clientService);
|
||||
this.formattingHandler = new FormattingHandler(textDocumentService);
|
||||
this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService);
|
||||
this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService);
|
||||
this.parserService = new ParserService(conversionHelper, clientService, cacheService);
|
||||
this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService, conversionHelper);
|
||||
this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService, parserService);
|
||||
this.changeHandler = new ChangeHandler(textDocumentService, parserService, conversionHelper, clientService, typeResolver, cacheService, logService);
|
||||
}
|
||||
|
||||
@@ -112,6 +107,14 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
*/
|
||||
@Override
|
||||
public void didOpen(DidOpenTextDocumentParams params) {
|
||||
cacheService.reset();
|
||||
typeResolver.reset();
|
||||
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(params.getTextDocument().getText(), params.getTextDocument().getUri());
|
||||
if (!syntaxErrors.isEmpty()) {
|
||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
|
||||
}
|
||||
client.refreshDiagnostics();
|
||||
client.refreshInlayHints();
|
||||
textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText());
|
||||
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), params.getTextDocument().getText());
|
||||
}
|
||||
@@ -126,6 +129,10 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
@Override
|
||||
public void didChange(DidChangeTextDocumentParams params) {
|
||||
logService.log("[didChange] Client triggered didChange Event.", MessageType.Info);
|
||||
cacheService.reset();
|
||||
String fileInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
||||
textDocuments.put(params.getTextDocument().getUri(), fileInput);
|
||||
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), fileInput);
|
||||
changeHandler.didChange(params);
|
||||
}
|
||||
|
||||
@@ -294,7 +301,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
logService.log("Code-Action Context was: " + params.getContext().getTriggerKind().name(), MessageType.Info);
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return codeActionHandler.handleCodeAction(params);
|
||||
return codeActionHandler.handleNewCodeAction(params);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -3,13 +3,8 @@ package de.dhbw;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.lsp4j.*;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
*
|
||||
* Handles Actions in Workspace
|
||||
|
@@ -3,15 +3,20 @@ package de.dhbw.handler;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import de.dhbw.helper.ConversionHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
||||
import de.dhbw.model.DocumentChanges;
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbw.model.LineCharPosition;
|
||||
import de.dhbw.model.*;
|
||||
import de.dhbw.service.*;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import org.eclipse.lsp4j.*;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChangeHandler {
|
||||
|
||||
@@ -33,50 +38,152 @@ public class ChangeHandler {
|
||||
this.logService = logService;
|
||||
}
|
||||
|
||||
|
||||
public static String findAddedWord(String str1, String str2) {
|
||||
int i = 0, j = 0;
|
||||
|
||||
// Suche den ersten Unterschied
|
||||
while (i < str1.length() && j < str2.length() && str1.charAt(i) == str2.charAt(j)) {
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
|
||||
// Falls alles gleich ist, gibt es nichts Neues
|
||||
if (i == str1.length() && j == str2.length()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Suche ab Ende rückwärts, um den gemeinsamen Suffix zu finden
|
||||
int iEnd = str1.length() - 1;
|
||||
int jEnd = str2.length() - 1;
|
||||
while (iEnd >= i && jEnd >= j && str1.charAt(iEnd) == str2.charAt(jEnd)) {
|
||||
iEnd--;
|
||||
jEnd--;
|
||||
}
|
||||
|
||||
// Der Unterschied liegt nun zwischen j und jEnd in str2
|
||||
return str2.substring(j, jEnd + 1);
|
||||
}
|
||||
|
||||
|
||||
public void didChange(DidChangeTextDocumentParams params) {
|
||||
String currentText = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
||||
|
||||
DocumentChanges documentChanges = textDocumentService.calculateDifference(currentText, params.getContentChanges().getFirst().getText());
|
||||
HashMap<LineCharPosition, String> preciseChanges = documentChanges.getPreciseChanges();
|
||||
ArrayList<Integer> offsetPerLine = documentChanges.getOffsetPerLine();
|
||||
HashMap<Integer, List<String>> textChanges = documentChanges.getTextChanges();
|
||||
|
||||
AtomicReference<String> summedUp = new AtomicReference<>("");
|
||||
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
|
||||
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), summedUp.get());
|
||||
|
||||
|
||||
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(summedUp.get(), params.getTextDocument().getUri());
|
||||
|
||||
if (!syntaxErrors.isEmpty()) {
|
||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
|
||||
}
|
||||
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
||||
|
||||
if (syntaxErrors.isEmpty()) {
|
||||
|
||||
String type = findAddedWord(currentText, summedUp.get());
|
||||
String input = summedUp.get();
|
||||
|
||||
checkParser(input, params.getTextDocument().getUri());
|
||||
logService.log("Variables are: " + cacheService.getVariables().size());
|
||||
|
||||
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables(), clientService.getClient());
|
||||
boolean shouldCalculate = false;
|
||||
|
||||
logService.log("Type is here: " + type);
|
||||
for (LSPVariable variable : cacheService.getVariables()) {
|
||||
for (Type variableType : variable.getPossibleTypes()) {
|
||||
logService.log(variableType.getType() + " <> "+ type.replaceAll(" ", "") + ": " + type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", "")));
|
||||
shouldCalculate = shouldCalculate || type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", ""));
|
||||
if (shouldCalculate) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
var sWatch = Stopwatch.createUnstarted();
|
||||
sWatch.start();
|
||||
|
||||
try {
|
||||
|
||||
String currentInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
||||
|
||||
if (currentInput == null) {
|
||||
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||
}
|
||||
|
||||
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(currentInput, params.getTextDocument().getUri());
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
logService.log("Calculating again.");
|
||||
var sWatch = Stopwatch.createUnstarted();
|
||||
sWatch.start();
|
||||
|
||||
try {
|
||||
try {
|
||||
File tempDir2 = new File(System.getProperty("java.io.tmpdir"));
|
||||
File tempFile2 = File.createTempFile("newText", ".tmp", tempDir2);
|
||||
FileWriter fileWriter = new FileWriter(tempFile2, true);
|
||||
BufferedWriter bw = new BufferedWriter(fileWriter);
|
||||
bw.write(input);
|
||||
bw.close();
|
||||
|
||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input, false);
|
||||
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);
|
||||
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(input, params.getTextDocument().getUri()));
|
||||
|
||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
||||
|
||||
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());
|
||||
|
||||
for (StackTraceElement elem : e.getStackTrace()) {
|
||||
logService.log(elem.toString());
|
||||
}
|
||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||
|
||||
} finally {
|
||||
@@ -84,40 +191,13 @@ public class ChangeHandler {
|
||||
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||
}
|
||||
|
||||
|
||||
updatePositions(params, offsetPerLine);
|
||||
|
||||
|
||||
cacheService.getGlobalInlayHintMap().put(params.getTextDocument().getUri(), cacheService.getGlobalInlayHintMap().get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||
//TODO: Hier das Label aufspalten an | weil die Typehints immer mit und getrennt sind und so jeder Typhint für sich durchlaufen werden kann.
|
||||
logService.log(el.getLabel().getLeft().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getPosition().getLine())) + ": " + (!textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", "")) ? "true" : "false"), MessageType.Info);
|
||||
return !textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", ""));
|
||||
}).toList());
|
||||
|
||||
cacheService.getGlobalDiagnosticsMap().put(params.getTextDocument().getUri(), cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||
logService.log(el.getMessage().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getRange().getStart().getLine())) + ": " + (!textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", "")) ? "true" : "false"), MessageType.Info);
|
||||
return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""));
|
||||
}).toList());
|
||||
|
||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri()));
|
||||
|
||||
} catch (Exception e) {
|
||||
logService.log(e.getMessage());
|
||||
}
|
||||
|
||||
private void checkParser(String input, String uri) {
|
||||
List<Diagnostic> diagnosticsList = conversionHelper.parseErrorToDiagnostic(parserService.getParserErrors(input));
|
||||
clientService.publishDiagnostics(uri, diagnosticsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePositions(DidChangeTextDocumentParams params, ArrayList<Integer> offsetPerLine){
|
||||
for (var inlayHint : cacheService.getGlobalInlayHintMap().get(params.getTextDocument().getUri())) {
|
||||
inlayHint.getPosition().setCharacter(inlayHint.getPosition().getCharacter() + offsetPerLine.get(inlayHint.getPosition().getLine()));
|
||||
}
|
||||
|
||||
for (var diagnostic : cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri())) {
|
||||
diagnostic.getRange().getStart().setCharacter(diagnostic.getRange().getStart().getCharacter() + offsetPerLine.get(diagnostic.getRange().getStart().getLine()));
|
||||
diagnostic.getRange().getEnd().setCharacter(diagnostic.getRange().getEnd().getCharacter() + offsetPerLine.get(diagnostic.getRange().getEnd().getLine()));
|
||||
}
|
||||
|
||||
clientService.updateClient();
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
package de.dhbw.handler;
|
||||
|
||||
import de.dhbw.helper.ConversionHelper;
|
||||
import de.dhbw.helper.TextHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbw.service.CacheService;
|
||||
import de.dhbw.service.LogService;
|
||||
import de.dhbw.service.TextDocumentService;
|
||||
import de.dhbw.model.PlaceholderVariable;
|
||||
import org.eclipse.lsp4j.*;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
|
||||
@@ -12,6 +14,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CodeActionHandler {
|
||||
|
||||
@@ -20,13 +23,125 @@ public class CodeActionHandler {
|
||||
private final CacheService cacheService;
|
||||
private final TypeResolver typeResolver;
|
||||
private final LogService logService;
|
||||
private final ConversionHelper conversionHelper;
|
||||
|
||||
public CodeActionHandler(TextHelper textHelper, TextDocumentService textDocumentService, CacheService cacheService, TypeResolver typeResolver, LogService logService) {
|
||||
public CodeActionHandler(TextHelper textHelper, TextDocumentService textDocumentService, CacheService cacheService, TypeResolver typeResolver, LogService logService, ConversionHelper conversionHelper) {
|
||||
this.textHelper = textHelper;
|
||||
this.textDocumentService = textDocumentService;
|
||||
this.cacheService = cacheService;
|
||||
this.typeResolver = typeResolver;
|
||||
this.logService = logService;
|
||||
this.conversionHelper = conversionHelper;
|
||||
}
|
||||
|
||||
public static Range wholeDocumentRange(String text) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
return new Range(new Position(0, 0), new Position(0, 0));
|
||||
}
|
||||
|
||||
int lastLine = 0;
|
||||
int lastBreak = -1; // Index des letzten Zeilenumbruchszeichens, das zum Zeilenende gehört
|
||||
|
||||
final int n = text.length();
|
||||
for (int i = 0; i < n; i++) {
|
||||
char c = text.charAt(i);
|
||||
if (c == '\n') {
|
||||
lastLine++;
|
||||
lastBreak = i;
|
||||
} else if (c == '\r') {
|
||||
// Unterscheide \r\n von alleine stehendem \r
|
||||
if (i + 1 < n && text.charAt(i + 1) == '\n') {
|
||||
lastLine++;
|
||||
lastBreak = i + 1;
|
||||
i++; // \n überspringen
|
||||
} else {
|
||||
lastLine++;
|
||||
lastBreak = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int lastLineStart = lastBreak + 1;
|
||||
int endChar = n - lastLineStart; // Länge der letzten Zeile in UTF-16 Code Units
|
||||
|
||||
return new Range(new Position(0, 0), new Position(lastLine, endChar));
|
||||
}
|
||||
|
||||
|
||||
public static <V> Map<String, V> getOverlapping(
|
||||
Map<String, V> map,
|
||||
int line,
|
||||
int startChar,
|
||||
int endChar
|
||||
) {
|
||||
if (startChar > endChar) {
|
||||
int t = startChar;
|
||||
startChar = endChar;
|
||||
endChar = t;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
public List<Either<Command, CodeAction>> handleNewCodeAction(CodeActionParams params) {
|
||||
|
||||
String documentUri = params.getTextDocument().getUri();
|
||||
Range rangeOfInsert = params.getRange();
|
||||
|
||||
//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());
|
||||
logService.log("Inserts are:");
|
||||
typeResolver.getInserts().forEach((key, value) -> logService.log(key));
|
||||
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<>();
|
||||
|
||||
for (var typeInsertList : typeInsertsOverlapping.values()) {
|
||||
for (var typeInsert : typeInsertList) {
|
||||
try {
|
||||
logService.log("NEW TEXT OF FILE BEFORE INSERT IS:");
|
||||
logService.log(textDocumentService.getFileOfUri(documentUri));
|
||||
String typeWithReplacedVariable = typeInsert.insert(textDocumentService.getFileOfUri(documentUri));
|
||||
|
||||
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
||||
|
||||
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()));
|
||||
action.setKind(CodeActionKind.QuickFix);
|
||||
action.setEdit(edit);
|
||||
actions.add(Either.forRight(action));
|
||||
} catch (Exception e) {
|
||||
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
public List<Either<Command, CodeAction>> handleCodeAction(CodeActionParams params) {
|
||||
@@ -60,7 +175,7 @@ public class CodeActionHandler {
|
||||
if (typeDiagnostic.getCode().getLeft().equals("GENERIC")) {
|
||||
for (var diagnostic : cacheService.getGlobalDiagnosticsMap().get(documentUri)) {
|
||||
|
||||
if (diagnostic.getMessage().contains(typeDiagnostic.getMessage()) || typeDiagnostic.getMessage().contains(diagnostic.getMessage())) {
|
||||
if (diagnostic.getCode().getLeft().equals("GENERIC")) {
|
||||
String genericType = diagnostic.getMessage() +
|
||||
" " +
|
||||
textHelper.getTextOfChars(
|
||||
|
@@ -1,55 +0,0 @@
|
||||
package de.dhbw.handler;
|
||||
|
||||
import com.github.difflib.DiffUtils;
|
||||
import com.github.difflib.patch.AbstractDelta;
|
||||
import com.github.difflib.patch.DeltaType;
|
||||
import com.github.difflib.patch.Patch;
|
||||
|
||||
import org.eclipse.lsp4j.InlayHint;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class InlayHintAdjusterDiffUtils {
|
||||
|
||||
public static List<InlayHint> adjustInlayHintsByLineDiff(String oldText, String newText, List<InlayHint> oldHints) {
|
||||
List<String> oldLines = Arrays.asList(oldText.split("\n", -1));
|
||||
List<String> newLines = Arrays.asList(newText.split("\n", -1));
|
||||
|
||||
Patch<String> patch = DiffUtils.diff(oldLines, newLines);
|
||||
List<AbstractDelta<String>> deltas = patch.getDeltas();
|
||||
|
||||
List<InlayHint> adjusted = new ArrayList<>();
|
||||
for (InlayHint hint : oldHints) {
|
||||
int oldLine = hint.getPosition().getLine();
|
||||
int lineShift = calculateLineShift(deltas, oldLine);
|
||||
int newLine = Math.max(0, oldLine + lineShift);
|
||||
|
||||
adjusted.add(new InlayHint(new Position(newLine, hint.getPosition().getCharacter()), hint.getLabel()));
|
||||
}
|
||||
|
||||
return adjusted;
|
||||
}
|
||||
|
||||
private static int calculateLineShift(List<AbstractDelta<String>> deltas, int oldLine) {
|
||||
int shift = 0;
|
||||
for (AbstractDelta<String> delta : deltas) {
|
||||
int deltaLine = delta.getSource().getPosition();
|
||||
int linesRemoved = delta.getSource().size();
|
||||
int linesAdded = delta.getTarget().size();
|
||||
|
||||
if (oldLine > deltaLine) {
|
||||
if (delta.getType() == DeltaType.INSERT) {
|
||||
shift += linesAdded;
|
||||
} else if (delta.getType() == DeltaType.DELETE) {
|
||||
shift -= linesRemoved;
|
||||
} else if (delta.getType() == DeltaType.CHANGE) {
|
||||
shift += linesAdded - linesRemoved;
|
||||
}
|
||||
}
|
||||
}
|
||||
return shift;
|
||||
}
|
||||
}
|
@@ -2,15 +2,17 @@ package de.dhbw.handler;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
||||
import de.dhbw.service.CacheService;
|
||||
import de.dhbw.service.ClientService;
|
||||
import de.dhbw.service.LogService;
|
||||
import de.dhbw.service.TextDocumentService;
|
||||
import de.dhbw.service.*;
|
||||
import de.dhbw.helper.ConversionHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||
import org.eclipse.lsp4j.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,31 +24,46 @@ public class SaveHandler {
|
||||
private final CacheService cacheService;
|
||||
private final ConversionHelper conversionHelper;
|
||||
private final ClientService clientService;
|
||||
private final ParserService parserService;
|
||||
|
||||
public SaveHandler(TypeResolver typeResolver, TextDocumentService textDocumentService, LogService logService, CacheService cacheService, ConversionHelper conversionHelper, ClientService clientService) {
|
||||
public SaveHandler(TypeResolver typeResolver, TextDocumentService textDocumentService, LogService logService, CacheService cacheService, ConversionHelper conversionHelper, ClientService clientService, ParserService parserService) {
|
||||
this.typeResolver = typeResolver;
|
||||
this.textDocumentService = textDocumentService;
|
||||
this.logService = logService;
|
||||
this.cacheService = cacheService;
|
||||
this.conversionHelper = conversionHelper;
|
||||
this.clientService = clientService;
|
||||
this.parserService = parserService;
|
||||
}
|
||||
|
||||
public void handleSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
||||
|
||||
cacheService.reset();
|
||||
typeResolver.reset();
|
||||
var sWatch = Stopwatch.createUnstarted();
|
||||
sWatch.start();
|
||||
|
||||
|
||||
try {
|
||||
|
||||
String fileInput = textDocumentService.getFileOfUri(didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
|
||||
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(fileInput, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
if (!syntaxErrors.isEmpty()) {
|
||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), syntaxErrors);
|
||||
}
|
||||
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
||||
|
||||
if (syntaxErrors.isEmpty()) {
|
||||
|
||||
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
//typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
|
||||
if (fileInput == null) {
|
||||
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||
}
|
||||
|
||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(fileInput, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput, false);
|
||||
cacheService.setVariables(variables);
|
||||
|
||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(variables, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
@@ -55,12 +72,20 @@ public class SaveHandler {
|
||||
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
||||
|
||||
cacheService.updateGlobalMaps(diagnostics, typeHint, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), diagnostics);
|
||||
|
||||
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
|
||||
|
||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), allDiagnostics);
|
||||
|
||||
}
|
||||
|
||||
} 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());
|
||||
|
||||
for (StackTraceElement elem : e.getStackTrace()) {
|
||||
logService.log(elem.toString());
|
||||
}
|
||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
|
||||
} finally {
|
||||
|
@@ -1,130 +1,98 @@
|
||||
package de.dhbw.helper;
|
||||
|
||||
import de.dhbw.model.*;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbw.model.PlaceholderPoint;
|
||||
import de.dhbw.model.PlaceholderType;
|
||||
import de.dhbw.model.PlaceholderVariable;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.Pattern;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.target.generate.GenerateGenerics;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.result.*;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ASTTransformationHelper {
|
||||
|
||||
private final DuplicationUtils duplicationUtils;
|
||||
private final TypeUtils typeUtils;
|
||||
private final GenericUtils genericUtils;
|
||||
|
||||
public ASTTransformationHelper(DuplicationUtils duplicationUtils, TypeUtils typeUtils, GenericUtils genericUtils) {
|
||||
this.duplicationUtils = duplicationUtils;
|
||||
this.typeUtils = typeUtils;
|
||||
this.genericUtils = genericUtils;
|
||||
public static Set<PlaceholderVariable> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, GenericsResult generics) {
|
||||
return new PlaceholderPlacer().getTypeInserts(forSourcefile, withResults, generics);
|
||||
}
|
||||
|
||||
public List<LSPParameter> constructorToVariable(LanguageServerTransferObject transferObject) {
|
||||
public static PlaceholderVariable createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
|
||||
ResultSet resultSet, GenericsResultSet constraints, GenericsResultSet classConstraints) {
|
||||
|
||||
List<LSPParameter> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
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());
|
||||
}
|
||||
|
||||
for (var constructor : transferObject.getAst().KlassenVektor.getFirst().getConstructors()) {
|
||||
for (var constructorParam : constructor.getParameterList().getFormalparalist()) {
|
||||
var types = typeUtils.getAvailableTypes(transferObject.getResultSets(), constructorParam.getType());
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter("", types, constructorParam.getOffset().getLine(), constructorParam.getOffset().getCharPositionInLine(), constructorParam.getOffset().getStopIndex(), constructorParam.getType()));
|
||||
private static synchronized Set<PlaceholderPoint> createGenericInsert(GenericsResultSet methodConstraints, GenericsResultSet classConstraints, ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){
|
||||
Set<PlaceholderPoint> result = createGenericClassInserts(classConstraints, cl);
|
||||
|
||||
if (m != null) {
|
||||
result.addAll(createMethodConstraints(methodConstraints, m.getOffset() != null ? m.getOffset() : mOffset));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
String insert = " <";
|
||||
|
||||
for (var genericInsertConstraint : constraints) {
|
||||
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.GENERERIC_METHOD_INSERT));
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Set<PlaceholderPoint> createGenericClassInserts(GenericsResultSet classConstraints, ClassOrInterface cl) {
|
||||
Set<PlaceholderPoint> result = new HashSet<>();
|
||||
Token offset = cl.getGenerics().getOffset();
|
||||
|
||||
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));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
public List<LSPParameter> fieldDeclToVariable(LanguageServerTransferObject transferObject) {
|
||||
|
||||
List<LSPParameter> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
|
||||
for (var fieldDecl : transferObject.getAst().KlassenVektor.getFirst().getFieldDecl()) {
|
||||
var types = typeUtils.getAvailableTypes(transferObject.getResultSets(), fieldDecl.getReturnType());
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter("", types, fieldDecl.getOffset().getLine(), fieldDecl.getOffset().getCharPositionInLine(), fieldDecl.getOffset().getStopIndex(), fieldDecl.getReturnType()));
|
||||
}
|
||||
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
public List<LSPClass> addGenericClassPosition(LanguageServerTransferObject transferObject, String input) {
|
||||
|
||||
List<LSPClass> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
|
||||
for (var method : transferObject.getAst().getAllMethods()) {
|
||||
for (var clazz : transferObject.getAst().getClasses()) {
|
||||
ArrayList<Type> genericTypes = genericUtils.getClassGenerics(transferObject.getGeneratedGenerics(), method, clazz);
|
||||
TextHelper helper = new TextHelper();
|
||||
if (!genericTypes.isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPClass("test", genericTypes, clazz.getOffset().getLine(), helper.getClassPositionForGeneric(clazz.getOffset().getLine() - 1, input, clazz.getOffset().getStopIndex()), clazz.getOffset().getStopIndex(), clazz.getReturnType()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
|
||||
public List<LSPVariable> methodsWithParameterToVariable(LanguageServerTransferObject transferObj, boolean ENABLE_GENERICS) {
|
||||
List<LSPVariable> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
methodsWithParametersLSPVariableList.addAll(methodToVariable(transferObj, method, ENABLE_GENERICS));
|
||||
|
||||
for (var param : method.getParameterList()) {
|
||||
methodsWithParametersLSPVariableList.addAll(parameterToVariable(transferObj, param, method, ENABLE_GENERICS));
|
||||
}
|
||||
}
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
private List<LSPMethod> methodToVariable(LanguageServerTransferObject transferObj, Method method, boolean ENABLE_GENERICS) {
|
||||
List<LSPMethod> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
|
||||
var types = typeUtils.getAvailableTypes(transferObj.getResultSets(), method);
|
||||
if (!duplicationUtils.filterOutDuplicates(types).isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, duplicationUtils.filterOutDuplicates(types), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||
}
|
||||
|
||||
if (ENABLE_GENERICS) {
|
||||
var generics = genericUtils.getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), method);
|
||||
if (!generics.isEmpty()) {
|
||||
ArrayList<Type> typesThatAreGeneric = duplicationUtils.filterOutDuplicates(generics, types);
|
||||
typesThatAreGeneric.forEach(el -> el.setType("<" + el.getType() + "> " + el.getType()));
|
||||
//TODO: Muss Global und wird mehrmals so gemacht. Das if hier ist eigentlich falsch wegen unnötiger Berechnungszeit
|
||||
if (!duplicationUtils.filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, duplicationUtils.filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
private List<LSPParameter> parameterToVariable(LanguageServerTransferObject transferObj, Pattern param, Method method, boolean ENABLE_GENERICS) {
|
||||
List<LSPParameter> parameters = new ArrayList<>();
|
||||
|
||||
ArrayList<Type> typeParam = typeUtils.getAvailableTypes(transferObj.getResultSets(), param.getType());
|
||||
|
||||
if (!typeParam.isEmpty()) {
|
||||
parameters.add(new LSPParameter(method.name, duplicationUtils.filterOutDuplicates(typeParam), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex(), param.getType()));
|
||||
}
|
||||
|
||||
if (ENABLE_GENERICS) {
|
||||
ArrayList<Type> genericParam = genericUtils.getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), param.getType());
|
||||
if (!genericParam.isEmpty()) {
|
||||
ArrayList<Type> typesThatAreGeneric = duplicationUtils.filterOutDuplicates(genericParam, typeParam);
|
||||
|
||||
if (!duplicationUtils.filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||
parameters.add(new LSPParameter(method.name, duplicationUtils.filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex(), param.getType()));
|
||||
parameters.add(new LSPParameter(method.name, new ArrayList<>(duplicationUtils.filterOutDuplicates(typesThatAreGeneric).stream().map(el -> new Type("<" + el.getType() + ">", true)).toList()), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import de.dhbw.service.TextDocumentService;
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbw.model.Type;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||
import jdk.jshell.Diag;
|
||||
import org.eclipse.lsp4j.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -21,12 +20,16 @@ public class ConversionHelper {
|
||||
this.textDocumentService = textDocumentService;
|
||||
}
|
||||
|
||||
public String cleanType(String type){
|
||||
return type.replaceAll("java.lang.", "").replaceAll("java.util.", "");
|
||||
}
|
||||
|
||||
public InlayHint getInlayHint(LSPVariable variable) {
|
||||
InlayHint inlayHint = new InlayHint();
|
||||
|
||||
String typeDisplay = "";
|
||||
for (Type type : variable.getPossibleTypes()) {
|
||||
typeDisplay += " | " + type.getType().replaceAll("GTV ", "");
|
||||
typeDisplay += " | " + cleanType(type.getType().replaceAll("GTV ", ""));
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +49,24 @@ public class ConversionHelper {
|
||||
Diagnostic diagnostic = new Diagnostic(
|
||||
errorRange,
|
||||
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
|
||||
type.getType().replaceAll("GTV ", ""),
|
||||
cleanType(type.getType().replaceAll("GTV ", "")),
|
||||
DiagnosticSeverity.Hint,
|
||||
"JavaTX Language Server"
|
||||
);
|
||||
diagnostic.setCode(type.isGeneric() ? "GENERIC" : "TYPE");
|
||||
|
||||
return diagnostic;
|
||||
}
|
||||
|
||||
public Diagnostic getDiagnosticWithInput(LSPVariable variable, String input, Type type) {
|
||||
Range errorRange = new Range(
|
||||
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
||||
new Position(variable.getLine() - 1, textHelper.getEndingCharOfStartingChar(variable.getLine() - 1, variable.getCharPosition(), input)) // Endposition
|
||||
);
|
||||
Diagnostic diagnostic = new Diagnostic(
|
||||
errorRange,
|
||||
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
|
||||
cleanType(type.getType().replaceAll("GTV ", "")),
|
||||
DiagnosticSeverity.Hint,
|
||||
"JavaTX Language Server"
|
||||
);
|
||||
@@ -87,4 +107,22 @@ public class ConversionHelper {
|
||||
|
||||
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
||||
}
|
||||
|
||||
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(ArrayList<LSPVariable> typesOfMethodAndParameters, String input) {
|
||||
List<InlayHint> typeHint = new ArrayList<>();
|
||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||
|
||||
for (var variable : typesOfMethodAndParameters) {
|
||||
|
||||
InlayHint inlayHint = getInlayHint(variable);
|
||||
typeHint.add(inlayHint);
|
||||
|
||||
for (var type : variable.getPossibleTypes()) {
|
||||
Diagnostic diagnostic = getDiagnosticWithInput(variable, input, type);
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +0,0 @@
|
||||
package de.dhbw.helper;
|
||||
|
||||
import de.dhbw.model.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GenericUtils {
|
||||
public ArrayList<Type> getClassGenerics(Map<SourceFile, List<GenericsResult>> genericsResult, Method method, ClassOrInterface clazz) {
|
||||
ArrayList<Type> genericTypes = new ArrayList<>();
|
||||
|
||||
genericsResult.forEach(((key, value) -> value.forEach(genericResultSet -> {
|
||||
|
||||
var result = genericResultSet.resolveTarget(method.getReturnType());
|
||||
|
||||
|
||||
var genericResult = genericResultSet.getBounds(method.getReturnType(), clazz, method);
|
||||
if (result != null && genericResult != null) {
|
||||
genericResult.forEach(res -> {
|
||||
if (res != null && !res.isOnMethod()) {
|
||||
genericTypes.add(new Type("<" + result.name() + (res.bound().toString().equals("java.lang.Object") ? ">" : " extends " + res.bound().toString() + ">"), true));
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
})));
|
||||
|
||||
return genericTypes;
|
||||
}
|
||||
|
||||
public ArrayList<Type> getAvailableGenericTypes(List<GenericsResult> genericsResult, RefTypeOrTPHOrWildcardOrGeneric parameter) {
|
||||
|
||||
|
||||
ArrayList<String> paramTypes = new ArrayList<>();
|
||||
genericsResult.forEach(conSet -> {
|
||||
if (parameter.toString().toLowerCase().contains("tph ")) {
|
||||
paramTypes.add(conSet.resolveTarget(parameter).name());
|
||||
}
|
||||
});
|
||||
|
||||
return new ArrayList<>(paramTypes.stream().filter(el -> !el.contains("TPH ")).map(el -> new Type(el, true)).toList());
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Type> getAvailableGenericTypes(List<GenericsResult> genericsResult, Method method) {
|
||||
|
||||
ArrayList<String> genericTypes = new ArrayList<>();
|
||||
|
||||
genericsResult.forEach(conSet -> {
|
||||
if (method.getReturnType().toString().toLowerCase().contains("tph ")) {
|
||||
genericTypes.add(conSet.resolveTarget(method.getReturnType()).name().replaceAll("GTV ", ""));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return new ArrayList<>(genericTypes.stream().filter(el -> !el.contains("TPH ")).map(el -> new Type(el, true)).toList());
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,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;
|
||||
String pkgName;
|
||||
private GenericsResult genericsResult;
|
||||
|
||||
public Set<PlaceholderVariable> getTypeInserts(SourceFile forSourceFile, ResultSet withResults, GenericsResult genericsResult){
|
||||
this.withResults = withResults;
|
||||
this.genericsResult = genericsResult;
|
||||
pkgName = forSourceFile.getPkgName();
|
||||
forSourceFile.accept(this);
|
||||
inserts.forEach(el -> el.reducePackage());
|
||||
return inserts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
de.dhbw.helper.PlaceholderPlacerClass cl = new de.dhbw.helper.PlaceholderPlacerClass(classOrInterface, withResults, genericsResult);
|
||||
this.inserts.addAll(cl.inserts);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,65 @@
|
||||
package de.dhbw.helper;
|
||||
|
||||
import de.dhbw.model.PlaceholderVariable;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
class PlaceholderPlacerClass extends AbstractASTWalker{
|
||||
protected final ResultSet results;
|
||||
private GenericsResult generatedGenerics;
|
||||
protected final ClassOrInterface cl;
|
||||
public final Set<PlaceholderVariable> inserts = new HashSet<>();
|
||||
private Method method;
|
||||
|
||||
GenericsResultSet constraints;
|
||||
GenericsResultSet classConstraints;
|
||||
|
||||
PlaceholderPlacerClass(ClassOrInterface forClass, ResultSet withResults, GenericsResult generatedGenerics){
|
||||
this.cl = forClass;
|
||||
this.method = null;
|
||||
this.results = withResults;
|
||||
this.generatedGenerics = generatedGenerics;
|
||||
forClass.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
this.method = method;
|
||||
constraints = generatedGenerics.get(method);
|
||||
classConstraints = generatedGenerics.get(cl);
|
||||
if(method.getReturnType() instanceof TypePlaceholder)
|
||||
inserts.add(ASTTransformationHelper.createInsertPoints(
|
||||
method.getReturnType(), method.getReturnType().getOffset(), cl, method, results, constraints, classConstraints));
|
||||
super.visit(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
if(field.getType() instanceof TypePlaceholder){
|
||||
classConstraints = generatedGenerics.get(cl);
|
||||
inserts.add(ASTTransformationHelper.createInsertPoints(
|
||||
field.getType(), field.getType().getOffset(), cl, method, results, null, classConstraints));
|
||||
}
|
||||
super.visit(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FormalParameter param) {
|
||||
if(param.getType() instanceof TypePlaceholder)
|
||||
inserts.add(ASTTransformationHelper.createInsertPoints(
|
||||
param.getType(), param.getType().getOffset(), cl, method, results, constraints, classConstraints));
|
||||
super.visit(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
//Lambda-Ausdrücke brauchen keine Typeinsetzungen
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
package de.dhbw.helper;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
||||
import de.dhbwstuttgart.typeinference.result.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class PlaceholderToInsertString implements ResultSetVisitor{
|
||||
public String insert = "";
|
||||
private GenericsResultSet constraints;
|
||||
private GenericsResultSet classConstraints;
|
||||
|
||||
|
||||
public PlaceholderToInsertString(RefTypeOrTPHOrWildcardOrGeneric type, GenericsResultSet constraints, GenericsResultSet classConstraints){
|
||||
this.constraints = constraints;
|
||||
this.classConstraints = classConstraints;
|
||||
type.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(PairTPHsmallerTPH p) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(PairTPHequalRefTypeOrWildcardType p) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(PairTPHEqualTPH p) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RefType resolved) {
|
||||
insert = resolved.getName().toString();
|
||||
if(resolved.getParaList().size() > 0){
|
||||
insert += "<";
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> iterator = resolved.getParaList().iterator();
|
||||
while(iterator.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric typeParam = iterator.next();
|
||||
insert += new PlaceholderToInsertString(typeParam, constraints, classConstraints).insert;
|
||||
if(iterator.hasNext())insert += ", ";
|
||||
}
|
||||
insert += ">";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
insert += genericRefType.getParsedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperWildcardType superWildcardType) {
|
||||
insert += "? super " + new PlaceholderToInsertString(superWildcardType.getInnerType(), constraints, classConstraints).insert;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
ResultPair<?, ?> 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExtendsWildcardType extendsWildcardType) {
|
||||
insert += "? extends " + new PlaceholderToInsertString(extendsWildcardType.getInnerType(), constraints, classConstraints).insert;
|
||||
}
|
||||
}
|
@@ -2,8 +2,6 @@ package de.dhbw.helper;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TextHelper {
|
||||
@@ -59,7 +57,7 @@ public class TextHelper {
|
||||
|
||||
if(lines.length < line){
|
||||
log.warn("Returning hardcoded Value because the requested Line [" + line + "] does not exist in Text Document.");
|
||||
return startChar+3;
|
||||
return startChar;
|
||||
}
|
||||
|
||||
String[] linesInChar = lines[line].split("");
|
||||
|
@@ -2,16 +2,28 @@ package de.dhbw.helper;
|
||||
|
||||
|
||||
import de.dhbw.model.*;
|
||||
import de.dhbw.model.PlaceholderVariable;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
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 org.eclipse.lsp4j.MessageParams;
|
||||
import org.eclipse.lsp4j.MessageType;
|
||||
import org.eclipse.lsp4j.services.LanguageClient;
|
||||
|
||||
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.*;
|
||||
|
||||
|
||||
@@ -21,19 +33,32 @@ import java.util.*;
|
||||
public class TypeResolver {
|
||||
private static final Logger logger = LogManager.getLogger(TypeResolver.class);
|
||||
|
||||
private final ASTTransformationHelper astTransformationHelper;
|
||||
private final TypeUtils typeUtils;
|
||||
private final GenericUtils genericUtils;
|
||||
private final DuplicationUtils duplicationUtils;
|
||||
private final boolean ENABLE_GENERICS = false;
|
||||
private final boolean ENABLE_GENERICS = true;
|
||||
private List<GenericsResult> generatedGenerics = null;
|
||||
private HashMap<String, List<PlaceholderVariable>> inserts;
|
||||
|
||||
|
||||
public HashMap<String, List<PlaceholderVariable>> getInserts() {
|
||||
return inserts;
|
||||
}
|
||||
|
||||
//Somehow you have to reset to the Letter N to keep the naming of the TPHs consistent
|
||||
private final String RESET_TO_LETTER = "A";
|
||||
|
||||
private LanguageServerTransferObject current;
|
||||
|
||||
public void reset() {
|
||||
HashMap<String, List<TypeInsert>> inserts = null;
|
||||
List<GenericsResult> generatedGenerics = null;
|
||||
current = null;
|
||||
}
|
||||
|
||||
|
||||
public TypeResolver() {
|
||||
this.typeUtils = new TypeUtils();
|
||||
this.genericUtils = new GenericUtils();
|
||||
this.duplicationUtils = new DuplicationUtils();
|
||||
this.astTransformationHelper = new ASTTransformationHelper(duplicationUtils, typeUtils, genericUtils);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,61 +82,141 @@ public class TypeResolver {
|
||||
|
||||
public void getCompilerInput(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
var transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||
var transferObj = languageServer.getResultSetAndAbastractSyntax(path, RESET_TO_LETTER);
|
||||
current = transferObj;
|
||||
}
|
||||
|
||||
public LanguageServerTransferObject updateIfNotPresent(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
if (current == null) {
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
LanguageServerTransferObject transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||
LanguageServerTransferObject transferObj = languageServer.getResultSetAndAbstractSyntax(path);
|
||||
return transferObj;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zum Erhalt für sowohl Parameter als auch Methoden.
|
||||
*/
|
||||
public ArrayList<LSPVariable> infereInput(String input, String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
logger.info("Infering Types for Input.");
|
||||
public ArrayList<LSPVariable> infereChangeInput() throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
|
||||
current = updateIfNotPresent(path, input);
|
||||
LanguageServerTransferObject transferObj = current;
|
||||
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)));
|
||||
|
||||
ArrayList<LSPVariable> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
|
||||
|
||||
methodsWithParametersLSPVariableList.addAll(astTransformationHelper.constructorToVariable(transferObj));
|
||||
methodsWithParametersLSPVariableList.addAll(astTransformationHelper.fieldDeclToVariable(transferObj));
|
||||
|
||||
|
||||
if (!transferObj.getResultSets().isEmpty()) {
|
||||
//TODO: Hier noch irgendwie die Klasse rausfinden oder durchgehen.
|
||||
|
||||
if (ENABLE_GENERICS) {
|
||||
methodsWithParametersLSPVariableList.addAll(astTransformationHelper.addGenericClassPosition(transferObj, input));
|
||||
}
|
||||
|
||||
methodsWithParametersLSPVariableList.addAll(astTransformationHelper.methodsWithParameterToVariable(transferObj, ENABLE_GENERICS));
|
||||
HashMap<String, 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)));
|
||||
} else {
|
||||
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
||||
}
|
||||
}
|
||||
|
||||
return methodsWithParametersLSPVariableList;
|
||||
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());
|
||||
|
||||
|
||||
for (var variable : variables) {
|
||||
|
||||
HashMap<String, Type> uniqueType = new HashMap<>();
|
||||
|
||||
for (var type : variable.getPossibleTypes()) {
|
||||
if (!uniqueType.containsKey(type.getType().replaceAll(" ", ""))) {
|
||||
uniqueType.put(type.getType(), type);
|
||||
}
|
||||
}
|
||||
variable.setPossibleTypes(new ArrayList<>(uniqueType.values()));
|
||||
logger.info(variable.getLine() + ":" + variable.getCharPosition());
|
||||
for (Type t : variable.getPossibleTypes()) {
|
||||
logger.info(t.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return variables;
|
||||
}
|
||||
|
||||
public ArrayList<LSPVariable> infereInput(String pathString, String input, boolean a) 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)));
|
||||
}
|
||||
System.setOut(System.out);
|
||||
this.current = lsTransfer;
|
||||
|
||||
HashMap<String, 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)));
|
||||
} else {
|
||||
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
||||
}
|
||||
}
|
||||
|
||||
inserts = insertsOnLines;
|
||||
|
||||
logger.info("TYPES ARE:");
|
||||
insertsOnLines.forEach((key, value) -> value.forEach(type -> logger.info(type.point.getInsertString())));
|
||||
ArrayList<LSPVariable> variables = new ArrayList<>();
|
||||
|
||||
|
||||
for(var entrySet : insertsOnLines.entrySet()){
|
||||
ArrayList<Type> typesOfVariable = new ArrayList<>();
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables, LanguageClient client) {
|
||||
client.logMessage(new MessageParams(MessageType.Info, "Lenght is: " + combinedList.size()));
|
||||
for (var variable : variables) {
|
||||
|
||||
HashMap<String, Type> uniqueType = new HashMap<>();
|
||||
|
||||
for (var type : variable.getPossibleTypes()) {
|
||||
if (!uniqueType.containsKey(type.getType().replaceAll(" ", ""))) {
|
||||
uniqueType.put(type.getType(), type);
|
||||
}
|
||||
}
|
||||
variable.setPossibleTypes(new ArrayList<>(uniqueType.values()));
|
||||
logger.info(variable.getLine() + ":" + variable.getCharPosition());
|
||||
for (Type t : variable.getPossibleTypes()) {
|
||||
logger.info(t.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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()) {
|
||||
client.logMessage(new MessageParams(MessageType.Info, "\"" + typeOfVariable.getType() + " : " + variable.getLine() + "\"< > \"" + contentChange + " : " + lines.getKey() + "\""));
|
||||
|
||||
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(" ", "")));
|
||||
client.logMessage(new MessageParams(MessageType.Info, "Removing Resultset"));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -119,4 +224,19 @@ public class TypeResolver {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SourceFile getNewAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
||||
return languageServerInterface.getAst(uri, RESET_TO_LETTER);
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
logger.info("NEW AST:");
|
||||
logger.info(ASTPrinter.print(current.getAst()));
|
||||
}
|
||||
|
||||
}
|
@@ -3,7 +3,6 @@ package de.dhbw.helper;
|
||||
import de.dhbw.model.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@@ -0,0 +1,92 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PlaceholderPoint {
|
||||
public Token point;
|
||||
private String insertString;
|
||||
private int extraOffset = 0;
|
||||
private PlaceholderType kind;
|
||||
|
||||
public void setInsertString(String insertString){
|
||||
this.insertString = insertString;
|
||||
}
|
||||
|
||||
public PlaceholderPoint(Token point, String toInsert, PlaceholderType kind){
|
||||
this.point = point;
|
||||
this.kind = kind;
|
||||
this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ;
|
||||
}
|
||||
|
||||
public boolean isGenericClassInsertPoint() {
|
||||
return kind == PlaceholderType.GENERIC_CLASS_INSERT;
|
||||
}
|
||||
|
||||
public String insert(String intoSource, List<PlaceholderPoint> additionalOffset){
|
||||
return new StringBuilder(intoSource).insert(point.getStartIndex()+extraOffset, insertString).toString();
|
||||
}
|
||||
|
||||
public String getInsertString() {
|
||||
return insertString;
|
||||
}
|
||||
|
||||
public void addExtraOffset(int toAdd) {
|
||||
this.extraOffset += toAdd;
|
||||
}
|
||||
|
||||
public int getPositionInCode() {
|
||||
return point.getStartIndex() + extraOffset;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return this == obj;
|
||||
/*
|
||||
if(!(obj instanceof TypeInsertPoint)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return
|
||||
((TypeInsertPoint)obj).getPositionInCode() == this.getPositionInCode() &&
|
||||
((TypeInsertPoint)obj).insertString.equals(this.insertString);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return getPositionInCode() * 11 * insertString.hashCode();
|
||||
}
|
||||
|
||||
public Set<PlaceholderPoint> getAdditionalPoints() {
|
||||
return this.getAdditionalPoints();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return point.getLine() + ":" + point.getCharPositionInLine() + ":" + insertString;
|
||||
}
|
||||
|
||||
public static final class TypeInsertPointPositionComparator implements Comparator<PlaceholderPoint> {
|
||||
|
||||
@Override
|
||||
public int compare(PlaceholderPoint o1, PlaceholderPoint o2) {
|
||||
if (o1.point == null && o2.point == null) {
|
||||
return 0;
|
||||
} else if (o2.point == null) {
|
||||
return 1;
|
||||
} else if (o1.point == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (o1.getPositionInCode() > o2.getPositionInCode()) {
|
||||
return 1;
|
||||
} else if (o1.getPositionInCode() < o2.getPositionInCode()) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
public enum PlaceholderType {
|
||||
NORMAL_INSERT,
|
||||
GENERIC_CLASS_INSERT,
|
||||
GENERERIC_METHOD_INSERT
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PlaceholderVariable {
|
||||
/**
|
||||
* point wird hauptsächlich zur Anzeige einer Annotation im Eclipse-plugin benutzt.
|
||||
*/
|
||||
public final PlaceholderPoint point;
|
||||
Set<PlaceholderPoint> inserts;
|
||||
ResultPair<?, ?> resultPair;
|
||||
|
||||
|
||||
|
||||
public PlaceholderVariable(PlaceholderPoint point, Set<PlaceholderPoint> additionalPoints, ResultPair<?, ?> resultPair) {
|
||||
this.point = point;
|
||||
inserts = additionalPoints;
|
||||
this.resultPair = resultPair;
|
||||
}
|
||||
|
||||
public String insert(String intoSource) {
|
||||
List<PlaceholderPoint> offsets = new ArrayList<>();
|
||||
String ret = intoSource;
|
||||
|
||||
List<PlaceholderPoint> insertsSorted = new ArrayList<>();
|
||||
insertsSorted.add(point);
|
||||
insertsSorted.addAll(inserts);
|
||||
Collections.sort(insertsSorted, new PlaceholderPoint.TypeInsertPointPositionComparator().reversed());
|
||||
|
||||
for (PlaceholderPoint insertPoint : insertsSorted) {
|
||||
ret = insertPoint.insert(ret, new ArrayList<>());
|
||||
offsets.add(insertPoint);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getInsertString() {
|
||||
return point.getInsertString();
|
||||
}
|
||||
|
||||
public void reducePackage(){point.setInsertString(point.getInsertString().replaceAll("java\\.lang\\.", "").replaceAll("java\\.util\\.", ""));
|
||||
}
|
||||
|
||||
public ResultPair<?, ?> getResultPair() {
|
||||
return this.resultPair;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof PlaceholderVariable)) {
|
||||
return false;
|
||||
} else {
|
||||
return ((PlaceholderVariable) obj).point.equals(this.point);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Set<PlaceholderPoint> getAdditionalPoints() {
|
||||
PlaceholderPoint.TypeInsertPointPositionComparator comparator = new PlaceholderPoint.TypeInsertPointPositionComparator();
|
||||
TreeSet<PlaceholderPoint> result = new TreeSet<>(comparator.reversed());
|
||||
result.addAll(inserts);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Set<PlaceholderPoint> getAdditionalPointsUnsorted() {
|
||||
return inserts;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return point.toString();
|
||||
}
|
||||
}
|
@@ -24,4 +24,15 @@ public class Type {
|
||||
public boolean isGeneric() {
|
||||
return generic;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return type.equals(obj.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import de.dhbw.helper.CodeSnippetOptions;
|
||||
import de.dhbw.helper.TextHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.InlayHint;
|
||||
|
||||
@@ -14,6 +15,7 @@ import java.util.List;
|
||||
|
||||
public class CacheService {
|
||||
private HashMap<String, List<InlayHint>> globalInlayHintMap = new HashMap<>();
|
||||
private HashMap<String, String> lastSavedFiles = new HashMap<>();
|
||||
private Boolean currentlyCalculating = false;
|
||||
private HashMap<String, List<Diagnostic>> globalDiagnosticsMap = new HashMap<>();
|
||||
private HashMap<String, String> textDocuments = new HashMap<>();
|
||||
@@ -24,6 +26,31 @@ public class CacheService {
|
||||
private Path fileRoot = null;
|
||||
private Boolean singleFileOpened = false;
|
||||
private List<LSPVariable> variables = new ArrayList<>();
|
||||
private List<TypeInsert> typeInserts;
|
||||
|
||||
public List<TypeInsert> getTypeInserts() {
|
||||
return typeInserts;
|
||||
}
|
||||
|
||||
public void setTypeInserts(List<TypeInsert> typeInserts) {
|
||||
this.typeInserts = typeInserts;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
globalInlayHintMap = new HashMap<>();
|
||||
lastSavedFiles = new HashMap<>();
|
||||
currentlyCalculating = false;
|
||||
globalDiagnosticsMap = new HashMap<>();
|
||||
textDocuments = new HashMap<>();
|
||||
codeSnippetOptions = new CodeSnippetOptions();
|
||||
textHelper = new TextHelper();
|
||||
dontShowHints = false;
|
||||
typeResolver = new TypeResolver();
|
||||
fileRoot = null;
|
||||
singleFileOpened = false;
|
||||
typeInserts = null;
|
||||
}
|
||||
|
||||
|
||||
public void updateGlobalMaps(List<Diagnostic> diagnostics, List<InlayHint> typeHint, String uri) {
|
||||
globalDiagnosticsMap.put(uri, diagnostics);
|
||||
@@ -42,6 +69,14 @@ public class CacheService {
|
||||
return singleFileOpened;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getLastSavedFiles() {
|
||||
return lastSavedFiles;
|
||||
}
|
||||
|
||||
public void setLastSavedFiles(HashMap<String, String> lastSavedFiles) {
|
||||
this.lastSavedFiles = lastSavedFiles;
|
||||
}
|
||||
|
||||
public CodeSnippetOptions getCodeSnippetOptions() {
|
||||
return codeSnippetOptions;
|
||||
}
|
||||
|
@@ -1,14 +1,35 @@
|
||||
package de.dhbw.service;
|
||||
|
||||
import de.dhbw.helper.ConversionHelper;
|
||||
import de.dhbwstuttgart.languageServerInterface.ParserInterface;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParserService {
|
||||
|
||||
private final ConversionHelper conversionHelper;
|
||||
private final ClientService clientService;
|
||||
|
||||
|
||||
public ParserService(ConversionHelper conversionHelper, ClientService clientService, CacheService cacheService) {
|
||||
this.conversionHelper = conversionHelper;
|
||||
this.clientService = clientService;
|
||||
}
|
||||
|
||||
public List<ParserError> getParserErrors(String input){
|
||||
ParserInterface parserInterface = new ParserInterface();
|
||||
return parserInterface.getParseErrors(input);
|
||||
}
|
||||
|
||||
public void checkParser(String input, String uri) {
|
||||
List<Diagnostic> diagnosticsList = conversionHelper.parseErrorToDiagnostic(getParserErrors(input));
|
||||
clientService.publishDiagnostics(uri, diagnosticsList);
|
||||
}
|
||||
|
||||
public List<Diagnostic> getDiagnosticsOfErrors(String input, String uri) {
|
||||
return conversionHelper.parseErrorToDiagnostic(getParserErrors(input));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,11 @@ public class TextDocumentService {
|
||||
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
files.clear();
|
||||
}
|
||||
|
||||
|
||||
public String getFileOfUri(String uri) {
|
||||
return files.get(uri);
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
|
||||
import de.dhbw.helper.CodeSnippetOptions;
|
||||
import de.dhbw.model.SnippetWithName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
|
||||
import de.dhbw.helper.TextHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,29 +12,6 @@ public class CompilerInterfaceTest {
|
||||
|
||||
@Test
|
||||
public void testAbstractSyntaxAsString() throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
var res = typeResolver.infereInput("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||
"public class test{\n" +
|
||||
"public main(test){" +
|
||||
"if(0>1){" +
|
||||
"return \"w\";" +
|
||||
"}" +
|
||||
"Integer i = 0;" +
|
||||
"return i;" +
|
||||
"}" +
|
||||
"}", "c%3A/Users/ruben/Neuer%20Ordner%20%282%29/LSP-Vortrag/images/test.jav");
|
||||
|
||||
var res2 = typeResolver.infereInput("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||
"public class test{\n" +
|
||||
"public main(test){" +
|
||||
"if(0>1){" +
|
||||
"return \"w\";" +
|
||||
"}" +
|
||||
"Integer i = 0;" +
|
||||
"return i;" +
|
||||
"}" +
|
||||
"}", "c%3A/Users/ruben/Neuer%20Ordner%20%282%29/LSP-Vortrag/images/test.jav");
|
||||
System.out.println("TEST OUTPUT:");
|
||||
//
|
||||
// ArrayList<String> allTypes = new ArrayList<>();
|
||||
//
|
||||
@@ -49,18 +27,16 @@ public class CompilerInterfaceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstraintTypes() throws IOException, ClassNotFoundException {
|
||||
// LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
// TypeResolver typeResolver = new TypeResolver();
|
||||
//
|
||||
//
|
||||
// var res = typeResolver.infereInput("import java.lang.Integer; public class test{\n" +
|
||||
// " \n" +
|
||||
// " public main(testa){\n" +
|
||||
// " return testa;\n" +
|
||||
// " }\n" +
|
||||
// "}");
|
||||
// res.forEach(el -> el.getPossibleTypes().forEach(el2 -> System.out.println(el2.getType() + " " + (el2.isGeneric() ? "GENERIC" : "NO GENERIC"))));
|
||||
public void testConstraintTypes() throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
|
||||
|
||||
var res = languageServer.getResultSetAndAbstractSyntax("/home/ruben/Documents/JavaTXLanguageServer/test/test.jav");
|
||||
|
||||
var res2 = languageServer.getResultSetAndAbstractSyntax("/home/ruben/Documents/JavaTXLanguageServer/test/test.jav");
|
||||
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -1,7 +1,3 @@
|
||||
import de.dhbw.JavaTXTextDocumentService;
|
||||
import de.dhbw.helper.CodeSnippetOptions;
|
||||
import org.eclipse.lsp4j.DidSaveTextDocumentParams;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
5
test/test.jav
Normal file
5
test/test.jav
Normal file
@@ -0,0 +1,5 @@
|
||||
public class t{
|
||||
public test(){
|
||||
return 1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user