Compare commits
15 Commits
refactor
...
positionAd
Author | SHA1 | Date | |
---|---|---|---|
|
1e125407f1 | ||
|
579d736efc | ||
|
c5760210fe | ||
|
2e6be4079a | ||
|
bb9be2c319 | ||
|
57c82542f4 | ||
|
cb54606a93 | ||
|
31ed1f16b6 | ||
|
5569b6d0db | ||
|
2a87b85dc1 | ||
|
11fb843efe | ||
|
701caab9cd | ||
|
c2cbd0aa92 | ||
|
e1b000b976 | ||
|
7de2b2764a |
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.2",
|
||||
"engines": {
|
||||
"vscode": "^1.94.0"
|
||||
},
|
||||
|
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;
|
||||
@@ -42,6 +37,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
private final ChangeHandler changeHandler;
|
||||
private final TextHelper textHelper;
|
||||
private final CodeActionHandler codeActionHandler;
|
||||
private final InlayHintAdjusterDiffUtils inlayHintAdjusterDiffUtils;
|
||||
|
||||
LanguageClient client;
|
||||
HashMap<String, String> textDocuments = new HashMap<>();
|
||||
@@ -52,7 +48,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
|
||||
public JavaTXTextDocumentService() {
|
||||
this.textHelper = new TextHelper();
|
||||
this.parserService = new ParserService();
|
||||
this.inlayHintAdjusterDiffUtils = new InlayHintAdjusterDiffUtils();
|
||||
this.cacheService = new CacheService();
|
||||
this.clientService = new ClientService(null);
|
||||
this.typeResolver = new TypeResolver();
|
||||
@@ -60,9 +56,10 @@ 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.parserService = new ParserService(conversionHelper, clientService, cacheService);
|
||||
this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService);
|
||||
this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService);
|
||||
this.changeHandler = new ChangeHandler(textDocumentService, parserService, conversionHelper, clientService, typeResolver, cacheService, logService);
|
||||
this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService, parserService);
|
||||
this.changeHandler = new ChangeHandler(textDocumentService, parserService, conversionHelper, clientService, typeResolver, cacheService, logService, inlayHintAdjusterDiffUtils);
|
||||
}
|
||||
|
||||
public void setClient(LanguageClient client) {
|
||||
|
@@ -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
|
||||
|
@@ -10,8 +10,12 @@ import de.dhbw.model.LineCharPosition;
|
||||
import de.dhbw.service.*;
|
||||
import org.eclipse.lsp4j.*;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChangeHandler {
|
||||
|
||||
@@ -22,8 +26,9 @@ public class ChangeHandler {
|
||||
private final TypeResolver typeResolver;
|
||||
private final CacheService cacheService;
|
||||
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.parserService = parserService;
|
||||
this.conversionHelper = conversionHelper;
|
||||
@@ -31,25 +36,53 @@ public class ChangeHandler {
|
||||
this.typeResolver = typeResolver;
|
||||
this.cacheService = cacheService;
|
||||
this.logService = logService;
|
||||
this.inlayHintAdjusterDiffUtils = inlayHintAdjusterDiffUtils;
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
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();
|
||||
|
||||
checkParser(input, params.getTextDocument().getUri());
|
||||
|
||||
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables(), clientService.getClient());
|
||||
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables());
|
||||
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());
|
||||
}catch (Exception e){
|
||||
logService.log(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
var sWatch = Stopwatch.createUnstarted();
|
||||
sWatch.start();
|
||||
@@ -59,7 +92,7 @@ public class ChangeHandler {
|
||||
String currentInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
||||
|
||||
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());
|
||||
@@ -75,17 +108,22 @@ public class ChangeHandler {
|
||||
|
||||
|
||||
} 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());
|
||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||
|
||||
} finally {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
updatePositions(params, offsetPerLine);
|
||||
//updatePositions(params, offsetPerLine);
|
||||
|
||||
|
||||
cacheService.getGlobalInlayHintMap().put(params.getTextDocument().getUri(), cacheService.getGlobalInlayHintMap().get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||
@@ -99,13 +137,29 @@ public class ChangeHandler {
|
||||
return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""));
|
||||
}).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){
|
||||
|
@@ -60,7 +60,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(
|
||||
|
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
|
||||
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> newLines = Arrays.asList(newText.split("\n", -1));
|
||||
|
||||
|
@@ -2,10 +2,7 @@ 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;
|
||||
@@ -22,14 +19,16 @@ 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) {
|
||||
@@ -40,6 +39,7 @@ public class SaveHandler {
|
||||
try {
|
||||
|
||||
String fileInput = textDocumentService.getFileOfUri(didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
|
||||
if (fileInput == null) {
|
||||
@@ -55,7 +55,11 @@ 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);
|
||||
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(fileInput, didSaveTextDocumentParams.getTextDocument().getUri()));
|
||||
|
||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), allDiagnostics);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@@ -4,6 +4,10 @@ import de.dhbw.model.*;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
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;
|
||||
@@ -12,6 +16,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class ASTTransformationHelper {
|
||||
|
||||
private static final Logger log = Logger.getLogger(ASTTransformationHelper.class);
|
||||
private final DuplicationUtils duplicationUtils;
|
||||
private final TypeUtils typeUtils;
|
||||
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()));
|
||||
}
|
||||
|
||||
if (transferObject.getAst().KlassenVektor.getFirst().getfieldInitializations().isPresent()) {
|
||||
methodsWithParametersLSPVariableList.addAll(lambdaExpressionToVariable(transferObject.getAst().KlassenVektor.getFirst().getfieldInitializations().get().block.statements, transferObject));
|
||||
}
|
||||
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
@@ -52,16 +61,16 @@ public class ASTTransformationHelper {
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
@@ -76,10 +85,33 @@ public class ASTTransformationHelper {
|
||||
for (var param : method.getParameterList()) {
|
||||
methodsWithParametersLSPVariableList.addAll(parameterToVariable(transferObj, param, method, ENABLE_GENERICS));
|
||||
}
|
||||
methodsWithParametersLSPVariableList.addAll(lambdaExpressionToVariable(method.block.statements, transferObj));
|
||||
}
|
||||
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) {
|
||||
List<LSPMethod> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -56,7 +56,9 @@ public class GenericUtils {
|
||||
|
||||
genericsResult.forEach(conSet -> {
|
||||
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 ", ""));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -0,0 +1,18 @@
|
||||
package de.dhbw.helper;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import org.eclipse.lsp4j.InlayHint;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
|
||||
public class PositionAdjustmentHelper {
|
||||
|
||||
private final TypeResolver typeResolver;
|
||||
|
||||
public PositionAdjustmentHelper(TypeResolver typeResolver) {
|
||||
this.typeResolver = typeResolver;
|
||||
}
|
||||
}
|
@@ -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 {
|
||||
|
@@ -4,11 +4,9 @@ package de.dhbw.helper;
|
||||
import de.dhbw.model.*;
|
||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
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.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -25,7 +23,10 @@ public class TypeResolver {
|
||||
private final TypeUtils typeUtils;
|
||||
private final GenericUtils genericUtils;
|
||||
private final DuplicationUtils duplicationUtils;
|
||||
private final boolean ENABLE_GENERICS = false;
|
||||
private final boolean ENABLE_GENERICS = true;
|
||||
|
||||
//Somehow you have to reset to the Letter N to keep the naming of the TPHs consistent
|
||||
private final String RESET_TO_LETTER = "N";
|
||||
|
||||
private LanguageServerTransferObject current;
|
||||
|
||||
@@ -57,14 +58,14 @@ 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.getResultSetAndAbstractSyntax(path);
|
||||
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;
|
||||
@@ -100,18 +101,47 @@ public class TypeResolver {
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
public ArrayList<LSPVariable> infereInput(String input, String path, SourceFile sourceFile) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
logger.info("Infering Types for Input.");
|
||||
|
||||
current = updateIfNotPresent(path, input);
|
||||
LanguageServerTransferObject transferObj = current;
|
||||
|
||||
transferObj = new LanguageServerTransferObject(transferObj.getResultSets(), sourceFile, "", transferObj.getGeneratedGenerics());
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
|
||||
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables) {
|
||||
|
||||
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables, LanguageClient client) {
|
||||
client.logMessage(new MessageParams(MessageType.Info, "Lenght is: " + combinedList.size()));
|
||||
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 +149,14 @@ 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 {
|
||||
current = new LanguageServerTransferObject(current.getResultSets(), getNewAst(uri), "", current.getGeneratedGenerics());
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
|
@@ -14,6 +14,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<>();
|
||||
@@ -42,6 +43,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));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
@@ -49,18 +50,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