Compare commits
6 Commits
637478b1c3
...
38166cf6f2
Author | SHA1 | Date | |
---|---|---|---|
|
38166cf6f2 | ||
|
c012471a22 | ||
|
0091c9ef71 | ||
|
f6ed883ddb | ||
|
ae3b5e80d0 | ||
|
4226623abc |
@@ -5,6 +5,7 @@ import de.dhbw.helper.CodeSnippetOptions;
|
|||||||
import de.dhbw.helper.TextHelper;
|
import de.dhbw.helper.TextHelper;
|
||||||
import de.dhbw.helper.TypeResolver;
|
import de.dhbw.helper.TypeResolver;
|
||||||
import de.dhbw.model.LSPVariable;
|
import de.dhbw.model.LSPVariable;
|
||||||
|
import de.dhbw.model.LineCharPosition;
|
||||||
import de.dhbw.model.SnippetWithName;
|
import de.dhbw.model.SnippetWithName;
|
||||||
import de.dhbw.model.Type;
|
import de.dhbw.model.Type;
|
||||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||||
@@ -48,6 +49,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
TypeResolver typeResolver = new TypeResolver();
|
TypeResolver typeResolver = new TypeResolver();
|
||||||
Path fileRoot = null;
|
Path fileRoot = null;
|
||||||
Boolean singleFileOpened = false;
|
Boolean singleFileOpened = false;
|
||||||
|
List<LSPVariable> variables = new ArrayList<>();
|
||||||
|
|
||||||
public void setClient(LanguageClient client) {
|
public void setClient(LanguageClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
@@ -128,6 +130,38 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<LineCharPosition, String> differenceLinePos(String first, String second, int line) {
|
||||||
|
Map<LineCharPosition, String> result = new HashMap<>();
|
||||||
|
|
||||||
|
int i = 0, j = 0;
|
||||||
|
int startDiff = -1;
|
||||||
|
|
||||||
|
while (j < second.length()) {
|
||||||
|
if (i < first.length() && first.charAt(i) == second.charAt(j)) {
|
||||||
|
if (startDiff != -1) {
|
||||||
|
String diff = second.substring(startDiff, j);
|
||||||
|
result.put(new LineCharPosition(line, startDiff), diff);
|
||||||
|
startDiff = -1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
if (startDiff == -1) {
|
||||||
|
startDiff = j;
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDiff != -1) {
|
||||||
|
String diff = second.substring(startDiff);
|
||||||
|
result.put(new LineCharPosition(line, startDiff), diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles didChange-Event.
|
* Handles didChange-Event.
|
||||||
* updates textDocument-State on Server and run Syntax-Check. If an Error is found it will get displayed as a Diagnostic.
|
* updates textDocument-State on Server and run Syntax-Check. If an Error is found it will get displayed as a Diagnostic.
|
||||||
@@ -143,7 +177,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
String currentText = textDocuments.get(params.getTextDocument().getUri());
|
String currentText = textDocuments.get(params.getTextDocument().getUri());
|
||||||
ArrayList<String> currentTextLines = new ArrayList<>(Arrays.stream(currentText.split("\n")).toList());
|
ArrayList<String> currentTextLines = new ArrayList<>(Arrays.stream(currentText.split("\n")).toList());
|
||||||
|
HashMap<LineCharPosition, String> preciseChanges = new HashMap<>();
|
||||||
String newText = params.getContentChanges().getFirst().getText();
|
String newText = params.getContentChanges().getFirst().getText();
|
||||||
ArrayList<String> newTextLines = new ArrayList<>(Arrays.stream(newText.split("\n")).toList());
|
ArrayList<String> newTextLines = new ArrayList<>(Arrays.stream(newText.split("\n")).toList());
|
||||||
|
|
||||||
@@ -154,6 +188,11 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
if (!(currentTextLines.size() > index)) {
|
if (!(currentTextLines.size() > index)) {
|
||||||
offsetPerLine.add(0);
|
offsetPerLine.add(0);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
|
Map<LineCharPosition, String> lineDiffs = differenceLinePos(currentTextLines.get(index), newTextLine, index);
|
||||||
|
preciseChanges.putAll(lineDiffs);
|
||||||
|
|
||||||
textChanges.put(index, difference(currentTextLines.get(index), newTextLine).stream().map(el -> el.replaceAll(" ", "")).toList());
|
textChanges.put(index, difference(currentTextLines.get(index), newTextLine).stream().map(el -> el.replaceAll(" ", "")).toList());
|
||||||
offsetPerLine.add(newTextLine.length() - currentTextLines.get(index).length());
|
offsetPerLine.add(newTextLine.length() - currentTextLines.get(index).length());
|
||||||
}
|
}
|
||||||
@@ -172,7 +211,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
List<ParserError> parserErrors = parserInterface.getParseErrors(input);
|
List<ParserError> parserErrors = parserInterface.getParseErrors(input);
|
||||||
|
|
||||||
List<Diagnostic> diagnostics = parserErrors.stream().map(el -> {
|
List<Diagnostic> diagnosticsList = parserErrors.stream().map(el -> {
|
||||||
Range errorRange = new Range(
|
Range errorRange = new Range(
|
||||||
new Position(el.getLine() - 1, el.getCharPositionInLine()), // Startposition
|
new Position(el.getLine() - 1, el.getCharPositionInLine()), // Startposition
|
||||||
new Position(el.getLine() - 1, el.getEndCharPosition()) // Endposition
|
new Position(el.getLine() - 1, el.getEndCharPosition()) // Endposition
|
||||||
@@ -189,6 +228,59 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
// PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnostics);
|
// PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnostics);
|
||||||
// client.publishDiagnostics(diagnosticsParams);
|
// client.publishDiagnostics(diagnosticsParams);
|
||||||
|
|
||||||
|
|
||||||
|
List<String> combinedList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (List<String> list : textChanges.values()) {
|
||||||
|
combinedList.addAll(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
typeResolver.reduceCurrent(preciseChanges, variables, client);
|
||||||
|
//Reduce and display Typehints and Diagnostics
|
||||||
|
|
||||||
|
if (!currentlyCalculating) {
|
||||||
|
currentlyCalculating = true;
|
||||||
|
|
||||||
|
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||||
|
var sWatch = Stopwatch.createUnstarted();
|
||||||
|
sWatch.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (textDocuments.get(params.getTextDocument().getUri()) == null) {
|
||||||
|
log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||||
|
}
|
||||||
|
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(textDocuments.get(params.getTextDocument().getUri()), params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
List<InlayHint> typeHint = new ArrayList<>();
|
||||||
|
|
||||||
|
for (var variable : typesOfMethodAndParameters) {
|
||||||
|
|
||||||
|
InlayHint inlayHint = getInlayHint(variable);
|
||||||
|
typeHint.add(inlayHint);
|
||||||
|
|
||||||
|
|
||||||
|
//Diagnostics of Types
|
||||||
|
for (var type : variable.getPossibleTypes()) {
|
||||||
|
Diagnostic diagnostic = getDiagnostic(variable, params.getTextDocument().getUri(), type);
|
||||||
|
diagnostics.add(diagnostic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||||
|
client.showMessage(new MessageParams(MessageType.Error, e.getMessage()));
|
||||||
|
updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
currentlyCalculating = false;
|
||||||
|
sWatch.stop();
|
||||||
|
log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var inlayHint : globalInlayHintMap.get(params.getTextDocument().getUri())) {
|
for (var inlayHint : globalInlayHintMap.get(params.getTextDocument().getUri())) {
|
||||||
inlayHint.getPosition().setCharacter(inlayHint.getPosition().getCharacter() + offsetPerLine.get(inlayHint.getPosition().getLine()));
|
inlayHint.getPosition().setCharacter(inlayHint.getPosition().getCharacter() + offsetPerLine.get(inlayHint.getPosition().getLine()));
|
||||||
}
|
}
|
||||||
@@ -205,16 +297,15 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
globalInlayHintMap.put(params.getTextDocument().getUri(), globalInlayHintMap.get(params.getTextDocument().getUri()).stream().filter(el -> {
|
globalInlayHintMap.put(params.getTextDocument().getUri(), globalInlayHintMap.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.
|
//TODO: Hier das Label aufspalten an | weil die Typehints immer mit und getrennt sind und so jeder Typhint für sich durchlaufen werden kann.
|
||||||
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);
|
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(" ", ""));
|
return !textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", ""));
|
||||||
}).toList());
|
}).toList());
|
||||||
|
|
||||||
globalDiagnosticsMap.put(params.getTextDocument().getUri(), globalDiagnosticsMap.get(params.getTextDocument().getUri()).stream().filter(el -> {
|
globalDiagnosticsMap.put(params.getTextDocument().getUri(), globalDiagnosticsMap.get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||||
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);
|
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(" ", ""));
|
return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""));
|
||||||
}).toList());
|
}).toList());
|
||||||
|
|
||||||
|
|
||||||
updateClient(client);
|
updateClient(client);
|
||||||
client.publishDiagnostics(new PublishDiagnosticsParams(params.getTextDocument().getUri(), globalDiagnosticsMap.get(params.getTextDocument().getUri())));
|
client.publishDiagnostics(new PublishDiagnosticsParams(params.getTextDocument().getUri(), globalDiagnosticsMap.get(params.getTextDocument().getUri())));
|
||||||
}
|
}
|
||||||
@@ -333,8 +424,6 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
startLoading("compile-task", "Inferring types...", client);
|
startLoading("compile-task", "Inferring types...", client);
|
||||||
|
|
||||||
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
|
||||||
|
|
||||||
if (!currentlyCalculating) {
|
if (!currentlyCalculating) {
|
||||||
currentlyCalculating = true;
|
currentlyCalculating = true;
|
||||||
|
|
||||||
@@ -343,12 +432,13 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
sWatch.start();
|
sWatch.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), textDocuments.get(didSaveTextDocumentParams.getTextDocument().getUri()));
|
||||||
if (textDocuments.get(didSaveTextDocumentParams.getTextDocument().getUri()) == null) {
|
if (textDocuments.get(didSaveTextDocumentParams.getTextDocument().getUri()) == null) {
|
||||||
log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||||
}
|
}
|
||||||
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(textDocuments.get(didSaveTextDocumentParams.getTextDocument().getUri()), didSaveTextDocumentParams.getTextDocument().getUri());
|
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(textDocuments.get(didSaveTextDocumentParams.getTextDocument().getUri()), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
|
|
||||||
|
variables = typesOfMethodAndParameters;
|
||||||
List<InlayHint> typeHint = new ArrayList<>();
|
List<InlayHint> typeHint = new ArrayList<>();
|
||||||
|
|
||||||
for (var variable : typesOfMethodAndParameters) {
|
for (var variable : typesOfMethodAndParameters) {
|
||||||
|
@@ -12,11 +12,15 @@ import de.dhbwstuttgart.target.generate.GenericsResult;
|
|||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.eclipse.lsp4j.MessageParams;
|
||||||
|
import org.eclipse.lsp4j.MessageType;
|
||||||
|
import org.eclipse.lsp4j.Range;
|
||||||
|
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
|
||||||
|
import org.eclipse.lsp4j.services.LanguageClient;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +33,17 @@ public class TypeResolver {
|
|||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(TypeResolver.class);
|
private static final Logger logger = LogManager.getLogger(TypeResolver.class);
|
||||||
|
|
||||||
|
private final boolean ENABLE_GENERICS = false;
|
||||||
|
|
||||||
|
private LanguageServerTransferObject current;
|
||||||
|
|
||||||
|
public LanguageServerTransferObject getCurrent() {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reduceCurrent() {
|
||||||
|
current.getResultSets().removeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
private List<ResultSet> currentResults = new ArrayList<>();
|
private List<ResultSet> currentResults = new ArrayList<>();
|
||||||
|
|
||||||
@@ -186,63 +201,88 @@ public class TypeResolver {
|
|||||||
return genericTypes;
|
return genericTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getCompilerInput(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||||
|
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||||
|
var transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||||
|
current = transferObj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zum Erhalt für sowohl Parameter als auch Methoden.
|
* Zum Erhalt für sowohl Parameter als auch Methoden.
|
||||||
*/
|
*/
|
||||||
public ArrayList<LSPVariable> infereInput(String input, String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
public ArrayList<LSPVariable> infereInput(String input, String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
logger.info("Infering Types for Input.");
|
logger.info("Infering Types for Input.");
|
||||||
|
|
||||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
LanguageServerTransferObject transferObj;
|
||||||
var transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
|
||||||
|
if (current == null) {
|
||||||
|
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||||
|
transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||||
|
current = transferObj;
|
||||||
|
} else {
|
||||||
|
transferObj = current;
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<LSPVariable> methodsWithParametersLSPVariableList = new ArrayList<>();
|
ArrayList<LSPVariable> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
//TODO: Hier noch irgendwie die Klasse rausfinden oder durchgehen.
|
if (!transferObj.getResultSets().isEmpty()) {
|
||||||
//GENERICS OF CLASS
|
//TODO: Hier noch irgendwie die Klasse rausfinden oder durchgehen.
|
||||||
for (var method : transferObj.getAst().getAllMethods()) {
|
|
||||||
|
if (ENABLE_GENERICS) {
|
||||||
|
//GENERICS OF CLASS
|
||||||
|
for (var method : transferObj.getAst().getAllMethods()) {
|
||||||
|
|
||||||
|
|
||||||
for (var clazz : transferObj.getAst().getClasses()) {
|
for (var clazz : transferObj.getAst().getClasses()) {
|
||||||
ArrayList<Type> genericTypes = getClassGenerics(transferObj.getGeneratedGenerics(), method, clazz);
|
ArrayList<Type> genericTypes = getClassGenerics(transferObj.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()));
|
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 : transferObj.getAst().getAllMethods()) {
|
|
||||||
var types = getAvailableTypes(transferObj.getResultSets(), method);
|
|
||||||
var generics = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), method);
|
|
||||||
|
|
||||||
if (!filterOutDuplicates(types).isEmpty()) {
|
|
||||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(types), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
|
||||||
}
|
|
||||||
if (!generics.isEmpty()) {
|
|
||||||
ArrayList<Type> typesThatAreGeneric = 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 (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
|
||||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var param : method.getParameterList()) {
|
|
||||||
ArrayList<Type> typeParam = getAvailableTypes(transferObj.getResultSets(), param.getType());
|
|
||||||
ArrayList<Type> genericParam = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), param.getType());
|
|
||||||
|
|
||||||
if (!typeParam.isEmpty()) {
|
|
||||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typeParam), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!genericParam.isEmpty()) {
|
}
|
||||||
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(genericParam, typeParam);
|
|
||||||
|
for (var method : transferObj.getAst().getAllMethods()) {
|
||||||
|
var types = getAvailableTypes(transferObj.getResultSets(), method);
|
||||||
|
var generics = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), method);
|
||||||
|
|
||||||
|
if (!filterOutDuplicates(types).isEmpty()) {
|
||||||
|
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(types), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ENABLE_GENERICS) {
|
||||||
|
if (!generics.isEmpty()) {
|
||||||
|
ArrayList<Type> typesThatAreGeneric = 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 (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||||
|
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var param : method.getParameterList()) {
|
||||||
|
ArrayList<Type> typeParam = getAvailableTypes(transferObj.getResultSets(), param.getType());
|
||||||
|
ArrayList<Type> genericParam = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), param.getType());
|
||||||
|
|
||||||
|
if (!typeParam.isEmpty()) {
|
||||||
|
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typeParam), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex(), param.getType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ENABLE_GENERICS) {
|
||||||
|
if (!genericParam.isEmpty()) {
|
||||||
|
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(genericParam, typeParam);
|
||||||
|
|
||||||
|
|
||||||
if (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
if (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex(), param.getType()));
|
||||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, new ArrayList<>(filterOutDuplicates(typesThatAreGeneric).stream().map(el -> new Type("<" + el.getType() + ">", true)).toList()), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, new ArrayList<>(filterOutDuplicates(typesThatAreGeneric).stream().map(el -> new Type("<" + el.getType() + ">", true)).toList()), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,4 +292,22 @@ public class TypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,9 +1,11 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LSPClass extends LSPVariable{
|
public class LSPClass extends LSPVariable{
|
||||||
public LSPClass(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition) {
|
public LSPClass(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||||
super(name, possibleTypes, line, charPosition, endPosition);
|
super(name, possibleTypes, line, charPosition, endPosition, originalTphName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LSPMethod extends LSPVariable {
|
public class LSPMethod extends LSPVariable {
|
||||||
public LSPMethod(String name, ArrayList<Type> type, int line, int charPosition, int endPosition) {
|
public LSPMethod(String name, ArrayList<Type> type, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||||
super(name, type, line, charPosition, endPosition);
|
super(name, type, line, charPosition, endPosition, originalTphName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LSPParameter extends LSPMethod {
|
public class LSPParameter extends LSPVariable {
|
||||||
|
|
||||||
public LSPParameter(String name, ArrayList<Type> type, int line, int charPosition, int endPosition) {
|
public LSPParameter(String name, ArrayList<Type> type, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||||
super(name, type, line, charPosition, endPosition);
|
super(name, type, line, charPosition, endPosition, originalTphName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,33 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LSPVariable { String name;
|
public class LSPVariable {
|
||||||
|
String name;
|
||||||
ArrayList<Type> possibleTypes;
|
ArrayList<Type> possibleTypes;
|
||||||
int line;
|
int line;
|
||||||
int charPosition;
|
int charPosition;
|
||||||
int endPosition;
|
int endPosition;
|
||||||
boolean needsInference;
|
boolean needsInference;
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric originalTphName;
|
||||||
|
|
||||||
public LSPVariable(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition) {
|
public LSPVariable(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.possibleTypes = possibleTypes;
|
this.possibleTypes = possibleTypes;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
this.charPosition = charPosition;
|
this.charPosition = charPosition;
|
||||||
this.endPosition = endPosition;
|
this.endPosition = endPosition;
|
||||||
|
this.originalTphName = originalTphName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric getOriginalTphName() {
|
||||||
|
return originalTphName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalTphName(RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||||
|
this.originalTphName = originalTphName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndPosition() {
|
public int getEndPosition() {
|
||||||
|
@@ -0,0 +1,25 @@
|
|||||||
|
package de.dhbw.model;
|
||||||
|
|
||||||
|
public class LineCharPosition {
|
||||||
|
public final int line;
|
||||||
|
public final int charPosition;
|
||||||
|
|
||||||
|
public LineCharPosition(int line, int charPosition) {
|
||||||
|
this.line = line;
|
||||||
|
this.charPosition = charPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof LineCharPosition)) return false;
|
||||||
|
LineCharPosition that = (LineCharPosition) o;
|
||||||
|
return line == that.line && charPosition == that.charPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Line " + line + ", Char " + charPosition;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,30 +1,39 @@
|
|||||||
|
|
||||||
import de.dhbw.helper.TextHelper;
|
import de.dhbw.helper.TextHelper;
|
||||||
import de.dhbw.helper.TypeResolver;
|
import de.dhbw.helper.TypeResolver;
|
||||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
public class CompilerInterfaceTest {
|
public class CompilerInterfaceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractSyntaxAsString() throws IOException, ClassNotFoundException {
|
public void testAbstractSyntaxAsString() throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
// LanguageServerInterface languageServer = new LanguageServerInterface();
|
TypeResolver typeResolver = new TypeResolver();
|
||||||
// var res = languageServer.getResultSetAndAbstractSyntax("import java.lang.Integer;\n import java.lang.String;\n" +
|
var res = typeResolver.infereInput("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||||
// "public class test{\n" +
|
"public class test{\n" +
|
||||||
// "public main(test){" +
|
"public main(test){" +
|
||||||
// "if(0>1){" +
|
"if(0>1){" +
|
||||||
// "return \"w\";" +
|
"return \"w\";" +
|
||||||
// "}" +
|
"}" +
|
||||||
// "Integer i = 0;" +
|
"Integer i = 0;" +
|
||||||
// "return i;" +
|
"return i;" +
|
||||||
// "}" +
|
"}" +
|
||||||
// "}", "TEST");
|
"}", "c%3A/Users/ruben/Neuer%20Ordner%20%282%29/LSP-Vortrag/images/test.jav");
|
||||||
//
|
|
||||||
// System.out.println("TEST OUTPUT:");
|
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<>();
|
// ArrayList<String> allTypes = new ArrayList<>();
|
||||||
//
|
//
|
||||||
@@ -114,7 +123,7 @@ public class CompilerInterfaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCharEnding() throws IOException, ClassNotFoundException {
|
public void testCharEnding() throws IOException, ClassNotFoundException {
|
||||||
TextHelper textHelper = new TextHelper();
|
TextHelper textHelper = new TextHelper();
|
||||||
var endingChar = textHelper.getEndingCharOfStartingChar(3,13,"import java.lang.Integer;\n" +
|
var endingChar = textHelper.getEndingCharOfStartingChar(3, 13, "import java.lang.Integer;\n" +
|
||||||
"import java.lang.String; \n" +
|
"import java.lang.String; \n" +
|
||||||
"public class test{\n" +
|
"public class test{\n" +
|
||||||
" public main(test, test2){\n" +
|
" public main(test, test2){\n" +
|
||||||
|
@@ -11,6 +11,7 @@ public class JavaTXLanguageDocumentServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void testWordExtraction() {
|
public void testWordExtraction() {
|
||||||
JavaTXTextDocumentService service = new JavaTXTextDocumentService();
|
// JavaTXTextDocumentService service = new JavaTXTextDocumentService();
|
||||||
|
// service.didSave(new DidSaveTextDocumentParams(new TextDocumentIdentifier("file:///c%3A/Users/ruben/Neuer%20Ordner%20%282%29/LSP-Vortrag/images/test.jav")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user