Compare commits
2 Commits
a53b79f91d
...
9d42e829e2
Author | SHA1 | Date | |
---|---|---|---|
|
9d42e829e2 | ||
|
a88e34431f |
@@ -51,8 +51,9 @@ public class ChangeHandler {
|
|||||||
|
|
||||||
|
|
||||||
//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
|
//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())){
|
if (cacheService.getLastSavedFiles().containsKey(params.getTextDocument().getUri())) {
|
||||||
DocumentChanges changesFromOldSave = textDocumentService.calculateDifference(cacheService.getLastSavedFiles().get(params.getTextDocument().getUri()), summedUp.get());;
|
DocumentChanges changesFromOldSave = textDocumentService.calculateDifference(cacheService.getLastSavedFiles().get(params.getTextDocument().getUri()), summedUp.get());
|
||||||
|
;
|
||||||
textChanges = changesFromOldSave.getTextChanges();
|
textChanges = changesFromOldSave.getTextChanges();
|
||||||
preciseChanges = changesFromOldSave.getPreciseChanges();
|
preciseChanges = changesFromOldSave.getPreciseChanges();
|
||||||
logService.log(textChanges.values().stream().map(el -> String.join(", ", el)).collect(Collectors.joining("\n")));
|
logService.log(textChanges.values().stream().map(el -> String.join(", ", el)).collect(Collectors.joining("\n")));
|
||||||
@@ -64,84 +65,145 @@ public class ChangeHandler {
|
|||||||
String input = summedUp.get();
|
String input = summedUp.get();
|
||||||
|
|
||||||
|
|
||||||
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables());
|
if (false) {
|
||||||
try{
|
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables());
|
||||||
File tempDir = new File(System.getProperty("java.io.tmpdir"));
|
try {
|
||||||
File tempFile = File.createTempFile("newText", ".tmp", tempDir);
|
File tempDir = new File(System.getProperty("java.io.tmpdir"));
|
||||||
FileWriter fileWriter = new FileWriter(tempFile, true);
|
File tempFile = File.createTempFile("newText", ".tmp", tempDir);
|
||||||
System.out.println(tempFile.getAbsolutePath());
|
FileWriter fileWriter = new FileWriter(tempFile, true);
|
||||||
BufferedWriter bw = new BufferedWriter(fileWriter);
|
System.out.println(tempFile.getAbsolutePath());
|
||||||
bw.write(summedUp.get());
|
BufferedWriter bw = new BufferedWriter(fileWriter);
|
||||||
bw.close();
|
bw.write(summedUp.get());
|
||||||
typeResolver.updateAst(tempFile.toURI().getPath());
|
bw.close();
|
||||||
tempFile.delete();
|
typeResolver.updateAst(tempFile.toURI().getPath());
|
||||||
}catch (Exception e){
|
tempFile.delete();
|
||||||
logService.log(e.getMessage());
|
} catch (Exception e) {
|
||||||
}
|
logService.log(e.getMessage());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var sWatch = Stopwatch.createUnstarted();
|
|
||||||
sWatch.start();
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
String currentInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
|
||||||
|
|
||||||
if (currentInput == null) {
|
|
||||||
logService.log("[didChange] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(params.getTextDocument().getUri());
|
|
||||||
|
var sWatch = Stopwatch.createUnstarted();
|
||||||
|
sWatch.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
String currentInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
if (currentInput == null) {
|
||||||
|
logService.log("[didChange] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereChangeInput(params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
|
||||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(typesOfMethodAndParameters, params.getTextDocument().getUri());
|
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(typesOfMethodAndParameters, params.getTextDocument().getUri());
|
||||||
|
|
||||||
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
||||||
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
||||||
|
|
||||||
|
|
||||||
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logService.log("[didChange] 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()){
|
for (var stackTrace : e.getStackTrace()) {
|
||||||
logService.log(stackTrace.toString());
|
logService.log(stackTrace.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
clientService.showMessage(MessageType.Error, e.getMessage());
|
||||||
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
sWatch.stop();
|
||||||
|
logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage());
|
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
|
||||||
|
|
||||||
} finally {
|
//updatePositions(params, offsetPerLine);
|
||||||
sWatch.stop();
|
|
||||||
logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
|
||||||
|
cacheService.getGlobalInlayHintMap().put(params.getTextDocument().getUri(), cacheService.getGlobalInlayHintMap().get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||||
|
//TODO: Hier das Label aufspalten an | weil die Typehints immer mit und getrennt sind und so jeder Typhint für sich durchlaufen werden kann.
|
||||||
|
logService.log(el.getLabel().getLeft().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getPosition().getLine())) + ": " + (!textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", "")) ? "true" : "false"), MessageType.Info);
|
||||||
|
return !textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", ""));
|
||||||
|
}).toList());
|
||||||
|
|
||||||
|
cacheService.getGlobalDiagnosticsMap().put(params.getTextDocument().getUri(), cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||||
|
logService.log(el.getMessage().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getRange().getStart().getLine())) + ": " + (!textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", "")) ? "true" : "false"), MessageType.Info);
|
||||||
|
return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""));
|
||||||
|
}).toList());
|
||||||
|
|
||||||
|
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);
|
||||||
|
} else {
|
||||||
|
var sWatch = Stopwatch.createUnstarted();
|
||||||
|
sWatch.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
String fileInput = input;
|
||||||
|
logService.log("Input ist:");
|
||||||
|
logService.log(fileInput);
|
||||||
|
// cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||||
|
// typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||||
|
|
||||||
|
try {
|
||||||
|
File tempDir2 = new File(System.getProperty("java.io.tmpdir"));
|
||||||
|
File tempFile2 = File.createTempFile("newText", ".tmp", tempDir2);
|
||||||
|
FileWriter fileWriter = new FileWriter(tempFile2, true);
|
||||||
|
BufferedWriter bw = new BufferedWriter(fileWriter);
|
||||||
|
bw.write(fileInput);
|
||||||
|
bw.close();
|
||||||
|
|
||||||
|
|
||||||
|
if (fileInput == null) {
|
||||||
|
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString());
|
||||||
|
cacheService.setVariables(variables);
|
||||||
|
|
||||||
|
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(variables, input);
|
||||||
|
|
||||||
|
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
||||||
|
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
||||||
|
|
||||||
|
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
|
||||||
|
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(fileInput, params.getTextDocument().getUri()));
|
||||||
|
|
||||||
|
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
||||||
|
|
||||||
|
tempFile2.delete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||||
|
|
||||||
|
for (StackTraceElement elem : e.getStackTrace()) {
|
||||||
|
logService.log(elem.toString());
|
||||||
|
}
|
||||||
|
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||||
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
sWatch.stop();
|
||||||
|
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logService.log(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//updatePositions(params, offsetPerLine);
|
|
||||||
|
|
||||||
|
|
||||||
cacheService.getGlobalInlayHintMap().put(params.getTextDocument().getUri(), cacheService.getGlobalInlayHintMap().get(params.getTextDocument().getUri()).stream().filter(el -> {
|
|
||||||
//TODO: Hier das Label aufspalten an | weil die Typehints immer mit und getrennt sind und so jeder Typhint für sich durchlaufen werden kann.
|
|
||||||
logService.log(el.getLabel().getLeft().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getPosition().getLine())) + ": " + (!textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", "")) ? "true" : "false"), MessageType.Info);
|
|
||||||
return !textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", ""));
|
|
||||||
}).toList());
|
|
||||||
|
|
||||||
cacheService.getGlobalDiagnosticsMap().put(params.getTextDocument().getUri(), cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri()).stream().filter(el -> {
|
|
||||||
logService.log(el.getMessage().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getRange().getStart().getLine())) + ": " + (!textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", "")) ? "true" : "false"), MessageType.Info);
|
|
||||||
return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""));
|
|
||||||
}).toList());
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -6,8 +6,12 @@ import de.dhbw.service.*;
|
|||||||
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;
|
||||||
|
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||||
import org.eclipse.lsp4j.*;
|
import org.eclipse.lsp4j.*;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -40,7 +44,7 @@ public class SaveHandler {
|
|||||||
|
|
||||||
String fileInput = textDocumentService.getFileOfUri(didSaveTextDocumentParams.getTextDocument().getUri());
|
String fileInput = textDocumentService.getFileOfUri(didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
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) {
|
||||||
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||||
@@ -61,11 +65,19 @@ public class SaveHandler {
|
|||||||
|
|
||||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), allDiagnostics);
|
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), allDiagnostics);
|
||||||
|
|
||||||
|
// LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
||||||
|
// Path path = Paths.get(new URI(didSaveTextDocumentParams.getTextDocument().getUri())).getParent();
|
||||||
|
// logService.log("Path is: " + path.toString());
|
||||||
|
//
|
||||||
|
// try{
|
||||||
|
// path.toFile().mkdirs();
|
||||||
|
// }catch (Exception e){}
|
||||||
|
// languageServerInterface.generateBytecode(path.toUri());
|
||||||
|
|
||||||
} 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("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||||
|
|
||||||
for(StackTraceElement elem : e.getStackTrace()){
|
for (StackTraceElement elem : e.getStackTrace()) {
|
||||||
logService.log(elem.toString());
|
logService.log(elem.toString());
|
||||||
}
|
}
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||||
|
@@ -54,6 +54,23 @@ public class ConversionHelper {
|
|||||||
return diagnostic;
|
return diagnostic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Diagnostic getDiagnosticWithInput(LSPVariable variable, String input, Type type) {
|
||||||
|
Range errorRange = new Range(
|
||||||
|
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
||||||
|
new Position(variable.getLine() - 1, textHelper.getEndingCharOfStartingChar(variable.getLine() - 1, variable.getCharPosition(), input)) // Endposition
|
||||||
|
);
|
||||||
|
Diagnostic diagnostic = new Diagnostic(
|
||||||
|
errorRange,
|
||||||
|
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
|
||||||
|
type.getType().replaceAll("GTV ", ""),
|
||||||
|
DiagnosticSeverity.Hint,
|
||||||
|
"JavaTX Language Server"
|
||||||
|
);
|
||||||
|
diagnostic.setCode(type.isGeneric() ? "GENERIC" : "TYPE");
|
||||||
|
|
||||||
|
return diagnostic;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Diagnostic> parseErrorToDiagnostic(List<ParserError> parserErrors){
|
public List<Diagnostic> parseErrorToDiagnostic(List<ParserError> parserErrors){
|
||||||
return parserErrors.stream().map(el -> {
|
return parserErrors.stream().map(el -> {
|
||||||
Range errorRange = new Range(
|
Range errorRange = new Range(
|
||||||
@@ -84,6 +101,23 @@ public class ConversionHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
||||||
|
}
|
||||||
|
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(ArrayList<LSPVariable> typesOfMethodAndParameters, String input){
|
||||||
|
List<InlayHint> typeHint = new ArrayList<>();
|
||||||
|
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||||
|
|
||||||
|
for (var variable : typesOfMethodAndParameters) {
|
||||||
|
|
||||||
|
InlayHint inlayHint = getInlayHint(variable);
|
||||||
|
typeHint.add(inlayHint);
|
||||||
|
|
||||||
|
for (var type : variable.getPossibleTypes()) {
|
||||||
|
Diagnostic diagnostic = getDiagnosticWithInput(variable, input, type);
|
||||||
|
diagnostics.add(diagnostic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,9 @@ import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
|||||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@@ -14,8 +17,11 @@ import org.apache.log4j.LogManager;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -31,9 +37,11 @@ public class TypeResolver {
|
|||||||
private final GenericUtils genericUtils;
|
private final GenericUtils genericUtils;
|
||||||
private final DuplicationUtils duplicationUtils;
|
private final DuplicationUtils duplicationUtils;
|
||||||
private final boolean ENABLE_GENERICS = true;
|
private final boolean ENABLE_GENERICS = true;
|
||||||
|
private List<GenericsResult> generatedGenerics = null;
|
||||||
|
|
||||||
|
|
||||||
//Somehow you have to reset to the Letter N to keep the naming of the TPHs consistent
|
//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 final String RESET_TO_LETTER = "A";
|
||||||
|
|
||||||
private LanguageServerTransferObject current;
|
private LanguageServerTransferObject current;
|
||||||
|
|
||||||
@@ -78,27 +86,69 @@ public class TypeResolver {
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<LSPVariable> infereChangeInput(String pathString) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
|
Set<TypeInsert> tips = new HashSet<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < current.getResultSets().size(); i++) {
|
||||||
|
ResultSet tiResult = current.getResultSets().get(i);
|
||||||
|
tips.addAll(TypeInsertFactory.createTypeInsertPoints(current.getAst(), tiResult, generatedGenerics.get(i)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, List<TypeInsert>> insertsOnLines = new HashMap<>();
|
||||||
|
|
||||||
|
for (TypeInsert insert : tips) {
|
||||||
|
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
|
||||||
|
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
|
||||||
|
} else {
|
||||||
|
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<LSPVariable> variables = new ArrayList<>(insertsOnLines.entrySet().stream().map(el -> new LSPVariable("test", new ArrayList<>(el.getValue().stream().map(typeinsert -> new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint())).toList()), el.getValue().getFirst().point.point.getLine(), el.getValue().getFirst().point.point.getCharPositionInLine(), el.getValue().get(0).point.point.getStopIndex(), el.getValue().get(0).getResultPair().getLeft())).toList());
|
||||||
|
|
||||||
|
for (var variable : variables) {
|
||||||
|
Set<Type> set = new HashSet<>(variable.getPossibleTypes().stream().map(el -> new Type(el.getType().replaceAll(" ", ""), el.isGeneric())).toList());
|
||||||
|
variable.getPossibleTypes().clear();
|
||||||
|
variable.getPossibleTypes().addAll(set);
|
||||||
|
logger.info(variable.getLine() + ":" + variable.getCharPosition());
|
||||||
|
for (Type t : variable.getPossibleTypes()) {
|
||||||
|
logger.info(t.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<LSPVariable> infereInput(String pathString) throws IOException, ClassNotFoundException, URISyntaxException {
|
public ArrayList<LSPVariable> infereInput(String pathString) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
|
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||||
|
|
||||||
var uri = new URI(pathString);
|
var uri = new URI(pathString);
|
||||||
var path = Path.of(uri);
|
var path = Path.of(uri);
|
||||||
var file = path.toFile();
|
var file = path.toFile();
|
||||||
|
NameGenerator.resetTo("A");
|
||||||
var compiler = new JavaTXCompiler(file, false);
|
var compiler = new JavaTXCompiler(file, false);
|
||||||
|
|
||||||
var parsedSource = compiler.sourceFiles.get(file);
|
var parsedSource = compiler.sourceFiles.get(file);
|
||||||
var tiResults = compiler.typeInference(file);
|
var tiResults = compiler.typeInference(file);
|
||||||
Set<TypeInsert> tips = new HashSet<>();
|
Set<TypeInsert> tips = new HashSet<>();
|
||||||
|
|
||||||
for (var sf : compiler.sourceFiles.values()) {
|
for (var sf : compiler.sourceFiles.values()) {
|
||||||
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(sf, tiResults);
|
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(sf, tiResults);
|
||||||
|
logger.info("Path for Class-File is: " + path.getParent().resolve("out").toFile());
|
||||||
|
Files.createDirectories(path.getParent().resolve("out"));
|
||||||
|
compiler.writeClassFile(bytecode, path.getParent().resolve("out").toFile(), false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generatedGenerics = compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file));
|
||||||
for (int i = 0; i < tiResults.size(); i++) {
|
for (int i = 0; i < tiResults.size(); i++) {
|
||||||
ResultSet tiResult = tiResults.get(i);
|
ResultSet tiResult = tiResults.get(i);
|
||||||
tips.addAll(TypeInsertFactory.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i)));
|
tips.addAll(TypeInsertFactory.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i)));
|
||||||
}
|
}
|
||||||
|
System.setOut(System.out);
|
||||||
current = new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics());
|
this.current = new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics());
|
||||||
|
|
||||||
|
|
||||||
HashMap<String, List<TypeInsert>> insertsOnLines = new HashMap<>();
|
HashMap<String, List<TypeInsert>> insertsOnLines = new HashMap<>();
|
||||||
@@ -213,7 +263,12 @@ public class TypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
public void updateAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||||
current = new LanguageServerTransferObject(current.getResultSets(), getNewAst(uri), "", current.getGeneratedGenerics());
|
logger.info("Old AST:");
|
||||||
|
logger.info(ASTPrinter.print(this.current.getAst()));
|
||||||
|
this.current = new LanguageServerTransferObject(current.getResultSets(), getNewAst(uri), "", current.getGeneratedGenerics());
|
||||||
|
|
||||||
|
logger.info("NEW AST:");
|
||||||
|
logger.info(ASTPrinter.print(current.getAst()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user