11 Commits

Author SHA1 Message Date
Ruben
bb9be2c319 feat: infere Lambdas in Methods 2025-07-12 11:55:59 +02:00
Ruben
57c82542f4 refactor: add Method instead of calculating directly 2025-07-12 11:35:43 +02:00
Ruben
cb54606a93 feat: add lambda inference for Field Variables 2025-07-12 11:15:34 +02:00
Ruben
31ed1f16b6 feat: import all generics when one is selected 2025-07-11 21:20:04 +02:00
Ruben
5569b6d0db feat: add Picture and Description to VSC Client 2025-07-09 16:15:47 +02:00
Ruben
2a87b85dc1 fix: display ParserErrors 2025-07-09 15:47:21 +02:00
Ruben
11fb843efe docs: add Doc for installation of LSP Client for Intellij 2025-07-09 15:25:15 +02:00
Ruben
701caab9cd fix: fix generic Display and enable them 2025-07-08 20:45:49 +02:00
Ruben
c2cbd0aa92 fix: reduction of ResultSet now also bases on last saved File 2025-07-08 19:54:35 +02:00
Ruben
e1b000b976 fix: fix position adjustment 2025-07-08 19:28:06 +02:00
RubenKraft
7de2b2764a Merge pull request 'refactor' (#37) from refactor into main
Reviewed-on: #37
2025-07-07 18:38:09 +00:00
14 changed files with 167 additions and 49 deletions

View 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.

After

Width:  |  Height:  |  Size: 902 KiB

View File

@@ -1,8 +1,9 @@
{ {
"name": "lspclient", "icon": "TX.png",
"displayName": "LSPClient", "name": "java-tx-language-extension",
"description": "", "displayName": "Java-TX Language Extension",
"version": "0.0.1", "description": "The Language Extension for Java-TX with Typehints and Syntax Checks",
"version": "0.0.2",
"engines": { "engines": {
"vscode": "^1.94.0" "vscode": "^1.94.0"
}, },

View File

@@ -1,12 +1,9 @@
package de.dhbw; package de.dhbw;
import de.dhbw.handler.ChangeHandler; import de.dhbw.handler.*;
import de.dhbw.handler.CodeActionHandler;
import de.dhbw.handler.FormattingHandler;
import de.dhbw.service.CacheService; import de.dhbw.service.CacheService;
import de.dhbw.service.ClientService; import de.dhbw.service.ClientService;
import de.dhbw.service.LogService; import de.dhbw.service.LogService;
import de.dhbw.handler.SaveHandler;
import de.dhbw.helper.CodeSnippetOptions; import de.dhbw.helper.CodeSnippetOptions;
import de.dhbw.helper.ConversionHelper; import de.dhbw.helper.ConversionHelper;
import de.dhbw.helper.TextHelper; import de.dhbw.helper.TextHelper;
@@ -42,6 +39,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
private final ChangeHandler changeHandler; private final ChangeHandler changeHandler;
private final TextHelper textHelper; private final TextHelper textHelper;
private final CodeActionHandler codeActionHandler; private final CodeActionHandler codeActionHandler;
private final InlayHintAdjusterDiffUtils inlayHintAdjusterDiffUtils;
LanguageClient client; LanguageClient client;
HashMap<String, String> textDocuments = new HashMap<>(); HashMap<String, String> textDocuments = new HashMap<>();
@@ -52,7 +50,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
public JavaTXTextDocumentService() { public JavaTXTextDocumentService() {
this.textHelper = new TextHelper(); this.textHelper = new TextHelper();
this.parserService = new ParserService(); this.inlayHintAdjusterDiffUtils = new InlayHintAdjusterDiffUtils();
this.cacheService = new CacheService(); this.cacheService = new CacheService();
this.clientService = new ClientService(null); this.clientService = new ClientService(null);
this.typeResolver = new TypeResolver(); this.typeResolver = new TypeResolver();
@@ -60,9 +58,10 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
this.conversionHelper = new ConversionHelper(textHelper, textDocumentService); this.conversionHelper = new ConversionHelper(textHelper, textDocumentService);
this.logService = new LogService(clientService); this.logService = new LogService(clientService);
this.formattingHandler = new FormattingHandler(textDocumentService); this.formattingHandler = new FormattingHandler(textDocumentService);
this.parserService = new ParserService(conversionHelper, clientService, cacheService);
this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService); this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService);
this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService); this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService, parserService);
this.changeHandler = new ChangeHandler(textDocumentService, parserService, conversionHelper, clientService, typeResolver, cacheService, logService); this.changeHandler = new ChangeHandler(textDocumentService, parserService, conversionHelper, clientService, typeResolver, cacheService, logService, inlayHintAdjusterDiffUtils);
} }
public void setClient(LanguageClient client) { public void setClient(LanguageClient client) {

View File

@@ -12,6 +12,7 @@ import org.eclipse.lsp4j.*;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class ChangeHandler { public class ChangeHandler {
@@ -22,8 +23,9 @@ public class ChangeHandler {
private final TypeResolver typeResolver; private final TypeResolver typeResolver;
private final CacheService cacheService; private final CacheService cacheService;
private final LogService logService; private final LogService logService;
private final InlayHintAdjusterDiffUtils inlayHintAdjusterDiffUtils;
public ChangeHandler(TextDocumentService textDocumentService, ParserService parserService, ConversionHelper conversionHelper, ClientService clientService, TypeResolver typeResolver, CacheService cacheService, LogService logService) { public ChangeHandler(TextDocumentService textDocumentService, ParserService parserService, ConversionHelper conversionHelper, ClientService clientService, TypeResolver typeResolver, CacheService cacheService, LogService logService, InlayHintAdjusterDiffUtils inlayHintAdjusterDiffUtils) {
this.textDocumentService = textDocumentService; this.textDocumentService = textDocumentService;
this.parserService = parserService; this.parserService = parserService;
this.conversionHelper = conversionHelper; this.conversionHelper = conversionHelper;
@@ -31,25 +33,39 @@ public class ChangeHandler {
this.typeResolver = typeResolver; this.typeResolver = typeResolver;
this.cacheService = cacheService; this.cacheService = cacheService;
this.logService = logService; this.logService = logService;
this.inlayHintAdjusterDiffUtils = inlayHintAdjusterDiffUtils;
} }
public void didChange(DidChangeTextDocumentParams params) { public void didChange(DidChangeTextDocumentParams params) {
String currentText = textDocumentService.getFileOfUri(params.getTextDocument().getUri()); 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<>(""); AtomicReference<String> summedUp = new AtomicReference<>("");
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText())); params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), summedUp.get()); textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), summedUp.get());
DocumentChanges documentChanges = textDocumentService.calculateDifference(currentText, summedUp.get());
HashMap<LineCharPosition, String> preciseChanges = documentChanges.getPreciseChanges();
HashMap<Integer, List<String>> textChanges;
ArrayList<Integer> offsetPerLine = documentChanges.getOffsetPerLine();
//Have to check of old saved Input because the result set and Inlay Hints will be updated according to the old AST which contains the old Positions
if(cacheService.getLastSavedFiles().containsKey(params.getTextDocument().getUri())){
DocumentChanges changesFromOldSave = textDocumentService.calculateDifference(cacheService.getLastSavedFiles().get(params.getTextDocument().getUri()), summedUp.get());
offsetPerLine = changesFromOldSave.getOffsetPerLine();
textChanges = changesFromOldSave.getTextChanges();
preciseChanges = changesFromOldSave.getPreciseChanges();
logService.log(textChanges.values().stream().map(el -> String.join(", ", el)).collect(Collectors.joining("\n")));
} else {
textChanges = documentChanges.getTextChanges();
}
String input = summedUp.get(); String input = summedUp.get();
checkParser(input, params.getTextDocument().getUri());
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables(), clientService.getClient()); typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables());
var sWatch = Stopwatch.createUnstarted(); var sWatch = Stopwatch.createUnstarted();
sWatch.start(); sWatch.start();
@@ -59,7 +75,7 @@ public class ChangeHandler {
String currentInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri()); String currentInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
if (currentInput == null) { if (currentInput == null) {
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error); logService.log("[didChange] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
} }
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(currentInput, params.getTextDocument().getUri()); ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(currentInput, params.getTextDocument().getUri());
@@ -75,13 +91,18 @@ public class ChangeHandler {
} catch (Exception e) { } catch (Exception e) {
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error); 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()); clientService.showMessage(MessageType.Error, e.getMessage());
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri()); cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
} finally { } finally {
sWatch.stop(); sWatch.stop();
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info); logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
} }
@@ -99,13 +120,29 @@ public class ChangeHandler {
return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", "")); return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""));
}).toList()); }).toList());
clientService.publishDiagnostics(params.getTextDocument().getUri(), cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri())); List<Diagnostic> typeDiagnostics = cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri());
List<Diagnostic> parserErrors = parserService.getDiagnosticsOfErrors(input, params.getTextDocument().getUri());
ArrayList<Diagnostic> allDiagnostics = new ArrayList<>(typeDiagnostics);
allDiagnostics.addAll(parserErrors);
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
} }
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, String old, String newText){
cacheService.getGlobalInlayHintMap().put(params.getTextDocument().getUri(), inlayHintAdjusterDiffUtils.adjustInlayHintsByLineDiff(old, newText, cacheService.getGlobalInlayHintMap().get(params.getTextDocument().getUri())));
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();
} }
private void updatePositions(DidChangeTextDocumentParams params, ArrayList<Integer> offsetPerLine){ private void updatePositions(DidChangeTextDocumentParams params, ArrayList<Integer> offsetPerLine){

View File

@@ -60,7 +60,7 @@ public class CodeActionHandler {
if (typeDiagnostic.getCode().getLeft().equals("GENERIC")) { if (typeDiagnostic.getCode().getLeft().equals("GENERIC")) {
for (var diagnostic : cacheService.getGlobalDiagnosticsMap().get(documentUri)) { 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() + String genericType = diagnostic.getMessage() +
" " + " " +
textHelper.getTextOfChars( textHelper.getTextOfChars(

View File

@@ -14,7 +14,7 @@ import java.util.List;
public class InlayHintAdjusterDiffUtils { public class InlayHintAdjusterDiffUtils {
public static List<InlayHint> adjustInlayHintsByLineDiff(String oldText, String newText, List<InlayHint> oldHints) { public List<InlayHint> adjustInlayHintsByLineDiff(String oldText, String newText, List<InlayHint> oldHints) {
List<String> oldLines = Arrays.asList(oldText.split("\n", -1)); List<String> oldLines = Arrays.asList(oldText.split("\n", -1));
List<String> newLines = Arrays.asList(newText.split("\n", -1)); List<String> newLines = Arrays.asList(newText.split("\n", -1));

View File

@@ -2,10 +2,7 @@ package de.dhbw.handler;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import de.dhbw.model.DiagnosticsAndTypehints; import de.dhbw.model.DiagnosticsAndTypehints;
import de.dhbw.service.CacheService; import de.dhbw.service.*;
import de.dhbw.service.ClientService;
import de.dhbw.service.LogService;
import de.dhbw.service.TextDocumentService;
import de.dhbw.helper.ConversionHelper; import de.dhbw.helper.ConversionHelper;
import de.dhbw.helper.TypeResolver; import de.dhbw.helper.TypeResolver;
import de.dhbw.model.LSPVariable; import de.dhbw.model.LSPVariable;
@@ -22,14 +19,16 @@ public class SaveHandler {
private final CacheService cacheService; private final CacheService cacheService;
private final ConversionHelper conversionHelper; private final ConversionHelper conversionHelper;
private final ClientService clientService; 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.typeResolver = typeResolver;
this.textDocumentService = textDocumentService; this.textDocumentService = textDocumentService;
this.logService = logService; this.logService = logService;
this.cacheService = cacheService; this.cacheService = cacheService;
this.conversionHelper = conversionHelper; this.conversionHelper = conversionHelper;
this.clientService = clientService; this.clientService = clientService;
this.parserService = parserService;
} }
public void handleSave(DidSaveTextDocumentParams didSaveTextDocumentParams) { public void handleSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
@@ -40,6 +39,7 @@ public class SaveHandler {
try { try {
String fileInput = textDocumentService.getFileOfUri(didSaveTextDocumentParams.getTextDocument().getUri()); String fileInput = textDocumentService.getFileOfUri(didSaveTextDocumentParams.getTextDocument().getUri());
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput); typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
if (fileInput == null) { if (fileInput == null) {
@@ -55,7 +55,11 @@ public class SaveHandler {
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics(); List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
cacheService.updateGlobalMaps(diagnostics, typeHint, didSaveTextDocumentParams.getTextDocument().getUri()); cacheService.updateGlobalMaps(diagnostics, typeHint, didSaveTextDocumentParams.getTextDocument().getUri());
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), diagnostics);
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(fileInput, didSaveTextDocumentParams.getTextDocument().getUri()));
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), allDiagnostics);
} catch (Exception e) { } catch (Exception e) {

View File

@@ -4,6 +4,10 @@ import de.dhbw.model.*;
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject; import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.Pattern; import de.dhbwstuttgart.syntaxtree.Pattern;
import de.dhbwstuttgart.syntaxtree.statement.Assign;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
import org.apache.log4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
@@ -12,6 +16,7 @@ import java.util.stream.Collectors;
public class ASTTransformationHelper { public class ASTTransformationHelper {
private static final Logger log = Logger.getLogger(ASTTransformationHelper.class);
private final DuplicationUtils duplicationUtils; private final DuplicationUtils duplicationUtils;
private final TypeUtils typeUtils; private final TypeUtils typeUtils;
private final GenericUtils genericUtils; private final GenericUtils genericUtils;
@@ -45,6 +50,10 @@ public class ASTTransformationHelper {
methodsWithParametersLSPVariableList.add(new LSPParameter("", types, fieldDecl.getOffset().getLine(), fieldDecl.getOffset().getCharPositionInLine(), fieldDecl.getOffset().getStopIndex(), fieldDecl.getReturnType())); methodsWithParametersLSPVariableList.add(new LSPParameter("", types, fieldDecl.getOffset().getLine(), fieldDecl.getOffset().getCharPositionInLine(), fieldDecl.getOffset().getStopIndex(), fieldDecl.getReturnType()));
} }
if (transferObject.getAst().KlassenVektor.getFirst().getfieldInitializations().isPresent()) {
methodsWithParametersLSPVariableList.addAll(lambdaExpressionToVariable(transferObject.getAst().KlassenVektor.getFirst().getfieldInitializations().get().block.statements, transferObject));
}
return methodsWithParametersLSPVariableList; return methodsWithParametersLSPVariableList;
} }
@@ -52,16 +61,16 @@ public class ASTTransformationHelper {
List<LSPClass> methodsWithParametersLSPVariableList = new ArrayList<>(); List<LSPClass> methodsWithParametersLSPVariableList = new ArrayList<>();
for (var method : transferObject.getAst().getAllMethods()) { // for (var method : transferObject.getAst().getAllMethods()) {
for (var clazz : transferObject.getAst().getClasses()) { // for (var clazz : transferObject.getAst().getClasses()) {
ArrayList<Type> genericTypes = genericUtils.getClassGenerics(transferObject.getGeneratedGenerics(), method, clazz); // ArrayList<Type> genericTypes = genericUtils.getClassGenerics(transferObject.getGeneratedGenerics(), method, clazz);
TextHelper helper = new TextHelper(); // TextHelper helper = new TextHelper();
if (!genericTypes.isEmpty()) { // 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())); // 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; return methodsWithParametersLSPVariableList;
} }
@@ -76,10 +85,33 @@ public class ASTTransformationHelper {
for (var param : method.getParameterList()) { for (var param : method.getParameterList()) {
methodsWithParametersLSPVariableList.addAll(parameterToVariable(transferObj, param, method, ENABLE_GENERICS)); methodsWithParametersLSPVariableList.addAll(parameterToVariable(transferObj, param, method, ENABLE_GENERICS));
} }
methodsWithParametersLSPVariableList.addAll(lambdaExpressionToVariable(method.block.statements, transferObj));
} }
return methodsWithParametersLSPVariableList; return methodsWithParametersLSPVariableList;
} }
private List<LSPParameter> lambdaExpressionToVariable(List<Statement> statements, LanguageServerTransferObject transferObj) {
List<LSPParameter> methodsWithParametersLSPVariableList = new ArrayList<>();
for (var statement : statements) {
if (statement instanceof Assign assign) {
if (assign.rightSide instanceof LambdaExpression lambdaExpression)
for (var param : lambdaExpression.params.getFormalparalist()) {
var types = typeUtils.getAvailableTypes(transferObj.getResultSets(), param.getType());
methodsWithParametersLSPVariableList.add(new LSPParameter("", types, param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex(), param.getType()));
}
}
}
return methodsWithParametersLSPVariableList;
}
private List<LSPMethod> methodToVariable(LanguageServerTransferObject transferObj, Method method, boolean ENABLE_GENERICS) { private List<LSPMethod> methodToVariable(LanguageServerTransferObject transferObj, Method method, boolean ENABLE_GENERICS) {
List<LSPMethod> methodsWithParametersLSPVariableList = new ArrayList<>(); List<LSPMethod> methodsWithParametersLSPVariableList = new ArrayList<>();

View File

@@ -56,7 +56,9 @@ public class GenericUtils {
genericsResult.forEach(conSet -> { genericsResult.forEach(conSet -> {
if (method.getReturnType().toString().toLowerCase().contains("tph ")) { if (method.getReturnType().toString().toLowerCase().contains("tph ")) {
genericTypes.add(conSet.resolveTarget(method.getReturnType()).name().replaceAll("GTV ", "")); if (conSet.resolveTarget(method.getReturnType()) != null && conSet.resolveTarget(method.getReturnType()).name() != null && conSet.resolveTarget(method.getReturnType()).name().contains("GTV")) {
genericTypes.add(conSet.resolveTarget(method.getReturnType()).name().replaceAll("GTV ", ""));
}
} }
}); });

View File

@@ -25,7 +25,7 @@ public class TypeResolver {
private final TypeUtils typeUtils; private final TypeUtils typeUtils;
private final GenericUtils genericUtils; private final GenericUtils genericUtils;
private final DuplicationUtils duplicationUtils; private final DuplicationUtils duplicationUtils;
private final boolean ENABLE_GENERICS = false; private final boolean ENABLE_GENERICS = true;
private LanguageServerTransferObject current; private LanguageServerTransferObject current;
@@ -101,17 +101,17 @@ public class TypeResolver {
} }
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables, LanguageClient client) { public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables) {
client.logMessage(new MessageParams(MessageType.Info, "Lenght is: " + combinedList.size()));
for (var lines : combinedList.entrySet()) { for (var lines : combinedList.entrySet()) {
var contentChange = lines.getValue(); var contentChange = lines.getValue();
for (LSPVariable variable : variables) { for (LSPVariable variable : variables) {
for (Type typeOfVariable : variable.getPossibleTypes()) { 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 (typeOfVariable.getType().equalsIgnoreCase(contentChange.replaceAll(" ", ""))) {
if (variable.getLine() - 1 == lines.getKey().line && variable.getCharPosition() == lines.getKey().charPosition) { 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(" ", ""))); current.getResultSets().removeIf(el -> !el.resolveType(variable.getOriginalTphName()).resolvedType.toString().equalsIgnoreCase(contentChange.replaceAll(" ", "")));
client.logMessage(new MessageParams(MessageType.Info, "Removing Resultset"));
return; return;
} }
} }

View File

@@ -14,6 +14,7 @@ import java.util.List;
public class CacheService { public class CacheService {
private HashMap<String, List<InlayHint>> globalInlayHintMap = new HashMap<>(); private HashMap<String, List<InlayHint>> globalInlayHintMap = new HashMap<>();
private HashMap<String, String> lastSavedFiles = new HashMap<>();
private Boolean currentlyCalculating = false; private Boolean currentlyCalculating = false;
private HashMap<String, List<Diagnostic>> globalDiagnosticsMap = new HashMap<>(); private HashMap<String, List<Diagnostic>> globalDiagnosticsMap = new HashMap<>();
private HashMap<String, String> textDocuments = new HashMap<>(); private HashMap<String, String> textDocuments = new HashMap<>();
@@ -42,6 +43,14 @@ public class CacheService {
return singleFileOpened; return singleFileOpened;
} }
public HashMap<String, String> getLastSavedFiles() {
return lastSavedFiles;
}
public void setLastSavedFiles(HashMap<String, String> lastSavedFiles) {
this.lastSavedFiles = lastSavedFiles;
}
public CodeSnippetOptions getCodeSnippetOptions() { public CodeSnippetOptions getCodeSnippetOptions() {
return codeSnippetOptions; return codeSnippetOptions;
} }

View File

@@ -1,14 +1,35 @@
package de.dhbw.service; package de.dhbw.service;
import de.dhbw.helper.ConversionHelper;
import de.dhbwstuttgart.languageServerInterface.ParserInterface; import de.dhbwstuttgart.languageServerInterface.ParserInterface;
import de.dhbwstuttgart.languageServerInterface.model.ParserError; import de.dhbwstuttgart.languageServerInterface.model.ParserError;
import org.eclipse.lsp4j.Diagnostic;
import java.util.List; import java.util.List;
public class ParserService { 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){ public List<ParserError> getParserErrors(String input){
ParserInterface parserInterface = new ParserInterface(); ParserInterface parserInterface = new ParserInterface();
return parserInterface.getParseErrors(input); 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));
}
} }